@beclab/olaresid 0.1.12 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/CLI-TREE.md +107 -0
  2. package/CLI.md +122 -1329
  3. package/README.md +30 -12
  4. package/SDK-TREE.md +151 -0
  5. package/TAG.md +95 -41
  6. package/config.json +6 -4
  7. package/dist/abi/TerminusDIDQueryABI.d.ts +397 -0
  8. package/dist/abi/TerminusDIDQueryABI.d.ts.map +1 -0
  9. package/dist/abi/TerminusDIDQueryABI.js +519 -0
  10. package/dist/abi/TerminusDIDQueryABI.js.map +1 -0
  11. package/dist/business/index.d.ts +1 -1
  12. package/dist/business/index.d.ts.map +1 -1
  13. package/dist/business/index.js +11 -24
  14. package/dist/business/index.js.map +1 -1
  15. package/dist/business/tag-context.d.ts +1 -0
  16. package/dist/business/tag-context.d.ts.map +1 -1
  17. package/dist/business/tag-context.js +13 -7
  18. package/dist/business/tag-context.js.map +1 -1
  19. package/dist/cli.js +238 -107
  20. package/dist/cli.js.map +1 -1
  21. package/dist/config/index.d.ts +16 -4
  22. package/dist/config/index.d.ts.map +1 -1
  23. package/dist/config/index.js +28 -14
  24. package/dist/config/index.js.map +1 -1
  25. package/dist/domain/core.d.ts +65 -0
  26. package/dist/domain/core.d.ts.map +1 -0
  27. package/dist/domain/core.js +317 -0
  28. package/dist/domain/core.js.map +1 -0
  29. package/dist/domain/index.d.ts +104 -57
  30. package/dist/domain/index.d.ts.map +1 -1
  31. package/dist/domain/index.js +188 -428
  32. package/dist/domain/index.js.map +1 -1
  33. package/dist/domain/types.d.ts +56 -0
  34. package/dist/domain/types.d.ts.map +1 -0
  35. package/dist/domain/types.js +3 -0
  36. package/dist/domain/types.js.map +1 -0
  37. package/dist/index.d.ts +81 -24
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +153 -143
  40. package/dist/index.js.map +1 -1
  41. package/dist/utils/crypto-utils.d.ts +124 -0
  42. package/dist/utils/crypto-utils.d.ts.map +1 -1
  43. package/dist/utils/crypto-utils.js +156 -8
  44. package/dist/utils/crypto-utils.js.map +1 -1
  45. package/dist/utils/error-parser.d.ts.map +1 -1
  46. package/dist/utils/error-parser.js +2 -1
  47. package/dist/utils/error-parser.js.map +1 -1
  48. package/dist/utils/event-parser.d.ts +161 -0
  49. package/dist/utils/event-parser.d.ts.map +1 -0
  50. package/dist/utils/event-parser.js +140 -0
  51. package/dist/utils/event-parser.js.map +1 -0
  52. package/dist/utils/tag-type-builder.d.ts +43 -0
  53. package/dist/utils/tag-type-builder.d.ts.map +1 -1
  54. package/dist/utils/tag-type-builder.js +122 -0
  55. package/dist/utils/tag-type-builder.js.map +1 -1
  56. package/dist/utils/tag-type-parser.d.ts +70 -0
  57. package/dist/utils/tag-type-parser.d.ts.map +1 -0
  58. package/dist/utils/tag-type-parser.js +190 -0
  59. package/dist/utils/tag-type-parser.js.map +1 -0
  60. package/examples/create-with-rpc-demo.ts +142 -0
  61. package/examples/fetch-all-flat-demo.ts +159 -0
  62. package/examples/fetch-by-indices-demo.ts +235 -0
  63. package/examples/fetch-domain-demo.ts +137 -0
  64. package/examples/fetch-domains-demo.ts +221 -0
  65. package/examples/frontend-demo/index.html +2 -2
  66. package/examples/frontend-demo/package-lock.json +4 -1
  67. package/examples/index.ts +3 -5
  68. package/jest.config.js +25 -0
  69. package/package.json +6 -2
  70. package/src/abi/TerminusDIDQueryABI.ts +516 -0
  71. package/src/business/index.ts +10 -33
  72. package/src/business/tag-context.ts +35 -7
  73. package/src/cli.ts +344 -121
  74. package/src/config/index.ts +34 -19
  75. package/src/domain/core.ts +382 -0
  76. package/src/domain/index.ts +271 -641
  77. package/src/domain/types.ts +59 -0
  78. package/src/index.ts +222 -207
  79. package/src/utils/crypto-utils.ts +239 -2
  80. package/src/utils/error-parser.ts +2 -1
  81. package/src/utils/event-parser.ts +353 -0
  82. package/src/utils/tag-type-builder.ts +138 -0
  83. package/src/utils/tag-type-parser.ts +246 -0
  84. package/tests/unit/crypto-utils.test.ts +338 -0
  85. package/tests/unit/ed25519-jwk.test.ts +201 -0
  86. package/tests/unit/event-parser.test.ts +690 -0
  87. package/tests/unit/generate-mnemonic.test.ts +268 -0
  88. package/tests/unit/olares-id-format.test.ts +321 -0
  89. package/tests/unit/tag-type-parser.test.ts +802 -0
  90. package/tests/unit/tag-types.test.ts +821 -0
  91. package/tsconfig.json +3 -2
  92. package/dist/abi/ABITypeABI.d.ts +0 -88
  93. package/dist/abi/ABITypeABI.d.ts.map +0 -1
  94. package/dist/abi/ABITypeABI.js +0 -382
  95. package/dist/abi/ABITypeABI.js.map +0 -1
  96. package/dist/abi/RegistryABI.d.ts +0 -77
  97. package/dist/abi/RegistryABI.d.ts.map +0 -1
  98. package/dist/abi/RegistryABI.js +0 -462
  99. package/dist/abi/RegistryABI.js.map +0 -1
  100. package/dist/tag/address.d.ts +0 -11
  101. package/dist/tag/address.d.ts.map +0 -1
  102. package/dist/tag/address.js +0 -44
  103. package/dist/tag/address.js.map +0 -1
  104. package/dist/tag/array.d.ts +0 -14
  105. package/dist/tag/array.d.ts.map +0 -1
  106. package/dist/tag/array.js +0 -72
  107. package/dist/tag/array.js.map +0 -1
  108. package/dist/tag/bool.d.ts +0 -11
  109. package/dist/tag/bool.d.ts.map +0 -1
  110. package/dist/tag/bool.js +0 -43
  111. package/dist/tag/bool.js.map +0 -1
  112. package/dist/tag/bytes.d.ts +0 -11
  113. package/dist/tag/bytes.d.ts.map +0 -1
  114. package/dist/tag/bytes.js +0 -37
  115. package/dist/tag/bytes.js.map +0 -1
  116. package/dist/tag/flarray.d.ts +0 -15
  117. package/dist/tag/flarray.d.ts.map +0 -1
  118. package/dist/tag/flarray.js +0 -81
  119. package/dist/tag/flarray.js.map +0 -1
  120. package/dist/tag/flbytes.d.ts +0 -11
  121. package/dist/tag/flbytes.d.ts.map +0 -1
  122. package/dist/tag/flbytes.js +0 -47
  123. package/dist/tag/flbytes.js.map +0 -1
  124. package/dist/tag/index.d.ts +0 -32
  125. package/dist/tag/index.d.ts.map +0 -1
  126. package/dist/tag/index.js +0 -121
  127. package/dist/tag/index.js.map +0 -1
  128. package/dist/tag/int.d.ts +0 -12
  129. package/dist/tag/int.d.ts.map +0 -1
  130. package/dist/tag/int.js +0 -49
  131. package/dist/tag/int.js.map +0 -1
  132. package/dist/tag/string.d.ts +0 -11
  133. package/dist/tag/string.d.ts.map +0 -1
  134. package/dist/tag/string.js +0 -37
  135. package/dist/tag/string.js.map +0 -1
  136. package/dist/tag/tag.d.ts +0 -67
  137. package/dist/tag/tag.d.ts.map +0 -1
  138. package/dist/tag/tag.js +0 -157
  139. package/dist/tag/tag.js.map +0 -1
  140. package/dist/tag/tuple.d.ts +0 -17
  141. package/dist/tag/tuple.d.ts.map +0 -1
  142. package/dist/tag/tuple.js +0 -162
  143. package/dist/tag/tuple.js.map +0 -1
  144. package/dist/tag/uint.d.ts +0 -12
  145. package/dist/tag/uint.d.ts.map +0 -1
  146. package/dist/tag/uint.js +0 -49
  147. package/dist/tag/uint.js.map +0 -1
  148. package/dist/test/did.d.ts +0 -2
  149. package/dist/test/did.d.ts.map +0 -1
  150. package/dist/test/did.js +0 -177
  151. package/dist/test/did.js.map +0 -1
  152. package/dist/utils/tag-abi-codec.d.ts +0 -69
  153. package/dist/utils/tag-abi-codec.d.ts.map +0 -1
  154. package/dist/utils/tag-abi-codec.js +0 -144
  155. package/dist/utils/tag-abi-codec.js.map +0 -1
  156. package/examples/crypto-utilities.ts +0 -140
  157. package/examples/ed25519-jwk.ts +0 -73
  158. package/examples/generate-mnemonic.ts +0 -149
  159. package/examples/legacy.ts +0 -33
  160. package/examples/olares-id-format.ts +0 -197
  161. package/examples/tag-builder.ts +0 -235
  162. package/examples/tag-nested-tuple.ts +0 -190
  163. package/examples/tag-simple.ts +0 -149
  164. package/examples/tag-tagger.ts +0 -217
  165. package/examples/test-nested-tuple-conversion.ts +0 -143
  166. package/examples/test-type-bytes-parser.ts +0 -70
  167. package/src/abi/ABITypeABI.ts +0 -379
  168. package/src/abi/RegistryABI.ts +0 -459
  169. package/src/tag/address.ts +0 -48
  170. package/src/tag/array.ts +0 -80
  171. package/src/tag/bool.ts +0 -43
  172. package/src/tag/bytes.ts +0 -38
  173. package/src/tag/flarray.ts +0 -99
  174. package/src/tag/flbytes.ts +0 -48
  175. package/src/tag/index.ts +0 -170
  176. package/src/tag/int.ts +0 -51
  177. package/src/tag/string.ts +0 -38
  178. package/src/tag/tag.ts +0 -229
  179. package/src/tag/tuple.ts +0 -193
  180. package/src/tag/uint.ts +0 -51
  181. package/src/test/did.ts +0 -346
  182. package/src/utils/tag-abi-codec.ts +0 -158
