@beclab/olaresid 0.1.2 ā 0.1.4
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/README.md +3 -0
- package/dist/business/index.d.ts +1 -1
- package/dist/business/index.d.ts.map +1 -1
- package/dist/business/index.js +5 -2
- package/dist/business/index.js.map +1 -1
- package/dist/business/tag-context.d.ts.map +1 -1
- package/dist/business/tag-context.js +23 -0
- package/dist/business/tag-context.js.map +1 -1
- package/dist/cli.js +18 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/dist/utils/crypto-utils.d.ts +39 -0
- package/dist/utils/crypto-utils.d.ts.map +1 -1
- package/dist/utils/crypto-utils.js +77 -27
- package/dist/utils/crypto-utils.js.map +1 -1
- 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/examples/ed25519-jwk.ts +73 -0
- package/examples/olares-id-format.ts +197 -0
- package/package.json +2 -1
- package/src/business/index.ts +5 -2
- package/src/business/tag-context.ts +35 -1
- package/src/cli.ts +18 -1
- package/src/index.ts +16 -26
- package/src/utils/crypto-utils.ts +90 -33
- package/src/utils/olares-id.ts +49 -0
|
@@ -44,37 +44,14 @@ exports.generateMnemonic = generateMnemonic;
|
|
|
44
44
|
exports.getEthereumAddressFromMnemonic = getEthereumAddressFromMnemonic;
|
|
45
45
|
exports.getEVMPrivateKeyFromMnemonic = getEVMPrivateKeyFromMnemonic;
|
|
46
46
|
exports.getDIDFromMnemonic = getDIDFromMnemonic;
|
|
47
|
+
exports.getEd25519JwkFromMnemonic = getEd25519JwkFromMnemonic;
|
|
47
48
|
exports.deriveDIDFromMnemonic = deriveDIDFromMnemonic;
|
|
48
49
|
exports.generateDIDKeyData = generateDIDKeyData;
|
|
49
50
|
exports.createRsaKeyPair = createRsaKeyPair;
|
|
50
51
|
const bip39 = __importStar(require("bip39"));
|
|
51
52
|
const varint = __importStar(require("varint"));
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
/**
|
|
55
|
-
* Encode bytes to base58btc format
|
|
56
|
-
* This is a pure implementation compatible with multiformats/bases/base58
|
|
57
|
-
*/
|
|
58
|
-
function base58Encode(bytes) {
|
|
59
|
-
// Convert bytes to bigint
|
|
60
|
-
let num = 0n;
|
|
61
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
62
|
-
num = num * 256n + BigInt(bytes[i]);
|
|
63
|
-
}
|
|
64
|
-
// Convert to base58
|
|
65
|
-
let encoded = '';
|
|
66
|
-
while (num > 0n) {
|
|
67
|
-
const remainder = Number(num % 58n);
|
|
68
|
-
encoded = BASE58_ALPHABET[remainder] + encoded;
|
|
69
|
-
num = num / 58n;
|
|
70
|
-
}
|
|
71
|
-
// Add leading '1's for leading zero bytes
|
|
72
|
-
for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
|
|
73
|
-
encoded = '1' + encoded;
|
|
74
|
-
}
|
|
75
|
-
// Add 'z' prefix for base58btc multibase
|
|
76
|
-
return 'z' + encoded;
|
|
77
|
-
}
|
|
53
|
+
const base58_1 = require("multiformats/bases/base58");
|
|
54
|
+
const base64_1 = require("multiformats/bases/base64");
|
|
78
55
|
// ============================================================================
|
|
79
56
|
// Trust Wallet Core Management
|
|
80
57
|
// ============================================================================
|
|
@@ -221,7 +198,7 @@ async function getID(mnemonic) {
|
|
|
221
198
|
idBytes.set(ED25519_CODEC_ID, 0);
|
|
222
199
|
idBytes.set(publicKey.data(), ED25519_CODEC_ID.length);
|
|
223
200
|
// Encode to base58btc
|
|
224
|
-
const id =
|
|
201
|
+
const id = base58_1.base58btc.encode(idBytes);
|
|
225
202
|
return id;
|
|
226
203
|
}
|
|
227
204
|
/**
|
|
@@ -247,6 +224,79 @@ async function getDIDFromMnemonic(mnemonic) {
|
|
|
247
224
|
const id = await getID(mnemonic);
|
|
248
225
|
return `did:key:${id}`;
|
|
249
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Generate Ed25519 JWK (JSON Web Key) from BIP39 mnemonic phrase
|
|
229
|
+
* Uses Trust Wallet Core for key derivation, ensuring compatibility with TermiPass
|
|
230
|
+
*
|
|
231
|
+
* @param mnemonic BIP39 mnemonic phrase (12, 15, 18, 21, or 24 words)
|
|
232
|
+
* @returns Object containing publicJwk and privateJwk in RFC 7517 format
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const { publicJwk, privateJwk } = await getEd25519JwkFromMnemonic(mnemonic);
|
|
237
|
+
*
|
|
238
|
+
* // Public JWK (safe to share)
|
|
239
|
+
* console.log(publicJwk);
|
|
240
|
+
* // {
|
|
241
|
+
* // "kty": "OKP",
|
|
242
|
+
* // "crv": "Ed25519",
|
|
243
|
+
* // "alg": "EdDSA",
|
|
244
|
+
* // "use": "sig",
|
|
245
|
+
* // "kid": "did:key:z6Mk...#z6Mk...",
|
|
246
|
+
* // "x": "base64url-encoded-public-key"
|
|
247
|
+
* // }
|
|
248
|
+
*
|
|
249
|
+
* // Private JWK (keep secure!)
|
|
250
|
+
* console.log(privateJwk);
|
|
251
|
+
* // {
|
|
252
|
+
* // "kty": "OKP",
|
|
253
|
+
* // "crv": "Ed25519",
|
|
254
|
+
* // "alg": "EdDSA",
|
|
255
|
+
* // "use": "sig",
|
|
256
|
+
* // "kid": "did:key:z6Mk...#z6Mk...",
|
|
257
|
+
* // "x": "base64url-encoded-public-key",
|
|
258
|
+
* // "d": "base64url-encoded-private-key"
|
|
259
|
+
* // }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
async function getEd25519JwkFromMnemonic(mnemonic) {
|
|
263
|
+
// Validate mnemonic
|
|
264
|
+
if (!bip39.validateMnemonic(mnemonic)) {
|
|
265
|
+
throw new Error('Invalid mnemonic phrase');
|
|
266
|
+
}
|
|
267
|
+
const core = await loadWalletCore();
|
|
268
|
+
const { HDWallet, Curve } = core;
|
|
269
|
+
const wallet = HDWallet.createWithMnemonic(mnemonic, '');
|
|
270
|
+
const privateKey = wallet.getMasterKey(Curve.ed25519);
|
|
271
|
+
const publicKey = privateKey.getPublicKeyEd25519();
|
|
272
|
+
// Get key data
|
|
273
|
+
const publicKeyBytes = publicKey.data();
|
|
274
|
+
const privateKeyBytes = privateKey.data();
|
|
275
|
+
const idBytes = new Uint8Array(publicKeyBytes.length + ED25519_CODEC_ID.length);
|
|
276
|
+
idBytes.set(ED25519_CODEC_ID, 0);
|
|
277
|
+
idBytes.set(publicKeyBytes, ED25519_CODEC_ID.length);
|
|
278
|
+
const id = base58_1.base58btc.encode(idBytes);
|
|
279
|
+
const did = `did:key:${id}`;
|
|
280
|
+
const keyId = `${did}#${id}`;
|
|
281
|
+
// Base64url encode the keys
|
|
282
|
+
const x = base64_1.base64url.baseEncode(publicKeyBytes);
|
|
283
|
+
const d = base64_1.base64url.baseEncode(privateKeyBytes);
|
|
284
|
+
// Public JWK (contains only public key material)
|
|
285
|
+
const publicJwk = {
|
|
286
|
+
kty: 'OKP', // Key Type: Octet Key Pair
|
|
287
|
+
crv: 'Ed25519', // Curve: Ed25519
|
|
288
|
+
alg: 'EdDSA', // Algorithm: EdDSA
|
|
289
|
+
use: 'sig', // Use: signature
|
|
290
|
+
kid: keyId, // Key ID
|
|
291
|
+
x: x // Public key parameter
|
|
292
|
+
};
|
|
293
|
+
// Private JWK (contains both public and private key material)
|
|
294
|
+
const privateJwk = {
|
|
295
|
+
...publicJwk,
|
|
296
|
+
d: d // Private key parameter
|
|
297
|
+
};
|
|
298
|
+
return { publicJwk, privateJwk };
|
|
299
|
+
}
|
|
250
300
|
/**
|
|
251
301
|
* Derive both owner (Ethereum address) and DID from existing mnemonic
|
|
252
302
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-utils.js","sourceRoot":"","sources":["../../src/utils/crypto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,QAAQ,CAAC,CAAC;IAEjC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE;QACnE,aAAa,EAAE,MAAM;QACrB,iBAAiB,EAAE;YAClB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,KAAK;SACb;QACD,kBAAkB,EAAE;YACnB,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,KAAK;SACb;KACD,CAAC,CAAC;IAEH,OAAO;QACN,YAAY,EAAE,SAAS;QACvB,aAAa,EAAE,UAAU;KACzB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,gBAAgB,CAC/B,SAAiB,IAAI;IAErB,sBAAsB;IACtB,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,MAAM,EAAE,EAAE,CAAC;QACd,4EAA4E;QAC5E,OAAO,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACP,yDAAyD;QACzD,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Olares ID Utilities
|
|
3
|
+
*
|
|
4
|
+
* Olares ID is a new format that looks like email addresses: user@domain.com
|
|
5
|
+
* It's essentially a domain name where the first dot (.) is replaced with an at sign (@)
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* - alice.example.com ā alice@example.com (Olares ID)
|
|
9
|
+
* - bob.sub.example.com ā bob@sub.example.com (Olares ID)
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Convert Olares ID format to standard domain format
|
|
13
|
+
* Replaces the first @ with a dot (.)
|
|
14
|
+
*
|
|
15
|
+
* @param input The input string (can be either Olares ID or domain format)
|
|
16
|
+
* @returns The normalized domain format
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* normalizeToDomain('alice@example.com') // returns 'alice.example.com'
|
|
20
|
+
* normalizeToDomain('alice.example.com') // returns 'alice.example.com' (no change)
|
|
21
|
+
* normalizeToDomain('bob@sub.example.com') // returns 'bob.sub.example.com'
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeToDomain(input: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Convert standard domain format to Olares ID format
|
|
26
|
+
* Replaces the first dot (.) with an at sign (@)
|
|
27
|
+
*
|
|
28
|
+
* @param domain The domain name
|
|
29
|
+
* @returns The Olares ID format
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* normalizeToOlaresId('alice.example.com') // returns 'alice@example.com'
|
|
33
|
+
* normalizeToOlaresId('bob.sub.example.com') // returns 'bob@sub.example.com'
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeToOlaresId(domain: string): string;
|
|
36
|
+
//# sourceMappingURL=olares-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"olares-id.d.ts","sourceRoot":"","sources":["../../src/utils/olares-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM1D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Olares ID Utilities
|
|
4
|
+
*
|
|
5
|
+
* Olares ID is a new format that looks like email addresses: user@domain.com
|
|
6
|
+
* It's essentially a domain name where the first dot (.) is replaced with an at sign (@)
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* - alice.example.com ā alice@example.com (Olares ID)
|
|
10
|
+
* - bob.sub.example.com ā bob@sub.example.com (Olares ID)
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.normalizeToDomain = normalizeToDomain;
|
|
14
|
+
exports.normalizeToOlaresId = normalizeToOlaresId;
|
|
15
|
+
/**
|
|
16
|
+
* Convert Olares ID format to standard domain format
|
|
17
|
+
* Replaces the first @ with a dot (.)
|
|
18
|
+
*
|
|
19
|
+
* @param input The input string (can be either Olares ID or domain format)
|
|
20
|
+
* @returns The normalized domain format
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* normalizeToDomain('alice@example.com') // returns 'alice.example.com'
|
|
24
|
+
* normalizeToDomain('alice.example.com') // returns 'alice.example.com' (no change)
|
|
25
|
+
* normalizeToDomain('bob@sub.example.com') // returns 'bob.sub.example.com'
|
|
26
|
+
*/
|
|
27
|
+
function normalizeToDomain(input) {
|
|
28
|
+
if (!input) {
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
// Replace the first @ with a dot
|
|
32
|
+
return input.replace('@', '.');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Convert standard domain format to Olares ID format
|
|
36
|
+
* Replaces the first dot (.) with an at sign (@)
|
|
37
|
+
*
|
|
38
|
+
* @param domain The domain name
|
|
39
|
+
* @returns The Olares ID format
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* normalizeToOlaresId('alice.example.com') // returns 'alice@example.com'
|
|
43
|
+
* normalizeToOlaresId('bob.sub.example.com') // returns 'bob@sub.example.com'
|
|
44
|
+
*/
|
|
45
|
+
function normalizeToOlaresId(domain) {
|
|
46
|
+
if (!domain) {
|
|
47
|
+
return domain;
|
|
48
|
+
}
|
|
49
|
+
// Replace the first dot with @
|
|
50
|
+
return domain.replace('.', '@');
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=olares-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"olares-id.js","sourceRoot":"","sources":["../../src/utils/olares-id.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAcH,8CAMC;AAaD,kDAMC;AArCD;;;;;;;;;;;GAWG;AACH,SAAgB,iBAAiB,CAAC,KAAa;IAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC;IACd,CAAC;IACD,iCAAiC;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAC,MAAc;IACjD,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,MAAM,CAAC;IACf,CAAC;IACD,+BAA+B;IAC/B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Generate Ed25519 JWK using mnemonic and key pair derivation
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to:
|
|
5
|
+
* 1. Generate a BIP39 mnemonic phrase
|
|
6
|
+
* 2. Derive Ed25519 key pair from the mnemonic
|
|
7
|
+
* 3. Convert the key pair to JSON Web Key (JWK) format
|
|
8
|
+
*
|
|
9
|
+
* The JWK format is commonly used for cryptographic keys in web applications
|
|
10
|
+
* and follows the RFC 7517 specification.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { generateMnemonic, getEd25519JwkFromMnemonic } from '../src/index';
|
|
14
|
+
|
|
15
|
+
async function example_generateEd25519JWK() {
|
|
16
|
+
console.log('='.repeat(70));
|
|
17
|
+
console.log('Example: Generate Ed25519 JWK from Mnemonic');
|
|
18
|
+
console.log('='.repeat(70));
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
// Step 1: Generate a new mnemonic phrase
|
|
22
|
+
console.log('\nš Step 1: Generating BIP39 mnemonic...');
|
|
23
|
+
const mnemonic = generateMnemonic(12);
|
|
24
|
+
console.log(`Mnemonic: ${mnemonic}`);
|
|
25
|
+
|
|
26
|
+
// Step 2: Derive Ed25519 key pair and DID from mnemonic
|
|
27
|
+
console.log('\nš Step 2: Deriving Ed25519 key pair from mnemonic...');
|
|
28
|
+
const { publicJwk, privateJwk } = await getEd25519JwkFromMnemonic(
|
|
29
|
+
mnemonic
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
console.log(`Public JWK: ${JSON.stringify(publicJwk, null, 2)}`);
|
|
33
|
+
console.log(`Private JWK: ${JSON.stringify(privateJwk, null, 2)}`);
|
|
34
|
+
} catch (error: any) {
|
|
35
|
+
console.error('\nā Error:', error.message);
|
|
36
|
+
if (error.stack) {
|
|
37
|
+
console.error('\nStack trace:');
|
|
38
|
+
console.error(error.stack);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function main() {
|
|
44
|
+
console.log('š Ed25519 JWK Generation Example\n');
|
|
45
|
+
console.log(
|
|
46
|
+
'This example shows how to generate Ed25519 keys in JWK format'
|
|
47
|
+
);
|
|
48
|
+
console.log("using olaresid's cryptographic utilities.\n");
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await example_generateEd25519JWK();
|
|
52
|
+
|
|
53
|
+
console.log('\n\n' + '='.repeat(70));
|
|
54
|
+
console.log('ā
All examples completed successfully!');
|
|
55
|
+
console.log('='.repeat(70));
|
|
56
|
+
console.log('\nā ļø SECURITY WARNING:');
|
|
57
|
+
console.log(' - Never share your mnemonic phrase or private JWK!');
|
|
58
|
+
console.log(
|
|
59
|
+
' - Store private keys securely (encrypted, hardware security modules)'
|
|
60
|
+
);
|
|
61
|
+
console.log(' - Use public JWKs for verification purposes only\n');
|
|
62
|
+
} catch (error: any) {
|
|
63
|
+
console.error('\nā Error:', error.message || error);
|
|
64
|
+
if (error.stack) {
|
|
65
|
+
console.error('\nStack trace:');
|
|
66
|
+
console.error(error.stack);
|
|
67
|
+
}
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Run the examples
|
|
73
|
+
main();
|
|
@@ -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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beclab/olaresid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "DID Contract SDK with CLI tool",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"bip39": "^3.1.0",
|
|
43
43
|
"bs58": "^5.0.0",
|
|
44
44
|
"ethers": "^6.9.1",
|
|
45
|
+
"multiformats": "9.6.4",
|
|
45
46
|
"tweetnacl": "^1.0.3",
|
|
46
47
|
"tweetnacl-util": "^0.15.1",
|
|
47
48
|
"varint": "^6.0.0"
|
package/src/business/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ethers } from 'ethers';
|
|
|
3
3
|
import { parseContractError } from '../utils/error-parser';
|
|
4
4
|
import { TagContext } from './tag-context';
|
|
5
5
|
import { TagTypeBuilder } from '../utils/tag-type-builder';
|
|
6
|
+
import { normalizeToDomain } from '../utils/olares-id';
|
|
6
7
|
|
|
7
8
|
export interface TransactionResult<T = any> {
|
|
8
9
|
// Basic transaction information
|
|
@@ -46,7 +47,8 @@ export {
|
|
|
46
47
|
getEVMPrivateKeyFromMnemonic,
|
|
47
48
|
getDIDFromMnemonic,
|
|
48
49
|
generateDIDKeyData,
|
|
49
|
-
deriveDIDFromMnemonic
|
|
50
|
+
deriveDIDFromMnemonic,
|
|
51
|
+
getEd25519JwkFromMnemonic
|
|
50
52
|
} from '../utils/crypto-utils';
|
|
51
53
|
export type { RSAPublicKeyData, DIDKeyData } from '../utils/crypto-utils';
|
|
52
54
|
|
|
@@ -71,7 +73,8 @@ export class DomainContext {
|
|
|
71
73
|
private tokenId?: string;
|
|
72
74
|
|
|
73
75
|
constructor(domainName: string, console: DIDConsole) {
|
|
74
|
-
|
|
76
|
+
// Support Olares ID format (user@domain.com) by converting to standard domain format
|
|
77
|
+
this.domainName = normalizeToDomain(domainName);
|
|
75
78
|
this.console = console;
|
|
76
79
|
}
|
|
77
80
|
|