@smoothsend/sdk 2.3.3 → 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.
Files changed (77) hide show
  1. package/dist/aptos/index.cjs +160 -0
  2. package/dist/aptos/index.cjs.map +1 -1
  3. package/dist/aptos/index.d.ts +65 -749
  4. package/dist/aptos/index.js +160 -3
  5. package/dist/aptos/index.js.map +1 -1
  6. package/dist/aptos-entry.d.ts +1 -0
  7. package/dist/aptos-entry.d.ts.map +1 -1
  8. package/dist/aptos-privy/SmoothSendAptosProvider.d.ts +7 -0
  9. package/dist/aptos-privy/SmoothSendAptosProvider.d.ts.map +1 -0
  10. package/dist/aptos-privy/index.cjs +40 -0
  11. package/dist/aptos-privy/index.cjs.map +1 -0
  12. package/dist/aptos-privy/index.d.ts +4 -0
  13. package/dist/aptos-privy/index.d.ts.map +1 -0
  14. package/dist/aptos-privy/index.js +34 -0
  15. package/dist/aptos-privy/index.js.map +1 -0
  16. package/dist/aptos-privy/normalizePrivyAptosWallet.d.ts +4 -0
  17. package/dist/aptos-privy/normalizePrivyAptosWallet.d.ts.map +1 -0
  18. package/dist/aptos-privy/privyAptosSigner.d.ts +32 -0
  19. package/dist/aptos-privy/privyAptosSigner.d.ts.map +1 -0
  20. package/dist/aptos-privy/types.d.ts +71 -0
  21. package/dist/aptos-privy/types.d.ts.map +1 -0
  22. package/dist/aptos-privy/useSmoothSendAptosPrivy.d.ts +13 -0
  23. package/dist/aptos-privy/useSmoothSendAptosPrivy.d.ts.map +1 -0
  24. package/dist/aptos-privy/useSmoothSendPrivyWrite.d.ts +13 -0
  25. package/dist/aptos-privy/useSmoothSendPrivyWrite.d.ts.map +1 -0
  26. package/dist/aptos-privy-entry.d.ts +9 -0
  27. package/dist/aptos-privy-entry.d.ts.map +1 -0
  28. package/dist/avax/SmoothSendAvaxClient.d.ts +4 -2
  29. package/dist/avax/SmoothSendAvaxClient.d.ts.map +1 -1
  30. package/dist/avax/index.cjs +114 -28
  31. package/dist/avax/index.cjs.map +1 -1
  32. package/dist/avax/index.d.ts +57 -6
  33. package/dist/avax/index.d.ts.map +1 -1
  34. package/dist/avax/index.js +113 -29
  35. package/dist/avax/index.js.map +1 -1
  36. package/dist/avax/privySigner.d.ts +12 -0
  37. package/dist/avax/privySigner.d.ts.map +1 -0
  38. package/dist/avax/types.d.ts +6 -0
  39. package/dist/avax/types.d.ts.map +1 -1
  40. package/dist/avax/useSmoothSendAvax.d.ts +6 -2
  41. package/dist/avax/useSmoothSendAvax.d.ts.map +1 -1
  42. package/dist/avax/useSmoothSendPrivyWrite.d.ts +35 -0
  43. package/dist/avax/useSmoothSendPrivyWrite.d.ts.map +1 -0
  44. package/dist/avax/useSmoothSendWrite.d.ts +11 -4
  45. package/dist/avax/useSmoothSendWrite.d.ts.map +1 -1
  46. package/dist/avax-entry.d.ts +1 -1
  47. package/dist/avax-entry.d.ts.map +1 -1
  48. package/dist/chunks/shared-2xx2VLH3.js +453 -0
  49. package/dist/chunks/shared-2xx2VLH3.js.map +1 -0
  50. package/dist/chunks/shared-B8UdyBTN.d.ts +143 -0
  51. package/dist/chunks/shared-BJv1JV1H.cjs +702 -0
  52. package/dist/chunks/shared-BJv1JV1H.cjs.map +1 -0
  53. package/dist/chunks/shared-BXvqbQ6f.d.ts +262 -0
  54. package/dist/chunks/shared-Bh4xtpHv.js +740 -0
  55. package/dist/chunks/shared-Bh4xtpHv.js.map +1 -0
  56. package/dist/chunks/shared-BlIQttCf.d.ts +1279 -0
  57. package/dist/chunks/shared-BoRfHN1w.js +1511 -0
  58. package/dist/chunks/shared-BoRfHN1w.js.map +1 -0
  59. package/dist/chunks/shared-CPpb2n9T.d.ts +780 -0
  60. package/dist/chunks/shared-Cgb7mhwI.d.ts +471 -0
  61. package/dist/chunks/shared-CzR0rIwZ.cjs +635 -0
  62. package/dist/chunks/shared-CzR0rIwZ.cjs.map +1 -0
  63. package/dist/chunks/shared-DQbEIiTE.cjs +746 -0
  64. package/dist/chunks/shared-DQbEIiTE.cjs.map +1 -0
  65. package/dist/chunks/shared-DzwYUjQn.cjs +457 -0
  66. package/dist/chunks/shared-DzwYUjQn.cjs.map +1 -0
  67. package/dist/chunks/shared-KUvoQkzf.d.ts +471 -0
  68. package/dist/chunks/shared-XH1iLZjy.js +629 -0
  69. package/dist/chunks/shared-XH1iLZjy.js.map +1 -0
  70. package/dist/chunks/shared-kovW7ATj.js +694 -0
  71. package/dist/chunks/shared-kovW7ATj.js.map +1 -0
  72. package/dist/index.cjs +43 -28
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.ts +2 -2
  75. package/dist/index.js +43 -28
  76. package/dist/index.js.map +1 -1
  77. package/package.json +1 -1
