@shelby-protocol/cli 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/entry.js +576 -393
  2. package/package.json +3 -3
package/bin/entry.js CHANGED
@@ -4,10 +4,16 @@
4
4
  import { Command } from "commander";
5
5
 
6
6
  // package.json
7
- var version = "0.0.9";
7
+ var version = "0.0.10";
8
8
 
9
9
  // src/commands/account.tsx
10
- import { AptosApiError as AptosApiError2, Hex as Hex4 } from "@aptos-labs/ts-sdk";
10
+ import readline from "readline";
11
+ import {
12
+ Account as Account3,
13
+ AptosApiError as AptosApiError2,
14
+ Ed25519PrivateKey as Ed25519PrivateKey4,
15
+ Hex as Hex4
16
+ } from "@aptos-labs/ts-sdk";
11
17
 
12
18
  // ../../packages/sdk/dist/chunk-RBFWGDMY.mjs
13
19
  import { AptosConfig, Network } from "@aptos-labs/ts-sdk";
@@ -229,10 +235,10 @@ var GraphQLError = class _GraphQLError extends Error {
229
235
  */
230
236
  constructor(message, ...rawArgs) {
231
237
  var _this$nodes, _nodeLocations$, _ref;
232
- const { nodes, source, positions, path: path5, originalError, extensions } = toNormalizedOptions(rawArgs);
238
+ const { nodes, source, positions, path: path6, originalError, extensions } = toNormalizedOptions(rawArgs);
233
239
  super(message);
234
240
  this.name = "GraphQLError";
235
- this.path = path5 !== null && path5 !== void 0 ? path5 : void 0;
241
+ this.path = path6 !== null && path6 !== void 0 ? path6 : void 0;
236
242
  this.originalError = originalError !== null && originalError !== void 0 ? originalError : void 0;
237
243
  this.nodes = undefinedIfEmpty(
238
244
  Array.isArray(nodes) ? nodes : nodes ? [nodes] : void 0
@@ -2800,14 +2806,14 @@ function visit(root, visitor, visitorKeys = QueryDocumentKeys) {
2800
2806
  let node = root;
2801
2807
  let key = void 0;
2802
2808
  let parent = void 0;
2803
- const path5 = [];
2809
+ const path6 = [];
2804
2810
  const ancestors = [];
2805
2811
  do {
2806
2812
  index++;
2807
2813
  const isLeaving = index === keys.length;
2808
2814
  const isEdited = isLeaving && edits.length !== 0;
2809
2815
  if (isLeaving) {
2810
- key = ancestors.length === 0 ? void 0 : path5[path5.length - 1];
2816
+ key = ancestors.length === 0 ? void 0 : path6[path6.length - 1];
2811
2817
  node = parent;
2812
2818
  parent = ancestors.pop();
2813
2819
  if (isEdited) {
@@ -2841,20 +2847,20 @@ function visit(root, visitor, visitorKeys = QueryDocumentKeys) {
2841
2847
  if (node === null || node === void 0) {
2842
2848
  continue;
2843
2849
  }
2844
- path5.push(key);
2850
+ path6.push(key);
2845
2851
  }
2846
2852
  let result;
2847
2853
  if (!Array.isArray(node)) {
2848
2854
  var _enterLeaveMap$get, _enterLeaveMap$get2;
2849
2855
  isNode(node) || devAssert(false, `Invalid AST Node: ${inspect(node)}.`);
2850
2856
  const visitFn = isLeaving ? (_enterLeaveMap$get = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get === void 0 ? void 0 : _enterLeaveMap$get.leave : (_enterLeaveMap$get2 = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get2 === void 0 ? void 0 : _enterLeaveMap$get2.enter;
2851
- result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path5, ancestors);
2857
+ result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path6, ancestors);
2852
2858
  if (result === BREAK) {
2853
2859
  break;
2854
2860
  }
2855
2861
  if (result === false) {
2856
2862
  if (!isLeaving) {
2857
- path5.pop();
2863
+ path6.pop();
2858
2864
  continue;
2859
2865
  }
2860
2866
  } else if (result !== void 0) {
@@ -2863,7 +2869,7 @@ function visit(root, visitor, visitorKeys = QueryDocumentKeys) {
2863
2869
  if (isNode(result)) {
2864
2870
  node = result;
2865
2871
  } else {
2866
- path5.pop();
2872
+ path6.pop();
2867
2873
  continue;
2868
2874
  }
2869
2875
  }
@@ -2873,7 +2879,7 @@ function visit(root, visitor, visitorKeys = QueryDocumentKeys) {
2873
2879
  edits.push([key, node]);
2874
2880
  }
2875
2881
  if (isLeaving) {
2876
- path5.pop();
2882
+ path6.pop();
2877
2883
  } else {
2878
2884
  var _node$kind;
2879
2885
  stack = {
@@ -3319,7 +3325,7 @@ function getSdk(client, withWrapper = defaultWrapper) {
3319
3325
  };
3320
3326
  }
3321
3327
 
3322
- // ../../packages/sdk/dist/chunk-75VHXY5P.mjs
3328
+ // ../../packages/sdk/dist/chunk-57KKLRIW.mjs
3323
3329
  import { Network as Network3 } from "@aptos-labs/ts-sdk";
3324
3330
 
3325
3331
  // ../../node_modules/.pnpm/graphql-request@7.2.0_graphql@16.11.0/node_modules/graphql-request/build/legacy/classes/ClientError.js
@@ -3834,14 +3840,14 @@ var parseRequestArgs = (documentOrOptions, variables, requestHeaders) => {
3834
3840
  };
3835
3841
  };
3836
3842
 
3837
- // ../../packages/sdk/dist/chunk-75VHXY5P.mjs
3843
+ // ../../packages/sdk/dist/chunk-57KKLRIW.mjs
3838
3844
  function createShelbyIndexerClient(baseUrl, options) {
3839
3845
  const graphqlClient = new GraphQLClient(baseUrl, options);
3840
3846
  return getSdk(graphqlClient);
3841
3847
  }
3842
3848
  function getShelbyIndexerClient(config) {
3843
3849
  const aptosConfig = config.aptos ?? getAptosConfig(config);
3844
- let { apiKey, baseUrl } = config.indexer ?? {};
3850
+ let { apiKey: indexerApiKey, baseUrl } = config.indexer ?? {};
3845
3851
  if (!baseUrl) {
3846
3852
  switch (aptosConfig?.network) {
3847
3853
  // TODO: Add endpoints for core networks
@@ -3858,6 +3864,7 @@ function getShelbyIndexerClient(config) {
3858
3864
  "The ShelbyClientConfig does not support the Shelby indexer. Please configure the endpoint in the ShelbyClientConfig.indexer.endpoint or provide a supported Aptos network."
3859
3865
  );
3860
3866
  }
3867
+ const apiKey = indexerApiKey ?? config.apiKey;
3861
3868
  return createShelbyIndexerClient(baseUrl, {
3862
3869
  headers: {
3863
3870
  ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
@@ -3945,10 +3952,10 @@ function isReadableStream(value) {
3945
3952
  function toUint8Array(view) {
3946
3953
  return view instanceof Uint8Array ? view : new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
3947
3954
  }
3948
- function buildRequestUrl(path5, baseUrl) {
3955
+ function buildRequestUrl(path6, baseUrl) {
3949
3956
  const baseHasSlash = baseUrl.endsWith("/");
3950
3957
  const safeBase = baseHasSlash ? baseUrl : `${baseUrl}/`;
3951
- const safePath = path5.replace(/^\/+/, "");
3958
+ const safePath = path6.replace(/^\/+/, "");
3952
3959
  return new URL(safePath, safeBase);
3953
3960
  }
3954
3961
 
@@ -4338,9 +4345,9 @@ async function loadWasm() {
4338
4345
  resolve(here, "../dist/clay.wasm")
4339
4346
  ];
4340
4347
  let bytes;
4341
- for (const path5 of paths) {
4348
+ for (const path6 of paths) {
4342
4349
  try {
4343
- bytes = await readFile(path5);
4350
+ bytes = await readFile(path6);
4344
4351
  break;
4345
4352
  } catch {
4346
4353
  }
@@ -4522,7 +4529,7 @@ var BlobNameSchema = z.string().min(1, "Blob name path parameter cannot be empty
4522
4529
  message: "Blob name cannot end with a slash"
4523
4530
  });
4524
4531
 
4525
- // ../../packages/sdk/dist/chunk-NRNVAY72.mjs
4532
+ // ../../packages/sdk/dist/chunk-PGBEBDNY.mjs
4526
4533
  import { AccountAddress as AccountAddress3 } from "@aptos-labs/ts-sdk";
4527
4534
  function encodeURIComponentKeepSlashes(str) {
4528
4535
  return encodeURIComponent(str).replace(/%2F/g, "/");
@@ -4914,7 +4921,7 @@ function validatePrePaddedChunkset(chunkset, expectedSize, chunksetIdx) {
4914
4921
  return chunkset;
4915
4922
  }
4916
4923
 
4917
- // ../../packages/sdk/dist/chunk-XGMJ4CG4.mjs
4924
+ // ../../packages/sdk/dist/chunk-USBWGA27.mjs
4918
4925
  import {
4919
4926
  AccountAddress as AccountAddress5,
4920
4927
  Aptos as Aptos2,
@@ -5078,16 +5085,16 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
5078
5085
  owner: AccountAddress5.from(blob.owner),
5079
5086
  name: blob.blob_name,
5080
5087
  blobMerkleRoot: Hex3.fromHexInput(blob.blob_commitment).toUint8Array(),
5081
- size: blob.size,
5088
+ size: Number(blob.size),
5082
5089
  // TODO: Add encoding when supported in NCI
5083
5090
  encoding: {
5084
5091
  variant: "clay",
5085
5092
  ...ERASURE_CODE_PARAMS.ClayCode_16Total_10Data_13Helper,
5086
5093
  ...ERASURE_CODE_AND_CHUNK_MAPPING.ClayCode_16Total_10Data_13Helper
5087
5094
  },
5088
- expirationMicros: blob.expires_at,
5095
+ expirationMicros: Number(blob.expires_at),
5089
5096
  sliceAddress: AccountAddress5.from(blob.slice_address),
5090
- isWritten: blob.is_written
5097
+ isWritten: Boolean(Number(blob.is_written))
5091
5098
  })
5092
5099
  );
5093
5100
  }
@@ -5272,7 +5279,7 @@ var ShelbyBlobClient = class _ShelbyBlobClient {
5272
5279
  }
5273
5280
  };
5274
5281
 
5275
- // ../../packages/sdk/dist/chunk-QP2C6ORP.mjs
5282
+ // ../../packages/sdk/dist/chunk-PUNXDYH2.mjs
5276
5283
  import {
5277
5284
  Aptos as Aptos3
5278
5285
  } from "@aptos-labs/ts-sdk";
@@ -5427,7 +5434,7 @@ var ShelbyClient = class {
5427
5434
  }
5428
5435
  };
5429
5436
 
5430
- // ../../packages/sdk/dist/chunk-LSNN4V5F.mjs
5437
+ // ../../packages/sdk/dist/chunk-I7SQAWUY.mjs
5431
5438
  var ShelbyNodeClient = class extends ShelbyClient {
5432
5439
  };
5433
5440
 
@@ -5464,7 +5471,7 @@ var shelbyNetworks = [Network4.LOCAL, Network4.SHELBYNET];
5464
5471
 
5465
5472
  // src/commands/account.tsx
5466
5473
  import { render } from "ink";
5467
- import { z as z8 } from "zod";
5474
+ import { z as z9 } from "zod";
5468
5475
 
5469
5476
  // src/components/AccountWizard.tsx
5470
5477
  import { Box, Text } from "ink";
@@ -5478,95 +5485,13 @@ import {
5478
5485
  Aptos as Aptos4,
5479
5486
  AptosConfig as AptosConfig3,
5480
5487
  Ed25519Account,
5481
- Ed25519PrivateKey as Ed25519PrivateKey2,
5482
- Network as Network7,
5488
+ Ed25519PrivateKey,
5483
5489
  NetworkToNetworkName
5484
5490
  } from "@aptos-labs/ts-sdk";
5485
5491
  import fs from "fs-extra";
5486
5492
  import YAML from "yaml";
5487
5493
  import { z as z6 } from "zod";
5488
5494
 
5489
- // tests/utils/mockConfig.ts
5490
- import { Network as Network5 } from "@aptos-labs/ts-sdk";
5491
-
5492
- // src/utils/context-helpers.ts
5493
- import {
5494
- NetworkToFaucetAPI,
5495
- NetworkToIndexerAPI,
5496
- NetworkToNodeAPI,
5497
- NetworkToPepperAPI,
5498
- NetworkToProverAPI
5499
- } from "@aptos-labs/ts-sdk";
5500
- function createContextForNetwork(network) {
5501
- return {
5502
- aptos_network: {
5503
- name: network,
5504
- fullnode: NetworkToNodeAPI[network],
5505
- faucet: NetworkToFaucetAPI[network],
5506
- indexer: NetworkToIndexerAPI[network],
5507
- pepper: NetworkToPepperAPI[network],
5508
- prover: NetworkToProverAPI[network]
5509
- },
5510
- shelby_network: {
5511
- rpc_endpoint: NetworkToShelbyRPCBaseUrl[network]
5512
- }
5513
- };
5514
- }
5515
-
5516
- // src/utils/keys.ts
5517
- import {
5518
- Account,
5519
- AccountAddress as AccountAddress6,
5520
- Ed25519PrivateKey,
5521
- Secp256k1PrivateKey,
5522
- SigningSchemeInput
5523
- } from "@aptos-labs/ts-sdk";
5524
- function generateEd25519Account() {
5525
- const account = Account.generate({
5526
- scheme: SigningSchemeInput.Ed25519,
5527
- legacy: true
5528
- });
5529
- return account;
5530
- }
5531
- function isValidEd25519PrivateKey(value) {
5532
- try {
5533
- new Ed25519PrivateKey(value);
5534
- return true;
5535
- } catch {
5536
- return false;
5537
- }
5538
- }
5539
- function isValidAddress(address) {
5540
- return AccountAddress6.isValid({ input: address }).valid;
5541
- }
5542
- var SECP256K1_NAME = "secp256k1";
5543
- var ED25519_NAME = "ed25519";
5544
- function isValidScheme(scheme) {
5545
- return SECP256K1_NAME === scheme || ED25519_NAME === scheme;
5546
- }
5547
-
5548
- // tests/utils/mockConfig.ts
5549
- var mockAccounts = {
5550
- alice: generateEd25519Account(),
5551
- bob: generateEd25519Account()
5552
- };
5553
- var mockConfig = {
5554
- contexts: {
5555
- [Network5.SHELBYNET]: createContextForNetwork(Network5.SHELBYNET)
5556
- },
5557
- accounts: Object.fromEntries(
5558
- Object.entries(mockAccounts).map(([name, acc]) => [
5559
- name,
5560
- {
5561
- address: acc.accountAddress.toString(),
5562
- private_key: acc.privateKey.toAIP80String()
5563
- }
5564
- ])
5565
- ),
5566
- default_context: Network5.SHELBYNET,
5567
- default_account: Object.keys(mockAccounts)[0]
5568
- };
5569
-
5570
5495
  // src/schemas/AptosNetworkSchema.ts
5571
5496
  import { z as z4 } from "zod";
5572
5497
 
@@ -5597,19 +5522,45 @@ var ShelbyNetworkSchema = z5.object({
5597
5522
  });
5598
5523
 
5599
5524
  // src/utils/constants.ts
5600
- import { APTOS_COIN, Network as Network6 } from "@aptos-labs/ts-sdk";
5525
+ import { APTOS_COIN, Network as Network5 } from "@aptos-labs/ts-sdk";
5526
+
5527
+ // src/utils/context-helpers.ts
5528
+ import {
5529
+ NetworkToFaucetAPI,
5530
+ NetworkToIndexerAPI,
5531
+ NetworkToNodeAPI,
5532
+ NetworkToPepperAPI,
5533
+ NetworkToProverAPI
5534
+ } from "@aptos-labs/ts-sdk";
5535
+ function createContextForNetwork(network) {
5536
+ return {
5537
+ aptos_network: {
5538
+ name: network,
5539
+ fullnode: NetworkToNodeAPI[network],
5540
+ faucet: NetworkToFaucetAPI[network],
5541
+ indexer: NetworkToIndexerAPI[network],
5542
+ pepper: NetworkToPepperAPI[network],
5543
+ prover: NetworkToProverAPI[network]
5544
+ },
5545
+ shelby_network: {
5546
+ rpc_endpoint: NetworkToShelbyRPCBaseUrl[network]
5547
+ }
5548
+ };
5549
+ }
5550
+
5551
+ // src/utils/constants.ts
5601
5552
  var DEFAULT_CONFIG_PATH = "~/.shelby/config.yaml";
5602
5553
  var DEFAULT_CONFIG = {
5603
5554
  contexts: {
5604
- [Network6.LOCAL]: {
5605
- ...createContextForNetwork(Network6.LOCAL),
5555
+ [Network5.LOCAL]: {
5556
+ ...createContextForNetwork(Network5.LOCAL),
5606
5557
  // Override shelby_network for local
5607
5558
  shelby_network: { rpc_endpoint: "http://localhost:9090/" }
5608
5559
  },
5609
- [Network6.SHELBYNET]: createContextForNetwork(Network6.SHELBYNET)
5560
+ [Network5.SHELBYNET]: createContextForNetwork(Network5.SHELBYNET)
5610
5561
  },
5611
5562
  accounts: {},
5612
- default_context: Network6.SHELBYNET,
5563
+ default_context: Network5.SHELBYNET,
5613
5564
  default_account: ""
5614
5565
  };
5615
5566
  var STANDARD_CONTEXT_NAMES = Object.keys(DEFAULT_CONFIG.contexts).join(
@@ -5631,6 +5582,7 @@ var BALANCE_TARGETS = [
5631
5582
 
5632
5583
  // src/utils/config.ts
5633
5584
  var ContextSchema = z6.object({
5585
+ api_key: z6.string().optional(),
5634
5586
  aptos_network: AptosNetworkSchema,
5635
5587
  shelby_network: ShelbyNetworkSchema.optional()
5636
5588
  });
@@ -5666,9 +5618,9 @@ function loadConfig(configPath = DEFAULT_CONFIG_PATH) {
5666
5618
  const dir = path.dirname(resolvedPath);
5667
5619
  if (!fs.existsSync(resolvedPath)) {
5668
5620
  fs.mkdirpSync(dir);
5669
- const yamlText = YAML.stringify(mockConfig);
5621
+ const yamlText = YAML.stringify(DEFAULT_CONFIG);
5670
5622
  fs.writeFileSync(resolvedPath, yamlText, "utf8");
5671
- return mockConfig;
5623
+ return DEFAULT_CONFIG;
5672
5624
  }
5673
5625
  const raw = fs.readFileSync(resolvedPath, "utf8");
5674
5626
  let parsed;
@@ -5696,6 +5648,7 @@ function getCurrentContext(config, contextName) {
5696
5648
  throw new Error(`Context '${name}' not found in config`);
5697
5649
  }
5698
5650
  return {
5651
+ api_key: context.api_key,
5699
5652
  aptos_network: context.aptos_network,
5700
5653
  shelby_network: context.shelby_network
5701
5654
  };
@@ -5719,46 +5672,36 @@ function getCurrentAccount(config, accountName) {
5719
5672
  address: account.address,
5720
5673
  privateKey,
5721
5674
  account: new Ed25519Account({
5722
- privateKey: new Ed25519PrivateKey2(privateKey)
5675
+ privateKey: new Ed25519PrivateKey(privateKey)
5723
5676
  })
5724
5677
  };
5725
5678
  }
5726
- function getAptosFromNetwork(network) {
5727
- const { name, api_key, ...options } = network;
5728
- let config;
5729
- switch (name) {
5730
- case Network7.SHELBYNET:
5731
- case Network7.LOCAL:
5732
- config = new AptosConfig3({
5733
- network: NetworkToNetworkName[name],
5734
- clientConfig: { API_KEY: api_key },
5735
- ...options
5736
- });
5737
- break;
5738
- default:
5739
- config = new AptosConfig3({
5740
- network: Network7.CUSTOM,
5741
- clientConfig: { API_KEY: api_key },
5742
- ...options
5743
- });
5744
- break;
5745
- }
5746
- return new Aptos4(config);
5679
+ function getAptosSettingsFromContext(context) {
5680
+ const { name, api_key, ...options } = context.aptos_network;
5681
+ const activeApiKey = api_key || context.api_key;
5682
+ return {
5683
+ ...options,
5684
+ network: NetworkToNetworkName[name],
5685
+ clientConfig: { API_KEY: activeApiKey }
5686
+ };
5687
+ }
5688
+ function getAptosFromContext(context) {
5689
+ const config = getAptosSettingsFromContext(context);
5690
+ return new Aptos4(new AptosConfig3(config));
5747
5691
  }
5748
- function getShelbyClientConfigFromNetwork(network, options) {
5692
+ function getShelbyConfigFromContext(context) {
5693
+ const aptosSettings = getAptosSettingsFromContext(context);
5749
5694
  return {
5750
- network: options.aptosNetwork.name,
5751
- aptos: {
5752
- ...options.aptosNetwork,
5753
- network: NetworkToNetworkName[options.aptosNetwork.name]
5754
- },
5695
+ network: context.aptos_network.name,
5696
+ apiKey: context.api_key,
5697
+ aptos: aptosSettings,
5755
5698
  rpc: {
5756
- baseUrl: network.rpc_endpoint ?? NetworkToShelbyRPCBaseUrl[options.aptosNetwork.name],
5757
- apiKey: network.rpc_api_key
5699
+ baseUrl: context.shelby_network?.rpc_endpoint,
5700
+ apiKey: context.shelby_network?.rpc_api_key
5758
5701
  },
5759
5702
  indexer: {
5760
- baseUrl: network.indexer_endpoint ?? NetworkToShelbyBlobIndexerBaseUrl[options.aptosNetwork.name],
5761
- apiKey: network.indexer_api_key ?? ""
5703
+ baseUrl: context.shelby_network?.indexer_endpoint,
5704
+ apiKey: context.shelby_network?.indexer_api_key
5762
5705
  }
5763
5706
  };
5764
5707
  }
@@ -5770,18 +5713,58 @@ function getCurrentShelbyConfig(config, opts = { context: config.default_context
5770
5713
  `Context '${context ?? config.default_context}' not found in config`
5771
5714
  );
5772
5715
  }
5773
- const shelby = getShelbyClientConfigFromNetwork(
5774
- selectedContext.shelby_network ?? {},
5775
- { aptosNetwork: selectedContext.aptos_network }
5776
- );
5716
+ const shelby = getShelbyConfigFromContext(selectedContext);
5777
5717
  return shelby;
5778
5718
  }
5779
5719
 
5720
+ // src/utils/account.ts
5721
+ function validateAccountName(name, config) {
5722
+ const parsed = AccountNameSchema.safeParse(name);
5723
+ if (!parsed.success || name.length === 0) {
5724
+ return parsed.error?.errors[0]?.message || "Account name must be a non-empty string containing only letters, numbers, underscores, or hyphens.";
5725
+ }
5726
+ if (config?.accounts[name]) {
5727
+ return `Account '${name}' already exists. Choose a different name.`;
5728
+ }
5729
+ return void 0;
5730
+ }
5731
+
5732
+ // src/utils/keys.ts
5733
+ import {
5734
+ Account,
5735
+ AccountAddress as AccountAddress6,
5736
+ Ed25519PrivateKey as Ed25519PrivateKey2,
5737
+ Secp256k1PrivateKey,
5738
+ SigningSchemeInput
5739
+ } from "@aptos-labs/ts-sdk";
5740
+ import { z as z7 } from "zod";
5741
+ function generateEd25519Account() {
5742
+ const account = Account.generate({
5743
+ scheme: SigningSchemeInput.Ed25519,
5744
+ legacy: true
5745
+ });
5746
+ return account;
5747
+ }
5748
+ function isValidEd25519PrivateKey(value) {
5749
+ try {
5750
+ new Ed25519PrivateKey2(value);
5751
+ return true;
5752
+ } catch {
5753
+ return false;
5754
+ }
5755
+ }
5756
+ function isValidAddress(address) {
5757
+ return AccountAddress6.isValid({ input: address }).valid;
5758
+ }
5759
+ var ED25519_NAME = "ed25519";
5760
+ var SignatureSchemeSchema = z7.enum([ED25519_NAME]);
5761
+
5780
5762
  // src/components/AccountWizard.tsx
5781
5763
  import { jsx, jsxs } from "react/jsx-runtime";
5782
5764
  var AccountWizard = ({
5783
5765
  onComplete,
5784
- initialName
5766
+ initialName,
5767
+ config
5785
5768
  }) => {
5786
5769
  const [step, setStep] = useState(
5787
5770
  initialName ? "address" : "name"
@@ -5808,21 +5791,17 @@ var AccountWizard = ({
5808
5791
  value: name,
5809
5792
  onChange: (value) => {
5810
5793
  setName(value);
5811
- const result = AccountNameSchema.safeParse(value);
5812
- if (!result.success) {
5813
- setNameError(result.error.errors[0]?.message || "Invalid name");
5814
- } else {
5815
- setNameError(null);
5816
- }
5794
+ const error = validateAccountName(value, config);
5795
+ setNameError(error || null);
5817
5796
  },
5818
5797
  onSubmit: () => {
5819
- const result = AccountNameSchema.safeParse(name);
5820
- if (!result.success) {
5821
- setNameError(result.error.errors[0]?.message || "Invalid name");
5822
- } else {
5823
- setNameError(null);
5824
- setStep("address");
5798
+ const error = validateAccountName(name, config);
5799
+ if (error) {
5800
+ setNameError(error);
5801
+ return;
5825
5802
  }
5803
+ setNameError(null);
5804
+ setStep("address");
5826
5805
  }
5827
5806
  }
5828
5807
  ),
@@ -6006,7 +5985,7 @@ var SHELBY_CONFIG_FIELDS = [
6006
5985
  import { Box as Box3, Text as Text3 } from "ink";
6007
5986
  import TextInput2 from "ink-text-input";
6008
5987
  import { useState as useState2 } from "react";
6009
- import z7 from "zod";
5988
+ import z8 from "zod";
6010
5989
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
6011
5990
  function FormTextInput({
6012
5991
  type,
@@ -6036,7 +6015,7 @@ function FormTextInput({
6036
6015
  return;
6037
6016
  }
6038
6017
  if (value2) {
6039
- if (type === "url" && !z7.string().url().safeParse(value2).success) {
6018
+ if (type === "url" && !z8.string().url().safeParse(value2).success) {
6040
6019
  setError("The field must be a valid URL");
6041
6020
  return;
6042
6021
  }
@@ -6053,21 +6032,28 @@ function FormTextInput({
6053
6032
  // src/components/ContextReviewWizard.tsx
6054
6033
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
6055
6034
  var ContextReviewWizard = ({
6035
+ initialApiKey,
6056
6036
  initialAptosNetwork,
6057
6037
  initialShelbyNetwork,
6058
6038
  onComplete
6059
6039
  }) => {
6060
6040
  const [step, setStep] = useState3("review");
6061
6041
  const [fieldEditorInput, setFieldEditorInput] = useState3("");
6042
+ const [apiKey, setApiKey] = useState3(initialApiKey || "");
6062
6043
  const [aptosNetwork, setAptosNetwork] = useState3(initialAptosNetwork);
6063
6044
  const [shelbyNetwork, setShelbyNetwork] = useState3(initialShelbyNetwork);
6064
6045
  useEffect2(() => {
6065
6046
  if (step === "done") {
6066
- onComplete({ aptosNetwork, shelbyNetwork });
6047
+ onComplete({
6048
+ apiKey: apiKey || void 0,
6049
+ aptosNetwork,
6050
+ shelbyNetwork
6051
+ });
6067
6052
  }
6068
- }, [step, aptosNetwork, shelbyNetwork, onComplete]);
6053
+ }, [step, apiKey, aptosNetwork, shelbyNetwork, onComplete]);
6069
6054
  const formatFieldDisplay = (display) => !display ? "(not set)" : display.source === "current" ? `(current: ${display.value})` : `(default: ${display.value})`;
6070
- const getShelbyFieldDisplayValue = (key) => {
6055
+ const formatApiKeyDisplay = (key) => key ? `(current: ${key})` : "(not set)";
6056
+ const getShelbyFieldDisplay = (key) => {
6071
6057
  const value = shelbyNetwork[key];
6072
6058
  if (value && value !== "") {
6073
6059
  return { value, source: "current" };
@@ -6106,11 +6092,17 @@ var ContextReviewWizard = ({
6106
6092
  SelectInput2,
6107
6093
  {
6108
6094
  items: [
6095
+ { label: "API Key", value: "api-key" },
6109
6096
  { label: "Shelby Config", value: "shelby" },
6110
6097
  { label: "Aptos Config", value: "aptos" },
6111
6098
  { label: "Finish Setup \u2714", value: "finish" }
6112
6099
  ],
6113
6100
  onSelect: (item) => {
6101
+ if (item.value === "api-key") {
6102
+ setFieldEditorInput(apiKey);
6103
+ setStep("api-key-edit");
6104
+ return;
6105
+ }
6114
6106
  if (item.value === "shelby") {
6115
6107
  setStep("shelby-config-options");
6116
6108
  return;
@@ -6125,9 +6117,13 @@ var ContextReviewWizard = ({
6125
6117
  ),
6126
6118
  /* @__PURE__ */ jsxs4(Box4, { marginTop: 1, flexDirection: "column", children: [
6127
6119
  /* @__PURE__ */ jsx5(Text4, { color: "gray", children: "Current settings" }),
6120
+ /* @__PURE__ */ jsxs4(Text4, { children: [
6121
+ "API Key: ",
6122
+ formatApiKeyDisplay(apiKey)
6123
+ ] }),
6128
6124
  /* @__PURE__ */ jsx5(Text4, { children: "Shelby Config:" }),
6129
6125
  SHELBY_CONFIG_FIELDS.map((field) => {
6130
- const display = getShelbyFieldDisplayValue(field.key);
6126
+ const display = getShelbyFieldDisplay(field.key);
6131
6127
  if (!display) return null;
6132
6128
  return /* @__PURE__ */ jsx5(
6133
6129
  Text4,
@@ -6152,6 +6148,24 @@ var ContextReviewWizard = ({
6152
6148
  ] })
6153
6149
  ] });
6154
6150
  }
6151
+ if (step === "api-key-edit") {
6152
+ return /* @__PURE__ */ jsx5(
6153
+ FormTextInput,
6154
+ {
6155
+ title: "Edit API Key",
6156
+ description: `Current value: ${formatApiKeyDisplay(apiKey)}`,
6157
+ required: false,
6158
+ value: fieldEditorInput,
6159
+ placeholder: "Enter API key (optional)",
6160
+ onChange: setFieldEditorInput,
6161
+ onSubmit: (value) => {
6162
+ setApiKey(value);
6163
+ setFieldEditorInput("");
6164
+ setStep("review");
6165
+ }
6166
+ }
6167
+ );
6168
+ }
6155
6169
  if (step === "shelby-config-options") {
6156
6170
  return /* @__PURE__ */ jsx5(
6157
6171
  FormSelectInput,
@@ -6161,7 +6175,7 @@ var ContextReviewWizard = ({
6161
6175
  items: [
6162
6176
  ...SHELBY_CONFIG_FIELDS.map((field) => ({
6163
6177
  label: `${field.label} ${formatFieldDisplay(
6164
- getShelbyFieldDisplayValue(field.key)
6178
+ getShelbyFieldDisplay(field.key)
6165
6179
  )}`,
6166
6180
  value: field.key
6167
6181
  })),
@@ -6186,7 +6200,7 @@ var ContextReviewWizard = ({
6186
6200
  const key = step.replace("shelby-config-edit-", "");
6187
6201
  const field = SHELBY_CONFIG_FIELDS.find((f) => f.key === key);
6188
6202
  if (!field) return null;
6189
- const currentValue = getShelbyFieldDisplayValue(key);
6203
+ const currentValue = getShelbyFieldDisplay(key);
6190
6204
  if (field.type !== "text") return null;
6191
6205
  return /* @__PURE__ */ jsx5(
6192
6206
  FormTextInput,
@@ -6303,6 +6317,7 @@ var CreateContextWizard = ({
6303
6317
  }) => {
6304
6318
  const [step, setStep] = useState4("name");
6305
6319
  const [name, setName] = useState4("");
6320
+ const [apiKey, setApiKey] = useState4("");
6306
6321
  const [shelbyNetwork, setShelbyNetwork] = useState4(
6307
6322
  {}
6308
6323
  );
@@ -6313,10 +6328,11 @@ var CreateContextWizard = ({
6313
6328
  const validatedShelbyNetwork = ShelbyNetworkSchema.parse(shelbyNetwork);
6314
6329
  onComplete({
6315
6330
  name,
6331
+ apiKey: apiKey || void 0,
6316
6332
  shelbyNetwork: validatedShelbyNetwork,
6317
6333
  aptosNetwork: validatedAptosNetwork
6318
6334
  });
6319
- }, [step, name, shelbyNetwork, aptosNetwork, onComplete]);
6335
+ }, [step, name, apiKey, shelbyNetwork, aptosNetwork, onComplete]);
6320
6336
  if (step === "name") {
6321
6337
  return /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", children: [
6322
6338
  /* @__PURE__ */ jsx6(Text5, { children: "Context name?" }),
@@ -6327,6 +6343,22 @@ var CreateContextWizard = ({
6327
6343
  required: true,
6328
6344
  value: name,
6329
6345
  onChange: setName,
6346
+ onSubmit: () => setStep("api-key")
6347
+ }
6348
+ )
6349
+ ] });
6350
+ }
6351
+ if (step === "api-key") {
6352
+ return /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", children: [
6353
+ /* @__PURE__ */ jsx6(Text5, { children: "API Key (optional)?" }),
6354
+ /* @__PURE__ */ jsx6(Text5, { color: "gray", children: "Enter an API key to use as default for this context, or press Enter to skip." }),
6355
+ /* @__PURE__ */ jsx6(
6356
+ FormTextInput,
6357
+ {
6358
+ placeholder: "Enter API key (optional)",
6359
+ required: false,
6360
+ value: apiKey,
6361
+ onChange: setApiKey,
6330
6362
  onSubmit: () => setStep("aptos-network-name")
6331
6363
  }
6332
6364
  )
@@ -6351,9 +6383,11 @@ var CreateContextWizard = ({
6351
6383
  return /* @__PURE__ */ jsx6(
6352
6384
  ContextReviewWizard,
6353
6385
  {
6386
+ initialApiKey: apiKey,
6354
6387
  initialAptosNetwork: aptosNetwork,
6355
6388
  initialShelbyNetwork: shelbyNetwork,
6356
- onComplete: ({ aptosNetwork: aptosNetwork2, shelbyNetwork: shelbyNetwork2 }) => {
6389
+ onComplete: ({ apiKey: newApiKey, aptosNetwork: aptosNetwork2, shelbyNetwork: shelbyNetwork2 }) => {
6390
+ setApiKey(newApiKey || "");
6357
6391
  setAptosNetwork(aptosNetwork2);
6358
6392
  setShelbyNetwork(shelbyNetwork2);
6359
6393
  setStep("done");
@@ -6369,7 +6403,7 @@ import { useState as useState5 } from "react";
6369
6403
  import { jsx as jsx7 } from "react/jsx-runtime";
6370
6404
 
6371
6405
  // src/components/InitWizard.tsx
6372
- import { Network as Network8 } from "@aptos-labs/ts-sdk";
6406
+ import { Account as Account2, Ed25519PrivateKey as Ed25519PrivateKey3, Network as Network6 } from "@aptos-labs/ts-sdk";
6373
6407
  import { Box as Box6, Text as Text6 } from "ink";
6374
6408
  import SelectInput3 from "ink-select-input";
6375
6409
  import Spinner from "ink-spinner";
@@ -6814,27 +6848,34 @@ function getAptosCliVersionInfo(minVersion = MIN_APTOS_CLI_VERSION) {
6814
6848
 
6815
6849
  // src/components/InitWizard.tsx
6816
6850
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
6817
- var InitWizard = ({ existingConfig, onComplete }) => {
6851
+ var InitWizard = ({
6852
+ existingConfig,
6853
+ onComplete,
6854
+ onCancel
6855
+ }) => {
6818
6856
  const [step, setStep] = useState6(
6819
6857
  existingConfig ? "confirmOverwrite" : "checkAptos"
6820
6858
  );
6859
+ const [overwriteExisting, setOverwriteExisting] = useState6(false);
6821
6860
  const [aptosCliMeetsRequirement, setAptosCliMeetsRequirement] = useState6(false);
6822
6861
  const [aptosCliVersion, setAptosCliVersion] = useState6(null);
6823
6862
  const [setupStandardContexts, setSetupStandardContexts] = useState6(false);
6824
6863
  const [setupCustomContext, setSetupCustomContext] = useState6(false);
6825
6864
  const [customContextName, setCustomContextName] = useState6(
6826
- Network8.SHELBYNET
6865
+ Network6.SHELBYNET
6827
6866
  );
6828
6867
  const [shelbyRpcEndpoint, setShelbyRpcEndpoint] = useState6(
6829
- NetworkToShelbyRPCBaseUrl[Network8.SHELBYNET]
6868
+ NetworkToShelbyRPCBaseUrl[Network6.SHELBYNET]
6830
6869
  );
6831
- const [aptosNetwork, setAptosNetwork] = useState6(Network8.SHELBYNET);
6870
+ const [aptosNetwork, setAptosNetwork] = useState6(Network6.SHELBYNET);
6871
+ const [standardContextsApiKey, setStandardContextsApiKey] = useState6("");
6872
+ const [customContextApiKey, setCustomContextApiKey] = useState6("");
6832
6873
  const [setupAccount, setSetupAccount] = useState6(false);
6833
6874
  const [accountName, setAccountName] = useState6("alice");
6834
6875
  const [accountNameError, setAccountNameError] = useState6("");
6835
6876
  const [signatureScheme, setSignatureScheme] = useState6("ed25519");
6836
6877
  const [privateKey, setPrivateKey] = useState6("");
6837
- const [address, _setAddress] = useState6("");
6878
+ const [address, setAddress] = useState6("");
6838
6879
  const [generatedKey, setGeneratedKey] = useState6("");
6839
6880
  const [generatedAddress, setGeneratedAddress] = useState6("");
6840
6881
  useEffect4(() => {
@@ -6847,12 +6888,13 @@ var InitWizard = ({ existingConfig, onComplete }) => {
6847
6888
  }, [step]);
6848
6889
  useEffect4(() => {
6849
6890
  if (step === "complete") {
6850
- const config = existingConfig ? { ...existingConfig } : {
6891
+ const shouldStartFresh = overwriteExisting || !existingConfig;
6892
+ const config = shouldStartFresh ? {
6851
6893
  contexts: {},
6852
6894
  accounts: {},
6853
6895
  default_context: setupStandardContexts ? DEFAULT_CONFIG.default_context : customContextName,
6854
- default_account: setupAccount ? accountName : "default_account"
6855
- };
6896
+ default_account: setupAccount ? accountName : ""
6897
+ } : { ...existingConfig };
6856
6898
  if (setupStandardContexts || setupCustomContext) {
6857
6899
  config.default_context = setupStandardContexts ? DEFAULT_CONFIG.default_context : customContextName;
6858
6900
  }
@@ -6860,10 +6902,20 @@ var InitWizard = ({ existingConfig, onComplete }) => {
6860
6902
  config.default_account = accountName;
6861
6903
  }
6862
6904
  if (setupStandardContexts) {
6863
- config.contexts = { ...config.contexts, ...DEFAULT_CONFIG.contexts };
6905
+ const modifiedStandardContexts = { ...DEFAULT_CONFIG.contexts };
6906
+ if (standardContextsApiKey) {
6907
+ Object.keys(modifiedStandardContexts).forEach((contextName) => {
6908
+ modifiedStandardContexts[contextName] = {
6909
+ ...modifiedStandardContexts[contextName],
6910
+ api_key: standardContextsApiKey
6911
+ };
6912
+ });
6913
+ }
6914
+ config.contexts = modifiedStandardContexts;
6864
6915
  }
6865
6916
  if (setupCustomContext) {
6866
6917
  config.contexts[customContextName] = {
6918
+ api_key: customContextApiKey || void 0,
6867
6919
  aptos_network: {
6868
6920
  name: aptosNetwork
6869
6921
  },
@@ -6894,9 +6946,14 @@ var InitWizard = ({ existingConfig, onComplete }) => {
6894
6946
  ],
6895
6947
  onSelect: (item) => {
6896
6948
  if (item.value) {
6949
+ setOverwriteExisting(true);
6897
6950
  setStep("checkAptos");
6898
6951
  } else {
6899
- process.exit(0);
6952
+ if (onCancel) {
6953
+ onCancel();
6954
+ } else {
6955
+ process.exit(0);
6956
+ }
6900
6957
  }
6901
6958
  }
6902
6959
  }
@@ -6942,12 +6999,41 @@ var InitWizard = ({ existingConfig, onComplete }) => {
6942
6999
  ],
6943
7000
  onSelect: (item) => {
6944
7001
  setSetupStandardContexts(item.value);
6945
- setStep("customContext");
7002
+ if (item.value) {
7003
+ setStep("standardContextsApiKey");
7004
+ } else {
7005
+ setStep("customContext");
7006
+ }
6946
7007
  }
6947
7008
  }
6948
7009
  )
6949
7010
  ] });
6950
7011
  }
7012
+ if (step === "standardContextsApiKey") {
7013
+ return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
7014
+ /* @__PURE__ */ jsxs6(Text6, { children: [
7015
+ "\u2714 Checking for Aptos CLI >=v",
7016
+ MIN_APTOS_CLI_VERSION,
7017
+ "...",
7018
+ " ",
7019
+ aptosCliMeetsRequirement ? "found" : "not found"
7020
+ ] }),
7021
+ /* @__PURE__ */ jsxs6(Text6, { children: [
7022
+ "\u2714 Do you want to set up standard contexts (",
7023
+ STANDARD_CONTEXT_NAMES,
7024
+ ")? Yes"
7025
+ ] }),
7026
+ /* @__PURE__ */ jsx8(Text6, { children: "API Key? (optional: leave blank to skip)" }),
7027
+ /* @__PURE__ */ jsx8(
7028
+ TextInput3,
7029
+ {
7030
+ value: standardContextsApiKey,
7031
+ onChange: setStandardContextsApiKey,
7032
+ onSubmit: () => setStep("customContext")
7033
+ }
7034
+ )
7035
+ ] });
7036
+ }
6951
7037
  if (step === "customContext") {
6952
7038
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
6953
7039
  /* @__PURE__ */ jsxs6(Text6, { children: [
@@ -6964,6 +7050,11 @@ var InitWizard = ({ existingConfig, onComplete }) => {
6964
7050
  " ",
6965
7051
  setupStandardContexts ? "Yes" : "No"
6966
7052
  ] }),
7053
+ setupStandardContexts && /* @__PURE__ */ jsxs6(Text6, { children: [
7054
+ "\u2714 API Key for standard contexts?",
7055
+ " ",
7056
+ standardContextsApiKey ? "Set" : "Not set"
7057
+ ] }),
6967
7058
  /* @__PURE__ */ jsx8(Text6, { children: "Do you want to set up a custom context?" }),
6968
7059
  /* @__PURE__ */ jsx8(
6969
7060
  SelectInput3,
@@ -7003,7 +7094,7 @@ var InitWizard = ({ existingConfig, onComplete }) => {
7003
7094
  ] });
7004
7095
  }
7005
7096
  if (step === "shelbyRpcEndpoint") {
7006
- const defaultRpcEndpoint = DEFAULT_CONFIG.contexts[Network8.SHELBYNET].shelby_network?.rpc_endpoint;
7097
+ const defaultRpcEndpoint = DEFAULT_CONFIG.contexts[Network6.SHELBYNET].shelby_network?.rpc_endpoint;
7007
7098
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
7008
7099
  /* @__PURE__ */ jsxs6(Text6, { children: [
7009
7100
  "\u2714 Context name? ",
@@ -7037,12 +7128,33 @@ var InitWizard = ({ existingConfig, onComplete }) => {
7037
7128
  items: shelbyNetworks.map((name) => ({ label: name, value: name })),
7038
7129
  onSelect: (item) => {
7039
7130
  setAptosNetwork(item.value);
7040
- setStep("setupAccount");
7131
+ setStep("customContextApiKey");
7041
7132
  }
7042
7133
  }
7043
7134
  )
7044
7135
  ] });
7045
7136
  }
7137
+ if (step === "customContextApiKey") {
7138
+ return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
7139
+ /* @__PURE__ */ jsxs6(Text6, { children: [
7140
+ "\u2714 Shelby RPC endpoint? ",
7141
+ shelbyRpcEndpoint
7142
+ ] }),
7143
+ /* @__PURE__ */ jsxs6(Text6, { children: [
7144
+ "\u2714 Aptos network? ",
7145
+ aptosNetwork
7146
+ ] }),
7147
+ /* @__PURE__ */ jsx8(Text6, { children: "API Key? (optional: leave blank to skip)" }),
7148
+ /* @__PURE__ */ jsx8(
7149
+ TextInput3,
7150
+ {
7151
+ value: customContextApiKey,
7152
+ onChange: setCustomContextApiKey,
7153
+ onSubmit: () => setStep("setupAccount")
7154
+ }
7155
+ )
7156
+ ] });
7157
+ }
7046
7158
  if (step === "setupAccount") {
7047
7159
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
7048
7160
  /* @__PURE__ */ jsx8(Text6, { children: "Create or update an account now?" }),
@@ -7132,6 +7244,10 @@ var InitWizard = ({ existingConfig, onComplete }) => {
7132
7244
  const newKey = generateEd25519Account();
7133
7245
  setGeneratedKey(newKey.privateKey.toAIP80String());
7134
7246
  setGeneratedAddress(newKey.accountAddress.toString());
7247
+ } else {
7248
+ const priv = new Ed25519PrivateKey3(privateKey);
7249
+ const key = Account2.fromPrivateKey({ privateKey: priv });
7250
+ setAddress(key.accountAddress.toString());
7135
7251
  }
7136
7252
  setStep("complete");
7137
7253
  }
@@ -7146,25 +7262,33 @@ var InitWizard = ({ existingConfig, onComplete }) => {
7146
7262
  import { useEffect as useEffect5, useState as useState7 } from "react";
7147
7263
  import { jsx as jsx9 } from "react/jsx-runtime";
7148
7264
  var UpdateContextWizard = ({
7265
+ currentApiKey,
7149
7266
  currentShelbyNetwork = {},
7150
7267
  currentAptosNetwork,
7151
7268
  onComplete
7152
7269
  }) => {
7153
7270
  const [step, setStep] = useState7("review");
7271
+ const [apiKey, setApiKey] = useState7(currentApiKey || "");
7154
7272
  const [shelbyNetwork, setShelbyNetwork] = useState7(currentShelbyNetwork);
7155
7273
  const [aptosNetwork, setAptosNetwork] = useState7(currentAptosNetwork);
7156
7274
  useEffect5(() => {
7157
7275
  if (step === "done") {
7158
- onComplete({ shelbyNetwork, aptosNetwork });
7276
+ onComplete({
7277
+ apiKey: apiKey || void 0,
7278
+ shelbyNetwork,
7279
+ aptosNetwork
7280
+ });
7159
7281
  }
7160
- }, [step, shelbyNetwork, aptosNetwork, onComplete]);
7282
+ }, [step, apiKey, shelbyNetwork, aptosNetwork, onComplete]);
7161
7283
  if (step === "review") {
7162
7284
  return /* @__PURE__ */ jsx9(
7163
7285
  ContextReviewWizard,
7164
7286
  {
7287
+ initialApiKey: apiKey,
7165
7288
  initialAptosNetwork: aptosNetwork,
7166
7289
  initialShelbyNetwork: shelbyNetwork,
7167
- onComplete: ({ aptosNetwork: aptosNetwork2, shelbyNetwork: shelbyNetwork2 }) => {
7290
+ onComplete: ({ apiKey: newApiKey, aptosNetwork: aptosNetwork2, shelbyNetwork: shelbyNetwork2 }) => {
7291
+ setApiKey(newApiKey || "");
7168
7292
  setAptosNetwork(aptosNetwork2);
7169
7293
  setShelbyNetwork(shelbyNetwork2);
7170
7294
  setStep("done");
@@ -7245,32 +7369,54 @@ var handleError = (error) => {
7245
7369
 
7246
7370
  // src/commands/account.tsx
7247
7371
  import { jsx as jsx10 } from "react/jsx-runtime";
7248
- var CreateAccountOptionsSchema = z8.object({
7249
- name: z8.string().optional(),
7250
- privateKey: z8.string().optional(),
7251
- address: z8.string().optional(),
7252
- scheme: z8.union([z8.literal(ED25519_NAME), z8.literal(SECP256K1_NAME)]).optional()
7372
+ var CreateAccountOptionsSchema = z9.object({
7373
+ name: z9.string().optional(),
7374
+ privateKey: z9.string().optional(),
7375
+ address: z9.string().optional(),
7376
+ scheme: SignatureSchemeSchema.optional()
7253
7377
  });
7254
- var ListAccountOptionsSchema = z8.object({});
7255
- var UseAccountOptionsSchema = z8.object({
7256
- accountName: z8.string()
7378
+ var allSchemes = SignatureSchemeSchema.options.join(", ");
7379
+ function askQuestion(question) {
7380
+ const rl = readline.createInterface({
7381
+ input: process.stdin,
7382
+ output: process.stdout
7383
+ });
7384
+ return new Promise((resolve3) => {
7385
+ rl.question(question, (answer) => {
7386
+ rl.close();
7387
+ resolve3(answer.trim());
7388
+ });
7389
+ });
7390
+ }
7391
+ async function promptForAccountName(config) {
7392
+ while (true) {
7393
+ const answer = await askQuestion("Enter a name for this account: ");
7394
+ const error = validateAccountName(answer, config);
7395
+ if (error) {
7396
+ console.error(`\u274C ${error}`);
7397
+ continue;
7398
+ }
7399
+ return answer;
7400
+ }
7401
+ }
7402
+ var ListAccountOptionsSchema = z9.object({});
7403
+ var UseAccountOptionsSchema = z9.object({
7404
+ accountName: z9.string()
7257
7405
  });
7258
- var DeleteAccountOptionsSchema = z8.object({
7259
- accountName: z8.string()
7406
+ var DeleteAccountOptionsSchema = z9.object({
7407
+ accountName: z9.string()
7260
7408
  });
7261
7409
  function accountCommand(program) {
7262
7410
  const account = program.command("account").description("Manage signing accounts (addresses & keys)");
7263
7411
  account.command("create").description("Create a new account").option("--name <account-name>", "Name of the account").option(
7264
- // '--scheme <signature-scheme: "secp256k1" | "ed25519">',
7265
- '--scheme <signature-scheme: "ed25519">',
7412
+ `--scheme <signature-scheme: "${SignatureSchemeSchema.Enum.ed25519}">`,
7266
7413
  "Signature scheme of the private key"
7267
7414
  ).option("--private-key <key>", "Raw private key").option(
7268
7415
  "--address <account-address>",
7269
7416
  "Aptos account address (hex-encoded)"
7270
- ).action((options) => {
7417
+ ).action(async (options) => {
7271
7418
  CreateAccountOptionsSchema.parse(options);
7272
7419
  const { name, privateKey, address, scheme } = options;
7273
- const allPresent = name && privateKey && address && scheme;
7274
7420
  const configPath = program.opts().configFile;
7275
7421
  let config;
7276
7422
  try {
@@ -7280,48 +7426,78 @@ function accountCommand(program) {
7280
7426
  `${err.message}. Please ensure you've first initialized the config by doing \`shelby init\``
7281
7427
  );
7282
7428
  }
7283
- if (allPresent) {
7284
- if (isValidAddress(address) && isValidEd25519PrivateKey(privateKey) && isValidScheme(scheme)) {
7285
- config.accounts[name] = {
7286
- private_key: privateKey
7287
- };
7288
- if (options.address) {
7289
- config.accounts[name].address = address;
7429
+ const targetName = options.name ?? null;
7430
+ if (privateKey && !scheme) {
7431
+ console.error(
7432
+ `\u274C --scheme is required when providing --private-key (currently only "${allSchemes}" is supported).`
7433
+ );
7434
+ process.exit(1);
7435
+ }
7436
+ if (scheme && !SignatureSchemeSchema.options.includes(scheme)) {
7437
+ console.error(
7438
+ `\u274C Unsupported signature scheme. Only "${allSchemes}" is supported.`
7439
+ );
7440
+ process.exit(1);
7441
+ }
7442
+ let finalName = targetName;
7443
+ if (privateKey && !finalName) {
7444
+ finalName = await promptForAccountName(config);
7445
+ }
7446
+ const canCreateFromFlags = Boolean(privateKey && finalName);
7447
+ if (canCreateFromFlags && privateKey && finalName) {
7448
+ if (!isValidEd25519PrivateKey(privateKey)) {
7449
+ throw new Error("Error invalid account address or private key");
7450
+ }
7451
+ let finalAddress = address ?? "";
7452
+ if (finalAddress) {
7453
+ if (!isValidAddress(finalAddress)) {
7454
+ throw new Error("Error invalid account address or private key");
7290
7455
  }
7291
7456
  } else {
7292
- throw new Error("Error invalid account address or private key");
7457
+ const edKey = new Ed25519PrivateKey4(privateKey);
7458
+ const derived = Account3.fromPrivateKey({ privateKey: edKey });
7459
+ finalAddress = derived.accountAddress.toString();
7460
+ }
7461
+ config.accounts[finalName] = {
7462
+ private_key: privateKey,
7463
+ address: finalAddress
7464
+ };
7465
+ if (!config.default_account) {
7466
+ config.default_account = finalName;
7293
7467
  }
7294
7468
  saveConfig(config, configPath);
7295
- console.log(`\u2705 Account '${name}' created successfully`);
7296
- } else {
7297
- try {
7298
- const { unmount } = render(
7299
- /* @__PURE__ */ jsx10(
7300
- AccountWizard,
7301
- {
7302
- initialName: name,
7303
- onComplete: ({
7304
- name: name2,
7305
- address: address2,
7306
- privateKey: privateKey2
7307
- }) => {
7308
- config.accounts[name2] = {
7309
- private_key: privateKey2,
7310
- address: address2
7311
- };
7312
- saveConfig(config, configPath);
7313
- console.log(
7314
- `\u2705 Account ${name2} saved to ${resolveConfigPath(configPath)}`
7315
- );
7316
- unmount();
7317
- }
7469
+ console.log(`\u2705 Account '${finalName}' created successfully`);
7470
+ console.log(` Address: ${finalAddress}`);
7471
+ return;
7472
+ }
7473
+ try {
7474
+ const { unmount } = render(
7475
+ /* @__PURE__ */ jsx10(
7476
+ AccountWizard,
7477
+ {
7478
+ initialName: name,
7479
+ config,
7480
+ onComplete: ({
7481
+ name: name2,
7482
+ address: address2,
7483
+ privateKey: privateKey2
7484
+ }) => {
7485
+ config.accounts[name2] = {
7486
+ private_key: privateKey2,
7487
+ address: address2
7488
+ };
7489
+ saveConfig(config, configPath);
7490
+ console.log(
7491
+ `\u2705 Account ${name2} saved to ${resolveConfigPath(configPath)}`
7492
+ );
7493
+ unmount();
7318
7494
  }
7319
- )
7320
- );
7321
- } catch (err) {
7322
- console.error(`Error listing accounts: ${err.message}`);
7323
- process.exit(1);
7324
- }
7495
+ }
7496
+ )
7497
+ );
7498
+ } catch (err) {
7499
+ console.error(`Error creating account: ${err.message}`);
7500
+ process.exit(1);
7325
7501
  }
7326
7502
  });
7327
7503
  account.command("list").description("List all accounts in a table view").action(() => {
@@ -7472,7 +7648,7 @@ function accountCommand(program) {
7472
7648
  const config = loadConfig(configPath);
7473
7649
  const contextName = globalOpts.context || config.default_context;
7474
7650
  const context = getCurrentContext(config, contextName);
7475
- const aptos = getAptosFromNetwork(context.aptos_network);
7651
+ const aptos = getAptosFromContext(context);
7476
7652
  const accountName = globalOpts.account || config.default_account;
7477
7653
  const accountInfo = getCurrentAccount(config, accountName);
7478
7654
  const targetAddress = resolveAccountAddress({
@@ -7564,18 +7740,18 @@ function accountCommand(program) {
7564
7740
  import * as fs2 from "fs";
7565
7741
  import * as fsP from "fs/promises";
7566
7742
  import { Readable } from "stream";
7567
- import { z as z9 } from "zod";
7568
- var CommitmentOptionsSchema = z9.object({
7569
- input: z9.string().nonempty("`--input` is required").refine(
7570
- async (path5) => {
7571
- const stat4 = await fsP.stat(path5);
7743
+ import { z as z10 } from "zod";
7744
+ var CommitmentOptionsSchema = z10.object({
7745
+ input: z10.string().nonempty("`--input` is required").refine(
7746
+ async (path6) => {
7747
+ const stat4 = await fsP.stat(path6);
7572
7748
  return stat4.isFile();
7573
7749
  },
7574
7750
  {
7575
7751
  message: "`--input` must be a file"
7576
7752
  }
7577
7753
  ),
7578
- output: z9.string().nonempty("`--output` is required")
7754
+ output: z10.string().nonempty("`--output` is required")
7579
7755
  });
7580
7756
  function commitmentCommand(program) {
7581
7757
  program.command("commitment <input> <output>").description(
@@ -7597,29 +7773,29 @@ function commitmentCommand(program) {
7597
7773
 
7598
7774
  // src/commands/context.tsx
7599
7775
  import { render as render2 } from "ink";
7600
- import { z as z11 } from "zod";
7776
+ import { z as z12 } from "zod";
7601
7777
 
7602
7778
  // src/utils/commands.ts
7603
- import z10 from "zod";
7604
- var AptosCommandOptionsSchema = z10.object({
7605
- aptosNetwork: z10.string().optional(),
7779
+ import z11 from "zod";
7780
+ var AptosCommandOptionsSchema = z11.object({
7781
+ aptosNetwork: z11.string().optional(),
7606
7782
  // predefined network name
7607
- aptosFullnode: z10.string().url().optional(),
7608
- aptosFaucet: z10.string().url().optional(),
7609
- aptosIndexer: z10.string().url().optional(),
7610
- aptosPepper: z10.string().url().optional(),
7611
- aptosProver: z10.string().url().optional(),
7612
- aptosApiKey: z10.string().optional()
7783
+ aptosFullnode: z11.string().url().optional(),
7784
+ aptosFaucet: z11.string().url().optional(),
7785
+ aptosIndexer: z11.string().url().optional(),
7786
+ aptosPepper: z11.string().url().optional(),
7787
+ aptosProver: z11.string().url().optional(),
7788
+ aptosApiKey: z11.string().optional()
7613
7789
  });
7614
7790
  var addAptosCommandOptions = (context) => context.option(
7615
7791
  "--aptos-network <network>",
7616
7792
  `Aptos network (${shelbyNetworks.join(", ")})`
7617
7793
  ).option("--aptos-fullnode <url>", "Aptos fullnode URL").option("--aptos-faucet <url>", "Aptos faucet URL").option("--aptos-indexer <url>", "Aptos indexer URL").option("--aptos-pepper <url>", "Aptos pepper URL").option("--aptos-prover <url>", "Aptos prover URL").option("--aptos-api-key <key>", "Aptos API key");
7618
- var ShelbyCommandOptionsSchema = z10.object({
7794
+ var ShelbyCommandOptionsSchema = z11.object({
7619
7795
  shelbyRpcEndpoint: EndpointSchema.optional(),
7620
7796
  shelbyIndexerEndpoint: EndpointSchema.optional(),
7621
- shelbyRpcApiKey: z10.string().optional(),
7622
- shelbyIndexerApiKey: z10.string().optional()
7797
+ shelbyRpcApiKey: z11.string().optional(),
7798
+ shelbyIndexerApiKey: z11.string().optional()
7623
7799
  });
7624
7800
  var addShelbyCommandOptions = (context) => context.option("--shelby-rpc-endpoint <url>", "Shelby RPC endpoint").option("--shelby-indexer-endpoint <url>", "Shelby indexer endpoint").option("--shelby-rpc-api-key <key>", "Shelby RPC API key").option("--shelby-indexer-api-key <key>", "Shelby indexer API key");
7625
7801
 
@@ -7656,8 +7832,8 @@ function getShelbyNetworkFromOptions(options) {
7656
7832
  indexer_api_key: options.shelbyIndexerApiKey
7657
7833
  };
7658
7834
  }
7659
- var CreateContextOptionsSchema = z11.object({ name: z11.string().optional() }).merge(AptosCommandOptionsSchema).merge(ShelbyCommandOptionsSchema);
7660
- var UpdateContextOptionsSchema = z11.object({}).merge(ShelbyCommandOptionsSchema).merge(AptosCommandOptionsSchema);
7835
+ var CreateContextOptionsSchema = z12.object({ name: z12.string().optional() }).merge(AptosCommandOptionsSchema).merge(ShelbyCommandOptionsSchema);
7836
+ var UpdateContextOptionsSchema = z12.object({}).merge(ShelbyCommandOptionsSchema).merge(AptosCommandOptionsSchema);
7661
7837
  function contextCommand(program) {
7662
7838
  const context = program.command("context").description("Manage network contexts (Shelby RPC & Aptos endpoints)");
7663
7839
  addShelbyCommandOptions(addAptosCommandOptions(context.command("create"))).description("Create a new context").option("--name <context-name>", "Name of the context").action((options) => {
@@ -7707,10 +7883,12 @@ function contextCommand(program) {
7707
7883
  {
7708
7884
  onComplete: ({
7709
7885
  name: name2,
7886
+ apiKey,
7710
7887
  shelbyNetwork: shelbyNetwork2,
7711
7888
  aptosNetwork: aptosNetwork2
7712
7889
  }) => {
7713
7890
  config.contexts[name2] = {
7891
+ api_key: apiKey,
7714
7892
  shelby_network: shelbyNetwork2,
7715
7893
  aptos_network: aptosNetwork2
7716
7894
  };
@@ -7772,10 +7950,12 @@ function contextCommand(program) {
7772
7950
  /* @__PURE__ */ jsx11(
7773
7951
  UpdateContextWizard,
7774
7952
  {
7953
+ currentApiKey: currentContext.api_key,
7775
7954
  currentShelbyNetwork: currentContext.shelby_network,
7776
7955
  currentAptosNetwork: currentContext.aptos_network,
7777
- onComplete: ({ shelbyNetwork: shelbyNetwork2, aptosNetwork: aptosNetwork2 }) => {
7956
+ onComplete: ({ apiKey, shelbyNetwork: shelbyNetwork2, aptosNetwork: aptosNetwork2 }) => {
7778
7957
  config.contexts[contextName] = {
7958
+ api_key: apiKey,
7779
7959
  shelby_network: {
7780
7960
  ...currentContext.shelby_network,
7781
7961
  ...shelbyNetwork2,
@@ -7819,8 +7999,6 @@ function contextCommand(program) {
7819
7999
  },
7820
8000
  { header: "Indexer", width: 40, shrinkPriority: "high" },
7821
8001
  { header: "Faucet", width: 40, shrinkPriority: "high" },
7822
- { header: "Pepper", width: 40, shrinkPriority: "low", minWidth: 8 },
7823
- { header: "Prover", width: 40, shrinkPriority: "low", minWidth: 8 },
7824
8002
  {
7825
8003
  header: "API Key",
7826
8004
  width: 15,
@@ -7828,7 +8006,7 @@ function contextCommand(program) {
7828
8006
  minWidth: 6
7829
8007
  }
7830
8008
  ],
7831
- padding: 25
8009
+ padding: 20
7832
8010
  });
7833
8011
  const { table: shelbyConfigTable, wrapCell: wrapShelbyCell } = createResponsiveTable({
7834
8012
  columns: [
@@ -7850,11 +8028,13 @@ function contextCommand(program) {
7850
8028
  ],
7851
8029
  padding: 18
7852
8030
  });
8031
+ const defaultContext = config.default_context;
8032
+ const formatName = (ctxName) => ctxName === defaultContext ? `${ctxName} (default)` : ctxName;
7853
8033
  for (const [ctxName, ctx] of Object.entries(config.contexts)) {
7854
8034
  const shelbyRow = [
7855
- ctxName,
7856
- ctx.shelby_network?.rpc_endpoint || "(default)",
7857
- ctx.shelby_network?.indexer_endpoint || "(default)",
8035
+ formatName(ctxName),
8036
+ ctx.shelby_network?.rpc_endpoint || "",
8037
+ ctx.shelby_network?.indexer_endpoint || "",
7858
8038
  ctx.shelby_network?.rpc_api_key || "",
7859
8039
  ctx.shelby_network?.indexer_api_key || ""
7860
8040
  ];
@@ -7862,13 +8042,11 @@ function contextCommand(program) {
7862
8042
  shelbyRow.map((cell, i) => wrapShelbyCell(cell, i))
7863
8043
  );
7864
8044
  const aptosRow = [
7865
- ctxName,
8045
+ formatName(ctxName),
7866
8046
  ctx.aptos_network.name,
7867
- ctx.aptos_network.fullnode || "(default)",
7868
- ctx.aptos_network.indexer || "(default)",
7869
- ctx.aptos_network.faucet || "(default)",
7870
- ctx.aptos_network.pepper || "(default)",
7871
- ctx.aptos_network.prover || "(default)",
8047
+ ctx.aptos_network.fullnode || "",
8048
+ ctx.aptos_network.indexer || "",
8049
+ ctx.aptos_network.faucet || "",
7872
8050
  ctx.aptos_network.api_key || ""
7873
8051
  ];
7874
8052
  aptosConfigTable.push(
@@ -7930,16 +8108,16 @@ import * as path3 from "path";
7930
8108
  import { Readable as Readable2, Transform } from "stream";
7931
8109
  import { pipeline } from "stream/promises";
7932
8110
  import ora from "ora";
7933
- import { z as z12 } from "zod";
8111
+ import { z as z13 } from "zod";
7934
8112
  var denormBlobName2 = (a, b, c) => denormBlobName(path3, a, b, c);
7935
8113
  var endsWithDirectorySeparator = (filePath) => {
7936
8114
  return filePath.endsWith("/") || filePath.endsWith("\\") || filePath.endsWith(path3.sep);
7937
8115
  };
7938
- var DownloadOptionsSchema = z12.object({
7939
- src: z12.string().min(1, "`src`must be a valid blob name or directory prefix").describe("Blob name or directory prefix to download"),
7940
- dst: z12.string().min(1, "`dst` must be a valid filepath").describe("Local path where to save the downloaded content"),
7941
- recursive: z12.boolean().default(false).describe("Download assuming canonical directory layout and recurse"),
7942
- force: z12.boolean().default(false).describe("Overwrite the dst if it already exists")
8116
+ var DownloadOptionsSchema = z13.object({
8117
+ src: z13.string().min(1, "`src`must be a valid blob name or directory prefix").describe("Blob name or directory prefix to download"),
8118
+ dst: z13.string().min(1, "`dst` must be a valid filepath").describe("Local path where to save the downloaded content"),
8119
+ recursive: z13.boolean().default(false).describe("Download assuming canonical directory layout and recurse"),
8120
+ force: z13.boolean().default(false).describe("Overwrite the dst if it already exists")
7943
8121
  }).refine(
7944
8122
  (data) => {
7945
8123
  if (data.recursive) {
@@ -8179,12 +8357,12 @@ function downloadCommand(program) {
8179
8357
  }
8180
8358
 
8181
8359
  // src/commands/faucet.tsx
8182
- import { Network as Network9 } from "@aptos-labs/ts-sdk";
8360
+ import { Network as Network7 } from "@aptos-labs/ts-sdk";
8183
8361
  import { execaSync } from "execa";
8184
- import { z as z13 } from "zod";
8185
- var FaucetOptionsSchema = z13.object({
8186
- network: z13.enum([Network9.SHELBYNET]).optional(),
8187
- "no-open": z13.boolean().optional().default(false)
8362
+ import { z as z14 } from "zod";
8363
+ var FaucetOptionsSchema = z14.object({
8364
+ network: z14.enum([Network7.SHELBYNET]).optional(),
8365
+ "no-open": z14.boolean().optional().default(false)
8188
8366
  });
8189
8367
  function faucetCommand(program) {
8190
8368
  program.command("faucet").description("Open the Shelby faucet web page to request tokens").option("--network <network>", "Network to request tokens for (shelbynet)").option("--no-open", "Don't automatically open browser, just print the URL").action((options) => {
@@ -8194,7 +8372,7 @@ function faucetCommand(program) {
8194
8372
  const config = loadConfig(configPath);
8195
8373
  const accountName = program.opts().account || config.default_account;
8196
8374
  const { account } = getCurrentAccount(config, accountName);
8197
- const network = validatedOptions.network || Network9.SHELBYNET;
8375
+ const network = validatedOptions.network || Network7.SHELBYNET;
8198
8376
  if (network === "mainnet") {
8199
8377
  throw new Error(
8200
8378
  "\u274C No faucet available for mainnet. Mainnet tokens must be obtained through other means."
@@ -8255,28 +8433,20 @@ function openBrowser(url) {
8255
8433
  }
8256
8434
 
8257
8435
  // src/commands/init.tsx
8436
+ import path4 from "path";
8437
+ import fs4 from "fs-extra";
8258
8438
  import { render as render3 } from "ink";
8259
8439
  import { jsx as jsx12 } from "react/jsx-runtime";
8260
8440
  function initCommand(program) {
8261
8441
  program.command("init").description(
8262
8442
  "Bootstrap your Shelby config via an interactive wizard or flags"
8263
8443
  ).option(
8264
- "--setup-default-contexts",
8265
- `Create ${STANDARD_CONTEXT_NAMES} contexts`,
8444
+ "--setup-default",
8445
+ "Generate standard contexts and a fresh account",
8266
8446
  false
8267
- ).option("--context <name>", "Custom context name").option(
8268
- "--shelby-rpc-endpoint <url>",
8269
- "Shelby RPC endpoint for this context"
8270
- ).option(
8271
- "--aptos-api-endpoint <url>",
8272
- "Aptos REST API endpoint for this context"
8273
- ).option(
8274
- "--signature-scheme <scheme>",
8275
- // "Signature scheme (ed25519 or secp256k1)",
8276
- "Signature scheme (ed25519)",
8277
- ED25519_NAME
8278
- ).option("--private-key <key>", "Raw private key").action((options) => {
8447
+ ).action((options) => {
8279
8448
  const configPath = program.opts().configFile || "~/.shelby/config.yaml";
8449
+ const resolvedPath = resolveConfigPath(configPath);
8280
8450
  const accountName = program.opts().account;
8281
8451
  const hasExistingConfig = configExists(configPath);
8282
8452
  let existingConfigValid = false;
@@ -8285,104 +8455,112 @@ function initCommand(program) {
8285
8455
  loadConfig(configPath);
8286
8456
  existingConfigValid = true;
8287
8457
  } catch (_error) {
8288
- const resolvedPath = resolveConfigPath(configPath);
8458
+ const resolvedPath2 = resolveConfigPath(configPath);
8289
8459
  console.log(
8290
- `\u26A0\uFE0F Found existing config at ${resolvedPath} but it has an incompatible schema.`
8460
+ `\u26A0\uFE0F Found existing config at ${resolvedPath2} but it has an incompatible schema.`
8291
8461
  );
8292
8462
  console.log(
8293
8463
  "\u26A0\uFE0F The config will be overwritten with a new configuration.\n"
8294
8464
  );
8295
8465
  }
8296
8466
  }
8297
- if (options.setupDefaultContexts || options.context && options.shelbyRpcEndpoint && options.aptosNetwork) {
8298
- if (options.privateKey) {
8299
- const validation = AccountNameSchema.safeParse(accountName);
8300
- if (!validation.success) {
8301
- console.error(
8302
- `\u274C Invalid account name: ${validation.error.errors[0].message}`
8303
- );
8304
- process.exit(1);
8305
- }
8306
- }
8307
- let config;
8308
- if (existingConfigValid) {
8309
- config = loadConfig(configPath);
8310
- } else {
8311
- config = {
8312
- contexts: {},
8313
- accounts: {},
8314
- default_context: options.setupDefaultContexts ? DEFAULT_CONFIG.default_context : options.context,
8315
- default_account: accountName
8316
- };
8317
- }
8318
- if (options.setupDefaultContexts) {
8319
- config.contexts = DEFAULT_CONFIG.contexts;
8320
- }
8321
- if (options.context && options.shelbyRpcEndpoint && options.aptosNetwork) {
8322
- config.contexts[options.context] = {
8323
- aptos_network: options.aptosNetwork,
8324
- shelby_network: { rpc_endpoint: options.shelbyRpcEndpoint }
8325
- };
8326
- }
8327
- if (options.privateKey) {
8328
- config.accounts[accountName] = {
8329
- private_key: options.privateKey
8330
- };
8467
+ if (options.setupDefault) {
8468
+ if (configExists(configPath)) {
8469
+ console.error(
8470
+ `\u274C Refusing to overwrite existing config at ${resolvedPath}. Remove it first or run 'shelby init' interactively.`
8471
+ );
8472
+ process.exit(1);
8331
8473
  }
8474
+ const generated = generateEd25519Account();
8475
+ const finalAccountName = accountName ?? "default";
8476
+ const config = {
8477
+ contexts: cloneContexts(DEFAULT_CONFIG.contexts),
8478
+ accounts: {
8479
+ [finalAccountName]: {
8480
+ private_key: generated.privateKey.toAIP80String(),
8481
+ address: generated.accountAddress.toString()
8482
+ }
8483
+ },
8484
+ default_context: DEFAULT_CONFIG.default_context,
8485
+ default_account: finalAccountName
8486
+ };
8487
+ ensureConfigDir(resolvedPath);
8332
8488
  saveConfig(config, configPath);
8333
8489
  console.log(
8334
- `\u2705 Configuration saved to ${resolveConfigPath(configPath)}`
8490
+ `\u2705 Default Shelby configuration created at ${resolvedPath}`
8335
8491
  );
8336
- } else {
8337
- let existingConfig;
8338
- if (existingConfigValid) {
8339
- existingConfig = loadConfig(configPath);
8340
- }
8341
- const { unmount } = render3(
8342
- /* @__PURE__ */ jsx12(
8343
- InitWizard,
8344
- {
8345
- existingConfig,
8346
- onComplete: (config) => {
8347
- saveConfig(config, configPath);
8492
+ console.log(` Account name: ${finalAccountName}`);
8493
+ console.log(` Address: ${generated.accountAddress.toString()}`);
8494
+ console.log(` Private key: ${generated.privateKey.toAIP80String()}`);
8495
+ console.log("\n\u2139\uFE0F Fund the new account before performing uploads:");
8496
+ console.log(
8497
+ ` aptos init --profile ${finalAccountName} --assume-yes --private-key ${generated.privateKey.toAIP80String()} --network ${DEFAULT_CONFIG.default_context}`
8498
+ );
8499
+ console.log(
8500
+ ` aptos account fund-with-faucet --profile ${finalAccountName}`
8501
+ );
8502
+ return;
8503
+ }
8504
+ let existingConfigInstance;
8505
+ if (existingConfigValid) {
8506
+ existingConfigInstance = loadConfig(configPath);
8507
+ }
8508
+ const { unmount } = render3(
8509
+ /* @__PURE__ */ jsx12(
8510
+ InitWizard,
8511
+ {
8512
+ existingConfig: existingConfigInstance,
8513
+ onComplete: (config) => {
8514
+ ensureConfigDir(resolvedPath);
8515
+ saveConfig(config, configPath);
8516
+ console.log(`\u2705 Configuration saved to ${resolvedPath}`);
8517
+ if (config.default_account && config.accounts[config.default_account]?.private_key?.startsWith(
8518
+ "ed25519-priv-"
8519
+ )) {
8348
8520
  console.log(
8349
- `\u2705 Configuration saved to ${resolveConfigPath(configPath)}`
8521
+ "\n\u2139\uFE0F To fund your new account on-chain (shelbynet only):"
8522
+ );
8523
+ console.log(" 1. Import the private key into Aptos CLI:");
8524
+ console.log(
8525
+ ` aptos init --profile ${config.default_account} --private-key ${config.accounts[config.default_account].private_key} --network ${config.default_context}`
8526
+ );
8527
+ console.log(" 2. Run the faucet:");
8528
+ console.log(
8529
+ ` aptos account fund-with-faucet --profile ${config.default_account}`
8350
8530
  );
8351
- if (config.default_account && config.accounts[config.default_account]?.private_key?.startsWith("ed25519-priv-")) {
8352
- console.log(
8353
- "\n\u2139\uFE0F To fund your new account on-chain (shelbynet only):"
8354
- );
8355
- console.log(" 1. Import the private key into Aptos CLI:");
8356
- console.log(
8357
- ` aptos init --profile ${config.default_account} --private-key ${config.accounts[config.default_account].private_key} --network ${config.default_context}`
8358
- );
8359
- console.log(" 2. Run the faucet:");
8360
- console.log(
8361
- ` aptos account fund-with-faucet --profile ${config.default_account}`
8362
- );
8363
- }
8364
- unmount();
8365
- process.exit(0);
8366
8531
  }
8532
+ unmount();
8533
+ process.exit(0);
8534
+ },
8535
+ onCancel: () => {
8536
+ unmount();
8537
+ console.log("\u274C Init cancelled. Config file was not modified.");
8538
+ process.exit(0);
8367
8539
  }
8368
- )
8369
- );
8370
- }
8540
+ }
8541
+ )
8542
+ );
8371
8543
  });
8372
8544
  }
8545
+ function cloneContexts(contexts) {
8546
+ return JSON.parse(JSON.stringify(contexts));
8547
+ }
8548
+ function ensureConfigDir(resolvedPath) {
8549
+ fs4.mkdirpSync(path4.dirname(resolvedPath));
8550
+ }
8373
8551
 
8374
8552
  // src/commands/upload.tsx
8375
- import * as fs4 from "fs/promises";
8376
- import * as path4 from "path";
8553
+ import * as fs5 from "fs/promises";
8554
+ import * as path5 from "path";
8377
8555
  import { Aptos as Aptos5, AptosConfig as AptosConfig4 } from "@aptos-labs/ts-sdk";
8378
8556
  import { glob } from "glob";
8379
8557
  import { Box as Box7, render as render4, Text as Text7 } from "ink";
8380
8558
  import SelectInput4 from "ink-select-input";
8381
8559
  import ora2 from "ora";
8382
- import { z as z14 } from "zod";
8560
+ import { z as z15 } from "zod";
8383
8561
  import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
8384
- var normBlobName2 = (i, f, b) => normBlobName(path4, i, f, b);
8385
- var flexibleDateSchema = z14.string().transform((val) => {
8562
+ var normBlobName2 = (i, f, b) => normBlobName(path5, i, f, b);
8563
+ var flexibleDateSchema = z15.string().transform((val) => {
8386
8564
  if (/^\d+$/.test(val)) {
8387
8565
  const timestamp = Number.parseInt(val, 10);
8388
8566
  if (timestamp > 0 && timestamp < 4102444800) {
@@ -8395,18 +8573,18 @@ var flexibleDateSchema = z14.string().transform((val) => {
8395
8573
  }
8396
8574
  return ret;
8397
8575
  });
8398
- var UploadOptionsSchema = z14.object({
8399
- src: z14.string().nonempty("`src` positional arg is required"),
8400
- dst: z14.string().nonempty("`dst` position arg is required"),
8576
+ var UploadOptionsSchema = z15.object({
8577
+ src: z15.string().nonempty("`src` positional arg is required"),
8578
+ dst: z15.string().nonempty("`dst` position arg is required"),
8401
8579
  expiration: flexibleDateSchema,
8402
- recursive: z14.boolean().optional().default(false),
8403
- assumeYes: z14.boolean().optional().default(false),
8404
- outputCommitments: z14.string().optional()
8580
+ recursive: z15.boolean().optional().default(false),
8581
+ assumeYes: z15.boolean().optional().default(false),
8582
+ outputCommitments: z15.string().optional()
8405
8583
  }).superRefine(async (data, ctx) => {
8406
- const stats = await fs4.stat(data.src);
8584
+ const stats = await fs5.stat(data.src);
8407
8585
  if (!stats.isFile() && !stats.isDirectory()) {
8408
8586
  ctx.addIssue({
8409
- code: z14.ZodIssueCode.custom,
8587
+ code: z15.ZodIssueCode.custom,
8410
8588
  message: "`src` must be a file or a directory",
8411
8589
  path: ["src"]
8412
8590
  });
@@ -8415,7 +8593,7 @@ var UploadOptionsSchema = z14.object({
8415
8593
  if (stats.isDirectory()) {
8416
8594
  if (!data.dst.endsWith("/")) {
8417
8595
  ctx.addIssue({
8418
- code: z14.ZodIssueCode.custom,
8596
+ code: z15.ZodIssueCode.custom,
8419
8597
  message: "When src is a directory, dst must end with '/'",
8420
8598
  path: ["dst"]
8421
8599
  });
@@ -8424,7 +8602,7 @@ var UploadOptionsSchema = z14.object({
8424
8602
  const blobNameResult = BlobNameSchema.safeParse(data.dst);
8425
8603
  if (!blobNameResult.success) {
8426
8604
  ctx.addIssue({
8427
- code: z14.ZodIssueCode.custom,
8605
+ code: z15.ZodIssueCode.custom,
8428
8606
  message: "When src is a file, dst must be a valid blob name (cannot end with '/')",
8429
8607
  path: ["dst"]
8430
8608
  });
@@ -8432,7 +8610,7 @@ var UploadOptionsSchema = z14.object({
8432
8610
  }
8433
8611
  });
8434
8612
  async function createFilelist(options) {
8435
- const stats = await fs4.stat(options.src);
8613
+ const stats = await fs5.stat(options.src);
8436
8614
  if (stats.isFile()) {
8437
8615
  const blobname = normBlobName2(options.src, options.src, options.dst);
8438
8616
  const blobNameValidation = BlobNameSchema.safeParse(blobname);
@@ -8449,11 +8627,11 @@ async function createFilelist(options) {
8449
8627
  );
8450
8628
  }
8451
8629
  const fileList = [];
8452
- const result = await glob(path4.join(options.src, "**", "*"), {
8630
+ const result = await glob(path5.join(options.src, "**", "*"), {
8453
8631
  nodir: true
8454
8632
  });
8455
8633
  for await (const file of result) {
8456
- const stats2 = await fs4.stat(file);
8634
+ const stats2 = await fs5.stat(file);
8457
8635
  const blobname = normBlobName2(options.src, file, options.dst);
8458
8636
  const blobNameValidation = BlobNameSchema.safeParse(blobname);
8459
8637
  if (!blobNameValidation.success) {
@@ -8580,7 +8758,7 @@ function uploadCommand(program) {
8580
8758
  for (const entry of filelist) {
8581
8759
  spinner.text = `Reading ${entry.filename}.. (Overall: ${formatProgressPercent()}%, ${formatProgressRate()} MiB/s)`;
8582
8760
  try {
8583
- const blobData = await fs4.readFile(entry.filename);
8761
+ const blobData = await fs5.readFile(entry.filename);
8584
8762
  if (blobData.length !== entry.sizeBytes) {
8585
8763
  throw new Error(
8586
8764
  `Size of file ${entry.filename} changed after initial scan. Original size was ${entry.sizeBytes} but it is now ${blobData.length}`
@@ -8640,7 +8818,7 @@ function uploadCommand(program) {
8640
8818
  }
8641
8819
  }
8642
8820
  if (validatedOptions.outputCommitments) {
8643
- await fs4.writeFile(
8821
+ await fs5.writeFile(
8644
8822
  validatedOptions.outputCommitments,
8645
8823
  JSON.stringify(outputCommitments)
8646
8824
  );
@@ -8690,4 +8868,9 @@ function createProgram() {
8690
8868
  }
8691
8869
 
8692
8870
  // src/entry.ts
8693
- createProgram().parse(process.argv);
8871
+ function main() {
8872
+ const rawArgs = process.argv.slice(2);
8873
+ const normalizedArgs = rawArgs[0] === "--" ? rawArgs.slice(1) : rawArgs;
8874
+ createProgram().parse([process.argv[0], process.argv[1], ...normalizedArgs]);
8875
+ }
8876
+ main();