From 06fc93f2fbc3c89b6e6d8285ef6c018647213f61 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Fri, 11 Oct 2024 10:24:20 -0400 Subject: [PATCH] refactor: Avoid conflation of Space and Account (#1545) * `space.signer.withDID(account)` gives us a Signer with the Space's key, but which reports the Account's DID. It looks like this might have been needed at some point when this thing was actually used to sign something. But as of now, we don't need a *Signer*, just a DID, and a `did:mailto:` is fine. So, simplify this. * This was being passed as the `agent`, but it's not an Agent. `createAuthorization()` doesn't need an Agent, it needs an *audience*. In some cases that's an Agent, in some cases it's an Account. This changes the name to clarify. --- packages/access-client/src/space.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/access-client/src/space.js b/packages/access-client/src/space.js index 753df58ff..ec2b1c15c 100644 --- a/packages/access-client/src/space.js +++ b/packages/access-client/src/space.js @@ -1,5 +1,5 @@ import * as ED25519 from '@ucanto/principal/ed25519' -import { delegate, Schema, UCAN, error, fail } from '@ucanto/core' +import { delegate, Schema, UCAN, error, fail, DID } from '@ucanto/core' import * as BIP39 from '@scure/bip39' import { wordlist } from '@scure/bip39/wordlists/english' import * as API from './types.js' @@ -67,7 +67,7 @@ export const toMnemonic = ({ signer }) => { */ export const createRecovery = (space, account) => createAuthorization(space, { - agent: space.signer.withDID(account), + audience: DID.parse(account), access: Access.accountAccess, expiration: Infinity, }) @@ -85,21 +85,21 @@ export const SESSION_LIFETIME = 60 * 60 * 24 * 365 * * @param {Model} space * @param {object} options - * @param {API.Principal} options.agent + * @param {API.Principal} options.audience * @param {API.Access} [options.access] * @param {API.UTCUnixTimestamp} [options.expiration] */ export const createAuthorization = async ( { signer, name }, { - agent, + audience, access = Access.spaceAccess, expiration = UCAN.now() + SESSION_LIFETIME, } ) => { return await delegate({ issuer: signer, - audience: agent, + audience: audience, capabilities: toCapabilities({ [signer.did()]: access, }), @@ -174,7 +174,7 @@ export class OwnedSpace { return fail('Please provide an agent to save the space into') } - const proof = await createAuthorization(this, { agent }) + const proof = await createAuthorization(this, { audience: agent }) await agent.importSpaceFromDelegation(proof) await agent.setCurrentSpace(this.did()) @@ -210,13 +210,13 @@ export class OwnedSpace { * specified ability (passed as `access.can` field) on the this space. * Optionally, you can specify `access.expiration` field to set the * - * @param {API.Principal} agent + * @param {API.Principal} principal * @param {object} [input] * @param {API.Access} [input.access] * @param {API.UCAN.UTCUnixTimestamp} [input.expiration] */ - createAuthorization(agent, input) { - return createAuthorization(this, { ...input, agent }) + createAuthorization(principal, input) { + return createAuthorization(this, { ...input, audience: principal }) } /**