@alchemy/cli 0.6.2 → 0.7.0-alpha.11

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.
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  if(process.argv.includes("--no-color"))process.env.NO_COLOR="1";
3
3
  import {
4
- getCredentials
5
- } from "./chunk-JQRGILIS.js";
6
- import {
4
+ configDir,
7
5
  load,
8
6
  save
9
- } from "./chunk-BAAQ7ELR.js";
7
+ } from "./chunk-HGZTGSXO.js";
10
8
  import {
11
9
  CLIError,
12
10
  ErrorCode,
@@ -31,10 +29,10 @@ import {
31
29
  parseBaseURLOverride,
32
30
  redactSensitiveText,
33
31
  verbose
34
- } from "./chunk-56ZVYB4G.js";
32
+ } from "./chunk-OLVYWGY6.js";
35
33
 
36
34
  // src/lib/resolve.ts
37
- import { readFileSync } from "fs";
35
+ import { readFileSync as readFileSync2 } from "fs";
38
36
 
39
37
  // src/lib/client.ts
40
38
  var Client = class _Client {
@@ -58,12 +56,12 @@ var Client = class _Client {
58
56
  parsed = new URL(`https://${hostname}`);
59
57
  } catch {
60
58
  throw errInvalidArgs(
61
- `Unknown network '${network}'. Run 'alchemy network list' to see available networks.`
59
+ `Unknown network '${network}'. Run 'alchemy evm network list' to see available networks.`
62
60
  );
63
61
  }
64
62
  if (!parsed.hostname.endsWith(`.g.${domain}`)) {
65
63
  throw errInvalidArgs(
66
- `Unknown network '${network}'. Run 'alchemy network list' to see available networks.`
64
+ `Unknown network '${network}'. Run 'alchemy evm network list' to see available networks.`
67
65
  );
68
66
  }
69
67
  }
@@ -413,6 +411,7 @@ var X402Client = class _X402Client {
413
411
  };
414
412
 
415
413
  // src/lib/admin-client.ts
