@fystack/sdk 0.1.7 → 0.1.9

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/src/types.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import { SweepTaskParams } from './api'
2
- import { TxApprovalStatus, TxStatus, WalletCreationStatus, WalletPurpose, WalletRole, WalletType } from './enum'
2
+ import {
3
+ TxApprovalStatus,
4
+ TxStatus,
5
+ WalletCreationStatus,
6
+ WalletPurpose,
7
+ WalletRole,
8
+ WalletType,
9
+ WithdrawalStatus
10
+ } from './enum'
3
11
 
4
12
  export class TransactionError extends Error {
5
13
  constructor(
@@ -165,3 +173,61 @@ export interface WalletByWorkspaceResponse {
165
173
  top_assets: TopAssets[]
166
174
  wallet_purpose: string
167
175
  }
176
+
177
+ export interface RequestWithdrawalParams {
178
+ assetId: string
179
+ amount: string
180
+ recipientAddress: string
181
+ notes?: string
182
+ skipBalanceCheck?: boolean
183
+ }
184
+
185
+ export interface WithdrawalApproval {
186
+ id: string
187
+ user_id: string
188
+ status: string
189
+ created_at: string
190
+ updated_at: string
191
+ }
192
+
193
+ export interface WithdrawalTransaction {
194
+ id: string
195
+ hash?: string
196
+ status: string
197
+ created_at: string
198
+ updated_at: string
199
+ }
200
+
201
+ export interface TxCategory {
202
+ id: string
203
+ name: string
204
+ }
205
+
206
+ export interface Withdrawal {
207
+ id: string
208
+ created_at: string
209
+ updated_at: string
210
+ amount: string
211
+ status: WithdrawalStatus
212
+ recipient_address: string
213
+ notes?: string
214
+ withdrawal_approvals: WithdrawalApproval[]
215
+ creator_id: string
216
+ asset_id: string
217
+ asset?: WalletAssetDetail
218
+ wallet_id: string
219
+ transaction_id?: string
220
+ transaction?: WithdrawalTransaction
221
+ asset_hold_id: string
222
+ error_reason?: string
223
+ categories?: TxCategory[]
224
+ }
225
+
226
+ export interface RequestWithdrawalResponse {
227
+ auto_approved: boolean
228
+ withdrawal: Withdrawal
229
+ }
230
+
231
+ export interface WebhookPublicKeyResponse {
232
+ public_key: string // base64 encoded ed25519 public key
233
+ }
package/test.js ADDED
@@ -0,0 +1,76 @@
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)