diff --git a/packages/access-client/package.json b/packages/access-client/package.json index 2f1f398d9..a3cba524c 100644 --- a/packages/access-client/package.json +++ b/packages/access-client/package.json @@ -113,7 +113,24 @@ "rules": { "unicorn/prefer-number-properties": "off", "unicorn/prefer-export-from": "off", - "unicorn/no-array-reduce": "off" + "unicorn/no-array-reduce": "off", + "jsdoc/no-undefined-types": [ + "error", + { + "definedTypes": [ + "ArrayLike", + "AsyncIterable", + "AsyncIterableIterator", + "Iterable", + "IterableIterator", + "Generator", + "CryptoKeyPair", + "NodeJS", + "ErrorOptions", + "IDBTransactionMode" + ] + } + ] }, "env": { "mocha": true diff --git a/packages/access-client/src/agent-data.js b/packages/access-client/src/agent-data.js index 7be6bf234..4d93c21cc 100644 --- a/packages/access-client/src/agent-data.js +++ b/packages/access-client/src/agent-data.js @@ -1,6 +1,7 @@ import { Signer } from '@ucanto/principal' import { Signer as EdSigner } from '@ucanto/principal/ed25519' import { importDAG } from '@ucanto/core/delegation' +import * as Ucanto from '@ucanto/interface' import { DID } from '@ucanto/core' import { CID } from 'multiformats' import { Access } from '@web3-storage/capabilities' @@ -161,16 +162,19 @@ export class AgentData { this.delegations.delete(cid.toString()) await this.#save(this.export()) } +} - /** - * The current session proof. - */ - sessionProof() { - for (const { delegation } of this.delegations.values()) { - const cap = delegation.capabilities.find( - (c) => c.can === Access.session.can // TODO we should make sure this is the current session proof - we were checking nb.key but that doesn't seem to exist in the staging ucan/attest at the moment - ) - if (cap && !isExpired(delegation)) return delegation - } +/** + * get session proof + * + * @param {AgentData} data + * @returns {Ucanto.Delegation | undefined} + */ +export function getSessionProof(data) { + for (const { delegation } of data.delegations.values()) { + const cap = delegation.capabilities.find( + (c) => c.can === Access.session.can // TODO we should make sure this is the current session proof - we were checking nb.key but that doesn't seem to exist in the staging ucan/attest at the moment + ) + if (cap && !isExpired(delegation)) return delegation } } diff --git a/packages/access-client/src/agent.js b/packages/access-client/src/agent.js index 71bb95de1..5864688e2 100644 --- a/packages/access-client/src/agent.js +++ b/packages/access-client/src/agent.js @@ -24,7 +24,7 @@ import { validate, canDelegateCapability, } from './delegations.js' -import { AgentData } from './agent-data.js' +import { AgentData, getSessionProof } from './agent-data.js' export { AgentData } @@ -269,7 +269,7 @@ export class Agent { */ proofs(caps) { const arr = [] - const session = this.#data.sessionProof() + const session = getSessionProof(this.#data) let hasSessionDelegations = false for (const { delegation } of this.#delegations(caps)) {