Skip to content

Commit

Permalink
Changed API names
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Nov 22, 2024
1 parent 24a3263 commit 5bf7466
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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
Recipient-->>Recipient: show passcode input
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
Expand Down
4 changes: 2 additions & 2 deletions tests/src/link-devices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/src/linked-devices-authorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
12 changes: 6 additions & 6 deletions tests/src/transitive-linking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand All @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/elements/link-device-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class LinkDevicesRecipient extends SignalWatcher(LitElement) {
// return;
// }
try {
await this.store.client.requestLinkDevices(
await this.store.client.acceptLinkDevices(
requestor,
inputtedRequestorPasscode,
);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/elements/link-device-requestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions ui/src/linked-devices-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ export class LinkedDevicesClient extends ZomeClient<LinkedDevicesSignal> {
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,
Expand All @@ -46,11 +49,11 @@ export class LinkedDevicesClient extends ZomeClient<LinkedDevicesSignal> {
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,
});
Expand Down
20 changes: 10 additions & 10 deletions zomes/coordinator/linked_devices/src/link_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ pub fn prepare_link_devices(my_passcode: Vec<u8>) -> 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),
Expand Down Expand Up @@ -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<u8>,
}
#[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)),
(),
)?;
Expand All @@ -148,21 +148,21 @@ 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 })?;
Ok(())
}

#[derive(Serialize, Deserialize, Debug)]
pub struct RequestLinkDevicesInput {
pub struct AcceptLinkDevicesInput {
pub requestor: AgentPubKey,
pub requestor_passcode: Vec<u8>,
}
// 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 {
Expand All @@ -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,
)?;
Expand Down Expand Up @@ -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<Signature> {
let linked_devices = incomplete_proof.linked_devices;
Expand Down

0 comments on commit 5bf7466

Please sign in to comment.