-
Notifications
You must be signed in to change notification settings - Fork 156
NKN Wallet Specification: Wallet Address Format
gdmmx edited this page Mar 30, 2021
·
10 revisions
Prefix | Uint160 | Uint32 |
---|---|---|
Fool-proof design | 160 bits Hash of RedeemScript | Checksum |
- Fool-proof:
Fix 0x35 in v0.8 for base58.encode got string start with "N"
Fix 0x02b825 in v0.9 for base58.encode got string start with "NKN"
- 160 bits Hash of RedeemScript:
generate RedeemScript vmCode from publicKey, and hash it with ripemd160
- Checksum:
SHA256 hash twice with (Prefix + Uint160), retain lowest 32bits
As part #1 definition, the valid address range (without consider Checksum
) should be:
Minimal | Maximum | |
---|---|---|
Expr | (0x2b825<<192) | (0^160)<<32 | 0^32 |
(0x2b825<<192) | ((1<<160)-1)<<32 | (1<<32)-1 |
Hex | 0x2b8250000000000...00000000000000L | 0x2b825ffffffffffff...ffffffffffffffffffffL |
Base58 | NKNBV71h5oUBjknMHPikPU7nraw9KtkegU1m | NKNaphzoP6BNCdbnRUkAinbv8NZeaqTtGJL6 |
- publicKey
- generated
RedeemScript vmCode
- sha256 & ripemd160 RedeemScript got 160bits Hash
- calc
Checksum
of (Prefix
+160 bits Hash
) - append
Checksum
- base58.encode
https://github.com/nknorg/nkn/blob/master/util/pubkey2addr/pubkey2addr.go#L12
go run util/pubkey2addr/pubkey2addr.go 1111111122222222333333334444444455555555666666667777777788888888
NKNRyqyBLzghJWGwogJTKNFM5WUnoqopiTYV
if pk, err := hex.DecodeString(pubkeyHexStr); err == nil {
if err = crypto.CheckPublicKey(pk); err == nil {
if redeemHash, err := program.CreateProgramHash(pk); err == nil {
return redeemHash.ToAddress()
}
}
}