@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.
Files changed (52) 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/chunks/shared-2xx2VLH3.js +453 -0
  29. package/dist/chunks/shared-2xx2VLH3.js.map +1 -0
  30. package/dist/chunks/shared-B8UdyBTN.d.ts +143 -0
  31. package/dist/chunks/shared-BJv1JV1H.cjs +702 -0
  32. package/dist/chunks/shared-BJv1JV1H.cjs.map +1 -0
  33. package/dist/chunks/shared-BXvqbQ6f.d.ts +262 -0
  34. package/dist/chunks/shared-Bh4xtpHv.js +740 -0
  35. package/dist/chunks/shared-Bh4xtpHv.js.map +1 -0
  36. package/dist/chunks/shared-BlIQttCf.d.ts +1279 -0
  37. package/dist/chunks/shared-BoRfHN1w.js +1511 -0
  38. package/dist/chunks/shared-BoRfHN1w.js.map +1 -0
  39. package/dist/chunks/shared-CPpb2n9T.d.ts +780 -0
  40. package/dist/chunks/shared-CzR0rIwZ.cjs +635 -0
  41. package/dist/chunks/shared-CzR0rIwZ.cjs.map +1 -0
  42. package/dist/chunks/shared-DQbEIiTE.cjs +746 -0
  43. package/dist/chunks/shared-DQbEIiTE.cjs.map +1 -0
  44. package/dist/chunks/shared-DzwYUjQn.cjs +457 -0
  45. package/dist/chunks/shared-DzwYUjQn.cjs.map +1 -0
  46. package/dist/chunks/shared-KUvoQkzf.d.ts +471 -0
  47. package/dist/chunks/shared-XH1iLZjy.js +629 -0
  48. package/dist/chunks/shared-XH1iLZjy.js.map +1 -0
  49. package/dist/chunks/shared-kovW7ATj.js +694 -0
  50. package/dist/chunks/shared-kovW7ATj.js.map +1 -0
  51. package/dist/index.d.ts +1 -1
  52. package/package.json +1 -1
