@beclab/olaresid 0.1.1

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 (112) hide show
  1. package/LICENSE.md +49 -0
  2. package/README.md +93 -0
  3. package/dist/abi/ABITypeABI.d.ts +88 -0
  4. package/dist/abi/ABITypeABI.d.ts.map +1 -0
  5. package/dist/abi/ABITypeABI.js +382 -0
  6. package/dist/abi/ABITypeABI.js.map +1 -0
  7. package/dist/abi/RegistryABI.d.ts +77 -0
  8. package/dist/abi/RegistryABI.d.ts.map +1 -0
  9. package/dist/abi/RegistryABI.js +462 -0
  10. package/dist/abi/RegistryABI.js.map +1 -0
  11. package/dist/abi/RootResolverABI.d.ts +78 -0
  12. package/dist/abi/RootResolverABI.d.ts.map +1 -0
  13. package/dist/abi/RootResolverABI.js +372 -0
  14. package/dist/abi/RootResolverABI.js.map +1 -0
  15. package/dist/abi/TerminusDIDABI.d.ts +80 -0
  16. package/dist/abi/TerminusDIDABI.d.ts.map +1 -0
  17. package/dist/abi/TerminusDIDABI.js +1877 -0
  18. package/dist/abi/TerminusDIDABI.js.map +1 -0
  19. package/dist/cli.d.ts +3 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +199 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/debug.d.ts +46 -0
  24. package/dist/debug.d.ts.map +1 -0
  25. package/dist/debug.js +129 -0
  26. package/dist/debug.js.map +1 -0
  27. package/dist/domain/index.d.ts +59 -0
  28. package/dist/domain/index.d.ts.map +1 -0
  29. package/dist/domain/index.js +431 -0
  30. package/dist/domain/index.js.map +1 -0
  31. package/dist/index.d.ts +193 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +166 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/tag/address.d.ts +11 -0
  36. package/dist/tag/address.d.ts.map +1 -0
  37. package/dist/tag/address.js +44 -0
  38. package/dist/tag/address.js.map +1 -0
  39. package/dist/tag/array.d.ts +14 -0
  40. package/dist/tag/array.d.ts.map +1 -0
  41. package/dist/tag/array.js +72 -0
  42. package/dist/tag/array.js.map +1 -0
  43. package/dist/tag/bool.d.ts +11 -0
  44. package/dist/tag/bool.d.ts.map +1 -0
  45. package/dist/tag/bool.js +43 -0
  46. package/dist/tag/bool.js.map +1 -0
  47. package/dist/tag/bytes.d.ts +11 -0
  48. package/dist/tag/bytes.d.ts.map +1 -0
  49. package/dist/tag/bytes.js +37 -0
  50. package/dist/tag/bytes.js.map +1 -0
  51. package/dist/tag/flarray.d.ts +15 -0
  52. package/dist/tag/flarray.d.ts.map +1 -0
  53. package/dist/tag/flarray.js +81 -0
  54. package/dist/tag/flarray.js.map +1 -0
  55. package/dist/tag/flbytes.d.ts +11 -0
  56. package/dist/tag/flbytes.d.ts.map +1 -0
  57. package/dist/tag/flbytes.js +47 -0
  58. package/dist/tag/flbytes.js.map +1 -0
  59. package/dist/tag/index.d.ts +32 -0
  60. package/dist/tag/index.d.ts.map +1 -0
  61. package/dist/tag/index.js +121 -0
  62. package/dist/tag/index.js.map +1 -0
  63. package/dist/tag/int.d.ts +12 -0
  64. package/dist/tag/int.d.ts.map +1 -0
  65. package/dist/tag/int.js +49 -0
  66. package/dist/tag/int.js.map +1 -0
  67. package/dist/tag/string.d.ts +11 -0
  68. package/dist/tag/string.d.ts.map +1 -0
  69. package/dist/tag/string.js +37 -0
  70. package/dist/tag/string.js.map +1 -0
  71. package/dist/tag/tag.d.ts +67 -0
  72. package/dist/tag/tag.d.ts.map +1 -0
  73. package/dist/tag/tag.js +157 -0
  74. package/dist/tag/tag.js.map +1 -0
  75. package/dist/tag/tuple.d.ts +17 -0
  76. package/dist/tag/tuple.d.ts.map +1 -0
  77. package/dist/tag/tuple.js +162 -0
  78. package/dist/tag/tuple.js.map +1 -0
  79. package/dist/tag/uint.d.ts +12 -0
  80. package/dist/tag/uint.d.ts.map +1 -0
  81. package/dist/tag/uint.js +49 -0
  82. package/dist/tag/uint.js.map +1 -0
  83. package/dist/test/did.d.ts +2 -0
  84. package/dist/test/did.d.ts.map +1 -0
  85. package/dist/test/did.js +177 -0
  86. package/dist/test/did.js.map +1 -0
  87. package/examples/index.ts +15 -0
  88. package/examples/legacy.ts +33 -0
  89. package/package.json +50 -0
  90. package/project.json +6 -0
  91. package/src/abi/ABITypeABI.ts +379 -0
  92. package/src/abi/RegistryABI.ts +459 -0
  93. package/src/abi/RootResolverABI.ts +369 -0
  94. package/src/abi/TerminusDIDABI.ts +1874 -0
  95. package/src/cli.ts +230 -0
  96. package/src/debug.ts +170 -0
  97. package/src/domain/index.ts +659 -0
  98. package/src/index.ts +302 -0
  99. package/src/tag/address.ts +48 -0
  100. package/src/tag/array.ts +80 -0
  101. package/src/tag/bool.ts +43 -0
  102. package/src/tag/bytes.ts +38 -0
  103. package/src/tag/flarray.ts +99 -0
  104. package/src/tag/flbytes.ts +48 -0
  105. package/src/tag/index.ts +170 -0
  106. package/src/tag/int.ts +51 -0
  107. package/src/tag/string.ts +38 -0
  108. package/src/tag/tag.ts +229 -0
  109. package/src/tag/tuple.ts +193 -0
  110. package/src/tag/uint.ts +51 -0
  111. package/src/test/did.ts +346 -0
  112. package/tsconfig.json +9 -0
