@smoothsend/sdk 2.2.0 → 2.2.2
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/README.md +121 -201
- package/dist/avax/SmoothSendAvaxSubmitter.d.ts +79 -0
- package/dist/avax/SmoothSendAvaxSubmitter.d.ts.map +1 -0
- package/dist/avax/index.d.ts +7 -0
- package/dist/avax/index.d.ts.map +1 -0
- package/dist/avax/publicAaDefaults.d.ts +16 -0
- package/dist/avax/publicAaDefaults.d.ts.map +1 -0
- package/dist/avax/simpleAccountFactory.d.ts +44 -0
- package/dist/avax/simpleAccountFactory.d.ts.map +1 -0
- package/dist/avax/types.d.ts +86 -0
- package/dist/avax/types.d.ts.map +1 -0
- package/dist/avax/useSmoothSendAvax.d.ts +60 -0
- package/dist/avax/useSmoothSendAvax.d.ts.map +1 -0
- package/dist/avax/viemHelpers.d.ts +40 -0
- package/dist/avax/viemHelpers.d.ts.map +1 -0
- package/dist/index.d.ts +440 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2370 -131
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2390 -133
- package/dist/index.js.map +1 -1
- package/dist/session/SmoothSendSession.d.ts +1 -6
- package/dist/session/SmoothSendSession.d.ts.map +1 -1
- package/dist/session/constants.d.ts +17 -0
- package/dist/session/constants.d.ts.map +1 -0
- package/dist/true-gasless/TrueGaslessClient.d.ts +72 -0
- package/dist/true-gasless/TrueGaslessClient.d.ts.map +1 -0
- package/dist/true-gasless/index.d.ts +2 -0
- package/dist/true-gasless/index.d.ts.map +1 -0
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/wallet-adapter/SmoothSendTransactionSubmitter.d.ts +53 -2
- package/dist/wallet-adapter/SmoothSendTransactionSubmitter.d.ts.map +1 -1
- package/dist/wallet-adapter/useSmoothSend.d.ts +10 -5
- package/dist/wallet-adapter/useSmoothSend.d.ts.map +1 -1
- package/package.json +18 -7
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { useEffect, useCallback } from 'react';
|
|
3
|
-
import { useWallet } from '@aptos-labs/wallet-adapter-react';
|
|
4
2
|
import { Network, Aptos, AptosConfig, Account, MoveVector, AccountAddress, AbstractedAccount } from '@aptos-labs/ts-sdk';
|
|
3
|
+
import require$$0, { useState, useEffect, useCallback, createContext, useMemo, useContext } from 'react';
|
|
4
|
+
import { useWallet } from '@aptos-labs/wallet-adapter-react';
|
|
5
|
+
import { encodeFunctionData, slice, size, hexToBigInt, toHex } from 'viem';
|
|
6
|
+
import { getUserOperationHash, entryPoint07Abi } from 'viem/account-abstraction';
|
|
7
|
+
import { readContract } from 'viem/actions';
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Error handling system for SmoothSend SDK v2
|
|
@@ -402,7 +405,7 @@ class HttpClient {
|
|
|
402
405
|
this.apiKey = config.apiKey;
|
|
403
406
|
this.network = config.network || 'testnet';
|
|
404
407
|
this.maxRetries = config.retries || 3;
|
|
405
|
-
this.baseURL = 'https://proxy.smoothsend.xyz';
|
|
408
|
+
this.baseURL = config.baseUrl || 'https://proxy.smoothsend.xyz';
|
|
406
409
|
this.isProxyMode = true;
|
|
407
410
|
this.includeOrigin = config.includeOrigin || false;
|
|
408
411
|
const headers = {
|
|
@@ -411,10 +414,9 @@ class HttpClient {
|
|
|
411
414
|
'X-Network': this.network,
|
|
412
415
|
...config.customHeaders,
|
|
413
416
|
};
|
|
414
|
-
//
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
417
|
+
// Browsers forbid setting the `Origin` header manually ("unsafe header").
|
|
418
|
+
// The browser will set it automatically on cross-origin requests.
|
|
419
|
+
// If callers need the origin explicitly, they can pass a custom header (e.g. `X-Origin`).
|
|
418
420
|
this.client = axios.create({
|
|
419
421
|
baseURL: this.baseURL,
|
|
420
422
|
timeout: config.timeout || 30000,
|
|
@@ -2062,6 +2064,24 @@ class SmoothSendSDK {
|
|
|
2062
2064
|
}
|
|
2063
2065
|
}
|
|
2064
2066
|
|
|
2067
|
+
/**
|
|
2068
|
+
* Pre-compiled Move script bytecode for add_permissioned_handle
|
|
2069
|
+
*
|
|
2070
|
+
* This bytecode is used to register session keys on-chain via the
|
|
2071
|
+
* `0x1::permissioned_delegation::add_permissioned_handle` function.
|
|
2072
|
+
*
|
|
2073
|
+
* The function cannot be called as an entry function directly — only via a Move script.
|
|
2074
|
+
* This bytecode handles:
|
|
2075
|
+
* - Takes the session public key bytes (vector<u8>) as input
|
|
2076
|
+
* - Constructs DelegationKey from the bytes
|
|
2077
|
+
* - Passes option::none() for rate limiter
|
|
2078
|
+
* - Hardcodes u64::MAX for expiration (on-chain handle never expires)
|
|
2079
|
+
*
|
|
2080
|
+
* Source: aptos-labs/aptos-ts-sdk tests/e2e/transaction/helper.ts
|
|
2081
|
+
*/
|
|
2082
|
+
const ADD_PERMISSIONED_HANDLE_BYTECODE = 'a11ceb0b0700000a0801001002101603262c04520405563d079301d70208ea034010aa041f0103010401060109010d010e011201140002080002080700030b0700040c0f0005100701000001050301010001020704050001030a05060001050f01080100010311090a000106130b01000107150b0100010002030702060c0a020001080001060c010a02010801010802010803010b0401090004060c08020b0401080303010c03060c060c03050802030b04010803060c0c083c53454c463e5f30046d61696e094170746f73436f696e0a6170746f735f636f696e04636f696e196d6967726174655f746f5f66756e6769626c655f73746f72650765643235353139256e65775f756e76616c6964617465645f7075626c69635f6b65795f66726f6d5f627974657314556e76616c6964617465645075626c69634b657917' +
|
|
2083
|
+
'7065726d697373696f6e65645f64656c65676174696f6e0f67656e5f656432353531395f6b65790d44656c65676174696f6e4b65790b526174654c696d697465720c726174655f6c696d69746572066f7074696f6e046e6f6e65064f7074696f6e176164645f7065726d697373696f6e65645f68616e646c65167072696d6172795f66756e6769626c655f73746f7265146772616e745f6170745f7065726d697373696f6e167472616e73616374696f6e5f76616c69646174696f6e146772616e745f6761735f7065726d697373696f6effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000114636f6d70696c6174696f6e5f6d65746164617461090003322e3003322e3100000c170a0038000b01110111020c020a0038010c040b020b040600a0724e1809000011040c060a000e060600e1f5050000000011050b000e060600e1f50500000000110602';
|
|
2084
|
+
|
|
2065
2085
|
/**
|
|
2066
2086
|
* SmoothSend Transaction Submitter
|
|
2067
2087
|
*
|
|
@@ -2099,6 +2119,7 @@ class SmoothSendSDK {
|
|
|
2099
2119
|
*/
|
|
2100
2120
|
class SmoothSendTransactionSubmitter {
|
|
2101
2121
|
constructor(config) {
|
|
2122
|
+
this._session = null;
|
|
2102
2123
|
this.sponsoredFunctionsCache = null;
|
|
2103
2124
|
this.sponsoredFunctionsCacheAt = 0;
|
|
2104
2125
|
this.SPONSORED_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
@@ -2123,7 +2144,177 @@ class SmoothSendTransactionSubmitter {
|
|
|
2123
2144
|
this.timeout = config.timeout || 30000;
|
|
2124
2145
|
this.getCaptchaToken = config.getCaptchaToken;
|
|
2125
2146
|
this.debug = config.debug || false;
|
|
2147
|
+
this.sessionEnabled = config.session || false;
|
|
2148
|
+
this.sessionDuration = config.sessionDuration || '24h';
|
|
2149
|
+
}
|
|
2150
|
+
// ─── Session key methods ────────────────────────────────────────────────────
|
|
2151
|
+
/**
|
|
2152
|
+
* Whether a valid session is currently active.
|
|
2153
|
+
*/
|
|
2154
|
+
hasSession() {
|
|
2155
|
+
return this._session !== null && Date.now() < this._session.expiresAtMs;
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Create a session key for the given master account.
|
|
2159
|
+
* Called once by useSmoothSend when session: true and no session exists.
|
|
2160
|
+
* SmoothSend pays gas for the setup transaction.
|
|
2161
|
+
*
|
|
2162
|
+
* @param masterAccount - The user's wallet account (from wallet adapter)
|
|
2163
|
+
*/
|
|
2164
|
+
async createSession(masterAccount) {
|
|
2165
|
+
const network = this.network === 'mainnet' ? Network.MAINNET : Network.TESTNET;
|
|
2166
|
+
const aptosClient = new Aptos(new AptosConfig({ network }));
|
|
2167
|
+
// Generate fresh in-memory session keypair
|
|
2168
|
+
const sessionAccount = Account.generate();
|
|
2169
|
+
const expiresAtMs = Date.now() + this._parseDuration(this.sessionDuration);
|
|
2170
|
+
// Step 1: Register session key on-chain via pre-compiled Move script
|
|
2171
|
+
const setupTx = await aptosClient.transaction.build.simple({
|
|
2172
|
+
sender: masterAccount.accountAddress,
|
|
2173
|
+
withFeePayer: true,
|
|
2174
|
+
data: {
|
|
2175
|
+
bytecode: ADD_PERMISSIONED_HANDLE_BYTECODE,
|
|
2176
|
+
functionArguments: [MoveVector.U8(sessionAccount.publicKey.toUint8Array())],
|
|
2177
|
+
},
|
|
2178
|
+
options: {
|
|
2179
|
+
replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
|
|
2180
|
+
},
|
|
2181
|
+
});
|
|
2182
|
+
const senderAuth = await this.signSenderAuthenticator(masterAccount, setupTx, aptosClient);
|
|
2183
|
+
const setupResult = await this.submitTransaction({
|
|
2184
|
+
aptosConfig: aptosClient.config,
|
|
2185
|
+
transaction: setupTx,
|
|
2186
|
+
senderAuthenticator: senderAuth,
|
|
2187
|
+
});
|
|
2188
|
+
await aptosClient.waitForTransaction({ transactionHash: setupResult.hash });
|
|
2189
|
+
if (this.debug) {
|
|
2190
|
+
console.log('[SmoothSend] Session key registered on-chain:', setupResult.hash);
|
|
2191
|
+
}
|
|
2192
|
+
// Step 2: Enable account abstraction (idempotent — skip if already on)
|
|
2193
|
+
const aaEnabled = await aptosClient.abstraction.isAccountAbstractionEnabled({
|
|
2194
|
+
accountAddress: masterAccount.accountAddress,
|
|
2195
|
+
authenticationFunction: '0x1::permissioned_delegation::authenticate',
|
|
2196
|
+
});
|
|
2197
|
+
if (!aaEnabled) {
|
|
2198
|
+
const aaTx = await aptosClient.transaction.build.simple({
|
|
2199
|
+
sender: masterAccount.accountAddress,
|
|
2200
|
+
withFeePayer: true,
|
|
2201
|
+
data: {
|
|
2202
|
+
function: '0x1::account_abstraction::add_authentication_function',
|
|
2203
|
+
functionArguments: [
|
|
2204
|
+
AccountAddress.fromString('0x1'),
|
|
2205
|
+
'permissioned_delegation',
|
|
2206
|
+
'authenticate',
|
|
2207
|
+
],
|
|
2208
|
+
},
|
|
2209
|
+
options: {
|
|
2210
|
+
replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
|
|
2211
|
+
},
|
|
2212
|
+
});
|
|
2213
|
+
const aaAuth = await this.signSenderAuthenticator(masterAccount, aaTx, aptosClient);
|
|
2214
|
+
const aaResult = await this.submitTransaction({
|
|
2215
|
+
aptosConfig: aptosClient.config,
|
|
2216
|
+
transaction: aaTx,
|
|
2217
|
+
senderAuthenticator: aaAuth,
|
|
2218
|
+
});
|
|
2219
|
+
await aptosClient.waitForTransaction({ transactionHash: aaResult.hash });
|
|
2220
|
+
if (this.debug) {
|
|
2221
|
+
console.log('[SmoothSend] Account abstraction enabled:', aaResult.hash);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
// Build AbstractedAccount — signs future txs with session key,
|
|
2225
|
+
// sender on-chain = master address, chain validates via permissioned_delegation
|
|
2226
|
+
const abstractedAccount = AbstractedAccount.fromPermissionedSigner({
|
|
2227
|
+
signer: sessionAccount,
|
|
2228
|
+
accountAddress: masterAccount.accountAddress,
|
|
2229
|
+
});
|
|
2230
|
+
this._session = {
|
|
2231
|
+
sessionAccount,
|
|
2232
|
+
abstractedAccount,
|
|
2233
|
+
masterAddress: masterAccount.accountAddress,
|
|
2234
|
+
expiresAtMs,
|
|
2235
|
+
aptosClient,
|
|
2236
|
+
};
|
|
2237
|
+
}
|
|
2238
|
+
async isPermissionedSignerEnabled(aptosClient) {
|
|
2239
|
+
try {
|
|
2240
|
+
const result = await aptosClient.view({
|
|
2241
|
+
payload: {
|
|
2242
|
+
function: '0x1::features::is_permissioned_signer_enabled',
|
|
2243
|
+
functionArguments: [],
|
|
2244
|
+
},
|
|
2245
|
+
});
|
|
2246
|
+
return Array.isArray(result) && result[0] === true;
|
|
2247
|
+
}
|
|
2248
|
+
catch (error) {
|
|
2249
|
+
if (this.debug) {
|
|
2250
|
+
console.warn('[SmoothSend] Failed to probe permissioned signer feature:', error);
|
|
2251
|
+
}
|
|
2252
|
+
return false;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
async signSenderAuthenticator(signer, transaction, aptosClient) {
|
|
2256
|
+
const walletLikeSigner = signer;
|
|
2257
|
+
// Wallet-adapter compatible path (returns { authenticator, rawTransaction } in v8)
|
|
2258
|
+
if (typeof walletLikeSigner?.signTransactionWithAuthenticator === 'function') {
|
|
2259
|
+
const result = await walletLikeSigner.signTransactionWithAuthenticator(transaction);
|
|
2260
|
+
return (result?.authenticator ?? result);
|
|
2261
|
+
}
|
|
2262
|
+
// Native ts-sdk account path
|
|
2263
|
+
return aptosClient.transaction.sign({
|
|
2264
|
+
signer,
|
|
2265
|
+
transaction,
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Submit a transaction using the active session key — no wallet popup.
|
|
2270
|
+
* Called by useSmoothSend after session is established.
|
|
2271
|
+
*/
|
|
2272
|
+
async submitWithSession(functionName, functionArguments = [], typeArguments = []) {
|
|
2273
|
+
if (!this._session || !this.hasSession()) {
|
|
2274
|
+
throw new Error('[SmoothSend] No active session. Call createSession() first.');
|
|
2275
|
+
}
|
|
2276
|
+
const { abstractedAccount, masterAddress, aptosClient } = this._session;
|
|
2277
|
+
const tx = await aptosClient.transaction.build.simple({
|
|
2278
|
+
sender: masterAddress,
|
|
2279
|
+
withFeePayer: true,
|
|
2280
|
+
data: {
|
|
2281
|
+
function: functionName,
|
|
2282
|
+
functionArguments,
|
|
2283
|
+
...(typeArguments.length > 0 ? { typeArguments } : {}),
|
|
2284
|
+
},
|
|
2285
|
+
options: {
|
|
2286
|
+
replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
|
|
2287
|
+
},
|
|
2288
|
+
});
|
|
2289
|
+
const senderAuth = aptosClient.transaction.sign({
|
|
2290
|
+
signer: abstractedAccount,
|
|
2291
|
+
transaction: tx,
|
|
2292
|
+
});
|
|
2293
|
+
return this.submitTransaction({
|
|
2294
|
+
aptosConfig: aptosClient.config,
|
|
2295
|
+
transaction: tx,
|
|
2296
|
+
senderAuthenticator: senderAuth,
|
|
2297
|
+
});
|
|
2126
2298
|
}
|
|
2299
|
+
_parseDuration(duration) {
|
|
2300
|
+
if (duration === 'never') {
|
|
2301
|
+
// Client-side "never expires" mode; on-chain handle already uses u64::MAX.
|
|
2302
|
+
return Number.MAX_SAFE_INTEGER;
|
|
2303
|
+
}
|
|
2304
|
+
const n = parseInt(duration, 10);
|
|
2305
|
+
if (isNaN(n))
|
|
2306
|
+
throw new Error(`Invalid sessionDuration "${duration}". Use e.g. "2h", "24h", "7d", or "never".`);
|
|
2307
|
+
if (duration.endsWith('s'))
|
|
2308
|
+
return n * 1000;
|
|
2309
|
+
if (duration.endsWith('m'))
|
|
2310
|
+
return n * 60 * 1000;
|
|
2311
|
+
if (duration.endsWith('h'))
|
|
2312
|
+
return n * 3600 * 1000;
|
|
2313
|
+
if (duration.endsWith('d'))
|
|
2314
|
+
return n * 86400 * 1000;
|
|
2315
|
+
throw new Error(`Unknown unit in "${duration}". Supported: s, m, h, d, or "never".`);
|
|
2316
|
+
}
|
|
2317
|
+
// ─── Transaction submission ──────────────────────────────────────────────────
|
|
2127
2318
|
/**
|
|
2128
2319
|
* Submit a transaction through SmoothSend's gasless relayer
|
|
2129
2320
|
*
|
|
@@ -2331,6 +2522,10 @@ function createSmoothSendSubmitter(apiKey, options) {
|
|
|
2331
2522
|
* - Function in allowlist → fee-payer gasless path via SmoothSend
|
|
2332
2523
|
* - Function not in allowlist → regular wallet submission (user pays gas)
|
|
2333
2524
|
*
|
|
2525
|
+
* When submitter has session: true, the first transaction triggers a one-time
|
|
2526
|
+
* wallet sign to register a session key on-chain. Every transaction after that
|
|
2527
|
+
* is signed silently — zero wallet popups.
|
|
2528
|
+
*
|
|
2334
2529
|
* Requires: react >=17, @aptos-labs/wallet-adapter-react >=3, @aptos-labs/ts-sdk >=1
|
|
2335
2530
|
*
|
|
2336
2531
|
* @example
|
|
@@ -2342,13 +2537,11 @@ function createSmoothSendSubmitter(apiKey, options) {
|
|
|
2342
2537
|
* await signAndSubmitTransaction({ data: { function: '0x1::coin::transfer', functionArguments: [to, amount] } });
|
|
2343
2538
|
* ```
|
|
2344
2539
|
*/
|
|
2345
|
-
/**
|
|
2346
|
-
* useSmoothSend
|
|
2347
|
-
*
|
|
2348
|
-
* @param submitter - A SmoothSendTransactionSubmitter instance (created once, e.g. at module scope)
|
|
2349
|
-
*/
|
|
2350
2540
|
function useSmoothSend(submitter) {
|
|
2351
2541
|
const { account, signTransaction, signAndSubmitTransaction: walletSignAndSubmit, } = useWallet();
|
|
2542
|
+
// Track session state reactively so UI updates when session is created/expires
|
|
2543
|
+
const initialHasSession = submitter?.hasSession?.() ?? false;
|
|
2544
|
+
const [hasSessionState, setHasSessionState] = useState(initialHasSession);
|
|
2352
2545
|
// Prefetch the sponsored-functions list on mount so the first transaction
|
|
2353
2546
|
// benefits from an already-populated cache with no added latency.
|
|
2354
2547
|
useEffect(() => {
|
|
@@ -2356,11 +2549,85 @@ function useSmoothSend(submitter) {
|
|
|
2356
2549
|
// Fail-open: getSponsoredFunctions already handles errors internally
|
|
2357
2550
|
});
|
|
2358
2551
|
}, [submitter]);
|
|
2552
|
+
useEffect(() => {
|
|
2553
|
+
if (!submitter)
|
|
2554
|
+
return;
|
|
2555
|
+
const refresh = () => {
|
|
2556
|
+
const hasSession = submitter.hasSession?.() ?? false;
|
|
2557
|
+
setHasSessionState(hasSession);
|
|
2558
|
+
};
|
|
2559
|
+
refresh();
|
|
2560
|
+
const timer = setInterval(refresh, 1000);
|
|
2561
|
+
return () => clearInterval(timer);
|
|
2562
|
+
}, [submitter]);
|
|
2359
2563
|
const signAndSubmitTransaction = useCallback(async (input) => {
|
|
2360
2564
|
if (!account?.address) {
|
|
2361
2565
|
throw new Error('[SmoothSend] Wallet not connected');
|
|
2362
2566
|
}
|
|
2363
2567
|
const functionName = input?.data?.function ?? '';
|
|
2568
|
+
console.log('[SmoothSend] signAndSubmitTransaction called:', {
|
|
2569
|
+
functionName,
|
|
2570
|
+
sessionEnabled: submitter.sessionEnabled,
|
|
2571
|
+
hasSession: submitter.hasSession(),
|
|
2572
|
+
});
|
|
2573
|
+
// ── Session key path ────────────────────────────────────────────────────
|
|
2574
|
+
// When session: true, bypass wallet signing entirely after first setup.
|
|
2575
|
+
// Still respects the per-function allowlist — non-sponsored functions
|
|
2576
|
+
// fall through to regular wallet submission (user pays gas).
|
|
2577
|
+
if (submitter.sessionEnabled) {
|
|
2578
|
+
console.log('[SmoothSend] Session mode enabled');
|
|
2579
|
+
// Check allowlist first — no point setting up a session for a non-sponsored function
|
|
2580
|
+
const canGoGasless = typeof signTransaction === 'function';
|
|
2581
|
+
const sponsored = canGoGasless && (await submitter.isSponsored(functionName));
|
|
2582
|
+
console.log('[SmoothSend] Sponsored check:', { sponsored, canGoGasless });
|
|
2583
|
+
if (sponsored) {
|
|
2584
|
+
// If no active session, do the one-time setup
|
|
2585
|
+
if (!submitter.hasSession()) {
|
|
2586
|
+
console.log('[SmoothSend] No session, creating one...');
|
|
2587
|
+
if (!signTransaction) {
|
|
2588
|
+
console.warn('[SmoothSend] session: true requires signTransaction support. Falling back to regular submission.');
|
|
2589
|
+
}
|
|
2590
|
+
else {
|
|
2591
|
+
try {
|
|
2592
|
+
// Adapter object only needs accountAddress + signTransactionWithAuthenticator.
|
|
2593
|
+
// The submitter handles both wallet-adapter and native signer shapes.
|
|
2594
|
+
const walletAccount = {
|
|
2595
|
+
accountAddress: account.address,
|
|
2596
|
+
signTransactionWithAuthenticator: async (tx) => {
|
|
2597
|
+
const rawResult = await signTransaction({
|
|
2598
|
+
transactionOrPayload: tx,
|
|
2599
|
+
asFeePayer: false,
|
|
2600
|
+
});
|
|
2601
|
+
return rawResult?.authenticator ?? rawResult;
|
|
2602
|
+
},
|
|
2603
|
+
};
|
|
2604
|
+
await submitter.createSession(walletAccount);
|
|
2605
|
+
console.log('[SmoothSend] Session created successfully');
|
|
2606
|
+
setHasSessionState(submitter.hasSession?.() ?? false);
|
|
2607
|
+
}
|
|
2608
|
+
catch (err) {
|
|
2609
|
+
console.warn('[SmoothSend] Session setup failed, falling back to regular gasless:', err.message);
|
|
2610
|
+
// Fall through to normal gasless path below
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
// If session is now active, submit silently — no wallet popup
|
|
2615
|
+
if (submitter.hasSession()) {
|
|
2616
|
+
console.log('[SmoothSend] Session is active, using submitWithSession');
|
|
2617
|
+
try {
|
|
2618
|
+
return await submitter.submitWithSession(functionName, input.data?.functionArguments ?? [], input.data?.typeArguments ?? []);
|
|
2619
|
+
}
|
|
2620
|
+
catch (err) {
|
|
2621
|
+
// Session may have expired mid-flight — clear it and fall through
|
|
2622
|
+
console.warn('[SmoothSend] Session submit failed, will re-auth on next call:', err.message);
|
|
2623
|
+
setHasSessionState(false);
|
|
2624
|
+
// Fall through to regular gasless path for this call
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
// Non-sponsored function → fall through to walletSignAndSubmit below
|
|
2629
|
+
}
|
|
2630
|
+
// ── Regular gasless path (TransactionSubmitter) ─────────────────────────
|
|
2364
2631
|
// signTransaction (sign-only) must be available for the gasless path.
|
|
2365
2632
|
// Most modern wallets (Petra, Nightly) support it. If absent, fall through.
|
|
2366
2633
|
const canGoGasless = typeof signTransaction === 'function';
|
|
@@ -2416,133 +2683,1977 @@ function useSmoothSend(submitter) {
|
|
|
2416
2683
|
// Not sponsored or signTransaction unavailable → regular wallet submission
|
|
2417
2684
|
return walletSignAndSubmit(input);
|
|
2418
2685
|
}, [account, signTransaction, walletSignAndSubmit, submitter]);
|
|
2419
|
-
return {
|
|
2686
|
+
return {
|
|
2687
|
+
signAndSubmitTransaction,
|
|
2688
|
+
hasSession: hasSessionState,
|
|
2689
|
+
};
|
|
2420
2690
|
}
|
|
2421
2691
|
|
|
2422
|
-
// ─── Pre-compiled Move script bytecode ───────────────────────────────────────
|
|
2423
|
-
// Source: aptos-labs/aptos-ts-sdk tests/e2e/transaction/helper.ts
|
|
2424
|
-
// This script calls permissioned_delegation::add_permissioned_handle, which is
|
|
2425
|
-
// NOT an entry function and cannot be called directly — only via a Move script.
|
|
2426
|
-
// Takes one argument: the session public key bytes (vector<u8>).
|
|
2427
|
-
const ADD_PERMISSIONED_HANDLE_BYTECODE = 'a11ceb0b0700000a0801001002101603262c04520405563d079301d70208ea034010aa041f0103010401060109010d010e011201140002080002080700030b0700040c0f0005100701000001050301010001020704050001030a05060001050f01080100010311090a000106130b01000107150b0100010002030702060c0a020001080001060c010a02010801010802010803010b0401090004060c08020b0401080303010c03060c060c03050802030b04010803060c0c083c53454c463e5f30046d61696e094170746f73436f696e0a6170746f735f636f696e04636f696e196d6967726174655f746f5f66756e6769626c655f73746f72650765643235353139256e65775f756e76616c6964617465645f7075626c69635f6b65795f66726f6d5f627974657314556e76616c6964617465645075626c69634b657917' +
|
|
2428
|
-
'7065726d697373696f6e65645f64656c65676174696f6e0f67656e5f656432353531395f6b65790d44656c65676174696f6e4b65790b526174654c696d697465720c726174655f6c696d69746572066f7074696f6e046e6f6e65064f7074696f6e176164645f7065726d697373696f6e65645f68616e646c65167072696d6172795f66756e6769626c655f73746f7265146772616e745f6170745f7065726d697373696f6e167472616e73616374696f6e5f76616c69646174696f6e146772616e745f6761735f7065726d697373696f6effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000114636f6d70696c6174696f6e5f6d65746164617461090003322e3003322e3100000c170a0038000b01110111020c020a0038010c040b020b040600a0724e1809000011040c060a000e060600e1f5050000000011050b000e060600e1f50500000000110602';
|
|
2429
|
-
// ─── helpers ────────────────────────────────────────────────────────────────
|
|
2430
|
-
function parseDurationToSeconds(duration) {
|
|
2431
|
-
const n = parseInt(duration, 10);
|
|
2432
|
-
if (isNaN(n))
|
|
2433
|
-
throw new Error(`Invalid duration "${duration}". Use e.g. "2h", "24h", "7d".`);
|
|
2434
|
-
if (duration.endsWith('s'))
|
|
2435
|
-
return n;
|
|
2436
|
-
if (duration.endsWith('m'))
|
|
2437
|
-
return n * 60;
|
|
2438
|
-
if (duration.endsWith('h'))
|
|
2439
|
-
return n * 3600;
|
|
2440
|
-
if (duration.endsWith('d'))
|
|
2441
|
-
return n * 86400;
|
|
2442
|
-
throw new Error(`Unknown duration unit in "${duration}". Supported: s, m, h, d.`);
|
|
2443
|
-
}
|
|
2444
|
-
// ─── SmoothSendSession ───────────────────────────────────────────────────────
|
|
2445
2692
|
/**
|
|
2446
|
-
*
|
|
2447
|
-
* Session keys require ACCOUNT_ABSTRACTION (feature 85) and PERMISSIONED_SIGNER (feature 84)
|
|
2448
|
-
* to be enabled on the Aptos network. As of now these features are only live on devnet/local node.
|
|
2449
|
-
* This will be fully released when the features are activated on testnet and mainnet.
|
|
2450
|
-
*
|
|
2451
|
-
* A session that lets your app submit transactions on behalf of a user
|
|
2452
|
-
* without any wallet popup after the initial one-time setup.
|
|
2453
|
-
*
|
|
2454
|
-
* Uses Aptos AIP-103 Permissioned Signers — authorization is enforced
|
|
2455
|
-
* on-chain by `0x1::permissioned_delegation`. No custom Move contract needed.
|
|
2456
|
-
*
|
|
2457
|
-
* @example
|
|
2458
|
-
* // 1. One-time setup (user signs once — can be keyless/Google login)
|
|
2459
|
-
* const session = await SmoothSendSession.create({
|
|
2460
|
-
* signer: keylessAccount,
|
|
2461
|
-
* expiresIn: '24h',
|
|
2462
|
-
* }, submitter)
|
|
2693
|
+
* Avalanche ERC-4337 (EntryPoint v0.7) via SmoothSend gateway — same idea as Aptos submitter.
|
|
2463
2694
|
*
|
|
2464
|
-
*
|
|
2465
|
-
*
|
|
2466
|
-
*
|
|
2695
|
+
* Minimal dApp flow:
|
|
2696
|
+
* ```ts
|
|
2697
|
+
* const avax = new SmoothSendAvaxSubmitter({ apiKey, network: 'testnet' });
|
|
2698
|
+
* await avax.submitSponsoredUserOperation({ userOp: draft, signUserOp: wallet.sign });
|
|
2699
|
+
* ```
|
|
2467
2700
|
*/
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2701
|
+
const DEFAULT_GATEWAY = 'https://proxy.smoothsend.xyz';
|
|
2702
|
+
/** Strip ethers@v6 UTF-8 decode noise from bundler JSON-RPC errors (viem shows as “internal error … Details”). */
|
|
2703
|
+
function sanitizeAvaxBundlerRpcMessage(raw) {
|
|
2704
|
+
if (raw.includes('invalid codepoint') ||
|
|
2705
|
+
raw.includes('INVALID_ARGUMENT') ||
|
|
2706
|
+
raw.includes('MISSING_CONTINUE')) {
|
|
2707
|
+
return 'RPC reverted; revert payload could not be decoded as text (usually EntryPoint/account — trace tx on explorer or update bundler).';
|
|
2708
|
+
}
|
|
2709
|
+
return raw;
|
|
2710
|
+
}
|
|
2711
|
+
class SmoothSendAvaxSubmitter {
|
|
2712
|
+
constructor(config) {
|
|
2713
|
+
this.config = config;
|
|
2714
|
+
this.rpcId = 1;
|
|
2715
|
+
if (!config?.apiKey) {
|
|
2716
|
+
throw new Error('[SmoothSendAvaxSubmitter] apiKey is required');
|
|
2717
|
+
}
|
|
2718
|
+
const headers = {
|
|
2719
|
+
'X-Chain': (config.chain ?? 'avalanche').toLowerCase(),
|
|
2720
|
+
};
|
|
2721
|
+
if (config.corsOrigin?.trim()) {
|
|
2722
|
+
headers.Origin = config.corsOrigin.trim();
|
|
2723
|
+
}
|
|
2724
|
+
this.http = new HttpClient({
|
|
2725
|
+
apiKey: config.apiKey,
|
|
2726
|
+
network: config.network ?? 'testnet',
|
|
2727
|
+
baseUrl: config.gatewayUrl ?? DEFAULT_GATEWAY,
|
|
2728
|
+
timeout: config.timeout ?? 45000,
|
|
2729
|
+
customHeaders: headers,
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
getConfig() {
|
|
2733
|
+
return { ...this.config };
|
|
2734
|
+
}
|
|
2735
|
+
/** Merge gas estimate fields into a partial UserOp */
|
|
2736
|
+
static applyGasEstimate(userOp, gas) {
|
|
2737
|
+
return {
|
|
2738
|
+
...userOp,
|
|
2739
|
+
preVerificationGas: gas.preVerificationGas,
|
|
2740
|
+
verificationGasLimit: gas.verificationGasLimit,
|
|
2741
|
+
callGasLimit: gas.callGasLimit,
|
|
2742
|
+
paymasterVerificationGasLimit: gas.paymasterVerificationGasLimit ??
|
|
2743
|
+
userOp.paymasterVerificationGasLimit,
|
|
2744
|
+
paymasterPostOpGasLimit: gas.paymasterPostOpGasLimit ?? userOp.paymasterPostOpGasLimit,
|
|
2745
|
+
};
|
|
2746
|
+
}
|
|
2747
|
+
/** Attach packed paymaster data returned from {@link paymasterSign} */
|
|
2748
|
+
static applyPaymasterAndData(userOp, paymasterAndData) {
|
|
2749
|
+
return {
|
|
2750
|
+
...userOp,
|
|
2751
|
+
paymasterAndData,
|
|
2752
|
+
paymaster: undefined,
|
|
2753
|
+
paymasterData: undefined,
|
|
2754
|
+
paymasterVerificationGasLimit: undefined,
|
|
2755
|
+
paymasterPostOpGasLimit: undefined,
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
async getChainId() {
|
|
2759
|
+
return this.rpc('eth_chainId', []);
|
|
2760
|
+
}
|
|
2761
|
+
async getSupportedEntryPoints() {
|
|
2762
|
+
return this.rpc('eth_supportedEntryPoints', []);
|
|
2763
|
+
}
|
|
2764
|
+
async estimateUserOperationGas(userOp, entryPoint) {
|
|
2765
|
+
return this.rpc('eth_estimateUserOperationGas', [
|
|
2766
|
+
userOp,
|
|
2767
|
+
entryPoint,
|
|
2768
|
+
]);
|
|
2769
|
+
}
|
|
2770
|
+
async sendUserOperation(userOp, entryPoint) {
|
|
2771
|
+
return this.rpc('eth_sendUserOperation', [userOp, entryPoint]);
|
|
2772
|
+
}
|
|
2773
|
+
async getUserOperationReceipt(userOpHash) {
|
|
2774
|
+
return this.rpc('eth_getUserOperationReceipt', [userOpHash]);
|
|
2775
|
+
}
|
|
2776
|
+
async waitForUserOperationReceipt(userOpHash, options) {
|
|
2777
|
+
const pollMs = options?.pollMs ?? 2000;
|
|
2778
|
+
const timeoutMs = options?.timeoutMs ?? 120000;
|
|
2779
|
+
const deadline = Date.now() + timeoutMs;
|
|
2780
|
+
while (Date.now() < deadline) {
|
|
2781
|
+
const receipt = await this.getUserOperationReceipt(userOpHash);
|
|
2782
|
+
if (receipt)
|
|
2783
|
+
return receipt;
|
|
2784
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
2785
|
+
}
|
|
2786
|
+
return null;
|
|
2787
|
+
}
|
|
2788
|
+
async paymasterSign(body) {
|
|
2789
|
+
const res = await this.http.post('/api/v1/bundler/paymaster/sign', body);
|
|
2790
|
+
if (!res.success || !res.data) {
|
|
2791
|
+
throw new Error('[SmoothSendAvaxSubmitter] paymasterSign failed');
|
|
2792
|
+
}
|
|
2793
|
+
const data = res.data;
|
|
2794
|
+
if (!data.success) {
|
|
2795
|
+
throw new Error(`[SmoothSendAvaxSubmitter] paymasterSign: ${data.error ?? 'unknown error'}`);
|
|
2796
|
+
}
|
|
2797
|
+
return data;
|
|
2798
|
+
}
|
|
2799
|
+
async getBundlerHealth() {
|
|
2800
|
+
const res = await this.http.get('/api/v1/bundler/health');
|
|
2801
|
+
if (!res.success)
|
|
2802
|
+
throw new Error('[SmoothSendAvaxSubmitter] health failed');
|
|
2803
|
+
return res.data;
|
|
2477
2804
|
}
|
|
2478
2805
|
/**
|
|
2479
|
-
*
|
|
2480
|
-
*
|
|
2481
|
-
* Registers the session key on-chain via
|
|
2482
|
-
* `0x1::permissioned_delegation::add_permissioned_handle`.
|
|
2483
|
-
* SmoothSend pays the gas for this setup transaction too.
|
|
2484
|
-
*
|
|
2485
|
-
* After this returns, the user never needs to approve anything again
|
|
2486
|
-
* until the session expires or is revoked.
|
|
2806
|
+
* One call: estimate gas → paymaster/sign → merge → your sign → send → (optional) wait for receipt.
|
|
2487
2807
|
*/
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
const
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
withFeePayer: true,
|
|
2504
|
-
data: {
|
|
2505
|
-
bytecode: ADD_PERMISSIONED_HANDLE_BYTECODE,
|
|
2506
|
-
functionArguments: [MoveVector.U8(sessionAccount.publicKey.toUint8Array())],
|
|
2507
|
-
},
|
|
2508
|
-
options: {
|
|
2509
|
-
replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
|
|
2510
|
-
},
|
|
2511
|
-
});
|
|
2512
|
-
const senderAuth = aptosClient.transaction.sign({
|
|
2513
|
-
signer: options.signer,
|
|
2514
|
-
transaction: setupTx,
|
|
2515
|
-
});
|
|
2516
|
-
const setupResult = await submitter.submitTransaction({
|
|
2517
|
-
aptosConfig: aptosClient.config,
|
|
2518
|
-
transaction: setupTx,
|
|
2519
|
-
senderAuthenticator: senderAuth,
|
|
2808
|
+
async submitSponsoredUserOperation(opts) {
|
|
2809
|
+
const entryPoint = opts.entryPoint ?? (await this.getSupportedEntryPoints())[0];
|
|
2810
|
+
if (!entryPoint) {
|
|
2811
|
+
throw new Error('[SmoothSendAvaxSubmitter] no EntryPoint from bundler');
|
|
2812
|
+
}
|
|
2813
|
+
let userOp = {
|
|
2814
|
+
...opts.userOp,
|
|
2815
|
+
signature: opts.userOp.signature ?? '0x',
|
|
2816
|
+
};
|
|
2817
|
+
const gas = await this.estimateUserOperationGas(userOp, entryPoint);
|
|
2818
|
+
userOp = SmoothSendAvaxSubmitter.applyGasEstimate(userOp, gas);
|
|
2819
|
+
const signedPm = await this.paymasterSign({
|
|
2820
|
+
mode: opts.mode ?? 'developer-sponsored',
|
|
2821
|
+
userOp,
|
|
2822
|
+
...opts.paymaster,
|
|
2520
2823
|
});
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2824
|
+
userOp = SmoothSendAvaxSubmitter.applyPaymasterAndData(userOp, signedPm.paymasterAndData);
|
|
2825
|
+
userOp = {
|
|
2826
|
+
...userOp,
|
|
2827
|
+
signature: await opts.signUserOp(userOp),
|
|
2828
|
+
};
|
|
2829
|
+
const userOpHash = await this.sendUserOperation(userOp, entryPoint);
|
|
2830
|
+
if (opts.waitForReceipt === false) {
|
|
2831
|
+
return { userOpHash, receipt: null };
|
|
2832
|
+
}
|
|
2833
|
+
const receipt = await this.waitForUserOperationReceipt(userOpHash, opts.receiptPoll);
|
|
2834
|
+
return { userOpHash, receipt };
|
|
2835
|
+
}
|
|
2836
|
+
async rpc(method, params) {
|
|
2837
|
+
const id = this.rpcId++;
|
|
2838
|
+
const envelope = await this.http.post('/', {
|
|
2839
|
+
jsonrpc: '2.0',
|
|
2840
|
+
id,
|
|
2841
|
+
method,
|
|
2842
|
+
params,
|
|
2528
2843
|
});
|
|
2529
|
-
if (!
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2844
|
+
if (!envelope.success || envelope.data == null) {
|
|
2845
|
+
throw new Error(`[SmoothSendAvaxSubmitter] ${method}: empty response`);
|
|
2846
|
+
}
|
|
2847
|
+
const body = envelope.data;
|
|
2848
|
+
if (body.error) {
|
|
2849
|
+
const msg = sanitizeAvaxBundlerRpcMessage(String(body.error.message ?? ''));
|
|
2850
|
+
throw new Error(`[SmoothSendAvaxSubmitter] ${method}: ${body.error.code} ${msg}`);
|
|
2851
|
+
}
|
|
2852
|
+
if (body.result === undefined) {
|
|
2853
|
+
throw new Error(`[SmoothSendAvaxSubmitter] ${method}: missing result`);
|
|
2854
|
+
}
|
|
2855
|
+
return body.result;
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
/**
|
|
2859
|
+
* @alias {@link SmoothSendAvaxSubmitter}
|
|
2860
|
+
*/
|
|
2861
|
+
const AvaxSubmitter = SmoothSendAvaxSubmitter;
|
|
2862
|
+
function createSmoothSendAvaxSubmitter(config) {
|
|
2863
|
+
return new SmoothSendAvaxSubmitter(config);
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
/**
|
|
2867
|
+
* Viem helpers for ERC-4337 v0.7 + common smart-account `execute` encoding.
|
|
2868
|
+
* Peer dependency: `viem` (optional install).
|
|
2869
|
+
*/
|
|
2870
|
+
/** Typical SimpleAccount-style `execute(dest,value,func)`. */
|
|
2871
|
+
const avaxExecuteAbi = [
|
|
2872
|
+
{
|
|
2873
|
+
name: 'execute',
|
|
2874
|
+
type: 'function',
|
|
2875
|
+
stateMutability: 'nonpayable',
|
|
2876
|
+
inputs: [
|
|
2877
|
+
{ name: 'dest', type: 'address' },
|
|
2878
|
+
{ name: 'value', type: 'uint256' },
|
|
2879
|
+
{ name: 'func', type: 'bytes' },
|
|
2880
|
+
],
|
|
2881
|
+
outputs: [],
|
|
2882
|
+
},
|
|
2883
|
+
];
|
|
2884
|
+
function encodeAvaxExecuteCalldata(to, value, data = '0x') {
|
|
2885
|
+
return encodeFunctionData({
|
|
2886
|
+
abi: avaxExecuteAbi,
|
|
2887
|
+
functionName: 'execute',
|
|
2888
|
+
args: [to, value, data],
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
function parseUint(name, v) {
|
|
2892
|
+
if (v === undefined || v === '') {
|
|
2893
|
+
throw new Error(`[SmoothSend AVAX] UserOp missing ${name}`);
|
|
2894
|
+
}
|
|
2895
|
+
return BigInt(v);
|
|
2896
|
+
}
|
|
2897
|
+
/** Convert API UserOp → viem shape for {@link getUserOperationHash}. */
|
|
2898
|
+
function userOperationAvaxToViem(u) {
|
|
2899
|
+
const base = {
|
|
2900
|
+
sender: u.sender,
|
|
2901
|
+
nonce: parseUint('nonce', u.nonce),
|
|
2902
|
+
callData: (u.callData ?? '0x'),
|
|
2903
|
+
callGasLimit: parseUint('callGasLimit', u.callGasLimit),
|
|
2904
|
+
verificationGasLimit: parseUint('verificationGasLimit', u.verificationGasLimit),
|
|
2905
|
+
preVerificationGas: parseUint('preVerificationGas', u.preVerificationGas),
|
|
2906
|
+
maxFeePerGas: parseUint('maxFeePerGas', u.maxFeePerGas),
|
|
2907
|
+
maxPriorityFeePerGas: parseUint('maxPriorityFeePerGas', u.maxPriorityFeePerGas),
|
|
2908
|
+
signature: (u.signature ?? '0x'),
|
|
2909
|
+
};
|
|
2910
|
+
let out = { ...base };
|
|
2911
|
+
if (u.factory && u.factoryData) {
|
|
2912
|
+
out = {
|
|
2913
|
+
...out,
|
|
2914
|
+
factory: u.factory,
|
|
2915
|
+
factoryData: u.factoryData,
|
|
2916
|
+
};
|
|
2917
|
+
}
|
|
2918
|
+
else if (u.initCode && u.initCode !== '0x') {
|
|
2919
|
+
const ic = u.initCode;
|
|
2920
|
+
out = {
|
|
2921
|
+
...out,
|
|
2922
|
+
factory: slice(ic, 0, 20),
|
|
2923
|
+
factoryData: slice(ic, 20),
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
if (u.paymasterAndData && u.paymasterAndData !== '0x') {
|
|
2927
|
+
const pm = u.paymasterAndData;
|
|
2928
|
+
if (size(pm) < 52) {
|
|
2929
|
+
throw new Error('[SmoothSend AVAX] paymasterAndData too short');
|
|
2930
|
+
}
|
|
2931
|
+
out = {
|
|
2932
|
+
...out,
|
|
2933
|
+
paymaster: slice(pm, 0, 20),
|
|
2934
|
+
paymasterVerificationGasLimit: hexToBigInt(slice(pm, 20, 36)),
|
|
2935
|
+
paymasterPostOpGasLimit: hexToBigInt(slice(pm, 36, 52)),
|
|
2936
|
+
paymasterData: size(pm) > 52 ? slice(pm, 52) : '0x',
|
|
2937
|
+
};
|
|
2938
|
+
}
|
|
2939
|
+
else if (u.paymaster) {
|
|
2940
|
+
out = {
|
|
2941
|
+
...out,
|
|
2942
|
+
paymaster: u.paymaster,
|
|
2943
|
+
paymasterVerificationGasLimit: u.paymasterVerificationGasLimit
|
|
2944
|
+
? BigInt(u.paymasterVerificationGasLimit)
|
|
2945
|
+
: 0n,
|
|
2946
|
+
paymasterPostOpGasLimit: u.paymasterPostOpGasLimit
|
|
2947
|
+
? BigInt(u.paymasterPostOpGasLimit)
|
|
2948
|
+
: 0n,
|
|
2949
|
+
paymasterData: (u.paymasterData ?? '0x'),
|
|
2950
|
+
};
|
|
2951
|
+
}
|
|
2952
|
+
return out;
|
|
2953
|
+
}
|
|
2954
|
+
function hashUserOperationAvax(params) {
|
|
2955
|
+
return getUserOperationHash({
|
|
2956
|
+
chainId: params.chainId,
|
|
2957
|
+
entryPointAddress: params.entryPointAddress,
|
|
2958
|
+
entryPointVersion: '0.7',
|
|
2959
|
+
userOperation: userOperationAvaxToViem(params.userOperation),
|
|
2960
|
+
});
|
|
2961
|
+
}
|
|
2962
|
+
/** EntryPoint v0.7 `getNonce(sender, key)` with key `0`. */
|
|
2963
|
+
async function readAvaxSenderNonce(params) {
|
|
2964
|
+
return readContract(params.publicClient, {
|
|
2965
|
+
address: params.entryPointAddress,
|
|
2966
|
+
abi: entryPoint07Abi,
|
|
2967
|
+
functionName: 'getNonce',
|
|
2968
|
+
args: [params.sender, params.key ?? 0n],
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
/**
|
|
2973
|
+
* Standard SimpleAccountFactory (EntryPoint v0.7) helpers for counterfactual address + init calldata.
|
|
2974
|
+
*/
|
|
2975
|
+
/** Minimal ABI for eth-infinitism–style SimpleAccountFactory. */
|
|
2976
|
+
const SIMPLE_ACCOUNT_FACTORY_ABI = [
|
|
2977
|
+
{
|
|
2978
|
+
inputs: [
|
|
2979
|
+
{ name: 'owner', type: 'address' },
|
|
2980
|
+
{ name: 'salt', type: 'uint256' },
|
|
2981
|
+
],
|
|
2982
|
+
name: 'createAccount',
|
|
2983
|
+
outputs: [{ name: 'account', type: 'address' }],
|
|
2984
|
+
stateMutability: 'nonpayable',
|
|
2985
|
+
type: 'function',
|
|
2986
|
+
},
|
|
2987
|
+
{
|
|
2988
|
+
inputs: [
|
|
2989
|
+
{ name: 'owner', type: 'address' },
|
|
2990
|
+
{ name: 'salt', type: 'uint256' },
|
|
2991
|
+
],
|
|
2992
|
+
name: 'getAddress',
|
|
2993
|
+
outputs: [{ name: '', type: 'address' }],
|
|
2994
|
+
stateMutability: 'view',
|
|
2995
|
+
type: 'function',
|
|
2996
|
+
},
|
|
2997
|
+
];
|
|
2998
|
+
async function predictSimpleAccountAddress(params) {
|
|
2999
|
+
const salt = params.salt ?? 0n;
|
|
3000
|
+
const addr = await readContract(params.publicClient, {
|
|
3001
|
+
address: params.factory,
|
|
3002
|
+
abi: SIMPLE_ACCOUNT_FACTORY_ABI,
|
|
3003
|
+
functionName: 'getAddress',
|
|
3004
|
+
args: [params.owner, salt],
|
|
3005
|
+
});
|
|
3006
|
+
return addr;
|
|
3007
|
+
}
|
|
3008
|
+
function encodeCreateAccountFactoryData(owner, salt) {
|
|
3009
|
+
return encodeFunctionData({
|
|
3010
|
+
abi: SIMPLE_ACCOUNT_FACTORY_ABI,
|
|
3011
|
+
functionName: 'createAccount',
|
|
3012
|
+
args: [owner, salt],
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
/**
|
|
3017
|
+
* Public gateway defaults for Avalanche AA (no API key).
|
|
3018
|
+
*/
|
|
3019
|
+
/** Canonical ERC-4337 EntryPoint v0.7 on Fuji / Avalanche C-Chain */
|
|
3020
|
+
const ENTRY_POINT_V07_ADDRESS = '0x0000000071727De22E5E9d8BAf0edAc6f37da032';
|
|
3021
|
+
/**
|
|
3022
|
+
* Fetch SimpleAccount factory hint from SmoothSend gateway (GET; no auth).
|
|
3023
|
+
* Ops configure {@link https://proxy.smoothsend.xyz} `AVAX_FUJI_SIMPLE_ACCOUNT_FACTORY`; until then this returns null.
|
|
3024
|
+
*/
|
|
3025
|
+
async function fetchAvaxAaPublicDefaults(gatewayUrl = 'https://proxy.smoothsend.xyz') {
|
|
3026
|
+
const base = gatewayUrl.replace(/\/$/, '');
|
|
3027
|
+
const res = await fetch(`${base}/api/v1/public/avax-aa-defaults`);
|
|
3028
|
+
if (!res.ok) {
|
|
3029
|
+
throw new Error(`fetchAvaxAaPublicDefaults failed: HTTP ${res.status}`);
|
|
3030
|
+
}
|
|
3031
|
+
const j = (await res.json());
|
|
3032
|
+
let factory = null;
|
|
3033
|
+
const fac = j.simpleAccountFactoryFuji?.trim();
|
|
3034
|
+
if (fac && fac.startsWith('0x') && /^0x[a-fA-F0-9]{40}$/.test(fac)) {
|
|
3035
|
+
factory = fac;
|
|
3036
|
+
}
|
|
3037
|
+
return {
|
|
3038
|
+
success: j.success,
|
|
3039
|
+
simpleAccountFactoryFuji: factory,
|
|
3040
|
+
entryPointV07: j.entryPointV07?.startsWith('0x') && /^0x[a-fA-F0-9]{40}$/.test(j.entryPointV07)
|
|
3041
|
+
? j.entryPointV07
|
|
3042
|
+
: ENTRY_POINT_V07_ADDRESS,
|
|
3043
|
+
};
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
var jsxRuntime = {exports: {}};
|
|
3047
|
+
|
|
3048
|
+
var reactJsxRuntime_production_min = {};
|
|
3049
|
+
|
|
3050
|
+
/**
|
|
3051
|
+
* @license React
|
|
3052
|
+
* react-jsx-runtime.production.min.js
|
|
3053
|
+
*
|
|
3054
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3055
|
+
*
|
|
3056
|
+
* This source code is licensed under the MIT license found in the
|
|
3057
|
+
* LICENSE file in the root directory of this source tree.
|
|
3058
|
+
*/
|
|
3059
|
+
|
|
3060
|
+
var hasRequiredReactJsxRuntime_production_min;
|
|
3061
|
+
|
|
3062
|
+
function requireReactJsxRuntime_production_min () {
|
|
3063
|
+
if (hasRequiredReactJsxRuntime_production_min) return reactJsxRuntime_production_min;
|
|
3064
|
+
hasRequiredReactJsxRuntime_production_min = 1;
|
|
3065
|
+
var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:true,ref:true,__self:true,__source:true};
|
|
3066
|
+
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a) void 0===d[b]&&(d[b]=a[b]);return {$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;
|
|
3067
|
+
return reactJsxRuntime_production_min;
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
var reactJsxRuntime_development = {};
|
|
3071
|
+
|
|
3072
|
+
/**
|
|
3073
|
+
* @license React
|
|
3074
|
+
* react-jsx-runtime.development.js
|
|
3075
|
+
*
|
|
3076
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3077
|
+
*
|
|
3078
|
+
* This source code is licensed under the MIT license found in the
|
|
3079
|
+
* LICENSE file in the root directory of this source tree.
|
|
3080
|
+
*/
|
|
3081
|
+
|
|
3082
|
+
var hasRequiredReactJsxRuntime_development;
|
|
3083
|
+
|
|
3084
|
+
function requireReactJsxRuntime_development () {
|
|
3085
|
+
if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
|
|
3086
|
+
hasRequiredReactJsxRuntime_development = 1;
|
|
3087
|
+
|
|
3088
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3089
|
+
(function() {
|
|
3090
|
+
|
|
3091
|
+
var React = require$$0;
|
|
3092
|
+
|
|
3093
|
+
// ATTENTION
|
|
3094
|
+
// When adding new symbols to this file,
|
|
3095
|
+
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
|
3096
|
+
// The Symbol used to tag the ReactElement-like types.
|
|
3097
|
+
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
|
3098
|
+
var REACT_PORTAL_TYPE = Symbol.for('react.portal');
|
|
3099
|
+
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
|
3100
|
+
var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
|
|
3101
|
+
var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
|
|
3102
|
+
var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
|
|
3103
|
+
var REACT_CONTEXT_TYPE = Symbol.for('react.context');
|
|
3104
|
+
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
|
3105
|
+
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
|
3106
|
+
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
|
3107
|
+
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
|
3108
|
+
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
|
3109
|
+
var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
|
|
3110
|
+
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
|
3111
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
|
3112
|
+
function getIteratorFn(maybeIterable) {
|
|
3113
|
+
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
|
3114
|
+
return null;
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
|
3118
|
+
|
|
3119
|
+
if (typeof maybeIterator === 'function') {
|
|
3120
|
+
return maybeIterator;
|
|
3121
|
+
}
|
|
3122
|
+
|
|
3123
|
+
return null;
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
3127
|
+
|
|
3128
|
+
function error(format) {
|
|
3129
|
+
{
|
|
3130
|
+
{
|
|
3131
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
3132
|
+
args[_key2 - 1] = arguments[_key2];
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
printWarning('error', format, args);
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
function printWarning(level, format, args) {
|
|
3141
|
+
// When changing this logic, you might want to also
|
|
3142
|
+
// update consoleWithStackDev.www.js as well.
|
|
3143
|
+
{
|
|
3144
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
3145
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
3146
|
+
|
|
3147
|
+
if (stack !== '') {
|
|
3148
|
+
format += '%s';
|
|
3149
|
+
args = args.concat([stack]);
|
|
3150
|
+
} // eslint-disable-next-line react-internal/safe-string-coercion
|
|
3151
|
+
|
|
3152
|
+
|
|
3153
|
+
var argsWithFormat = args.map(function (item) {
|
|
3154
|
+
return String(item);
|
|
3155
|
+
}); // Careful: RN currently depends on this prefix
|
|
3156
|
+
|
|
3157
|
+
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
3158
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
3159
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
|
3160
|
+
|
|
3161
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
// -----------------------------------------------------------------------------
|
|
3166
|
+
|
|
3167
|
+
var enableScopeAPI = false; // Experimental Create Event Handle API.
|
|
3168
|
+
var enableCacheElement = false;
|
|
3169
|
+
var enableTransitionTracing = false; // No known bugs, but needs performance testing
|
|
3170
|
+
|
|
3171
|
+
var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
|
|
3172
|
+
// stuff. Intended to enable React core members to more easily debug scheduling
|
|
3173
|
+
// issues in DEV builds.
|
|
3174
|
+
|
|
3175
|
+
var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
|
|
3176
|
+
|
|
3177
|
+
var REACT_MODULE_REFERENCE;
|
|
3178
|
+
|
|
3179
|
+
{
|
|
3180
|
+
REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
function isValidElementType(type) {
|
|
3184
|
+
if (typeof type === 'string' || typeof type === 'function') {
|
|
3185
|
+
return true;
|
|
3186
|
+
} // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
|
3187
|
+
|
|
3188
|
+
|
|
3189
|
+
if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
|
|
3190
|
+
return true;
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
if (typeof type === 'object' && type !== null) {
|
|
3194
|
+
if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
|
|
3195
|
+
// types supported by any Flight configuration anywhere since
|
|
3196
|
+
// we don't know which Flight build this will end up being used
|
|
3197
|
+
// with.
|
|
3198
|
+
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
|
|
3199
|
+
return true;
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
return false;
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
function getWrappedName(outerType, innerType, wrapperName) {
|
|
3207
|
+
var displayName = outerType.displayName;
|
|
3208
|
+
|
|
3209
|
+
if (displayName) {
|
|
3210
|
+
return displayName;
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
var functionName = innerType.displayName || innerType.name || '';
|
|
3214
|
+
return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
|
|
3215
|
+
} // Keep in sync with react-reconciler/getComponentNameFromFiber
|
|
3216
|
+
|
|
3217
|
+
|
|
3218
|
+
function getContextName(type) {
|
|
3219
|
+
return type.displayName || 'Context';
|
|
3220
|
+
} // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
|
|
3221
|
+
|
|
3222
|
+
|
|
3223
|
+
function getComponentNameFromType(type) {
|
|
3224
|
+
if (type == null) {
|
|
3225
|
+
// Host root, text node or just invalid type.
|
|
3226
|
+
return null;
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
{
|
|
3230
|
+
if (typeof type.tag === 'number') {
|
|
3231
|
+
error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
|
|
3235
|
+
if (typeof type === 'function') {
|
|
3236
|
+
return type.displayName || type.name || null;
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
if (typeof type === 'string') {
|
|
3240
|
+
return type;
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
switch (type) {
|
|
3244
|
+
case REACT_FRAGMENT_TYPE:
|
|
3245
|
+
return 'Fragment';
|
|
3246
|
+
|
|
3247
|
+
case REACT_PORTAL_TYPE:
|
|
3248
|
+
return 'Portal';
|
|
3249
|
+
|
|
3250
|
+
case REACT_PROFILER_TYPE:
|
|
3251
|
+
return 'Profiler';
|
|
3252
|
+
|
|
3253
|
+
case REACT_STRICT_MODE_TYPE:
|
|
3254
|
+
return 'StrictMode';
|
|
3255
|
+
|
|
3256
|
+
case REACT_SUSPENSE_TYPE:
|
|
3257
|
+
return 'Suspense';
|
|
3258
|
+
|
|
3259
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
3260
|
+
return 'SuspenseList';
|
|
3261
|
+
|
|
3262
|
+
}
|
|
3263
|
+
|
|
3264
|
+
if (typeof type === 'object') {
|
|
3265
|
+
switch (type.$$typeof) {
|
|
3266
|
+
case REACT_CONTEXT_TYPE:
|
|
3267
|
+
var context = type;
|
|
3268
|
+
return getContextName(context) + '.Consumer';
|
|
3269
|
+
|
|
3270
|
+
case REACT_PROVIDER_TYPE:
|
|
3271
|
+
var provider = type;
|
|
3272
|
+
return getContextName(provider._context) + '.Provider';
|
|
3273
|
+
|
|
3274
|
+
case REACT_FORWARD_REF_TYPE:
|
|
3275
|
+
return getWrappedName(type, type.render, 'ForwardRef');
|
|
3276
|
+
|
|
3277
|
+
case REACT_MEMO_TYPE:
|
|
3278
|
+
var outerName = type.displayName || null;
|
|
3279
|
+
|
|
3280
|
+
if (outerName !== null) {
|
|
3281
|
+
return outerName;
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
return getComponentNameFromType(type.type) || 'Memo';
|
|
3285
|
+
|
|
3286
|
+
case REACT_LAZY_TYPE:
|
|
3287
|
+
{
|
|
3288
|
+
var lazyComponent = type;
|
|
3289
|
+
var payload = lazyComponent._payload;
|
|
3290
|
+
var init = lazyComponent._init;
|
|
3291
|
+
|
|
3292
|
+
try {
|
|
3293
|
+
return getComponentNameFromType(init(payload));
|
|
3294
|
+
} catch (x) {
|
|
3295
|
+
return null;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
// eslint-disable-next-line no-fallthrough
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3303
|
+
return null;
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
var assign = Object.assign;
|
|
3307
|
+
|
|
3308
|
+
// Helpers to patch console.logs to avoid logging during side-effect free
|
|
3309
|
+
// replaying on render function. This currently only patches the object
|
|
3310
|
+
// lazily which won't cover if the log function was extracted eagerly.
|
|
3311
|
+
// We could also eagerly patch the method.
|
|
3312
|
+
var disabledDepth = 0;
|
|
3313
|
+
var prevLog;
|
|
3314
|
+
var prevInfo;
|
|
3315
|
+
var prevWarn;
|
|
3316
|
+
var prevError;
|
|
3317
|
+
var prevGroup;
|
|
3318
|
+
var prevGroupCollapsed;
|
|
3319
|
+
var prevGroupEnd;
|
|
3320
|
+
|
|
3321
|
+
function disabledLog() {}
|
|
3322
|
+
|
|
3323
|
+
disabledLog.__reactDisabledLog = true;
|
|
3324
|
+
function disableLogs() {
|
|
3325
|
+
{
|
|
3326
|
+
if (disabledDepth === 0) {
|
|
3327
|
+
/* eslint-disable react-internal/no-production-logging */
|
|
3328
|
+
prevLog = console.log;
|
|
3329
|
+
prevInfo = console.info;
|
|
3330
|
+
prevWarn = console.warn;
|
|
3331
|
+
prevError = console.error;
|
|
3332
|
+
prevGroup = console.group;
|
|
3333
|
+
prevGroupCollapsed = console.groupCollapsed;
|
|
3334
|
+
prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
|
|
3335
|
+
|
|
3336
|
+
var props = {
|
|
3337
|
+
configurable: true,
|
|
3338
|
+
enumerable: true,
|
|
3339
|
+
value: disabledLog,
|
|
3340
|
+
writable: true
|
|
3341
|
+
}; // $FlowFixMe Flow thinks console is immutable.
|
|
3342
|
+
|
|
3343
|
+
Object.defineProperties(console, {
|
|
3344
|
+
info: props,
|
|
3345
|
+
log: props,
|
|
3346
|
+
warn: props,
|
|
3347
|
+
error: props,
|
|
3348
|
+
group: props,
|
|
3349
|
+
groupCollapsed: props,
|
|
3350
|
+
groupEnd: props
|
|
3351
|
+
});
|
|
3352
|
+
/* eslint-enable react-internal/no-production-logging */
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
disabledDepth++;
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
function reenableLogs() {
|
|
3359
|
+
{
|
|
3360
|
+
disabledDepth--;
|
|
3361
|
+
|
|
3362
|
+
if (disabledDepth === 0) {
|
|
3363
|
+
/* eslint-disable react-internal/no-production-logging */
|
|
3364
|
+
var props = {
|
|
3365
|
+
configurable: true,
|
|
3366
|
+
enumerable: true,
|
|
3367
|
+
writable: true
|
|
3368
|
+
}; // $FlowFixMe Flow thinks console is immutable.
|
|
3369
|
+
|
|
3370
|
+
Object.defineProperties(console, {
|
|
3371
|
+
log: assign({}, props, {
|
|
3372
|
+
value: prevLog
|
|
3373
|
+
}),
|
|
3374
|
+
info: assign({}, props, {
|
|
3375
|
+
value: prevInfo
|
|
3376
|
+
}),
|
|
3377
|
+
warn: assign({}, props, {
|
|
3378
|
+
value: prevWarn
|
|
3379
|
+
}),
|
|
3380
|
+
error: assign({}, props, {
|
|
3381
|
+
value: prevError
|
|
3382
|
+
}),
|
|
3383
|
+
group: assign({}, props, {
|
|
3384
|
+
value: prevGroup
|
|
3385
|
+
}),
|
|
3386
|
+
groupCollapsed: assign({}, props, {
|
|
3387
|
+
value: prevGroupCollapsed
|
|
3388
|
+
}),
|
|
3389
|
+
groupEnd: assign({}, props, {
|
|
3390
|
+
value: prevGroupEnd
|
|
3391
|
+
})
|
|
3392
|
+
});
|
|
3393
|
+
/* eslint-enable react-internal/no-production-logging */
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
if (disabledDepth < 0) {
|
|
3397
|
+
error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
|
|
3403
|
+
var prefix;
|
|
3404
|
+
function describeBuiltInComponentFrame(name, source, ownerFn) {
|
|
3405
|
+
{
|
|
3406
|
+
if (prefix === undefined) {
|
|
3407
|
+
// Extract the VM specific prefix used by each line.
|
|
3408
|
+
try {
|
|
3409
|
+
throw Error();
|
|
3410
|
+
} catch (x) {
|
|
3411
|
+
var match = x.stack.trim().match(/\n( *(at )?)/);
|
|
3412
|
+
prefix = match && match[1] || '';
|
|
3413
|
+
}
|
|
3414
|
+
} // We use the prefix to ensure our stacks line up with native stack frames.
|
|
3415
|
+
|
|
3416
|
+
|
|
3417
|
+
return '\n' + prefix + name;
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
var reentry = false;
|
|
3421
|
+
var componentFrameCache;
|
|
3422
|
+
|
|
3423
|
+
{
|
|
3424
|
+
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
|
|
3425
|
+
componentFrameCache = new PossiblyWeakMap();
|
|
3426
|
+
}
|
|
3427
|
+
|
|
3428
|
+
function describeNativeComponentFrame(fn, construct) {
|
|
3429
|
+
// If something asked for a stack inside a fake render, it should get ignored.
|
|
3430
|
+
if ( !fn || reentry) {
|
|
3431
|
+
return '';
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
{
|
|
3435
|
+
var frame = componentFrameCache.get(fn);
|
|
3436
|
+
|
|
3437
|
+
if (frame !== undefined) {
|
|
3438
|
+
return frame;
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
var control;
|
|
3443
|
+
reentry = true;
|
|
3444
|
+
var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
|
|
3445
|
+
|
|
3446
|
+
Error.prepareStackTrace = undefined;
|
|
3447
|
+
var previousDispatcher;
|
|
3448
|
+
|
|
3449
|
+
{
|
|
3450
|
+
previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
|
|
3451
|
+
// for warnings.
|
|
3452
|
+
|
|
3453
|
+
ReactCurrentDispatcher.current = null;
|
|
3454
|
+
disableLogs();
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3457
|
+
try {
|
|
3458
|
+
// This should throw.
|
|
3459
|
+
if (construct) {
|
|
3460
|
+
// Something should be setting the props in the constructor.
|
|
3461
|
+
var Fake = function () {
|
|
3462
|
+
throw Error();
|
|
3463
|
+
}; // $FlowFixMe
|
|
3464
|
+
|
|
3465
|
+
|
|
3466
|
+
Object.defineProperty(Fake.prototype, 'props', {
|
|
3467
|
+
set: function () {
|
|
3468
|
+
// We use a throwing setter instead of frozen or non-writable props
|
|
3469
|
+
// because that won't throw in a non-strict mode function.
|
|
3470
|
+
throw Error();
|
|
3471
|
+
}
|
|
3472
|
+
});
|
|
3473
|
+
|
|
3474
|
+
if (typeof Reflect === 'object' && Reflect.construct) {
|
|
3475
|
+
// We construct a different control for this case to include any extra
|
|
3476
|
+
// frames added by the construct call.
|
|
3477
|
+
try {
|
|
3478
|
+
Reflect.construct(Fake, []);
|
|
3479
|
+
} catch (x) {
|
|
3480
|
+
control = x;
|
|
3481
|
+
}
|
|
3482
|
+
|
|
3483
|
+
Reflect.construct(fn, [], Fake);
|
|
3484
|
+
} else {
|
|
3485
|
+
try {
|
|
3486
|
+
Fake.call();
|
|
3487
|
+
} catch (x) {
|
|
3488
|
+
control = x;
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
fn.call(Fake.prototype);
|
|
3492
|
+
}
|
|
3493
|
+
} else {
|
|
3494
|
+
try {
|
|
3495
|
+
throw Error();
|
|
3496
|
+
} catch (x) {
|
|
3497
|
+
control = x;
|
|
3498
|
+
}
|
|
3499
|
+
|
|
3500
|
+
fn();
|
|
3501
|
+
}
|
|
3502
|
+
} catch (sample) {
|
|
3503
|
+
// This is inlined manually because closure doesn't do it for us.
|
|
3504
|
+
if (sample && control && typeof sample.stack === 'string') {
|
|
3505
|
+
// This extracts the first frame from the sample that isn't also in the control.
|
|
3506
|
+
// Skipping one frame that we assume is the frame that calls the two.
|
|
3507
|
+
var sampleLines = sample.stack.split('\n');
|
|
3508
|
+
var controlLines = control.stack.split('\n');
|
|
3509
|
+
var s = sampleLines.length - 1;
|
|
3510
|
+
var c = controlLines.length - 1;
|
|
3511
|
+
|
|
3512
|
+
while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
|
|
3513
|
+
// We expect at least one stack frame to be shared.
|
|
3514
|
+
// Typically this will be the root most one. However, stack frames may be
|
|
3515
|
+
// cut off due to maximum stack limits. In this case, one maybe cut off
|
|
3516
|
+
// earlier than the other. We assume that the sample is longer or the same
|
|
3517
|
+
// and there for cut off earlier. So we should find the root most frame in
|
|
3518
|
+
// the sample somewhere in the control.
|
|
3519
|
+
c--;
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
for (; s >= 1 && c >= 0; s--, c--) {
|
|
3523
|
+
// Next we find the first one that isn't the same which should be the
|
|
3524
|
+
// frame that called our sample function and the control.
|
|
3525
|
+
if (sampleLines[s] !== controlLines[c]) {
|
|
3526
|
+
// In V8, the first line is describing the message but other VMs don't.
|
|
3527
|
+
// If we're about to return the first line, and the control is also on the same
|
|
3528
|
+
// line, that's a pretty good indicator that our sample threw at same line as
|
|
3529
|
+
// the control. I.e. before we entered the sample frame. So we ignore this result.
|
|
3530
|
+
// This can happen if you passed a class to function component, or non-function.
|
|
3531
|
+
if (s !== 1 || c !== 1) {
|
|
3532
|
+
do {
|
|
3533
|
+
s--;
|
|
3534
|
+
c--; // We may still have similar intermediate frames from the construct call.
|
|
3535
|
+
// The next one that isn't the same should be our match though.
|
|
3536
|
+
|
|
3537
|
+
if (c < 0 || sampleLines[s] !== controlLines[c]) {
|
|
3538
|
+
// V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
|
|
3539
|
+
var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
|
|
3540
|
+
// but we have a user-provided "displayName"
|
|
3541
|
+
// splice it in to make the stack more readable.
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
if (fn.displayName && _frame.includes('<anonymous>')) {
|
|
3545
|
+
_frame = _frame.replace('<anonymous>', fn.displayName);
|
|
3546
|
+
}
|
|
3547
|
+
|
|
3548
|
+
{
|
|
3549
|
+
if (typeof fn === 'function') {
|
|
3550
|
+
componentFrameCache.set(fn, _frame);
|
|
3551
|
+
}
|
|
3552
|
+
} // Return the line we found.
|
|
3553
|
+
|
|
3554
|
+
|
|
3555
|
+
return _frame;
|
|
3556
|
+
}
|
|
3557
|
+
} while (s >= 1 && c >= 0);
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
break;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
} finally {
|
|
3565
|
+
reentry = false;
|
|
3566
|
+
|
|
3567
|
+
{
|
|
3568
|
+
ReactCurrentDispatcher.current = previousDispatcher;
|
|
3569
|
+
reenableLogs();
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3572
|
+
Error.prepareStackTrace = previousPrepareStackTrace;
|
|
3573
|
+
} // Fallback to just using the name if we couldn't make it throw.
|
|
3574
|
+
|
|
3575
|
+
|
|
3576
|
+
var name = fn ? fn.displayName || fn.name : '';
|
|
3577
|
+
var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
|
|
3578
|
+
|
|
3579
|
+
{
|
|
3580
|
+
if (typeof fn === 'function') {
|
|
3581
|
+
componentFrameCache.set(fn, syntheticFrame);
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
return syntheticFrame;
|
|
3586
|
+
}
|
|
3587
|
+
function describeFunctionComponentFrame(fn, source, ownerFn) {
|
|
3588
|
+
{
|
|
3589
|
+
return describeNativeComponentFrame(fn, false);
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
function shouldConstruct(Component) {
|
|
3594
|
+
var prototype = Component.prototype;
|
|
3595
|
+
return !!(prototype && prototype.isReactComponent);
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
|
|
3599
|
+
|
|
3600
|
+
if (type == null) {
|
|
3601
|
+
return '';
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3604
|
+
if (typeof type === 'function') {
|
|
3605
|
+
{
|
|
3606
|
+
return describeNativeComponentFrame(type, shouldConstruct(type));
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
if (typeof type === 'string') {
|
|
3611
|
+
return describeBuiltInComponentFrame(type);
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
switch (type) {
|
|
3615
|
+
case REACT_SUSPENSE_TYPE:
|
|
3616
|
+
return describeBuiltInComponentFrame('Suspense');
|
|
3617
|
+
|
|
3618
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
3619
|
+
return describeBuiltInComponentFrame('SuspenseList');
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
if (typeof type === 'object') {
|
|
3623
|
+
switch (type.$$typeof) {
|
|
3624
|
+
case REACT_FORWARD_REF_TYPE:
|
|
3625
|
+
return describeFunctionComponentFrame(type.render);
|
|
3626
|
+
|
|
3627
|
+
case REACT_MEMO_TYPE:
|
|
3628
|
+
// Memo may contain any component type so we recursively resolve it.
|
|
3629
|
+
return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
|
|
3630
|
+
|
|
3631
|
+
case REACT_LAZY_TYPE:
|
|
3632
|
+
{
|
|
3633
|
+
var lazyComponent = type;
|
|
3634
|
+
var payload = lazyComponent._payload;
|
|
3635
|
+
var init = lazyComponent._init;
|
|
3636
|
+
|
|
3637
|
+
try {
|
|
3638
|
+
// Lazy may contain any component type so we recursively resolve it.
|
|
3639
|
+
return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
|
|
3640
|
+
} catch (x) {}
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
}
|
|
3644
|
+
|
|
3645
|
+
return '';
|
|
3646
|
+
}
|
|
3647
|
+
|
|
3648
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3649
|
+
|
|
3650
|
+
var loggedTypeFailures = {};
|
|
3651
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
3652
|
+
|
|
3653
|
+
function setCurrentlyValidatingElement(element) {
|
|
3654
|
+
{
|
|
3655
|
+
if (element) {
|
|
3656
|
+
var owner = element._owner;
|
|
3657
|
+
var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
|
3658
|
+
ReactDebugCurrentFrame.setExtraStackFrame(stack);
|
|
3659
|
+
} else {
|
|
3660
|
+
ReactDebugCurrentFrame.setExtraStackFrame(null);
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
function checkPropTypes(typeSpecs, values, location, componentName, element) {
|
|
3666
|
+
{
|
|
3667
|
+
// $FlowFixMe This is okay but Flow doesn't know it.
|
|
3668
|
+
var has = Function.call.bind(hasOwnProperty);
|
|
3669
|
+
|
|
3670
|
+
for (var typeSpecName in typeSpecs) {
|
|
3671
|
+
if (has(typeSpecs, typeSpecName)) {
|
|
3672
|
+
var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
|
|
3673
|
+
// fail the render phase where it didn't fail before. So we log it.
|
|
3674
|
+
// After these have been cleaned up, we'll let them throw.
|
|
3675
|
+
|
|
3676
|
+
try {
|
|
3677
|
+
// This is intentionally an invariant that gets caught. It's the same
|
|
3678
|
+
// behavior as without this statement except with a better message.
|
|
3679
|
+
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
3680
|
+
// eslint-disable-next-line react-internal/prod-error-codes
|
|
3681
|
+
var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
|
|
3682
|
+
err.name = 'Invariant Violation';
|
|
3683
|
+
throw err;
|
|
3684
|
+
}
|
|
3685
|
+
|
|
3686
|
+
error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
|
|
3687
|
+
} catch (ex) {
|
|
3688
|
+
error$1 = ex;
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
if (error$1 && !(error$1 instanceof Error)) {
|
|
3692
|
+
setCurrentlyValidatingElement(element);
|
|
3693
|
+
|
|
3694
|
+
error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
|
|
3695
|
+
|
|
3696
|
+
setCurrentlyValidatingElement(null);
|
|
3697
|
+
}
|
|
3698
|
+
|
|
3699
|
+
if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
|
|
3700
|
+
// Only monitor this failure once because there tends to be a lot of the
|
|
3701
|
+
// same error.
|
|
3702
|
+
loggedTypeFailures[error$1.message] = true;
|
|
3703
|
+
setCurrentlyValidatingElement(element);
|
|
3704
|
+
|
|
3705
|
+
error('Failed %s type: %s', location, error$1.message);
|
|
3706
|
+
|
|
3707
|
+
setCurrentlyValidatingElement(null);
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
|
3715
|
+
|
|
3716
|
+
function isArray(a) {
|
|
3717
|
+
return isArrayImpl(a);
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
/*
|
|
3721
|
+
* The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
|
|
3722
|
+
* and Temporal.* types. See https://github.com/facebook/react/pull/22064.
|
|
3723
|
+
*
|
|
3724
|
+
* The functions in this module will throw an easier-to-understand,
|
|
3725
|
+
* easier-to-debug exception with a clear errors message message explaining the
|
|
3726
|
+
* problem. (Instead of a confusing exception thrown inside the implementation
|
|
3727
|
+
* of the `value` object).
|
|
3728
|
+
*/
|
|
3729
|
+
// $FlowFixMe only called in DEV, so void return is not possible.
|
|
3730
|
+
function typeName(value) {
|
|
3731
|
+
{
|
|
3732
|
+
// toStringTag is needed for namespaced types like Temporal.Instant
|
|
3733
|
+
var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
|
|
3734
|
+
var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
|
|
3735
|
+
return type;
|
|
3736
|
+
}
|
|
3737
|
+
} // $FlowFixMe only called in DEV, so void return is not possible.
|
|
3738
|
+
|
|
3739
|
+
|
|
3740
|
+
function willCoercionThrow(value) {
|
|
3741
|
+
{
|
|
3742
|
+
try {
|
|
3743
|
+
testStringCoercion(value);
|
|
3744
|
+
return false;
|
|
3745
|
+
} catch (e) {
|
|
3746
|
+
return true;
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
function testStringCoercion(value) {
|
|
3752
|
+
// If you ended up here by following an exception call stack, here's what's
|
|
3753
|
+
// happened: you supplied an object or symbol value to React (as a prop, key,
|
|
3754
|
+
// DOM attribute, CSS property, string ref, etc.) and when React tried to
|
|
3755
|
+
// coerce it to a string using `'' + value`, an exception was thrown.
|
|
3756
|
+
//
|
|
3757
|
+
// The most common types that will cause this exception are `Symbol` instances
|
|
3758
|
+
// and Temporal objects like `Temporal.Instant`. But any object that has a
|
|
3759
|
+
// `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
|
|
3760
|
+
// exception. (Library authors do this to prevent users from using built-in
|
|
3761
|
+
// numeric operators like `+` or comparison operators like `>=` because custom
|
|
3762
|
+
// methods are needed to perform accurate arithmetic or comparison.)
|
|
3763
|
+
//
|
|
3764
|
+
// To fix the problem, coerce this object or symbol value to a string before
|
|
3765
|
+
// passing it to React. The most reliable way is usually `String(value)`.
|
|
3766
|
+
//
|
|
3767
|
+
// To find which value is throwing, check the browser or debugger console.
|
|
3768
|
+
// Before this exception was thrown, there should be `console.error` output
|
|
3769
|
+
// that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
|
|
3770
|
+
// problem and how that type was used: key, atrribute, input value prop, etc.
|
|
3771
|
+
// In most cases, this console output also shows the component and its
|
|
3772
|
+
// ancestor components where the exception happened.
|
|
3773
|
+
//
|
|
3774
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
3775
|
+
return '' + value;
|
|
3776
|
+
}
|
|
3777
|
+
function checkKeyStringCoercion(value) {
|
|
3778
|
+
{
|
|
3779
|
+
if (willCoercionThrow(value)) {
|
|
3780
|
+
error('The provided key is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
|
|
3781
|
+
|
|
3782
|
+
return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
|
|
3787
|
+
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
|
3788
|
+
var RESERVED_PROPS = {
|
|
3789
|
+
key: true,
|
|
3790
|
+
ref: true,
|
|
3791
|
+
__self: true,
|
|
3792
|
+
__source: true
|
|
3793
|
+
};
|
|
3794
|
+
var specialPropKeyWarningShown;
|
|
3795
|
+
var specialPropRefWarningShown;
|
|
3796
|
+
|
|
3797
|
+
function hasValidRef(config) {
|
|
3798
|
+
{
|
|
3799
|
+
if (hasOwnProperty.call(config, 'ref')) {
|
|
3800
|
+
var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
|
|
3801
|
+
|
|
3802
|
+
if (getter && getter.isReactWarning) {
|
|
3803
|
+
return false;
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3808
|
+
return config.ref !== undefined;
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
function hasValidKey(config) {
|
|
3812
|
+
{
|
|
3813
|
+
if (hasOwnProperty.call(config, 'key')) {
|
|
3814
|
+
var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
|
|
3815
|
+
|
|
3816
|
+
if (getter && getter.isReactWarning) {
|
|
3817
|
+
return false;
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3822
|
+
return config.key !== undefined;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
function warnIfStringRefCannotBeAutoConverted(config, self) {
|
|
3826
|
+
{
|
|
3827
|
+
if (typeof config.ref === 'string' && ReactCurrentOwner.current && self) ;
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
|
|
3831
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
3832
|
+
{
|
|
3833
|
+
var warnAboutAccessingKey = function () {
|
|
3834
|
+
if (!specialPropKeyWarningShown) {
|
|
3835
|
+
specialPropKeyWarningShown = true;
|
|
3836
|
+
|
|
3837
|
+
error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
|
|
3838
|
+
}
|
|
3839
|
+
};
|
|
3840
|
+
|
|
3841
|
+
warnAboutAccessingKey.isReactWarning = true;
|
|
3842
|
+
Object.defineProperty(props, 'key', {
|
|
3843
|
+
get: warnAboutAccessingKey,
|
|
3844
|
+
configurable: true
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
function defineRefPropWarningGetter(props, displayName) {
|
|
3850
|
+
{
|
|
3851
|
+
var warnAboutAccessingRef = function () {
|
|
3852
|
+
if (!specialPropRefWarningShown) {
|
|
3853
|
+
specialPropRefWarningShown = true;
|
|
3854
|
+
|
|
3855
|
+
error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
|
|
3856
|
+
}
|
|
3857
|
+
};
|
|
3858
|
+
|
|
3859
|
+
warnAboutAccessingRef.isReactWarning = true;
|
|
3860
|
+
Object.defineProperty(props, 'ref', {
|
|
3861
|
+
get: warnAboutAccessingRef,
|
|
3862
|
+
configurable: true
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
/**
|
|
3867
|
+
* Factory method to create a new React element. This no longer adheres to
|
|
3868
|
+
* the class pattern, so do not use new to call it. Also, instanceof check
|
|
3869
|
+
* will not work. Instead test $$typeof field against Symbol.for('react.element') to check
|
|
3870
|
+
* if something is a React Element.
|
|
3871
|
+
*
|
|
3872
|
+
* @param {*} type
|
|
3873
|
+
* @param {*} props
|
|
3874
|
+
* @param {*} key
|
|
3875
|
+
* @param {string|object} ref
|
|
3876
|
+
* @param {*} owner
|
|
3877
|
+
* @param {*} self A *temporary* helper to detect places where `this` is
|
|
3878
|
+
* different from the `owner` when React.createElement is called, so that we
|
|
3879
|
+
* can warn. We want to get rid of owner and replace string `ref`s with arrow
|
|
3880
|
+
* functions, and as long as `this` and owner are the same, there will be no
|
|
3881
|
+
* change in behavior.
|
|
3882
|
+
* @param {*} source An annotation object (added by a transpiler or otherwise)
|
|
3883
|
+
* indicating filename, line number, and/or other information.
|
|
3884
|
+
* @internal
|
|
3885
|
+
*/
|
|
3886
|
+
|
|
3887
|
+
|
|
3888
|
+
var ReactElement = function (type, key, ref, self, source, owner, props) {
|
|
3889
|
+
var element = {
|
|
3890
|
+
// This tag allows us to uniquely identify this as a React Element
|
|
3891
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
3892
|
+
// Built-in properties that belong on the element
|
|
3893
|
+
type: type,
|
|
3894
|
+
key: key,
|
|
3895
|
+
ref: ref,
|
|
3896
|
+
props: props,
|
|
3897
|
+
// Record the component responsible for creating this element.
|
|
3898
|
+
_owner: owner
|
|
3899
|
+
};
|
|
3900
|
+
|
|
3901
|
+
{
|
|
3902
|
+
// The validation flag is currently mutative. We put it on
|
|
3903
|
+
// an external backing store so that we can freeze the whole object.
|
|
3904
|
+
// This can be replaced with a WeakMap once they are implemented in
|
|
3905
|
+
// commonly used development environments.
|
|
3906
|
+
element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
|
|
3907
|
+
// the validation flag non-enumerable (where possible, which should
|
|
3908
|
+
// include every environment we run tests in), so the test framework
|
|
3909
|
+
// ignores it.
|
|
3910
|
+
|
|
3911
|
+
Object.defineProperty(element._store, 'validated', {
|
|
3912
|
+
configurable: false,
|
|
3913
|
+
enumerable: false,
|
|
3914
|
+
writable: true,
|
|
3915
|
+
value: false
|
|
3916
|
+
}); // self and source are DEV only properties.
|
|
3917
|
+
|
|
3918
|
+
Object.defineProperty(element, '_self', {
|
|
3919
|
+
configurable: false,
|
|
3920
|
+
enumerable: false,
|
|
3921
|
+
writable: false,
|
|
3922
|
+
value: self
|
|
3923
|
+
}); // Two elements created in two different places should be considered
|
|
3924
|
+
// equal for testing purposes and therefore we hide it from enumeration.
|
|
3925
|
+
|
|
3926
|
+
Object.defineProperty(element, '_source', {
|
|
3927
|
+
configurable: false,
|
|
3928
|
+
enumerable: false,
|
|
3929
|
+
writable: false,
|
|
3930
|
+
value: source
|
|
3931
|
+
});
|
|
3932
|
+
|
|
3933
|
+
if (Object.freeze) {
|
|
3934
|
+
Object.freeze(element.props);
|
|
3935
|
+
Object.freeze(element);
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
|
|
3939
|
+
return element;
|
|
3940
|
+
};
|
|
3941
|
+
/**
|
|
3942
|
+
* https://github.com/reactjs/rfcs/pull/107
|
|
3943
|
+
* @param {*} type
|
|
3944
|
+
* @param {object} props
|
|
3945
|
+
* @param {string} key
|
|
3946
|
+
*/
|
|
3947
|
+
|
|
3948
|
+
function jsxDEV(type, config, maybeKey, source, self) {
|
|
3949
|
+
{
|
|
3950
|
+
var propName; // Reserved names are extracted
|
|
3951
|
+
|
|
3952
|
+
var props = {};
|
|
3953
|
+
var key = null;
|
|
3954
|
+
var ref = null; // Currently, key can be spread in as a prop. This causes a potential
|
|
3955
|
+
// issue if key is also explicitly declared (ie. <div {...props} key="Hi" />
|
|
3956
|
+
// or <div key="Hi" {...props} /> ). We want to deprecate key spread,
|
|
3957
|
+
// but as an intermediary step, we will use jsxDEV for everything except
|
|
3958
|
+
// <div {...props} key="Hi" />, because we aren't currently able to tell if
|
|
3959
|
+
// key is explicitly declared to be undefined or not.
|
|
3960
|
+
|
|
3961
|
+
if (maybeKey !== undefined) {
|
|
3962
|
+
{
|
|
3963
|
+
checkKeyStringCoercion(maybeKey);
|
|
3964
|
+
}
|
|
3965
|
+
|
|
3966
|
+
key = '' + maybeKey;
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
if (hasValidKey(config)) {
|
|
3970
|
+
{
|
|
3971
|
+
checkKeyStringCoercion(config.key);
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
key = '' + config.key;
|
|
3975
|
+
}
|
|
3976
|
+
|
|
3977
|
+
if (hasValidRef(config)) {
|
|
3978
|
+
ref = config.ref;
|
|
3979
|
+
warnIfStringRefCannotBeAutoConverted(config, self);
|
|
3980
|
+
} // Remaining properties are added to a new props object
|
|
3981
|
+
|
|
3982
|
+
|
|
3983
|
+
for (propName in config) {
|
|
3984
|
+
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
3985
|
+
props[propName] = config[propName];
|
|
3986
|
+
}
|
|
3987
|
+
} // Resolve default props
|
|
3988
|
+
|
|
3989
|
+
|
|
3990
|
+
if (type && type.defaultProps) {
|
|
3991
|
+
var defaultProps = type.defaultProps;
|
|
3992
|
+
|
|
3993
|
+
for (propName in defaultProps) {
|
|
3994
|
+
if (props[propName] === undefined) {
|
|
3995
|
+
props[propName] = defaultProps[propName];
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
if (key || ref) {
|
|
4001
|
+
var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
|
|
4002
|
+
|
|
4003
|
+
if (key) {
|
|
4004
|
+
defineKeyPropWarningGetter(props, displayName);
|
|
4005
|
+
}
|
|
4006
|
+
|
|
4007
|
+
if (ref) {
|
|
4008
|
+
defineRefPropWarningGetter(props, displayName);
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
|
|
4012
|
+
return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
|
|
4016
|
+
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
|
|
4017
|
+
var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
4018
|
+
|
|
4019
|
+
function setCurrentlyValidatingElement$1(element) {
|
|
4020
|
+
{
|
|
4021
|
+
if (element) {
|
|
4022
|
+
var owner = element._owner;
|
|
4023
|
+
var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
|
4024
|
+
ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
|
|
4025
|
+
} else {
|
|
4026
|
+
ReactDebugCurrentFrame$1.setExtraStackFrame(null);
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
|
|
4031
|
+
var propTypesMisspellWarningShown;
|
|
4032
|
+
|
|
4033
|
+
{
|
|
4034
|
+
propTypesMisspellWarningShown = false;
|
|
4035
|
+
}
|
|
4036
|
+
/**
|
|
4037
|
+
* Verifies the object is a ReactElement.
|
|
4038
|
+
* See https://reactjs.org/docs/react-api.html#isvalidelement
|
|
4039
|
+
* @param {?object} object
|
|
4040
|
+
* @return {boolean} True if `object` is a ReactElement.
|
|
4041
|
+
* @final
|
|
4042
|
+
*/
|
|
4043
|
+
|
|
4044
|
+
|
|
4045
|
+
function isValidElement(object) {
|
|
4046
|
+
{
|
|
4047
|
+
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
function getDeclarationErrorAddendum() {
|
|
4052
|
+
{
|
|
4053
|
+
if (ReactCurrentOwner$1.current) {
|
|
4054
|
+
var name = getComponentNameFromType(ReactCurrentOwner$1.current.type);
|
|
4055
|
+
|
|
4056
|
+
if (name) {
|
|
4057
|
+
return '\n\nCheck the render method of `' + name + '`.';
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
return '';
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
function getSourceInfoErrorAddendum(source) {
|
|
4066
|
+
{
|
|
4067
|
+
|
|
4068
|
+
return '';
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
/**
|
|
4072
|
+
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
4073
|
+
* object keys are not valid. This allows us to keep track of children between
|
|
4074
|
+
* updates.
|
|
4075
|
+
*/
|
|
4076
|
+
|
|
4077
|
+
|
|
4078
|
+
var ownerHasKeyUseWarning = {};
|
|
4079
|
+
|
|
4080
|
+
function getCurrentComponentErrorInfo(parentType) {
|
|
4081
|
+
{
|
|
4082
|
+
var info = getDeclarationErrorAddendum();
|
|
4083
|
+
|
|
4084
|
+
if (!info) {
|
|
4085
|
+
var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
|
4086
|
+
|
|
4087
|
+
if (parentName) {
|
|
4088
|
+
info = "\n\nCheck the top-level render call using <" + parentName + ">.";
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
return info;
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
/**
|
|
4096
|
+
* Warn if the element doesn't have an explicit key assigned to it.
|
|
4097
|
+
* This element is in an array. The array could grow and shrink or be
|
|
4098
|
+
* reordered. All children that haven't already been validated are required to
|
|
4099
|
+
* have a "key" property assigned to it. Error statuses are cached so a warning
|
|
4100
|
+
* will only be shown once.
|
|
4101
|
+
*
|
|
4102
|
+
* @internal
|
|
4103
|
+
* @param {ReactElement} element Element that requires a key.
|
|
4104
|
+
* @param {*} parentType element's parent's type.
|
|
4105
|
+
*/
|
|
4106
|
+
|
|
4107
|
+
|
|
4108
|
+
function validateExplicitKey(element, parentType) {
|
|
4109
|
+
{
|
|
4110
|
+
if (!element._store || element._store.validated || element.key != null) {
|
|
4111
|
+
return;
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
element._store.validated = true;
|
|
4115
|
+
var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
|
|
4116
|
+
|
|
4117
|
+
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
|
|
4118
|
+
return;
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4121
|
+
ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
|
|
4122
|
+
// property, it may be the creator of the child that's responsible for
|
|
4123
|
+
// assigning it a key.
|
|
4124
|
+
|
|
4125
|
+
var childOwner = '';
|
|
4126
|
+
|
|
4127
|
+
if (element && element._owner && element._owner !== ReactCurrentOwner$1.current) {
|
|
4128
|
+
// Give the component that originally created this child.
|
|
4129
|
+
childOwner = " It was passed a child from " + getComponentNameFromType(element._owner.type) + ".";
|
|
4130
|
+
}
|
|
4131
|
+
|
|
4132
|
+
setCurrentlyValidatingElement$1(element);
|
|
4133
|
+
|
|
4134
|
+
error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
|
|
4135
|
+
|
|
4136
|
+
setCurrentlyValidatingElement$1(null);
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
/**
|
|
4140
|
+
* Ensure that every element either is passed in a static location, in an
|
|
4141
|
+
* array with an explicit keys property defined, or in an object literal
|
|
4142
|
+
* with valid key property.
|
|
4143
|
+
*
|
|
4144
|
+
* @internal
|
|
4145
|
+
* @param {ReactNode} node Statically passed child of any type.
|
|
4146
|
+
* @param {*} parentType node's parent's type.
|
|
4147
|
+
*/
|
|
4148
|
+
|
|
4149
|
+
|
|
4150
|
+
function validateChildKeys(node, parentType) {
|
|
4151
|
+
{
|
|
4152
|
+
if (typeof node !== 'object') {
|
|
4153
|
+
return;
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
if (isArray(node)) {
|
|
4157
|
+
for (var i = 0; i < node.length; i++) {
|
|
4158
|
+
var child = node[i];
|
|
4159
|
+
|
|
4160
|
+
if (isValidElement(child)) {
|
|
4161
|
+
validateExplicitKey(child, parentType);
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4164
|
+
} else if (isValidElement(node)) {
|
|
4165
|
+
// This element was passed in a valid location.
|
|
4166
|
+
if (node._store) {
|
|
4167
|
+
node._store.validated = true;
|
|
4168
|
+
}
|
|
4169
|
+
} else if (node) {
|
|
4170
|
+
var iteratorFn = getIteratorFn(node);
|
|
4171
|
+
|
|
4172
|
+
if (typeof iteratorFn === 'function') {
|
|
4173
|
+
// Entry iterators used to provide implicit keys,
|
|
4174
|
+
// but now we print a separate warning for them later.
|
|
4175
|
+
if (iteratorFn !== node.entries) {
|
|
4176
|
+
var iterator = iteratorFn.call(node);
|
|
4177
|
+
var step;
|
|
4178
|
+
|
|
4179
|
+
while (!(step = iterator.next()).done) {
|
|
4180
|
+
if (isValidElement(step.value)) {
|
|
4181
|
+
validateExplicitKey(step.value, parentType);
|
|
4182
|
+
}
|
|
4183
|
+
}
|
|
4184
|
+
}
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
}
|
|
4189
|
+
/**
|
|
4190
|
+
* Given an element, validate that its props follow the propTypes definition,
|
|
4191
|
+
* provided by the type.
|
|
4192
|
+
*
|
|
4193
|
+
* @param {ReactElement} element
|
|
4194
|
+
*/
|
|
4195
|
+
|
|
4196
|
+
|
|
4197
|
+
function validatePropTypes(element) {
|
|
4198
|
+
{
|
|
4199
|
+
var type = element.type;
|
|
4200
|
+
|
|
4201
|
+
if (type === null || type === undefined || typeof type === 'string') {
|
|
4202
|
+
return;
|
|
4203
|
+
}
|
|
4204
|
+
|
|
4205
|
+
var propTypes;
|
|
4206
|
+
|
|
4207
|
+
if (typeof type === 'function') {
|
|
4208
|
+
propTypes = type.propTypes;
|
|
4209
|
+
} else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
|
|
4210
|
+
// Inner props are checked in the reconciler.
|
|
4211
|
+
type.$$typeof === REACT_MEMO_TYPE)) {
|
|
4212
|
+
propTypes = type.propTypes;
|
|
4213
|
+
} else {
|
|
4214
|
+
return;
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
if (propTypes) {
|
|
4218
|
+
// Intentionally inside to avoid triggering lazy initializers:
|
|
4219
|
+
var name = getComponentNameFromType(type);
|
|
4220
|
+
checkPropTypes(propTypes, element.props, 'prop', name, element);
|
|
4221
|
+
} else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
|
|
4222
|
+
propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
|
|
4223
|
+
|
|
4224
|
+
var _name = getComponentNameFromType(type);
|
|
4225
|
+
|
|
4226
|
+
error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
|
|
4230
|
+
error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
/**
|
|
4235
|
+
* Given a fragment, validate that it can only be provided with fragment props
|
|
4236
|
+
* @param {ReactElement} fragment
|
|
4237
|
+
*/
|
|
4238
|
+
|
|
4239
|
+
|
|
4240
|
+
function validateFragmentProps(fragment) {
|
|
4241
|
+
{
|
|
4242
|
+
var keys = Object.keys(fragment.props);
|
|
4243
|
+
|
|
4244
|
+
for (var i = 0; i < keys.length; i++) {
|
|
4245
|
+
var key = keys[i];
|
|
4246
|
+
|
|
4247
|
+
if (key !== 'children' && key !== 'key') {
|
|
4248
|
+
setCurrentlyValidatingElement$1(fragment);
|
|
4249
|
+
|
|
4250
|
+
error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
|
|
4251
|
+
|
|
4252
|
+
setCurrentlyValidatingElement$1(null);
|
|
4253
|
+
break;
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
|
|
4257
|
+
if (fragment.ref !== null) {
|
|
4258
|
+
setCurrentlyValidatingElement$1(fragment);
|
|
4259
|
+
|
|
4260
|
+
error('Invalid attribute `ref` supplied to `React.Fragment`.');
|
|
4261
|
+
|
|
4262
|
+
setCurrentlyValidatingElement$1(null);
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
|
|
4267
|
+
var didWarnAboutKeySpread = {};
|
|
4268
|
+
function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
|
|
4269
|
+
{
|
|
4270
|
+
var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
|
|
4271
|
+
// succeed and there will likely be errors in render.
|
|
4272
|
+
|
|
4273
|
+
if (!validType) {
|
|
4274
|
+
var info = '';
|
|
4275
|
+
|
|
4276
|
+
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
|
|
4277
|
+
info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
var sourceInfo = getSourceInfoErrorAddendum();
|
|
4281
|
+
|
|
4282
|
+
if (sourceInfo) {
|
|
4283
|
+
info += sourceInfo;
|
|
4284
|
+
} else {
|
|
4285
|
+
info += getDeclarationErrorAddendum();
|
|
4286
|
+
}
|
|
4287
|
+
|
|
4288
|
+
var typeString;
|
|
4289
|
+
|
|
4290
|
+
if (type === null) {
|
|
4291
|
+
typeString = 'null';
|
|
4292
|
+
} else if (isArray(type)) {
|
|
4293
|
+
typeString = 'array';
|
|
4294
|
+
} else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
|
|
4295
|
+
typeString = "<" + (getComponentNameFromType(type.type) || 'Unknown') + " />";
|
|
4296
|
+
info = ' Did you accidentally export a JSX literal instead of a component?';
|
|
4297
|
+
} else {
|
|
4298
|
+
typeString = typeof type;
|
|
4299
|
+
}
|
|
4300
|
+
|
|
4301
|
+
error('React.jsx: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
|
|
4302
|
+
}
|
|
4303
|
+
|
|
4304
|
+
var element = jsxDEV(type, props, key, source, self); // The result can be nullish if a mock or a custom function is used.
|
|
4305
|
+
// TODO: Drop this when these are no longer allowed as the type argument.
|
|
4306
|
+
|
|
4307
|
+
if (element == null) {
|
|
4308
|
+
return element;
|
|
4309
|
+
} // Skip key warning if the type isn't valid since our key validation logic
|
|
4310
|
+
// doesn't expect a non-string/function type and can throw confusing errors.
|
|
4311
|
+
// We don't want exception behavior to differ between dev and prod.
|
|
4312
|
+
// (Rendering will throw with a helpful message and as soon as the type is
|
|
4313
|
+
// fixed, the key warnings will appear.)
|
|
4314
|
+
|
|
4315
|
+
|
|
4316
|
+
if (validType) {
|
|
4317
|
+
var children = props.children;
|
|
4318
|
+
|
|
4319
|
+
if (children !== undefined) {
|
|
4320
|
+
if (isStaticChildren) {
|
|
4321
|
+
if (isArray(children)) {
|
|
4322
|
+
for (var i = 0; i < children.length; i++) {
|
|
4323
|
+
validateChildKeys(children[i], type);
|
|
4324
|
+
}
|
|
4325
|
+
|
|
4326
|
+
if (Object.freeze) {
|
|
4327
|
+
Object.freeze(children);
|
|
4328
|
+
}
|
|
4329
|
+
} else {
|
|
4330
|
+
error('React.jsx: Static children should always be an array. ' + 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + 'Use the Babel transform instead.');
|
|
4331
|
+
}
|
|
4332
|
+
} else {
|
|
4333
|
+
validateChildKeys(children, type);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
}
|
|
4337
|
+
|
|
4338
|
+
{
|
|
4339
|
+
if (hasOwnProperty.call(props, 'key')) {
|
|
4340
|
+
var componentName = getComponentNameFromType(type);
|
|
4341
|
+
var keys = Object.keys(props).filter(function (k) {
|
|
4342
|
+
return k !== 'key';
|
|
4343
|
+
});
|
|
4344
|
+
var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
|
|
4345
|
+
|
|
4346
|
+
if (!didWarnAboutKeySpread[componentName + beforeExample]) {
|
|
4347
|
+
var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
|
|
4348
|
+
|
|
4349
|
+
error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
|
|
4350
|
+
|
|
4351
|
+
didWarnAboutKeySpread[componentName + beforeExample] = true;
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
}
|
|
4355
|
+
|
|
4356
|
+
if (type === REACT_FRAGMENT_TYPE) {
|
|
4357
|
+
validateFragmentProps(element);
|
|
4358
|
+
} else {
|
|
4359
|
+
validatePropTypes(element);
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
return element;
|
|
4363
|
+
}
|
|
4364
|
+
} // These two functions exist to still get child warnings in dev
|
|
4365
|
+
// even with the prod transform. This means that jsxDEV is purely
|
|
4366
|
+
// opt-in behavior for better messages but that we won't stop
|
|
4367
|
+
// giving you warnings if you use production apis.
|
|
4368
|
+
|
|
4369
|
+
function jsxWithValidationStatic(type, props, key) {
|
|
4370
|
+
{
|
|
4371
|
+
return jsxWithValidation(type, props, key, true);
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
function jsxWithValidationDynamic(type, props, key) {
|
|
4375
|
+
{
|
|
4376
|
+
return jsxWithValidation(type, props, key, false);
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
|
|
4380
|
+
var jsx = jsxWithValidationDynamic ; // we may want to special case jsxs internally to take advantage of static children.
|
|
4381
|
+
// for now we can ship identical prod functions
|
|
4382
|
+
|
|
4383
|
+
var jsxs = jsxWithValidationStatic ;
|
|
4384
|
+
|
|
4385
|
+
reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
|
|
4386
|
+
reactJsxRuntime_development.jsx = jsx;
|
|
4387
|
+
reactJsxRuntime_development.jsxs = jsxs;
|
|
4388
|
+
})();
|
|
4389
|
+
}
|
|
4390
|
+
return reactJsxRuntime_development;
|
|
4391
|
+
}
|
|
4392
|
+
|
|
4393
|
+
if (process.env.NODE_ENV === 'production') {
|
|
4394
|
+
jsxRuntime.exports = requireReactJsxRuntime_production_min();
|
|
4395
|
+
} else {
|
|
4396
|
+
jsxRuntime.exports = requireReactJsxRuntime_development();
|
|
4397
|
+
}
|
|
4398
|
+
|
|
4399
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
4400
|
+
|
|
4401
|
+
const SmoothSendAvaxContext = createContext(null);
|
|
4402
|
+
function SmoothSendAvaxProvider({ apiKey, network = 'testnet', smartAccountAddress, accountFactory, accountSalt, children, }) {
|
|
4403
|
+
const value = useMemo(() => ({
|
|
4404
|
+
apiKey,
|
|
4405
|
+
network,
|
|
4406
|
+
smartAccountAddress,
|
|
4407
|
+
accountFactory,
|
|
4408
|
+
accountSalt: accountSalt ?? 0n,
|
|
4409
|
+
}), [apiKey, network, smartAccountAddress, accountFactory, accountSalt]);
|
|
4410
|
+
return (jsxRuntimeExports.jsx(SmoothSendAvaxContext.Provider, { value: value, children: children }));
|
|
4411
|
+
}
|
|
4412
|
+
function useSmoothSendAvaxContext() {
|
|
4413
|
+
return useContext(SmoothSendAvaxContext);
|
|
4414
|
+
}
|
|
4415
|
+
function useSmoothSendAvax(params) {
|
|
4416
|
+
const ctx = useSmoothSendAvaxContext();
|
|
4417
|
+
const apiKey = params.apiKey ?? ctx?.apiKey;
|
|
4418
|
+
const network = params.network ?? ctx?.network ?? 'testnet';
|
|
4419
|
+
const smartAccountAddressProp = params.smartAccountAddress ?? ctx?.smartAccountAddress;
|
|
4420
|
+
const accountFactory = params.accountFactory ?? ctx?.accountFactory;
|
|
4421
|
+
const accountSalt = params.accountSalt ?? ctx?.accountSalt ?? 0n;
|
|
4422
|
+
if (!apiKey) {
|
|
4423
|
+
throw new Error('[SmoothSend AVAX] apiKey required — pass useSmoothSendAvax({ apiKey }) or wrap SmoothSendAvaxProvider');
|
|
4424
|
+
}
|
|
4425
|
+
if (!smartAccountAddressProp && !accountFactory) {
|
|
4426
|
+
throw new Error('[SmoothSend AVAX] Provide smartAccountAddress and/or accountFactory (SimpleAccountFactory)');
|
|
4427
|
+
}
|
|
4428
|
+
const submitter = useMemo(() => new SmoothSendAvaxSubmitter({ apiKey, network }), [apiKey, network]);
|
|
4429
|
+
const { publicClient, walletClient } = params;
|
|
4430
|
+
const submitCall = useCallback(async (call) => {
|
|
4431
|
+
if (!publicClient) {
|
|
4432
|
+
throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
|
|
4433
|
+
}
|
|
4434
|
+
if (!walletClient) {
|
|
4435
|
+
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
4436
|
+
}
|
|
4437
|
+
const account = walletClient.account;
|
|
4438
|
+
if (!account) {
|
|
4439
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing — connect wallet (wagmi useWalletClient)');
|
|
4440
|
+
}
|
|
4441
|
+
const ownerAddress = account.address;
|
|
4442
|
+
const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
|
|
4443
|
+
const entryPoint = (await submitter.getSupportedEntryPoints())[0];
|
|
4444
|
+
let sender;
|
|
4445
|
+
if (accountFactory) {
|
|
4446
|
+
const predicted = await predictSimpleAccountAddress({
|
|
4447
|
+
publicClient,
|
|
4448
|
+
factory: accountFactory,
|
|
4449
|
+
owner: ownerAddress,
|
|
4450
|
+
salt: accountSalt,
|
|
4451
|
+
});
|
|
4452
|
+
if (smartAccountAddressProp &&
|
|
4453
|
+
predicted.toLowerCase() !== smartAccountAddressProp.toLowerCase()) {
|
|
4454
|
+
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddressProp} does not match factory prediction ${predicted}`);
|
|
4455
|
+
}
|
|
4456
|
+
sender = predicted;
|
|
4457
|
+
}
|
|
4458
|
+
else {
|
|
4459
|
+
sender = smartAccountAddressProp;
|
|
4460
|
+
}
|
|
4461
|
+
const code = await publicClient.getBytecode({ address: sender });
|
|
4462
|
+
const deployed = typeof code === 'string' &&
|
|
4463
|
+
code !== '0x' &&
|
|
4464
|
+
code.length > 2;
|
|
4465
|
+
let nonce;
|
|
4466
|
+
let factory;
|
|
4467
|
+
let factoryData;
|
|
4468
|
+
if (!deployed) {
|
|
4469
|
+
if (!accountFactory) {
|
|
4470
|
+
throw new Error('[SmoothSend AVAX] No bytecode at sender — pass accountFactory so the paymaster can sponsor deploy + call in one UserOp');
|
|
4471
|
+
}
|
|
4472
|
+
nonce = 0n;
|
|
4473
|
+
factory = accountFactory;
|
|
4474
|
+
factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
|
|
4475
|
+
}
|
|
4476
|
+
else {
|
|
4477
|
+
nonce = await readAvaxSenderNonce({
|
|
4478
|
+
publicClient,
|
|
4479
|
+
entryPointAddress: entryPoint,
|
|
4480
|
+
sender,
|
|
4481
|
+
});
|
|
4482
|
+
}
|
|
4483
|
+
let maxFeePerGas = 50n * 10n ** 9n;
|
|
4484
|
+
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
4485
|
+
try {
|
|
4486
|
+
const est = await publicClient.estimateFeesPerGas();
|
|
4487
|
+
if (est.maxFeePerGas)
|
|
4488
|
+
maxFeePerGas = est.maxFeePerGas;
|
|
4489
|
+
if (est.maxPriorityFeePerGas) {
|
|
4490
|
+
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
catch {
|
|
4494
|
+
/* chain may not support EIP-1559 estimation */
|
|
4495
|
+
}
|
|
4496
|
+
const callData = encodeAvaxExecuteCalldata(call.to, call.value ?? 0n, call.data ?? '0x');
|
|
4497
|
+
return submitter.submitSponsoredUserOperation({
|
|
4498
|
+
userOp: {
|
|
4499
|
+
sender,
|
|
4500
|
+
nonce: toHex(nonce),
|
|
4501
|
+
callData,
|
|
4502
|
+
maxFeePerGas: toHex(maxFeePerGas),
|
|
4503
|
+
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
|
|
4504
|
+
...(factory && factoryData ? { factory, factoryData } : {}),
|
|
4505
|
+
},
|
|
4506
|
+
mode: call.mode ?? 'developer-sponsored',
|
|
4507
|
+
paymaster: call.paymaster,
|
|
4508
|
+
waitForReceipt: call.waitForReceipt,
|
|
4509
|
+
signUserOp: async (op) => {
|
|
4510
|
+
const hash = hashUserOperationAvax({
|
|
4511
|
+
chainId,
|
|
4512
|
+
entryPointAddress: entryPoint,
|
|
4513
|
+
userOperation: op,
|
|
4514
|
+
});
|
|
4515
|
+
return walletClient.signMessage({
|
|
4516
|
+
account,
|
|
4517
|
+
message: { raw: hash },
|
|
4518
|
+
});
|
|
4519
|
+
},
|
|
4520
|
+
});
|
|
4521
|
+
}, [
|
|
4522
|
+
accountFactory,
|
|
4523
|
+
accountSalt,
|
|
4524
|
+
publicClient,
|
|
4525
|
+
smartAccountAddressProp,
|
|
4526
|
+
submitter,
|
|
4527
|
+
walletClient,
|
|
4528
|
+
]);
|
|
4529
|
+
return { submitter, submitCall };
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
// ─── helpers ────────────────────────────────────────────────────────────────
|
|
4533
|
+
function parseDurationToSeconds(duration) {
|
|
4534
|
+
if (duration === 'never') {
|
|
4535
|
+
// Client-side "never expires" mode; on-chain handle already uses u64::MAX.
|
|
4536
|
+
return Math.floor(Number.MAX_SAFE_INTEGER / 1000);
|
|
4537
|
+
}
|
|
4538
|
+
const n = parseInt(duration, 10);
|
|
4539
|
+
if (isNaN(n))
|
|
4540
|
+
throw new Error(`Invalid duration "${duration}". Use e.g. "2h", "24h", "7d", or "never".`);
|
|
4541
|
+
if (duration.endsWith('s'))
|
|
4542
|
+
return n;
|
|
4543
|
+
if (duration.endsWith('m'))
|
|
4544
|
+
return n * 60;
|
|
4545
|
+
if (duration.endsWith('h'))
|
|
4546
|
+
return n * 3600;
|
|
4547
|
+
if (duration.endsWith('d'))
|
|
4548
|
+
return n * 86400;
|
|
4549
|
+
throw new Error(`Unknown duration unit in "${duration}". Supported: s, m, h, d, or "never".`);
|
|
4550
|
+
}
|
|
4551
|
+
// ─── SmoothSendSession ───────────────────────────────────────────────────────
|
|
4552
|
+
/**
|
|
4553
|
+
* A session that lets your app submit transactions on behalf of a user
|
|
4554
|
+
* without any wallet popup after the initial one-time setup.
|
|
4555
|
+
*
|
|
4556
|
+
* Uses Aptos AIP-103 Permissioned Signers — authorization is enforced
|
|
4557
|
+
* on-chain by `0x1::permissioned_delegation`. No custom Move contract needed.
|
|
4558
|
+
*
|
|
4559
|
+
* @example
|
|
4560
|
+
* // 1. One-time setup (user signs once — can be keyless/Google login)
|
|
4561
|
+
* const session = await SmoothSendSession.create({
|
|
4562
|
+
* signer: keylessAccount,
|
|
4563
|
+
* expiresIn: '24h',
|
|
4564
|
+
* }, submitter)
|
|
4565
|
+
*
|
|
4566
|
+
* // 2. Every action after — zero popups, zero gas
|
|
4567
|
+
* await session.submit('0xgame::player::move', ['north'])
|
|
4568
|
+
* await session.submit('0xgame::player::attack', [enemyId])
|
|
4569
|
+
*/
|
|
4570
|
+
class SmoothSendSession {
|
|
4571
|
+
constructor(args) {
|
|
4572
|
+
this.sessionAccount = args.sessionAccount;
|
|
4573
|
+
this.abstractedAccount = args.abstractedAccount;
|
|
4574
|
+
this.masterAddress = args.masterAddress;
|
|
4575
|
+
this.expiresAtMs = args.expiresAtMs;
|
|
4576
|
+
this.submitter = args.submitter;
|
|
4577
|
+
this.aptosClient = args.aptosClient;
|
|
4578
|
+
this._network = args.network;
|
|
4579
|
+
}
|
|
4580
|
+
/**
|
|
4581
|
+
* Create a new session.
|
|
4582
|
+
*
|
|
4583
|
+
* Registers the session key on-chain via
|
|
4584
|
+
* `0x1::permissioned_delegation::add_permissioned_handle`.
|
|
4585
|
+
* SmoothSend pays the gas for this setup transaction too.
|
|
4586
|
+
*
|
|
4587
|
+
* After this returns, the user never needs to approve anything again
|
|
4588
|
+
* until the session expires or is revoked.
|
|
4589
|
+
*/
|
|
4590
|
+
static async create(options, submitter) {
|
|
4591
|
+
// Resolve network from options or submitter config
|
|
4592
|
+
const network = options.network ?? submitter.getConfig().network ?? 'testnet';
|
|
4593
|
+
const aptosNetwork = network === 'mainnet' ? Network.MAINNET : Network.TESTNET;
|
|
4594
|
+
const aptosClient = new Aptos(new AptosConfig({ network: aptosNetwork }));
|
|
4595
|
+
const feature = await aptosClient.view({
|
|
4596
|
+
payload: {
|
|
4597
|
+
function: '0x1::features::is_permissioned_signer_enabled',
|
|
4598
|
+
functionArguments: [],
|
|
4599
|
+
},
|
|
4600
|
+
}).catch(() => [false]);
|
|
4601
|
+
if (!Array.isArray(feature) || feature[0] !== true) {
|
|
4602
|
+
throw new Error('[SmoothSend] Session keys unavailable on this network (permissioned signer feature disabled).');
|
|
4603
|
+
}
|
|
4604
|
+
// Generate a fresh Ed25519 session keypair (lives in memory, never persisted)
|
|
4605
|
+
const sessionAccount = Account.generate();
|
|
4606
|
+
// Client-side expiry tracking (the bytecode script doesn't take an expiry arg)
|
|
4607
|
+
const nowSecs = Math.floor(Date.now() / 1000);
|
|
4608
|
+
const expirationTimeSecs = nowSecs + parseDurationToSeconds(options.expiresIn);
|
|
4609
|
+
// Step 1: Register the session key on-chain via a pre-compiled Move script.
|
|
4610
|
+
// add_permissioned_handle is NOT an entry function — only callable from a Move script.
|
|
4611
|
+
// Must happen BEFORE enabling account abstraction.
|
|
4612
|
+
const setupTx = await aptosClient.transaction.build.simple({
|
|
4613
|
+
sender: options.signer.accountAddress,
|
|
4614
|
+
withFeePayer: true,
|
|
4615
|
+
data: {
|
|
4616
|
+
bytecode: ADD_PERMISSIONED_HANDLE_BYTECODE,
|
|
4617
|
+
functionArguments: [MoveVector.U8(sessionAccount.publicKey.toUint8Array())],
|
|
4618
|
+
},
|
|
4619
|
+
options: {
|
|
4620
|
+
replayProtectionNonce: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
|
|
4621
|
+
},
|
|
4622
|
+
});
|
|
4623
|
+
const senderAuth = aptosClient.transaction.sign({
|
|
4624
|
+
signer: options.signer,
|
|
4625
|
+
transaction: setupTx,
|
|
4626
|
+
});
|
|
4627
|
+
const setupResult = await submitter.submitTransaction({
|
|
4628
|
+
aptosConfig: aptosClient.config,
|
|
4629
|
+
transaction: setupTx,
|
|
4630
|
+
senderAuthenticator: senderAuth,
|
|
4631
|
+
});
|
|
4632
|
+
await aptosClient.waitForTransaction({ transactionHash: setupResult.hash });
|
|
4633
|
+
// Step 2: Enable account abstraction — tells the chain to use
|
|
4634
|
+
// 0x1::permissioned_delegation::authenticate for this account.
|
|
4635
|
+
// Idempotent — skip if already enabled.
|
|
4636
|
+
const aaEnabled = await aptosClient.abstraction.isAccountAbstractionEnabled({
|
|
4637
|
+
accountAddress: options.signer.accountAddress,
|
|
4638
|
+
authenticationFunction: '0x1::permissioned_delegation::authenticate',
|
|
4639
|
+
});
|
|
4640
|
+
if (!aaEnabled) {
|
|
4641
|
+
const aaTx = await aptosClient.transaction.build.simple({
|
|
4642
|
+
sender: options.signer.accountAddress,
|
|
4643
|
+
withFeePayer: true,
|
|
4644
|
+
data: {
|
|
4645
|
+
function: '0x1::account_abstraction::add_authentication_function',
|
|
4646
|
+
functionArguments: [
|
|
4647
|
+
AccountAddress.fromString('0x1'),
|
|
4648
|
+
'permissioned_delegation',
|
|
4649
|
+
'authenticate',
|
|
4650
|
+
],
|
|
4651
|
+
},
|
|
4652
|
+
});
|
|
4653
|
+
const aaAuth = aptosClient.transaction.sign({ signer: options.signer, transaction: aaTx });
|
|
4654
|
+
const aaResult = await submitter.submitTransaction({
|
|
4655
|
+
aptosConfig: aptosClient.config,
|
|
4656
|
+
transaction: aaTx,
|
|
2546
4657
|
senderAuthenticator: aaAuth,
|
|
2547
4658
|
});
|
|
2548
4659
|
await aptosClient.waitForTransaction({ transactionHash: aaResult.hash });
|
|
@@ -2886,6 +4997,134 @@ function createScriptComposerClient(config) {
|
|
|
2886
4997
|
return new ScriptComposerClient(config);
|
|
2887
4998
|
}
|
|
2888
4999
|
|
|
5000
|
+
/**
|
|
5001
|
+
* True Gasless Client
|
|
5002
|
+
*
|
|
5003
|
+
* Designed for server-side (backend) environments to securely build, sign,
|
|
5004
|
+
* and submit 100% sponsored gasless transactions using a Secret Key.
|
|
5005
|
+
*
|
|
5006
|
+
* @example
|
|
5007
|
+
* ```typescript
|
|
5008
|
+
* import { TrueGaslessClient } from '@smoothsend/sdk';
|
|
5009
|
+
* import { Account } from '@aptos-labs/ts-sdk';
|
|
5010
|
+
*
|
|
5011
|
+
* const backendWallet = Account.fromPrivateKey({ privateKey: '...' });
|
|
5012
|
+
* const client = new TrueGaslessClient({ apiKey: 'sk_nogas_...', network: 'mainnet' });
|
|
5013
|
+
*
|
|
5014
|
+
* const result = await client.execute({
|
|
5015
|
+
* senderAccount: backendWallet,
|
|
5016
|
+
* payload: {
|
|
5017
|
+
* function: "0x123::my_module::mint_nft",
|
|
5018
|
+
* functionArguments: []
|
|
5019
|
+
* }
|
|
5020
|
+
* });
|
|
5021
|
+
*
|
|
5022
|
+
* console.log("Gasless NFT Minted!", result.txHash);
|
|
5023
|
+
* ```
|
|
5024
|
+
*/
|
|
5025
|
+
class TrueGaslessClient {
|
|
5026
|
+
constructor(config) {
|
|
5027
|
+
if (!config.apiKey) {
|
|
5028
|
+
throw new SmoothSendError('API key is required', 'MISSING_API_KEY', 400);
|
|
5029
|
+
}
|
|
5030
|
+
if (!config.apiKey.startsWith('sk_nogas_')) {
|
|
5031
|
+
console.warn('⚠️ WARNING: TrueGaslessClient is intended for backend use with a Secret Key (sk_nogas_*).\n' +
|
|
5032
|
+
'Using a Public Key may result in CORS errors if ran in a browser environment.');
|
|
5033
|
+
}
|
|
5034
|
+
if (!config.network) {
|
|
5035
|
+
throw new SmoothSendError('Network is required (testnet or mainnet)', 'MISSING_NETWORK', 400);
|
|
5036
|
+
}
|
|
5037
|
+
this.config = {
|
|
5038
|
+
apiKey: config.apiKey,
|
|
5039
|
+
network: config.network,
|
|
5040
|
+
proxyUrl: config.proxyUrl,
|
|
5041
|
+
timeout: config.timeout || 30000,
|
|
5042
|
+
debug: config.debug || false,
|
|
5043
|
+
};
|
|
5044
|
+
this.httpClient = new HttpClient({
|
|
5045
|
+
apiKey: this.config.apiKey,
|
|
5046
|
+
network: this.config.network,
|
|
5047
|
+
timeout: this.config.timeout,
|
|
5048
|
+
retries: 3,
|
|
5049
|
+
includeOrigin: false, // Backend client should not send Origin header
|
|
5050
|
+
baseUrl: this.config.proxyUrl, // Use custom proxy URL if provided
|
|
5051
|
+
});
|
|
5052
|
+
const networkMap = {
|
|
5053
|
+
testnet: Network.TESTNET,
|
|
5054
|
+
mainnet: Network.MAINNET,
|
|
5055
|
+
};
|
|
5056
|
+
this.aptos = new Aptos(new AptosConfig({ network: networkMap[this.config.network] }));
|
|
5057
|
+
}
|
|
5058
|
+
log(message, data) {
|
|
5059
|
+
if (this.config.debug) {
|
|
5060
|
+
console.log(`[TrueGaslessClient] ${message}`, data || '');
|
|
5061
|
+
}
|
|
5062
|
+
}
|
|
5063
|
+
/**
|
|
5064
|
+
* Builds, signs (as sender), and relays an arbitrary payload for complete sponsorship.
|
|
5065
|
+
*/
|
|
5066
|
+
async execute(params) {
|
|
5067
|
+
this.log('Starting gasless execution', { sender: params.senderAccount.accountAddress.toString(), payload: params.payload });
|
|
5068
|
+
if (!params.senderAccount || !params.payload) {
|
|
5069
|
+
throw new SmoothSendError('Missing required parameters: senderAccount and payload', 'INVALID_PARAMETERS', 400);
|
|
5070
|
+
}
|
|
5071
|
+
try {
|
|
5072
|
+
this.log('Building simple transaction with fee payer enabled');
|
|
5073
|
+
// Build the transaction and flag it requires a remote fee payer
|
|
5074
|
+
const transaction = await this.aptos.transaction.build.simple({
|
|
5075
|
+
sender: params.senderAccount.accountAddress,
|
|
5076
|
+
data: params.payload,
|
|
5077
|
+
withFeePayer: true,
|
|
5078
|
+
});
|
|
5079
|
+
this.log('Signing transaction locally with senderAccount');
|
|
5080
|
+
// Sign locally over the transaction hash
|
|
5081
|
+
const senderAuthenticator = this.aptos.transaction.sign({
|
|
5082
|
+
signer: params.senderAccount,
|
|
5083
|
+
transaction,
|
|
5084
|
+
});
|
|
5085
|
+
this.log('Serializing to bytes for relayer transmission');
|
|
5086
|
+
// Convert to BCS bytes expected by the proxy
|
|
5087
|
+
const transactionBytes = Array.from(transaction.bcsToBytes());
|
|
5088
|
+
const authenticatorBytes = Array.from(senderAuthenticator.bcsToBytes());
|
|
5089
|
+
this.log('Sending to relayer...');
|
|
5090
|
+
const response = await this.httpClient.post('/api/v1/relayer/gasless-transaction', {
|
|
5091
|
+
transactionBytes,
|
|
5092
|
+
authenticatorBytes,
|
|
5093
|
+
network: this.config.network,
|
|
5094
|
+
functionName: 'function' in params.payload ? params.payload.function : 'unknown',
|
|
5095
|
+
});
|
|
5096
|
+
this.log('Relayer submission successful', response.data);
|
|
5097
|
+
return {
|
|
5098
|
+
success: response.data.success ?? true,
|
|
5099
|
+
requestId: response.data.requestId,
|
|
5100
|
+
txHash: response.data.txnHash || response.data.txHash,
|
|
5101
|
+
gasUsed: response.data.gasUsed,
|
|
5102
|
+
vmStatus: response.data.vmStatus,
|
|
5103
|
+
sender: response.data.sender || params.senderAccount.accountAddress.toString(),
|
|
5104
|
+
};
|
|
5105
|
+
}
|
|
5106
|
+
catch (error) {
|
|
5107
|
+
this.log('Gasless execution failed', error);
|
|
5108
|
+
if (error instanceof SmoothSendError) {
|
|
5109
|
+
throw error;
|
|
5110
|
+
}
|
|
5111
|
+
throw new SmoothSendError(`Failed to execute gasless transaction: ${error.message}`, 'EXECUTION_FAILED', 500, { originalError: error.message });
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
/**
|
|
5115
|
+
* Expose the core Aptos instance to allow backend developers to access chain state if needed
|
|
5116
|
+
*/
|
|
5117
|
+
getAptosClient() {
|
|
5118
|
+
return this.aptos;
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
/**
|
|
5122
|
+
* Helper to initialize TrueGaslessClient
|
|
5123
|
+
*/
|
|
5124
|
+
function createTrueGaslessClient(config) {
|
|
5125
|
+
return new TrueGaslessClient(config);
|
|
5126
|
+
}
|
|
5127
|
+
|
|
2889
5128
|
/**
|
|
2890
5129
|
* SmoothSend SDK v2.0
|
|
2891
5130
|
*
|
|
@@ -2917,7 +5156,7 @@ function createScriptComposerClient(config) {
|
|
|
2917
5156
|
* SDK version
|
|
2918
5157
|
* @public
|
|
2919
5158
|
*/
|
|
2920
|
-
const VERSION = '2.2.
|
|
5159
|
+
const VERSION = '2.2.1';
|
|
2921
5160
|
|
|
2922
|
-
export { APTOS_ERROR_CODES, AptosAdapter, AuthenticationError, CHAIN_ECOSYSTEM_MAP, HttpClient, NetworkError, RateLimitError, STELLAR_ERROR_CODES, ScriptComposerClient, SmoothSendError, SmoothSendSDK, SmoothSendSession, SmoothSendTransactionSubmitter, StellarAdapter, StellarCAddressAdapter, VERSION, ValidationError, createErrorFromResponse, createNetworkError, createScriptComposerClient, createSmoothSendSubmitter, SmoothSendSDK as default, useSmoothSend };
|
|
5161
|
+
export { APTOS_ERROR_CODES, AptosAdapter, AuthenticationError, AvaxSubmitter, CHAIN_ECOSYSTEM_MAP, ENTRY_POINT_V07_ADDRESS, HttpClient, NetworkError, RateLimitError, SIMPLE_ACCOUNT_FACTORY_ABI, STELLAR_ERROR_CODES, ScriptComposerClient, SmoothSendAvaxProvider, SmoothSendAvaxSubmitter, SmoothSendError, SmoothSendSDK, SmoothSendSession, SmoothSendTransactionSubmitter, StellarAdapter, StellarCAddressAdapter, TrueGaslessClient, VERSION, ValidationError, avaxExecuteAbi, createErrorFromResponse, createNetworkError, createScriptComposerClient, createSmoothSendAvaxSubmitter, createSmoothSendSubmitter, createTrueGaslessClient, SmoothSendSDK as default, encodeAvaxExecuteCalldata, encodeCreateAccountFactoryData, fetchAvaxAaPublicDefaults, hashUserOperationAvax, predictSimpleAccountAddress, readAvaxSenderNonce, useSmoothSend, useSmoothSendAvax, useSmoothSendAvaxContext, userOperationAvaxToViem };
|
|
2923
5162
|
//# sourceMappingURL=index.esm.js.map
|