forked from hashgraph/hedera-improvement-proposal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added implementations in more languages
- Loading branch information
Showing
9 changed files
with
160 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(* (c) 2020-2021 Hedera Hashgraph,released under Apache 2.0 license.*) | ||
|
||
(* find the HIP-15 checksum for a given Hedera address and ledger ID *) | ||
|
||
checksum[ledgerId_, address_] := | ||
Module[{h, d, p3, p5, s0, s1, s, sh, c, cp}, | ||
h = Join[ledgerId, {0, 0, 0, 0, 0, 0}]; | ||
d = (ToCharacterCode[address] //. {46 -> 10 + 48}) - 48; (* "." is 46, "0" is 48 *) | ||
p3 = 26^3; | ||
p5 = 26^5; | ||
sd0 = Mod[Total[d[[1 ;; Length[d] ;; 2]]], 11]; | ||
sd1 = Mod[Total[d[[2 ;; Length[d] ;; 2]]], 11]; | ||
sd = Fold[Mod[#1*31 + #2, p3] &, d]; | ||
sh = Fold[Mod[#1*31 + #2, p5] &, h]; | ||
c = Mod[((Mod[Length[d], 5]*11 + sd0)*11 + sd1)*p3 + sd + sh, p5]; | ||
cp = Mod[c*1000003, p5]; | ||
StringJoin @@ | ||
FromCharacterCode[(IntegerDigits[cp, 26, 5] + | ||
ToCharacterCode["a"][[1]])]]; | ||
|
||
(* Output the given ledger ID and address along with the calculated \ | ||
checksum *) | ||
|
||
output[ledgerId_, address_] := | ||
Print["ledger: ", ledgerId, " address: ", address, "-", | ||
checksum[ledgerId, address]]; | ||
|
||
(* Output checksums for all the examples given in HIP-15 *) | ||
|
||
addresses = {"0.0.1", "0.0.4", "0.0.5", "0.0.6", "0.0.12", "0.0.123", | ||
"0.0.1234567890", "12.345.6789", "1.23.456"}; | ||
output[{0}, #] & /@ addresses; | ||
output[{161, 255, 1}, #] & /@ addresses; | ||
|
||
(* | ||
OUTPUT: | ||
ledger:{0} address:0.0.1-dfkxr | ||
ledger:{0} address:0.0.4-cjcuq | ||
ledger:{0} address:0.0.5-ktach | ||
ledger:{0} address:0.0.6-tcxjy | ||
ledger:{0} address:0.0.12-uuuup | ||
ledger:{0} address:0.0.123-vfmkw | ||
ledger:{0} address:0.0.1234567890-zbhlt | ||
ledger:{0} address:12.345.6789-aoyyt | ||
ledger:{0} address:1.23.456-adpbr | ||
ledger:{161,255,1} address:0.0.1-xzlgq | ||
ledger:{161,255,1} address:0.0.4-xdddp | ||
ledger:{161,255,1} address:0.0.5-fnalg | ||
ledger:{161,255,1} address:0.0.6-nwxsx | ||
ledger:{161,255,1} address:0.0.12-povdo | ||
ledger:{161,255,1} address:0.0.123-pzmtv | ||
ledger:{161,255,1} address:0.0.1234567890-tvhus | ||
ledger:{161,255,1} address:12.345.6789-vizhs | ||
ledger:{161,255,1} address:1.23.456-uxpkq | ||
*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# HIP-15 Checksum calculation Pseudocode | ||
|
||
The checksum (such as `vfmkw`) is calculated from the no-checksum address (such as `0.0.123` ) by this algorithm: | ||
|
||
``` | ||
a = a valid no-checksum address string, such as 0.0.123 | ||
d = int array for the digits of a (using 10 to represent "."), so 0.0.123 is [0,10,0,10,1,2,3] | ||
h = unsigned byte array containing the ledger ID followed by 6 zero bytes | ||
p3 = 26 * 26 * 26 | ||
p5 = 26 * 26 * 26 * 26 * 26 | ||
sd0 = (d[0] + d[2] + d[4] + d[6] + ...) mod 11 | ||
sd1 = (d[1] + d[3] + d[5] + d[7] + ...) mod 11 | ||
sd = (...((((d[0] * 31) + d[1]) * 31) + d[2]) * 31 + ... ) * 31 + d[d.length-1]) mod p3 | ||
sh = (...(((h[0] * 31) + h[1]) * 31) + h[2]) * 31 + ... ) * 31 + h[h.length-1]) mod p5 | ||
c = (((d.length mod 5) * 11 + sd0) * 11 + sd1) * p3 + sd + sh ) mod p5 | ||
cp = (c * 1000003) % p5 | ||
checksum = cp, written as 5 digits in base 26, using a-z | ||
``` | ||
|
||
Cryptographically secure ledger IDs will be implemented as part of state proofs. But for now, the following three ledgers will each have a ledger ID consisting of a single byte: | ||
|
||
``` | ||
0 = Hedera mainnet | ||
1 = stable testnet | ||
2 = preview net | ||
``` | ||
|
||
Test vectors: | ||
|
||
``` | ||
For ledger ID 0x00: | ||
0.0.1-dfkxr | ||
0.0.4-cjcuq | ||
0.0.5-ktach | ||
0.0.6-tcxjy | ||
0.0.12-uuuup | ||
0.0.123-vfmkw | ||
0.0.1234567890-zbhlt | ||
12.345.6789-aoyyt | ||
1.23.456-adpbr | ||
For ledger ID 0xa1ff01: | ||
0.0.1-xzlgq | ||
0.0.4-xdddp | ||
0.0.5-fnalg | ||
0.0.6-nwxsx | ||
0.0.12-povdo | ||
0.0.123-pzmtv | ||
0.0.1234567890-tvhus | ||
12.345.6789-vizhs | ||
1.23.456-uxpkq | ||
``` | ||
|
||
(c) 2020-2021 Hedera Hashgraph,released under Apache 2.0 license. |
Binary file not shown.