Giter Site home page Giter Site logo

Comments (4)

zhil avatar zhil commented on May 29, 2024

As I understand, by default you encode secret key with base58 (Bitcoin characters set?) and I need to convert it to base64?

from tweetnacl-js.

zhil avatar zhil commented on May 29, 2024

ok, I am pretty confused. I have converted secret key to Uint8Array using bs58.decode(), but its 64 bytes? And Ed25519 private key length should be 32 bytes? openssl/openssl#6357

from tweetnacl-js.

dchest avatar dchest commented on May 29, 2024

You need to convert keys generated by TweetNaCl to Base64. The secret key consists of 32 bytes secret and 32 bytes public key (for OpenSSH you'll need the first part). Also, there's some encoding likely needed for the key before you convert it to Base64 for OpenSSH format.

from tweetnacl-js.

zhil avatar zhil commented on May 29, 2024

@dchest thanks for your help. I failed to generate OpenSSH key but still solved my main target.
Quick info for somebody, who will google this.

Basically, I need to reuse Near signature functionality https://docs.near.org/ru/docs/api/naj-cookbook#verify-signature in PHP code. So I planned to convert Near private keys to something compatible with PEM key format. And since Near uses tweetnacl-js - I created this one issue.

But everything is way more simple. PHP has sodium_* functions and sodium Ed25519 have the same 64 bytes length.

print strlen(sodium_crypto_sign_secretkey(sodium_crypto_sign_keypair()));
// 64

So, I basically converted NEAR (tweetnacl-js) key from base58 format to raw bytes and used them in sodium. It worked just fine!

         $nearPrivateKey = 'qZQEGDN5wQmiVtEQZgHQ3Y4uZJ3EBKuFGydAcM84pVbfnDxiq2Ufp38WaE8wyV6MELRMV9jZtT9RfCqKPELWe98';
        $base58Decoder = new Tuupola\Base58(["characters" => Base58::BITCOIN]);
        $rawNearKey = $base58Decoder->decode($nearPrivateKey);
        print bin2hex(sodium_crypto_sign('Test message', $rawNearKey));

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.