@docknetwork/wallet-sdk-wasm 1.5.9 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/format-utils.js +0 -28
- package/lib/core/format-utils.mjs +1 -24
- package/lib/core/validation.js +1 -24
- package/lib/core/validation.mjs +2 -21
- package/lib/index.js +13 -23
- package/lib/index.mjs +13 -23
- package/lib/rpc-server.js +13 -23
- package/lib/rpc-server.mjs +13 -23
- package/lib/rpc-util.js +14 -0
- package/lib/rpc-util.mjs +14 -0
- package/lib/services/blockchain/index.js +3 -6
- package/lib/services/blockchain/index.mjs +3 -6
- package/lib/services/blockchain/service.js +5 -9
- package/lib/services/blockchain/service.mjs +5 -9
- package/lib/services/credential/bbs-revocation.js +4 -7
- package/lib/services/credential/bbs-revocation.mjs +3 -6
- package/lib/services/credential/bound-check.js +9 -4
- package/lib/services/credential/bound-check.mjs +9 -4
- package/lib/services/credential/index.js +11 -13
- package/lib/services/credential/index.mjs +11 -13
- package/lib/services/credential/service.js +18 -18
- package/lib/services/credential/service.mjs +15 -15
- package/lib/services/credential/utils.js +59 -28
- package/lib/services/credential/utils.mjs +62 -32
- package/lib/services/dids/index.js +7 -25
- package/lib/services/dids/index.mjs +7 -25
- package/lib/services/dids/keypair-utils.js +142 -0
- package/lib/services/dids/keypair-utils.mjs +113 -0
- package/lib/services/dids/service-rpc.js +0 -3
- package/lib/services/dids/service-rpc.mjs +0 -3
- package/lib/services/dids/service.js +13 -55
- package/lib/services/dids/service.mjs +13 -54
- package/lib/services/edv/index.js +4 -25
- package/lib/services/edv/index.mjs +4 -25
- package/lib/services/edv/service.js +6 -33
- package/lib/services/edv/service.mjs +6 -33
- package/lib/services/index.js +13 -25
- package/lib/services/index.mjs +13 -25
- package/lib/services/relay-service/configs.js +0 -1
- package/lib/services/relay-service/configs.mjs +0 -1
- package/lib/services/relay-service/index.android.js +0 -1
- package/lib/services/relay-service/index.android.mjs +0 -1
- package/lib/services/relay-service/index.ios.js +0 -1
- package/lib/services/relay-service/index.ios.mjs +0 -1
- package/lib/services/relay-service/index.js +0 -1
- package/lib/services/relay-service/index.mjs +0 -1
- package/lib/services/relay-service/service-rpc.js +0 -1
- package/lib/services/relay-service/service-rpc.mjs +0 -1
- package/lib/services/relay-service/service.js +0 -1
- package/lib/services/relay-service/service.mjs +0 -1
- package/lib/services/test-utils.js +0 -44
- package/lib/services/test-utils.mjs +1 -44
- package/lib/services/util-crypto/configs.js +0 -12
- package/lib/services/util-crypto/configs.mjs +0 -12
- package/lib/services/util-crypto/index.android.js +0 -3
- package/lib/services/util-crypto/index.android.mjs +0 -3
- package/lib/services/util-crypto/index.ios.js +0 -3
- package/lib/services/util-crypto/index.ios.mjs +0 -3
- package/lib/services/util-crypto/index.js +4 -7
- package/lib/services/util-crypto/index.mjs +4 -7
- package/lib/services/util-crypto/service-rpc.js +2 -30
- package/lib/services/util-crypto/service-rpc.mjs +2 -30
- package/lib/services/util-crypto/service.js +68 -61
- package/lib/services/util-crypto/service.mjs +50 -59
- package/lib/services/wallet/configs.js +0 -63
- package/lib/services/wallet/configs.mjs +1 -64
- package/lib/services/wallet/index.android.js +0 -1
- package/lib/services/wallet/index.android.mjs +0 -1
- package/lib/services/wallet/index.ios.js +0 -1
- package/lib/services/wallet/index.ios.mjs +0 -1
- package/lib/services/wallet/index.js +2 -12
- package/lib/services/wallet/index.mjs +2 -12
- package/lib/services/wallet/service-rpc.js +0 -77
- package/lib/services/wallet/service-rpc.mjs +0 -77
- package/lib/services/wallet/service.js +1 -215
- package/lib/services/wallet/service.mjs +1 -211
- package/lib/setup-nodejs.js +13 -23
- package/lib/setup-nodejs.mjs +13 -23
- package/lib/setup-tests.js +13 -23
- package/lib/setup-tests.mjs +13 -23
- package/lib/src/core/format-utils.d.ts +0 -5
- package/lib/src/core/format-utils.d.ts.map +1 -1
- package/lib/src/core/validation.d.ts +0 -3
- package/lib/src/core/validation.d.ts.map +1 -1
- package/lib/src/rpc-util.d.ts.map +1 -1
- package/lib/src/services/blockchain/service.d.ts.map +1 -1
- package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
- package/lib/src/services/credential/bound-check.d.ts +1 -1
- package/lib/src/services/credential/bound-check.d.ts.map +1 -1
- package/lib/src/services/credential/service.d.ts.map +1 -1
- package/lib/src/services/credential/utils.d.ts +2 -1
- package/lib/src/services/credential/utils.d.ts.map +1 -1
- package/lib/src/services/dids/keypair-utils.d.ts +15 -0
- package/lib/src/services/dids/keypair-utils.d.ts.map +1 -0
- package/lib/src/services/dids/service-rpc.d.ts +0 -1
- package/lib/src/services/dids/service-rpc.d.ts.map +1 -1
- package/lib/src/services/dids/service.d.ts +11 -8
- package/lib/src/services/dids/service.d.ts.map +1 -1
- package/lib/src/services/edv/service.d.ts.map +1 -1
- package/lib/src/services/util-crypto/configs.d.ts +0 -3
- package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
- package/lib/src/services/util-crypto/service.d.ts +3 -8
- package/lib/src/services/util-crypto/service.d.ts.map +1 -1
- package/lib/src/services/wallet/configs.d.ts +13 -0
- package/lib/src/services/wallet/configs.d.ts.map +1 -0
- package/lib/src/services/wallet/service.d.ts +1 -44
- package/lib/src/services/wallet/service.d.ts.map +1 -1
- package/lib/test-utils.js +0 -4
- package/lib/test-utils.mjs +1 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -25
- package/readme.md +0 -61
- package/src/core/format-utils.test.js +1 -28
- package/src/core/format-utils.ts +0 -33
- package/src/core/validation.test.js +1 -33
- package/src/core/validation.ts +1 -25
- package/src/rpc-server.test.js +2 -9
- package/src/rpc-util.js +14 -0
- package/src/services/blockchain/service.ts +2 -3
- package/src/services/credential/bbs-revocation.ts +2 -1
- package/src/services/credential/bound-check.test.ts +6 -6
- package/src/services/credential/bound-check.ts +4 -4
- package/src/services/credential/index.test.js +0 -2
- package/src/services/credential/service.ts +5 -2
- package/src/services/credential/utils.js +65 -23
- package/src/services/dids/index.test.js +45 -33
- package/src/services/dids/keypair-utils.js +111 -0
- package/src/services/dids/service-rpc.ts +0 -3
- package/src/services/dids/service.ts +7 -34
- package/src/services/edv/service.ts +2 -9
- package/src/services/index.js +0 -4
- package/src/services/test-utils.js +0 -29
- package/src/services/util-crypto/configs.ts +0 -12
- package/src/services/util-crypto/index.test.js +6 -83
- package/src/services/util-crypto/service-rpc.js +2 -27
- package/src/services/util-crypto/service.ts +62 -75
- package/src/services/wallet/configs.ts +1 -113
- package/src/services/wallet/index.test.js +0 -159
- package/src/services/wallet/service-rpc.js +1 -88
- package/src/services/wallet/service.ts +0 -258
- package/src/test-utils.js +0 -13
- package/lib/account-357ab05d.js +0 -742
- package/lib/account-399e6053.js +0 -752
- package/lib/core/polkadot-utils.js +0 -119
- package/lib/core/polkadot-utils.mjs +0 -94
- package/lib/core/realm-schemas.js +0 -50
- package/lib/core/realm-schemas.mjs +0 -44
- package/lib/core/subscan.js +0 -75
- package/lib/core/subscan.mjs +0 -64
- package/lib/fixtures.js +0 -56
- package/lib/fixtures.mjs +0 -52
- package/lib/modules/account.js +0 -48
- package/lib/modules/account.mjs +0 -40
- package/lib/modules/accounts.js +0 -49
- package/lib/modules/accounts.mjs +0 -40
- package/lib/modules/data-migration.js +0 -72
- package/lib/modules/data-migration.mjs +0 -68
- package/lib/modules/wallet-backup.js +0 -82
- package/lib/modules/wallet-backup.mjs +0 -71
- package/lib/modules/wallet.js +0 -49
- package/lib/modules/wallet.mjs +0 -40
- package/lib/services/example/configs.js +0 -21
- package/lib/services/example/configs.mjs +0 -13
- package/lib/services/example/index.js +0 -18
- package/lib/services/example/index.mjs +0 -14
- package/lib/services/example/service-rpc.js +0 -25
- package/lib/services/example/service-rpc.mjs +0 -21
- package/lib/services/example/service.js +0 -25
- package/lib/services/example/service.mjs +0 -20
- package/lib/services/keyring/configs.js +0 -70
- package/lib/services/keyring/configs.mjs +0 -61
- package/lib/services/keyring/index.android.js +0 -22
- package/lib/services/keyring/index.android.mjs +0 -18
- package/lib/services/keyring/index.ios.js +0 -22
- package/lib/services/keyring/index.ios.mjs +0 -18
- package/lib/services/keyring/index.js +0 -16
- package/lib/services/keyring/index.mjs +0 -8
- package/lib/services/keyring/service-rpc.js +0 -65
- package/lib/services/keyring/service-rpc.mjs +0 -61
- package/lib/services/keyring/service.js +0 -84
- package/lib/services/keyring/service.mjs +0 -74
- package/lib/services/polkadot/configs.js +0 -17
- package/lib/services/polkadot/configs.mjs +0 -13
- package/lib/services/polkadot/index.android.js +0 -22
- package/lib/services/polkadot/index.android.mjs +0 -18
- package/lib/services/polkadot/index.ios.js +0 -22
- package/lib/services/polkadot/index.ios.mjs +0 -18
- package/lib/services/polkadot/index.js +0 -15
- package/lib/services/polkadot/index.mjs +0 -7
- package/lib/services/polkadot/service-rpc.js +0 -30
- package/lib/services/polkadot/service-rpc.mjs +0 -26
- package/lib/services/polkadot/service.js +0 -28
- package/lib/services/polkadot/service.mjs +0 -23
- package/lib/src/core/polkadot-utils.d.ts +0 -11
- package/lib/src/core/polkadot-utils.d.ts.map +0 -1
- package/lib/src/modules/account.d.ts +0 -60
- package/lib/src/modules/account.d.ts.map +0 -1
- package/lib/src/modules/accounts.d.ts +0 -48
- package/lib/src/modules/accounts.d.ts.map +0 -1
- package/lib/src/modules/data-migration.d.ts +0 -7
- package/lib/src/modules/data-migration.d.ts.map +0 -1
- package/lib/src/modules/wallet-backup.d.ts +0 -12
- package/lib/src/modules/wallet-backup.d.ts.map +0 -1
- package/lib/src/modules/wallet.d.ts +0 -134
- package/lib/src/modules/wallet.d.ts.map +0 -1
- package/lib/src/services/blockchain/index.d.ts +0 -2
- package/lib/src/services/blockchain/index.d.ts.map +0 -1
- package/lib/src/services/example/configs.d.ts +0 -9
- package/lib/src/services/example/configs.d.ts.map +0 -1
- package/lib/src/services/example/service.d.ts +0 -8
- package/lib/src/services/example/service.d.ts.map +0 -1
- package/lib/src/services/keyring/configs.d.ts +0 -39
- package/lib/src/services/keyring/configs.d.ts.map +0 -1
- package/lib/src/services/keyring/index.d.ts +0 -2
- package/lib/src/services/keyring/index.d.ts.map +0 -1
- package/lib/src/services/polkadot/configs.d.ts +0 -8
- package/lib/src/services/polkadot/configs.d.ts.map +0 -1
- package/lib/src/services/polkadot/index.d.ts +0 -2
- package/lib/src/services/polkadot/index.d.ts.map +0 -1
- package/lib/src/services/polkadot/service.d.ts +0 -8
- package/lib/src/services/polkadot/service.d.ts.map +0 -1
- package/lib/src/services/wallet/index.d.ts +0 -2
- package/lib/src/services/wallet/index.d.ts.map +0 -1
- package/lib/test/axiosMocks.js +0 -431
- package/lib/test/axiosMocks.mjs +0 -420
- package/lib/test/setup-test-state.js +0 -81
- package/lib/test/setup-test-state.mjs +0 -73
- package/src/core/polkadot-utils.js +0 -99
- package/src/core/realm-schemas.js +0 -42
- package/src/core/subscan.js +0 -62
- package/src/core/subscan.test.js +0 -56
- package/src/fixtures.js +0 -43
- package/src/modules/account.test.js +0 -56
- package/src/modules/account.ts +0 -128
- package/src/modules/accounts.test.js +0 -63
- package/src/modules/accounts.ts +0 -231
- package/src/modules/data-migration.test.js +0 -61
- package/src/modules/data-migration.ts +0 -86
- package/src/modules/wallet-backup.test.js +0 -24
- package/src/modules/wallet-backup.ts +0 -68
- package/src/modules/wallet.test.js +0 -216
- package/src/modules/wallet.ts +0 -424
- package/src/services/example/configs.js +0 -14
- package/src/services/example/index.js +0 -3
- package/src/services/example/index.test.js +0 -28
- package/src/services/example/service-rpc.js +0 -11
- package/src/services/example/service.ts +0 -18
- package/src/services/keyring/configs.ts +0 -110
- package/src/services/keyring/index.android.js +0 -3
- package/src/services/keyring/index.ios.js +0 -3
- package/src/services/keyring/index.js +0 -1
- package/src/services/keyring/index.test.js +0 -48
- package/src/services/keyring/service-rpc.js +0 -56
- package/src/services/keyring/service.ts +0 -111
- package/src/services/polkadot/configs.ts +0 -13
- package/src/services/polkadot/index.android.js +0 -3
- package/src/services/polkadot/index.ios.js +0 -3
- package/src/services/polkadot/index.js +0 -1
- package/src/services/polkadot/index.test.js +0 -52
- package/src/services/polkadot/service-rpc.js +0 -13
- package/src/services/polkadot/service.ts +0 -21
- package/src/test/axiosMocks.js +0 -20
- package/src/test/fixtures/subscan-failure.json +0 -5
- package/src/test/fixtures/subscan-success.json +0 -370
- package/src/test/fixtures/subscan-too-many-requests.json +0 -9
- package/src/test/setup-test-state.js +0 -35
- package/src/test/test-wallet.test.js +0 -15
|
@@ -1,59 +1,8 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import assert from 'assert';
|
|
3
|
-
import {
|
|
4
|
-
assertAddress,
|
|
5
|
-
assertKeyType,
|
|
6
|
-
assertPassword,
|
|
7
|
-
} from '../../core/validation';
|
|
8
|
-
import {KeypairType} from '../../types';
|
|
9
|
-
|
|
10
|
-
function assertContent(content: WalletContent) {
|
|
11
|
-
assert(typeof content === 'object', 'invalid wallet content');
|
|
12
|
-
assert(typeof content.id === 'string', `invalid content id ${content.id}`);
|
|
13
|
-
assert(
|
|
14
|
-
typeof content.type === 'string',
|
|
15
|
-
`invalid content type ${content.type}`,
|
|
16
|
-
);
|
|
17
|
-
}
|
|
3
|
+
import {assertPassword} from '../../core/validation';
|
|
18
4
|
|
|
19
5
|
export const validation = {
|
|
20
|
-
getDocumentById(id: string) {
|
|
21
|
-
assert(typeof id === 'string', 'invalid documentId');
|
|
22
|
-
assert(!!id, 'documentId is required');
|
|
23
|
-
},
|
|
24
|
-
resolveCorrelations(address) {
|
|
25
|
-
assert(typeof address === 'string', 'invalid documentId');
|
|
26
|
-
assert(!!address, 'documentId is required');
|
|
27
|
-
},
|
|
28
|
-
exportAccount({address, password}: ExportAccountParams) {
|
|
29
|
-
assertAddress(address);
|
|
30
|
-
assertPassword(password);
|
|
31
|
-
},
|
|
32
|
-
create({walletId}: CreateParams): Promise<any> {
|
|
33
|
-
assert(typeof walletId === 'string', `invalid walletId ${walletId}`);
|
|
34
|
-
},
|
|
35
|
-
lock(password: string) {
|
|
36
|
-
assertPassword(password);
|
|
37
|
-
},
|
|
38
|
-
unlock(password: string) {
|
|
39
|
-
assertPassword(password);
|
|
40
|
-
},
|
|
41
|
-
add(params: AddParams) {
|
|
42
|
-
assertContent(params);
|
|
43
|
-
},
|
|
44
|
-
remove(id: string) {
|
|
45
|
-
assert(typeof id === 'string', 'invalid documentId');
|
|
46
|
-
assert(!!id, 'documentId is required');
|
|
47
|
-
},
|
|
48
|
-
update(params: UpdateParams) {
|
|
49
|
-
assertContent(params);
|
|
50
|
-
},
|
|
51
|
-
query(params: QueryParams) {
|
|
52
|
-
assert(typeof params === 'object', 'invalid query');
|
|
53
|
-
},
|
|
54
|
-
exportWallet(password: string) {
|
|
55
|
-
assertPassword(password);
|
|
56
|
-
},
|
|
57
6
|
getDocumentsFromEncryptedWallet({
|
|
58
7
|
encryptedJSONWallet,
|
|
59
8
|
password,
|
|
@@ -64,10 +13,6 @@ export const validation = {
|
|
|
64
13
|
);
|
|
65
14
|
assertPassword(password);
|
|
66
15
|
},
|
|
67
|
-
importWallet({json, password}: ImportWalletParams) {
|
|
68
|
-
assert(typeof json === 'object', `invalid json data: ${json}`);
|
|
69
|
-
assertPassword(password);
|
|
70
|
-
},
|
|
71
16
|
exportDocuments({documents, password}: ExportDocuments) {
|
|
72
17
|
assert(Array.isArray(documents), 'Invalid Documents');
|
|
73
18
|
assert(documents.length > 0, 'Cannot export empty documents');
|
|
@@ -81,50 +26,10 @@ export const validation = {
|
|
|
81
26
|
|
|
82
27
|
assertPassword(password);
|
|
83
28
|
},
|
|
84
|
-
createAccountDocuments(params: CreateAccountDocumentsParams) {
|
|
85
|
-
const {name, json, password, mnemonic, type} = params;
|
|
86
|
-
|
|
87
|
-
// Property derivationPath was replaced by derivePath
|
|
88
|
-
assert(
|
|
89
|
-
!params.derivationPath,
|
|
90
|
-
'invalid parameter derivationPath, it should be derivePath instead',
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
assert(typeof name === 'string', `invalid account name: ${name}`);
|
|
94
|
-
|
|
95
|
-
if (json) {
|
|
96
|
-
assert(typeof json === 'object', `invalid json: ${password}`);
|
|
97
|
-
assert(typeof password === 'string', `invalid password: ${password}`);
|
|
98
|
-
} else {
|
|
99
|
-
assert(typeof mnemonic === 'string', `invalid mnemonic: ${mnemonic}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (type) {
|
|
103
|
-
assertKeyType(type);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
29
|
};
|
|
107
30
|
|
|
108
31
|
export const serviceName = 'wallet';
|
|
109
32
|
|
|
110
|
-
export type WalletContent = {
|
|
111
|
-
'@context'?: string[],
|
|
112
|
-
name?: any,
|
|
113
|
-
id: any,
|
|
114
|
-
type: DocumentType,
|
|
115
|
-
value?: any,
|
|
116
|
-
correlation?: any[],
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export type CreateAccountDocumentsParams = {
|
|
120
|
-
name: string,
|
|
121
|
-
json?: string,
|
|
122
|
-
password?: string,
|
|
123
|
-
mnemonic?: string,
|
|
124
|
-
type?: KeypairType,
|
|
125
|
-
derivePath?: string,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
33
|
export type GetDocumentsFromEncryptedWallet = {
|
|
129
34
|
encryptedJSONWallet: any,
|
|
130
35
|
password: string,
|
|
@@ -133,20 +38,3 @@ export type GetDocumentsFromEncryptedWallet = {
|
|
|
133
38
|
export type ExportDocuments = {
|
|
134
39
|
documents: Array<any>,
|
|
135
40
|
};
|
|
136
|
-
|
|
137
|
-
export type QueryParams = any;
|
|
138
|
-
export type AddParams = WalletContenxt;
|
|
139
|
-
export type UpdateParams = WalletContent;
|
|
140
|
-
export type RemoveParams = string;
|
|
141
|
-
export type ImportWalletParams = {
|
|
142
|
-
json: string,
|
|
143
|
-
password: string,
|
|
144
|
-
};
|
|
145
|
-
export type ExportAccountParams = {
|
|
146
|
-
address: string,
|
|
147
|
-
password: string,
|
|
148
|
-
};
|
|
149
|
-
export type CreateParams = {
|
|
150
|
-
walletId: string,
|
|
151
|
-
type: string,
|
|
152
|
-
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {mnemonicGenerate} from '@polkadot/util-crypto';
|
|
2
|
-
import {NetworkManager} from '../../modules/network-manager';
|
|
3
|
-
import {keyringService} from '../keyring/service';
|
|
4
1
|
import {assertRpcService, getPromiseError} from '../test-utils';
|
|
5
2
|
import {validation} from './configs';
|
|
6
3
|
import {walletService as service, walletService} from './service';
|
|
@@ -11,163 +8,7 @@ describe('WalletService', () => {
|
|
|
11
8
|
assertRpcService(WalletServiceRpc, service, validation);
|
|
12
9
|
});
|
|
13
10
|
|
|
14
|
-
let accountDocuments;
|
|
15
|
-
let testAccount;
|
|
16
|
-
|
|
17
11
|
describe('service', () => {
|
|
18
|
-
beforeAll(async () => {
|
|
19
|
-
await keyringService.initialize({
|
|
20
|
-
ss58Format: NetworkManager.getInstance().getNetworkInfo().addressPrefix,
|
|
21
|
-
});
|
|
22
|
-
await service.create({
|
|
23
|
-
walletId: 'test',
|
|
24
|
-
type: 'memory',
|
|
25
|
-
});
|
|
26
|
-
await service.load();
|
|
27
|
-
await service.sync();
|
|
28
|
-
accountDocuments = await service.createAccountDocuments({
|
|
29
|
-
mnemonic: mnemonicGenerate(12),
|
|
30
|
-
name: 'test',
|
|
31
|
-
type: 'sr25519',
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
testAccount = accountDocuments[0];
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getDocumentById', () => {
|
|
38
|
-
it('expect to sum numbers', async () => {
|
|
39
|
-
const result = await service.getDocumentById(testAccount.id);
|
|
40
|
-
expect(result.id).toBe(testAccount.id);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('expect to validate params', async () => {
|
|
44
|
-
const error = await getPromiseError(() =>
|
|
45
|
-
service.getDocumentById(null),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(error.message).toBe('invalid documentId');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('getAccountKeypair', () => {
|
|
53
|
-
it('expect to validate params', async () => {
|
|
54
|
-
const error = await getPromiseError(() =>
|
|
55
|
-
service.getDocumentById(null),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
expect(error.message).toBe('invalid documentId');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('createAccountDocuments', () => {
|
|
63
|
-
const params = {
|
|
64
|
-
derivationPath: '',
|
|
65
|
-
mnemonic: mnemonicGenerate(12),
|
|
66
|
-
type: 'sr25519',
|
|
67
|
-
name: 'Test account',
|
|
68
|
-
};
|
|
69
|
-
let documents;
|
|
70
|
-
let correlation;
|
|
71
|
-
|
|
72
|
-
beforeAll(async () => {
|
|
73
|
-
documents = await service.createAccountDocuments(params);
|
|
74
|
-
correlation = await service.resolveCorrelations(documents[0].id);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('expect to create 4 documents', () => {
|
|
78
|
-
expect(documents.length).toBe(4);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('expect to create address document ', () => {
|
|
82
|
-
const document = correlation.find(doc => doc.type === 'Address');
|
|
83
|
-
expect(document.value).toBe(documents[0].id);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('expect to create mnemonic document', () => {
|
|
87
|
-
const document = correlation.find(doc => doc.type === 'Mnemonic');
|
|
88
|
-
expect(document.value).toBe(params.mnemonic);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('expect to create keyringPair document', () => {
|
|
92
|
-
const document = correlation.find(doc => doc.type === 'KeyringPair');
|
|
93
|
-
const keyringPairJson = document.value;
|
|
94
|
-
const keyringPair = keyringService.decryptKeyPair({
|
|
95
|
-
jsonData: keyringPairJson,
|
|
96
|
-
password: '',
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
expect(keyringPair.address).toBe(documents[0].value);
|
|
100
|
-
expect(keyringPair.type).toBe(params.type);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('expect to create DOCK currency document', () => {
|
|
104
|
-
const document = correlation.find(doc => doc.type === 'Currency');
|
|
105
|
-
expect(document.value).toBe(0);
|
|
106
|
-
expect(document.symbol).toBe('DOCK');
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('exportAccount', () => {
|
|
111
|
-
it('expect to export account', async () => {
|
|
112
|
-
const result = await service.exportAccount({
|
|
113
|
-
address: testAccount.id,
|
|
114
|
-
password: '123',
|
|
115
|
-
});
|
|
116
|
-
expect(result.address).toBe(testAccount.id);
|
|
117
|
-
const pair = keyringService.addFromJson({
|
|
118
|
-
jsonData: result,
|
|
119
|
-
password: '123',
|
|
120
|
-
});
|
|
121
|
-
expect(pair.address).toBe(testAccount.id);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('expect to validate params', async () => {
|
|
125
|
-
const error = await getPromiseError(() =>
|
|
126
|
-
service.exportAccount({
|
|
127
|
-
address: undefined,
|
|
128
|
-
password: null,
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
expect(error.message).toBe('invalid address: undefined');
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('exportWallet', () => {
|
|
136
|
-
it('expect to export account', async () => {
|
|
137
|
-
const result = await service.exportWallet('123');
|
|
138
|
-
expect(result.id).toBeDefined();
|
|
139
|
-
expect(result['@context']).toBeDefined();
|
|
140
|
-
expect(result.type).toBeDefined();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('expect to validate params', async () => {
|
|
144
|
-
const error = await getPromiseError(() =>
|
|
145
|
-
service.exportWallet(undefined),
|
|
146
|
-
);
|
|
147
|
-
expect(error.message).toBe('invalid password: undefined');
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('importWallet', () => {
|
|
152
|
-
it('expect to export account', async () => {
|
|
153
|
-
const json = await service.exportWallet('123');
|
|
154
|
-
await walletService.removeAll();
|
|
155
|
-
await service.importWallet({json, password: '123'});
|
|
156
|
-
for (let doc of accountDocuments) {
|
|
157
|
-
const walletDoc = await walletService.getDocumentById(doc.id);
|
|
158
|
-
delete walletDoc.hasBackup;
|
|
159
|
-
delete doc.hasBackup;
|
|
160
|
-
expect(walletDoc).toStrictEqual(doc);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('expect to validate params', async () => {
|
|
165
|
-
const error = await getPromiseError(() =>
|
|
166
|
-
service.importWallet({json: undefined}),
|
|
167
|
-
);
|
|
168
|
-
expect(error.message).toBe('invalid json data: undefined');
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
12
|
describe('getDocumentsFromEncryptedWallet', () => {
|
|
172
13
|
it('expect to validate params', async () => {
|
|
173
14
|
const error = await getPromiseError(() =>
|
|
@@ -1,98 +1,11 @@
|
|
|
1
1
|
import {RpcService} from '../rpc-service-client';
|
|
2
|
-
import {
|
|
3
|
-
AddParams,
|
|
4
|
-
CreateAccountDocumentsParams,
|
|
5
|
-
ExportAccountParams,
|
|
6
|
-
ImportWalletParams,
|
|
7
|
-
QueryParams,
|
|
8
|
-
serviceName,
|
|
9
|
-
UpdateParams,
|
|
10
|
-
GetDocumentsFromEncryptedWallet,
|
|
11
|
-
ExportDocuments,
|
|
12
|
-
validation,
|
|
13
|
-
} from './configs';
|
|
2
|
+
import {serviceName, ExportDocuments, validation} from './configs';
|
|
14
3
|
|
|
15
4
|
export class WalletServiceRpc extends RpcService {
|
|
16
5
|
constructor() {
|
|
17
6
|
super(serviceName);
|
|
18
7
|
}
|
|
19
8
|
|
|
20
|
-
getDocumentById(id: string): Promise<any> {
|
|
21
|
-
validation.getDocumentById(id);
|
|
22
|
-
return this.call('getDocumentById', id);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
create(params: CreateParams): Promise<any> {
|
|
26
|
-
validation.create(params);
|
|
27
|
-
return this.call('create', params);
|
|
28
|
-
}
|
|
29
|
-
load() {
|
|
30
|
-
return this.call('load');
|
|
31
|
-
}
|
|
32
|
-
sync() {
|
|
33
|
-
return this.call('sync');
|
|
34
|
-
}
|
|
35
|
-
lock(password) {
|
|
36
|
-
return this.call('lock');
|
|
37
|
-
}
|
|
38
|
-
healthCheck(timestamp) {
|
|
39
|
-
return this.call('healthCheck', timestamp);
|
|
40
|
-
}
|
|
41
|
-
unlock(password) {
|
|
42
|
-
return this.call('unlock');
|
|
43
|
-
}
|
|
44
|
-
status() {
|
|
45
|
-
return this.call('status');
|
|
46
|
-
}
|
|
47
|
-
toJSON() {
|
|
48
|
-
return this.call('toJSON');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
add(params: AddParams) {
|
|
52
|
-
validation.add(params);
|
|
53
|
-
return this.call('add', params);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
remove(id: string) {
|
|
57
|
-
validation.remove(id);
|
|
58
|
-
return this.call('remove', id);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
update(params: UpdateParams) {
|
|
62
|
-
validation.update(params);
|
|
63
|
-
return this.call('update', params);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
query(params: QueryParams) {
|
|
67
|
-
validation.query(params);
|
|
68
|
-
return this.call('query', params);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
exportWallet(password: string) {
|
|
72
|
-
validation.exportWallet(password);
|
|
73
|
-
return this.call('exportWallet', password);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
importWallet(params: ImportWalletParams) {
|
|
77
|
-
validation.importWallet(params);
|
|
78
|
-
return this.call('importWallet', params);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
exportAccount(params: ExportAccountParams) {
|
|
82
|
-
validation.exportAccount(params);
|
|
83
|
-
return this.call('exportAccount', params);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
createAccountDocuments(params: CreateAccountDocumentsParams) {
|
|
87
|
-
validation.createAccountDocuments(params);
|
|
88
|
-
return this.call('createAccountDocuments', params);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
resolveCorrelations(address: string) {
|
|
92
|
-
validation.resolveCorrelations(address);
|
|
93
|
-
return this.call('resolveCorrelations', address);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
9
|
getDocumentsFromEncryptedWallet(params: GetDocumentsFromEncryptedWallet) {
|
|
97
10
|
validation.getDocumentsFromEncryptedWallet(params);
|
|
98
11
|
return this.call('getDocumentsFromEncryptedWallet', params);
|
|
@@ -5,7 +5,6 @@ import {v4 as uuid} from 'uuid';
|
|
|
5
5
|
import {WalletDocument} from '../../types';
|
|
6
6
|
import MemoryWallet from '../../wallet/memory-storage-wallet';
|
|
7
7
|
import RpcWallet from '../../wallet/rpc-storage-wallet';
|
|
8
|
-
import {keyringService} from '../keyring/service';
|
|
9
8
|
import {
|
|
10
9
|
CreateAccountDocumentsParams,
|
|
11
10
|
CreateParams,
|
|
@@ -23,24 +22,6 @@ export class WalletService {
|
|
|
23
22
|
wallet: StorageWallet;
|
|
24
23
|
|
|
25
24
|
rpcMethods = [
|
|
26
|
-
WalletService.prototype.create,
|
|
27
|
-
WalletService.prototype.add,
|
|
28
|
-
WalletService.prototype.exportWallet,
|
|
29
|
-
WalletService.prototype.importWallet,
|
|
30
|
-
WalletService.prototype.resolveCorrelations,
|
|
31
|
-
WalletService.prototype.createAccountDocuments,
|
|
32
|
-
WalletService.prototype.exportAccount,
|
|
33
|
-
WalletService.prototype.getDocumentById,
|
|
34
|
-
WalletService.prototype.load,
|
|
35
|
-
WalletService.prototype.lock,
|
|
36
|
-
WalletService.prototype.query,
|
|
37
|
-
WalletService.prototype.remove,
|
|
38
|
-
WalletService.prototype.status,
|
|
39
|
-
WalletService.prototype.toJSON,
|
|
40
|
-
WalletService.prototype.sync,
|
|
41
|
-
WalletService.prototype.unlock,
|
|
42
|
-
WalletService.prototype.update,
|
|
43
|
-
WalletService.prototype.healthCheck,
|
|
44
25
|
WalletService.prototype.getDocumentsFromEncryptedWallet,
|
|
45
26
|
WalletService.prototype.exportDocuments,
|
|
46
27
|
];
|
|
@@ -49,245 +30,6 @@ export class WalletService {
|
|
|
49
30
|
this.name = serviceName;
|
|
50
31
|
}
|
|
51
32
|
|
|
52
|
-
create(params: CreateParams) {
|
|
53
|
-
const {walletId, type} = params;
|
|
54
|
-
Logger.debug('Creating wallet', params);
|
|
55
|
-
if (type === 'memory') {
|
|
56
|
-
this.wallet = new MemoryWallet(walletId);
|
|
57
|
-
} else {
|
|
58
|
-
this.wallet = new RpcWallet(walletId);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
healthCheck(timestamp) {
|
|
63
|
-
return `${this.name}: ${timestamp}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
load() {
|
|
67
|
-
this._assertWallet();
|
|
68
|
-
|
|
69
|
-
return this.wallet.load();
|
|
70
|
-
}
|
|
71
|
-
sync() {
|
|
72
|
-
this._assertWallet();
|
|
73
|
-
|
|
74
|
-
return this.wallet.sync();
|
|
75
|
-
}
|
|
76
|
-
lock(password) {
|
|
77
|
-
this._assertWallet();
|
|
78
|
-
|
|
79
|
-
return this.wallet.lock(password);
|
|
80
|
-
}
|
|
81
|
-
unlock(password) {
|
|
82
|
-
this._assertWallet();
|
|
83
|
-
|
|
84
|
-
return this.wallet.unlock(password);
|
|
85
|
-
}
|
|
86
|
-
status() {
|
|
87
|
-
this._assertWallet();
|
|
88
|
-
|
|
89
|
-
return this.wallet.status;
|
|
90
|
-
}
|
|
91
|
-
toJSON() {
|
|
92
|
-
this._assertWallet();
|
|
93
|
-
|
|
94
|
-
return this.wallet.toJSON();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
add(content) {
|
|
98
|
-
this._assertWallet();
|
|
99
|
-
validation.add(content);
|
|
100
|
-
return this.wallet.add(content);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
remove(id: string) {
|
|
104
|
-
this._assertWallet();
|
|
105
|
-
validation.remove(id);
|
|
106
|
-
return this.wallet.remove(id);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
update(content) {
|
|
110
|
-
this._assertWallet();
|
|
111
|
-
validation.update(content);
|
|
112
|
-
return this.wallet.update(content);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
query(search) {
|
|
116
|
-
this._assertWallet();
|
|
117
|
-
validation.query(search);
|
|
118
|
-
return this.wallet.query(search);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
123
|
-
* @param {*} password
|
|
124
|
-
* @returns
|
|
125
|
-
*/
|
|
126
|
-
exportWallet(password) {
|
|
127
|
-
this._assertWallet();
|
|
128
|
-
validation.exportWallet(password);
|
|
129
|
-
return this.wallet.export(password);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
* @param {*} param0
|
|
135
|
-
* @returns
|
|
136
|
-
*/
|
|
137
|
-
importWallet(params: ImportWalletParams) {
|
|
138
|
-
this._assertWallet();
|
|
139
|
-
validation.importWallet(params);
|
|
140
|
-
|
|
141
|
-
const {json, password} = params;
|
|
142
|
-
return this.wallet.import(json, password);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async removeAll() {
|
|
146
|
-
this._assertWallet();
|
|
147
|
-
const documents = await this.wallet.query({});
|
|
148
|
-
|
|
149
|
-
for (let doc of documents) {
|
|
150
|
-
await this.wallet.remove(doc.id);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
await this.wallet.sync();
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
* @param {*} params
|
|
158
|
-
* @returns
|
|
159
|
-
*/
|
|
160
|
-
async exportAccount(params: ExportAccountParams) {
|
|
161
|
-
validation.exportAccount(params);
|
|
162
|
-
|
|
163
|
-
const {address, password, keyPairDocument} = params;
|
|
164
|
-
|
|
165
|
-
let pair;
|
|
166
|
-
|
|
167
|
-
if (keyPairDocument) {
|
|
168
|
-
pair = keyringService.decryptKeyPair({
|
|
169
|
-
jsonData: keyPairDocument,
|
|
170
|
-
password: '',
|
|
171
|
-
});
|
|
172
|
-
} else {
|
|
173
|
-
pair = await this.getAccountKeypair(address);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return pair.toJson(password);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
*
|
|
180
|
-
* @param {*} params
|
|
181
|
-
* @returns
|
|
182
|
-
*/
|
|
183
|
-
async createAccountDocuments(params: CreateAccountDocumentsParams) {
|
|
184
|
-
this._assertWallet();
|
|
185
|
-
validation.createAccountDocuments(params);
|
|
186
|
-
|
|
187
|
-
const {
|
|
188
|
-
name,
|
|
189
|
-
type = 'sr25519',
|
|
190
|
-
derivePath,
|
|
191
|
-
mnemonic,
|
|
192
|
-
json,
|
|
193
|
-
password,
|
|
194
|
-
hasBackup
|
|
195
|
-
} = params;
|
|
196
|
-
|
|
197
|
-
const keyringPair = json
|
|
198
|
-
? keyringService.decryptKeyPair({jsonData: json, password})
|
|
199
|
-
: keyringService.getKeyringPair({mnemonic, derivePath, type});
|
|
200
|
-
const keyringJson = keyringPair.toJson();
|
|
201
|
-
const correlationDocs: WalletDocument[] = [];
|
|
202
|
-
|
|
203
|
-
correlationDocs.push({
|
|
204
|
-
'@context': ['https://w3id.org/wallet/v1'],
|
|
205
|
-
id: uuid(),
|
|
206
|
-
type: 'KeyringPair',
|
|
207
|
-
value: keyringJson,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
correlationDocs.push({
|
|
211
|
-
'@context': ['https://w3id.org/wallet/v1'],
|
|
212
|
-
id: uuid(),
|
|
213
|
-
type: 'Currency',
|
|
214
|
-
value: 0,
|
|
215
|
-
symbol: 'DOCK',
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
if (mnemonic) {
|
|
219
|
-
correlationDocs.push({
|
|
220
|
-
'@context': ['https://w3id.org/wallet/v1'],
|
|
221
|
-
id: uuid(),
|
|
222
|
-
type: 'Mnemonic',
|
|
223
|
-
value: mnemonic,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
Logger.info(`Account created: ${keyringPair.address}`);
|
|
228
|
-
|
|
229
|
-
const addressDocument: WalletDocument = {
|
|
230
|
-
'@context': ['https://w3id.org/wallet/v1'],
|
|
231
|
-
id: keyringPair.address,
|
|
232
|
-
type: 'Address',
|
|
233
|
-
value: keyringPair.address,
|
|
234
|
-
address: keyringPair.address,
|
|
235
|
-
name,
|
|
236
|
-
correlation: correlationDocs.map(doc => doc.id),
|
|
237
|
-
hasBackup,
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
await this.wallet.add(addressDocument);
|
|
241
|
-
await Promise.all(correlationDocs.map(doc => this.wallet.add(doc)));
|
|
242
|
-
|
|
243
|
-
return [addressDocument, ...correlationDocs];
|
|
244
|
-
}
|
|
245
|
-
async resolveCorrelations(documentId) {
|
|
246
|
-
const document = await this.getDocumentById(documentId);
|
|
247
|
-
|
|
248
|
-
assert(!!document, `Document ${documentId} not found`);
|
|
249
|
-
|
|
250
|
-
const correlation = await Promise.all(
|
|
251
|
-
(document.correlation || []).map(docId => this.getDocumentById(docId)),
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
const result = [document, ...correlation];
|
|
255
|
-
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
_assertWallet() {
|
|
260
|
-
assert(!!this.wallet, 'wallet is not created');
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async getAccountKeypair(accountId) {
|
|
264
|
-
const correlations = await this.resolveCorrelations(accountId);
|
|
265
|
-
const keyPairDocument = correlations.find(
|
|
266
|
-
doc => doc.type === 'KeyringPair',
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
assert(
|
|
270
|
-
!!keyPairDocument,
|
|
271
|
-
`Keypair document not found for account: ${accountId}`,
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
const pair = keyringService.decryptKeyPair({
|
|
275
|
-
jsonData: keyPairDocument.value,
|
|
276
|
-
password: '',
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
pair.unlock();
|
|
280
|
-
|
|
281
|
-
return pair;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
getDocumentById(id: string) {
|
|
285
|
-
this._assertWallet();
|
|
286
|
-
validation.getDocumentById(id);
|
|
287
|
-
|
|
288
|
-
return this.wallet.getStorageDocument({id}).then(doc => doc.content);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
33
|
async getDocumentsFromEncryptedWallet(params) {
|
|
292
34
|
validation.getDocumentsFromEncryptedWallet(params);
|
|
293
35
|
const {encryptedJSONWallet, password} = params;
|
package/src/test-utils.js
CHANGED
|
@@ -27,16 +27,3 @@ export function testRpcEndpoint(service, rpcMethod, ...params) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const waitFor = timeout => new Promise(res => setTimeout(res, timeout));
|
|
30
|
-
|
|
31
|
-
let sendTokensSpy;
|
|
32
|
-
let getFeeSpy;
|
|
33
|
-
|
|
34
|
-
export function resetMockTransaction() {
|
|
35
|
-
if (sendTokensSpy) {
|
|
36
|
-
sendTokensSpy.mockRestore();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (getFeeSpy) {
|
|
40
|
-
getFeeSpy.mockRestore();
|
|
41
|
-
}
|
|
42
|
-
}
|