Closed shrpne closed 4 years ago
@shrpne do you have a script or repo to reproduce? using your code snippet works for me and I don't run into the error, it returns the publicKey fine for me.
You can try it on my project. Try to run this test directly https://github.com/MinterTeam/minterjs-util/blob/ethereum-7/test/public.test.js#L13 or run npm run jest
If it is not suitable, then I can try to make a minimal test case later.
But I still don't understand, how such code can run without problems:
const privateToPublic = function(privateKey: Buffer): Buffer {
assertIsBuffer(privateKey)
publicKeyCreate(privateKey, false)
}
function publicKeyCreate (seckey, compressed = true, output) {
isUint8Array('private key', seckey, 32)
/* ... */
},
Because privateKey
can't be a Buffer
and a Uint8Array
at the same time.
@shrpne a Node.js Buffer
is a special type of Uint8Array
and actually inherits from the Uint8Array
class, see e.g. this explanation.
You can test this e.g. with the following code snippet in ts-node
:
> let t = Buffer.alloc(0)
undefined
> t
<Buffer >
> Buffer.isBuffer(t)
true
> t instanceof Uint8Array
true
This is also the code executed in the assertions from the function calls in your example above.
Thank you for clarification
Looks like it is an issue with jest-environment-jsdom@26
, which is a part of the latest jest
https://github.com/facebook/jest/issues/7780#issuecomment-669828353
Ok, will close here.
@holgerd77 could this be Buffer.isBuffer(buf)
instead of an instanceof
check, for duck typing?
i worked around this by adding jest-environment-jsdom@25
as a dev dep
@kumavis did a bit of a first read on duck typing - e.g. https://realpython.com/lessons/duck-typing/ - but have no great experience with the concept. Please just open a new issue if you think this is worth a change to make (everyone else of course as well).
With such code:
I've got an error
privateToPublic want
Buffer
argument. And it uses publicKeyCreate which wantsUint8Array
. So I can't use eitherBuffer
orUint8Array
My setup macOS - 10.15.6 Node - 12.16.1 ethereumjs-util - 7.0.3 secp256k1 - 4.0.2
BTW I tried to clone
ethereumjs-util
and run its test and everything work fine, I don't understand why.