"Invalid Encoding"
See original GitHub issueThis function
const decryptedMessege = decryptSafely({ encryptedData: {ciphertext: validator.data, version:"x25519-xsalsa20-poly1305", ephemPublicKey:validator.publicKey, nonce:"XUYgP2Bgtr4CPZVxTCPzKdSaTyMV7JzUkH7a5msSXxs="}, privateKey: validator.privateKey })
Leads to an “invalid encoding” error. I tracked it down to this piece of code:
function validateBase64(s) { if (!(/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(s))) { throw new TypeError('invalid encoding'); } }
And this appears to happen when s=validator.pubilcKey. That is to say, MetaMask public keys such as my own “0x3b89aC05D2d53f3775697B5Dbc75d8852E740403” is not valid according to the regex. If I remove the “0x” at the start it works but I instead get “bad public key size” error instead. So I don’t know what to do here.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (1 by maintainers)
According to the documentation for
nacl.box.open
, it will returnnull
if authentication fails: https://github.com/dchest/tweetnacl-js#naclboxopenbox-nonce-theirpublickey-mysecretkey. So something must be wrong with either the public key or private key.Closing as it doesn’t appear that this is due to a bug. Feel free to continue asking for help in this thread and we’ll help if we get time.