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

Upload Delegation - Error: stored principal and passed principal must match #1274

Closed
rinaldorossiavvale opened this issue Jan 22, 2024 · 13 comments
Assignees

Comments

@rinaldorossiavvale
Copy link

We are currently in the process of migrating our code to new version.

Our current focus is on uploading files through delegation. Here are the steps we've taken in the console:

  • Log in with the command: w3 login [my-mail]
  • Specify the space using: w3 space use did:key:z6Mkf6GqWzVJQVdX5d4S4skrRetFRXPM2YwTarvn7fg2NLZH
  • Generate a key with: npx ucan-key ed
  • Create a delegation with: w3 delegation create did:key:z6MkjDpk6K6B4Bec2b2M98SESAVz4iquVyfXVSpARSw4LKT1

During the client creation on React:

const principal = Signer.parse(process.env.REACT_WEB3_STORAGE_KEY)
const client = await Client.create({ principal })

we have an error in console:

Uncaught (in promise) Error: store cannot be used with did:key:z6MkjDpk6K6B4Bec2b2M98SESAVz4iquVyfXVSpARSw4LKT1, stored principal and passed principal must match

@alanshaw
Copy link
Member

Try using the in-memory store:

import * as Client from '@web3-storage/w3up-client'
import { StoreMemory } from '@web3-storage/w3up-client/stores'

const principal = Signer.parse("...")
const store = new StoreMemory()
const client = await Client.create({ principal, store })

@rinaldorossiavvale
Copy link
Author

Try using the in-memory store:

import * as Client from '@web3-storage/w3up-client'
import { StoreMemory } from '@web3-storage/w3up-client/stores'

const principal = Signer.parse("...")
const store = new StoreMemory()
const client = await Client.create({ principal, store })

Thank you, now I'm able to create the client

Please fix you code block changing the import with this:

import { StoreMemory } from '@web3-storage/access/stores/store-memory'

now in parseProof function:

/** @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)
}

during reader creation I have this error in console:
Uncaught (in promise) Error: Unexpected CID version (28)

Can you please help me? I can't figure out the problem.

@magror
Copy link

magror commented Jan 23, 2024

@rinaldorossiavvale I didn't have this exact problem but I had a problem with creating the Reader from proof at async decodeReaderComplete. I think my problem was caused because the @web3-storage/w3up-cli package on NPM is over a year out of date (3.0.1) and potentially generated invalid proof data. You might want to try what I did: download the @web3-storage/w3up-cli package straight from GitHub and execute the key/proof creation commands again with the GitHub version (7.2.1). Good luck!

@magror
Copy link

magror commented Jan 23, 2024

@rinaldorossiavvale Also, the code block
import { StoreMemory } from '@web3-storage/w3up-client/stores'
IS correct. You might have an outdated version of @web3-storage/w3up-client if that import didn't work for you.

@magror
Copy link

magror commented Jan 23, 2024

@rinaldorossiavvale Finally, I just realized that it looks like you are passing did:key:z6MkjDpk6K6B4Bec2b2M98SESAVz4iquVyfXVSpARSw4LKT1
as your principal. That value is not a principal key; it is a DID.

When you generate a Key/DID pair, use npx ucan-key ed --json (or w3 key create). You get BOTH a KEY and a DID. You use the Key value for PRINCIPAL, and you give the DID to the w3 delegation create <did_from_ucan-key_command_above> --can 'store/*' --can 'upload/*' | base64 command, which generates the PROOF.

@rinaldorossiavvale
Copy link
Author

import { StoreMemory } from '@web3-storage/w3up-client/stores'

@magror I'm already passing the key as principal and I created the proof starting from the did.
I'm not putting the did as principal

@rinaldorossiavvale
Copy link
Author

import { StoreMemory } from '@web3-storage/w3up-client/stores'

@magror upgrading to 12.1.0 throw me an error in console

UnhandledSchemeError: Reading from "node:util" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default

@alanshaw alanshaw self-assigned this Jan 24, 2024
alanshaw pushed a commit that referenced this issue Jan 24, 2024
`stores.js` was importing code that uses nodejs modules and is not
bundleable....

refs
#1274 (comment)
@alanshaw
Copy link
Member

@rinaldorossiavvale v12.2.1 should fix this, use import:

import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'

@rinaldorossiavvale
Copy link
Author

rinaldorossiavvale commented Jan 25, 2024

import { StoreMemory } from '@web3-storage/w3up-client/stores/memory'

@alanshaw upgraded to v12.2.1 but on reader creation it throw:

decoder.js:62 Uncaught (in promise) Error: Unexpected CID version (28) at readCid (decoder.js:62:1) at async readBlockHead (decoder.js:76:1) at async readBlock (decoder.js:85:28) at async Object.blocks (decoder.js:113:1) at async decodeReaderComplete (reader-browser.js:53:1)

@magror
Copy link

magror commented Jan 25, 2024

@rinaldorossiavvale I didn't have this exact problem but I had a problem with creating the Reader from proof at async decodeReaderComplete. I think my problem was caused because the @web3-storage/w3up-cli package on NPM is over a year out of date (3.0.1) and potentially generated invalid proof data. You might want to try what I did: download the @web3-storage/w3up-cli package straight from GitHub and execute the key/proof creation commands again with the GitHub version (7.2.1). Good luck!

@rinaldorossiavvale Have you downloaded the new version of the CLI from GitHub and generated a brand new set of key/proof?

@rinaldorossiavvale
Copy link
Author

@rinaldorossiavvale I didn't have this exact problem but I had a problem with creating the Reader from proof at async decodeReaderComplete. I think my problem was caused because the @web3-storage/w3up-cli package on NPM is over a year out of date (3.0.1) and potentially generated invalid proof data. You might want to try what I did: download the @web3-storage/w3up-cli package straight from GitHub and execute the key/proof creation commands again with the GitHub version (7.2.1). Good luck!

@rinaldorossiavvale Have you downloaded the new version of the CLI from GitHub and generated a brand new set of key/proof?

@magror

  • uninstalled the cli: npm uninstall -g @web3-storage/w3cli
  • installed again: npm install -g @web3-storage/w3cli
  • re-generate key/proof

and now I have:
Uncaught (in promise) Error: Unexpected CID version (11776) at readCid (decoder.js:62:1) at async readBlockHead (decoder.js:76:1) at async readBlock (decoder.js:85:28) at async Object.blocks (decoder.js:113:1) at async decodeReaderComplete (reader-browser.js:53:1)

@magror
Copy link

magror commented Jan 25, 2024

@rinaldorossiavvale Do not use the version on NPM. It is out of date. I am recommending you go to GitHub and clone the CLI project directly from GitHub. GitHub has version 7.5.0, whereas NPM only has version 3.0.1

  • go to https://github.com/web3-storage/w3cli
  • clone the repo using the link found in the green "code" button" ( create a new folder for the repo clone, cd into it in your command line, then command: git clone https://github.com/web3-storage/w3cli.git) notice the .git on the end of the url
  • once you have cloned the GitHub repo, cd into the downloaded w3cli folder and do npm install to install all the node_modules folder and everything
  • Then you can do npm exec w3 login <email> to start regenerating your key/proof combo

@rinaldorossiavvale
Copy link
Author

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

@magror done but always the same error.

Uncaught (in promise) Error: Unexpected CID version (11776) at readCid (decoder.js:62:1) at async readBlockHead (decoder.js:76:1) at async readBlock (decoder.js:85:28) at async Object.blocks (decoder.js:113:1) at async decodeReaderComplete (reader-browser.js:53:1)

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

No branches or pull requests

3 participants