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,43 @@ describe('ALGO:', function () {
11281129 } ) ;
11291130 } ) ;
11301131 } ) ;
1132+
1133+ describe ( 'AuditKey' , ( ) => {
1134+ const { key } = algoBackupKey ;
1135+ const walletPassphrase = 'ZQ8MhxT84m4P' ;
1136+
1137+ it ( 'should return { isValid: true) } for valid inputs' , async ( ) => {
1138+ const result = await basecoin . auditKey ( {
1139+ encryptedPrv : key ,
1140+ walletPassphrase,
1141+ } ) ;
1142+ result . should . deepEqual ( { isValid : true } ) ;
1143+ } ) ;
1144+
1145+ it ( 'should return { isValid: false } if the walletPassphrase is incorrect' , async ( ) => {
1146+ const result = await basecoin . auditKey ( {
1147+ encryptedPrv : key ,
1148+ walletPassphrase : 'foo' ,
1149+ } ) ;
1150+ result . should . deepEqual ( { isValid : false , message : "failed to decrypt prv: ccm: tag doesn't match" } ) ;
1151+ } ) ;
1152+ it ( 'should return { isValid: false } if the key is altered' , async ( ) => {
1153+ const alteredKey = key . replace ( / [ 0 - 9 ] / g, '0' ) ;
1154+ const result = await basecoin . auditKey ( {
1155+ encryptedPrv : alteredKey ,
1156+ walletPassphrase,
1157+ } ) ;
1158+ result . isValid . should . equal ( false ) ;
1159+ } ) ;
1160+
1161+ it ( 'should return { isValid: false } if the key is not a valid key' , async ( ) => {
1162+ const invalidKey = '#@)$#($*@)#($*' ;
1163+ const encryptedPrv = encrypt ( walletPassphrase , invalidKey ) ;
1164+ const result = await basecoin . auditKey ( {
1165+ encryptedPrv,
1166+ walletPassphrase,
1167+ } ) ;
1168+ result . should . deepEqual ( { isValid : false , message : 'Invalid private key' } ) ;
1169+ } ) ;
1170+ } ) ;
11311171} ) ;
0 commit comments