Coder Social home page Coder Social logo

Comments (8)

ryanio avatar ryanio commented on June 6, 2024

@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.

from ethereumjs-util.

shrpne avatar shrpne commented on June 6, 2024

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.

from ethereumjs-util.

holgerd77 avatar holgerd77 commented on June 6, 2024

@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.

from ethereumjs-util.

shrpne avatar shrpne commented on June 6, 2024

Thank you for clarification

Looks like it is an issue with jest-environment-jsdom@26, which is a part of the latest jest
jestjs/jest#7780 (comment)

from ethereumjs-util.

holgerd77 avatar holgerd77 commented on June 6, 2024

Ok, will close here.

from ethereumjs-util.

kumavis avatar kumavis commented on June 6, 2024

@holgerd77 could this be Buffer.isBuffer(buf) instead of an instanceof check, for duck typing?

from ethereumjs-util.

kumavis avatar kumavis commented on June 6, 2024

i worked around this by adding jest-environment-jsdom@25 as a dev dep

from ethereumjs-util.

holgerd77 avatar holgerd77 commented on June 6, 2024

@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).

from ethereumjs-util.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.