@beclab/olaresid 0.1.9 → 0.1.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.
package/CLI.md CHANGED
@@ -1259,7 +1259,51 @@ did-cli tag remove example.com premium
1259
1259
 
1260
1260
  ## Network Configuration
1261
1261
 
1262
- ### Mainnet (Default)
1262
+ ### Configuration File
1263
+
1264
+ All network settings are stored in `config.json` in the package directory. You can modify settings using CLI commands or by directly editing the file.
1265
+
1266
+ **Priority:** Command-line args > config file values
1267
+
1268
+ ### Configuration Commands
1269
+
1270
+ ```bash
1271
+ # Show configuration
1272
+ did-cli config show [--network mainnet|sepolia]
1273
+
1274
+ # List all networks
1275
+ did-cli config list
1276
+
1277
+ # Set configuration value (creates network if it doesn't exist)
1278
+ did-cli config set <key> <value> [--network <network>]
1279
+ # Keys: rpc, contractDid, contractRootResolver, contractAbiType,
1280
+ # contractRootResolver2, supportSvcUrl
1281
+ # Default network: mainnet
1282
+ ```
1283
+
1284
+ **Examples:**
1285
+
1286
+ ```bash
1287
+ # View mainnet config
1288
+ did-cli config show --network mainnet
1289
+
1290
+ # Update mainnet RPC (default network)
1291
+ did-cli config set rpc https://eth.llamarpc.com
1292
+
1293
+ # Update sepolia contract
1294
+ did-cli config set contractDid 0x1234... --network sepolia
1295
+
1296
+ # Add new network
1297
+ did-cli config set rpc https://my-rpc.com --network custom_net
1298
+ did-cli config set contractDid 0x5678... --network custom_net
1299
+
1300
+ # List all networks
1301
+ did-cli config list
1302
+ ```
1303
+
1304
+ ### Default Networks
1305
+
1306
+ #### Mainnet (Default)
1263
1307
 
1264
1308
  - RPC: `https://optimism-rpc.publicnode.com`
1265
1309
  - DID Contract: `0x5DA4Fa8E567d86e52Ef8Da860de1be8f54cae97D`
@@ -1268,11 +1312,11 @@ did-cli tag remove example.com premium
1268
1312
  - RootResolver2: `0x7e7961aB771cA942CE4DB6e79579e016a33Dc95B`
1269
1313
  - Support Service: `https://api.olares.com/did/support`
1270
1314
 
1271
- ### Sepolia Testnet
1315
+ #### Sepolia Testnet
1272
1316
 
1273
1317
  - RPC: `https://sepolia.optimism.io`
1274
1318
  - DID Contract: `0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8`
1275
- - RootResolver: `0xeF727cb066Fee98F88Db84555830063b4A24ddfc`
1319
+ - RootResolver: `0x8eEE5E6Ba315693149c687090042D41252442e84`
1276
1320
  - ABI Type: `0x7386fCBae6Ad4CCE1499d9153D99bc950B589718`
1277
1321
  - RootResolver2: `0xcbC02aa08c77a374eC0D5A0403E108b7573d96e8`
1278
1322
  - Support Service: `https://api-test.olares.com/did/support`
package/README.md CHANGED
@@ -107,6 +107,6 @@ After testing, feel free to submit a Pull Request!
107
107
 
108
108
  - **RPC:** https://sepolia.optimism.io
109
109
  - **DID Contract:** 0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8
110
- - **Root Resolver:** 0xeF727cb066Fee98F88Db84555830063b4A24ddfc
110
+ - **Root Resolver:** 0x8eEE5E6Ba315693149c687090042D41252442e84
111
111
  - **Root Resolver2:** 0xcbC02aa08c77a374eC0D5A0403E108b7573d96e8
112
112
  - **ABI Type:** 0x7386fCBae6Ad4CCE1499d9153D99bc950B589718
