@docknetwork/wallet-sdk-wasm 1.5.9 → 1.5.10

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.
Files changed (262) hide show
  1. package/lib/core/format-utils.js +0 -28
  2. package/lib/core/format-utils.mjs +1 -24
  3. package/lib/core/validation.js +1 -24
  4. package/lib/core/validation.mjs +2 -21
  5. package/lib/index.js +13 -23
  6. package/lib/index.mjs +13 -23
  7. package/lib/rpc-server.js +13 -23
  8. package/lib/rpc-server.mjs +13 -23
  9. package/lib/rpc-util.js +14 -0
  10. package/lib/rpc-util.mjs +14 -0
  11. package/lib/services/blockchain/index.js +3 -6
  12. package/lib/services/blockchain/index.mjs +3 -6
  13. package/lib/services/blockchain/service.js +4 -6
  14. package/lib/services/blockchain/service.mjs +4 -6
  15. package/lib/services/credential/bbs-revocation.js +4 -7
  16. package/lib/services/credential/bbs-revocation.mjs +3 -6
  17. package/lib/services/credential/bound-check.js +9 -4
  18. package/lib/services/credential/bound-check.mjs +9 -4
  19. package/lib/services/credential/index.js +11 -13
  20. package/lib/services/credential/index.mjs +11 -13
  21. package/lib/services/credential/service.js +18 -18
  22. package/lib/services/credential/service.mjs +15 -15
  23. package/lib/services/credential/utils.js +65 -28
  24. package/lib/services/credential/utils.mjs +62 -32
  25. package/lib/services/dids/index.js +11 -14
  26. package/lib/services/dids/index.mjs +11 -14
  27. package/lib/services/dids/keypair-utils.js +142 -0
  28. package/lib/services/dids/keypair-utils.mjs +113 -0
  29. package/lib/services/dids/service.js +15 -34
  30. package/lib/services/dids/service.mjs +15 -34
  31. package/lib/services/edv/index.js +8 -14
  32. package/lib/services/edv/index.mjs +8 -14
  33. package/lib/services/edv/service.js +10 -22
  34. package/lib/services/edv/service.mjs +10 -22
  35. package/lib/services/index.js +13 -25
  36. package/lib/services/index.mjs +13 -25
  37. package/lib/services/relay-service/configs.js +0 -1
  38. package/lib/services/relay-service/configs.mjs +0 -1
  39. package/lib/services/relay-service/index.android.js +0 -1
  40. package/lib/services/relay-service/index.android.mjs +0 -1
  41. package/lib/services/relay-service/index.ios.js +0 -1
  42. package/lib/services/relay-service/index.ios.mjs +0 -1
  43. package/lib/services/relay-service/index.js +0 -1
  44. package/lib/services/relay-service/index.mjs +0 -1
  45. package/lib/services/relay-service/service-rpc.js +0 -1
  46. package/lib/services/relay-service/service-rpc.mjs +0 -1
  47. package/lib/services/relay-service/service.js +0 -1
  48. package/lib/services/relay-service/service.mjs +0 -1
  49. package/lib/services/test-utils.js +0 -44
  50. package/lib/services/test-utils.mjs +1 -44
  51. package/lib/services/util-crypto/configs.js +0 -12
  52. package/lib/services/util-crypto/configs.mjs +0 -12
  53. package/lib/services/util-crypto/index.android.js +0 -3
  54. package/lib/services/util-crypto/index.android.mjs +0 -3
  55. package/lib/services/util-crypto/index.ios.js +0 -3
  56. package/lib/services/util-crypto/index.ios.mjs +0 -3
  57. package/lib/services/util-crypto/index.js +4 -7
  58. package/lib/services/util-crypto/index.mjs +4 -7
  59. package/lib/services/util-crypto/service-rpc.js +0 -23
  60. package/lib/services/util-crypto/service-rpc.mjs +0 -23
  61. package/lib/services/util-crypto/service.js +68 -61
  62. package/lib/services/util-crypto/service.mjs +50 -59
  63. package/lib/services/wallet/configs.js +0 -63
  64. package/lib/services/wallet/configs.mjs +1 -64
  65. package/lib/services/wallet/index.android.js +0 -1
  66. package/lib/services/wallet/index.android.mjs +0 -1
  67. package/lib/services/wallet/index.ios.js +0 -1
  68. package/lib/services/wallet/index.ios.mjs +0 -1
  69. package/lib/services/wallet/index.js +2 -12
  70. package/lib/services/wallet/index.mjs +2 -12
  71. package/lib/services/wallet/service-rpc.js +0 -77
  72. package/lib/services/wallet/service-rpc.mjs +0 -77
  73. package/lib/services/wallet/service.js +1 -215
  74. package/lib/services/wallet/service.mjs +1 -211
  75. package/lib/setup-nodejs.js +13 -23
  76. package/lib/setup-nodejs.mjs +13 -23
  77. package/lib/setup-tests.js +13 -23
  78. package/lib/setup-tests.mjs +13 -23
  79. package/lib/src/core/format-utils.d.ts +0 -5
  80. package/lib/src/core/format-utils.d.ts.map +1 -1
  81. package/lib/src/core/validation.d.ts +0 -3
  82. package/lib/src/core/validation.d.ts.map +1 -1
  83. package/lib/src/rpc-util.d.ts.map +1 -1
  84. package/lib/src/services/blockchain/service.d.ts.map +1 -1
  85. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  86. package/lib/src/services/credential/bound-check.d.ts +1 -1
  87. package/lib/src/services/credential/bound-check.d.ts.map +1 -1
  88. package/lib/src/services/credential/service.d.ts.map +1 -1
  89. package/lib/src/services/credential/utils.d.ts +2 -1
  90. package/lib/src/services/credential/utils.d.ts.map +1 -1
  91. package/lib/src/services/dids/keypair-utils.d.ts +15 -0
  92. package/lib/src/services/dids/keypair-utils.d.ts.map +1 -0
  93. package/lib/src/services/dids/service.d.ts +6 -6
  94. package/lib/src/services/dids/service.d.ts.map +1 -1
  95. package/lib/src/services/edv/service.d.ts.map +1 -1
  96. package/lib/src/services/util-crypto/configs.d.ts +0 -3
  97. package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
  98. package/lib/src/services/util-crypto/service.d.ts +3 -8
  99. package/lib/src/services/util-crypto/service.d.ts.map +1 -1
  100. package/lib/src/services/wallet/configs.d.ts +13 -0
  101. package/lib/src/services/wallet/configs.d.ts.map +1 -0
  102. package/lib/src/services/wallet/service.d.ts +1 -44
  103. package/lib/src/services/wallet/service.d.ts.map +1 -1
  104. package/lib/test-utils.js +0 -4
  105. package/lib/test-utils.mjs +1 -4
  106. package/lib/tsconfig.tsbuildinfo +1 -1
  107. package/package.json +5 -25
  108. package/readme.md +0 -61
  109. package/src/core/format-utils.test.js +1 -28
  110. package/src/core/format-utils.ts +0 -33
  111. package/src/core/validation.test.js +1 -33
  112. package/src/core/validation.ts +1 -25
  113. package/src/rpc-server.test.js +2 -9
  114. package/src/rpc-util.js +14 -0
  115. package/src/services/blockchain/service.ts +1 -0
  116. package/src/services/credential/bbs-revocation.ts +2 -1
  117. package/src/services/credential/bound-check.test.ts +6 -6
  118. package/src/services/credential/bound-check.ts +4 -4
  119. package/src/services/credential/index.test.js +0 -2
  120. package/src/services/credential/service.ts +5 -2
  121. package/src/services/credential/utils.js +65 -23
  122. package/src/services/dids/index.test.js +8 -19
  123. package/src/services/dids/keypair-utils.js +111 -0
  124. package/src/services/dids/service.ts +6 -25
  125. package/src/services/edv/service.ts +2 -9
  126. package/src/services/index.js +0 -4
  127. package/src/services/test-utils.js +0 -29
  128. package/src/services/util-crypto/configs.ts +0 -12
  129. package/src/services/util-crypto/index.test.js +6 -83
  130. package/src/services/util-crypto/service-rpc.js +0 -20
  131. package/src/services/util-crypto/service.ts +62 -75
  132. package/src/services/wallet/configs.ts +1 -113
  133. package/src/services/wallet/index.test.js +0 -159
  134. package/src/services/wallet/service-rpc.js +1 -88
  135. package/src/services/wallet/service.ts +0 -258
  136. package/src/test-utils.js +0 -13
  137. package/lib/account-357ab05d.js +0 -742
  138. package/lib/account-399e6053.js +0 -752
  139. package/lib/core/polkadot-utils.js +0 -119
  140. package/lib/core/polkadot-utils.mjs +0 -94
  141. package/lib/core/realm-schemas.js +0 -50
  142. package/lib/core/realm-schemas.mjs +0 -44
  143. package/lib/core/subscan.js +0 -75
  144. package/lib/core/subscan.mjs +0 -64
  145. package/lib/fixtures.js +0 -56
  146. package/lib/fixtures.mjs +0 -52
  147. package/lib/modules/account.js +0 -48
  148. package/lib/modules/account.mjs +0 -40
  149. package/lib/modules/accounts.js +0 -49
  150. package/lib/modules/accounts.mjs +0 -40
  151. package/lib/modules/data-migration.js +0 -72
  152. package/lib/modules/data-migration.mjs +0 -68
  153. package/lib/modules/wallet-backup.js +0 -82
  154. package/lib/modules/wallet-backup.mjs +0 -71
  155. package/lib/modules/wallet.js +0 -49
  156. package/lib/modules/wallet.mjs +0 -40
  157. package/lib/services/example/configs.js +0 -21
  158. package/lib/services/example/configs.mjs +0 -13
  159. package/lib/services/example/index.js +0 -18
  160. package/lib/services/example/index.mjs +0 -14
  161. package/lib/services/example/service-rpc.js +0 -25
  162. package/lib/services/example/service-rpc.mjs +0 -21
  163. package/lib/services/example/service.js +0 -25
  164. package/lib/services/example/service.mjs +0 -20
  165. package/lib/services/keyring/configs.js +0 -70
  166. package/lib/services/keyring/configs.mjs +0 -61
  167. package/lib/services/keyring/index.android.js +0 -22
  168. package/lib/services/keyring/index.android.mjs +0 -18
  169. package/lib/services/keyring/index.ios.js +0 -22
  170. package/lib/services/keyring/index.ios.mjs +0 -18
  171. package/lib/services/keyring/index.js +0 -16
  172. package/lib/services/keyring/index.mjs +0 -8
  173. package/lib/services/keyring/service-rpc.js +0 -65
  174. package/lib/services/keyring/service-rpc.mjs +0 -61
  175. package/lib/services/keyring/service.js +0 -84
  176. package/lib/services/keyring/service.mjs +0 -74
  177. package/lib/services/polkadot/configs.js +0 -17
  178. package/lib/services/polkadot/configs.mjs +0 -13
  179. package/lib/services/polkadot/index.android.js +0 -22
  180. package/lib/services/polkadot/index.android.mjs +0 -18
  181. package/lib/services/polkadot/index.ios.js +0 -22
  182. package/lib/services/polkadot/index.ios.mjs +0 -18
  183. package/lib/services/polkadot/index.js +0 -15
  184. package/lib/services/polkadot/index.mjs +0 -7
  185. package/lib/services/polkadot/service-rpc.js +0 -30
  186. package/lib/services/polkadot/service-rpc.mjs +0 -26
  187. package/lib/services/polkadot/service.js +0 -28
  188. package/lib/services/polkadot/service.mjs +0 -23
  189. package/lib/src/core/polkadot-utils.d.ts +0 -11
  190. package/lib/src/core/polkadot-utils.d.ts.map +0 -1
  191. package/lib/src/modules/account.d.ts +0 -60
  192. package/lib/src/modules/account.d.ts.map +0 -1
  193. package/lib/src/modules/accounts.d.ts +0 -48
  194. package/lib/src/modules/accounts.d.ts.map +0 -1
  195. package/lib/src/modules/data-migration.d.ts +0 -7
  196. package/lib/src/modules/data-migration.d.ts.map +0 -1
  197. package/lib/src/modules/wallet-backup.d.ts +0 -12
  198. package/lib/src/modules/wallet-backup.d.ts.map +0 -1
  199. package/lib/src/modules/wallet.d.ts +0 -134
  200. package/lib/src/modules/wallet.d.ts.map +0 -1
  201. package/lib/src/services/blockchain/index.d.ts +0 -2
  202. package/lib/src/services/blockchain/index.d.ts.map +0 -1
  203. package/lib/src/services/example/configs.d.ts +0 -9
  204. package/lib/src/services/example/configs.d.ts.map +0 -1
  205. package/lib/src/services/example/service.d.ts +0 -8
  206. package/lib/src/services/example/service.d.ts.map +0 -1
  207. package/lib/src/services/keyring/configs.d.ts +0 -39
  208. package/lib/src/services/keyring/configs.d.ts.map +0 -1
  209. package/lib/src/services/keyring/index.d.ts +0 -2
  210. package/lib/src/services/keyring/index.d.ts.map +0 -1
  211. package/lib/src/services/polkadot/configs.d.ts +0 -8
  212. package/lib/src/services/polkadot/configs.d.ts.map +0 -1
  213. package/lib/src/services/polkadot/index.d.ts +0 -2
  214. package/lib/src/services/polkadot/index.d.ts.map +0 -1
  215. package/lib/src/services/polkadot/service.d.ts +0 -8
  216. package/lib/src/services/polkadot/service.d.ts.map +0 -1
  217. package/lib/src/services/wallet/index.d.ts +0 -2
  218. package/lib/src/services/wallet/index.d.ts.map +0 -1
  219. package/lib/test/axiosMocks.js +0 -431
  220. package/lib/test/axiosMocks.mjs +0 -420
  221. package/lib/test/setup-test-state.js +0 -81
  222. package/lib/test/setup-test-state.mjs +0 -73
  223. package/src/core/polkadot-utils.js +0 -99
  224. package/src/core/realm-schemas.js +0 -42
  225. package/src/core/subscan.js +0 -62
  226. package/src/core/subscan.test.js +0 -56
  227. package/src/fixtures.js +0 -43
  228. package/src/modules/account.test.js +0 -56
  229. package/src/modules/account.ts +0 -128
  230. package/src/modules/accounts.test.js +0 -63
  231. package/src/modules/accounts.ts +0 -231
  232. package/src/modules/data-migration.test.js +0 -61
  233. package/src/modules/data-migration.ts +0 -86
  234. package/src/modules/wallet-backup.test.js +0 -24
  235. package/src/modules/wallet-backup.ts +0 -68
  236. package/src/modules/wallet.test.js +0 -216
  237. package/src/modules/wallet.ts +0 -424
  238. package/src/services/example/configs.js +0 -14
  239. package/src/services/example/index.js +0 -3
  240. package/src/services/example/index.test.js +0 -28
  241. package/src/services/example/service-rpc.js +0 -11
  242. package/src/services/example/service.ts +0 -18
  243. package/src/services/keyring/configs.ts +0 -110
  244. package/src/services/keyring/index.android.js +0 -3
  245. package/src/services/keyring/index.ios.js +0 -3
  246. package/src/services/keyring/index.js +0 -1
  247. package/src/services/keyring/index.test.js +0 -48
  248. package/src/services/keyring/service-rpc.js +0 -56
  249. package/src/services/keyring/service.ts +0 -111
  250. package/src/services/polkadot/configs.ts +0 -13
  251. package/src/services/polkadot/index.android.js +0 -3
  252. package/src/services/polkadot/index.ios.js +0 -3
  253. package/src/services/polkadot/index.js +0 -1
  254. package/src/services/polkadot/index.test.js +0 -52
  255. package/src/services/polkadot/service-rpc.js +0 -13
  256. package/src/services/polkadot/service.ts +0 -21
  257. package/src/test/axiosMocks.js +0 -20
  258. package/src/test/fixtures/subscan-failure.json +0 -5
  259. package/src/test/fixtures/subscan-success.json +0 -370
  260. package/src/test/fixtures/subscan-too-many-requests.json +0 -9
  261. package/src/test/setup-test-state.js +0 -35
  262. 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.9",