package/src/cli.ts ADDED
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env node
2
+
3
+ import OlaresID from './index';
4
+ import { debug } from './debug';
5
+
6
+ // 预设的网络配置
7
+ const NETWORKS = {
8
+ sepolia: {
9
+ rpc: 'https://sepolia.optimism.io',
10
+ contractDid: '0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8',
11
+ contractRootResolver: '0xeF727cb066Fee98F88Db84555830063b4A24ddfc',
12
+ contractAbiType: '0x7386fCBae6Ad4CCE1499d9153D99bc950B589718'
13
+ },
14
+ mainnet: {
15
+ rpc: 'https://optimism-rpc.publicnode.com',
16
+ contractDid: '0x5DA4Fa8E567d86e52Ef8Da860de1be8f54cae97D',
17
+ contractRootResolver: '0xE2EABA0979277A90511F8873ae1e8cA26B54E740',
18
+ contractAbiType: '0x9ae3F16bD99294Af1784beB1a0A5C84bf2636365'
19
+ }
20
+ };
21
+
22
+ interface CliOptions {
23
+ network: string;
24
+ rpc?: string;
25
+ contractDid?: string;
26
+ contractResolver?: string;
27
+ contractAbi?: string;
28
+ json: boolean;
29
+ verbose: boolean;
30
+ debug: boolean;
31
+ debugLevel: string;
32
+ help: boolean;
33
+ }
34
+
35
+ function parseArgs(): {
36
+ command: string;
37
+ domain?: string;
38
+ options: CliOptions;
39
+ } {
40
+ const args = process.argv.slice(2);
41
+ const options: CliOptions = {
42
+ network: 'sepolia',
43
+ json: false,
44
+ verbose: false,
45
+ debug: false,
46
+ debugLevel: 'info',
47
+ help: false
48
+ };
49
+
50
+ let command = '';
51
+ let domain: string | undefined;
52
+
53
+ for (let i = 0; i < args.length; i++) {
54
+ const arg = args[i];
55
+
56
+ if (arg === '--help' || arg === '-h') {
57
+ options.help = true;
58
+ } else if (arg === '--version' || arg === '-V') {
59
+ console.log('0.1.0');
60
+ process.exit(0);
61
+ } else if (arg === '--network' || arg === '-n') {
62
+ options.network = args[++i] || 'sepolia';
63
+ } else if (arg === '--rpc') {
64
+ options.rpc = args[++i];
65
+ } else if (arg === '--contract-did') {
66
+ options.contractDid = args[++i];
67
+ } else if (arg === '--contract-resolver') {
68
+ options.contractResolver = args[++i];
69
+ } else if (arg === '--contract-abi') {
70
+ options.contractAbi = args[++i];
71
+ } else if (arg === '--json' || arg === '-j') {
72
+ options.json = true;
73
+ } else if (arg === '--verbose' || arg === '-v') {
74
+ options.verbose = true;
75
+ } else if (arg === '--debug') {
76
+ options.debug = true;
77
+ } else if (arg === '--debug-level') {
78
+ options.debugLevel = args[++i] || 'info';
79
+ } else if (!command) {
80
+ command = arg;
81
+ } else if (
82
+ !domain &&
83
+ (command === 'fetch' || command === 'fetch-domain')
84
+ ) {
85
+ domain = arg;
86
+ }
87
+ }
88
+
89
+ return { command, domain, options };
90
+ }
91
+
92
+ function showHelp(): void {
93
+ console.log(`
94
+ DID CLI Tool v0.1.0
95
+
96
+ USAGE:
97
+ did-cli <command> [arguments] [options]
98
+
99
+ COMMANDS:
100
+ fetch <domain> Fetch domain information (alias: fetch-domain)
101
+ fetch-all Fetch all domains from contract
102
+ config Show network configurations
103
+ help Show this help message
104
+
105
+ ARGUMENTS:
106
+ <domain> Domain name to fetch (e.g., example.olares.com)
107
+
108
+ OPTIONS:
109
+ -n, --network <network> Network to use (sepolia|mainnet) [default: sepolia]
110
+ --rpc <url> Custom RPC endpoint URL
111
+ --contract-did <address> Custom DID contract address
112
+ --contract-resolver <address> Custom RootResolver contract address
113
+ --contract-abi <address> Custom ABIType contract address
114
+ -v, --verbose Enable verbose debug output
115
+ --debug Enable debug output
116
+ --debug-level <level> Set debug level (debug|info|warn|error) [default: info]
117
+ -h, --help Show help message
118
+ -V, --version Show version number
119
+
120
+ EXAMPLES:
121
+ did-cli fetch example.olares.com
122
+ did-cli fetch example.olares.com --network mainnet
123
+ did-cli fetch example.olares.com --json
124
+ did-cli fetch example.olares.com --debug
125
+ did-cli fetch-all --network sepolia
126
+ did-cli config
127
+ `);
128
+ }
129
+
130
+ async function fetchDomain(domain: string, options: CliOptions): Promise<void> {
131
+ try {
132
+ // 设置调试选项
133
+ if (options.verbose || options.debug) {
134
+ debug.enable();
135
+ debug.setLevel(options.debugLevel as any);
136
+ }
137
+
138
+ // 确定网络配置
139
+ let config;
140
+ if (
141
+ options.rpc &&
142
+ options.contractDid &&
143
+ options.contractResolver &&
144
+ options.contractAbi
145
+ ) {
146
+ // 使用自定义配置
147
+ config = {
148
+ rpc: options.rpc,
149
+ contractDid: options.contractDid,
150
+ contractRootResolver: options.contractResolver,
151
+ contractAbiType: options.contractAbi
152
+ };
153
+ } else if (NETWORKS[options.network as keyof typeof NETWORKS]) {
154
+ // 使用预设网络配置
155
+ config = NETWORKS[options.network as keyof typeof NETWORKS];
156
+ } else {
157
+ console.error(`❌ Unknown network: ${options.network}`);
158
+ console.error('Available networks: sepolia, mainnet');
159
+ process.exit(1);
160
+ }
161
+
162
+ if (debug.isEnabled()) {
163
+ debug.info(`🔍 Fetching domain: ${domain}`);
164
+ debug.info(`🌐 Network: ${options.network}`);
165
+ debug.info('Using configuration:', config);
166
+ }
167
+
168
+ // 创建DID控制台实例
169
+ const olaresId = OlaresID.createConsole(
170
+ config.rpc,
171
+ config.contractDid,
172
+ config.contractRootResolver,
173
+ config.contractAbiType
174
+ );
175
+
176
+ // 获取域名数据
177
+ const domainData = await olaresId.fetchDomain(domain);
178
+
179
+ if (!domainData) {
180
+ console.log(`❌ Domain not found: ${domain}`);
181
+ process.exit(1);
182
+ }
183
+
184
+ console.log(JSON.stringify(domainData, null, 2));
185
+ } catch (error) {
186
+ console.error(
187
+ '❌ Error fetching domain:',
188
+ error instanceof Error ? error.message : String(error)
189
+ );
190
+ if (debug.isEnabled()) {
191
+ debug.error('Full error details:', error);
192
+ }
193
+ process.exit(1);
194
+ }
195
+ }
196
+
197
+ async function main(): Promise<void> {
198
+ const { command, domain, options } = parseArgs();
199
+
200
+ if (options.help || !command || command === 'help') {
201
+ showHelp();
202
+ return;
203
+ }
204
+
205
+ switch (command) {
206
+ case 'fetch':
207
+ case 'fetch-domain':
208
+ if (!domain) {
209
+ console.error('❌ Error: Domain argument is required');
210
+ console.error('Usage: did-cli fetch <domain> [options]');
211
+ process.exit(1);
212
+ }
213
+ await fetchDomain(domain, options);
214
+ break;
215
+
216
+ default:
217
+ console.error(`❌ Unknown command: ${command}`);
218
+ console.error('Run "did-cli help" for usage information');
219
+ process.exit(1);
220
+ }
221
+ }
222
+
223
+ // 运行主函数
224
+ main().catch((error) => {
225
+ console.error(
226
+ '❌ Unexpected error:',
227
+ error instanceof Error ? error.message : String(error)
228
+ );
229
+ process.exit(1);
230
+ });
package/src/debug.ts ADDED
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Debug utility for DID system
3
+ * Provides separate debug logging without affecting normal console output
4
+ * Supports environment variables and command line arguments
5
+ */
6
+
7
+ interface DebugConfig {
8
+ enabled: boolean;
9
+ level: 'debug' | 'info' | 'warn' | 'error';
10
+ prefix: string;
11
+ }
12
+
13
+ class DebugLogger {
14
+ private config: DebugConfig;
15
+
16
+ constructor() {
17
+ this.config = this.parseConfig();
18
+ }
19
+
20
+ private parseConfig(): DebugConfig {
21
+ // Check environment variables
22
+ const envDebug =
23
+ process.env.DEBUG === 'true' || process.env.DEBUG === '1';
24
+ const envLevel =
25
+ (process.env.DEBUG_LEVEL as DebugConfig['level']) || 'debug';
26
+ const envPrefix = process.env.DEBUG_PREFIX || '[DID-DEBUG]';
27
+
28
+ // Check command line arguments
29
+ const args = process.argv;
30
+ const hasDebugFlag = args.includes('--debug') || args.includes('-d');
31
+ const hasVerboseFlag =
32
+ args.includes('--verbose') || args.includes('-v');
33
+
34
+ // Parse debug level from command line
35
+ let cmdLevel: DebugConfig['level'] = 'debug';
36
+ const levelIndex = args.findIndex((arg) =>
37
+ arg.startsWith('--debug-level=')
38
+ );
39
+ if (levelIndex !== -1) {
40
+ const level = args[levelIndex].split(
41
+ '='
42
+ )[1] as DebugConfig['level'];
43
+ if (['debug', 'info', 'warn', 'error'].includes(level)) {
44
+ cmdLevel = level;
45
+ }
46
+ }
47
+
48
+ // Parse prefix from command line
49
+ let cmdPrefix = '[DID-DEBUG]';
50
+ const prefixIndex = args.findIndex((arg) =>
51
+ arg.startsWith('--debug-prefix=')
52
+ );
53
+ if (prefixIndex !== -1) {
54
+ cmdPrefix = args[prefixIndex].split('=')[1];
55
+ }
56
+
57
+ return {
58
+ enabled: envDebug || hasDebugFlag || hasVerboseFlag,
59
+ level: cmdLevel || envLevel,
60
+ prefix: cmdPrefix || envPrefix
61
+ };
62
+ }
63
+
64
+ private shouldLog(level: DebugConfig['level']): boolean {
65
+ if (!this.config.enabled) return false;
66
+
67
+ const levels = ['debug', 'info', 'warn', 'error'];
68
+ const currentLevelIndex = levels.indexOf(this.config.level);
69
+ const messageLevelIndex = levels.indexOf(level);
70
+
71
+ return messageLevelIndex >= currentLevelIndex;
72
+ }
73
+
74
+ private formatMessage(level: string, ...args: any[]): any[] {
75
+ const timestamp = new Date().toISOString();
76
+ const prefix = `${
77
+ this.config.prefix
78
+ } [${level.toUpperCase()}] [${timestamp}]`;
79
+ return [prefix, ...args];
80
+ }
81
+
82
+ // Debug logging methods - these are separate from console
83
+ public debug(...args: any[]): void {
84
+ if (this.shouldLog('debug')) {
85
+ console.debug(...this.formatMessage('debug', ...args));
86
+ }
87
+ }
88
+
89
+ public info(...args: any[]): void {
90
+ if (this.shouldLog('info')) {
91
+ console.info(...this.formatMessage('info', ...args));
92
+ }
93
+ }
94
+
95
+ public warn(...args: any[]): void {
96
+ if (this.shouldLog('warn')) {
97
+ console.warn(...this.formatMessage('warn', ...args));
98
+ }
99
+ }
100
+
101
+ public error(...args: any[]): void {
102
+ if (this.shouldLog('error')) {
103
+ console.error(...this.formatMessage('error', ...args));
104
+ }
105
+ }
106
+
107
+ public group(...args: any[]): void {
108
+ if (this.shouldLog('info')) {
109
+ console.group(...this.formatMessage('group', ...args));
110
+ }
111
+ }
112
+
113
+ public groupCollapsed(...args: any[]): void {
114
+ if (this.shouldLog('info')) {
115
+ console.groupCollapsed(...this.formatMessage('group', ...args));
116
+ }
117
+ }
118
+
119
+ public groupEnd(): void {
120
+ if (this.shouldLog('info')) {
121
+ console.groupEnd();
122
+ }
123
+ }
124
+
125
+ // Public methods for configuration control
126
+ public enable(): void {
127
+ this.config.enabled = true;
128
+ }
129
+
130
+ public disable(): void {
131
+ this.config.enabled = false;
132
+ }
133
+
134
+ public setLevel(level: DebugConfig['level']): void {
135
+ this.config.level = level;
136
+ }
137
+
138
+ public getConfig(): DebugConfig {
139
+ return { ...this.config };
140
+ }
141
+
142
+ public isEnabled(): boolean {
143
+ return this.config.enabled;
144
+ }
145
+ }
146
+
147
+ // Create singleton instance
148
+ const debugLogger = new DebugLogger();
149
+
150
+ // Export the debug logger instance and utility functions
151
+ export const debug = {
152
+ // Logging methods
153
+ debug: (...args: any[]) => debugLogger.debug(...args),
154
+ info: (...args: any[]) => debugLogger.info(...args),
155
+ warn: (...args: any[]) => debugLogger.warn(...args),
156
+ error: (...args: any[]) => debugLogger.error(...args),
157
+ group: (...args: any[]) => debugLogger.group(...args),
158
+ groupCollapsed: (...args: any[]) => debugLogger.groupCollapsed(...args),
159
+ groupEnd: () => debugLogger.groupEnd(),
160
+
161
+ // Configuration methods
162
+ enable: () => debugLogger.enable(),
163
+ disable: () => debugLogger.disable(),
164
+ setLevel: (level: 'debug' | 'info' | 'warn' | 'error') =>
165
+ debugLogger.setLevel(level),
166
+ getConfig: () => debugLogger.getConfig(),
167
+ isEnabled: () => debugLogger.isEnabled()
168
+ };
169
+
170
+ export default debugLogger;