11import { AlgoLib , Talgo } from '../../src' ;
22import { TestBitGo , TestBitGoAPI } from '@bitgo/sdk-test' ;
3- import { BitGoAPI } from '@bitgo/sdk-api' ;
3+ import { BitGoAPI , encrypt } from '@bitgo/sdk-api' ;
44import * as AlgoResources from '../fixtures/algo' ;
55import { randomBytes } from 'crypto' ;
66import { coins } from '@bitgo/statics' ;
@@ -10,6 +10,7 @@ import { Algo } from '../../src/algo';
1010import BigNumber from 'bignumber.js' ;
1111import { TransactionBuilderFactory } from '../../src/lib' ;
1212import { KeyPair } from '@bitgo/sdk-core' ;
13+ import { algoBackupKey } from './fixtures/algoBackupKey' ;
1314
1415describe ( 'ALGO:' , function ( ) {
1516 let bitgo : TestBitGoAPI ;
@@ -1128,4 +1129,55 @@ describe('ALGO:', function () {
11281129 } ) ;
11291130 } ) ;
11301131 } ) ;
1132+
1133+ describe ( 'AuditKey' , ( ) => {
1134+ const { key } = algoBackupKey ;
1135+ const walletPassphrase = 'ZQ8MhxT84m4P' ;
1136+
1137+ it ( 'should return for valid inputs' , ( ) => {
1138+ basecoin . assertIsValidKey ( {
1139+ encryptedPrv : key ,
1140+ walletPassphrase,
1141+ } ) ;
1142+ } ) ;
1143+
1144+ it ( 'should throw error if the walletPassphrase is incorrect' , ( ) => {
1145+ assert . throws (
1146+ ( ) => {
1147+ basecoin . assertIsValidKey ( {
1148+ encryptedPrv : key ,
1149+ walletPassphrase : 'foo' ,
1150+ } ) ;
1151+ } ,
1152+ { message : "failed to decrypt prv: ccm: tag doesn't match" }
1153+ ) ;
1154+ } ) ;
1155+
1156+ it ( 'should throw error if the key is altered' , ( ) => {
1157+ const alteredKey = key . replace ( / [ 0 - 9 ] / g, '0' ) ;
1158+ assert . throws (
1159+ ( ) => {
1160+ basecoin . assertIsValidKey ( {
1161+ encryptedPrv : alteredKey ,
1162+ walletPassphrase,
1163+ } ) ;
1164+ } ,
1165+ { message : 'failed to decrypt prv: json decrypt: invalid parameters' }
1166+ ) ;
1167+ } ) ;
1168+
1169+ it ( 'should throw error if the key is not a valid key' , ( ) => {
1170+ const invalidKey = '#@)$#($*@)#($*' ;
1171+ const encryptedPrv = encrypt ( walletPassphrase , invalidKey ) ;
1172+ assert . throws (
1173+ ( ) => {
1174+ basecoin . assertIsValidKey ( {
1175+ encryptedPrv,
1176+ walletPassphrase,
1177+ } ) ;
1178+ } ,
1179+ { message : 'Invalid private key' }
1180+ ) ;
1181+ } ) ;
1182+ } ) ;
11311183} ) ;
0 commit comments