Skip to content

Commit cdbc749

Browse files
committed
fix(api): Fixed better handling of multiple keys in sign()
1 parent acfa0af commit cdbc749

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/u2f-api.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,15 @@ export function sign(
268268

269269
const appId = _signRequests[ 0 ].appId;
270270
const challenge = _signRequests[ 0 ].challenge;
271-
const registeredKeys = _signRequests
271+
const registeredKeys = ( [ ] as Array< RegisteredKey > ).concat(
272+
..._signRequests
272273
.map( ( { version, keyHandle, appId } ) =>
273-
( { version, keyHandle, appId } as RegisteredKey )
274-
);
274+
arrayify( keyHandle )
275+
.map( keyHandle =>
276+
( { version, keyHandle, appId } as RegisteredKey )
277+
)
278+
)
279+
);
275280

276281
u2f.sign( appId, challenge, registeredKeys, callback, timeout );
277282
} );

test/u2f-api/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,15 @@ describe( 'general', ( ) =>
271271
{
272272
await api.ensureSupport( );
273273

274-
const request = "req";
274+
const request = {
275+
version: 'U2F_V2',
276+
appId,
277+
challenge: 'Sk1hrSXt_KswFHOhTQ7BED45yQRU2gqY37dfBQ8nNiI',
278+
keyHandle: 'foo',
279+
};
275280

276-
await api.register( { appId, request } );
281+
await api.register( request );
277282

278-
await api.sign( { appId, request } );
283+
await api.sign( request );
279284
} ) );
280285
} );

0 commit comments

Comments
 (0)