@beclab/olaresid 0.1.1 → 0.1.3
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 +1300 -0
- package/README.md +40 -31
- package/TAG.md +589 -0
- package/dist/abi/RootResolver2ABI.d.ts +54 -0
- package/dist/abi/RootResolver2ABI.d.ts.map +1 -0
- package/dist/abi/RootResolver2ABI.js +240 -0
- package/dist/abi/RootResolver2ABI.js.map +1 -0
- package/dist/business/index.d.ts +302 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/index.js +1211 -0
- package/dist/business/index.js.map +1 -0
- package/dist/business/tag-context.d.ts +219 -0
- package/dist/business/tag-context.d.ts.map +1 -0
- package/dist/business/tag-context.js +560 -0
- package/dist/business/tag-context.js.map +1 -0
- package/dist/cli.js +2102 -39
- package/dist/cli.js.map +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/debug.js +14 -2
- package/dist/debug.js.map +1 -1
- package/dist/index.d.ts +51 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +241 -12
- package/dist/index.js.map +1 -1
- package/dist/utils/crypto-utils.d.ts +130 -0
- package/dist/utils/crypto-utils.d.ts.map +1 -0
- package/dist/utils/crypto-utils.js +402 -0
- package/dist/utils/crypto-utils.js.map +1 -0
- package/dist/utils/error-parser.d.ts +35 -0
- package/dist/utils/error-parser.d.ts.map +1 -0
- package/dist/utils/error-parser.js +202 -0
- package/dist/utils/error-parser.js.map +1 -0
- package/dist/utils/olares-id.d.ts +36 -0
- package/dist/utils/olares-id.d.ts.map +1 -0
- package/dist/utils/olares-id.js +52 -0
- package/dist/utils/olares-id.js.map +1 -0
- package/dist/utils/tag-abi-codec.d.ts +69 -0
- package/dist/utils/tag-abi-codec.d.ts.map +1 -0
- package/dist/utils/tag-abi-codec.js +144 -0
- package/dist/utils/tag-abi-codec.js.map +1 -0
- package/dist/utils/tag-type-builder.d.ts +158 -0
- package/dist/utils/tag-type-builder.d.ts.map +1 -0
- package/dist/utils/tag-type-builder.js +410 -0
- package/dist/utils/tag-type-builder.js.map +1 -0
- package/examples/crypto-utilities.ts +140 -0
- package/examples/domain-context.ts +80 -0
- package/examples/generate-mnemonic.ts +149 -0
- package/examples/index.ts +1 -1
- package/examples/ip.ts +171 -0
- package/examples/legacy.ts +10 -10
- package/examples/list-wallets.ts +81 -0
- package/examples/olares-id-format.ts +197 -0
- package/examples/quasar-demo/.eslintrc.js +23 -0
- package/examples/quasar-demo/.quasar/app.js +43 -0
- package/examples/quasar-demo/.quasar/client-entry.js +38 -0
- package/examples/quasar-demo/.quasar/client-prefetch.js +130 -0
- package/examples/quasar-demo/.quasar/quasar-user-options.js +16 -0
- package/examples/quasar-demo/README.md +49 -0
- package/examples/quasar-demo/index.html +11 -0
- package/examples/quasar-demo/package-lock.json +6407 -0
- package/examples/quasar-demo/package.json +36 -0
- package/examples/quasar-demo/quasar.config.js +73 -0
- package/examples/quasar-demo/src/App.vue +13 -0
- package/examples/quasar-demo/src/css/app.scss +1 -0
- package/examples/quasar-demo/src/layouts/MainLayout.vue +21 -0
- package/examples/quasar-demo/src/pages/IndexPage.vue +905 -0
- package/examples/quasar-demo/src/router/index.ts +25 -0
- package/examples/quasar-demo/src/router/routes.ts +11 -0
- package/examples/quasar-demo/tsconfig.json +28 -0
- package/examples/register-subdomain.ts +152 -0
- package/examples/rsa-keypair.ts +148 -0
- package/examples/tag-builder.ts +235 -0
- package/examples/tag-management.ts +534 -0
- package/examples/tag-nested-tuple.ts +190 -0
- package/examples/tag-simple.ts +149 -0
- package/examples/tag-tagger.ts +217 -0
- package/examples/test-nested-tuple-conversion.ts +143 -0
- package/examples/test-type-bytes-parser.ts +70 -0
- package/examples/transfer-domain.ts +197 -0
- package/examples/wallet-management.ts +196 -0
- package/package.json +24 -15
- package/src/abi/RootResolver2ABI.ts +237 -0
- package/src/business/index.ts +1492 -0
- package/src/business/tag-context.ts +747 -0
- package/src/cli.ts +2772 -39
- package/src/debug.ts +17 -2
- package/src/index.ts +313 -17
- package/src/utils/crypto-utils.ts +459 -0
- package/src/utils/error-parser.ts +225 -0
- package/src/utils/olares-id.ts +49 -0
- package/src/utils/tag-abi-codec.ts +158 -0
- package/src/utils/tag-type-builder.ts +469 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Generate mnemonic and derive keys using Trust Wallet Core
|
|
3
|
+
*
|
|
4
|
+
* This implementation is compatible with TermiPass and the entire Olares ecosystem.
|
|
5
|
+
* It uses Trust Wallet Core for key derivation, ensuring consistency across all projects.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
generateMnemonic,
|
|
10
|
+
getEthereumAddressFromMnemonic,
|
|
11
|
+
getDIDFromMnemonic,
|
|
12
|
+
generateDIDKeyData,
|
|
13
|
+
deriveDIDFromMnemonic
|
|
14
|
+
} from '../src/index';
|
|
15
|
+
|
|
16
|
+
async function example1_generateNew() {
|
|
17
|
+
console.log('='.repeat(60));
|
|
18
|
+
console.log('Example 1: Generate New Mnemonic and Keys');
|
|
19
|
+
console.log('Using Trust Wallet Core (Same as TermiPass)');
|
|
20
|
+
console.log('='.repeat(60));
|
|
21
|
+
|
|
22
|
+
// Generate a 12-word mnemonic
|
|
23
|
+
console.log('\n🔑 Generating 12-word mnemonic...');
|
|
24
|
+
const mnemonic12 = generateMnemonic(12);
|
|
25
|
+
console.log(`Mnemonic: ${mnemonic12}`);
|
|
26
|
+
|
|
27
|
+
console.log('\n⏳ Deriving keys using Trust Wallet Core...');
|
|
28
|
+
const owner12 = await getEthereumAddressFromMnemonic(mnemonic12);
|
|
29
|
+
const did12 = await getDIDFromMnemonic(mnemonic12);
|
|
30
|
+
|
|
31
|
+
console.log('\n✅ Derived keys:');
|
|
32
|
+
console.log(` Ethereum Address: ${owner12}`);
|
|
33
|
+
console.log(` DID: ${did12}`);
|
|
34
|
+
|
|
35
|
+
// Generate a 24-word mnemonic
|
|
36
|
+
console.log('\n' + '-'.repeat(60));
|
|
37
|
+
console.log('\n🔑 Generating 24-word mnemonic...');
|
|
38
|
+
const mnemonic24 = generateMnemonic(24);
|
|
39
|
+
console.log(`Mnemonic: ${mnemonic24}`);
|
|
40
|
+
|
|
41
|
+
console.log('\n⏳ Deriving keys...');
|
|
42
|
+
const owner24 = await getEthereumAddressFromMnemonic(mnemonic24);
|
|
43
|
+
const did24 = await getDIDFromMnemonic(mnemonic24);
|
|
44
|
+
|
|
45
|
+
console.log('\n✅ Derived keys:');
|
|
46
|
+
console.log(` Ethereum Address: ${owner24}`);
|
|
47
|
+
console.log(` DID: ${did24}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function example2_useGenerateDIDKeyData() {
|
|
51
|
+
console.log('\n\n' + '='.repeat(60));
|
|
52
|
+
console.log('Example 2: Generate Everything at Once');
|
|
53
|
+
console.log('='.repeat(60));
|
|
54
|
+
|
|
55
|
+
console.log('\n⏳ Generating mnemonic and deriving keys...');
|
|
56
|
+
const keyData = await generateDIDKeyData(12);
|
|
57
|
+
|
|
58
|
+
console.log('\n✅ Generated DID Key Data:');
|
|
59
|
+
console.log(` Mnemonic: ${keyData.mnemonic}`);
|
|
60
|
+
console.log(` Owner (Ethereum): ${keyData.owner}`);
|
|
61
|
+
console.log(` DID: ${keyData.did}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function example3_testCompatibility() {
|
|
65
|
+
console.log('\n\n' + '='.repeat(60));
|
|
66
|
+
console.log('Example 3: Verify Compatibility with TermiPass');
|
|
67
|
+
console.log('='.repeat(60));
|
|
68
|
+
|
|
69
|
+
// Use the same test mnemonic as in TermiPass
|
|
70
|
+
const testMnemonic =
|
|
71
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
|
|
72
|
+
|
|
73
|
+
console.log(`\n📝 Input mnemonic (standard test mnemonic):`);
|
|
74
|
+
console.log(testMnemonic);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
console.log('\n⏳ Deriving keys using Trust Wallet Core...');
|
|
78
|
+
const { owner, did } = await deriveDIDFromMnemonic(testMnemonic);
|
|
79
|
+
|
|
80
|
+
console.log('\n✅ Derived keys:');
|
|
81
|
+
console.log(` Ethereum Address: ${owner}`);
|
|
82
|
+
console.log(` DID: ${did}`);
|
|
83
|
+
|
|
84
|
+
console.log('\n💡 Note: These keys should match with TermiPass output');
|
|
85
|
+
console.log(
|
|
86
|
+
' You can verify this by running the same mnemonic in TermiPass'
|
|
87
|
+
);
|
|
88
|
+
} catch (error: any) {
|
|
89
|
+
console.error(`\n❌ Error: ${error.message}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function example4_parallelDerivation() {
|
|
94
|
+
console.log('\n\n' + '='.repeat(60));
|
|
95
|
+
console.log('Example 4: Parallel Key Derivation (Performance Test)');
|
|
96
|
+
console.log('='.repeat(60));
|
|
97
|
+
|
|
98
|
+
const mnemonic = generateMnemonic(12);
|
|
99
|
+
console.log(`\n📝 Mnemonic: ${mnemonic}`);
|
|
100
|
+
|
|
101
|
+
console.log('\n⏳ Deriving owner and DID in parallel...');
|
|
102
|
+
const startTime = Date.now();
|
|
103
|
+
|
|
104
|
+
const { owner, did } = await deriveDIDFromMnemonic(mnemonic);
|
|
105
|
+
|
|
106
|
+
const endTime = Date.now();
|
|
107
|
+
const duration = endTime - startTime;
|
|
108
|
+
|
|
109
|
+
console.log('\n✅ Results:');
|
|
110
|
+
console.log(` Owner: ${owner}`);
|
|
111
|
+
console.log(` DID: ${did}`);
|
|
112
|
+
console.log(` Time taken: ${duration}ms`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function main() {
|
|
116
|
+
console.log('🔐 Trust Wallet Core Integration - Key Generation Examples\n');
|
|
117
|
+
console.log('This implementation ensures compatibility with TermiPass');
|
|
118
|
+
console.log('and the entire Olares ecosystem.\n');
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
await example1_generateNew();
|
|
122
|
+
await example2_useGenerateDIDKeyData();
|
|
123
|
+
await example3_testCompatibility();
|
|
124
|
+
await example4_parallelDerivation();
|
|
125
|
+
|
|
126
|
+
console.log('\n\n' + '='.repeat(60));
|
|
127
|
+
console.log('✅ All examples completed successfully!');
|
|
128
|
+
console.log('='.repeat(60));
|
|
129
|
+
console.log(
|
|
130
|
+
'\n⚠️ SECURITY WARNING: Never share your mnemonic phrase!'
|
|
131
|
+
);
|
|
132
|
+
console.log(
|
|
133
|
+
' Store it securely and never commit it to version control.'
|
|
134
|
+
);
|
|
135
|
+
console.log(
|
|
136
|
+
'\n💡 These keys are compatible with TermiPass and other Olares tools.\n'
|
|
137
|
+
);
|
|
138
|
+
} catch (error: any) {
|
|
139
|
+
console.error('\n❌ Error:', error.message || error);
|
|
140
|
+
if (error.stack) {
|
|
141
|
+
console.error('\nStack trace:');
|
|
142
|
+
console.error(error.stack);
|
|
143
|
+
}
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Run the examples
|
|
149
|
+
main();
|
package/examples/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ async function main() {
|
|
|
6
6
|
const domain = await olaresId.fetchDomain('tw7613781.olares.com');
|
|
7
7
|
console.log(domain);
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// Get all domain data (the mainnet has a large amount of data, the testnet has a small amount of data, for testing it is recommended to experience this function in the testnet environment)
|
|
10
10
|
// await olaresId.fetchAll();
|
|
11
11
|
// console.log('All Domains:', olaresId.allDomainCache);
|
|
12
12
|
// console.log('Domain Tree Cache:', olaresId.treesCache);
|
package/examples/ip.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import OlaresID, { ipv4ToBytes4, bytes4ToIpv4 } from '../src/index';
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
console.log('='.repeat(60));
|
|
5
|
+
console.log('Testing DNS A Record (IP) Methods');
|
|
6
|
+
console.log('='.repeat(60));
|
|
7
|
+
|
|
8
|
+
// Test 1: Convert IPv4 to bytes4
|
|
9
|
+
console.log('\n🔄 Test 1: ipv4ToBytes4()');
|
|
10
|
+
console.log('-'.repeat(60));
|
|
11
|
+
try {
|
|
12
|
+
const testIPs = [
|
|
13
|
+
'127.0.0.1',
|
|
14
|
+
'192.168.1.1',
|
|
15
|
+
'8.8.8.8',
|
|
16
|
+
'255.255.255.255'
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
for (const ip of testIPs) {
|
|
20
|
+
const bytes4 = ipv4ToBytes4(ip);
|
|
21
|
+
console.log(` ${ip} → ${bytes4}`);
|
|
22
|
+
}
|
|
23
|
+
console.log('✅ Successfully converted IPv4 to bytes4');
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('❌ Failed:', error);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Test 2: Convert bytes4 to IPv4
|
|
29
|
+
console.log('\n🔄 Test 2: bytes4ToIpv4()');
|
|
30
|
+
console.log('-'.repeat(60));
|
|
31
|
+
try {
|
|
32
|
+
const testBytes = [
|
|
33
|
+
'0x7f000001',
|
|
34
|
+
'0xc0a80101',
|
|
35
|
+
'0x08080808',
|
|
36
|
+
'0xffffffff'
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
for (const bytes of testBytes) {
|
|
40
|
+
const ip = bytes4ToIpv4(bytes);
|
|
41
|
+
console.log(` ${bytes} → ${ip}`);
|
|
42
|
+
}
|
|
43
|
+
console.log('✅ Successfully converted bytes4 to IPv4');
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('❌ Failed:', error);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Test 3: Round-trip conversion
|
|
49
|
+
console.log('\n🔄 Test 3: Round-trip conversion');
|
|
50
|
+
console.log('-'.repeat(60));
|
|
51
|
+
try {
|
|
52
|
+
const originalIP = '192.168.1.100';
|
|
53
|
+
const bytes4 = ipv4ToBytes4(originalIP);
|
|
54
|
+
const convertedIP = bytes4ToIpv4(bytes4);
|
|
55
|
+
|
|
56
|
+
console.log(` Original: ${originalIP}`);
|
|
57
|
+
console.log(` Bytes4: ${bytes4}`);
|
|
58
|
+
console.log(` Converted: ${convertedIP}`);
|
|
59
|
+
|
|
60
|
+
if (originalIP === convertedIP) {
|
|
61
|
+
console.log('✅ Round-trip conversion successful!');
|
|
62
|
+
} else {
|
|
63
|
+
console.log('⚠️ Round-trip conversion mismatch');
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('❌ Failed:', error);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Test 4: Blockchain operations
|
|
70
|
+
if (process.env.PRIVATE_KEY_OR_MNEMONIC) {
|
|
71
|
+
console.log('\n📝 Test 4: setIP()');
|
|
72
|
+
console.log('-'.repeat(60));
|
|
73
|
+
|
|
74
|
+
const didConsole = OlaresID.createTestnet();
|
|
75
|
+
await didConsole.setSigner(process.env.PRIVATE_KEY_OR_MNEMONIC);
|
|
76
|
+
|
|
77
|
+
const testDomain = '1.com';
|
|
78
|
+
const domain = didConsole.domain(testDomain);
|
|
79
|
+
const testIP = '192.168.1.100';
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const result = await domain.setIP(testIP);
|
|
83
|
+
|
|
84
|
+
if (result.success) {
|
|
85
|
+
console.log('✅ Success:');
|
|
86
|
+
console.log(' Transaction Hash:', result.transactionHash);
|
|
87
|
+
console.log(' Gas Used:', result.gasUsed?.toString());
|
|
88
|
+
|
|
89
|
+
// Wait for the blockchain to index the data
|
|
90
|
+
console.log('⏳ Waiting for blockchain to index data...');
|
|
91
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
92
|
+
} else {
|
|
93
|
+
console.log('❌ Failed:', result.error);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error('❌ Failed:', error);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Test 5: Verify IP was set
|
|
100
|
+
console.log('\n🔍 Test 5: getIP()');
|
|
101
|
+
console.log('-'.repeat(60));
|
|
102
|
+
try {
|
|
103
|
+
const storedIP = await domain.getIP();
|
|
104
|
+
if (storedIP) {
|
|
105
|
+
console.log('✅ DNS A Record found on chain:', storedIP);
|
|
106
|
+
|
|
107
|
+
if (storedIP === testIP) {
|
|
108
|
+
console.log('✅ Stored IP matches our original IP!');
|
|
109
|
+
} else {
|
|
110
|
+
console.log('⚠️ Stored IP differs from original');
|
|
111
|
+
console.log(' Expected:', testIP);
|
|
112
|
+
console.log(' Got:', storedIP);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
console.log('❌ No DNS A Record found');
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error('❌ Failed:', error);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Test 6: Remove IP
|
|
122
|
+
console.log('\n🗑️ Test 6: removeIP()');
|
|
123
|
+
console.log('-'.repeat(60));
|
|
124
|
+
try {
|
|
125
|
+
const removeResult = await domain.removeIP();
|
|
126
|
+
|
|
127
|
+
if (removeResult.success) {
|
|
128
|
+
console.log('✅ Success:');
|
|
129
|
+
console.log(
|
|
130
|
+
' Transaction Hash:',
|
|
131
|
+
removeResult.transactionHash
|
|
132
|
+
);
|
|
133
|
+
console.log(' Gas Used:', removeResult.gasUsed?.toString());
|
|
134
|
+
|
|
135
|
+
// Wait for the blockchain to index the data
|
|
136
|
+
console.log('⏳ Waiting for blockchain to index data...');
|
|
137
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
138
|
+
} else {
|
|
139
|
+
console.log('❌ Failed:', removeResult.error);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error('❌ Failed:', error);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Test 7: Verify IP was removed
|
|
146
|
+
console.log('\n🔍 Test 7: Verify IP after removal');
|
|
147
|
+
console.log('-'.repeat(60));
|
|
148
|
+
try {
|
|
149
|
+
const removedIP = await domain.getIP();
|
|
150
|
+
if (removedIP) {
|
|
151
|
+
console.log('❌ DNS A Record still exists:', removedIP);
|
|
152
|
+
} else {
|
|
153
|
+
console.log('✅ DNS A Record successfully removed');
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error('❌ Failed:', error);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
didConsole.clearSigner();
|
|
160
|
+
} else {
|
|
161
|
+
console.log(
|
|
162
|
+
'\n⚠️ Skipping blockchain tests (no PRIVATE_KEY_OR_MNEMONIC provided)'
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
console.log('\n' + '='.repeat(60));
|
|
167
|
+
console.log('✅ All tests completed!');
|
|
168
|
+
console.log('='.repeat(60));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
main().catch(console.error);
|
package/examples/legacy.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import DID from '../src/index';
|
|
2
2
|
|
|
3
|
-
// op sepolia
|
|
3
|
+
// op sepolia testnet environment
|
|
4
4
|
const RPC = 'https://sepolia.optimism.io';
|
|
5
|
-
const CONTRACT_DID = '0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8'; // DID
|
|
6
|
-
const CONTRACT_ROOT_RESOLVER = '0xeF727cb066Fee98F88Db84555830063b4A24ddfc'; // RootResolver
|
|
7
|
-
const CONTRACT_ABI_TYPE = '0x7386fCBae6Ad4CCE1499d9153D99bc950B589718'; // ABIType
|
|
5
|
+
const CONTRACT_DID = '0xe2D7c3a9013960E04d4E9F5F9B63fff37eEd97A8'; // DID contract address
|
|
6
|
+
const CONTRACT_ROOT_RESOLVER = '0xeF727cb066Fee98F88Db84555830063b4A24ddfc'; // RootResolver contract address
|
|
7
|
+
const CONTRACT_ABI_TYPE = '0x7386fCBae6Ad4CCE1499d9153D99bc950B589718'; // ABIType contract address
|
|
8
8
|
|
|
9
|
-
// // op
|
|
9
|
+
// // op mainnet environment
|
|
10
10
|
// const RPC = 'https://optimism-rpc.publicnode.com';
|
|
11
|
-
// const CONTRACT_DID = '0x5DA4Fa8E567d86e52Ef8Da860de1be8f54cae97D'; // DID
|
|
12
|
-
// const CONTRACT_ROOT_RESOLVER = '0xE2EABA0979277A90511F8873ae1e8cA26B54E740'; // RootResolver
|
|
13
|
-
// const CONTRACT_ABI_TYPE = '0x9ae3F16bD99294Af1784beB1a0A5C84bf2636365'; // ABIType
|
|
11
|
+
// const CONTRACT_DID = '0x5DA4Fa8E567d86e52Ef8Da860de1be8f54cae97D'; // DID contract address
|
|
12
|
+
// const CONTRACT_ROOT_RESOLVER = '0xE2EABA0979277A90511F8873ae1e8cA26B54E740'; // RootResolver contract address
|
|
13
|
+
// const CONTRACT_ABI_TYPE = '0x9ae3F16bD99294Af1784beB1a0A5C84bf2636365'; // ABIType contract address
|
|
14
14
|
|
|
15
15
|
async function main() {
|
|
16
16
|
const did = DID.createConsole(
|
|
@@ -20,11 +20,11 @@ async function main() {
|
|
|
20
20
|
CONTRACT_ABI_TYPE
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
// Get specific domain data
|
|
24
24
|
const domain = await did.fetchDomain('tw7613781.olares.com');
|
|
25
25
|
console.log('Domain Data:', domain);
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// Get all domain data (the mainnet has a large amount of data, the testnet has a small amount of data, for testing it is recommended to experience this function in the testnet environment)
|
|
28
28
|
await did.fetchAll();
|
|
29
29
|
console.log('All Domains:', did.allDomainCache);
|
|
30
30
|
console.log('Domain Tree Cache:', did.treesCache);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import OlaresID from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example: List All Wallets for a Domain
|
|
5
|
+
*
|
|
6
|
+
* This example shows how to query all authenticated wallet addresses
|
|
7
|
+
* (both EVM and Solana) for an Olares Name.
|
|
8
|
+
*
|
|
9
|
+
* Note: This is a read-only operation, no signer required.
|
|
10
|
+
*
|
|
11
|
+
* Optional environment variables:
|
|
12
|
+
* - DOMAIN_NAME: The Olares Name to query (default: use command line argument)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
// Get domain name from environment or command line
|
|
17
|
+
const domainName = process.env.DOMAIN_NAME || process.argv[2];
|
|
18
|
+
|
|
19
|
+
if (!domainName) {
|
|
20
|
+
console.error('\n❌ Please provide a domain name:');
|
|
21
|
+
console.error(' node examples/list-wallets.js your.olares');
|
|
22
|
+
console.error(' OR');
|
|
23
|
+
console.error(
|
|
24
|
+
' export DOMAIN_NAME="your.olares" && node examples/list-wallets.js\n'
|
|
25
|
+
);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log('\n📋 Listing Wallets for Domain\n');
|
|
30
|
+
console.log(`Domain: ${domainName}\n`);
|
|
31
|
+
|
|
32
|
+
// Initialize OlaresID (no signer needed for read operations)
|
|
33
|
+
// Use createMainnet() for production, createTestnet() for testing
|
|
34
|
+
const olaresId = OlaresID.createTestnet();
|
|
35
|
+
|
|
36
|
+
// Get domain context
|
|
37
|
+
const domain = olaresId.domain(domainName);
|
|
38
|
+
|
|
39
|
+
// Get EVM wallets
|
|
40
|
+
console.log('⏳ Fetching EVM wallets...');
|
|
41
|
+
const evmWallets = await domain.getEVMWallets();
|
|
42
|
+
|
|
43
|
+
console.log(`\n💰 EVM Wallets (${evmWallets.length}):\n`);
|
|
44
|
+
if (evmWallets.length === 0) {
|
|
45
|
+
console.log(' (No EVM wallets found)\n');
|
|
46
|
+
} else {
|
|
47
|
+
evmWallets.forEach((addr, i) => {
|
|
48
|
+
console.log(` ${i + 1}. ${addr}`);
|
|
49
|
+
});
|
|
50
|
+
console.log('');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Get Solana wallets
|
|
54
|
+
console.log('⏳ Fetching Solana wallets...');
|
|
55
|
+
const solanaWallets = await domain.getSolanaWallets();
|
|
56
|
+
|
|
57
|
+
console.log(`\n🌟 Solana Wallets (${solanaWallets.length}):\n`);
|
|
58
|
+
if (solanaWallets.length === 0) {
|
|
59
|
+
console.log(' (No Solana wallets found)\n');
|
|
60
|
+
} else {
|
|
61
|
+
solanaWallets.forEach((addr, i) => {
|
|
62
|
+
console.log(` ${i + 1}. ${addr}`);
|
|
63
|
+
});
|
|
64
|
+
console.log('');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Summary
|
|
68
|
+
const totalWallets = evmWallets.length + solanaWallets.length;
|
|
69
|
+
console.log('📊 Summary:');
|
|
70
|
+
console.log(` Total: ${totalWallets} wallet(s)`);
|
|
71
|
+
console.log(` EVM: ${evmWallets.length}`);
|
|
72
|
+
console.log(` Solana: ${solanaWallets.length}`);
|
|
73
|
+
|
|
74
|
+
console.log('\n✨ Done!\n');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Run the example
|
|
78
|
+
main().catch((error) => {
|
|
79
|
+
console.error('\n❌ Error:', error.message);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
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);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parserOptions: {
|
|
4
|
+
parser: '@typescript-eslint/parser',
|
|
5
|
+
ecmaVersion: 2021
|
|
6
|
+
},
|
|
7
|
+
env: {
|
|
8
|
+
browser: true,
|
|
9
|
+
es2021: true,
|
|
10
|
+
node: true
|
|
11
|
+
},
|
|
12
|
+
extends: [
|
|
13
|
+
'plugin:vue/vue3-essential',
|
|
14
|
+
'eslint:recommended',
|
|
15
|
+
'@vue/typescript/recommended',
|
|
16
|
+
'prettier'
|
|
17
|
+
],
|
|
18
|
+
plugins: ['vue', '@typescript-eslint'],
|
|
19
|
+
rules: {
|
|
20
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
21
|
+
'@typescript-eslint/no-unused-vars': 'warn'
|
|
22
|
+
}
|
|
23
|
+
};
|