{
  "title": "The hashes a hardware wallet shows for a Safe transaction, recomputed three ways without the Safe API",
  "command": "pnpm --filter @guard/site exec tsx scripts/run-device-hash-example.ts",
  "executedAt": "2026-11-16T07:22:08.493Z",
  "sourceRevision": "3013cbb8bfb688ec78a33c4e61cc338d09c9edd2",
  "environment": "Node.js script and cast Version: 1.7.1, offline. No RPC, no Safe Transaction Service, no website, no hardware wallet, no signing, no broadcast.",
  "reusesExample": "/resources/safe-batch-review-example.json (batch A)",
  "setup": {
    "chainId": 1,
    "safe": "0x00000000000000000000000000000000000000a1 (synthetic, not a deployed Safe)",
    "nestedSafe": "0x00000000000000000000000000000000000000a2 (synthetic, an owner of the first Safe)"
  },
  "method": "Rebuilt batch A of the C02 example, then computed its EIP-712 domain hash, message hash and SafeTxHash with Guard's implementation, with viem's hashTypedData and with plain cast commands. Asserted that all three agree and equal the values published with C02. Repeated with one hand-typed error (nonce 43). Built the approveHash call a nested owner Safe would execute and computed its own hashes the same three ways.",
  "castRecipe": {
    "note": "Fill in your own chain ID, Safe address and the ten SafeTx fields. Everything below is offline.",
    "commands": [
      "DOMAIN_TYPEHASH=$(cast keccak \"EIP712Domain(uint256 chainId,address verifyingContract)\")",
      "SAFETX_TYPEHASH=$(cast keccak \"SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)\")",
      "DOMAIN_HASH=$(cast keccak $(cast abi-encode \"f(bytes32,uint256,address)\" $DOMAIN_TYPEHASH $CHAIN_ID $SAFE))",
      "DATA_HASH=$(cast keccak $DATA)",
      "MESSAGE_HASH=$(cast keccak $(cast abi-encode \"f(bytes32,address,uint256,bytes32,uint8,uint256,uint256,uint256,address,address,uint256)\" $SAFETX_TYPEHASH $TO $VALUE $DATA_HASH $OPERATION $SAFE_TX_GAS $BASE_GAS $GAS_PRICE $GAS_TOKEN $REFUND_RECEIVER $NONCE))",
      "SAFE_TX_HASH=$(cast keccak $(cast concat-hex 0x1901 $DOMAIN_HASH $MESSAGE_HASH))"
    ],
    "batchAVariables": [
      "CHAIN_ID=1",
      "SAFE=0x00000000000000000000000000000000000000a1",
      "TO=0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
      "VALUE=0",
      "DATA=0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004760000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000000000000000000000000000000000000000000c10000000000000000000000000000000000000000000000000000000ba43b74000000000000000000000000000000000000000000c10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010438ed17390000000000000000000000000000000000000000000000000000000ba43b7400000000000000000000000000000000000000000000000000d02ab486cedc000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000713fb300000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000b20000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000000000000000000000000000000000000000000c2000000000000000000000000000000000000000000000000d02ab486cedc00000000000000000000000000000000000000000000c200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084617ba03700000000000000000000000000000000000000000000000000000000000000b2000000000000000000000000000000000000000000000000d02ab486cedc000000000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024ef5cfb8c00000000000000000000000000000000000000000000000000000000000000a10000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000000000000000000000000000000000000000000d100000000000000000000000000000000000000000000000000000002cb41780000000000000000000000",
      "OPERATION=1",
      "SAFE_TX_GAS=0",
      "BASE_GAS=0",
      "GAS_PRICE=0",
      "GAS_TOKEN=0x0000000000000000000000000000000000000000",
      "REFUND_RECEIVER=0x0000000000000000000000000000000000000000",
      "NONCE=42"
    ],
    "batchACheck": "Pasting batchAVariables then commands into bash, then echo $DOMAIN_HASH $MESSAGE_HASH $SAFE_TX_HASH, prints batchA.domainHash, batchA.messageHash and batchA.safeTxHash. The script that wrote this file ran exactly that and asserted it.",
    "appliesTo": "Safe contracts v1.3.0 and later (chain ID in the domain). Older Safes use a different domain type and SafeTx type name."
  },
  "batchA": {
    "fields": {
      "to": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
      "value": "0",
      "operation": 1,
      "safeTxGas": "0",
      "baseGas": "0",
      "gasPrice": "0",
      "gasToken": "0x0000000000000000000000000000000000000000",
      "refundReceiver": "0x0000000000000000000000000000000000000000",
      "nonce": 42,
      "dataBytes": 1220,
      "dataKeccak": "0x6c818d730b0cfd39f8e4bddce7e44e8fa54f04dd53de292e36ca8bed9293213a",
      "data": "0x8d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004760000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000000000000000000000000000000000000000000c10000000000000000000000000000000000000000000000000000000ba43b74000000000000000000000000000000000000000000c10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010438ed17390000000000000000000000000000000000000000000000000000000ba43b7400000000000000000000000000000000000000000000000000d02ab486cedc000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000713fb300000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000b20000000000000000000000000000000000000000b200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000000000000000000000000000000000000000000c2000000000000000000000000000000000000000000000000d02ab486cedc00000000000000000000000000000000000000000000c200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084617ba03700000000000000000000000000000000000000000000000000000000000000b2000000000000000000000000000000000000000000000000d02ab486cedc000000000000000000000000000000000000000000000000000000000000000000a100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024ef5cfb8c00000000000000000000000000000000000000000000000000000000000000a10000000000000000000000000000000000000000b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000000000000000000000000000000000000000000d100000000000000000000000000000000000000000000000000000002cb41780000000000000000000000"
    },
    "domainHash": "0x2876acb9e3053361e432c7b0a8becf9003595bb44f691899c3ade8b8bf6edd6f",
    "messageHash": "0xc11acd4903d319d622965cda9a200609a10810f212d5e1d35924c96d6ad30201",
    "safeTxHash": "0x4665039a8f7a20df2b026ba66c7a3c82327b36685c7ae16b432e082ae62f257c",
    "implementationsAgree": [
      "guard",
      "viem",
      "cast"
    ]
  },
  "oneTypo": {
    "change": "nonce 43 instead of 42",
    "domainHash": "0x2876acb9e3053361e432c7b0a8becf9003595bb44f691899c3ade8b8bf6edd6f",
    "messageHash": "0xb9c52123e21bba294875cd396a58911b6424c14be9ac567700f6b6ab1c82ce61",
    "domainHashUnchanged": true,
    "note": "Only the message hash moves. A domain hash that matches says nothing about the ten fields."
  },
  "otherChain": {
    "change": "chain ID 10 instead of 1",
    "domainHash": "0x4507a2099391924597441ac41ae462047538c94bf5c1fcad9a3adab84e94ebf7",
    "note": "The domain hash moves, and with it the SafeTxHash."
  },
  "nested": {
    "explanation": "When a Safe owns another Safe, its signers sign a transaction of their own Safe: a call to approveHash on the parent with the parent SafeTxHash as argument. Their device shows the nested Safe's hashes. The parent SafeTxHash only appears inside data.",
    "fields": {
      "to": "0x00000000000000000000000000000000000000a1",
      "value": "0",
      "operation": 0,
      "nonce": 7,
      "data": "0xd4d9bdcd4665039a8f7a20df2b026ba66c7a3c82327b36685c7ae16b432e082ae62f257c"
    },
    "domainHash": "0x5b8636f5896d6d77d4e49ebdb8e62f9230a7dacf7acee62c83d0d062f73f986e",
    "messageHash": "0xbc8fd413a96b830a1ba61ef84c3b661f70d202b454a4640201f04d5f21abde24",
    "safeTxHash": "0x9f127138feaee2c917333e7190970dd13d60d0792ac58377277cf0bb6319b59e",
    "parentSafeTxHashInsideData": "0x4665039a8f7a20df2b026ba66c7a3c82327b36685c7ae16b432e082ae62f257c"
  },
  "limits": [
    "Synthetic addresses only. Nothing was deployed, simulated, signed or broadcast.",
    "No hardware wallet was used. What each device displays comes from vendor documentation, not from this run.",
    "A matching hash proves the device signs the fields you hashed. It says nothing about what those fields do: that is the review in /blog/how-to-review-a-safe-transaction/.",
    "The nested case assumes the owner Safe confirms through approveHash, the pattern computed here. Other confirmation paths exist and would produce different payloads."
  ]
}