3
+ "version": "1.5.10",
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.9",
22
+ "@docknetwork/wallet-sdk-dids": "^1.5.10",
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
- "@polkadot/api": "9.7.1",
36
- "@polkadot/keyring": "10.1.11",
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');
@@ -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 BigNumber from 'bignumber.js';
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
  });
@@ -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
- if (v instanceof BigNumber) {
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
- }
@@ -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.cryptoWaitReady();
13
- expect(result).toBe(true);
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
 
@@ -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('base64string')).toBe(true);
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://certs.dock.io/some-key')).toBe(false);
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
- keyDoc.keypair = keyDocToKeypair(keyDoc, blockchainService.dock);
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(keyDoc, challenge, domain, blockchainService.resolver);
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 {Bls12381G2KeyPairDock2022} from '@docknetwork/credential-sdk/vc/crypto';
3
- import {getKeyring} from '../keyring/service';
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
- const privateKeyEncoded = privateKeyBase58 || privateKeyMultibase.substr(1);
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
- const publicKeyEncoded = publicKeyBase58 || publicKeyMultibase.substr(1);
25
- const keyType = docToKeyMap[type];
26
- if (!keyType) {
27
- throw new Error(`Unsupported key type: ${type}`);
28
- }
29
-
30
- return getKeyring().createFromPair(
31
- {
32
- publicKey: bs58.decode(publicKeyEncoded),
33
- secretKey: privateKeyBytes,
34
- },
35
- {},
36
- keyType,
37
- );
59
+ throw new Error(`Unsupported key type: ${type}`);
60
+ }
61
+ }
62
+
63
+ const keyConstructors = {
64
+ Ed25519VerificationKey2018: keypairOptions =>
65
+ new ed25519VerificationKey2018.Ed25519VerificationKey2018(keypairOptions),
66
+ Ed25519VerificationKey2020: keypairOptions =>
67
+ new ed25519VerificationKey2020.Ed25519VerificationKey2020(keypairOptions),
68
+ X25519KeyAgreementKey2019: keypairOptions =>
69
+ new x25519KeyAgreementKey2019.X25519KeyAgreementKey2019(keypairOptions),
70
+ X25519KeyAgreementKey2020: keypairOptions =>
71
+ new x25519KeyAgreementKey2020.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,10 @@ 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 {getTestWallet} from '../../test/setup-test-state';
7
6
  import {blockchainService} from '../blockchain/service';
7
+ import {Ed25519Keypair} from '@docknetwork/credential-sdk/keypairs';
8
8
 
9
9
  describe('DID Service', () => {
10
- beforeAll(async () => {
11
- await getTestWallet();
12
- });
13
-
14
10
  it('ServiceRpc', () => {
15
11
  assertRpcService(DIDServiceRPC, service, validation);
16
12
  });
@@ -121,25 +117,18 @@ describe('DID Service', () => {
121
117
  expect(keyDoc.privateKeyMultibase).toBeDefined();
122
118
  });
123
119
 
124
- it('expect to generateKeyDoc with keyPair', async () => {
120
+ it('expect to deriveKeyDoc', async () => {
125
121
  const controller =
126
122
  '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
123
 
135
- const keyDoc = await service.generateKeyDoc({
124
+ const {keyPair} = Ed25519Keypair.random();
125
+
126
+ const derivedKeyDoc = await service.deriveKeyDoc({
136
127
  controller,
137
- keyPairJSON,
128
+ pair: keyPair,
138
129
  });
139
130
 
140
- expect(keyDoc.controller).toEqual(controller);
141
- expect(keyDoc.privateKeyMultibase).toEqual(
142
- 'z3ttk77Si8AUHHGAGLWue3qZacSgZDtRRCbd75Bmujx2qstznWv4ZRWtCjEKcJAUUufQpSsurEAJ47mYYKPwQnA2C',
143
- );
131
+ expect(derivedKeyDoc.controller).toEqual(controller);
132
+ expect(derivedKeyDoc.privateKeyMultibase).toBeDefined();
144
133
  });
145
134
  });