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

chore: 433 minimize public api #545

Merged
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
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