@@ -7,7 +7,7 @@ import * as nock from 'nock';
77import * as should from 'should' ;
88import assert = require( 'assert' ) ;
99
10- import { common , generateGPGKeyPair , encryptAndSignText } from '@bitgo/sdk-core' ;
10+ import { common , generateGPGKeyPair } from '@bitgo/sdk-core' ;
1111import { bip32 , ECPair } from '@bitgo/utxo-lib' ;
1212import * as _ from 'lodash' ;
1313import * as BitGoJS from '../../src/index' ;
@@ -709,19 +709,12 @@ describe('BitGo Prototype Methods', function () {
709709 . post ( '/api/auth/v1/session' )
710710 . reply ( 200 , async ( uri , requestBody ) => {
711711 assert ( typeof requestBody === 'object' ) ;
712- should . exist ( requestBody . publicKey ) ;
713712 should . exist ( requestBody . userId ) ;
714713 should . exist ( requestBody . passkey ) ;
715714 requestBody . userId . should . equal ( userId ) ;
716715 requestBody . passkey . should . equal ( passkey ) ;
717- const encryptedToken = ( await encryptAndSignText (
718- 'access_token' ,
719- requestBody . publicKey ,
720- keyPair . privateKey
721- ) ) as string ;
722-
723716 return {
724- encryptedToken : encryptedToken ,
717+ access_token : 'access_token' ,
725718 user :
{ username :
'[email protected] ' } , 726719 } ;
727720 } ) ;
@@ -732,105 +725,6 @@ describe('BitGo Prototype Methods', function () {
732725 response . access_token . should . equal ( 'access_token' ) ;
733726 } ) ;
734727
735- it ( 'should not authenticate with wrong encryption key' , async ( ) => {
736- const keyPair = await generateGPGKeyPair ( 'secp256k1' ) ;
737-
738- nock ( 'https://bitgo.fakeurl' )
739- . persist ( )
740- . get ( '/api/v1/client/constants' )
741- . reply ( 200 , { ttl : 3600 , constants : { passkeyBitGoGpgKey : keyPair . publicKey } } ) ;
742- nock ( 'https://bitgo.fakeurl' )
743- . post ( '/api/auth/v1/session' )
744- . reply ( 200 , async ( ) => {
745- const keyPair = await generateGPGKeyPair ( 'secp256k1' ) ;
746- const encryptedToken = ( await encryptAndSignText (
747- 'access_token' ,
748- keyPair . publicKey ,
749- keyPair . privateKey
750- ) ) as string ;
751- return {
752- encryptedToken : encryptedToken ,
753- user :
{ username :
'[email protected] ' } , 754- } ;
755- } ) ;
756-
757- const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' } ) ;
758- try {
759- await bitgo . authenticateWithPasskey (
760- '{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "123"}}'
761- ) ;
762- assert . fail ( 'Expected error not thrown' ) ;
763- } catch ( e ) {
764- assert . equal ( e . message , 'Error decrypting message: Session key decryption failed.' ) ;
765- }
766- } ) ;
767-
768- it ( 'should not authenticate with wrong signing key' , async ( ) => {
769- const userId = '123' ;
770- const passkey = `{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "${ userId } "}}` ;
771- const badKeyPair = await generateGPGKeyPair ( 'secp256k1' ) ;
772- const bitgoKeyPair = await generateGPGKeyPair ( 'secp256k1' ) ;
773-
774- nock ( 'https://bitgo.fakeurl' )
775- . persist ( )
776- . get ( '/api/v1/client/constants' )
777- . reply ( 200 , { ttl : 3600 , constants : { passkeyBitGoGpgKey : bitgoKeyPair . publicKey } } ) ;
778-
779- nock ( 'https://bitgo.fakeurl' )
780- . post ( '/api/auth/v1/session' )
781- . reply ( 200 , async ( uri , requestBody ) => {
782- assert ( typeof requestBody === 'object' ) ;
783- const encryptedToken = ( await encryptAndSignText (
784- 'access_token' ,
785- requestBody . publicKey ,
786- badKeyPair . privateKey
787- ) ) as string ;
788-
789- return {
790- encryptedToken : encryptedToken ,
791- user :
{ username :
'[email protected] ' } , 792- } ;
793- } ) ;
794-
795- const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' } ) ;
796- try {
797- await bitgo . authenticateWithPasskey ( passkey ) ;
798- assert . fail ( 'Expected error not thrown' ) ;
799- } catch ( e ) {
800- assert ( e . message . startsWith ( 'Error decrypting message: Could not find signing key with key ID' ) ) ;
801- }
802- } ) ;
803- it ( 'should throw - missing bitgo public key' , async ( ) => {
804- const userId = '123' ;
805- const passkey = `{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "${ userId } "}}` ;
806- const keyPair = await generateGPGKeyPair ( 'secp256k1' ) ;
807-
808- nock ( 'https://bitgo.fakeurl' ) . persist ( ) . get ( '/api/v1/client/constants' ) . reply ( 200 , { ttl : 3600 , constants : { } } ) ;
809-
810- nock ( 'https://bitgo.fakeurl' )
811- . post ( '/api/auth/v1/session' )
812- . reply ( 200 , async ( uri , requestBody ) => {
813- assert ( typeof requestBody === 'object' ) ;
814- const encryptedToken = ( await encryptAndSignText (
815- 'access_token' ,
816- requestBody . publicKey ,
817- keyPair . privateKey
818- ) ) as string ;
819-
820- return {
821- encryptedToken : encryptedToken ,
822- user :
{ username :
'[email protected] ' } , 823- } ;
824- } ) ;
825-
826- const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' } ) ;
827- try {
828- await bitgo . authenticateWithPasskey ( passkey ) ;
829- assert . fail ( 'Expected error not thrown' ) ;
830- } catch ( e ) {
831- assert . equal ( e . message , 'Unable to get passkeyBitGoGpgKey' ) ;
832- }
833- } ) ;
834728 it ( 'should throw - invalid userHandle' , async ( ) => {
835729 const passkey = `{"id": "id", "response": {"authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": 123}}` ;
836730 const bitgo = TestBitGo . decorate ( BitGo , { env : 'mock' } ) ;
@@ -862,7 +756,7 @@ describe('BitGo Prototype Methods', function () {
862756 assert ( e . message . includes ( 'JSON' ) ) ;
863757 }
864758 } ) ;
865- it ( 'should throw - missing encrypted token' , async ( ) => {
759+ it ( 'should throw - missing access token' , async ( ) => {
866760 const passkey = `{"id": "id", "response": { "authenticatorData": "123", "clientDataJSON": "123", "signature": "123", "userHandle": "123"}}` ;
867761 nock ( 'https://bitgo.fakeurl' )
868762 . post ( '/api/auth/v1/session' )
0 commit comments