@fystack/sdk 0.1.0 → 0.1.1
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/dist/index.cjs +5 -7
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.esm.d.ts +3 -3
- package/dist/index.esm.js +5 -7
- package/dist/index.mjs +5 -7
- package/dist/types/index.d.ts +3 -3
- package/package.json +1 -1
- package/readme.md +200 -0
- package/src/signer.ts +4 -4
- package/src/solanaSigner.ts +1 -4
package/dist/index.cjs
CHANGED
|
@@ -514,7 +514,7 @@ class FystackSDK {
|
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
-
class
|
|
517
|
+
class EtherSigner extends ethers.AbstractSigner {
|
|
518
518
|
setWallet(walletId) {
|
|
519
519
|
if (!walletId || walletId.trim() === '') {
|
|
520
520
|
throw new Error('Invalid wallet ID provided');
|
|
@@ -560,7 +560,7 @@ class ApexSigner extends ethers.AbstractSigner {
|
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
562
|
connect(provider) {
|
|
563
|
-
return new
|
|
563
|
+
return new EtherSigner(this.APICredentials, this.environment, provider);
|
|
564
564
|
}
|
|
565
565
|
async waitForSignature(walletId, transactionId) {
|
|
566
566
|
const poller = new StatusPoller(this.pollerOptions);
|
|
@@ -665,7 +665,7 @@ class ApexSigner extends ethers.AbstractSigner {
|
|
|
665
665
|
// Ensure all properties are properly resolved to their string representations
|
|
666
666
|
const resolvedTx = await ethers.resolveProperties(populatedTx);
|
|
667
667
|
const txObj = ethers.Transaction.from(resolvedTx);
|
|
668
|
-
console.log('
|
|
668
|
+
console.log('[WalletSDK] Tx Data', txObj);
|
|
669
669
|
const txHash = await this.signTransaction(txObj);
|
|
670
670
|
// Instead of creating a mock response, get the actual transaction from the provider
|
|
671
671
|
const endTime = new Date();
|
|
@@ -842,7 +842,7 @@ class SolanaSigner {
|
|
|
842
842
|
data: transaction,
|
|
843
843
|
from: this.address
|
|
844
844
|
};
|
|
845
|
-
// Call the signRaw API similar to
|
|
845
|
+
// Call the signRaw API similar to EtherSigner
|
|
846
846
|
const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
|
|
847
847
|
...data,
|
|
848
848
|
meta: {
|
|
@@ -850,7 +850,6 @@ class SolanaSigner {
|
|
|
850
850
|
},
|
|
851
851
|
chainId: '1399811149'
|
|
852
852
|
});
|
|
853
|
-
console.log('respnpse', response);
|
|
854
853
|
// Wait for the signature
|
|
855
854
|
return this.waitForTransactionStatus(response.transaction_id);
|
|
856
855
|
}
|
|
@@ -868,7 +867,6 @@ class SolanaSigner {
|
|
|
868
867
|
message: messageStr,
|
|
869
868
|
chain_id: 0 // Not used for Solana but required by API
|
|
870
869
|
});
|
|
871
|
-
console.log('Respnse', response);
|
|
872
870
|
return this.waitForTransactionStatus(response.transaction_id);
|
|
873
871
|
}
|
|
874
872
|
/**
|
|
@@ -947,8 +945,8 @@ class SolanaSigner {
|
|
|
947
945
|
}
|
|
948
946
|
|
|
949
947
|
exports.APIService = APIService;
|
|
950
|
-
exports.ApexSigner = ApexSigner;
|
|
951
948
|
exports.DEFAULT_POLLER_OPTIONS = DEFAULT_POLLER_OPTIONS;
|
|
949
|
+
exports.EtherSigner = EtherSigner;
|
|
952
950
|
exports.FystackSDK = FystackSDK;
|
|
953
951
|
exports.PaymentService = PaymentService;
|
|
954
952
|
exports.SolanaSigner = SolanaSigner;
|
package/dist/index.d.cts
CHANGED
|
@@ -229,7 +229,7 @@ declare class StatusPoller {
|
|
|
229
229
|
poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
declare class
|
|
232
|
+
declare class EtherSigner extends AbstractSigner {
|
|
233
233
|
private address;
|
|
234
234
|
private APICredentials;
|
|
235
235
|
private APIService;
|
|
@@ -240,7 +240,7 @@ declare class ApexSigner extends AbstractSigner {
|
|
|
240
240
|
setWallet(walletId: string): void;
|
|
241
241
|
getAddress(): Promise<string>;
|
|
242
242
|
private getChainId;
|
|
243
|
-
connect(provider: null | Provider):
|
|
243
|
+
connect(provider: null | Provider): EtherSigner;
|
|
244
244
|
private waitForSignature;
|
|
245
245
|
private waitForTransactonStatus;
|
|
246
246
|
signTransaction(tx: TransactionRequest): Promise<string>;
|
|
@@ -608,4 +608,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
|
|
|
608
608
|
wallet_type: WalletType;
|
|
609
609
|
};
|
|
610
610
|
|
|
611
|
-
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType,
|
|
611
|
+
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, 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/dist/index.d.mts
CHANGED
|
@@ -229,7 +229,7 @@ declare class StatusPoller {
|
|
|
229
229
|
poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
declare class
|
|
232
|
+
declare class EtherSigner extends AbstractSigner {
|
|
233
233
|
private address;
|
|
234
234
|
private APICredentials;
|
|
235
235
|
private APIService;
|
|
@@ -240,7 +240,7 @@ declare class ApexSigner extends AbstractSigner {
|
|
|
240
240
|
setWallet(walletId: string): void;
|
|
241
241
|
getAddress(): Promise<string>;
|
|
242
242
|
private getChainId;
|
|
243
|
-
connect(provider: null | Provider):
|
|
243
|
+
connect(provider: null | Provider): EtherSigner;
|
|
244
244
|
private waitForSignature;
|
|
245
245
|
private waitForTransactonStatus;
|
|
246
246
|
signTransaction(tx: TransactionRequest): Promise<string>;
|
|
@@ -608,4 +608,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
|
|
|
608
608
|
wallet_type: WalletType;
|
|
609
609
|
};
|
|
610
610
|
|
|
611
|
-
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType,
|
|
611
|
+
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, 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/dist/index.esm.d.ts
CHANGED
|
@@ -229,7 +229,7 @@ declare class StatusPoller {
|
|
|
229
229
|
poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
declare class
|
|
232
|
+
declare class EtherSigner extends AbstractSigner {
|
|
233
233
|
private address;
|
|
234
234
|
private APICredentials;
|
|
235
235
|
private APIService;
|
|
@@ -240,7 +240,7 @@ declare class ApexSigner extends AbstractSigner {
|
|
|
240
240
|
setWallet(walletId: string): void;
|
|
241
241
|
getAddress(): Promise<string>;
|
|
242
242
|
private getChainId;
|
|
243
|
-
connect(provider: null | Provider):
|
|
243
|
+
connect(provider: null | Provider): EtherSigner;
|
|
244
244
|
private waitForSignature;
|
|
245
245
|
private waitForTransactonStatus;
|
|
246
246
|
signTransaction(tx: TransactionRequest): Promise<string>;
|
|
@@ -608,4 +608,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
|
|
|
608
608
|
wallet_type: WalletType;
|
|
609
609
|
};
|
|
610
610
|
|
|
611
|
-
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType,
|
|
611
|
+
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, 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/dist/index.esm.js
CHANGED
|
@@ -506,7 +506,7 @@ class FystackSDK {
|
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
-
class
|
|
509
|
+
class EtherSigner extends AbstractSigner {
|
|
510
510
|
setWallet(walletId) {
|
|
511
511
|
if (!walletId || walletId.trim() === '') {
|
|
512
512
|
throw new Error('Invalid wallet ID provided');
|
|
@@ -552,7 +552,7 @@ class ApexSigner extends AbstractSigner {
|
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
connect(provider) {
|
|
555
|
-
return new
|
|
555
|
+
return new EtherSigner(this.APICredentials, this.environment, provider);
|
|
556
556
|
}
|
|
557
557
|
async waitForSignature(walletId, transactionId) {
|
|
558
558
|
const poller = new StatusPoller(this.pollerOptions);
|
|
@@ -657,7 +657,7 @@ class ApexSigner extends AbstractSigner {
|
|
|
657
657
|
// Ensure all properties are properly resolved to their string representations
|
|
658
658
|
const resolvedTx = await resolveProperties(populatedTx);
|
|
659
659
|
const txObj = Transaction.from(resolvedTx);
|
|
660
|
-
console.log('
|
|
660
|
+
console.log('[WalletSDK] Tx Data', txObj);
|
|
661
661
|
const txHash = await this.signTransaction(txObj);
|
|
662
662
|
// Instead of creating a mock response, get the actual transaction from the provider
|
|
663
663
|
const endTime = new Date();
|
|
@@ -834,7 +834,7 @@ class SolanaSigner {
|
|
|
834
834
|
data: transaction,
|
|
835
835
|
from: this.address
|
|
836
836
|
};
|
|
837
|
-
// Call the signRaw API similar to
|
|
837
|
+
// Call the signRaw API similar to EtherSigner
|
|
838
838
|
const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
|
|
839
839
|
...data,
|
|
840
840
|
meta: {
|
|
@@ -842,7 +842,6 @@ class SolanaSigner {
|
|
|
842
842
|
},
|
|
843
843
|
chainId: '1399811149'
|
|
844
844
|
});
|
|
845
|
-
console.log('respnpse', response);
|
|
846
845
|
// Wait for the signature
|
|
847
846
|
return this.waitForTransactionStatus(response.transaction_id);
|
|
848
847
|
}
|
|
@@ -860,7 +859,6 @@ class SolanaSigner {
|
|
|
860
859
|
message: messageStr,
|
|
861
860
|
chain_id: 0 // Not used for Solana but required by API
|
|
862
861
|
});
|
|
863
|
-
console.log('Respnse', response);
|
|
864
862
|
return this.waitForTransactionStatus(response.transaction_id);
|
|
865
863
|
}
|
|
866
864
|
/**
|
|
@@ -938,4 +936,4 @@ class SolanaSigner {
|
|
|
938
936
|
}
|
|
939
937
|
}
|
|
940
938
|
|
|
941
|
-
export { APIService, AddressType,
|
|
939
|
+
export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletAddressType, WalletCreationStatus, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
|
package/dist/index.mjs
CHANGED
|
@@ -506,7 +506,7 @@ class FystackSDK {
|
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
-
class
|
|
509
|
+
class EtherSigner extends AbstractSigner {
|
|
510
510
|
setWallet(walletId) {
|
|
511
511
|
if (!walletId || walletId.trim() === '') {
|
|
512
512
|
throw new Error('Invalid wallet ID provided');
|
|
@@ -552,7 +552,7 @@ class ApexSigner extends AbstractSigner {
|
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
connect(provider) {
|
|
555
|
-
return new
|
|
555
|
+
return new EtherSigner(this.APICredentials, this.environment, provider);
|
|
556
556
|
}
|
|
557
557
|
async waitForSignature(walletId, transactionId) {
|
|
558
558
|
const poller = new StatusPoller(this.pollerOptions);
|
|
@@ -657,7 +657,7 @@ class ApexSigner extends AbstractSigner {
|
|
|
657
657
|
// Ensure all properties are properly resolved to their string representations
|
|
658
658
|
const resolvedTx = await resolveProperties(populatedTx);
|
|
659
659
|
const txObj = Transaction.from(resolvedTx);
|
|
660
|
-
console.log('
|
|
660
|
+
console.log('[WalletSDK] Tx Data', txObj);
|
|
661
661
|
const txHash = await this.signTransaction(txObj);
|
|
662
662
|
// Instead of creating a mock response, get the actual transaction from the provider
|
|
663
663
|
const endTime = new Date();
|
|
@@ -834,7 +834,7 @@ class SolanaSigner {
|
|
|
834
834
|
data: transaction,
|
|
835
835
|
from: this.address
|
|
836
836
|
};
|
|
837
|
-
// Call the signRaw API similar to
|
|
837
|
+
// Call the signRaw API similar to EtherSigner
|
|
838
838
|
const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
|
|
839
839
|
...data,
|
|
840
840
|
meta: {
|
|
@@ -842,7 +842,6 @@ class SolanaSigner {
|
|
|
842
842
|
},
|
|
843
843
|
chainId: '1399811149'
|
|
844
844
|
});
|
|
845
|
-
console.log('respnpse', response);
|
|
846
845
|
// Wait for the signature
|
|
847
846
|
return this.waitForTransactionStatus(response.transaction_id);
|
|
848
847
|
}
|
|
@@ -860,7 +859,6 @@ class SolanaSigner {
|
|
|
860
859
|
message: messageStr,
|
|
861
860
|
chain_id: 0 // Not used for Solana but required by API
|
|
862
861
|
});
|
|
863
|
-
console.log('Respnse', response);
|
|
864
862
|
return this.waitForTransactionStatus(response.transaction_id);
|
|
865
863
|
}
|
|
866
864
|
/**
|
|
@@ -938,4 +936,4 @@ class SolanaSigner {
|
|
|
938
936
|
}
|
|
939
937
|
}
|
|
940
938
|
|
|
941
|
-
export { APIService, AddressType,
|
|
939
|
+
export { APIService, AddressType, DEFAULT_POLLER_OPTIONS, Environment, EtherSigner, FystackSDK, PaymentService, SolanaSigner, StatusPoller, TransactionError, TxApprovalStatus, TxStatus, WalletAddressType, WalletCreationStatus, WalletType, WebhookService, createAPI, get, post, transformCreateWalletPayload, transformWalletDetail };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -229,7 +229,7 @@ declare class StatusPoller {
|
|
|
229
229
|
poll<T>(pollingFn: () => Promise<T>, successCondition: (result: T) => boolean, errorCondition?: (result: T) => boolean | void): Promise<T>;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
declare class
|
|
232
|
+
declare class EtherSigner extends AbstractSigner {
|
|
233
233
|
private address;
|
|
234
234
|
private APICredentials;
|
|
235
235
|
private APIService;
|
|
@@ -240,7 +240,7 @@ declare class ApexSigner extends AbstractSigner {
|
|
|
240
240
|
setWallet(walletId: string): void;
|
|
241
241
|
getAddress(): Promise<string>;
|
|
242
242
|
private getChainId;
|
|
243
|
-
connect(provider: null | Provider):
|
|
243
|
+
connect(provider: null | Provider): EtherSigner;
|
|
244
244
|
private waitForSignature;
|
|
245
245
|
private waitForTransactonStatus;
|
|
246
246
|
signTransaction(tx: TransactionRequest): Promise<string>;
|
|
@@ -608,4 +608,4 @@ declare function transformCreateWalletPayload(data: CreateWalletPayload): {
|
|
|
608
608
|
wallet_type: WalletType;
|
|
609
609
|
};
|
|
610
610
|
|
|
611
|
-
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType,
|
|
611
|
+
export { type APIConfig, type APICredentials, type APIEndpoints, APIService, AddressType, type ApprovalInfo, type CreateWalletOptions, type CreateWalletPayload, type CreateWalletResponse, DEFAULT_POLLER_OPTIONS, type DepositAddressResponse, Environment, EtherSigner, 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
CHANGED
package/readme.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Fystack Platform SDK
|
|
2
|
+
|
|
3
|
+
A Typescript SDK for Fystack's wallet and payment services, providing seamless integration with both EVM and Solana blockchains.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @fystack/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Wallet Management
|
|
14
|
+
|
|
15
|
+
Create and manage blockchain wallets with minimal code.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { FystackSDK } from '@fystack/sdk'
|
|
19
|
+
import { Environment, WalletType } from '@fystack/sdk'
|
|
20
|
+
|
|
21
|
+
// Initialize the SDK
|
|
22
|
+
const sdk = new FystackSDK({
|
|
23
|
+
credentials: {
|
|
24
|
+
apiKey: 'YOUR_API_KEY',
|
|
25
|
+
apiSecret: 'YOUR_API_SECRET'
|
|
26
|
+
},
|
|
27
|
+
environment: Environment.Production,
|
|
28
|
+
logger: true // Enable logging
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const response = await sdk.createWallet({
|
|
32
|
+
name: 'My Blockchain Wallet',
|
|
33
|
+
walletType: WalletType.MPC // Multi-Party Computation wallet
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
console.log('Wallet ID:', response.wallet_id)
|
|
37
|
+
console.log('Status:', response.status)
|
|
38
|
+
|
|
39
|
+
// Check wallet creation status
|
|
40
|
+
const statusResponse = await sdk.getWalletCreationStatus(response.wallet_id)
|
|
41
|
+
console.log('WalletID:', statusResponse.wallet_id)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Solana Transaction Signing
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { SolanaSigner } from '@fystack/sdk'
|
|
48
|
+
import { Connection, PublicKey, SystemProgram, Transaction } from '@solana/web3.js'
|
|
49
|
+
|
|
50
|
+
async function signSolanaTransaction() {
|
|
51
|
+
// Initialize the signer
|
|
52
|
+
const signer = new SolanaSigner(
|
|
53
|
+
{
|
|
54
|
+
apiKey: 'YOUR_API_KEY',
|
|
55
|
+
apiSecret: 'YOUR_API_SECRET'
|
|
56
|
+
},
|
|
57
|
+
Environment.Production
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
// Get signer's address
|
|
61
|
+
const fromAddress = await signer.getAddress()
|
|
62
|
+
const fromPubkey = new PublicKey(fromAddress)
|
|
63
|
+
|
|
64
|
+
// Set recipient address
|
|
65
|
+
const toAddress = 'RECIPIENT_SOLANA_ADDRESS'
|
|
66
|
+
const toPubkey = new PublicKey(toAddress)
|
|
67
|
+
|
|
68
|
+
// Connect to Solana network
|
|
69
|
+
const connection = new Connection('https://api.mainnet-beta.solana.com/')
|
|
70
|
+
|
|
71
|
+
// Get recent blockhash
|
|
72
|
+
const { blockhash } = await connection.getLatestBlockhash({
|
|
73
|
+
commitment: 'finalized'
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Create transfer instruction
|
|
77
|
+
const transferInstruction = SystemProgram.transfer({
|
|
78
|
+
fromPubkey,
|
|
79
|
+
toPubkey,
|
|
80
|
+
lamports: 1000 // 0.000001 SOL
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// Create and setup transaction
|
|
84
|
+
const transaction = new Transaction().add(transferInstruction)
|
|
85
|
+
transaction.recentBlockhash = blockhash
|
|
86
|
+
transaction.feePayer = fromPubkey
|
|
87
|
+
|
|
88
|
+
// Serialize the transaction to base64
|
|
89
|
+
const serializedTransaction = transaction
|
|
90
|
+
.serialize({
|
|
91
|
+
requireAllSignatures: false,
|
|
92
|
+
verifySignatures: false
|
|
93
|
+
})
|
|
94
|
+
.toString('base64')
|
|
95
|
+
|
|
96
|
+
// Sign the transaction
|
|
97
|
+
const signature = await signer.signTransaction(serializedTransaction)
|
|
98
|
+
console.log('Transaction signature:', signature)
|
|
99
|
+
|
|
100
|
+
return signature
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Ethereum Transaction Signing
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { EtherSigner } from '@fystack/sdk'
|
|
108
|
+
import { JsonRpcProvider, ethers } from 'ethers'
|
|
109
|
+
|
|
110
|
+
async function signEthereumTransaction() {
|
|
111
|
+
const address = await signer.getAddress()
|
|
112
|
+
console.log('Wallet address:', address)
|
|
113
|
+
|
|
114
|
+
// Connect to a provider
|
|
115
|
+
const provider = new JsonRpcProvider('YOUR_RPC_ENDPOINT')
|
|
116
|
+
const signerWithProvider = signer.connect(provider)
|
|
117
|
+
|
|
118
|
+
// Send a transaction
|
|
119
|
+
const tx = await signerWithProvider.sendTransaction({
|
|
120
|
+
to: '0xRecipientAddress',
|
|
121
|
+
value: ethers.parseEther('0.0001') // Amount in ETH
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
console.log('Transaction hash:', tx.hash)
|
|
125
|
+
return tx.hash
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Payment Processing
|
|
130
|
+
|
|
131
|
+
Create checkouts and process payments.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { PaymentService } from '@fystack/sdk'
|
|
135
|
+
import { Environment } from '@fystack/sdk'
|
|
136
|
+
|
|
137
|
+
async function createPaymentCheckout() {
|
|
138
|
+
const paymentService = new PaymentService({
|
|
139
|
+
apiKey: 'YOUR_API_KEY',
|
|
140
|
+
environment: Environment.Production
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Create a checkout
|
|
144
|
+
const response = await paymentService.createCheckout({
|
|
145
|
+
price: '10.50',
|
|
146
|
+
currency: 'USD',
|
|
147
|
+
supported_assets: [
|
|
148
|
+
'SOL:1399811149', // Format: "ASSET:CHAIN_ID"
|
|
149
|
+
'USDC:1399811149'
|
|
150
|
+
],
|
|
151
|
+
description: 'Premium subscription package',
|
|
152
|
+
success_url: 'https://yourapp.com/payment/success',
|
|
153
|
+
cancel_url: 'https://yourapp.com/payment/cancel',
|
|
154
|
+
product_id: 'YOUR_PRODUCT_ID',
|
|
155
|
+
customer_id: 'YOUR_CUSTOMER_ID',
|
|
156
|
+
order_id: 'YOUR_ORDER_ID',
|
|
157
|
+
enable_localization: false,
|
|
158
|
+
destination_wallet_id: 'YOUR_DESTINATION_WALLET_ID',
|
|
159
|
+
expiry_duration_seconds: 3600 // 1 hour
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
console.log('Checkout created:', response.id)
|
|
163
|
+
|
|
164
|
+
// Get checkout details
|
|
165
|
+
const checkout = await paymentService.getCheckout(response.id)
|
|
166
|
+
|
|
167
|
+
// Create payment using the first supported asset
|
|
168
|
+
const payment = await paymentService.createCheckoutPayment(response.id, {
|
|
169
|
+
pay_asset_id: checkout.supported_assets[0].id
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
console.log('Payment created:', payment.id)
|
|
173
|
+
console.log('Send payment to:', payment.deposit_address)
|
|
174
|
+
|
|
175
|
+
// Get payment status
|
|
176
|
+
const paymentStatus = await paymentService.getCheckoutPayment(payment.id)
|
|
177
|
+
console.log('Payment status:', paymentStatus)
|
|
178
|
+
|
|
179
|
+
return payment
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Webhook Verification
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { APIService } from '@fystack/sdk'
|
|
187
|
+
|
|
188
|
+
function verifyWebhook(event, signature) {
|
|
189
|
+
const apiService = new APIService(
|
|
190
|
+
{
|
|
191
|
+
apiKey: 'YOUR_API_KEY',
|
|
192
|
+
apiSecret: 'YOUR_API_SECRET'
|
|
193
|
+
},
|
|
194
|
+
Environment.Production
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
const isValid = apiService.Webhook.verifyEvent(event, signature)
|
|
198
|
+
return isValid
|
|
199
|
+
}
|
|
200
|
+
```
|
package/src/signer.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { APICredentials, TransactionStatusResponse, TxStatus, TransactionError }
|
|
|
20
20
|
import { Environment } from './config'
|
|
21
21
|
import { StatusPoller, StatusPollerOptions } from './utils/statusPoller'
|
|
22
22
|
|
|
23
|
-
export class
|
|
23
|
+
export class EtherSigner extends AbstractSigner {
|
|
24
24
|
private address!: string
|
|
25
25
|
private APICredentials!: APICredentials
|
|
26
26
|
private APIService: APIService
|
|
@@ -99,8 +99,8 @@ export class ApexSigner extends AbstractSigner {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
connect(provider: null | Provider):
|
|
103
|
-
return new
|
|
102
|
+
connect(provider: null | Provider): EtherSigner {
|
|
103
|
+
return new EtherSigner(this.APICredentials, this.environment, provider)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
private async waitForSignature(walletId: string, transactionId: string): Promise<string> {
|
|
@@ -253,7 +253,7 @@ export class ApexSigner extends AbstractSigner {
|
|
|
253
253
|
const resolvedTx = (await resolveProperties(populatedTx)) as TransactionLike<string>
|
|
254
254
|
const txObj = Transaction.from(resolvedTx)
|
|
255
255
|
|
|
256
|
-
console.log('
|
|
256
|
+
console.log('[WalletSDK] Tx Data', txObj)
|
|
257
257
|
|
|
258
258
|
const txHash = await this.signTransaction(txObj)
|
|
259
259
|
|
package/src/solanaSigner.ts
CHANGED
|
@@ -120,7 +120,7 @@ export class SolanaSigner {
|
|
|
120
120
|
from: this.address
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
// Call the signRaw API similar to
|
|
123
|
+
// Call the signRaw API similar to EtherSigner
|
|
124
124
|
const response = await this.APIService.signTransaction(this.walletDetail.WalletID, {
|
|
125
125
|
...data,
|
|
126
126
|
meta: {
|
|
@@ -128,7 +128,6 @@ export class SolanaSigner {
|
|
|
128
128
|
},
|
|
129
129
|
chainId: '1399811149'
|
|
130
130
|
})
|
|
131
|
-
console.log('respnpse', response)
|
|
132
131
|
|
|
133
132
|
// Wait for the signature
|
|
134
133
|
return this.waitForTransactionStatus(response.transaction_id)
|
|
@@ -153,8 +152,6 @@ export class SolanaSigner {
|
|
|
153
152
|
chain_id: 0 // Not used for Solana but required by API
|
|
154
153
|
})
|
|
155
154
|
|
|
156
|
-
console.log('Respnse', response)
|
|
157
|
-
|
|
158
155
|
return this.waitForTransactionStatus(response.transaction_id)
|
|
159
156
|
}
|
|
160
157
|
|