@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,42 +0,0 @@
|
|
|
1
|
-
export const TokenPrice = {
|
|
2
|
-
name: 'TokenPrice',
|
|
3
|
-
properties: {
|
|
4
|
-
symbol: 'string',
|
|
5
|
-
name: 'string?',
|
|
6
|
-
price: 'float',
|
|
7
|
-
},
|
|
8
|
-
primaryKey: 'symbol',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const Account = {
|
|
12
|
-
name: 'Account',
|
|
13
|
-
properties: {
|
|
14
|
-
id: 'string',
|
|
15
|
-
name: 'string',
|
|
16
|
-
balance: 'string?',
|
|
17
|
-
},
|
|
18
|
-
network: {
|
|
19
|
-
type: 'string',
|
|
20
|
-
default: 'testnet',
|
|
21
|
-
},
|
|
22
|
-
readyOnly: {
|
|
23
|
-
type: 'bool',
|
|
24
|
-
default: false,
|
|
25
|
-
},
|
|
26
|
-
primaryKey: 'id',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const RequestLog = {
|
|
30
|
-
name: 'RequestLog',
|
|
31
|
-
properties: {
|
|
32
|
-
id: 'string',
|
|
33
|
-
url: 'string',
|
|
34
|
-
status: 'int',
|
|
35
|
-
method: 'string',
|
|
36
|
-
headers: 'string',
|
|
37
|
-
body: 'string',
|
|
38
|
-
response: 'string',
|
|
39
|
-
createdAt: 'date',
|
|
40
|
-
},
|
|
41
|
-
primaryKey: 'id',
|
|
42
|
-
};
|
package/src/core/subscan.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import axiosRetry from 'axios-retry';
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
import {Logger} from './logger';
|
|
5
|
-
import {TaskQueue} from 'cwait';
|
|
6
|
-
|
|
7
|
-
axiosRetry(axios, {
|
|
8
|
-
retries: 4,
|
|
9
|
-
retryDelay: retryCount => {
|
|
10
|
-
return retryCount * 500;
|
|
11
|
-
},
|
|
12
|
-
retryCondition: error => {
|
|
13
|
-
return error.response.status === 503 || error.response.status === 429;
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const SUBSCAN_URL = 'https://dock.api.subscan.io';
|
|
18
|
-
export const SUBSCAN_TRANSFER_URL = `${SUBSCAN_URL}/api/v2/scan/transfers`;
|
|
19
|
-
|
|
20
|
-
const queue = new TaskQueue(global.Promise, 1);
|
|
21
|
-
|
|
22
|
-
function doFetchTransactions({address, page = 0, itemsPerPage = 50}) {
|
|
23
|
-
assert(typeof address === 'string', 'address must be a string');
|
|
24
|
-
assert(typeof page === 'number', 'page must be a number');
|
|
25
|
-
assert(typeof itemsPerPage === 'number', 'itemsPerPage must be a number');
|
|
26
|
-
|
|
27
|
-
const body = {
|
|
28
|
-
row: itemsPerPage,
|
|
29
|
-
page,
|
|
30
|
-
address: address,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
Logger.info(
|
|
34
|
-
`Fetching transactions from subscan ${SUBSCAN_TRANSFER_URL} with body ${JSON.stringify(
|
|
35
|
-
body,
|
|
36
|
-
)}`,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
return axios
|
|
40
|
-
.post(SUBSCAN_TRANSFER_URL, body, {})
|
|
41
|
-
.then(res => {
|
|
42
|
-
const {data, message} = res.data;
|
|
43
|
-
|
|
44
|
-
if (message === 'Success') {
|
|
45
|
-
const {transfers, count} = data;
|
|
46
|
-
return {
|
|
47
|
-
items: transfers,
|
|
48
|
-
count,
|
|
49
|
-
page,
|
|
50
|
-
hasNextPage: (page + 1) * itemsPerPage < count,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
throw new Error(message);
|
|
55
|
-
})
|
|
56
|
-
.catch(err => {
|
|
57
|
-
console.error(err);
|
|
58
|
-
throw err;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const fetchTransactions = queue.wrap(doFetchTransactions);
|
package/src/core/subscan.test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {fetchTransactions} from './subscan';
|
|
2
|
-
import {mockSubscanParamsFailure, mockSubscanSuccess} from '../test/axiosMocks';
|
|
3
|
-
import {getPromiseError} from '../services/test-utils';
|
|
4
|
-
|
|
5
|
-
describe('Subscan integration', () => {
|
|
6
|
-
describe('fetchTransactions', () => {
|
|
7
|
-
it('expect to return transactions', async () => {
|
|
8
|
-
mockSubscanSuccess();
|
|
9
|
-
|
|
10
|
-
const transactions = await fetchTransactions({address: '123'});
|
|
11
|
-
|
|
12
|
-
expect(transactions.items.length).toBe(12);
|
|
13
|
-
expect(transactions.hasNextPage).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('expect to return transactions (last page)', async () => {
|
|
17
|
-
mockSubscanSuccess();
|
|
18
|
-
|
|
19
|
-
const transactions = await fetchTransactions({address: '123', page: 2});
|
|
20
|
-
|
|
21
|
-
expect(transactions.hasNextPage).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('expect to handle api error', async () => {
|
|
25
|
-
let error;
|
|
26
|
-
mockSubscanParamsFailure();
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
await fetchTransactions({address: '123', page: 2});
|
|
30
|
-
} catch (err) {
|
|
31
|
-
error = err;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
expect(error.message).toBe('Params Error');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('validate adddress param', async () => {
|
|
38
|
-
const error = await getPromiseError(() => fetchTransactions({}));
|
|
39
|
-
expect(error.message).toBe('address must be a string');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('validate page param', async () => {
|
|
43
|
-
const error = await getPromiseError(() =>
|
|
44
|
-
fetchTransactions({address: '123', page: 'test'}),
|
|
45
|
-
);
|
|
46
|
-
await expect(error.message).toBe('page must be a number');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('validate itemsPerPage param', async () => {
|
|
50
|
-
const error = await getPromiseError(() =>
|
|
51
|
-
fetchTransactions({address: '123', itemsPerPage: 'test'}),
|
|
52
|
-
);
|
|
53
|
-
await expect(error.message).toBe('itemsPerPage must be a number');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
package/src/fixtures.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {getKeyring} from './services/keyring/service';
|
|
2
|
-
|
|
3
|
-
export const TestFixtures = {
|
|
4
|
-
account1: {
|
|
5
|
-
name: 'Account 1',
|
|
6
|
-
mnemonic:
|
|
7
|
-
'twenty fat wood hub lock cattle thought base lazy apology lyrics innocent',
|
|
8
|
-
address: '393NFT43eUgKnEthAaKXnuCzizuxExMYULWrsjep5c1TmV4X',
|
|
9
|
-
balance: 100,
|
|
10
|
-
getKeyring: () =>
|
|
11
|
-
getKeyring().addFromMnemonic(
|
|
12
|
-
TestFixtures.account1.mnemonic,
|
|
13
|
-
null,
|
|
14
|
-
'sr25519',
|
|
15
|
-
),
|
|
16
|
-
},
|
|
17
|
-
account2: {
|
|
18
|
-
name: 'Account 2',
|
|
19
|
-
mnemonic:
|
|
20
|
-
'multiply obtain exact matrix write chimney observe blind siege mobile spoon club',
|
|
21
|
-
address: '38Pg2Kiod34RiWMEKNZHR6oLUahatQxaeMSfVXAGU3MbX83g',
|
|
22
|
-
balance: 200,
|
|
23
|
-
getKeyring: () =>
|
|
24
|
-
getKeyring().addFromMnemonic(
|
|
25
|
-
TestFixtures.account2.mnemonic,
|
|
26
|
-
null,
|
|
27
|
-
'sr25519',
|
|
28
|
-
),
|
|
29
|
-
},
|
|
30
|
-
noBalanceAccount: {
|
|
31
|
-
name: 'Account No Balance',
|
|
32
|
-
mnemonic:
|
|
33
|
-
'raise genuine melt wagon make sense paddle sea human skirt lucky humor',
|
|
34
|
-
address: '3AxrRtwmcmezJLv9Nj6uD6MHJY5HN4buFX1r8vyGVpJmeZmE',
|
|
35
|
-
balance: 0,
|
|
36
|
-
getKeyring: () =>
|
|
37
|
-
getKeyring().addFromMnemonic(
|
|
38
|
-
TestFixtures.noBalanceAccount.mnemonic,
|
|
39
|
-
null,
|
|
40
|
-
'sr25519',
|
|
41
|
-
),
|
|
42
|
-
},
|
|
43
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {Account} from './account';
|
|
2
|
-
import {Wallet} from './wallet';
|
|
3
|
-
import {NetworkManager} from './network-manager';
|
|
4
|
-
import {TestFixtures} from '../fixtures';
|
|
5
|
-
import {getTestWallet} from '../test/setup-test-state';
|
|
6
|
-
|
|
7
|
-
describe('Account', () => {
|
|
8
|
-
let wallet: Wallet;
|
|
9
|
-
let account: Account;
|
|
10
|
-
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
NetworkManager.getInstance().setNetworkId('testnet');
|
|
13
|
-
wallet = await getTestWallet();
|
|
14
|
-
await wallet.ensureNetwork();
|
|
15
|
-
account = await wallet.accounts.getByAddress(TestFixtures.account1.address);
|
|
16
|
-
await account.loadDetails();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('expect to get account name', () => {
|
|
20
|
-
expect(account.getName()).toBe(TestFixtures.account1.name);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('expect to get address', () => {
|
|
24
|
-
expect(account.getAddress()).toBe(TestFixtures.account1.address);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('expect to get mnemonic phrase', async () => {
|
|
28
|
-
const phrase = await account.getMnemonic();
|
|
29
|
-
expect(phrase).toBe(TestFixtures.account1.mnemonic);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('expect to get keyring pair', async () => {
|
|
33
|
-
const pair = await account.getKeyPair();
|
|
34
|
-
expect(pair.address).toBe(TestFixtures.account1.address);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('expect to export account', () => {
|
|
38
|
-
const password = '123';
|
|
39
|
-
jest.spyOn(account.accounts, 'exportAccount');
|
|
40
|
-
account.export(password);
|
|
41
|
-
expect(account.accounts.exportAccount).toBeCalledWith(
|
|
42
|
-
account.address,
|
|
43
|
-
password,
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('expect to remove account', () => {
|
|
48
|
-
jest.spyOn(account.accounts, 'remove');
|
|
49
|
-
account.remove();
|
|
50
|
-
expect(account.accounts.remove).toBeCalledWith(account.address);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterAll(() => {
|
|
54
|
-
return wallet.close();
|
|
55
|
-
});
|
|
56
|
-
});
|
package/src/modules/account.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import assert from 'assert';
|
|
3
|
-
import {isAddressValid} from '../core/validation';
|
|
4
|
-
import {Accounts} from './accounts';
|
|
5
|
-
import { KeypairType } from '../types';
|
|
6
|
-
|
|
7
|
-
export type AccountDetails = {
|
|
8
|
-
id: string,
|
|
9
|
-
name: string,
|
|
10
|
-
type: KeypairType,
|
|
11
|
-
address: string,
|
|
12
|
-
correlations: any[],
|
|
13
|
-
balance?: number,
|
|
14
|
-
readonly?: boolean,
|
|
15
|
-
meta?: {
|
|
16
|
-
keypairNotFoundWarning: boolean,
|
|
17
|
-
name: string,
|
|
18
|
-
keypairType: KeypairType,
|
|
19
|
-
derivationPath: string,
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Account
|
|
25
|
-
*/
|
|
26
|
-
export class Account {
|
|
27
|
-
details: AccountDetails;
|
|
28
|
-
address: string;
|
|
29
|
-
name: string;
|
|
30
|
-
accounts: Accounts;
|
|
31
|
-
|
|
32
|
-
constructor(address: string, accounts: Accounts) {
|
|
33
|
-
this.accounts = accounts;
|
|
34
|
-
this.address = address;
|
|
35
|
-
this.id = address;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get account for a given address
|
|
40
|
-
* The account needs to exist in the wallet
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* const accounts = Account.with('some-address')
|
|
44
|
-
* @param {string} address
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
static with(address, accounts) {
|
|
48
|
-
assert(isAddressValid(address), 'invalid address');
|
|
49
|
-
|
|
50
|
-
const account = new Account(address, accounts || Accounts.getInstance());
|
|
51
|
-
|
|
52
|
-
account.loadPromise = account.loadDetails();
|
|
53
|
-
|
|
54
|
-
return account;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
* @param {string} address
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
static async withAsync(address, accounts) {
|
|
63
|
-
const account = Account.with(address, accounts);
|
|
64
|
-
|
|
65
|
-
await account.loadPromise;
|
|
66
|
-
|
|
67
|
-
return account;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @returns {Promise<void>}
|
|
72
|
-
*/
|
|
73
|
-
async loadDetails() {
|
|
74
|
-
this.details = await this.accounts.wallet.getDocumentById(this.id);
|
|
75
|
-
this.name = this.details && this.details.name;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getAddress() {
|
|
79
|
-
return this.details.address;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
getDetails(): AccountDetails {
|
|
83
|
-
return this.details;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async getBalance(skipFetch?) {
|
|
87
|
-
return this.accounts.getBalance(this.details.address, skipFetch);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export(password: string) {
|
|
91
|
-
return this.accounts.exportAccount(this.address, password);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
remove() {
|
|
95
|
-
return this.accounts.remove(this.address);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
update({name}) {
|
|
99
|
-
return this.accounts.update({
|
|
100
|
-
...this.details,
|
|
101
|
-
name,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async getMnemonic() {
|
|
106
|
-
const doc = await this.accounts.findCorrelationByType(
|
|
107
|
-
this.address,
|
|
108
|
-
'Mnemonic',
|
|
109
|
-
);
|
|
110
|
-
return doc.value;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async getKeyPair() {
|
|
114
|
-
const doc = await this.accounts.findCorrelationByType(
|
|
115
|
-
this.address,
|
|
116
|
-
'KeyringPair',
|
|
117
|
-
);
|
|
118
|
-
return doc.value;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getName(): string {
|
|
122
|
-
return this.details.name;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getIcon(isAlternative?: boolean): Promise<any> {
|
|
126
|
-
return this.accounts.getAccountIcon(this.details.address, isAlternative);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {Accounts} from './accounts';
|
|
2
|
-
import {Wallet} from './wallet';
|
|
3
|
-
import {getTestWallet} from '../test/setup-test-state';
|
|
4
|
-
|
|
5
|
-
describe('Accounts module', () => {
|
|
6
|
-
let wallet: Wallet;
|
|
7
|
-
let accounts: Accounts;
|
|
8
|
-
|
|
9
|
-
beforeAll(async () => {
|
|
10
|
-
wallet = await getTestWallet();
|
|
11
|
-
await wallet.ensureNetwork();
|
|
12
|
-
|
|
13
|
-
accounts = wallet.accounts;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('Expect to create account', async () => {
|
|
17
|
-
const name = 'Test account';
|
|
18
|
-
const account = await accounts.create({
|
|
19
|
-
name,
|
|
20
|
-
});
|
|
21
|
-
const foundDocument = accounts
|
|
22
|
-
.getAccounts()
|
|
23
|
-
.find(item => item.id === account.address);
|
|
24
|
-
|
|
25
|
-
expect(account.name).toBe(name);
|
|
26
|
-
expect(account.address).toBeDefined();
|
|
27
|
-
expect(foundDocument.id).toBe(account.address);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('Expect to create accounts with existing mnemonic', async () => {
|
|
31
|
-
const name = 'test';
|
|
32
|
-
const mnemonic =
|
|
33
|
-
'young defense crouch puzzle mosquito wire front town trophy assist salt entire';
|
|
34
|
-
const address = '3APujz7DViXXKyh7oKQRR2771aLxMHhh9ZwVadXQZnHSH2kF';
|
|
35
|
-
|
|
36
|
-
const account = await accounts.create({
|
|
37
|
-
name: name,
|
|
38
|
-
mnemonic: mnemonic,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(account.getName()).toBe(name);
|
|
42
|
-
expect(account.address).toBe(address);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('Expect to export account and import account', async () => {
|
|
46
|
-
const account = await accounts.create({
|
|
47
|
-
name: 'test',
|
|
48
|
-
});
|
|
49
|
-
const json = await accounts.exportAccount(account.address, 'test');
|
|
50
|
-
|
|
51
|
-
expect(json.address).toBe(account.address);
|
|
52
|
-
|
|
53
|
-
await accounts.remove(account.address);
|
|
54
|
-
|
|
55
|
-
const account2 = await accounts.create({
|
|
56
|
-
name: 'json account',
|
|
57
|
-
json,
|
|
58
|
-
password: 'test',
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(account2.address).toBe(account.address);
|
|
62
|
-
});
|
|
63
|
-
});
|
package/src/modules/accounts.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import assert from 'assert';
|
|
3
|
-
import {walletService as _walletService} from '../services/wallet';
|
|
4
|
-
import {utilCryptoService} from '../services/util-crypto';
|
|
5
|
-
import {keyringService} from '../services/keyring';
|
|
6
|
-
import {polkadotService} from '../services/polkadot';
|
|
7
|
-
import {Wallet, WalletEvents} from './wallet';
|
|
8
|
-
import {Errors} from '../errors';
|
|
9
|
-
import {
|
|
10
|
-
KeypairType,
|
|
11
|
-
WalletDocument,
|
|
12
|
-
DocumentType,
|
|
13
|
-
KeypairTypes,
|
|
14
|
-
} from '../types';
|
|
15
|
-
import {EventManager} from './event-manager';
|
|
16
|
-
import {AccountDetails, Account} from './account';
|
|
17
|
-
import {isAddressValid} from '../core/validation';
|
|
18
|
-
|
|
19
|
-
export const AccountsEvents = {
|
|
20
|
-
loaded: 'loaded',
|
|
21
|
-
accountCreated: 'account-added',
|
|
22
|
-
accountUpdated: 'account-updated',
|
|
23
|
-
accountRemoved: 'account-removed',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type CreateAccountParams = {
|
|
27
|
-
name: string,
|
|
28
|
-
type?: KeypairType,
|
|
29
|
-
derivationPath?: string,
|
|
30
|
-
mnemonic?: string,
|
|
31
|
-
json?: string,
|
|
32
|
-
password?: string,
|
|
33
|
-
getIfExists?: boolean,
|
|
34
|
-
hasBackup?: boolean,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export class Accounts {
|
|
38
|
-
accounts: AccountDetails[];
|
|
39
|
-
wallet: Wallet;
|
|
40
|
-
eventManager: EventManager;
|
|
41
|
-
static DocumentFilters = {
|
|
42
|
-
mnemonicType: (item: WalletDocument) => item.type === 'Mnemonic',
|
|
43
|
-
currencyType: (item: WalletDocument) => item.type === 'Currency',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
constructor({wallet, walletService} = {}) {
|
|
47
|
-
this.accounts = [];
|
|
48
|
-
this.wallet = wallet || Wallet.getInstance();
|
|
49
|
-
this.walletService = walletService || _walletService;
|
|
50
|
-
this.eventManager = new EventManager();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async load() {
|
|
54
|
-
this.accounts = await this.wallet.query({
|
|
55
|
-
type: 'Address',
|
|
56
|
-
});
|
|
57
|
-
this.eventManager.emit(AccountsEvents.loaded);
|
|
58
|
-
return this.accounts;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async exportAccount(address, password) {
|
|
62
|
-
return this.walletService.exportAccount({address, password});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async importAccount(json, password) {
|
|
66
|
-
return this.create({
|
|
67
|
-
json,
|
|
68
|
-
password,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async getBalance(address, skipFetch?) {
|
|
73
|
-
assert(isAddressValid(address), 'address is required');
|
|
74
|
-
|
|
75
|
-
if (!skipFetch) {
|
|
76
|
-
await this.fetchBalance(address);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const currency = await this.findCorrelationByType(
|
|
80
|
-
address,
|
|
81
|
-
'Currency',
|
|
82
|
-
true,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
return currency.value;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getAccounts() {
|
|
89
|
-
return this.accounts;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getAccountIcon(address: string, isAlternative: boolean): Promise<any> {
|
|
93
|
-
return polkadotService.getPolkadotSvgIcon(address, isAlternative);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async getByAddress(address: string): Promise<AccountDetails> {
|
|
97
|
-
return Account.with(address);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async findCorrelationByType(
|
|
101
|
-
address: string,
|
|
102
|
-
type: DocumentType,
|
|
103
|
-
assertResult: boolean,
|
|
104
|
-
) {
|
|
105
|
-
assert(isAddressValid(address), 'invalid address');
|
|
106
|
-
|
|
107
|
-
const correlations = await this.wallet.resolveCorrelations(address);
|
|
108
|
-
const result = correlations.find(c => c.type.includes(type));
|
|
109
|
-
|
|
110
|
-
if (assertResult) {
|
|
111
|
-
assert(!!result, `${type} document not found for the account ${address}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
generateMnemonic(): Promise<string> {
|
|
118
|
-
return utilCryptoService.mnemonicGenerate(12);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async update(account: AccountDetails) {
|
|
122
|
-
assert(!!account, 'account is required');
|
|
123
|
-
|
|
124
|
-
await this.walletService.update(account);
|
|
125
|
-
this.eventManager.emit(AccountsEvents.accountUpdated);
|
|
126
|
-
await this.load();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async getOrCreate(params: CreateAccountParams) {
|
|
130
|
-
return this.create({
|
|
131
|
-
...params,
|
|
132
|
-
getIfExists: true,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async create(params: CreateAccountParams): Promise<Account> {
|
|
137
|
-
let {name, json, password, type = 'sr25519', getIfExists, hasBackup} = params;
|
|
138
|
-
|
|
139
|
-
assert(!!name, 'name is required');
|
|
140
|
-
assert(!!type, 'keypair type is required');
|
|
141
|
-
assert(
|
|
142
|
-
KeypairTypes.find(t => t === type),
|
|
143
|
-
`invalid keypair type ${type}`,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
if (json) {
|
|
147
|
-
assert(typeof password === 'string', 'password is required');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const mnemonic =
|
|
151
|
-
params.mnemonic || (!json && (await this.generateMnemonic()));
|
|
152
|
-
const derivePath = params.derivationPath || '';
|
|
153
|
-
|
|
154
|
-
const address = json
|
|
155
|
-
? json.address
|
|
156
|
-
: await keyringService.addressFromUri({
|
|
157
|
-
mnemonic,
|
|
158
|
-
type,
|
|
159
|
-
derivePath,
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const existingAccountDocs = await this.wallet.query({
|
|
163
|
-
id: address,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const accountExists = existingAccountDocs.length > 0;
|
|
167
|
-
|
|
168
|
-
if (getIfExists && accountExists) {
|
|
169
|
-
return this.getByAddress(address);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
assert(!accountExists, Errors.accountAlreadyExists);
|
|
173
|
-
|
|
174
|
-
if (json) {
|
|
175
|
-
const pair = await keyringService.decryptKeyPair({
|
|
176
|
-
jsonData: json,
|
|
177
|
-
password,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
assert(pair && pair.address, 'invalid keypair');
|
|
181
|
-
|
|
182
|
-
type = pair.type;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const account: AccountDetails = {
|
|
186
|
-
id: address,
|
|
187
|
-
name,
|
|
188
|
-
type,
|
|
189
|
-
address,
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const documents = await this.walletService.createAccountDocuments({
|
|
193
|
-
name,
|
|
194
|
-
type,
|
|
195
|
-
derivePath,
|
|
196
|
-
mnemonic,
|
|
197
|
-
json,
|
|
198
|
-
password,
|
|
199
|
-
hasBackup,
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
documents.forEach(doc => {
|
|
203
|
-
this.wallet.eventManager.emit(WalletEvents.documentAdded, doc);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
this.eventManager.emit(AccountsEvents.accountCreated, account);
|
|
207
|
-
|
|
208
|
-
await this.load();
|
|
209
|
-
|
|
210
|
-
return Account.withAsync(account.address, this);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async remove(accountId) {
|
|
214
|
-
await this.wallet.remove(accountId);
|
|
215
|
-
|
|
216
|
-
// remove other documents
|
|
217
|
-
// mnemonic phrase and all the stuff
|
|
218
|
-
|
|
219
|
-
this.eventManager.emit(AccountsEvents.accountRemoved, accountId);
|
|
220
|
-
|
|
221
|
-
this.load();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
static getInstance(options): Accounts {
|
|
225
|
-
if (!Accounts.instance || options) {
|
|
226
|
-
Accounts.instance = new Accounts(options);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return Accounts.instance;
|
|
230
|
-
}
|
|
231
|
-
}
|