@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.
- package/CLI-TREE.md +107 -0
- package/CLI.md +122 -1329
- package/README.md +30 -12
- package/SDK-TREE.md +151 -0
- package/TAG.md +95 -41
- package/config.json +6 -4
- package/dist/abi/TerminusDIDQueryABI.d.ts +397 -0
- package/dist/abi/TerminusDIDQueryABI.d.ts.map +1 -0
- package/dist/abi/TerminusDIDQueryABI.js +519 -0
- package/dist/abi/TerminusDIDQueryABI.js.map +1 -0
- package/dist/business/index.d.ts +1 -1
- package/dist/business/index.d.ts.map +1 -1
- package/dist/business/index.js +11 -24
- package/dist/business/index.js.map +1 -1
- package/dist/business/tag-context.d.ts +1 -0
- package/dist/business/tag-context.d.ts.map +1 -1
- package/dist/business/tag-context.js +13 -7
- package/dist/business/tag-context.js.map +1 -1
- package/dist/cli.js +238 -107
- package/dist/cli.js.map +1 -1
- package/dist/config/index.d.ts +16 -4
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +28 -14
- package/dist/config/index.js.map +1 -1
- package/dist/domain/core.d.ts +65 -0
- package/dist/domain/core.d.ts.map +1 -0
- package/dist/domain/core.js +317 -0
- package/dist/domain/core.js.map +1 -0
- package/dist/domain/index.d.ts +104 -57
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +188 -428
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/types.d.ts +56 -0
- package/dist/domain/types.d.ts.map +1 -0
- package/dist/domain/types.js +3 -0
- package/dist/domain/types.js.map +1 -0
- package/dist/index.d.ts +81 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -143
- package/dist/index.js.map +1 -1
- package/dist/utils/crypto-utils.d.ts +124 -0
- package/dist/utils/crypto-utils.d.ts.map +1 -1
- package/dist/utils/crypto-utils.js +156 -8
- package/dist/utils/crypto-utils.js.map +1 -1
- package/dist/utils/error-parser.d.ts.map +1 -1
- package/dist/utils/error-parser.js +2 -1
- package/dist/utils/error-parser.js.map +1 -1
- package/dist/utils/event-parser.d.ts +161 -0
- package/dist/utils/event-parser.d.ts.map +1 -0
- package/dist/utils/event-parser.js +140 -0
- package/dist/utils/event-parser.js.map +1 -0
- package/dist/utils/tag-type-builder.d.ts +43 -0
- package/dist/utils/tag-type-builder.d.ts.map +1 -1
- package/dist/utils/tag-type-builder.js +122 -0
- package/dist/utils/tag-type-builder.js.map +1 -1
- package/dist/utils/tag-type-parser.d.ts +70 -0
- package/dist/utils/tag-type-parser.d.ts.map +1 -0
- package/dist/utils/tag-type-parser.js +190 -0
- package/dist/utils/tag-type-parser.js.map +1 -0
- package/examples/create-with-rpc-demo.ts +142 -0
- package/examples/fetch-all-flat-demo.ts +159 -0
- package/examples/fetch-by-indices-demo.ts +235 -0
- package/examples/fetch-domain-demo.ts +137 -0
- package/examples/fetch-domains-demo.ts +221 -0
- package/examples/frontend-demo/index.html +2 -2
- package/examples/frontend-demo/package-lock.json +4 -1
- package/examples/index.ts +3 -5
- package/jest.config.js +25 -0
- package/package.json +6 -2
- package/src/abi/TerminusDIDQueryABI.ts +516 -0
- package/src/business/index.ts +10 -33
- package/src/business/tag-context.ts +35 -7
- package/src/cli.ts +344 -121
- package/src/config/index.ts +34 -19
- package/src/domain/core.ts +382 -0
- package/src/domain/index.ts +271 -641
- package/src/domain/types.ts +59 -0
- package/src/index.ts +222 -207
- package/src/utils/crypto-utils.ts +239 -2
- package/src/utils/error-parser.ts +2 -1
- package/src/utils/event-parser.ts +353 -0
- package/src/utils/tag-type-builder.ts +138 -0
- package/src/utils/tag-type-parser.ts +246 -0
- package/tests/unit/crypto-utils.test.ts +338 -0
- package/tests/unit/ed25519-jwk.test.ts +201 -0
- package/tests/unit/event-parser.test.ts +690 -0
- package/tests/unit/generate-mnemonic.test.ts +268 -0
- package/tests/unit/olares-id-format.test.ts +321 -0
- package/tests/unit/tag-type-parser.test.ts +802 -0
- package/tests/unit/tag-types.test.ts +821 -0
- package/tsconfig.json +3 -2
- package/dist/abi/ABITypeABI.d.ts +0 -88
- package/dist/abi/ABITypeABI.d.ts.map +0 -1
- package/dist/abi/ABITypeABI.js +0 -382
- package/dist/abi/ABITypeABI.js.map +0 -1
- package/dist/abi/RegistryABI.d.ts +0 -77
- package/dist/abi/RegistryABI.d.ts.map +0 -1
- package/dist/abi/RegistryABI.js +0 -462
- package/dist/abi/RegistryABI.js.map +0 -1
- package/dist/tag/address.d.ts +0 -11
- package/dist/tag/address.d.ts.map +0 -1
- package/dist/tag/address.js +0 -44
- package/dist/tag/address.js.map +0 -1
- package/dist/tag/array.d.ts +0 -14
- package/dist/tag/array.d.ts.map +0 -1
- package/dist/tag/array.js +0 -72
- package/dist/tag/array.js.map +0 -1
- package/dist/tag/bool.d.ts +0 -11
- package/dist/tag/bool.d.ts.map +0 -1
- package/dist/tag/bool.js +0 -43
- package/dist/tag/bool.js.map +0 -1
- package/dist/tag/bytes.d.ts +0 -11
- package/dist/tag/bytes.d.ts.map +0 -1
- package/dist/tag/bytes.js +0 -37
- package/dist/tag/bytes.js.map +0 -1
- package/dist/tag/flarray.d.ts +0 -15
- package/dist/tag/flarray.d.ts.map +0 -1
- package/dist/tag/flarray.js +0 -81
- package/dist/tag/flarray.js.map +0 -1
- package/dist/tag/flbytes.d.ts +0 -11
- package/dist/tag/flbytes.d.ts.map +0 -1
- package/dist/tag/flbytes.js +0 -47
- package/dist/tag/flbytes.js.map +0 -1
- package/dist/tag/index.d.ts +0 -32
- package/dist/tag/index.d.ts.map +0 -1
- package/dist/tag/index.js +0 -121
- package/dist/tag/index.js.map +0 -1
- package/dist/tag/int.d.ts +0 -12
- package/dist/tag/int.d.ts.map +0 -1
- package/dist/tag/int.js +0 -49
- package/dist/tag/int.js.map +0 -1
- package/dist/tag/string.d.ts +0 -11
- package/dist/tag/string.d.ts.map +0 -1
- package/dist/tag/string.js +0 -37
- package/dist/tag/string.js.map +0 -1
- package/dist/tag/tag.d.ts +0 -67
- package/dist/tag/tag.d.ts.map +0 -1
- package/dist/tag/tag.js +0 -157
- package/dist/tag/tag.js.map +0 -1
- package/dist/tag/tuple.d.ts +0 -17
- package/dist/tag/tuple.d.ts.map +0 -1
- package/dist/tag/tuple.js +0 -162
- package/dist/tag/tuple.js.map +0 -1
- package/dist/tag/uint.d.ts +0 -12
- package/dist/tag/uint.d.ts.map +0 -1
- package/dist/tag/uint.js +0 -49
- package/dist/tag/uint.js.map +0 -1
- package/dist/test/did.d.ts +0 -2
- package/dist/test/did.d.ts.map +0 -1
- package/dist/test/did.js +0 -177
- package/dist/test/did.js.map +0 -1
- package/dist/utils/tag-abi-codec.d.ts +0 -69
- package/dist/utils/tag-abi-codec.d.ts.map +0 -1
- package/dist/utils/tag-abi-codec.js +0 -144
- package/dist/utils/tag-abi-codec.js.map +0 -1
- package/examples/crypto-utilities.ts +0 -140
- package/examples/ed25519-jwk.ts +0 -73
- package/examples/generate-mnemonic.ts +0 -149
- package/examples/legacy.ts +0 -33
- package/examples/olares-id-format.ts +0 -197
- package/examples/tag-builder.ts +0 -235
- package/examples/tag-nested-tuple.ts +0 -190
- package/examples/tag-simple.ts +0 -149
- package/examples/tag-tagger.ts +0 -217
- package/examples/test-nested-tuple-conversion.ts +0 -143
- package/examples/test-type-bytes-parser.ts +0 -70
- package/src/abi/ABITypeABI.ts +0 -379
- package/src/abi/RegistryABI.ts +0 -459
- package/src/tag/address.ts +0 -48
- package/src/tag/array.ts +0 -80
- package/src/tag/bool.ts +0 -43
- package/src/tag/bytes.ts +0 -38
- package/src/tag/flarray.ts +0 -99
- package/src/tag/flbytes.ts +0 -48
- package/src/tag/index.ts +0 -170
- package/src/tag/int.ts +0 -51
- package/src/tag/string.ts +0 -38
- package/src/tag/tag.ts +0 -229
- package/src/tag/tuple.ts +0 -193
- package/src/tag/uint.ts +0 -51
- package/src/test/did.ts +0 -346
- package/src/utils/tag-abi-codec.ts +0 -158
package/examples/tag-simple.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple Tag Example
|
|
3
|
-
*
|
|
4
|
-
* This example shows the simplest way to use Tags:
|
|
5
|
-
* - Define a few simple tags
|
|
6
|
-
* - Set and get values
|
|
7
|
-
* - No complex types or arrays
|
|
8
|
-
*
|
|
9
|
-
* Prerequisites:
|
|
10
|
-
* - Set PRIVATE_KEY_OR_MNEMONIC environment variable
|
|
11
|
-
* - You must own the domain you're operating on
|
|
12
|
-
*
|
|
13
|
-
* Run:
|
|
14
|
-
* export PRIVATE_KEY_OR_MNEMONIC="your private key or mnemonic"
|
|
15
|
-
* npx ts-node examples/tag-simple.ts <domain-name>
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import OlaresID from '../src/index';
|
|
19
|
-
|
|
20
|
-
async function main() {
|
|
21
|
-
// Initialize
|
|
22
|
-
const olaresId = OlaresID.createTestnet();
|
|
23
|
-
const privateKeyOrMnemonic = process.env.PRIVATE_KEY_OR_MNEMONIC;
|
|
24
|
-
|
|
25
|
-
if (!privateKeyOrMnemonic) {
|
|
26
|
-
console.error(
|
|
27
|
-
'ā Error: PRIVATE_KEY_OR_MNEMONIC environment variable not set'
|
|
28
|
-
);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await olaresId.setSigner(privateKeyOrMnemonic);
|
|
33
|
-
|
|
34
|
-
const domainName = process.argv[2];
|
|
35
|
-
if (!domainName) {
|
|
36
|
-
console.error('ā Error: Please provide a domain name');
|
|
37
|
-
console.log('Usage: npx ts-node examples/tag-simple.ts <domain-name>');
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const domain = olaresId.domain(domainName);
|
|
42
|
-
const signerAddress = await olaresId.getSigner().getAddress();
|
|
43
|
-
console.log(`\nš·ļø Simple Tag Example for: ${domainName}`);
|
|
44
|
-
console.log(`š¤ Signer: ${signerAddress}\n`);
|
|
45
|
-
|
|
46
|
-
// Step 1: Define tag types (skip if already defined)
|
|
47
|
-
console.log('1ļøā£ Defining tag types...');
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
await domain.defineSimpleTag('bio', 'string');
|
|
51
|
-
console.log(' ā
Defined "bio" (string)');
|
|
52
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
53
|
-
} catch (error: any) {
|
|
54
|
-
if (
|
|
55
|
-
error.message?.includes('RedefinedTag') ||
|
|
56
|
-
error.message?.includes('already been defined')
|
|
57
|
-
) {
|
|
58
|
-
console.log(' ā ļø "bio" already defined, skipping...');
|
|
59
|
-
} else {
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
await domain.defineSimpleTag('followers', 'uint32');
|
|
66
|
-
console.log(' ā
Defined "followers" (uint32)');
|
|
67
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
68
|
-
} catch (error: any) {
|
|
69
|
-
if (
|
|
70
|
-
error.message?.includes('RedefinedTag') ||
|
|
71
|
-
error.message?.includes('already been defined')
|
|
72
|
-
) {
|
|
73
|
-
console.log(' ā ļø "followers" already defined, skipping...');
|
|
74
|
-
} else {
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
await domain.defineSimpleTag('premium', 'bool');
|
|
81
|
-
console.log(' ā
Defined "premium" (bool)\n');
|
|
82
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
83
|
-
} catch (error: any) {
|
|
84
|
-
if (
|
|
85
|
-
error.message?.includes('RedefinedTag') ||
|
|
86
|
-
error.message?.includes('already been defined')
|
|
87
|
-
) {
|
|
88
|
-
console.log(' ā ļø "premium" already defined, skipping...\n');
|
|
89
|
-
} else {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Step 2: Set taggers (IMPORTANT!)
|
|
95
|
-
console.log('2ļøā£ Setting taggers (required before setting values)...');
|
|
96
|
-
await domain.setTagger('bio', signerAddress);
|
|
97
|
-
console.log(' ā
Set tagger for "bio"');
|
|
98
|
-
|
|
99
|
-
await domain.setTagger('followers', signerAddress);
|
|
100
|
-
console.log(' ā
Set tagger for "followers"');
|
|
101
|
-
|
|
102
|
-
await domain.setTagger('premium', signerAddress);
|
|
103
|
-
console.log(' ā
Set tagger for "premium"\n');
|
|
104
|
-
|
|
105
|
-
// Wait for indexing
|
|
106
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
107
|
-
|
|
108
|
-
// Step 3: Set values
|
|
109
|
-
console.log('3ļøā£ Setting tag values...');
|
|
110
|
-
await domain.setTag('bio', 'Web3 developer and blockchain enthusiast');
|
|
111
|
-
console.log(' ā
Set "bio"');
|
|
112
|
-
|
|
113
|
-
await domain.setTag('followers', 1250);
|
|
114
|
-
console.log(' ā
Set "followers"');
|
|
115
|
-
|
|
116
|
-
await domain.setTag('premium', true);
|
|
117
|
-
console.log(' ā
Set "premium"\n');
|
|
118
|
-
|
|
119
|
-
// Wait for indexing
|
|
120
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
121
|
-
|
|
122
|
-
// Step 4: Get values
|
|
123
|
-
console.log('4ļøā£ Reading tag values...');
|
|
124
|
-
const bio = await domain.getTag('bio');
|
|
125
|
-
const followers = await domain.getTag('followers');
|
|
126
|
-
const premium = await domain.getTag('premium');
|
|
127
|
-
|
|
128
|
-
console.log(` bio: "${bio}"`);
|
|
129
|
-
console.log(` followers: ${followers}`);
|
|
130
|
-
console.log(` premium: ${premium}\n`);
|
|
131
|
-
|
|
132
|
-
// Step 5: Update a value
|
|
133
|
-
console.log('5ļøā£ Updating "followers" count...');
|
|
134
|
-
await domain.setTag('followers', 1350);
|
|
135
|
-
console.log(' ā
Updated "followers"\n');
|
|
136
|
-
|
|
137
|
-
// Wait for indexing
|
|
138
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
139
|
-
|
|
140
|
-
const updatedFollowers = await domain.getTag('followers');
|
|
141
|
-
console.log(` New followers count: ${updatedFollowers}\n`);
|
|
142
|
-
|
|
143
|
-
console.log('ā
Simple Tag Example Completed!\n');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
main().catch((error) => {
|
|
147
|
-
console.error('ā Error:', error.message);
|
|
148
|
-
process.exit(1);
|
|
149
|
-
});
|
package/examples/tag-tagger.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tag Tagger Management Example
|
|
3
|
-
*
|
|
4
|
-
* This example demonstrates how to set and get taggers (managers) for Tags.
|
|
5
|
-
* A tagger is an address that has permission to manage a specific Tag.
|
|
6
|
-
*
|
|
7
|
-
* Prerequisites:
|
|
8
|
-
* - Set PRIVATE_KEY_OR_MNEMONIC environment variable (domain owner)
|
|
9
|
-
* - You must own the domain you're operating on
|
|
10
|
-
*
|
|
11
|
-
* Run:
|
|
12
|
-
* export PRIVATE_KEY_OR_MNEMONIC="your private key or mnemonic"
|
|
13
|
-
* npx ts-node examples/tag-tagger.ts <domain-name>
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import OlaresID from '../src/index';
|
|
17
|
-
|
|
18
|
-
async function main() {
|
|
19
|
-
// Initialize OlaresID
|
|
20
|
-
const olaresId = OlaresID.createTestnet();
|
|
21
|
-
|
|
22
|
-
// Get private key or mnemonic from environment
|
|
23
|
-
const privateKeyOrMnemonic = process.env.PRIVATE_KEY_OR_MNEMONIC;
|
|
24
|
-
if (!privateKeyOrMnemonic) {
|
|
25
|
-
console.error(
|
|
26
|
-
'ā Error: PRIVATE_KEY_OR_MNEMONIC environment variable not set'
|
|
27
|
-
);
|
|
28
|
-
console.log(
|
|
29
|
-
'Usage: export PRIVATE_KEY_OR_MNEMONIC="your private key or mnemonic"'
|
|
30
|
-
);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
await olaresId.setSigner(privateKeyOrMnemonic);
|
|
35
|
-
const signerAddress = await olaresId.getSigner().getAddress();
|
|
36
|
-
console.log(`ā
Signer address: ${signerAddress}\n`);
|
|
37
|
-
|
|
38
|
-
// Get domain name from command line
|
|
39
|
-
const domainName = process.argv[2];
|
|
40
|
-
if (!domainName) {
|
|
41
|
-
console.error('ā Error: Please provide a domain name');
|
|
42
|
-
console.log('Usage: npx ts-node examples/tag-tagger.ts <domain-name>');
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const domain = olaresId.domain(domainName);
|
|
47
|
-
console.log(`š·ļø Managing Taggers for domain: ${domainName}\n`);
|
|
48
|
-
|
|
49
|
-
// ========================================
|
|
50
|
-
// Part 1: Define a Tag
|
|
51
|
-
// ========================================
|
|
52
|
-
console.log('='.repeat(60));
|
|
53
|
-
console.log('Part 1: Define a Tag');
|
|
54
|
-
console.log('='.repeat(60));
|
|
55
|
-
|
|
56
|
-
const tagName = 'userStatus';
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
console.log(`š Defining "${tagName}" tag (type: string)...`);
|
|
60
|
-
await domain.defineSimpleTag(tagName, 'string');
|
|
61
|
-
console.log(`ā
"${tagName}" tag defined\n`);
|
|
62
|
-
|
|
63
|
-
// Wait for indexing
|
|
64
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
65
|
-
} catch (error: any) {
|
|
66
|
-
console.error(`ā Error defining tag: ${error.message}\n`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ========================================
|
|
70
|
-
// Part 2: Check Initial Tagger
|
|
71
|
-
// ========================================
|
|
72
|
-
console.log('='.repeat(60));
|
|
73
|
-
console.log('Part 2: Check Initial Tagger');
|
|
74
|
-
console.log('='.repeat(60));
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const initialTagger = await domain.getTagger(tagName);
|
|
78
|
-
console.log(`š Current tagger: ${initialTagger}`);
|
|
79
|
-
|
|
80
|
-
if (initialTagger === '0x0000000000000000000000000000000000000000') {
|
|
81
|
-
console.log(' ā¹ļø No specific tagger set (zero address)');
|
|
82
|
-
console.log(' ā¹ļø No one can manage this tag (disabled)\n');
|
|
83
|
-
} else {
|
|
84
|
-
console.log(` ā¹ļø Tagger is set to: ${initialTagger}\n`);
|
|
85
|
-
}
|
|
86
|
-
} catch (error: any) {
|
|
87
|
-
console.error(`ā Error getting tagger: ${error.message}\n`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ========================================
|
|
91
|
-
// Part 3: Set a Specific Tagger
|
|
92
|
-
// ========================================
|
|
93
|
-
console.log('='.repeat(60));
|
|
94
|
-
console.log('Part 3: Set a Specific Tagger');
|
|
95
|
-
console.log('='.repeat(60));
|
|
96
|
-
|
|
97
|
-
// Example tagger address (replace with your own)
|
|
98
|
-
const taggerAddress = '0x1234567890123456789012345678901234567890';
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
console.log(`š Setting tagger to: ${taggerAddress}...`);
|
|
102
|
-
const result = await domain.setTagger(tagName, taggerAddress);
|
|
103
|
-
console.log(`ā
Tagger set successfully`);
|
|
104
|
-
console.log(` Transaction hash: ${result.transactionHash}\n`);
|
|
105
|
-
|
|
106
|
-
// Wait for indexing
|
|
107
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
108
|
-
|
|
109
|
-
// Verify the tagger was set
|
|
110
|
-
const newTagger = await domain.getTagger(tagName);
|
|
111
|
-
console.log(`š Verified tagger: ${newTagger}`);
|
|
112
|
-
|
|
113
|
-
if (newTagger.toLowerCase() === taggerAddress.toLowerCase()) {
|
|
114
|
-
console.log(' ā
Tagger correctly set!\n');
|
|
115
|
-
} else {
|
|
116
|
-
console.log(' ā ļø Tagger mismatch!\n');
|
|
117
|
-
}
|
|
118
|
-
} catch (error: any) {
|
|
119
|
-
console.error(`ā Error setting tagger: ${error.message}\n`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// ========================================
|
|
123
|
-
// Part 4: Set Tagger to Zero Address (Disable Tag Management)
|
|
124
|
-
// ========================================
|
|
125
|
-
console.log('='.repeat(60));
|
|
126
|
-
console.log('Part 4: Set Tagger to Zero Address (Disable Management)');
|
|
127
|
-
console.log('='.repeat(60));
|
|
128
|
-
|
|
129
|
-
const zeroAddress = '0x0000000000000000000000000000000000000000';
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
console.log(
|
|
133
|
-
`š Setting tagger to zero address (disable management)...`
|
|
134
|
-
);
|
|
135
|
-
const result = await domain.setTagger(tagName, zeroAddress);
|
|
136
|
-
console.log(`ā
Tagger set to zero address`);
|
|
137
|
-
console.log(` Transaction hash: ${result.transactionHash}\n`);
|
|
138
|
-
|
|
139
|
-
// Wait for indexing
|
|
140
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
141
|
-
|
|
142
|
-
// Verify
|
|
143
|
-
const publicTagger = await domain.getTagger(tagName);
|
|
144
|
-
console.log(`š Verified tagger: ${publicTagger}`);
|
|
145
|
-
|
|
146
|
-
if (publicTagger === zeroAddress) {
|
|
147
|
-
console.log(
|
|
148
|
-
' ā
Tag management is now disabled (no one can set it)!\n'
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
} catch (error: any) {
|
|
152
|
-
console.error(`ā Error setting tagger to zero: ${error.message}\n`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ========================================
|
|
156
|
-
// Part 5: Set Tagger to Self (Owner Only)
|
|
157
|
-
// ========================================
|
|
158
|
-
console.log('='.repeat(60));
|
|
159
|
-
console.log('Part 5: Set Tagger to Self (Owner Only)');
|
|
160
|
-
console.log('='.repeat(60));
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
console.log(`š Setting tagger to signer address (owner only)...`);
|
|
164
|
-
const result = await domain.setTagger(tagName, signerAddress);
|
|
165
|
-
console.log(`ā
Tagger set to: ${signerAddress}`);
|
|
166
|
-
console.log(` Transaction hash: ${result.transactionHash}\n`);
|
|
167
|
-
|
|
168
|
-
// Wait for indexing
|
|
169
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
170
|
-
|
|
171
|
-
// Verify
|
|
172
|
-
const ownerTagger = await domain.getTagger(tagName);
|
|
173
|
-
console.log(`š Verified tagger: ${ownerTagger}`);
|
|
174
|
-
|
|
175
|
-
if (ownerTagger.toLowerCase() === signerAddress.toLowerCase()) {
|
|
176
|
-
console.log(' ā
Only the owner can manage this tag now!\n');
|
|
177
|
-
}
|
|
178
|
-
} catch (error: any) {
|
|
179
|
-
console.error(`ā Error setting tagger to self: ${error.message}\n`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// ========================================
|
|
183
|
-
// Part 6: Using TagContext (Advanced)
|
|
184
|
-
// ========================================
|
|
185
|
-
console.log('='.repeat(60));
|
|
186
|
-
console.log('Part 6: Using TagContext (Advanced API)');
|
|
187
|
-
console.log('='.repeat(60));
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
const tagCtx = domain.tag();
|
|
191
|
-
|
|
192
|
-
console.log('š Getting tagger using TagContext...');
|
|
193
|
-
const ctxTagger = await tagCtx.getTagger(tagName);
|
|
194
|
-
console.log(` Tagger: ${ctxTagger}`);
|
|
195
|
-
|
|
196
|
-
console.log('\nš Setting tagger back to zero using TagContext...');
|
|
197
|
-
const result = await tagCtx.setTagger(tagName, zeroAddress);
|
|
198
|
-
console.log(` ā
Done: ${result.transactionHash}\n`);
|
|
199
|
-
} catch (error: any) {
|
|
200
|
-
console.error(`ā Error with TagContext: ${error.message}\n`);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
console.log('='.repeat(60));
|
|
204
|
-
console.log('ā
Tag Tagger Management Example Completed');
|
|
205
|
-
console.log('='.repeat(60));
|
|
206
|
-
console.log('\nš” Key Points:');
|
|
207
|
-
console.log(' ⢠Only domain owner can set taggers');
|
|
208
|
-
console.log(' ⢠Zero address = disabled (no one can manage)');
|
|
209
|
-
console.log(' ⢠Specific address = only that address can manage');
|
|
210
|
-
console.log(' ⢠Use getTagger() to check who can manage a tag\n');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Run the example
|
|
214
|
-
main().catch((error) => {
|
|
215
|
-
console.error('ā Fatal error:', error);
|
|
216
|
-
process.exit(1);
|
|
217
|
-
});
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { TagAbiCodec } from '../src/utils/tag-abi-codec';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Test script for TagAbiCodec nested tuple conversion
|
|
5
|
-
* Tests the parseTupleFields and convertObjectToArray functions
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
console.log('='.repeat(60));
|
|
9
|
-
console.log('TagAbiCodec Nested Tuple Conversion Test');
|
|
10
|
-
console.log('='.repeat(60));
|
|
11
|
-
|
|
12
|
-
// Test 1: Simple tuple
|
|
13
|
-
console.log('\n1. Simple Tuple:');
|
|
14
|
-
console.log(' ABI Type: tuple(string,uint8)');
|
|
15
|
-
const obj1 = { name: 'Alice', age: 30 };
|
|
16
|
-
console.log(' Input:', JSON.stringify(obj1));
|
|
17
|
-
const encoded1 = TagAbiCodec.encode('tuple(string,uint8)', obj1);
|
|
18
|
-
console.log(' Encoded:', encoded1);
|
|
19
|
-
const decoded1 = TagAbiCodec.decode('tuple(string,uint8)', encoded1);
|
|
20
|
-
console.log(
|
|
21
|
-
' Decoded:',
|
|
22
|
-
JSON.stringify(decoded1, (_, v) =>
|
|
23
|
-
typeof v === 'bigint' ? v.toString() : v
|
|
24
|
-
)
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
// Test 2: Nested tuple (1 level)
|
|
28
|
-
console.log('\n2. Nested Tuple (1 level):');
|
|
29
|
-
console.log(' ABI Type: tuple(string,tuple(uint8,bool))');
|
|
30
|
-
const obj2 = {
|
|
31
|
-
name: 'Alice',
|
|
32
|
-
details: {
|
|
33
|
-
age: 30,
|
|
34
|
-
verified: true
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
console.log(' Input:', JSON.stringify(obj2));
|
|
38
|
-
const encoded2 = TagAbiCodec.encode('tuple(string,tuple(uint8,bool))', obj2);
|
|
39
|
-
console.log(' Encoded:', encoded2);
|
|
40
|
-
const decoded2 = TagAbiCodec.decode(
|
|
41
|
-
'tuple(string,tuple(uint8,bool))',
|
|
42
|
-
encoded2
|
|
43
|
-
);
|
|
44
|
-
console.log(
|
|
45
|
-
' Decoded:',
|
|
46
|
-
JSON.stringify(decoded2, (_, v) =>
|
|
47
|
-
typeof v === 'bigint' ? v.toString() : v
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// Test 3: Nested tuple (2 levels)
|
|
52
|
-
console.log('\n3. Nested Tuple (2 levels):');
|
|
53
|
-
console.log(
|
|
54
|
-
' ABI Type: tuple(string,tuple(uint8,bool),tuple(string,string))'
|
|
55
|
-
);
|
|
56
|
-
const obj3 = {
|
|
57
|
-
name: 'Alice',
|
|
58
|
-
details: {
|
|
59
|
-
age: 30,
|
|
60
|
-
verified: true
|
|
61
|
-
},
|
|
62
|
-
contact: {
|
|
63
|
-
email: 'alice@example.com',
|
|
64
|
-
phone: '+1-555-0123'
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
console.log(' Input:', JSON.stringify(obj3, null, 2));
|
|
68
|
-
const encoded3 = TagAbiCodec.encode(
|
|
69
|
-
'tuple(string,tuple(uint8,bool),tuple(string,string))',
|
|
70
|
-
obj3
|
|
71
|
-
);
|
|
72
|
-
console.log(' Encoded:', encoded3);
|
|
73
|
-
const decoded3 = TagAbiCodec.decode(
|
|
74
|
-
'tuple(string,tuple(uint8,bool),tuple(string,string))',
|
|
75
|
-
encoded3
|
|
76
|
-
);
|
|
77
|
-
console.log(
|
|
78
|
-
' Decoded:',
|
|
79
|
-
JSON.stringify(
|
|
80
|
-
decoded3,
|
|
81
|
-
(_, v) => (typeof v === 'bigint' ? v.toString() : v),
|
|
82
|
-
2
|
|
83
|
-
)
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// Test 4: Array notation (still supported)
|
|
87
|
-
console.log('\n4. Array Notation (still supported):');
|
|
88
|
-
console.log(' ABI Type: tuple(string,tuple(uint8,bool))');
|
|
89
|
-
const arr4 = ['Bob', [25, false]];
|
|
90
|
-
console.log(' Input:', JSON.stringify(arr4));
|
|
91
|
-
const encoded4 = TagAbiCodec.encode('tuple(string,tuple(uint8,bool))', arr4);
|
|
92
|
-
console.log(' Encoded:', encoded4);
|
|
93
|
-
const decoded4 = TagAbiCodec.decode(
|
|
94
|
-
'tuple(string,tuple(uint8,bool))',
|
|
95
|
-
encoded4
|
|
96
|
-
);
|
|
97
|
-
console.log(
|
|
98
|
-
' Decoded:',
|
|
99
|
-
JSON.stringify(decoded4, (_, v) =>
|
|
100
|
-
typeof v === 'bigint' ? v.toString() : v
|
|
101
|
-
)
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Test 5: Complex nested structure
|
|
105
|
-
console.log('\n5. Complex Nested Structure:');
|
|
106
|
-
console.log(' ABI Type: tuple(string,tuple(tuple(uint8,bool),address))');
|
|
107
|
-
const obj5 = {
|
|
108
|
-
name: 'Charlie',
|
|
109
|
-
data: {
|
|
110
|
-
info: {
|
|
111
|
-
age: 40,
|
|
112
|
-
active: true
|
|
113
|
-
},
|
|
114
|
-
wallet: '0x1234567890123456789012345678901234567890'
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
console.log(' Input:', JSON.stringify(obj5, null, 2));
|
|
118
|
-
const encoded5 = TagAbiCodec.encode(
|
|
119
|
-
'tuple(string,tuple(tuple(uint8,bool),address))',
|
|
120
|
-
obj5
|
|
121
|
-
);
|
|
122
|
-
console.log(' Encoded:', encoded5);
|
|
123
|
-
const decoded5 = TagAbiCodec.decode(
|
|
124
|
-
'tuple(string,tuple(tuple(uint8,bool),address))',
|
|
125
|
-
encoded5
|
|
126
|
-
);
|
|
127
|
-
console.log(
|
|
128
|
-
' Decoded:',
|
|
129
|
-
JSON.stringify(
|
|
130
|
-
decoded5,
|
|
131
|
-
(_, v) => (typeof v === 'bigint' ? v.toString() : v),
|
|
132
|
-
2
|
|
133
|
-
)
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
console.log('\n' + '='.repeat(60));
|
|
137
|
-
console.log('ā
All tests completed successfully!');
|
|
138
|
-
console.log('='.repeat(60));
|
|
139
|
-
console.log('\nš” Key Features:');
|
|
140
|
-
console.log(' ⢠Objects are automatically converted to arrays');
|
|
141
|
-
console.log(' ⢠Nested tuples work recursively');
|
|
142
|
-
console.log(' ⢠Array notation is still supported');
|
|
143
|
-
console.log(' ⢠No need to manually provide field names\n');
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
/**
|
|
3
|
-
* Test Type Bytes Parser
|
|
4
|
-
* Verifies that parseTypeBytesToAbiString correctly converts type bytes to ABI strings
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { TagTypeBuilder } from '../src/utils/tag-type-builder';
|
|
8
|
-
|
|
9
|
-
console.log('š§Ŗ Testing Type Bytes Parser\n');
|
|
10
|
-
|
|
11
|
-
interface TestCase {
|
|
12
|
-
name: string;
|
|
13
|
-
typeBytes: string;
|
|
14
|
-
expectedAbi: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const testCases: TestCase[] = [
|
|
18
|
-
// Simple types
|
|
19
|
-
{ name: 'string', typeBytes: '0x03', expectedAbi: 'string' },
|
|
20
|
-
{ name: 'uint8', typeBytes: '0x0101', expectedAbi: 'uint8' },
|
|
21
|
-
{ name: 'uint256', typeBytes: '0x0120', expectedAbi: 'uint256' },
|
|
22
|
-
{ name: 'bool', typeBytes: '0x02', expectedAbi: 'bool' },
|
|
23
|
-
{ name: 'address', typeBytes: '0x07', expectedAbi: 'address' },
|
|
24
|
-
|
|
25
|
-
// Array types
|
|
26
|
-
{ name: 'string[]', typeBytes: '0x0403', expectedAbi: 'string[]' },
|
|
27
|
-
{ name: 'address[]', typeBytes: '0x0407', expectedAbi: 'address[]' },
|
|
28
|
-
|
|
29
|
-
// Complex tuple (from tag-management.ts)
|
|
30
|
-
{
|
|
31
|
-
name: 'userInfo tuple',
|
|
32
|
-
typeBytes: '0x060004030101040702',
|
|
33
|
-
expectedAbi: 'tuple(string,uint8,address[],bool)'
|
|
34
|
-
}
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
let passed = 0;
|
|
38
|
-
let failed = 0;
|
|
39
|
-
|
|
40
|
-
for (const testCase of testCases) {
|
|
41
|
-
try {
|
|
42
|
-
const result = TagTypeBuilder.parseTypeBytesToAbiString(
|
|
43
|
-
testCase.typeBytes
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (result === testCase.expectedAbi) {
|
|
47
|
-
console.log(`ā
${testCase.name}`);
|
|
48
|
-
console.log(` Type bytes: ${testCase.typeBytes}`);
|
|
49
|
-
console.log(` ABI string: ${result}\n`);
|
|
50
|
-
passed++;
|
|
51
|
-
} else {
|
|
52
|
-
console.log(`ā ${testCase.name} - MISMATCH`);
|
|
53
|
-
console.log(` Type bytes: ${testCase.typeBytes}`);
|
|
54
|
-
console.log(` Expected: ${testCase.expectedAbi}`);
|
|
55
|
-
console.log(` Got: ${result}\n`);
|
|
56
|
-
failed++;
|
|
57
|
-
}
|
|
58
|
-
} catch (error: any) {
|
|
59
|
-
console.log(`ā ${testCase.name} - ERROR`);
|
|
60
|
-
console.log(` Type bytes: ${testCase.typeBytes}`);
|
|
61
|
-
console.log(` Error: ${error.message}\n`);
|
|
62
|
-
failed++;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log('============================================================');
|
|
67
|
-
console.log(`Results: ${passed} passed, ${failed} failed`);
|
|
68
|
-
console.log('============================================================\n');
|
|
69
|
-
|
|
70
|
-
process.exit(failed > 0 ? 1 : 0);
|