@@ -0,0 +1,635 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var tsSdk = require('@aptos-labs/ts-sdk');
5
+
6
+ /**
7
+ * Pre-compiled Move script bytecode for add_permissioned_handle
8
+ *
9
+ * This bytecode is used to register session keys on-chain via the
10
+ * `0x1::permissioned_delegation::add_permissioned_handle` function.
11
+ *
12
+ * The function cannot be called as an entry function directly — only via a Move script.
13
+ * This bytecode handles:
14
+ * - Takes the session public key bytes (vector<u8>) as input
15
+ * - Constructs DelegationKey from the bytes
16
+ * - Passes option::none() for rate limiter
17
+ * - Hardcodes u64::MAX for expiration (on-chain handle never expires)
18
+ *
19
+ * Source: aptos-labs/aptos-ts-sdk tests/e2e/transaction/helper.ts
20
+ */
21
+ const ADD_PERMISSIONED_HANDLE_BYTECODE = 'a11ceb0b0700000a0801001002101603262c04520405563d079301d70208ea034010aa041f0103010401060109010d010e011201140002080002080700030b0700040c0f0005100701000001050301010001020704050001030a05060001050f01080100010311090a000106130b01000107150b0100010002030702060c0a020001080001060c010a02010801010802010803010b0401090004060c08020b0401080303010c03060c060c03050802030b04010803060c0c083c53454c463e5f30046d61696e094170746f73436f696e0a6170746f735f636f696e04636f696e196d6967726174655f746f5f66756e6769626c655f73746f72650765643235353139256e65775f756e76616c6964617465645f7075626c69635f6b65795f66726f6d5f627974657314556e76616c6964617465645075626c69634b657917' +
22
+ '7065726d697373696f6e65645f64656c65676174696f6e0f67656e5f656432353531395f6b65790d44656c65676174696f6e4b65790b526174654c696d697465720c726174655f6c696d69746572066f7074696f6e046e6f6e65064f7074696f6e176164645f7065726d697373696f6e65645f68616e646c65167072696d6172795f66756e6769626c655f73746f7265146772616e745f6170745f7065726d697373696f6e167472616e73616374696f6e5f76616c69646174696f6e146772616e745f6761735f7065726d697373696f6effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000114636f6d70696c6174696f6e5f6d65746164617461090003322e3003322e3100000c170a0038000b01110111020c020a0038010c040b020b040600a0724e1809000011040c060a000e060600e1f5050000000011050b000e060600e1f50500000000110602';
23
+
24
+ /**
25
+ * SmoothSend Transaction Submitter
26
+ *
27
+ * A TransactionSubmitter implementation that integrates with the Aptos Wallet Adapter
28
+ * to enable gasless transactions via SmoothSend's relayer network.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { SmoothSendTransactionSubmitter } from '@smoothsend/sdk';
33
+ * import { AptosWalletAdapterProvider } from '@aptos-labs/wallet-adapter-react';
34
+ *
35
+ * // Create the transaction submitter
36
+ * const transactionSubmitter = new SmoothSendTransactionSubmitter({
37
+ * apiKey: 'pk_nogas_your_api_key_here',
38
+ * network: 'testnet'
39
+ * });
40
+ *
41
+ * // Use in your wallet provider - that's it!
42
+ * <AptosWalletAdapterProvider
43
+ * dappConfig={{
44
+ * network: Network.TESTNET,
45
+ * transactionSubmitter: transactionSubmitter
46
+ * }}
47
+ * >
48
+ * <App />
49
+ * </AptosWalletAdapterProvider>
50
+ * ```
51
+ */
52
+ /**
53
+ * SmoothSend Transaction Submitter
54
+ *
55
+ * Implements the TransactionSubmitter interface to enable gasless transactions
56
+ * through the Aptos Wallet Adapter. Simply pass this to your AptosWalletAdapterProvider
57
+ * and all transactions will automatically be submitted as gasless through SmoothSend.
58
+ */
59
+ class SmoothSendTransactionSubmitter {
60
+ constructor(config) {
61
+ this._session = null;
62
+ this.sponsoredFunctionsCache = null;
63
+ this.sponsoredFunctionsCacheAt = 0;
64
+ this.SPONSORED_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
65
+ if (!config.apiKey) {
66
+ throw new Error('SmoothSend API key is required. Get your key at dashboard.smoothsend.xyz');
67
+ }
68
+ // Validate API key format
69
+ if (!config.apiKey.startsWith('pk_nogas_') &&
70
+ !config.apiKey.startsWith('sk_nogas_') &&
71
+ !config.apiKey.startsWith('no_gas_')) {
72
+ throw new Error('Invalid API key format. Key must start with pk_nogas_, sk_nogas_, or no_gas_');
73
+ }
74
+ // Warn if using secret key in browser
75
+ if (config.apiKey.startsWith('sk_nogas_') && typeof window !== 'undefined') {
76
+ console.warn('⚠️ WARNING: Secret key detected in browser environment.\n' +
77
+ 'Secret keys (sk_nogas_*) should only be used in server-side code.\n' +
78
+ 'Use public keys (pk_nogas_*) for frontend applications.');
79
+ }
80
+ this.apiKey = config.apiKey;
81
+ this.network = config.network || 'testnet';
82
+ this.gatewayUrl = config.gatewayUrl || 'https://proxy.smoothsend.xyz';
83
+ this.timeout = config.timeout || 30000;
84
+ this.getCaptchaToken = config.getCaptchaToken;
85
+ this.debug = config.debug || false;
86
+ this.sessionEnabled = config.session || false;
87
+ this.sessionDuration = config.sessionDuration || '24h';
88
+ }
89
+ // ─── Session key methods ────────────────────────────────────────────────────
90
+ /**
91
+ * Whether a valid session is currently active.
92
+ */
93
+ hasSession() {
94
+ return this._session !== null && Date.now() < this._session.expiresAtMs;
95
+ }
96
+ /**
97
+ * Create a session key for the given master account.
98
+ * Called once by useSmoothSend when session: true and no session exists.
99
+ * SmoothSend pays gas for the setup transaction.
100
+ *
101
+ * @param masterAccount - The user's wallet account (from wallet adapter)
102
+ */
103
+ async createSession(masterAccount) {
104
+ const network = this.network === 'mainnet' ? tsSdk.Network.MAINNET : tsSdk.Network.TESTNET;
105
+ const aptosClient = new tsSdk.Aptos(new tsSdk.AptosConfig({ network }));
106
+ // Generate fresh in-memory session keypair
107
+ const sessionAccount = tsSdk.Account.generate();
108
+ const expiresAtMs = Date.now() + this._parseDuration(this.sessionDuration);
109
+ // Step 1: Register session key on-chain via pre-compiled Move script
110
+ const setupTx = await aptosClient.transaction.build.simple({
111
+ sender: masterAccount.accountAddress,
112
+ withFeePayer: true,
113
+ data: {
114
+ bytecode: ADD_PERMISSIONED_HANDLE_BYTECODE,
115
+ functionArguments: [tsSdk.MoveVector.U8(sessionAccount.publicKey.toUint8Array())],
116
+ },
117
+ options: {
118
+ replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
119
+ },
120
+ });
121
+ const senderAuth = await this.signSenderAuthenticator(masterAccount, setupTx, aptosClient);
122
+ const setupResult = await this.submitTransaction({
123
+ aptosConfig: aptosClient.config,
124
+ transaction: setupTx,
125
+ senderAuthenticator: senderAuth,
126
+ });
127
+ await aptosClient.waitForTransaction({ transactionHash: setupResult.hash });
128
+ if (this.debug) {
129
+ console.log('[SmoothSend] Session key registered on-chain:', setupResult.hash);
130
+ }
131
+ // Step 2: Enable account abstraction (idempotent — skip if already on)
132
+ const aaEnabled = await aptosClient.abstraction.isAccountAbstractionEnabled({
133
+ accountAddress: masterAccount.accountAddress,
134
+ authenticationFunction: '0x1::permissioned_delegation::authenticate',
135
+ });
136
+ if (!aaEnabled) {
137
+ const aaTx = await aptosClient.transaction.build.simple({
138
+ sender: masterAccount.accountAddress,
139
+ withFeePayer: true,
140
+ data: {
141
+ function: '0x1::account_abstraction::add_authentication_function',
142
+ functionArguments: [
143
+ tsSdk.AccountAddress.fromString('0x1'),
144
+ 'permissioned_delegation',
145
+ 'authenticate',
146
+ ],
147
+ },
148
+ options: {
149
+ replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
150
+ },
151
+ });
152
+ const aaAuth = await this.signSenderAuthenticator(masterAccount, aaTx, aptosClient);
153
+ const aaResult = await this.submitTransaction({
154
+ aptosConfig: aptosClient.config,
155
+ transaction: aaTx,
156
+ senderAuthenticator: aaAuth,
157
+ });
158
+ await aptosClient.waitForTransaction({ transactionHash: aaResult.hash });
159
+ if (this.debug) {
160
+ console.log('[SmoothSend] Account abstraction enabled:', aaResult.hash);
161
+ }
162
+ }
163
+ // Build AbstractedAccount — signs future txs with session key,
164
+ // sender on-chain = master address, chain validates via permissioned_delegation
165
+ const abstractedAccount = tsSdk.AbstractedAccount.fromPermissionedSigner({
166
+ signer: sessionAccount,
167
+ accountAddress: masterAccount.accountAddress,
168
+ });
169
+ this._session = {
170
+ sessionAccount,
171
+ abstractedAccount,
172
+ masterAddress: masterAccount.accountAddress,
173
+ expiresAtMs,
174
+ aptosClient,
175
+ };
176
+ }
177
+ async isPermissionedSignerEnabled(aptosClient) {
178
+ try {
179
+ const result = await aptosClient.view({
180
+ payload: {
181
+ function: '0x1::features::is_permissioned_signer_enabled',
182
+ functionArguments: [],
183
+ },
184
+ });
185
+ return Array.isArray(result) && result[0] === true;
186
+ }
187
+ catch (error) {
188
+ if (this.debug) {
189
+ console.warn('[SmoothSend] Failed to probe permissioned signer feature:', error);
190
+ }
191
+ return false;
192
+ }
193
+ }
194
+ async signSenderAuthenticator(signer, transaction, aptosClient) {
195
+ const walletLikeSigner = signer;
196
+ // Wallet-adapter compatible path (returns { authenticator, rawTransaction } in v8)
197
+ if (typeof walletLikeSigner?.signTransactionWithAuthenticator === 'function') {
198
+ const result = await walletLikeSigner.signTransactionWithAuthenticator(transaction);
199
+ return (result?.authenticator ?? result);
200
+ }
201
+ // Native ts-sdk account path
202
+ return aptosClient.transaction.sign({
203
+ signer,
204
+ transaction,
205
+ });
206
+ }
207
+ /**
208
+ * Submit a transaction using the active session key — no wallet popup.
209
+ * Called by useSmoothSend after session is established.
210
+ */
211
+ async submitWithSession(functionName, functionArguments = [], typeArguments = []) {
212
+ if (!this._session || !this.hasSession()) {
213
+ throw new Error('[SmoothSend] No active session. Call createSession() first.');
214
+ }
215
+ const { abstractedAccount, masterAddress, aptosClient } = this._session;
216
+ const tx = await aptosClient.transaction.build.simple({
217
+ sender: masterAddress,
218
+ withFeePayer: true,
219
+ data: {
220
+ function: functionName,
221
+ functionArguments,
222
+ ...(typeArguments.length > 0 ? { typeArguments } : {}),
223
+ },
224
+ options: {
225
+ replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
226
+ },
227
+ });
228
+ const senderAuth = aptosClient.transaction.sign({
229
+ signer: abstractedAccount,
230
+ transaction: tx,
231
+ });
232
+ return this.submitTransaction({
233
+ aptosConfig: aptosClient.config,
234
+ transaction: tx,
235
+ senderAuthenticator: senderAuth,
236
+ });
237
+ }
238
+ _parseDuration(duration) {
239
+ if (duration === 'never') {
240
+ // Client-side "never expires" mode; on-chain handle already uses u64::MAX.
241
+ return Number.MAX_SAFE_INTEGER;
242
+ }
243
+ const n = parseInt(duration, 10);
244
+ if (isNaN(n))
245
+ throw new Error(`Invalid sessionDuration "${duration}". Use e.g. "2h", "24h", "7d", or "never".`);
246
+ if (duration.endsWith('s'))
247
+ return n * 1000;
248
+ if (duration.endsWith('m'))
249
+ return n * 60 * 1000;
250
+ if (duration.endsWith('h'))
251
+ return n * 3600 * 1000;
252
+ if (duration.endsWith('d'))
253
+ return n * 86400 * 1000;
254
+ throw new Error(`Unknown unit in "${duration}". Supported: s, m, h, d, or "never".`);
255
+ }
256
+ // ─── Transaction submission ──────────────────────────────────────────────────
257
+ /**
258
+ * Submit a transaction through SmoothSend's gasless relayer
259
+ *
260
+ * This method is called automatically by the Aptos Wallet Adapter when
261
+ * you use signAndSubmitTransaction. The transaction is submitted to
262
+ * SmoothSend's relayer which sponsors the gas fees.
263
+ */
264
+ async submitTransaction(args) {
265
+ const { aptosConfig, transaction, senderAuthenticator, pluginParams } = args;
266
+ // Auto-detect network from aptosConfig (source of truth from wallet adapter)
267
+ // Falls back to constructor value if aptosConfig doesn't have a recognized network
268
+ const detectedNetwork = this.resolveNetwork(aptosConfig);
269
+ if (this.debug) {
270
+ console.log('[SmoothSend] Submitting gasless transaction:', {
271
+ sender: transaction.rawTransaction?.sender?.toString(),
272
+ configNetwork: this.network,
273
+ detectedNetwork,
274
+ });
275
+ }
276
+ if (detectedNetwork !== this.network && this.debug) {
277
+ console.warn(`[SmoothSend] Network mismatch: constructor=${this.network}, aptosConfig=${detectedNetwork}. ` +
278
+ `Using aptosConfig network (${detectedNetwork}).`);
279
+ }
280
+ try {
281
+ // Serialize transaction and authenticator to bytes
282
+ const transactionBytes = Array.from(transaction.bcsToBytes());
283
+ const authenticatorBytes = Array.from(senderAuthenticator.bcsToBytes());
284
+ // Prepare request payload — always use the detected network
285
+ const payload = {
286
+ transactionBytes,
287
+ authenticatorBytes,
288
+ network: detectedNetwork,
289
+ functionName: pluginParams?.functionName || 'unknown',
290
+ };
291
+ // Make request to SmoothSend gateway
292
+ const response = await this.makeRequest('/api/v1/relayer/gasless-transaction', payload, detectedNetwork);
293
+ if (!response.success || !response.txnHash) {
294
+ throw new Error(response.error || response.details || 'Transaction submission failed');
295
+ }
296
+ if (this.debug) {
297
+ console.log('[SmoothSend] Transaction successful:', {
298
+ hash: response.txnHash,
299
+ gasUsed: response.gasUsed,
300
+ });
301
+ }
302
+ // Return in the format expected by Aptos SDK
303
+ return {
304
+ hash: response.txnHash,
305
+ sender: response.sender || transaction.rawTransaction?.sender?.toString() || '',
306
+ sequence_number: transaction.rawTransaction?.sequence_number?.toString() || '0',
307
+ max_gas_amount: transaction.rawTransaction?.max_gas_amount?.toString() || '0',
308
+ gas_unit_price: transaction.rawTransaction?.gas_unit_price?.toString() || '0',
309
+ expiration_timestamp_secs: transaction.rawTransaction?.expiration_timestamp_secs?.toString() || '0',
310
+ payload: {},
311
+ signature: undefined,
312
+ };
313
+ }
314
+ catch (error) {
315
+ if (this.debug) {
316
+ console.error('[SmoothSend] Transaction failed:', error);
317
+ }
318
+ throw new Error(`SmoothSend gasless transaction failed: ${error.message}`);
319
+ }
320
+ }
321
+ /**
322
+ * Resolve the effective network from aptosConfig.
323
+ * aptosConfig.network is the source of truth set by AptosWalletAdapterProvider.
324
+ */
325
+ resolveNetwork(aptosConfig) {
326
+ try {
327
+ const configNetwork = aptosConfig?.network;
328
+ if (configNetwork === 'testnet' || configNetwork === 'mainnet') {
329
+ return configNetwork;
330
+ }
331
+ if (typeof configNetwork === 'string') {
332
+ const normalized = configNetwork.toLowerCase();
333
+ if (normalized === 'testnet' || normalized === 'mainnet') {
334
+ return normalized;
335
+ }
336
+ }
337
+ }
338
+ catch {
339
+ // fall through
340
+ }
341
+ return this.network;
342
+ }
343
+ /**
344
+ * Make an HTTP request to the SmoothSend gateway
345
+ */
346
+ async makeRequest(endpoint, payload, network, method = 'POST') {
347
+ const effectiveNetwork = network || this.network;
348
+ const url = `${this.gatewayUrl}${endpoint}`;
349
+ const headers = {
350
+ 'Content-Type': 'application/json',
351
+ 'X-API-Key': this.apiKey,
352
+ 'X-Chain': `aptos-${effectiveNetwork}`,
353
+ };
354
+ // Add Origin header for public keys in browser
355
+ if (this.apiKey.startsWith('pk_nogas_') && typeof window !== 'undefined') {
356
+ headers['Origin'] = window.location.origin;
357
+ }
358
+ // Add captcha token if the project requires it
359
+ if (this.getCaptchaToken) {
360
+ try {
361
+ const token = await this.getCaptchaToken();
362
+ if (token) {
363
+ headers['X-Captcha-Token'] = token;
364
+ }
365
+ }
366
+ catch (e) {
367
+ if (this.debug) {
368
+ console.warn('[SmoothSend] Failed to get captcha token:', e);
369
+ }
370
+ }
371
+ }
372
+ const controller = new AbortController();
373
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
374
+ try {
375
+ const response = await fetch(url, {
376
+ method,
377
+ headers,
378
+ body: method === 'GET' ? undefined : JSON.stringify(payload),
379
+ signal: controller.signal,
380
+ });
381
+ clearTimeout(timeoutId);
382
+ if (!response.ok) {
383
+ const errorData = await response.json().catch(() => ({}));
384
+ throw new Error(errorData.error || errorData.message || `HTTP ${response.status}`);
385
+ }
386
+ return await response.json();
387
+ }
388
+ catch (error) {
389
+ clearTimeout(timeoutId);
390
+ if (error.name === 'AbortError') {
391
+ throw new Error('Request timed out');
392
+ }
393
+ throw error;
394
+ }
395
+ }
396
+ /**
397
+ * Fetch the list of sponsored functions for this API key's project.
398
+ * Results are cached for 5 minutes. Returns ['*'] if all functions are sponsored.
399
+ */
400
+ async getSponsoredFunctions() {
401
+ const now = Date.now();
402
+ if (this.sponsoredFunctionsCache !== null && now - this.sponsoredFunctionsCacheAt < this.SPONSORED_CACHE_TTL) {
403
+ return this.sponsoredFunctionsCache;
404
+ }
405
+ try {
406
+ const response = await this.makeRequest('/api/v1/sponsorship', {}, undefined, 'GET');
407
+ const fns = response.sponsoredFunctions;
408
+ this.sponsoredFunctionsCache = Array.isArray(fns) ? fns : ['*'];
409
+ }
410
+ catch {
411
+ this.sponsoredFunctionsCache = ['*']; // fail-open: assume all sponsored
412
+ }
413
+ this.sponsoredFunctionsCacheAt = now;
414
+ return this.sponsoredFunctionsCache;
415
+ }
416
+ /**
417
+ * Check if a specific function is sponsored for gasless execution.
418
+ * @param functionName - Full function identifier, e.g. "0x123::module::function"
419
+ */
420
+ async isSponsored(functionName) {
421
+ const fns = await this.getSponsoredFunctions();
422
+ if (fns.includes('*'))
423
+ return true;
424
+ const normalize = (id) => id.replace(/^(0x)0+([1-9a-f][0-9a-f]*)(::.+)$/i, '$1$2$3').toLowerCase();
425
+ const normalized = normalize(functionName);
426
+ return fns.some(f => normalize(f) === normalized);
427
+ }
428
+ /**
429
+ */
430
+ getConfig() {
431
+ return {
432
+ apiKey: this.apiKey.substring(0, 15) + '...', // Don't expose full key
433
+ network: this.network,
434
+ gatewayUrl: this.gatewayUrl,
435
+ timeout: this.timeout,
436
+ debug: this.debug,
437
+ };
438
+ }
439
+ }
440
+ /**
441
+ * Create a SmoothSend transaction submitter with minimal configuration
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * const submitter = createSmoothSendSubmitter('pk_nogas_your_key');
446
+ * ```
447
+ */
448
+ function createSmoothSendSubmitter(apiKey, options) {
449
+ return new SmoothSendTransactionSubmitter({
450
+ apiKey,
451
+ ...options,
452
+ });
453
+ }
454
+
455
+ /**
456
+ * `useSmoothSendAptosPrivy` — Aptos + Privy gasless writes via SmoothSend.
457
+ *
458
+ * Privy's embedded ed25519 wallet signs the signing-message hash via
459
+ * `signRawHash`. SmoothSend's relayer then adds the fee-payer signature and
460
+ * submits, so the end user pays 0 APT gas.
461
+ *
462
+ * This hook is a thin shell over the existing `SmoothSendTransactionSubmitter`
463
+ * — same gasless gateway path used by all other Aptos integrations.
464
+ */
465
+ function bytesToHex(bytes) {
466
+ let hex = '0x';
467
+ for (let i = 0; i < bytes.length; i++) {
468
+ hex += bytes[i].toString(16).padStart(2, '0');
469
+ }
470
+ return hex;
471
+ }
472
+ function stripHexPrefix(value) {
473
+ return value.startsWith('0x') ? value.slice(2) : value;
474
+ }
475
+ function useSmoothSendAptosPrivy(params) {
476
+ const network = params.network ?? 'testnet';
477
+ const aptos = react.useMemo(() => {
478
+ const networkEnum = network === 'mainnet' ? tsSdk.Network.MAINNET : tsSdk.Network.TESTNET;
479
+ const cfg = { network: networkEnum };
480
+ if (params.fullnode)
481
+ cfg.fullnode = params.fullnode;
482
+ if (params.aptosApiKey) {
483
+ cfg.clientConfig = { API_KEY: params.aptosApiKey };
484
+ }
485
+ return new tsSdk.Aptos(new tsSdk.AptosConfig(cfg));
486
+ }, [network, params.fullnode, params.aptosApiKey]);
487
+ const submitter = react.useMemo(() => new SmoothSendTransactionSubmitter({
488
+ apiKey: params.apiKey,
489
+ network,
490
+ gatewayUrl: params.gatewayUrl,
491
+ debug: params.debug,
492
+ }), [params.apiKey, network, params.gatewayUrl, params.debug]);
493
+ const [isPending, setIsPending] = react.useState(false);
494
+ const [data, setData] = react.useState(undefined);
495
+ const [error, setError] = react.useState(null);
496
+ const inFlight = react.useRef(false);
497
+ const reset = react.useCallback(() => {
498
+ setIsPending(false);
499
+ setData(undefined);
500
+ setError(null);
501
+ }, []);
502
+ const isReady = !!params.address && !!params.publicKey && !!params.signRawHash;
503
+ const signAndSubmitTransaction = react.useCallback(async (input) => {
504
+ if (inFlight.current) {
505
+ throw new Error('[SmoothSend Aptos+Privy] Another transaction is already in flight');
506
+ }
507
+ if (!params.address) {
508
+ throw new Error('[SmoothSend Aptos+Privy] Missing Privy Aptos wallet address. Make sure the user is logged in and an embedded Aptos wallet exists.');
509
+ }
510
+ if (!params.publicKey) {
511
+ throw new Error('[SmoothSend Aptos+Privy] Missing Privy Aptos wallet publicKey (32-byte ed25519 hex).');
512
+ }
513
+ if (!params.signRawHash) {
514
+ throw new Error('[SmoothSend Aptos+Privy] Missing signRawHash adapter. Wire up Privy useSignRawHash with chainType: "aptos".');
515
+ }
516
+ inFlight.current = true;
517
+ setIsPending(true);
518
+ setError(null);
519
+ try {
520
+ const sender = tsSdk.AccountAddress.from(params.address);
521
+ const rawTxn = await aptos.transaction.build.simple({
522
+ sender,
523
+ withFeePayer: true,
524
+ data: {
525
+ function: input.function,
526
+ typeArguments: input.typeArguments,
527
+ functionArguments: input.functionArguments,
528
+ },
529
+ options: input.maxGasAmount
530
+ ? { maxGasAmount: input.maxGasAmount }
531
+ : undefined,
532
+ });
533
+ const signingMessage = tsSdk.generateSigningMessageForTransaction(rawTxn);
534
+ const messageHex = bytesToHex(signingMessage);
535
+ if (params.debug) {
536
+ // eslint-disable-next-line no-console
537
+ console.log('[SmoothSend Aptos+Privy] Signing', {
538
+ sender: params.address,
539
+ messageHexLen: messageHex.length,
540
+ });
541
+ }
542
+ const signatureHex = await params.signRawHash({ hash: messageHex });
543
+ const sigClean = stripHexPrefix(signatureHex);
544
+ const senderAuthenticator = new tsSdk.AccountAuthenticatorEd25519(new tsSdk.Ed25519PublicKey(params.publicKey), new tsSdk.Ed25519Signature(sigClean));
545
+ const response = await submitter.submitTransaction({
546
+ aptosConfig: aptos.config,
547
+ transaction: rawTxn,
548
+ senderAuthenticator,
549
+ });
550
+ setData(response);
551
+ return response;
552
+ }
553
+ catch (e) {
554
+ const err = e instanceof Error ? e : new Error(String(e));
555
+ setError(err);
556
+ throw err;
557
+ }
558
+ finally {
559
+ inFlight.current = false;
560
+ setIsPending(false);
561
+ }
562
+ }, [
563
+ aptos,
564
+ submitter,
565
+ params.address,
566
+ params.publicKey,
567
+ params.signRawHash,
568
+ params.debug,
569
+ ]);
570
+ const status = isPending
571
+ ? 'pending'
572
+ : error
573
+ ? 'error'
574
+ : data
575
+ ? 'success'
576
+ : 'idle';
577
+ return {
578
+ signAndSubmitTransaction,
579
+ isPending,
580
+ isIdle: status === 'idle',
581
+ status,
582
+ data,
583
+ error,
584
+ address: params.address,
585
+ isReady,
586
+ reset,
587
+ };
588
+ }
589
+
590
+ /**
591
+ * Adapter that wraps Privy's `useSignRawHash().signRawHash` (Tier-2 chains)
592
+ * into the `PrivyAptosRawSigner` shape expected by `useSmoothSendAptosPrivy`.
593
+ *
594
+ * The SDK does NOT import `@privy-io/react-auth` directly — the dApp passes
595
+ * the function in. This keeps Privy as an optional dependency.
596
+ *
597
+ * @example
598
+ * ```tsx
599
+ * import { useSignRawHash } from '@privy-io/react-auth/extended-chains';
600
+ * import { createPrivyAptosSigner, useSmoothSendAptosPrivy } from '@smoothsend/sdk/aptos';
601
+ *
602
+ * const { signRawHash } = useSignRawHash();
603
+ * const signer = createPrivyAptosSigner({ wallet: aptosWallet, signRawHash });
604
+ *
605
+ * const { signAndSubmitTransaction } = useSmoothSendAptosPrivy({
606
+ * apiKey, network: 'testnet',
607
+ * address: aptosWallet?.address,
608
+ * publicKey: aptosWallet?.publicKey,
609
+ * signRawHash: signer,
610
+ * });
611
+ * ```
612
+ */
613
+ function createPrivyAptosSigner(params) {
614
+ return async ({ hash }) => {
615
+ if (!params.wallet?.address) {
616
+ throw new Error('[SmoothSend Aptos+Privy] Privy Aptos wallet not found. Make sure the user is logged in and an embedded wallet with chainType="aptos" exists.');
617
+ }
618
+ const result = await params.signRawHash({
619
+ address: params.wallet.address,
620
+ chainType: 'aptos',
621
+ hash: hash.startsWith('0x') ? hash : `0x${hash}`,
622
+ });
623
+ if (!result?.signature) {
624
+ throw new Error('[SmoothSend Aptos+Privy] Privy signRawHash returned an empty signature');
625
+ }
626
+ return result.signature;
627
+ };
628
+ }
629
+
630
+ exports.ADD_PERMISSIONED_HANDLE_BYTECODE = ADD_PERMISSIONED_HANDLE_BYTECODE;
631
+ exports.SmoothSendTransactionSubmitter = SmoothSendTransactionSubmitter;
632
+ exports.createPrivyAptosSigner = createPrivyAptosSigner;
633
+ exports.createSmoothSendSubmitter = createSmoothSendSubmitter;
634
+ exports.useSmoothSendAptosPrivy = useSmoothSendAptosPrivy;
635
+ //# sourceMappingURL=shared-CzR0rIwZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-CzR0rIwZ.cjs","sources":["../../src/session/constants.ts","../../src/wallet-adapter/SmoothSendTransactionSubmitter.ts","../../src/aptos-privy/useSmoothSendAptosPrivy.tsx","../../src/aptos-privy/privyAptosSigner.ts"],"sourcesContent":[null,null,null,null],"names":["Network","Aptos","AptosConfigClass","Account","MoveVector","AccountAddress","AbstractedAccount","useMemo","AptosConfig","useState","useRef","useCallback","generateSigningMessageForTransaction","AccountAuthenticatorEd25519","Ed25519PublicKey","Ed25519Signature"],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