@moon-x/core 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-527SU2F6.mjs +6 -0
- package/dist/{chunk-I56GRKAG.mjs → chunk-W6BYGZ2F.mjs} +218 -65
- package/dist/{chunk-KRZVIDBQ.mjs → chunk-Z57WM6IO.mjs} +16 -9
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +21 -9
- package/dist/index.mjs +5 -2
- package/dist/{interfaces-CF5UrEBb.d.mts → interfaces-Bt5CAMSt.d.mts} +1 -1
- package/dist/{interfaces-B5zxo2Jx.d.ts → interfaces-pGbKBjWD.d.ts} +1 -1
- package/dist/lib/index.d.mts +133 -51
- package/dist/lib/index.d.ts +133 -51
- package/dist/lib/index.js +228 -67
- package/dist/lib/index.mjs +21 -5
- package/dist/{post-message-2NAnU0Lf.d.mts → post-message-BR2NClJ5.d.mts} +4 -1
- package/dist/{post-message-2NAnU0Lf.d.ts → post-message-BR2NClJ5.d.ts} +4 -1
- package/dist/react/index.mjs +1 -1
- package/dist/sdk/index.d.mts +3 -3
- package/dist/sdk/index.d.ts +3 -3
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/index.mjs +3 -2
- package/dist/types/index.d.mts +204 -76
- package/dist/types/index.d.ts +204 -76
- package/dist/utils/index.d.mts +14 -2
- package/dist/utils/index.d.ts +14 -2
- package/dist/utils/index.js +21 -9
- package/dist/utils/index.mjs +5 -2
- package/dist/web/index.d.mts +2 -2
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +16 -9
- package/dist/web/index.mjs +1 -1
- package/package.json +4 -3
- package/dist/chunk-CMYR6AOY.mjs +0 -0
|
@@ -276,18 +276,6 @@ function resolvePasskeyMetadata(input) {
|
|
|
276
276
|
|
|
277
277
|
// src/lib/ethereum/chains.ts
|
|
278
278
|
import { formatEther, parseEther } from "viem";
|
|
279
|
-
function setChainRpcUrl(chain, rpcUrl) {
|
|
280
|
-
return {
|
|
281
|
-
...chain,
|
|
282
|
-
rpcUrls: {
|
|
283
|
-
...chain.rpcUrls,
|
|
284
|
-
default: {
|
|
285
|
-
http: [rpcUrl],
|
|
286
|
-
webSocket: chain.rpcUrls.default.webSocket
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
279
|
function getRpcUrl(chain) {
|
|
292
280
|
return chain.rpcUrls.default.http[0];
|
|
293
281
|
}
|
|
@@ -420,35 +408,152 @@ async function estimateEvmGasReserve(rpcUrl, chainId, opts = {}) {
|
|
|
420
408
|
return Number(formatEther(reserveWei));
|
|
421
409
|
}
|
|
422
410
|
function getChainById(chains, chainId) {
|
|
423
|
-
|
|
411
|
+
for (const item of chains) {
|
|
412
|
+
const entry = normalizeChainItem(item);
|
|
413
|
+
if (isEvmEntry(entry) && entry.chain.id === chainId) return entry.chain;
|
|
414
|
+
}
|
|
415
|
+
return void 0;
|
|
424
416
|
}
|
|
425
417
|
function isChainSupported(chains, chainId) {
|
|
426
|
-
return chains
|
|
418
|
+
return getChainById(chains, chainId) !== void 0;
|
|
427
419
|
}
|
|
428
|
-
function
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
420
|
+
function isEvmEntry(entry) {
|
|
421
|
+
return "chain" in entry;
|
|
422
|
+
}
|
|
423
|
+
function normalizeChainItem(item) {
|
|
424
|
+
if ("chain" in item) return item;
|
|
425
|
+
if (typeof item.id === "number") {
|
|
426
|
+
return { chain: item };
|
|
432
427
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
428
|
+
return item;
|
|
429
|
+
}
|
|
430
|
+
function entryCaip2(entry) {
|
|
431
|
+
return isEvmEntry(entry) ? `eip155:${entry.chain.id}` : entry.id;
|
|
432
|
+
}
|
|
433
|
+
function slug(s) {
|
|
434
|
+
return s.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
435
|
+
}
|
|
436
|
+
function aliasesFor(entry) {
|
|
437
|
+
const keys = [];
|
|
438
|
+
if (isEvmEntry(entry)) {
|
|
439
|
+
const { chain } = entry;
|
|
440
|
+
keys.push(`eip155:${chain.id}`, String(chain.id));
|
|
441
|
+
if (chain.name) {
|
|
442
|
+
const s = slug(chain.name);
|
|
443
|
+
keys.push(`eth:${s}`, s);
|
|
444
|
+
}
|
|
445
|
+
if (chain.network) {
|
|
446
|
+
const s = slug(chain.network);
|
|
447
|
+
keys.push(`eth:${s}`, s);
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
keys.push(entry.id);
|
|
451
|
+
const cluster = entry.id.split(":")[1];
|
|
452
|
+
if (cluster) keys.push(`solana:${cluster}`, `sol:${cluster}`, cluster);
|
|
453
|
+
}
|
|
454
|
+
return keys;
|
|
455
|
+
}
|
|
456
|
+
function normalizeChainKey(key) {
|
|
457
|
+
if (typeof key === "number") return `eip155:${key}`;
|
|
458
|
+
if (typeof key === "string") return key.trim().toLowerCase();
|
|
459
|
+
const id = key?.id;
|
|
460
|
+
throw new Error(
|
|
461
|
+
typeof id === "number" ? `Invalid chain reference: expected an alias, CAIP-2 id, or numeric chainId, but got a chain object. Use "eip155:${id}" or ${id}.` : `Invalid chain reference: expected a string alias / CAIP-2 id or a numeric chainId, got ${typeof key}.`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
function buildChainIndex(chains = []) {
|
|
465
|
+
const entries = chains.map(normalizeChainItem);
|
|
466
|
+
const byAlias = /* @__PURE__ */ new Map();
|
|
467
|
+
for (const entry of entries) {
|
|
468
|
+
for (const alias of aliasesFor(entry)) {
|
|
469
|
+
const key = alias.toLowerCase();
|
|
470
|
+
if (!byAlias.has(key)) byAlias.set(key, entry);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return { entries, byAlias };
|
|
474
|
+
}
|
|
475
|
+
function resolveChainEntry(chains, selector, defaultSelector) {
|
|
476
|
+
const index = buildChainIndex(chains ?? []);
|
|
477
|
+
if (selector != null) {
|
|
478
|
+
return index.byAlias.get(normalizeChainKey(selector));
|
|
479
|
+
}
|
|
480
|
+
if (defaultSelector != null) {
|
|
481
|
+
const fallback = index.byAlias.get(normalizeChainKey(defaultSelector));
|
|
482
|
+
if (fallback) return fallback;
|
|
483
|
+
}
|
|
484
|
+
return index.entries[0];
|
|
485
|
+
}
|
|
486
|
+
function resolveSolanaChainEntry(chains, selector, defaultSelector) {
|
|
487
|
+
const index = buildChainIndex(chains ?? []);
|
|
488
|
+
const asSolana = (k) => {
|
|
489
|
+
if (k == null) return void 0;
|
|
490
|
+
const e = index.byAlias.get(normalizeChainKey(k));
|
|
491
|
+
return e && !isEvmEntry(e) ? e : void 0;
|
|
492
|
+
};
|
|
493
|
+
if (selector != null) return asSolana(selector);
|
|
494
|
+
return asSolana(defaultSelector) ?? index.entries.find((e) => !isEvmEntry(e));
|
|
495
|
+
}
|
|
496
|
+
function resolveEvmChainEntry(opts) {
|
|
497
|
+
const index = buildChainIndex(opts.chains ?? []);
|
|
498
|
+
const lookup = (k) => {
|
|
499
|
+
if (k == null) return void 0;
|
|
500
|
+
const e = index.byAlias.get(normalizeChainKey(k));
|
|
501
|
+
return e && isEvmEntry(e) ? e : void 0;
|
|
502
|
+
};
|
|
503
|
+
if (opts.selector != null) return lookup(opts.selector);
|
|
504
|
+
if (opts.requestedChainId != null) return lookup(opts.requestedChainId);
|
|
505
|
+
return lookup(opts.walletChainId) ?? lookup(opts.defaultSelector) ?? index.entries.find(isEvmEntry);
|
|
506
|
+
}
|
|
507
|
+
function resolveRpcUrl(entry, override) {
|
|
508
|
+
if (override) return override;
|
|
509
|
+
if (isEvmEntry(entry)) return entry.rpcUrl ?? getRpcUrl(entry.chain);
|
|
510
|
+
return entry.rpcUrl;
|
|
511
|
+
}
|
|
512
|
+
function resolveWsUrl(entry, override) {
|
|
513
|
+
if (override) return override;
|
|
514
|
+
if (isEvmEntry(entry)) {
|
|
515
|
+
return entry.wsUrl ?? entry.chain.rpcUrls.default.webSocket?.[0];
|
|
516
|
+
}
|
|
517
|
+
return entry.wsUrl;
|
|
518
|
+
}
|
|
519
|
+
function validateChainConfig(config) {
|
|
520
|
+
const { chains, defaultChain } = config;
|
|
521
|
+
if (defaultChain != null) {
|
|
522
|
+
if (typeof defaultChain !== "string" && typeof defaultChain !== "number") {
|
|
523
|
+
const id = defaultChain.id;
|
|
524
|
+
throw new Error(
|
|
525
|
+
`defaultChain must be a chain reference (alias, CAIP-2 id, or numeric chainId), not a chain object.${typeof id === "number" ? ` Use "eip155:${id}" or ${id}.` : ""}`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
if (!chains || chains.length === 0) {
|
|
438
529
|
throw new Error(
|
|
439
|
-
`defaultChain
|
|
530
|
+
`defaultChain "${defaultChain}" is set but no \`chains\` are configured. Add the chain to \`chains\`, or remove \`defaultChain\`.`
|
|
440
531
|
);
|
|
441
532
|
}
|
|
442
533
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return config.defaultChain;
|
|
534
|
+
if (!chains) return;
|
|
535
|
+
if (chains.length === 0) {
|
|
536
|
+
throw new Error("chains cannot be an empty array");
|
|
447
537
|
}
|
|
448
|
-
|
|
449
|
-
|
|
538
|
+
const index = buildChainIndex(chains);
|
|
539
|
+
const seen = /* @__PURE__ */ new Set();
|
|
540
|
+
for (const entry of index.entries) {
|
|
541
|
+
const id = entryCaip2(entry);
|
|
542
|
+
if (seen.has(id)) {
|
|
543
|
+
throw new Error(`Duplicate chain in config: ${id}`);
|
|
544
|
+
}
|
|
545
|
+
seen.add(id);
|
|
546
|
+
if (!isEvmEntry(entry) && !entry.rpcUrl) {
|
|
547
|
+
throw new Error(`Solana chain "${entry.id}" is missing an rpcUrl`);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (defaultChain != null && !index.byAlias.get(normalizeChainKey(defaultChain))) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
`defaultChain "${defaultChain}" is not in the configured chains (${[
|
|
553
|
+
...seen
|
|
554
|
+
].join(", ")})`
|
|
555
|
+
);
|
|
450
556
|
}
|
|
451
|
-
return void 0;
|
|
452
557
|
}
|
|
453
558
|
|
|
454
559
|
// src/lib/ethereum/siwe.ts
|
|
@@ -511,7 +616,7 @@ function createManualSiweMessage({
|
|
|
511
616
|
let siweMessage = `${domain} wants you to sign in with your Ethereum account:
|
|
512
617
|
`;
|
|
513
618
|
siweMessage += `${checksummedAddress}`;
|
|
514
|
-
const defaultStatement = `Sign in with Ethereum to
|
|
619
|
+
const defaultStatement = `Sign in with Ethereum to MoonX using ${walletName}.`;
|
|
515
620
|
siweMessage += `
|
|
516
621
|
|
|
517
622
|
${statement || defaultStatement}`;
|
|
@@ -529,54 +634,91 @@ ${fields.join("\n")}`;
|
|
|
529
634
|
|
|
530
635
|
// src/lib/ethereum/tx-prep.ts
|
|
531
636
|
import { parseEther as parseEther2, parseGwei, serializeTransaction } from "viem";
|
|
637
|
+
function syntheticChain(chainId, rpcUrl) {
|
|
638
|
+
return {
|
|
639
|
+
id: chainId,
|
|
640
|
+
name: `chain-${chainId}`,
|
|
641
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
642
|
+
rpcUrls: { default: { http: [rpcUrl] } }
|
|
643
|
+
};
|
|
644
|
+
}
|
|
532
645
|
function resolveEvmChain({
|
|
646
|
+
chains,
|
|
647
|
+
chainSelector,
|
|
533
648
|
requestedChainId,
|
|
534
649
|
walletChainId,
|
|
535
|
-
supportedChains,
|
|
536
650
|
defaultChain,
|
|
651
|
+
rpcUrlOverride,
|
|
537
652
|
strict = false
|
|
538
653
|
}) {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
654
|
+
if (chainSelector != null) {
|
|
655
|
+
const entry2 = resolveEvmChainEntry({ chains, selector: chainSelector });
|
|
656
|
+
if (!entry2) {
|
|
657
|
+
throw new Error(
|
|
658
|
+
`chain "${chainSelector}" is not in the configured chains.`
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return { chain: entry2.chain, rpcUrl: resolveRpcUrl(entry2, rpcUrlOverride) };
|
|
545
662
|
}
|
|
546
|
-
if (
|
|
547
|
-
|
|
663
|
+
if (requestedChainId != null) {
|
|
664
|
+
const entry2 = resolveEvmChainEntry({ chains, requestedChainId });
|
|
665
|
+
if (entry2) {
|
|
666
|
+
return {
|
|
667
|
+
chain: entry2.chain,
|
|
668
|
+
rpcUrl: resolveRpcUrl(entry2, rpcUrlOverride)
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
if (rpcUrlOverride) {
|
|
672
|
+
return {
|
|
673
|
+
chain: syntheticChain(Number(requestedChainId), rpcUrlOverride),
|
|
674
|
+
rpcUrl: rpcUrlOverride
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
if (strict) {
|
|
678
|
+
throw new Error(
|
|
679
|
+
`Requested chainId ${requestedChainId} is not in the configured chains.`
|
|
680
|
+
);
|
|
681
|
+
}
|
|
548
682
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
683
|
+
const entry = resolveEvmChainEntry({
|
|
684
|
+
chains,
|
|
685
|
+
walletChainId,
|
|
686
|
+
defaultSelector: defaultChain
|
|
687
|
+
});
|
|
688
|
+
if (entry) {
|
|
689
|
+
return { chain: entry.chain, rpcUrl: resolveRpcUrl(entry, rpcUrlOverride) };
|
|
553
690
|
}
|
|
554
|
-
if (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
691
|
+
if (rpcUrlOverride && requestedChainId != null) {
|
|
692
|
+
return {
|
|
693
|
+
chain: syntheticChain(Number(requestedChainId), rpcUrlOverride),
|
|
694
|
+
rpcUrl: rpcUrlOverride
|
|
695
|
+
};
|
|
558
696
|
}
|
|
559
|
-
|
|
697
|
+
throw new Error(
|
|
698
|
+
"No chain configured. Set `chains` (and optionally `defaultChain`) in MoonKeyProvider config, or pass an `rpcUrl` together with the transaction's `chainId`."
|
|
699
|
+
);
|
|
560
700
|
}
|
|
561
701
|
async function prepareEvmSignTransaction({
|
|
562
702
|
transaction,
|
|
563
703
|
wallet,
|
|
564
|
-
|
|
565
|
-
defaultChain
|
|
704
|
+
chains,
|
|
705
|
+
defaultChain,
|
|
706
|
+
chainSelector
|
|
566
707
|
}) {
|
|
567
708
|
if (typeof transaction === "string") {
|
|
568
709
|
return { serializedTransaction: transaction, chain: void 0 };
|
|
569
710
|
}
|
|
570
711
|
const txObj = transaction;
|
|
571
712
|
const transactionType = txObj.type ?? 2;
|
|
572
|
-
const chain = resolveEvmChain({
|
|
713
|
+
const { chain } = resolveEvmChain({
|
|
714
|
+
chains,
|
|
715
|
+
chainSelector,
|
|
573
716
|
requestedChainId: txObj.chainId,
|
|
574
717
|
walletChainId: wallet.chainId,
|
|
575
|
-
supportedChains,
|
|
576
718
|
defaultChain,
|
|
577
719
|
strict: false
|
|
578
720
|
});
|
|
579
|
-
const derivedChainId = txObj.chainId || chain.id;
|
|
721
|
+
const derivedChainId = chainSelector != null ? chain.id : txObj.chainId || chain.id;
|
|
580
722
|
const formattedTransaction = {
|
|
581
723
|
to: txObj.to,
|
|
582
724
|
value: txObj.value ? typeof txObj.value === "bigint" ? txObj.value : parseEther2(txObj.value.toString()) : BigInt(0),
|
|
@@ -608,17 +750,20 @@ async function prepareEvmSignTransaction({
|
|
|
608
750
|
async function prepareEvmSendTransaction({
|
|
609
751
|
transaction,
|
|
610
752
|
wallet,
|
|
611
|
-
|
|
612
|
-
defaultChain
|
|
753
|
+
chains,
|
|
754
|
+
defaultChain,
|
|
755
|
+
chainSelector,
|
|
756
|
+
rpcUrlOverride
|
|
613
757
|
}) {
|
|
614
|
-
const chain = resolveEvmChain({
|
|
758
|
+
const { chain, rpcUrl } = resolveEvmChain({
|
|
759
|
+
chains,
|
|
760
|
+
chainSelector,
|
|
615
761
|
requestedChainId: transaction.chainId,
|
|
616
762
|
walletChainId: wallet.chainId,
|
|
617
|
-
supportedChains,
|
|
618
763
|
defaultChain,
|
|
764
|
+
rpcUrlOverride,
|
|
619
765
|
strict: true
|
|
620
766
|
});
|
|
621
|
-
const rpcUrl = getRpcUrl(chain);
|
|
622
767
|
if (!rpcUrl) {
|
|
623
768
|
throw new Error(
|
|
624
769
|
`No RPC URL found for chain ${chain.name}. Chain may be missing rpcUrls configuration.`
|
|
@@ -1285,12 +1430,12 @@ async function getSOLTransfersFromInstructions(base64Transaction, logs, solPrice
|
|
|
1285
1430
|
// src/lib/build-url.ts
|
|
1286
1431
|
var buildUrl = (baseUrl, sdkConfig, enableCaptcha, captchaSitekey) => {
|
|
1287
1432
|
if (!sdkConfig.publishableKey) {
|
|
1288
|
-
throw new Error("
|
|
1433
|
+
throw new Error("MoonX SDK Error: Publishable Key is required");
|
|
1289
1434
|
}
|
|
1290
1435
|
if (!baseUrl || typeof baseUrl !== "string" || baseUrl === "null" || baseUrl === "undefined") {
|
|
1291
1436
|
console.error("Invalid baseUrl:", baseUrl);
|
|
1292
1437
|
throw new Error(
|
|
1293
|
-
`
|
|
1438
|
+
`MoonX SDK Error: Invalid base URL provided: "${baseUrl}"`
|
|
1294
1439
|
);
|
|
1295
1440
|
}
|
|
1296
1441
|
if (typeof window === "undefined") {
|
|
@@ -1324,7 +1469,7 @@ var buildUrl = (baseUrl, sdkConfig, enableCaptcha, captchaSitekey) => {
|
|
|
1324
1469
|
return url.toString();
|
|
1325
1470
|
} catch (error) {
|
|
1326
1471
|
throw new Error(
|
|
1327
|
-
`
|
|
1472
|
+
`MoonX SDK Error: Invalid base URL "${baseUrl}": ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1328
1473
|
);
|
|
1329
1474
|
}
|
|
1330
1475
|
};
|
|
@@ -1479,7 +1624,6 @@ export {
|
|
|
1479
1624
|
generatePasskeyUserId,
|
|
1480
1625
|
formatPasskeyLabel,
|
|
1481
1626
|
resolvePasskeyMetadata,
|
|
1482
|
-
setChainRpcUrl,
|
|
1483
1627
|
getRpcUrl,
|
|
1484
1628
|
getEvmMaxPriorityFeePerGas,
|
|
1485
1629
|
getEvmGasPrice,
|
|
@@ -1488,8 +1632,17 @@ export {
|
|
|
1488
1632
|
estimateEvmGasReserve,
|
|
1489
1633
|
getChainById,
|
|
1490
1634
|
isChainSupported,
|
|
1635
|
+
isEvmEntry,
|
|
1636
|
+
normalizeChainItem,
|
|
1637
|
+
entryCaip2,
|
|
1638
|
+
normalizeChainKey,
|
|
1639
|
+
buildChainIndex,
|
|
1640
|
+
resolveChainEntry,
|
|
1641
|
+
resolveSolanaChainEntry,
|
|
1642
|
+
resolveEvmChainEntry,
|
|
1643
|
+
resolveRpcUrl,
|
|
1644
|
+
resolveWsUrl,
|
|
1491
1645
|
validateChainConfig,
|
|
1492
|
-
getDefaultChain,
|
|
1493
1646
|
EthereumSiweMessage,
|
|
1494
1647
|
createManualSiweMessage,
|
|
1495
1648
|
resolveEvmChain,
|
|
@@ -200,12 +200,13 @@ var PostMessageServer = class {
|
|
|
200
200
|
if (queued?.length) {
|
|
201
201
|
this.pending.delete(key);
|
|
202
202
|
const now = Date.now();
|
|
203
|
-
for (const { request, reply, at } of queued) {
|
|
203
|
+
for (const { request, reply, at, ctx } of queued) {
|
|
204
204
|
if (now - at < QUEUE_TTL_MS) {
|
|
205
205
|
void this.invokeHandler(
|
|
206
206
|
handler,
|
|
207
207
|
request,
|
|
208
|
-
reply
|
|
208
|
+
reply,
|
|
209
|
+
ctx
|
|
209
210
|
);
|
|
210
211
|
}
|
|
211
212
|
}
|
|
@@ -257,7 +258,7 @@ var PostMessageServer = class {
|
|
|
257
258
|
id: request.id,
|
|
258
259
|
type: request.type,
|
|
259
260
|
success: false,
|
|
260
|
-
error: `Origin ${event.origin} is not whitelisted. Please add it to your
|
|
261
|
+
error: `Origin ${event.origin} is not whitelisted. Please add it to your MoonX dashboard.`
|
|
261
262
|
});
|
|
262
263
|
return;
|
|
263
264
|
}
|
|
@@ -274,14 +275,20 @@ var PostMessageServer = class {
|
|
|
274
275
|
const key = `${request.type}:${request.method}`;
|
|
275
276
|
const handler = this.handlers.get(key);
|
|
276
277
|
if (handler) {
|
|
277
|
-
await this.invokeHandler(handler, request, reply
|
|
278
|
+
await this.invokeHandler(handler, request, reply, {
|
|
279
|
+
origin: event.origin,
|
|
280
|
+
source: event.source
|
|
281
|
+
});
|
|
278
282
|
} else {
|
|
279
|
-
this.bufferRequest(key, request, reply
|
|
283
|
+
this.bufferRequest(key, request, reply, {
|
|
284
|
+
origin: event.origin,
|
|
285
|
+
source: event.source
|
|
286
|
+
});
|
|
280
287
|
}
|
|
281
288
|
}
|
|
282
|
-
async invokeHandler(handler, request, reply) {
|
|
289
|
+
async invokeHandler(handler, request, reply, ctx) {
|
|
283
290
|
try {
|
|
284
|
-
const data = await handler(request.payload);
|
|
291
|
+
const data = await handler(request.payload, ctx);
|
|
285
292
|
reply({
|
|
286
293
|
id: request.id,
|
|
287
294
|
type: request.type,
|
|
@@ -305,14 +312,14 @@ var PostMessageServer = class {
|
|
|
305
312
|
});
|
|
306
313
|
}
|
|
307
314
|
}
|
|
308
|
-
bufferRequest(key, request, reply) {
|
|
315
|
+
bufferRequest(key, request, reply, ctx) {
|
|
309
316
|
this.evictExpiredPending();
|
|
310
317
|
let queue = this.pending.get(key);
|
|
311
318
|
if (!queue) {
|
|
312
319
|
queue = [];
|
|
313
320
|
this.pending.set(key, queue);
|
|
314
321
|
}
|
|
315
|
-
queue.push({ request, reply, at: Date.now() });
|
|
322
|
+
queue.push({ request, reply, at: Date.now(), ctx });
|
|
316
323
|
if (queue.length > MAX_PENDING_PER_KEY) {
|
|
317
324
|
queue.splice(0, queue.length - MAX_PENDING_PER_KEY);
|
|
318
325
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AccessTokenClaims, AppConfigRequest, AppConfigResponse, AttachOAuthTokenRequest, AttachOAuthTokenResponse, AuthAppearance, AuthFlow, AuthFlowComponent, AuthLoginMethod, AuthProviderConfig, BaseGetBalanceParams, BaseGetBalanceResult, BaseGetTokenAccountsParams, BaseSendTransactionParams, BaseSendTransactionResult, BaseSignMessageParams, BaseSignMessageResult, BaseSignTransactionParams, BaseSignTransactionResult, BaseTokenClaims, BaseUIOptions, BaseWalletHooks, BlockExplorer, Chain, ChainLikeWithId, ContractUIOptions, CreateWalletResponse, DefaultFundingMethod, DeleteSessionRequest, DeleteSessionResponse, DetachOAuthTokenRequest, DeviceFingerprint, DisplayMode, EmailOtpConfig, EmailOtpFlowState, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet,
|
|
2
|
-
export { getIframeOrigin, getIframeUrl, getMoonKeyApiUrl } from './utils/index.mjs';
|
|
3
|
-
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-
|
|
1
|
+
export { AccessTokenClaims, AppConfigRequest, AppConfigResponse, AppearanceBackdrop, AppearanceBorderRadius, AppearanceCard, AppearanceColors, AppearanceComponents, AppearanceLogo, AppearanceModeTokens, AppearanceTypography, AttachOAuthTokenRequest, AttachOAuthTokenResponse, AuthAppearance, AuthFlow, AuthFlowComponent, AuthLoginMethod, AuthProviderConfig, BaseGetBalanceParams, BaseGetBalanceResult, BaseGetTokenAccountsParams, BaseSendTransactionParams, BaseSendTransactionResult, BaseSignMessageParams, BaseSignMessageResult, BaseSignTransactionParams, BaseSignTransactionResult, BaseTokenClaims, BaseUIOptions, BaseWalletHooks, BlockExplorer, Chain, ChainConfigItem, ChainEntry, ChainLikeWithId, ComponentStyle, ContractUIOptions, CreateWalletResponse, DefaultFundingMethod, DeleteSessionRequest, DeleteSessionResponse, DetachOAuthTokenRequest, DeviceFingerprint, DisplayMode, EmailOtpConfig, EmailOtpFlowState, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumFundingConfig, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumGetTokenAccountsByOwnerParams, EthereumGetTokenAccountsByOwnerResult, EthereumSendTransactionParams, EthereumSendTransactionRequest, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSwitchChainParams, EvmChainEntry, ExportKeyConfig, Factor, FlexibleTheme, FundWalletConfig, FundingEvents, FundingMethod, FundingUIConfig, GetCurrentSessionRequest, GetCurrentSessionResponse, Hex, IdentityTokenClaims, IdpProvider, IsAuthenticatedRequest, IsAuthenticatedResponse, ListEphemeralSignersResult, LoginTokenBundle, LogoutRequest, LogoutResponse, MessageTypeProperty, MessageTypes, MoonPaySignRequest, MoonPaySignResponse, MpcKeyShares, NativeCurrency, Network, OAuthRequest, OAuthResponse, OnrampFundingSettings, PasskeyEnrollConfig, PasskeySettings, PreferredCardProvider, PrefillConfig, PresenceTokenClaims, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicEthereumWallet, PublicSessionData, PublicWallet, RefreshSessionRequest, RefreshSessionResponse, RetrieveWalletKeyRequest, RetrieveWalletKeyResponse, RevokeEphemeralSignerParams, RpcConfig, RpcUrls, SdkSettings, SendEmailOtpRequest, SendEmailOtpResponse, SendTransactionConfig, SendTransactionRequest, SessionData, SessionWallet, SharesDeviceRequest, SharesDeviceResponse, Sign7702AuthorizationError, Sign7702AuthorizationParams, Sign7702AuthorizationResponse, Sign7702AuthorizationResult, SignMessageConfig, SignTransactionConfig, SignTypedDataError, SignTypedDataParams, SignTypedDataResponse, SignTypedDataResult, SmsSettings, SolanaChain, SolanaChainEntry, SolanaFundingConfig, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, TransactionCommitment, TransactionEncoding, TransactionUIOptions, TypedMessage, UseFundWalletInterface, UsersMePublicResponse, UsersMeRequest, UsersMeResponse, VerifiedSession, VerifyEmailOtpRequest, VerifyEmailOtpResponse, VerifyEmailOtpUser, VerifyOAuthTokenRequest, VerifyOAuthTokenResponse, VerifySiweWalletRegistrationRequest, WALLET_ERROR_CODES, Wallet, WalletChain, WalletChainType, WalletConnectConfig, WalletCreationError, WalletError, WalletErrorCode, WalletKeyRequest, WalletListEntry, WalletRegistrationNonceRequest, WalletRegistrationNonceResponse, WalletType, WalletVerifyRequest } from './types/index.mjs';
|
|
2
|
+
export { FONT_URLS_KEY, getIframeOrigin, getIframeUrl, getMoonKeyApiUrl } from './utils/index.mjs';
|
|
3
|
+
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-BR2NClJ5.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AccessTokenClaims, AppConfigRequest, AppConfigResponse, AttachOAuthTokenRequest, AttachOAuthTokenResponse, AuthAppearance, AuthFlow, AuthFlowComponent, AuthLoginMethod, AuthProviderConfig, BaseGetBalanceParams, BaseGetBalanceResult, BaseGetTokenAccountsParams, BaseSendTransactionParams, BaseSendTransactionResult, BaseSignMessageParams, BaseSignMessageResult, BaseSignTransactionParams, BaseSignTransactionResult, BaseTokenClaims, BaseUIOptions, BaseWalletHooks, BlockExplorer, Chain, ChainLikeWithId, ContractUIOptions, CreateWalletResponse, DefaultFundingMethod, DeleteSessionRequest, DeleteSessionResponse, DetachOAuthTokenRequest, DeviceFingerprint, DisplayMode, EmailOtpConfig, EmailOtpFlowState, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet,
|
|
2
|
-
export { getIframeOrigin, getIframeUrl, getMoonKeyApiUrl } from './utils/index.js';
|
|
3
|
-
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-
|
|
1
|
+
export { AccessTokenClaims, AppConfigRequest, AppConfigResponse, AppearanceBackdrop, AppearanceBorderRadius, AppearanceCard, AppearanceColors, AppearanceComponents, AppearanceLogo, AppearanceModeTokens, AppearanceTypography, AttachOAuthTokenRequest, AttachOAuthTokenResponse, AuthAppearance, AuthFlow, AuthFlowComponent, AuthLoginMethod, AuthProviderConfig, BaseGetBalanceParams, BaseGetBalanceResult, BaseGetTokenAccountsParams, BaseSendTransactionParams, BaseSendTransactionResult, BaseSignMessageParams, BaseSignMessageResult, BaseSignTransactionParams, BaseSignTransactionResult, BaseTokenClaims, BaseUIOptions, BaseWalletHooks, BlockExplorer, Chain, ChainConfigItem, ChainEntry, ChainLikeWithId, ComponentStyle, ContractUIOptions, CreateWalletResponse, DefaultFundingMethod, DeleteSessionRequest, DeleteSessionResponse, DetachOAuthTokenRequest, DeviceFingerprint, DisplayMode, EmailOtpConfig, EmailOtpFlowState, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumFundingConfig, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumGetTokenAccountsByOwnerParams, EthereumGetTokenAccountsByOwnerResult, EthereumSendTransactionParams, EthereumSendTransactionRequest, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSwitchChainParams, EvmChainEntry, ExportKeyConfig, Factor, FlexibleTheme, FundWalletConfig, FundingEvents, FundingMethod, FundingUIConfig, GetCurrentSessionRequest, GetCurrentSessionResponse, Hex, IdentityTokenClaims, IdpProvider, IsAuthenticatedRequest, IsAuthenticatedResponse, ListEphemeralSignersResult, LoginTokenBundle, LogoutRequest, LogoutResponse, MessageTypeProperty, MessageTypes, MoonPaySignRequest, MoonPaySignResponse, MpcKeyShares, NativeCurrency, Network, OAuthRequest, OAuthResponse, OnrampFundingSettings, PasskeyEnrollConfig, PasskeySettings, PreferredCardProvider, PrefillConfig, PresenceTokenClaims, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicEthereumWallet, PublicSessionData, PublicWallet, RefreshSessionRequest, RefreshSessionResponse, RetrieveWalletKeyRequest, RetrieveWalletKeyResponse, RevokeEphemeralSignerParams, RpcConfig, RpcUrls, SdkSettings, SendEmailOtpRequest, SendEmailOtpResponse, SendTransactionConfig, SendTransactionRequest, SessionData, SessionWallet, SharesDeviceRequest, SharesDeviceResponse, Sign7702AuthorizationError, Sign7702AuthorizationParams, Sign7702AuthorizationResponse, Sign7702AuthorizationResult, SignMessageConfig, SignTransactionConfig, SignTypedDataError, SignTypedDataParams, SignTypedDataResponse, SignTypedDataResult, SmsSettings, SolanaChain, SolanaChainEntry, SolanaFundingConfig, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, TransactionCommitment, TransactionEncoding, TransactionUIOptions, TypedMessage, UseFundWalletInterface, UsersMePublicResponse, UsersMeRequest, UsersMeResponse, VerifiedSession, VerifyEmailOtpRequest, VerifyEmailOtpResponse, VerifyEmailOtpUser, VerifyOAuthTokenRequest, VerifyOAuthTokenResponse, VerifySiweWalletRegistrationRequest, WALLET_ERROR_CODES, Wallet, WalletChain, WalletChainType, WalletConnectConfig, WalletCreationError, WalletError, WalletErrorCode, WalletKeyRequest, WalletListEntry, WalletRegistrationNonceRequest, WalletRegistrationNonceResponse, WalletType, WalletVerifyRequest } from './types/index.js';
|
|
2
|
+
export { FONT_URLS_KEY, getIframeOrigin, getIframeUrl, getMoonKeyApiUrl } from './utils/index.js';
|
|
3
|
+
export { F as FORWARDED_ERROR_FIELDS, P as PostMessageClient, a as PostMessageMethod, b as PostMessageServer, c as PostMessageType } from './post-message-BR2NClJ5.js';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
FONT_URLS_KEY: () => FONT_URLS_KEY,
|
|
23
24
|
FORWARDED_ERROR_FIELDS: () => FORWARDED_ERROR_FIELDS,
|
|
24
25
|
Network: () => Network,
|
|
25
26
|
PostMessageClient: () => PostMessageClient,
|
|
@@ -326,12 +327,13 @@ var PostMessageServer = class {
|
|
|
326
327
|
if (queued?.length) {
|
|
327
328
|
this.pending.delete(key);
|
|
328
329
|
const now = Date.now();
|
|
329
|
-
for (const { request, reply, at } of queued) {
|
|
330
|
+
for (const { request, reply, at, ctx } of queued) {
|
|
330
331
|
if (now - at < QUEUE_TTL_MS) {
|
|
331
332
|
void this.invokeHandler(
|
|
332
333
|
handler,
|
|
333
334
|
request,
|
|
334
|
-
reply
|
|
335
|
+
reply,
|
|
336
|
+
ctx
|
|
335
337
|
);
|
|
336
338
|
}
|
|
337
339
|
}
|
|
@@ -383,7 +385,7 @@ var PostMessageServer = class {
|
|
|
383
385
|
id: request.id,
|
|
384
386
|
type: request.type,
|
|
385
387
|
success: false,
|
|
386
|
-
error: `Origin ${event.origin} is not whitelisted. Please add it to your
|
|
388
|
+
error: `Origin ${event.origin} is not whitelisted. Please add it to your MoonX dashboard.`
|
|
387
389
|
});
|
|
388
390
|
return;
|
|
389
391
|
}
|
|
@@ -400,14 +402,20 @@ var PostMessageServer = class {
|
|
|
400
402
|
const key = `${request.type}:${request.method}`;
|
|
401
403
|
const handler = this.handlers.get(key);
|
|
402
404
|
if (handler) {
|
|
403
|
-
await this.invokeHandler(handler, request, reply
|
|
405
|
+
await this.invokeHandler(handler, request, reply, {
|
|
406
|
+
origin: event.origin,
|
|
407
|
+
source: event.source
|
|
408
|
+
});
|
|
404
409
|
} else {
|
|
405
|
-
this.bufferRequest(key, request, reply
|
|
410
|
+
this.bufferRequest(key, request, reply, {
|
|
411
|
+
origin: event.origin,
|
|
412
|
+
source: event.source
|
|
413
|
+
});
|
|
406
414
|
}
|
|
407
415
|
}
|
|
408
|
-
async invokeHandler(handler, request, reply) {
|
|
416
|
+
async invokeHandler(handler, request, reply, ctx) {
|
|
409
417
|
try {
|
|
410
|
-
const data = await handler(request.payload);
|
|
418
|
+
const data = await handler(request.payload, ctx);
|
|
411
419
|
reply({
|
|
412
420
|
id: request.id,
|
|
413
421
|
type: request.type,
|
|
@@ -431,14 +439,14 @@ var PostMessageServer = class {
|
|
|
431
439
|
});
|
|
432
440
|
}
|
|
433
441
|
}
|
|
434
|
-
bufferRequest(key, request, reply) {
|
|
442
|
+
bufferRequest(key, request, reply, ctx) {
|
|
435
443
|
this.evictExpiredPending();
|
|
436
444
|
let queue = this.pending.get(key);
|
|
437
445
|
if (!queue) {
|
|
438
446
|
queue = [];
|
|
439
447
|
this.pending.set(key, queue);
|
|
440
448
|
}
|
|
441
|
-
queue.push({ request, reply, at: Date.now() });
|
|
449
|
+
queue.push({ request, reply, at: Date.now(), ctx });
|
|
442
450
|
if (queue.length > MAX_PENDING_PER_KEY) {
|
|
443
451
|
queue.splice(0, queue.length - MAX_PENDING_PER_KEY);
|
|
444
452
|
}
|
|
@@ -455,8 +463,12 @@ var PostMessageServer = class {
|
|
|
455
463
|
}
|
|
456
464
|
}
|
|
457
465
|
};
|
|
466
|
+
|
|
467
|
+
// src/utils/theme-param.ts
|
|
468
|
+
var FONT_URLS_KEY = "__moonxFontUrls";
|
|
458
469
|
// Annotate the CommonJS export names for ESM import in node:
|
|
459
470
|
0 && (module.exports = {
|
|
471
|
+
FONT_URLS_KEY,
|
|
460
472
|
FORWARDED_ERROR_FIELDS,
|
|
461
473
|
Network,
|
|
462
474
|
PostMessageClient,
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
WALLET_ERROR_CODES,
|
|
4
4
|
WalletCreationError
|
|
5
5
|
} from "./chunk-IMLBIIJ4.mjs";
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
FONT_URLS_KEY
|
|
8
|
+
} from "./chunk-527SU2F6.mjs";
|
|
7
9
|
import {
|
|
8
10
|
getIframeOrigin,
|
|
9
11
|
getIframeUrl
|
|
@@ -14,11 +16,12 @@ import {
|
|
|
14
16
|
PostMessageMethod,
|
|
15
17
|
PostMessageServer,
|
|
16
18
|
PostMessageType
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-Z57WM6IO.mjs";
|
|
18
20
|
import {
|
|
19
21
|
getMoonKeyApiUrl
|
|
20
22
|
} from "./chunk-GQKIA37O.mjs";
|
|
21
23
|
export {
|
|
24
|
+
FONT_URLS_KEY,
|
|
22
25
|
FORWARDED_ERROR_FIELDS,
|
|
23
26
|
Network,
|
|
24
27
|
PostMessageClient,
|