EIP 712
Definition
Zabi supports hashing and encoding of EIP712 typed data according to the EIP712 Specification
Usage hashTypedData
This takes in 5 arguments.
- an allocator used to manage all memory allocations
- a set of EIP712 types.
- the primary type to hash against
- the domain data. This can be null if you don't have it.
- the message with the values that will be encoded and hashed
hash_typed_data.zig
const hash = try hashTypedData(
testing.allocator,
types,
"Mail",
domain,
message
);
const hex = try std.fmt.allocPrint(testing.allocator, "0x{s}", .{std.fmt.fmtSliceHexLower(&hash)});
defer testing.allocator.free(hex);
try testing.expectEqualStrings("0xbe609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2", hex);
Returns
Type: []u8
-> This is not hex encoded
Usage hashStruct
This takes in 4 arguments.
- an allocator used to manage all memory allocations
- a set of EIP712 types.
- the primary type to hash against
- the message with the values that will be encoded and hashed
hash_typed_data.zig
const hash = try hashStruct(
testing.allocator,
types,
"Mail",
message
);
const hex = try std.fmt.allocPrint(testing.allocator, "0x{s}", .{std.fmt.fmtSliceHexLower(&hash)});
defer testing.allocator.free(hex);
try testing.expectEqualStrings("0xc52c0ee5d84264471806290a3f2c4cecfc5490626bf912d01f240d7a274b371e", hex);
Returns
Type: []u8
-> This is not hex encoded