Skip to content

NodeJs script to w3s delegated upload#387

Closed
red-0ne wants to merge 1 commit into
mainfrom
w3-delegated-upload
Closed

NodeJs script to w3s delegated upload#387
red-0ne wants to merge 1 commit into
mainfrom
w3-delegated-upload

Conversation

@red-0ne
Copy link
Copy Markdown
Contributor

@red-0ne red-0ne commented Jan 24, 2023

NodeJs script that uploads a file to w3.storage given a delegation proof. It takes the following arguments

--path Path to the file to upload.
--secret ed25519 base64 encoded private key.
--delegation base64 encoded proof coming from client.

It outputs CID of the uploaded file to stdout.

Note: It uses some ES modules that prevented packaging by pkg.

From cmd/, install direct dependencies:

npm i @ipld/car @noble/ed25519 @ucanto/principal @web3-storage/access @web3-storage/w3up-client command-line-args

Test

We create the user and setup a delegation proof that will be used by our script.

$ npm i -g @web3-storage/cli

$ w3 whoami
did:key:z6MkvCoHWj1VViZLqVpT5fcec8NNGjmiX4KkGjuonUxF22E2

$ w3 space create test
did:key:z6MktgQ4fG9cEM7UcwNMHnEBtkVWbd6ABKDXwU1J2ZouZhvp

$ w3 space register email@address #should receive an activation link, this resolved after requesting the link

$ w3 delegation create did:key:z6MkkwKy2C9sCgoWcCGgxVCCt1qFyLJzwkoWi9BF3zi5s5jw | base64 -w 0 # LivePeer's DID key
EaJlcm9vdHOAZ3ZlcnNpb24BmgIBcRIguVaNefyQMACKNgi3XA46t5ijCH19S/ndLpkGhZ0kWiOnYXNYRO2hA0CVYBCNOU9IW+u+IUqhZ9gSHPzFMB7tzLYBE0tjOUrg11K3p3bC31kprHJ769ISMQSJDMRvWCGamwks2rsWJA4GYXZlMC45LjFjYXR0gaJjY2FuYSpkd2l0aHg4ZGlkOmtleTp6Nk1rdGdRNGZHOWNFTTdVY3dOTUhuRUJ0a1ZXYmQ2QUJLRFh3VTFKMlpvdVpodnBjYXVkWCLtAeoGmhaC2aAQPNKXr4AK7MOo8OR/9RkLNIZ6/SgZUq2/Y2V4cPZjaXNzWCLtAdNhO+TS5YOYwp4wQuxsFq9Hi2uBoldfmfxUxf3HW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TKKhhc1hE7aEDQJqxaum4RfYm8EF9W2G2SSoI6rI58lC6buIUoSZaThMs0JA3blC7PPrTgL06AqWOaaAnQKN4b9TuBezi3llLnQhhdmUwLjkuMWNhdHSBomNjYW5hKmR3aXRoeDhkaWQ6a2V5Ono2TWt0Z1E0Zkc5Y0VNN1Vjd05NSG5FQnRrVldiZDZBQktEWHdVMUoyWm91Wmh2cGNhdWRYIu0BYFbRZFVNOcB+ZhrKuhujUFU3l9oaQa68+YMRNtYtqDpjZXhw9mNmY3SBoWVzcGFjZaJkbmFtZWR0ZXN0bGlzUmVnaXN0ZXJlZPVjaXNzWCLtAeoGmhaC2aAQPNKXr4AK7MOo8OR/9RkLNIZ6/SgZUq2/Y3ByZoHYKlglAAFxEiC5Vo15/JAwAIo2CLdcDjq3mKMIfX1L+d0umQaFnSRaIw==

ipfs://bafkreiako44adlxayv4fxsew7bwg6qs7cxzds7x3snw6quqj2sui4iicze/

Closes livepeer/catalyst#365

@red-0ne red-0ne marked this pull request as draft January 24, 2023 03:54
@red-0ne red-0ne requested a review from leszko January 24, 2023 03:54
@red-0ne red-0ne force-pushed the w3-delegated-upload branch from f7ddad0 to 11b5735 Compare January 24, 2023 03:57
@red-0ne red-0ne force-pushed the w3-delegated-upload branch from 11b5735 to 697b53c Compare January 24, 2023 04:12
@leszko
Copy link
Copy Markdown
Contributor

leszko commented Jan 24, 2023

Thanks for the PR @red-0ne .

I skimmed through and it looks nice. I think it'll be the way to go to use this script instead of the w3 CLI binary, mainly because of multi-tenancy and the fact that we're better off keeping credentials in memory.

Saying that, let's park it (and keep as draft) until I complete the work on the w3s driver (livepeer/catalyst#375). It should take no more than a few days. After that, we'll come back to your PR and fill the script with all the commands we need, plus do a the actual code review.

@leszko leszko closed this Feb 14, 2023
iameli pushed a commit that referenced this pull request Feb 21, 2023
Files changed:
M	manifest.yaml

Co-authored-by: livepeer-docker <livepeer-docker@users.noreply.github.com>
@hjpotter92 hjpotter92 deleted the w3-delegated-upload branch May 30, 2023 07:24
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.

Spike using credentials in w3 client

2 participants