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:
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
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.
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);
base58 pub key: 1edpkubvws8V7KQcrSFMu3SjXU5PTbJASgJrdfzXd37rEBzWv9uKWvV
EDIT after resolving leading
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: