@profullstack/coinpay 0.3.10 → 0.4.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.
- package/bin/coinpay.js +901 -277
- package/package.json +21 -4
- package/src/index.d.ts +65 -2
- package/src/index.js +61 -1
- package/src/swap.d.ts +254 -0
- package/src/swap.js +360 -0
- package/src/wallet.d.ts +259 -0
- package/src/wallet.js +757 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/coinpay",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC)
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC) with wallet and swap support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
"./webhooks": {
|
|
21
21
|
"import": "./src/webhooks.js",
|
|
22
22
|
"types": "./src/webhooks.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./wallet": {
|
|
25
|
+
"import": "./src/wallet.js",
|
|
26
|
+
"types": "./src/wallet.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./swap": {
|
|
29
|
+
"import": "./src/swap.js",
|
|
30
|
+
"types": "./src/swap.d.ts"
|
|
23
31
|
}
|
|
24
32
|
},
|
|
25
33
|
"files": [
|
|
@@ -49,12 +57,16 @@
|
|
|
49
57
|
"stablecoin",
|
|
50
58
|
"non-custodial",
|
|
51
59
|
"wallet",
|
|
60
|
+
"swap",
|
|
61
|
+
"exchange",
|
|
52
62
|
"sdk",
|
|
53
63
|
"cli",
|
|
54
64
|
"web3",
|
|
55
65
|
"blockchain",
|
|
56
66
|
"payment-gateway",
|
|
57
|
-
"merchant"
|
|
67
|
+
"merchant",
|
|
68
|
+
"bip39",
|
|
69
|
+
"mnemonic"
|
|
58
70
|
],
|
|
59
71
|
"author": "Profullstack, Inc.",
|
|
60
72
|
"license": "MIT",
|
|
@@ -76,5 +88,10 @@
|
|
|
76
88
|
"prettier": "^3.4.1"
|
|
77
89
|
},
|
|
78
90
|
"peerDependencies": {},
|
|
79
|
-
"dependencies": {
|
|
91
|
+
"dependencies": {
|
|
92
|
+
"@scure/bip39": "^1.4.0",
|
|
93
|
+
"@scure/bip32": "^1.5.0",
|
|
94
|
+
"@noble/curves": "^1.6.0",
|
|
95
|
+
"@noble/hashes": "^1.5.0"
|
|
96
|
+
}
|
|
80
97
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -5,9 +5,17 @@
|
|
|
5
5
|
* @module @profullstack/coinpay
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
// Client exports
|
|
8
9
|
export { CoinPayClient } from './client.js';
|
|
9
|
-
export type {
|
|
10
|
+
export type {
|
|
11
|
+
CoinPayClientOptions,
|
|
12
|
+
PaymentParams,
|
|
13
|
+
ListPaymentsParams,
|
|
14
|
+
WaitForPaymentOptions,
|
|
15
|
+
CreateBusinessParams
|
|
16
|
+
} from './client.js';
|
|
10
17
|
|
|
18
|
+
// Payment exports
|
|
11
19
|
export {
|
|
12
20
|
createPayment,
|
|
13
21
|
getPayment,
|
|
@@ -17,8 +25,13 @@ export {
|
|
|
17
25
|
PaymentStatus,
|
|
18
26
|
FiatCurrency,
|
|
19
27
|
} from './payments.js';
|
|
20
|
-
export type {
|
|
28
|
+
export type {
|
|
29
|
+
CreatePaymentParams,
|
|
30
|
+
GetPaymentParams,
|
|
31
|
+
ListPaymentsFnParams
|
|
32
|
+
} from './payments.js';
|
|
21
33
|
|
|
34
|
+
// Webhook exports
|
|
22
35
|
export {
|
|
23
36
|
verifyWebhookSignature,
|
|
24
37
|
generateWebhookSignature,
|
|
@@ -33,5 +46,55 @@ export type {
|
|
|
33
46
|
ParsedWebhookEvent,
|
|
34
47
|
} from './webhooks.js';
|
|
35
48
|
|
|
49
|
+
// Wallet exports
|
|
50
|
+
export {
|
|
51
|
+
WalletClient,
|
|
52
|
+
WalletChain,
|
|
53
|
+
DEFAULT_CHAINS,
|
|
54
|
+
generateMnemonic,
|
|
55
|
+
validateMnemonic,
|
|
56
|
+
getDerivationPath,
|
|
57
|
+
restoreFromBackup,
|
|
58
|
+
} from './wallet.js';
|
|
59
|
+
export type {
|
|
60
|
+
WalletChainType,
|
|
61
|
+
WalletCreateOptions,
|
|
62
|
+
WalletImportOptions,
|
|
63
|
+
WalletAddress,
|
|
64
|
+
AddressListResult,
|
|
65
|
+
WalletBalance,
|
|
66
|
+
SendOptions,
|
|
67
|
+
HistoryOptions,
|
|
68
|
+
Transaction,
|
|
69
|
+
FeeEstimate,
|
|
70
|
+
} from './wallet.js';
|
|
71
|
+
|
|
72
|
+
// Swap exports
|
|
73
|
+
export {
|
|
74
|
+
SwapClient,
|
|
75
|
+
SwapCoins,
|
|
76
|
+
SwapStatus,
|
|
77
|
+
getSwapCoins,
|
|
78
|
+
getSwapQuote,
|
|
79
|
+
createSwap,
|
|
80
|
+
getSwapStatus,
|
|
81
|
+
getSwapHistory,
|
|
82
|
+
} from './swap.js';
|
|
83
|
+
export type {
|
|
84
|
+
SwapStatusType,
|
|
85
|
+
SwapClientOptions,
|
|
86
|
+
CoinInfo,
|
|
87
|
+
CoinsResult,
|
|
88
|
+
SwapQuote,
|
|
89
|
+
QuoteResult,
|
|
90
|
+
CreateSwapParams,
|
|
91
|
+
Swap,
|
|
92
|
+
SwapResult,
|
|
93
|
+
WaitForSwapOptions,
|
|
94
|
+
SwapHistoryOptions,
|
|
95
|
+
SwapHistoryPagination,
|
|
96
|
+
SwapHistoryResult,
|
|
97
|
+
} from './swap.js';
|
|
98
|
+
|
|
36
99
|
import { CoinPayClient } from './client.js';
|
|
37
100
|
export default CoinPayClient;
|
package/src/index.js
CHANGED
|
@@ -16,6 +16,24 @@
|
|
|
16
16
|
* blockchain: Blockchain.BTC,
|
|
17
17
|
* description: 'Order #12345'
|
|
18
18
|
* });
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Wallet usage
|
|
22
|
+
* import { WalletClient } from '@profullstack/coinpay';
|
|
23
|
+
*
|
|
24
|
+
* // Create a new wallet
|
|
25
|
+
* const wallet = await WalletClient.create({ words: 12, chains: ['BTC', 'ETH'] });
|
|
26
|
+
* console.log('Backup your seed:', wallet.getMnemonic());
|
|
27
|
+
*
|
|
28
|
+
* // Or import existing
|
|
29
|
+
* const wallet = await WalletClient.fromSeed('your twelve word mnemonic phrase ...');
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Swap usage
|
|
33
|
+
* import { SwapClient } from '@profullstack/coinpay';
|
|
34
|
+
*
|
|
35
|
+
* const swap = new SwapClient({ walletId: 'your-wallet-id' });
|
|
36
|
+
* const quote = await swap.getSwapQuote('BTC', 'ETH', 0.1);
|
|
19
37
|
*/
|
|
20
38
|
|
|
21
39
|
import { CoinPayClient } from './client.js';
|
|
@@ -47,6 +65,29 @@ import {
|
|
|
47
65
|
waitForEscrow,
|
|
48
66
|
} from './escrow.js';
|
|
49
67
|
|
|
68
|
+
// Wallet exports
|
|
69
|
+
import {
|
|
70
|
+
WalletClient,
|
|
71
|
+
WalletChain,
|
|
72
|
+
DEFAULT_CHAINS,
|
|
73
|
+
generateMnemonic,
|
|
74
|
+
validateMnemonic,
|
|
75
|
+
getDerivationPath,
|
|
76
|
+
restoreFromBackup,
|
|
77
|
+
} from './wallet.js';
|
|
78
|
+
|
|
79
|
+
// Swap exports
|
|
80
|
+
import {
|
|
81
|
+
SwapClient,
|
|
82
|
+
SwapCoins,
|
|
83
|
+
SwapStatus,
|
|
84
|
+
getSwapCoins,
|
|
85
|
+
getSwapQuote,
|
|
86
|
+
createSwap,
|
|
87
|
+
getSwapStatus,
|
|
88
|
+
getSwapHistory,
|
|
89
|
+
} from './swap.js';
|
|
90
|
+
|
|
50
91
|
export {
|
|
51
92
|
// Client
|
|
52
93
|
CoinPayClient,
|
|
@@ -66,6 +107,25 @@ export {
|
|
|
66
107
|
getEscrowEvents,
|
|
67
108
|
waitForEscrow,
|
|
68
109
|
|
|
110
|
+
// Wallet
|
|
111
|
+
WalletClient,
|
|
112
|
+
WalletChain,
|
|
113
|
+
DEFAULT_CHAINS,
|
|
114
|
+
generateMnemonic,
|
|
115
|
+
validateMnemonic,
|
|
116
|
+
getDerivationPath,
|
|
117
|
+
restoreFromBackup,
|
|
118
|
+
|
|
119
|
+
// Swap
|
|
120
|
+
SwapClient,
|
|
121
|
+
SwapCoins,
|
|
122
|
+
SwapStatus,
|
|
123
|
+
getSwapCoins,
|
|
124
|
+
getSwapQuote,
|
|
125
|
+
createSwap,
|
|
126
|
+
getSwapStatus,
|
|
127
|
+
getSwapHistory,
|
|
128
|
+
|
|
69
129
|
// Constants
|
|
70
130
|
Blockchain,
|
|
71
131
|
Cryptocurrency, // Deprecated, use Blockchain
|
|
@@ -80,4 +140,4 @@ export {
|
|
|
80
140
|
WebhookEvent,
|
|
81
141
|
};
|
|
82
142
|
|
|
83
|
-
export default CoinPayClient;
|
|
143
|
+
export default CoinPayClient;
|
package/src/swap.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swap Module Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Supported coins for swaps
|
|
7
|
+
*/
|
|
8
|
+
export declare const SwapCoins: readonly string[];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Swap status values
|
|
12
|
+
*/
|
|
13
|
+
export declare const SwapStatus: {
|
|
14
|
+
readonly PENDING: 'pending';
|
|
15
|
+
readonly PROCESSING: 'processing';
|
|
16
|
+
readonly SETTLING: 'settling';
|
|
17
|
+
readonly SETTLED: 'settled';
|
|
18
|
+
readonly FAILED: 'failed';
|
|
19
|
+
readonly REFUNDED: 'refunded';
|
|
20
|
+
readonly EXPIRED: 'expired';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type SwapStatusType = (typeof SwapStatus)[keyof typeof SwapStatus];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Swap client options
|
|
27
|
+
*/
|
|
28
|
+
export interface SwapClientOptions {
|
|
29
|
+
/** Wallet ID for tracking swaps */
|
|
30
|
+
walletId?: string;
|
|
31
|
+
/** API base URL */
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
/** Request timeout in ms */
|
|
34
|
+
timeout?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Coin information
|
|
39
|
+
*/
|
|
40
|
+
export interface CoinInfo {
|
|
41
|
+
symbol: string;
|
|
42
|
+
name: string;
|
|
43
|
+
network: string;
|
|
44
|
+
ticker: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Coins list result
|
|
49
|
+
*/
|
|
50
|
+
export interface CoinsResult {
|
|
51
|
+
success: boolean;
|
|
52
|
+
provider: string;
|
|
53
|
+
coins: CoinInfo[];
|
|
54
|
+
count: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Swap quote
|
|
59
|
+
*/
|
|
60
|
+
export interface SwapQuote {
|
|
61
|
+
from: string;
|
|
62
|
+
to: string;
|
|
63
|
+
depositAmount: string;
|
|
64
|
+
settleAmount: string;
|
|
65
|
+
rate: string;
|
|
66
|
+
minAmount: number;
|
|
67
|
+
provider: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Quote result
|
|
72
|
+
*/
|
|
73
|
+
export interface QuoteResult {
|
|
74
|
+
success: boolean;
|
|
75
|
+
quote: SwapQuote;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create swap parameters
|
|
80
|
+
*/
|
|
81
|
+
export interface CreateSwapParams {
|
|
82
|
+
/** Source coin (e.g., 'BTC') */
|
|
83
|
+
from: string;
|
|
84
|
+
/** Destination coin (e.g., 'ETH') */
|
|
85
|
+
to: string;
|
|
86
|
+
/** Amount to swap */
|
|
87
|
+
amount: string | number;
|
|
88
|
+
/** Address to receive swapped coins */
|
|
89
|
+
settleAddress: string;
|
|
90
|
+
/** Address for refunds (recommended) */
|
|
91
|
+
refundAddress?: string;
|
|
92
|
+
/** Override wallet ID */
|
|
93
|
+
walletId?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Swap details
|
|
98
|
+
*/
|
|
99
|
+
export interface Swap {
|
|
100
|
+
id: string;
|
|
101
|
+
from: string;
|
|
102
|
+
to: string;
|
|
103
|
+
depositAddress: string;
|
|
104
|
+
depositAmount: string;
|
|
105
|
+
depositCoin?: string;
|
|
106
|
+
settleAddress: string;
|
|
107
|
+
settleAmount?: string;
|
|
108
|
+
settleCoin?: string;
|
|
109
|
+
status: SwapStatusType;
|
|
110
|
+
createdAt: string;
|
|
111
|
+
provider: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Swap result
|
|
116
|
+
*/
|
|
117
|
+
export interface SwapResult {
|
|
118
|
+
success: boolean;
|
|
119
|
+
swap: Swap;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Wait for swap options
|
|
124
|
+
*/
|
|
125
|
+
export interface WaitForSwapOptions {
|
|
126
|
+
/** Polling interval in ms (default: 10000) */
|
|
127
|
+
interval?: number;
|
|
128
|
+
/** Maximum wait time in ms (default: 3600000) */
|
|
129
|
+
timeout?: number;
|
|
130
|
+
/** Statuses to wait for */
|
|
131
|
+
targetStatuses?: SwapStatusType[];
|
|
132
|
+
/** Callback when status changes */
|
|
133
|
+
onStatusChange?: (status: SwapStatusType, swap: Swap) => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Swap history options
|
|
138
|
+
*/
|
|
139
|
+
export interface SwapHistoryOptions {
|
|
140
|
+
/** Filter by status */
|
|
141
|
+
status?: SwapStatusType;
|
|
142
|
+
/** Number of results (default: 50) */
|
|
143
|
+
limit?: number;
|
|
144
|
+
/** Pagination offset */
|
|
145
|
+
offset?: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Swap history pagination
|
|
150
|
+
*/
|
|
151
|
+
export interface SwapHistoryPagination {
|
|
152
|
+
total: number;
|
|
153
|
+
limit: number;
|
|
154
|
+
offset: number;
|
|
155
|
+
hasMore: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Swap history result
|
|
160
|
+
*/
|
|
161
|
+
export interface SwapHistoryResult {
|
|
162
|
+
success: boolean;
|
|
163
|
+
swaps: Swap[];
|
|
164
|
+
pagination: SwapHistoryPagination;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* SwapClient class for handling cryptocurrency swaps
|
|
169
|
+
*/
|
|
170
|
+
export declare class SwapClient {
|
|
171
|
+
/**
|
|
172
|
+
* Create a SwapClient
|
|
173
|
+
*/
|
|
174
|
+
constructor(options?: SwapClientOptions);
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Set the wallet ID for tracking swaps
|
|
178
|
+
*/
|
|
179
|
+
setWalletId(walletId: string): void;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get list of supported coins for swaps
|
|
183
|
+
*/
|
|
184
|
+
getSwapCoins(options?: { search?: string }): Promise<CoinsResult>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get a swap quote
|
|
188
|
+
*/
|
|
189
|
+
getSwapQuote(from: string, to: string, amount: string | number): Promise<QuoteResult>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Create a swap transaction
|
|
193
|
+
*/
|
|
194
|
+
createSwap(params: CreateSwapParams): Promise<SwapResult>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get the status of a swap
|
|
198
|
+
*/
|
|
199
|
+
getSwapStatus(swapId: string): Promise<SwapResult>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Wait for a swap to complete
|
|
203
|
+
*/
|
|
204
|
+
waitForSwap(swapId: string, options?: WaitForSwapOptions): Promise<SwapResult>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get swap history for a wallet
|
|
208
|
+
*/
|
|
209
|
+
getSwapHistory(walletId?: string, options?: SwapHistoryOptions): Promise<SwapHistoryResult>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get supported swap coins (convenience function)
|
|
214
|
+
*/
|
|
215
|
+
export declare function getSwapCoins(options?: {
|
|
216
|
+
baseUrl?: string;
|
|
217
|
+
search?: string;
|
|
218
|
+
}): Promise<CoinsResult>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Get a swap quote (convenience function)
|
|
222
|
+
*/
|
|
223
|
+
export declare function getSwapQuote(
|
|
224
|
+
from: string,
|
|
225
|
+
to: string,
|
|
226
|
+
amount: string | number,
|
|
227
|
+
options?: { baseUrl?: string }
|
|
228
|
+
): Promise<QuoteResult>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Create a swap (convenience function)
|
|
232
|
+
*/
|
|
233
|
+
export declare function createSwap(
|
|
234
|
+
params: CreateSwapParams,
|
|
235
|
+
options?: { baseUrl?: string }
|
|
236
|
+
): Promise<SwapResult>;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get swap status (convenience function)
|
|
240
|
+
*/
|
|
241
|
+
export declare function getSwapStatus(
|
|
242
|
+
swapId: string,
|
|
243
|
+
options?: { baseUrl?: string }
|
|
244
|
+
): Promise<SwapResult>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get swap history (convenience function)
|
|
248
|
+
*/
|
|
249
|
+
export declare function getSwapHistory(
|
|
250
|
+
walletId: string,
|
|
251
|
+
options?: SwapHistoryOptions & { baseUrl?: string }
|
|
252
|
+
): Promise<SwapHistoryResult>;
|
|
253
|
+
|
|
254
|
+
export default SwapClient;
|