Skip to content

Commit

Permalink
feat: add admin call to revoke agent key (#275)
Browse files Browse the repository at this point in the history
* feat: add admin call to revoke agent key

* docs: update changelog

* fix: stabilize zome call timeout override
  • Loading branch information
jost-s authored Sep 30, 2024
1 parent ce92234 commit 459390d
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## \[Unreleased\]

### Added
- Admin API call `RevokeAgentKey`.
### Changed
### Fixed
### Removed
Expand Down
19 changes: 19 additions & 0 deletions docs/client.adminwebsocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,25 @@ Register a DNA for later app installation.
Stores the given DNA into the Holochain DNA database and returns the hash of it.
</td></tr>
<tr><td>
[revokeAgentKey](./client.adminwebsocket.revokeagentkey.md)
</td><td>
</td><td>
[Requester](./client.requester.md)<!-- -->&lt;[RevokeAgentKeyRequest](./client.revokeagentkeyrequest.md)<!-- -->, [RevokeAgentKeyResponse](./client.revokeagentkeyresponse.md)<!-- -->&gt;
</td><td>
Generate a new agent pub key.
</td></tr>
<tr><td>
Expand Down
13 changes: 13 additions & 0 deletions docs/client.adminwebsocket.revokeagentkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [AdminWebsocket](./client.adminwebsocket.md) &gt; [revokeAgentKey](./client.adminwebsocket.revokeagentkey.md)

## AdminWebsocket.revokeAgentKey property

Generate a new agent pub key.

**Signature:**

```typescript
revokeAgentKey: Requester<RevokeAgentKeyRequest, RevokeAgentKeyResponse>;
```
20 changes: 20 additions & 0 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,26 @@ An internal link type index within the DNA, from 0 to 255.



</td></tr>
<tr><td>

[RevokeAgentKeyRequest](./client.revokeagentkeyrequest.md)


</td><td>



</td></tr>
<tr><td>

[RevokeAgentKeyResponse](./client.revokeagentkeyresponse.md)


</td><td>



</td></tr>
<tr><td>

Expand Down
17 changes: 17 additions & 0 deletions docs/client.revokeagentkeyrequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [RevokeAgentKeyRequest](./client.revokeagentkeyrequest.md)

## RevokeAgentKeyRequest type


**Signature:**

```typescript
export type RevokeAgentKeyRequest = {
agent_key: AgentPubKey;
app_id: InstalledAppId;
};
```
**References:** [AgentPubKey](./client.agentpubkey.md)<!-- -->, [InstalledAppId](./client.installedappid.md)

12 changes: 12 additions & 0 deletions docs/client.revokeagentkeyresponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [RevokeAgentKeyResponse](./client.revokeagentkeyresponse.md)

## RevokeAgentKeyResponse type


**Signature:**

```typescript
export type RevokeAgentKeyResponse = void;
```
12 changes: 12 additions & 0 deletions src/api/admin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ export type GenerateAgentPubKeyRequest = void;
*/
export type GenerateAgentPubKeyResponse = AgentPubKey;

/**
* @public
*/
export type RevokeAgentKeyRequest = {
agent_key: AgentPubKey;
app_id: InstalledAppId;
};
/**
* @public
*/
export type RevokeAgentKeyResponse = void;

/**
* @public
*/
Expand Down
8 changes: 8 additions & 0 deletions src/api/admin/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import {
ListDnasResponse,
RegisterDnaRequest,
RegisterDnaResponse,
RevokeAgentKeyRequest,
RevokeAgentKeyResponse,
StorageInfoRequest,
StorageInfoResponse,
UninstallAppRequest,
Expand Down Expand Up @@ -181,6 +183,12 @@ export class AdminWebsocket implements AdminApi {
GenerateAgentPubKeyResponse
> = this._requester("generate_agent_pub_key");

/**
* Generate a new agent pub key.
*/
revokeAgentKey: Requester<RevokeAgentKeyRequest, RevokeAgentKeyResponse> =
this._requester("revoke_agent_key");

/**
* Register a DNA for later app installation.
*
Expand Down
28 changes: 18 additions & 10 deletions test/e2e/fixture/zomes/foo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use hdk::prelude::{holo_hash::DnaHash, *};

#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes)]
#[repr(transparent)]
#[serde(transparent)]
#[hdk_entry_helper]
pub struct TestString(pub String);

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -23,29 +21,39 @@ impl From<&str> for TestString {
}
}

#[hdk_entry_types]
#[unit_enum(UnitEntryTypes)]
enum EntryTypes {
Test(TestString),
}

#[hdk_link_types]
// #[derive]
enum LinkTypes {
A,
}

#[hdk_extern]
fn init(_: ()) -> ExternResult<InitCallbackResult> {
fn init() -> ExternResult<InitCallbackResult> {
Ok(InitCallbackResult::Pass)
}

#[hdk_extern]
fn foo(_: ()) -> ExternResult<TestString> {
fn foo() -> ExternResult<TestString> {
Ok(TestString::from(String::from("foo")))
}

#[hdk_extern]
fn bar(_: ()) -> ExternResult<TestString> {
fn bar() -> ExternResult<TestString> {
Ok(TestString::from(String::from("bar")))
}

#[hdk_extern]
fn emitter(_: ()) -> ExternResult<TestString> {
fn create_an_entry() -> ExternResult<ActionHash> {
create_entry(EntryTypes::Test(TestString::from(String::from("bar"))))
}

#[hdk_extern]
fn emitter() -> ExternResult<TestString> {
match emit_signal(&TestString::from(String::from("i am a signal"))) {
Ok(()) => Ok(TestString::from(String::from("bar"))),
Err(e) => Err(e),
Expand All @@ -59,7 +67,7 @@ pub fn echo_app_entry_def(entry_def: AppEntryDef) -> ExternResult<()> {
}

#[hdk_extern]
pub fn waste_some_time(_: ()) -> ExternResult<TestString> {
pub fn waste_some_time() -> ExternResult<TestString> {
let mut x: u32 = 3;
for _ in 0..2 {
for _ in 0..99999999 {
Expand Down Expand Up @@ -111,7 +119,7 @@ pub fn create_and_get_link(tag: Vec<u8>) -> ExternResult<Link> {
}

#[hdk_extern]
pub fn create_and_delete_link(_: ()) -> ExternResult<ActionHash> {
pub fn create_and_delete_link() -> ExternResult<ActionHash> {
let link_base = agent_info()?.agent_latest_pubkey;
let link_target = link_base.clone();
let create_link_action_hash = create_link(link_base.clone(), link_target, LinkTypes::A, ())?;
Expand Down
37 changes: 36 additions & 1 deletion test/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ test(
const zomeCallPayload: CallZomeRequest = {
cell_id,
zome_name: TEST_ZOME_NAME,
fn_name: "foo",
fn_name: "waste_some_time",
provenance: fakeAgentPubKey(),
payload: null,
};
Expand Down Expand Up @@ -1458,3 +1458,38 @@ test(
t.deepEqual(response, { Output: "success" });
})
);

test(
"Agent key can be revoked",
withConductor(ADMIN_PORT, async (t) => {
const { admin, cell_id, client, installed_app_id } = await installAppAndDna(
ADMIN_PORT
);
await admin.authorizeSigningCredentials(cell_id);

const zomeCallPayload: CallZomeRequest = {
cell_id,
zome_name: TEST_ZOME_NAME,
fn_name: "create_an_entry",
provenance: cell_id[1],
payload: null,
};
let response = await client.callZome(zomeCallPayload);
t.ok(response, "zome call succeeds");

response = await admin.revokeAgentKey({
app_id: installed_app_id,
agent_key: cell_id[1],
});
t.deepEqual(response, []);

try {
response = await client.callZome(zomeCallPayload);
console.log("response", response);
t.fail("create entry must no be possible after revoking agent key");
} catch (error) {
t.assert(error instanceof HolochainError);
t.pass("create entry must no be possible after revoking agent key");
}
})
);

0 comments on commit 459390d

Please sign in to comment.