@beclab/olaresid 0.1.13 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLI-TREE.md +107 -0
- package/CLI.md +122 -1340
- 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.map +1 -1
- package/dist/business/index.js +9 -23
- 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 +177 -76
- 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 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +158 -143
- package/dist/index.js.map +1 -1
- package/dist/utils/crypto-utils.d.ts +110 -0
- package/dist/utils/crypto-utils.d.ts.map +1 -1
- package/dist/utils/crypto-utils.js +127 -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 +9 -33
- package/src/business/tag-context.ts +35 -7
- package/src/cli.ts +253 -90
- 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 +230 -207
- package/src/utils/crypto-utils.ts +205 -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/tests/unit/version.test.ts +14 -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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tag data structure
|
|
3
|
+
*/
|
|
4
|
+
export interface Tag {
|
|
5
|
+
from: string;
|
|
6
|
+
name: string;
|
|
7
|
+
abiType: string; // ABI type string (e.g., "tuple(string,uint8)")
|
|
8
|
+
value: string; // bytes (hex string) - raw encoded value
|
|
9
|
+
fieldNamesHash: string[]; // bytes32[] (hex strings)
|
|
10
|
+
valueFormatted?: string | null; // Decoded value; objects/arrays are JSON.stringify'd; null if tag has no value
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Flattened domain data structure
|
|
15
|
+
*/
|
|
16
|
+
export interface FlatDomainData {
|
|
17
|
+
id: string; // tokenId (hex)
|
|
18
|
+
name: string;
|
|
19
|
+
did: string;
|
|
20
|
+
note: string;
|
|
21
|
+
allowSubdomain: boolean;
|
|
22
|
+
owner: string;
|
|
23
|
+
parentId?: string; // ⭐ New: parent domain ID
|
|
24
|
+
level: number; // ⭐ New: level (1=top-level, 2=second-level...)
|
|
25
|
+
tags: Tag[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Raw domain data returned by contract
|
|
30
|
+
*/
|
|
31
|
+
export interface RawDomainData {
|
|
32
|
+
tokenId: bigint;
|
|
33
|
+
domain: string;
|
|
34
|
+
did: string;
|
|
35
|
+
notes: string;
|
|
36
|
+
allowSubdomain: boolean;
|
|
37
|
+
owner: string;
|
|
38
|
+
tags: RawTagData[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Raw Tag data returned by contract
|
|
43
|
+
*/
|
|
44
|
+
export interface RawTagData {
|
|
45
|
+
from: string;
|
|
46
|
+
name: string;
|
|
47
|
+
abiType: string; // bytes (hex string)
|
|
48
|
+
value: string; // bytes (hex string)
|
|
49
|
+
fieldNamesHash: string[]; // bytes32[] (hex strings)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* fetchAll options
|
|
54
|
+
*/
|
|
55
|
+
export interface FetchAllOptions {
|
|
56
|
+
queryContractAddress?: string;
|
|
57
|
+
batchSize?: number; // Number of domains to fetch per batch, default 100
|
|
58
|
+
onProgress?: (current: number, total: number) => void;
|
|
59
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
4
|
import DID_ABI from './abi/TerminusDIDABI';
|
|
5
5
|
import RootResolverABI from './abi/RootResolverABI';
|
|
6
6
|
import RootResolver2ABI from './abi/RootResolver2ABI';
|
|
7
|
-
import { debug } from './debug';
|
|
8
7
|
import { parseContractError } from './utils/error-parser';
|
|
9
|
-
import { normalizeToDomain } from './utils/olares-id';
|
|
10
8
|
|
|
11
9
|
import { DomainContext, TransactionResult } from './business';
|
|
12
10
|
|
|
13
|
-
// Import Tag utilities
|
|
14
|
-
import { TagTypeBuilder } from './utils/tag-type-builder';
|
|
15
|
-
import { TagAbiCodec } from './utils/tag-abi-codec';
|
|
16
|
-
|
|
17
11
|
// Import config utilities
|
|
18
|
-
import { getNetworkConfig
|
|
12
|
+
import { getNetworkConfig } from './config';
|
|
13
|
+
|
|
14
|
+
// Import domain functions
|
|
15
|
+
import {
|
|
16
|
+
fetchDomain,
|
|
17
|
+
fetchDomains,
|
|
18
|
+
fetchDomainsByIndices,
|
|
19
|
+
fetchAllFlat
|
|
20
|
+
} from './domain/index';
|
|
19
21
|
|
|
20
22
|
export type {
|
|
21
23
|
DomainInfo,
|
|
@@ -45,23 +47,17 @@ export {
|
|
|
45
47
|
getEd25519JwkFromMnemonic
|
|
46
48
|
} from './business';
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
type StoreDomain = PackageDomain.DomainData;
|
|
51
|
-
|
|
52
|
-
export class DIDConsole implements DIDTag.ABITypeProviderHolder {
|
|
50
|
+
export class DIDConsole {
|
|
53
51
|
rpcNode: string;
|
|
54
52
|
contractDid: string;
|
|
55
53
|
contractRootResolver: string;
|
|
56
54
|
contractAbiType: string;
|
|
57
55
|
contractRootResolver2?: string;
|
|
58
56
|
supportSvcUrl?: string;
|
|
57
|
+
queryContractAddress?: string; // New: query contract address
|
|
59
58
|
|
|
60
59
|
signer?: ethers.Signer;
|
|
61
60
|
|
|
62
|
-
allDomainCache: Domain[] = [];
|
|
63
|
-
treesCache: Domain[] = [];
|
|
64
|
-
|
|
65
61
|
// caching contract instances
|
|
66
62
|
private _contractDID?: ethers.Contract;
|
|
67
63
|
private _signerContractDID?: ethers.Contract;
|
|
@@ -78,7 +74,8 @@ export class DIDConsole implements DIDTag.ABITypeProviderHolder {
|
|
|
78
74
|
contractRootResolver: string,
|
|
79
75
|
contractAbiType: string,
|
|
80
76
|
contractRootResolver2?: string,
|
|
81
|
-
supportSvcUrl?: string
|
|
77
|
+
supportSvcUrl?: string,
|
|
78
|
+
queryContractAddress?: string
|
|
82
79
|
) {
|
|
83
80
|
this.rpcNode = rpcNode;
|
|
84
81
|
this.contractDid = contractDid;
|
|
@@ -86,6 +83,7 @@ export class DIDConsole implements DIDTag.ABITypeProviderHolder {
|
|
|
86
83
|
this.contractAbiType = contractAbiType;
|
|
87
84
|
this.contractRootResolver2 = contractRootResolver2;
|
|
88
85
|
this.supportSvcUrl = supportSvcUrl;
|
|
86
|
+
this.queryContractAddress = queryContractAddress;
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
getProvider = (): ethers.JsonRpcProvider => {
|
|
@@ -247,193 +245,98 @@ export class DIDConsole implements DIDTag.ABITypeProviderHolder {
|
|
|
247
245
|
await provider.getSigner()
|
|
248
246
|
);
|
|
249
247
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
)}%`
|
|
265
|
-
);
|
|
266
|
-
arr.push(domain);
|
|
267
|
-
}
|
|
268
|
-
this.allDomainCache = arr;
|
|
269
|
-
this.treesCache = PackageDomain.buildTree(this.allDomainCache);
|
|
270
|
-
|
|
271
|
-
debug.groupEnd();
|
|
272
|
-
resolve(this.treesCache);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
fetchDomain = (name: string) =>
|
|
276
|
-
new Promise<Domain | undefined>(async (resolve, reject) => {
|
|
277
|
-
// Support Olares ID format (user@domain.com)
|
|
278
|
-
const normalizedName = normalizeToDomain(name);
|
|
279
|
-
|
|
280
|
-
debug.group('fetchDomain');
|
|
281
|
-
const hasCache = this.allDomainCache.length > 0;
|
|
282
|
-
debug.info('fetchDomain--->hasCache', hasCache);
|
|
283
|
-
|
|
284
|
-
if (hasCache) {
|
|
285
|
-
const domain = PackageDomain.findASubtree(
|
|
286
|
-
normalizedName,
|
|
287
|
-
this.allDomainCache
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
debug.groupEnd();
|
|
291
|
-
resolve(domain);
|
|
292
|
-
} else {
|
|
293
|
-
const domain = await PackageDomain.syncByName(
|
|
294
|
-
normalizedName,
|
|
295
|
-
await this.getContractDID()
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
debug.groupEnd();
|
|
299
|
-
resolve(domain);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
updateDomain = (name: string) =>
|
|
304
|
-
new Promise<Domain>(async (resolve, reject) => {
|
|
305
|
-
// Support Olares ID format (user@domain.com)
|
|
306
|
-
const normalizedName = normalizeToDomain(name);
|
|
307
|
-
|
|
308
|
-
const domain = await PackageDomain.syncByName(
|
|
309
|
-
normalizedName,
|
|
310
|
-
await this.getContractDID()
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
if (domain == undefined) {
|
|
314
|
-
reject('not found domain');
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const [oldDomain] = this.allDomainCache.filter(
|
|
319
|
-
(d) => d.name == domain.name
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
if (oldDomain != undefined) {
|
|
323
|
-
for (const tagNew of domain.tags) {
|
|
324
|
-
for (const tagOld of oldDomain.tags) {
|
|
325
|
-
if (tagNew.name == tagOld.name) {
|
|
326
|
-
if (
|
|
327
|
-
tagNew.valueFormated == undefined &&
|
|
328
|
-
tagOld.valueFormated != undefined
|
|
329
|
-
) {
|
|
330
|
-
tagNew.valueFormated = tagOld.valueFormated;
|
|
331
|
-
}
|
|
332
|
-
if (
|
|
333
|
-
tagNew.valueSource == undefined &&
|
|
334
|
-
tagOld.valueSource != undefined
|
|
335
|
-
) {
|
|
336
|
-
tagNew.valueSource = tagOld.valueSource;
|
|
337
|
-
}
|
|
338
|
-
if (
|
|
339
|
-
tagNew.definition == undefined &&
|
|
340
|
-
tagOld.definition != undefined
|
|
341
|
-
) {
|
|
342
|
-
tagNew.definition = tagOld.definition;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
this.allDomainCache = this.allDomainCache.filter(
|
|
350
|
-
(d) => d.name != domain.name
|
|
248
|
+
/**
|
|
249
|
+
* Fetch a single domain by name or tokenId
|
|
250
|
+
* Uses the query contract configured for this network
|
|
251
|
+
*
|
|
252
|
+
* @param nameOrTokenId - Domain name or tokenId
|
|
253
|
+
* @returns Domain data or null if not found
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* const domain = await console.fetchDomain("alice.olares.com");
|
|
257
|
+
*/
|
|
258
|
+
async fetchDomain(nameOrTokenId: string | bigint) {
|
|
259
|
+
if (!this.queryContractAddress) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
'Query contract address not configured for this network'
|
|
351
262
|
);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
resolve(domain);
|
|
263
|
+
}
|
|
264
|
+
return fetchDomain(this, nameOrTokenId, {
|
|
265
|
+
queryContractAddress: this.queryContractAddress
|
|
357
266
|
});
|
|
267
|
+
}
|
|
358
268
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
);
|
|
374
|
-
for (const tagNew of domain.tags) {
|
|
375
|
-
for (const tagOld of oldDomain.tags) {
|
|
376
|
-
if (tagNew.name == tagOld.name) {
|
|
377
|
-
if (
|
|
378
|
-
tagNew.valueFormated == undefined &&
|
|
379
|
-
tagOld.valueFormated != undefined
|
|
380
|
-
) {
|
|
381
|
-
tagNew.valueFormated = tagOld.valueFormated;
|
|
382
|
-
}
|
|
383
|
-
if (
|
|
384
|
-
tagNew.valueSource == undefined &&
|
|
385
|
-
tagOld.valueSource != undefined
|
|
386
|
-
) {
|
|
387
|
-
tagNew.valueSource = tagOld.valueSource;
|
|
388
|
-
}
|
|
389
|
-
if (
|
|
390
|
-
tagNew.definition == undefined &&
|
|
391
|
-
tagOld.definition != undefined
|
|
392
|
-
) {
|
|
393
|
-
tagNew.definition = tagOld.definition;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
this.allDomainCache = this.allDomainCache.filter(
|
|
400
|
-
(d) => d.name != domain.name
|
|
269
|
+
/**
|
|
270
|
+
* Fetch multiple domains with pagination
|
|
271
|
+
*
|
|
272
|
+
* @param offset - Starting index
|
|
273
|
+
* @param limit - Number of domains to fetch
|
|
274
|
+
* @returns Array of domains in the specified range
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* const domains = await console.fetchDomains(0, 10);
|
|
278
|
+
*/
|
|
279
|
+
async fetchDomains(offset: number, limit: number) {
|
|
280
|
+
if (!this.queryContractAddress) {
|
|
281
|
+
throw new Error(
|
|
282
|
+
'Query contract address not configured for this network'
|
|
401
283
|
);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
formatData = (doamin: Domain) =>
|
|
410
|
-
new Promise<StoreDomain>((resolve, reject) => {
|
|
411
|
-
resolve(doamin);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
formatDatas = (doamins: Domain[]) =>
|
|
415
|
-
new Promise<StoreDomain[]>((resolve, reject) => {
|
|
416
|
-
resolve(doamins);
|
|
284
|
+
}
|
|
285
|
+
return fetchDomains(this, {
|
|
286
|
+
offset,
|
|
287
|
+
limit,
|
|
288
|
+
queryContractAddress: this.queryContractAddress
|
|
417
289
|
});
|
|
290
|
+
}
|
|
418
291
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
292
|
+
/**
|
|
293
|
+
* Fetch all domains with flat structure
|
|
294
|
+
*
|
|
295
|
+
* @param options - Additional options (batchSize, onProgress)
|
|
296
|
+
* @returns Array of all domains
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* const domains = await console.fetchAllFlat({
|
|
300
|
+
* batchSize: 100,
|
|
301
|
+
* onProgress: (current, total) => console.log(`${current}/${total}`)
|
|
302
|
+
* });
|
|
303
|
+
*/
|
|
304
|
+
async fetchAllFlat(
|
|
305
|
+
options: {
|
|
306
|
+
batchSize?: number;
|
|
307
|
+
onProgress?: (current: number, total: number) => void;
|
|
308
|
+
} = {}
|
|
309
|
+
) {
|
|
310
|
+
if (!this.queryContractAddress) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
'Query contract address not configured for this network'
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return fetchAllFlat(this, {
|
|
316
|
+
queryContractAddress: this.queryContractAddress,
|
|
317
|
+
...options
|
|
422
318
|
});
|
|
319
|
+
}
|
|
423
320
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Fetch multiple domains by their indices
|
|
323
|
+
*
|
|
324
|
+
* @param indices - Array of domain indices (e.g., [5, 6, 9, 10])
|
|
325
|
+
* @returns Array of domains corresponding to the specified indices
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const domains = await console.fetchDomainsByIndices([5, 6, 9, 10]);
|
|
329
|
+
*/
|
|
330
|
+
async fetchDomainsByIndices(indices: number[]) {
|
|
331
|
+
if (!this.queryContractAddress) {
|
|
332
|
+
throw new Error(
|
|
333
|
+
'Query contract address not configured for this network'
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
return fetchDomainsByIndices(this, indices, {
|
|
337
|
+
queryContractAddress: this.queryContractAddress
|
|
436
338
|
});
|
|
339
|
+
}
|
|
437
340
|
|
|
438
341
|
/**
|
|
439
342
|
* Uses a chain-style operation design pattern, returning the operation context for the specified domain
|
|
@@ -590,13 +493,21 @@ export class DIDConsole implements DIDTag.ABITypeProviderHolder {
|
|
|
590
493
|
}
|
|
591
494
|
|
|
592
495
|
namespace OlaresID {
|
|
496
|
+
export const version = (): string => {
|
|
497
|
+
const packageJson = JSON.parse(
|
|
498
|
+
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')
|
|
499
|
+
);
|
|
500
|
+
return packageJson.version;
|
|
501
|
+
};
|
|
502
|
+
|
|
593
503
|
export const createConsole = (
|
|
594
504
|
rpcNode: string,
|
|
595
505
|
contractDid: string,
|
|
596
506
|
contractRootResolver: string,
|
|
597
507
|
contractAbiType: string,
|
|
598
508
|
contractRootResolver2?: string,
|
|
599
|
-
supportSvcUrl?: string
|
|
509
|
+
supportSvcUrl?: string,
|
|
510
|
+
queryContractAddress?: string
|
|
600
511
|
): DIDConsole => {
|
|
601
512
|
return new DIDConsole(
|
|
602
513
|
rpcNode,
|
|
@@ -604,14 +515,15 @@ namespace OlaresID {
|
|
|
604
515
|
contractRootResolver,
|
|
605
516
|
contractAbiType,
|
|
606
517
|
contractRootResolver2,
|
|
607
|
-
supportSvcUrl
|
|
518
|
+
supportSvcUrl,
|
|
519
|
+
queryContractAddress
|
|
608
520
|
);
|
|
609
521
|
};
|
|
610
522
|
|
|
611
523
|
export const createMainnet = (): DIDConsole => {
|
|
612
524
|
const config = getNetworkConfig('mainnet');
|
|
613
525
|
if (!config) {
|
|
614
|
-
throw new Error('Mainnet configuration not found
|
|
526
|
+
throw new Error('Mainnet configuration not found');
|
|
615
527
|
}
|
|
616
528
|
|
|
617
529
|
return createConsole(
|
|
@@ -620,14 +532,15 @@ namespace OlaresID {
|
|
|
620
532
|
config.contractRootResolver,
|
|
621
533
|
config.contractAbiType,
|
|
622
534
|
config.contractRootResolver2,
|
|
623
|
-
config.supportSvcUrl
|
|
535
|
+
config.supportSvcUrl,
|
|
536
|
+
config.queryContract
|
|
624
537
|
);
|
|
625
538
|
};
|
|
626
539
|
|
|
627
540
|
export const createTestnet = (): DIDConsole => {
|
|
628
541
|
const config = getNetworkConfig('sepolia');
|
|
629
542
|
if (!config) {
|
|
630
|
-
throw new Error('Sepolia configuration not found
|
|
543
|
+
throw new Error('Sepolia configuration not found');
|
|
631
544
|
}
|
|
632
545
|
|
|
633
546
|
return createConsole(
|
|
@@ -636,15 +549,46 @@ namespace OlaresID {
|
|
|
636
549
|
config.contractRootResolver,
|
|
637
550
|
config.contractAbiType,
|
|
638
551
|
config.contractRootResolver2,
|
|
639
|
-
config.supportSvcUrl
|
|
552
|
+
config.supportSvcUrl,
|
|
553
|
+
config.queryContract
|
|
640
554
|
);
|
|
641
555
|
};
|
|
642
556
|
|
|
643
|
-
|
|
557
|
+
/**
|
|
558
|
+
* Create a DIDConsole instance with custom RPC endpoint
|
|
559
|
+
* Contract addresses are loaded from configuration based on network type
|
|
560
|
+
*
|
|
561
|
+
* @param rpc - Custom RPC endpoint URL
|
|
562
|
+
* @param network - Network type: 'mainnet' or 'sepolia' (default: 'mainnet')
|
|
563
|
+
* @returns DIDConsole instance
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* // Create mainnet instance with custom RPC
|
|
567
|
+
* const console = OlaresID.createWithRpc('https://my-optimism-rpc.com');
|
|
568
|
+
*
|
|
569
|
+
* // Create sepolia instance with custom RPC
|
|
570
|
+
* const console = OlaresID.createWithRpc('https://my-sepolia-rpc.com', 'sepolia');
|
|
571
|
+
*/
|
|
572
|
+
export const createWithRpc = (
|
|
573
|
+
rpc: string,
|
|
574
|
+
network: 'mainnet' | 'sepolia' = 'mainnet'
|
|
575
|
+
): DIDConsole => {
|
|
576
|
+
const config = getNetworkConfig(network);
|
|
644
577
|
|
|
645
|
-
|
|
578
|
+
if (!config) {
|
|
579
|
+
throw new Error(`${network} configuration not found`);
|
|
580
|
+
}
|
|
646
581
|
|
|
647
|
-
|
|
582
|
+
return createConsole(
|
|
583
|
+
rpc, // Use custom RPC
|
|
584
|
+
config.contractDid,
|
|
585
|
+
config.contractRootResolver,
|
|
586
|
+
config.contractAbiType,
|
|
587
|
+
config.contractRootResolver2,
|
|
588
|
+
config.supportSvcUrl,
|
|
589
|
+
config.queryContract
|
|
590
|
+
);
|
|
591
|
+
};
|
|
648
592
|
|
|
649
593
|
export const ABI_DID = DID_ABI;
|
|
650
594
|
|
|
@@ -653,10 +597,89 @@ namespace OlaresID {
|
|
|
653
597
|
|
|
654
598
|
export { debug } from './debug';
|
|
655
599
|
|
|
656
|
-
// Export Tag utilities
|
|
657
|
-
export { TagTypeBuilder
|
|
600
|
+
// Export Tag utilities
|
|
601
|
+
export { TagTypeBuilder } from './utils/tag-type-builder';
|
|
602
|
+
export { TagTypeParser } from './utils/tag-type-parser';
|
|
658
603
|
|
|
659
604
|
// Export Olares ID utilities
|
|
660
605
|
export { normalizeToDomain, normalizeToOlaresId } from './utils/olares-id';
|
|
661
606
|
|
|
607
|
+
// Export event parser
|
|
608
|
+
export { parseEvents } from './utils/event-parser';
|
|
609
|
+
export type {
|
|
610
|
+
EthLog,
|
|
611
|
+
AnyParsedEvent,
|
|
612
|
+
ParsedEvent,
|
|
613
|
+
TerminusDIDEventName,
|
|
614
|
+
TerminusDIDEventArgsMap,
|
|
615
|
+
TransferArgs,
|
|
616
|
+
ApprovalArgs,
|
|
617
|
+
ApprovalForAllArgs,
|
|
618
|
+
InitializedArgs,
|
|
619
|
+
NewTagTypeArgs,
|
|
620
|
+
OffchainStringArrayArgs,
|
|
621
|
+
OwnershipTransferStartedArgs,
|
|
622
|
+
OwnershipTransferredArgs,
|
|
623
|
+
TagAddedArgs,
|
|
624
|
+
TagElemPoppedArgs,
|
|
625
|
+
TagElemPushedArgs,
|
|
626
|
+
TagElemUpdatedArgs,
|
|
627
|
+
TagRemovedArgs,
|
|
628
|
+
TransferByParentOwnerArgs,
|
|
629
|
+
TransferBySuperAdminArgs,
|
|
630
|
+
UpgradedArgs
|
|
631
|
+
} from './utils/event-parser';
|
|
632
|
+
export {
|
|
633
|
+
isTransferEvent,
|
|
634
|
+
isMintEvent,
|
|
635
|
+
isTagAddedEvent,
|
|
636
|
+
isTagRemovedEvent,
|
|
637
|
+
isTagElemUpdatedEvent,
|
|
638
|
+
isTagElemPushedEvent,
|
|
639
|
+
isTagElemPoppedEvent,
|
|
640
|
+
isNewTagTypeEvent
|
|
641
|
+
} from './utils/event-parser';
|
|
642
|
+
|
|
643
|
+
// Export new domain fetching functions and utilities
|
|
644
|
+
export { QueryContractHelper } from './domain/core';
|
|
645
|
+
export {
|
|
646
|
+
fetchDomain,
|
|
647
|
+
fetchDomains,
|
|
648
|
+
fetchDomainsByIndices,
|
|
649
|
+
fetchAllFlat,
|
|
650
|
+
FetchDomainOptions,
|
|
651
|
+
FetchDomainsOptions,
|
|
652
|
+
FetchDomainsByIndicesOptions
|
|
653
|
+
} from './domain/index';
|
|
654
|
+
export type {
|
|
655
|
+
Tag,
|
|
656
|
+
FlatDomainData,
|
|
657
|
+
RawDomainData,
|
|
658
|
+
RawTagData,
|
|
659
|
+
FetchAllOptions
|
|
660
|
+
} from './domain/types';
|
|
661
|
+
|
|
662
|
+
// Export config utilities
|
|
663
|
+
export { getContractConfig } from './config';
|
|
664
|
+
export type { ContractConfig } from './config';
|
|
665
|
+
|
|
666
|
+
// Export DID utilities
|
|
667
|
+
export type {
|
|
668
|
+
PublicJwk,
|
|
669
|
+
PrivateJwk,
|
|
670
|
+
VerificationMethod,
|
|
671
|
+
DIDDocument,
|
|
672
|
+
Service
|
|
673
|
+
} from './utils/crypto-utils';
|
|
674
|
+
export {
|
|
675
|
+
LDKeyType,
|
|
676
|
+
getPublicJWKFromX,
|
|
677
|
+
getPublicJWKFromDID,
|
|
678
|
+
getPrivateJWKFromD,
|
|
679
|
+
getIDFromEd25519Pubkey,
|
|
680
|
+
getPrivateJWKFromEd25519,
|
|
681
|
+
getFullyQualifiedVerificationMethodID,
|
|
682
|
+
resolveDID
|
|
683
|
+
} from './utils/crypto-utils';
|
|
684
|
+
|
|
662
685
|
export default OlaresID;
|