package/config.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "networks": {
3
+ "sepolia": {
4
+ "rpc": "https://sepolia.optimism.io",
5
+ "contractDid": "0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8",
6
+ "contractRootResolver": "0x8eEE5E6Ba315693149c687090042D41252442e84",
7
+ "contractAbiType": "0x7386fCBae6Ad4CCE1499d9153D99bc950B589718",
8
+ "contractRootResolver2": "0xcbC02aa08c77a374eC0D5A0403E108b7573d96e8",
9
+ "supportSvcUrl": "https://api-test.olares.com/did/support"
10
+ },
11
+ "mainnet": {
12
+ "rpc": "https://optimism-rpc.publicnode.com",
13
+ "contractDid": "0x5DA4Fa8E567d86e52Ef8Da860de1be8f54cae97D",
14
+ "contractRootResolver": "0xE2EABA0979277A90511F8873ae1e8cA26B54E740",
15
+ "contractAbiType": "0x9ae3F16bD99294Af1784beB1a0A5C84bf2636365",
16
+ "contractRootResolver2": "0x7e7961aB771cA942CE4DB6e79579e016a33Dc95B",
17
+ "supportSvcUrl": "https://api.olares.com/did/support"
18
+ }
19
+ }
20
+ }
package/dist/cli.js CHANGED
@@ -39,28 +39,11 @@ const debug_1 = require("./debug");
39
39
  const olares_id_1 = require("./utils/olares-id");
40
40
  const fs = __importStar(require("fs"));
41
41
  const path = __importStar(require("path"));
42
+ // Import config utilities
43
+ const config_1 = require("./config");
42
44
  // CLI Version - read from package.json
43
45
  const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
44
46
  const CLI_VERSION = packageJson.version;
