@docknetwork/wallet-sdk-wasm 1.5.14 → 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 +12 -0
- package/lib/services/blockchain/service-rpc.mjs +12 -0
- package/lib/services/blockchain/service.js +140 -11
- package/lib/services/blockchain/service.mjs +140 -11
- 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/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 +324 -7
- package/lib/services/credential/service.mjs +324 -7
- 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 +114 -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/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 +12 -0
- package/src/services/blockchain/service.ts +142 -11
- package/src/services/credential/config.ts +7 -1
- 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 +328 -7
- 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
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @module blockchain-service
|
|
5
|
+
* @description Blockchain connectivity and DID resolution service for the Wallet SDK.
|
|
6
|
+
* This module provides functionality for connecting to Cheqd blockchain, resolving DIDs,
|
|
7
|
+
* and managing accumulator-related operations.
|
|
8
|
+
*/
|
|
9
|
+
|
|
3
10
|
import {DirectSecp256k1HdWallet} from '@cosmjs/proto-signing';
|
|
4
11
|
import {CheqdAPI} from '@docknetwork/cheqd-blockchain-api';
|
|
5
12
|
import {CheqdCoreModules} from '@docknetwork/cheqd-blockchain-modules';
|
|
@@ -18,6 +25,10 @@ import {once} from '../../modules/event-manager';
|
|
|
18
25
|
import {utilCryptoService} from '../util-crypto';
|
|
19
26
|
import {InitParams} from './configs';
|
|
20
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Universal resolver URL for DID resolution fallback
|
|
30
|
+
* @constant {string}
|
|
31
|
+
*/
|
|
21
32
|
export const universalResolverUrl = 'https://uniresolver.truvera.io';
|
|
22
33
|
|
|
23
34
|
import {
|
|
@@ -25,13 +36,23 @@ import {
|
|
|
25
36
|
AccumulatorId,
|
|
26
37
|
AccumulatorPublicKey,
|
|
27
38
|
} from '@docknetwork/credential-sdk/types';
|
|
39
|
+
import { CachedDIDResolver } from './cached-did-resolver';
|
|
28
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Resolver that accepts any DID method using wildcard matching
|
|
43
|
+
* @class
|
|
44
|
+
* @extends ResolverRouter
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
29
47
|
class AnyDIDResolver extends ResolverRouter {
|
|
30
48
|
method = WILDCARD;
|
|
31
49
|
}
|
|
32
50
|
|
|
33
51
|
/**
|
|
34
|
-
*
|
|
52
|
+
* Main blockchain service class for managing blockchain connections and DID resolution
|
|
53
|
+
* @class
|
|
54
|
+
* @description Provides methods for connecting to Cheqd blockchain, resolving DIDs,
|
|
55
|
+
* and managing blockchain-related operations
|
|
35
56
|
*/
|
|
36
57
|
export class BlockchainService {
|
|
37
58
|
dock;
|
|
@@ -40,6 +61,12 @@ export class BlockchainService {
|
|
|
40
61
|
cheqdApiUrl;
|
|
41
62
|
isBlockchainReady = false;
|
|
42
63
|
resolver: any;
|
|
64
|
+
/**
|
|
65
|
+
* Event names emitted by the blockchain service
|
|
66
|
+
* @static
|
|
67
|
+
* @readonly
|
|
68
|
+
* @property {string} BLOCKCHAIN_READY - Emitted when blockchain connection is established
|
|
69
|
+
*/
|
|
43
70
|
static Events = {
|
|
44
71
|
BLOCKCHAIN_READY: 'blockchain-ready',
|
|
45
72
|
};
|
|
@@ -50,8 +77,16 @@ export class BlockchainService {
|
|
|
50
77
|
BlockchainService.prototype.init,
|
|
51
78
|
BlockchainService.prototype.isApiConnected,
|
|
52
79
|
BlockchainService.prototype.getAddress,
|
|
80
|
+
BlockchainService.prototype.resolveDID,
|
|
81
|
+
BlockchainService.prototype.getCachedDIDs,
|
|
82
|
+
BlockchainService.prototype.clearCache,
|
|
83
|
+
BlockchainService.prototype.getCacheEntry,
|
|
53
84
|
];
|
|
54
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new BlockchainService instance
|
|
88
|
+
* @constructor
|
|
89
|
+
*/
|
|
55
90
|
constructor() {
|
|
56
91
|
this.name = 'blockchain';
|
|
57
92
|
this.cheqdApi = new CheqdAPI();
|
|
@@ -61,6 +96,15 @@ export class BlockchainService {
|
|
|
61
96
|
this.resolver = this.createDIDResolver();
|
|
62
97
|
}
|
|
63
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Gets the types and modules needed for DID or accumulator operations
|
|
101
|
+
* @param {string} didOrRegistryId - DID or registry identifier
|
|
102
|
+
* @returns {Object} Object containing accumulator-related types and modules
|
|
103
|
+
* @returns {typeof AccumulatorPublicKey} returns.PublicKey - Accumulator public key type
|
|
104
|
+
* @returns {typeof AccumulatorId} returns.AccumulatorId - Accumulator ID type
|
|
105
|
+
* @returns {typeof AccumulatorCommon} returns.AccumulatorCommon - Common accumulator type
|
|
106
|
+
* @returns {Object} returns.AccumulatorModule - Accumulator module instance
|
|
107
|
+
*/
|
|
64
108
|
getTypesForDIDOrAccumulator(didOrRegistryId) {
|
|
65
109
|
return {
|
|
66
110
|
PublicKey: AccumulatorPublicKey,
|
|
@@ -71,8 +115,11 @@ export class BlockchainService {
|
|
|
71
115
|
}
|
|
72
116
|
|
|
73
117
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @returns
|
|
118
|
+
* Ensures the blockchain connection is ready before proceeding
|
|
119
|
+
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
120
|
+
* @example
|
|
121
|
+
* await blockchainService.ensureBlockchainReady();
|
|
122
|
+
* // Blockchain is now connected and ready
|
|
76
123
|
*/
|
|
77
124
|
async ensureBlockchainReady() {
|
|
78
125
|
if (await this.isApiConnected()) {
|
|
@@ -82,17 +129,60 @@ export class BlockchainService {
|
|
|
82
129
|
return once(this.emitter, BlockchainService.Events.BLOCKCHAIN_READY);
|
|
83
130
|
}
|
|
84
131
|
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Gets the cached DIDs
|
|
135
|
+
* @returns {Promise<string[]>} Cached DIDs
|
|
136
|
+
*/
|
|
137
|
+
getCachedDIDs() {
|
|
138
|
+
return this.resolver.getCachedDIDs();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Gets the cached DID resolution data
|
|
143
|
+
* @param {string} did - The DID to get the cache entry for
|
|
144
|
+
* @returns {Promise<any>} Cached DID resolution data
|
|
145
|
+
*/
|
|
146
|
+
getCacheEntry(did) {
|
|
147
|
+
return this.resolver.getCacheEntry(did);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Clears cached data for a specific DID
|
|
152
|
+
* @param {string} did - The DID to clear from cache
|
|
153
|
+
* @returns {void}
|
|
154
|
+
*/
|
|
155
|
+
clearCache(did) {
|
|
156
|
+
return this.resolver.clearCache(did);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Creates a DID resolver with caching support
|
|
161
|
+
* @private
|
|
162
|
+
* @returns {CachedDIDResolver} Cached DID resolver instance
|
|
163
|
+
*/
|
|
85
164
|
createDIDResolver() {
|
|
86
|
-
|
|
165
|
+
const router = new AnyDIDResolver([
|
|
87
166
|
new DIDKeyResolver(),
|
|
88
167
|
new CoreResolver(this.modules),
|
|
89
168
|
new UniversalResolver(universalResolverUrl),
|
|
90
169
|
]);
|
|
170
|
+
|
|
171
|
+
return new CachedDIDResolver(router);
|
|
91
172
|
}
|
|
92
173
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @param {
|
|
95
|
-
* @
|
|
174
|
+
* Initializes the blockchain service with connection parameters
|
|
175
|
+
* @param {InitParams} params - Initialization parameters
|
|
176
|
+
* @param {string} params.cheqdApiUrl - URL of the Cheqd API endpoint
|
|
177
|
+
* @param {string} [params.networkId] - Cheqd network identifier
|
|
178
|
+
* @param {string} [params.cheqdMnemonic] - Mnemonic for Cheqd wallet (auto-generated if not provided)
|
|
179
|
+
* @returns {Promise<boolean>} True if initialization successful
|
|
180
|
+
* @throws {Error} If cheqdApiUrl is not provided
|
|
181
|
+
* @example
|
|
182
|
+
* await blockchainService.init({
|
|
183
|
+
* cheqdApiUrl: 'https://api.cheqd.network',
|
|
184
|
+
* networkId: 'mainnet'
|
|
185
|
+
* });
|
|
96
186
|
*/
|
|
97
187
|
async init(params: InitParams) {
|
|
98
188
|
if (!params?.cheqdApiUrl) {
|
|
@@ -151,8 +241,10 @@ export class BlockchainService {
|
|
|
151
241
|
}
|
|
152
242
|
|
|
153
243
|
/**
|
|
154
|
-
*
|
|
155
|
-
* @returns
|
|
244
|
+
* Disconnects from the blockchain
|
|
245
|
+
* @returns {Promise<void>} Resolves when disconnection is complete
|
|
246
|
+
* @example
|
|
247
|
+
* await blockchainService.disconnect();
|
|
156
248
|
*/
|
|
157
249
|
async disconnect() {
|
|
158
250
|
let result;
|
|
@@ -166,6 +258,11 @@ export class BlockchainService {
|
|
|
166
258
|
return result;
|
|
167
259
|
}
|
|
168
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Waits for the blockchain to be ready
|
|
263
|
+
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
169
266
|
async waitBlockchainReady() {
|
|
170
267
|
return new Promise(resolve => {
|
|
171
268
|
if (this.isBlockchainReady) {
|
|
@@ -176,21 +273,41 @@ export class BlockchainService {
|
|
|
176
273
|
});
|
|
177
274
|
}
|
|
178
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Resolves a DID to its document
|
|
278
|
+
* @param {string} did - The DID to resolve
|
|
279
|
+
* @returns {Promise<Object>} The resolved DID document
|
|
280
|
+
* @example
|
|
281
|
+
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
282
|
+
*/
|
|
179
283
|
async resolveDID(did: string) {
|
|
180
284
|
return this.resolver.resolve(did);
|
|
181
285
|
}
|
|
182
286
|
/**
|
|
183
|
-
*
|
|
184
|
-
* @returns
|
|
287
|
+
* Checks if the blockchain API is connected
|
|
288
|
+
* @returns {Promise<boolean>} True if connected, false otherwise
|
|
289
|
+
* @example
|
|
290
|
+
* const isConnected = await blockchainService.isApiConnected();
|
|
185
291
|
*/
|
|
186
292
|
async isApiConnected() {
|
|
187
293
|
return this.cheqdApi.isInitialized();
|
|
188
294
|
}
|
|
189
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Gets the current Cheqd API URL
|
|
298
|
+
* @returns {Promise<string>} The Cheqd API URL
|
|
299
|
+
* @example
|
|
300
|
+
* const apiUrl = await blockchainService.getAddress();
|
|
301
|
+
*/
|
|
190
302
|
async getAddress() {
|
|
191
303
|
return this.cheqdApiUrl;
|
|
192
304
|
}
|
|
193
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Sets the blockchain ready state and emits events
|
|
308
|
+
* @private
|
|
309
|
+
* @param {boolean} isBlockchainReady - Whether blockchain is ready
|
|
310
|
+
*/
|
|
194
311
|
_setBlockchainReady(isBlockchainReady) {
|
|
195
312
|
this.isBlockchainReady = isBlockchainReady;
|
|
196
313
|
|
|
@@ -200,4 +317,18 @@ export class BlockchainService {
|
|
|
200
317
|
}
|
|
201
318
|
}
|
|
202
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Singleton instance of the blockchain service
|
|
322
|
+
* @type {BlockchainService}
|
|
323
|
+
* @example
|
|
324
|
+
* import { blockchainService } from '@docknetwork/wallet-sdk-wasm/services/blockchain';
|
|
325
|
+
*
|
|
326
|
+
* // Initialize the service
|
|
327
|
+
* await blockchainService.init({
|
|
328
|
+
* cheqdApiUrl: 'https://api.cheqd.network'
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* // Resolve a DID
|
|
332
|
+
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
333
|
+
*/
|
|
203
334
|
export const blockchainService: BlockchainService = new BlockchainService();
|
|
@@ -12,7 +12,13 @@ export const validation = {
|
|
|
12
12
|
},
|
|
13
13
|
verifyCredential: params => {
|
|
14
14
|
const {credential} = params;
|
|
15
|
-
assert(
|
|
15
|
+
assert(
|
|
16
|
+
typeof credential === 'object' || typeof credential === 'string',
|
|
17
|
+
'invalid credential',
|
|
18
|
+
);
|
|
19
|
+
if (typeof credential === 'object') {
|
|
20
|
+
assert(Object.keys(credential).length > 0, 'invalid credential');
|
|
21
|
+
}
|
|
16
22
|
},
|
|
17
23
|
createBBSPresentation: params => {
|
|
18
24
|
const {credentials} = params;
|