@fystack/sdk 0.1.0

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.
@@ -0,0 +1,611 @@
1
+ import { AbstractSigner, Provider, TransactionResponse, TypedDataDomain, TypedDataField } from 'ethers';
2
+ import { TransactionRequest } from 'ethers/src.ts/providers';
3
+
4
+ declare class TransactionError extends Error {
5
+ readonly code: string;
6
+ readonly transactionId?: string | undefined;
7
+ readonly originalError?: Error | undefined;
8
+ constructor(message: string, code: string, transactionId?: string | undefined, originalError?: Error | undefined);
9
+ }
10
+ declare enum TxStatus {
11
+ Pending = "pending",
12
+ Completed = "completed",
13
+ Confirmed = "confirmed",
14
+ Failed = "failed",
15
+ PendingApproval = "pending_approval",
16
+ Rejected = "rejected"
17
+ }
18
+ declare enum TxApprovalStatus {
19
+ Pending = "pending",
20
+ Approved = "approved",
21
+ Rejected = "rejected"
22
+ }
23
+ interface APICredentials {
24
+ apiKey: string;
25
+ apiSecret: string;
26
+ }
27
+ interface WebhookEvent {
28
+ webhook_id: string;
29
+ resource_id: string;
30
+ url: string;
31
+ payload: any;
32
+ event: string;
33
+ }
34
+ interface SignRequestParams {
35
+ method: string;
36
+ message: string;
37
+ chain_id: number;
38
+ typed_data?: string;
39
+ }
40
+ interface SignResponse {
41
+ transaction_id: string;
42
+ }
43
+ interface SignatureStatusResponse {
44
+ status: TxStatus;
45
+ signature?: string;
46
+ transaction_id: string;
47
+ created_at: string;
48
+ updated_at: string;
49
+ approvals: Array<{
50
+ user_id: string;
51
+ status: TxApprovalStatus;
52
+ }>;
53
+ }
54
+ interface ApprovalInfo {
55
+ user_id: string;
56
+ status: TxApprovalStatus;
57
+ }
58
+ interface TransactionStatusResponse {
59
+ transaction_id: string;
60
+ status: TxStatus;
61
+ method: string;
62
+ hash?: string;
63
+ created_at: string;
64
+ updated_at: string;
65
+ approvals: ApprovalInfo[];
66
+ failed_reason?: string;
67
+ }
68
+ declare enum WalletType {
69
+ Standard = "standard",
70
+ MPC = "mpc"
71
+ }
72
+ interface CreateWalletOptions {
73
+ name: string;
74
+ walletType: WalletType;
75
+ }
76
+ declare enum WalletCreationStatus {
77
+ Pending = "pending",
78
+ Success = "success",
79
+ Error = "error"
80
+ }
81
+ interface CreateWalletResponse {
82
+ wallet_id: string;
83
+ status: WalletCreationStatus;
84
+ }
85
+ interface WalletCreationStatusResponse {
86
+ wallet_id: string;
87
+ status: WalletCreationStatus;
88
+ }
89
+ interface WalletAssetNetwork {
90
+ id: string;
91
+ created_at: string;
92
+ updated_at: string;
93
+ name: string;
94
+ description?: string;
95
+ is_evm: boolean;
96
+ chain_id: number;
97
+ native_currency: string;
98
+ is_testnet?: boolean;
99
+ internal_code: string;
100
+ explorer_tx: string;
101
+ explorer_address: string;
102
+ explorer_token: string;
103
+ confirmation_blocks: number;
104
+ block_interval_in_seconds: number;
105
+ disabled: boolean;
106
+ logo_url: string;
107
+ }
108
+ interface WalletAssetDetail {
109
+ id: string;
110
+ created_at: string;
111
+ updated_at: string;
112
+ name: string;
113
+ symbol: string;
114
+ decimals: number;
115
+ logo_url: string;
116
+ is_native: boolean;
117
+ address_type: string;
118
+ is_whitelisted: boolean;
119
+ address?: string;
120
+ network_id: string;
121
+ network?: WalletAssetNetwork;
122
+ }
123
+ interface WalletAsset {
124
+ id: string;
125
+ created_at: string;
126
+ updated_at: string;
127
+ wallet_id: string;
128
+ asset_id: string;
129
+ deposit_address: string;
130
+ hidden: boolean;
131
+ asset: WalletAssetDetail;
132
+ }
133
+ declare enum AddressType {
134
+ Evm = "evm",
135
+ Solana = "sol"
136
+ }
137
+ interface DepositAddressResponse {
138
+ asset_id?: string;
139
+ address: string;
140
+ qr_code: string;
141
+ }
142
+
143
+ declare enum Environment {
144
+ Local = "local",
145
+ Sandbox = "sandbox",
146
+ Production = "production"
147
+ }
148
+ interface APIEndpoints {
149
+ signTransaction: (walletId: string) => string;
150
+ requestSign: (walletId: string) => string;
151
+ getSignStatus: (walletId: string, transactionId: string) => string;
152
+ getTransactionStatus: (walletId: string, transactionId: string) => string;
153
+ getWalletDetail: (walletId?: string) => string;
154
+ createWallet: () => string;
155
+ createCheckout: () => string;
156
+ getCheckout: (checkoutId: string) => string;
157
+ createCheckoutPayment: (checkoutId: string) => string;
158
+ getCheckoutPayment: (checkoutId: string) => string;
159
+ getWalletCreationStatus: (walletId: string) => string;
160
+ getWalletAssets: (walletId: string) => string;
161
+ getDepositAddress: (walletId: string, addressType: string) => string;
162
+ }
163
+ interface APIConfig {
164
+ baseURL: string;
165
+ endpoints: APIEndpoints;
166
+ }
167
+ declare const createAPI: (env: Environment) => APIConfig;
168
+
169
+ interface SDKOptions {
170
+ credentials: APICredentials;
171
+ environment?: Environment;
172
+ logger?: boolean;
173
+ }
174
+ declare class FystackSDK {
175
+ private apiService;
176
+ private enableLogging;
177
+ constructor(options: SDKOptions);
178
+ private log;
179
+ /**
180
+ * Creates a new wallet
181
+ * @param options Wallet creation options
182
+ * @param waitForCompletion Whether to wait for the wallet creation to complete
183
+ * @returns Promise with wallet ID and status
184
+ */
185
+ createWallet(options: CreateWalletOptions, waitForCompletion?: boolean): Promise<CreateWalletResponse>;
186
+ /**
187
+ * Gets the current status of a wallet creation process
188
+ * @param walletId The ID of the wallet being created
189
+ * @returns Promise with wallet creation status details
190
+ */
191
+ getWalletCreationStatus(walletId: string): Promise<WalletCreationStatusResponse>;
192
+ /**
193
+ * Waits for a wallet to be created and returns the final status
194
+ * @param walletId The ID of the wallet being created
195
+ * @returns Promise with wallet ID and final status
196
+ */
197
+ private waitForWalletCreation;
198
+ /**
199
+ * Gets assets associated with a wallet
200
+ * @param walletId The ID of the wallet
201
+ * @returns Promise with wallet assets
202
+ */
203
+ getWalletAssets(walletId: string): Promise<WalletAsset[]>;
204
+ /**
205
+ * Gets deposit address for a wallet by address type
206
+ * @param walletId The wallet ID
207
+ * @param addressType The type of address (evm, sol)
208
+ * @returns Promise with deposit address information
209
+ */
210
+ getDepositAddress(walletId: string, addressType: AddressType): Promise<DepositAddressResponse>;
211
+ }
212
+
213
+ interface StatusPollerOptions {
214
+ maxAttempts?: number;
215
+ interval?: number;
216
+ backoffFactor?: number;
217
+ maxInterval?: number;
218
+ timeoutMs?: number;
219
+ }
220
+ declare const DEFAULT_POLLER_OPTIONS: StatusPollerOptions;
221
+ declare class StatusPoller {
222
+ private startTime;
223
+ private attempts;
224
+ private currentInterval;
225
+ private readonly options;
226
+ constructor(options?: StatusPollerOptions);
227
+ private wait;
228
+ private shouldContinue;
229
+ poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
230
+ }
231
+
232
+ declare class ApexSigner extends AbstractSigner {
233
+ private address;
234
+ private APICredentials;
235
+ private APIService;
236
+ private walletDetail;
237
+ private environment;
238
+ private pollerOptions?;
239
+ constructor(credentials: APICredentials, environment: Environment, provider?: null | Provider, pollerOptions?: StatusPollerOptions);
240
+ setWallet(walletId: string): void;
241
+ getAddress(): Promise<string>;
242
+ private getChainId;
243
+ connect(provider: null | Provider): ApexSigner;
244
+ private waitForSignature;
245
+ private waitForTransactonStatus;
246
+ signTransaction(tx: TransactionRequest): Promise<string>;
247
+ sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
248
+ signMessage(message: string | Uint8Array): Promise<string>;
249
+ signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
250
+ }
251
+
252
+ declare class SolanaSigner {
253
+ private address;
254
+ private APIService;
255
+ private APIKey;
256
+ private walletDetail;
257
+ private pollerOptions?;
258
+ constructor(credentials: APICredentials, environment: Environment, pollerOptions?: StatusPollerOptions);
259
+ setWallet(walletId: string): void;
260
+ getAddress(): Promise<string>;
261
+ private waitForTransactionStatus;
262
+ /**
263
+ * Signs a Solana transaction
264
+ * @param transaction Base64 encoded serialized transaction
265
+ * @returns Signature as a base58 encoded string
266
+ */
267
+ signTransaction(transaction: string): Promise<string>;
268
+ /**
269
+ * Signs a Solana message
270
+ * @param message The message to sign (string or Uint8Array)
271
+ * @returns Signature as a base58 encoded string
272
+ */
273
+ signMessage(message: string | Uint8Array): Promise<string>;
274
+ /**
275
+ * Signs and sends a Solana transaction
276
+ * @param transaction Base64 encoded serialized transaction
277
+ * @returns Transaction signature
278
+ */
279
+ signAndSendTransaction(transaction: string): Promise<string>;
280
+ /**
281
+ * Signs multiple Solana transactions
282
+ * @param transactions Array of base64 encoded serialized transactions
283
+ * @returns Array of signatures as base58 encoded strings
284
+ */
285
+ signAllTransactions(transactions: string[]): Promise<{
286
+ transactions: string[];
287
+ }>;
288
+ private incorporateSignatureIntoTransaction;
289
+ }
290
+
291
+ interface Network {
292
+ id: string;
293
+ created_at: string;
294
+ updated_at: string;
295
+ name: string;
296
+ description: string;
297
+ is_evm: boolean;
298
+ chain_id: number;
299
+ native_currency: string;
300
+ is_testnet: boolean;
301
+ internal_code: string;
302
+ explorer_tx: string;
303
+ explorer_address: string;
304
+ explorer_token: string;
305
+ confirmation_blocks: number;
306
+ block_interval_in_seconds: number;
307
+ disabled: boolean;
308
+ logo_url: string;
309
+ }
310
+ interface Asset {
311
+ id: string;
312
+ created_at: string;
313
+ updated_at: string;
314
+ name: string;
315
+ symbol: string;
316
+ decimals: number;
317
+ logo_url: string;
318
+ is_native: boolean;
319
+ address_type: 'evm';
320
+ is_whitelisted: boolean;
321
+ address?: string;
322
+ network_id: string;
323
+ network?: Network;
324
+ }
325
+ interface CreateCheckoutPayload {
326
+ price: string;
327
+ currency: string;
328
+ supported_assets: string[];
329
+ underpaid_cover_percent?: number;
330
+ description?: string;
331
+ success_url?: string;
332
+ cancel_url?: string;
333
+ product_id?: string;
334
+ customer_id?: string;
335
+ order_id?: string;
336
+ enable_localization?: boolean;
337
+ destination_wallet_id: string;
338
+ from_address?: string;
339
+ expiry_duration_seconds: number;
340
+ }
341
+ /**
342
+ * Represents the payload required to create a checkout payment.
343
+ */
344
+ interface CreateCheckoutPaymentPayload {
345
+ /**
346
+ * Customer's email address.
347
+ *
348
+ * - This field is **optional**.
349
+ * - If provided, it must be a valid email format.
350
+ */
351
+ customer_email?: string;
352
+ /**
353
+ * Unique identifier of the asset used for payment.
354
+ *
355
+ * - This field is **required**.
356
+ * - Must be a **UUIDv4**.
357
+ */
358
+ pay_asset_id: string;
359
+ }
360
+ interface CreateCheckoutResponse {
361
+ id: string;
362
+ created_at: string;
363
+ updated_at: string;
364
+ currency: string;
365
+ product_id: string;
366
+ order_id: string;
367
+ workspace_id: string;
368
+ underpaid_cover_percent: number;
369
+ description: string;
370
+ price: string;
371
+ supported_assets: Array<{
372
+ id: string;
373
+ created_at: string;
374
+ updated_at: string;
375
+ is_native: boolean;
376
+ is_whitelisted: boolean;
377
+ }>;
378
+ customer_id: string;
379
+ expiry_duration_seconds: number;
380
+ enable_localization: boolean;
381
+ success_url: string;
382
+ cancel_url: string;
383
+ status: string;
384
+ outcome: any;
385
+ from_address: string;
386
+ }
387
+ declare enum PaymentStatus {
388
+ Pending = "Pending",
389
+ Confirming = "Confirming",
390
+ Success = "Success"
391
+ }
392
+ interface SupportedAsset {
393
+ id: string;
394
+ created_at: string;
395
+ updated_at: string;
396
+ name: string;
397
+ symbol: string;
398
+ decimals: number;
399
+ logo_url: string;
400
+ is_native: boolean;
401
+ address_type: 'evm';
402
+ is_whitelisted: boolean;
403
+ address?: string;
404
+ network_id: string;
405
+ network: {
406
+ id: string;
407
+ created_at: string;
408
+ updated_at: string;
409
+ name: string;
410
+ description: string;
411
+ is_evm: boolean;
412
+ chain_id: number;
413
+ native_currency: string;
414
+ is_testnet: boolean;
415
+ internal_code: string;
416
+ explorer_tx: string;
417
+ explorer_address: string;
418
+ explorer_token: string;
419
+ confirmation_blocks: number;
420
+ block_interval_in_seconds: number;
421
+ disabled: boolean;
422
+ logo_url: string;
423
+ };
424
+ }
425
+ interface GetCheckoutResponse {
426
+ id: string;
427
+ created_at: string;
428
+ updated_at: string;
429
+ currency: string;
430
+ product_id: string;
431
+ order_id: string;
432
+ workspace_id: string;
433
+ underpaid_cover_percent: number;
434
+ description: string;
435
+ price: string;
436
+ supported_assets: SupportedAsset[];
437
+ customer_id: string;
438
+ expiry_duration_seconds: number;
439
+ enable_localization: boolean;
440
+ success_url: string;
441
+ cancel_url: string;
442
+ status: PaymentStatus;
443
+ outcome?: string | null;
444
+ from_address: string;
445
+ }
446
+ /**
447
+ * Represents the response structure for a checkout payment.
448
+ */
449
+ interface CreateCheckoutPaymentResponse {
450
+ /**
451
+ * Unique identifier of the payment.
452
+ */
453
+ id: string;
454
+ /**
455
+ * Timestamp when the payment was created (ISO 8601 format).
456
+ */
457
+ created_at: string;
458
+ /**
459
+ * Timestamp when the payment was last updated (ISO 8601 format).
460
+ */
461
+ updated_at: string;
462
+ /**
463
+ * Unique identifier of the associated checkout.
464
+ */
465
+ checkout_id: string;
466
+ /**
467
+ * Details of the associated checkout (if available).
468
+ * Can be `null` if no data is linked.
469
+ */
470
+ checkout: any | null;
471
+ /**
472
+ * Customer's email address (if provided).
473
+ * Can be `null` if not available.
474
+ */
475
+ customer_email: string | null;
476
+ /**
477
+ * Unique identifier of the asset used for payment.
478
+ */
479
+ pay_asset_id: string;
480
+ /**
481
+ * Unique identifier of the blockchain network used for the transaction.
482
+ */
483
+ network_id: string;
484
+ /**
485
+ * Details of the associated blockchain network (if available).
486
+ * Can be `null` if no data is linked.
487
+ */
488
+ network: any | null;
489
+ /**
490
+ * Timestamp when the payment expires (ISO 8601 format).
491
+ */
492
+ expired_at: string;
493
+ /**
494
+ * Blockchain address of the payer (if available).
495
+ * Can be `null` if not yet provided.
496
+ */
497
+ payer_address: string | null;
498
+ /**
499
+ * Hash of the blockchain transaction (if completed).
500
+ * Can be `null` if the transaction has not been broadcasted yet.
501
+ */
502
+ tx_hash: string | null;
503
+ /**
504
+ * The amount of cryptocurrency required for the payment,
505
+ * converted to the selected payment asset.
506
+ */
507
+ converted_crypto_price: string;
508
+ /**
509
+ * The blockchain address where the customer should send the payment.
510
+ */
511
+ deposit_address: string;
512
+ /**
513
+ * QR code (as a string) representing the deposit address for easy payment.
514
+ * Could be an empty string if not generated.
515
+ */
516
+ deposit_qr: string;
517
+ }
518
+ interface GetCheckoutPaymentResponse {
519
+ id: string;
520
+ created_at: string;
521
+ updated_at: string;
522
+ checkout_id: string;
523
+ checkout: GetCheckoutResponse;
524
+ customer_email?: string | null;
525
+ pay_asset_id: string;
526
+ pay_asset: Asset;
527
+ network_id: string;
528
+ network: Network;
529
+ expired_at: string;
530
+ payer_address?: string | null;
531
+ tx_hash?: string | null;
532
+ converted_crypto_price: string;
533
+ deposit_address: string;
534
+ deposit_qr: string;
535
+ }
536
+
537
+ interface APIResponse {
538
+ data: any;
539
+ success: boolean;
540
+ message?: string;
541
+ }
542
+ interface HMACParams {
543
+ method: string;
544
+ path: string;
545
+ timestamp: string;
546
+ body?: string;
547
+ }
548
+ interface WalletDetail {
549
+ APIKey: string;
550
+ WalletID: string;
551
+ Name: string;
552
+ AddressType: string;
553
+ Address: string;
554
+ }
555
+ interface CreateWalletPayload {
556
+ name: string;
557
+ walletType: WalletType;
558
+ }
559
+ interface PaymentServiceParams {
560
+ apiKey: string;
561
+ environment: Environment;
562
+ }
563
+ declare enum WalletAddressType {
564
+ Evm = "evm",
565
+ Sol = "sol"
566
+ }
567
+ declare class APIService {
568
+ private credentials;
569
+ Webhook: WebhookService;
570
+ private API;
571
+ constructor(credentials: APICredentials, environment: Environment);
572
+ getWalletDetail(addressType?: WalletAddressType, walletId?: string): Promise<WalletDetail>;
573
+ requestSign(walletId: string, params: SignRequestParams): Promise<SignResponse>;
574
+ getSignStatus(walletId: string, transactionId: string): Promise<SignatureStatusResponse>;
575
+ signTransaction(walletId: string, body: Record<string, any>): Promise<SignResponse>;
576
+ getTransactionStatus(walletId: string, transactionId: string): Promise<TransactionStatusResponse>;
577
+ createWallet(payload: CreateWalletPayload): Promise<CreateWalletResponse>;
578
+ createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse>;
579
+ getWalletCreationStatus(walletId: string): Promise<WalletCreationStatusResponse>;
580
+ getWalletAssets(walletId: string): Promise<WalletAsset[]>;
581
+ /**
582
+ * Gets deposit address for a wallet by address type
583
+ * @param walletId The wallet ID
584
+ * @param addressType The type of address (evm, sol)
585
+ * @returns Deposit address response
586
+ */
587
+ getDepositAddress(walletId: string, addressType: AddressType): Promise<DepositAddressResponse>;
588
+ }
589
+ declare class PaymentService {
590
+ private apiKey;
591
+ private API;
592
+ constructor(params: PaymentServiceParams);
593
+ createCheckout(payload: CreateCheckoutPayload): Promise<CreateCheckoutResponse>;
594
+ getCheckout(checkoutId: string): Promise<GetCheckoutResponse>;
595
+ createCheckoutPayment(checkoutId: string, payload: CreateCheckoutPaymentPayload): Promise<CreateCheckoutPaymentResponse>;
596
+ getCheckoutPayment(checkoutId: string): Promise<GetCheckoutPaymentResponse>;
597
+ }
598
+ declare class WebhookService {
599
+ private credentials;
600
+ constructor(credentials: APICredentials);
601
+ verifyEvent(event: WebhookEvent, signature: string): Promise<boolean>;
602
+ }
603
+ declare function get(endpoint: string, headers?: Record<string, string>): Promise<APIResponse>;
604
+ declare function post(endpoint: string, body: any, headers?: Record<string, string>): Promise<APIResponse>;
605
+ declare function transformWalletDetail(data: Record<string, string>): WalletDetail;
606
+ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
607
+ name: string;
608
+ wallet_type: WalletType;
609
+ };
610
+
611
+ export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, ApexSigner, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, FystackSDK, type HMACParams, PaymentService, type PaymentServiceParams, type SDKOptions, type SignRequestParams, type SignResponse, type SignatureStatusResponse, SolanaSigner, StatusPoller, type StatusPollerOptions, TransactionError, type TransactionStatusResponse, TxApprovalStatus, TxStatus, WalletAddressType, type WalletAsset, type WalletAssetDetail, type WalletAssetNetwork, WalletCreationStatus, type WalletCreationStatusResponse, type WalletDetail, WalletType, type WebhookEvent, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@fystack/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Wallet SDK",
5
+ "main": "dist/index.cjs",
6
+ "types": "dist/types/index.d.ts",
7
+ "exports": {
8
+ "module": "./dist/index.esm.js",
9
+ "import": "./dist/index.mjs",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "scripts": {
13
+ "test": "npx vitest",
14
+ "build": "bunchee",
15
+ "prepub": "npm run build",
16
+ "pub": "npm publish --access public"
17
+ },
18
+ "author": "anhthii",
19
+ "license": "ISC",
20
+ "devDependencies": {
21
+ "@types/crypto-js": "^4.2.2",
22
+ "bunchee": "^4.4.8",
23
+ "vitest": "^1.2.2"
24
+ },
25
+ "dependencies": {
26
+ "@solana/web3.js": "^1.98.0",
27
+ "bs58": "^6.0.0",
28
+ "buffer": "^6.0.3",
29
+ "cross-fetch": "^4.0.0",
30
+ "crypto-js": "^4.2.0",
31
+ "ethers": "^6.10.0",
32
+ "rpc-websockets": "^10.0.0"
33
+ },
34
+ "directories": {
35
+ "test": "test"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/cryptoniumX/wallet-sdk.git"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/cryptoniumX/wallet-sdk/issues"
43
+ },
44
+ "homepage": "https://github.com/cryptoniumX/wallet-sdk#readme"
45
+ }