2

I would like to fully understand how base58 encoding for a Tezos public key works, what are specific parts of an encoded edpk version and what do they stand for.

I attempted to create such key manually by generating random ed25519 bytes and prepending [13, 15, 37, 217] bytes to that. A base58check encoded version looks as follows:

edpku3g7CeTEvSKhxipD4Q2B6EiEP8cR323u8PFmGFgKRVRvCneEmT

My questions are:

  • Which parts of an encoded string are Tezos-specific things? For example - is it possible to map prefix bytes to characters in the encoded string?
  • Which part is a base58check checksum?

I appreciate that some answers might not be related not to Tezos knowledge but to cryptography, specifically to how base58check works. In such case, apart from the answers I'd appreciate links to read up on.

Thanks, K


EDIT after Athur B's comment:

Turns out a 1 means I'm doing something wrong. I would like to learn what is it, then :) . I am using a following nodejs code to generate my key:

import * as ed25519 from "ed25519";
import crypto from "crypto";

const seed = crypto.randomBytes(32);
const keyPair = ed25519.MakeKeypair(seed);
const pubKeyBytes = keyPair.publicKey;

const tezosPublicKeyPrefix = Buffer.from([13, 15, 37, 217]);
const prefixedPublicKey = Buffer.concat([tezosPublicKeyPrefix, pubKeyBytes]);
const base58checkEncoded = base58check.encode(prefixedPublicKey);

console.log('base58 pub key: ' + base58checkEncoded);

it prints:

base58 pub key: 1edpkubvws8V7KQcrSFMu3SjXU5PTbJASgJrdfzXd37rEBzWv9uKWvV

EDIT after resolving leading 1 issue

I managed to fix a leading 1 issue! The problem was, a base58check lib that I was using for encoding was bugged! Switching to bs58check lib helped and my code generated a correct key (no leading 1) . I guess I should have looked at weekly downloads as it's 68k vs 2k!

Anyway, I will change my question now that the 1 is not there anymore.


Topics for other people wanting to learn of things around that issue:

Format of public key, signature and key_hash literals

How to hash a Tezos public key

How to convert ed25519 bytes to Tezos public key

2
  • 1
    There's no 1 in front of edpk, if you're getting a 1 you're doing something wrong.
    – Arthur B
    Jan 28 '20 at 17:30
  • Thanks. I edited my answer and posted a code sample I'm using to generate the key. What seems to be amiss?
    – K SS
    Jan 28 '20 at 18:08
1

Have a look at this library for Tezos, written in Go. This function in particular generates a new wallet from random bytes (mnemonic and password can both be considered as random bytes) and creates an unencrypted secret key, public key, and public address.

4
  • If javascript is more your style, check out github.com/TezTech/eztz/blob/master/dist/eztz.cli.js#L274
    – utdrmac
    Jan 28 '20 at 17:50
  • Thank you for that. Sadly, in my use case I need to base on ed25519 bytes, not on mnemonics.
    – K SS
    Jan 28 '20 at 18:09
  • As I said in the post above, treat mnemonics as random bytes. It doesn't have to be words, it can be random bytes.
    – utdrmac
    Jan 28 '20 at 18:30
  • Tried that, got the same result - a base58check encoded string starting with 1edpk and 55 characters long, which is incorrect.
    – K SS
    Jan 29 '20 at 12:25

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.