Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Last active June 25, 2024 10:46
Show Gist options
  • Save alanshaw/e949abfcf6728f590ac9fa083dba5648 to your computer and use it in GitHub Desktop.
Save alanshaw/e949abfcf6728f590ac9fa083dba5648 to your computer and use it in GitHub Desktop.
How do you use w3up on the server/in CI where there's no persistent filesystem?

On your local computer:

  1. Create a keypair for the server

    npx ucan-key ed --json

    Note down did and key values!

  2. Install the w3cli:

    npm i -g @web3-storage/w3cli
  3. Authorize your agent to use spaces owned by your email address:

    w3 authorize you@email.com
  4. Create a space for where the uploads will be registered:

    w3 space create myspacename
    w3 space register
  5. Delegate from your local machine to the server:

    w3 delegation create <did_from_ucan-key_command_above> --can 'store/add' --can 'upload/add' | base64

On the server:

  1. Set up environment variables KEY with the output of key from step 1 and PROOF with the output of step 4.

  2. In the script, load the agent with the server private key and add the proof of delegation:

    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'
    
    async function main () {
      // Load client with specific private key
      const principal = Signer.parse(process.env.KEY)
      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 Proof.parse(process.env.PROOF)
      const space = await client.addSpace(proof)
      await client.setCurrentSpace(space.did())
      // READY to go!
    }
@alanshaw
Copy link
Author

Yes the CLI automatically “uses” the created space for you so it’s not necessary to w3 space use did…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment