diff --git a/src/pages/docs/concepts/architecture-options.mdx b/src/pages/docs/concepts/architecture-options.mdx index ec2e53f..9ee24d1 100644 --- a/src/pages/docs/concepts/architecture-options.mdx +++ b/src/pages/docs/concepts/architecture-options.mdx @@ -78,12 +78,11 @@ A code example that does this can be found below: **Backend** ```js -import { CarReader } from '@ipld/car' -import * as DID from '@ipld/dag-ucan/did' -import * as Delegation from '@ucanto/core/delegation' -import * as Signer from '@ucanto/principal/ed25519' import * as Client from '@web3-storage/w3up-client' import { StoreMemory } from '@web3-storage/w3up-client/stores/memory' +import * as Proof from '@web3-storage/w3up-client/proof' +import { Signer } from '@web3-storage/w3up-client/principal/ed25519' +import * as DID from '@ipld/dag-ucan/did' async function backend(did) { // Load client with specific private key @@ -92,7 +91,7 @@ async function backend(did) { const client = await Client.create({ principal, store }) // Add proof that this agent has been delegated capabilities on the space - const proof = await parseProof(process.env.PROOF) + const proof = await Proof.parse(process.env.PROOF) const space = await client.addSpace(proof) await client.setCurrentSpace(space.did()) @@ -106,22 +105,12 @@ async function backend(did) { const archive = await delegation.archive() return archive.ok } - -/** @param {string} data Base64 encoded CAR file */ -async function parseProof(data) { - const blocks = [] - const reader = await CarReader.fromBytes(Buffer.from(data, 'base64')) - for await (const block of reader.blocks()) { - blocks.push(block) - } - return Delegation.importDAG(blocks) -} ``` **Frontend** ```js -import * as Delegation from '@ucanto/core/delegation' +import * as Delegation from '@web3-storage/w3up-client/delegation' import * as Client from '@web3-storage/w3up-client' async function frontend() { diff --git a/src/pages/docs/concepts/car.md b/src/pages/docs/concepts/car.md index 064df71..5d2429a 100644 --- a/src/pages/docs/concepts/car.md +++ b/src/pages/docs/concepts/car.md @@ -98,14 +98,13 @@ The [`@ipld/car`](https://github.com/ipld/js-car) package contains the main Java Here's a simple example of loading a CAR file from a Node.js stream and storing it with web3.storage: ```js -import { createReadStream } from 'fs' -import { CarReader } from '@ipld/car' +import fs from 'node:fs' +import { Readable } from 'node:stream' async function storeCarFile(filename) { - const inStream = createReadStream(filename) - const car = await CarReader.fromIterable(inStream) + const stream = () => Readable.toWeb(fs.createReadStream(filename)) const client = makeStorageClient() - const cid = await client.uploadCAR(car) + const cid = await client.uploadCAR({ stream }) console.log('Stored CAR file! CID:', cid) } ``` @@ -114,7 +113,7 @@ CarReader.fromIterable accepts any iterable of Uint8Array data, including Node.j The CarReader type shown above will read the entire contents of the CAR into memory, which may cause issues with large files. On Node.js, you can use [CarIndexedReader](https://github.com/ipld/js-car#carindexedreader), which reads CAR data from disk directly and uses less memory than CarReader. -## [Advanced IPLD formats](https://web3.storage/docs/how-tos/work-with-car-files/#advanced-ipld-formats) +## Advanced IPLD formats IPLD can also be used as a general purpose data format like JSON. In fact, you can use JSON directly as IPLD just by using a special convention for linking to other IPLD objects. This convention is defined in the [dag-json](https://ipld.io/docs/codecs/known/dag-json/)["codec"](https://ipld.io/docs/codecs/known/dag-json/). @@ -124,7 +123,7 @@ Here's an example of a `dag-json` object: { "name": "Have you seen this dog?", "description": "I have now...", - "image":{"/":"bafybeihkqv2ukwgpgzkwsuz7whmvneztvxglkljbs3zosewgku2cfluvba"} + "image": { "/": "bafybeihkqv2ukwgpgzkwsuz7whmvneztvxglkljbs3zosewgku2cfluvba" } } ``` diff --git a/src/pages/docs/how-to/remove.mdx b/src/pages/docs/how-to/remove.mdx index 1a0faa3..010ad0e 100644 --- a/src/pages/docs/how-to/remove.mdx +++ b/src/pages/docs/how-to/remove.mdx @@ -54,5 +54,5 @@ To remove shard CIDs and upload CIDs separately, you'll generally do this by: - Client: `client.capability.upload.remove(contentCID)` - CLI: `w3 can upload rm ` 1. Remove each of the shards (ensure first that no other content is using that shard!): - - Client: `client.capability.store.remove(shardCID)` - - CLI: `w3 can store rm ` + - Client: `client.capability.blob.remove(shardMultihash)` + - CLI: `w3 can blob rm ` diff --git a/src/pages/docs/how-to/upload.mdx b/src/pages/docs/how-to/upload.mdx index ebbd595..7c230e1 100644 --- a/src/pages/docs/how-to/upload.mdx +++ b/src/pages/docs/how-to/upload.mdx @@ -131,19 +131,18 @@ w3 key create # If you want to limit permissions being passed to the Agent, you can specify # permissions to give, e.g., `--can space/blob/add --can space/index/add --can # filecoin/offer --can upload/add` limits to just being able to upload. -w3 delegation create | base64 +w3 delegation create --base64 # ❗️ Store the output in environment variable PROOF ``` -Then, when you initialize and configure the client, you can pass in this Agent and UCAN. +Then, when you initialize and configure the client, you can pass in this private key and UCAN delegation. ```javascript import * as Client from '@web3-storage/w3up-client' import { StoreMemory } from '@web3-storage/w3up-client/stores/memory' -import { importDAG } from '@ucanto/core/delegation' -import { CarReader } from '@ipld/car' -import * as Signer from '@ucanto/principal/ed25519' +import * as Proof from '@web3-storage/w3up-client/proof' +import { Signer } from '@web3-storage/w3up-client/principal/ed25519' async function main () { // Load client with specific private key @@ -151,28 +150,11 @@ async function main () { const store = new StoreMemory() const client = await Client.create({ principal, store }) // Add proof that this agent has been delegated capabilities on the space - const proof = await parseProof(process.env.PROOF) + const proof = await Proof.parse(process.env.PROOF) const space = await client.addSpace(proof) await client.setCurrentSpace(space.did()) // READY to go! } - -/** @param {string} data Base64 encoded CAR file */ -async function parseProof (data) { - const blocks = [] - const reader = await CarReader.fromBytes(Buffer.from(data, 'base64')) - for await (const block of reader.blocks()) { - blocks.push(block) - } - return importDAG(blocks) -} -``` - -If you're doing this in a non-persistent or serverless backend, you might consider using an in-memory [Store](https://github.com/web3-storage/w3up/tree/main/packages/access-client) for your Agent information rather than the default on-disk: - -```javascript -import { StoreMemory } from '@web3-storage/access/stores/store-memory' -const client = await Client.create({ principal, store: new StoreMemory() }) ``` ### Uploading to web3.storage @@ -226,12 +208,11 @@ Your backend instance can also be used to delegate upload permissions directly t **Backend** ```js -import { CarReader } from '@ipld/car' -import * as DID from '@ipld/dag-ucan/did' -import * as Delegation from '@ucanto/core/delegation' -import * as Signer from '@ucanto/principal/ed25519' import * as Client from '@web3-storage/w3up-client' import { StoreMemory } from '@web3-storage/w3up-client/stores/memory' +import * as Proof from '@web3-storage/w3up-client/proof' +import { Signer } from '@web3-storage/w3up-client/principal/ed25519' +import * as DID from '@ipld/dag-ucan/did' async function backend(did) { // Load client with specific private key @@ -240,7 +221,7 @@ async function backend(did) { const client = await Client.create({ principal, store }) // Add proof that this agent has been delegated capabilities on the space - const proof = await parseProof(process.env.PROOF) + const proof = await Proof.parse(process.env.PROOF) const space = await client.addSpace(proof) await client.setCurrentSpace(space.did()) @@ -254,22 +235,12 @@ async function backend(did) { const archive = await delegation.archive() return archive.ok } - -/** @param {string} data Base64 encoded CAR file */ -async function parseProof(data) { - const blocks = [] - const reader = await CarReader.fromBytes(Buffer.from(data, 'base64')) - for await (const block of reader.blocks()) { - blocks.push(block) - } - return Delegation.importDAG(blocks) -} ``` **Frontend** ```js -import * as Delegation from '@ucanto/core/delegation' +import * as Delegation from '@web3-storage/w3up-client/delegation' import * as Client from '@web3-storage/w3up-client' async function frontend() {