@simplewebauthn/browser 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- /* [@simplewebauthn/browser] Version: 5.0.0 - Saturday, April 2nd, 2022, 10:32:44 AM */
2
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},r(e,t)};var t=function(){return t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},t.apply(this,arguments)};function n(e,r,t,n){return new(t||(t=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function l(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,l)}u((n=n.apply(e,r||[])).next())}))}function o(e,r){var t,n,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(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=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++,n=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=r.call(e,a)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}function i(e){var r,t,n=new Uint8Array(e),o="";try{for(var i=function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.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(r?"Object is not iterable.":"Symbol.iterator is not defined.")}(n),a=i.next();!a.done;a=i.next()){var l=a.value;o+=String.fromCharCode(l)}}catch(e){r={error:e}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function a(e){for(var r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4,n=r.padEnd(r.length+t,"="),o=atob(n),i=new ArrayBuffer(o.length),a=new Uint8Array(i),l=0;l<o.length;l++)a[l]=o.charCodeAt(l);return i}function l(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function u(e){var r=e.id;return t(t({},e),{id:a(r)})}function s(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}var c=function(e){function t(r){var t=e.call(this,r)||this;return t.name="WebAuthnError",t}return 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)}(t,e),t}(Error);e.browserSupportsWebauthn=l,e.platformAuthenticatorIsAvailable=function(){return n(this,void 0,void 0,(function(){return o(this,(function(e){return l()?[2,PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()]:[2,!1]}))}))},e.startAuthentication=function(e){var r,d;return n(this,void 0,void 0,(function(){var n,f,p,w,h,y,b,v,g;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");0!==(null===(r=e.allowCredentials)||void 0===r?void 0:r.length)&&(n=null===(d=e.allowCredentials)||void 0===d?void 0:d.map(u)),f=t(t({},e),{challenge:a(e.challenge),allowCredentials:n}),p={publicKey:f},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,navigator.credentials.get(p)];case 2:return w=o.sent(),[3,4];case 3:throw function(e){var r,t=e.error,n=e.options,o=n.publicKey;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===t.name){if(n.signal===(new AbortController).signal)return new c("Authentication ceremony was sent an abort signal (AbortError)")}else{if("NotAllowedError"===t.name)return(null===(r=o.allowCredentials)||void 0===r?void 0:r.length)?new c("No available authenticator recognized any of the allowed credentials (NotAllowedError)"):new c("User clicked cancel, or the authentication ceremony timed out (NotAllowedError)");if("SecurityError"===t.name){var i=window.location.hostname;if(!s(i))return new c(window.location.hostname+" is an invalid domain (SecurityError)");if(o.rpId!==i)return new c('The RP ID "'+o.rpId+'" is invalid for this domain (SecurityError)')}else if("UnknownError"===t.name)return new c("The authenticator was unable to process the specified options, or could not create a new assertion signature (UnknownError)")}return t}({error:o.sent(),options:p});case 4:if(!w)throw new Error("Authentication was not completed");return h=w.id,y=w.rawId,b=w.response,v=w.type,g=void 0,b.userHandle&&(m=b.userHandle,g=new TextDecoder("utf-8").decode(m)),[2,{id:h,rawId:i(y),response:{authenticatorData:i(b.authenticatorData),clientDataJSON:i(b.clientDataJSON),signature:i(b.signature),userHandle:g},type:v,clientExtensionResults:w.getClientExtensionResults()}]}var m}))}))},e.startRegistration=function(e){return n(this,void 0,void 0,(function(){var r,n,d,f,p,w,h,y;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");r=t(t({},e),{challenge:a(e.challenge),user:t(t({},e.user),{id:(b=e.user.id,(new TextEncoder).encode(b))}),excludeCredentials:e.excludeCredentials.map(u)}),n={publicKey:r},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,navigator.credentials.create(n)];case 2:return d=o.sent(),[3,4];case 3:throw function(e){var r,t,n=e.error,o=e.options,i=o.publicKey;if(!i)throw Error("options was missing required publicKey property");if("AbortError"===n.name){if(o.signal===(new AbortController).signal)return new c("Registration ceremony was sent an abort signal")}else if("ConstraintError"===n.name){if(!0===(null===(r=i.authenticatorSelection)||void 0===r?void 0:r.requireResidentKey))return new c("Discoverable credentials were required but no available authenticator supported it (ConstraintError)");if("required"===(null===(t=i.authenticatorSelection)||void 0===t?void 0:t.userVerification))return new c("User verification was required but no available authenticator supported it (ConstraintError)")}else{if("InvalidStateError"===n.name)return new c("The authenticator was previously registered (InvalidStateError)");if("NotAllowedError"===n.name)return new c("User clicked cancel, or the registration ceremony timed out (NotAllowedError)");if("NotSupportedError"===n.name)return 0===i.pubKeyCredParams.filter((function(e){return"public-key"===e.type})).length?new c('No entry in pubKeyCredParams was of type "public-key" (NotSupportedError)'):new c("No available authenticator supported any of the specified pubKeyCredParams algorithms (NotSupportedError)");if("SecurityError"===n.name){var a=window.location.hostname;if(!s(a))return new c(window.location.hostname+" is an invalid domain (SecurityError)");if(i.rp.id!==a)return new c('The RP ID "'+i.rp.id+'" is invalid for this domain (SecurityError)')}else if("TypeError"===n.name){if(i.user.id.byteLength<1||i.user.id.byteLength>64)return new c("User ID was not between 1 and 64 characters (TypeError)")}else if("UnknownError"===n.name)return new c("The authenticator was unable to process the specified options, or could not create a new credential (UnknownError)")}return n}({error:o.sent(),options:n});case 4:if(!d)throw new Error("Registration was not completed");return f=d.id,p=d.rawId,w=d.response,h=d.type,y={id:f,rawId:i(p),response:{attestationObject:i(w.attestationObject),clientDataJSON:i(w.clientDataJSON)},type:h,clientExtensionResults:d.getClientExtensionResults()},"function"==typeof w.getTransports&&(y.transports=w.getTransports()),[2,y]}var b}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ /* [@simplewebauthn/browser] Version: 5.1.0 - Wednesday, April 13th, 2022, 8:40:47 AM */
2
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},r(e,t)};var t=function(){return t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},t.apply(this,arguments)};function n(e,r,t,n){return new(t||(t=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function l(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,l)}u((n=n.apply(e,r||[])).next())}))}function o(e,r){var t,n,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(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=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++,n=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=r.call(e,a)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}function i(e){var r,t,n=new Uint8Array(e),o="";try{for(var i=function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.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(r?"Object is not iterable.":"Symbol.iterator is not defined.")}(n),a=i.next();!a.done;a=i.next()){var l=a.value;o+=String.fromCharCode(l)}}catch(e){r={error:e}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function a(e){for(var r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4,n=r.padEnd(r.length+t,"="),o=atob(n),i=new ArrayBuffer(o.length),a=new Uint8Array(i),l=0;l<o.length;l++)a[l]=o.charCodeAt(l);return i}function l(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function u(e){var r=e.id;return t(t({},e),{id:a(r)})}function s(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}var c=function(e){function t(r,t){void 0===t&&(t="WebAuthnError");var n=e.call(this,r)||this;return n.name=t,n}return 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)}(t,e),t}(Error);e.browserSupportsWebauthn=l,e.platformAuthenticatorIsAvailable=function(){return n(this,void 0,void 0,(function(){return o(this,(function(e){return l()?[2,PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()]:[2,!1]}))}))},e.startAuthentication=function(e){var r,d;return n(this,void 0,void 0,(function(){var n,f,p,w,h,y,b,v,g;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");0!==(null===(r=e.allowCredentials)||void 0===r?void 0:r.length)&&(n=null===(d=e.allowCredentials)||void 0===d?void 0:d.map(u)),f=t(t({},e),{challenge:a(e.challenge),allowCredentials:n}),p={publicKey:f},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,navigator.credentials.get(p)];case 2:return w=o.sent(),[3,4];case 3:throw function(e){var r,t=e.error,n=e.options,o=n.publicKey;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===t.name){if(n.signal===(new AbortController).signal)return new c("Authentication ceremony was sent an abort signal","AbortError")}else{if("NotAllowedError"===t.name)return(null===(r=o.allowCredentials)||void 0===r?void 0:r.length)?new c("No available authenticator recognized any of the allowed credentials","NotAllowedError"):new c("User clicked cancel, or the authentication ceremony timed out","NotAllowedError");if("SecurityError"===t.name){var i=window.location.hostname;if(!s(i))return new c(window.location.hostname+" is an invalid domain","SecurityError");if(o.rpId!==i)return new c('The RP ID "'+o.rpId+'" is invalid for this domain',"SecurityError")}else if("UnknownError"===t.name)return new c("The authenticator was unable to process the specified options, or could not create a new assertion signature","UnknownError")}return t}({error:o.sent(),options:p});case 4:if(!w)throw new Error("Authentication was not completed");return h=w.id,y=w.rawId,b=w.response,v=w.type,g=void 0,b.userHandle&&(m=b.userHandle,g=new TextDecoder("utf-8").decode(m)),[2,{id:h,rawId:i(y),response:{authenticatorData:i(b.authenticatorData),clientDataJSON:i(b.clientDataJSON),signature:i(b.signature),userHandle:g},type:v,clientExtensionResults:w.getClientExtensionResults()}]}var m}))}))},e.startRegistration=function(e){return n(this,void 0,void 0,(function(){var r,n,d,f,p,w,h,y;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");r=t(t({},e),{challenge:a(e.challenge),user:t(t({},e.user),{id:(b=e.user.id,(new TextEncoder).encode(b))}),excludeCredentials:e.excludeCredentials.map(u)}),n={publicKey:r},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,navigator.credentials.create(n)];case 2:return d=o.sent(),[3,4];case 3:throw function(e){var r,t,n=e.error,o=e.options,i=o.publicKey;if(!i)throw Error("options was missing required publicKey property");if("AbortError"===n.name){if(o.signal===(new AbortController).signal)return new c("Registration ceremony was sent an abort signal","AbortError")}else if("ConstraintError"===n.name){if(!0===(null===(r=i.authenticatorSelection)||void 0===r?void 0:r.requireResidentKey))return new c("Discoverable credentials were required but no available authenticator supported it","ConstraintError");if("required"===(null===(t=i.authenticatorSelection)||void 0===t?void 0:t.userVerification))return new c("User verification was required but no available authenticator supported it","ConstraintError")}else{if("InvalidStateError"===n.name)return new c("The authenticator was previously registered","InvalidStateError");if("NotAllowedError"===n.name)return new c("User clicked cancel, or the registration ceremony timed out","NotAllowedError");if("NotSupportedError"===n.name)return 0===i.pubKeyCredParams.filter((function(e){return"public-key"===e.type})).length?new c('No entry in pubKeyCredParams was of type "public-key"',"NotSupportedError"):new c("No available authenticator supported any of the specified pubKeyCredParams algorithms","NotSupportedError");if("SecurityError"===n.name){var a=window.location.hostname;if(!s(a))return new c(window.location.hostname+" is an invalid domain","SecurityError");if(i.rp.id!==a)return new c('The RP ID "'+i.rp.id+'" is invalid for this domain',"SecurityError")}else if("TypeError"===n.name){if(i.user.id.byteLength<1||i.user.id.byteLength>64)return new c("User ID was not between 1 and 64 characters","TypeError")}else if("UnknownError"===n.name)return new c("The authenticator was unable to process the specified options, or could not create a new credential","UnknownError")}return n}({error:o.sent(),options:n});case 4:if(!d)throw new Error("Registration was not completed");return f=d.id,p=d.rawId,w=d.response,h=d.type,y={id:f,rawId:i(p),response:{attestationObject:i(w.attestationObject),clientDataJSON:i(w.clientDataJSON)},type:h,clientExtensionResults:d.getClientExtensionResults()},"function"==typeof w.getTransports&&(y.transports=w.getTransports()),[2,y]}var b}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,4 +1,4 @@
1
- /* [@simplewebauthn/browser] Version: 5.0.0 - Saturday, April 2nd, 2022, 10:32:43 AM */
1
+ /* [@simplewebauthn/browser] Version: 5.1.0 - Wednesday, April 13th, 2022, 8:40:46 AM */
2
2
  function utf8StringToBuffer(value) {
3
3
  return new TextEncoder().encode(value);
4
4
  }
@@ -43,9 +43,9 @@ function isValidDomain(hostname) {
43
43
  }
44
44
 
45
45
  class WebAuthnError extends Error {
46
- constructor(message) {
46
+ constructor(message, name = 'WebAuthnError') {
47
47
  super(message);
48
- this.name = 'WebAuthnError';
48
+ this.name = name;
49
49
  }
50
50
  }
51
51
 
@@ -57,46 +57,46 @@ function identifyRegistrationError({ error, options, }) {
57
57
  }
58
58
  if (error.name === 'AbortError') {
59
59
  if (options.signal === new AbortController().signal) {
60
- return new WebAuthnError('Registration ceremony was sent an abort signal');
60
+ return new WebAuthnError('Registration ceremony was sent an abort signal', 'AbortError');
61
61
  }
62
62
  }
63
63
  else if (error.name === 'ConstraintError') {
64
64
  if (((_a = publicKey.authenticatorSelection) === null || _a === void 0 ? void 0 : _a.requireResidentKey) === true) {
65
- return new WebAuthnError('Discoverable credentials were required but no available authenticator supported it (ConstraintError)');
65
+ return new WebAuthnError('Discoverable credentials were required but no available authenticator supported it', 'ConstraintError');
66
66
  }
67
67
  else if (((_b = publicKey.authenticatorSelection) === null || _b === void 0 ? void 0 : _b.userVerification) === 'required') {
68
- return new WebAuthnError('User verification was required but no available authenticator supported it (ConstraintError)');
68
+ return new WebAuthnError('User verification was required but no available authenticator supported it', 'ConstraintError');
69
69
  }
70
70
  }
71
71
  else if (error.name === 'InvalidStateError') {
72
- return new WebAuthnError('The authenticator was previously registered (InvalidStateError)');
72
+ return new WebAuthnError('The authenticator was previously registered', 'InvalidStateError');
73
73
  }
74
74
  else if (error.name === 'NotAllowedError') {
75
- return new WebAuthnError('User clicked cancel, or the registration ceremony timed out (NotAllowedError)');
75
+ return new WebAuthnError('User clicked cancel, or the registration ceremony timed out', 'NotAllowedError');
76
76
  }
77
77
  else if (error.name === 'NotSupportedError') {
78
78
  const validPubKeyCredParams = publicKey.pubKeyCredParams.filter(param => param.type === 'public-key');
79
79
  if (validPubKeyCredParams.length === 0) {
80
- return new WebAuthnError('No entry in pubKeyCredParams was of type "public-key" (NotSupportedError)');
80
+ return new WebAuthnError('No entry in pubKeyCredParams was of type "public-key"', 'NotSupportedError');
81
81
  }
82
- return new WebAuthnError('No available authenticator supported any of the specified pubKeyCredParams algorithms (NotSupportedError)');
82
+ return new WebAuthnError('No available authenticator supported any of the specified pubKeyCredParams algorithms', 'NotSupportedError');
83
83
  }
84
84
  else if (error.name === 'SecurityError') {
85
85
  const effectiveDomain = window.location.hostname;
86
86
  if (!isValidDomain(effectiveDomain)) {
87
- return new WebAuthnError(`${window.location.hostname} is an invalid domain (SecurityError)`);
87
+ return new WebAuthnError(`${window.location.hostname} is an invalid domain`, 'SecurityError');
88
88
  }
89
89
  else if (publicKey.rp.id !== effectiveDomain) {
90
- return new WebAuthnError(`The RP ID "${publicKey.rp.id}" is invalid for this domain (SecurityError)`);
90
+ return new WebAuthnError(`The RP ID "${publicKey.rp.id}" is invalid for this domain`, 'SecurityError');
91
91
  }
92
92
  }
93
93
  else if (error.name === 'TypeError') {
94
94
  if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
95
- return new WebAuthnError('User ID was not between 1 and 64 characters (TypeError)');
95
+ return new WebAuthnError('User ID was not between 1 and 64 characters', 'TypeError');
96
96
  }
97
97
  }
98
98
  else if (error.name === 'UnknownError') {
99
- return new WebAuthnError('The authenticator was unable to process the specified options, or could not create a new credential (UnknownError)');
99
+ return new WebAuthnError('The authenticator was unable to process the specified options, or could not create a new credential', 'UnknownError');
100
100
  }
101
101
  return error;
102
102
  }
