@fystack/sdk 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test.js DELETED
@@ -1,76 +0,0 @@
1
- import { TypedDataEncoder, verifyTypedData, Signature } from 'ethers'
2
-
3
- // 0x2f71f2595162eaca40708bf6d6327d437e760b27d26f3a933389ebdb4eedf3b167008df6f1d403503c82a6d58da5659b14c578019603d6b138b2c03729c92af701
4
- // 0xd77d10c530b25d1ea6a466eb2b3169138b5ca0d1320ff54bbad000d97f686d0a314c5233844d84da5adf3580afa38c82d9595c22a985acfea02ca722c55df48a00
5
- // Example usage
6
- const address = '0xFFe120Fd4D5AB5A9f25b25c30620ac8ee3E1EF21'
7
- const jsonData = {
8
- domain: {
9
- name: 'Permit2',
10
- chainId: '8453',
11
- verifyingContract: '0x000000000022d473030f116ddee9f6b43ac78ba3'
12
- },
13
- types: {
14
- PermitSingle: [
15
- { name: 'details', type: 'PermitDetails' },
16
- { name: 'spender', type: 'address' },
17
- { name: 'sigDeadline', type: 'uint256' }
18
- ],
19
- PermitDetails: [
20
- { name: 'token', type: 'address' },
21
- { name: 'amount', type: 'uint160' },
22
- { name: 'expiration', type: 'uint48' },
23
- { name: 'nonce', type: 'uint48' }
24
- ]
25
- },
26
- message: {
27
- details: {
28
- token: '0x0b3e328455c4059eeb9e3f84b5543f74e24e7e1b',
29
- amount: '1461501637330902918203684832716283019655932542975',
30
- expiration: '1743496074',
31
- nonce: '0'
32
- },
33
- spender: '0x6ff5693b99212da76ad316178a184ab56d299b43',
34
- sigDeadline: '1740905874'
35
- }
36
- }
37
- const signature =
38
- '0x032f29648f9c2d9d2524aef755c225b96121f2c9b01beee5869a70ef95eb089548dc41f71126dac83c1632738dbea12bf5c925715068e32dda0064701bfc019e00'
39
-
40
- async function verifySignature(address, jsonData, signature) {
41
- try {
42
- // Step 1: Compute the EIP-712 hash
43
- const computedHash = TypedDataEncoder.hash(jsonData.domain, jsonData.types, jsonData.message)
44
- console.log('🔹 Computed EIP-712 Hash:', computedHash)
45
-
46
- // Step 2: Recover the signer address
47
- const recoveredAddress = verifyTypedData(
48
- jsonData.domain,
49
- jsonData.types,
50
- jsonData.message,
51
- signature
52
- )
53
-
54
- console.log('✅ Recovered Address:', recoveredAddress)
55
- console.log('🔹 Expected Address:', address)
56
-
57
- // Step 3: Compare the addresses
58
- const isValid = recoveredAddress.toLowerCase() === address.toLowerCase()
59
- console.log('🔹 Is Signature Valid?', isValid)
60
-
61
- // Step 4: Debug signature parts (r, s, v)
62
- const sig = Signature.from(signature)
63
- console.log('🔹 Signature Parts:')
64
- console.log(' r:', sig.r)
65
- console.log(' s:', sig.s)
66
- console.log(' v:', sig.v)
67
-
68
- return isValid
69
- } catch (error) {
70
- console.error('❌ Signature Verification Failed:', error)
71
- return false
72
- }
73
- }
74
-
75
- // Run verification
76
- verifySignature(address, jsonData, signature)