Address type format
Address data structure formats multiple cryptographic public key types.
Address public key types start out as uncompressed ECDSA secp256k1_ 64 byte binary arrays.
Address is generated by hashing the raw bytes of the public key and appending a 4 byte checksum.
The checksum comes from the hash of the first 4 bytes of the
The result is
You can generate test addresses with the the
function main() var account = Address("2ifr5dSFRAnXexBMC3HYEVp3JHSuz7KBPXWDRBV4xdFrqGy6R9"); endfunction
Type size in detail
There are two
INTERNAL: This is a straightforward canonical representation of a
sha256public key and the length is always 32 bytes. This is the
Addressformat used inside the Fetch.ai ledger C++ code.
EXTERNAL: This is the public format used to interact with the Python Ledger HTTP API and also in smart contract
etchcode. The final size of the external
Addressresult is between 50-51 bytes as the Base58 encoding process increases the size by a multiple of 1.42.
In Python-type pseudocode below, we show you the steps for producing both types of
public_key = XYZ # simple internal representation canonical_address = sha256(public_key) # external representation RAW_public_api_address = concatenate(canonical_address, sha256(canonical_address)[0 : 4bytes]) # check length assert(36bytes == len(RAW_public_api_address)) # Base58 encoding public_api_address = Base58(RAW_public_api_address)
etch currently supports the SHA256 encryption algorithm. Find out more here.
Address type has a function
signedTx() which allows you to verify the signature. It returns a boolean. This is only valid in an
@action function, else it will return false.
function main() var account = Address("2ifr5dSFRAnXexBMC3HYEVp3JHSuz7KBPXWDRBV4xdFrqGy6R9"); var verified : Bool; verified = account.signedTx(); printLn(toString(verified)); endfunction
The above code always prints
false when it is not contained within an
Address type will eventually support all asymmetric cryptographic types and, more importantly, will be quantum computing ready.
toString() to print
function main() var account = Address("2ifr5dSFRAnXexBMC3HYEVp3JHSuz7KBPXWDRBV4xdFrqGy6R9"); printLn(toString(account)); endfunction