Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 0 additions & 260 deletions modules/abstract-utxo/test/unit/impl/btc/unit/btc.ts

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 0 additions & 41 deletions modules/abstract-utxo/test/unit/impl/ltc/unit/index.ts

This file was deleted.

55 changes: 55 additions & 0 deletions modules/abstract-utxo/test/unit/keychains.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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';

Expand All @@ -16,3 +20,54 @@ function run(coin: AbstractUtxoCoin) {
}

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' }
);
});
});
Loading