@sidhujag/sysweb3-keyring 1.0.547 → 1.0.548
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/package.json +2 -27
- package/coverage/clover.xml +0 -2875
- package/coverage/coverage-final.json +0 -29468
- package/coverage/lcov-report/base.css +0 -354
- package/coverage/lcov-report/block-navigation.js +0 -85
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -320
- package/coverage/lcov-report/prettify.css +0 -101
- package/coverage/lcov-report/prettify.js +0 -1008
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -191
- package/coverage/lcov-report/src/index.html +0 -276
- package/coverage/lcov-report/src/index.ts.html +0 -114
- package/coverage/lcov-report/src/initial-state.ts.html +0 -558
- package/coverage/lcov-report/src/keyring-manager.ts.html +0 -6279
- package/coverage/lcov-report/src/ledger/bitcoin_client/index.html +0 -178
- package/coverage/lcov-report/src/ledger/bitcoin_client/index.ts.html +0 -144
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/appClient.ts.html +0 -1560
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/bip32.ts.html +0 -276
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/buffertools.ts.html +0 -495
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/clientCommands.ts.html +0 -1138
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/index.html +0 -363
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/merkelizedPsbt.ts.html +0 -289
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/merkle.ts.html +0 -486
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/merkleMap.ts.html +0 -240
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/policy.ts.html +0 -342
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/psbtv2.ts.html +0 -2388
- package/coverage/lcov-report/src/ledger/bitcoin_client/lib/varint.ts.html +0 -453
- package/coverage/lcov-report/src/ledger/consts.ts.html +0 -177
- package/coverage/lcov-report/src/ledger/index.html +0 -216
- package/coverage/lcov-report/src/ledger/index.ts.html +0 -1371
- package/coverage/lcov-report/src/ledger/utils.ts.html +0 -102
- package/coverage/lcov-report/src/signers.ts.html +0 -591
- package/coverage/lcov-report/src/storage.ts.html +0 -198
- package/coverage/lcov-report/src/transactions/ethereum.ts.html +0 -5826
- package/coverage/lcov-report/src/transactions/index.html +0 -216
- package/coverage/lcov-report/src/transactions/index.ts.html +0 -93
- package/coverage/lcov-report/src/transactions/syscoin.ts.html +0 -1521
- package/coverage/lcov-report/src/trezor/index.html +0 -176
- package/coverage/lcov-report/src/trezor/index.ts.html +0 -2655
- package/coverage/lcov-report/src/types.ts.html +0 -1443
- package/coverage/lcov-report/src/utils/derivation-paths.ts.html +0 -486
- package/coverage/lcov-report/src/utils/index.html +0 -196
- package/coverage/lcov-report/src/utils/psbt.ts.html +0 -159
- package/coverage/lcov-report/test/helpers/constants.ts.html +0 -627
- package/coverage/lcov-report/test/helpers/index.html +0 -176
- package/coverage/lcov.info +0 -4832
- package/dist/package.json +0 -50
- package/examples/basic-usage.js +0 -140
- package/jest.config.js +0 -32
- package/readme.md +0 -201
- package/src/declare.d.ts +0 -7
- package/src/errorUtils.ts +0 -83
- package/src/hardware-wallet-manager.ts +0 -655
- package/src/index.ts +0 -12
- package/src/initial-state.ts +0 -108
- package/src/keyring-manager.ts +0 -2698
- package/src/ledger/bitcoin_client/index.ts +0 -19
- package/src/ledger/bitcoin_client/lib/appClient.ts +0 -405
- package/src/ledger/bitcoin_client/lib/bip32.ts +0 -61
- package/src/ledger/bitcoin_client/lib/buffertools.ts +0 -134
- package/src/ledger/bitcoin_client/lib/clientCommands.ts +0 -356
- package/src/ledger/bitcoin_client/lib/constants.ts +0 -12
- package/src/ledger/bitcoin_client/lib/merkelizedPsbt.ts +0 -65
- package/src/ledger/bitcoin_client/lib/merkle.ts +0 -136
- package/src/ledger/bitcoin_client/lib/merkleMap.ts +0 -49
- package/src/ledger/bitcoin_client/lib/policy.ts +0 -91
- package/src/ledger/bitcoin_client/lib/psbtv2.ts +0 -768
- package/src/ledger/bitcoin_client/lib/varint.ts +0 -120
- package/src/ledger/consts.ts +0 -3
- package/src/ledger/index.ts +0 -685
- package/src/ledger/types.ts +0 -74
- package/src/network-utils.ts +0 -99
- package/src/providers.ts +0 -345
- package/src/signers.ts +0 -158
- package/src/storage.ts +0 -63
- package/src/transactions/__tests__/integration.test.ts +0 -303
- package/src/transactions/__tests__/syscoin.test.ts +0 -409
- package/src/transactions/ethereum.ts +0 -2503
- package/src/transactions/index.ts +0 -2
- package/src/transactions/syscoin.ts +0 -542
- package/src/trezor/index.ts +0 -1050
- package/src/types.ts +0 -366
- package/src/utils/derivation-paths.ts +0 -133
- package/src/utils/psbt.ts +0 -24
- package/src/utils.ts +0 -191
- package/test/README.md +0 -158
- package/test/__mocks__/ledger-mock.js +0 -20
- package/test/__mocks__/trezor-mock.js +0 -75
- package/test/cleanup-summary.md +0 -167
- package/test/helpers/README.md +0 -78
- package/test/helpers/constants.ts +0 -79
- package/test/helpers/setup.ts +0 -714
- package/test/integration/import-validation.spec.ts +0 -588
- package/test/unit/hardware/ledger.spec.ts +0 -869
- package/test/unit/hardware/trezor.spec.ts +0 -828
- package/test/unit/keyring-manager/account-management.spec.ts +0 -970
- package/test/unit/keyring-manager/import-watchonly.spec.ts +0 -181
- package/test/unit/keyring-manager/import-wif.spec.ts +0 -126
- package/test/unit/keyring-manager/initialization.spec.ts +0 -782
- package/test/unit/keyring-manager/key-derivation.spec.ts +0 -996
- package/test/unit/keyring-manager/security.spec.ts +0 -505
- package/test/unit/keyring-manager/state-management.spec.ts +0 -375
- package/test/unit/network/network-management.spec.ts +0 -372
- package/test/unit/transactions/ethereum-transactions.spec.ts +0 -382
- package/test/unit/transactions/syscoin-transactions.spec.ts +0 -615
- package/tsconfig.json +0 -14
- /package/{dist/README.md → README.md} +0 -0
- /package/{dist/cjs → cjs}/errorUtils.js +0 -0
- /package/{dist/cjs → cjs}/errorUtils.js.map +0 -0
- /package/{dist/cjs → cjs}/hardware-wallet-manager.js +0 -0
- /package/{dist/cjs → cjs}/hardware-wallet-manager.js.map +0 -0
- /package/{dist/cjs → cjs}/index.js +0 -0
- /package/{dist/cjs → cjs}/index.js.map +0 -0
- /package/{dist/cjs → cjs}/initial-state.js +0 -0
- /package/{dist/cjs → cjs}/initial-state.js.map +0 -0
- /package/{dist/cjs → cjs}/keyring-manager.js +0 -0
- /package/{dist/cjs → cjs}/keyring-manager.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/index.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/index.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/appClient.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/appClient.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/bip32.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/bip32.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/buffertools.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/buffertools.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/clientCommands.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/clientCommands.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/constants.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/constants.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkelizedPsbt.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkelizedPsbt.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkle.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkle.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkleMap.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/merkleMap.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/policy.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/policy.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/psbtv2.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/psbtv2.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/varint.js +0 -0
- /package/{dist/cjs → cjs}/ledger/bitcoin_client/lib/varint.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/consts.js +0 -0
- /package/{dist/cjs → cjs}/ledger/consts.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/index.js +0 -0
- /package/{dist/cjs → cjs}/ledger/index.js.map +0 -0
- /package/{dist/cjs → cjs}/ledger/types.js +0 -0
- /package/{dist/cjs → cjs}/ledger/types.js.map +0 -0
- /package/{dist/cjs → cjs}/network-utils.js +0 -0
- /package/{dist/cjs → cjs}/network-utils.js.map +0 -0
- /package/{dist/cjs → cjs}/providers.js +0 -0
- /package/{dist/cjs → cjs}/providers.js.map +0 -0
- /package/{dist/cjs → cjs}/signers.js +0 -0
- /package/{dist/cjs → cjs}/signers.js.map +0 -0
- /package/{dist/cjs → cjs}/storage.js +0 -0
- /package/{dist/cjs → cjs}/storage.js.map +0 -0
- /package/{dist/cjs → cjs}/transactions/__tests__/integration.test.js +0 -0
- /package/{dist/cjs → cjs}/transactions/__tests__/integration.test.js.map +0 -0
- /package/{dist/cjs → cjs}/transactions/__tests__/syscoin.test.js +0 -0
- /package/{dist/cjs → cjs}/transactions/__tests__/syscoin.test.js.map +0 -0
- /package/{dist/cjs → cjs}/transactions/ethereum.js +0 -0
- /package/{dist/cjs → cjs}/transactions/ethereum.js.map +0 -0
- /package/{dist/cjs → cjs}/transactions/index.js +0 -0
- /package/{dist/cjs → cjs}/transactions/index.js.map +0 -0
- /package/{dist/cjs → cjs}/transactions/syscoin.js +0 -0
- /package/{dist/cjs → cjs}/transactions/syscoin.js.map +0 -0
- /package/{dist/cjs → cjs}/trezor/index.js +0 -0
- /package/{dist/cjs → cjs}/trezor/index.js.map +0 -0
- /package/{dist/cjs → cjs}/types.js +0 -0
- /package/{dist/cjs → cjs}/types.js.map +0 -0
- /package/{dist/cjs → cjs}/utils/derivation-paths.js +0 -0
- /package/{dist/cjs → cjs}/utils/derivation-paths.js.map +0 -0
- /package/{dist/cjs → cjs}/utils/psbt.js +0 -0
- /package/{dist/cjs → cjs}/utils/psbt.js.map +0 -0
- /package/{dist/cjs → cjs}/utils.js +0 -0
- /package/{dist/cjs → cjs}/utils.js.map +0 -0
- /package/{dist/types → types}/errorUtils.d.ts +0 -0
- /package/{dist/types → types}/hardware-wallet-manager.d.ts +0 -0
- /package/{dist/types → types}/index.d.ts +0 -0
- /package/{dist/types → types}/initial-state.d.ts +0 -0
- /package/{dist/types → types}/keyring-manager.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/index.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/appClient.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/bip32.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/buffertools.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/clientCommands.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/constants.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/merkelizedPsbt.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/merkle.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/merkleMap.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/policy.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/psbtv2.d.ts +0 -0
- /package/{dist/types → types}/ledger/bitcoin_client/lib/varint.d.ts +0 -0
- /package/{dist/types → types}/ledger/consts.d.ts +0 -0
- /package/{dist/types → types}/ledger/index.d.ts +0 -0
- /package/{dist/types → types}/ledger/types.d.ts +0 -0
- /package/{dist/types → types}/network-utils.d.ts +0 -0
- /package/{dist/types → types}/providers.d.ts +0 -0
- /package/{dist/types → types}/signers.d.ts +0 -0
- /package/{dist/types → types}/storage.d.ts +0 -0
- /package/{dist/types → types}/transactions/__tests__/integration.test.d.ts +0 -0
- /package/{dist/types → types}/transactions/__tests__/syscoin.test.d.ts +0 -0
- /package/{dist/types → types}/transactions/ethereum.d.ts +0 -0
- /package/{dist/types → types}/transactions/index.d.ts +0 -0
- /package/{dist/types → types}/transactions/syscoin.d.ts +0 -0
- /package/{dist/types → types}/trezor/index.d.ts +0 -0
- /package/{dist/types → types}/types.d.ts +0 -0
- /package/{dist/types → types}/utils/derivation-paths.d.ts +0 -0
- /package/{dist/types → types}/utils/psbt.d.ts +0 -0
- /package/{dist/types → types}/utils.d.ts +0 -0
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { INetworkType } from '@sidhujag/sysweb3-network';
|
|
2
|
-
|
|
3
|
-
import { KeyringManager, KeyringAccountType } from '../../../src';
|
|
4
|
-
import { FAKE_PASSWORD, PEACE_SEED_PHRASE } from '../../helpers/constants';
|
|
5
|
-
import { setupMocks } from '../../helpers/setup';
|
|
6
|
-
|
|
7
|
-
describe('Watch-only Import - KeyringManager', () => {
|
|
8
|
-
let keyringManager: KeyringManager;
|
|
9
|
-
let mockVaultStateGetter: jest.Mock;
|
|
10
|
-
let currentVaultState: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
setupMocks();
|
|
14
|
-
await setupTestVault(FAKE_PASSWORD);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('Single-address watch-only (address)', () => {
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
currentVaultState = createMockVaultState({
|
|
20
|
-
activeAccountId: 0,
|
|
21
|
-
activeAccountType: KeyringAccountType.HDAccount,
|
|
22
|
-
networkType: INetworkType.Syscoin,
|
|
23
|
-
chainId: 5700,
|
|
24
|
-
});
|
|
25
|
-
mockVaultStateGetter = jest.fn(() => currentVaultState);
|
|
26
|
-
|
|
27
|
-
keyringManager = await KeyringManager.createInitialized(
|
|
28
|
-
PEACE_SEED_PHRASE,
|
|
29
|
-
FAKE_PASSWORD,
|
|
30
|
-
mockVaultStateGetter
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('imports address as watch-only single-address and blocks derivation', async () => {
|
|
35
|
-
const addr = 'tsys1qtestaddressxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
|
|
36
|
-
const imported = await (keyringManager as any).importWatchOnly(
|
|
37
|
-
addr,
|
|
38
|
-
'Watch-only'
|
|
39
|
-
);
|
|
40
|
-
expect(imported.isImported).toBe(true);
|
|
41
|
-
// xpub === address marks single-address imported
|
|
42
|
-
expect(imported.xpub).toBe(addr);
|
|
43
|
-
expect(imported.xprv).toBe('');
|
|
44
|
-
|
|
45
|
-
// Insert into mock vault and activate
|
|
46
|
-
currentVaultState.accounts[KeyringAccountType.Imported][imported.id] = {
|
|
47
|
-
id: imported.id,
|
|
48
|
-
label: imported.label,
|
|
49
|
-
address: imported.address,
|
|
50
|
-
xpub: imported.xpub,
|
|
51
|
-
xprv: imported.xprv,
|
|
52
|
-
isImported: true,
|
|
53
|
-
isTrezorWallet: false,
|
|
54
|
-
isLedgerWallet: false,
|
|
55
|
-
balances: { syscoin: 0, ethereum: 0 },
|
|
56
|
-
assets: { syscoin: [], ethereum: [] },
|
|
57
|
-
};
|
|
58
|
-
currentVaultState.activeAccount = {
|
|
59
|
-
id: imported.id,
|
|
60
|
-
type: KeyringAccountType.Imported,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// Guards
|
|
64
|
-
const changeAddr = await keyringManager.getChangeAddress(imported.id);
|
|
65
|
-
expect(changeAddr).toBe(imported.address);
|
|
66
|
-
await expect(
|
|
67
|
-
keyringManager.getPubkey(imported.id, false)
|
|
68
|
-
).rejects.toThrow(/watch-only|Public key|not available/i);
|
|
69
|
-
await expect(
|
|
70
|
-
keyringManager.getBip32Path(imported.id, false)
|
|
71
|
-
).rejects.toThrow(/watch-only|BIP32|not available/i);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('XPUB/Descriptor watch-only', () => {
|
|
76
|
-
beforeEach(async () => {
|
|
77
|
-
currentVaultState = createMockVaultState({
|
|
78
|
-
activeAccountId: 0,
|
|
79
|
-
activeAccountType: KeyringAccountType.HDAccount,
|
|
80
|
-
networkType: INetworkType.Syscoin,
|
|
81
|
-
chainId: 57,
|
|
82
|
-
});
|
|
83
|
-
mockVaultStateGetter = jest.fn(() => currentVaultState);
|
|
84
|
-
|
|
85
|
-
keyringManager = await KeyringManager.createInitialized(
|
|
86
|
-
PEACE_SEED_PHRASE,
|
|
87
|
-
FAKE_PASSWORD,
|
|
88
|
-
mockVaultStateGetter
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('imports xpub-like as watch-only and blocks derivation', async () => {
|
|
93
|
-
// Not a real xpub; importWatchOnly should still accept and mark watch-only
|
|
94
|
-
const xpub = 'zpub6testxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
|
|
95
|
-
const imported = await (keyringManager as any).importWatchOnly(
|
|
96
|
-
xpub,
|
|
97
|
-
'Watch-only XPUB'
|
|
98
|
-
);
|
|
99
|
-
expect(imported.xprv).toBe('');
|
|
100
|
-
expect(imported.xpub).toBe(xpub);
|
|
101
|
-
|
|
102
|
-
currentVaultState.accounts[KeyringAccountType.Imported][imported.id] = {
|
|
103
|
-
id: imported.id,
|
|
104
|
-
label: imported.label,
|
|
105
|
-
address: imported.address,
|
|
106
|
-
xpub: imported.xpub,
|
|
107
|
-
xprv: imported.xprv,
|
|
108
|
-
isImported: true,
|
|
109
|
-
isTrezorWallet: false,
|
|
110
|
-
isLedgerWallet: false,
|
|
111
|
-
balances: { syscoin: 0, ethereum: 0 },
|
|
112
|
-
assets: { syscoin: [], ethereum: [] },
|
|
113
|
-
};
|
|
114
|
-
currentVaultState.activeAccount = {
|
|
115
|
-
id: imported.id,
|
|
116
|
-
type: KeyringAccountType.Imported,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
await expect(
|
|
120
|
-
keyringManager.getPubkey(imported.id, false)
|
|
121
|
-
).rejects.toThrow(/watch-only|Public key|not available/i);
|
|
122
|
-
await expect(
|
|
123
|
-
keyringManager.getBip32Path(imported.id, false)
|
|
124
|
-
).rejects.toThrow(/watch-only|BIP32|not available/i);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('imports descriptor as watch-only and blocks derivation', async () => {
|
|
128
|
-
const desc = 'wpkh(xpub6testxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/0/*)';
|
|
129
|
-
const imported = await (keyringManager as any).importWatchOnly(
|
|
130
|
-
desc,
|
|
131
|
-
'Watch-only DESC'
|
|
132
|
-
);
|
|
133
|
-
expect(imported.xprv).toBe('');
|
|
134
|
-
expect(imported.xpub).toBe(desc);
|
|
135
|
-
|
|
136
|
-
currentVaultState.accounts[KeyringAccountType.Imported][imported.id] = {
|
|
137
|
-
id: imported.id,
|
|
138
|
-
label: imported.label,
|
|
139
|
-
address: imported.address,
|
|
140
|
-
xpub: imported.xpub,
|
|
141
|
-
xprv: imported.xprv,
|
|
142
|
-
isImported: true,
|
|
143
|
-
isTrezorWallet: false,
|
|
144
|
-
isLedgerWallet: false,
|
|
145
|
-
balances: { syscoin: 0, ethereum: 0 },
|
|
146
|
-
assets: { syscoin: [], ethereum: [] },
|
|
147
|
-
};
|
|
148
|
-
currentVaultState.activeAccount = {
|
|
149
|
-
id: imported.id,
|
|
150
|
-
type: KeyringAccountType.Imported,
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
await expect(
|
|
154
|
-
keyringManager.getPubkey(imported.id, false)
|
|
155
|
-
).rejects.toThrow(/watch-only|Public key|not available/i);
|
|
156
|
-
await expect(
|
|
157
|
-
keyringManager.getBip32Path(imported.id, false)
|
|
158
|
-
).rejects.toThrow(/watch-only|BIP32|not available/i);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('rejects duplicate watch-only import by address', async () => {
|
|
162
|
-
const addr = 'sys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq';
|
|
163
|
-
const first = await (keyringManager as any).importWatchOnly(addr, 'WO1');
|
|
164
|
-
currentVaultState.accounts[KeyringAccountType.Imported][first.id] = {
|
|
165
|
-
id: first.id,
|
|
166
|
-
label: first.label,
|
|
167
|
-
address: first.address,
|
|
168
|
-
xpub: first.xpub,
|
|
169
|
-
xprv: first.xprv,
|
|
170
|
-
isImported: true,
|
|
171
|
-
isTrezorWallet: false,
|
|
172
|
-
isLedgerWallet: false,
|
|
173
|
-
balances: { syscoin: 0, ethereum: 0 },
|
|
174
|
-
assets: { syscoin: [], ethereum: [] },
|
|
175
|
-
};
|
|
176
|
-
await expect(
|
|
177
|
-
(keyringManager as any).importWatchOnly(addr, 'WO2')
|
|
178
|
-
).rejects.toThrow(/already exists/i);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { INetworkType } from '@sidhujag/sysweb3-network';
|
|
2
|
-
import * as bjs from 'bitcoinjs-lib';
|
|
3
|
-
import * as wif from 'wif';
|
|
4
|
-
|
|
5
|
-
import { KeyringManager, KeyringAccountType } from '../../../src';
|
|
6
|
-
import { FAKE_PASSWORD, PEACE_SEED_PHRASE } from '../../helpers/constants';
|
|
7
|
-
import { setupMocks } from '../../helpers/setup';
|
|
8
|
-
|
|
9
|
-
// Helper to generate deterministic WIFs from a fixed private key for given network
|
|
10
|
-
const generateWif = (network: any): string => {
|
|
11
|
-
const priv = Buffer.from(
|
|
12
|
-
'0101010101010101010101010101010101010101010101010101010101010101',
|
|
13
|
-
'hex'
|
|
14
|
-
);
|
|
15
|
-
const version = network.wif; // 0x80 mainnet, 0xef testnet
|
|
16
|
-
return wif.encode({ version, privateKey: priv, compressed: true });
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe('WIF Import - KeyringManager', () => {
|
|
20
|
-
let keyringManager: KeyringManager;
|
|
21
|
-
let mockVaultStateGetter: jest.Mock;
|
|
22
|
-
let currentVaultState: any;
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
setupMocks();
|
|
26
|
-
await setupTestVault(FAKE_PASSWORD);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('Syscoin mainnet', () => {
|
|
30
|
-
let MAINNET_WIF: string;
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
currentVaultState = createMockVaultState({
|
|
34
|
-
activeAccountId: 0,
|
|
35
|
-
activeAccountType: KeyringAccountType.HDAccount,
|
|
36
|
-
networkType: INetworkType.Syscoin,
|
|
37
|
-
chainId: 57,
|
|
38
|
-
});
|
|
39
|
-
mockVaultStateGetter = jest.fn(() => currentVaultState);
|
|
40
|
-
|
|
41
|
-
keyringManager = await KeyringManager.createInitialized(
|
|
42
|
-
PEACE_SEED_PHRASE,
|
|
43
|
-
FAKE_PASSWORD,
|
|
44
|
-
mockVaultStateGetter
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
MAINNET_WIF = generateWif(bjs.networks.bitcoin);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('validates and imports a mainnet WIF as single-address account', async () => {
|
|
51
|
-
const validation = (keyringManager as any).validateWif(MAINNET_WIF);
|
|
52
|
-
expect(validation.isValid).toBe(true);
|
|
53
|
-
|
|
54
|
-
const imported = await keyringManager.importAccount(
|
|
55
|
-
MAINNET_WIF,
|
|
56
|
-
'WIF Import'
|
|
57
|
-
);
|
|
58
|
-
expect(imported.isImported).toBe(true);
|
|
59
|
-
expect(imported.label).toBe('WIF Import');
|
|
60
|
-
// xpub should equal address to mark single-address mode
|
|
61
|
-
expect(imported.xpub).toBe(imported.address);
|
|
62
|
-
|
|
63
|
-
// Update mock vault with imported account
|
|
64
|
-
currentVaultState.accounts[KeyringAccountType.Imported][imported.id] = {
|
|
65
|
-
id: imported.id,
|
|
66
|
-
label: imported.label,
|
|
67
|
-
address: imported.address,
|
|
68
|
-
xpub: imported.xpub,
|
|
69
|
-
xprv: imported.xprv,
|
|
70
|
-
isImported: true,
|
|
71
|
-
isTrezorWallet: false,
|
|
72
|
-
isLedgerWallet: false,
|
|
73
|
-
balances: { syscoin: 0, ethereum: 0 },
|
|
74
|
-
assets: { syscoin: [], ethereum: [] },
|
|
75
|
-
};
|
|
76
|
-
// Switch active account to the imported one for getter calls
|
|
77
|
-
currentVaultState.activeAccount = {
|
|
78
|
-
id: imported.id,
|
|
79
|
-
type: KeyringAccountType.Imported,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Single-address getters behavior
|
|
83
|
-
const changeAddr = await keyringManager.getChangeAddress(imported.id);
|
|
84
|
-
expect(changeAddr).toBe(imported.address);
|
|
85
|
-
await expect(
|
|
86
|
-
keyringManager.getPubkey(imported.id, false)
|
|
87
|
-
).rejects.toThrow(/not available|Public key/);
|
|
88
|
-
await expect(
|
|
89
|
-
keyringManager.getBip32Path(imported.id, false)
|
|
90
|
-
).rejects.toThrow(/not available|BIP32/);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('Syscoin testnet mismatch', () => {
|
|
95
|
-
let TESTNET_WIF: string;
|
|
96
|
-
|
|
97
|
-
beforeEach(async () => {
|
|
98
|
-
currentVaultState = createMockVaultState({
|
|
99
|
-
activeAccountId: 0,
|
|
100
|
-
activeAccountType: KeyringAccountType.HDAccount,
|
|
101
|
-
networkType: INetworkType.Syscoin,
|
|
102
|
-
chainId: 5700,
|
|
103
|
-
});
|
|
104
|
-
mockVaultStateGetter = jest.fn(() => currentVaultState);
|
|
105
|
-
|
|
106
|
-
keyringManager = await KeyringManager.createInitialized(
|
|
107
|
-
PEACE_SEED_PHRASE,
|
|
108
|
-
FAKE_PASSWORD,
|
|
109
|
-
mockVaultStateGetter
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
TESTNET_WIF = generateWif(bjs.networks.testnet);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('rejects mainnet WIF on testnet (validateWif false)', async () => {
|
|
116
|
-
const mainnetWif = generateWif(bjs.networks.bitcoin);
|
|
117
|
-
const validation = (keyringManager as any).validateWif(mainnetWif);
|
|
118
|
-
expect(validation.isValid).toBe(false);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('accepts testnet WIF on testnet', async () => {
|
|
122
|
-
const validation = (keyringManager as any).validateWif(TESTNET_WIF);
|
|
123
|
-
expect(validation.isValid).toBe(true);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|