Last active
November 4, 2021 02:29
-
-
Save JTraversa/b1e1f0e082d0cdccd0c7249595d46de0 to your computer and use it in GitHub Desktop.
sig test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function signOrder() { | |
const currentAddress = `0x3f60008Dfd0EfC03F476D9B489D6C5B13B3eBF2C`; | |
const testOrderHash = web3.sha3(currentAddress); | |
const msgParams = { | |
domain: { | |
name: 'Swivel', | |
version: '1', | |
chainId: 5, | |
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' | |
}, | |
message: { | |
key: testOrderHash, | |
maker: currentAddress, | |
underlying: "0xdc31ee1784292379fbb2964b3b9c4124d8f89c60", | |
floating: false, | |
principal: web3.toWei("100"), | |
interest: web3.toWei("5"), | |
duration: 31536000, | |
expiry: 1615505253, | |
nonce: 1 | |
}, | |
primaryType: 'order', | |
types: { | |
EIP712Domain: [ | |
{ name: 'name', type: 'string' }, | |
{ name: 'version', type: 'string' }, | |
{ name: 'chainId', type: 'uint256' }, | |
{ name: 'verifyingContract', type: 'address' }, | |
], | |
order: [ | |
{ name: 'key', type: 'bytes32' }, | |
{ name: 'maker', type: 'address' }, | |
{ name: 'underlying', type: 'address' }, | |
{ name: 'floating', type: 'bool' }, | |
{ name: 'principal', type: 'uint256' }, | |
{ name: 'interest', type: 'uint256' }, | |
{ name: 'duration', type: 'uint256' }, | |
{ name: 'expiry', type: 'uint256' }, | |
{ name: 'nonce', type: 'uint256' } | |
] | |
}, | |
} | |
try { | |
const signature = await ethereum.request({ | |
method: 'eth_signTypedData_v4', | |
params: [currentAddress, JSON.stringify(msgParams)], | |
}) | |
console.log(signature); | |
const r = "0x" + signature.substring(0, 64); | |
const s = "0x" + signature.substring(64, 128); | |
const v = parseInt(signature.substring(128, 130), 16); | |
console.log(v); | |
console.log(r); | |
console.log(s); | |
} catch (err) { | |
console.error(err); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment