@@ -25,6 +25,7 @@ import {
2525 BulkWalletShareOptions ,
2626 KeychainWithEncryptedPrv ,
2727 WalletWithKeychains ,
28+ multisigTypes ,
2829} from '@bitgo/sdk-core' ;
2930import { BitGo } from '../../../src' ;
3031import { afterEach } from 'mocha' ;
@@ -184,6 +185,7 @@ describe('V2 Wallets:', function () {
184185 } ) ;
185186
186187 describe ( 'Generate wallet:' , function ( ) {
188+ const sandbox = sinon . createSandbox ( ) ;
187189 it ( 'should validate parameters' , async function ( ) {
188190 let params = { } ;
189191 await wallets . generateWallet ( params ) . should . be . rejectedWith ( 'Missing parameter: label' ) ;
@@ -475,6 +477,42 @@ describe('V2 Wallets:', function () {
475477 params . passphrase
476478 ) ;
477479 } ) ;
480+
481+ it ( 'should generate hot onchain wallet without passing multisig type' , async ( ) => {
482+ const params : GenerateWalletOptions = {
483+ label : 'test wallet' ,
484+ passphrase : 'multisig password' ,
485+ enterprise : 'enterprise' ,
486+ passcodeEncryptionCode : 'originalPasscodeEncryptionCode' ,
487+ } ;
488+
489+ const walletNock = nock ( bgUrl )
490+ . post ( '/api/v2/tbtc/wallet/add' , function ( body ) {
491+ body . type . should . equal ( 'hot' ) ;
492+ return true ;
493+ } )
494+ . reply ( 200 ) ;
495+
496+ nock ( bgUrl )
497+ . post ( '/api/v2/tbtc/key' , _ . matches ( { source : 'bitgo' } ) )
498+ . reply ( 200 , { pub : 'bitgoPub' } ) ;
499+ nock ( bgUrl ) . post ( '/api/v2/tbtc/key' , _ . matches ( { } ) ) . reply ( 200 ) ;
500+ nock ( bgUrl )
501+ . post ( '/api/v2/tbtc/key' , _ . matches ( { source : 'backup' } ) )
502+ . reply ( 200 , { pub : 'backupPub' } ) ;
503+
504+ const generateWalletSpy = sandbox . spy ( wallets , 'generateWallet' ) ;
505+ const response = await wallets . generateWallet ( params ) ;
506+ walletNock . isDone ( ) . should . be . true ( ) ;
507+ sinon . assert . calledOnce ( generateWalletSpy ) ;
508+ assert . equal ( generateWalletSpy . firstCall ?. args [ 0 ] ?. multisigType , multisigTypes . onchain ) ;
509+ assert . ok ( response . encryptedWalletPassphrase ) ;
510+ assert . ok ( response . wallet ) ;
511+ assert . equal (
512+ bitgo . decrypt ( { input : response . encryptedWalletPassphrase , password : params . passcodeEncryptionCode } ) ,
513+ params . passphrase
514+ ) ;
515+ } ) ;
478516 } ) ;
479517
480518 describe ( 'Generate TSS wallet:' , function ( ) {
@@ -552,6 +590,58 @@ describe('V2 Wallets:', function () {
552590 ) ;
553591 } ) ;
554592
593+ it ( 'should create a new TSS wallet without passing multisig type' , async function ( ) {
594+ const stubbedKeychainsTriplet : KeychainsTriplet = {
595+ userKeychain : {
596+ id : '1' ,
597+ pub : 'userPub' ,
598+ type : 'independent' ,
599+ source : 'user' ,
600+ } ,
601+ backupKeychain : {
602+ id : '2' ,
603+ pub : 'userPub' ,
604+ type : 'independent' ,
605+ source : 'backup' ,
606+ } ,
607+ bitgoKeychain : {
608+ id : '3' ,
609+ pub : 'userPub' ,
610+ type : 'independent' ,
611+ source : 'bitgo' ,
612+ } ,
613+ } ;
614+ sandbox . stub ( TssUtils . prototype , 'createKeychains' ) . resolves ( stubbedKeychainsTriplet ) ;
615+
616+ const walletNock = nock ( 'https://bitgo.fakeurl' )
617+ . post ( '/api/v2/tsol/wallet/add' , function ( body ) {
618+ body . multisigType . should . equal ( multisigTypes . tss ) ;
619+ return true ;
620+ } )
621+ . reply ( 200 ) ;
622+
623+ const wallets = new Wallets ( bitgo , tsol ) ;
624+
625+ const params = {
626+ label : 'tss wallet' ,
627+ passphrase : 'tss password' ,
628+ enterprise : 'enterprise' ,
629+ passcodeEncryptionCode : 'originalPasscodeEncryptionCode' ,
630+ } ;
631+
632+ const generateWalletSpy = sandbox . spy ( wallets , 'generateWallet' ) ;
633+ const response = await wallets . generateWallet ( params ) ;
634+ walletNock . isDone ( ) . should . be . true ( ) ;
635+ sinon . assert . calledOnce ( generateWalletSpy ) ;
636+ assert . equal ( generateWalletSpy . firstCall ?. args [ 0 ] ?. multisigType , multisigTypes . tss ) ;
637+ assert . ok ( response . encryptedWalletPassphrase ) ;
638+ assert . ok ( response . wallet ) ;
639+ assert . equal (
640+ bitgo . decrypt ( { input : response . encryptedWalletPassphrase , password : params . passcodeEncryptionCode } ) ,
641+ params . passphrase
642+ ) ;
643+ } ) ;
644+
555645 it ( 'should create a new TSS wallet without providing passcodeEncryptionCode' , async function ( ) {
556646 const stubbedKeychainsTriplet : KeychainsTriplet = {
557647 userKeychain : {
@@ -961,6 +1051,62 @@ describe('V2 Wallets:', function () {
9611051 ) ;
9621052 } ) ;
9631053
1054+ it ( `should create a new ${ coin } TSS MPCv2 hot wallet without passing multisig type` , async function ( ) {
1055+ const testCoin = bitgo . coin ( coin ) ;
1056+ const stubbedKeychainsTriplet : KeychainsTriplet = {
1057+ userKeychain : {
1058+ id : '1' ,
1059+ commonKeychain : 'userPub' ,
1060+ type : 'tss' ,
1061+ source : 'user' ,
1062+ } ,
1063+ backupKeychain : {
1064+ id : '2' ,
1065+ commonKeychain : 'userPub' ,
1066+ type : 'tss' ,
1067+ source : 'backup' ,
1068+ } ,
1069+ bitgoKeychain : {
1070+ id : '3' ,
1071+ commonKeychain : 'userPub' ,
1072+ type : 'tss' ,
1073+ source : 'bitgo' ,
1074+ } ,
1075+ } ;
1076+ const stubCreateKeychains = sandbox
1077+ . stub ( ECDSAUtils . EcdsaMPCv2Utils . prototype , 'createKeychains' )
1078+ . resolves ( stubbedKeychainsTriplet ) ;
1079+
1080+ const walletNock = nock ( 'https://bitgo.fakeurl' )
1081+ . post ( `/api/v2/${ coin } /wallet/add` , function ( body ) {
1082+ body . multisigType . should . equal ( multisigTypes . tss ) ;
1083+ return true ;
1084+ } )
1085+ . reply ( 200 ) ;
1086+
1087+ const wallets = new Wallets ( bitgo , testCoin ) ;
1088+
1089+ const params = {
1090+ label : 'tss wallet' ,
1091+ passphrase : 'tss password' ,
1092+ enterprise : 'enterprise' ,
1093+ passcodeEncryptionCode : 'originalPasscodeEncryptionCode' ,
1094+ walletVersion : 3 ,
1095+ } ;
1096+
1097+ const response = await wallets . generateWallet ( params ) ;
1098+
1099+ walletNock . isDone ( ) . should . be . true ( ) ;
1100+ stubCreateKeychains . calledOnce . should . be . true ( ) ;
1101+
1102+ assert . ok ( response . encryptedWalletPassphrase ) ;
1103+ assert . ok ( response . wallet ) ;
1104+ assert . equal (
1105+ bitgo . decrypt ( { input : response . encryptedWalletPassphrase , password : params . passcodeEncryptionCode } ) ,
1106+ params . passphrase
1107+ ) ;
1108+ } ) ;
1109+
9641110 it ( `should create a new ${ coin } TSS MPCv2 cold wallet` , async function ( ) {
9651111 const testCoin = bitgo . coin ( coin ) ;
9661112 const bitgoKeyId = 'key123' ;
0 commit comments