@zama-fhe/sdk 2.1.1-alpha.2 → 2.2.0-alpha.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 +3 -4
- package/dist/cjs/activity.cjs +1 -1
- package/dist/cjs/activity.cjs.map +1 -1
- package/dist/cjs/cleartext/index.cjs +1 -2
- package/dist/cjs/cleartext.cjs +2 -0
- package/dist/cjs/{cleartext/index.cjs.map → cleartext.cjs.map} +1 -1
- package/dist/cjs/ethers/index.cjs +1 -1
- package/dist/cjs/ethers/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/query/index.cjs +1 -1
- package/dist/cjs/query/index.cjs.map +1 -1
- package/dist/cjs/transfer-batcher.cjs +1 -1
- package/dist/cjs/transfer-batcher.cjs.map +1 -1
- package/dist/cjs/viem/index.cjs +1 -1
- package/dist/cjs/viem/index.cjs.map +1 -1
- package/dist/cjs/{erc165.cjs → wrappers-registry.cjs} +2 -2
- package/dist/cjs/wrappers-registry.cjs.map +1 -0
- package/dist/esm/{activity-B4coeVs1.d.ts → activity-BRrEPcPO.d.ts} +256 -27
- package/dist/esm/activity-ChJnF5yd.js +2 -0
- package/dist/esm/activity-ChJnF5yd.js.map +1 -0
- package/dist/esm/cleartext/index.d.ts +5 -2
- package/dist/esm/cleartext/index.js +1 -2
- package/dist/esm/cleartext-CxGEREks.js +2 -0
- package/dist/esm/cleartext-CxGEREks.js.map +1 -0
- package/dist/esm/{eip1193-subscribe-Cl_wlVuQ.js → eip1193-subscribe-Cp2QVN0m.js} +1 -1
- package/dist/esm/{eip1193-subscribe-Cl_wlVuQ.js.map → eip1193-subscribe-Cp2QVN0m.js.map} +1 -1
- package/dist/esm/ethers/index.d.ts +12 -5
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/ethers/index.js.map +1 -1
- package/dist/esm/fhe-artifact-cache-vzh7Xn9G.js.map +1 -1
- package/dist/esm/{index-BaBH5_l6.d.ts → index-IhsduS7h.d.ts} +1134 -7
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/index.d.ts +3 -3
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/query/index.d.ts +124 -8
- package/dist/esm/query/index.js +1 -1
- package/dist/esm/query/index.js.map +1 -1
- package/dist/esm/{relayer-sdk-mcgawhDN.d.ts → relayer-sdk-CcIghrEq.d.ts} +2 -2
- package/dist/esm/{relayer-sdk.types--cY3a2ni.d.ts → relayer-sdk.types-D7rylLS4.d.ts} +1 -1
- package/dist/esm/{relayer-utils-DgRkaB8f.d.ts → relayer-utils-BcTAyZOr.d.ts} +14 -3
- package/dist/esm/relayer-utils-BeoTNDM4.js +2 -0
- package/dist/esm/relayer-utils-BeoTNDM4.js.map +1 -0
- package/dist/esm/transfer-batcher-BXIo7hnu.js +2 -0
- package/dist/esm/transfer-batcher-BXIo7hnu.js.map +1 -0
- package/dist/esm/viem/index.d.ts +24 -5
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/viem/index.js.map +1 -1
- package/dist/esm/{erc165-GmIEu75Z.js → wrappers-registry-DqPr_JG2.js} +2 -2
- package/dist/esm/wrappers-registry-DqPr_JG2.js.map +1 -0
- package/package.json +1 -1
- package/dist/cjs/erc165.cjs.map +0 -1
- package/dist/cjs/relayer-utils.cjs +0 -2
- package/dist/cjs/relayer-utils.cjs.map +0 -1
- package/dist/esm/activity-q5o6CCaY.js +0 -2
- package/dist/esm/activity-q5o6CCaY.js.map +0 -1
- package/dist/esm/cleartext/index.js.map +0 -1
- package/dist/esm/erc165-GmIEu75Z.js.map +0 -1
- package/dist/esm/relayer-utils--TV3NTMg.js +0 -2
- package/dist/esm/relayer-utils--TV3NTMg.js.map +0 -1
- package/dist/esm/transfer-batcher-C8gp7S82.js +0 -2
- package/dist/esm/transfer-batcher-C8gp7S82.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as TransactionResult, _ as StoredCredentials, b as SignerLifecycleCallbacks, g as DelegatedStoredCredentials, h as UnshieldCallbacks, m as TransferCallbacks, o as Handle, p as ShieldCallbacks, v as GenericStorage, x as RawLog, y as GenericSigner } from "./relayer-sdk.types
|
|
2
|
-
import { t as
|
|
1
|
+
import { C as TransactionResult, _ as StoredCredentials, b as SignerLifecycleCallbacks, g as DelegatedStoredCredentials, h as UnshieldCallbacks, m as TransferCallbacks, o as Handle, p as ShieldCallbacks, v as GenericStorage, x as RawLog, y as GenericSigner } from "./relayer-sdk.types-D7rylLS4.js";
|
|
2
|
+
import { n as TokenWrapperPair, r as TokenWrapperPairWithMetadata, t as PaginatedResult } from "./index-IhsduS7h.js";
|
|
3
|
+
import { t as RelayerSDK } from "./relayer-sdk-CcIghrEq.js";
|
|
3
4
|
import { Address, Hex } from "viem";
|
|
4
5
|
|
|
5
6
|
//#region src/events/sdk-events.d.ts
|
|
@@ -13,8 +14,8 @@ declare const ZamaSDKEvents: {
|
|
|
13
14
|
readonly CredentialsCreating: "credentials:creating";
|
|
14
15
|
readonly CredentialsCreated: "credentials:created";
|
|
15
16
|
readonly CredentialsRevoked: "credentials:revoked";
|
|
16
|
-
readonly CredentialsAllowed: "credentials:allowed";
|
|
17
17
|
readonly CredentialsPersistFailed: "credentials:persist_failed";
|
|
18
|
+
readonly CredentialsAllowed: "credentials:allowed";
|
|
18
19
|
readonly CredentialsCorrupted: "credentials:corrupted";
|
|
19
20
|
readonly SessionExpired: "session:expired";
|
|
20
21
|
readonly EncryptStart: "encrypt:start";
|
|
@@ -74,16 +75,16 @@ interface CredentialsRevokedEvent extends BaseEvent {
|
|
|
74
75
|
type: typeof ZamaSDKEvents.CredentialsRevoked;
|
|
75
76
|
contractAddresses?: Address[];
|
|
76
77
|
}
|
|
78
|
+
interface CredentialsPersistFailedEvent extends BaseEvent {
|
|
79
|
+
type: typeof ZamaSDKEvents.CredentialsPersistFailed;
|
|
80
|
+
/** The error that caused the persist failure. */
|
|
81
|
+
error: Error;
|
|
82
|
+
}
|
|
77
83
|
interface CredentialsAllowedEvent extends BaseEvent {
|
|
78
84
|
type: typeof ZamaSDKEvents.CredentialsAllowed;
|
|
79
85
|
/** Contract addresses covered by the authorized credentials. */
|
|
80
86
|
contractAddresses?: Address[];
|
|
81
87
|
}
|
|
82
|
-
interface CredentialsPersistFailedEvent extends BaseEvent {
|
|
83
|
-
type: typeof ZamaSDKEvents.CredentialsPersistFailed;
|
|
84
|
-
/** The error that caused persistence to fail. */
|
|
85
|
-
error: Error;
|
|
86
|
-
}
|
|
87
88
|
interface CredentialsCorruptedEvent extends BaseEvent {
|
|
88
89
|
type: typeof ZamaSDKEvents.CredentialsCorrupted;
|
|
89
90
|
/** The error that revealed storage corruption. */
|
|
@@ -175,7 +176,7 @@ interface UnshieldPhase2SubmittedEvent extends BaseEvent {
|
|
|
175
176
|
txHash: Hex;
|
|
176
177
|
}
|
|
177
178
|
/** Discriminated union of all SDK events. Never contains amounts, private keys, handles, or proofs. */
|
|
178
|
-
type ZamaSDKEvent = CredentialsLoadingEvent | CredentialsCachedEvent | CredentialsExpiredEvent | CredentialsCreatingEvent | CredentialsCreatedEvent | CredentialsRevokedEvent |
|
|
179
|
+
type ZamaSDKEvent = CredentialsLoadingEvent | CredentialsCachedEvent | CredentialsExpiredEvent | CredentialsCreatingEvent | CredentialsCreatedEvent | CredentialsRevokedEvent | CredentialsPersistFailedEvent | CredentialsAllowedEvent | CredentialsCorruptedEvent | SessionExpiredEvent | EncryptStartEvent | EncryptEndEvent | EncryptErrorEvent | DecryptStartEvent | DecryptEndEvent | DecryptErrorEvent | TransactionErrorEvent | ShieldSubmittedEvent | TransferSubmittedEvent | TransferFromSubmittedEvent | ApproveSubmittedEvent | ApproveUnderlyingSubmittedEvent | UnwrapSubmittedEvent | FinalizeUnwrapSubmittedEvent | DelegationSubmittedEvent | RevokeDelegationSubmittedEvent | UnshieldPhase1SubmittedEvent | UnshieldPhase2StartedEvent | UnshieldPhase2SubmittedEvent;
|
|
179
180
|
type ZamaSDKEventListener = (event: ZamaSDKEvent) => void;
|
|
180
181
|
/** Distributive Omit that preserves the discriminated union. */
|
|
181
182
|
type ZamaSDKEventInput = ZamaSDKEvent extends infer E ? E extends ZamaSDKEvent ? Omit<E, "timestamp" | "tokenAddress"> : never : never;
|
|
@@ -662,22 +663,6 @@ declare class ReadonlyToken {
|
|
|
662
663
|
* ```
|
|
663
664
|
*/
|
|
664
665
|
static batchDecryptBalancesAs(tokens: ReadonlyToken[], options: BatchDecryptAsOptions): Promise<Map<Address, bigint>>;
|
|
665
|
-
/**
|
|
666
|
-
* Look up the wrapper contract for this token via the deployment coordinator.
|
|
667
|
-
* Returns `null` if no wrapper is deployed.
|
|
668
|
-
*
|
|
669
|
-
* @param coordinatorAddress - The deployment coordinator contract address.
|
|
670
|
-
* @returns The wrapper address, or `null` if no wrapper exists.
|
|
671
|
-
*
|
|
672
|
-
* @example
|
|
673
|
-
* ```ts
|
|
674
|
-
* const wrapper = await token.discoverWrapper("0xCoordinator");
|
|
675
|
-
* if (wrapper) {
|
|
676
|
-
* const fullToken = sdk.createToken(token.address, wrapper);
|
|
677
|
-
* }
|
|
678
|
-
* ```
|
|
679
|
-
*/
|
|
680
|
-
discoverWrapper(coordinatorAddress: Address): Promise<Address | null>;
|
|
681
666
|
/**
|
|
682
667
|
* Read the underlying ERC-20 address from this token's wrapper contract.
|
|
683
668
|
*
|
|
@@ -1225,6 +1210,210 @@ declare class Token extends ReadonlyToken {
|
|
|
1225
1210
|
}): Promise<Map<Address, TransactionResult | ZamaError>>;
|
|
1226
1211
|
}
|
|
1227
1212
|
//#endregion
|
|
1213
|
+
//#region src/wrappers-registry.d.ts
|
|
1214
|
+
/**
|
|
1215
|
+
* Default wrappers registry addresses for known chains.
|
|
1216
|
+
* Only includes chains where a registry is deployed (excludes Hardhat).
|
|
1217
|
+
*/
|
|
1218
|
+
declare const DefaultRegistryAddresses: Record<number, Address>;
|
|
1219
|
+
/** Configuration for {@link WrappersRegistry}. */
|
|
1220
|
+
interface WrappersRegistryConfig {
|
|
1221
|
+
/** The connected wallet signer. Must satisfy the full `GenericSigner` interface. */
|
|
1222
|
+
signer: GenericSigner;
|
|
1223
|
+
/**
|
|
1224
|
+
* Per-chain registry address overrides, merged on top of
|
|
1225
|
+
* {@link DefaultRegistryAddresses}. Use this to supply a registry
|
|
1226
|
+
* address for custom or local chains (e.g. Hardhat).
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```ts
|
|
1230
|
+
* new WrappersRegistry({
|
|
1231
|
+
* signer,
|
|
1232
|
+
* registryAddresses: { [31337]: "0xYourHardhatRegistry" },
|
|
1233
|
+
* });
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
registryAddresses?: Record<number, Address>;
|
|
1237
|
+
/**
|
|
1238
|
+
* How long cached registry results remain valid, in seconds.
|
|
1239
|
+
* Default: `86400` (24 hours). Consistent with `keypairTTL`/`sessionTTL`.
|
|
1240
|
+
*/
|
|
1241
|
+
registryTTL?: number;
|
|
1242
|
+
}
|
|
1243
|
+
/** Options for {@link WrappersRegistry.listPairs}. */
|
|
1244
|
+
interface ListPairsOptions {
|
|
1245
|
+
/** Page number (1-indexed). Default: `1`. */
|
|
1246
|
+
page?: number;
|
|
1247
|
+
/** Number of items per page. Default: `100`. */
|
|
1248
|
+
pageSize?: number;
|
|
1249
|
+
/**
|
|
1250
|
+
* When `true`, fetches on-chain metadata (name, symbol, decimals) for both
|
|
1251
|
+
* the ERC-20 and confidential token, plus totalSupply for the ERC-20.
|
|
1252
|
+
* Default: `false`.
|
|
1253
|
+
*/
|
|
1254
|
+
metadata?: boolean;
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* High-level interface for the on-chain token wrappers registry.
|
|
1258
|
+
*
|
|
1259
|
+
* Uses the connected signer to resolve the correct registry contract
|
|
1260
|
+
* address for the current chain and exposes typed read helpers for
|
|
1261
|
+
* every registry query. Results are cached in memory with a
|
|
1262
|
+
* configurable TTL (default 24 hours).
|
|
1263
|
+
*
|
|
1264
|
+
* @example
|
|
1265
|
+
* ```ts
|
|
1266
|
+
* const registry = new WrappersRegistry({ signer });
|
|
1267
|
+
*
|
|
1268
|
+
* // Paginated listing
|
|
1269
|
+
* const page1 = await registry.listPairs({ page: 1, pageSize: 20 });
|
|
1270
|
+
*
|
|
1271
|
+
* // Structured lookups
|
|
1272
|
+
* const result = await registry.getConfidentialToken(erc20Address);
|
|
1273
|
+
* if (result) console.log(result.confidentialTokenAddress);
|
|
1274
|
+
*
|
|
1275
|
+
* // Force refresh
|
|
1276
|
+
* registry.refresh();
|
|
1277
|
+
* ```
|
|
1278
|
+
*/
|
|
1279
|
+
declare class WrappersRegistry {
|
|
1280
|
+
#private;
|
|
1281
|
+
readonly signer: GenericSigner;
|
|
1282
|
+
constructor(config: WrappersRegistryConfig);
|
|
1283
|
+
/**
|
|
1284
|
+
* Synchronous lookup of the registry address for a given chain ID.
|
|
1285
|
+
* Returns `undefined` if no address is configured for that chain.
|
|
1286
|
+
*/
|
|
1287
|
+
getAddress(chainId: number): Address | undefined;
|
|
1288
|
+
/**
|
|
1289
|
+
* Force-invalidate the in-memory cache. The next call to any read method
|
|
1290
|
+
* will fetch fresh data from the chain.
|
|
1291
|
+
*/
|
|
1292
|
+
refresh(): void;
|
|
1293
|
+
/**
|
|
1294
|
+
* The cache TTL in milliseconds.
|
|
1295
|
+
* Exposed so query option factories can set a matching `staleTime`.
|
|
1296
|
+
*/
|
|
1297
|
+
get ttlMs(): number;
|
|
1298
|
+
/**
|
|
1299
|
+
* Resolve the registry contract address for the current chain.
|
|
1300
|
+
*
|
|
1301
|
+
* Priority: `registryAddresses[chainId]` \> built-in default.
|
|
1302
|
+
*
|
|
1303
|
+
* @returns The registry contract address for the connected chain.
|
|
1304
|
+
* @throws {@link ConfigurationError} if no address is configured for the chain.
|
|
1305
|
+
*/
|
|
1306
|
+
getRegistryAddress(): Promise<Address>;
|
|
1307
|
+
/**
|
|
1308
|
+
* List token wrapper pairs with page-based pagination.
|
|
1309
|
+
*
|
|
1310
|
+
* Internally maps to `getTokenConfidentialTokenPairsSlice` on-chain.
|
|
1311
|
+
*
|
|
1312
|
+
* @param options - Pagination and enrichment options.
|
|
1313
|
+
* @returns A {@link PaginatedResult} of pairs.
|
|
1314
|
+
*
|
|
1315
|
+
* @example
|
|
1316
|
+
* ```ts
|
|
1317
|
+
* const result = await registry.listPairs({ page: 1, pageSize: 20 });
|
|
1318
|
+
* console.log(`${result.total} pairs, showing page ${result.page}`);
|
|
1319
|
+
*
|
|
1320
|
+
* // With on-chain metadata
|
|
1321
|
+
* const withMeta = await registry.listPairs({ metadata: true, pageSize: 10 });
|
|
1322
|
+
* for (const pair of withMeta.items) {
|
|
1323
|
+
* console.log(pair.underlying.symbol, "→", pair.confidential.symbol);
|
|
1324
|
+
* }
|
|
1325
|
+
* ```
|
|
1326
|
+
*/
|
|
1327
|
+
listPairs(options: ListPairsOptions & {
|
|
1328
|
+
metadata: true;
|
|
1329
|
+
}): Promise<PaginatedResult<TokenWrapperPairWithMetadata>>;
|
|
1330
|
+
listPairs(options?: ListPairsOptions): Promise<PaginatedResult<TokenWrapperPair>>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Look up the confidential token for a given plain ERC-20 address.
|
|
1333
|
+
*
|
|
1334
|
+
* @param tokenAddress - The plain ERC-20 token address.
|
|
1335
|
+
* @returns The lookup result, or `null` if no pair is registered.
|
|
1336
|
+
*
|
|
1337
|
+
* @example
|
|
1338
|
+
* ```ts
|
|
1339
|
+
* const result = await registry.getConfidentialToken(usdcAddress);
|
|
1340
|
+
* if (result) {
|
|
1341
|
+
* console.log(result.confidentialTokenAddress, result.isValid);
|
|
1342
|
+
* }
|
|
1343
|
+
* ```
|
|
1344
|
+
*/
|
|
1345
|
+
getConfidentialToken(tokenAddress: Address): Promise<{
|
|
1346
|
+
confidentialTokenAddress: Address;
|
|
1347
|
+
isValid: boolean;
|
|
1348
|
+
} | null>;
|
|
1349
|
+
/**
|
|
1350
|
+
* Reverse lookup — find the plain ERC-20 for a given confidential token.
|
|
1351
|
+
*
|
|
1352
|
+
* @param confidentialTokenAddress - The confidential token address.
|
|
1353
|
+
* @returns The lookup result, or `null` if no pair is registered.
|
|
1354
|
+
*
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```ts
|
|
1357
|
+
* const result = await registry.getUnderlyingToken(cUsdcAddress);
|
|
1358
|
+
* if (result) {
|
|
1359
|
+
* console.log(result.tokenAddress, result.isValid);
|
|
1360
|
+
* }
|
|
1361
|
+
* ```
|
|
1362
|
+
*/
|
|
1363
|
+
getUnderlyingToken(confidentialTokenAddress: Address): Promise<{
|
|
1364
|
+
tokenAddress: Address;
|
|
1365
|
+
isValid: boolean;
|
|
1366
|
+
} | null>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Fetch all token wrapper pairs from the registry.
|
|
1369
|
+
*
|
|
1370
|
+
* @returns All registered `TokenWrapperPair` entries.
|
|
1371
|
+
*/
|
|
1372
|
+
getTokenPairs(): Promise<readonly TokenWrapperPair[]>;
|
|
1373
|
+
/**
|
|
1374
|
+
* Get the total number of token wrapper pairs.
|
|
1375
|
+
*
|
|
1376
|
+
* @returns The count as a bigint.
|
|
1377
|
+
*/
|
|
1378
|
+
getTokenPairsLength(): Promise<bigint>;
|
|
1379
|
+
/**
|
|
1380
|
+
* Fetch a range of token wrapper pairs (paginated by index).
|
|
1381
|
+
*
|
|
1382
|
+
* @param fromIndex - Start index (inclusive).
|
|
1383
|
+
* @param toIndex - End index (exclusive).
|
|
1384
|
+
* @returns The slice of `TokenWrapperPair` entries.
|
|
1385
|
+
*/
|
|
1386
|
+
getTokenPairsSlice(fromIndex: bigint, toIndex: bigint): Promise<readonly TokenWrapperPair[]>;
|
|
1387
|
+
/**
|
|
1388
|
+
* Fetch a single token wrapper pair by index.
|
|
1389
|
+
*
|
|
1390
|
+
* @param index - Zero-based pair index.
|
|
1391
|
+
* @returns The `TokenWrapperPair` at that index.
|
|
1392
|
+
*/
|
|
1393
|
+
getTokenPair(index: bigint): Promise<TokenWrapperPair>;
|
|
1394
|
+
/**
|
|
1395
|
+
* Look up the confidential token address for a given plain ERC-20 token.
|
|
1396
|
+
*
|
|
1397
|
+
* @param tokenAddress - The plain ERC-20 token address.
|
|
1398
|
+
* @returns A tuple `[found, confidentialTokenAddress]`.
|
|
1399
|
+
*/
|
|
1400
|
+
getConfidentialTokenAddress(tokenAddress: Address): Promise<readonly [boolean, Address]>;
|
|
1401
|
+
/**
|
|
1402
|
+
* Reverse lookup — find the plain ERC-20 for a given confidential token.
|
|
1403
|
+
*
|
|
1404
|
+
* @param confidentialTokenAddress - The confidential token address.
|
|
1405
|
+
* @returns A tuple `[found, tokenAddress]`.
|
|
1406
|
+
*/
|
|
1407
|
+
getTokenAddress(confidentialTokenAddress: Address): Promise<readonly [boolean, Address]>;
|
|
1408
|
+
/**
|
|
1409
|
+
* Check whether a confidential token is registered and valid.
|
|
1410
|
+
*
|
|
1411
|
+
* @param confidentialTokenAddress - The confidential token address to check.
|
|
1412
|
+
* @returns `true` if the token is a known valid wrapper in the registry.
|
|
1413
|
+
*/
|
|
1414
|
+
isConfidentialTokenValid(confidentialTokenAddress: Address): Promise<boolean>;
|
|
1415
|
+
}
|
|
1416
|
+
//#endregion
|
|
1228
1417
|
//#region src/zama-sdk.d.ts
|
|
1229
1418
|
/** Configuration for {@link ZamaSDK}. */
|
|
1230
1419
|
interface ZamaSDKConfig {
|
|
@@ -1256,6 +1445,16 @@ interface ZamaSDKConfig {
|
|
|
1256
1445
|
sessionTTL?: number | "infinite";
|
|
1257
1446
|
/** Optional structured event listener for debugging and telemetry. Never receives sensitive data. */
|
|
1258
1447
|
onEvent?: ZamaSDKEventListener;
|
|
1448
|
+
/**
|
|
1449
|
+
* Per-chain wrappers registry address overrides, merged on top of built-in defaults.
|
|
1450
|
+
* Use this for custom or local chains (e.g. Hardhat) where no default registry exists.
|
|
1451
|
+
*/
|
|
1452
|
+
registryAddresses?: Record<number, Address>;
|
|
1453
|
+
/**
|
|
1454
|
+
* How long cached registry results remain valid, in seconds.
|
|
1455
|
+
* Default: `86400` (24 hours). Consistent with `keypairTTL`/`sessionTTL`.
|
|
1456
|
+
*/
|
|
1457
|
+
registryTTL?: number;
|
|
1259
1458
|
/** Optional signer lifecycle callbacks composed with the SDK's internal session handling. */
|
|
1260
1459
|
signerLifecycleCallbacks?: SignerLifecycleCallbacks;
|
|
1261
1460
|
}
|
|
@@ -1271,6 +1470,17 @@ declare class ZamaSDK {
|
|
|
1271
1470
|
readonly sessionStorage: GenericStorage;
|
|
1272
1471
|
readonly credentials: CredentialsManager;
|
|
1273
1472
|
readonly delegatedCredentials: DelegatedCredentialsManager;
|
|
1473
|
+
/**
|
|
1474
|
+
* A {@link WrappersRegistry} instance auto-configured for the current chain.
|
|
1475
|
+
* Uses built-in defaults merged with any `registryAddresses` overrides, and the SDK's `registryTTL` if configured.
|
|
1476
|
+
*
|
|
1477
|
+
* @example
|
|
1478
|
+
* ```ts
|
|
1479
|
+
* const pairs = await sdk.registry.listPairs({ page: 1 });
|
|
1480
|
+
* const result = await sdk.registry.getConfidentialToken(erc20Address);
|
|
1481
|
+
* ```
|
|
1482
|
+
*/
|
|
1483
|
+
readonly registry: WrappersRegistry;
|
|
1274
1484
|
constructor(config: ZamaSDKConfig);
|
|
1275
1485
|
/**
|
|
1276
1486
|
* Create a read-only interface for a confidential token.
|
|
@@ -1289,6 +1499,25 @@ declare class ZamaSDK {
|
|
|
1289
1499
|
* @returns A {@link Token} instance bound to this SDK's relayer, signer, and storage.
|
|
1290
1500
|
*/
|
|
1291
1501
|
createToken(address: Address, wrapper?: Address): Token;
|
|
1502
|
+
/**
|
|
1503
|
+
* Create a {@link WrappersRegistry} instance bound to this SDK's signer.
|
|
1504
|
+
* On Mainnet and Sepolia the registry address is resolved automatically.
|
|
1505
|
+
*
|
|
1506
|
+
* @param registryAddresses - Optional per-chain overrides (e.g. Hardhat).
|
|
1507
|
+
* @returns A {@link WrappersRegistry} instance.
|
|
1508
|
+
*
|
|
1509
|
+
* @example
|
|
1510
|
+
* ```ts
|
|
1511
|
+
* // Mainnet / Sepolia — resolved automatically
|
|
1512
|
+
* const registry = sdk.createWrappersRegistry();
|
|
1513
|
+
*
|
|
1514
|
+
* // Hardhat or custom chain — override per chain
|
|
1515
|
+
* const registry = sdk.createWrappersRegistry({ [31337]: "0xYourRegistry" });
|
|
1516
|
+
*
|
|
1517
|
+
* const pairs = await registry.getTokenPairs();
|
|
1518
|
+
* ```
|
|
1519
|
+
*/
|
|
1520
|
+
createWrappersRegistry(registryAddresses?: Record<number, Address>): WrappersRegistry;
|
|
1292
1521
|
/**
|
|
1293
1522
|
* Pre-authorize FHE credentials for one or more contract addresses.
|
|
1294
1523
|
* A single wallet signature covers all addresses, so subsequent decrypt
|
|
@@ -1573,5 +1802,5 @@ declare function applyDecryptedValues(items: readonly ActivityItem[], decryptedM
|
|
|
1573
1802
|
*/
|
|
1574
1803
|
declare function sortByBlockNumber(items: readonly ActivityItem[]): ActivityItem[];
|
|
1575
1804
|
//#endregion
|
|
1576
|
-
export {
|
|
1577
|
-
//# sourceMappingURL=activity-
|
|
1805
|
+
export { CredentialsCreatedEvent as $, ListPairsOptions as A, ReadonlyToken as B, decodeUnwrappedStarted as C, ZamaSDKEvent as Ct, ZamaSDK as D, ZamaSDKEvents as Dt, findWrapped as E, ZamaSDKEventType as Et, ZamaError as F, CredentialsManager as G, ZERO_HANDLE as H, ZamaErrorCode as I, ApproveUnderlyingSubmittedEvent as J, CredentialsManagerConfig as K, matchZamaError as L, WrappersRegistryConfig as M, Token as N, ZamaSDKConfig as O, TokenConfig as P, CredentialsCorruptedEvent as Q, BatchDecryptAsOptions as R, decodeUnwrappedFinalized as S, UnwrapSubmittedEvent as St, findUnwrapRequested as T, ZamaSDKEventListener as Tt, DelegatedCredentialsManager as U, ReadonlyTokenConfig as V, DelegatedCredentialsManagerConfig as W, CredentialsAllowedEvent as X, BaseEvent as Y, CredentialsCachedEvent as Z, WrappedEvent as _, TransferFromSubmittedEvent as _t, ActivityType as a, DecryptEndEvent as at, decodeOnChainEvents as b, UnshieldPhase2StartedEvent as bt, parseActivityFeed as c, DelegationSubmittedEvent as ct, OnChainEvent as d, EncryptStartEvent as dt, CredentialsCreatingEvent as et, TOKEN_TOPICS as f, FinalizeUnwrapSubmittedEvent as ft, UnwrappedStartedEvent as g, TransactionErrorEvent as gt, UnwrappedFinalizedEvent as h, ShieldSubmittedEvent as ht, ActivityLogMetadata as i, CredentialsRevokedEvent as it, WrappersRegistry as j, DefaultRegistryAddresses as k, sortByBlockNumber as l, EncryptEndEvent as lt, UnwrapRequestedEvent as m, SessionExpiredEvent as mt, ActivityDirection as n, CredentialsLoadingEvent as nt, applyDecryptedValues as o, DecryptErrorEvent as ot, Topics as p, RevokeDelegationSubmittedEvent as pt, ApproveSubmittedEvent as q, ActivityItem as r, CredentialsPersistFailedEvent as rt, extractEncryptedHandles as s, DecryptStartEvent as st, ActivityAmount as t, CredentialsExpiredEvent as tt, ConfidentialTransferEvent as u, EncryptErrorEvent as ut, decodeConfidentialTransfer as v, TransferSubmittedEvent as vt, decodeWrapped as w, ZamaSDKEventInput as wt, decodeUnwrapRequested as x, UnshieldPhase2SubmittedEvent as xt, decodeOnChainEvent as y, UnshieldPhase1SubmittedEvent as yt, BatchDecryptOptions as z };
|
|
1806
|
+
//# sourceMappingURL=activity-BRrEPcPO.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./relayer-BwP0WtkF.js";import{t as i}from"./encryption-cqcqcQQB.js";import{r as a,t as o}from"./memory-storage-DNvc-6oK.js";import{i as s,n as c,r as l,t as u}from"./assertions-BNzM20oj.js";import{t as d}from"./hex-BVdZkMrT.js";import{_ as f,c as p,f as m,l as h,m as g}from"./wrappers-registry-DqPr_JG2.js";import{erc20Abi as _,getAddress as v,isAddress as y}from"viem";var b=class extends n{constructor(t,n){super(e.SigningRejected,t,n),this.name=`SigningRejectedError`}},x=class extends n{constructor(t,n){super(e.SigningFailed,t,n),this.name=`SigningFailedError`}};function ee(e,t){let n=typeof e==`object`&&!!e&&`code`in e&&e.code===4001,r=e instanceof Error?e.message:String(e),i=r.toLowerCase().includes(`user rejected`)||r.toLowerCase().includes(`user denied`),a=`${t}: ${r}`;throw n||i?new b(a,{cause:e}):new x(a,{cause:e})}var te=class extends n{constructor(t,n){super(e.KeypairExpired,t,n),this.name=`KeypairExpiredError`}},ne=class extends n{constructor(t,n){super(e.InvalidKeypair,t,n),this.name=`InvalidKeypairError`}},S=class extends n{constructor(t,n){super(e.NoCiphertext,t,n),this.name=`NoCiphertextError`}},re=class extends n{constructor(t,n){super(e.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},ie=class extends n{constructor(t,n){super(e.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},C=class extends n{constructor(t,n){super(e.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},w=class extends n{constructor(t,n){super(e.DelegationExpired,t,n),this.name=`DelegationExpiredError`}};function ae(e){return{address:e,abi:_,functionName:`name`,args:[]}}function oe(e){return{address:e,abi:_,functionName:`symbol`,args:[]}}function se(e){return{address:e,abi:_,functionName:`decimals`,args:[]}}function ce(e){return{address:e,abi:_,functionName:`totalSupply`,args:[]}}function le(e,t){return{address:e,abi:_,functionName:`balanceOf`,args:[t]}}function ue(e,t,n){return{address:e,abi:_,functionName:`allowance`,args:[t,n]}}function de(e,t,n){return{address:e,abi:_,functionName:`approve`,args:[t,n]}}const T=[{inputs:[{internalType:`uint64`,name:`wrapFeeBasisPoints_`,type:`uint64`},{internalType:`uint64`,name:`unwrapFeeBasisPoints_`,type:`uint64`},{internalType:`uint64`,name:`deployFee_`,type:`uint64`},{internalType:`uint64`,name:`batchTransferFee_`,type:`uint64`},{internalType:`address`,name:`feeRecipient_`,type:`address`}],stateMutability:`nonpayable`,type:`constructor`},{inputs:[],name:`AccessControlBadConfirmation`,type:`error`},{inputs:[{internalType:`address`,name:`account`,type:`address`},{internalType:`bytes32`,name:`neededRole`,type:`bytes32`}],name:`AccessControlUnauthorizedAccount`,type:`error`},{inputs:[],name:`FeeExceedsMaximum`,type:`error`},{inputs:[],name:`ZeroAddressFeeRecipient`,type:`error`},{anonymous:!1,inputs:[{indexed:!1,internalType:`uint64`,name:`oldBatchTransferFee`,type:`uint64`},{indexed:!1,internalType:`uint64`,name:`newBatchTransferFee`,type:`uint64`}],name:`BatchTransferFeeUpdated`,type:`event`},{anonymous:!1,inputs:[{indexed:!1,internalType:`uint64`,name:`oldDeployFee`,type:`uint64`},{indexed:!1,internalType:`uint64`,name:`newDeployFee`,type:`uint64`}],name:`DeployFeeUpdated`,type:`event`},{anonymous:!1,inputs:[{indexed:!0,internalType:`address`,name:`oldRecipient`,type:`address`},{indexed:!0,internalType:`address`,name:`newRecipient`,type:`address`}],name:`FeeRecipientUpdated`,type:`event`},{anonymous:!1,inputs:[{indexed:!0,internalType:`bytes32`,name:`role`,type:`bytes32`},{indexed:!0,internalType:`bytes32`,name:`previousAdminRole`,type:`bytes32`},{indexed:!0,internalType:`bytes32`,name:`newAdminRole`,type:`bytes32`}],name:`RoleAdminChanged`,type:`event`},{anonymous:!1,inputs:[{indexed:!0,internalType:`bytes32`,name:`role`,type:`bytes32`},{indexed:!0,internalType:`address`,name:`account`,type:`address`},{indexed:!0,internalType:`address`,name:`sender`,type:`address`}],name:`RoleGranted`,type:`event`},{anonymous:!1,inputs:[{indexed:!0,internalType:`bytes32`,name:`role`,type:`bytes32`},{indexed:!0,internalType:`address`,name:`account`,type:`address`},{indexed:!0,internalType:`address`,name:`sender`,type:`address`}],name:`RoleRevoked`,type:`event`},{anonymous:!1,inputs:[{indexed:!1,internalType:`bool`,name:`active`,type:`bool`}],name:`SwapperFeeWaiverUpdated`,type:`event`},{anonymous:!1,inputs:[{indexed:!1,internalType:`uint64`,name:`oldFeeBasisPoints`,type:`uint64`},{indexed:!1,internalType:`uint64`,name:`newFeeBasisPoints`,type:`uint64`}],name:`UnwrapFeeBasisPointsUpdated`,type:`event`},{anonymous:!1,inputs:[{indexed:!1,internalType:`uint64`,name:`oldFeeBasisPoints`,type:`uint64`},{indexed:!1,internalType:`uint64`,name:`newFeeBasisPoints`,type:`uint64`}],name:`WrapFeeBasisPointsUpdated`,type:`event`},{inputs:[],name:`DEFAULT_ADMIN_ROLE`,outputs:[{internalType:`bytes32`,name:``,type:`bytes32`}],stateMutability:`view`,type:`function`},{inputs:[],name:`FEE_MANAGER_ROLE`,outputs:[{internalType:`bytes32`,name:``,type:`bytes32`}],stateMutability:`view`,type:`function`},{inputs:[],name:`MAX_BASIS_POINTS`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`SWAPPER_ROLE`,outputs:[{internalType:`bytes32`,name:``,type:`bytes32`}],stateMutability:`view`,type:`function`},{inputs:[],name:`batchTransferFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`deployFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`feeRecipient`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`},{inputs:[],name:`getBatchTransferFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`deployer`,type:`address`}],name:`getDeployFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`getFeeRecipient`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`bytes32`,name:`role`,type:`bytes32`}],name:`getRoleAdmin`,outputs:[{internalType:`bytes32`,name:``,type:`bytes32`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`uint64`,name:`amount`,type:`uint64`},{internalType:`address`,name:`unwrapFrom`,type:`address`},{internalType:`address`,name:`unwrapTo`,type:`address`}],name:`getUnwrapFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`uint256`,name:`amount`,type:`uint256`},{internalType:`address`,name:`wrapFrom`,type:`address`},{internalType:`address`,name:`wrapTo`,type:`address`}],name:`getWrapFee`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`bytes32`,name:`role`,type:`bytes32`},{internalType:`address`,name:`account`,type:`address`}],name:`grantRole`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`bytes32`,name:`role`,type:`bytes32`},{internalType:`address`,name:`account`,type:`address`}],name:`hasRole`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[],name:`protocolId`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`pure`,type:`function`},{inputs:[{internalType:`bytes32`,name:`role`,type:`bytes32`},{internalType:`address`,name:`callerConfirmation`,type:`address`}],name:`renounceRole`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`bytes32`,name:`role`,type:`bytes32`},{internalType:`address`,name:`account`,type:`address`}],name:`revokeRole`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`uint64`,name:`newBatchTransferFee`,type:`uint64`}],name:`setBatchTransferFee`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`uint64`,name:`newDeployFee`,type:`uint64`}],name:`setDeployFee`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`recipient`,type:`address`}],name:`setFeeRecipient`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`bool`,name:`active`,type:`bool`}],name:`setSwapperFeeWaiverActive`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`uint64`,name:`feeBasisPoints`,type:`uint64`}],name:`setUnwrapFeeBasisPoints`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`uint64`,name:`feeBasisPoints`,type:`uint64`}],name:`setWrapFeeBasisPoints`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`bytes4`,name:`interfaceId`,type:`bytes4`}],name:`supportsInterface`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[],name:`swapperFeeWaiverActive`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[],name:`unwrapFeeBasisPoints`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`wrapFeeBasisPoints`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`}];function fe(e,t,n,r){return{address:e,abi:T,functionName:`getWrapFee`,args:[t,n,r]}}function pe(e,t,n,r){return{address:e,abi:T,functionName:`getUnwrapFee`,args:[t,n,r]}}function me(e){return{address:e,abi:T,functionName:`getBatchTransferFee`,args:[]}}function he(e){return{address:e,abi:T,functionName:`getFeeRecipient`,args:[]}}const E=[{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`},{internalType:`uint64`,name:`expirationDate`,type:`uint64`}],name:`delegateForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`revokeDelegationForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegator`,type:`address`},{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`getUserDecryptionDelegationExpirationDate`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`}];function ge(e,t,n,r){return{address:e,abi:E,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function _e(e,t,n){return{address:e,abi:E,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function ve(e,t,n,r){return{address:e,abi:E,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}const D=2n**64n-1n,O={CredentialsLoading:`credentials:loading`,CredentialsCached:`credentials:cached`,CredentialsExpired:`credentials:expired`,CredentialsCreating:`credentials:creating`,CredentialsCreated:`credentials:created`,CredentialsRevoked:`credentials:revoked`,CredentialsPersistFailed:`credentials:persist_failed`,CredentialsAllowed:`credentials:allowed`,CredentialsCorrupted:`credentials:corrupted`,SessionExpired:`session:expired`,EncryptStart:`encrypt:start`,EncryptEnd:`encrypt:end`,EncryptError:`encrypt:error`,DecryptStart:`decrypt:start`,DecryptEnd:`decrypt:end`,DecryptError:`decrypt:error`,TransactionError:`transaction:error`,ShieldSubmitted:`shield:submitted`,TransferSubmitted:`transfer:submitted`,TransferFromSubmitted:`transferFrom:submitted`,ApproveSubmitted:`approve:submitted`,ApproveUnderlyingSubmitted:`approveUnderlying:submitted`,UnwrapSubmitted:`unwrap:submitted`,FinalizeUnwrapSubmitted:`finalizeUnwrap:submitted`,DelegationSubmitted:`delegation:submitted`,RevokeDelegationSubmitted:`revokeDelegation:submitted`,UnshieldPhase1Submitted:`unshield:phase1_submitted`,UnshieldPhase2Started:`unshield:phase2_started`,UnshieldPhase2Submitted:`unshield:phase2_submitted`};var ye=class{#e=null;#t=null;clearCache(){this.#e=null,this.#t=null}async encrypt(e,t,n){let r=await this.#n(t,n),i=crypto.getRandomValues(new Uint8Array(12)),a=new TextEncoder,o=await crypto.subtle.encrypt({name:`AES-GCM`,iv:i},r,a.encode(e));return{iv:btoa(String.fromCharCode(...i)),ciphertext:btoa(String.fromCharCode(...new Uint8Array(o)))}}async decrypt(e,t,n){let r=await this.#n(t,n),i=Uint8Array.from(atob(e.iv),e=>e.charCodeAt(0)),a=Uint8Array.from(atob(e.ciphertext),e=>e.charCodeAt(0)),o=await crypto.subtle.decrypt({name:`AES-GCM`,iv:i},r,a);return d(new TextDecoder().decode(o))}async#n(e,t){let n=`${e}:${t}`;if(this.#e&&this.#t===n)return this.#e;let r=new TextEncoder,i=await crypto.subtle.importKey(`raw`,r.encode(e),`PBKDF2`,!1,[`deriveKey`]),a=await crypto.subtle.deriveKey({name:`PBKDF2`,salt:r.encode(t),iterations:6e5,hash:`SHA-256`},i,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`]);return this.#t=n,this.#e=a,a}};function k(e){l(e,`Stored credentials`),s(e.publicKey,`credentials.publicKey`),u(e.contractAddresses,`credentials.contractAddresses`);for(let t of e.contractAddresses)c(typeof t==`string`&&y(t,{strict:!1}),`Expected each contractAddress to be a valid hex address`);l(e.encryptedPrivateKey,`credentials.encryptedPrivateKey`),s(e.encryptedPrivateKey.iv,`encryptedPrivateKey.iv`),s(e.encryptedPrivateKey.ciphertext,`encryptedPrivateKey.ciphertext`),c(typeof e.startTimestamp==`number`,`Expected credentials.startTimestamp to be a number`),c(typeof e.durationDays==`number`,`Expected credentials.durationDays to be a number`)}function be(e){k(e);let t=e;c(typeof t.delegatorAddress==`string`&&y(t.delegatorAddress,{strict:!1}),`Expected credentials.delegatorAddress to be a valid address`),c(typeof t.delegateAddress==`string`&&y(t.delegateAddress,{strict:!1}),`Expected credentials.delegateAddress to be a valid address`),c(typeof t.startTimestamp==`number`,`Expected startTimestamp to be a number`),c(typeof t.durationDays==`number`,`Expected durationDays to be a number`)}function A(e){return Math.floor(Date.now()/1e3)<e.startTimestamp+e.durationDays*86400}function j(e,t){let n=new Set(t.map(e=>v(e))),r=new Set(e.map(e=>v(e)));return n.isSubsetOf(r)}function M(e,t){return A(e)?j(e.contractAddresses,t):!1}function N(e){return[...new Set(e.map(e=>v(e)))].toSorted()}async function P(...e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e.map(String).join(`:`)));return Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,`0`)).join(``).slice(0,32)}var xe=class{#e;constructor(e){this.#e=e}#t(e){l(e,`Session entry`),s(e.signature,`session.signature`),c(typeof e.createdAt==`number`,`Expected session.createdAt to be a number`),c(typeof e.ttl==`number`||e.ttl===`infinite`,`Expected session.ttl to be a number or "infinite"`)}async get(e){let t=await this.#e.get(e);return t===null?null:(this.#t(t),t)}async set(e){let t={signature:e.signature,createdAt:Math.floor(Date.now()/1e3),ttl:e.ttl};await this.#e.set(e.key,t)}async delete(e){await this.#e.delete(e)}isExpired(e){return e.ttl===`infinite`?!1:e.ttl===0?!0:Math.floor(Date.now()/1e3)-e.createdAt>=e.ttl}},F=class{signer;storage;sessionSignatures;crypto;keypairTTL;sessionTTL;#e;#t=null;#n=null;#r=null;constructor(e){if(this.signer=e.signer,this.storage=e.storage,this.sessionSignatures=new xe(e.sessionStorage),this.crypto=new ye,this.keypairTTL=e.keypairTTL??86400,this.sessionTTL=e.sessionTTL??2592e3,this.#e=e.onEvent??(()=>{}),typeof this.keypairTTL==`number`&&this.keypairTTL<0)throw Error(`keypairTTL must be >= 0`);if(typeof this.sessionTTL==`number`&&this.sessionTTL<0)throw Error(`sessionTTL must be >= 0`)}emit(e){this.#e({...e,timestamp:Date.now()})}async resolveCredentials({key:e,contracts:t,createKey:n,createFn:r}){this.emit({type:O.CredentialsLoading,contractAddresses:t});try{let n=await this.storage.get(e);if(n){this.assertEncrypted(n);let r=await this.sessionSignatures.get(e);if(r)if(this.sessionSignatures.isExpired(r))await this.sessionSignatures.delete(e),this.emit({type:O.SessionExpired,reason:`ttl`});else{let i=await this.decryptCredentials(n,r.signature);if(M(i,t))return this.emit({type:O.CredentialsCached,contractAddresses:t}),this.emit({type:O.CredentialsAllowed,contractAddresses:t}),i;if(A(i))return this.#i({key:e,credentials:i,requiredContracts:t});this.emit({type:O.CredentialsExpired,contractAddresses:t})}if(A(n)){if(j(n.contractAddresses,t)){let r=await this.signForContracts(n,n.contractAddresses);await this.sessionSignatures.set({key:e,signature:r,ttl:this.sessionTTL});let i=await this.decryptCredentials(n,r);return this.emit({type:O.CredentialsCached,contractAddresses:t}),this.emit({type:O.CredentialsAllowed,contractAddresses:t}),i}let r=await this.signForContracts(n,n.contractAddresses),i=await this.decryptCredentials(n,r);return this.#i({key:e,credentials:i,requiredContracts:t})}this.emit({type:O.CredentialsExpired,contractAddresses:t})}}catch(t){if(t instanceof b||t instanceof x)throw t;console.warn(`[zama-sdk] Credential resolution failed, recreating:`,t),this.emit({type:O.CredentialsCorrupted,error:a(t)}),await this.#o(e)}return(!this.#t||this.#n!==n)&&(this.#n=n,this.#t=r().then(e=>(this.emit({type:O.CredentialsAllowed,contractAddresses:t}),e)).finally(()=>{this.#t=null,this.#n=null})),this.#t}async checkExpired(e,t){try{let n=await this.storage.get(e);return n?(this.assertEncrypted(n),!M(n,t?[t]:[])):!1}catch(e){return console.warn(`[zama-sdk] isExpired check failed, treating as expired:`,e),!0}}async revokeSession(e,t){await this.sessionSignatures.delete(e),this.clearCaches(),this.emit({type:O.CredentialsRevoked,...t?{contractAddresses:t}:{}})}async checkAllowed(e){let t=await this.sessionSignatures.get(e);return t===null?!1:!this.sessionSignatures.isExpired(t)}async clearAll(e){await this.sessionSignatures.delete(e),this.clearCaches(),await this.#o(e)}clearCaches(){this.crypto.clearCache()}async createCredentials({key:e,contractAddresses:t,createFn:n,errorContext:r}){this.emit({type:O.CredentialsCreating,contractAddresses:t});try{let r=await n();return await this.persistCredentials(e,r),await this.sessionSignatures.set({key:e,signature:r.signature,ttl:this.sessionTTL}),this.emit({type:O.CredentialsCreated,contractAddresses:t}),r}catch(e){ee(e,r)}}async#i({key:e,credentials:t,requiredContracts:n}){if(this.#r){let e=await this.#r;if(j(e.contractAddresses,n))return this.emit({type:O.CredentialsAllowed,contractAddresses:n}),e;t=e}let r=this.#a({key:e,credentials:t,requiredContracts:n});this.#r=r;try{return await r}finally{this.#r===r&&(this.#r=null)}}async#a({key:e,credentials:t,requiredContracts:n}){let r=N([...t.contractAddresses,...n]),i=await this.signForContracts(t,r),a={...t,contractAddresses:r,signature:i};return await this.persistCredentials(e,a),await this.sessionSignatures.set({key:e,signature:i,ttl:this.sessionTTL}),this.emit({type:O.CredentialsAllowed,contractAddresses:n}),a}async persistCredentials(e,t){try{let n=await this.encryptCredentials(t);await this.storage.set(e,n)}catch(e){console.warn(`[zama-sdk] Failed to encrypt credentials for persistence:`,e),this.emit({type:O.CredentialsPersistFailed,error:a(e)})}}async#o(e){try{await this.storage.delete(e)}catch(e){console.warn(`[zama-sdk] Failed to delete credentials:`,e),this.emit({type:O.CredentialsPersistFailed,error:a(e)})}}};function Se(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`runtime`);return typeof t!=`object`||!t?!1:typeof Reflect.get(t,`id`)==`string`}var I=class e extends F{#e;#t=null;#n=null;static async computeStoreKey(e,t){return P(v(e),t)}constructor(e){super(e),this.#e=e.relayer,Se(typeof globalThis<`u`?Reflect.get(globalThis,`chrome`):void 0)&&e.sessionStorage instanceof o&&console.warn(`[zama-sdk] Detected Chrome extension context with in-memory session storage. Session signatures will be lost on service worker restart and won't be shared across contexts. Consider using chromeSessionStorage instead. `)}async allow(...e){let t=N(e),n=await this.#r();return this.resolveCredentials({key:n,contracts:t,createKey:t.join(`,`),createFn:()=>this.create(t)})}async isExpired(e){return this.checkExpired(await this.#r(),e)}async revoke(...e){await this.revokeSession(await this.#r(),e.length>0?e:void 0)}async revokeByKey(e){await this.revokeSession(e)}async isAllowed(){return this.checkAllowed(await this.#r())}async clear(){await this.clearAll(await this.#r())}async create(e){let t=N(e),n=await this.#r();return this.createCredentials({key:n,contractAddresses:t,createFn:async()=>{let e=await this.#e.generateKeypair(),n=Math.floor(Date.now()/1e3),r=Math.ceil(this.keypairTTL/86400),i=await this.#e.createEIP712(e.publicKey,t,n,r),a=await this.signer.signTypedData(i);return{publicKey:e.publicKey,privateKey:e.privateKey,signature:a,contractAddresses:t,startTimestamp:n,durationDays:r}},errorContext:`Failed to create decrypt credentials`})}assertEncrypted(e){k(e)}async signForContracts(e,t){let n=await this.#e.createEIP712(e.publicKey,t,e.startTimestamp,e.durationDays);return this.signer.signTypedData(n)}async encryptCredentials(e){let t=await this.signer.getAddress(),n=await this.crypto.encrypt(e.privateKey,e.signature,t),{privateKey:r,signature:i,...a}=e;return{...a,encryptedPrivateKey:n}}async decryptCredentials(e,t){let n=await this.signer.getAddress(),r=await this.crypto.decrypt(e.encryptedPrivateKey,t,n),{encryptedPrivateKey:i,...a}=e;return{...a,privateKey:r,signature:t}}clearCaches(){this.#t=null,this.#n=null,super.clearCaches()}async#r(){let t=await this.signer.getAddress(),n=await this.signer.getChainId(),r=`${v(t)}:${n}`;if(this.#t&&this.#n===r)return this.#t;let i=await e.computeStoreKey(t,n);return this.#n=r,this.#t=i,i}},L=class e extends F{#e;#t=null;#n=null;static async computeStoreKey(e,t,n){return P(v(e),v(t),n)}constructor(e){super(e),this.#e=e.relayer}async allow(e,...t){let n=v(e),r=N(t),i=await this.#i(n);return this.resolveCredentials({key:i,contracts:r,createKey:`${n}:${r.join(`,`)}`,createFn:()=>this.#r(n,r)})}async isExpired(e,t){return this.checkExpired(await this.#i(v(e)),t)}async revoke(e){await this.revokeSession(await this.#i(v(e)))}async isAllowed(e){return this.checkAllowed(await this.#i(v(e)))}async clear(e){await this.clearAll(await this.#i(v(e)))}async#r(e,t){let n=await this.#i(e);return this.createCredentials({key:n,contractAddresses:t,createFn:async()=>{let n=await this.#e.generateKeypair(),r=await this.signer.getAddress(),i=Math.floor(Date.now()/1e3),a=Math.ceil(this.keypairTTL/86400),o={publicKey:n.publicKey,startTimestamp:i,durationDays:a,delegatorAddress:e},s=await this.#a(o,t);return{publicKey:n.publicKey,privateKey:n.privateKey,signature:s,contractAddresses:t,startTimestamp:i,durationDays:a,delegatorAddress:e,delegateAddress:r}},errorContext:`Failed to create delegated decrypt credentials`})}assertEncrypted(e){be(e)}async signForContracts(e,t){return this.#a(e,t)}async encryptCredentials(e){let t=await this.signer.getAddress(),n=await this.crypto.encrypt(e.privateKey,e.signature,t),{privateKey:r,signature:i,...a}=e;return{...a,encryptedPrivateKey:n}}async decryptCredentials(e,t){let n=await this.signer.getAddress(),r=await this.crypto.decrypt(e.encryptedPrivateKey,t,n),{encryptedPrivateKey:i,...a}=e;return{...a,privateKey:r,signature:t}}clearCaches(){this.#t=null,this.#n=null,super.clearCaches()}async#i(t){let n=await this.signer.getAddress(),r=await this.signer.getChainId(),i=`${v(n)}:${v(t)}:${r}`;if(this.#t&&this.#n===i)return this.#t;let a=await e.computeStoreKey(n,t,r);return this.#n=i,this.#t=a,a}async#a(e,t){let n=await this.#e.createDelegatedUserDecryptEIP712(e.publicKey,t,e.delegatorAddress,e.startTimestamp,e.durationDays);return this.signer.signTypedData({domain:{...n.domain,chainId:Number(n.domain.chainId)},types:n.types,message:{...n.message,startTimestamp:BigInt(n.message.startTimestamp),durationDays:BigInt(n.message.durationDays)}})}};const Ce=`zama:balances`;function we(e,t,n){return`zama:balance:${v(e)}:${v(t)}:${n.toLowerCase()}`}async function R({storage:e,tokenAddress:t,owner:n,handle:r}){try{let i=await e.get(we(t,n,r));return i===null?null:BigInt(i)}catch(e){return console.warn(`[zama-sdk] Balance cache read failed:`,e),null}}async function z(e){let{storage:t,tokenAddress:n,owner:r,handle:i,value:a}=e,o=we(n,r,i);try{await t.set(o,a.toString()),await Ee(t,o)}catch{}}const Te=new WeakMap;async function Ee(e,t){let n=(Te.get(e)??Promise.resolve()).then(async()=>{let n=await e.get(Ce),r=n?JSON.parse(n):[];r.includes(t)||(r.push(t),await e.set(Ce,JSON.stringify(r)))});return Te.set(e,n.catch(()=>{})),n}async function De(e,t=1/0){if(Number.isFinite(t)&&t<=0)throw Error(`maxConcurrency must be a positive number`);if(!Number.isFinite(t)||t>=e.length)return Promise.all(e.map(e=>e()));let n=Array.from({length:e.length}),r=0;async function i(){for(;r<e.length;){let t=r++;e[t]&&(n[t]=await e[t]())}}return await Promise.all(Array.from({length:t},i)),n}const Oe=`0x0000000000000000000000000000000000000000000000000000000000000000`;var ke=class e{credentials;delegatedCredentials;relayer;signer;address;storage;#e;constructor(e){let t={relayer:e.relayer,signer:e.signer,storage:e.storage,sessionStorage:e.sessionStorage,keypairTTL:e.keypairTTL??86400,sessionTTL:e.sessionTTL??2592e3,onEvent:e.onEvent};this.credentials=e.credentials??new I(t),this.delegatedCredentials=e.delegatedCredentials??new L(t),this.relayer=e.relayer,this.signer=e.signer,this.address=v(e.address),this.storage=e.storage,this.#e=e.onEvent}emit(e){this.#e?.({...e,tokenAddress:this.address,timestamp:Date.now()})}async balanceOf(e){let t=e?v(e):await this.signer.getAddress(),n=await this.readConfidentialBalanceOf(t);return this.decryptBalance(n,t)}async confidentialBalanceOf(e){let t=e?v(e):await this.signer.getAddress();return this.readConfidentialBalanceOf(t)}async isConfidential(){return await this.signer.readContract(m(this.address,p))}async isWrapper(){return await this.signer.readContract(m(this.address,h))}static async batchDecryptBalances(t,n){if(t.length===0)return new Map;let{handles:r,owner:i,onError:a,maxConcurrency:o}=n??{},s=t[0],c=e.assertSameRelayer(t),l=i??await s.signer.getAddress();return e.#t({tokens:t,handles:r,ownerAddress:l,onError:a,maxConcurrency:o,obtainCreds:e=>s.credentials.allow(...e),decrypt:(e,t,n)=>c.userDecrypt({handles:[t],contractAddress:n,signedContractAddresses:e.contractAddresses,privateKey:e.privateKey,publicKey:e.publicKey,signature:e.signature,signerAddress:l,startTimestamp:e.startTimestamp,durationDays:e.durationDays}),errorPrefix:`Batch decryption`})}static async batchDecryptBalancesAs(t,n){if(t.length===0)return new Map;let{delegatorAddress:r,handles:i,owner:a,onError:o,maxConcurrency:s}=n,c=a??r,l=t[0];return e.assertSameRelayer(t),e.#t({tokens:t,handles:i,ownerAddress:c,onError:o,maxConcurrency:s,preFlightCheck:()=>l.#n(r),obtainCreds:e=>l.delegatedCredentials.allow(r,...e),decrypt:(e,t,n)=>l.relayer.delegatedUserDecrypt({handles:[t],contractAddress:n,signedContractAddresses:e.contractAddresses,privateKey:e.privateKey,publicKey:e.publicKey,signature:e.signature,delegatorAddress:e.delegatorAddress,delegateAddress:e.delegateAddress,startTimestamp:e.startTimestamp,durationDays:e.durationDays}),errorPrefix:`Batch delegated decryption`})}static async#t(e){let{tokens:t,handles:n,ownerAddress:r,onError:o,maxConcurrency:s,obtainCreds:c,decrypt:l,errorPrefix:u}=e,d=t[0],f=n??await Promise.all(t.map(e=>e.readConfidentialBalanceOf(r)));if(t.length!==f.length)throw new i(`tokens.length (${t.length}) must equal handles.length (${f.length})`);let p=d.storage,m=new Map,h=[],g=await Promise.all(t.map((e,t)=>{let n=f[t];return e.isZeroHandle(n)?0n:R({storage:p,tokenAddress:e.address,owner:r,handle:n})}));for(let e=0;e<t.length;e++){let n=t[e],r=f[e],i=g[e];if(i!=null){m.set(n.address,i);continue}h.push({token:n,handle:r})}if(h.length===0)return m;e.preFlightCheck&&await e.preFlightCheck();let _=await c(h.map(e=>e.token.address)),v=[],y=[];for(let{token:e,handle:t}of h)y.push(()=>l(_,t,e.address).then(async n=>{let a=n[t];if(a===void 0)throw new i(`${u} returned no value for handle ${t} on token ${e.address}`);m.set(e.address,a);try{await z({storage:p,tokenAddress:e.address,owner:r,handle:t,value:a})}catch(e){console.warn(`[zama-sdk] Cache write failed (non-blocking):`,e)}}).catch(t=>{let n=a(t);if(o)try{m.set(e.address,o(n,e.address))}catch(t){v.push({address:e.address,error:a(t)})}else v.push({address:e.address,error:n})}));if(await De(y,s),v.length>0){let e=v.map(e=>`${e.address}: ${e.error.message}`).join(`; `);throw new i(`${u} failed for ${v.length} token(s): ${e}`)}return m}async underlyingToken(){return this.signer.readContract(g(this.address))}async allowance(e,t){let n=v(e),r=await this.signer.readContract(g(n)),i=t?v(t):await this.signer.getAddress();return this.signer.readContract(ue(r,i,n))}async name(){return this.signer.readContract(ae(this.address))}async symbol(){return this.signer.readContract(oe(this.address))}async decimals(){return this.signer.readContract(se(this.address))}async allow(){await this.credentials.allow(this.address)}async isAllowed(){return this.credentials.isAllowed()}async revoke(...e){await this.credentials.revoke(...e)}static async allow(...e){if(e.length===0)return;let t=e.map(e=>e.address);await e[0].credentials.allow(...t)}async getAclAddress(){return this.relayer.getAclAddress()}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===D?!0:t>await this.signer.getBlockTimestamp()}async getDelegationExpiry({delegatorAddress:e,delegateAddress:t}){let n=await this.getAclAddress();return this.signer.readContract(ve(n,v(e),v(t),this.address))}async#n(e){let t=await this.signer.getAddress(),n=await this.getDelegationExpiry({delegatorAddress:e,delegateAddress:t});if(n===0n)throw new C(`No active delegation from ${e} to ${t} for ${this.address}`);if(n!==D&&n<=await this.signer.getBlockTimestamp())throw new w(`Delegation from ${e} to ${t} for ${this.address} has expired`)}async readConfidentialBalanceOf(e){return await this.signer.readContract(f(this.address,e))}isZeroHandle(e){return e===`0x0000000000000000000000000000000000000000000000000000000000000000`||e===`0x`}async decryptBalanceAs({delegatorAddress:e,owner:t}){let n=v(e),r=t?v(t):n,o=await this.readConfidentialBalanceOf(r);if(this.isZeroHandle(o))return 0n;let s=await R({storage:this.storage,tokenAddress:this.address,owner:r,handle:o});if(s!==null)return s;await this.#n(n);let c=Date.now();try{this.emit({type:O.DecryptStart});let e=await this.delegatedCredentials.allow(n,this.address),t=await this.relayer.delegatedUserDecrypt({handles:[o],contractAddress:this.address,signedContractAddresses:e.contractAddresses,privateKey:e.privateKey,publicKey:e.publicKey,signature:e.signature,delegatorAddress:e.delegatorAddress,delegateAddress:e.delegateAddress,startTimestamp:e.startTimestamp,durationDays:e.durationDays});this.emit({type:O.DecryptEnd,durationMs:Date.now()-c});let a=t[o];if(a===void 0)throw new i(`Delegated decryption returned no value for handle ${o}`);try{await z({storage:this.storage,tokenAddress:this.address,owner:r,handle:o,value:a})}catch(e){console.warn(`[zama-sdk] Cache write failed (non-blocking):`,e)}return a}catch(e){throw this.emit({type:O.DecryptError,error:a(e),durationMs:Date.now()-c}),B(e,`Failed to decrypt delegated balance`)}}async decryptBalance(e,t){if(this.isZeroHandle(e))return 0n;let n=t??await this.signer.getAddress(),r=await R({storage:this.storage,tokenAddress:this.address,owner:n,handle:e});if(r!==null)return r;let o=await this.credentials.allow(this.address),s=Date.now();try{this.emit({type:O.DecryptStart});let t=await this.relayer.userDecrypt({handles:[e],contractAddress:this.address,signedContractAddresses:o.contractAddresses,privateKey:o.privateKey,publicKey:o.publicKey,signature:o.signature,signerAddress:n,startTimestamp:o.startTimestamp,durationDays:o.durationDays});this.emit({type:O.DecryptEnd,durationMs:Date.now()-s});let r=t[e];if(r===void 0)throw new i(`Decryption returned no value for handle ${e}`);try{await z({storage:this.storage,tokenAddress:this.address,owner:n,handle:e,value:r})}catch(e){console.warn(`[zama-sdk] Cache write failed (non-blocking):`,e)}return r}catch(e){throw this.emit({type:O.DecryptError,error:a(e),durationMs:Date.now()-s}),B(e,`Failed to decrypt balance`)}}async decryptHandles(e,t){let n=new Map,r=[];for(let t of e)this.isZeroHandle(t)?n.set(t,0n):r.push(t);if(r.length===0)return n;let o=await this.credentials.allow(this.address),s=Date.now();try{this.emit({type:O.DecryptStart});let e=await this.relayer.userDecrypt({handles:r,contractAddress:this.address,signedContractAddresses:o.contractAddresses,privateKey:o.privateKey,publicKey:o.publicKey,signature:o.signature,signerAddress:t??await this.signer.getAddress(),startTimestamp:o.startTimestamp,durationDays:o.durationDays});this.emit({type:O.DecryptEnd,durationMs:Date.now()-s});for(let t of r){let r=e[t];if(r===void 0)throw new i(`Decryption returned no value for handle ${t}`);n.set(t,r)}}catch(e){throw this.emit({type:O.DecryptError,error:a(e),durationMs:Date.now()-s}),B(e,`Failed to decrypt handles`)}return n}static assertSameRelayer(e){let t=e[0].relayer;for(let n=1;n<e.length;n++)if(e[n].relayer!==t)throw new r(`All tokens in a batch operation must share the same relayer instance`);return t}};function B(e,n){if(e instanceof i||e instanceof S||e instanceof t||e instanceof b||e instanceof x)return e;let r=typeof e==`object`&&e&&`statusCode`in e&&typeof e.statusCode==`number`?e.statusCode:void 0;return r===400?new S(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):r===void 0?new i(n,{cause:e}):new t(e instanceof Error?e.message:n,r,{cause:e})}const V={ConfidentialTransfer:`0x67500e8d0ed826d2194f514dd0d8124f35648ab6e3fb5e6ed867134cffe661e9`,Wrapped:`0x1f7907f4d84043abe0fb7c74e8865ee5fe93fe4f691c54a7b8fa9d6fb17c7cba`,UnwrapRequested:`0x77d02d353c5629272875d11f1b34ec4c65d7430b075575b78cd2502034c469ee`,UnwrappedFinalized:`0xc64e7c81b18b674fc5b037d8a0041bfe3332d86c780a4688f404ee01fbabb152`,UnwrappedStarted:`0x3838891d4843c6d7f9f494570b6fd8843f4e3c3ddb817c1411760bd31b819806`};function H(e){return v(d(e.slice(-40)))}function U(e){return BigInt(e)}function Ae(e){return e}function W(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function je(e,t){return v(d(W(e,t).slice(-40)))}function G(e,t){return BigInt(`0x`+W(e,t))}function K(e,t){return BigInt(`0x`+W(e,t))!==0n}function q(e,t){return d(W(e,t))}function Me(e){return e.topics[0]!==V.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:H(e.topics[1]),to:H(e.topics[2]),encryptedAmountHandle:Ae(e.topics[3])}}function J(e){return e.topics[0]!==V.Wrapped||e.topics.length<3?null:{eventName:`Wrapped`,to:H(e.topics[1]),mintTxId:U(e.topics[2]),mintAmount:G(e.data,0),amountIn:G(e.data,1),feeAmount:G(e.data,2)}}function Y(e){return e.topics[0]!==V.UnwrapRequested||e.topics.length<2?null:{eventName:`UnwrapRequested`,receiver:H(e.topics[1]),encryptedAmount:q(e.data,0)}}function Ne(e){return e.topics[0]!==V.UnwrappedFinalized||e.topics.length<3?null:{eventName:`UnwrappedFinalized`,burntAmountHandle:Ae(e.topics[1]),nextTxId:U(e.topics[2]),finalizeSuccess:K(e.data,0),feeTransferSuccess:K(e.data,1),burnAmount:G(e.data,2),unwrapAmount:G(e.data,3),feeAmount:G(e.data,4)}}function X(e){return e.topics[0]!==V.UnwrappedStarted||e.topics.length<4?null:{eventName:`UnwrappedStarted`,requestId:U(e.topics[1]),txId:U(e.topics[2]),to:H(e.topics[3]),returnVal:K(e.data,0),refund:je(e.data,1),requestedAmount:q(e.data,2),burnAmount:q(e.data,3)}}function Z(e){return Me(e)??J(e)??Y(e)??Ne(e)??X(e)}function Pe(e){let t=[];for(let n of e){let e=Z(n);e&&t.push(e)}return t}function Fe(e){for(let t of e){let e=Y(t);if(e)return e}return null}function Ie(e){for(let t of e){let e=J(t);if(e)return e}return null}const Le=[V.ConfidentialTransfer,V.Wrapped,V.UnwrapRequested,V.UnwrappedFinalized,V.UnwrappedStarted];function Q(e,t){return e.toLowerCase()===t.toLowerCase()}function $(e,t,n){let r=t!==void 0&&Q(e,t),i=n!==void 0&&Q(e,n);return r&&i?`self`:r?`outgoing`:`incoming`}function Re(e,t,n){switch(e.eventName){case`ConfidentialTransfer`:return ze(e,t,n);case`Wrapped`:return Be(e,t,n);case`UnwrapRequested`:return Ve(e,t,n);case`UnwrappedStarted`:return He(e,t,n);case`UnwrappedFinalized`:return Ue(e,n)}}function ze(e,t,n){return{type:`transfer`,direction:$(t,e.from,e.to),amount:{type:`encrypted`,handle:e.encryptedAmountHandle},from:e.from,to:e.to,metadata:n,rawEvent:e}}function Be(e,t,n){return{type:`shield`,direction:$(t,void 0,e.to),amount:{type:`clear`,value:e.amountIn},to:e.to,fee:e.feeAmount,metadata:n,rawEvent:e}}function Ve(e,t,n){return{type:`unshield_requested`,direction:$(t,void 0,e.receiver),amount:{type:`encrypted`,handle:e.encryptedAmount},to:e.receiver,metadata:n,rawEvent:e}}function He(e,t,n){return{type:`unshield_started`,direction:$(t,void 0,e.to),amount:{type:`encrypted`,handle:e.requestedAmount},to:e.to,success:e.returnVal,metadata:n,rawEvent:e}}function Ue(e,t){return{type:`unshield_finalized`,direction:`incoming`,amount:{type:`clear`,value:e.unwrapAmount},fee:e.feeAmount,success:e.finalizeSuccess,metadata:t,rawEvent:e}}function We(e,t){let n=[];for(let r of e){let e=Z(r);if(!e)continue;let i={transactionHash:r.transactionHash,blockNumber:r.blockNumber,logIndex:r.logIndex};n.push(Re(e,t,i))}return n}function Ge(e){let t=new Set;for(let n of e)if(n.amount.type===`encrypted`&&n.amount.decryptedValue===void 0){let e=n.amount.handle;e!==`0x`&&e!==`0x0000000000000000000000000000000000000000000000000000000000000000`&&t.add(e)}return[...t]}function Ke(e,t){return e.map(e=>{if(e.amount.type!==`encrypted`)return e;let n=t.get(e.amount.handle);return n===void 0?e:{...e,amount:{type:`encrypted`,handle:e.amount.handle,decryptedValue:n}}})}function qe(e){return[...e].toSorted((e,t)=>{let n=e.metadata.blockNumber,r=t.metadata.blockNumber;if(n===void 0&&r===void 0)return 0;if(n===void 0)return-1;if(r===void 0)return 1;let i=typeof n==`bigint`?n:BigInt(n),a=typeof r==`bigint`?r:BigInt(r);if(a>i)return 1;if(a<i)return-1;let o=e.metadata.logIndex??0;return(t.metadata.logIndex??0)-o})}export{de as A,ne as B,ve as C,pe as D,he as E,oe as F,S as H,ie as I,w as L,se as M,ce as N,fe as O,ae as P,C as R,ge as S,me as T,x as U,te as V,b as W,Oe as _,Le as a,O as b,Z as c,Ne as d,X as f,ke as g,Ie as h,qe as i,le as j,ue as k,Pe as l,Fe as m,Ge as n,V as o,J as p,We as r,Me as s,Ke as t,Y as u,L as v,_e as w,D as x,I as y,re as z};
|
|
2
|
+
//# sourceMappingURL=activity-ChJnF5yd.js.map
|