11import * as assert from 'assert' ;
22
33import 'should' ;
4+ import { type TestBitGoAPI , TestBitGo } from '@bitgo/sdk-test' ;
5+ import { BitGoAPI } from '@bitgo/sdk-api' ;
6+
47import { AbstractUtxoCoin } from '../../src' ;
8+ import { Tbtc } from '../../src/impl/btc' ;
59
610import { utxoCoins } from './util' ;
711
@@ -16,3 +20,54 @@ function run(coin: AbstractUtxoCoin) {
1620}
1721
1822utxoCoins . forEach ( ( c ) => run ( c ) ) ;
23+
24+ describe ( 'Audit Key' , function ( ) {
25+ // Encrypted backup key fixture for testing assertIsValidKey
26+ const btcBackupKey = {
27+ key :
28+ '{"iv":"JgqqE4W45/tKBSMSYqD+qg==","v":1,"iter":10000,"ks":256,"ts":64,"mode"' +
29+ ':"ccm","adata":"","cipher":"aes","salt":"kiLPf8VSdI0=","ct":"zUh4Oko/06g02E' +
30+ 'wnqOfzJbTwtE2p3b19jDk8Tum07Jv3N/RP7Bo0w/ObLBO1uIJFossO3nJ1JS+7t/vPQhdCtN8oD' +
31+ '6YrZnEZYrRwN6JQkL1uYPnZ1PoWbYI9navK5CLU1KQwDTO9YEN46++OrzFH+CjpQVLblaw="}' ,
32+ } ;
33+
34+ let bitgo : TestBitGoAPI ;
35+ let coin : Tbtc ;
36+
37+ before ( function ( ) {
38+ bitgo = TestBitGo . decorate ( BitGoAPI , { env : 'test' } ) ;
39+ bitgo . safeRegister ( 'tbtc' , Tbtc . createInstance ) ;
40+ bitgo . initializeTestVars ( ) ;
41+ coin = bitgo . coin ( 'tbtc' ) as Tbtc ;
42+ } ) ;
43+
44+ it ( 'should return for valid inputs' , function ( ) {
45+ coin . assertIsValidKey ( {
46+ encryptedPrv : btcBackupKey . key ,
47+ walletPassphrase : 'kAm[EFQ6o=SxlcLFDw%,' ,
48+ } ) ;
49+ } ) ;
50+
51+ it ( 'should throw error if the walletPassphrase is incorrect' , function ( ) {
52+ assert . throws (
53+ ( ) =>
54+ coin . assertIsValidKey ( {
55+ encryptedPrv : btcBackupKey . key ,
56+ walletPassphrase : 'foo' ,
57+ } ) ,
58+ { message : "failed to decrypt prv: ccm: tag doesn't match" }
59+ ) ;
60+ } ) ;
61+
62+ it ( 'should throw if the key is altered' , function ( ) {
63+ const alteredKey = btcBackupKey . key . replace ( / [ 0 - 9 ] / g, '0' ) ;
64+ assert . throws (
65+ ( ) =>
66+ coin . assertIsValidKey ( {
67+ encryptedPrv : alteredKey ,
68+ walletPassphrase : 'kAm[EFQ6o=SxlcLFDw%,' ,
69+ } ) ,
70+ { message : 'failed to decrypt prv: json decrypt: invalid parameters' }
71+ ) ;
72+ } ) ;
73+ } ) ;
0 commit comments