-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathkeychains.ts
More file actions
73 lines (62 loc) · 2.15 KB
/
keychains.ts
File metadata and controls
73 lines (62 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as assert from 'assert';
import 'should';
import { type TestBitGoAPI, TestBitGo } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';
import { AbstractUtxoCoin } from '../../src';
import { Tbtc } from '../../src/impl/btc';
import { utxoCoins } from './util';
function run(coin: AbstractUtxoCoin) {
describe(`UTXO Keychains ${coin.getChain()}`, function () {
it('validates pub', function () {
const { pub } = coin.keychains().create();
assert.ok(pub);
coin.isValidPub(pub).should.equal(true);
});
});
}
utxoCoins.forEach((c) => run(c));
describe('Audit Key', function () {
// Encrypted backup key fixture for testing assertIsValidKey
const btcBackupKey = {
key:
'{"iv":"JgqqE4W45/tKBSMSYqD+qg==","v":1,"iter":10000,"ks":256,"ts":64,"mode"' +
':"ccm","adata":"","cipher":"aes","salt":"kiLPf8VSdI0=","ct":"zUh4Oko/06g02E' +
'wnqOfzJbTwtE2p3b19jDk8Tum07Jv3N/RP7Bo0w/ObLBO1uIJFossO3nJ1JS+7t/vPQhdCtN8oD' +
'6YrZnEZYrRwN6JQkL1uYPnZ1PoWbYI9navK5CLU1KQwDTO9YEN46++OrzFH+CjpQVLblaw="}',
};
let bitgo: TestBitGoAPI;
let coin: Tbtc;
before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
bitgo.safeRegister('tbtc', Tbtc.createInstance);
bitgo.initializeTestVars();
coin = bitgo.coin('tbtc') as Tbtc;
});
it('should return for valid inputs', function () {
coin.assertIsValidKey({
encryptedPrv: btcBackupKey.key,
walletPassphrase: 'kAm[EFQ6o=SxlcLFDw%,',
});
});
it('should throw error if the walletPassphrase is incorrect', function () {
assert.throws(
() =>
coin.assertIsValidKey({
encryptedPrv: btcBackupKey.key,
walletPassphrase: 'foo',
}),
{ message: "failed to decrypt prv: ccm: tag doesn't match" }
);
});
it('should throw if the key is altered', function () {
const alteredKey = btcBackupKey.key.replace(/[0-9]/g, '0');
assert.throws(
() =>
coin.assertIsValidKey({
encryptedPrv: alteredKey,
walletPassphrase: 'kAm[EFQ6o=SxlcLFDw%,',
}),
{ message: 'failed to decrypt prv: json decrypt: invalid parameters' }
);
});
});