Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: import space from base64 string #122

Closed
wants to merge 2 commits into from
Closed

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Nov 11, 2023

tweak w3cli to make it easier to use in CI where you want to provide state via env vars... aka what if this flow could all be done from w3cli https://gist.github.com/alanshaw/e949abfcf6728f590ac9fa083dba5648

tl;dr what if instead of custom code, the server side of this dance looked like

$ W3_PRINCIPAL=<ure key here>
$ SPACE_PROOF=<base64 proof string>
$ w3cli space add --base64 $SPACE_PROOF
$ w3cli up ./your/files/here

by setting W3_PRINCIPAL you w3cli in ci will use the key you generated, and the new w3cli space add --base64 <proof string> flag lets you import and use a space proof from a string.


Serving suggestion:

on your local machine

  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 [email protected]
  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

in CI or ephemeral server

  1. Set up environment variables W3_PRINCIPAL with the output of key from step 1 and SPACE_PROOF_BASE64 with the output of step 5 above.
  2. Install w3cli in your CI workflow, import the space from SPACE_PROOF_BASE64 and upload your files
    w3 space add --base64 $SPACE_PROOF_BASE64 
    w3 up <./path to your file> 

DONE!

License: MIT

tweak w3cli to make it easier to use in CI where you want to provide state via env vars... aka what if this flow could all be done from w3cli https://gist.github.com/alanshaw/e949abfcf6728f590ac9fa083dba5648

Service suggestion:

1. Create a keypair for the server

    ```sh
    npx ucan-key ed --json
    ```

    Note down `did` and `key` values!

1. Install the w3cli:

    ```sh
    npm i -g @web3-storage/w3cli
    ```

1. Authorize your agent to use spaces owned by your email address:

    ```sh
    w3 authorize [email protected]
    ```

1. Create a space for where the uploads will be registered:

    ```sh
    w3 space create myspacename
    w3 space register
    ```

1. Delegate from your local machine to the server:

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

1. Set up environment variables `W3_PRINCIPAL` with the output of `key` from step 1 and `SPACE_PROOF_BASE64` with the output of step 4.
1. Install w3cli in your CI workflow, import the space from `SPACE_PROOF_BASE64` and upload your files
   ```sh
   w3cli space add --base64 $SPACE_PROOF_BASE64
   w3cli up <./path to your file>
   ```
DONE!

by setting `W3_PRINCIPAL` you w3cli in ci will use the key you generated, and the new w3cli space add --base64 <proof string> flag lets you import and use a space proof from a string.

License: MIT
Signed-off-by: Oli Evans <[email protected]>
? await proofFromString(opts.base64)
: await proofFromPath(proofPath)
const space = await client.addSpace(proof)
await client.setCurrentSpace(space.did())
Copy link
Contributor Author

@olizilla olizilla Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon space add should set the current space. It was annoying to have to do that manually after calling space add. This is what space create does, so this would be consistent.

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@@ -121,7 +121,8 @@ cli
.action(registerSpace)

cli
.command('space add <proof>')
.command('space add [proof]')
.option('--base64', 'provide proof as base64 encoded string')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be helpful for noobs to know more about what is expected as the bytes that are base64d. iirc the idea is we accept any UCAN serialization? but esp car files?
(e.g. do you want base64(cidOfProofCar) or base64(proofCarWithDagUcanCbor)) ?

@olizilla
Copy link
Contributor Author

Superceeded by #158

@olizilla olizilla closed this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants