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

instanceof Uint8Array returning false #175

Open
bitsanity opened this issue Feb 27, 2021 · 4 comments
Open

instanceof Uint8Array returning false #175

bitsanity opened this issue Feb 27, 2021 · 4 comments

Comments

@bitsanity
Copy link

Using secp256k1 npm module within nwjs-sdk-v0.51.2-linux-x64

let sigbytes = [an ECDSA signature in DER format, 71 bytes]
let dersig = Uint8Array.from( sigbytes );
let sigobj = SECP256K1.signatureImport( dersig );

Result

Error: Expected signature to be an Uint8Array", source: [...]/node_modules/secp256k1/lib/index.js (18)

Origin of the Error

function isUint8Array (name, value, length) {
  assert(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`)

Root Cause

The instanceof operator returns false. The typeof operator returns object, so javascript is seeing value as an object not as a Uint8Array.

Workaround/Fix

function isUint8Array (name, value, length) {
  assert(value instanceof Uint8Array || value.constructor.name === 'Uint8Array', `Expected ${name} to be an Uint8Array`)

@fanatid
Copy link
Member

fanatid commented Feb 27, 2021

I do not understand, instanceof does not work in nwjs?

@bitsanity bitsanity reopened this Feb 27, 2021
@bitsanity
Copy link
Author

Oops accidentally hit close. fanatid - yes correct for some reason the instanceof operator is failing for Uint8Array - sees as object for some reason.

@bitsanity
Copy link
Author

The workaround/fix works for me. I get the signature imported ok.

@goncer
Copy link

goncer commented Nov 3, 2021

I am having this error,
why not use the node implementation?

const isuint8 = require('util').types.isUint8Array;
in:

    privateKeyVerify (seckey) {
      isUint8Array('private key', seckey, 32)

      return secp256k1.privateKeyVerify(seckey) === 0
    },

I tested for a Buffer in the console, and it works,

isuint8(value)
>true
value instanceof Uint8Array
>false
value
>Buffer(32) [86, 56, 62, 77, 229, 4, 46, 49, 85, 225, 47, 117, 104, 122, 39, 225, 167, 132, 235, 238, 234, 100, 41, 84, 208, >162, 176, 13, 122, 151, 47, 92]

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

Successfully merging a pull request may close this issue.

3 participants