@smoothsend/sdk 1.0.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/LICENSE +22 -0
- package/README.md +346 -0
- package/dist/adapters/aptos.d.ts +98 -0
- package/dist/adapters/aptos.d.ts.map +1 -0
- package/dist/core/SmoothSendSDK.d.ts +261 -0
- package/dist/core/SmoothSendSDK.d.ts.map +1 -0
- package/dist/index.d.ts +2072 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2076 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2097 -0
- package/dist/index.js.map +1 -0
- package/dist/script-composer/ScriptComposerClient.d.ts +263 -0
- package/dist/script-composer/ScriptComposerClient.d.ts.map +1 -0
- package/dist/script-composer/index.d.ts +42 -0
- package/dist/script-composer/index.d.ts.map +1 -0
- package/dist/shared-constants.d.ts +103 -0
- package/dist/shared-constants.d.ts.map +1 -0
- package/dist/types/errors.d.ts +216 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +939 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/http.d.ts +77 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/wallet-adapter/SmoothSendTransactionSubmitter.d.ts +179 -0
- package/dist/wallet-adapter/SmoothSendTransactionSubmitter.d.ts.map +1 -0
- package/dist/wallet-adapter/index.d.ts +20 -0
- package/dist/wallet-adapter/index.d.ts.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { SupportedChain, ChainEcosystem, TransferRequest, SignedTransferData, TransferResult, SmoothSendConfig, EventListener, HealthResponse, FeeEstimate, UsageMetadata } from '../types';
|
|
2
|
+
export declare class SmoothSendSDK {
|
|
3
|
+
private adapters;
|
|
4
|
+
private eventListeners;
|
|
5
|
+
private config;
|
|
6
|
+
private keyType;
|
|
7
|
+
private hasWarnedAboutSecretKey;
|
|
8
|
+
constructor(config: SmoothSendConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Detect key type from API key prefix
|
|
11
|
+
* Supports pk_nogas_* (public), sk_nogas_* (secret), and no_gas_* (legacy)
|
|
12
|
+
*/
|
|
13
|
+
private detectKeyType;
|
|
14
|
+
/**
|
|
15
|
+
* Check if running in browser environment
|
|
16
|
+
* Used for conditional warnings and Origin header logic
|
|
17
|
+
*/
|
|
18
|
+
private isBrowserEnvironment;
|
|
19
|
+
/**
|
|
20
|
+
* Warn if secret key is used in browser environment
|
|
21
|
+
* Only warns once per SDK instance
|
|
22
|
+
*/
|
|
23
|
+
private warnIfSecretKeyInBrowser;
|
|
24
|
+
/**
|
|
25
|
+
* Determine if Origin header should be included in requests
|
|
26
|
+
* Include Origin header only for public keys in browser environment
|
|
27
|
+
*/
|
|
28
|
+
private shouldIncludeOrigin;
|
|
29
|
+
/**
|
|
30
|
+
* Get or create adapter for a specific chain on-demand
|
|
31
|
+
*/
|
|
32
|
+
private getOrCreateAdapter;
|
|
33
|
+
addEventListener(listener: EventListener): void;
|
|
34
|
+
removeEventListener(listener: EventListener): void;
|
|
35
|
+
private emitEvent;
|
|
36
|
+
estimateFee(request: TransferRequest): Promise<FeeEstimate & {
|
|
37
|
+
metadata?: UsageMetadata;
|
|
38
|
+
}>;
|
|
39
|
+
executeGaslessTransfer(signedData: SignedTransferData): Promise<TransferResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Convenience method for complete transfer flow
|
|
42
|
+
* Combines estimateFee and executeGaslessTransfer into a single call
|
|
43
|
+
*
|
|
44
|
+
* @param request Transfer request with from, to, token, amount, chain
|
|
45
|
+
* @param wallet Wallet instance that can build and sign transactions
|
|
46
|
+
* @returns Transfer result with transaction hash and usage metadata
|
|
47
|
+
*
|
|
48
|
+
* Note: The wallet parameter should have methods:
|
|
49
|
+
* - buildTransaction(params): Build transaction from parameters
|
|
50
|
+
* - signTransaction(transaction): Sign and serialize transaction
|
|
51
|
+
*
|
|
52
|
+
* The wallet's signTransaction should return an object with:
|
|
53
|
+
* - transactionBytes: number[] - Serialized transaction
|
|
54
|
+
* - authenticatorBytes: number[] - Serialized authenticator
|
|
55
|
+
*/
|
|
56
|
+
transfer(request: TransferRequest, wallet: {
|
|
57
|
+
buildTransaction: (params: any) => Promise<any>;
|
|
58
|
+
signTransaction: (transaction: any) => Promise<{
|
|
59
|
+
transactionBytes: number[];
|
|
60
|
+
authenticatorBytes: number[];
|
|
61
|
+
}>;
|
|
62
|
+
}): Promise<TransferResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Get transaction status for a specific transaction
|
|
65
|
+
* Routes through proxy to chain-specific status endpoint
|
|
66
|
+
*
|
|
67
|
+
* @param chain Chain where the transaction was executed
|
|
68
|
+
* @param txHash Transaction hash to query
|
|
69
|
+
* @returns Transaction status information
|
|
70
|
+
* @throws SmoothSendError if chain is not supported or status check fails
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const status = await sdk.getTransactionStatus('aptos-testnet', '0x123...');
|
|
75
|
+
* console.log('Transaction status:', status);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
getTransactionStatus(chain: SupportedChain, txHash: string): Promise<any>;
|
|
79
|
+
validateAddress(chain: SupportedChain, address: string): boolean;
|
|
80
|
+
validateAmount(chain: SupportedChain, amount: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Check proxy worker health status
|
|
83
|
+
* Routes directly to proxy's /health endpoint (not chain-specific)
|
|
84
|
+
*
|
|
85
|
+
* @returns Health response with status, version, and timestamp
|
|
86
|
+
* @throws NetworkError if proxy is unavailable
|
|
87
|
+
* @throws SmoothSendError for other errors
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* try {
|
|
92
|
+
* const health = await sdk.getHealth();
|
|
93
|
+
* console.log('Proxy status:', health.status);
|
|
94
|
+
* console.log('Version:', health.version);
|
|
95
|
+
* } catch (error) {
|
|
96
|
+
* if (error instanceof NetworkError) {
|
|
97
|
+
* console.error('Proxy unavailable. Please retry later.');
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
getHealth(): Promise<HealthResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Get list of supported chains (static list)
|
|
105
|
+
* For dynamic list from proxy, use getSupportedChainsFromProxy()
|
|
106
|
+
*
|
|
107
|
+
* @returns Array of supported chain identifiers
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const chains = sdk.getSupportedChains();
|
|
112
|
+
* console.log('Supported chains:', chains);
|
|
113
|
+
* // Output: ['aptos-testnet', 'aptos-mainnet']
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
getSupportedChains(): SupportedChain[];
|
|
117
|
+
/**
|
|
118
|
+
* Get list of supported chains from proxy worker (dynamic)
|
|
119
|
+
* Queries the proxy for the current list of supported chains
|
|
120
|
+
*
|
|
121
|
+
* @returns Promise with array of chain information including status
|
|
122
|
+
* @throws SmoothSendError if unable to fetch chains from proxy
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const chains = await sdk.getSupportedChainsFromProxy();
|
|
127
|
+
* chains.forEach(chain => {
|
|
128
|
+
* console.log(`${chain.name} (${chain.id}): ${chain.status}`);
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
getSupportedChainsFromProxy(): Promise<Array<{
|
|
133
|
+
id: string;
|
|
134
|
+
name: string;
|
|
135
|
+
ecosystem: string;
|
|
136
|
+
network: string;
|
|
137
|
+
status: string;
|
|
138
|
+
}>>;
|
|
139
|
+
/**
|
|
140
|
+
* Check if a specific chain is currently supported
|
|
141
|
+
*
|
|
142
|
+
* @param chain Chain identifier to check
|
|
143
|
+
* @returns true if chain is supported, false otherwise
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* if (sdk.isChainSupported('aptos-testnet')) {
|
|
148
|
+
* console.log('Aptos testnet is supported');
|
|
149
|
+
* } else {
|
|
150
|
+
* console.log('Chain not supported');
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
isChainSupported(chain: string): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Check health status of a specific chain's relayer
|
|
157
|
+
* Routes through proxy to chain-specific health endpoint
|
|
158
|
+
*
|
|
159
|
+
* @param chain Chain identifier to check
|
|
160
|
+
* @returns Health response for the specific chain
|
|
161
|
+
* @throws SmoothSendError if chain is not supported or health check fails
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* try {
|
|
166
|
+
* const health = await sdk.getChainHealth('aptos-testnet');
|
|
167
|
+
* console.log('Aptos testnet status:', health.status);
|
|
168
|
+
* } catch (error) {
|
|
169
|
+
* console.error('Chain health check failed:', error.message);
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
getChainHealth(chain: SupportedChain): Promise<HealthResponse>;
|
|
174
|
+
/**
|
|
175
|
+
* Get current usage statistics without making a transfer
|
|
176
|
+
* Makes a lightweight health check request to retrieve usage metadata
|
|
177
|
+
*
|
|
178
|
+
* @returns Usage metadata with rate limit and monthly usage information
|
|
179
|
+
* @throws Error if unable to retrieve usage stats
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const usage = await sdk.getUsageStats();
|
|
184
|
+
* console.log('Rate limit:', usage.rateLimit);
|
|
185
|
+
* console.log('Monthly usage:', usage.monthly);
|
|
186
|
+
* console.log('Request ID:', usage.requestId);
|
|
187
|
+
*
|
|
188
|
+
* // Check if approaching limits
|
|
189
|
+
* if (parseInt(usage.rateLimit.remaining) < 2) {
|
|
190
|
+
* console.warn('Approaching rate limit!');
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
getUsageStats(): Promise<UsageMetadata>;
|
|
195
|
+
/**
|
|
196
|
+
* Extract request ID from a transfer result for debugging and support
|
|
197
|
+
*
|
|
198
|
+
* @param result Transfer result from executeGaslessTransfer or transfer
|
|
199
|
+
* @returns Request ID if available, undefined otherwise
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const result = await sdk.executeGaslessTransfer(signedData);
|
|
204
|
+
* const requestId = sdk.getRequestId(result);
|
|
205
|
+
* if (requestId) {
|
|
206
|
+
* console.log('Request ID for support:', requestId);
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
getRequestId(result: TransferResult): string | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Check if approaching rate limit based on transfer result metadata
|
|
213
|
+
*
|
|
214
|
+
* @param result Transfer result with metadata
|
|
215
|
+
* @param threshold Percentage threshold (0-100) to consider as "approaching" (default: 20)
|
|
216
|
+
* @returns true if remaining requests are below threshold percentage
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const result = await sdk.transfer(request, wallet);
|
|
221
|
+
* if (sdk.isApproachingRateLimit(result)) {
|
|
222
|
+
* console.warn('Approaching rate limit, consider slowing down requests');
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
isApproachingRateLimit(result: TransferResult, threshold?: number): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Check if approaching monthly usage limit based on transfer result metadata
|
|
229
|
+
*
|
|
230
|
+
* @param result Transfer result with metadata
|
|
231
|
+
* @param threshold Percentage threshold (0-100) to consider as "approaching" (default: 90)
|
|
232
|
+
* @returns true if monthly usage is above threshold percentage
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const result = await sdk.transfer(request, wallet);
|
|
237
|
+
* if (sdk.isApproachingMonthlyLimit(result)) {
|
|
238
|
+
* console.warn('Approaching monthly limit, consider upgrading plan');
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
isApproachingMonthlyLimit(result: TransferResult, threshold?: number): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Check if a chain belongs to a specific ecosystem
|
|
245
|
+
*/
|
|
246
|
+
getChainEcosystem(chain: SupportedChain): ChainEcosystem;
|
|
247
|
+
/**
|
|
248
|
+
* Get list of supported chains (static method)
|
|
249
|
+
* Can be called without instantiating the SDK
|
|
250
|
+
*
|
|
251
|
+
* @returns Array of supported chain identifiers
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const chains = SmoothSendSDK.getSupportedChains();
|
|
256
|
+
* console.log('Supported chains:', chains);
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
static getSupportedChains(): SupportedChain[];
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=SmoothSendSDK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SmoothSendSDK.d.ts","sourceRoot":"","sources":["../../src/core/SmoothSendSDK.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EAEd,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAGhB,aAAa,EAEb,cAAc,EACd,WAAW,EACX,aAAa,EACd,MAAM,UAAU,CAAC;AAGlB,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAiD;IACjE,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,uBAAuB,CAAkB;gBAErC,MAAM,EAAE,gBAAgB;IAiCpC;;;OAGG;IACH,OAAO,CAAC,aAAa;IAgBrB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAgBhC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