@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
@@ -1,742 +0,0 @@
1
- import assert from 'assert';
2
- import { isAddressValid } from './core/validation.mjs';
3
- import { walletService } from './services/wallet/service.mjs';
4
- import { utilCryptoService } from './services/util-crypto/service.mjs';
5
- import { keyringService } from './services/keyring/service.mjs';
6
- import { polkadotService } from './services/polkadot/service.mjs';
7
- import { v4 } from 'uuid';
8
- import { getStorage } from './core/storage.mjs';
9
- import { blockchainService } from './services/blockchain/service.mjs';
10
- import { EventManager } from './modules/event-manager.mjs';
11
- import { NetworkManager } from './modules/network-manager.mjs';
12
- import { migrate } from './modules/data-migration.mjs';
13
- import { Logger } from './core/logger.mjs';
14
- import { Errors } from './errors.mjs';
15
- import { KeypairTypes } from './types.mjs';
16
-
17
- var doc2213 = {
18
- "@context": [
19
- "https://w3id.org/wallet/v1"
20
- ],
21
- id: "credential-1652390503413",
22
- value: {
23
- "@context": [
24
- "https://www.w3.org/2018/credentials/v1",
25
- {
26
- dk: "https://ld.dock.io/credentials#",
27
- BasicCredential: "dk:BasicCredential",
28
- subjectName: "dk:subjectName",
29
- title: "dk:title",
30
- name: "dk:name",
31
- description: "dk:description",
32
- logo: "dk:logo"
33
- }
34
- ],
35
- credentialStatus: {
36
- id: "rev-reg:dock:0x8e4ff3d6de36a3e4dbd014b5979e6fc0ab1e4c0a5f1ceddae2c7c67a4b94d0de",
37
- type: "CredentialStatusList2017"
38
- },
39
- id: "https://creds.dock.io/79277556ab5504ec064492780d3678d04f9f4ec370de28537e9d5be09f11df92",
40
- type: [
41
- "VerifiableCredential",
42
- "BasicCredential"
43
- ],
44
- credentialSubject: {
45
- id: "planespotter325",
46
- subjectName: "Oleh Yatskiv",
47
- title: "Beta Testing Credential"
48
- },
49
- issuanceDate: "2022-05-10T10:06:49.346Z",
50
- proof: {
51
- type: "Ed25519Signature2018",
52
- created: "2022-05-10T10:07:08Z",
53
- verificationMethod: "did:dock:5C53c6uirausdvARD891dyyEkQE388iXhDwypkmp1nHh1odv#keys-1",
54
- proofPurpose: "assertionMethod",
55
- proofValue: "z2RVKT1jYhooV3JidULqxTwPq2R41RqPNEMf14GWMTrh2NpzoFj4uiEzkzcu3HYZ8C8Vc7qBctVALMjXferqTiJkQ"
56
- },
57
- issuer: {
58
- name: "Dock Beta Testing",
59
- description: "",
60
- logo: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAgVBMVEUyLEH///81L0T8/PwpIzkkHjRbV2iAfIkwKj8nIDcsJjs2MEQkHTQ5M0goIjguKD7U09fa2dzm5uloZHT09PU/OU1MR1pSTV+al6HIx8y/vcT29ve2tLzh4ON1cX9EPlKLh5NybnysqbJhXW2ioKqGg49+eoiVkp0YEilVUGC5t77fPQhvAAAIBElEQVR4nO2dbXfqKhOGYTAWQgwak2h8qS+17qf9/z/wCVFbDRMb056Aa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IwjlW/HFD1XVk4L+p1k3QqQ0flilDKOXx2HGxUO4hIoDMlsOi8YjkFPJ6ktksh42HAS5pxunoyLxWq/XxXFZPlFiHAkefPFgf2QBPgBkSuW6z/jT5Y+NbR+WyYEu3un3q6OtTc+VHK4cH0pBPjhitaqDgbY59AkQ9zj23KsZ9bb1Uky3ow7ndWllfMXmWU//xaE5ICOci3MQQ+8r+2QFgIS7ZLHjaKPY+2CpltO7QiCzb5plGjGoPuNhUjqvkCJacP0oxFjPBUOXkkOEJNj21s49DPJuxRu3txfRhpf96L8REHX/7LA3bvuy9gPdgtGG6cj559ZcRwF3DXvuFEZOA3ybZFeal1T9fN4/hE6bI2LQP+DD/lxj96DtFzvtzMSDdzqcpukr9cKIthM3+efxVhfTZUkyaRYHLa7XIogvJeY7Zp0SBiKSIgQsmyz2WSZVLEIgrAW/j6HQAe5nHOlFOf6BrEnZPDy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy+jP9HxFUcx6xjp2xAAAAAElFTkSuQmCC",
61
- id: "did:dock:5C53c6uirausdvARD891dyyEkQE388iXhDwypkmp1nHh1odv"
62
- }
63
- },
64
- type: "VerifiableCredential"
65
- };
66
- var legacyWalletSchema = {
67
- "doc:d4bd8145-4a56-456e-9b78-71509184f6ed": {
68
- "@context": [
69
- "https://w3id.org/wallet/v1"
70
- ],
71
- id: "6ee76a80-bdf2-4cf8-9647-4897ed6feadd",
72
- name: "Account 1",
73
- type: "Mnemonic",
74
- value: "toe crowd portion cook feel minute deny piece feel barrel member swarm"
75
- },
76
- "doc:74366f2f-a137-46f1-b661-be2956d9afb2": {
77
- "@context": [
78
- "https://w3id.org/wallet/v1"
79
- ],
80
- id: "0a7d45d3-8ca4-41a2-93c8-d4bec5652376",
81
- name: "mnemonic 1",
82
- type: "Mnemonic",
83
- value: "exact next frown coconut exit pledge blind program film elephant wife clutch"
84
- },
85
- "doc:670ef0a2-c748-45ab-9515-460d907ba529": {
86
- "@context": [
87
- "https://w3id.org/wallet/v1"
88
- ],
89
- id: "7e0b6479-59c8-4f76-95d5-d25f7413751f",
90
- name: "mnemonic1 ",
91
- type: "Mnemonic",
92
- value: "exact next frown coconut exit pledge blind program film elephant wife clutch"
93
- },
94
- "doc:497337c2-29fc-4a88-9b78-ee55abd0a500": {
95
- "@context": [
96
- "https://w3id.org/wallet/v1"
97
- ],
98
- id: "37g1HpqrRjWozRxT5MCpqUDxHQtu2ASPy6yJRD5cqKRVBefS",
99
- type: "Account",
100
- correlation: [
101
- "7e0b6479-59c8-4f76-95d5-d25f7413751f"
102
- ],
103
- meta: {
104
- name: "mnemonic1 ",
105
- keypairType: "sr25519",
106
- derivationPath: "",
107
- hasBackup: true,
108
- balance: 0
109
- }
110
- },
111
- "doc:069c5733-8516-4dff-aa91-cb3eefc3f16d": {
112
- "@context": [
113
- "https://w3id.org/wallet/v1"
114
- ],
115
- id: "80f68f17-14a8-4f2d-9865-b1477e605115",
116
- name: "test 33",
117
- type: "KeyPair",
118
- value: {
119
- encoded: "MFMCAQEwBQYDK2VwBCIEIGhWQpGhRsLAOg8FFbvjUOOZ0UZZX2OJzIKhrTJ2Od1mKEidt13wS9Kxefy98pm/8w9an45To/IuYiKX7PlDyS6hIwMhAP4WQCN9VTz2Hn18GOwXw9ZhVZyCYQnbE5DcZeMamHYt",
120
- encoding: {
121
- content: [
122
- "pkcs8",
123
- "sr25519"
124
- ],
125
- type: [
126
- "none"
127
- ],
128
- version: "3"
129
- },
130
- address: "3CH1Ce5k516MNoyJvRbq4CtuiSDisa8SF9JBqCcSYRAEzgUk",
131
- meta: {
132
- genesisHash: "0x17643cd935f8379c6683c74f739460be4ccc4e4c30b0183bdb2fb9973af242f1",
133
- isHardware: false,
134
- name: "test 33",
135
- tags: [
136
- ],
137
- whenCreated: 1654447770598
138
- }
139
- }
140
- },
141
- "doc:d56aa925-2da8-469a-ab4b-c4878e19b9fc": {
142
- "@context": [
143
- "https://w3id.org/wallet/v1"
144
- ],
145
- id: "3CH1Ce5k516MNoyJvRbq4CtuiSDisa8SF9JBqCcSYRAEzgUk",
146
- type: "Account",
147
- correlation: [
148
- "80f68f17-14a8-4f2d-9865-b1477e605115"
149
- ],
150
- meta: {
151
- name: "test 33",
152
- hasBackup: true,
153
- balance: 0
154
- }
155
- },
156
- "doc:69cfaf57-4b04-40b4-9d2a-143c4f05a2e3": {
157
- "@context": [
158
- "https://w3id.org/wallet/v1"
159
- ],
160
- id: "dd3868e5-dab7-4e43-95ac-530a65ef8917",
161
- name: "ACCOUNT NEW",
162
- type: "Mnemonic",
163
- value: "surround cotton ecology happy artist opera alert resemble jewel jaguar risk rude"
164
- },
165
- "doc:729e40eb-e36c-460e-a85b-0f9ad2fbf199": {
166
- "@context": [
167
- "https://w3id.org/wallet/v1"
168
- ],
169
- id: "3BcMTtyijuEQYBfSCR45jaZUCgEeCgLCNeJGZm336S638C7G",
170
- type: "Account",
171
- correlation: [
172
- "dd3868e5-dab7-4e43-95ac-530a65ef8917"
173
- ],
174
- meta: {
175
- name: "ACCOUNT NEW",
176
- keypairType: "sr25519",
177
- derivationPath: "",
178
- hasBackup: false,
179
- balance: 0
180
- }
181
- },
182
- doc2213: doc2213
183
- };
184
-
185
- // @ts-nocheck
186
- /** Wallet events */
187
- const WalletEvents = {
188
- ready: 'ready',
189
- error: 'error',
190
- migrated: 'migrated',
191
- statusUpdated: 'status-updated',
192
- documentAdded: 'document-added',
193
- documentUpdated: 'document-updated',
194
- documentRemoved: 'document-removed',
195
- walletDeleted: 'wallet-deleted',
196
- walletImported: 'wallet-imported',
197
- networkUpdated: 'network-updated',
198
- networkConnected: 'network-connected',
199
- networkError: 'network-error',
200
- };
201
- /**
202
- * Can be used to debug the data migration behavior in the wallet
203
- */
204
- const MOCK_STORAGE = process.env.MOCK_STORAGE;
205
- async function shouldMockStorage(walletId) {
206
- if (MOCK_STORAGE !== 'true') {
207
- return;
208
- }
209
- await getStorage().setItem(walletId, JSON.stringify(legacyWalletSchema));
210
- }
211
- // const environment = getEnvironment();
212
- // if (environment !== 'reactnative') {
213
- // require('../setup-nodejs');
214
- // }
215
- /**
216
- * Wallet
217
- */
218
- class Wallet {
219
- networkManager;
220
- context;
221
- status;
222
- apiConnected;
223
- eventManager;
224
- walletId;
225
- accounts;
226
- /**
227
- * @constructor
228
- * @param {object} params
229
- */
230
- constructor({ walletId = 'wallet', context = ['https://w3id.org/wallet/v1'], } = {}) {
231
- this.walletId = walletId;
232
- this.context = context;
233
- this.networkManager = NetworkManager.getInstance();
234
- this.eventManager = new EventManager();
235
- this.accounts = Accounts.getInstance({ wallet: this });
236
- }
237
- async recoverFromBadState() {
238
- const storageItems = await getStorage().getItem(this.walletId);
239
- const walletData = JSON.parse(storageItems);
240
- Object.keys(walletData).forEach(docKey => {
241
- const document = walletData[docKey];
242
- if (!document['@context']) {
243
- document['@context'] = this.context;
244
- }
245
- });
246
- await getStorage().setItem(this.walletId, JSON.stringify(walletData));
247
- await this.createWallet();
248
- }
249
- async createWallet() {
250
- await walletService.create({
251
- walletId: this.walletId,
252
- type: 'rpc',
253
- });
254
- await walletService.sync();
255
- await walletService.load();
256
- }
257
- /**
258
- * Get the y value.
259
- * @return {Promise} The y value.
260
- */
261
- async load() {
262
- if (this.status === 'loading') {
263
- return this.eventManager.waitFor(WalletEvents.ready);
264
- }
265
- if (this.status === 'ready') {
266
- return;
267
- }
268
- this.setStatus('loading');
269
- // TODO: get network from dataStore
270
- const networkId = (await getStorage().getItem('networkId')) || 'mainnet';
271
- this.networkManager.setNetworkId(networkId);
272
- await shouldMockStorage(this.walletId);
273
- try {
274
- await utilCryptoService.cryptoWaitReady();
275
- await keyringService.initialize({
276
- ss58Format: this.networkManager.getNetworkInfo().addressPrefix,
277
- });
278
- try {
279
- await this.createWallet();
280
- }
281
- catch (err) {
282
- await this.recoverFromBadState();
283
- }
284
- this.setStatus('ready');
285
- this.eventManager.emit(WalletEvents.ready);
286
- this.initNetwork();
287
- this.migrated = await migrate({ wallet: this });
288
- this.eventManager.emit(WalletEvents.migrated);
289
- }
290
- catch (err) {
291
- this.setStatus('error');
292
- this.eventManager.emit(WalletEvents.error, err);
293
- throw err;
294
- }
295
- }
296
- async getVersion() {
297
- const docs = await this.query({});
298
- const versionDoc = docs.find((item) => item.type === 'Metadata' && !!item.walletVersion);
299
- return (versionDoc && versionDoc.walletVersion) || '0.1';
300
- }
301
- /**
302
- *
303
- * Close wallet
304
- */
305
- async close() {
306
- await blockchainService.disconnect();
307
- this.setStatus('closed');
308
- }
309
- async switchNetwork(networkId) {
310
- getStorage().setItem('networkId', networkId);
311
- this.networkManager.setNetworkId(networkId);
312
- await this.initNetwork();
313
- }
314
- /**
315
- * delete wallet
316
- */
317
- async deleteWallet() {
318
- this.eventManager.emit(WalletEvents.walletDeleted);
319
- await getStorage().removeItem('logs');
320
- await getStorage().removeItem('transactions');
321
- await getStorage().removeItem(this.walletId);
322
- await walletService.create({
323
- walletId: this.walletId,
324
- });
325
- await walletService.load();
326
- await walletService.sync();
327
- }
328
- /**
329
- *
330
- * @param {*} status
331
- */
332
- setStatus(status) {
333
- assert(!!status, 'status is required');
334
- this.status = status;
335
- this.eventManager.emit(WalletEvents.statusUpdated, status);
336
- }
337
- /**
338
- * Ensure network
339
- *
340
- * @returns Promise
341
- */
342
- async ensureNetwork() {
343
- if (!this.connectionInProgress) {
344
- this.initNetwork();
345
- }
346
- else if (this.networkReady) {
347
- return;
348
- }
349
- await this.eventManager.waitFor(WalletEvents.networkConnected);
350
- }
351
- async initNetwork() {
352
- try {
353
- this.connectionInProgress = true;
354
- const networkInfo = this.networkManager.getNetworkInfo();
355
- await keyringService.initialize({
356
- ss58Format: networkInfo.addressPrefix,
357
- });
358
- Logger.debug(`Initializing network ${JSON.stringify(networkInfo)}`);
359
- const isDockConnected = await blockchainService.isApiConnected();
360
- if (isDockConnected) {
361
- await blockchainService.disconnect();
362
- }
363
- await blockchainService.init({
364
- cheqdApiUrl: networkInfo.cheqdApiUrl,
365
- });
366
- this.eventManager.emit(WalletEvents.networkConnected);
367
- }
368
- catch (err) {
369
- this.eventManager.emit(WalletEvents.error, err);
370
- throw err;
371
- }
372
- finally {
373
- this.connectionInProgress = false;
374
- this.networkReady = true;
375
- }
376
- }
377
- async waitReady() {
378
- if (this.status === 'ready') {
379
- return;
380
- }
381
- let warningTimeout = setTimeout(() => {
382
- throw new Error('Wallet module timed out. Make sure the wallet is loaded, or you are not using multiple instances');
383
- }, 6000);
384
- await this.eventManager.waitFor(WalletEvents.ready);
385
- clearTimeout(warningTimeout);
386
- }
387
- getContext() {
388
- return this.getContext;
389
- }
390
- setContext(context) {
391
- this.context = context;
392
- }
393
- assertReady() {
394
- return this.waitReady();
395
- }
396
- /**
397
- * Remove document
398
- * @returns Promise<boolean>
399
- */
400
- async remove(documentId) {
401
- await walletService.remove(documentId);
402
- this.eventManager.emit(WalletEvents.documentRemoved, documentId);
403
- }
404
- async upsert(document) {
405
- const existing = await this.getDocumentById(document.id);
406
- if (existing) {
407
- return this.update({
408
- ...existing,
409
- ...document,
410
- });
411
- }
412
- return this.add(document);
413
- }
414
- /**
415
- * Add document to the wallet
416
- * @param {*} options
417
- * @throws InvalidAccountErrors
418
- * @returns document
419
- */
420
- async add(document) {
421
- await this.assertReady();
422
- const newDocument = {
423
- ...document,
424
- id: document.id || v4(),
425
- '@context': document.context || this.context,
426
- };
427
- await walletService.add(newDocument);
428
- this.eventManager.emit(WalletEvents.documentAdded, newDocument);
429
- return newDocument;
430
- }
431
- async update(document) {
432
- await this.assertReady();
433
- await walletService.update({
434
- '@context': document['@context'] || this.context,
435
- ...document,
436
- });
437
- this.eventManager.emit(WalletEvents.documentUpdated, document);
438
- return document;
439
- }
440
- async export(password) {
441
- return walletService.exportWallet(password);
442
- }
443
- /**
444
- * Add all documents in the wallet
445
- * @param {*} options
446
- * @returns document
447
- */
448
- async query(params = {}) {
449
- await this.assertReady();
450
- let equals;
451
- Object.keys(params).forEach(key => {
452
- const value = params[key];
453
- if (!value) {
454
- return;
455
- }
456
- if (!equals) {
457
- equals = {};
458
- }
459
- equals[`content.${key}`] = value;
460
- });
461
- return walletService.query({
462
- equals,
463
- });
464
- }
465
- async getDocumentById(documentId) {
466
- await this.assertReady();
467
- const result = await this.query({ id: documentId });
468
- return result[0];
469
- }
470
- static async create({ walletId, json, password } = {}) {
471
- const wallet = new Wallet({ walletId });
472
- await wallet.load();
473
- if (json) {
474
- await wallet.importWallet({ json, password });
475
- }
476
- return wallet;
477
- }
478
- async importWallet({ json, password }) {
479
- await this.deleteWallet();
480
- await walletService.importWallet({ json, password });
481
- this.migrated = await migrate({ wallet: this });
482
- await this.eventManager.emit(WalletEvents.walletImported);
483
- }
484
- async getDocumentsFromEncryptedWallet({ encryptedJSONWallet, password }) {
485
- return walletService.getDocumentsFromEncryptedWallet({
486
- encryptedJSONWallet,
487
- password,
488
- });
489
- }
490
- async resolveCorrelations(documentId) {
491
- return walletService.resolveCorrelations(documentId);
492
- }
493
- async exportDocuments({ documents, password }) {
494
- return walletService.exportDocuments({
495
- documents,
496
- password,
497
- });
498
- }
499
- /**
500
- * Get wallet module instance
501
- * @returns Wallet
502
- */
503
- static getInstance() {
504
- if (!Wallet.instance) {
505
- Wallet.instance = new Wallet();
506
- }
507
- return Wallet.instance;
508
- }
509
- }
510
-
511
- // @ts-nocheck
512
- const AccountsEvents = {
513
- loaded: 'loaded',
514
- accountCreated: 'account-added',
515
- accountUpdated: 'account-updated',
516
- accountRemoved: 'account-removed',
517
- };
518
- class Accounts {
519
- accounts;
520
- wallet;
521
- eventManager;
522
- static DocumentFilters = {
523
- mnemonicType: (item) => item.type === 'Mnemonic',
524
- currencyType: (item) => item.type === 'Currency',
525
- };
526
- constructor({ wallet, walletService: walletService$1 } = {}) {
527
- this.accounts = [];
528
- this.wallet = wallet || Wallet.getInstance();
529
- this.walletService = walletService$1 || walletService;
530
- this.eventManager = new EventManager();
531
- }
532
- async load() {
533
- this.accounts = await this.wallet.query({
534
- type: 'Address',
535
- });
536
- this.eventManager.emit(AccountsEvents.loaded);
537
- return this.accounts;
538
- }
539
- async exportAccount(address, password) {
540
- return this.walletService.exportAccount({ address, password });
541
- }
542
- async importAccount(json, password) {
543
- return this.create({
544
- json,
545
- password,
546
- });
547
- }
548
- async getBalance(address, skipFetch) {
549
- assert(isAddressValid(address), 'address is required');
550
- if (!skipFetch) {
551
- await this.fetchBalance(address);
552
- }
553
- const currency = await this.findCorrelationByType(address, 'Currency', true);
554
- return currency.value;
555
- }
556
- getAccounts() {
557
- return this.accounts;
558
- }
559
- getAccountIcon(address, isAlternative) {
560
- return polkadotService.getPolkadotSvgIcon(address, isAlternative);
561
- }
562
- async getByAddress(address) {
563
- return Account.with(address);
564
- }
565
- async findCorrelationByType(address, type, assertResult) {
566
- assert(isAddressValid(address), 'invalid address');
567
- const correlations = await this.wallet.resolveCorrelations(address);
568
- const result = correlations.find(c => c.type.includes(type));
569
- if (assertResult) {
570
- assert(!!result, `${type} document not found for the account ${address}`);
571
- }
572
- return result;
573
- }
574
- generateMnemonic() {
575
- return utilCryptoService.mnemonicGenerate(12);
576
- }
577
- async update(account) {
578
- assert(!!account, 'account is required');
579
- await this.walletService.update(account);
580
- this.eventManager.emit(AccountsEvents.accountUpdated);
581
- await this.load();
582
- }
583
- async getOrCreate(params) {
584
- return this.create({
585
- ...params,
586
- getIfExists: true,
587
- });
588
- }
589
- async create(params) {
590
- let { name, json, password, type = 'sr25519', getIfExists, hasBackup } = params;
591
- assert(!!name, 'name is required');
592
- assert(!!type, 'keypair type is required');
593
- assert(KeypairTypes.find(t => t === type), `invalid keypair type ${type}`);
594
- if (json) {
595
- assert(typeof password === 'string', 'password is required');
596
- }
597
- const mnemonic = params.mnemonic || (!json && (await this.generateMnemonic()));
598
- const derivePath = params.derivationPath || '';
599
- const address = json
600
- ? json.address
601
- : await keyringService.addressFromUri({
602
- mnemonic,
603
- type,
604
- derivePath,
605
- });
606
- const existingAccountDocs = await this.wallet.query({
607
- id: address,
608
- });
609
- const accountExists = existingAccountDocs.length > 0;
610
- if (getIfExists && accountExists) {
611
- return this.getByAddress(address);
612
- }
613
- assert(!accountExists, Errors.accountAlreadyExists);
614
- if (json) {
615
- const pair = await keyringService.decryptKeyPair({
616
- jsonData: json,
617
- password,
618
- });
619
- assert(pair && pair.address, 'invalid keypair');
620
- type = pair.type;
621
- }
622
- const account = {
623
- id: address,
624
- name,
625
- type,
626
- address,
627
- };
628
- const documents = await this.walletService.createAccountDocuments({
629
- name,
630
- type,
631
- derivePath,
632
- mnemonic,
633
- json,
634
- password,
635
- hasBackup,
636
- });
637
- documents.forEach(doc => {
638
- this.wallet.eventManager.emit(WalletEvents.documentAdded, doc);
639
- });
640
- this.eventManager.emit(AccountsEvents.accountCreated, account);
641
- await this.load();
642
- return Account.withAsync(account.address, this);
643
- }
644
- async remove(accountId) {
645
- await this.wallet.remove(accountId);
646
- // remove other documents
647
- // mnemonic phrase and all the stuff
648
- this.eventManager.emit(AccountsEvents.accountRemoved, accountId);
649
- this.load();
650
- }
651
- static getInstance(options) {
652
- if (!Accounts.instance || options) {
653
- Accounts.instance = new Accounts(options);
654
- }
655
- return Accounts.instance;
656
- }
657
- }
658
-
659
- // @ts-nocheck
660
- /**
661
- * Account
662
- */
663
- class Account {
664
- details;
665
- address;
666
- name;
667
- accounts;
668
- constructor(address, accounts) {
669
- this.accounts = accounts;
670
- this.address = address;
671
- this.id = address;
672
- }
673
- /**
674
- * Get account for a given address
675
- * The account needs to exist in the wallet
676
- *
677
- * @example
678
- * const accounts = Account.with('some-address')
679
- * @param {string} address
680
- * @returns
681
- */
682
- static with(address, accounts) {
683
- assert(isAddressValid(address), 'invalid address');
684
- const account = new Account(address, accounts || Accounts.getInstance());
685
- account.loadPromise = account.loadDetails();
686
- return account;
687
- }
688
- /**
689
- *
690
- * @param {string} address
691
- * @returns
692
- */
693
- static async withAsync(address, accounts) {
694
- const account = Account.with(address, accounts);
695
- await account.loadPromise;
696
- return account;
697
- }
698
- /**
699
- * @returns {Promise<void>}
700
- */
701
- async loadDetails() {
702
- this.details = await this.accounts.wallet.getDocumentById(this.id);
703
- this.name = this.details && this.details.name;
704
- }
705
- getAddress() {
706
- return this.details.address;
707
- }
708
- getDetails() {
709
- return this.details;
710
- }
711
- async getBalance(skipFetch) {
712
- return this.accounts.getBalance(this.details.address, skipFetch);
713
- }
714
- export(password) {
715
- return this.accounts.exportAccount(this.address, password);
716
- }
717
- remove() {
718
- return this.accounts.remove(this.address);
719
- }
720
- update({ name }) {
721
- return this.accounts.update({
722
- ...this.details,
723
- name,
724
- });
725
- }
726
- async getMnemonic() {
727
- const doc = await this.accounts.findCorrelationByType(this.address, 'Mnemonic');
728
- return doc.value;
729
- }
730
- async getKeyPair() {
731
- const doc = await this.accounts.findCorrelationByType(this.address, 'KeyringPair');
732
- return doc.value;
733
- }
734
- getName() {
735
- return this.details.name;
736
- }
737
- getIcon(isAlternative) {
738
- return this.accounts.getAccountIcon(this.details.address, isAlternative);
739
- }
740
- }
741
-
742
- export { AccountsEvents as A, Wallet as W, WalletEvents as a, Accounts as b, Account as c };