@@ -0,0 +1,453 @@
1
+ import { Network, Aptos, AptosConfig, Account, MoveVector, AccountAddress, AbstractedAccount } from '@aptos-labs/ts-sdk';
2
+
3
+ /**
4
+ * Pre-compiled Move script bytecode for add_permissioned_handle
5
+ *
6
+ * This bytecode is used to register session keys on-chain via the
7
+ * `0x1::permissioned_delegation::add_permissioned_handle` function.
8
+ *
9
+ * The function cannot be called as an entry function directly — only via a Move script.
10
+ * This bytecode handles:
11
+ * - Takes the session public key bytes (vector<u8>) as input
12
+ * - Constructs DelegationKey from the bytes
13
+ * - Passes option::none() for rate limiter
14
+ * - Hardcodes u64::MAX for expiration (on-chain handle never expires)
15
+ *
16
+ * Source: aptos-labs/aptos-ts-sdk tests/e2e/transaction/helper.ts
17
+ */
18
+ const ADD_PERMISSIONED_HANDLE_BYTECODE = 'a11ceb0b0700000a0801001002101603262c04520405563d079301d70208ea034010aa041f0103010401060109010d010e011201140002080002080700030b0700040c0f0005100701000001050301010001020704050001030a05060001050f01080100010311090a000106130b01000107150b0100010002030702060c0a020001080001060c010a02010801010802010803010b0401090004060c08020b0401080303010c03060c060c03050802030b04010803060c0c083c53454c463e5f30046d61696e094170746f73436f696e0a6170746f735f636f696e04636f696e196d6967726174655f746f5f66756e6769626c655f73746f72650765643235353139256e65775f756e76616c6964617465645f7075626c69635f6b65795f66726f6d5f627974657314556e76616c6964617465645075626c69634b657917' +
19
+ '7065726d697373696f6e65645f64656c65676174696f6e0f67656e5f656432353531395f6b65790d44656c65676174696f6e4b65790b526174654c696d697465720c726174655f6c696d69746572066f7074696f6e046e6f6e65064f7074696f6e176164645f7065726d697373696f6e65645f68616e646c65167072696d6172795f66756e6769626c655f73746f7265146772616e745f6170745f7065726d697373696f6e167472616e73616374696f6e5f76616c69646174696f6e146772616e745f6761735f7065726d697373696f6effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000114636f6d70696c6174696f6e5f6d65746164617461090003322e3003322e3100000c170a0038000b01110111020c020a0038010c040b020b040600a0724e1809000011040c060a000e060600e1f5050000000011050b000e060600e1f50500000000110602';
20
+
21
+ /**
22
+ * SmoothSend Transaction Submitter
23
+ *
24
+ * A TransactionSubmitter implementation that integrates with the Aptos Wallet Adapter
25
+ * to enable gasless transactions via SmoothSend's relayer network.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { SmoothSendTransactionSubmitter } from '@smoothsend/sdk';
30
+ * import { AptosWalletAdapterProvider } from '@aptos-labs/wallet-adapter-react';
31
+ *
32
+ * // Create the transaction submitter
33
+ * const transactionSubmitter = new SmoothSendTransactionSubmitter({
34
+ * apiKey: 'pk_nogas_your_api_key_here',
35
+ * network: 'testnet'
36
+ * });
37
+ *
38
+ * // Use in your wallet provider - that's it!
39
+ * <AptosWalletAdapterProvider
40
+ * dappConfig={{
41
+ * network: Network.TESTNET,
42
+ * transactionSubmitter: transactionSubmitter
43
+ * }}
44
+ * >
45
+ * <App />
46
+ * </AptosWalletAdapterProvider>
47
+ * ```
48
+ */
49
+ /**
50
+ * SmoothSend Transaction Submitter
51
+ *
52
+ * Implements the TransactionSubmitter interface to enable gasless transactions
53
+ * through the Aptos Wallet Adapter. Simply pass this to your AptosWalletAdapterProvider
54
+ * and all transactions will automatically be submitted as gasless through SmoothSend.
55
+ */
56
+ class SmoothSendTransactionSubmitter {
57
+ constructor(config) {
58
+ this._session = null;
59
+ this.sponsoredFunctionsCache = null;
60
+ this.sponsoredFunctionsCacheAt = 0;
61
+ this.SPONSORED_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
62
+ if (!config.apiKey) {
63
+ throw new Error('SmoothSend API key is required. Get your key at dashboard.smoothsend.xyz');
64
+ }
65
+ // Validate API key format
66
+ if (!config.apiKey.startsWith('pk_nogas_') &&
67
+ !config.apiKey.startsWith('sk_nogas_') &&
68
+ !config.apiKey.startsWith('no_gas_')) {
69
+ throw new Error('Invalid API key format. Key must start with pk_nogas_, sk_nogas_, or no_gas_');
70
+ }
71
+ // Warn if using secret key in browser
72
+ if (config.apiKey.startsWith('sk_nogas_') && typeof window !== 'undefined') {
73
+ console.warn('⚠️ WARNING: Secret key detected in browser environment.\n' +
74
+ 'Secret keys (sk_nogas_*) should only be used in server-side code.\n' +
75
+ 'Use public keys (pk_nogas_*) for frontend applications.');
76
+ }
77
+ this.apiKey = config.apiKey;
78
+ this.network = config.network || 'testnet';
79
+ this.gatewayUrl = config.gatewayUrl || 'https://proxy.smoothsend.xyz';
80
+ this.timeout = config.timeout || 30000;
81
+ this.getCaptchaToken = config.getCaptchaToken;
82
+ this.debug = config.debug || false;
83
+ this.sessionEnabled = config.session || false;
84
+ this.sessionDuration = config.sessionDuration || '24h';
85
+ }
86
+ // ─── Session key methods ────────────────────────────────────────────────────
87
+ /**
88
+ * Whether a valid session is currently active.
89
+ */
90
+ hasSession() {
91
+ return this._session !== null && Date.now() < this._session.expiresAtMs;
92
+ }
93
+ /**
94
+ * Create a session key for the given master account.
95
+ * Called once by useSmoothSend when session: true and no session exists.
96
+ * SmoothSend pays gas for the setup transaction.
97
+ *
98
+ * @param masterAccount - The user's wallet account (from wallet adapter)
99
+ */
100
+ async createSession(masterAccount) {
101
+ const network = this.network === 'mainnet' ? Network.MAINNET : Network.TESTNET;
102
+ const aptosClient = new Aptos(new AptosConfig({ network }));
103
+ // Generate fresh in-memory session keypair
104
+ const sessionAccount = Account.generate();
105
+ const expiresAtMs = Date.now() + this._parseDuration(this.sessionDuration);
106
+ // Step 1: Register session key on-chain via pre-compiled Move script
107
+ const setupTx = await aptosClient.transaction.build.simple({
108
+ sender: masterAccount.accountAddress,
109
+ withFeePayer: true,
110
+ data: {
111
+ bytecode: ADD_PERMISSIONED_HANDLE_BYTECODE,
112
+ functionArguments: [MoveVector.U8(sessionAccount.publicKey.toUint8Array())],
113
+ },
114
+ options: {
115
+ replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
116
+ },
117
+ });
118
+ const senderAuth = await this.signSenderAuthenticator(masterAccount, setupTx, aptosClient);
119
+ const setupResult = await this.submitTransaction({
120
+ aptosConfig: aptosClient.config,
121
+ transaction: setupTx,
122
+ senderAuthenticator: senderAuth,
123
+ });
124
+ await aptosClient.waitForTransaction({ transactionHash: setupResult.hash });
125
+ if (this.debug) {
126
+ console.log('[SmoothSend] Session key registered on-chain:', setupResult.hash);
127
+ }
128
+ // Step 2: Enable account abstraction (idempotent — skip if already on)
129
+ const aaEnabled = await aptosClient.abstraction.isAccountAbstractionEnabled({
130
+ accountAddress: masterAccount.accountAddress,
131
+ authenticationFunction: '0x1::permissioned_delegation::authenticate',
132
+ });
133
+ if (!aaEnabled) {
134
+ const aaTx = await aptosClient.transaction.build.simple({
135
+ sender: masterAccount.accountAddress,
136
+ withFeePayer: true,
137
+ data: {
138
+ function: '0x1::account_abstraction::add_authentication_function',
139
+ functionArguments: [
140
+ AccountAddress.fromString('0x1'),
141
+ 'permissioned_delegation',
142
+ 'authenticate',
143
+ ],
144
+ },
145
+ options: {
146
+ replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
147
+ },
148
+ });
149
+ const aaAuth = await this.signSenderAuthenticator(masterAccount, aaTx, aptosClient);
150
+ const aaResult = await this.submitTransaction({
151
+ aptosConfig: aptosClient.config,
152
+ transaction: aaTx,
153
+ senderAuthenticator: aaAuth,
154
+ });
155
+ await aptosClient.waitForTransaction({ transactionHash: aaResult.hash });
156
+ if (this.debug) {
157
+ console.log('[SmoothSend] Account abstraction enabled:', aaResult.hash);
158
+ }
159
+ }
160
+ // Build AbstractedAccount — signs future txs with session key,
161
+ // sender on-chain = master address, chain validates via permissioned_delegation
162
+ const abstractedAccount = AbstractedAccount.fromPermissionedSigner({
163
+ signer: sessionAccount,
164
+ accountAddress: masterAccount.accountAddress,
165
+ });
166
+ this._session = {
167
+ sessionAccount,
168
+ abstractedAccount,
169
+ masterAddress: masterAccount.accountAddress,
170
+ expiresAtMs,
171
+ aptosClient,
172
+ };
173
+ }
174
+ async isPermissionedSignerEnabled(aptosClient) {
175
+ try {
176
+ const result = await aptosClient.view({
177
+ payload: {
178
+ function: '0x1::features::is_permissioned_signer_enabled',
179
+ functionArguments: [],
180
+ },
181
+ });
182
+ return Array.isArray(result) && result[0] === true;
183
+ }
184
+ catch (error) {
185
+ if (this.debug) {
186
+ console.warn('[SmoothSend] Failed to probe permissioned signer feature:', error);
187
+ }
188
+ return false;
189
+ }
190
+ }
191
+ async signSenderAuthenticator(signer, transaction, aptosClient) {
192
+ const walletLikeSigner = signer;
193
+ // Wallet-adapter compatible path (returns { authenticator, rawTransaction } in v8)
194
+ if (typeof walletLikeSigner?.signTransactionWithAuthenticator === 'function') {
195
+ const result = await walletLikeSigner.signTransactionWithAuthenticator(transaction);
196
+ return (result?.authenticator ?? result);
197
+ }
198
+ // Native ts-sdk account path
199
+ return aptosClient.transaction.sign({
200
+ signer,
201
+ transaction,
202
+ });
203
+ }
204
+ /**
205
+ * Submit a transaction using the active session key — no wallet popup.
206
+ * Called by useSmoothSend after session is established.
207
+ */
208
+ async submitWithSession(functionName, functionArguments = [], typeArguments = []) {
209
+ if (!this._session || !this.hasSession()) {
210
+ throw new Error('[SmoothSend] No active session. Call createSession() first.');
211
+ }
212
+ const { abstractedAccount, masterAddress, aptosClient } = this._session;
213
+ const tx = await aptosClient.transaction.build.simple({
214
+ sender: masterAddress,
215
+ withFeePayer: true,
216
+ data: {
217
+ function: functionName,
218
+ functionArguments,
219
+ ...(typeArguments.length > 0 ? { typeArguments } : {}),
220
+ },
221
+ options: {
222
+ replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
223
+ },
224
+ });
225
+ const senderAuth = aptosClient.transaction.sign({
226
+ signer: abstractedAccount,
227
+ transaction: tx,
228
+ });
229
+ return this.submitTransaction({
230
+ aptosConfig: aptosClient.config,
231
+ transaction: tx,
232
+ senderAuthenticator: senderAuth,
233
+ });
234
+ }
235
+ _parseDuration(duration) {
236
+ if (duration === 'never') {
237
+ // Client-side "never expires" mode; on-chain handle already uses u64::MAX.
238
+ return Number.MAX_SAFE_INTEGER;
239
+ }
240
+ const n = parseInt(duration, 10);
241
+ if (isNaN(n))
242
+ throw new Error(`Invalid sessionDuration "${duration}". Use e.g. "2h", "24h", "7d", or "never".`);
243
+ if (duration.endsWith('s'))
244
+ return n * 1000;
245
+ if (duration.endsWith('m'))
246
+ return n * 60 * 1000;
247
+ if (duration.endsWith('h'))
248
+ return n * 3600 * 1000;
249
+ if (duration.endsWith('d'))
250
+ return n * 86400 * 1000;
251
+ throw new Error(`Unknown unit in "${duration}". Supported: s, m, h, d, or "never".`);
252
+ }
253
+ // ─── Transaction submission ──────────────────────────────────────────────────
254
+ /**
255
+ * Submit a transaction through SmoothSend's gasless relayer
256
+ *
257
+ * This method is called automatically by the Aptos Wallet Adapter when
258
+ * you use signAndSubmitTransaction. The transaction is submitted to
259
+ * SmoothSend's relayer which sponsors the gas fees.
260
+ */
261
+ async submitTransaction(args) {
262
+ const { aptosConfig, transaction, senderAuthenticator, pluginParams } = args;
263
+ // Auto-detect network from aptosConfig (source of truth from wallet adapter)
264
+ // Falls back to constructor value if aptosConfig doesn't have a recognized network
265
+ const detectedNetwork = this.resolveNetwork(aptosConfig);
266
+ if (this.debug) {
267
+ console.log('[SmoothSend] Submitting gasless transaction:', {
268
+ sender: transaction.rawTransaction?.sender?.toString(),
269
+ configNetwork: this.network,
270
+ detectedNetwork,
271
+ });
272
+ }
273
+ if (detectedNetwork !== this.network && this.debug) {
274
+ console.warn(`[SmoothSend] Network mismatch: constructor=${this.network}, aptosConfig=${detectedNetwork}. ` +
275
+ `Using aptosConfig network (${detectedNetwork}).`);
276
+ }
277
+ try {
278
+ // Serialize transaction and authenticator to bytes
279
+ const transactionBytes = Array.from(transaction.bcsToBytes());
280
+ const authenticatorBytes = Array.from(senderAuthenticator.bcsToBytes());
281
+ // Prepare request payload — always use the detected network
282
+ const payload = {
283
+ transactionBytes,
284
+ authenticatorBytes,
285
+ network: detectedNetwork,
286
+ functionName: pluginParams?.functionName || 'unknown',
287
+ };
288
+ // Make request to SmoothSend gateway
289
+ const response = await this.makeRequest('/api/v1/relayer/gasless-transaction', payload, detectedNetwork);
290
+ if (!response.success || !response.txnHash) {
291
+ throw new Error(response.error || response.details || 'Transaction submission failed');
292
+ }
293
+ if (this.debug) {
294
+ console.log('[SmoothSend] Transaction successful:', {
295
+ hash: response.txnHash,
296
+ gasUsed: response.gasUsed,
297
+ });
298
+ }
299
+ // Return in the format expected by Aptos SDK
300
+ return {
301
+ hash: response.txnHash,
302
+ sender: response.sender || transaction.rawTransaction?.sender?.toString() || '',
303
+ sequence_number: transaction.rawTransaction?.sequence_number?.toString() || '0',
304
+ max_gas_amount: transaction.rawTransaction?.max_gas_amount?.toString() || '0',
305
+ gas_unit_price: transaction.rawTransaction?.gas_unit_price?.toString() || '0',
306
+ expiration_timestamp_secs: transaction.rawTransaction?.expiration_timestamp_secs?.toString() || '0',
307
+ payload: {},
308
+ signature: undefined,
309
+ };
310
+ }
311
+ catch (error) {
312
+ if (this.debug) {
313
+ console.error('[SmoothSend] Transaction failed:', error);
314
+ }
315
+ throw new Error(`SmoothSend gasless transaction failed: ${error.message}`);
316
+ }
317
+ }
318
+ /**
319
+ * Resolve the effective network from aptosConfig.
320
+ * aptosConfig.network is the source of truth set by AptosWalletAdapterProvider.
321
+ */
322
+ resolveNetwork(aptosConfig) {
323
+ try {
324
+ const configNetwork = aptosConfig?.network;
325
+ if (configNetwork === 'testnet' || configNetwork === 'mainnet') {
326
+ return configNetwork;
327
+ }
328
+ if (typeof configNetwork === 'string') {
329
+ const normalized = configNetwork.toLowerCase();
330
+ if (normalized === 'testnet' || normalized === 'mainnet') {
331
+ return normalized;
332
+ }
333
+ }
334
+ }
335
+ catch {
336
+ // fall through
337
+ }
338
+ return this.network;
339
+ }
340
+ /**
341
+ * Make an HTTP request to the SmoothSend gateway
342
+ */
343
+ async makeRequest(endpoint, payload, network, method = 'POST') {
344
+ const effectiveNetwork = network || this.network;
345
+ const url = `${this.gatewayUrl}${endpoint}`;
346
+ const headers = {
347
+ 'Content-Type': 'application/json',
348
+ 'X-API-Key': this.apiKey,
349
+ 'X-Chain': `aptos-${effectiveNetwork}`,
350
+ };
351
+ // Add Origin header for public keys in browser
352
+ if (this.apiKey.startsWith('pk_nogas_') && typeof window !== 'undefined') {
353
+ headers['Origin'] = window.location.origin;
354
+ }
355
+ // Add captcha token if the project requires it
356
+ if (this.getCaptchaToken) {
357
+ try {
358
+ const token = await this.getCaptchaToken();
359
+ if (token) {
360
+ headers['X-Captcha-Token'] = token;
361
+ }
362
+ }
363
+ catch (e) {
364
+ if (this.debug) {
365
+ console.warn('[SmoothSend] Failed to get captcha token:', e);
366
+ }
367
+ }
368
+ }
369
+ const controller = new AbortController();
370
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
371
+ try {
372
+ const response = await fetch(url, {
373
+ method,
374
+ headers,
375
+ body: method === 'GET' ? undefined : JSON.stringify(payload),
376
+ signal: controller.signal,
377
+ });
378
+ clearTimeout(timeoutId);
379
+ if (!response.ok) {
380
+ const errorData = await response.json().catch(() => ({}));
381
+ throw new Error(errorData.error || errorData.message || `HTTP ${response.status}`);
382
+ }
383
+ return await response.json();
384
+ }
385
+ catch (error) {
386
+ clearTimeout(timeoutId);
387
+ if (error.name === 'AbortError') {
388
+ throw new Error('Request timed out');
389
+ }
390
+ throw error;
391
+ }
392
+ }
393
+ /**
394
+ * Fetch the list of sponsored functions for this API key's project.
395
+ * Results are cached for 5 minutes. Returns ['*'] if all functions are sponsored.
396
+ */
397
+ async getSponsoredFunctions() {
398
+ const now = Date.now();
399
+ if (this.sponsoredFunctionsCache !== null && now - this.sponsoredFunctionsCacheAt < this.SPONSORED_CACHE_TTL) {
400
+ return this.sponsoredFunctionsCache;
401
+ }
402
+ try {
403
+ const response = await this.makeRequest('/api/v1/sponsorship', {}, undefined, 'GET');
404
+ const fns = response.sponsoredFunctions;
405
+ this.sponsoredFunctionsCache = Array.isArray(fns) ? fns : ['*'];
406
+ }
407
+ catch {
408
+ this.sponsoredFunctionsCache = ['*']; // fail-open: assume all sponsored
409
+ }
410
+ this.sponsoredFunctionsCacheAt = now;
411
+ return this.sponsoredFunctionsCache;
412
+ }
413
+ /**
414
+ * Check if a specific function is sponsored for gasless execution.
415
+ * @param functionName - Full function identifier, e.g. "0x123::module::function"
416
+ */
417
+ async isSponsored(functionName) {
418
+ const fns = await this.getSponsoredFunctions();
419
+ if (fns.includes('*'))
420
+ return true;
421
+ const normalize = (id) => id.replace(/^(0x)0+([1-9a-f][0-9a-f]*)(::.+)$/i, '$1$2$3').toLowerCase();
422
+ const normalized = normalize(functionName);
423
+ return fns.some(f => normalize(f) === normalized);
424
+ }
425
+ /**
426
+ */
427
+ getConfig() {
428
+ return {
429
+ apiKey: this.apiKey.substring(0, 15) + '...', // Don't expose full key
430
+ network: this.network,
431
+ gatewayUrl: this.gatewayUrl,
432
+ timeout: this.timeout,
433
+ debug: this.debug,
434
+ };
435
+ }
436
+ }
437
+ /**
438
+ * Create a SmoothSend transaction submitter with minimal configuration
439
+ *
440
+ * @example
441
+ * ```typescript
442
+ * const submitter = createSmoothSendSubmitter('pk_nogas_your_key');
443
+ * ```
444
+ */
445
+ function createSmoothSendSubmitter(apiKey, options) {
446
+ return new SmoothSendTransactionSubmitter({
447
+ apiKey,
448
+ ...options,
449
+ });
450
+ }
451
+
452
+ export { ADD_PERMISSIONED_HANDLE_BYTECODE as A, SmoothSendTransactionSubmitter as S, createSmoothSendSubmitter as c };
453
+ //# sourceMappingURL=shared-2xx2VLH3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-2xx2VLH3.js","sources":["../../src/session/constants.ts","../../src/wallet-adapter/SmoothSendTransactionSubmitter.ts"],"sourcesContent":[null,null],"names":["AptosConfigClass"],"mappings":";;AAAA;;;;;;;;;;;;;;AAcG;AACI,MAAM,gCAAgC,GAC3C,8nBAA8nB;AAC9nB,IAAA;;ACjBF;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AAqIH;;;;;;AAMG;MACU,8BAA8B,CAAA;AAWzC,IAAA,WAAA,CAAY,MAA4C,EAAA;QAFhD,IAAA,CAAA,QAAQ,GAAwB,IAAI;QA8YpC,IAAA,CAAA,uBAAuB,GAAoB,IAAI;QAC/C,IAAA,CAAA,yBAAyB,GAAG,CAAC;QACpB,IAAA,CAAA,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AA7YnD,QAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;AAClB,YAAA,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC;QAC7F;;QAGA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC;AACxC,YAAA,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC;YACtC,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;AACtC,YAAA,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC;QACjG;;AAGA,QAAA,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAC1E,OAAO,CAAC,IAAI,CACV,2D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,CAAC,KAAK,UAAU,CAAC;IACnD;AAEA;AACG;IACH,SAAS,GAAA;QACP,OAAO;AACL,YAAA,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK;YAC5C,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB;IACH;AACD;AAED;;;;;;;AAOG;AACG,SAAU,yBAAyB,CACvC,MAAc,EACd,OAAuE,EAAA;IAEvE,OAAO,IAAI,8BAA8B,CAAC;QACxC,MAAM;AACN,QAAA,GAAG,OAAO;AACX,KAAA,CAAC;AACJ;;;;"}
@@ -0,0 +1,143 @@
1
+ import { EntryFunctionArgumentTypes, SimpleEntryFunctionArgumentTypes, PendingTransactionResponse } from '@aptos-labs/ts-sdk';
2
+
3
+ /**
4
+ * Types for `useSmoothSendAptosPrivy` and the Privy raw-sign adapter.
5
+ *
6
+ * The hook is wallet-agnostic: it accepts the Privy embedded-wallet address +
7
+ * public key + a `signRawHash` adapter, so the SDK never needs `@privy-io/*`
8
+ * as a peer dependency.
9
+ */
10
+
11
+ type AptosPrivyHash = string;
12
+ /** Internal contract: takes the Aptos signing-message bytes (hex) and returns
13
+ * a 64-byte ed25519 signature as a hex string. */
14
+ interface PrivyAptosRawSigner {
15
+ (input: {
16
+ hash: AptosPrivyHash;
17
+ }): Promise<string>;
18
+ }
19
+ /** Shape extracted from a Privy embedded wallet for Aptos. */
20
+ interface PrivyAptosWalletInfo {
21
+ /** Aptos address from Privy embedded wallet (e.g. `0x123...`) */
22
+ address: string;
23
+ /** 32-byte Ed25519 public key. Accepts hex, `ed25519:` prefix, base64/base64url, or byte-array string. */
24
+ publicKey?: string;
25
+ /** Privy's API/linked-account field name for the public key. */
26
+ public_key?: string;
27
+ type?: string;
28
+ chainType?: string;
29
+ }
30
+ interface PrivyAptosSignRawHash {
31
+ (input: {
32
+ address: string;
33
+ chainType: 'aptos';
34
+ hash: `0x${string}`;
35
+ }): Promise<{
36
+ signature: string;
37
+ }>;
38
+ }
39
+ interface UseSmoothSendAptosPrivyParams {
40
+ /** SmoothSend API key. Use `pk_nogas_*` for browser usage. */
41
+ apiKey: string;
42
+ /** SmoothSend network. Defaults to `'testnet'`. */
43
+ network?: 'testnet' | 'mainnet';
44
+ /** Privy Aptos wallet address (find via `user.linkedAccounts`). */
45
+ address?: string;
46
+ /** Privy Aptos wallet ed25519 public key (hex, 32 bytes). */
47
+ publicKey?: string;
48
+ /**
49
+ * Adapter that calls Privy's `signRawHash({ chainType: 'aptos', address, hash })`
50
+ * and returns the hex signature string.
51
+ */
52
+ signRawHash?: PrivyAptosRawSigner;
53
+ /** Optional Aptos fullnode URL override (e.g. dedicated/private RPC). */
54
+ fullnode?: string;
55
+ /** Optional Aptos API key for fullnode/indexer (sticky-routing key). */
56
+ aptosApiKey?: string;
57
+ /** Override SmoothSend gateway URL (default: `https://proxy.smoothsend.xyz`). */
58
+ gatewayUrl?: string;
59
+ /** Enable verbose `[SmoothSend Aptos+Privy]` logs. */
60
+ debug?: boolean;
61
+ }
62
+ interface UseSmoothSendPrivyWriteParams extends Omit<UseSmoothSendAptosPrivyParams, 'address' | 'publicKey' | 'signRawHash'> {
63
+ /** Aptos wallet from Privy's `user.linkedAccounts`. */
64
+ wallet?: PrivyAptosWalletInfo | null;
65
+ /** Privy's `useSignRawHash().signRawHash`. */
66
+ signRawHash?: PrivyAptosSignRawHash;
67
+ }
68
+ /** Minimal Aptos entry-function payload. Mirrors the shape used by the
69
+ * existing wallet-adapter integration. */
70
+ interface SignAndSubmitTransactionInput {
71
+ function: `${string}::${string}::${string}`;
72
+ typeArguments?: string[];
73
+ functionArguments: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>;
74
+ /** Optional max gas amount override (in gas units). */
75
+ maxGasAmount?: number;
76
+ }
77
+ interface UseSmoothSendAptosPrivyResult {
78
+ /**
79
+ * Build a sponsored Aptos transaction (`withFeePayer: true`), have Privy
80
+ * sign the signing-message via `signRawHash`, then submit through the
81
+ * SmoothSend gateway. The user pays 0 APT gas.
82
+ */
83
+ signAndSubmitTransaction: (input: SignAndSubmitTransactionInput) => Promise<PendingTransactionResponse>;
84
+ isPending: boolean;
85
+ isIdle: boolean;
86
+ status: 'idle' | 'pending' | 'success' | 'error';
87
+ data: PendingTransactionResponse | undefined;
88
+ error: Error | null;
89
+ /** Privy Aptos wallet address (echoed for convenience). */
90
+ address: string | undefined;
91
+ /** True when address + publicKey + signRawHash are all available. */
92
+ isReady: boolean;
93
+ reset: () => void;
94
+ }
95
+ type UseSmoothSendPrivyWriteResult = UseSmoothSendAptosPrivyResult;
96
+
97
+ /**
98
+ * `useSmoothSendAptosPrivy` — Aptos + Privy gasless writes via SmoothSend.
99
+ *
100
+ * Privy's embedded ed25519 wallet signs the signing-message hash via
101
+ * `signRawHash`. SmoothSend's relayer then adds the fee-payer signature and
102
+ * submits, so the end user pays 0 APT gas.
103
+ *
104
+ * This hook is a thin shell over the existing `SmoothSendTransactionSubmitter`
105
+ * — same gasless gateway path used by all other Aptos integrations.
106
+ */
107
+
108
+ declare function useSmoothSendAptosPrivy(params: UseSmoothSendAptosPrivyParams): UseSmoothSendAptosPrivyResult;
109
+
110
+ /**
111
+ * Adapter that wraps Privy's `useSignRawHash().signRawHash` (Tier-2 chains)
112
+ * into the `PrivyAptosRawSigner` shape expected by `useSmoothSendAptosPrivy`.
113
+ *
114
+ * The SDK does NOT import `@privy-io/react-auth` directly — the dApp passes
115
+ * the function in. This keeps Privy as an optional dependency.
116
+ *
117
+ * @example
118
+ * ```tsx
119
+ * import { useSignRawHash } from '@privy-io/react-auth/extended-chains';
120
+ * import { createPrivyAptosSigner, useSmoothSendAptosPrivy } from '@smoothsend/sdk/aptos';
121
+ *
122
+ * const { signRawHash } = useSignRawHash();
123
+ * const signer = createPrivyAptosSigner({ wallet: aptosWallet, signRawHash });
124
+ *
125
+ * const { signAndSubmitTransaction } = useSmoothSendAptosPrivy({
126
+ * apiKey, network: 'testnet',
127
+ * address: aptosWallet?.address,
128
+ * publicKey: aptosWallet?.publicKey,
129
+ * signRawHash: signer,
130
+ * });
131
+ * ```
132
+ */
133
+
134
+ interface CreatePrivyAptosSignerParams {
135
+ /** Aptos embedded wallet from Privy. Look it up via `user.linkedAccounts`. */
136
+ wallet: PrivyAptosWalletInfo | null | undefined;
137
+ /** The `signRawHash` function returned by `useSignRawHash()`. */
138
+ signRawHash: PrivyAptosSignRawHash;
139
+ }
140
+ declare function createPrivyAptosSigner(params: CreatePrivyAptosSignerParams): PrivyAptosRawSigner;
141
+
142
+ export { createPrivyAptosSigner as c, useSmoothSendAptosPrivy as u };
143
+ export type { AptosPrivyHash as A, CreatePrivyAptosSignerParams as C, PrivyAptosRawSigner as P, SignAndSubmitTransactionInput as S, UseSmoothSendAptosPrivyParams as U, PrivyAptosWalletInfo as a, UseSmoothSendAptosPrivyResult as b, UseSmoothSendPrivyWriteParams as d, UseSmoothSendPrivyWriteResult as e, PrivyAptosSignRawHash as f };