-
Create a keypair for the server
npx ucan-key ed --json
Note down
did
andkey
values! -
Install the w3cli:
npm i -g @web3-storage/w3cli
-
Authorize your agent to use spaces owned by your email address:
w3 authorize you@email.com
-
Create a space for where the uploads will be registered:
w3 space create myspacename w3 space register
-
Delegate from your local machine to the server:
w3 delegation create <did_from_ucan-key_command_above> --can 'store/add' --can 'upload/add' | base64
-
Set up environment variables
KEY
with the output ofkey
from step 1 andPROOF
with the output of step 4. -
In the script, load the agent with the server private key and add the proof of delegation:
import * as Signer from '@ucanto/principal/ed25519' import { importDAG } from '@ucanto/core/delegation' import { CarReader } from '@ipld/car' import * as Client from '@web3-storage/w3up-client' async function main () { // Load client with specific private key const principal = Signer.parse(process.env.KEY) const client = await Client.create({ principal }) // Add proof that this agent has been delegated capabilities on the space const proof = await parseProof(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) }
web3-storage/w3up-client#74 should make this a little better. ✅ done