Skip to content

NKN Wallet Specification: Wallet Address Format

gdmmx edited this page Nov 11, 2019 · 10 revisions

Wallet Address Format as below:

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

Valid address range

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

Process of convert public Key to wallet address

  1. publicKey
  2. commpress publicKey
  3. generated RedeemScript vmCode
  4. sha256 & ripemd160 RedeemScript got 160bits Hash
  5. calc Checksum of (Prefix + 160 bits Hash)
  6. append Checksum
  7. base58.encode

Convertor Example

https://github.com/nknorg/nkn/blob/v0.9/util/pubkey2addr.go

    if k, err = hex.DecodeString(key); err == nil {
	if pk, err = crypto.DecodePoint(k); err == nil {
		if redeemHash, err = contract.CreateRedeemHash(pk); err == nil {
			return redeemHash.ToAddress()
		}
	}
    }