forked from storacha/w3up
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: generate sharded DAG index on client and invoke w
index/add
(s…
…toracha#1451) This PR generates index data for blocks as CAR shards are constructed. Once all shards have been successfully sent, a sharded DAG index is encoded and stored (using `blob/add`) and then `index/add` is invoked with the CID of the index as a parameter. BREAKING CHANGE: delegated capabilities required to use `uploadFile`, `uploadDirectory` and `uploadCAR` have changed. In order to use these methods your agent will now need to be delegated `blob/add`, `index/add`, `filecoin/offer` and `upload/add` capabilities. Note: no code changes are required.
- Loading branch information
Alan Shaw
authored
May 15, 2024
1 parent
eefd885
commit a6d9026
Showing
29 changed files
with
994 additions
and
338 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
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
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
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,63 @@ | ||
import * as IndexCapabilities from '@web3-storage/capabilities/index' | ||
import { SpaceDID } from '@web3-storage/capabilities/utils' | ||
import retry from 'p-retry' | ||
import { servicePrincipal, connection } from './service.js' | ||
import { REQUEST_RETRIES } from './constants.js' | ||
|
||
/** | ||
* Register an "index" with the service. The issuer needs the `index/add` | ||
* delegated capability. | ||
* | ||
* Required delegated capability proofs: `index/add` | ||
* | ||
* @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 `index/add` delegated capability. | ||
* @param {import('./types.js').CARLink} index Index to store. | ||
* @param {import('./types.js').RequestOptions} [options] | ||
* @returns {Promise<import('./types.js').IndexAddSuccess>} | ||
*/ | ||
export async function add( | ||
{ issuer, with: resource, proofs, audience }, | ||
index, | ||
options = {} | ||
) { | ||
/* c8 ignore next */ | ||
const conn = options.connection ?? connection | ||
const result = await retry( | ||
async () => { | ||
return await IndexCapabilities.add | ||
.invoke({ | ||
issuer, | ||
/* c8 ignore next */ | ||
audience: audience ?? servicePrincipal, | ||
with: SpaceDID.from(resource), | ||
nb: { index }, | ||
proofs, | ||
}) | ||
.execute(conn) | ||
}, | ||
{ | ||
onFailedAttempt: console.warn, | ||
retries: options.retries ?? REQUEST_RETRIES, | ||
} | ||
) | ||
|
||
if (!result.out.ok) { | ||
throw new Error(`failed ${IndexCapabilities.add.can} invocation`, { | ||
cause: result.out.error, | ||
}) | ||
} | ||
|
||
return result.out.ok | ||
} |
Oops, something went wrong.