45
- // 预设的网络配置
46
- const NETWORKS = {
47
- sepolia: {
48
- rpc: 'https://sepolia.optimism.io',
49
- contractDid: '0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8',
50
- contractRootResolver: '0xeF727cb066Fee98F88Db84555830063b4A24ddfc',
51
- contractAbiType: '0x7386fCBae6Ad4CCE1499d9153D99bc950B589718',
52
- contractRootResolver2: '0xcbC02aa08c77a374eC0D5A0403E108b7573d96e8',
53
- supportSvcUrl: 'https://api-test.olares.com/did/support'
54
- },
55
- mainnet: {
56
- rpc: 'https://optimism-rpc.publicnode.com',
57
- contractDid: '0x5DA4Fa8E567d86e52Ef8Da860de1be8f54cae97D',
58
- contractRootResolver: '0xE2EABA0979277A90511F8873ae1e8cA26B54E740',
59
- contractAbiType: '0x9ae3F16bD99294Af1784beB1a0A5C84bf2636365',
60
- contractRootResolver2: '0x7e7961aB771cA942CE4DB6e79579e016a33Dc95B',
61
- supportSvcUrl: 'https://api.olares.com/did/support'
62
- }
63
- };
64
47
  function parseArgs() {
65
48
  const args = process.argv.slice(2);
66
49
  const options = {
@@ -135,6 +118,9 @@ function parseArgs() {
135
118
  else if (arg === '--debug-level') {
136
119
  options.debugLevel = args[++i] || 'info';
137
120
  }
121
+ else if (arg === '--all') {
122
+ options.all = true;
123
+ }
138
124
  else if (!command) {
139
125
  command = arg;
140
126
  }
@@ -229,6 +215,15 @@ COMMANDS:
229
215
  Transfer contract ownership to new address (requires PRIVATE_KEY_OR_MNEMONIC)
230
216
  admin accept-ownership Accept pending ownership transfer (requires PRIVATE_KEY_OR_MNEMONIC)
231
217
 
218
+ Configuration Commands:
219
+ config show [--network <network>]
220
+ Show configuration for network (default: mainnet)
221
+ config list List all available networks
222
+ config set <key> <value> [--network <network>]
223
+ Set configuration value (default network: mainnet)
224
+ Keys: rpc, contractDid, contractRootResolver,
225
+ contractAbiType, contractRootResolver2, supportSvcUrl
226
+
232
227
  Crypto Utility Commands:
233
228
  crypto generate Generate a new mnemonic phrase (--words option)
234
229
  Saves to file, use --output to specify file path
@@ -383,6 +378,14 @@ EXAMPLES:
383
378
  did-cli admin transfer-ownership 0x5678...
384
379
  did-cli admin accept-ownership
385
380
 
381
+ # Configuration management
382
+ did-cli config show # Show mainnet config
383
+ did-cli config show --network sepolia # Show sepolia config
384
+ did-cli config list # List all networks
385
+ did-cli config set rpc https://optimism.llamarpc.com # Set mainnet RPC
386
+ did-cli config set contractDid 0x1234... --network sepolia # Set sepolia contract
387
+ did-cli config set rpc https://my-rpc.com --network custom_net # Create new network
388
+
386
389
  # Utilities
387
390
  did-cli convert pem-to-der ./public-key.pem
388
391
  did-cli convert ip-to-bytes 192.168.1.1
@@ -406,42 +409,33 @@ ENVIRONMENT VARIABLES:
406
409
  }
407
410
  async function fetchDomain(domain, options) {
408
411
  try {
409
- // 设置调试选项
412
+ // Set debug options
410
413
  if (options.verbose || options.debug) {
411
414
  debug_1.debug.enable();
412
415
  debug_1.debug.setLevel(options.debugLevel);
413
416
  }
414
- // 确定网络配置
415
- let config;
416
- if (options.rpc &&
417
- options.contractDid &&
418
- options.contractResolver &&
419
- options.contractAbi) {
420
- // 使用自定义配置
421
- config = {
422
- rpc: options.rpc,
423
- contractDid: options.contractDid,
424
- contractRootResolver: options.contractResolver,
425
- contractAbiType: options.contractAbi
426
- };
427
- }
428
- else if (NETWORKS[options.network]) {
429
- // 使用预设网络配置
430
- config = NETWORKS[options.network];
431
- }
432
- else {
417
+ // Get network configuration
418
+ const config = (0, config_1.getNetworkConfig)(options.network);
419
+ if (!config) {
433
420
  console.error(`❌ Unknown network: ${options.network}`);
434
- console.error('Available networks: sepolia, mainnet');
421
+ console.error('Available networks:', (0, config_1.getAvailableNetworks)().join(', '));
435
422
  process.exit(1);
436
423
  }
424
+ // Command line parameters take priority
425
+ const finalConfig = {
426
+ rpc: options.rpc || config.rpc,
427
+ contractDid: options.contractDid || config.contractDid,
428
+ contractRootResolver: options.contractResolver || config.contractRootResolver,
429
+ contractAbiType: options.contractAbi || config.contractAbiType
430
+ };
437
431
  if (debug_1.debug.isEnabled()) {
438
432
  debug_1.debug.info(`🔍 Fetching domain: ${domain}`);
439
433
  debug_1.debug.info(`🌐 Network: ${options.network}`);
440
- debug_1.debug.info('Using configuration:', config);
434
+ debug_1.debug.info('Using configuration:', finalConfig);
441
435
  }
442
- // 创建DID控制台实例
443
- const olaresId = index_1.default.createConsole(config.rpc, config.contractDid, config.contractRootResolver, config.contractAbiType);
444
- // 获取域名数据
436
+ // Create DID console instance
437
+ const olaresId = index_1.default.createConsole(finalConfig.rpc, finalConfig.contractDid, finalConfig.contractRootResolver, finalConfig.contractAbiType);
438
+ // Fetch domain data
445
439
  const domainData = await olaresId.fetchDomain(domain);
446
440
  if (!domainData) {
447
441
  console.log(`❌ Domain not found: ${domain}`);
@@ -461,28 +455,21 @@ async function fetchDomain(domain, options) {
461
455
  // Helper Functions
462
456
  // ============================================================================
463
457
  function getConsole(options) {
464
- let config;
465
- if (options.rpc &&
466
- options.contractDid &&
467
- options.contractResolver &&
468
- options.contractAbi &&
469
- options.contractRootResolver2 &&
470
- options.supportSvcUrl) {
471
- config = {
472
- rpc: options.rpc,
473
- contractDid: options.contractDid,
474
- contractRootResolver: options.contractResolver,
475
- contractAbiType: options.contractAbi,
476
- contractRootResolver2: options.contractRootResolver2,
477
- supportSvcUrl: options.supportSvcUrl
478
- };
479
- }
480
- else if (NETWORKS[options.network]) {
481
- config = NETWORKS[options.network];
482
- }
483
- else {
484
- throw new Error(`Unknown network: ${options.network}`);
485
- }
458
+ // Get network configuration (automatically loads from config file or uses defaults)
459
+ const networkConfig = (0, config_1.getNetworkConfig)(options.network);
460
+ if (!networkConfig) {
461
+ throw new Error(`Unknown network: ${options.network}. Available networks: ${(0, config_1.getAvailableNetworks)().join(', ')}`);
462
+ }
463
+ // Command line options override config file
464
+ const config = {
465
+ rpc: options.rpc || networkConfig.rpc,
466
+ contractDid: options.contractDid || networkConfig.contractDid,
467
+ contractRootResolver: options.contractResolver || networkConfig.contractRootResolver,
468
+ contractAbiType: options.contractAbi || networkConfig.contractAbiType,
469
+ contractRootResolver2: options.contractRootResolver2 ||
470
+ networkConfig.contractRootResolver2,
471
+ supportSvcUrl: options.supportSvcUrl || networkConfig.supportSvcUrl
472
+ };
486
473
  return index_1.default.createConsole(config.rpc, config.contractDid, config.contractRootResolver, config.contractAbiType, config.contractRootResolver2, config.supportSvcUrl);
487
474
  }
488
475
  function getPrivateKeyOrMnemonic() {
@@ -1508,6 +1495,114 @@ async function walletSolana(action, domain, options) {
1508
1495
  }
1509
1496
  }
1510
1497
  // ========================================
1498
+ // Configuration Management Commands
1499
+ // ========================================
1500
+ /**
1501
+ * Show network configuration
1502
+ */
1503
+ async function configShow(options) {
1504
+ try {
1505
+ const network = options.network;
1506
+ const networkConfig = (0, config_1.getNetworkConfig)(network);
1507
+ if (!networkConfig) {
1508
+ console.error(`❌ Unknown network: ${network}`);
1509
+ console.error('Available networks:', (0, config_1.getAvailableNetworks)().join(', '));
1510
+ process.exit(1);
1511
+ }
1512
+ if (options.json) {
1513
+ console.log(JSON.stringify(networkConfig, null, 2));
1514
+ }
1515
+ else {
1516
+ console.log(`\n📋 Network Configuration: ${network}\n`);
1517
+ console.log(` RPC: ${networkConfig.rpc}`);
1518
+ console.log(` Contract DID: ${networkConfig.contractDid}`);
1519
+ console.log(` Contract RootResolver: ${networkConfig.contractRootResolver}`);
1520
+ console.log(` Contract ABIType: ${networkConfig.contractAbiType}`);
1521
+ console.log(` Contract RootResolver2: ${networkConfig.contractRootResolver2}`);
1522
+ console.log(` Support Service URL: ${networkConfig.supportSvcUrl}`);
1523
+ console.log(`\n📄 Configuration file: ${(0, config_1.getConfigFilePath)()}`);
1524
+ }
1525
+ }
1526
+ catch (error) {
1527
+ console.error('❌ Error:', error instanceof Error ? error.message : String(error));
1528
+ process.exit(1);
1529
+ }
1530
+ }
1531
+ /**
1532
+ * List all available networks
1533
+ */
1534
+ async function configList(options) {
1535
+ try {
1536
+ const allNetworks = (0, config_1.getAvailableNetworks)();
1537
+ if (options.json) {
1538
+ console.log(JSON.stringify(allNetworks, null, 2));
1539
+ }
1540
+ else {
1541
+ console.log('\n📋 Available Networks:\n');
1542
+ allNetworks.forEach((net) => {
1543
+ console.log(` - ${net}`);
1544
+ });
1545
+ console.log(`\n📄 Configuration file: ${(0, config_1.getConfigFilePath)()}`);
1546
+ }
1547
+ }
1548
+ catch (error) {
1549
+ console.error('❌ Error:', error instanceof Error ? error.message : String(error));
1550
+ process.exit(1);
1551
+ }
1552
+ }
1553
+ /**
1554
+ * Set configuration value
1555
+ */
1556
+ async function configSet(key, value, options) {
1557
+ try {
1558
+ const network = options.network;
1559
+ const config = (0, config_1.loadConfig)();
1560
+ // Check if network exists, if not create it
1561
+ if (!config.networks[network]) {
1562
+ console.log(`\n📝 Creating new network: ${network}`);
1563
+ config.networks[network] = {
1564
+ rpc: '',
1565
+ contractDid: '',
1566
+ contractRootResolver: '',
1567
+ contractAbiType: '',
1568
+ contractRootResolver2: '',
1569
+ supportSvcUrl: ''
1570
+ };
1571
+ }
1572
+ // Validate key
1573
+ const validKeys = [
1574
+ 'rpc',
1575
+ 'contractDid',
1576
+ 'contractRootResolver',
1577
+ 'contractAbiType',
1578
+ 'contractRootResolver2',
1579
+ 'supportSvcUrl'
1580
+ ];
1581
+ if (!validKeys.includes(key)) {
1582
+ console.error(`❌ Invalid config key: ${key}`);
1583
+ console.error(`Valid keys: ${validKeys.join(', ')}`);
1584
+ process.exit(1);
1585
+ }
1586
+ // Update configuration
1587
+ config.networks[network][key] = value;
1588
+ // Save configuration
1589
+ (0, config_1.saveConfig)(config);
1590
+ if (options.json) {
1591
+ console.log(JSON.stringify({ success: true, network, key, value }, null, 2));
1592
+ }
1593
+ else {
1594
+ console.log(`\n✅ Configuration updated`);
1595
+ console.log(` Network: ${network}`);
1596
+ console.log(` ${key}: ${value}`);
1597
+ console.log(`\n📄 Saved to: ${(0, config_1.getConfigFilePath)()}`);
1598
+ }
1599
+ }
1600
+ catch (error) {
1601
+ console.error('❌ Error:', error instanceof Error ? error.message : String(error));
1602
+ process.exit(1);
1603
+ }
1604
+ }
1605
+ // ========================================
1511
1606
  // Tag Management Functions
1512
1607
  // ========================================
1513
1608
  /**
@@ -2071,6 +2166,43 @@ async function main() {
2071
2166
  process.exit(1);
2072
2167
  }
2073
2168
  break;
2169
+ // Configuration commands
2170
+ case 'config':
2171
+ if (!subCommand) {
2172
+ console.error('❌ Error: Config subcommand is required');
2173
+ console.error('Usage: did-cli config <show|list|set> [args]');
2174
+ process.exit(1);
2175
+ }
2176
+ switch (subCommand) {
2177
+ case 'show':
2178
+ await configShow(options);
2179
+ break;
2180
+ case 'list':
2181
+ await configList(options);
2182
+ break;
2183
+ case 'set': {
2184
+ // did-cli config set <key> <value> [--network <network>]
2185
+ const args = process.argv.slice(2);
2186
+ const setIdx = args.indexOf('set');
2187
+ if (setIdx >= 0 && args.length > setIdx + 2) {
2188
+ const key = args[setIdx + 1];
2189
+ const val = args[setIdx + 2];
2190
+ await configSet(key, val, options);
2191
+ }
2192
+ else {
2193
+ console.error('❌ Error: Usage: did-cli config set <key> <value> [--network <network>]');
2194
+ console.error(' Valid keys: rpc, contractDid, contractRootResolver, contractAbiType, contractRootResolver2, supportSvcUrl');
2195
+ console.error('\n Example: did-cli config set rpc https://optimism.llamarpc.com --network mainnet');
2196
+ process.exit(1);
2197
+ }
2198
+ break;
2199
+ }
2200
+ default:
2201
+ console.error(`❌ Unknown config subcommand: ${subCommand}`);
2202
+ console.error(' Valid subcommands: show, list, set');
2203
+ process.exit(1);
2204
+ }
2205
+ break;
2074
2206
  // Crypto utilities
2075
2207
  case 'crypto':
2076
2208
  if (!subCommand) {