-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow convication configuration genetaed on demand
- Loading branch information
Alan Shaw
committed
Jun 17, 2024
1 parent
028e8d2
commit b12f933
Showing
20 changed files
with
729 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as BlobCapabilities from '@web3-storage/capabilities/blob' | ||
import { SpaceDID } from '@web3-storage/capabilities/utils' | ||
import { servicePrincipal, connection } from '../service.js' | ||
|
||
/** | ||
* Gets a stored Blob file by digest. | ||
* | ||
* @param {import('../types.js').InvocationConfig} conf Configuration | ||
* for the UCAN invocation. An object with `issuer`, `with` and `proofs`. | ||
* | ||
* The `issuer` is the signing authority that is issuing the UCAN | ||
* invocation(s). It is typically the user _agent_. | ||
* | ||
* The `with` is the resource the invocation applies to. It is typically the | ||
* DID of a space. | ||
* | ||
* The `proofs` are a set of capability delegations that prove the issuer | ||
* has the capability to perform the action. | ||
* | ||
* The issuer needs the `blob/get/0/1` delegated capability. | ||
* @param {import('multiformats').MultihashDigest} multihash of the blob | ||
* @param {import('../types.js').RequestOptions} [options] | ||
*/ | ||
export async function get( | ||
{ issuer, with: resource, proofs, audience }, | ||
multihash, | ||
options = {} | ||
) { | ||
/* c8 ignore next */ | ||
const conn = options.connection ?? connection | ||
const result = await BlobCapabilities.get | ||
.invoke({ | ||
issuer, | ||
/* c8 ignore next */ | ||
audience: audience ?? servicePrincipal, | ||
with: SpaceDID.from(resource), | ||
nb: input(multihash), | ||
proofs, | ||
nonce: options.nonce, | ||
}) | ||
.execute(conn) | ||
|
||
if (!result.out.ok) { | ||
throw new Error(`failed ${BlobCapabilities.get.can} invocation`, { | ||
cause: result.out.error, | ||
}) | ||
} | ||
|
||
return result.out | ||
} | ||
|
||
/** Returns the ability used by an invocation. */ | ||
export const ability = BlobCapabilities.get.can | ||
|
||
/** | ||
* Returns required input to the invocation. | ||
* | ||
* @param {import('multiformats').MultihashDigest} digest | ||
*/ | ||
export const input = (digest) => ({ digest: digest.bytes }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { add } from './add.js' | ||
export { get } from './get.js' | ||
export { list } from './list.js' | ||
export { remove } from './remove.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as BlobCapabilities from '@web3-storage/capabilities/blob' | ||
import { SpaceDID } from '@web3-storage/capabilities/utils' | ||
import { servicePrincipal, connection } from '../service.js' | ||
|
||
/** | ||
* List Blobs stored in the space. | ||
* | ||
* @param {import('../types.js').InvocationConfig} conf Configuration | ||
* for the UCAN invocation. An object with `issuer`, `with` and `proofs`. | ||
* | ||
* The `issuer` is the signing authority that is issuing the UCAN | ||
* invocation(s). It is typically the user _agent_. | ||
* | ||
* The `with` is the resource the invocation applies to. It is typically the | ||
* DID of a space. | ||
* | ||
* The `proofs` are a set of capability delegations that prove the issuer | ||
* has the capability to perform the action. | ||
* | ||
* The issuer needs the `blob/list` delegated capability. | ||
* @param {import('../types.js').ListRequestOptions} [options] | ||
* @returns {Promise<import('../types.js').BlobListSuccess>} | ||
*/ | ||
export async function list( | ||
{ issuer, with: resource, proofs, audience }, | ||
options = {} | ||
) { | ||
/* c8 ignore next */ | ||
const conn = options.connection ?? connection | ||
const result = await BlobCapabilities.list | ||
.invoke({ | ||
issuer, | ||
/* c8 ignore next */ | ||
audience: audience ?? servicePrincipal, | ||
with: SpaceDID.from(resource), | ||
proofs, | ||
nb: input(options.cursor, options.size), | ||
nonce: options.nonce, | ||
}) | ||
.execute(conn) | ||
|
||
if (!result.out.ok) { | ||
throw new Error(`failed ${BlobCapabilities.list.can} invocation`, { | ||
cause: result.out.error, | ||
}) | ||
} | ||
|
||
return result.out.ok | ||
} | ||
|
||
/** Returns the ability used by an invocation. */ | ||
export const ability = BlobCapabilities.list.can | ||
|
||
/** | ||
* Returns required input to the invocation. | ||
* | ||
* @param {string} [cursor] | ||
* @param {number} [size] | ||
*/ | ||
export const input = (cursor, size) => ({ cursor, size }) |
Oops, something went wrong.