Typed data hashing and signing
Common structure
The whole idea is heavily inspired by EIP-712. To get a signature needed to calculate hash(hash(domain), hash(aci), hash(data)).
hash function is blake2b.
domain is a record containing not required properties:
nameas string,versionas integer,networkIdas string,contractAddressas ct-encoded string.
aci is part of a complete contract ACI. It defines a type of data to sign. For example, the ACI
{
"record": [
{ "name": "foo", "type": "string" },
{ "name": "bar", "type": "int" }
]
}
corresponds to the data
{ "foo": "test", "bar": 42 }
domain and data are fate-encoded before hashing. aci is prepared for hashing according to RFC8785.
Implementation
- AccountBase:signTypedData — calculates signature, supported in AccountMemory and in aepp-wallet connection;
- hashTypedData — calculates the overall hash of typed data to sign;
- hashJson — deterministic hashing of an arbitrary JS value, used to calculate
hash(aci); - hashDomain — use for debugging or to prepare the hash value for smart contract.