@@ -154,26 +154,26 @@ function identifyAuthenticationError({ error, options, }) {
154
154
  }
155
155
  if (error.name === 'AbortError') {
156
156
  if (options.signal === new AbortController().signal) {
157
- return new WebAuthnError('Authentication ceremony was sent an abort signal (AbortError)');
157
+ return new WebAuthnError('Authentication ceremony was sent an abort signal', 'AbortError');
158
158
  }
159
159
  }
160
160
  else if (error.name === 'NotAllowedError') {
161
161
  if ((_a = publicKey.allowCredentials) === null || _a === void 0 ? void 0 : _a.length) {
162
- return new WebAuthnError('No available authenticator recognized any of the allowed credentials (NotAllowedError)');
162
+ return new WebAuthnError('No available authenticator recognized any of the allowed credentials', 'NotAllowedError');
163
163
  }
164
- return new WebAuthnError('User clicked cancel, or the authentication ceremony timed out (NotAllowedError)');
164
+ return new WebAuthnError('User clicked cancel, or the authentication ceremony timed out', 'NotAllowedError');
165
165
  }
166
166
  else if (error.name === 'SecurityError') {
167
167
  const effectiveDomain = window.location.hostname;
168
168
  if (!isValidDomain(effectiveDomain)) {
169
- return new WebAuthnError(`${window.location.hostname} is an invalid domain (SecurityError)`);
169
+ return new WebAuthnError(`${window.location.hostname} is an invalid domain`, 'SecurityError');
170
170
  }
171
171
  else if (publicKey.rpId !== effectiveDomain) {
172
- return new WebAuthnError(`The RP ID "${publicKey.rpId}" is invalid for this domain (SecurityError)`);
172
+ return new WebAuthnError(`The RP ID "${publicKey.rpId}" is invalid for this domain`, 'SecurityError');
173
173
  }
174
174
  }
