1

I developed a small script to generate a new tezos account, result has this form: ->

{ sk:
   'edskReYTc3xorfemyNAcrYb6Sz8Wgj6e1PfevpZ6uysf4KXWBNxXcoLA4KBtZp7hmUCy6V3bhtWZRMSuya5DgXA1TU2JXYeDmG',
  pk: 'edpktnRinzUJFSfkvL9VC7Mfcb5PFDtKeXhZmjEcBGfKnJc9PKZWXn',
  pkh: 'tz1Ub34SJF9DsUvsmqQqnrJ7gw6SreCg2Pue' 
}

What I get for the secret key is ed25519 secret key with a length of 98, I want to unencrypt it to get ed25519 seed with a length of 54, just like the secret key displayed when entring ./tezos-client show address tz1..... --show-secret ->

Hash: tz1MwakuLuEmR9X96uT9rfQyc62S3BnZNvi6
Public Key: edpktirtvUD2T8MyZYKLfAFNVYrtTtFhUJCAr1uWsKXBHjnHvyT68N
Secret Key: unencrypted:edsk4QPXFBLsi5Pmx5PY6PnKDSB2GWrBw913qrRm5LGtJiXDVatFNC

Is it possible programmatically to pass from the first secret key form (length == 98) to the second (length == 54)?

2

If using pytezos that would be:

>>> from pytezos import Key
... Key.from_encoded_key('edskReYTc3xorfemyNAcrYb6Sz8Wgj6e1PfevpZ6uysf4KXWBNxXcoLA4KBtZp7hmUCy6V3bhtWZRMSuya5DgXA1TU2JXYeDmG').secret_key()
<<< 'edsk2pR4GssrHRPDFBci4wkLGAH97HcwmLAWMEGWh6D9zyTUvbQb1p'

Under the hood:

  1. Base58 decode (with checksum)
  2. Cut first 4 bytes
  3. That's ed25519 secret key (64 bytes)
  4. Using crypto_sign_sk_to_seed from libsoduim
  5. Got 32 bytes long seed
  6. Adding 4 bytes prefix (0x0d0f3a07)
  7. Base58 encode with checksum
  • Thank you, it works with pytezos, I tried to implement the "under the hood" that you mentioned but libsodium.js doesn't have the crypto_sign_sk_to_seed function, do you know an alternative in JS? – Daly Feb 14 at 12:28
  • Try crypto_sign_ed25519_sk_to_seed – Michael Zaikin Feb 14 at 13:00
  • Doesn't exist also :/, I searched in all the libsodium.js for a function xxx_to_seed and nothing there. – Daly Feb 14 at 14:46
  • 1
    codesandbox.io/s/… – Michael Zaikin Feb 14 at 15:25
  • 1
    I didn't try with libsodium-wrappers-sumo, it finally works, this is how for everyone else in the future: b58encode(sodium_sumo.crypto_sign_ed25519_sk_to_seed(b58decode(sk, prefix.edsk)), prefix.edsk2); – Daly Feb 14 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.