You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const domain = {
// Defining the chain aka Rinkeby testnet or Ethereum Main Net
chainId: 56,
// Give a user friendly name to the specific contract you are signing for.
name: 'da.systems',
// // If name isn't enough add verifying contract to make sure you are establishing contracts with the proper entity
verifyingContract: '0x0000000000000000000000000000000020210722',
// // Just let's you know the latest version. Definitely make sure the field name is correct.
version: '1',
};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Use metamask and ethers.js to generate inconsistent results. How can I resolve this?
const { signTypedData, SignTypedDataVersion } = require("@metamask/eth-sig-util");
const ethers = require("ethers");
const domain = {
// Defining the chain aka Rinkeby testnet or Ethereum Main Net
chainId: 56,
// Give a user friendly name to the specific contract you are signing for.
name: 'da.systems',
// // If name isn't enough add verifying contract to make sure you are establishing contracts with the proper entity
verifyingContract: '0x0000000000000000000000000000000020210722',
// // Just let's you know the latest version. Definitely make sure the field name is correct.
version: '1',
};
const types = {
"Transaction": [
{
"name": "DAS_MESSAGE",
"type": "string"
},
{
"name": "inputsCapacity",
"type": "string"
},
{
"name": "outputsCapacity",
"type": "string"
},
{
"name": "fee",
"type": "string"
},
{
"name": "action",
"type": "Action"
},
{
"name": "inputs",
"type": "Cell[]"
},
{
"name": "outputs",
"type": "Cell[]"
},
{
"name": "digest",
"type": "bytes32"
}
],
"Action": [
{
"name": "action",
"type": "string"
},
{
"name": "params",
"type": "string"
}
],
"Cell": [
{
"name": "capacity",
"type": "string"
},
{
"name": "lock",
"type": "string"
},
{
"name": "type",
"type": "string"
},
{
"name": "data",
"type": "string"
},
{
"name": "extraData",
"type": "string"
}
]
};
const types2 = {
"EIP712Domain": [
{
"name": "chainId",
"type": "uint256"
},
{
"name": "name",
"type": "string"
},
{
"name": "verifyingContract",
"type": "address"
},
{
"name": "version",
"type": "string"
}
],
"Action": [
{
"name": "action",
"type": "string"
},
{
"name": "params",
"type": "string"
}
],
"Cell": [
{
"name": "capacity",
"type": "string"
},
{
"name": "lock",
"type": "string"
},
{
"name": "type",
"type": "string"
},
{
"name": "data",
"type": "string"
},
{
"name": "extraData",
"type": "string"
}
],
"Transaction": [
{
"name": "DAS_MESSAGE",
"type": "string"
},
{
"name": "inputsCapacity",
"type": "string"
},
{
"name": "outputsCapacity",
"type": "string"
},
{
"name": "fee",
"type": "string"
},
{
"name": "action",
"type": "Action"
},
{
"name": "inputs",
"type": "Cell[]"
},
{
"name": "outputs",
"type": "Cell[]"
},
{
"name": "digest",
"type": "bytes32"
}
]
};
const privateKey = Buffer.from(
"9af0e6fcc9c1cd750d8bc98c27d2b32e4df86781e5ccefc1e11f75b8010ec442",
"hex"
);
const signature2 = signTypedData({
privateKey,
data: {
types: types2,
primaryType: "Transaction",
domain,
message: {
"DAS_MESSAGE": "TRANSFER FROM 0x491fcb31a14c8b8058d450fda54d1b7710c400da(4999.99 CKB) TO ckb1qyqxmyfg2a5w0jt0rn4qzu7gzead5t87405qs8cqan(1402.5 CKB), 0x491fcb31a14c8b8058d450fda54d1b7710c400da(3597.489973 CKB)",
"inputsCapacity": "4999.99 CKB",
"outputsCapacity": "4999.989973 CKB",
"fee": "0.000027 CKB",
"digest": "0xafd41c1971eef452eed5b2921c92e61fac152f6759235c95fd2f33a9e3be9440",
"action": {
"action": "transfer",
"params": "0x00"
},
"inputs": [],
"outputs": []
},
},
version: SignTypedDataVersion.V4,
});
console.log("Metamask sig utils generated signature", signature2);
const wallet = new ethers.Wallet(privateKey);
wallet
._signTypedData(domain, types, {
"DAS_MESSAGE": "TRANSFER FROM 0x491fcb31a14c8b8058d450fda54d1b7710c400da(4999.99 CKB) TO ckb1qyqxmyfg2a5w0jt0rn4qzu7gzead5t87405qs8cqan(1402.5 CKB), 0x491fcb31a14c8b8058d450fda54d1b7710c400da(3597.489973 CKB)",
"inputsCapacity": "4999.99 CKB",
"outputsCapacity": "4999.989973 CKB",
"fee": "0.000027 CKB",
"digest": "0xafd41c1971eef452eed5b2921c92e61fac152f6759235c95fd2f33a9e3be9440",
"action": {
"action": "transfer",
"params": "0x00"
},
"inputs": [],
"outputs": []
})
.then((signature) => {
console.log("Ether js _signTypedData", signature);
});
Beta Was this translation helpful? Give feedback.
All reactions