-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Web3 } from 'web3'; | ||
import * as web3Accounts from 'web3-eth-accounts'; | ||
import { utils } from '../../src'; | ||
import * as constants from '../../src/constants'; | ||
import { EIP712Signer } from '../../src/Eip712'; | ||
|
||
describe('utils', () => { | ||
describe('#isTypedDataSignatureCorrect()', () => { | ||
it('should return true if correct', async () => { | ||
const PRIVATE_KEY = | ||
'0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; | ||
const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; | ||
const tx = { | ||
type: 113, | ||
chainId: 270, | ||
from: ADDRESS, | ||
to: '0xa61464658AfeAf65CccaaFD3a512b69A83B77618', | ||
value: 7_000_000n, | ||
}; | ||
const eip712Signer = new EIP712Signer( | ||
web3Accounts.privateKeyToAccount(PRIVATE_KEY), | ||
270, | ||
); | ||
const signature = eip712Signer.sign(tx); | ||
const web3 = new Web3('http://localhost:8545'); | ||
|
||
expect(signature.signature).toBe( | ||
'0x5ea12f3d54a1624d7e7f5161dbf6ab746c3335e643b2966264e740cf8e10e9b64b0251fb79d9a5b11730387085a0d58f105926f72e20242ecb274639991939ca1b', | ||
); | ||
const isValidSignature = await utils.isTypedDataSignatureCorrect( | ||
web3, | ||
ADDRESS, | ||
eip712Signer.getDomain(), | ||
constants.EIP712_TYPES, | ||
utils.EIP712.getSignInput(tx), | ||
signature.signature, | ||
); | ||
expect(isValidSignature).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains 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