Web3Auth / mpc-core-kit

15 stars 4 forks source link

[v3] importTssKey JWTLoginParams issue #158

Closed AyushBherwani1998 closed 3 weeks ago

AyushBherwani1998 commented 4 weeks ago

Description

loginWithJWT throws error for both key types when passing private key as importTssKey in JWTLoginParams.

Ed25519 KeyType Error

{
"name": "CoreKitError",
"code": 1000,
"message": "undefined Invalid seed for ed25519 key derivation"
}

Console

Error: Invalid seed for ed25519 key derivation
    at getEd25519ExtendedPublicKey (torusUtils.esm.js:449:1)
    at tss.esm.js:462:1
    at TKeyTSS.importTssKey (tss.esm.js:471:1)
    at Web3AuthMPCCoreKit.importTssKey (mpcCoreKit.esm.js:1573:1)
    at mpcCoreKit.esm.js:1632:1
    at async Web3AuthMPCCoreKit.atomicSync (mpcCoreKit.esm.js:1561:1)
    at async Web3AuthMPCCoreKit.handleNewUser (mpcCoreKit.esm.js:1606:1)
    at async Web3AuthMPCCoreKit.setupTkey (mpcCoreKit.esm.js:1595:1)
    at async Web3AuthMPCCoreKit.loginWithJWT (mpcCoreKit.esm.js:1174:1)
    at async login (App.tsx:103:1)

SEC1 KeyType Error

{
"name": "CoreKitError",
"code": 1000,
"message": "undefined Invalid importedKey"
}

Console

Error: Invalid importedKey
    at TKeyTSS.importTssKey (tss.esm.js:473:15)
    at async Web3AuthMPCCoreKit.importTssKey (mpcCoreKit.esm.js:1573:5)
    at async mpcCoreKit.esm.js:1632:9
    at async Web3AuthMPCCoreKit.atomicSync (mpcCoreKit.esm.js:1561:17)
    at async Web3AuthMPCCoreKit.handleNewUser (mpcCoreKit.esm.js:1606:5)
    at async Web3AuthMPCCoreKit.setupTkey (mpcCoreKit.esm.js:1595:7)
    at async Web3AuthMPCCoreKit.loginWithJWT (mpcCoreKit.esm.js:1174:7)
    at async Proxy.login (Home.vue:139:9)

Reproducible steps

ed25519 Sample: https://github.com/Web3Auth/web3auth-core-kit-examples/tree/importTssKey-issue/mpc-core-kit-web/mpc-core-kit-solana

secp256k1 Sample: https://github.com/Web3Auth/web3auth-core-kit-examples/tree/importTssKey-issue/mpc-core-kit-web/quick-starts/mpc-core-kit-vue-quick-start

metalurgical commented 3 weeks ago

In the example you're using you have the following values:

secp256k1 ->
importTssKey: "0xc07e62798875a08deda085ca8eb4ccbcafe00a9ab7697cb3a4f4c4aa833364cc",

ed25519 ->
importTssKey: "5P7PPFbB3AYoXZE32GXXyx7LkkoWv3H9KruiHnteba4uCjZ4FWCVNJJxDcRp7TNwhBK93RYJahWUftteGCaZJbTc"

These are invalid and the returned errors are correct.

The key is being converted from a plain hex string (no prefix):

   const tssKeyBN = new BN(tssKey, "hex");

Please try again with the following: 1) Generate an secp256k1 private key and serialize the BN to hex, little endian. 2) Generate an ed25519 seed and serialize to hex, big endian.

AyushBherwani1998 commented 3 weeks ago

Okay, I'll try by removing the 0x prefix in the sec1 key, and for ed25519 I think the naming convention is confusing because importTssKey expects the ed25519 seed instead of private key.