@web3-storage/access
Advanced tools
Comparing version 16.3.0 to 16.4.0
/** | ||
* @typedef {string} SessionProofAuthorizationCid - the nb.proof CID of the ucan/attest in the session proof | ||
* @typedef {Ucanto.DID} SessionProofIssuer - issuer of ucan/attest session proof | ||
* @typedef {Record<SessionProofAuthorizationCid, Record<SessionProofIssuer, [Ucanto.Delegation, ...Ucanto.Delegation[]]>>} SessionProofIndexedByAuthorizationAndIssuer | ||
*/ | ||
/** | ||
* Get a map from CIDs to the session proofs that reference them | ||
* | ||
* @param {AgentData} data | ||
* @returns {Record<string, Ucanto.Delegation>} | ||
* @returns {SessionProofIndexedByAuthorizationAndIssuer} | ||
*/ | ||
export function getSessionProofs(data: AgentData): Record<string, Ucanto.Delegation>; | ||
export function getSessionProofs(data: AgentData): SessionProofIndexedByAuthorizationAndIssuer; | ||
/** @typedef {import('./types.js').AgentDataModel} AgentDataModel */ | ||
@@ -76,5 +81,14 @@ /** @implements {AgentDataModel} */ | ||
}]>; | ||
/** | ||
* - the nb.proof CID of the ucan/attest in the session proof | ||
*/ | ||
export type SessionProofAuthorizationCid = string; | ||
/** | ||
* - issuer of ucan/attest session proof | ||
*/ | ||
export type SessionProofIssuer = Ucanto.DID; | ||
export type SessionProofIndexedByAuthorizationAndIssuer = Record<SessionProofAuthorizationCid, Record<SessionProofIssuer, [Ucanto.Delegation, ...Ucanto.Delegation[]]>>; | ||
export type AgentDataModel = import('./types.js').AgentDataModel; | ||
import { Signer as EdSigner } from '@ucanto/principal/ed25519'; | ||
import * as Ucanto from '@ucanto/interface'; | ||
import { Signer as EdSigner } from '@ucanto/principal/ed25519'; | ||
//# sourceMappingURL=agent-data.d.ts.map |
@@ -56,3 +56,3 @@ import { Signer } from '@ucanto/principal'; | ||
delegation: importDAG(value.delegation.map((d) => ({ | ||
cid: CID.parse(d.cid), | ||
cid: CID.parse(d.cid).toV1(), | ||
bytes: d.bytes, | ||
@@ -147,9 +147,14 @@ }))), | ||
/** | ||
* @typedef {string} SessionProofAuthorizationCid - the nb.proof CID of the ucan/attest in the session proof | ||
* @typedef {Ucanto.DID} SessionProofIssuer - issuer of ucan/attest session proof | ||
* @typedef {Record<SessionProofAuthorizationCid, Record<SessionProofIssuer, [Ucanto.Delegation, ...Ucanto.Delegation[]]>>} SessionProofIndexedByAuthorizationAndIssuer | ||
*/ | ||
/** | ||
* Get a map from CIDs to the session proofs that reference them | ||
* | ||
* @param {AgentData} data | ||
* @returns {Record<string, Ucanto.Delegation>} | ||
* @returns {SessionProofIndexedByAuthorizationAndIssuer} | ||
*/ | ||
export function getSessionProofs(data) { | ||
/** @type {Record<string, Ucanto.Delegation>} */ | ||
/** @type {SessionProofIndexedByAuthorizationAndIssuer} */ | ||
const proofs = {}; | ||
@@ -162,3 +167,7 @@ for (const { delegation } of data.delegations.values()) { | ||
if (proof) { | ||
proofs[proof.toString()] = delegation; | ||
const proofCid = proof.toString(); | ||
const issuerDid = delegation.issuer.did(); | ||
proofs[proofCid] = proofs[proofCid] ?? {}; | ||
proofs[proofCid][issuerDid] = proofs[proofCid][issuerDid] ?? []; | ||
proofs[proofCid][issuerDid].push(delegation); | ||
} | ||
@@ -165,0 +174,0 @@ } |
@@ -117,5 +117,9 @@ /** | ||
* | ||
* @param {import('@ucanto/interface').Capability[]} [caps] - Capabilities to filter by. Empty or undefined caps with return all the proofs. | ||
* @param {import('@ucanto/interface').Capability[]|undefined} [caps] - Capabilities to filter by. Empty or undefined caps with return all the proofs. | ||
* @param {object} [options] | ||
* @param {Ucanto.DID} [options.sessionProofIssuer] - only include session proofs for this issuer | ||
*/ | ||
proofs(caps?: Client.Capability<Client.Ability, `${string}:${string}`, any>[] | undefined): Client.Delegation<Client.Capabilities>[]; | ||
proofs(caps?: import('@ucanto/interface').Capability[] | undefined, options?: { | ||
sessionProofIssuer?: `did:${string}:${string}` | undefined; | ||
} | undefined): Client.Delegation<Client.Capabilities>[]; | ||
/** | ||
@@ -122,0 +126,0 @@ * Get delegations created by the agent for others. |
@@ -162,3 +162,2 @@ /* eslint-disable max-depth */ | ||
if (canDelegateCapability(value.delegation, cap)) { | ||
_caps.delete(cap); | ||
values.push(value); | ||
@@ -207,2 +206,6 @@ } | ||
const receipt = await this.invokeAndExecute(UCAN.revoke, { | ||
// per https://github.com/web3-storage/w3up/blob/main/packages/capabilities/src/ucan.js#L38C6-L38C6 the resource here should be | ||
// the current issuer - using the space DID here works for simple cases but falls apart when a delegee tries to revoke a delegation | ||
// they have re-delegated, since they don't have "ucan/revoke" capabilities on the space | ||
with: this.issuer.did(), | ||
nb: { | ||
@@ -224,19 +227,25 @@ ucan: delegation.cid, | ||
* | ||
* @param {import('@ucanto/interface').Capability[]} [caps] - Capabilities to filter by. Empty or undefined caps with return all the proofs. | ||
* @param {import('@ucanto/interface').Capability[]|undefined} [caps] - Capabilities to filter by. Empty or undefined caps with return all the proofs. | ||
* @param {object} [options] | ||
* @param {Ucanto.DID} [options.sessionProofIssuer] - only include session proofs for this issuer | ||
*/ | ||
proofs(caps) { | ||
const arr = []; | ||
proofs(caps, options) { | ||
const authorizations = []; | ||
for (const { delegation } of this.#delegations(caps)) { | ||
if (delegation.audience.did() === this.issuer.did()) { | ||
arr.push(delegation); | ||
authorizations.push(delegation); | ||
} | ||
} | ||
// now let's add any session proofs that refer to those authorizations | ||
const sessions = getSessionProofs(this.#data); | ||
for (const proof of arr) { | ||
const session = sessions[proof.asCID.toString()]; | ||
if (session) { | ||
arr.push(session); | ||
for (const proof of authorizations) { | ||
const proofsByIssuer = sessions[proof.asCID.toString()] ?? {}; | ||
const sessionProofs = options?.sessionProofIssuer | ||
? proofsByIssuer[options.sessionProofIssuer] ?? [] | ||
: Object.values(proofsByIssuer).flat(); | ||
if (sessionProofs.length) { | ||
authorizations.push(...sessionProofs); | ||
} | ||
} | ||
return arr; | ||
return authorizations; | ||
} | ||
@@ -491,2 +500,3 @@ /** | ||
async invoke(cap, options) { | ||
const audience = options.audience || this.connection.id; | ||
const space = options.with || this.currentSpace(); | ||
@@ -503,3 +513,3 @@ if (!space) { | ||
}, | ||
]), | ||
], { sessionProofIssuer: audience.did() }), | ||
]; | ||
@@ -511,3 +521,3 @@ if (proofs.length === 0 && options.with !== this.did()) { | ||
...options, | ||
audience: options.audience || this.connection.id, | ||
audience, | ||
// @ts-ignore | ||
@@ -514,0 +524,0 @@ capability: cap.create({ |
{ | ||
"name": "@web3-storage/access", | ||
"version": "16.3.0", | ||
"version": "16.4.0", | ||
"description": "w3access client", | ||
@@ -65,3 +65,3 @@ "homepage": "https://github.com/web3-storage/w3-protocol/tree/main/packages/access-client", | ||
"uint8arrays": "^4.0.6", | ||
"@web3-storage/capabilities": "^11.0.1", | ||
"@web3-storage/capabilities": "^11.1.0", | ||
"@web3-storage/did-mailto": "^2.0.2" | ||
@@ -99,2 +99,3 @@ }, | ||
"unicorn/explicit-length-check": "off", | ||
"no-continue": "off", | ||
"jsdoc/no-undefined-types": [ | ||
@@ -101,0 +102,0 @@ "error", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177070
2925