Skip to content

Commit

Permalink
docs: fix message type hash in snip12 guide
Browse files Browse the repository at this point in the history
  • Loading branch information
trishtzy committed Dec 28, 2024
1 parent 7b4ff76 commit a1c95a3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/modules/ROOT/pages/guides/snip12.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ In this case it can be computed as follows:

[,cairo]
----
// Since there's no u64 type in SNIP-12, we use u128 for `expiry` in the type hash generation.
let message_type_hash = selector!(
"\"Message\"(\"recipient\":\"ContractAddress\",\"amount\":\"u256\",\"nonce\":\"felt\",\"expiry\":\"u64\")\"u256\"(\"low\":\"felt\",\"high\":\"felt\")"
"\"Message\"(\"recipient\":\"ContractAddress\",\"amount\":\"u256\",\"nonce\":\"felt\",\"expiry\":\"u128\")\"u256\"(\"low\":\"felt\",\"high\":\"felt\")"
);
----

which is the same as:

[,cairo]
----
let message_type_hash = 0x120ae1bdaf7c1e48349da94bb8dad27351ca115d6605ce345aee02d68d99ec1;
let message_type_hash = 0xa2a7036c1f406af7c47722b209f23bd2f2d6ac21423c8c73bd92cf28409ee2;
----

NOTE: In practice it's better to compute the type hash off-chain and hardcode it in the contract, since it is a constant value.
Expand All @@ -128,7 +129,7 @@ use openzeppelin_utils::snip12::StructHash;
use starknet::ContractAddress;
const MESSAGE_TYPE_HASH: felt252 =
0x120ae1bdaf7c1e48349da94bb8dad27351ca115d6605ce345aee02d68d99ec1;
0xa2a7036c1f406af7c47722b209f23bd2f2d6ac21423c8c73bd92cf28409ee2;
#[derive(Copy, Drop, Hash)]
struct Message {
Expand Down Expand Up @@ -194,7 +195,7 @@ use openzeppelin_utils::snip12::{SNIP12Metadata, StructHash, OffchainMessageHash
use starknet::ContractAddress;
const MESSAGE_TYPE_HASH: felt252 =
0x120ae1bdaf7c1e48349da94bb8dad27351ca115d6605ce345aee02d68d99ec1;
0xa2a7036c1f406af7c47722b209f23bd2f2d6ac21423c8c73bd92cf28409ee2;
#[derive(Copy, Drop, Hash)]
struct Message {
Expand Down Expand Up @@ -248,7 +249,7 @@ use openzeppelin_utils::snip12::{SNIP12Metadata, StructHash, OffchainMessageHash
use starknet::ContractAddress;
const MESSAGE_TYPE_HASH: felt252 =
0x120ae1bdaf7c1e48349da94bb8dad27351ca115d6605ce345aee02d68d99ec1;
0xa2a7036c1f406af7c47722b209f23bd2f2d6ac21423c8c73bd92cf28409ee2;
#[derive(Copy, Drop, Hash)]
struct Message {
Expand Down

0 comments on commit a1c95a3

Please sign in to comment.