@simplewebauthn/browser
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -1,2 +0,3 @@ | ||
function toUint8Array(value) { | ||
/* [@simplewebauthn/browser] Version: 3.0.0 - Saturday, April 17th, 2021, 11:17:53 PM */ | ||
function utf8StringToBuffer(value) { | ||
return new TextEncoder().encode(value); | ||
@@ -49,3 +50,3 @@ } | ||
...creationOptionsJSON.user, | ||
id: toUint8Array(creationOptionsJSON.user.id), | ||
id: utf8StringToBuffer(creationOptionsJSON.user.id), | ||
}, | ||
@@ -75,2 +76,6 @@ excludeCredentials: creationOptionsJSON.excludeCredentials.map(toPublicKeyCredentialDescriptor), | ||
function bufferToUTF8String(value) { | ||
return new TextDecoder('utf-8').decode(value); | ||
} | ||
async function startAssertion(requestOptionsJSON) { | ||
@@ -97,3 +102,3 @@ var _a, _b; | ||
if (response.userHandle) { | ||
userHandle = bufferToBase64URLString(response.userHandle); | ||
userHandle = bufferToUTF8String(response.userHandle); | ||
} | ||
@@ -100,0 +105,0 @@ return { |
@@ -1,1 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";function t(e){const t=new Uint8Array(e);let n="";for(const e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function n(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,"="),o=atob(r),i=new ArrayBuffer(o.length),a=new Uint8Array(i);for(let e=0;e<o.length;e++)a[e]=o.charCodeAt(e);return i}function r(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function o(e){const{id:t}=e;return{...e,id:n(t)}}e.startAssertion=async function(e){var i,a;if(!r())throw new Error("WebAuthn is not supported in this browser");let s;0!==(null===(i=e.allowCredentials)||void 0===i?void 0:i.length)&&(s=null===(a=e.allowCredentials)||void 0===a?void 0:a.map(o));const l={...e,challenge:n(e.challenge),allowCredentials:s},c=await navigator.credentials.get({publicKey:l});if(!c)throw new Error("Assertion was not completed");const{id:d,rawId:u,response:p,type:f}=c;let w;return p.userHandle&&(w=t(p.userHandle)),{id:d,rawId:t(u),response:{authenticatorData:t(p.authenticatorData),clientDataJSON:t(p.clientDataJSON),signature:t(p.signature),userHandle:w},type:f,clientExtensionResults:c.getClientExtensionResults()}},e.startAttestation=async function(e){if(!r())throw new Error("WebAuthn is not supported in this browser");const i={...e,challenge:n(e.challenge),user:{...e.user,id:(a=e.user.id,(new TextEncoder).encode(a))},excludeCredentials:e.excludeCredentials.map(o)};var a;const s=await navigator.credentials.create({publicKey:i});if(!s)throw new Error("Attestation was not completed");const{id:l,rawId:c,response:d,type:u}=s,p={id:l,rawId:t(c),response:{attestationObject:t(d.attestationObject),clientDataJSON:t(d.clientDataJSON)},type:u,clientExtensionResults:s.getClientExtensionResults()};return"function"==typeof d.getTransports&&(p.transports=d.getTransports()),p},e.supportsWebauthn=r,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
/* [@simplewebauthn/browser] Version: 3.0.0 - Saturday, April 17th, 2021, 11:17:53 PM */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";function t(e){const t=new Uint8Array(e);let n="";for(const e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function n(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,"="),o=atob(r),i=new ArrayBuffer(o.length),a=new Uint8Array(i);for(let e=0;e<o.length;e++)a[e]=o.charCodeAt(e);return i}function r(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function o(e){const{id:t}=e;return{...e,id:n(t)}}e.startAssertion=async function(e){var i,a;if(!r())throw new Error("WebAuthn is not supported in this browser");let s;0!==(null===(i=e.allowCredentials)||void 0===i?void 0:i.length)&&(s=null===(a=e.allowCredentials)||void 0===a?void 0:a.map(o));const l={...e,challenge:n(e.challenge),allowCredentials:s},d=await navigator.credentials.get({publicKey:l});if(!d)throw new Error("Assertion was not completed");const{id:c,rawId:u,response:p,type:f}=d;let w;var g;return p.userHandle&&(g=p.userHandle,w=new TextDecoder("utf-8").decode(g)),{id:c,rawId:t(u),response:{authenticatorData:t(p.authenticatorData),clientDataJSON:t(p.clientDataJSON),signature:t(p.signature),userHandle:w},type:f,clientExtensionResults:d.getClientExtensionResults()}},e.startAttestation=async function(e){if(!r())throw new Error("WebAuthn is not supported in this browser");const i={...e,challenge:n(e.challenge),user:{...e.user,id:(a=e.user.id,(new TextEncoder).encode(a))},excludeCredentials:e.excludeCredentials.map(o)};var a;const s=await navigator.credentials.create({publicKey:i});if(!s)throw new Error("Attestation was not completed");const{id:l,rawId:d,response:c,type:u}=s,p={id:l,rawId:t(d),response:{attestationObject:t(c.attestationObject),clientDataJSON:t(c.clientDataJSON)},type:u,clientExtensionResults:s.getClientExtensionResults()};return"function"==typeof c.getTransports&&(p.transports=c.getTransports()),p},e.supportsWebauthn=r,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -0,27 +1,12 @@ | ||
/* [@simplewebauthn/browser] Version: 3.0.0 - Saturday, April 17th, 2021, 11:17:54 PM */ | ||
'use strict'; | ||
var tslib_1 = require('tslib'); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var tslib = require('tslib'); | ||
var tslib_1__default = /*#__PURE__*/_interopDefaultLegacy(tslib_1); | ||
function getDefaultExportFromCjs (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
function createCommonjsModule(fn) { | ||
var module = { exports: {} }; | ||
return fn(module, module.exports), module.exports; | ||
} | ||
function toUint8Array(value) { | ||
function utf8StringToBuffer(value) { | ||
return new TextEncoder().encode(value); | ||
} | ||
var _default$6 = toUint8Array; | ||
var toUint8Array_1$1 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default$6 | ||
}, '__esModule', {value: true}); | ||
function bufferToBase64URLString(buffer) { | ||
@@ -32,3 +17,3 @@ var e_1, _a; | ||
try { | ||
for (var bytes_1 = tslib_1__default['default'].__values(bytes), bytes_1_1 = bytes_1.next(); !bytes_1_1.done; bytes_1_1 = bytes_1.next()) { | ||
for (var bytes_1 = tslib.__values(bytes), bytes_1_1 = bytes_1.next(); !bytes_1_1.done; bytes_1_1 = bytes_1.next()) { | ||
var charCode = bytes_1_1.value; | ||
@@ -48,8 +33,3 @@ str += String.fromCharCode(charCode); | ||
} | ||
var _default$5 = bufferToBase64URLString; | ||
var bufferToBase64URLString_1$2 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default$5 | ||
}, '__esModule', {value: true}); | ||
function base64URLStringToBuffer(base64URLString) { | ||
@@ -67,43 +47,22 @@ var base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/'); | ||
} | ||
var _default$4 = base64URLStringToBuffer; | ||
var base64URLStringToBuffer_1$3 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default$4 | ||
}, '__esModule', {value: true}); | ||
function supportsWebauthn() { | ||
return ((window === null || window === void 0 ? void 0 : window.PublicKeyCredential) !== undefined && typeof window.PublicKeyCredential === 'function'); | ||
} | ||
var _default$3 = supportsWebauthn; | ||
var supportsWebauthn_1$2 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default$3 | ||
}, '__esModule', {value: true}); | ||
var base64URLStringToBuffer_1$2 = tslib_1__default['default'].__importDefault(base64URLStringToBuffer_1$3); | ||
function toPublicKeyCredentialDescriptor(descriptor) { | ||
var id = descriptor.id; | ||
return tslib_1__default['default'].__assign(tslib_1__default['default'].__assign({}, descriptor), { id: base64URLStringToBuffer_1$2.default(id) }); | ||
return tslib.__assign(tslib.__assign({}, descriptor), { id: base64URLStringToBuffer(id) }); | ||
} | ||
var _default$2 = toPublicKeyCredentialDescriptor; | ||
var toPublicKeyCredentialDescriptor_1$2 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default$2 | ||
}, '__esModule', {value: true}); | ||
var toUint8Array_1 = tslib_1__default['default'].__importDefault(toUint8Array_1$1); | ||
var bufferToBase64URLString_1$1 = tslib_1__default['default'].__importDefault(bufferToBase64URLString_1$2); | ||
var base64URLStringToBuffer_1$1 = tslib_1__default['default'].__importDefault(base64URLStringToBuffer_1$3); | ||
var supportsWebauthn_1$1 = tslib_1__default['default'].__importDefault(supportsWebauthn_1$2); | ||
var toPublicKeyCredentialDescriptor_1$1 = tslib_1__default['default'].__importDefault(toPublicKeyCredentialDescriptor_1$2); | ||
function startAttestation(creationOptionsJSON) { | ||
return tslib_1__default['default'].__awaiter(this, void 0, void 0, function () { | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var publicKey, credential, id, rawId, response, type, credentialJSON; | ||
return tslib_1__default['default'].__generator(this, function (_a) { | ||
return tslib.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!supportsWebauthn_1$1.default()) { | ||
if (!supportsWebauthn()) { | ||
throw new Error('WebAuthn is not supported in this browser'); | ||
} | ||
publicKey = tslib_1__default['default'].__assign(tslib_1__default['default'].__assign({}, creationOptionsJSON), { challenge: base64URLStringToBuffer_1$1.default(creationOptionsJSON.challenge), user: tslib_1__default['default'].__assign(tslib_1__default['default'].__assign({}, creationOptionsJSON.user), { id: toUint8Array_1.default(creationOptionsJSON.user.id) }), excludeCredentials: creationOptionsJSON.excludeCredentials.map(toPublicKeyCredentialDescriptor_1$1.default) }); | ||
publicKey = tslib.__assign(tslib.__assign({}, creationOptionsJSON), { challenge: base64URLStringToBuffer(creationOptionsJSON.challenge), user: tslib.__assign(tslib.__assign({}, creationOptionsJSON.user), { id: utf8StringToBuffer(creationOptionsJSON.user.id) }), excludeCredentials: creationOptionsJSON.excludeCredentials.map(toPublicKeyCredentialDescriptor) }); | ||
return [4, navigator.credentials.create({ publicKey: publicKey })]; | ||
@@ -118,6 +77,6 @@ case 1: | ||
id: id, | ||
rawId: bufferToBase64URLString_1$1.default(rawId), | ||
rawId: bufferToBase64URLString(rawId), | ||
response: { | ||
attestationObject: bufferToBase64URLString_1$1.default(response.attestationObject), | ||
clientDataJSON: bufferToBase64URLString_1$1.default(response.clientDataJSON), | ||
attestationObject: bufferToBase64URLString(response.attestationObject), | ||
clientDataJSON: bufferToBase64URLString(response.clientDataJSON), | ||
}, | ||
@@ -135,26 +94,21 @@ type: type, | ||
} | ||
var _default$1 = startAttestation; | ||
var startAttestation_1 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default$1 | ||
}, '__esModule', {value: true}); | ||
function bufferToUTF8String(value) { | ||
return new TextDecoder('utf-8').decode(value); | ||
} | ||
var bufferToBase64URLString_1 = tslib_1__default['default'].__importDefault(bufferToBase64URLString_1$2); | ||
var base64URLStringToBuffer_1 = tslib_1__default['default'].__importDefault(base64URLStringToBuffer_1$3); | ||
var supportsWebauthn_1 = tslib_1__default['default'].__importDefault(supportsWebauthn_1$2); | ||
var toPublicKeyCredentialDescriptor_1 = tslib_1__default['default'].__importDefault(toPublicKeyCredentialDescriptor_1$2); | ||
function startAssertion(requestOptionsJSON) { | ||
var _a, _b; | ||
return tslib_1__default['default'].__awaiter(this, void 0, void 0, function () { | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var allowCredentials, publicKey, credential, id, rawId, response, type, userHandle; | ||
return tslib_1__default['default'].__generator(this, function (_c) { | ||
return tslib.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!supportsWebauthn_1.default()) { | ||
if (!supportsWebauthn()) { | ||
throw new Error('WebAuthn is not supported in this browser'); | ||
} | ||
if (((_a = requestOptionsJSON.allowCredentials) === null || _a === void 0 ? void 0 : _a.length) !== 0) { | ||
allowCredentials = (_b = requestOptionsJSON.allowCredentials) === null || _b === void 0 ? void 0 : _b.map(toPublicKeyCredentialDescriptor_1.default); | ||
allowCredentials = (_b = requestOptionsJSON.allowCredentials) === null || _b === void 0 ? void 0 : _b.map(toPublicKeyCredentialDescriptor); | ||
} | ||
publicKey = tslib_1__default['default'].__assign(tslib_1__default['default'].__assign({}, requestOptionsJSON), { challenge: base64URLStringToBuffer_1.default(requestOptionsJSON.challenge), allowCredentials: allowCredentials }); | ||
publicKey = tslib.__assign(tslib.__assign({}, requestOptionsJSON), { challenge: base64URLStringToBuffer(requestOptionsJSON.challenge), allowCredentials: allowCredentials }); | ||
return [4, navigator.credentials.get({ publicKey: publicKey })]; | ||
@@ -169,11 +123,11 @@ case 1: | ||
if (response.userHandle) { | ||
userHandle = bufferToBase64URLString_1.default(response.userHandle); | ||
userHandle = bufferToUTF8String(response.userHandle); | ||
} | ||
return [2, { | ||
id: id, | ||
rawId: bufferToBase64URLString_1.default(rawId), | ||
rawId: bufferToBase64URLString(rawId), | ||
response: { | ||
authenticatorData: bufferToBase64URLString_1.default(response.authenticatorData), | ||
clientDataJSON: bufferToBase64URLString_1.default(response.clientDataJSON), | ||
signature: bufferToBase64URLString_1.default(response.signature), | ||
authenticatorData: bufferToBase64URLString(response.authenticatorData), | ||
clientDataJSON: bufferToBase64URLString(response.clientDataJSON), | ||
signature: bufferToBase64URLString(response.signature), | ||
userHandle: userHandle, | ||
@@ -188,22 +142,5 @@ }, | ||
} | ||
var _default = startAssertion; | ||
var startAssertion_1 = /*#__PURE__*/Object.defineProperty({ | ||
default: _default | ||
}, '__esModule', {value: true}); | ||
var src = createCommonjsModule(function (module, exports) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.supportsWebauthn = exports.startAssertion = exports.startAttestation = void 0; | ||
var startAttestation_1$1 = tslib_1__default['default'].__importDefault(startAttestation_1); | ||
exports.startAttestation = startAttestation_1$1.default; | ||
var startAssertion_1$1 = tslib_1__default['default'].__importDefault(startAssertion_1); | ||
exports.startAssertion = startAssertion_1$1.default; | ||
var supportsWebauthn_1 = tslib_1__default['default'].__importDefault(supportsWebauthn_1$2); | ||
exports.supportsWebauthn = supportsWebauthn_1.default; | ||
}); | ||
var index = /*@__PURE__*/getDefaultExportFromCjs(src); | ||
module.exports = index; | ||
exports.startAssertion = startAssertion; | ||
exports.startAttestation = startAttestation; | ||
exports.supportsWebauthn = supportsWebauthn; |
@@ -1,1 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t}var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};var n=function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var o=Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]};function a(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,a=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(o)throw o.error}}return i}function u(e){return this instanceof u?(this.v=e,this):new u(e)}var l=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};var c=Object.freeze({__proto__:null,__extends:function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)},get __assign(){return n},__rest:function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},__decorate:function(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i},__param:function(e,t){return function(r,n){t(r,n,e)}},__metadata:function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__awaiter:function(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{l(n.next(e))}catch(e){a(e)}}function u(e){try{l(n.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}l((n=n.apply(e,t||[])).next())}))},__generator:function(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},__createBinding:o,__exportStar:function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)},__values:a,__read:i,__spread:function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e},__spreadArrays:function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var a=arguments[t],i=0,u=a.length;i<u;i++,o++)n[o]=a[i];return n},__spreadArray:function(e,t){for(var r=0,n=t.length,o=e.length;r<n;r++,o++)e[o]=t[r];return e},__await:u,__asyncGenerator:function(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(e,t||[]),a=[];return n={},i("next"),i("throw"),i("return"),n[Symbol.asyncIterator]=function(){return this},n;function i(e){o[e]&&(n[e]=function(t){return new Promise((function(r,n){a.push([e,t,r,n])>1||l(e,t)}))})}function l(e,t){try{(r=o[e](t)).value instanceof u?Promise.resolve(r.value.v).then(c,f):s(a[0][2],r)}catch(e){s(a[0][3],e)}var r}function c(e){l("next",e)}function f(e){l("throw",e)}function s(e,t){e(t),a.shift(),a.length&&l(a[0][0],a[0][1])}},__asyncDelegator:function(e){var t,r;return t={},n("next"),n("throw",(function(e){throw e})),n("return"),t[Symbol.iterator]=function(){return this},t;function n(n,o){t[n]=e[n]?function(t){return(r=!r)?{value:u(e[n](t)),done:"return"===n}:o?o(t):t}:o}},__asyncValues:function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=a(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){(function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)})(n,o,(t=e[r](t)).done,t.value)}))}}},__makeTemplateObject:function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e},__importStar:function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return l(t,e),t},__importDefault:function(e){return e&&e.__esModule?e:{default:e}},__classPrivateFieldGet:function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)},__classPrivateFieldSet:function(e,t,r,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,r):o?o.value=r:t.set(e,r),r}});var f=function(e){return(new TextEncoder).encode(e)},s=Object.defineProperty({default:f},"__esModule",{value:!0}),d=t(c);var p=function(e){var t,r,n=new Uint8Array(e),o="";try{for(var a=d.__values(n),i=a.next();!i.done;i=a.next()){var u=i.value;o+=String.fromCharCode(u)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")},_=Object.defineProperty({default:p},"__esModule",{value:!0});var y=function(e){for(var t=e.replace(/-/g,"+").replace(/_/g,"/"),r=(4-t.length%4)%4,n=t.padEnd(t.length+r,"="),o=atob(n),a=new ArrayBuffer(o.length),i=new Uint8Array(a),u=0;u<o.length;u++)i[u]=o.charCodeAt(u);return a},v=Object.defineProperty({default:y},"__esModule",{value:!0});var h=function(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential},b=Object.defineProperty({default:h},"__esModule",{value:!0}),w=d.__importDefault(v);var g=function(e){var t=e.id;return d.__assign(d.__assign({},e),{id:w.default(t)})},m=Object.defineProperty({default:g},"__esModule",{value:!0}),O=d.__importDefault(s),j=d.__importDefault(_),P=d.__importDefault(v),x=d.__importDefault(b),S=d.__importDefault(m);var D=function(e){return d.__awaiter(this,void 0,void 0,(function(){var t,r,n,o,a,i,u;return d.__generator(this,(function(l){switch(l.label){case 0:if(!x.default())throw new Error("WebAuthn is not supported in this browser");return t=d.__assign(d.__assign({},e),{challenge:P.default(e.challenge),user:d.__assign(d.__assign({},e.user),{id:O.default(e.user.id)}),excludeCredentials:e.excludeCredentials.map(S.default)}),[4,navigator.credentials.create({publicKey:t})];case 1:if(!(r=l.sent()))throw new Error("Attestation was not completed");return n=r.id,o=r.rawId,a=r.response,i=r.type,u={id:n,rawId:j.default(o),response:{attestationObject:j.default(a.attestationObject),clientDataJSON:j.default(a.clientDataJSON)},type:i,clientExtensionResults:r.getClientExtensionResults()},"function"==typeof a.getTransports&&(u.transports=a.getTransports()),[2,u]}}))}))},E=Object.defineProperty({default:D},"__esModule",{value:!0}),A=d.__importDefault(_),T=d.__importDefault(v),C=d.__importDefault(b),M=d.__importDefault(m);var I=function(e){var t,r;return d.__awaiter(this,void 0,void 0,(function(){var n,o,a,i,u,l,c,f;return d.__generator(this,(function(s){switch(s.label){case 0:if(!C.default())throw new Error("WebAuthn is not supported in this browser");return 0!==(null===(t=e.allowCredentials)||void 0===t?void 0:t.length)&&(n=null===(r=e.allowCredentials)||void 0===r?void 0:r.map(M.default)),o=d.__assign(d.__assign({},e),{challenge:T.default(e.challenge),allowCredentials:n}),[4,navigator.credentials.get({publicKey:o})];case 1:if(!(a=s.sent()))throw new Error("Assertion was not completed");return i=a.id,u=a.rawId,l=a.response,c=a.type,f=void 0,l.userHandle&&(f=A.default(l.userHandle)),[2,{id:i,rawId:A.default(u),response:{authenticatorData:A.default(l.authenticatorData),clientDataJSON:A.default(l.clientDataJSON),signature:A.default(l.signature),userHandle:f},type:c,clientExtensionResults:a.getClientExtensionResults()}]}}))}))},R=Object.defineProperty({default:I},"__esModule",{value:!0});return e(function(e){var t={exports:{}};return e(t,t.exports),t.exports}((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.supportsWebauthn=t.startAssertion=t.startAttestation=void 0;var r=d.__importDefault(E);t.startAttestation=r.default;var n=d.__importDefault(R);t.startAssertion=n.default;var o=d.__importDefault(b);t.supportsWebauthn=o.default})))})); | ||
/* [@simplewebauthn/browser] Version: 3.0.0 - Saturday, April 17th, 2021, 11:17:55 PM */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function l(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}function o(e){var t,n,r=new Uint8Array(e),o="";try{for(var i=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(r),a=i.next();!a.done;a=i.next()){var l=a.value;o+=String.fromCharCode(l)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function i(e){for(var t=e.replace(/-/g,"+").replace(/_/g,"/"),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,"="),o=atob(r),i=new ArrayBuffer(o.length),a=new Uint8Array(i),l=0;l<o.length;l++)a[l]=o.charCodeAt(l);return i}function a(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function l(e){var n=e.id;return t(t({},e),{id:i(n)})}e.startAssertion=function(e){var u,s;return n(this,void 0,void 0,(function(){var n,c,d,f,p,h,w,y;return r(this,(function(r){switch(r.label){case 0:if(!a())throw new Error("WebAuthn is not supported in this browser");return 0!==(null===(u=e.allowCredentials)||void 0===u?void 0:u.length)&&(n=null===(s=e.allowCredentials)||void 0===s?void 0:s.map(l)),c=t(t({},e),{challenge:i(e.challenge),allowCredentials:n}),[4,navigator.credentials.get({publicKey:c})];case 1:if(!(d=r.sent()))throw new Error("Assertion was not completed");return f=d.id,p=d.rawId,h=d.response,w=d.type,y=void 0,h.userHandle&&(b=h.userHandle,y=new TextDecoder("utf-8").decode(b)),[2,{id:f,rawId:o(p),response:{authenticatorData:o(h.authenticatorData),clientDataJSON:o(h.clientDataJSON),signature:o(h.signature),userHandle:y},type:w,clientExtensionResults:d.getClientExtensionResults()}]}var b}))}))},e.startAttestation=function(e){return n(this,void 0,void 0,(function(){var n,u,s,c,d,f,p;return r(this,(function(r){switch(r.label){case 0:if(!a())throw new Error("WebAuthn is not supported in this browser");return n=t(t({},e),{challenge:i(e.challenge),user:t(t({},e.user),{id:(h=e.user.id,(new TextEncoder).encode(h))}),excludeCredentials:e.excludeCredentials.map(l)}),[4,navigator.credentials.create({publicKey:n})];case 1:if(!(u=r.sent()))throw new Error("Attestation was not completed");return s=u.id,c=u.rawId,d=u.response,f=u.type,p={id:s,rawId:o(c),response:{attestationObject:o(d.attestationObject),clientDataJSON:o(d.clientDataJSON)},type:f,clientExtensionResults:u.getClientExtensionResults()},"function"==typeof d.getTransports&&(p.transports=d.getTransports()),[2,p]}var h}))}))},e.supportsWebauthn=a,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -19,2 +19,10 @@ /* eslint-disable @typescript-eslint/no-var-requires */ | ||
} | ||
/** | ||
* Add support for TextDecoder to JSDOM | ||
*/ | ||
if (typeof this.global.TextDecoder === 'undefined') { | ||
const { TextDecoder } = require('util'); | ||
this.global.TextDecoder = TextDecoder; | ||
} | ||
} | ||
@@ -21,0 +29,0 @@ } |
{ | ||
"name": "@simplewebauthn/browser", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "SimpleWebAuthn for Browsers", | ||
"main": "dist/es2018/index.js", | ||
"browser": "dist/es5/index.js", | ||
"main": "dist/es5/index.js", | ||
"main:es2018": "dist/es2018/index.js", | ||
"types": "dist/types/index.d.ts", | ||
@@ -36,12 +36,11 @@ "author": "Matthew Miller <matthew@millerti.me>", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@simplewebauthn/typescript-types": "^2.1.0", | ||
"@simplewebauthn/typescript-types": "^3.0.0", | ||
"rollup": "^2.44.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-version-injector": "^1.3.2", | ||
"rollup-plugin-version-injector": "^1.3.3", | ||
"tslib": "^2.2.0" | ||
}, | ||
"gitHead": "1a186879d647256cae2bc1c6b9ae73ba28624f65" | ||
"gitHead": "8324f1fff96fb08422e609aa91a646dc2b08d184" | ||
} |
@@ -12,8 +12,8 @@ <!-- omit in toc --> | ||
- [UMD](#umd) | ||
- [ES5](#es5) | ||
- [ES2018](#es2018) | ||
- [ES5](#es5) | ||
- [Usage](#usage) | ||
- [Building for Production](#building-for-production) | ||
- [ES5](#es5-1) | ||
- [ES2018](#es2018-1) | ||
- [ES5](#es5-1) | ||
- [Webpack support](#webpack-support) | ||
@@ -36,18 +36,18 @@ - [Rollup support](#rollup-support) | ||
#### ES2018 | ||
#### ES5 | ||
If you only need to support modern browsers, include the `ES2018` version: | ||
If you need to support WebAuthn feature detection in deprecated browsers like IE11 and Edge Legacy, include the `ES5` version: | ||
```html | ||
<script src="https://unpkg.com/@simplewebauthn/browser/dist/es2018/index.umd.min.js"></script> | ||
<script src="https://unpkg.com/@simplewebauthn/browser/dist/es5/index.umd.min.js"></script> | ||
``` | ||
#### ES5 | ||
#### ES2018 | ||
If you need to support WebAuthn feature detection in deprecated browsers like IE11 and Edge Legacy, include the `ES5` version: | ||
If you only need to support modern browsers, include the `ES2018` version: | ||
```html | ||
<script src="https://unpkg.com/@simplewebauthn/browser/dist/es5/index.umd.min.js"></script> | ||
<script src="https://unpkg.com/@simplewebauthn/browser/dist/es2018/index.umd.min.js"></script> | ||
``` | ||
@@ -61,14 +61,12 @@ | ||
Two unbundled versions of this library are offered for your convenience, one targeting `ES2018` and a second targeting `ES5`. | ||
Two unbundled versions of this library are offered for your convenience, one targeting `ES5` and a second targeting `ES2018`. | ||
### ES2018 | ||
### ES5 | ||
The `ES2018` version is suitable for use when only **modern browsers** need to be supported. TypeScript and JavaScript codebases alike can import and use this library without any special build configuration considerations. | ||
The `ES5` version is suitable for use when **deprecated browsers** like IE10+ or Edge Legacy need to be supported. This version is also the **default** version that gets pulled in as the `"main"` entry in **package.json**. | ||
### ES5 | ||
TypeScript and JavaScript codebases alike can import and use this library without any special build configuration considerations. | ||
The `ES5` version can also be used in both TypeScript and JavaScript codebases. However, you will need to ensure that your bundler pulls in the ES5 version of the library when building your application! | ||
However, you will need to ensure that the `tslib` dependency gets pulled into your build artifact: | ||
You will also need to ensure that the `tslib` dependency gets pulled into your build artifact: | ||
- If you are authoring your application in TypeScript then this package will be **automatically** included so long as your **tsconfig.json** sets `"target": "ES5"`. | ||
@@ -81,22 +79,26 @@ - If your application is written in Javascript then you will need to install this package **manually** by adding it to `dependencies` in your project's **package. json**: | ||
### ES2018 | ||
The `ES2018` version is suitable for use when only **modern browsers** need to be supported. TypeScript and JavaScript codebases alike can import and use this library. However, you will need to ensure that your bundler pulls in the ES2018 version of the library when building your application! | ||
See bundler instructions below. | ||
#### Webpack support | ||
If your Webpack config's `"target"` is set to `"web"` ([the default value](https://webpack.js.org/configuration/target/)) then you're done - Webpack will pull in the ES5 build from the `"browser"` property in @simplewebauthn/browser's **package.json**. | ||
No matter the `"target"` of your build you'll need to indicate additional files for webpack to resolve via the [`"resolve.mainFields"`](https://webpack.js.org/configuration/resolve/#resolvemainfields) property in your config. Resolve the `"main:es2018"` field defined in **package.json**: | ||
If you've set a different value for `"target"`, though, then you'll need to indicate additional files for WebPack to resolve via the [`"resolve.mainFields"`](https://webpack.js.org/configuration/resolve/#resolvemainfields) property in your Webpack config: | ||
```js | ||
module.exports = { | ||
//... | ||
resolve: { | ||
mainFields: [ 'browser', 'module', 'main' ], | ||
}, | ||
//... | ||
resolve: { | ||
mainFields: [ 'main:es2018', 'module', 'main' ], | ||
}, | ||
}; | ||
``` | ||
`'browser'` must come first in the list to ensure that the `ES5` version of this library is bundled. Additional values can be added afterwards as needed. | ||
`'main:es2018'` must come first in the list to ensure that the `ES2018` version of this library is bundled. Additional values can be added afterwards as needed. | ||
#### Rollup support | ||
The [`@rollup/plugin-node-resolve`](https://github.com/rollup/rollup-plugin-node-resolve#usage) plugin can be added to your Rollup config to read in the `browser` entry from @simplewebauthn/browser's **package.json**: | ||
Add the [`@rollup/plugin-node-resolve`](https://github.com/rollup/rollup-plugin-node-resolve#usage) plugin to your Rollup config to read in the `"main:es2018"` field from **package.json**: | ||
@@ -108,11 +110,11 @@ ```js | ||
export default { | ||
// input: ... | ||
// output: ... | ||
plugins: [ | ||
//... | ||
resolve({ mainFields: [ 'browser', 'module', 'main' ] }), | ||
] | ||
// input: ... | ||
// output: ... | ||
plugins: [ | ||
//... | ||
resolve({ mainFields: [ 'main:es2018', 'module', 'main' ] }), | ||
] | ||
} | ||
``` | ||
`'browser'` must come first in the list to ensure that the `ES5` version of this library is bundled. Additional values can be added afterwards as needed. | ||
`'main:es2018'` must come first in the list to ensure that the `ES2018` version of this library is bundled. Additional values can be added afterwards as needed. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7
17
116
0
26706
308