From 58eb76f34d8f640e122bedc1df65ea75fb5e5f44 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Thu, 31 May 2018 20:13:41 +0100 Subject: [PATCH 1/3] simplify & update documentation, fiy typo --- docs/spec/blockchain/encoding.md | 106 +++++-------------------------- 1 file changed, 17 insertions(+), 89 deletions(-) diff --git a/docs/spec/blockchain/encoding.md b/docs/spec/blockchain/encoding.md index 4fcd9e7f..f2674ab9 100644 --- a/docs/spec/blockchain/encoding.md +++ b/docs/spec/blockchain/encoding.md @@ -39,7 +39,7 @@ place of the public key. Here we list the concrete types, their names, and prefix bytes for public keys and signatures, as well as the address schemes for each PubKey. Note for brevity we don't include details of the private keys beyond their type and name, as they can be -derrived the same way as the others using Amino. +derived the same way as the others using Amino. All registered objects are encoded by Amino using a 4-byte PrefixBytes that uniquely identifies the object and includes information about its underlying @@ -51,105 +51,33 @@ Notice that when encoding byte-arrays, the length of the byte-array is appended to the PrefixBytes. Thus the encoding of a byte array becomes ` ` -NOTE: the remainder of this section on Public Key Cryptography can be generated -from [this script](https://github.com/tendermint/tendermint/blob/master/docs/spec/scripts/crypto.go) +| Type | Name | Prefix | Length | Notes | +| ---- | ---- | ------ | ----- | ------ | +| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE62 | 0x20 | raw 32-byte Ed25519 pubkey | +| PubKeyLedgerEd25519 | tendermint/PubKeyLedgerEd25519 | 0x5C3453B2 | 0x20 | | +| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE982 | 0x21 | | +| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288912 | 0x40 | | +| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79A | 0x20 | OpenSSL compressed pubkey prefixed with 0x02 or 0x03 | +| PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | | +| PrivKeyLedgerEd25519 | tendermint/PrivKeyLedgerEd25519 | 0x0CFEEF9B | variable | | +| SignatureEd25519 | tendermint/SignatureKeyEd25519 | 0x3DA1DB2A | 0x40 | raw 64-byte Ed25519 signature | +| SignatureSecp256k1 | tendermint/SignatureKeySecp256k1 | 0x16E1FEEA | variable | raw bytes of the Secp256k1 signature | -### PubKeyEd25519 +To encode any of the above you do not need to be familiar with amino encoding. You can simply +use above table and concatenate Prefix || Length of raw bytes || raw bytes ( || stands for simple concatenation here). -``` -// Name: tendermint/PubKeyEd25519 -// PrefixBytes: 0x1624DE62 -// Length: 0x20 -// Notes: raw 32-byte Ed25519 pubkey -type PubKeyEd25519 [32]byte - -func (pubkey PubKeyEd25519) Address() []byte { - // NOTE: hash of the Amino encoded bytes! - return RIPEMD160(AminoEncode(pubkey)) -} -``` - -For example, the 32-byte Ed25519 pubkey -`CCACD52F9B29D04393F01CD9AF6535455668115641F3D8BAEFD2295F24BAF60E` would be -encoded as -`1624DE6220CCACD52F9B29D04393F01CD9AF6535455668115641F3D8BAEFD2295F24BAF60E`. - -The address would then be -`RIPEMD160(0x1624DE6220CCACD52F9B29D04393F01CD9AF6535455668115641F3D8BAEFD2295F24BAF60E)` -or `430FF75BAF1EC4B0D51BB3EEC2955479D0071605` - -### SignatureEd25519 - -``` -// Name: tendermint/SignatureKeyEd25519 -// PrefixBytes: 0x3DA1DB2A -// Length: 0x40 -// Notes: raw 64-byte Ed25519 signature -type SignatureEd25519 [64]byte -``` - -For example, the 64-byte Ed25519 signature -`1B6034A8ED149D3C94FDA13EC03B26CC0FB264D9B0E47D3FA3DEF9FCDE658E49C80B35F9BE74949356401B15B18FB817D6E54495AD1C4A8401B248466CB0DB0B` -would be encoded as -`3DA1DB2A401B6034A8ED149D3C94FDA13EC03B26CC0FB264D9B0E47D3FA3DEF9FCDE658E49C80B35F9BE74949356401B15B18FB817D6E54495AD1C4A8401B248466CB0DB0B` - -### PrivKeyEd25519 - -``` -// Name: tendermint/PrivKeyEd25519 -// Notes: raw 32-byte priv key concatenated to raw 32-byte pub key -type PrivKeyEd25519 [64]byte -``` - -### PubKeySecp256k1 - -``` -// Name: tendermint/PubKeySecp256k1 -// PrefixBytes: 0xEB5AE982 -// Length: 0x21 -// Notes: OpenSSL compressed pubkey prefixed with 0x02 or 0x03 -type PubKeySecp256k1 [33]byte - -func (pubkey PubKeySecp256k1) Address() []byte { - // NOTE: hash of the raw pubkey bytes (not Amino encoded!). - // Compatible with Bitcoin addresses. - return RIPEMD160(SHA256(pubkey[:])) -} -``` - -For example, the 33-byte Secp256k1 pubkey +For example, the 33-byte (or 0x21-byte in hex) Secp256k1 pubkey `020BD40F225A57ED383B440CF073BC5539D0341F5767D2BF2D78406D00475A2EE9` would be encoded as `EB5AE98221020BD40F225A57ED383B440CF073BC5539D0341F5767D2BF2D78406D00475A2EE9` -The address would then be -`RIPEMD160(SHA256(0x020BD40F225A57ED383B440CF073BC5539D0341F5767D2BF2D78406D00475A2EE9))` -or `0AE5BEE929ABE51BAD345DB925EEA652680783FC` +SignatureSecp256k1: -### SignatureSecp256k1 - -``` -// Name: tendermint/SignatureKeySecp256k1 -// PrefixBytes: 0x16E1FEEA -// Length: Variable -// Encoding prefix: Variable -// Notes: raw bytes of the Secp256k1 signature -type SignatureSecp256k1 []byte -``` - -For example, the Secp256k1 signature +For example, the variable size Secp256k1 signature (in this particular example 70 or 0x46 bytes) `304402201CD4B8C764D2FD8AF23ECFE6666CA8A53886D47754D951295D2D311E1FEA33BF02201E0F906BB1CF2C30EAACFFB032A7129358AFF96B9F79B06ACFFB18AC90C2ADD7` would be encoded as `16E1FEEA46304402201CD4B8C764D2FD8AF23ECFE6666CA8A53886D47754D951295D2D311E1FEA33BF02201E0F906BB1CF2C30EAACFFB032A7129358AFF96B9F79B06ACFFB18AC90C2ADD7` -### PrivKeySecp256k1 - -``` -// Name: tendermint/PrivKeySecp256k1 -// Notes: raw 32-byte priv key -type PrivKeySecp256k1 [32]byte -``` - ## Other Common Types ### BitArray From 978277a4c18258a8aaa1a829c4924a31e96d9270 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Thu, 31 May 2018 20:21:41 +0100 Subject: [PATCH 2/3] make slightly more readable --- docs/spec/blockchain/encoding.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/spec/blockchain/encoding.md b/docs/spec/blockchain/encoding.md index f2674ab9..336fa8b0 100644 --- a/docs/spec/blockchain/encoding.md +++ b/docs/spec/blockchain/encoding.md @@ -49,7 +49,10 @@ spec](https://github.com/tendermint/go-amino#computing-the-prefix-and-disambigua In what follows, we provide the type names and prefix bytes directly. Notice that when encoding byte-arrays, the length of the byte-array is appended to the PrefixBytes. Thus the encoding of a byte array becomes ` - ` + `. In other words, to encode any type listed below you do not need to be +familiar with amino encoding. +You can simply use below table and concatenate Prefix || Length (of raw bytes) || raw bytes +( while || stands for byte concatenation here). | Type | Name | Prefix | Length | Notes | | ---- | ---- | ------ | ----- | ------ | @@ -63,17 +66,14 @@ to the PrefixBytes. Thus the encoding of a byte array becomes ` | SignatureEd25519 | tendermint/SignatureKeyEd25519 | 0x3DA1DB2A | 0x40 | raw 64-byte Ed25519 signature | | SignatureSecp256k1 | tendermint/SignatureKeySecp256k1 | 0x16E1FEEA | variable | raw bytes of the Secp256k1 signature | -To encode any of the above you do not need to be familiar with amino encoding. You can simply -use above table and concatenate Prefix || Length of raw bytes || raw bytes ( || stands for simple concatenation here). +### Examples -For example, the 33-byte (or 0x21-byte in hex) Secp256k1 pubkey -`020BD40F225A57ED383B440CF073BC5539D0341F5767D2BF2D78406D00475A2EE9` would be -encoded as +1. For example, the 33-byte (or 0x21-byte in hex) Secp256k1 pubkey +`020BD40F225A57ED383B440CF073BC5539D0341F5767D2BF2D78406D00475A2EE9` +would be encoded as `EB5AE98221020BD40F225A57ED383B440CF073BC5539D0341F5767D2BF2D78406D00475A2EE9` -SignatureSecp256k1: - -For example, the variable size Secp256k1 signature (in this particular example 70 or 0x46 bytes) +2. For example, the variable size Secp256k1 signature (in this particular example 70 or 0x46 bytes) `304402201CD4B8C764D2FD8AF23ECFE6666CA8A53886D47754D951295D2D311E1FEA33BF02201E0F906BB1CF2C30EAACFFB032A7129358AFF96B9F79B06ACFFB18AC90C2ADD7` would be encoded as `16E1FEEA46304402201CD4B8C764D2FD8AF23ECFE6666CA8A53886D47754D951295D2D311E1FEA33BF02201E0F906BB1CF2C30EAACFFB032A7129358AFF96B9F79B06ACFFB18AC90C2ADD7` From 7030d5c2a7df1d9574d040b2c5d43f4a2306cafc Mon Sep 17 00:00:00 2001 From: Liamsi Date: Sat, 2 Jun 2018 13:04:40 +0100 Subject: [PATCH 3/3] remove notes column according to: https://github.com/tendermint/go-crypto/pull/110#issuecomment-394048086 --- docs/spec/blockchain/encoding.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/spec/blockchain/encoding.md b/docs/spec/blockchain/encoding.md index 336fa8b0..c60f7035 100644 --- a/docs/spec/blockchain/encoding.md +++ b/docs/spec/blockchain/encoding.md @@ -54,17 +54,17 @@ familiar with amino encoding. You can simply use below table and concatenate Prefix || Length (of raw bytes) || raw bytes ( while || stands for byte concatenation here). -| Type | Name | Prefix | Length | Notes | -| ---- | ---- | ------ | ----- | ------ | -| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE62 | 0x20 | raw 32-byte Ed25519 pubkey | -| PubKeyLedgerEd25519 | tendermint/PubKeyLedgerEd25519 | 0x5C3453B2 | 0x20 | | -| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE982 | 0x21 | | -| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288912 | 0x40 | | -| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79A | 0x20 | OpenSSL compressed pubkey prefixed with 0x02 or 0x03 | -| PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | | -| PrivKeyLedgerEd25519 | tendermint/PrivKeyLedgerEd25519 | 0x0CFEEF9B | variable | | -| SignatureEd25519 | tendermint/SignatureKeyEd25519 | 0x3DA1DB2A | 0x40 | raw 64-byte Ed25519 signature | -| SignatureSecp256k1 | tendermint/SignatureKeySecp256k1 | 0x16E1FEEA | variable | raw bytes of the Secp256k1 signature | +| Type | Name | Prefix | Length | +| ---- | ---- | ------ | ----- | +| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE62 | 0x20 | +| PubKeyLedgerEd25519 | tendermint/PubKeyLedgerEd25519 | 0x5C3453B2 | 0x20 | +| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE982 | 0x21 | +| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288912 | 0x40 | +| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79A | 0x20 | +| PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | +| PrivKeyLedgerEd25519 | tendermint/PrivKeyLedgerEd25519 | 0x0CFEEF9B | variable | +| SignatureEd25519 | tendermint/SignatureKeyEd25519 | 0x3DA1DB2A | 0x40 | +| SignatureSecp256k1 | tendermint/SignatureKeySecp256k1 | 0x16E1FEEA | variable | ### Examples