From 5bf7466cc8091d1a69b3c4be07a2f2367c1eb65e Mon Sep 17 00:00:00 2001 From: "guillem.cordoba" Date: Fri, 22 Nov 2024 09:52:16 +0100 Subject: [PATCH] Changed API names --- docs/design.md | 4 ++-- tests/src/link-devices.test.ts | 4 ++-- .../src/linked-devices-authorization.test.ts | 4 ++-- tests/src/transitive-linking.test.ts | 12 +++++------ ui/src/elements/link-device-recipient.ts | 2 +- ui/src/elements/link-device-requestor.ts | 2 +- ui/src/linked-devices-client.ts | 11 ++++++---- .../linked_devices/src/link_devices.rs | 20 +++++++++---------- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/docs/design.md b/docs/design.md index 5fa20920..d5505292 100644 --- a/docs/design.md +++ b/docs/design.md @@ -20,7 +20,7 @@ DHT-->>Requestor: linking_agents Requestor-->>Requestor: enter recipient passcode loop for agent in linking_agents - Requestor->>Recipient: initiate_link_devices + Requestor->>Recipient: request_link_devices Recipient-->>Requestor: ack Requestor-->>Requestor: show requestor passcode @@ -28,7 +28,7 @@ loop for agent in linking_agents Recipient->>Recipient: enter requestor passcode Recipient-->>Recipient: generate LinkedDevicesProof - Recipient->>Requestor: request_sign_linked_devices_proof(proof) + Recipient->>Requestor: accept_link_devices(proof) Requestor-->>Requestor: sign LinkedDevicesProof and create AgentToLinkedDevices link Requestor-->>Recipient: signature Recipient-->>Recipient: create AgentToLinkedDevices link diff --git a/tests/src/link-devices.test.ts b/tests/src/link-devices.test.ts index ff2faa34..b4821421 100644 --- a/tests/src/link-devices.test.ts +++ b/tests/src/link-devices.test.ts @@ -22,11 +22,11 @@ test('link devices', async () => { await alice.store.client.prepareLinkDevices(alicePasscode); await bob.store.client.prepareLinkDevices(bobPasscode); - await alice.store.client.initLinkDevices( + await alice.store.client.requestLinkDevices( bob.player.agentPubKey, bobPasscode, ); - await bob.store.client.requestLinkDevices( + await bob.store.client.acceptLinkDevices( alice.player.agentPubKey, alicePasscode, ); diff --git a/tests/src/linked-devices-authorization.test.ts b/tests/src/linked-devices-authorization.test.ts index db481ccb..eb65a676 100644 --- a/tests/src/linked-devices-authorization.test.ts +++ b/tests/src/linked-devices-authorization.test.ts @@ -40,11 +40,11 @@ test('link devices can edit posts for the starting agent', async () => { await alice.store.client.prepareLinkDevices(alicePasscode); await bob.store.client.prepareLinkDevices(bobPasscode); - await alice.store.client.initLinkDevices( + await alice.store.client.requestLinkDevices( bob.player.agentPubKey, bobPasscode, ); - await bob.store.client.requestLinkDevices( + await bob.store.client.acceptLinkDevices( alice.player.agentPubKey, alicePasscode, ); diff --git a/tests/src/transitive-linking.test.ts b/tests/src/transitive-linking.test.ts index 97aed408..fd0f9c47 100644 --- a/tests/src/transitive-linking.test.ts +++ b/tests/src/transitive-linking.test.ts @@ -22,11 +22,11 @@ test('link devices transitively', async () => { await alice.store.client.prepareLinkDevices(alicePasscode); await bob.store.client.prepareLinkDevices(bobPasscode); - await alice.store.client.initLinkDevices( + await alice.store.client.requestLinkDevices( bob.player.agentPubKey, bobPasscode, ); - await bob.store.client.requestLinkDevices( + await bob.store.client.acceptLinkDevices( alice.player.agentPubKey, alicePasscode, ); @@ -63,11 +63,11 @@ test('link devices transitively', async () => { await carol.store.client.prepareLinkDevices(carolPasscode); await dave.store.client.prepareLinkDevices(davePasscode); - await carol.store.client.initLinkDevices( + await carol.store.client.requestLinkDevices( dave.player.agentPubKey, davePasscode, ); - await dave.store.client.requestLinkDevices( + await dave.store.client.acceptLinkDevices( carol.player.agentPubKey, carolPasscode, ); @@ -85,11 +85,11 @@ test('link devices transitively', async () => { await bob.store.client.prepareLinkDevices(bobPasscode); await carol.store.client.prepareLinkDevices(carolPasscode); - await bob.store.client.initLinkDevices( + await bob.store.client.requestLinkDevices( carol.player.agentPubKey, carolPasscode, ); - await carol.store.client.requestLinkDevices( + await carol.store.client.acceptLinkDevices( bob.player.agentPubKey, bobPasscode, ); diff --git a/ui/src/elements/link-device-recipient.ts b/ui/src/elements/link-device-recipient.ts index 297d6f60..03f97682 100644 --- a/ui/src/elements/link-device-recipient.ts +++ b/ui/src/elements/link-device-recipient.ts @@ -104,7 +104,7 @@ export class LinkDevicesRecipient extends SignalWatcher(LitElement) { // return; // } try { - await this.store.client.requestLinkDevices( + await this.store.client.acceptLinkDevices( requestor, inputtedRequestorPasscode, ); diff --git a/ui/src/elements/link-device-requestor.ts b/ui/src/elements/link-device-requestor.ts index 62e5c3c8..f6e08f2f 100644 --- a/ui/src/elements/link-device-requestor.ts +++ b/ui/src/elements/link-device-requestor.ts @@ -103,7 +103,7 @@ export class LinkDevicesRequestor extends SignalWatcher(LitElement) { // if (!this.attemptedRecipients.has(linkingAgent)) { // this.attemptedRecipients.set(linkingAgent, 'requesting'); try { - await this.store.client.initLinkDevices(linkingAgent, passcode); + await this.store.client.requestLinkDevices(linkingAgent, passcode); this.requestorpasscode = randomPasscode( this.store.config.linkDevicePasscodeLength, diff --git a/ui/src/linked-devices-client.ts b/ui/src/linked-devices-client.ts index d48c4bab..8740aaa9 100644 --- a/ui/src/linked-devices-client.ts +++ b/ui/src/linked-devices-client.ts @@ -33,11 +33,14 @@ export class LinkedDevicesClient extends ZomeClient { await this.callZome('clear_link_devices', null); } - async initLinkDevices(recipient: AgentPubKey, recipient_passcode: number[]) { + async requestLinkDevices( + recipient: AgentPubKey, + recipient_passcode: number[], + ) { const req: AppCallZomeRequest = { role_name: this.roleName, zome_name: this.zomeName, - fn_name: 'init_link_devices', + fn_name: 'request_link_devices', payload: { recipient, recipient_passcode, @@ -46,11 +49,11 @@ export class LinkedDevicesClient extends ZomeClient { await this.client.callZome(req, 2_000); } - async requestLinkDevices( + async acceptLinkDevices( requestor: AgentPubKey, requestor_passcode: number[], ) { - await this.callZome('request_link_devices', { + await this.callZome('accept_link_devices', { requestor, requestor_passcode, }); diff --git a/zomes/coordinator/linked_devices/src/link_devices.rs b/zomes/coordinator/linked_devices/src/link_devices.rs index 0c08d9e6..b893541a 100644 --- a/zomes/coordinator/linked_devices/src/link_devices.rs +++ b/zomes/coordinator/linked_devices/src/link_devices.rs @@ -28,11 +28,11 @@ pub fn prepare_link_devices(my_passcode: Vec) -> ExternResult<()> { let mut functions = BTreeSet::new(); functions.insert(( zome_info()?.name, - FunctionName("receive_init_link_devices".into()), + FunctionName("receive_request_link_devices".into()), )); functions.insert(( zome_info()?.name, - FunctionName("receive_request_link_devices".into()), + FunctionName("receive_accept_link_devices".into()), )); let access = CapAccess::Transferable { secret: secret_from_passcode(my_passcode), @@ -121,16 +121,16 @@ pub fn clear_link_devices() -> ExternResult<()> { } #[derive(Serialize, Deserialize, Debug)] -pub struct InitLinkDevicesInput { +pub struct RequestLinkDevicesInput { pub recipient: AgentPubKey, pub recipient_passcode: Vec, } #[hdk_extern] -pub fn init_link_devices(input: InitLinkDevicesInput) -> ExternResult<()> { +pub fn request_link_devices(input: RequestLinkDevicesInput) -> ExternResult<()> { let response = call_remote( input.recipient, zome_info()?.name, - "receive_init_link_devices".into(), + "receive_request_link_devices".into(), Some(secret_from_passcode(input.recipient_passcode)), (), )?; @@ -148,7 +148,7 @@ pub enum LinkDevicesSignal { } #[hdk_extern] -pub fn receive_init_link_devices() -> ExternResult<()> { +pub fn receive_request_link_devices() -> ExternResult<()> { let requestor = call_info()?.provenance; emit_signal(LinkDevicesSignal::LinkDevicesInitialized { requestor })?; @@ -156,13 +156,13 @@ pub fn receive_init_link_devices() -> ExternResult<()> { } #[derive(Serialize, Deserialize, Debug)] -pub struct RequestLinkDevicesInput { +pub struct AcceptLinkDevicesInput { pub requestor: AgentPubKey, pub requestor_passcode: Vec, } // Called by the recipient #[hdk_extern] -pub fn request_link_devices(input: RequestLinkDevicesInput) -> ExternResult<()> { +pub fn accept_link_devices(input: AcceptLinkDevicesInput) -> ExternResult<()> { let my_pub_key = agent_info()?.agent_latest_pubkey; let linked_devices = LinkedDevices { @@ -179,7 +179,7 @@ pub fn request_link_devices(input: RequestLinkDevicesInput) -> ExternResult<()> let response = call_remote( input.requestor.clone(), zome_info()?.name, - "receive_request_link_devices".into(), + "receive_accept_link_devices".into(), Some(secret_from_passcode(input.requestor_passcode)), incomplete_proof, )?; @@ -210,7 +210,7 @@ pub const LINKED_DEVICES_PROOF_TTL_US: u64 = 5_000_000; // 5 seconds const TTL_LIVE_AGENTS_CAP_GRANTS: i64 = 1000 * 1000 * 60; // 1 minute #[hdk_extern] -pub fn receive_request_link_devices( +pub fn receive_accept_link_devices( incomplete_proof: LinkedDevicesProof, ) -> ExternResult { let linked_devices = incomplete_proof.linked_devices;