@smoothsend/sdk 2.3.4 → 2.3.5
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/aptos/index.cjs +160 -0
- package/dist/aptos/index.cjs.map +1 -1
- package/dist/aptos/index.d.ts +65 -749
- package/dist/aptos/index.js +160 -3
- package/dist/aptos/index.js.map +1 -1
- package/dist/aptos-entry.d.ts +1 -0
- package/dist/aptos-entry.d.ts.map +1 -1
- package/dist/aptos-privy/SmoothSendAptosProvider.d.ts +7 -0
- package/dist/aptos-privy/SmoothSendAptosProvider.d.ts.map +1 -0
- package/dist/aptos-privy/index.cjs +40 -0
- package/dist/aptos-privy/index.cjs.map +1 -0
- package/dist/aptos-privy/index.d.ts +4 -0
- package/dist/aptos-privy/index.d.ts.map +1 -0
- package/dist/aptos-privy/index.js +34 -0
- package/dist/aptos-privy/index.js.map +1 -0
- package/dist/aptos-privy/normalizePrivyAptosWallet.d.ts +4 -0
- package/dist/aptos-privy/normalizePrivyAptosWallet.d.ts.map +1 -0
- package/dist/aptos-privy/privyAptosSigner.d.ts +32 -0
- package/dist/aptos-privy/privyAptosSigner.d.ts.map +1 -0
- package/dist/aptos-privy/types.d.ts +71 -0
- package/dist/aptos-privy/types.d.ts.map +1 -0
- package/dist/aptos-privy/useSmoothSendAptosPrivy.d.ts +13 -0
- package/dist/aptos-privy/useSmoothSendAptosPrivy.d.ts.map +1 -0
- package/dist/aptos-privy/useSmoothSendPrivyWrite.d.ts +13 -0
- package/dist/aptos-privy/useSmoothSendPrivyWrite.d.ts.map +1 -0
- package/dist/aptos-privy-entry.d.ts +9 -0
- package/dist/aptos-privy-entry.d.ts.map +1 -0
- package/dist/chunks/shared-2xx2VLH3.js +453 -0
- package/dist/chunks/shared-2xx2VLH3.js.map +1 -0
- package/dist/chunks/shared-B8UdyBTN.d.ts +143 -0
- package/dist/chunks/shared-BJv1JV1H.cjs +702 -0
- package/dist/chunks/shared-BJv1JV1H.cjs.map +1 -0
- package/dist/chunks/shared-BXvqbQ6f.d.ts +262 -0
- package/dist/chunks/shared-Bh4xtpHv.js +740 -0
- package/dist/chunks/shared-Bh4xtpHv.js.map +1 -0
- package/dist/chunks/shared-BlIQttCf.d.ts +1279 -0
- package/dist/chunks/shared-BoRfHN1w.js +1511 -0
- package/dist/chunks/shared-BoRfHN1w.js.map +1 -0
- package/dist/chunks/shared-CPpb2n9T.d.ts +780 -0
- package/dist/chunks/shared-CzR0rIwZ.cjs +635 -0
- package/dist/chunks/shared-CzR0rIwZ.cjs.map +1 -0
- package/dist/chunks/shared-DQbEIiTE.cjs +746 -0
- package/dist/chunks/shared-DQbEIiTE.cjs.map +1 -0
- package/dist/chunks/shared-DzwYUjQn.cjs +457 -0
- package/dist/chunks/shared-DzwYUjQn.cjs.map +1 -0
- package/dist/chunks/shared-KUvoQkzf.d.ts +471 -0
- package/dist/chunks/shared-XH1iLZjy.js +629 -0
- package/dist/chunks/shared-XH1iLZjy.js.map +1 -0
- package/dist/chunks/shared-kovW7ATj.js +694 -0
- package/dist/chunks/shared-kovW7ATj.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import { AptosConfig, AnyRawTransaction, AccountAuthenticator, PendingTransactionResponse, Account, InputGenerateTransactionPayloadData, Aptos } from '@aptos-labs/ts-sdk';
|
|
2
|
+
import { N as IChainAdapter, S as SupportedChain, d as ChainConfig, e as TransferRequest, F as FeeEstimate, l as SignedTransferData, h as TransferResult, g as TransferQuote, k as SignatureData, m as TokenBalance, T as TokenInfo, u as HealthResponse } from './shared-Cn4duBJT.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SmoothSend Transaction Submitter
|
|
6
|
+
*
|
|
7
|
+
* A TransactionSubmitter implementation that integrates with the Aptos Wallet Adapter
|
|
8
|
+
* to enable gasless transactions via SmoothSend's relayer network.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { SmoothSendTransactionSubmitter } from '@smoothsend/sdk';
|
|
13
|
+
* import { AptosWalletAdapterProvider } from '@aptos-labs/wallet-adapter-react';
|
|
14
|
+
*
|
|
15
|
+
* // Create the transaction submitter
|
|
16
|
+
* const transactionSubmitter = new SmoothSendTransactionSubmitter({
|
|
17
|
+
* apiKey: 'pk_nogas_your_api_key_here',
|
|
18
|
+
* network: 'testnet'
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Use in your wallet provider - that's it!
|
|
22
|
+
* <AptosWalletAdapterProvider
|
|
23
|
+
* dappConfig={{
|
|
24
|
+
* network: Network.TESTNET,
|
|
25
|
+
* transactionSubmitter: transactionSubmitter
|
|
26
|
+
* }}
|
|
27
|
+
* >
|
|
28
|
+
* <App />
|
|
29
|
+
* </AptosWalletAdapterProvider>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options for SmoothSendTransactionSubmitter
|
|
35
|
+
*/
|
|
36
|
+
interface SmoothSendTransactionSubmitterConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Your SmoothSend API key
|
|
39
|
+
* - Use `pk_nogas_*` for frontend applications (CORS protected)
|
|
40
|
+
* - Use `sk_nogas_*` for backend applications only
|
|
41
|
+
*/
|
|
42
|
+
apiKey: string;
|
|
43
|
+
/**
|
|
44
|
+
* Network to use
|
|
45
|
+
* @default 'testnet'
|
|
46
|
+
*/
|
|
47
|
+
network?: 'testnet' | 'mainnet';
|
|
48
|
+
/**
|
|
49
|
+
* Gateway URL (usually you don't need to change this)
|
|
50
|
+
* @default 'https://proxy.smoothsend.xyz'
|
|
51
|
+
*/
|
|
52
|
+
gatewayUrl?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Request timeout in milliseconds
|
|
55
|
+
* @default 30000
|
|
56
|
+
*/
|
|
57
|
+
timeout?: number;
|
|
58
|
+
/**
|
|
59
|
+
* A function that returns a captcha token (e.g. from Cloudflare Turnstile or reCAPTCHA).
|
|
60
|
+
* Called before each transaction if the project requires captcha verification.
|
|
61
|
+
* Return null/undefined to skip captcha.
|
|
62
|
+
*/
|
|
63
|
+
getCaptchaToken?: () => Promise<string | null | undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* Enable debug logging
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
debug?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Enable session key mode — user signs once, all subsequent transactions
|
|
71
|
+
* are signed silently by an in-memory session key. Zero wallet popups after setup.
|
|
72
|
+
*
|
|
73
|
+
* Uses Aptos Account Abstraction (AIP-103 Permissioned Signers) — enforced on-chain.
|
|
74
|
+
* Live on mainnet and testnet (as of April 2025).
|
|
75
|
+
* SmoothSend pays gas for the one-time session setup transaction too.
|
|
76
|
+
*
|
|
77
|
+
* @default false
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const smoothSend = new SmoothSendTransactionSubmitter({
|
|
82
|
+
* apiKey: 'pk_nogas_xxx',
|
|
83
|
+
* network: 'mainnet',
|
|
84
|
+
* session: true,
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
session?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* How long the session key stays valid.
|
|
91
|
+
* Format: number + unit (s, m, h, d)
|
|
92
|
+
* Use "never" for client-side indefinite session validity.
|
|
93
|
+
* @default '24h'
|
|
94
|
+
*/
|
|
95
|
+
sessionDuration?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* TransactionSubmitter interface compatible with @aptos-labs/ts-sdk v2.x
|
|
99
|
+
* This interface allows the SmoothSendTransactionSubmitter to work as a drop-in
|
|
100
|
+
* replacement for the default transaction submitter in the Aptos Wallet Adapter.
|
|
101
|
+
*/
|
|
102
|
+
interface TransactionSubmitter {
|
|
103
|
+
submitTransaction(args: {
|
|
104
|
+
aptosConfig: AptosConfig;
|
|
105
|
+
transaction: AnyRawTransaction;
|
|
106
|
+
senderAuthenticator: AccountAuthenticator;
|
|
107
|
+
feePayerAuthenticator?: AccountAuthenticator;
|
|
108
|
+
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
|
|
109
|
+
pluginParams?: Record<string, unknown>;
|
|
110
|
+
}): Promise<PendingTransactionResponse>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* SmoothSend Transaction Submitter
|
|
114
|
+
*
|
|
115
|
+
* Implements the TransactionSubmitter interface to enable gasless transactions
|
|
116
|
+
* through the Aptos Wallet Adapter. Simply pass this to your AptosWalletAdapterProvider
|
|
117
|
+
* and all transactions will automatically be submitted as gasless through SmoothSend.
|
|
118
|
+
*/
|
|
119
|
+
declare class SmoothSendTransactionSubmitter implements TransactionSubmitter {
|
|
120
|
+
private readonly apiKey;
|
|
121
|
+
private readonly network;
|
|
122
|
+
private readonly gatewayUrl;
|
|
123
|
+
private readonly timeout;
|
|
124
|
+
private readonly getCaptchaToken?;
|
|
125
|
+
private readonly debug;
|
|
126
|
+
readonly sessionEnabled: boolean;
|
|
127
|
+
private readonly sessionDuration;
|
|
128
|
+
private _session;
|
|
129
|
+
constructor(config: SmoothSendTransactionSubmitterConfig);
|
|
130
|
+
/**
|
|
131
|
+
* Whether a valid session is currently active.
|
|
132
|
+
*/
|
|
133
|
+
hasSession(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Create a session key for the given master account.
|
|
136
|
+
* Called once by useSmoothSend when session: true and no session exists.
|
|
137
|
+
* SmoothSend pays gas for the setup transaction.
|
|
138
|
+
*
|
|
139
|
+
* @param masterAccount - The user's wallet account (from wallet adapter)
|
|
140
|
+
*/
|
|
141
|
+
createSession(masterAccount: Account): Promise<void>;
|
|
142
|
+
private isPermissionedSignerEnabled;
|
|
143
|
+
private signSenderAuthenticator;
|
|
144
|
+
/**
|
|
145
|
+
* Submit a transaction using the active session key — no wallet popup.
|
|
146
|
+
* Called by useSmoothSend after session is established.
|
|
147
|
+
*/
|
|
148
|
+
submitWithSession(functionName: `${string}::${string}::${string}`, functionArguments?: any[], typeArguments?: string[]): Promise<PendingTransactionResponse>;
|
|
149
|
+
private _parseDuration;
|
|
150
|
+
/**
|
|
151
|
+
* Submit a transaction through SmoothSend's gasless relayer
|
|
152
|
+
*
|
|
153
|
+
* This method is called automatically by the Aptos Wallet Adapter when
|
|
154
|
+
* you use signAndSubmitTransaction. The transaction is submitted to
|
|
155
|
+
* SmoothSend's relayer which sponsors the gas fees.
|
|
156
|
+
*/
|
|
157
|
+
submitTransaction(args: {
|
|
158
|
+
aptosConfig: AptosConfig;
|
|
159
|
+
transaction: AnyRawTransaction;
|
|
160
|
+
senderAuthenticator: AccountAuthenticator;
|
|
161
|
+
feePayerAuthenticator?: AccountAuthenticator;
|
|
162
|
+
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
|
|
163
|
+
pluginParams?: Record<string, unknown>;
|
|
164
|
+
}): Promise<PendingTransactionResponse>;
|
|
165
|
+
/**
|
|
166
|
+
* Resolve the effective network from aptosConfig.
|
|
167
|
+
* aptosConfig.network is the source of truth set by AptosWalletAdapterProvider.
|
|
168
|
+
*/
|
|
169
|
+
private resolveNetwork;
|
|
170
|
+
/**
|
|
171
|
+
* Make an HTTP request to the SmoothSend gateway
|
|
172
|
+
*/
|
|
173
|
+
private makeRequest;
|
|
174
|
+
private sponsoredFunctionsCache;
|
|
175
|
+
private sponsoredFunctionsCacheAt;
|
|
176
|
+
private readonly SPONSORED_CACHE_TTL;
|
|
177
|
+
/**
|
|
178
|
+
* Fetch the list of sponsored functions for this API key's project.
|
|
179
|
+
* Results are cached for 5 minutes. Returns ['*'] if all functions are sponsored.
|
|
180
|
+
*/
|
|
181
|
+
getSponsoredFunctions(): Promise<string[]>;
|
|
182
|
+
/**
|
|
183
|
+
* Check if a specific function is sponsored for gasless execution.
|
|
184
|
+
* @param functionName - Full function identifier, e.g. "0x123::module::function"
|
|
185
|
+
*/
|
|
186
|
+
isSponsored(functionName: string): Promise<boolean>;
|
|
187
|
+
/**
|
|
188
|
+
*/
|
|
189
|
+
getConfig(): Readonly<SmoothSendTransactionSubmitterConfig>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a SmoothSend transaction submitter with minimal configuration
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const submitter = createSmoothSendSubmitter('pk_nogas_your_key');
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function createSmoothSendSubmitter(apiKey: string, options?: Partial<Omit<SmoothSendTransactionSubmitterConfig, 'apiKey'>>): SmoothSendTransactionSubmitter;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* useSmoothSend — React hook for automatic gasless / user-pays-gas routing
|
|
203
|
+
*
|
|
204
|
+
* Drop-in replacement for useWallet()'s signAndSubmitTransaction.
|
|
205
|
+
* Fetches the project's sponsored-functions list from the gateway on mount
|
|
206
|
+
* and routes each transaction automatically:
|
|
207
|
+
* - Function in allowlist → fee-payer gasless path via SmoothSend
|
|
208
|
+
* - Function not in allowlist → regular wallet submission (user pays gas)
|
|
209
|
+
*
|
|
210
|
+
* When submitter has session: true, the first transaction triggers a one-time
|
|
211
|
+
* wallet sign to register a session key on-chain. Every transaction after that
|
|
212
|
+
* is signed silently — zero wallet popups.
|
|
213
|
+
*
|
|
214
|
+
* Requires: react >=17, @aptos-labs/wallet-adapter-react >=3, @aptos-labs/ts-sdk >=1
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```tsx
|
|
218
|
+
* // Replace useWallet() with useSmoothSend() where you submit transactions.
|
|
219
|
+
* // No other changes needed.
|
|
220
|
+
*
|
|
221
|
+
* const { signAndSubmitTransaction } = useSmoothSend(submitter);
|
|
222
|
+
* await signAndSubmitTransaction({ data: { function: '0x1::coin::transfer', functionArguments: [to, amount] } });
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
interface UseSmoothSendResult {
|
|
227
|
+
/**
|
|
228
|
+
* Smart signAndSubmitTransaction — same signature as the wallet adapter's version.
|
|
229
|
+
* Sponsored functions go gasless via SmoothSend; others fall back to user-pays-gas.
|
|
230
|
+
* With session: true, zero wallet popups after the first transaction.
|
|
231
|
+
*/
|
|
232
|
+
signAndSubmitTransaction: (input: {
|
|
233
|
+
data: any;
|
|
234
|
+
options?: any;
|
|
235
|
+
}) => Promise<any>;
|
|
236
|
+
/**
|
|
237
|
+
* Whether a session key is currently active (only relevant when session: true).
|
|
238
|
+
* Updates reactively when session is created or expires.
|
|
239
|
+
*/
|
|
240
|
+
hasSession: boolean;
|
|
241
|
+
}
|
|
242
|
+
declare function useSmoothSend(submitter: SmoothSendTransactionSubmitter): UseSmoothSendResult;
|
|
243
|
+
|
|
244
|
+
interface CreateSessionOptions {
|
|
245
|
+
/**
|
|
246
|
+
* The master account that owns the Aptos address.
|
|
247
|
+
* Can be a KeylessAccount (Google/Apple login), Ed25519Account, or any Account
|
|
248
|
+
* that implements the Aptos Account interface.
|
|
249
|
+
*
|
|
250
|
+
* @example keylessAccount from aptos.deriveKeylessAccount(...)
|
|
251
|
+
* @example Account.fromPrivateKey({ privateKey })
|
|
252
|
+
*/
|
|
253
|
+
signer: Account;
|
|
254
|
+
/**
|
|
255
|
+
* How long the session should stay valid.
|
|
256
|
+
* Format: number + unit (s = seconds, m = minutes, h = hours, d = days)
|
|
257
|
+
* @example '2h' | '24h' | '7d' | 'never'
|
|
258
|
+
*/
|
|
259
|
+
expiresIn: string;
|
|
260
|
+
/**
|
|
261
|
+
* Network to use. Inferred from submitter if not provided.
|
|
262
|
+
*/
|
|
263
|
+
network?: 'testnet' | 'mainnet';
|
|
264
|
+
}
|
|
265
|
+
interface SessionInfo {
|
|
266
|
+
/** The user's main account address — sender for all transactions */
|
|
267
|
+
masterAddress: string;
|
|
268
|
+
/** The temporary session key address (for debugging / display) */
|
|
269
|
+
sessionKeyAddress: string;
|
|
270
|
+
/** When this session expires (Unix timestamp in ms) */
|
|
271
|
+
expiresAt: number;
|
|
272
|
+
/** Network this session operates on */
|
|
273
|
+
network: 'testnet' | 'mainnet';
|
|
274
|
+
}
|
|
275
|
+
interface SubmitResult {
|
|
276
|
+
hash: string;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* A session that lets your app submit transactions on behalf of a user
|
|
280
|
+
* without any wallet popup after the initial one-time setup.
|
|
281
|
+
*
|
|
282
|
+
* Uses Aptos AIP-103 Permissioned Signers — authorization is enforced
|
|
283
|
+
* on-chain by `0x1::permissioned_delegation`. No custom Move contract needed.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* // 1. One-time setup (user signs once — can be keyless/Google login)
|
|
287
|
+
* const session = await SmoothSendSession.create({
|
|
288
|
+
* signer: keylessAccount,
|
|
289
|
+
* expiresIn: '24h',
|
|
290
|
+
* }, submitter)
|
|
291
|
+
*
|
|
292
|
+
* // 2. Every action after — zero popups, zero gas
|
|
293
|
+
* await session.submit('0xgame::player::move', ['north'])
|
|
294
|
+
* await session.submit('0xgame::player::attack', [enemyId])
|
|
295
|
+
*/
|
|
296
|
+
declare class SmoothSendSession {
|
|
297
|
+
private readonly sessionAccount;
|
|
298
|
+
private readonly abstractedAccount;
|
|
299
|
+
private readonly masterAddress;
|
|
300
|
+
private readonly expiresAtMs;
|
|
301
|
+
private readonly submitter;
|
|
302
|
+
private readonly aptosClient;
|
|
303
|
+
private readonly _network;
|
|
304
|
+
private constructor();
|
|
305
|
+
/**
|
|
306
|
+
* Create a new session.
|
|
307
|
+
*
|
|
308
|
+
* Registers the session key on-chain via
|
|
309
|
+
* `0x1::permissioned_delegation::add_permissioned_handle`.
|
|
310
|
+
* SmoothSend pays the gas for this setup transaction too.
|
|
311
|
+
*
|
|
312
|
+
* After this returns, the user never needs to approve anything again
|
|
313
|
+
* until the session expires or is revoked.
|
|
314
|
+
*/
|
|
315
|
+
static create(options: CreateSessionOptions, submitter: SmoothSendTransactionSubmitter): Promise<SmoothSendSession>;
|
|
316
|
+
/**
|
|
317
|
+
* Submit a transaction silently — no wallet popup, zero gas.
|
|
318
|
+
*
|
|
319
|
+
* The transaction sender on-chain is still the user's main address.
|
|
320
|
+
* The session key signs it, and `permissioned_delegation::authenticate`
|
|
321
|
+
* validates the authorization at the VM level.
|
|
322
|
+
*
|
|
323
|
+
* @param functionName Full Move function identifier e.g. '0xgame::player::move'
|
|
324
|
+
* @param functionArguments Arguments matching the Move function signature
|
|
325
|
+
* @param typeArguments Optional type arguments for generic functions
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* await session.submit('0xgame::player::move', ['north'])
|
|
329
|
+
* await session.submit('0x1::coin::transfer', [recipientAddr, 1000000n])
|
|
330
|
+
*/
|
|
331
|
+
submit(functionName: `${string}::${string}::${string}`, functionArguments?: any[], typeArguments?: string[]): Promise<SubmitResult>;
|
|
332
|
+
/**
|
|
333
|
+
* Whether this session is still valid (not yet expired).
|
|
334
|
+
*/
|
|
335
|
+
isValid(): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Milliseconds until this session expires. Returns 0 if already expired.
|
|
338
|
+
*/
|
|
339
|
+
expiresInMs(): number;
|
|
340
|
+
/**
|
|
341
|
+
* Session metadata — useful for display or debugging.
|
|
342
|
+
*/
|
|
343
|
+
get info(): SessionInfo;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Script Composer Client
|
|
348
|
+
*
|
|
349
|
+
* Wrapper for Script Composer gasless transactions.
|
|
350
|
+
* Use this for token transfers on mainnet with free tier (fee deducted from token).
|
|
351
|
+
*
|
|
352
|
+
* @remarks
|
|
353
|
+
* Script Composer builds a batched transaction that:
|
|
354
|
+
* 1. Withdraws (amount + fee) from sender
|
|
355
|
+
* 2. Deposits amount to recipient
|
|
356
|
+
* 3. Deposits fee to treasury
|
|
357
|
+
*
|
|
358
|
+
* This allows gasless transactions where the fee is paid in the token being transferred.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* import { ScriptComposerClient } from '@smoothsend/aptos-sdk';
|
|
363
|
+
*
|
|
364
|
+
* const client = new ScriptComposerClient({
|
|
365
|
+
* apiKey: 'pk_nogas_xxx',
|
|
366
|
+
* network: 'mainnet'
|
|
367
|
+
* });
|
|
368
|
+
*
|
|
369
|
+
* // Step 1: Build transaction (fee calculated automatically)
|
|
370
|
+
* const { transactionBytes, fee, totalAmount } = await client.buildTransfer({
|
|
371
|
+
* sender: wallet.address,
|
|
372
|
+
* recipient: '0x123...',
|
|
373
|
+
* amount: '1000000', // 1 USDC (6 decimals)
|
|
374
|
+
* assetType: '0x...::usdc::USDC',
|
|
375
|
+
* decimals: 6,
|
|
376
|
+
* symbol: 'USDC'
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* // Step 2: Sign with wallet
|
|
380
|
+
* const signedTx = await wallet.signTransaction(transactionBytes);
|
|
381
|
+
*
|
|
382
|
+
* // Step 3: Submit
|
|
383
|
+
* const result = await client.submitSignedTransaction({
|
|
384
|
+
* transactionBytes: signedTx.transactionBytes,
|
|
385
|
+
* authenticatorBytes: signedTx.authenticatorBytes
|
|
386
|
+
* });
|
|
387
|
+
*
|
|
388
|
+
* console.log('Tx:', result.txHash);
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
/**
|
|
392
|
+
* Configuration for Script Composer Client
|
|
393
|
+
*/
|
|
394
|
+
interface ScriptComposerConfig {
|
|
395
|
+
/** API key for authentication (pk_nogas_* or sk_nogas_*) */
|
|
396
|
+
apiKey: string;
|
|
397
|
+
/** Network to use: 'testnet' or 'mainnet' */
|
|
398
|
+
network: 'testnet' | 'mainnet';
|
|
399
|
+
/** Custom proxy URL (optional, defaults to proxy.smoothsend.xyz) */
|
|
400
|
+
proxyUrl?: string;
|
|
401
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
402
|
+
timeout?: number;
|
|
403
|
+
/** Enable debug logging */
|
|
404
|
+
debug?: boolean;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Parameters for building a Script Composer transfer
|
|
408
|
+
*/
|
|
409
|
+
interface BuildTransferParams {
|
|
410
|
+
/** Sender's wallet address */
|
|
411
|
+
sender: string;
|
|
412
|
+
/** Recipient's wallet address */
|
|
413
|
+
recipient: string;
|
|
414
|
+
/** Amount in smallest units (e.g., 1000000 for 1 USDC) */
|
|
415
|
+
amount: string;
|
|
416
|
+
/** Full asset type address (e.g., '0x...::usdc::USDC') */
|
|
417
|
+
assetType: string;
|
|
418
|
+
/** Token decimals (e.g., 6 for USDC, 8 for APT) */
|
|
419
|
+
decimals: number;
|
|
420
|
+
/** Token symbol (e.g., 'USDC', 'APT') */
|
|
421
|
+
symbol: string;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Result from building a transfer
|
|
425
|
+
*/
|
|
426
|
+
interface BuildTransferResult {
|
|
427
|
+
/** Success status */
|
|
428
|
+
success: boolean;
|
|
429
|
+
/** Request ID for tracking */
|
|
430
|
+
requestId: string;
|
|
431
|
+
/** Serialized transaction bytes for wallet signing */
|
|
432
|
+
transactionBytes: number[];
|
|
433
|
+
/** Transaction details */
|
|
434
|
+
transaction: {
|
|
435
|
+
sender: string;
|
|
436
|
+
recipient: string;
|
|
437
|
+
amount: string;
|
|
438
|
+
assetType: string;
|
|
439
|
+
network: string;
|
|
440
|
+
};
|
|
441
|
+
/** Fee amount in smallest units */
|
|
442
|
+
fee: string;
|
|
443
|
+
/** Total amount (amount + fee) in smallest units */
|
|
444
|
+
totalAmount: string;
|
|
445
|
+
/** Fee breakdown with formatted values */
|
|
446
|
+
feeBreakdown: {
|
|
447
|
+
amount: string;
|
|
448
|
+
fee: string;
|
|
449
|
+
totalAmount: string;
|
|
450
|
+
formatted: {
|
|
451
|
+
amount: string;
|
|
452
|
+
fee: string;
|
|
453
|
+
totalAmount: string;
|
|
454
|
+
};
|
|
455
|
+
pricing: {
|
|
456
|
+
tier: string;
|
|
457
|
+
zeroFees: boolean;
|
|
458
|
+
feeInUsd: number;
|
|
459
|
+
tokenPrice: number | null;
|
|
460
|
+
description: string;
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Parameters for submitting a signed transaction
|
|
466
|
+
*/
|
|
467
|
+
interface SubmitSignedTransactionParams {
|
|
468
|
+
/** Serialized transaction bytes (from wallet signing) */
|
|
469
|
+
transactionBytes: number[];
|
|
470
|
+
/** Serialized authenticator bytes (from wallet signing) */
|
|
471
|
+
authenticatorBytes: number[];
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Result from submitting a transaction
|
|
475
|
+
*/
|
|
476
|
+
interface SubmitTransactionResult {
|
|
477
|
+
/** Success status */
|
|
478
|
+
success: boolean;
|
|
479
|
+
/** Request ID for tracking */
|
|
480
|
+
requestId: string;
|
|
481
|
+
/** Transaction hash */
|
|
482
|
+
txHash: string;
|
|
483
|
+
/** Gas used */
|
|
484
|
+
gasUsed?: string;
|
|
485
|
+
/** VM status */
|
|
486
|
+
vmStatus?: string;
|
|
487
|
+
/** Sender address */
|
|
488
|
+
sender?: string;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Fee estimation result
|
|
492
|
+
*/
|
|
493
|
+
interface FeeEstimateResult {
|
|
494
|
+
/** Success status */
|
|
495
|
+
success: boolean;
|
|
496
|
+
/** Request ID for tracking */
|
|
497
|
+
requestId: string;
|
|
498
|
+
/** Fee estimation details */
|
|
499
|
+
estimation: {
|
|
500
|
+
/** Amount in smallest units */
|
|
501
|
+
amount: string;
|
|
502
|
+
/** Fee in smallest units */
|
|
503
|
+
fee: string;
|
|
504
|
+
/** Total amount in smallest units */
|
|
505
|
+
totalAmount: string;
|
|
506
|
+
/** Formatted values for display */
|
|
507
|
+
formatted: {
|
|
508
|
+
amount: string;
|
|
509
|
+
fee: string;
|
|
510
|
+
totalAmount: string;
|
|
511
|
+
};
|
|
512
|
+
/** Pricing information */
|
|
513
|
+
pricing: {
|
|
514
|
+
tier: string;
|
|
515
|
+
zeroFees: boolean;
|
|
516
|
+
feeInUsd: number;
|
|
517
|
+
tokenPrice: number | null;
|
|
518
|
+
description: string;
|
|
519
|
+
};
|
|
520
|
+
/** Usage information */
|
|
521
|
+
usage: {
|
|
522
|
+
monthlyLimit: number;
|
|
523
|
+
usedThisMonth: number;
|
|
524
|
+
remaining: number;
|
|
525
|
+
};
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Script Composer Client
|
|
530
|
+
*
|
|
531
|
+
* For gasless token transfers with fee deducted from the token.
|
|
532
|
+
* Use this on mainnet with free tier, or anytime you want fee-in-token.
|
|
533
|
+
*/
|
|
534
|
+
declare class ScriptComposerClient {
|
|
535
|
+
private httpClient;
|
|
536
|
+
private config;
|
|
537
|
+
constructor(config: ScriptComposerConfig);
|
|
538
|
+
private isBrowser;
|
|
539
|
+
private log;
|
|
540
|
+
/**
|
|
541
|
+
* Estimate fee for a transfer without building the transaction
|
|
542
|
+
*
|
|
543
|
+
* @param params Transfer parameters
|
|
544
|
+
* @returns Fee estimation with pricing details
|
|
545
|
+
*/
|
|
546
|
+
estimateFee(params: BuildTransferParams): Promise<FeeEstimateResult>;
|
|
547
|
+
/**
|
|
548
|
+
* Build a gasless transfer transaction
|
|
549
|
+
*
|
|
550
|
+
* Returns unsigned transaction bytes that must be signed by the user's wallet.
|
|
551
|
+
* The fee will be deducted from the token being transferred.
|
|
552
|
+
*
|
|
553
|
+
* @param params Transfer parameters
|
|
554
|
+
* @returns Transaction bytes for signing and fee details
|
|
555
|
+
*/
|
|
556
|
+
buildTransfer(params: BuildTransferParams): Promise<BuildTransferResult>;
|
|
557
|
+
/**
|
|
558
|
+
* Submit a signed transaction
|
|
559
|
+
*
|
|
560
|
+
* After the user signs the transaction bytes returned by buildTransfer(),
|
|
561
|
+
* use this method to submit the signed transaction.
|
|
562
|
+
*
|
|
563
|
+
* @param params Signed transaction bytes
|
|
564
|
+
* @returns Transaction result with hash
|
|
565
|
+
*/
|
|
566
|
+
submitSignedTransaction(params: SubmitSignedTransactionParams): Promise<SubmitTransactionResult>;
|
|
567
|
+
/**
|
|
568
|
+
* Complete transfer flow: build, sign, and submit
|
|
569
|
+
*
|
|
570
|
+
* Convenience method that handles the entire flow.
|
|
571
|
+
* Requires a wallet that can sign transactions.
|
|
572
|
+
*
|
|
573
|
+
* @param params Transfer parameters
|
|
574
|
+
* @param wallet Wallet with signTransaction method
|
|
575
|
+
* @returns Transaction result
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* const result = await client.transfer({
|
|
580
|
+
* sender: wallet.address,
|
|
581
|
+
* recipient: '0x123...',
|
|
582
|
+
* amount: '1000000',
|
|
583
|
+
* assetType: USDC_ADDRESS,
|
|
584
|
+
* decimals: 6,
|
|
585
|
+
* symbol: 'USDC'
|
|
586
|
+
* }, wallet);
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
transfer(params: BuildTransferParams, wallet: {
|
|
590
|
+
signTransaction: (txBytes: number[]) => Promise<{
|
|
591
|
+
transactionBytes: number[];
|
|
592
|
+
authenticatorBytes: number[];
|
|
593
|
+
}>;
|
|
594
|
+
}): Promise<SubmitTransactionResult>;
|
|
595
|
+
/**
|
|
596
|
+
* Get current network
|
|
597
|
+
*/
|
|
598
|
+
getNetwork(): 'testnet' | 'mainnet';
|
|
599
|
+
/**
|
|
600
|
+
* Set network
|
|
601
|
+
*/
|
|
602
|
+
setNetwork(network: 'testnet' | 'mainnet'): void;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Create a Script Composer client (convenience function)
|
|
606
|
+
*/
|
|
607
|
+
declare function createScriptComposerClient(config: ScriptComposerConfig): ScriptComposerClient;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* True Gasless Client
|
|
611
|
+
*
|
|
612
|
+
* Designed for server-side (backend) environments to securely build, sign,
|
|
613
|
+
* and submit 100% sponsored gasless transactions using a Secret Key.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* import { TrueGaslessClient } from '@smoothsend/sdk';
|
|
618
|
+
* import { Account } from '@aptos-labs/ts-sdk';
|
|
619
|
+
*
|
|
620
|
+
* const backendWallet = Account.fromPrivateKey({ privateKey: '...' });
|
|
621
|
+
* const client = new TrueGaslessClient({ apiKey: 'sk_nogas_...', network: 'mainnet' });
|
|
622
|
+
*
|
|
623
|
+
* const result = await client.execute({
|
|
624
|
+
* senderAccount: backendWallet,
|
|
625
|
+
* payload: {
|
|
626
|
+
* function: "0x123::my_module::mint_nft",
|
|
627
|
+
* functionArguments: []
|
|
628
|
+
* }
|
|
629
|
+
* });
|
|
630
|
+
*
|
|
631
|
+
* console.log("Gasless NFT Minted!", result.txHash);
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
|
|
635
|
+
interface TrueGaslessConfig {
|
|
636
|
+
/** API key for authentication (must be sk_nogas_* for backend) */
|
|
637
|
+
apiKey: string;
|
|
638
|
+
/** Network to use: 'testnet' | 'mainnet' */
|
|
639
|
+
network: 'testnet' | 'mainnet';
|
|
640
|
+
/** Custom proxy URL (optional) */
|
|
641
|
+
proxyUrl?: string;
|
|
642
|
+
/** Request timeout in milliseconds */
|
|
643
|
+
timeout?: number;
|
|
644
|
+
/** Enable debug logging */
|
|
645
|
+
debug?: boolean;
|
|
646
|
+
}
|
|
647
|
+
interface ExecuteGaslessParams {
|
|
648
|
+
/** The backend sender wallet identity */
|
|
649
|
+
senderAccount: Account;
|
|
650
|
+
/** Raw transaction payload to execute */
|
|
651
|
+
payload: InputGenerateTransactionPayloadData;
|
|
652
|
+
}
|
|
653
|
+
interface ExecuteGaslessResult {
|
|
654
|
+
success: boolean;
|
|
655
|
+
requestId?: string;
|
|
656
|
+
txHash?: string;
|
|
657
|
+
gasUsed?: string;
|
|
658
|
+
vmStatus?: string;
|
|
659
|
+
sender?: string;
|
|
660
|
+
}
|
|
661
|
+
declare class TrueGaslessClient {
|
|
662
|
+
private httpClient;
|
|
663
|
+
private config;
|
|
664
|
+
private aptos;
|
|
665
|
+
constructor(config: TrueGaslessConfig);
|
|
666
|
+
private log;
|
|
667
|
+
/**
|
|
668
|
+
* Builds, signs (as sender), and relays an arbitrary payload for complete sponsorship.
|
|
669
|
+
*/
|
|
670
|
+
execute(params: ExecuteGaslessParams): Promise<ExecuteGaslessResult>;
|
|
671
|
+
/**
|
|
672
|
+
* Expose the core Aptos instance to allow backend developers to access chain state if needed
|
|
673
|
+
*/
|
|
674
|
+
getAptosClient(): Aptos;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Helper to initialize TrueGaslessClient
|
|
678
|
+
*/
|
|
679
|
+
declare function createTrueGaslessClient(config: TrueGaslessConfig): TrueGaslessClient;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Aptos Multi-Chain Adapter - v2 Proxy Architecture
|
|
683
|
+
* Handles all Aptos chains (aptos-testnet, aptos-mainnet)
|
|
684
|
+
* Routes all requests through proxy.smoothsend.xyz with API key authentication
|
|
685
|
+
* Supports Aptos-specific features like gasless transactions and Move-based contracts
|
|
686
|
+
*/
|
|
687
|
+
declare class AptosAdapter implements IChainAdapter {
|
|
688
|
+
readonly chain: SupportedChain;
|
|
689
|
+
readonly config: ChainConfig;
|
|
690
|
+
private httpClient;
|
|
691
|
+
private apiKey;
|
|
692
|
+
private network;
|
|
693
|
+
constructor(chain: SupportedChain, config: ChainConfig, apiKey: string, network?: 'testnet' | 'mainnet', includeOrigin?: boolean);
|
|
694
|
+
/**
|
|
695
|
+
* Build API path for proxy worker routing to Aptos relayer
|
|
696
|
+
* All requests route through /api/v1/relayer/aptos/* endpoints
|
|
697
|
+
*/
|
|
698
|
+
private getApiPath;
|
|
699
|
+
/**
|
|
700
|
+
* Update network parameter for subsequent requests
|
|
701
|
+
* Network is passed via X-Network header to proxy worker
|
|
702
|
+
*/
|
|
703
|
+
setNetwork(network: 'testnet' | 'mainnet'): void;
|
|
704
|
+
/**
|
|
705
|
+
* Get current network
|
|
706
|
+
*/
|
|
707
|
+
getNetwork(): 'testnet' | 'mainnet';
|
|
708
|
+
/**
|
|
709
|
+
* Estimate fee for a transfer (v2 interface method)
|
|
710
|
+
* Routes through proxy: POST /api/v1/relayer/aptos/quote
|
|
711
|
+
*/
|
|
712
|
+
estimateFee(request: TransferRequest): Promise<FeeEstimate>;
|
|
713
|
+
/**
|
|
714
|
+
* Execute gasless transfer (v2 interface method)
|
|
715
|
+
* Routes through proxy: POST /api/v1/relayer/aptos/execute
|
|
716
|
+
*/
|
|
717
|
+
executeGaslessTransfer(signedData: SignedTransferData): Promise<TransferResult>;
|
|
718
|
+
/**
|
|
719
|
+
* Get quote for a transfer (legacy method, kept for backward compatibility)
|
|
720
|
+
* Routes through proxy: POST /api/v1/relayer/aptos/quote
|
|
721
|
+
*/
|
|
722
|
+
getQuote(request: TransferRequest): Promise<TransferQuote>;
|
|
723
|
+
prepareTransfer(request: TransferRequest, quote: TransferQuote): Promise<SignatureData>;
|
|
724
|
+
executeTransfer(signedData: SignedTransferData): Promise<TransferResult>;
|
|
725
|
+
getBalance(address: string, token?: string): Promise<TokenBalance[]>;
|
|
726
|
+
getTokenInfo(token: string): Promise<TokenInfo>;
|
|
727
|
+
getNonce(address: string): Promise<string>;
|
|
728
|
+
getTransactionStatus(txHash: string): Promise<any>;
|
|
729
|
+
/**
|
|
730
|
+
* Get health status of Aptos relayer through proxy
|
|
731
|
+
* Routes through proxy: GET /api/v1/relayer/aptos/health
|
|
732
|
+
*/
|
|
733
|
+
getHealth(): Promise<HealthResponse>;
|
|
734
|
+
validateAddress(address: string): boolean;
|
|
735
|
+
validateAmount(amount: string): boolean;
|
|
736
|
+
/**
|
|
737
|
+
* Get Aptos token address from symbol
|
|
738
|
+
* Mirrors aptosrelayer/config/chains.json
|
|
739
|
+
*/
|
|
740
|
+
private getAptosTokenAddress;
|
|
741
|
+
/**
|
|
742
|
+
* Build Aptos explorer URL for transaction
|
|
743
|
+
*/
|
|
744
|
+
private buildAptosExplorerUrl;
|
|
745
|
+
/**
|
|
746
|
+
* Validate serialized transaction data for proxy worker
|
|
747
|
+
* @param signedData The signed transfer data to validate
|
|
748
|
+
*/
|
|
749
|
+
private validateSerializedTransactionData;
|
|
750
|
+
/**
|
|
751
|
+
* Enhanced address validation with detailed error messages
|
|
752
|
+
* @param address The address to validate
|
|
753
|
+
* @returns true if valid, throws error if invalid
|
|
754
|
+
*/
|
|
755
|
+
validateAddressStrict(address: string): boolean;
|
|
756
|
+
/**
|
|
757
|
+
* Verify that a public key corresponds to an expected address
|
|
758
|
+
* This mirrors the enhanced verification in the relayer
|
|
759
|
+
* @param publicKey The public key to verify
|
|
760
|
+
* @param expectedAddress The expected address
|
|
761
|
+
* @returns true if they match
|
|
762
|
+
*/
|
|
763
|
+
verifyPublicKeyAddress(publicKey: string, expectedAddress: string): Promise<boolean>;
|
|
764
|
+
/**
|
|
765
|
+
* Enhanced transaction preparation with better signature data structure
|
|
766
|
+
* @param request Transfer request
|
|
767
|
+
* @param quote Transfer quote
|
|
768
|
+
* @returns Signature data with enhanced structure
|
|
769
|
+
*/
|
|
770
|
+
prepareTransferEnhanced(request: TransferRequest, quote: TransferQuote): Promise<SignatureData & {
|
|
771
|
+
metadata: any;
|
|
772
|
+
}>;
|
|
773
|
+
/**
|
|
774
|
+
* Aptos-specific Move contract interaction
|
|
775
|
+
*/
|
|
776
|
+
callMoveFunction(functionName: string, args: any[]): Promise<any>;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export { AptosAdapter as A, SmoothSendTransactionSubmitter as S, SmoothSendSession as b, createSmoothSendSubmitter as c, ScriptComposerClient as f, createScriptComposerClient as g, TrueGaslessClient as l, createTrueGaslessClient as m, useSmoothSend as u };
|
|
780
|
+
export type { BuildTransferParams as B, CreateSessionOptions as C, ExecuteGaslessParams as E, FeeEstimateResult as F, TransactionSubmitter as T, UseSmoothSendResult as U, SmoothSendTransactionSubmitterConfig as a, SessionInfo as d, SubmitResult as e, ScriptComposerConfig as h, BuildTransferResult as i, SubmitSignedTransactionParams as j, SubmitTransactionResult as k, TrueGaslessConfig as n, ExecuteGaslessResult as o };
|