@docknetwork/wallet-sdk-wasm 1.7.6 → 1.9.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/package.json +6 -7
- package/rollup.config.mjs +1 -0
- package/src/globals.d.ts +4 -1
- package/src/services/blockchain/cached-did-resolver.ts +4 -3
- package/src/services/blockchain/normalize-did-document.ts +73 -0
- package/src/services/blockchain/service.ts +0 -2
- package/src/services/credential/bbs-revocation.test.js +147 -0
- package/src/services/credential/bbs-revocation.ts +65 -18
- package/src/services/credential/config.ts +7 -0
- package/src/services/credential/index.test.js +261 -17
- package/src/services/credential/oid4vci.js +44 -0
- package/src/services/credential/oid4vci.test.js +162 -0
- package/src/services/credential/pex-helpers.js +77 -31
- package/src/services/credential/pex-helpers.test.js +4 -4
- package/src/services/credential/sd-jwt.ts +41 -5
- package/src/services/credential/service-rpc.js +6 -0
- package/src/services/credential/service.ts +171 -16
- package/src/services/credential/utils.js +3 -5
- package/src/services/delegation/index.android.js +3 -0
- package/src/services/delegation/index.ios.js +3 -0
- package/src/services/delegation/index.ts +1 -0
- package/src/services/delegation/service-rpc.ts +21 -0
- package/src/services/delegation/service.ts +59 -0
- package/src/services/edv/service-rpc.js +18 -2
- package/src/services/edv/service.test.js +327 -0
- package/src/services/edv/service.ts +103 -13
- package/src/services/index.js +2 -0
- package/src/wallet/rpc-storage-interface.js +9 -4
- package/lib/core/crypto.js +0 -45
- package/lib/core/crypto.mjs +0 -33
- package/lib/core/format-utils.js +0 -51
- package/lib/core/format-utils.mjs +0 -42
- package/lib/core/keychain.js +0 -61
- package/lib/core/keychain.mjs +0 -37
- package/lib/core/logger.js +0 -13
- package/lib/core/logger.mjs +0 -9
- package/lib/core/storage.js +0 -14
- package/lib/core/storage.mjs +0 -9
- package/lib/core/validation.js +0 -29
- package/lib/core/validation.mjs +0 -16
- package/lib/core/webview-logger.js +0 -49
- package/lib/core/webview-logger.mjs +0 -41
- package/lib/errors.js +0 -17
- package/lib/errors.mjs +0 -12
- package/lib/events.js +0 -18
- package/lib/events.mjs +0 -13
- package/lib/index.js +0 -146
- package/lib/index.mjs +0 -144
- package/lib/logger.js +0 -22
- package/lib/logger.mjs +0 -17
- package/lib/modules/event-manager.js +0 -46
- package/lib/modules/event-manager.mjs +0 -37
- package/lib/modules/network-manager.js +0 -80
- package/lib/modules/network-manager.mjs +0 -71
- package/lib/mrklt.js +0 -2
- package/lib/mrklt.mjs +0 -1
- package/lib/rpc-client.js +0 -83
- package/lib/rpc-client.mjs +0 -73
- package/lib/rpc-server.js +0 -97
- package/lib/rpc-server.mjs +0 -95
- package/lib/rpc-util.js +0 -113
- package/lib/rpc-util.mjs +0 -103
- package/lib/sandbox-rpc-server.js +0 -28
- package/lib/sandbox-rpc-server.mjs +0 -26
- package/lib/sandbox.js +0 -102
- package/lib/sandbox.mjs +0 -100
- package/lib/services/blockchain/cached-did-resolver.js +0 -113
- package/lib/services/blockchain/cached-did-resolver.mjs +0 -109
- package/lib/services/blockchain/configs.js +0 -7
- package/lib/services/blockchain/configs.mjs +0 -3
- package/lib/services/blockchain/index.android.js +0 -18
- package/lib/services/blockchain/index.android.mjs +0 -14
- package/lib/services/blockchain/index.ios.js +0 -18
- package/lib/services/blockchain/index.ios.mjs +0 -14
- package/lib/services/blockchain/index.js +0 -36
- package/lib/services/blockchain/index.mjs +0 -28
- package/lib/services/blockchain/service-rpc.js +0 -72
- package/lib/services/blockchain/service-rpc.mjs +0 -68
- package/lib/services/blockchain/service.js +0 -312
- package/lib/services/blockchain/service.mjs +0 -306
- package/lib/services/credential/bbs-revocation.js +0 -92
- package/lib/services/credential/bbs-revocation.mjs +0 -87
- package/lib/services/credential/bound-check.js +0 -77
- package/lib/services/credential/bound-check.mjs +0 -64
- package/lib/services/credential/config.js +0 -56
- package/lib/services/credential/config.mjs +0 -47
- package/lib/services/credential/delegatable-credentials.js +0 -300
- package/lib/services/credential/delegatable-credentials.mjs +0 -263
- package/lib/services/credential/index.android.js +0 -19
- package/lib/services/credential/index.android.mjs +0 -15
- package/lib/services/credential/index.ios.js +0 -19
- package/lib/services/credential/index.ios.mjs +0 -15
- package/lib/services/credential/index.js +0 -106
- package/lib/services/credential/index.mjs +0 -67
- package/lib/services/credential/pex-helpers.js +0 -333
- package/lib/services/credential/pex-helpers.mjs +0 -319
- package/lib/services/credential/range-proofs-example.js +0 -107
- package/lib/services/credential/range-proofs-example.mjs +0 -103
- package/lib/services/credential/sd-jwt.js +0 -214
- package/lib/services/credential/sd-jwt.mjs +0 -200
- package/lib/services/credential/service-rpc.js +0 -61
- package/lib/services/credential/service-rpc.mjs +0 -57
- package/lib/services/credential/service.js +0 -683
- package/lib/services/credential/service.mjs +0 -672
- package/lib/services/credential/utils.js +0 -103
- package/lib/services/credential/utils.mjs +0 -78
- package/lib/services/dids/config.js +0 -40
- package/lib/services/dids/config.mjs +0 -31
- package/lib/services/dids/index.android.js +0 -19
- package/lib/services/dids/index.android.mjs +0 -15
- package/lib/services/dids/index.ios.js +0 -19
- package/lib/services/dids/index.ios.mjs +0 -15
- package/lib/services/dids/index.js +0 -23
- package/lib/services/dids/index.mjs +0 -19
- package/lib/services/dids/keypair-utils.js +0 -142
- package/lib/services/dids/keypair-utils.mjs +0 -113
- package/lib/services/dids/service-rpc.js +0 -37
- package/lib/services/dids/service-rpc.mjs +0 -33
- package/lib/services/dids/service.js +0 -100
- package/lib/services/dids/service.mjs +0 -92
- package/lib/services/edv/configs.js +0 -25
- package/lib/services/edv/configs.mjs +0 -16
- package/lib/services/edv/hmac.js +0 -88
- package/lib/services/edv/hmac.mjs +0 -63
- package/lib/services/edv/index.android.js +0 -19
- package/lib/services/edv/index.android.mjs +0 -15
- package/lib/services/edv/index.ios.js +0 -19
- package/lib/services/edv/index.ios.mjs +0 -15
- package/lib/services/edv/index.js +0 -32
- package/lib/services/edv/index.mjs +0 -24
- package/lib/services/edv/service-rpc.js +0 -78
- package/lib/services/edv/service-rpc.mjs +0 -74
- package/lib/services/edv/service.js +0 -370
- package/lib/services/edv/service.mjs +0 -357
- package/lib/services/index.js +0 -94
- package/lib/services/index.mjs +0 -92
- package/lib/services/pex/config.js +0 -29
- package/lib/services/pex/config.mjs +0 -20
- package/lib/services/pex/index.android.js +0 -19
- package/lib/services/pex/index.android.mjs +0 -15
- package/lib/services/pex/index.ios.js +0 -19
- package/lib/services/pex/index.ios.mjs +0 -15
- package/lib/services/pex/index.js +0 -12
- package/lib/services/pex/index.mjs +0 -4
- package/lib/services/pex/service-rpc.js +0 -39
- package/lib/services/pex/service-rpc.mjs +0 -35
- package/lib/services/pex/service.js +0 -91
- package/lib/services/pex/service.mjs +0 -86
- package/lib/services/pex/tests/jest.config.js +0 -25
- package/lib/services/pex/tests/jest.config.mjs +0 -23
- package/lib/services/relay-service/configs.js +0 -45
- package/lib/services/relay-service/configs.mjs +0 -36
- package/lib/services/relay-service/index.android.js +0 -21
- package/lib/services/relay-service/index.android.mjs +0 -17
- package/lib/services/relay-service/index.ios.js +0 -21
- package/lib/services/relay-service/index.ios.mjs +0 -17
- package/lib/services/relay-service/index.js +0 -14
- package/lib/services/relay-service/index.mjs +0 -6
- package/lib/services/relay-service/service-rpc.js +0 -47
- package/lib/services/relay-service/service-rpc.mjs +0 -43
- package/lib/services/relay-service/service.js +0 -181
- package/lib/services/relay-service/service.mjs +0 -173
- package/lib/services/rpc-service-client.js +0 -36
- package/lib/services/rpc-service-client.mjs +0 -28
- package/lib/services/sandbox.js +0 -10
- package/lib/services/sandbox.mjs +0 -8
- package/lib/services/storage/configs.js +0 -7
- package/lib/services/storage/configs.mjs +0 -3
- package/lib/services/storage/index.android.js +0 -18
- package/lib/services/storage/index.android.mjs +0 -14
- package/lib/services/storage/index.ios.js +0 -18
- package/lib/services/storage/index.ios.mjs +0 -14
- package/lib/services/storage/index.js +0 -26
- package/lib/services/storage/index.mjs +0 -24
- package/lib/services/storage/service-rpc.js +0 -37
- package/lib/services/storage/service-rpc.mjs +0 -33
- package/lib/services/storage/service.js +0 -32
- package/lib/services/storage/service.mjs +0 -27
- package/lib/services/test-utils.js +0 -98
- package/lib/services/test-utils.mjs +0 -84
- package/lib/services/util-crypto/configs.js +0 -23
- package/lib/services/util-crypto/configs.mjs +0 -15
- package/lib/services/util-crypto/index.android.js +0 -19
- package/lib/services/util-crypto/index.android.mjs +0 -15
- package/lib/services/util-crypto/index.ios.js +0 -19
- package/lib/services/util-crypto/index.ios.mjs +0 -15
- package/lib/services/util-crypto/index.js +0 -14
- package/lib/services/util-crypto/index.mjs +0 -6
- package/lib/services/util-crypto/service-rpc.js +0 -42
- package/lib/services/util-crypto/service-rpc.mjs +0 -38
- package/lib/services/util-crypto/service.js +0 -108
- package/lib/services/util-crypto/service.mjs +0 -83
- package/lib/services/wallet/configs.js +0 -32
- package/lib/services/wallet/configs.mjs +0 -23
- package/lib/services/wallet/index.android.js +0 -21
- package/lib/services/wallet/index.android.mjs +0 -17
- package/lib/services/wallet/index.ios.js +0 -21
- package/lib/services/wallet/index.ios.mjs +0 -17
- package/lib/services/wallet/index.js +0 -17
- package/lib/services/wallet/index.mjs +0 -9
- package/lib/services/wallet/service-rpc.js +0 -33
- package/lib/services/wallet/service-rpc.mjs +0 -29
- package/lib/services/wallet/service.js +0 -62
- package/lib/services/wallet/service.mjs +0 -57
- package/lib/setup-nodejs.js +0 -93
- package/lib/setup-nodejs.mjs +0 -91
- package/lib/setup-tests.js +0 -92
- package/lib/setup-tests.mjs +0 -90
- package/lib/src/core/crypto.d.ts +0 -8
- package/lib/src/core/crypto.d.ts.map +0 -1
- package/lib/src/core/format-utils.d.ts +0 -26
- package/lib/src/core/format-utils.d.ts.map +0 -1
- package/lib/src/core/logger.d.ts +0 -3
- package/lib/src/core/logger.d.ts.map +0 -1
- package/lib/src/core/storage.d.ts +0 -8
- package/lib/src/core/storage.d.ts.map +0 -1
- package/lib/src/core/validation.d.ts +0 -6
- package/lib/src/core/validation.d.ts.map +0 -1
- package/lib/src/errors.d.ts +0 -7
- package/lib/src/errors.d.ts.map +0 -1
- package/lib/src/logger.d.ts +0 -5
- package/lib/src/logger.d.ts.map +0 -1
- package/lib/src/modules/event-manager.d.ts +0 -12
- package/lib/src/modules/event-manager.d.ts.map +0 -1
- package/lib/src/modules/network-manager.d.ts +0 -32
- package/lib/src/modules/network-manager.d.ts.map +0 -1
- package/lib/src/rpc-client.d.ts +0 -4
- package/lib/src/rpc-client.d.ts.map +0 -1
- package/lib/src/rpc-util.d.ts +0 -11
- package/lib/src/rpc-util.d.ts.map +0 -1
- package/lib/src/services/blockchain/cached-did-resolver.d.ts +0 -28
- package/lib/src/services/blockchain/cached-did-resolver.d.ts.map +0 -1
- package/lib/src/services/blockchain/cached-did-resolver.test.d.ts +0 -2
- package/lib/src/services/blockchain/cached-did-resolver.test.d.ts.map +0 -1
- package/lib/src/services/blockchain/configs.d.ts +0 -7
- package/lib/src/services/blockchain/configs.d.ts.map +0 -1
- package/lib/src/services/blockchain/service.d.ts +0 -155
- package/lib/src/services/blockchain/service.d.ts.map +0 -1
- package/lib/src/services/credential/bbs-revocation.d.ts +0 -10
- package/lib/src/services/credential/bbs-revocation.d.ts.map +0 -1
- package/lib/src/services/credential/bound-check.d.ts +0 -61
- package/lib/src/services/credential/bound-check.d.ts.map +0 -1
- package/lib/src/services/credential/bound-check.test.d.ts +0 -2
- package/lib/src/services/credential/bound-check.test.d.ts.map +0 -1
- package/lib/src/services/credential/config.d.ts +0 -10
- package/lib/src/services/credential/config.d.ts.map +0 -1
- package/lib/src/services/credential/delegatable-credentials.d.ts +0 -272
- package/lib/src/services/credential/delegatable-credentials.d.ts.map +0 -1
- package/lib/src/services/credential/index.d.ts +0 -35
- package/lib/src/services/credential/index.d.ts.map +0 -1
- package/lib/src/services/credential/pex-helpers.d.ts +0 -23
- package/lib/src/services/credential/pex-helpers.d.ts.map +0 -1
- package/lib/src/services/credential/range-proofs-example.d.ts +0 -2
- package/lib/src/services/credential/range-proofs-example.d.ts.map +0 -1
- package/lib/src/services/credential/sd-jwt.test.d.ts +0 -2
- package/lib/src/services/credential/sd-jwt.test.d.ts.map +0 -1
- package/lib/src/services/credential/service.d.ts +0 -313
- package/lib/src/services/credential/service.d.ts.map +0 -1
- package/lib/src/services/credential/utils.d.ts +0 -3
- package/lib/src/services/credential/utils.d.ts.map +0 -1
- package/lib/src/services/dids/config.d.ts +0 -24
- package/lib/src/services/dids/config.d.ts.map +0 -1
- package/lib/src/services/dids/keypair-utils.d.ts +0 -15
- package/lib/src/services/dids/keypair-utils.d.ts.map +0 -1
- package/lib/src/services/dids/service-rpc.d.ts +0 -11
- package/lib/src/services/dids/service-rpc.d.ts.map +0 -1
- package/lib/src/services/dids/service.d.ts +0 -70
- package/lib/src/services/dids/service.d.ts.map +0 -1
- package/lib/src/services/edv/configs.d.ts +0 -12
- package/lib/src/services/edv/configs.d.ts.map +0 -1
- package/lib/src/services/edv/hmac.d.ts +0 -29
- package/lib/src/services/edv/hmac.d.ts.map +0 -1
- package/lib/src/services/edv/service.d.ts +0 -229
- package/lib/src/services/edv/service.d.ts.map +0 -1
- package/lib/src/services/pex/config.d.ts +0 -21
- package/lib/src/services/pex/config.d.ts.map +0 -1
- package/lib/src/services/pex/service.d.ts +0 -21
- package/lib/src/services/pex/service.d.ts.map +0 -1
- package/lib/src/services/relay-service/configs.d.ts +0 -35
- package/lib/src/services/relay-service/configs.d.ts.map +0 -1
- package/lib/src/services/relay-service/service-rpc.d.ts +0 -12
- package/lib/src/services/relay-service/service-rpc.d.ts.map +0 -1
- package/lib/src/services/relay-service/service.d.ts +0 -159
- package/lib/src/services/relay-service/service.d.ts.map +0 -1
- package/lib/src/services/rpc-service-client.d.ts +0 -7
- package/lib/src/services/rpc-service-client.d.ts.map +0 -1
- package/lib/src/services/storage/configs.d.ts +0 -2
- package/lib/src/services/storage/configs.d.ts.map +0 -1
- package/lib/src/services/storage/index.d.ts +0 -2
- package/lib/src/services/storage/index.d.ts.map +0 -1
- package/lib/src/services/storage/service-rpc.d.ts +0 -9
- package/lib/src/services/storage/service-rpc.d.ts.map +0 -1
- package/lib/src/services/storage/service.d.ts +0 -10
- package/lib/src/services/storage/service.d.ts.map +0 -1
- package/lib/src/services/util-crypto/configs.d.ts +0 -5
- package/lib/src/services/util-crypto/configs.d.ts.map +0 -1
- package/lib/src/services/util-crypto/index.d.ts +0 -2
- package/lib/src/services/util-crypto/index.d.ts.map +0 -1
- package/lib/src/services/util-crypto/service.d.ts +0 -10
- package/lib/src/services/util-crypto/service.d.ts.map +0 -1
- package/lib/src/services/wallet/configs.d.ts +0 -13
- package/lib/src/services/wallet/configs.d.ts.map +0 -1
- package/lib/src/services/wallet/service.d.ts +0 -13
- package/lib/src/services/wallet/service.d.ts.map +0 -1
- package/lib/src/types.d.ts +0 -12
- package/lib/src/types.d.ts.map +0 -1
- package/lib/src/wallet/memory-storage-interface.d.ts +0 -31
- package/lib/src/wallet/memory-storage-interface.d.ts.map +0 -1
- package/lib/src/wallet/memory-storage-wallet.d.ts +0 -6
- package/lib/src/wallet/memory-storage-wallet.d.ts.map +0 -1
- package/lib/src/wallet/rpc-storage-interface.d.ts +0 -32
- package/lib/src/wallet/rpc-storage-interface.d.ts.map +0 -1
- package/lib/src/wallet/rpc-storage-wallet.d.ts +0 -6
- package/lib/src/wallet/rpc-storage-wallet.d.ts.map +0 -1
- package/lib/test-utils.js +0 -46
- package/lib/test-utils.mjs +0 -38
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types.js +0 -7
- package/lib/types.mjs +0 -3
- package/lib/wallet/memory-storage-interface.js +0 -101
- package/lib/wallet/memory-storage-interface.mjs +0 -95
- package/lib/wallet/memory-storage-wallet.js +0 -30
- package/lib/wallet/memory-storage-wallet.mjs +0 -24
- package/lib/wallet/rpc-storage-interface.js +0 -134
- package/lib/wallet/rpc-storage-interface.mjs +0 -128
- package/lib/wallet/rpc-storage-wallet.js +0 -46
- package/lib/wallet/rpc-storage-wallet.mjs +0 -40
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
|
|
2
|
-
import { CheqdAPI } from '@docknetwork/cheqd-blockchain-api';
|
|
3
|
-
import { CheqdCoreModules } from '@docknetwork/cheqd-blockchain-modules';
|
|
4
|
-
import { MultiApiCoreModules } from '@docknetwork/credential-sdk/modules';
|
|
5
|
-
import { UniversalResolver, DIDKeyResolver, CoreResolver, ResolverRouter, WILDCARD } from '@docknetwork/credential-sdk/resolver';
|
|
6
|
-
import { initializeWasm } from '@docknetwork/crypto-wasm-ts/lib/index';
|
|
7
|
-
import { EventEmitter } from 'events';
|
|
8
|
-
import { Logger } from '../../core/logger.mjs';
|
|
9
|
-
import { once } from '../../modules/event-manager.mjs';
|
|
10
|
-
import { utilCryptoService } from '../util-crypto/service.mjs';
|
|
11
|
-
import { AccumulatorPublicKey, AccumulatorId, AccumulatorCommon } from '@docknetwork/credential-sdk/types';
|
|
12
|
-
import { CachedDIDResolver } from './cached-did-resolver.mjs';
|
|
13
|
-
import 'assert';
|
|
14
|
-
import '@docknetwork/credential-sdk/utils';
|
|
15
|
-
import '@scure/bip39';
|
|
16
|
-
import '@scure/bip39/wordlists/english';
|
|
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';
|
|
28
|
-
|
|
29
|
-
// @ts-nocheck
|
|
30
|
-
/**
|
|
31
|
-
* Universal resolver URL for DID resolution fallback
|
|
32
|
-
* @constant {string}
|
|
33
|
-
*/
|
|
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
|
-
*/
|
|
41
|
-
class AnyDIDResolver extends ResolverRouter {
|
|
42
|
-
method = WILDCARD;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
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
|
|
49
|
-
*/
|
|
50
|
-
class BlockchainService {
|
|
51
|
-
dock;
|
|
52
|
-
modules;
|
|
53
|
-
cheqdApi;
|
|
54
|
-
cheqdApiUrl;
|
|
55
|
-
isBlockchainReady = false;
|
|
56
|
-
_resolver;
|
|
57
|
-
get resolver() {
|
|
58
|
-
return this._resolver;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Event names emitted by the blockchain service
|
|
62
|
-
* @static
|
|
63
|
-
* @readonly
|
|
64
|
-
* @property {string} BLOCKCHAIN_READY - Emitted when blockchain connection is established
|
|
65
|
-
*/
|
|
66
|
-
static Events = {
|
|
67
|
-
BLOCKCHAIN_READY: 'blockchain-ready',
|
|
68
|
-
};
|
|
69
|
-
rpcMethods = [
|
|
70
|
-
BlockchainService.prototype.disconnect,
|
|
71
|
-
BlockchainService.prototype.ensureBlockchainReady,
|
|
72
|
-
BlockchainService.prototype.init,
|
|
73
|
-
BlockchainService.prototype.isApiConnected,
|
|
74
|
-
BlockchainService.prototype.getAddress,
|
|
75
|
-
BlockchainService.prototype.resolveDID,
|
|
76
|
-
BlockchainService.prototype.getCachedDIDs,
|
|
77
|
-
BlockchainService.prototype.clearCache,
|
|
78
|
-
BlockchainService.prototype.getCacheEntry,
|
|
79
|
-
];
|
|
80
|
-
/**
|
|
81
|
-
* Creates a new BlockchainService instance
|
|
82
|
-
* @constructor
|
|
83
|
-
*/
|
|
84
|
-
constructor() {
|
|
85
|
-
this.name = 'blockchain';
|
|
86
|
-
this.cheqdApi = new CheqdAPI();
|
|
87
|
-
this.cheqdModules = new CheqdCoreModules(this.cheqdApi);
|
|
88
|
-
this.modules = new MultiApiCoreModules([this.cheqdModules]);
|
|
89
|
-
this.emitter = new EventEmitter();
|
|
90
|
-
// Blockchain is not ready yet, but we can use fallback resolvers
|
|
91
|
-
this._resolver = this.createDIDResolver();
|
|
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
|
-
*/
|
|
102
|
-
getTypesForDIDOrAccumulator(didOrRegistryId) {
|
|
103
|
-
return {
|
|
104
|
-
PublicKey: AccumulatorPublicKey,
|
|
105
|
-
AccumulatorId,
|
|
106
|
-
AccumulatorCommon,
|
|
107
|
-
AccumulatorModule: this.modules.accumulator,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
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
|
|
116
|
-
*/
|
|
117
|
-
async ensureBlockchainReady() {
|
|
118
|
-
if (await this.isApiConnected()) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
return once(this.emitter, BlockchainService.Events.BLOCKCHAIN_READY);
|
|
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
|
-
*/
|
|
151
|
-
createDIDResolver(isBlockchainReady) {
|
|
152
|
-
let resolvers = [
|
|
153
|
-
new UniversalResolver(universalResolverUrl),
|
|
154
|
-
new DIDKeyResolver(),
|
|
155
|
-
];
|
|
156
|
-
// Add blockchain resolvers if the blockchain is ready
|
|
157
|
-
if (isBlockchainReady) {
|
|
158
|
-
resolvers = [
|
|
159
|
-
new CoreResolver(this.modules),
|
|
160
|
-
...resolvers
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
const router = new AnyDIDResolver(resolvers);
|
|
164
|
-
return new CachedDIDResolver(router);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Initializes the blockchain service with connection parameters
|
|
168
|
-
* @param {InitParams} params - Initialization parameters
|
|
169
|
-
* @param {string} params.cheqdApiUrl - URL of the Cheqd API endpoint
|
|
170
|
-
* @param {string} [params.networkId] - Cheqd network identifier
|
|
171
|
-
* @param {string} [params.cheqdMnemonic] - Mnemonic for Cheqd wallet (auto-generated if not provided)
|
|
172
|
-
* @returns {Promise<boolean>} True if initialization successful
|
|
173
|
-
* @throws {Error} If cheqdApiUrl is not provided
|
|
174
|
-
* @example
|
|
175
|
-
* await blockchainService.init({
|
|
176
|
-
* cheqdApiUrl: 'https://api.cheqd.network',
|
|
177
|
-
* networkId: 'mainnet'
|
|
178
|
-
* });
|
|
179
|
-
*/
|
|
180
|
-
async init(params) {
|
|
181
|
-
if (!params?.cheqdApiUrl) {
|
|
182
|
-
throw new Error('cheqdApiUrl is required');
|
|
183
|
-
}
|
|
184
|
-
if (this.cheqdApi && this.cheqdApi.isInitialized()) {
|
|
185
|
-
Logger.info('Disconnecting from cheqd');
|
|
186
|
-
await this.cheqdApi.disconnect();
|
|
187
|
-
}
|
|
188
|
-
this.modules = new MultiApiCoreModules([this.cheqdModules]);
|
|
189
|
-
const checkdApiUrl = params?.cheqdApiUrl;
|
|
190
|
-
const cheqdNetworkId = params?.networkId;
|
|
191
|
-
const cheqdMnemonic = params?.cheqdMnemonic || (await utilCryptoService.mnemonicGenerate(12));
|
|
192
|
-
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(cheqdMnemonic, {
|
|
193
|
-
prefix: 'cheqd',
|
|
194
|
-
});
|
|
195
|
-
const walletAccounts = await wallet.getAccounts();
|
|
196
|
-
const [{ address }] = walletAccounts;
|
|
197
|
-
console.log('Using cheqd account:', address);
|
|
198
|
-
Logger.info(`Attempt to initialized cheqd at: ${checkdApiUrl} with networkId: ${cheqdNetworkId}`);
|
|
199
|
-
Logger.info(`Using cheqd account: ${address}`);
|
|
200
|
-
try {
|
|
201
|
-
await this.cheqdApi.init({
|
|
202
|
-
wallet,
|
|
203
|
-
urls: Array.isArray(checkdApiUrl) ? checkdApiUrl : [checkdApiUrl],
|
|
204
|
-
network: cheqdNetworkId,
|
|
205
|
-
});
|
|
206
|
-
Logger.info(`Cheqd initialized at: ${checkdApiUrl}`);
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
debugger;
|
|
210
|
-
Logger.error(`Failed to initialize cheqd at: ${checkdApiUrl}`, err);
|
|
211
|
-
}
|
|
212
|
-
// Re-create the resolver with the new blockchain connection
|
|
213
|
-
this._resolver = this.createDIDResolver(true);
|
|
214
|
-
if (process.env.NODE_ENV !== 'test' ||
|
|
215
|
-
process.env.API_MOCK_DISABLED === 'true') {
|
|
216
|
-
await initializeWasm();
|
|
217
|
-
}
|
|
218
|
-
this._setBlockchainReady(true);
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Disconnects from the blockchain
|
|
223
|
-
* @returns {Promise<void>} Resolves when disconnection is complete
|
|
224
|
-
* @example
|
|
225
|
-
* await blockchainService.disconnect();
|
|
226
|
-
*/
|
|
227
|
-
async disconnect() {
|
|
228
|
-
let result;
|
|
229
|
-
if (this.cheqdApi && this.cheqdApi.isInitialized()) {
|
|
230
|
-
result = await this.cheqdApi.disconnect();
|
|
231
|
-
}
|
|
232
|
-
this._setBlockchainReady(false);
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Waits for the blockchain to be ready
|
|
237
|
-
* @returns {Promise<void>} Resolves when blockchain is ready
|
|
238
|
-
* @private
|
|
239
|
-
*/
|
|
240
|
-
async waitBlockchainReady() {
|
|
241
|
-
return new Promise(resolve => {
|
|
242
|
-
if (this.isBlockchainReady) {
|
|
243
|
-
resolve();
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
this.emitter.once(BlockchainService.Events.BLOCKCHAIN_READY, resolve);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Resolves a DID to its document
|
|
252
|
-
* @param {string} did - The DID to resolve
|
|
253
|
-
* @returns {Promise<Object>} The resolved DID document
|
|
254
|
-
* @example
|
|
255
|
-
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
256
|
-
*/
|
|
257
|
-
async resolveDID(did) {
|
|
258
|
-
return this.resolver.resolve(did);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Checks if the blockchain API is connected
|
|
262
|
-
* @returns {Promise<boolean>} True if connected, false otherwise
|
|
263
|
-
* @example
|
|
264
|
-
* const isConnected = await blockchainService.isApiConnected();
|
|
265
|
-
*/
|
|
266
|
-
async isApiConnected() {
|
|
267
|
-
return this.cheqdApi.isInitialized();
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Gets the current Cheqd API URL
|
|
271
|
-
* @returns {Promise<string>} The Cheqd API URL
|
|
272
|
-
* @example
|
|
273
|
-
* const apiUrl = await blockchainService.getAddress();
|
|
274
|
-
*/
|
|
275
|
-
async getAddress() {
|
|
276
|
-
return this.cheqdApiUrl;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Sets the blockchain ready state and emits events
|
|
280
|
-
* @private
|
|
281
|
-
* @param {boolean} isBlockchainReady - Whether blockchain is ready
|
|
282
|
-
*/
|
|
283
|
-
_setBlockchainReady(isBlockchainReady) {
|
|
284
|
-
this.isBlockchainReady = isBlockchainReady;
|
|
285
|
-
if (isBlockchainReady) {
|
|
286
|
-
this.emitter.emit(BlockchainService.Events.BLOCKCHAIN_READY);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Singleton instance of the blockchain service
|
|
292
|
-
* @type {BlockchainService}
|
|
293
|
-
* @example
|
|
294
|
-
* import { blockchainService } from '@docknetwork/wallet-sdk-wasm/services/blockchain';
|
|
295
|
-
*
|
|
296
|
-
* // Initialize the service
|
|
297
|
-
* await blockchainService.init({
|
|
298
|
-
* cheqdApiUrl: 'https://api.cheqd.network'
|
|
299
|
-
* });
|
|
300
|
-
*
|
|
301
|
-
* // Resolve a DID
|
|
302
|
-
* const didDoc = await blockchainService.resolveDID('did:key:z6Mk...');
|
|
303
|
-
*/
|
|
304
|
-
const blockchainService = new BlockchainService();
|
|
305
|
-
|
|
306
|
-
export { BlockchainService, blockchainService, universalResolverUrl };
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var cryptoWasmTs = require('@docknetwork/crypto-wasm-ts');
|
|
6
|
-
var utils = require('@docknetwork/credential-sdk/utils');
|
|
7
|
-
var services_blockchain_service = require('../blockchain/service.js');
|
|
8
|
-
require('@cosmjs/proto-signing');
|
|
9
|
-
require('@docknetwork/cheqd-blockchain-api');
|
|
10
|
-
require('@docknetwork/cheqd-blockchain-modules');
|
|
11
|
-
require('@docknetwork/credential-sdk/modules');
|
|
12
|
-
require('@docknetwork/credential-sdk/resolver');
|
|
13
|
-
require('@docknetwork/crypto-wasm-ts/lib/index');
|
|
14
|
-
require('events');
|
|
15
|
-
require('../../core/logger.js');
|
|
16
|
-
require('../../modules/event-manager.js');
|
|
17
|
-
require('assert');
|
|
18
|
-
require('../util-crypto/service.js');
|
|
19
|
-
require('@scure/bip39');
|
|
20
|
-
require('@scure/bip39/wordlists/english');
|
|
21
|
-
require('../util-crypto/configs.js');
|
|
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');
|
|
34
|
-
|
|
35
|
-
const getWitnessDetails = async (credential, _membershipWitness) => {
|
|
36
|
-
let witness = _membershipWitness;
|
|
37
|
-
let blockNo;
|
|
38
|
-
try {
|
|
39
|
-
({ witness, blockNo } = JSON.parse(_membershipWitness));
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
console.error(err);
|
|
43
|
-
}
|
|
44
|
-
const { credentialStatus } = credential;
|
|
45
|
-
const registryId = credentialStatus?.id;
|
|
46
|
-
const revocationIndex = credentialStatus.revocationId;
|
|
47
|
-
const queriedAccumulator = await services_blockchain_service.blockchainService.modules.accumulator.getAccumulator(registryId, false);
|
|
48
|
-
if (!queriedAccumulator) {
|
|
49
|
-
throw new Error('Accumulator not found');
|
|
50
|
-
}
|
|
51
|
-
const accumulator = cryptoWasmTs.PositiveAccumulator.fromAccumulated(queriedAccumulator.accumulated.bytes);
|
|
52
|
-
const encodedRevId = cryptoWasmTs.Encoder.defaultEncodeFunc()(revocationIndex.toString());
|
|
53
|
-
const publicKey = await services_blockchain_service.blockchainService.modules.accumulator.getPublicKey(queriedAccumulator.keyRef[0], queriedAccumulator.keyRef[1]);
|
|
54
|
-
const params = cryptoWasmTs.dockAccumulatorParams();
|
|
55
|
-
const pk = new cryptoWasmTs.AccumulatorPublicKey(publicKey.bytes);
|
|
56
|
-
const membershipWitness = new cryptoWasmTs.VBMembershipWitness(utils.hexToU8a(witness));
|
|
57
|
-
try {
|
|
58
|
-
const credentialStatusId = credential.credentialStatus.id;
|
|
59
|
-
const accumulatorId = services_blockchain_service.blockchainService
|
|
60
|
-
.getTypesForDIDOrAccumulator(credentialStatusId)
|
|
61
|
-
.AccumulatorId.from(credentialStatusId);
|
|
62
|
-
const history = await services_blockchain_service.blockchainService.modules.accumulator.accumulatorHistory(accumulatorId);
|
|
63
|
-
const blockNoIndex = history.updates.findIndex(update => update.id.toString() === blockNo);
|
|
64
|
-
const nextBlockNo = history.updates[blockNoIndex + 1]?.id?.toString();
|
|
65
|
-
if (nextBlockNo) {
|
|
66
|
-
await services_blockchain_service.blockchainService.modules.accumulator.updateWitness(registryId, encodedRevId, membershipWitness, nextBlockNo, queriedAccumulator.lastModified);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
console.error(err);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
encodedRevId,
|
|
74
|
-
membershipWitness,
|
|
75
|
-
pk,
|
|
76
|
-
params,
|
|
77
|
-
accumulator,
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
const getIsRevoked = async (credential, _membershipWitness) => {
|
|
81
|
-
const { encodedRevId, membershipWitness, pk, params, accumulator } = await getWitnessDetails(credential, _membershipWitness);
|
|
82
|
-
try {
|
|
83
|
-
return !accumulator.verifyMembershipWitness(encodedRevId, membershipWitness, pk, params);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
console.error(err);
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
exports.getIsRevoked = getIsRevoked;
|
|
92
|
-
exports.getWitnessDetails = getWitnessDetails;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { PositiveAccumulator, Encoder, dockAccumulatorParams, AccumulatorPublicKey, VBMembershipWitness } from '@docknetwork/crypto-wasm-ts';
|
|
2
|
-
import { hexToU8a } from '@docknetwork/credential-sdk/utils';
|
|
3
|
-
import { blockchainService } from '../blockchain/service.mjs';
|
|
4
|
-
import '@cosmjs/proto-signing';
|
|
5
|
-
import '@docknetwork/cheqd-blockchain-api';
|
|
6
|
-
import '@docknetwork/cheqd-blockchain-modules';
|
|
7
|
-
import '@docknetwork/credential-sdk/modules';
|
|
8
|
-
import '@docknetwork/credential-sdk/resolver';
|
|
9
|
-
import '@docknetwork/crypto-wasm-ts/lib/index';
|
|
10
|
-
import 'events';
|
|
11
|
-
import '../../core/logger.mjs';
|
|
12
|
-
import '../../modules/event-manager.mjs';
|
|
13
|
-
import 'assert';
|
|
14
|
-
import '../util-crypto/service.mjs';
|
|
15
|
-
import '@scure/bip39';
|
|
16
|
-
import '@scure/bip39/wordlists/english';
|
|
17
|
-
import '../util-crypto/configs.mjs';
|
|
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';
|
|
30
|
-
|
|
31
|
-
const getWitnessDetails = async (credential, _membershipWitness) => {
|
|
32
|
-
let witness = _membershipWitness;
|
|
33
|
-
let blockNo;
|
|
34
|
-
try {
|
|
35
|
-
({ witness, blockNo } = JSON.parse(_membershipWitness));
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
console.error(err);
|
|
39
|
-
}
|
|
40
|
-
const { credentialStatus } = credential;
|
|
41
|
-
const registryId = credentialStatus?.id;
|
|
42
|
-
const revocationIndex = credentialStatus.revocationId;
|
|
43
|
-
const queriedAccumulator = await blockchainService.modules.accumulator.getAccumulator(registryId, false);
|
|
44
|
-
if (!queriedAccumulator) {
|
|
45
|
-
throw new Error('Accumulator not found');
|
|
46
|
-
}
|
|
47
|
-
const accumulator = PositiveAccumulator.fromAccumulated(queriedAccumulator.accumulated.bytes);
|
|
48
|
-
const encodedRevId = Encoder.defaultEncodeFunc()(revocationIndex.toString());
|
|
49
|
-
const publicKey = await blockchainService.modules.accumulator.getPublicKey(queriedAccumulator.keyRef[0], queriedAccumulator.keyRef[1]);
|
|
50
|
-
const params = dockAccumulatorParams();
|
|
51
|
-
const pk = new AccumulatorPublicKey(publicKey.bytes);
|
|
52
|
-
const membershipWitness = new VBMembershipWitness(hexToU8a(witness));
|
|
53
|
-
try {
|
|
54
|
-
const credentialStatusId = credential.credentialStatus.id;
|
|
55
|
-
const accumulatorId = blockchainService
|
|
56
|
-
.getTypesForDIDOrAccumulator(credentialStatusId)
|
|
57
|
-
.AccumulatorId.from(credentialStatusId);
|
|
58
|
-
const history = await blockchainService.modules.accumulator.accumulatorHistory(accumulatorId);
|
|
59
|
-
const blockNoIndex = history.updates.findIndex(update => update.id.toString() === blockNo);
|
|
60
|
-
const nextBlockNo = history.updates[blockNoIndex + 1]?.id?.toString();
|
|
61
|
-
if (nextBlockNo) {
|
|
62
|
-
await blockchainService.modules.accumulator.updateWitness(registryId, encodedRevId, membershipWitness, nextBlockNo, queriedAccumulator.lastModified);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
console.error(err);
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
encodedRevId,
|
|
70
|
-
membershipWitness,
|
|
71
|
-
pk,
|
|
72
|
-
params,
|
|
73
|
-
accumulator,
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
const getIsRevoked = async (credential, _membershipWitness) => {
|
|
77
|
-
const { encodedRevId, membershipWitness, pk, params, accumulator } = await getWitnessDetails(credential, _membershipWitness);
|
|
78
|
-
try {
|
|
79
|
-
return !accumulator.verifyMembershipWitness(encodedRevId, membershipWitness, pk, params);
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
console.error(err);
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export { getIsRevoked, getWitnessDetails };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var legosnark = require('@docknetwork/crypto-wasm-ts/lib/legosnark');
|
|
6
|
-
var base64url = require('base64url');
|
|
7
|
-
var services_credential_pexHelpers = require('./pex-helpers.js');
|
|
8
|
-
var services_utilCrypto_service = require('../util-crypto/service.js');
|
|
9
|
-
require('@astronautlabs/jsonpath');
|
|
10
|
-
require('@docknetwork/credential-sdk/utils');
|
|
11
|
-
require('@scure/bip39');
|
|
12
|
-
require('@scure/bip39/wordlists/english');
|
|
13
|
-
require('../util-crypto/configs.js');
|
|
14
|
-
require('assert');
|
|
15
|
-
|
|
16
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
-
|
|
18
|
-
var base64url__default = /*#__PURE__*/_interopDefaultLegacy(base64url);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Receive a presentation builder and a proof request template
|
|
22
|
-
* Convert the proof request template into enforce bound calls on the presentation builder
|
|
23
|
-
* @param param0
|
|
24
|
-
*/
|
|
25
|
-
function applyEnforceBounds({ builder, proofRequest, provingKeyId, provingKey, selectedCredentials, }) {
|
|
26
|
-
const descriptorBounds = services_credential_pexHelpers.pexToBounds(proofRequest.request, selectedCredentials);
|
|
27
|
-
let skipProvingKey = false;
|
|
28
|
-
descriptorBounds.forEach((items, credentialIdx) => {
|
|
29
|
-
if (!selectedCredentials[credentialIdx]) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
items.forEach((bound) => {
|
|
33
|
-
builder.enforceBounds(credentialIdx, bound.attributeName, bound.min, bound.max, provingKeyId, skipProvingKey ? undefined : provingKey);
|
|
34
|
-
skipProvingKey = true;
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return descriptorBounds;
|
|
38
|
-
}
|
|
39
|
-
async function fetchBlobFromUrl(url) {
|
|
40
|
-
try {
|
|
41
|
-
const response = await fetch(url);
|
|
42
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
43
|
-
return new Uint8Array(arrayBuffer);
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
throw new Error(`Error fetching proving key: ${err.message}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function blobFromBase64(base64String) {
|
|
50
|
-
const cleanedBase64 = base64String.replace(/^data:application\/octet-stream;base64,/, '');
|
|
51
|
-
return new Uint8Array(base64url__default["default"].toBuffer(cleanedBase64));
|
|
52
|
-
}
|
|
53
|
-
async function isBase64OrDataUrl(str) {
|
|
54
|
-
return ((await services_utilCrypto_service.utilCryptoService.isBase64(str)) ||
|
|
55
|
-
str.indexOf('data:application/octet-stream') > -1);
|
|
56
|
-
}
|
|
57
|
-
async function fetchProvingKey(proofRequest) {
|
|
58
|
-
let blob;
|
|
59
|
-
if (await isBase64OrDataUrl(proofRequest.boundCheckSnarkKey)) {
|
|
60
|
-
console.log('Is base64');
|
|
61
|
-
blob = blobFromBase64(proofRequest.boundCheckSnarkKey);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
console.log('is not base64');
|
|
65
|
-
blob = await fetchBlobFromUrl(proofRequest.boundCheckSnarkKey);
|
|
66
|
-
}
|
|
67
|
-
const provingKey = new legosnark.LegoProvingKey(blob);
|
|
68
|
-
return { provingKey, provingKeyId: 'key0' };
|
|
69
|
-
}
|
|
70
|
-
const hasProvingKey = (proofRequest) => !!proofRequest.boundCheckSnarkKey;
|
|
71
|
-
|
|
72
|
-
exports.applyEnforceBounds = applyEnforceBounds;
|
|
73
|
-
exports.blobFromBase64 = blobFromBase64;
|
|
74
|
-
exports.fetchBlobFromUrl = fetchBlobFromUrl;
|
|
75
|
-
exports.fetchProvingKey = fetchProvingKey;
|
|
76
|
-
exports.hasProvingKey = hasProvingKey;
|
|
77
|
-
exports.isBase64OrDataUrl = isBase64OrDataUrl;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { LegoProvingKey } from '@docknetwork/crypto-wasm-ts/lib/legosnark';
|
|
2
|
-
import base64url from 'base64url';
|
|
3
|
-
import { pexToBounds } from './pex-helpers.mjs';
|
|
4
|
-
import { utilCryptoService } from '../util-crypto/service.mjs';
|
|
5
|
-
import '@astronautlabs/jsonpath';
|
|
6
|
-
import '@docknetwork/credential-sdk/utils';
|
|
7
|
-
import '@scure/bip39';
|
|
8
|
-
import '@scure/bip39/wordlists/english';
|
|
9
|
-
import '../util-crypto/configs.mjs';
|
|
10
|
-
import 'assert';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Receive a presentation builder and a proof request template
|
|
14
|
-
* Convert the proof request template into enforce bound calls on the presentation builder
|
|
15
|
-
* @param param0
|
|
16
|
-
*/
|
|
17
|
-
function applyEnforceBounds({ builder, proofRequest, provingKeyId, provingKey, selectedCredentials, }) {
|
|
18
|
-
const descriptorBounds = pexToBounds(proofRequest.request, selectedCredentials);
|
|
19
|
-
let skipProvingKey = false;
|
|
20
|
-
descriptorBounds.forEach((items, credentialIdx) => {
|
|
21
|
-
if (!selectedCredentials[credentialIdx]) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
items.forEach((bound) => {
|
|
25
|
-
builder.enforceBounds(credentialIdx, bound.attributeName, bound.min, bound.max, provingKeyId, skipProvingKey ? undefined : provingKey);
|
|
26
|
-
skipProvingKey = true;
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
return descriptorBounds;
|
|
30
|
-
}
|
|
31
|
-
async function fetchBlobFromUrl(url) {
|
|
32
|
-
try {
|
|
33
|
-
const response = await fetch(url);
|
|
34
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
35
|
-
return new Uint8Array(arrayBuffer);
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
throw new Error(`Error fetching proving key: ${err.message}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function blobFromBase64(base64String) {
|
|
42
|
-
const cleanedBase64 = base64String.replace(/^data:application\/octet-stream;base64,/, '');
|
|
43
|
-
return new Uint8Array(base64url.toBuffer(cleanedBase64));
|
|
44
|
-
}
|
|
45
|
-
async function isBase64OrDataUrl(str) {
|
|
46
|
-
return ((await utilCryptoService.isBase64(str)) ||
|
|
47
|
-
str.indexOf('data:application/octet-stream') > -1);
|
|
48
|
-
}
|
|
49
|
-
async function fetchProvingKey(proofRequest) {
|
|
50
|
-
let blob;
|
|
51
|
-
if (await isBase64OrDataUrl(proofRequest.boundCheckSnarkKey)) {
|
|
52
|
-
console.log('Is base64');
|
|
53
|
-
blob = blobFromBase64(proofRequest.boundCheckSnarkKey);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
console.log('is not base64');
|
|
57
|
-
blob = await fetchBlobFromUrl(proofRequest.boundCheckSnarkKey);
|
|
58
|
-
}
|
|
59
|
-
const provingKey = new LegoProvingKey(blob);
|
|
60
|
-
return { provingKey, provingKeyId: 'key0' };
|
|
61
|
-
}
|
|
62
|
-
const hasProvingKey = (proofRequest) => !!proofRequest.boundCheckSnarkKey;
|
|
63
|
-
|
|
64
|
-
export { applyEnforceBounds, blobFromBase64, fetchBlobFromUrl, fetchProvingKey, hasProvingKey, isBase64OrDataUrl };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var assert = require('assert');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
|
|
10
|
-
|
|
11
|
-
// @ts-nocheck
|
|
12
|
-
const serviceName = 'credentials';
|
|
13
|
-
const validation = {
|
|
14
|
-
generateCredential: params => {
|
|
15
|
-
const { subject } = params;
|
|
16
|
-
if (subject) {
|
|
17
|
-
assert__default["default"](typeof subject === 'object', 'invalid subject');
|
|
18
|
-
assert__default["default"](Object.keys(subject).length > 0, 'invalid subject');
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
verifyCredential: params => {
|
|
22
|
-
const { credential } = params;
|
|
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
|
-
}
|
|
27
|
-
},
|
|
28
|
-
createBBSPresentation: params => {
|
|
29
|
-
const { credentials } = params;
|
|
30
|
-
assert__default["default"](Array.isArray(credentials), 'invalid credentials');
|
|
31
|
-
assert__default["default"](credentials.length > 0, 'no credential found');
|
|
32
|
-
},
|
|
33
|
-
deriveVCFromPresentation: params => {
|
|
34
|
-
const { credentials } = params;
|
|
35
|
-
assert__default["default"](Array.isArray(credentials), 'invalid credentials');
|
|
36
|
-
assert__default["default"](credentials.length > 0, 'no credential found');
|
|
37
|
-
},
|
|
38
|
-
signCredential: params => {
|
|
39
|
-
const { vcJson, keyDoc } = params;
|
|
40
|
-
assert__default["default"](typeof vcJson === 'object', 'invalid vcJson');
|
|
41
|
-
assert__default["default"](typeof keyDoc === 'object', 'invalid keyDoc');
|
|
42
|
-
assert__default["default"](typeof keyDoc.publicKeyBase58 === 'string', 'publicKeyBase58 is not present');
|
|
43
|
-
},
|
|
44
|
-
createPresentation: params => {
|
|
45
|
-
const { credentials, keyDoc, challenge, id } = params;
|
|
46
|
-
assert__default["default"](typeof id === 'string', 'invalid id');
|
|
47
|
-
assert__default["default"](typeof keyDoc === 'object', 'invalid KeyDoc');
|
|
48
|
-
assert__default["default"](typeof challenge === 'string', 'invalid challenge');
|
|
49
|
-
assert__default["default"](Array.isArray(credentials), 'invalid credentials');
|
|
50
|
-
assert__default["default"](credentials.length > 0, 'no credential found');
|
|
51
|
-
assert__default["default"](typeof keyDoc.publicKeyBase58 === 'string', 'publicKeyBase58 is not present');
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
exports.serviceName = serviceName;
|
|
56
|
-
exports.validation = validation;
|