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