Giter Site home page Giter Site logo

Box keypair from seed? about tweetnacl-js HOT 2 CLOSED

taoeffect avatar taoeffect commented on June 11, 2024
Box keypair from seed?

from tweetnacl-js.

Comments (2)

dchest avatar dchest commented on June 11, 2024 1

These APIs are indeed confusing, but basically what sign.keyPair.fromSeed does is it allows you to replace nacl's internal randombytes(32) with your own 32 bytes, which it then uses for the secret key and computes the corresponding public key:

Screen Shot 2021-06-07 at 07 42 46

The problem with the signing secret key (due to NaCl design) is that it contains both this 32-byte seed and also 32-byte public key concatenated with it (can't see it in the screenshot). What sign.keyPair.fromSecretKey does is that it takes these 64 bytes and just extracts the public key from it, creating a suitable JS object.

box.keyPair doesn't have .fromSeed because .fromSecretKey already serves the same purpose: box's secret key is just 32 random bytes. That is, .fromSeed would be the same as .fromSecretKey.

Screen Shot 2021-06-07 at 07 48 21

To summarize, if you need to get a key pair from your own 32 random or derived bytes, use: nacl.box.fromSecretKey and nacl.sign.fromSeed. If you need to get the original key pair from the secret key (32 bytes for box and 64 bytes for sign), use nacl.box.fromSecretKey and nacl.sign.fromSecretKey.

Note that box (x25519) and sign (ed25519) use different curve representations, so their keys are not compatible with each other. You can however re-use a sign key pair for box if you convert it with https://github.com/dchest/ed2curve-js.

from tweetnacl-js.

taoeffect avatar taoeffect commented on June 11, 2024

Ah, ok, thank you @dchest! That's very clear and very helpful. Closing this issue then. 😄

from tweetnacl-js.

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.