-
Notifications
You must be signed in to change notification settings - Fork 16
/
testConfig.js
61 lines (59 loc) · 2.17 KB
/
testConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { verifyMessage } = require('./dist/index')
const { createPublicClient, http } = require('viem')
const { polygon } = require('viem/chains')
const ethers = require('ethers')
/**
* @dev Fn is ran for every provider
* @param {*} t
* @param {(Provider | window.ethereum | PublicClient)[]} providers Web3 Compatible provider
* @param {string} signer The signer address to verify the signature against
* @param {string | Uint8Array} message To verify eth_sign type of signatures. Human-readable message to verify. Message should be a human string or the hex version of the human string encoded as Uint8Array. If a hex string is passed, it will be considered as a regular string
* @param {{domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>}} typedData To verify a 712 signature type. The {domain, type, message} 712 message object
* @param {string} finalDigest The final digest to verify. dApp will have to pre-compute the hash as no hashing transformation will occur and this digest will be directly used for recoverAddress and isValidSignature
* @param {string | Uint8Array} signature The signature to verify as a hex string or Uint8Array
* NOTE: you only need to pass one of: typedData, finalDigest, message
*/
const verifySignature = async ({
t,
providers,
signer,
message,
typedData,
finalDigest,
signature,
expectedValid,
}) => {
for (const provider of providers) {
try {
const result = await verifyMessage({
provider,
signer,
message,
typedData,
finalDigest,
signature,
})
t.assert(
result === expectedValid,
expectedValid ? 'Valid signature' : 'Detected invalid signature'
)
} catch (e) {
t.error(e, 'Invalid Signature')
}
}
}
module.exports = {
RPC: {
polygon: 'https://polygon-rpc.com',
},
MNEMONIC:
'radar blur cabbage chef fix engine embark joy scheme fiction master release',
defaultPublicClient: createPublicClient({
chain: polygon,
transport: http('https://polygon-rpc.com'),
}),
defaultProvider: new ethers.providers.JsonRpcProvider(
'https://polygon-rpc.com'
),
verifySignature,
}