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

hashToPrivateScalar Error: hex string is invalid: unpadded 63 #35

Closed
0xc0de4c0ffee opened this issue Apr 23, 2023 · 2 comments
Closed

Comments

@0xc0de4c0ffee
Copy link

        let caip10 = `eip155:1:${App.ADDR}`
        let domain = "domain.eth"
        let msg = `Generate Deterministic IPNS Keys for '${domain}'\n\nSigned By: ${caip10}`;
        let sig = await App.SIGNER.signMessage(msg);
        let password = "pass12#$"
        let inputKey = sha256(
            hexToBytes(
                sig.toLowerCase().startsWith('0x') ? sig.slice(2) : sig
            ) 
        )
        let info = `${caip10}:${domain}`
        let salt = sha256(`${info}:${password ? password : ''}:${sig.slice(-64)}`)
        let hashKey = hkdf(sha256, inputKey, salt, info, 42)
        let privKey = hashToPrivateScalar(hashKey, ed25519.CURVE.n).toString(16)
        let pubKey = await ed25519.getPublicKey(privKey)

utils.js:86 Uncaught (in promise) Error: private key must be valid hex string, got "d06c76f87d42fe0e683b454318543ba25463b34a4c17594f32c05a3051ae608". Cause: Error: hex string is invalid: unpadded 63

@paulmillr
Copy link
Owner

The error is pretty clear: you need padded hex. d06 bad, 0d06 good.

@0xc0de4c0ffee
Copy link
Author

The error is pretty clear: you need padded hex. d06 bad, 0d06 good.

I've used let privateKey = hashToPrivateScalar(hashKey, ed25519.CURVE.n).toString(16).padStart(64, "0").
it's always 63 char long so privkey always starts with "0x0...".

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

2 participants