@@ -47,7 +47,6 @@ import {
4747 AddAccessTokenOptions ,
4848 AddAccessTokenResponse ,
4949 AuthenticateOptions ,
50- AuthenticateWithPasskeyOptions ,
5150 AuthenticateWithAuthCodeOptions ,
5251 BitGoAPIOptions ,
5352 BitGoJson ,
@@ -777,26 +776,26 @@ export class BitGoAPI implements BitGoBase {
777776 * Validate the passkey response is in the expected format
778777 * Should be as is returned from navigator.credentials.get()
779778 */
780- validateWebauthnResponse ( params : AuthenticateWithPasskeyOptions ) : void {
781- if ( ! _ . isString ( params . username ) ) {
782- throw new Error ( 'expected string username' ) ;
783- }
784- const webauthnResponse = JSON . parse ( params . webauthnResponse ) ;
785- if ( ! webauthnResponse && ! webauthnResponse . response ) {
779+ validatePasskeyResponse ( passkeyResponse : string ) : void {
780+ const parsedPasskeyResponse = JSON . parse ( passkeyResponse ) ;
781+ if ( ! parsedPasskeyResponse && ! parsedPasskeyResponse . response ) {
786782 throw new Error ( 'unexpected webauthnResponse' ) ;
787783 }
788- if ( ! _ . isString ( webauthnResponse . id ) ) {
784+ if ( ! _ . isString ( parsedPasskeyResponse . id ) ) {
789785 throw new Error ( 'id is missing' ) ;
790786 }
791- if ( ! _ . isString ( webauthnResponse . response . authenticatorData ) ) {
787+ if ( ! _ . isString ( parsedPasskeyResponse . response . authenticatorData ) ) {
792788 throw new Error ( 'authenticatorData is missing' ) ;
793789 }
794- if ( ! _ . isString ( webauthnResponse . response . clientDataJSON ) ) {
790+ if ( ! _ . isString ( parsedPasskeyResponse . response . clientDataJSON ) ) {
795791 throw new Error ( 'clientDataJSON is missing' ) ;
796792 }
797- if ( ! _ . isString ( webauthnResponse . response . signature ) ) {
793+ if ( ! _ . isString ( parsedPasskeyResponse . response . signature ) ) {
798794 throw new Error ( 'signature is missing' ) ;
799795 }
796+ if ( ! _ . isString ( parsedPasskeyResponse . response . userHandle ) ) {
797+ throw new Error ( 'userHandle is missing' ) ;
798+ }
800799 }
801800
802801 /**
@@ -945,22 +944,22 @@ export class BitGoAPI implements BitGoBase {
945944 /**
946945 * Login to the bitgo platform with passkey.
947946 */
948- async authenticateWithPasskey ( params : AuthenticateWithPasskeyOptions ) : Promise < LoginResponse | any > {
947+ async authenticateWithPasskey ( passkey : string ) : Promise < LoginResponse | any > {
949948 try {
950- if ( ! _ . isObject ( params ) ) {
951- throw new Error ( 'required object params' ) ;
952- }
953-
954949 if ( this . _token ) {
955950 return new Error ( 'already logged in' ) ;
956951 }
957952
958953 const authUrl = this . microservicesUrl ( '/api/auth/v1/session' ) ;
959954 const request = this . post ( authUrl ) ;
960955
961- this . validateWebauthnResponse ( params ) ;
956+ this . validatePasskeyResponse ( passkey ) ;
957+ const userId = JSON . parse ( passkey ) . response . userHandle ;
962958
963- const response : superagent . Response = await request . send ( params ) ;
959+ const response : superagent . Response = await request . send ( {
960+ passkey : passkey ,
961+ userId : userId ,
962+ } ) ;
964963 // extract body and user information
965964 const body = response . body ;
966965 this . _user = body . user ;
0 commit comments