cryptocoinjs / hdkey

JavaScript component for Bitcoin hierarchical deterministic keys (BIP32)
MIT License
201 stars 74 forks source link

Fix HDKey.sign method arguments types #50

Closed DDushkin closed 2 years ago

DDushkin commented 2 years ago

secp256k1.ecdsaSign() expects Uint8Arrays as arguments instead of Buffers

RyanZim commented 2 years ago

Buffer is a subclass of Uint8Array, so buffer instanceof Uint8Array === true. There's no point in casting it here.

DDushkin commented 2 years ago

Buffer is a subclass of Uint8Array, so buffer instanceof Uint8Array === true. There's no point in casting it here.

Yeah, I understand but I introduced this because I got such error on hdkey.sign() [Error: Expected private key to be an Uint8Array] And it also mimics the hdkey.verify() method, which already contains Uint8Array.from() https://github.com/cryptocoinjs/hdkey/blob/be098e483a1a4e2509f1e3e0619d2aaca7e28669/lib/hdkey.js#L163

junderw commented 2 years ago

Some front ends have Buffer polyfills that are not subclass of Uint8Array

DDushkin commented 2 years ago

Some front ends have Buffer polyfills that are not subclass of Uint8Array

I'm on React Native, using rn-nodeify and shim like this

if (typeof Buffer === "undefined") global.Buffer = require("buffer").Buffer;
RyanZim commented 2 years ago

Some front ends have Buffer polyfills that are not subclass of Uint8Array

Was not aware of this; in that case, not opposed to the change; @junderw feel free to merge