Skip to content

Commit

Permalink
refactor: Avoid conflation of Space and Account (#1545)
Browse files Browse the repository at this point in the history
* `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.
  • Loading branch information
Peeja authored Oct 11, 2024
1 parent 61d408a commit 06fc93f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/access-client/src/space.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
})
Expand All @@ -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,
}),
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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 })
}

/**
Expand Down

0 comments on commit 06fc93f

Please sign in to comment.