414
+ var STAGING_ADMIN_API_HOST = "admin-api.alchemypreview.com";
416
415
  var AdminClient = class _AdminClient {
417
416
  static get ADMIN_API_HOST() {
418
417
  return `admin-api.${getBaseDomain()}`;
@@ -448,7 +447,9 @@ var AdminClient = class _AdminClient {
448
447
  return isLocalhost(hostname);
449
448
  }
450
449
  baseURLOverride() {
451
- return parseBaseURLOverride(_AdminClient.ADMIN_API_BASE_URL_ENV);
450
+ return parseBaseURLOverride(_AdminClient.ADMIN_API_BASE_URL_ENV, {
451
+ allowedHostnames: [STAGING_ADMIN_API_HOST]
452
+ });
452
453
  }
453
454
  validateAccessKey(accessKey) {
454
455
  if (!accessKey.trim() || /\s/.test(accessKey)) {
@@ -592,9 +593,431 @@ var AdminClient = class _AdminClient {
592
593
  }
593
594
  };
594
595
 
596
+ // src/lib/networks.ts
597
+ var TESTNET_TOKEN_RE = /(testnet|sepolia|holesky|hoodi|devnet|minato|amoy|fuji|saigon|cardona|aeneid|curtis|chiado|cassiopeia|blaze|ropsten|signet|mocha|fam|bepolia)$/i;
598
+ var FAMILY_ALIASES = {
599
+ arb: "Arbitrum",
600
+ arbnova: "Arbitrum Nova",
601
+ avax: "Avalanche",
602
+ bnb: "BNB Smart Chain",
603
+ eth: "Ethereum",
604
+ opt: "OP Mainnet",
605
+ polygonzkevm: "Polygon zkEVM"
606
+ };
607
+ var NAME_ALIASES = {
608
+ arb: "Arbitrum",
609
+ avax: "Avalanche",
610
+ bnb: "BNB",
611
+ eth: "Ethereum",
612
+ opbnb: "opBNB",
613
+ opt: "OP Mainnet",
614
+ sui: "SUI",
615
+ xmtp: "XMTP",
616
+ zksync: "ZKsync"
617
+ };
618
+ var RPC_NETWORK_IDS = [
619
+ "abstract-mainnet",
620
+ "abstract-testnet",
621
+ "adi-mainnet",
622
+ "adi-testnet",
623
+ "alchemy-internal",
624
+ "alchemy-sepolia",
625
+ "alchemyarb-fam",
626
+ "alchemyarb-sepolia",
627
+ "alterscope-mainnet",
628
+ "anime-mainnet",
629
+ "anime-sepolia",
630
+ "apechain-curtis",
631
+ "apechain-mainnet",
632
+ "aptos-mainnet",
633
+ "aptos-testnet",
634
+ "arb-mainnet",
635
+ "arb-sepolia",
636
+ "arbnova-mainnet",
637
+ "arc-testnet",
638
+ "astar-mainnet",
639
+ "avax-fuji",
640
+ "avax-mainnet",
641
+ "base-mainnet",
642
+ "base-sepolia",
643
+ "berachain-bepolia",
644
+ "berachain-mainnet",
645
+ "bitcoin-mainnet",
646
+ "bitcoin-signet",
647
+ "bitcoin-testnet",
648
+ "blast-mainnet",
649
+ "blast-sepolia",
650
+ "bnb-mainnet",
651
+ "bnb-testnet",
652
+ "bob-mainnet",
653
+ "bob-sepolia",
654
+ "boba-mainnet",
655
+ "boba-sepolia",
656
+ "botanix-mainnet",
657
+ "botanix-testnet",
658
+ "celestiabridge-mainnet",
659
+ "celestiabridge-mocha",
660
+ "celo-mainnet",
661
+ "celo-sepolia",
662
+ "citrea-mainnet",
663
+ "citrea-testnet",
664
+ "clankermon-mainnet",
665
+ "commons-mainnet",
666
+ "crossfi-mainnet",
667
+ "crossfi-testnet",
668
+ "degen-mainnet",
669
+ "degen-sepolia",
670
+ "earnm-mainnet",
671
+ "earnm-sepolia",
672
+ "edge-mainnet",
673
+ "edge-testnet",
674
+ "eth-holesky",
675
+ "eth-holeskybeacon",
676
+ "eth-hoodi",
677
+ "eth-hoodibeacon",
678
+ "eth-mainnet",
679
+ "eth-mainnetbeacon",
680
+ "eth-sepolia",
681
+ "eth-sepoliabeacon",
682
+ "flow-mainnet",
683
+ "flow-testnet",
684
+ "frax-hoodi",
685
+ "frax-mainnet",
686
+ "galactica-cassiopeia",
687
+ "galactica-mainnet",
688
+ "gensyn-mainnet",
689
+ "gensyn-testnet",
690
+ "gnosis-chiado",
691
+ "gnosis-mainnet",
692
+ "humanity-mainnet",
693
+ "humanity-testnet",
694
+ "hyperliquid-mainnet",
695
+ "hyperliquid-testnet",
696
+ "ink-mainnet",
697
+ "ink-sepolia",
698
+ "lens-mainnet",
699
+ "lens-sepolia",
700
+ "linea-mainnet",
701
+ "linea-sepolia",
702
+ "mantle-mainnet",
703
+ "mantle-sepolia",
704
+ "megaeth-mainnet",
705
+ "megaeth-testnet",
706
+ "metis-mainnet",
707
+ "mode-mainnet",
708
+ "mode-sepolia",
709
+ "monad-mainnet",
710
+ "monad-testnet",
711
+ "moonbeam-mainnet",
712
+ "mythos-mainnet",
713
+ "opbnb-mainnet",
714
+ "opbnb-testnet",
715
+ "openloot-sepolia",
716
+ "opt-mainnet",
717
+ "opt-sepolia",
718
+ "plasma-mainnet",
719
+ "plasma-testnet",
720
+ "polygon-amoy",
721
+ "polygon-mainnet",
722
+ "polygonzkevm-cardona",
723
+ "polygonzkevm-mainnet",
724
+ "polynomial-mainnet",
725
+ "polynomial-sepolia",
726
+ "race-mainnet",
727
+ "race-sepolia",
728
+ "risa-testnet",
729
+ "rise-testnet",
730
+ "ronin-mainnet",
731
+ "ronin-saigon",
732
+ "rootstock-mainnet",
733
+ "rootstock-testnet",
734
+ "scroll-mainnet",
735
+ "scroll-sepolia",
736
+ "sei-mainnet",
737
+ "sei-testnet",
738
+ "settlus-mainnet",
739
+ "settlus-septestnet",
740
+ "shape-mainnet",
741
+ "shape-sepolia",
742
+ "solana-devnet",
743
+ "solana-mainnet",
744
+ "soneium-mainnet",
745
+ "soneium-minato",
746
+ "sonic-blaze",
747
+ "sonic-mainnet",
748
+ "sonic-testnet",
749
+ "stable-mainnet",
750
+ "stable-testnet",
751
+ "standard-mainnet",
752
+ "starknet-mainnet",
753
+ "starknet-sepolia",
754
+ "story-aeneid",
755
+ "story-mainnet",
756
+ "sui-mainnet",
757
+ "sui-testnet",
758
+ "superseed-mainnet",
759
+ "superseed-sepolia",
760
+ "synd-mainnet",
761
+ "syndicate-manchego",
762
+ "tea-sepolia",
763
+ "tempo-testnet",
764
+ "tron-mainnet",
765
+ "tron-testnet",
766
+ "unichain-mainnet",
767
+ "unichain-sepolia",
768
+ "unite-mainnet",
769
+ "unite-testnet",
770
+ "worldchain-mainnet",
771
+ "worldchain-sepolia",
772
+ "worldl3-devnet",
773
+ "worldmobile-devnet",
774
+ "worldmobile-testnet",
775
+ "worldmobilechain-mainnet",
776
+ "xmtp-mainnet",
777
+ "xmtp-ropsten",
778
+ "xprotocol-mainnet",
779
+ "zetachain-mainnet",
780
+ "zetachain-testnet",
781
+ "zksync-mainnet",
782
+ "zksync-sepolia",
783
+ "zora-mainnet",
784
+ "zora-sepolia"
785
+ ];
786
+ function isTestnetNetwork(id) {
787
+ return TESTNET_TOKEN_RE.test(id);
788
+ }
789
+ function tokenToName(token) {
790
+ const alias = NAME_ALIASES[token];
791
+ if (alias) return alias;
792
+ return token.charAt(0).toUpperCase() + token.slice(1);
793
+ }
794
+ function toFamily(id) {
795
+ const [head] = id.split("-");
796
+ return FAMILY_ALIASES[head] ?? tokenToName(head);
797
+ }
798
+ function toDisplayName(id) {
799
+ return id.split("-").map((part) => tokenToName(part)).join(" ");
800
+ }
801
+ function toHttpsUrlTemplate(id) {
802
+ const domain = getBaseDomain();
803
+ if (id === "starknet-mainnet" || id === "starknet-sepolia") {
804
+ return `https://${id}.g.${domain}/starknet/version/rpc/v0_10/{apiKey}`;
805
+ }
806
+ return `https://${id}.g.${domain}/v2/{apiKey}`;
807
+ }
808
+ function getRPCNetworks() {
809
+ return RPC_NETWORK_IDS.map((id) => ({
810
+ id,
811
+ name: toDisplayName(id),
812
+ family: toFamily(id),
813
+ isTestnet: isTestnetNetwork(id),
814
+ httpsUrlTemplate: toHttpsUrlTemplate(id)
815
+ }));
816
+ }
817
+ function getRPCNetworkIds() {
818
+ return [...RPC_NETWORK_IDS];
819
+ }
820
+ var NATIVE_TOKEN_SYMBOLS = {
821
+ eth: "ETH",
822
+ arb: "ETH",
823
+ arbnova: "ETH",
824
+ opt: "ETH",
825
+ base: "ETH",
826
+ zksync: "ETH",
827
+ scroll: "ETH",
828
+ blast: "ETH",
829
+ linea: "ETH",
830
+ zora: "ETH",
831
+ shape: "ETH",
832
+ polygon: "POL",
833
+ polygonzkevm: "ETH",
834
+ bnb: "BNB",
835
+ opbnb: "BNB",
836
+ avax: "AVAX",
837
+ solana: "SOL",
838
+ starknet: "ETH",
839
+ fantom: "FTM",
840
+ metis: "METIS",
841
+ mantle: "MNT",
842
+ celo: "CELO",
843
+ gnosis: "xDAI",
844
+ frax: "frxETH",
845
+ worldchain: "ETH",
846
+ berachain: "BERA",
847
+ flow: "FLOW",
848
+ rootstock: "RBTC",
849
+ zetachain: "ZETA",
850
+ sui: "SUI"
851
+ };
852
+ function isSolanaNetwork(networkId) {
853
+ return networkId.startsWith("solana-");
854
+ }
855
+ function nativeTokenSymbol(networkId) {
856
+ const prefix = networkId.replace(/-(mainnet|testnet|sepolia|holesky|hoodi|devnet|amoy|fuji|cardona|saigon|chiado|signet|mocha|blaze|curtis|bepolia).*$/, "");
857
+ return NATIVE_TOKEN_SYMBOLS[prefix] ?? "ETH";
858
+ }
859
+
860
+ // src/lib/wallet-session.ts
861
+ import { generateKeyPairSync, randomUUID } from "crypto";
862
+ import { readFileSync, writeFileSync, mkdirSync, rmSync, existsSync } from "fs";
863
+ import { join, dirname } from "path";
864
+ import { z } from "zod";
865
+ var SESSION_FILE = "wallet-session.json";
866
+ var SESSION_TTL_DAYS = 7;
867
+ var SESSION_ENVELOPE_VERSION = "v1";
868
+ var walletSessionCapabilitiesSchema = z.object({
869
+ "evm.signMessage": z.boolean().optional(),
870
+ "evm.signTypedData": z.boolean().optional(),
871
+ "evm.signAuthorization": z.boolean().optional(),
872
+ "solana.signTransaction": z.boolean().optional()
873
+ }).strict();
874
+ var walletSessionEnvironmentSchema = z.object({
875
+ platform: z.string().min(1),
876
+ arch: z.string().min(1),
877
+ nodeVersion: z.string().min(1),
878
+ interactive: z.boolean(),
879
+ clientInstanceId: z.string().uuid().optional(),
880
+ clientInstanceName: z.string().min(1).max(64).optional()
881
+ }).strict();
882
+ var walletSessionSchema = z.object({
883
+ sessionId: z.string().uuid(),
884
+ status: z.enum(["pending", "approved", "revoked", "expired"]),
885
+ createdAt: z.string().datetime(),
886
+ expiresAt: z.string().datetime(),
887
+ envelopeVersion: z.string().min(1),
888
+ publicKeyJwk: z.object({}).passthrough(),
889
+ privateKeyPem: z.string().min(1),
890
+ privyAppId: z.string().min(1).optional(),
891
+ walletId: z.string().min(1).optional(),
892
+ evmWalletId: z.string().min(1).optional(),
893
+ evmAddress: z.string().min(1).optional(),
894
+ solanaWalletId: z.string().min(1).optional(),
895
+ solanaAddress: z.string().min(1).optional(),
896
+ privyKeyQuorumId: z.string().min(1).optional(),
897
+ privySignerId: z.string().min(1).optional(),
898
+ chainType: z.string().min(1).optional(),
899
+ backendBaseUrl: z.string().min(1).optional(),
900
+ environment: walletSessionEnvironmentSchema.optional(),
901
+ capabilities: walletSessionCapabilitiesSchema.optional()
902
+ }).strict();
903
+ function sessionPath() {
904
+ return join(configDir(), SESSION_FILE);
905
+ }
906
+ function parseStoredSession(value) {
907
+ const parsed = walletSessionSchema.safeParse(value);
908
+ if (!parsed.success) return null;
909
+ return parsed.data;
910
+ }
911
+ function loadStoredSessionFromPath(path) {
912
+ if (!existsSync(path)) return null;
913
+ try {
914
+ return parseStoredSession(JSON.parse(readFileSync(path, "utf-8")));
915
+ } catch {
916
+ return null;
917
+ }
918
+ }
919
+ function isExpired(session) {
920
+ const expiresAt = new Date(session.expiresAt);
921
+ return !Number.isNaN(expiresAt.getTime()) && expiresAt <= /* @__PURE__ */ new Date();
922
+ }
923
+ function createFileWalletSessionStore(path = sessionPath()) {
924
+ return {
925
+ load() {
926
+ const session = loadStoredSessionFromPath(path);
927
+ if (!session) return null;
928
+ if (session.status === "revoked") return null;
929
+ if (isExpired(session)) return null;
930
+ return session;
931
+ },
932
+ loadRaw() {
933
+ return loadStoredSessionFromPath(path);
934
+ },
935
+ save(session) {
936
+ mkdirSync(dirname(path), { recursive: true, mode: 493 });
937
+ writeFileSync(path, JSON.stringify(session, null, 2) + "\n", { mode: 384 });
938
+ },
939
+ clear() {
940
+ if (!existsSync(path)) return false;
941
+ try {
942
+ rmSync(path, { force: true });
943
+ return true;
944
+ } catch {
945
+ return false;
946
+ }
947
+ }
948
+ };
949
+ }
950
+ var walletSessionStore = null;
951
+ function getWalletSessionStore() {
952
+ if (!walletSessionStore) {
953
+ walletSessionStore = createFileWalletSessionStore();
954
+ }
955
+ return walletSessionStore;
956
+ }
957
+ function generateP256Keypair() {
958
+ const { publicKey, privateKey } = generateKeyPairSync("ec", {
959
+ namedCurve: "P-256"
960
+ });
961
+ const publicKeyJwk = publicKey.export({ format: "jwk" });
962
+ const privateKeyPem = privateKey.export({
963
+ type: "pkcs8",
964
+ format: "pem"
965
+ });
966
+ return { publicKeyJwk, privateKeyPem };
967
+ }
968
+ function createPendingSession() {
969
+ const keypair = generateP256Keypair();
970
+ const now = /* @__PURE__ */ new Date();
971
+ const expiresAt = new Date(now.getTime() + SESSION_TTL_DAYS * 24 * 60 * 60 * 1e3);
972
+ const session = {
973
+ sessionId: randomUUID(),
974
+ status: "pending",
975
+ createdAt: now.toISOString(),
976
+ expiresAt: expiresAt.toISOString(),
977
+ envelopeVersion: SESSION_ENVELOPE_VERSION,
978
+ publicKeyJwk: keypair.publicKeyJwk,
979
+ privateKeyPem: keypair.privateKeyPem
980
+ };
981
+ saveSession(session);
982
+ return session;
983
+ }
984
+ function loadSession() {
985
+ return getWalletSessionStore().load();
986
+ }
987
+ function loadStoredSession() {
988
+ const store = getWalletSessionStore();
989
+ if (store.loadRaw) {
990
+ return store.loadRaw();
991
+ }
992
+ return store.load();
993
+ }
994
+ function saveSession(session) {
995
+ getWalletSessionStore().save(session);
996
+ }
997
+ function updateSession(updates) {
998
+ const session = loadSession();
999
+ if (!session) return null;
1000
+ const updated = { ...session, ...updates };
1001
+ saveSession(updated);
1002
+ return updated;
1003
+ }
1004
+ function clearSession() {
1005
+ return getWalletSessionStore().clear();
1006
+ }
1007
+ function isSessionValid(session) {
1008
+ if (session.status !== "approved") return false;
1009
+ const expiresAt = new Date(session.expiresAt);
1010
+ if (Number.isNaN(expiresAt.getTime())) return false;
1011
+ return expiresAt > /* @__PURE__ */ new Date();
1012
+ }
1013
+
595
1014
  // src/lib/resolve.ts
1015
+ function getCommandOptions(program) {
1016
+ const commandWithGlobals = program;
1017
+ return commandWithGlobals.optsWithGlobals?.() ?? program.opts();
1018
+ }
596
1019
  function resolveAPIKey(program, cfg) {
597
- const opts = program.opts();
1020
+ const opts = getCommandOptions(program);
598
1021
  if (opts.apiKey) return opts.apiKey;
599
1022
  if (process.env.ALCHEMY_API_KEY) return process.env.ALCHEMY_API_KEY;
600
1023
  const config = cfg ?? load();
@@ -602,40 +1025,52 @@ function resolveAPIKey(program, cfg) {
602
1025
  if (config.app?.apiKey) return config.app.apiKey;
603
1026
  return void 0;
604
1027
  }
605
- function resolveAccessKey(program, cfg) {
606
- const opts = program.opts();
607
- if (opts.accessKey) return opts.accessKey;
1028
+ function resolveAccessKey(_program, cfg) {
608
1029
  if (process.env.ALCHEMY_ACCESS_KEY) return process.env.ALCHEMY_ACCESS_KEY;
609
1030
  const config = cfg ?? load();
610
1031
  if (config.access_key) return config.access_key;
611
1032
  return void 0;
612
1033
  }
613
1034
  function resolveNetwork(program, cfg, defaultNetwork) {
614
- const opts = program.opts();
1035
+ const opts = getCommandOptions(program);
615
1036
  if (opts.network) return opts.network;
616
1037
  if (process.env.ALCHEMY_NETWORK) return process.env.ALCHEMY_NETWORK;
617
1038
  const config = cfg ?? load();
618
1039
  if (config.network) return config.network;
619
1040
  return defaultNetwork ?? "eth-mainnet";
620
1041
  }
1042
+ function resolveSolanaNetwork(program, cfg) {
1043
+ const opts = getCommandOptions(program);
1044
+ if (opts.network) {
1045
+ if (!isSolanaNetwork(opts.network)) {
1046
+ throw errInvalidArgs(
1047
+ `Network '${opts.network}' is not a Solana network. Use a solana-* network with the solana namespace.`
1048
+ );
1049
+ }
1050
+ return opts.network;
1051
+ }
1052
+ if (process.env.ALCHEMY_NETWORK) {
1053
+ if (!isSolanaNetwork(process.env.ALCHEMY_NETWORK)) {
1054
+ throw errInvalidArgs(
1055
+ `ALCHEMY_NETWORK='${process.env.ALCHEMY_NETWORK}' is not a Solana network. Use a solana-* network with the solana namespace.`
1056
+ );
1057
+ }
1058
+ return process.env.ALCHEMY_NETWORK;
1059
+ }
1060
+ const config = cfg ?? load();
1061
+ if (config.network && isSolanaNetwork(config.network)) {
1062
+ return config.network;
1063
+ }
1064
+ return "solana-mainnet";
1065
+ }
621
1066
  function resolveAppId(program, cfg) {
622
- const opts = program.opts();
1067
+ const opts = getCommandOptions(program);
623
1068
  if (opts.appId) return opts.appId;
624
1069
  const config = cfg ?? load();
625
1070
  if (config.app?.id) return config.app.id;
626
1071
  return void 0;
627
1072
  }
628
- async function resolveAuthToken(cfg) {
629
- const creds = await getCredentials();
630
- if (creds?.auth_token?.trim()) {
631
- if (creds.auth_token_expires_at) {
632
- const expiry = new Date(creds.auth_token_expires_at);
633
- if (!Number.isNaN(expiry.getTime()) && expiry <= /* @__PURE__ */ new Date()) {
634
- return void 0;
635
- }
636
- }
637
- return creds.auth_token;
638
- }
1073
+ function resolveAuthToken(cfg) {
639
1074
  const config = cfg ?? load();
640
1075
  if (!config.auth_token?.trim()) return void 0;
641
1076
  if (config.auth_token_expires_at) {
@@ -646,16 +1081,16 @@ async function resolveAuthToken(cfg) {
646
1081
  }
647
1082
  return config.auth_token;
648
1083
  }
649
- async function adminClientFromFlags(program) {
1084
+ function adminClientFromFlags(program) {
650
1085
  const cfg = load();
651
1086
  const accessKey = resolveAccessKey(program, cfg);
652
1087
  if (accessKey) return new AdminClient(accessKey);
653
- const authToken = await resolveAuthToken(cfg);
1088
+ const authToken = resolveAuthToken(cfg);
654
1089
  if (authToken) return new AdminClient({ type: "auth_token", token: authToken });
655
1090
  throw errAccessKeyRequired();
656
1091
  }
657
1092
  function resolveX402(program, cfg) {
658
- const opts = program.opts();
1093
+ const opts = getCommandOptions(program);
659
1094
  if (opts.x402) return true;
660
1095
  const config = cfg ?? load();
661
1096
  return config.x402 === true;
@@ -668,29 +1103,97 @@ function resolveX402Client(program) {
668
1103
  return new X402Client(walletKey, resolveNetwork(program, cfg));
669
1104
  }
670
1105
  function resolveWalletKey(program, cfg) {
671
- const opts = program.opts();
1106
+ const opts = getCommandOptions(program);
672
1107
  if (opts.walletKeyFile) {
673
- return readFileSync(opts.walletKeyFile, "utf-8").trim();
1108
+ return readFileSync2(opts.walletKeyFile, "utf-8").trim();
674
1109
  }
675
1110
  if (process.env.ALCHEMY_WALLET_KEY) {
676
1111
  return process.env.ALCHEMY_WALLET_KEY;
677
1112
  }
678
1113
  const config = cfg ?? load();
679
1114
  if (config.wallet_key_file) {
680
- return readFileSync(config.wallet_key_file, "utf-8").trim();
1115
+ return readFileSync2(config.wallet_key_file, "utf-8").trim();
1116
+ }
1117
+ return void 0;
1118
+ }
1119
+ function resolveSolanaWalletKey(program, cfg) {
1120
+ const opts = getCommandOptions(program);
1121
+ if (opts.solanaWalletKeyFile) {
1122
+ return readFileSync2(opts.solanaWalletKeyFile, "utf-8").trim();
1123
+ }
1124
+ if (process.env.ALCHEMY_SOLANA_WALLET_KEY) {
1125
+ return process.env.ALCHEMY_SOLANA_WALLET_KEY;
1126
+ }
1127
+ const config = cfg ?? load();
1128
+ if (config.solana_wallet_key_file) {
1129
+ return readFileSync2(config.solana_wallet_key_file, "utf-8").trim();
1130
+ }
1131
+ return void 0;
1132
+ }
1133
+ function resolveGasSponsored(program, cfg) {
1134
+ const opts = getCommandOptions(program);
1135
+ if (opts.gasSponsored) return true;
1136
+ if (process.env.ALCHEMY_EVM_GAS_SPONSORED) {
1137
+ return process.env.ALCHEMY_EVM_GAS_SPONSORED.trim().toLowerCase() === "true";
1138
+ }
1139
+ const config = cfg ?? load();
1140
+ return config.evm_gas_sponsored === true;
1141
+ }
1142
+ function resolveGasPolicyId(program, cfg) {
1143
+ const opts = getCommandOptions(program);
1144
+ if (opts.gasPolicyId) return opts.gasPolicyId;
1145
+ if (process.env.ALCHEMY_EVM_GAS_POLICY_ID) return process.env.ALCHEMY_EVM_GAS_POLICY_ID;
1146
+ const config = cfg ?? load();
1147
+ return config.evm_gas_policy_id;
1148
+ }
1149
+ function resolveSolanaFeeSponsored(program, cfg) {
1150
+ const opts = getCommandOptions(program);
1151
+ if (opts.feeSponsored) return true;
1152
+ if (process.env.ALCHEMY_SOLANA_FEE_SPONSORED) {
1153
+ return process.env.ALCHEMY_SOLANA_FEE_SPONSORED.trim().toLowerCase() === "true";
681
1154
  }
1155
+ const config = cfg ?? load();
1156
+ return config.solana_fee_sponsored === true;
1157
+ }
1158
+ function resolveSolanaFeePolicyId(program, cfg) {
1159
+ const opts = getCommandOptions(program);
1160
+ if (opts.feePolicyId) return opts.feePolicyId;
1161
+ if (process.env.ALCHEMY_SOLANA_FEE_POLICY_ID) return process.env.ALCHEMY_SOLANA_FEE_POLICY_ID;
1162
+ const config = cfg ?? load();
1163
+ return config.solana_fee_policy_id;
1164
+ }
1165
+ function parseBoolean(value) {
1166
+ const normalized = value.trim().toLowerCase();
1167
+ if (normalized === "true" || normalized === "1") return true;
1168
+ if (normalized === "false" || normalized === "0") return false;
682
1169
  return void 0;
683
1170
  }
1171
+ function resolveActiveSigner(program, cfg) {
1172
+ const opts = getCommandOptions(program);
1173
+ if (opts.signer === "session" || opts.signer === "local") {
1174
+ return opts.signer;
1175
+ }
1176
+ const env = process.env.ALCHEMY_ACTIVE_SIGNER;
1177
+ if (env === "session" || env === "local") {
1178
+ return env;
1179
+ }
1180
+ const config = cfg ?? load();
1181
+ if (config.active_signer === "session" || config.active_signer === "local") {
1182
+ return config.active_signer;
1183
+ }
1184
+ if (process.env.ALCHEMY_DELEGATED_WALLET !== void 0) {
1185
+ const parsed = parseBoolean(process.env.ALCHEMY_DELEGATED_WALLET);
1186
+ if (parsed === true) return "session";
1187
+ }
1188
+ return void 0;
1189
+ }
1190
+ function resolveDelegatedMode(program, cfg) {
1191
+ return resolveActiveSigner(program, cfg) === "session";
1192
+ }
684
1193
  function clientFromFlags(program, opts) {
685
1194
  const cfg = load();
686
- const network = resolveNetwork(program, cfg, opts?.defaultNetwork);
1195
+ const network = opts?.forceNetwork ?? resolveNetwork(program, cfg, opts?.defaultNetwork);
687
1196
  debug(`using network=${network}`);
688
- const programOpts = program.opts();
689
- if (programOpts.accessKey) {
690
- throw errInvalidArgs(
691
- "--access-key is for admin commands (apps, chains, webhooks). Use --api-key for RPC commands."
692
- );
693
- }
694
1197
  if (resolveX402(program, cfg)) {
695
1198
  const walletKey = resolveWalletKey(program, cfg);
696
1199
  if (!walletKey) throw errWalletKeyRequired();
@@ -715,23 +1218,51 @@ function appNetworkToSlug(rpcUrl) {
715
1218
  async function resolveConfiguredNetworkSlugs(program, appIdOverride) {
716
1219
  const appId = appIdOverride || resolveAppId(program);
717
1220
  if (!appId) throw errAppRequired();
718
- const admin = await adminClientFromFlags(program);
1221
+ const admin = adminClientFromFlags(program);
719
1222
  const app = await admin.getApp(appId);
720
1223
  const slugs = app.chainNetworks.map((network) => appNetworkToSlug(network.rpcUrl)).filter((slug) => Boolean(slug));
721
1224
  return Array.from(new Set(slugs)).sort((a, b) => a.localeCompare(b));
722
1225
  }
1226
+ function resolveWalletSession() {
1227
+ const session = loadSession();
1228
+ if (!session) return null;
1229
+ if (!isSessionValid(session)) return null;
1230
+ return session;
1231
+ }
1232
+ var resolveDelegatedSession = resolveWalletSession;
723
1233
 
724
1234
  export {
725
1235
  AdminClient,
1236
+ getRPCNetworks,
1237
+ getRPCNetworkIds,
1238
+ isSolanaNetwork,
1239
+ nativeTokenSymbol,
1240
+ createPendingSession,
1241
+ loadSession,
1242
+ loadStoredSession,
1243
+ saveSession,
1244
+ updateSession,
1245
+ clearSession,
1246
+ isSessionValid,
726
1247
  resolveAPIKey,
727
1248
  resolveAccessKey,
728
1249
  resolveNetwork,
1250
+ resolveSolanaNetwork,
729
1251
  resolveAppId,
730
1252
  resolveAuthToken,
731
1253
  adminClientFromFlags,
732
1254
  resolveX402,
733
1255
  resolveX402Client,
734
1256
  resolveWalletKey,
1257
+ resolveSolanaWalletKey,
1258
+ resolveGasSponsored,
1259
+ resolveGasPolicyId,
1260
+ resolveSolanaFeeSponsored,
1261
+ resolveSolanaFeePolicyId,
1262
+ resolveActiveSigner,
1263
+ resolveDelegatedMode,
735
1264
  clientFromFlags,
736
- resolveConfiguredNetworkSlugs
1265
+ resolveConfiguredNetworkSlugs,
1266
+ resolveWalletSession,
1267
+ resolveDelegatedSession
737
1268
  };