-
-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
like this
export default {
domain: {
// Defining the chain aka Rinkeby testnet or Ethereum Main Net
chainId: 1,
// Give a user friendly name to the specific contract you are signing for.
name: "Ether Mail",
// If name isn't enough add verifying contract to make sure you are establishing contracts with the proper entity
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
// Just let's you know the latest version. Definitely make sure the field name is correct.
version: "1"
},
// Defining the message signing data content.
message: {
/*
- Anything you want. Just a JSON Blob that encodes the data you want to send
- No required fields
- This is DApp Specific
- Be as explicit as possible when building out the message schema.
*/
contents: "Hello, Bob!",
attachedMoneyInEth: 4.2,
from: {
name: "Cow",
wallets: [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"
]
},
to: [
{
name: "Bob",
wallets: [
"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
"0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57",
"0xB0B0b0b0b0b0B000000000000000000000000000"
]
}
]
},
// Refers to the keys of the *types* object below.
primaryType: "Mail",
types: {
// TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" }
],
// Not an EIP712Domain definition
Group: [
{ name: "name", type: "string" },
{ name: "members", type: "Person[]" }
],
// Refer to PrimaryType
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person[]" },
{ name: "contents", type: "string" }
],
// Not an EIP712Domain definition
Person: [
{ name: "name", type: "string" },
{ name: "wallets", type: "address[]" }
]
}
};online test https://codesandbox.io/p/sandbox/eth-signtypeddata-v4-335wo?file=%2Fsrc%2FtypedDataV4.js%3A1%2C1-69%2C1
MyTestCode:
procedure TForm12.Button6Click(Sender: TObject);
begin
const typedData = TTypedData.Create;
try
typedData.types.Add('Person',
[
TType.Create('name', 'string'),
TType.Create('wallet', 'address[]')
]);
typedData.types.Add('Group',
[
TType.Create('name', 'string'),
TType.Create('members', 'Person[]')
]);
typedData.types.Add('Mail',
[
TType.Create('from', 'Person'),
TType.Create('to', 'Person[]'),
TType.Create('contents', 'string')
]);
typedData.PrimaryType := 'Mail';
typedData.Domain.Name := 'Ether Mail';
typedData.Domain.Version := '1';
typedData.Domain.ChainId := 1;
typedData.Domain.VerifyingContract := '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC';
typedData.Message.Add('from', newTypedMessage.Add('name', 'Cow').Add('wallet', VarArrayOf(['0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826', '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF'])));
typedData.Message.Add('to', newTypedMessage.Add('name', 'Bob').Add('wallet', VarArrayOf(['0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB', '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57', '0xB0B0b0b0b0b0B000000000000000000000000000'])));
typedData.Message.Add('contents', 'Hello, Bob!');
typedData.Message.Add('attachedMoneyInEth', 4.2);
const challengeHash = typedData.challengeHash;
if challengeHash.isErr then
memo1.Lines.Add(challengeHash.Error.Message)
else
begin
if web3.utils.toHex(challengeHash.Value) = '0xBE609AEE343FB3C4B28E1DF9E632FCA64FCFAEDE20F02E86244EFDDF30957BD2' then
begin
memo1.Lines.Add('Equal');
end
else
begin
memo1.Lines.Add(web3.utils.toHex(challengeHash.Value));
end;
end;
const signature = web3.eth.eip712.sign(TPrivateKey('8994250F00DB3D85A260D8FDCF2152063938C1F57005928AA7B964197BCC8830'), challengeHash.Value);
if signature.isErr then
memo1.Lines.Add(signature.Error.Message)
else
begin
if '0xF714D2CD123498A5551CAFEE538D073C139C5C237C2D0A98937A5CCE109BFEFB7C6585FED974543C649B0CAE34AC8763EE0AC536A56A82980C14470F0029907B1B' = signature.Value.toHex then
begin
memo1.Lines.Add('Equal');
end
else
begin
memo1.Lines.Add(web3.utils.toHex(challengeHash.Value));
end;
end;
finally
typedData.Free;
end;
end;will couse error
there is extra data provided in the message (3 < 4)
comment typedData.Message.Add('attachedMoneyInEth', 4.2); can work but the result is wrong
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels