From 8cd7e143cd9308cff6a76d57dbb77180dc28f32f Mon Sep 17 00:00:00 2001 From: Benjamin Goering <171782+gobengo@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:01:15 -0700 Subject: [PATCH 1/2] remove agent-data sessionProof public method --- packages/access-client/package.json | 13 ++++++++++++- packages/access-client/src/agent-data.js | 24 ++++++++++++++---------- packages/access-client/src/agent.js | 4 ++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/access-client/package.json b/packages/access-client/package.json index 2f1f398d9..cf3cd8577 100644 --- a/packages/access-client/package.json +++ b/packages/access-client/package.json @@ -113,7 +113,18 @@ "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": [ + "warn", + { + "definedTypes": [ + "AsyncIterable", + "AsyncIterableIterator", + "Iterable", + "IterableIterator" + ] + } + ] }, "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 6992896bd..f52f764ac 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 } @@ -265,7 +265,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)) { From 5cae9498f6a0f1ac7ee853d1fd71de23c37dc116 Mon Sep 17 00:00:00 2001 From: Benjamin Goering <171782+gobengo@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:03:50 -0700 Subject: [PATCH 2/2] jsdoc/no-undefined-types warn -> error --- packages/access-client/package.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/access-client/package.json b/packages/access-client/package.json index cf3cd8577..a3cba524c 100644 --- a/packages/access-client/package.json +++ b/packages/access-client/package.json @@ -115,13 +115,19 @@ "unicorn/prefer-export-from": "off", "unicorn/no-array-reduce": "off", "jsdoc/no-undefined-types": [ - "warn", + "error", { "definedTypes": [ + "ArrayLike", "AsyncIterable", "AsyncIterableIterator", "Iterable", - "IterableIterator" + "IterableIterator", + "Generator", + "CryptoKeyPair", + "NodeJS", + "ErrorOptions", + "IDBTransactionMode" ] } ]