175
175
  else if (error.name === 'UnknownError') {
176
- return new WebAuthnError('The authenticator was unable to process the specified options, or could not create a new assertion signature (UnknownError)');
176
+ return new WebAuthnError('The authenticator was unable to process the specified options, or could not create a new assertion signature', 'UnknownError');
177
177
  }
178
178
  return error;
179
179
  }
@@ -1,2 +1,2 @@
1
- /* [@simplewebauthn/browser] Version: 5.0.0 - Saturday, April 2nd, 2022, 10:32:43 AM */
2
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";function r(e){const r=new Uint8Array(e);let t="";for(const e of r)t+=String.fromCharCode(e);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function t(e){const r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4,n=r.padEnd(r.length+t,"="),o=atob(n),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 n(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function o(e){const{id:r}=e;return{...e,id:t(r)}}function i(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}class a extends Error{constructor(e){super(e),this.name="WebAuthnError"}}e.browserSupportsWebauthn=n,e.platformAuthenticatorIsAvailable=async function(){return!!n()&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()},e.startAuthentication=async function(e){var s,l;if(!n())throw new Error("WebAuthn is not supported in this browser");let c;0!==(null===(s=e.allowCredentials)||void 0===s?void 0:s.length)&&(c=null===(l=e.allowCredentials)||void 0===l?void 0:l.map(o));const u={publicKey:{...e,challenge:t(e.challenge),allowCredentials:c}};let d;try{d=await navigator.credentials.get(u)}catch(e){throw function({error:e,options:r}){var t;const{publicKey:n}=r;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(r.signal===(new AbortController).signal)return new a("Authentication ceremony was sent an abort signal (AbortError)")}else{if("NotAllowedError"===e.name)return(null===(t=n.allowCredentials)||void 0===t?void 0:t.length)?new a("No available authenticator recognized any of the allowed credentials (NotAllowedError)"):new a("User clicked cancel, or the authentication ceremony timed out (NotAllowedError)");if("SecurityError"===e.name){const e=window.location.hostname;if(!i(e))return new a(`${window.location.hostname} is an invalid domain (SecurityError)`);if(n.rpId!==e)return new a(`The RP ID "${n.rpId}" is invalid for this domain (SecurityError)`)}else if("UnknownError"===e.name)return new a("The authenticator was unable to process the specified options, or could not create a new assertion signature (UnknownError)")}return e}({error:e,options:u})}if(!d)throw new Error("Authentication was not completed");const{id:w,rawId:p,response:f,type:h}=d;let y;var b;return f.userHandle&&(b=f.userHandle,y=new TextDecoder("utf-8").decode(b)),{id:w,rawId:r(p),response:{authenticatorData:r(f.authenticatorData),clientDataJSON:r(f.clientDataJSON),signature:r(f.signature),userHandle:y},type:h,clientExtensionResults:d.getClientExtensionResults()}},e.startRegistration=async function(e){if(!n())throw new Error("WebAuthn is not supported in this browser");var s;const l={publicKey:{...e,challenge:t(e.challenge),user:{...e.user,id:(s=e.user.id,(new TextEncoder).encode(s))},excludeCredentials:e.excludeCredentials.map(o)}};let c;try{c=await navigator.credentials.create(l)}catch(e){throw function({error:e,options:r}){var t,n;const{publicKey:o}=r;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(r.signal===(new AbortController).signal)return new a("Registration ceremony was sent an abort signal")}else if("ConstraintError"===e.name){if(!0===(null===(t=o.authenticatorSelection)||void 0===t?void 0:t.requireResidentKey))return new a("Discoverable credentials were required but no available authenticator supported it (ConstraintError)");if("required"===(null===(n=o.authenticatorSelection)||void 0===n?void 0:n.userVerification))return new a("User verification was required but no available authenticator supported it (ConstraintError)")}else{if("InvalidStateError"===e.name)return new a("The authenticator was previously registered (InvalidStateError)");if("NotAllowedError"===e.name)return new a("User clicked cancel, or the registration ceremony timed out (NotAllowedError)");if("NotSupportedError"===e.name)return 0===o.pubKeyCredParams.filter((e=>"public-key"===e.type)).length?new a('No entry in pubKeyCredParams was of type "public-key" (NotSupportedError)'):new a("No available authenticator supported any of the specified pubKeyCredParams algorithms (NotSupportedError)");if("SecurityError"===e.name){const e=window.location.hostname;if(!i(e))return new a(`${window.location.hostname} is an invalid domain (SecurityError)`);if(o.rp.id!==e)return new a(`The RP ID "${o.rp.id}" is invalid for this domain (SecurityError)`)}else if("TypeError"===e.name){if(o.user.id.byteLength<1||o.user.id.byteLength>64)return new a("User ID was not between 1 and 64 characters (TypeError)")}else if("UnknownError"===e.name)return new a("The authenticator was unable to process the specified options, or could not create a new credential (UnknownError)")}return e}({error:e,options:l})}if(!c)throw new Error("Registration was not completed");const{id:u,rawId:d,response:w,type:p}=c,f={id:u,rawId:r(d),response:{attestationObject:r(w.attestationObject),clientDataJSON:r(w.clientDataJSON)},type:p,clientExtensionResults:c.getClientExtensionResults()};return"function"==typeof w.getTransports&&(f.transports=w.getTransports()),f},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ /* [@simplewebauthn/browser] Version: 5.1.0 - Wednesday, April 13th, 2022, 8:40:46 AM */
2
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).SimpleWebAuthnBrowser={})}(this,(function(e){"use strict";function r(e){const r=new Uint8Array(e);let t="";for(const e of r)t+=String.fromCharCode(e);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function t(e){const r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4,n=r.padEnd(r.length+t,"="),o=atob(n),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 n(){return void 0!==(null===window||void 0===window?void 0:window.PublicKeyCredential)&&"function"==typeof window.PublicKeyCredential}function o(e){const{id:r}=e;return{...e,id:t(r)}}function i(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}class a extends Error{constructor(e,r="WebAuthnError"){super(e),this.name=r}}e.browserSupportsWebauthn=n,e.platformAuthenticatorIsAvailable=async function(){return!!n()&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()},e.startAuthentication=async function(e){var s,l;if(!n())throw new Error("WebAuthn is not supported in this browser");let c;0!==(null===(s=e.allowCredentials)||void 0===s?void 0:s.length)&&(c=null===(l=e.allowCredentials)||void 0===l?void 0:l.map(o));const u={publicKey:{...e,challenge:t(e.challenge),allowCredentials:c}};let d;try{d=await navigator.credentials.get(u)}catch(e){throw function({error:e,options:r}){var t;const{publicKey:n}=r;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(r.signal===(new AbortController).signal)return new a("Authentication ceremony was sent an abort signal","AbortError")}else{if("NotAllowedError"===e.name)return(null===(t=n.allowCredentials)||void 0===t?void 0:t.length)?new a("No available authenticator recognized any of the allowed credentials","NotAllowedError"):new a("User clicked cancel, or the authentication ceremony timed out","NotAllowedError");if("SecurityError"===e.name){const e=window.location.hostname;if(!i(e))return new a(`${window.location.hostname} is an invalid domain`,"SecurityError");if(n.rpId!==e)return new a(`The RP ID "${n.rpId}" is invalid for this domain`,"SecurityError")}else if("UnknownError"===e.name)return new a("The authenticator was unable to process the specified options, or could not create a new assertion signature","UnknownError")}return e}({error:e,options:u})}if(!d)throw new Error("Authentication was not completed");const{id:w,rawId:p,response:f,type:h}=d;let y;var b;return f.userHandle&&(b=f.userHandle,y=new TextDecoder("utf-8").decode(b)),{id:w,rawId:r(p),response:{authenticatorData:r(f.authenticatorData),clientDataJSON:r(f.clientDataJSON),signature:r(f.signature),userHandle:y},type:h,clientExtensionResults:d.getClientExtensionResults()}},e.startRegistration=async function(e){if(!n())throw new Error("WebAuthn is not supported in this browser");var s;const l={publicKey:{...e,challenge:t(e.challenge),user:{...e.user,id:(s=e.user.id,(new TextEncoder).encode(s))},excludeCredentials:e.excludeCredentials.map(o)}};let c;try{c=await navigator.credentials.create(l)}catch(e){throw function({error:e,options:r}){var t,n;const{publicKey:o}=r;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(r.signal===(new AbortController).signal)return new a("Registration ceremony was sent an abort signal","AbortError")}else if("ConstraintError"===e.name){if(!0===(null===(t=o.authenticatorSelection)||void 0===t?void 0:t.requireResidentKey))return new a("Discoverable credentials were required but no available authenticator supported it","ConstraintError");if("required"===(null===(n=o.authenticatorSelection)||void 0===n?void 0:n.userVerification))return new a("User verification was required but no available authenticator supported it","ConstraintError")}else{if("InvalidStateError"===e.name)return new a("The authenticator was previously registered","InvalidStateError");if("NotAllowedError"===e.name)return new a("User clicked cancel, or the registration ceremony timed out","NotAllowedError");if("NotSupportedError"===e.name)return 0===o.pubKeyCredParams.filter((e=>"public-key"===e.type)).length?new a('No entry in pubKeyCredParams was of type "public-key"',"NotSupportedError"):new a("No available authenticator supported any of the specified pubKeyCredParams algorithms","NotSupportedError");if("SecurityError"===e.name){const e=window.location.hostname;if(!i(e))return new a(`${window.location.hostname} is an invalid domain`,"SecurityError");if(o.rp.id!==e)return new a(`The RP ID "${o.rp.id}" is invalid for this domain`,"SecurityError")}else if("TypeError"===e.name){if(o.user.id.byteLength<1||o.user.id.byteLength>64)return new a("User ID was not between 1 and 64 characters","TypeError")}else if("UnknownError"===e.name)return new a("The authenticator was unable to process the specified options, or could not create a new credential","UnknownError")}return e}({error:e,options:l})}if(!c)throw new Error("Registration was not completed");const{id:u,rawId:d,response:w,type:p}=c,f={id:u,rawId:r(d),response:{attestationObject:r(w.attestationObject),clientDataJSON:r(w.clientDataJSON)},type:p,clientExtensionResults:c.getClientExtensionResults()};return"function"==typeof w.getTransports&&(f.transports=w.getTransports()),f},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,3 +1,3 @@
1
1
  export declare class WebAuthnError extends Error {
2
- constructor(message: string);
2
+ constructor(message: string, name?: string);
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplewebauthn/browser",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "SimpleWebAuthn for Browsers",
5
5
  "main": "dist/bundle/index.js",
6
6
  "unpkg": "dist/bundle/index.umd.min.js",
@@ -38,5 +38,5 @@
38
38
  "rollup-plugin-version-injector": "^1.3.3",
39
39
  "typescript": "~4.3.5"
40
40
  },
41
- "gitHead": "7628494bedac039ce7ab9c5fad6bf153c99b2d34"
41
+ "gitHead": "3393143f68ecb428d61f43d2fa65915fbd38fa49"
42
42
  }