API v0.1 · pre-release

Verifying signatures

Every message is signed. Verify it before you act on it, and pin the signer address we give you.

The scheme

Every message is signed with an Ethereum personal-message signature (EIP-191). The signed bytes are the message without sig, serialised with the JSON Canonicalization Scheme (RFC 8785): keys sorted, no whitespace, numbers written as JavaScript writes them (0.0 becomes 0). Libraries exist for most languages.

Three checks

Reject any message that fails one of them:

  1. the signature does not recover the pinned signer address;
  2. seq is not greater than the last message you accepted for that asset;
  3. t is older than your staleness limit.

Python

import rfc8785
from eth_account import Account
from eth_account.messages import encode_defunct

def signer_of(msg: dict) -> str:
    data = rfc8785.dumps({k: v for k, v in msg.items() if k != "sig"})
    return Account.recover_message(encode_defunct(data), signature=msg["sig"])

assert signer_of(msg) == GUARD_SIGNER

JavaScript

With ethers v6 and canonicalize:

import canonicalize from "canonicalize";
import { verifyMessage } from "ethers";

const { sig, ...body } = msg;
if (verifyMessage(canonicalize(body), sig) !== GUARD_SIGNER) throw new Error("bad signature");

On-chain

Recover the signer with ecrecover from the EIP-191 hash of the same canonical bytes, and compare it with the pinned address. Canonicalise off-chain (in your keeper or relayer) and pass the bytes with the signature.

Test vector

The example message on Message format recovers to 0x7B0e9c6D3371D9e37505a9c9bAdb7ce066fAc087, the key used for that recorded run. Use it to test your code. Its canonical bytes, exactly as signed:

{"asset":"XAU","guard":{"auction":true,"band_breach":false,"pause":false},"hi":3563.85,"lo":3550.88,"price":3557.36,"seq":378581,"since_reference_s":0,"sources_total":9,"sources_used":9,"state":"REOPENING","t":1795388400000}
Production keys are confirmed to each pilot partner directly. Never accept a signer address from a message or a web page alone.