I was going through ss58 documentation and trying to find out the relationship between ss58 and public key.
I want to know what is the use of this prefix https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json?
I was going through ss58 documentation and trying to find out the relationship between ss58 and public key.
I want to know what is the use of this prefix https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json?
First thing to keep in mind is that an SS58 address is just a sequence of bytes encoded in base 58. This sequence can be dissected in three components:
The Network-Id is what is referred as the "prefix" in the ss58 registry you shared. For example a generic Substrate address has a prefix set to 42 (here).
The same public key can be used to generate different addresses by changing the prefix (the checksum changes as a consequence).
An example may help.
Generate a sr25519 keypair via subkey
tool:
❯ subkey generate --scheme sr25519
Secret phrase `trip embody match refuse exchange cabin brand try write eight lamp endorse` is account:
Secret seed: 0xa444d232c8a70098d94add70f9ceb4702c58aca4558966e2ce7d59c153306389
Public key (hex): 0x6a5bfc392d5479b306d85c1e03766207b5443466f8e4668eedb97c26918e2e79
Account ID: 0x6a5bfc392d5479b306d85c1e03766207b5443466f8e4668eedb97c26918e2e79
SS58 Address: 5EUAFw4JM21WgrjqEqBPXGSZ2zUCkxdCiaNTeuzC7t8twpiD
Convert the SS58 address from base 58 to hex to inspect the content (for example using this website).
B58: 5EUAFw4JM21WgrjqEqBPXGSZ2zUCkxdCiaNTeuzC7t8twpiD
Hex: 2a6a5bfc392d5479b306d85c1e03766207b5443466f8e4668eedb97c26918e2e7973b2
The hex version can be decomposed as follows:
The very same public key can be part of an address used in a different network. For example, for Polkadot:
❯ subkey inspect --network polkadot --scheme sr25519 "trip embody match refuse exchange cabin brand try write eight lamp endorse"
Secret phrase `trip embody match refuse exchange cabin brand try write eight lamp endorse` is account:
Secret seed: 0xa444d232c8a70098d94add70f9ceb4702c58aca4558966e2ce7d59c153306389
Public key (hex): 0x6a5bfc392d5479b306d85c1e03766207b5443466f8e4668eedb97c26918e2e79
Account ID: 0x6a5bfc392d5479b306d85c1e03766207b5443466f8e4668eedb97c26918e2e79
SS58 Address: 13QTQGKNCoGz8PkMCUEPfRGhtcTrTGBLo56wpCyYfyAR89hu
Convert the SS58 address from base 58 to hex
Base 58: 13QTQGKNCoGz8PkMCUEPfRGhtcTrTGBLo56wpCyYfyAR89hu
Hex: 006a5bfc392d5479b306d85c1e03766207b5443466f8e4668eedb97c26918e2e79259c
Note that the public key component is still the same, while the Network-ID and the Checksum is changed (Network id is now set to 0x00, i.e. the Polkadot prefix here)
You can find another example here