@docknetwork/wallet-sdk-wasm 1.5.9 → 1.5.11
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/lib/core/format-utils.js +0 -28
- package/lib/core/format-utils.mjs +1 -24
- package/lib/core/validation.js +1 -24
- package/lib/core/validation.mjs +2 -21
- package/lib/index.js +13 -23
- package/lib/index.mjs +13 -23
- package/lib/rpc-server.js +13 -23
- package/lib/rpc-server.mjs +13 -23
- package/lib/rpc-util.js +14 -0
- package/lib/rpc-util.mjs +14 -0
- package/lib/services/blockchain/index.js +3 -6
- package/lib/services/blockchain/index.mjs +3 -6
- package/lib/services/blockchain/service.js +5 -9
- package/lib/services/blockchain/service.mjs +5 -9
- package/lib/services/credential/bbs-revocation.js +4 -7
- package/lib/services/credential/bbs-revocation.mjs +3 -6
- package/lib/services/credential/bound-check.js +9 -4
- package/lib/services/credential/bound-check.mjs +9 -4
- package/lib/services/credential/index.js +11 -13
- package/lib/services/credential/index.mjs +11 -13
- package/lib/services/credential/service.js +18 -18
- package/lib/services/credential/service.mjs +15 -15
- package/lib/services/credential/utils.js +59 -28
- package/lib/services/credential/utils.mjs +62 -32
- package/lib/services/dids/index.js +7 -25
- package/lib/services/dids/index.mjs +7 -25
- package/lib/services/dids/keypair-utils.js +142 -0
- package/lib/services/dids/keypair-utils.mjs +113 -0
- package/lib/services/dids/service-rpc.js +0 -3
- package/lib/services/dids/service-rpc.mjs +0 -3
- package/lib/services/dids/service.js +13 -55
- package/lib/services/dids/service.mjs +13 -54
- package/lib/services/edv/index.js +4 -25
- package/lib/services/edv/index.mjs +4 -25
- package/lib/services/edv/service.js +6 -33
- package/lib/services/edv/service.mjs +6 -33
- package/lib/services/index.js +13 -25
- package/lib/services/index.mjs +13 -25
- package/lib/services/relay-service/configs.js +0 -1
- package/lib/services/relay-service/configs.mjs +0 -1
- package/lib/services/relay-service/index.android.js +0 -1
- package/lib/services/relay-service/index.android.mjs +0 -1
- package/lib/services/relay-service/index.ios.js +0 -1
- package/lib/services/relay-service/index.ios.mjs +0 -1
- package/lib/services/relay-service/index.js +0 -1
- package/lib/services/relay-service/index.mjs +0 -1
- package/lib/services/relay-service/service-rpc.js +0 -1
- package/lib/services/relay-service/service-rpc.mjs +0 -1
- package/lib/services/relay-service/service.js +0 -1
- package/lib/services/relay-service/service.mjs +0 -1
- package/lib/services/test-utils.js +0 -44
- package/lib/services/test-utils.mjs +1 -44
- package/lib/services/util-crypto/configs.js +0 -12
- package/lib/services/util-crypto/configs.mjs +0 -12
- package/lib/services/util-crypto/index.android.js +0 -3
- package/lib/services/util-crypto/index.android.mjs +0 -3
- package/lib/services/util-crypto/index.ios.js +0 -3
- package/lib/services/util-crypto/index.ios.mjs +0 -3
- package/lib/services/util-crypto/index.js +4 -7
- package/lib/services/util-crypto/index.mjs +4 -7
- package/lib/services/util-crypto/service-rpc.js +2 -30
- package/lib/services/util-crypto/service-rpc.mjs +2 -30
- package/lib/services/util-crypto/service.js +68 -61
- package/lib/services/util-crypto/service.mjs +50 -59
- package/lib/services/wallet/configs.js +0 -63
- package/lib/services/wallet/configs.mjs +1 -64
- package/lib/services/wallet/index.android.js +0 -1
- package/lib/services/wallet/index.android.mjs +0 -1
- package/lib/services/wallet/index.ios.js +0 -1
- package/lib/services/wallet/index.ios.mjs +0 -1
- package/lib/services/wallet/index.js +2 -12
- package/lib/services/wallet/index.mjs +2 -12
- package/lib/services/wallet/service-rpc.js +0 -77
- package/lib/services/wallet/service-rpc.mjs +0 -77
- package/lib/services/wallet/service.js +1 -215
- package/lib/services/wallet/service.mjs +1 -211
- package/lib/setup-nodejs.js +13 -23
- package/lib/setup-nodejs.mjs +13 -23
- package/lib/setup-tests.js +13 -23
- package/lib/setup-tests.mjs +13 -23
- package/lib/src/core/format-utils.d.ts +0 -5
- package/lib/src/core/format-utils.d.ts.map +1 -1
- package/lib/src/core/validation.d.ts +0 -3
- package/lib/src/core/validation.d.ts.map +1 -1
- package/lib/src/rpc-util.d.ts.map +1 -1
- package/lib/src/services/blockchain/service.d.ts.map +1 -1
- package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
- package/lib/src/services/credential/bound-check.d.ts +1 -1
- package/lib/src/services/credential/bound-check.d.ts.map +1 -1
- package/lib/src/services/credential/service.d.ts.map +1 -1
- package/lib/src/services/credential/utils.d.ts +2 -1
- package/lib/src/services/credential/utils.d.ts.map +1 -1
- package/lib/src/services/dids/keypair-utils.d.ts +15 -0
- package/lib/src/services/dids/keypair-utils.d.ts.map +1 -0
- package/lib/src/services/dids/service-rpc.d.ts +0 -1
- package/lib/src/services/dids/service-rpc.d.ts.map +1 -1
- package/lib/src/services/dids/service.d.ts +11 -8
- package/lib/src/services/dids/service.d.ts.map +1 -1
- package/lib/src/services/edv/service.d.ts.map +1 -1
- package/lib/src/services/util-crypto/configs.d.ts +0 -3
- package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
- package/lib/src/services/util-crypto/service.d.ts +3 -8
- package/lib/src/services/util-crypto/service.d.ts.map +1 -1
- package/lib/src/services/wallet/configs.d.ts +13 -0
- package/lib/src/services/wallet/configs.d.ts.map +1 -0
- package/lib/src/services/wallet/service.d.ts +1 -44
- package/lib/src/services/wallet/service.d.ts.map +1 -1
- package/lib/test-utils.js +0 -4
- package/lib/test-utils.mjs +1 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -25
- package/readme.md +0 -61
- package/src/core/format-utils.test.js +1 -28
- package/src/core/format-utils.ts +0 -33
- package/src/core/validation.test.js +1 -33
- package/src/core/validation.ts +1 -25
- package/src/rpc-server.test.js +2 -9
- package/src/rpc-util.js +14 -0
- package/src/services/blockchain/service.ts +2 -3
- package/src/services/credential/bbs-revocation.ts +2 -1
- package/src/services/credential/bound-check.test.ts +6 -6
- package/src/services/credential/bound-check.ts +4 -4
- package/src/services/credential/index.test.js +0 -2
- package/src/services/credential/service.ts +5 -2
- package/src/services/credential/utils.js +65 -23
- package/src/services/dids/index.test.js +45 -33
- package/src/services/dids/keypair-utils.js +111 -0
- package/src/services/dids/service-rpc.ts +0 -3
- package/src/services/dids/service.ts +7 -34
- package/src/services/edv/service.ts +2 -9
- package/src/services/index.js +0 -4
- package/src/services/test-utils.js +0 -29
- package/src/services/util-crypto/configs.ts +0 -12
- package/src/services/util-crypto/index.test.js +6 -83
- package/src/services/util-crypto/service-rpc.js +2 -27
- package/src/services/util-crypto/service.ts +62 -75
- package/src/services/wallet/configs.ts +1 -113
- package/src/services/wallet/index.test.js +0 -159
- package/src/services/wallet/service-rpc.js +1 -88
- package/src/services/wallet/service.ts +0 -258
- package/src/test-utils.js +0 -13
- package/lib/account-357ab05d.js +0 -742
- package/lib/account-399e6053.js +0 -752
- package/lib/core/polkadot-utils.js +0 -119
- package/lib/core/polkadot-utils.mjs +0 -94
- package/lib/core/realm-schemas.js +0 -50
- package/lib/core/realm-schemas.mjs +0 -44
- package/lib/core/subscan.js +0 -75
- package/lib/core/subscan.mjs +0 -64
- package/lib/fixtures.js +0 -56
- package/lib/fixtures.mjs +0 -52
- package/lib/modules/account.js +0 -48
- package/lib/modules/account.mjs +0 -40
- package/lib/modules/accounts.js +0 -49
- package/lib/modules/accounts.mjs +0 -40
- package/lib/modules/data-migration.js +0 -72
- package/lib/modules/data-migration.mjs +0 -68
- package/lib/modules/wallet-backup.js +0 -82
- package/lib/modules/wallet-backup.mjs +0 -71
- package/lib/modules/wallet.js +0 -49
- package/lib/modules/wallet.mjs +0 -40
- package/lib/services/example/configs.js +0 -21
- package/lib/services/example/configs.mjs +0 -13
- package/lib/services/example/index.js +0 -18
- package/lib/services/example/index.mjs +0 -14
- package/lib/services/example/service-rpc.js +0 -25
- package/lib/services/example/service-rpc.mjs +0 -21
- package/lib/services/example/service.js +0 -25
- package/lib/services/example/service.mjs +0 -20
- package/lib/services/keyring/configs.js +0 -70
- package/lib/services/keyring/configs.mjs +0 -61
- package/lib/services/keyring/index.android.js +0 -22
- package/lib/services/keyring/index.android.mjs +0 -18
- package/lib/services/keyring/index.ios.js +0 -22
- package/lib/services/keyring/index.ios.mjs +0 -18
- package/lib/services/keyring/index.js +0 -16
- package/lib/services/keyring/index.mjs +0 -8
- package/lib/services/keyring/service-rpc.js +0 -65
- package/lib/services/keyring/service-rpc.mjs +0 -61
- package/lib/services/keyring/service.js +0 -84
- package/lib/services/keyring/service.mjs +0 -74
- package/lib/services/polkadot/configs.js +0 -17
- package/lib/services/polkadot/configs.mjs +0 -13
- package/lib/services/polkadot/index.android.js +0 -22
- package/lib/services/polkadot/index.android.mjs +0 -18
- package/lib/services/polkadot/index.ios.js +0 -22
- package/lib/services/polkadot/index.ios.mjs +0 -18
- package/lib/services/polkadot/index.js +0 -15
- package/lib/services/polkadot/index.mjs +0 -7
- package/lib/services/polkadot/service-rpc.js +0 -30
- package/lib/services/polkadot/service-rpc.mjs +0 -26
- package/lib/services/polkadot/service.js +0 -28
- package/lib/services/polkadot/service.mjs +0 -23
- package/lib/src/core/polkadot-utils.d.ts +0 -11
- package/lib/src/core/polkadot-utils.d.ts.map +0 -1
- package/lib/src/modules/account.d.ts +0 -60
- package/lib/src/modules/account.d.ts.map +0 -1
- package/lib/src/modules/accounts.d.ts +0 -48
- package/lib/src/modules/accounts.d.ts.map +0 -1
- package/lib/src/modules/data-migration.d.ts +0 -7
- package/lib/src/modules/data-migration.d.ts.map +0 -1
- package/lib/src/modules/wallet-backup.d.ts +0 -12
- package/lib/src/modules/wallet-backup.d.ts.map +0 -1
- package/lib/src/modules/wallet.d.ts +0 -134
- package/lib/src/modules/wallet.d.ts.map +0 -1
- package/lib/src/services/blockchain/index.d.ts +0 -2
- package/lib/src/services/blockchain/index.d.ts.map +0 -1
- package/lib/src/services/example/configs.d.ts +0 -9
- package/lib/src/services/example/configs.d.ts.map +0 -1
- package/lib/src/services/example/service.d.ts +0 -8
- package/lib/src/services/example/service.d.ts.map +0 -1
- package/lib/src/services/keyring/configs.d.ts +0 -39
- package/lib/src/services/keyring/configs.d.ts.map +0 -1
- package/lib/src/services/keyring/index.d.ts +0 -2
- package/lib/src/services/keyring/index.d.ts.map +0 -1
- package/lib/src/services/polkadot/configs.d.ts +0 -8
- package/lib/src/services/polkadot/configs.d.ts.map +0 -1
- package/lib/src/services/polkadot/index.d.ts +0 -2
- package/lib/src/services/polkadot/index.d.ts.map +0 -1
- package/lib/src/services/polkadot/service.d.ts +0 -8
- package/lib/src/services/polkadot/service.d.ts.map +0 -1
- package/lib/src/services/wallet/index.d.ts +0 -2
- package/lib/src/services/wallet/index.d.ts.map +0 -1
- package/lib/test/axiosMocks.js +0 -431
- package/lib/test/axiosMocks.mjs +0 -420
- package/lib/test/setup-test-state.js +0 -81
- package/lib/test/setup-test-state.mjs +0 -73
- package/src/core/polkadot-utils.js +0 -99
- package/src/core/realm-schemas.js +0 -42
- package/src/core/subscan.js +0 -62
- package/src/core/subscan.test.js +0 -56
- package/src/fixtures.js +0 -43
- package/src/modules/account.test.js +0 -56
- package/src/modules/account.ts +0 -128
- package/src/modules/accounts.test.js +0 -63
- package/src/modules/accounts.ts +0 -231
- package/src/modules/data-migration.test.js +0 -61
- package/src/modules/data-migration.ts +0 -86
- package/src/modules/wallet-backup.test.js +0 -24
- package/src/modules/wallet-backup.ts +0 -68
- package/src/modules/wallet.test.js +0 -216
- package/src/modules/wallet.ts +0 -424
- package/src/services/example/configs.js +0 -14
- package/src/services/example/index.js +0 -3
- package/src/services/example/index.test.js +0 -28
- package/src/services/example/service-rpc.js +0 -11
- package/src/services/example/service.ts +0 -18
- package/src/services/keyring/configs.ts +0 -110
- package/src/services/keyring/index.android.js +0 -3
- package/src/services/keyring/index.ios.js +0 -3
- package/src/services/keyring/index.js +0 -1
- package/src/services/keyring/index.test.js +0 -48
- package/src/services/keyring/service-rpc.js +0 -56
- package/src/services/keyring/service.ts +0 -111
- package/src/services/polkadot/configs.ts +0 -13
- package/src/services/polkadot/index.android.js +0 -3
- package/src/services/polkadot/index.ios.js +0 -3
- package/src/services/polkadot/index.js +0 -1
- package/src/services/polkadot/index.test.js +0 -52
- package/src/services/polkadot/service-rpc.js +0 -13
- package/src/services/polkadot/service.ts +0 -21
- package/src/test/axiosMocks.js +0 -20
- package/src/test/fixtures/subscan-failure.json +0 -5
- package/src/test/fixtures/subscan-success.json +0 -370
- package/src/test/fixtures/subscan-too-many-requests.json +0 -9
- package/src/test/setup-test-state.js +0 -35
- package/src/test/test-wallet.test.js +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docknetwork/wallet-sdk-wasm",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.11",
|
|
4
4
|
"license": "https://github.com/docknetwork/react-native-sdk/LICENSE",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,43 +13,23 @@
|
|
|
13
13
|
"build": "rm -rf lib && rollup -c && node ../../scripts/fix-build-imports.js ./lib"
|
|
14
14
|
},
|
|
15
15
|
"resolutions": {
|
|
16
|
-
"p-limit": "2.3.0"
|
|
17
|
-
"@polkadot/wasm-crypto": "6.3.1",
|
|
18
|
-
"@polkadot/rpc-core": "9.7.1",
|
|
19
|
-
"@polkadot/api": "9.7.1",
|
|
20
|
-
"@polkadot/keyring": "10.1.11",
|
|
21
|
-
"@polkadot/rpc-provider": "9.7.1",
|
|
22
|
-
"@polkadot/types": "9.7.1",
|
|
23
|
-
"@polkadot/types-known": "9.7.1",
|
|
24
|
-
"@polkadot/util": "10.1.11",
|
|
25
|
-
"@polkadot/util-crypto": "10.1.11"
|
|
16
|
+
"p-limit": "2.3.0"
|
|
26
17
|
},
|
|
27
18
|
"dependencies": {
|
|
28
19
|
"p-limit": "2.3.0",
|
|
29
20
|
"@astronautlabs/jsonpath": "^1.1.2",
|
|
30
21
|
"@docknetwork/universal-wallet": "^2.0.1",
|
|
31
|
-
"@docknetwork/wallet-sdk-dids": "^1.5.
|
|
22
|
+
"@docknetwork/wallet-sdk-dids": "^1.5.11",
|
|
32
23
|
"@cosmjs/proto-signing": "^0.32.4",
|
|
33
24
|
"@docknetwork/cheqd-blockchain-api": "0.36.1",
|
|
34
25
|
"@docknetwork/cheqd-blockchain-modules": "0.33.0",
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@polkadot/rpc-core": "9.7.1",
|
|
38
|
-
"@polkadot/rpc-provider": "9.7.1",
|
|
39
|
-
"@polkadot/types": "9.7.1",
|
|
40
|
-
"@polkadot/types-known": "9.7.1",
|
|
41
|
-
"@polkadot/ui-shared": "3.4.1",
|
|
42
|
-
"@polkadot/util": "10.1.11",
|
|
43
|
-
"@polkadot/util-crypto": "10.1.11",
|
|
44
|
-
"@polkadot/wasm-crypto": "6.3.1",
|
|
26
|
+
"@scure/bip39": "^1.6.0",
|
|
27
|
+
"@noble/hashes": "1.8.0",
|
|
45
28
|
"@docknetwork/credential-sdk": "0.50.0",
|
|
46
29
|
"@sphereon/oid4vci-client": "^0.16.0",
|
|
47
30
|
"@sphereon/oid4vci-common": "^0.16.0",
|
|
48
31
|
"axios": "^0.25.0",
|
|
49
|
-
"babel-node": "^0.0.1-security",
|
|
50
|
-
"bignumber.js": "^9.0.1",
|
|
51
32
|
"json-rpc-2.0": "^0.2.16",
|
|
52
|
-
"react-native-keychain": "^8.0.0",
|
|
53
33
|
"uuid": "^8.3.2",
|
|
54
34
|
"winston": "^3.3.3",
|
|
55
35
|
"cwait": "1.1.2",
|
package/readme.md
CHANGED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# Dock Wallet SDK
|
|
2
|
-
|
|
3
|
-
The Dock Wallet SDK provides all the required functions to build a PolkaDot Wallet on top of a [Universal Wallet 2020](https://w3c-ccg.github.io/universal-wallet-interop-spec/) document storage. It supports both Node.js and React Native.
|
|
4
|
-
|
|
5
|
-
For React Native usage please check [@docknetwork/wallet-sdk-react-native](https://www.npmjs.com/package/@docknetwork/wallet-sdk-react-native)
|
|
6
|
-
|
|
7
|
-
This is the core package and includes basic functionalities such as:
|
|
8
|
-
- Document storage following [Universal Wallet 2020 spec](https://w3c-ccg.github.io/universal-wallet-interop-spec/)
|
|
9
|
-
- Manage a wallet (CRUD)
|
|
10
|
-
- Manage accounts (CRUD)
|
|
11
|
-
- Fetch account balances
|
|
12
|
-
- Wallet/Account backup
|
|
13
|
-
- Import wallet/accounts
|
|
14
|
-
|
|
15
|
-
You might require to install extra packages depending on your needs, please refer to:
|
|
16
|
-
- [@docknetwork/wallet-sdk-react-native](https://www.npmjs.com/package/@docknetwork/wallet-sdk-react-native)
|
|
17
|
-
- [@docknetwork/wallet-sdk-dids](https://www.npmjs.com/package/@docknetwork/wallet-sdk-dids)
|
|
18
|
-
- [@docknetwork/wallet-sdk-transactions](https://www.npmjs.com/package/@docknetwork/wallet-sdk-transactions)
|
|
19
|
-
- [@docknetwork/wallet-sdk-credentials](https://www.npmjs.com/package/@docknetwork/wallet-sdk-credentials)
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
```js
|
|
23
|
-
yarn add @docknetwork/wallet-sdk-core
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## React Native Example
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
import {Wallet} from '@docknetwork/wallet-sdk-core/lib/modules/wallet';
|
|
32
|
-
|
|
33
|
-
const wallet = await Wallet.create();
|
|
34
|
-
|
|
35
|
-
const account1 = await wallet.accounts.create({
|
|
36
|
-
name: 'test',
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
console.log(`Account1 address ${account1.address}`);
|
|
40
|
-
// result: Account1 address 3D1M9UnR684eBfVujjQr6ucPqvXERSxYxcVBFGAhRohhRXxq
|
|
41
|
-
|
|
42
|
-
// Create account using an existing mnemonic
|
|
43
|
-
const mnemonic =
|
|
44
|
-
'indicate mention thing discover clarify grief inherit vivid dish health market spoil';
|
|
45
|
-
const account2 = await wallet.accounts.create({
|
|
46
|
-
name: 'Test',
|
|
47
|
-
mnemonic,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
console.log(`Account2 address ${account2.address}`);
|
|
51
|
-
|
|
52
|
-
// result: Account2 address 3FENesfZgFmBruv2H9Hc17GmobeTfxFAp8gHKXFmUtA38hcW
|
|
53
|
-
|
|
54
|
-
// Fetch accounts balance
|
|
55
|
-
const balance = await account1.getBalance();
|
|
56
|
-
|
|
57
|
-
console.log('Account1 balance', balance);
|
|
58
|
-
|
|
59
|
-
// result: Account1 balance 0
|
|
60
|
-
|
|
61
|
-
```
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatAddress,
|
|
3
|
-
formatCurrency,
|
|
4
|
-
formatDate,
|
|
5
|
-
getPlainDockAmount,
|
|
6
|
-
} from './format-utils';
|
|
7
|
-
|
|
8
|
-
const sr25519Address = '395pw1L5R4XiScC2BGRrSSSH6fadFuGSTfUcqA5cHPyA21eQ';
|
|
9
|
-
const ed25519Address = '38yWnWt8k3j5BuxssLAH43t5cNevxyShkCAMEx8su3nSsayh';
|
|
1
|
+
import {formatCurrency, formatDate} from './format-utils';
|
|
10
2
|
|
|
11
3
|
describe('Format util', () => {
|
|
12
|
-
it('expect to format sr25519 address', () => {
|
|
13
|
-
expect(formatAddress(sr25519Address)).toBe('395pw1L5R...5cHPyA21eQ');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('expect to format ed25519Address address', () => {
|
|
17
|
-
expect(formatAddress(ed25519Address)).toBe('38yWnWt8k...8su3nSsayh');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('expect to validate address length', () => {
|
|
21
|
-
expect(formatAddress(sr25519Address, sr25519Address.length + 10)).toBe(
|
|
22
|
-
sr25519Address,
|
|
23
|
-
);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('getPlainDockAmount', () => {
|
|
27
|
-
const amount = getPlainDockAmount(10);
|
|
28
|
-
expect(amount.toNumber()).toBe(10000000);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
4
|
it('formatCurrency', () => {
|
|
32
5
|
const result = formatCurrency(12.55);
|
|
33
6
|
expect(result).toBe('$12.55');
|
package/src/core/format-utils.ts
CHANGED
|
@@ -6,10 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import assert from 'assert';
|
|
9
|
-
import BigNumber from 'bignumber.js';
|
|
10
|
-
import {isNumberValid} from './validation';
|
|
11
|
-
|
|
12
|
-
export const DOCK_TOKEN_UNIT = 1000000;
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Format number as currency
|
|
@@ -44,35 +40,6 @@ export function formatCurrency(
|
|
|
44
40
|
return formatter.format(value);
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
export function formatAddress(address, size = 19) {
|
|
48
|
-
assert(!!address, 'address is required');
|
|
49
|
-
assert(typeof address === 'string', 'address must be a string');
|
|
50
|
-
|
|
51
|
-
if (!address || size > address.length) {
|
|
52
|
-
return address;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const offset = size / 2;
|
|
56
|
-
|
|
57
|
-
return `${address.substring(0, offset)}...${address.substring(
|
|
58
|
-
address.length - offset,
|
|
59
|
-
)}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function formatDockAmount(value) {
|
|
63
|
-
assert(!!value, 'value is required');
|
|
64
|
-
assert(isNumberValid(value), 'value is not valid');
|
|
65
|
-
|
|
66
|
-
return BigNumber(value).dividedBy(DOCK_TOKEN_UNIT).toNumber();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function getPlainDockAmount(value) {
|
|
70
|
-
assert(!!value, 'value is required');
|
|
71
|
-
assert(isNumberValid(value), 'value is not valid');
|
|
72
|
-
|
|
73
|
-
return BigNumber(value).times(DOCK_TOKEN_UNIT);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
43
|
/**
|
|
77
44
|
*
|
|
78
45
|
* @param date
|
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
assertAddress,
|
|
4
|
-
assertTokenAmount,
|
|
5
|
-
isAddressValid,
|
|
6
|
-
isNumberValid,
|
|
7
|
-
} from './validation';
|
|
1
|
+
import {isNumberValid} from './validation';
|
|
8
2
|
|
|
9
3
|
describe('core validation', () => {
|
|
10
|
-
it('isAddressValid', () => {
|
|
11
|
-
expect(isAddressValid(' ')).toBeFalsy();
|
|
12
|
-
expect(isAddressValid(' ')).toBeFalsy();
|
|
13
|
-
expect(isAddressValid('')).toBeFalsy();
|
|
14
|
-
expect(isAddressValid(null)).toBeFalsy();
|
|
15
|
-
expect(isAddressValid(undefined)).toBeFalsy();
|
|
16
|
-
expect(isAddressValid(123)).toBeFalsy();
|
|
17
|
-
expect(isAddressValid('address')).toBeTruthy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
4
|
it('isNumberValid', () => {
|
|
21
|
-
expect(isNumberValid('100000000')).toBeTruthy();
|
|
22
5
|
expect(isNumberValid('this is not valid')).toBeFalsy();
|
|
23
6
|
expect(isNumberValid(false)).toBeFalsy();
|
|
24
7
|
expect(isNumberValid(10)).toBeTruthy();
|
|
25
|
-
expect(isNumberValid(BigNumber(1))).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('assertAddress', () => {
|
|
29
|
-
expect(() => assertAddress(' ')).toThrow(`invalid address: ${' '}`);
|
|
30
|
-
expect(() => assertAddress(null)).toThrow('invalid address: null');
|
|
31
|
-
expect(() => assertAddress('address')).not.toThrow();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('assertTokenAmount', () => {
|
|
35
|
-
expect(() => assertTokenAmount(' ')).toThrow('invalid token amount');
|
|
36
|
-
expect(() => assertTokenAmount('abc')).toThrow('invalid token amount');
|
|
37
|
-
expect(() => assertTokenAmount(null)).toThrow('invalid token amount');
|
|
38
|
-
expect(() => assertTokenAmount('10')).not.toThrow();
|
|
39
|
-
expect(() => assertTokenAmount(100)).not.toThrow();
|
|
40
8
|
});
|
|
41
9
|
});
|
package/src/core/validation.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
2
|
import assert from 'assert';
|
|
4
3
|
import {KeypairTypes} from '../types';
|
|
5
4
|
|
|
6
5
|
export {assert};
|
|
7
6
|
|
|
8
7
|
export function isNumberValid(v: any) {
|
|
9
|
-
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return !isNaN(parseInt(v, 10));
|
|
8
|
+
return typeof v === 'number' && !isNaN(v);
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
export function assertKeyType(type) {
|
|
@@ -24,22 +19,3 @@ export function assertPassword(password) {
|
|
|
24
19
|
assert(typeof password === 'string', `invalid password: ${password}`);
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
export function assertTokenAmount(amount) {
|
|
28
|
-
assert(isNumberValid(amount), 'invalid token amount');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function assertAddress(address, name = 'address') {
|
|
32
|
-
assert(isAddressValid(address), `invalid ${name}: ${address}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function isAddressValid(address) {
|
|
36
|
-
if (!address || typeof address !== 'string') {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!address.trim()) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return true;
|
|
45
|
-
}
|
package/src/rpc-server.test.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import {utilCryptoService} from './services/util-crypto/service';
|
|
2
|
-
import {walletService} from './services/wallet';
|
|
3
2
|
|
|
4
3
|
describe('RpcServer', () => {
|
|
5
|
-
it('expect to register walletService', async () => {
|
|
6
|
-
const timestamp = Date.now();
|
|
7
|
-
const result = await walletService.healthCheck(timestamp);
|
|
8
|
-
expect(result).toBe(`wallet: ${timestamp}`);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
4
|
it('expect to register utilCrypto', async () => {
|
|
12
|
-
const result = await utilCryptoService.
|
|
13
|
-
expect(result).
|
|
5
|
+
const result = await utilCryptoService.mnemonicGenerate(12);
|
|
6
|
+
expect(result).toBeDefined();
|
|
14
7
|
});
|
|
15
8
|
});
|
package/src/rpc-util.js
CHANGED
|
@@ -3,6 +3,12 @@ import {decryptData, SECURE_JSON_RPC} from './core/crypto';
|
|
|
3
3
|
import {Logger} from './core/logger';
|
|
4
4
|
|
|
5
5
|
export function createMethodResolver({service, methodFn, methodName}) {
|
|
6
|
+
if (methodFn === undefined) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`Resolver is undefined for ${methodName} in ${service.name}`,
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
const methodPath = `${service.name}.${methodName}`;
|
|
7
13
|
|
|
8
14
|
return {
|
|
@@ -58,6 +64,14 @@ export function createRpcService(service) {
|
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
return methods.map(methodFn => {
|
|
67
|
+
if (methodFn === undefined) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Method is undefined in ${
|
|
70
|
+
service.name
|
|
71
|
+
}, available methods: ${Object.keys(service.rpcMethods).join(', ')}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
return createMethodResolver({
|
|
62
76
|
methodFn,
|
|
63
77
|
methodName: methodFn.name,
|
|
@@ -100,6 +100,7 @@ export class BlockchainService {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
if (this.cheqdApi && this.cheqdApi.isInitialized()) {
|
|
103
|
+
Logger.info('Disconnecting from cheqd');
|
|
103
104
|
await this.cheqdApi.disconnect();
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -131,9 +132,7 @@ export class BlockchainService {
|
|
|
131
132
|
});
|
|
132
133
|
Logger.info(`Cheqd initialized at: ${checkdApiUrl}`);
|
|
133
134
|
} catch (err) {
|
|
134
|
-
|
|
135
|
-
debugger;
|
|
136
|
-
Logger.error(`Failed to initialize cheqd at: ${checkdApiUrl}`);
|
|
135
|
+
Logger.error(`Failed to initialize cheqd at: ${checkdApiUrl}`, err);
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
|
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
VBWitnessUpdateInfo,
|
|
8
8
|
Encoder,
|
|
9
9
|
} from '@docknetwork/crypto-wasm-ts';
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import {hexToU8a} from '@docknetwork/credential-sdk/utils';
|
|
10
12
|
|
|
11
|
-
import {hexToU8a} from '@polkadot/util';
|
|
12
13
|
import {
|
|
13
14
|
blockchainService,
|
|
14
15
|
} from '../blockchain/service';
|
|
@@ -374,16 +374,16 @@ describe('Bound check', () => {
|
|
|
374
374
|
});
|
|
375
375
|
|
|
376
376
|
describe('isBase64OrDataUrl', () => {
|
|
377
|
-
it('expect to return true for base64 string', () => {
|
|
378
|
-
expect(isBase64OrDataUrl('
|
|
377
|
+
it('expect to return true for base64 string', async () => {
|
|
378
|
+
expect(await isBase64OrDataUrl('SGVsbG8gV29ybGQ=')).toBe(true);
|
|
379
379
|
});
|
|
380
380
|
|
|
381
|
-
it('expect to return true for data URL', () => {
|
|
382
|
-
expect(isBase64OrDataUrl('data:application/octet-stream;base64,base64string')).toBe(true);
|
|
381
|
+
it('expect to return true for data URL', async () => {
|
|
382
|
+
expect(await isBase64OrDataUrl('data:application/octet-stream;base64,base64string')).toBe(true);
|
|
383
383
|
});
|
|
384
384
|
|
|
385
|
-
it('expect to return false for other strings', () => {
|
|
386
|
-
expect(isBase64OrDataUrl('http://
|
|
385
|
+
it('expect to return false for other strings', async () => {
|
|
386
|
+
expect(await isBase64OrDataUrl('http://workspace.truvera.io/some-key')).toBe(false);
|
|
387
387
|
});
|
|
388
388
|
});
|
|
389
389
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {LegoProvingKey} from '@docknetwork/crypto-wasm-ts/lib/legosnark';
|
|
2
2
|
import {PresentationBuilder} from '@docknetwork/crypto-wasm-ts/lib';
|
|
3
|
-
import {isBase64} from '@polkadot/util-crypto';
|
|
4
3
|
import base64url from 'base64url';
|
|
5
4
|
import {pexToBounds} from './pex-helpers';
|
|
5
|
+
import {utilCryptoService} from '../util-crypto/service';
|
|
6
6
|
|
|
7
7
|
interface Filter {
|
|
8
8
|
type: string;
|
|
@@ -110,9 +110,9 @@ export function blobFromBase64(base64String: string): Uint8Array {
|
|
|
110
110
|
return base64url.toBuffer(cleanedBase64);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
export function isBase64OrDataUrl(str: string): boolean {
|
|
113
|
+
export async function isBase64OrDataUrl(str: string): Promise<boolean> {
|
|
114
114
|
return (
|
|
115
|
-
isBase64(str) ||
|
|
115
|
+
(await utilCryptoService.isBase64(str)) ||
|
|
116
116
|
(str as string).indexOf('data:application/octet-stream') > -1
|
|
117
117
|
);
|
|
118
118
|
}
|
|
@@ -120,7 +120,7 @@ export function isBase64OrDataUrl(str: string): boolean {
|
|
|
120
120
|
export async function fetchProvingKey(proofRequest: ProofRequest) {
|
|
121
121
|
let blob: Uint8Array;
|
|
122
122
|
|
|
123
|
-
if (isBase64OrDataUrl(proofRequest.boundCheckSnarkKey)) {
|
|
123
|
+
if (await isBase64OrDataUrl(proofRequest.boundCheckSnarkKey)) {
|
|
124
124
|
console.log('Is base64');
|
|
125
125
|
blob = blobFromBase64(proofRequest.boundCheckSnarkKey);
|
|
126
126
|
} else {
|
|
@@ -3,13 +3,11 @@ import {credentialService as service} from './service';
|
|
|
3
3
|
import {validation} from './config';
|
|
4
4
|
import * as credentialUtils from '@docknetwork/credential-sdk/vc';
|
|
5
5
|
import {CredentialServiceRPC} from './service-rpc';
|
|
6
|
-
import {getTestWallet} from '../../test/setup-test-state';
|
|
7
6
|
import {OpenID4VCIClientV1_0_13} from '@sphereon/oid4vci-client';
|
|
8
7
|
import {didService} from '../dids/service';
|
|
9
8
|
|
|
10
9
|
describe('Credential Service', () => {
|
|
11
10
|
beforeAll(async () => {
|
|
12
|
-
await getTestWallet();
|
|
13
11
|
const mockAddCredentialToPresent = jest.fn(() => 0);
|
|
14
12
|
const mockAddAttributeToReveal = jest.fn();
|
|
15
13
|
const mockCreatePresentation = jest.fn();
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import {OpenID4VCIClientV1_0_13} from '@sphereon/oid4vci-client';
|
|
10
10
|
import {Alg} from '@sphereon/oid4vci-common';
|
|
11
11
|
import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
|
|
12
|
+
import {hexToU8a} from '@docknetwork/credential-sdk/utils';
|
|
12
13
|
import {
|
|
13
14
|
VerifiablePresentation,
|
|
14
15
|
Presentation,
|
|
@@ -117,13 +118,15 @@ class CredentialService {
|
|
|
117
118
|
vp.setHolder(keyDoc.controller);
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
const keyPair = getKeypairFromDoc(keyDoc);
|
|
122
|
+
keyPair.signer = keyPair.signer();
|
|
123
|
+
const suite = await getSuiteFromKeyDoc(keyPair);
|
|
121
124
|
|
|
122
125
|
if (shouldSkipSigning) {
|
|
123
126
|
return vp.toJSON();
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
return vp.sign(
|
|
129
|
+
return vp.sign(suite, challenge, domain, blockchainService.resolver);
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
async verifyPresentation({ presentation, options }: any) {
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import * as bs58 from 'base58-universal';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
Bls12381BBSKeyPairDock2023,
|
|
4
|
+
Bls12381G2KeyPairDock2022,
|
|
5
|
+
Bls12381BBDT16KeyPairDock2024,
|
|
6
|
+
} from '@docknetwork/credential-sdk/vc/crypto';
|
|
7
|
+
import {randomAsHex} from '@docknetwork/credential-sdk/utils';
|
|
8
|
+
import {X25519KeyAgreementKey2020} from '@digitalbazaar/x25519-key-agreement-key-2020';
|
|
9
|
+
import {X25519KeyAgreementKey2019} from '@digitalbazaar/x25519-key-agreement-key-2019';
|
|
10
|
+
import {Ed25519VerificationKey2018} from '@digitalbazaar/ed25519-verification-key-2018';
|
|
11
|
+
import {Ed25519VerificationKey2020} from '@digitalbazaar/ed25519-verification-key-2020';
|
|
12
|
+
|
|
13
|
+
import {Ed25519Keypair} from '@docknetwork/credential-sdk/keypairs';
|
|
14
|
+
|
|
15
|
+
export async function keyDocToKeypair(keyDoc) {
|
|
16
|
+
if (keyDoc.keypair) {
|
|
17
|
+
return keyDoc;
|
|
18
|
+
}
|
|
4
19
|
|
|
5
|
-
const docToKeyMap = {
|
|
6
|
-
Sr25519VerificationKey2020: 'sr25519',
|
|
7
|
-
Ed25519VerificationKey2018: 'ed25519',
|
|
8
|
-
};
|
|
9
|
-
export function keyDocToKeypair(keyDoc, dock) {
|
|
10
|
-
// For now we expect multibase to just be b58, this needs fixing later if/when we support more keys
|
|
11
20
|
const {
|
|
12
21
|
type,
|
|
13
22
|
privateKeyBase58,
|
|
@@ -15,25 +24,58 @@ export function keyDocToKeypair(keyDoc, dock) {
|
|
|
15
24
|
privateKeyMultibase,
|
|
16
25
|
publicKeyMultibase,
|
|
17
26
|
} = keyDoc;
|
|
18
|
-
|
|
27
|
+
|
|
28
|
+
const publicKeyEncoded = publicKeyBase58 || publicKeyMultibase.substr(1);
|
|
29
|
+
const privateKeyEncoded =
|
|
30
|
+
privateKeyBase58 || (privateKeyMultibase && privateKeyMultibase.substr(1));
|
|
31
|
+
if (!privateKeyEncoded) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`No private key in document found, this should not happen. Got: ${JSON.stringify(
|
|
34
|
+
keyDoc,
|
|
35
|
+
null,
|
|
36
|
+
2,
|
|
37
|
+
)}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
const privateKeyBytes = bs58.decode(privateKeyEncoded);
|
|
42
|
+
const publicKeyBytes = bs58.decode(publicKeyEncoded);
|
|
20
43
|
|
|
21
44
|
if (type === 'Bls12381G2VerificationKeyDock2022') {
|
|
22
45
|
return new Bls12381G2KeyPairDock2022(keyDoc);
|
|
46
|
+
} else if (type === 'Bls12381BBSVerificationKeyDock2023') {
|
|
47
|
+
return new Bls12381BBSKeyPairDock2023(keyDoc);
|
|
48
|
+
} else if (type === 'Bls12381BBDT16VerificationKeyDock2024') {
|
|
49
|
+
return new Bls12381BBDT16KeyPairDock2024(keyDoc);
|
|
50
|
+
} else if (
|
|
51
|
+
type === 'Ed25519VerificationKey2020' ||
|
|
52
|
+
type === 'Ed25519VerificationKey2018'
|
|
53
|
+
) {
|
|
54
|
+
const key = new Ed25519Keypair(randomAsHex(32));
|
|
55
|
+
key.keyPair.publicKey = publicKeyBytes;
|
|
56
|
+
key.keyPair.secretKey = privateKeyBytes;
|
|
57
|
+
return key;
|
|
23
58
|
} else {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
throw new Error(`Unsupported key type: ${type}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const keyConstructors = {
|
|
64
|
+
Ed25519VerificationKey2018: keypairOptions =>
|
|
65
|
+
new Ed25519VerificationKey2018(keypairOptions),
|
|
66
|
+
Ed25519VerificationKey2020: keypairOptions =>
|
|
67
|
+
new Ed25519VerificationKey2020(keypairOptions),
|
|
68
|
+
X25519KeyAgreementKey2019: keypairOptions =>
|
|
69
|
+
new X25519KeyAgreementKey2019(keypairOptions),
|
|
70
|
+
X25519KeyAgreementKey2020: keypairOptions =>
|
|
71
|
+
new X25519KeyAgreementKey2020(keypairOptions),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function getKeypairFromDoc(keypairOptions) {
|
|
75
|
+
const {type} = keypairOptions;
|
|
76
|
+
const keyConstructor = keyConstructors[type];
|
|
77
|
+
if (!keyConstructor) {
|
|
78
|
+
throw new Error(`Unrecognized keypair type to construct: ${type}`);
|
|
38
79
|
}
|
|
80
|
+
return keyConstructor(keypairOptions);
|
|
39
81
|
}
|
|
@@ -3,14 +3,9 @@ import {DIDServiceRPC} from './service-rpc';
|
|
|
3
3
|
import {didService as service} from './service';
|
|
4
4
|
import {validation} from './config';
|
|
5
5
|
import {DIDKeyManager} from '@docknetwork/wallet-sdk-dids/src';
|
|
6
|
-
import {
|
|
7
|
-
import {blockchainService} from '../blockchain/service';
|
|
6
|
+
import {Ed25519Keypair} from '@docknetwork/credential-sdk/keypairs';
|
|
8
7
|
|
|
9
8
|
describe('DID Service', () => {
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
await getTestWallet();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
9
|
it('ServiceRpc', () => {
|
|
15
10
|
assertRpcService(DIDServiceRPC, service, validation);
|
|
16
11
|
});
|
|
@@ -97,19 +92,6 @@ describe('DID Service', () => {
|
|
|
97
92
|
spy.mockReset();
|
|
98
93
|
});
|
|
99
94
|
|
|
100
|
-
it('expect to get did document', async () => {
|
|
101
|
-
const document = 'document';
|
|
102
|
-
jest
|
|
103
|
-
.spyOn(blockchainService.modules.did, 'getDocument')
|
|
104
|
-
.mockResolvedValue(document);
|
|
105
|
-
|
|
106
|
-
const result = await service.getDidDockDocument(
|
|
107
|
-
'did:dock:5HL5XB7CHcHT2ZUKjY2SCJvDAK11qoa1exgfVnVTHRbmjJQi',
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
expect(result).toStrictEqual(document);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
95
|
it('expect to generateKeyDoc without keyPair', async () => {
|
|
114
96
|
const controller =
|
|
115
97
|
'did:dock:5HL5XB7CHcHT2ZUKjY2SCJvDAK11qoa1exgfVnVTHRbmjJQ';
|
|
@@ -121,25 +103,55 @@ describe('DID Service', () => {
|
|
|
121
103
|
expect(keyDoc.privateKeyMultibase).toBeDefined();
|
|
122
104
|
});
|
|
123
105
|
|
|
124
|
-
it('expect to
|
|
106
|
+
it('expect to deriveKeyDoc', async () => {
|
|
125
107
|
const controller =
|
|
126
108
|
'did:dock:5HL5XB7CHcHT2ZUKjY2SCJvDAK11qoa1exgfVnVTHRbmjJQ';
|
|
127
|
-
const keyPairJSON = {
|
|
128
|
-
encoded:
|
|
129
|
-
'MFMCAQEwBQYDK2VwBCIEIJDIpsaUjZCkVkPmBPqKD0dgu59F8ks4yepJKNFQkz+A/fYvnshD7g1RpaSXuGcLytu6fN/P/PGt2ahhH2Bkh0GhIwMhAP32L57IQ+4NUaWkl7hnC8rbunzfz/zxrdmoYR9gZIdB',
|
|
130
|
-
encoding: {content: ['pkcs8', 'ed25519'], type: ['none'], version: '3'},
|
|
131
|
-
address: '3CGqgBTzZEPyhVTjpWdX5z2uDQ6hxEUALcZ6HthscNnVrKy7',
|
|
132
|
-
meta: {},
|
|
133
|
-
};
|
|
134
109
|
|
|
135
|
-
const
|
|
110
|
+
const {keyPair} = Ed25519Keypair.random();
|
|
111
|
+
|
|
112
|
+
const derivedKeyDoc = await service.deriveKeyDoc({
|
|
136
113
|
controller,
|
|
137
|
-
|
|
114
|
+
pair: keyPair,
|
|
138
115
|
});
|
|
139
116
|
|
|
140
|
-
expect(
|
|
141
|
-
expect(
|
|
142
|
-
|
|
143
|
-
|
|
117
|
+
expect(derivedKeyDoc.controller).toEqual(controller);
|
|
118
|
+
expect(derivedKeyDoc.privateKeyMultibase).toBeDefined();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('expect to createSignedJWT', async () => {
|
|
122
|
+
const headerInput = {
|
|
123
|
+
typ: 'openid4vci-proof+jwt',
|
|
124
|
+
alg: 'EdDSA',
|
|
125
|
+
kid: 'did:key:z6MkjW3DVk4mXjnK8GUuK2SydyFg8oMJbUnHiVzzSz3N9iGM#z6MkjW3DVk4mXjnK8GUuK2SydyFg8oMJbUnHiVzzSz3N9iGM',
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const payload = {
|
|
129
|
+
aud: 'https://api.truvera.io/openid/issuers/d044f3d3-0934-4f62-9b6f-6f06ae8f383e',
|
|
130
|
+
iat: 1750356930,
|
|
131
|
+
exp: 1750357590,
|
|
132
|
+
iss: 'dock.wallet',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const privateKeyDoc = {
|
|
136
|
+
controller: 'did:key:z6MkjW3DVk4mXjnK8GUuK2SydyFg8oMJbUnHiVzzSz3N9iGM',
|
|
137
|
+
type: 'Ed25519VerificationKey2018',
|
|
138
|
+
id: 'did:key:z6MkjW3DVk4mXjnK8GUuK2SydyFg8oMJbUnHiVzzSz3N9iGM#z6MkjW3DVk4mXjnK8GUuK2SydyFg8oMJbUnHiVzzSz3N9iGM',
|
|
139
|
+
publicKeyMultibase: 'z6MkjW3DVk4mXjnK8GUuK2SydyFg8oMJbUnHiVzzSz3N9iGM',
|
|
140
|
+
privateKeyMultibase:
|
|
141
|
+
'zruzuEmC9VrJ3JUcufskfX4qNKwqqrNDztqJsDp1dXXQFS8CkfEDqK1ZBgNXeWF9xGhAPeVVfV1vL5pVaHpXLU2JwXK',
|
|
142
|
+
privateKeyBase58:
|
|
143
|
+
'GLkPGM4hz3AhQkQA1y63PtxdA3GL4vJiWgYpnB4N1sFi2wzr2tDbc482igkKaDcAwbrhe92LKJygEHd5xmBJtvR',
|
|
144
|
+
publicKeyBase58: '63nAuVpLCCHr1meCdTV8nshgKE5TBbXw2V64ci5MEVUy',
|
|
145
|
+
'@context': ['https://w3id.org/wallet/v1'],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const signedJWT = await service.createSignedJWT({
|
|
149
|
+
payload,
|
|
150
|
+
privateKeyDoc,
|
|
151
|
+
headerInput,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(signedJWT).toBeDefined();
|
|
155
|
+
expect(signedJWT).toContain('.');
|
|
144
156
|
});
|
|
145
157
|
});
|