@docknetwork/wallet-sdk-wasm 1.5.11 → 1.7.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/generate-docs.js +49 -0
- package/jsdoc.conf.json +29 -6
- package/lib/index.js +8 -1
- package/lib/index.mjs +8 -1
- package/lib/rpc-server.js +10 -1
- package/lib/rpc-server.mjs +10 -1
- package/lib/services/blockchain/cached-did-resolver.js +113 -0
- package/lib/services/blockchain/cached-did-resolver.mjs +109 -0
- package/lib/services/blockchain/index.js +11 -0
- package/lib/services/blockchain/index.mjs +11 -0
- package/lib/services/blockchain/service-rpc.js +16 -0
- package/lib/services/blockchain/service-rpc.mjs +16 -0
- package/lib/services/blockchain/service.js +144 -12
- package/lib/services/blockchain/service.mjs +144 -12
- package/lib/services/credential/bbs-revocation.js +11 -0
- package/lib/services/credential/bbs-revocation.mjs +11 -0
- package/lib/services/credential/config.js +4 -1
- package/lib/services/credential/config.mjs +4 -1
- package/lib/services/credential/index.js +14 -0
- package/lib/services/credential/index.mjs +14 -0
- package/lib/services/credential/pex-helpers.js +20 -0
- package/lib/services/credential/pex-helpers.mjs +20 -1
- package/lib/services/credential/sd-jwt.js +214 -0
- package/lib/services/credential/sd-jwt.mjs +200 -0
- package/lib/services/credential/service-rpc.js +9 -0
- package/lib/services/credential/service-rpc.mjs +9 -0
- package/lib/services/credential/service.js +325 -8
- package/lib/services/credential/service.mjs +326 -9
- package/lib/services/edv/service.js +145 -1
- package/lib/services/edv/service.mjs +145 -1
- package/lib/services/index.js +13 -0
- package/lib/services/index.mjs +13 -0
- package/lib/services/relay-service/service.js +124 -1
- package/lib/services/relay-service/service.mjs +124 -1
- package/lib/services/rpc-service-client.js +0 -3
- package/lib/services/rpc-service-client.mjs +0 -3
- package/lib/services/storage/index.js +19 -2
- package/lib/services/storage/index.mjs +24 -1
- package/lib/services/storage/service-rpc.js +7 -3
- package/lib/services/storage/service-rpc.mjs +7 -3
- package/lib/services/storage/service.js +4 -0
- package/lib/services/storage/service.mjs +4 -0
- package/lib/setup-nodejs.js +8 -1
- package/lib/setup-nodejs.mjs +8 -1
- package/lib/setup-tests.js +8 -1
- package/lib/setup-tests.mjs +8 -1
- package/lib/src/services/blockchain/cached-did-resolver.d.ts +28 -0
- package/lib/src/services/blockchain/cached-did-resolver.d.ts.map +1 -0
- package/lib/src/services/blockchain/cached-did-resolver.test.d.ts +2 -0
- package/lib/src/services/blockchain/cached-did-resolver.test.d.ts.map +1 -0
- package/lib/src/services/blockchain/service.d.ts +115 -17
- package/lib/src/services/blockchain/service.d.ts.map +1 -1
- package/lib/src/services/credential/config.d.ts.map +1 -1
- package/lib/src/services/credential/index.d.ts +3 -0
- package/lib/src/services/credential/index.d.ts.map +1 -1
- package/lib/src/services/credential/pex-helpers.d.ts +13 -1
- package/lib/src/services/credential/pex-helpers.d.ts.map +1 -1
- package/lib/src/services/credential/sd-jwt.test.d.ts +2 -0
- package/lib/src/services/credential/sd-jwt.test.d.ts.map +1 -0
- package/lib/src/services/credential/service.d.ts +274 -4
- package/lib/src/services/credential/service.d.ts.map +1 -1
- package/lib/src/services/edv/service.d.ts +151 -1
- package/lib/src/services/edv/service.d.ts.map +1 -1
- package/lib/src/services/relay-service/service.d.ts +129 -1
- package/lib/src/services/relay-service/service.d.ts.map +1 -1
- package/lib/src/services/rpc-service-client.d.ts +2 -2
- package/lib/src/services/rpc-service-client.d.ts.map +1 -1
- package/lib/src/services/storage/index.d.ts +1 -1
- package/lib/src/services/storage/index.d.ts.map +1 -1
- package/lib/src/services/storage/service-rpc.d.ts +9 -0
- package/lib/src/services/storage/service-rpc.d.ts.map +1 -0
- package/lib/src/services/storage/service.d.ts +1 -0
- package/lib/src/services/storage/service.d.ts.map +1 -1
- package/lib/src/services/util-crypto/service.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/wallet/rpc-storage-interface.js +13 -3
- package/lib/wallet/rpc-storage-interface.mjs +11 -1
- package/lib/wallet/rpc-storage-wallet.js +10 -0
- package/lib/wallet/rpc-storage-wallet.mjs +10 -0
- package/package.json +13 -8
- package/src/services/blockchain/cached-did-resolver.test.ts +288 -0
- package/src/services/blockchain/cached-did-resolver.ts +126 -0
- package/src/services/blockchain/service-rpc.js +16 -0
- package/src/services/blockchain/service.ts +146 -12
- package/src/services/credential/config.ts +7 -1
- package/src/services/credential/pex-helpers.js +20 -1
- package/src/services/credential/pex-helpers.test.js +114 -0
- package/src/services/credential/sd-jwt.test.ts +718 -0
- package/src/services/credential/sd-jwt.ts +231 -0
- package/src/services/credential/service-rpc.js +9 -0
- package/src/services/credential/service.ts +330 -9
- package/src/services/edv/service.ts +153 -1
- package/src/services/relay-service/service.ts +130 -1
- package/src/services/rpc-service-client.js +0 -3
- package/src/services/storage/index.js +15 -1
- package/src/services/storage/service-rpc.js +7 -3
- package/src/services/storage/service.ts +5 -0
|
@@ -13,19 +13,43 @@ var core_logger = require('../../core/logger.js');
|
|
|
13
13
|
var modules_eventManager = require('../../modules/event-manager.js');
|
|
14
14
|
var services_utilCrypto_service = require('../util-crypto/service.js');
|
|
15
15
|
var types = require('@docknetwork/credential-sdk/types');
|
|
16
|
+
var services_blockchain_cachedDidResolver = require('./cached-did-resolver.js');
|
|
16
17
|
require('assert');
|
|
17
18
|
require('@docknetwork/credential-sdk/utils');
|
|
18
19
|
require('@scure/bip39');
|
|
19
20
|
require('@scure/bip39/wordlists/english');
|
|
20
21
|
require('../util-crypto/configs.js');
|
|
22
|
+
require('../storage/index.js');
|
|
23
|
+
require('../storage/service.js');
|
|
24
|
+
require('../storage/service-rpc.js');
|
|
25
|
+
require('../rpc-service-client.js');
|
|
26
|
+
require('../../rpc-client.js');
|
|
27
|
+
require('json-rpc-2.0');
|
|
28
|
+
require('../../core/crypto.js');
|
|
29
|
+
require('crypto');
|
|
30
|
+
require('../../logger.js');
|
|
31
|
+
require('../../rpc-util.js');
|
|
21
32
|
|
|
22
33
|
// @ts-nocheck
|
|
34
|
+
/**
|
|
35
|
+
* Universal resolver URL for DID resolution fallback
|
|
36
|
+
* @constant {string}
|
|
37
|
+
*/
|
|
23
38
|
const universalResolverUrl = 'https://uniresolver.truvera.io';
|
|
39
|
+
/**
|
|
40
|
+
* Resolver that accepts any DID method using wildcard matching
|
|
41
|
+
* @class
|
|
42
|
+
* @extends ResolverRouter
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
24
45
|
class AnyDIDResolver extends resolver.ResolverRouter {
|
|
25
46
|
method = resolver.WILDCARD;
|
|
26
47
|
}
|
|
27
48
|
/**
|
|
28
|
-
*
|
|
49
|
+
* Main blockchain service class for managing blockchain connections and DID resolution
|
|
50
|
+
* @class
|
|
51
|
+
* @description Provides methods for connecting to Cheqd blockchain, resolving DIDs,
|
|
52
|
+
* and managing blockchain-related operations
|
|
29
53
|
*/
|
|
30
54
|
class BlockchainService {
|
|
31
55
|
dock;
|
|
@@ -34,6 +58,12 @@ class BlockchainService {
|
|
|
34
58
|
cheqdApiUrl;
|
|
35
59
|
isBlockchainReady = false;
|
|
36
60
|
resolver;
|
|
61
|
+
/**
|
|
62
|
+
* Event names emitted by the blockchain service
|
|
63
|
+
* @static
|
|
64
|
+
* @readonly
|
|
65
|
+
* @property {string} BLOCKCHAIN_READY - Emitted when blockchain connection is established
|
|
66
|
+
*/
|
|
37
67
|
static Events = {
|
|
38
68
|
BLOCKCHAIN_READY: 'blockchain-ready',
|
|
39
69
|
};
|
|
@@ -43,7 +73,15 @@ class BlockchainService {
|
|
|
43
73
|
BlockchainService.prototype.init,
|
|
44
74
|
BlockchainService.prototype.isApiConnected,
|
|
45
75
|
BlockchainService.prototype.getAddress,
|
|
76
|
+
BlockchainService.prototype.resolveDID,
|
|
77
|
+
BlockchainService.prototype.getCachedDIDs,
|
|
78
|
+
BlockchainService.prototype.clearCache,
|
|
79
|
+
BlockchainService.prototype.getCacheEntry,
|
|
46
80
|
];
|
|
81
|
+
/**
|
|
82
|
+
* Creates a new BlockchainService instance
|
|
83
|
+
* @constructor
|
|
84
|
+
*/
|
|
47
85
|
constructor() {
|
|
48
86
|
this.name = 'blockchain';
|
|
49
87
|
this.cheqdApi = new cheqdBlockchainApi.CheqdAPI();
|
|
@@ -52,6 +90,15 @@ class BlockchainService {
|
|
|
52
90
|
this.emitter = new events.EventEmitter();
|
|
53
91
|
this.resolver = this.createDIDResolver();
|
|
54
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Gets the types and modules needed for DID or accumulator operations
|
|
95
|
+
* @param {string} didOrRegistryId - DID or registry identifier
|
|
96
|
+
* @returns {Object} Object containing accumulator-related types and modules
|
|
97
|
+
* @returns {typeof AccumulatorPublicKey} returns.PublicKey - Accumulator public key type
|
|
98
|
+
* @returns {typeof AccumulatorId} returns.AccumulatorId - Accumulator ID type
|
|
99
|
+
* @returns {typeof AccumulatorCommon} returns.AccumulatorCommon - Common accumulator type
|
|
100
|
+
* @returns {Object} returns.AccumulatorModule - Accumulator module instance
|
|
101
|
+
*/
|
|
55
102
|
getTypesForDIDOrAccumulator(didOrRegistryId) {
|
|
56
103
|
return {
|
|
57
104
|
PublicKey: types.AccumulatorPublicKey,
|
|
@@ -61,26 +108,67 @@ class BlockchainService {
|
|
|
61
108
|
};
|
|
62
109
|
}
|
|
63
110
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @returns
|
|
111
|
+
* Ensures the blockchain connection is ready before proceeding
|
|
112
|
+
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
113
|
+
* @example
|
|
114
|
+
* await blockchainService.ensureBlockchainReady();
|
|
115
|
+
* // Blockchain is now connected and ready
|
|
66
116
|
*/
|
|
67
117
|
async ensureBlockchainReady() {
|
|
68
|
-
if (this.
|
|
118
|
+
if (await this.isApiConnected()) {
|
|
69
119
|
return;
|
|
70
120
|
}
|
|
71
121
|
return modules_eventManager.once(this.emitter, BlockchainService.Events.BLOCKCHAIN_READY);
|
|
72
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Gets the cached DIDs
|
|
125
|
+
* @returns {Promise<string[]>} Cached DIDs
|
|
126
|
+
*/
|
|
127
|
+
getCachedDIDs() {
|
|
128
|
+
return this.resolver.getCachedDIDs();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Gets the cached DID resolution data
|
|
132
|
+
* @param {string} did - The DID to get the cache entry for
|
|
133
|
+
* @returns {Promise<any>} Cached DID resolution data
|
|
134
|
+
*/
|
|
135
|
+
getCacheEntry(did) {
|
|
136
|
+
return this.resolver.getCacheEntry(did);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Clears cached data for a specific DID
|
|
140
|
+
* @param {string} did - The DID to clear from cache
|
|
141
|
+
* @returns {void}
|
|
142
|
+
*/
|
|
143
|
+
clearCache(did) {
|
|
144
|
+
return this.resolver.clearCache(did);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a DID resolver with caching support
|
|
148
|
+
* @private
|
|
149
|
+
* @returns {CachedDIDResolver} Cached DID resolver instance
|
|
150
|
+
*/
|
|
73
151
|
createDIDResolver() {
|
|
74
|
-
|
|
152
|
+
const router = new AnyDIDResolver([
|
|
75
153
|
new resolver.DIDKeyResolver(),
|
|
76
154
|
new resolver.CoreResolver(this.modules),
|
|
77
155
|
new resolver.UniversalResolver(universalResolverUrl),
|
|
78
156
|
]);
|
|
157
|
+
return new services_blockchain_cachedDidResolver.CachedDIDResolver(router);
|
|
79
158
|
}
|
|
80
159
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @param {
|
|
83
|
-
* @
|
|
160
|
+
* Initializes the blockchain service with connection parameters
|
|
161
|
+
* @param {InitParams} params - Initialization parameters
|
|
162
|
+
* @param {string} params.cheqdApiUrl - URL of the Cheqd API endpoint
|
|
163
|
+
* @param {string} [params.networkId] - Cheqd network identifier
|
|
164
|
+
* @param {string} [params.cheqdMnemonic] - Mnemonic for Cheqd wallet (auto-generated if not provided)
|
|
165
|
+
* @returns {Promise<boolean>} True if initialization successful
|
|
166
|
+
* @throws {Error} If cheqdApiUrl is not provided
|
|
167
|
+
* @example
|
|
168
|
+
* await blockchainService.init({
|
|
169
|
+
* cheqdApiUrl: 'https://api.cheqd.network',
|
|
170
|
+
* networkId: 'mainnet'
|
|
171
|
+
* });
|
|
84
172
|
*/
|
|
85
173
|
async init(params) {
|
|
86
174
|
if (!params?.cheqdApiUrl) {
|
|
@@ -122,8 +210,10 @@ class BlockchainService {
|
|
|
122
210
|
return true;
|
|
123
211
|
}
|
|
124
212
|
/**
|
|
125
|
-
*
|
|
126
|
-
* @returns
|
|
213
|
+
* Disconnects from the blockchain
|
|
214
|
+
* @returns {Promise<void>} Resolves when disconnection is complete
|
|
215
|
+
* @example
|
|
216
|
+
* await blockchainService.disconnect();
|
|
127
217
|
*/
|
|
128
218
|
async disconnect() {
|
|
129
219
|
let result;
|
|
@@ -133,6 +223,11 @@ class BlockchainService {
|
|
|
133
223
|
this._setBlockchainReady(false);
|
|
134
224
|
return result;
|
|
135
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Waits for the blockchain to be ready
|
|
228
|
+
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
136
231
|
async waitBlockchainReady() {
|
|
137
232
|
return new Promise(resolve => {
|
|
138
233
|
if (this.isBlockchainReady) {
|
|
@@ -144,15 +239,38 @@ class BlockchainService {
|
|
|
144
239
|
});
|
|
145
240
|
}
|
|
146
241
|
/**
|
|
147
|
-
*
|
|
148
|
-
* @
|
|
242
|
+
* Resolves a DID to its document
|
|
243
|
+
* @param {string} did - The DID to resolve
|
|
244
|
+
* @returns {Promise<Object>} The resolved DID document
|
|
245
|
+
* @example
|
|
246
|
+
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
247
|
+
*/
|
|
248
|
+
async resolveDID(did) {
|
|
249
|
+
return this.resolver.resolve(did);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Checks if the blockchain API is connected
|
|
253
|
+
* @returns {Promise<boolean>} True if connected, false otherwise
|
|
254
|
+
* @example
|
|
255
|
+
* const isConnected = await blockchainService.isApiConnected();
|
|
149
256
|
*/
|
|
150
257
|
async isApiConnected() {
|
|
151
258
|
return this.cheqdApi.isInitialized();
|
|
152
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Gets the current Cheqd API URL
|
|
262
|
+
* @returns {Promise<string>} The Cheqd API URL
|
|
263
|
+
* @example
|
|
264
|
+
* const apiUrl = await blockchainService.getAddress();
|
|
265
|
+
*/
|
|
153
266
|
async getAddress() {
|
|
154
267
|
return this.cheqdApiUrl;
|
|
155
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Sets the blockchain ready state and emits events
|
|
271
|
+
* @private
|
|
272
|
+
* @param {boolean} isBlockchainReady - Whether blockchain is ready
|
|
273
|
+
*/
|
|
156
274
|
_setBlockchainReady(isBlockchainReady) {
|
|
157
275
|
this.isBlockchainReady = isBlockchainReady;
|
|
158
276
|
if (isBlockchainReady) {
|
|
@@ -160,6 +278,20 @@ class BlockchainService {
|
|
|
160
278
|
}
|
|
161
279
|
}
|
|
162
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Singleton instance of the blockchain service
|
|
283
|
+
* @type {BlockchainService}
|
|
284
|
+
* @example
|
|
285
|
+
* import { blockchainService } from '@docknetwork/wallet-sdk-wasm/services/blockchain';
|
|
286
|
+
*
|
|
287
|
+
* // Initialize the service
|
|
288
|
+
* await blockchainService.init({
|
|
289
|
+
* cheqdApiUrl: 'https://api.cheqd.network'
|
|
290
|
+
* });
|
|
291
|
+
*
|
|
292
|
+
* // Resolve a DID
|
|
293
|
+
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
294
|
+
*/
|
|
163
295
|
const blockchainService = new BlockchainService();
|
|
164
296
|
|
|
165
297
|
exports.BlockchainService = BlockchainService;
|
|
@@ -9,19 +9,43 @@ import { Logger } from '../../core/logger.mjs';
|
|
|
9
9
|
import { once } from '../../modules/event-manager.mjs';
|
|
10
10
|
import { utilCryptoService } from '../util-crypto/service.mjs';
|
|
11
11
|
import { AccumulatorPublicKey, AccumulatorId, AccumulatorCommon } from '@docknetwork/credential-sdk/types';
|
|
12
|
+
import { CachedDIDResolver } from './cached-did-resolver.mjs';
|
|
12
13
|
import 'assert';
|
|
13
14
|
import '@docknetwork/credential-sdk/utils';
|
|
14
15
|
import '@scure/bip39';
|
|
15
16
|
import '@scure/bip39/wordlists/english';
|
|
16
17
|
import '../util-crypto/configs.mjs';
|
|
18
|
+
import '../storage/index.mjs';
|
|
19
|
+
import '../storage/service.mjs';
|
|
20
|
+
import '../storage/service-rpc.mjs';
|
|
21
|
+
import '../rpc-service-client.mjs';
|
|
22
|
+
import '../../rpc-client.mjs';
|
|
23
|
+
import 'json-rpc-2.0';
|
|
24
|
+
import '../../core/crypto.mjs';
|
|
25
|
+
import 'crypto';
|
|
26
|
+
import '../../logger.mjs';
|
|
27
|
+
import '../../rpc-util.mjs';
|
|
17
28
|
|
|
18
29
|
// @ts-nocheck
|
|
30
|
+
/**
|
|
31
|
+
* Universal resolver URL for DID resolution fallback
|
|
32
|
+
* @constant {string}
|
|
33
|
+
*/
|
|
19
34
|
const universalResolverUrl = 'https://uniresolver.truvera.io';
|
|
35
|
+
/**
|
|
36
|
+
* Resolver that accepts any DID method using wildcard matching
|
|
37
|
+
* @class
|
|
38
|
+
* @extends ResolverRouter
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
20
41
|
class AnyDIDResolver extends ResolverRouter {
|
|
21
42
|
method = WILDCARD;
|
|
22
43
|
}
|
|
23
44
|
/**
|
|
24
|
-
*
|
|
45
|
+
* Main blockchain service class for managing blockchain connections and DID resolution
|
|
46
|
+
* @class
|
|
47
|
+
* @description Provides methods for connecting to Cheqd blockchain, resolving DIDs,
|
|
48
|
+
* and managing blockchain-related operations
|
|
25
49
|
*/
|
|
26
50
|
class BlockchainService {
|
|
27
51
|
dock;
|
|
@@ -30,6 +54,12 @@ class BlockchainService {
|
|
|
30
54
|
cheqdApiUrl;
|
|
31
55
|
isBlockchainReady = false;
|
|
32
56
|
resolver;
|
|
57
|
+
/**
|
|
58
|
+
* Event names emitted by the blockchain service
|
|
59
|
+
* @static
|
|
60
|
+
* @readonly
|
|
61
|
+
* @property {string} BLOCKCHAIN_READY - Emitted when blockchain connection is established
|
|
62
|
+
*/
|
|
33
63
|
static Events = {
|
|
34
64
|
BLOCKCHAIN_READY: 'blockchain-ready',
|
|
35
65
|
};
|
|
@@ -39,7 +69,15 @@ class BlockchainService {
|
|
|
39
69
|
BlockchainService.prototype.init,
|
|
40
70
|
BlockchainService.prototype.isApiConnected,
|
|
41
71
|
BlockchainService.prototype.getAddress,
|
|
72
|
+
BlockchainService.prototype.resolveDID,
|
|
73
|
+
BlockchainService.prototype.getCachedDIDs,
|
|
74
|
+
BlockchainService.prototype.clearCache,
|
|
75
|
+
BlockchainService.prototype.getCacheEntry,
|
|
42
76
|
];
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new BlockchainService instance
|
|
79
|
+
* @constructor
|
|
80
|
+
*/
|
|
43
81
|
constructor() {
|
|
44
82
|
this.name = 'blockchain';
|
|
45
83
|
this.cheqdApi = new CheqdAPI();
|
|
@@ -48,6 +86,15 @@ class BlockchainService {
|
|
|
48
86
|
this.emitter = new EventEmitter();
|
|
49
87
|
this.resolver = this.createDIDResolver();
|
|
50
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Gets the types and modules needed for DID or accumulator operations
|
|
91
|
+
* @param {string} didOrRegistryId - DID or registry identifier
|
|
92
|
+
* @returns {Object} Object containing accumulator-related types and modules
|
|
93
|
+
* @returns {typeof AccumulatorPublicKey} returns.PublicKey - Accumulator public key type
|
|
94
|
+
* @returns {typeof AccumulatorId} returns.AccumulatorId - Accumulator ID type
|
|
95
|
+
* @returns {typeof AccumulatorCommon} returns.AccumulatorCommon - Common accumulator type
|
|
96
|
+
* @returns {Object} returns.AccumulatorModule - Accumulator module instance
|
|
97
|
+
*/
|
|
51
98
|
getTypesForDIDOrAccumulator(didOrRegistryId) {
|
|
52
99
|
return {
|
|
53
100
|
PublicKey: AccumulatorPublicKey,
|
|
@@ -57,26 +104,67 @@ class BlockchainService {
|
|
|
57
104
|
};
|
|
58
105
|
}
|
|
59
106
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @returns
|
|
107
|
+
* Ensures the blockchain connection is ready before proceeding
|
|
108
|
+
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
109
|
+
* @example
|
|
110
|
+
* await blockchainService.ensureBlockchainReady();
|
|
111
|
+
* // Blockchain is now connected and ready
|
|
62
112
|
*/
|
|
63
113
|
async ensureBlockchainReady() {
|
|
64
|
-
if (this.
|
|
114
|
+
if (await this.isApiConnected()) {
|
|
65
115
|
return;
|
|
66
116
|
}
|
|
67
117
|
return once(this.emitter, BlockchainService.Events.BLOCKCHAIN_READY);
|
|
68
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Gets the cached DIDs
|
|
121
|
+
* @returns {Promise<string[]>} Cached DIDs
|
|
122
|
+
*/
|
|
123
|
+
getCachedDIDs() {
|
|
124
|
+
return this.resolver.getCachedDIDs();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets the cached DID resolution data
|
|
128
|
+
* @param {string} did - The DID to get the cache entry for
|
|
129
|
+
* @returns {Promise<any>} Cached DID resolution data
|
|
130
|
+
*/
|
|
131
|
+
getCacheEntry(did) {
|
|
132
|
+
return this.resolver.getCacheEntry(did);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Clears cached data for a specific DID
|
|
136
|
+
* @param {string} did - The DID to clear from cache
|
|
137
|
+
* @returns {void}
|
|
138
|
+
*/
|
|
139
|
+
clearCache(did) {
|
|
140
|
+
return this.resolver.clearCache(did);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates a DID resolver with caching support
|
|
144
|
+
* @private
|
|
145
|
+
* @returns {CachedDIDResolver} Cached DID resolver instance
|
|
146
|
+
*/
|
|
69
147
|
createDIDResolver() {
|
|
70
|
-
|
|
148
|
+
const router = new AnyDIDResolver([
|
|
71
149
|
new DIDKeyResolver(),
|
|
72
150
|
new CoreResolver(this.modules),
|
|
73
151
|
new UniversalResolver(universalResolverUrl),
|
|
74
152
|
]);
|
|
153
|
+
return new CachedDIDResolver(router);
|
|
75
154
|
}
|
|
76
155
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @param {
|
|
79
|
-
* @
|
|
156
|
+
* Initializes the blockchain service with connection parameters
|
|
157
|
+
* @param {InitParams} params - Initialization parameters
|
|
158
|
+
* @param {string} params.cheqdApiUrl - URL of the Cheqd API endpoint
|
|
159
|
+
* @param {string} [params.networkId] - Cheqd network identifier
|
|
160
|
+
* @param {string} [params.cheqdMnemonic] - Mnemonic for Cheqd wallet (auto-generated if not provided)
|
|
161
|
+
* @returns {Promise<boolean>} True if initialization successful
|
|
162
|
+
* @throws {Error} If cheqdApiUrl is not provided
|
|
163
|
+
* @example
|
|
164
|
+
* await blockchainService.init({
|
|
165
|
+
* cheqdApiUrl: 'https://api.cheqd.network',
|
|
166
|
+
* networkId: 'mainnet'
|
|
167
|
+
* });
|
|
80
168
|
*/
|
|
81
169
|
async init(params) {
|
|
82
170
|
if (!params?.cheqdApiUrl) {
|
|
@@ -118,8 +206,10 @@ class BlockchainService {
|
|
|
118
206
|
return true;
|
|
119
207
|
}
|
|
120
208
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @returns
|
|
209
|
+
* Disconnects from the blockchain
|
|
210
|
+
* @returns {Promise<void>} Resolves when disconnection is complete
|
|
211
|
+
* @example
|
|
212
|
+
* await blockchainService.disconnect();
|
|
123
213
|
*/
|
|
124
214
|
async disconnect() {
|
|
125
215
|
let result;
|
|
@@ -129,6 +219,11 @@ class BlockchainService {
|
|
|
129
219
|
this._setBlockchainReady(false);
|
|
130
220
|
return result;
|
|
131
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Waits for the blockchain to be ready
|
|
224
|
+
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
132
227
|
async waitBlockchainReady() {
|
|
133
228
|
return new Promise(resolve => {
|
|
134
229
|
if (this.isBlockchainReady) {
|
|
@@ -140,15 +235,38 @@ class BlockchainService {
|
|
|
140
235
|
});
|
|
141
236
|
}
|
|
142
237
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @
|
|
238
|
+
* Resolves a DID to its document
|
|
239
|
+
* @param {string} did - The DID to resolve
|
|
240
|
+
* @returns {Promise<Object>} The resolved DID document
|
|
241
|
+
* @example
|
|
242
|
+
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
243
|
+
*/
|
|
244
|
+
async resolveDID(did) {
|
|
245
|
+
return this.resolver.resolve(did);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Checks if the blockchain API is connected
|
|
249
|
+
* @returns {Promise<boolean>} True if connected, false otherwise
|
|
250
|
+
* @example
|
|
251
|
+
* const isConnected = await blockchainService.isApiConnected();
|
|
145
252
|
*/
|
|
146
253
|
async isApiConnected() {
|
|
147
254
|
return this.cheqdApi.isInitialized();
|
|
148
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Gets the current Cheqd API URL
|
|
258
|
+
* @returns {Promise<string>} The Cheqd API URL
|
|
259
|
+
* @example
|
|
260
|
+
* const apiUrl = await blockchainService.getAddress();
|
|
261
|
+
*/
|
|
149
262
|
async getAddress() {
|
|
150
263
|
return this.cheqdApiUrl;
|
|
151
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Sets the blockchain ready state and emits events
|
|
267
|
+
* @private
|
|
268
|
+
* @param {boolean} isBlockchainReady - Whether blockchain is ready
|
|
269
|
+
*/
|
|
152
270
|
_setBlockchainReady(isBlockchainReady) {
|
|
153
271
|
this.isBlockchainReady = isBlockchainReady;
|
|
154
272
|
if (isBlockchainReady) {
|
|
@@ -156,6 +274,20 @@ class BlockchainService {
|
|
|
156
274
|
}
|
|
157
275
|
}
|
|
158
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Singleton instance of the blockchain service
|
|
279
|
+
* @type {BlockchainService}
|
|
280
|
+
* @example
|
|
281
|
+
* import { blockchainService } from '@docknetwork/wallet-sdk-wasm/services/blockchain';
|
|
282
|
+
*
|
|
283
|
+
* // Initialize the service
|
|
284
|
+
* await blockchainService.init({
|
|
285
|
+
* cheqdApiUrl: 'https://api.cheqd.network'
|
|
286
|
+
* });
|
|
287
|
+
*
|
|
288
|
+
* // Resolve a DID
|
|
289
|
+
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
290
|
+
*/
|
|
159
291
|
const blockchainService = new BlockchainService();
|
|
160
292
|
|
|
161
293
|
export { BlockchainService, blockchainService, universalResolverUrl };
|
|
@@ -20,6 +20,17 @@ require('@scure/bip39');
|
|
|
20
20
|
require('@scure/bip39/wordlists/english');
|
|
21
21
|
require('../util-crypto/configs.js');
|
|
22
22
|
require('@docknetwork/credential-sdk/types');
|
|
23
|
+
require('../blockchain/cached-did-resolver.js');
|
|
24
|
+
require('../storage/index.js');
|
|
25
|
+
require('../storage/service.js');
|
|
26
|
+
require('../storage/service-rpc.js');
|
|
27
|
+
require('../rpc-service-client.js');
|
|
28
|
+
require('../../rpc-client.js');
|
|
29
|
+
require('json-rpc-2.0');
|
|
30
|
+
require('../../core/crypto.js');
|
|
31
|
+
require('crypto');
|
|
32
|
+
require('../../logger.js');
|
|
33
|
+
require('../../rpc-util.js');
|
|
23
34
|
|
|
24
35
|
const getWitnessDetails = async (credential, _membershipWitness) => {
|
|
25
36
|
let witness = _membershipWitness;
|
|
@@ -16,6 +16,17 @@ import '@scure/bip39';
|
|
|
16
16
|
import '@scure/bip39/wordlists/english';
|
|
17
17
|
import '../util-crypto/configs.mjs';
|
|
18
18
|
import '@docknetwork/credential-sdk/types';
|
|
19
|
+
import '../blockchain/cached-did-resolver.mjs';
|
|
20
|
+
import '../storage/index.mjs';
|
|
21
|
+
import '../storage/service.mjs';
|
|
22
|
+
import '../storage/service-rpc.mjs';
|
|
23
|
+
import '../rpc-service-client.mjs';
|
|
24
|
+
import '../../rpc-client.mjs';
|
|
25
|
+
import 'json-rpc-2.0';
|
|
26
|
+
import '../../core/crypto.mjs';
|
|
27
|
+
import 'crypto';
|
|
28
|
+
import '../../logger.mjs';
|
|
29
|
+
import '../../rpc-util.mjs';
|
|
19
30
|
|
|
20
31
|
const getWitnessDetails = async (credential, _membershipWitness) => {
|
|
21
32
|
let witness = _membershipWitness;
|
|
@@ -20,7 +20,10 @@ const validation = {
|
|
|
20
20
|
},
|
|
21
21
|
verifyCredential: params => {
|
|
22
22
|
const { credential } = params;
|
|
23
|
-
assert__default["default"](typeof credential === 'object', 'invalid credential');
|
|
23
|
+
assert__default["default"](typeof credential === 'object' || typeof credential === 'string', 'invalid credential');
|
|
24
|
+
if (typeof credential === 'object') {
|
|
25
|
+
assert__default["default"](Object.keys(credential).length > 0, 'invalid credential');
|
|
26
|
+
}
|
|
24
27
|
},
|
|
25
28
|
createBBSPresentation: params => {
|
|
26
29
|
const { credentials } = params;
|
|
@@ -12,7 +12,10 @@ const validation = {
|
|
|
12
12
|
},
|
|
13
13
|
verifyCredential: params => {
|
|
14
14
|
const { credential } = params;
|
|
15
|
-
assert(typeof credential === 'object', 'invalid credential');
|
|
15
|
+
assert(typeof credential === 'object' || typeof credential === 'string', 'invalid credential');
|
|
16
|
+
if (typeof credential === 'object') {
|
|
17
|
+
assert(Object.keys(credential).length > 0, 'invalid credential');
|
|
18
|
+
}
|
|
16
19
|
},
|
|
17
20
|
createBBSPresentation: params => {
|
|
18
21
|
const { credentials } = params;
|
|
@@ -27,6 +27,17 @@ require('@scure/bip39');
|
|
|
27
27
|
require('@scure/bip39/wordlists/english');
|
|
28
28
|
require('../util-crypto/configs.js');
|
|
29
29
|
require('@docknetwork/credential-sdk/types');
|
|
30
|
+
require('../blockchain/cached-did-resolver.js');
|
|
31
|
+
require('../storage/index.js');
|
|
32
|
+
require('../storage/service.js');
|
|
33
|
+
require('../storage/service-rpc.js');
|
|
34
|
+
require('../rpc-service-client.js');
|
|
35
|
+
require('../../rpc-client.js');
|
|
36
|
+
require('json-rpc-2.0');
|
|
37
|
+
require('../../core/crypto.js');
|
|
38
|
+
require('crypto');
|
|
39
|
+
require('../../logger.js');
|
|
40
|
+
require('../../rpc-util.js');
|
|
30
41
|
require('./bound-check.js');
|
|
31
42
|
require('@docknetwork/crypto-wasm-ts/lib/legosnark');
|
|
32
43
|
require('base64url');
|
|
@@ -45,6 +56,9 @@ require('@digitalbazaar/x25519-key-agreement-key-2019');
|
|
|
45
56
|
require('@digitalbazaar/ed25519-verification-key-2018');
|
|
46
57
|
require('@digitalbazaar/ed25519-verification-key-2020');
|
|
47
58
|
require('../dids/keypair-utils.js');
|
|
59
|
+
require('./sd-jwt.js');
|
|
60
|
+
require('@sd-jwt/sd-jwt-vc');
|
|
61
|
+
require('@sd-jwt/crypto-nodejs');
|
|
48
62
|
|
|
49
63
|
// @ts-nocheck
|
|
50
64
|
// TODO: rename it to credentialService, will need to update dock-app
|
|
@@ -23,6 +23,17 @@ import '@scure/bip39';
|
|
|
23
23
|
import '@scure/bip39/wordlists/english';
|
|
24
24
|
import '../util-crypto/configs.mjs';
|
|
25
25
|
import '@docknetwork/credential-sdk/types';
|
|
26
|
+
import '../blockchain/cached-did-resolver.mjs';
|
|
27
|
+
import '../storage/index.mjs';
|
|
28
|
+
import '../storage/service.mjs';
|
|
29
|
+
import '../storage/service-rpc.mjs';
|
|
30
|
+
import '../rpc-service-client.mjs';
|
|
31
|
+
import '../../rpc-client.mjs';
|
|
32
|
+
import 'json-rpc-2.0';
|
|
33
|
+
import '../../core/crypto.mjs';
|
|
34
|
+
import 'crypto';
|
|
35
|
+
import '../../logger.mjs';
|
|
36
|
+
import '../../rpc-util.mjs';
|
|
26
37
|
import './bound-check.mjs';
|
|
27
38
|
import '@docknetwork/crypto-wasm-ts/lib/legosnark';
|
|
28
39
|
import 'base64url';
|
|
@@ -41,6 +52,9 @@ import '@digitalbazaar/x25519-key-agreement-key-2019';
|
|
|
41
52
|
import '@digitalbazaar/ed25519-verification-key-2018';
|
|
42
53
|
import '@digitalbazaar/ed25519-verification-key-2020';
|
|
43
54
|
import '../dids/keypair-utils.mjs';
|
|
55
|
+
import './sd-jwt.mjs';
|
|
56
|
+
import '@sd-jwt/sd-jwt-vc';
|
|
57
|
+
import '@sd-jwt/crypto-nodejs';
|
|
44
58
|
|
|
45
59
|
// @ts-nocheck
|
|
46
60
|
// TODO: rename it to credentialService, will need to update dock-app
|
|
@@ -64,6 +64,17 @@ function getAttributeName({field, selectedCredentials, index}) {
|
|
|
64
64
|
return attributeName;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Convert PEX request to bounds for each descriptor
|
|
69
|
+
* @param {*} pexRequest - The PEX request object containing input descriptors and constraints
|
|
70
|
+
* @param {*} selectedCredentials - Array of selected credentials corresponding to the input descriptors
|
|
71
|
+
* @param {*} removeFromRequest - if true, removes range proofs fields from the request. it might be dangerous if you will be using the proof request later
|
|
72
|
+
* because it will not have the range proofs fields anymore.
|
|
73
|
+
* @returns {Array} - Array of bounds for each descriptor, where each bound is an object with attributeName, min, and max
|
|
74
|
+
* @throws {Error} - If a field path is missing or empty
|
|
75
|
+
* @throws {Error} - If an unsupported format or type is encountered
|
|
76
|
+
* @throws {Error} - If a selected credential is expected but not found at the given index
|
|
77
|
+
*/
|
|
67
78
|
function pexToBounds(
|
|
68
79
|
pexRequest,
|
|
69
80
|
selectedCredentials = [],
|
|
@@ -166,6 +177,9 @@ function pexToBounds(
|
|
|
166
177
|
: formatMinimum
|
|
167
178
|
: minimum;
|
|
168
179
|
|
|
180
|
+
const proofRequestMax = max;
|
|
181
|
+
const proofRequestMin = min;
|
|
182
|
+
|
|
169
183
|
if (max === undefined && min === undefined) {
|
|
170
184
|
return;
|
|
171
185
|
}
|
|
@@ -240,6 +254,10 @@ function pexToBounds(
|
|
|
240
254
|
attributeName,
|
|
241
255
|
min,
|
|
242
256
|
max,
|
|
257
|
+
proofRequestMax,
|
|
258
|
+
proofRequestMin,
|
|
259
|
+
format,
|
|
260
|
+
type,
|
|
243
261
|
});
|
|
244
262
|
});
|
|
245
263
|
|
|
@@ -262,6 +280,7 @@ const attributesToSkip = [
|
|
|
262
280
|
/^@context/,
|
|
263
281
|
/^proof/,
|
|
264
282
|
/^credentialSchema/,
|
|
283
|
+
/^issuanceDate/,
|
|
265
284
|
];
|
|
266
285
|
|
|
267
286
|
const shouldSkipAttribute = attributeName =>
|
|
@@ -311,3 +330,4 @@ exports.MIN_INTEGER = MIN_INTEGER;
|
|
|
311
330
|
exports.MIN_NUMBER = MIN_NUMBER;
|
|
312
331
|
exports.getPexRequiredAttributes = getPexRequiredAttributes;
|
|
313
332
|
exports.pexToBounds = pexToBounds;
|
|
333
|
+
exports.shouldSkipAttribute = shouldSkipAttribute;
|