Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Avoid conflation of Space and Account #1545

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/access-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/blob-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
uses: actions/checkout@v3
- name: Install
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/did-mailto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
uses: actions/checkout@v3
- name: Install
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/filecoin-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:

- name: Install
uses: pnpm/action-setup@v4
with:
version: 9

- name: Setup
uses: actions/setup-node@v3
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/upload-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:

- name: Install
uses: pnpm/action-setup@v4
with:
version: 9

- name: Setup
uses: actions/setup-node@v3
Expand Down Expand Up @@ -61,8 +59,6 @@ jobs:

- name: Install
uses: pnpm/action-setup@v4
with:
version: 9

- name: Setup
uses: actions/setup-node@v3
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/w3up-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
uses: actions/checkout@v3
- name: Install
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup
uses: actions/setup-node@v3
with:
Expand Down
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
Loading