@@ -1,197 +0,0 @@
1
- /**
2
- * Example: Testing Olares ID Format Support
3
- *
4
- * This example demonstrates the new Olares ID format support.
5
- * Olares ID uses @ instead of the first dot, making it look like an email address.
6
- *
7
- * Format conversion:
8
- * - Standard domain: alice.example.com
9
- * - Olares ID format: alice@example.com
10
- *
11
- * Both formats should work identically in the SDK and CLI.
12
- */
13
-
14
- import OlaresID from '../src/index';
15
- import { normalizeToDomain, normalizeToOlaresId } from '../src/utils/olares-id';
16
-
17
- async function main() {
18
- console.log('='.repeat(80));
19
- console.log('Testing Olares ID Format Support');
20
- console.log('='.repeat(80));
21
-
22
- // Test 1: Utility Functions
23
- console.log('\n📝 Test 1: Olares ID Utility Functions');
24
- console.log('-'.repeat(80));
25
-
26
- const testCases = [
27
- { input: 'alice@example.com', expected: 'alice.example.com' },
28
- { input: 'bob@sub.example.com', expected: 'bob.sub.example.com' },
29
- { input: 'charlie.example.com', expected: 'charlie.example.com' },
30
- { input: 'user@olares.com', expected: 'user.olares.com' }
31
- ];
32
-
33
- console.log('Testing normalizeToDomain():');
34
- for (const test of testCases) {
35
- const result = normalizeToDomain(test.input);
36
- const status = result === test.expected ? '✅' : '❌';
37
- console.log(
38
- ` ${status} normalizeToDomain('${test.input}') => '${result}' (expected: '${test.expected}')`
39
- );
40
- }
41
-
42
- console.log('\nTesting normalizeToOlaresId():');
43
- const domainToOlaresIdTests = [
44
- { input: 'alice.example.com', expected: 'alice@example.com' },
45
- { input: 'bob.sub.example.com', expected: 'bob@sub.example.com' }
46
- ];
47
-
48
- for (const test of domainToOlaresIdTests) {
49
- const result = normalizeToOlaresId(test.input);
50
- const status = result === test.expected ? '✅' : '❌';
51
- console.log(
52
- ` ${status} normalizeToOlaresId('${test.input}') => '${result}' (expected: '${test.expected}')`
53
- );
54
- }
55
-
56
- // Test 2: SDK with Olares ID Format
57
- console.log('\n🔧 Test 2: SDK with Olares ID Format');
58
- console.log('-'.repeat(80));
59
-
60
- const didConsole = OlaresID.createTestnet();
61
-
62
- // Use a real test domain (1.com is a common test domain on testnet)
63
- const testDomainStandard = '1.com';
64
- const testDomainOlaresId = '1@com'; // Olares ID format
65
-
66
- console.log('\nTesting with standard domain format:', testDomainStandard);
67
- try {
68
- const domainStandard = didConsole.domain(testDomainStandard);
69
- const metaStandard = await domainStandard.getMetaInfo();
70
- console.log('✅ Standard format works:');
71
- console.log(' Name:', metaStandard.name);
72
- console.log(' DID:', metaStandard.did);
73
- console.log(' Owner:', await domainStandard.getOwner());
74
- } catch (error) {
75
- console.error('❌ Standard format failed:', error);
76
- }
77
-
78
- console.log('\nTesting with Olares ID format:', testDomainOlaresId);
79
- try {
80
- const domainOlaresId = didConsole.domain(testDomainOlaresId);
81
- const metaOlaresId = await domainOlaresId.getMetaInfo();
82
- console.log('✅ Olares ID format works:');
83
- console.log(' Name:', metaOlaresId.name);
84
- console.log(' DID:', metaOlaresId.did);
85
- console.log(' Owner:', await domainOlaresId.getOwner());
86
- } catch (error) {
87
- console.error('❌ Olares ID format failed:', error);
88
- }
89
-
90
- // Test 3: Verify Both Formats Return Same Data
91
- console.log('\n🔍 Test 3: Verify Both Formats Return Same Data');
92
- console.log('-'.repeat(80));
93
-
94
- try {
95
- const domainStandard = didConsole.domain(testDomainStandard);
96
- const domainOlaresId = didConsole.domain(testDomainOlaresId);
97
-
98
- const [metaStandard, metaOlaresId] = await Promise.all([
99
- domainStandard.getMetaInfo(),
100
- domainOlaresId.getMetaInfo()
101
- ]);
102
-
103
- const ownerStandard = await domainStandard.getOwner();
104
- const ownerOlaresId = await domainOlaresId.getOwner();
105
-
106
- console.log('Comparing results:');
107
- console.log(
108
- ` Name match: ${
109
- metaStandard.name === metaOlaresId.name ? '✅' : '❌'
110
- } (${metaStandard.name} vs ${metaOlaresId.name})`
111
- );
112
- console.log(
113
- ` DID match: ${
114
- metaStandard.did === metaOlaresId.did ? '✅' : '❌'
115
- }`
116
- );
117
- console.log(
118
- ` Owner match: ${
119
- ownerStandard === ownerOlaresId ? '✅' : '❌'
120
- } (${ownerStandard} vs ${ownerOlaresId})`
121
- );
122
- console.log(
123
- ` TokenId match: ${
124
- domainStandard.getTokenId() === domainOlaresId.getTokenId()
125
- ? '✅'
126
- : '❌'
127
- }`
128
- );
129
- } catch (error) {
130
- console.error('❌ Comparison failed:', error);
131
- }
132
-
133
- // Test 4: Multi-level Domain Support
134
- console.log('\n🌳 Test 4: Multi-level Domain Support');
135
- console.log('-'.repeat(80));
136
-
137
- const multiLevelTests = [
138
- { standard: 'alice.example.com', olaresId: 'alice@example.com' },
139
- { standard: 'bob.sub.example.com', olaresId: 'bob@sub.example.com' },
140
- {
141
- standard: 'user.deep.nested.domain.com',
142
- olaresId: 'user@deep.nested.domain.com'
143
- }
144
- ];
145
-
146
- for (const test of multiLevelTests) {
147
- const normalized = normalizeToDomain(test.olaresId);
148
- const matches = normalized === test.standard;
149
- console.log(
150
- ` ${matches ? '✅' : '❌'} ${
151
- test.olaresId
152
- } => ${normalized} (expected: ${test.standard})`
153
- );
154
- }
155
-
156
- // Test 5: Edge Cases
157
- console.log('\n⚠️ Test 5: Edge Cases');
158
- console.log('-'.repeat(80));
159
-
160
- const edgeCases = [
161
- { input: '', description: 'Empty string' },
162
- { input: 'nodot', description: 'No dot or @' },
163
- {
164
- input: 'multiple@at@signs.com',
165
- description: 'Multiple @ signs (only first is converted)'
166
- },
167
- { input: '.startswithdot', description: 'Starts with dot' },
168
- { input: '@startswithat', description: 'Starts with @' }
169
- ];
170
-
171
- for (const test of edgeCases) {
172
- try {
173
- const result = normalizeToDomain(test.input);
174
- console.log(
175
- ` ℹ️ ${test.description}: '${test.input}' => '${result}'`
176
- );
177
- } catch (error) {
178
- console.log(` ℹ️ ${test.description}: Error - ${error}`);
179
- }
180
- }
181
-
182
- console.log('\n' + '='.repeat(80));
183
- console.log('✅ All Olares ID format tests completed!');
184
- console.log('='.repeat(80));
185
- console.log('\n💡 Key Takeaways:');
186
- console.log(
187
- ' • Both standard domain and Olares ID formats work identically'
188
- );
189
- console.log(
190
- ' • Use alice@example.com instead of alice.example.com for a more intuitive format'
191
- );
192
- console.log(' • The conversion happens automatically in the SDK and CLI');
193
- console.log(' • Only the first dot/@ is affected by the conversion');
194
- console.log('='.repeat(80));
195
- }
196
-
197
- main().catch(console.error);
@@ -1,235 +0,0 @@
1
- /**
2
- * TagTypeBuilder Example
3
- *
4
- * This example demonstrates how to use TagTypeBuilder to:
5
- * - Create various Tag types offline (no contract calls)
6
- * - See the generated ABI type bytes
7
- * - Understand the encoding rules
8
- *
9
- * This is purely informational - no blockchain interaction required.
10
- *
11
- * Run:
12
- * npx ts-node examples/tag-builder.ts
13
- */
14
-
15
- import { TagTypeBuilder } from '../src/index';
16
-
17
- console.log('\n' + '='.repeat(70));
18
- console.log('TagTypeBuilder - Offline ABI Type Encoding Demo');
19
- console.log('='.repeat(70) + '\n');
20
-
21
- // ========================================
22
- // 1. Basic Types
23
- // ========================================
24
- console.log('📦 Part 1: Basic Types');
25
- console.log('-'.repeat(70));
26
-
27
- const stringType = TagTypeBuilder.string();
28
- console.log(`string → 0x${stringType.getTypeBytes()}`);
29
-
30
- const addressType = TagTypeBuilder.address();
31
- console.log(`address → 0x${addressType.getTypeBytes()}`);
32
-
33
- const boolType = TagTypeBuilder.bool();
34
- console.log(`bool → 0x${boolType.getTypeBytes()}`);
35
-
36
- const uint8Type = TagTypeBuilder.uint8();
37
- console.log(`uint8 → 0x${uint8Type.getTypeBytes()}`);
38
-
39
- const uint256Type = TagTypeBuilder.uint256();
40
- console.log(`uint256 → 0x${uint256Type.getTypeBytes()}`);
41
-
42
- const bytes32Type = TagTypeBuilder.bytes32();
43
- console.log(`bytes32 → 0x${bytes32Type.getTypeBytes()}`);
44
-
45
- const bytesType = TagTypeBuilder.bytes();
46
- console.log(`bytes → 0x${bytesType.getTypeBytes()}`);
47
-
48
- console.log();
49
-
50
- // ========================================
51
- // 2. Array Types
52
- // ========================================
53
- console.log('📦 Part 2: Array Types (Dynamic)');
54
- console.log('-'.repeat(70));
55
-
56
- const addressArrayType = TagTypeBuilder.addressArray();
57
- console.log(`address[] → 0x${addressArrayType.getTypeBytes()}`);
58
- console.log(` = 0x04 (array) + 0x07 (address)`);
59
-
60
- const stringArrayType = TagTypeBuilder.stringArray();
61
- console.log(`string[] → 0x${stringArrayType.getTypeBytes()}`);
62
- console.log(` = 0x04 (array) + 0x03 (string)`);
63
-
64
- const uint256ArrayType = TagTypeBuilder.uint256Array();
65
- console.log(`uint256[] → 0x${uint256ArrayType.getTypeBytes()}`);
66
- console.log(` = 0x04 (array) + 0x0120 (uint256)`);
67
-
68
- // Nested array
69
- const nestedArrayType = TagTypeBuilder.array(TagTypeBuilder.addressArray());
70
- console.log(`address[][] → 0x${nestedArrayType.getTypeBytes()}`);
71
- console.log(` = 0x04 (array) + 0x0407 (address[])`);
72
-
73
- console.log();
74
-
75
- // ========================================
76
- // 3. Fixed-Length Array Types
77
- // ========================================
78
- console.log('📦 Part 3: Fixed-Length Arrays');
79
- console.log('-'.repeat(70));
80
-
81
- const fixedArray5 = TagTypeBuilder.fixedArray(TagTypeBuilder.address(), 5);
82
- console.log(`address[5] → 0x${fixedArray5.getTypeBytes()}`);
83
- console.log(
84
- ` = 0x05 (fixed array) + 0x0005 (length 5) + 0x07 (address)`
85
- );
86
-
87
- const fixedArray10 = TagTypeBuilder.fixedArray(TagTypeBuilder.uint8(), 10);
88
- console.log(`uint8[10] → 0x${fixedArray10.getTypeBytes()}`);
89
- console.log(
90
- ` = 0x05 (fixed array) + 0x000A (length 10) + 0x0101 (uint8)`
91
- );
92
-
93
- console.log();
94
-
95
- // ========================================
96
- // 4. Tuple Types (Struct)
97
- // ========================================
98
- console.log('📦 Part 4: Tuple Types (Struct)');
99
- console.log('-'.repeat(70));
100
-
101
- // Simple tuple
102
- const userType = TagTypeBuilder.tuple({
103
- name: TagTypeBuilder.string(),
104
- age: TagTypeBuilder.uint8()
105
- });
106
- console.log(`tuple(string name, uint8 age)`);
107
- console.log(` → 0x${userType.getTypeBytes()}`);
108
- console.log(
109
- ` = 0x06 (tuple) + 0x0002 (2 fields) + 0x03 (string) + 0x0101 (uint8)`
110
- );
111
- console.log(` Field names: ${JSON.stringify(userType.getFieldNames())}`);
112
-
113
- console.log();
114
-
115
- // Complex tuple
116
- const profileType = TagTypeBuilder.tuple({
117
- username: TagTypeBuilder.string(),
118
- age: TagTypeBuilder.uint8(),
119
- wallets: TagTypeBuilder.addressArray(),
120
- verified: TagTypeBuilder.bool()
121
- });
122
- console.log(
123
- `tuple(string username, uint8 age, address[] wallets, bool verified)`
124
- );
125
- console.log(` → 0x${profileType.getTypeBytes()}`);
126
- console.log(` = 0x06 (tuple)`);
127
- console.log(` + 0x0004 (4 fields)`);
128
- console.log(` + 0x03 (string)`);
129
- console.log(` + 0x0101 (uint8)`);
130
- console.log(` + 0x0407 (address[])`);
131
- console.log(` + 0x02 (bool)`);
132
- console.log(` Field names: ${JSON.stringify(profileType.getFieldNames())}`);
133
-
134
- console.log();
135
-
136
- // ========================================
137
- // 5. Nested Tuple Types
138
- // ========================================
139
- console.log('📦 Part 5: Nested Tuple Types');
140
- console.log('-'.repeat(70));
141
-
142
- const addressBookType = TagTypeBuilder.tuple({
143
- owner: TagTypeBuilder.tuple({
144
- name: TagTypeBuilder.string(),
145
- wallet: TagTypeBuilder.address()
146
- }),
147
- contacts: TagTypeBuilder.array(
148
- TagTypeBuilder.tuple({
149
- name: TagTypeBuilder.string(),
150
- wallet: TagTypeBuilder.address()
151
- })
152
- )
153
- });
154
-
155
- console.log(`Complex nested tuple:`);
156
- console.log(` → 0x${addressBookType.getTypeBytes()}`);
157
- console.log(
158
- ` Field names: ${JSON.stringify(
159
- addressBookType.getFieldNames(),
160
- null,
161
- 2
162
- )}`
163
- );
164
-
165
- console.log();
166
-
167
- // ========================================
168
- // 6. Array of Tuples
169
- // ========================================
170
- console.log('📦 Part 6: Array of Tuples');
171
- console.log('-'.repeat(70));
172
-
173
- const authAddressType = TagTypeBuilder.array(
174
- TagTypeBuilder.tuple({
175
- algorithm: TagTypeBuilder.uint8(),
176
- addr: TagTypeBuilder.address()
177
- })
178
- );
179
-
180
- console.log(`tuple(uint8 algorithm, address addr)[]`);
181
- console.log(` → 0x${authAddressType.getTypeBytes()}`);
182
- console.log(` = 0x04 (array)`);
183
- console.log(` + 0x06 (tuple)`);
184
- console.log(` + 0x0002 (2 fields)`);
185
- console.log(` + 0x0101 (uint8)`);
186
- console.log(` + 0x07 (address)`);
187
- console.log(
188
- ` Field names: ${JSON.stringify(authAddressType.getFieldNames())}`
189
- );
190
-
191
- console.log();
192
-
193
- // ========================================
194
- // 7. Encoding Rules Summary
195
- // ========================================
196
- console.log('📦 Part 7: Encoding Rules Summary');
197
- console.log('-'.repeat(70));
198
- console.log(`
199
- Type Code | Type | Encoding
200
- --------- | ----------- | ----------------------------------------
201
- 0x00 | int | 0x00 + size (size = bits / 8)
202
- 0x01 | uint | 0x01 + size (size = bits / 8)
203
- 0x02 | bool | 0x02
204
- 0x03 | string | 0x03
205
- 0x04 | array | 0x04 + elementType
206
- 0x05 | fixedArray | 0x05 + length (2 bytes) + elementType
207
- 0x06 | tuple | 0x06 + fieldCount (2 bytes) + fieldTypes...
208
- 0x07 | address | 0x07
209
- 0x08 | fixedBytes | 0x08 + size (1-32)
210
- 0x09 | bytes | 0x09
211
-
212
- Examples:
213
- uint8 = 0x0101 (0x01 for uint + 0x01 for 8 bits / 8)
214
- uint256 = 0x0120 (0x01 for uint + 0x20 for 256 bits / 8 = 32)
215
- bytes32 = 0x0820 (0x08 for fixed bytes + 0x20 for 32 bytes)
216
-
217
- Array Examples:
218
- address[] = 0x0407 (0x04 + 0x07)
219
- address[][] = 0x040407 (0x04 + 0x0407)
220
- address[5] = 0x05000507 (0x05 + 0x0005 + 0x07)
221
-
222
- Tuple Examples:
223
- tuple(string, uint8) = 0x06000203 0101
224
- ^^ ^^^^ ^^ ^^^^
225
- | | | uint8
226
- | | string
227
- | 2 fields
228
- tuple
229
- `);
230
-
231
- console.log('='.repeat(70));
232
- console.log('✅ TagTypeBuilder Demo Completed');
233
- console.log('='.repeat(70) + '\n');
234
- console.log('💡 Key Takeaway: All ABI type bytes are calculated OFFLINE!');
235
- console.log(' No blockchain calls needed for type definition.\n');
@@ -1,190 +0,0 @@
1
- import OlaresID from '../src/index';
2
- import { TagTypeBuilder } from '../src/utils/tag-type-builder';
3
-
4
- // Helper function to wait for blockchain indexing
5
- async function waitForIndexing(seconds: number = 3) {
6
- console.log(`⏳ Waiting ${seconds} seconds for blockchain indexing...`);
7
- await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
8
- }
9
-
10
- /**
11
- * Example: Nested Tuple Tag Operations
12
- * Demonstrates automatic object-to-array conversion for nested tuples
13
- */
14
-
15
- async function main() {
16
- const domainName = process.argv[2];
17
- if (!domainName) {
18
- console.error(
19
- 'Usage: npx ts-node examples/tag-nested-tuple.ts <domain-name>'
20
- );
21
- process.exit(1);
22
- }
23
-
24
- const privateKeyOrMnemonic = process.env.PRIVATE_KEY_OR_MNEMONIC;
25
- if (!privateKeyOrMnemonic) {
26
- console.error(
27
- 'Error: PRIVATE_KEY_OR_MNEMONIC environment variable is required'
28
- );
29
- process.exit(1);
30
- }
31
-
32
- console.log('🚀 Nested Tuple Tag Example\n');
33
- console.log(`Domain: ${domainName}\n`);
34
-
35
- // Initialize
36
- const olaresId = OlaresID.createTestnet();
37
- await olaresId.setSigner(privateKeyOrMnemonic);
38
- const domain = olaresId.domain(domainName);
39
- const tagCtx = domain.tag();
40
- const signerAddress = await olaresId.signer!.getAddress();
41
-
42
- // ========================================
43
- // Part 1: Define Nested Tuple Type
44
- // ========================================
45
- console.log('='.repeat(60));
46
- console.log('Part 1: Define Nested Tuple Type');
47
- console.log('='.repeat(60));
48
-
49
- const profileType = TagTypeBuilder.tuple({
50
- name: TagTypeBuilder.string(),
51
- details: TagTypeBuilder.tuple({
52
- age: TagTypeBuilder.uint8(),
53
- verified: TagTypeBuilder.bool()
54
- }),
55
- contact: TagTypeBuilder.tuple({
56
- email: TagTypeBuilder.string(),
57
- phone: TagTypeBuilder.string()
58
- })
59
- });
60
-
61
- try {
62
- await tagCtx.defineTag('profile', profileType);
63
- console.log('✅ Defined "profile" nested tuple tag\n');
64
- } catch (error: any) {
65
- if (error.message.includes('already been defined')) {
66
- console.log('⚠️ "profile" tag already defined, skipping...\n');
67
- } else {
68
- throw error;
69
- }
70
- }
71
-
72
- // Set tagger
73
- await domain.setTagger('profile', signerAddress);
74
- console.log(`✅ Set tagger for "profile" to ${signerAddress}\n`);
75
-
76
- // ========================================
77
- // Part 2: Set Nested Tuple using Object
78
- // ========================================
79
- console.log('='.repeat(60));
80
- console.log('Part 2: Set Nested Tuple (Object Notation)');
81
- console.log('='.repeat(60));
82
-
83
- const profileValue = {
84
- name: 'Alice Johnson',
85
- details: {
86
- age: 30,
87
- verified: true
88
- },
89
- contact: {
90
- email: 'alice@example.com',
91
- phone: '+1-555-0123'
92
- }
93
- };
94
-
95
- console.log('📝 Setting nested tuple with object notation:');
96
- console.log(JSON.stringify(profileValue, null, 2));
97
-
98
- await tagCtx.setTag(domainName, 'profile', profileValue);
99
- console.log('\n✅ Nested tuple set successfully!\n');
100
- await waitForIndexing(3);
101
-
102
- // ========================================
103
- // Part 3: Get and Display Nested Tuple
104
- // ========================================
105
- console.log('='.repeat(60));
106
- console.log('Part 3: Read Nested Tuple');
107
- console.log('='.repeat(60));
108
-
109
- const profile = await tagCtx.getTag(domainName, 'profile');
110
- console.log('📖 Retrieved profile (raw array):');
111
- console.log(
112
- JSON.stringify(profile, (_, v) =>
113
- typeof v === 'bigint' ? v.toString() : v
114
- )
115
- );
116
-
117
- console.log('\n📖 Retrieved profile (parsed):');
118
- console.log(` name: ${profile[0]}`);
119
- console.log(` details.age: ${profile[1][0]}`);
120
- console.log(` details.verified: ${profile[1][1]}`);
121
- console.log(` contact.email: ${profile[2][0]}`);
122
- console.log(` contact.phone: ${profile[2][1]}\n`);
123
-
124
- // ========================================
125
- // Part 4: Update Nested Field
126
- // ========================================
127
- console.log('='.repeat(60));
128
- console.log('Part 4: Update Nested Field');
129
- console.log('='.repeat(60));
130
-
131
- console.log('🔄 Updating details.age from 30 to 31...\n');
132
-
133
- const updatedProfile = {
134
- name: profile[0],
135
- details: {
136
- age: 31, // Updated
137
- verified: profile[1][1]
138
- },
139
- contact: {
140
- email: profile[2][0],
141
- phone: profile[2][1]
142
- }
143
- };
144
-
145
- await tagCtx.setTag(domainName, 'profile', updatedProfile);
146
- console.log('✅ Updated nested field\n');
147
- await waitForIndexing(3);
148
-
149
- // Verify update
150
- const updatedProfileRead = await tagCtx.getTag(domainName, 'profile');
151
- console.log('📖 Verified update:');
152
- console.log(
153
- ` details.age: ${updatedProfileRead[1][0]} (was 30, now 31)\n`
154
- );
155
-
156
- // ========================================
157
- // Part 5: Array Notation (Still Supported)
158
- // ========================================
159
- console.log('='.repeat(60));
160
- console.log('Part 5: Array Notation (Alternative)');
161
- console.log('='.repeat(60));
162
-
163
- console.log('📝 Setting with array notation (for comparison):\n');
164
-
165
- await tagCtx.setTag(domainName, 'profile', [
166
- 'Bob Smith', // name
167
- [25, false], // details: {age: 25, verified: false}
168
- ['bob@example.com', '+1-555-9999'] // contact: {email, phone}
169
- ]);
170
-
171
- console.log('✅ Array notation also works!\n');
172
- await waitForIndexing(3);
173
-
174
- const profileArray = await tagCtx.getTag(domainName, 'profile');
175
- console.log('📖 Retrieved (set via array notation):');
176
- console.log(` name: ${profileArray[0]}`);
177
- console.log(` details.age: ${profileArray[1][0]}`);
178
- console.log(` details.verified: ${profileArray[1][1]}\n`);
179
-
180
- console.log('='.repeat(60));
181
- console.log('✅ All nested tuple operations completed!');
182
- console.log('='.repeat(60));
183
- console.log('\n💡 Key Takeaways:');
184
- console.log(' • Objects are automatically converted to arrays');
185
- console.log(' • Nested tuples work seamlessly');
186
- console.log(' • No need to provide field names manually');
187
- console.log(' • Array notation is still supported for flexibility\n');
188
- }
189
-
190
- main().catch(console.error);