Comparing version 1.0.7 to 1.0.8
@@ -1,8 +0,19 @@ | ||
export declare type NotYetTyped = { | ||
[key: string]: any; | ||
}; | ||
export declare type RegisterRequest = NotYetTyped; | ||
export declare type SignRequest = NotYetTyped; | ||
export declare type RegisterResponse = NotYetTyped; | ||
export declare type SignResponse = NotYetTyped; | ||
export interface RegisterRequest { | ||
version: string; | ||
appId: string; | ||
challenge: string; | ||
} | ||
export interface SignRequest extends RegisterRequest { | ||
keyHandle: string; | ||
} | ||
export interface RegisterResponse { | ||
clientData: string; | ||
registrationData: string; | ||
version: string; | ||
} | ||
export interface SignResponse { | ||
clientData: string; | ||
keyHandle: string; | ||
signatureData: string; | ||
} | ||
export declare const ErrorCodes: { | ||
@@ -9,0 +20,0 @@ OK: number; |
@@ -11,37 +11,42 @@ 'use strict'; | ||
function getBackend() { | ||
if (!_backend) | ||
_backend = new Promise(function (resolve, reject) { | ||
function notSupported() { | ||
resolve({ u2f: null }); | ||
} | ||
if (!isBrowser) | ||
return notSupported(); | ||
if (isSafari) | ||
// Safari doesn't support U2F, and the Safari-FIDO-U2F | ||
// extension lacks full support (Multi-facet apps), so we | ||
// block it until proper support. | ||
return notSupported(); | ||
var hasNativeSupport = (typeof window.u2f !== 'undefined') && | ||
(typeof window.u2f.sign === 'function'); | ||
if (hasNativeSupport) | ||
return resolve({ u2f: window.u2f }); | ||
if (isEDGE) | ||
// We don't want to check for Google's extension hack on EDGE | ||
// as it'll cause trouble (popups, etc) | ||
return notSupported(); | ||
if (location.protocol === 'http:') | ||
// U2F isn't supported over http, only https | ||
return notSupported(); | ||
if (typeof MessageChannel === 'undefined') | ||
// Unsupported browser, the chrome hack would throw | ||
return notSupported(); | ||
// Test for google extension support | ||
chromeApi.isSupported(function (ok) { | ||
if (ok) | ||
resolve({ u2f: chromeApi }); | ||
else | ||
notSupported(); | ||
}); | ||
if (_backend) | ||
return _backend; | ||
var supportChecker = new Promise(function (resolve, reject) { | ||
function notSupported() { | ||
resolve({ u2f: null }); | ||
} | ||
if (!isBrowser) | ||
return notSupported(); | ||
if (isSafari) | ||
// Safari doesn't support U2F, and the Safari-FIDO-U2F | ||
// extension lacks full support (Multi-facet apps), so we | ||
// block it until proper support. | ||
return notSupported(); | ||
var hasNativeSupport = (typeof window.u2f !== 'undefined') && | ||
(typeof window.u2f.sign === 'function'); | ||
if (hasNativeSupport) | ||
return resolve({ u2f: window.u2f }); | ||
if (isEDGE) | ||
// We don't want to check for Google's extension hack on EDGE | ||
// as it'll cause trouble (popups, etc) | ||
return notSupported(); | ||
if (location.protocol === 'http:') | ||
// U2F isn't supported over http, only https | ||
return notSupported(); | ||
if (typeof MessageChannel === 'undefined') | ||
// Unsupported browser, the chrome hack would throw | ||
return notSupported(); | ||
// Test for google extension support | ||
chromeApi.isSupported(function (ok) { | ||
if (ok) | ||
resolve({ u2f: chromeApi }); | ||
else | ||
notSupported(); | ||
}); | ||
return _backend; | ||
}) | ||
.then(function (response) { | ||
_backend = response.u2f ? supportChecker : null; | ||
return response; | ||
}); | ||
return supportChecker; | ||
} | ||
@@ -48,0 +53,0 @@ exports.ErrorCodes = { |
@@ -18,59 +18,83 @@ 'use strict'; | ||
export declare type NotYetTyped = { [ key: string ]: any; }; | ||
export declare type RegisterRequest = NotYetTyped; | ||
export declare type SignRequest = NotYetTyped; | ||
export declare type RegisterResponse = NotYetTyped; | ||
export declare type SignResponse = NotYetTyped; | ||
export interface RegisterRequest { | ||
version: string; | ||
appId: string; | ||
challenge: string; | ||
} | ||
export interface SignRequest | ||
extends RegisterRequest { | ||
keyHandle: string; | ||
} | ||
export interface RegisterResponse { | ||
clientData: string; | ||
registrationData: string; | ||
version: string; | ||
} | ||
export interface SignResponse { | ||
clientData: string; | ||
keyHandle: string; | ||
signatureData: string; | ||
} | ||
var _backend: Promise< API > = null; | ||
function getBackend( ) | ||
{ | ||
if ( !_backend ) | ||
_backend = new Promise< API >( function( resolve, reject ) | ||
if ( _backend ) | ||
return _backend; | ||
const supportChecker = new Promise< API >( function( resolve, reject ) | ||
{ | ||
function notSupported( ) | ||
{ | ||
function notSupported( ) | ||
{ | ||
resolve( { u2f: null } ); | ||
} | ||
resolve( { u2f: null } ); | ||
} | ||
if ( !isBrowser ) | ||
return notSupported( ); | ||
if ( !isBrowser ) | ||
return notSupported( ); | ||
if ( isSafari ) | ||
// Safari doesn't support U2F, and the Safari-FIDO-U2F | ||
// extension lacks full support (Multi-facet apps), so we | ||
// block it until proper support. | ||
return notSupported( ); | ||
if ( isSafari ) | ||
// Safari doesn't support U2F, and the Safari-FIDO-U2F | ||
// extension lacks full support (Multi-facet apps), so we | ||
// block it until proper support. | ||
return notSupported( ); | ||
const hasNativeSupport = | ||
( typeof ( < any >window ).u2f !== 'undefined' ) && | ||
( typeof ( < any >window ).u2f.sign === 'function' ); | ||
const hasNativeSupport = | ||
( typeof ( < any >window ).u2f !== 'undefined' ) && | ||
( typeof ( < any >window ).u2f.sign === 'function' ); | ||
if ( hasNativeSupport ) | ||
return resolve( { u2f: ( < any >window ).u2f } ); | ||
if ( hasNativeSupport ) | ||
return resolve( { u2f: ( < any >window ).u2f } ); | ||
if ( isEDGE ) | ||
// We don't want to check for Google's extension hack on EDGE | ||
// as it'll cause trouble (popups, etc) | ||
return notSupported( ); | ||
if ( isEDGE ) | ||
// We don't want to check for Google's extension hack on EDGE | ||
// as it'll cause trouble (popups, etc) | ||
return notSupported( ); | ||
if ( location.protocol === 'http:' ) | ||
// U2F isn't supported over http, only https | ||
return notSupported( ); | ||
if ( location.protocol === 'http:' ) | ||
// U2F isn't supported over http, only https | ||
return notSupported( ); | ||
if ( typeof MessageChannel === 'undefined' ) | ||
// Unsupported browser, the chrome hack would throw | ||
return notSupported( ); | ||
if ( typeof MessageChannel === 'undefined' ) | ||
// Unsupported browser, the chrome hack would throw | ||
return notSupported( ); | ||
// Test for google extension support | ||
chromeApi.isSupported( function( ok ) | ||
{ | ||
if ( ok ) | ||
resolve( { u2f: chromeApi } ); | ||
else | ||
notSupported( ); | ||
} ); | ||
// Test for google extension support | ||
chromeApi.isSupported( function( ok ) | ||
{ | ||
if ( ok ) | ||
resolve( { u2f: chromeApi } ); | ||
else | ||
notSupported( ); | ||
} ); | ||
} ) | ||
.then( function ( response ) | ||
{ | ||
_backend = response.u2f ? supportChecker : null; | ||
return response; | ||
} ); | ||
return _backend; | ||
return supportChecker; | ||
} | ||
@@ -144,3 +168,3 @@ | ||
if ( !Array.isArray( registerRequests ) ) | ||
registerRequests = [ registerRequests ]; | ||
registerRequests = [ registerRequests ] as ReadonlyArray< RegisterRequest >; | ||
@@ -191,3 +215,3 @@ if ( typeof signRequests === 'number' && typeof timeout === 'undefined' ) | ||
if ( !Array.isArray( signRequests ) ) | ||
signRequests = [ signRequests ]; | ||
signRequests = [ signRequests ] as ReadonlyArray< SignRequest >; | ||
@@ -194,0 +218,0 @@ return getBackend( ) |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"author": "Gustaf Räntilä <g.rantila@gmail.com>", | ||
@@ -8,0 +8,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
140025
2965