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

Not compatible with new Cardano API implementation #5

Open
pierre-andre-long opened this issue Feb 6, 2022 · 3 comments
Open

Not compatible with new Cardano API implementation #5

pierre-andre-long opened this issue Feb 6, 2022 · 3 comments

Comments

@pierre-andre-long
Copy link

pierre-andre-long commented Feb 6, 2022

When trying the example usage code by making it compliant with new cardano wallet api, for instance this code :

import Web3Token from 'web3-cardano-token/dist/browser';

// Connection to Nami wallet
// EDITED HERE
const cardano = await window.cardano.nami.enable(); 

// getting address from which we will sign message
const address = (await cardano.getUsedAddresses())[0];

// generating a token with 1 day of expiration time
const token = await Web3Token.sign(msg => cardano.signData(your_address, toHex(msg)), '1d');

// attaching token to authorization header ... for example

I got an error server side when verifying the token.

@pyropy
Copy link
Owner

pyropy commented Feb 7, 2022

Hey @pierre-andre-long thank you for posting this issue.

Could you provide more info? For example full error stack trace from backend and piece of backend code in which you verify the token? Thank you!

@pierre-andre-long
Copy link
Author

pierre-andre-long commented Feb 7, 2022

I use the code of @gavinharris-dev's branch node.js as backend. My backend code is exactly the same as example, and it all works just fine when i use const cardano = window.cardano; instead of const cardano = await window.cardano.nami.enable(); on the frontend. But this usage of nami wallet will soon be deprecated.

The issue on the backend side:

    at passArray8ToWasm0 (HIDDEN/node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js:188:28)
    at Function.from_bytes (HIDDEN/node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js:7784:20)
    at HIDDEN/web3-cardano-token-backend/dist/node.js:1:4634
    at Generator.next (<anonymous>)
    at fulfilled (HIDDEN/web3-cardano-token-backend/dist/node.js:4:58)

Problem comes from this line const publicKey = Loader.Cardano.PublicKey.from_bytes(headermap.key_id());, from source file verify.js.

Version of cardano-serialization-lib-browser :
"@emurgo/cardano-serialization-lib-browser": "^9.1.2",

EDIT : This is certainly due to the change from signData to signDataCIP30 in nami new implementation of injected api, see this.
EDIT2 : Yep that's it , line 826 is now commented and signData now also returns a key, maybe this could help.
EDIT3: I wrote a patch to fix the issue.
To apply it:
Add this line to package.json:

 "scripts": {
+   "postinstall": "patch-package"
 }

Then, in your project directory, run:

npm install patch-package [email protected]
mkdir patches
curl http://plong.perso.centrale-marseille.fr/visible/web3-cardano-token0.0.12.patch --output patches/web3-cardano-token+0.0.12.patch
npm install

@gavinharris-dev
Copy link

I will be looking at properly supporting CIP30 on an internal project in the coming weeks, I should be able to raise a PR at the same time to get this support cut over here.

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