magicHash method

List<int> magicHash()

A double-sha256 digest unique to Bitcoin Signed Messages

The hash is constructed from the double-sha256 of a buffer. The buffer is composed from appending the following elements in order:

  • The integer Length of MAGIC_BYTES
  • MAGIC_BYTES which is the string literal "Bitcoin Signed Message:\n"
  • The integer length of the message that needs to be signed
  • The message text

Returns the double-sha256 of the buffer constructed as shown above

Implementation

List<int> magicHash() {

    var prefix1 = MAGIC_BYTES.length;
    var prefix2 = this._message!.length;
    var buf = HEX.encode([prefix1] + utf8.encode(MAGIC_BYTES) + [prefix2] + this._message!);
    var hash = sha256Twice(HEX.decode(buf));
    return hash;
}