Skip to content

Commit

Permalink
chore: 433 minimize public api (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
gobengo authored Mar 15, 2023
1 parent dfe264d commit 459aa6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
19 changes: 18 additions & 1 deletion packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions packages/access-client/src/agent-data.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

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

0 comments on commit 459aa6f

Please sign in to comment.