@simplewebauthn/browser 6.3.0-alpha.1 → 7.0.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@6.3.0-alpha.1] */
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";var t=function(e,r){return t=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])},t(e,r)};var r=function(){return r=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},r.apply(this,arguments)};function n(e,t,r,n){return new(r||(r=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 t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}u((n=n.apply(e,t||[])).next())}))}function o(e,t){var r,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(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=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=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=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 t,r,n=new Uint8Array(e),o="";try{for(var i=function(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.")}(n),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&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function a(e){for(var t=e.replace(/-/g,"+").replace(/_/g,"/"),r=(4-t.length%4)%4,n=t.padEnd(t.length+r,"="),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 t=e.id;return r(r({},e),{id:a(t),transports:e.transports})}function c(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}var s=function(e){function r(t,r){void 0===r&&(r="WebAuthnError");var n=e.call(this,t)||this;return n.name=r,n}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(r,e),r}(Error);var d=new(function(){function e(){}return e.prototype.createNewAbortSignal=function(){return this.controller&&this.controller.abort("Cancelling existing WebAuthn API call for new one"),this.controller=new AbortController,this.controller.signal},e}());function p(e){var t=e.getClientExtensionResults(),r={},n=t.appid,o=t.credProps,a=t.devicePubKey,l=t.uvm;return n&&(r.appid=n),o&&(r.credProps=o),l&&(r.uvm=t.uvm),a&&(r.devicePubKey={authenticatorOutput:i(a.authenticatorOutput),signature:i(a.signature)}),r}function f(){return n(this,void 0,void 0,(function(){var e;return o(this,(function(t){return navigator.credentials.conditionalMediationSupported?[2,!0]:[2,void 0!==(e=window.PublicKeyCredential).isConditionalMediationAvailable&&e.isConditionalMediationAvailable()]}))}))}e.browserSupportsWebAuthn=l,e.browserSupportsWebAuthnAutofill=f,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,t){var h,w;return void 0===t&&(t=!1),n(this,void 0,void 0,(function(){var n,b,y,v,g,m,E,A,S;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");return 0!==(null===(h=e.allowCredentials)||void 0===h?void 0:h.length)&&(n=null===(w=e.allowCredentials)||void 0===w?void 0:w.map(u)),b=r(r({},e),{challenge:a(e.challenge),allowCredentials:n}),y={},t?[4,f()]:[3,2];case 1:if(!o.sent())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete*='webauthn']").length<1)throw Error('No <input> with `"webauthn"` in its `autocomplete` attribute was detected');y.mediation="conditional",b.allowCredentials=[],o.label=2;case 2:y.publicKey=b,y.signal=d.createNewAbortSignal(),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,navigator.credentials.get(y)];case 4:return v=o.sent(),[3,6];case 5:throw function(e){var t,r=e.error,n=e.options,o=n.publicKey;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===r.name){if(n.signal===(new AbortController).signal)return new s("Authentication ceremony was sent an abort signal","AbortError")}else{if("NotAllowedError"===r.name)return(null===(t=o.allowCredentials)||void 0===t?void 0:t.length)?new s("No available authenticator recognized any of the allowed credentials","NotAllowedError"):new s("User clicked cancel, or the authentication ceremony timed out","NotAllowedError");if("SecurityError"===r.name){var i=window.location.hostname;if(!c(i))return new s("".concat(window.location.hostname," is an invalid domain"),"SecurityError");if(o.rpId!==i)return new s('The RP ID "'.concat(o.rpId,'" is invalid for this domain'),"SecurityError")}else if("UnknownError"===r.name)return new s("The authenticator was unable to process the specified options, or could not create a new assertion signature","UnknownError")}return r}({error:o.sent(),options:y});case 6:if(!v)throw new Error("Authentication was not completed");return g=v.id,m=v.rawId,E=v.response,A=v.type,S=void 0,E.userHandle&&(C=E.userHandle,S=new TextDecoder("utf-8").decode(C)),[2,{id:g,rawId:i(m),response:{authenticatorData:i(E.authenticatorData),clientDataJSON:i(E.clientDataJSON),signature:i(E.signature),userHandle:S},type:A,clientExtensionResults:p(v),authenticatorAttachment:v.authenticatorAttachment}]}var C}))}))},e.startRegistration=function(e){return n(this,void 0,void 0,(function(){var t,n,f,h,w,b,y,v;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");t=r(r({},e),{challenge:a(e.challenge),user:r(r({},e.user),{id:(g=e.user.id,(new TextEncoder).encode(g))}),excludeCredentials:e.excludeCredentials.map(u)}),(n={publicKey:t}).signal=d.createNewAbortSignal(),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,navigator.credentials.create(n)];case 2:return f=o.sent(),[3,4];case 3:throw function(e){var t,r,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 s("Registration ceremony was sent an abort signal","AbortError")}else if("ConstraintError"===n.name){if(!0===(null===(t=i.authenticatorSelection)||void 0===t?void 0:t.requireResidentKey))return new s("Discoverable credentials were required but no available authenticator supported it","ConstraintError");if("required"===(null===(r=i.authenticatorSelection)||void 0===r?void 0:r.userVerification))return new s("User verification was required but no available authenticator supported it","ConstraintError")}else{if("InvalidStateError"===n.name)return new s("The authenticator was previously registered","InvalidStateError");if("NotAllowedError"===n.name)return new s("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 s('No entry in pubKeyCredParams was of type "public-key"',"NotSupportedError"):new s("No available authenticator supported any of the specified pubKeyCredParams algorithms","NotSupportedError");if("SecurityError"===n.name){var a=window.location.hostname;if(!c(a))return new s("".concat(window.location.hostname," is an invalid domain"),"SecurityError");if(i.rp.id!==a)return new s('The RP ID "'.concat(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 s("User ID was not between 1 and 64 characters","TypeError")}else if("UnknownError"===n.name)return new s("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(!f)throw new Error("Registration was not completed");return h=f.id,w=f.rawId,b=f.response,y=f.type,v={id:h,rawId:i(w),response:{attestationObject:i(b.attestationObject),clientDataJSON:i(b.clientDataJSON)},type:y,clientExtensionResults:p(f),authenticatorAttachment:f.authenticatorAttachment},"function"==typeof b.getTransports&&(v.transports=b.getTransports()),[2,v]}var g}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ /* [@simplewebauthn/browser@7.0.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";var t=function(e,r){return t=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])},t(e,r)};var r=function(){return r=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},r.apply(this,arguments)};function n(e,t,r,n){return new(r||(r=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 t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}u((n=n.apply(e,t||[])).next())}))}function o(e,t){var r,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(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=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=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=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 t,r,n=new Uint8Array(e),o="";try{for(var i=function(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.")}(n),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&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function a(e){for(var t=e.replace(/-/g,"+").replace(/_/g,"/"),r=(4-t.length%4)%4,n=t.padEnd(t.length+r,"="),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 t=e.id;return r(r({},e),{id:a(t),transports:e.transports})}function s(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}var c=function(e){function r(t,r){void 0===r&&(r="WebAuthnError");var n=e.call(this,t)||this;return n.name=r,n}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(r,e),r}(Error);var d=new(function(){function e(){}return e.prototype.createNewAbortSignal=function(){this.controller&&this.controller.abort("Cancelling existing WebAuthn API call for new one");var e=new AbortController;return this.controller=e,e.signal},e}()),f=["cross-platform","platform"];function p(e){if(e&&!(f.indexOf(e)<0))return e}function h(){return n(this,void 0,void 0,(function(){var e;return o(this,(function(t){return[2,void 0!==(e=window.PublicKeyCredential).isConditionalMediationAvailable&&e.isConditionalMediationAvailable()]}))}))}e.browserSupportsWebAuthn=l,e.browserSupportsWebAuthnAutofill=h,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,t){var f,w;return void 0===t&&(t=!1),n(this,void 0,void 0,(function(){var n,b,y,v,g,m,E,A,S;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");return 0!==(null===(f=e.allowCredentials)||void 0===f?void 0:f.length)&&(n=null===(w=e.allowCredentials)||void 0===w?void 0:w.map(u)),b=r(r({},e),{challenge:a(e.challenge),allowCredentials:n}),y={},t?[4,h()]:[3,2];case 1:if(!o.sent())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete*='webauthn']").length<1)throw Error('No <input> with `"webauthn"` in its `autocomplete` attribute was detected');y.mediation="conditional",b.allowCredentials=[],o.label=2;case 2:y.publicKey=b,y.signal=d.createNewAbortSignal(),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,navigator.credentials.get(y)];case 4:return v=o.sent(),[3,6];case 5:throw function(e){var t,r=e.error,n=e.options,o=n.publicKey;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===r.name){if(n.signal===(new AbortController).signal)return new c("Authentication ceremony was sent an abort signal","AbortError")}else{if("NotAllowedError"===r.name)return(null===(t=o.allowCredentials)||void 0===t?void 0:t.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"===r.name){var i=window.location.hostname;if(!s(i))return new c("".concat(window.location.hostname," is an invalid domain"),"SecurityError");if(o.rpId!==i)return new c('The RP ID "'.concat(o.rpId,'" is invalid for this domain'),"SecurityError")}else if("UnknownError"===r.name)return new c("The authenticator was unable to process the specified options, or could not create a new assertion signature","UnknownError")}return r}({error:o.sent(),options:y});case 6:if(!v)throw new Error("Authentication was not completed");return g=v.id,m=v.rawId,E=v.response,A=v.type,S=void 0,E.userHandle&&(C=E.userHandle,S=new TextDecoder("utf-8").decode(C)),[2,{id:g,rawId:i(m),response:{authenticatorData:i(E.authenticatorData),clientDataJSON:i(E.clientDataJSON),signature:i(E.signature),userHandle:S},type:A,clientExtensionResults:v.getClientExtensionResults(),authenticatorAttachment:p(v.authenticatorAttachment)}]}var C}))}))},e.startRegistration=function(e){var t;return n(this,void 0,void 0,(function(){var n,f,h,w,b,y,v,g;return o(this,(function(o){switch(o.label){case 0:if(!l())throw new Error("WebAuthn is not supported in this browser");n=r(r({},e),{challenge:a(e.challenge),user:r(r({},e.user),{id:(m=e.user.id,(new TextEncoder).encode(m))}),excludeCredentials:null===(t=e.excludeCredentials)||void 0===t?void 0:t.map(u)}),(f={publicKey:n}).signal=d.createNewAbortSignal(),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,navigator.credentials.create(f)];case 2:return h=o.sent(),[3,4];case 3:throw function(e){var t,r,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===(t=i.authenticatorSelection)||void 0===t?void 0:t.requireResidentKey))return new c("Discoverable credentials were required but no available authenticator supported it","ConstraintError");if("required"===(null===(r=i.authenticatorSelection)||void 0===r?void 0:r.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("".concat(window.location.hostname," is an invalid domain"),"SecurityError");if(i.rp.id!==a)return new c('The RP ID "'.concat(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:f});case 4:if(!h)throw new Error("Registration was not completed");return w=h.id,b=h.rawId,y=h.response,v=h.type,g=void 0,"function"==typeof y.getTransports&&(g=y.getTransports()),[2,{id:w,rawId:i(b),response:{attestationObject:i(y.attestationObject),clientDataJSON:i(y.clientDataJSON),transports:g},type:v,clientExtensionResults:h.getClientExtensionResults(),authenticatorAttachment:p(h.authenticatorAttachment)}]}var m}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,4 +1,4 @@
1
- /* [@simplewebauthn/browser@6.3.0-alpha.1] */
1
+ /* [@simplewebauthn/browser@7.0.0] */
2
2
  function utf8StringToBuffer(value) {
3
3
  return new TextEncoder().encode(value);
4
4
  }
@@ -107,35 +107,26 @@ class WebAuthnAbortService {
107
107
  if (this.controller) {
108
108
  this.controller.abort('Cancelling existing WebAuthn API call for new one');
109
109
  }
110
- this.controller = new AbortController();
111
- return this.controller.signal;
110
+ const newController = new AbortController();
111
+ this.controller = newController;
112
+ return newController.signal;
112
113
  }
113
114
  }
114
115
  const webauthnAbortService = new WebAuthnAbortService();
115
116
 
116
- function parseClientExtensionResults(credential) {
117
- const clientExtensionResults = credential.getClientExtensionResults();
118
- const clientExtensionResultsJSON = {};
119
- const { appid, credProps, devicePubKey, uvm } = clientExtensionResults;
120
- if (appid) {
121
- clientExtensionResultsJSON.appid = appid;
122
- }
123
- if (credProps) {
124
- clientExtensionResultsJSON.credProps = credProps;
125
- }
126
- if (uvm) {
127
- clientExtensionResultsJSON.uvm = clientExtensionResults.uvm;
128
- }
129
- if (devicePubKey) {
130
- clientExtensionResultsJSON.devicePubKey = {
131
- authenticatorOutput: bufferToBase64URLString(devicePubKey.authenticatorOutput),
132
- signature: bufferToBase64URLString(devicePubKey.signature),
133
- };
134
- }
135
- return clientExtensionResultsJSON;
117
+ const attachments = ['cross-platform', 'platform'];
118
+ function toAuthenticatorAttachment(attachment) {
119
+ if (!attachment) {
120
+ return;
121
+ }
122
+ if (attachments.indexOf(attachment) < 0) {
123
+ return;
124
+ }
125
+ return attachment;
136
126
  }
137
127
 
138
128
  async function startRegistration(creationOptionsJSON) {
129
+ var _a;
139
130
  if (!browserSupportsWebAuthn()) {
140
131
  throw new Error('WebAuthn is not supported in this browser');
141
132
  }
@@ -146,7 +137,7 @@ async function startRegistration(creationOptionsJSON) {
146
137
  ...creationOptionsJSON.user,
147
138
  id: utf8StringToBuffer(creationOptionsJSON.user.id),
148
139
  },
149
- excludeCredentials: creationOptionsJSON.excludeCredentials.map(toPublicKeyCredentialDescriptor),
140
+ excludeCredentials: (_a = creationOptionsJSON.excludeCredentials) === null || _a === void 0 ? void 0 : _a.map(toPublicKeyCredentialDescriptor),
150
141
  };
151
142
  const options = { publicKey };
152
143
  options.signal = webauthnAbortService.createNewAbortSignal();
@@ -161,21 +152,22 @@ async function startRegistration(creationOptionsJSON) {
161
152
  throw new Error('Registration was not completed');
162
153
  }
163
154
  const { id, rawId, response, type } = credential;
164
- const credentialJSON = {
155
+ let transports = undefined;
156
+ if (typeof response.getTransports === 'function') {
157
+ transports = response.getTransports();
158
+ }
159
+ return {
165
160
  id,
166
161
  rawId: bufferToBase64URLString(rawId),
167
162
  response: {
168
163
  attestationObject: bufferToBase64URLString(response.attestationObject),
169
164
  clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
165
+ transports,
170
166
  },
171
167
  type,
172
- clientExtensionResults: parseClientExtensionResults(credential),
173
- authenticatorAttachment: credential.authenticatorAttachment,
168
+ clientExtensionResults: credential.getClientExtensionResults(),
169
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
174
170
  };
175
- if (typeof response.getTransports === 'function') {
176
- credentialJSON.transports = response.getTransports();
177
- }
178
- return credentialJSON;
179
171
  }
180
172
 
181
173
  function bufferToUTF8String(value) {
@@ -183,9 +175,6 @@ function bufferToUTF8String(value) {
183
175
  }
184
176
 
185
177
  async function browserSupportsWebAuthnAutofill() {
186
- if (navigator.credentials.conditionalMediationSupported) {
187
- return true;
188
- }
189
178
  const globalPublicKeyCredential = window.PublicKeyCredential;
190
179
  return (globalPublicKeyCredential.isConditionalMediationAvailable !== undefined &&
191
180
  globalPublicKeyCredential.isConditionalMediationAvailable());
@@ -276,8 +265,8 @@ async function startAuthentication(requestOptionsJSON, useBrowserAutofill = fals
276
265
  userHandle,
277
266
  },
278
267
  type,
279
- clientExtensionResults: parseClientExtensionResults(credential),
280
- authenticatorAttachment: credential.authenticatorAttachment,
268
+ clientExtensionResults: credential.getClientExtensionResults(),
269
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
281
270
  };
282
271
  }
283
272
 
@@ -1,2 +1,2 @@
1
- /* [@simplewebauthn/browser@6.3.0-alpha.1] */
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 r="";for(const e of t)r+=String.fromCharCode(e);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function r(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),r=(4-t.length%4)%4,n=t.padEnd(t.length+r,"="),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:t}=e;return{...e,id:r(t),transports:e.transports}}function i(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}class a extends Error{constructor(e,t="WebAuthnError"){super(e),this.name=t}}const l=new class{createNewAbortSignal(){return this.controller&&this.controller.abort("Cancelling existing WebAuthn API call for new one"),this.controller=new AbortController,this.controller.signal}};function s(e){const r=e.getClientExtensionResults(),n={},{appid:o,credProps:i,devicePubKey:a,uvm:l}=r;return o&&(n.appid=o),i&&(n.credProps=i),l&&(n.uvm=r.uvm),a&&(n.devicePubKey={authenticatorOutput:t(a.authenticatorOutput),signature:t(a.signature)}),n}async function u(){if(navigator.credentials.conditionalMediationSupported)return!0;const e=window.PublicKeyCredential;return void 0!==e.isConditionalMediationAvailable&&e.isConditionalMediationAvailable()}e.browserSupportsWebAuthn=n,e.browserSupportsWebAuthnAutofill=u,e.platformAuthenticatorIsAvailable=async function(){return!!n()&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()},e.startAuthentication=async function(e,c=!1){var d,w;if(!n())throw new Error("WebAuthn is not supported in this browser");let p;0!==(null===(d=e.allowCredentials)||void 0===d?void 0:d.length)&&(p=null===(w=e.allowCredentials)||void 0===w?void 0:w.map(o));const h={...e,challenge:r(e.challenge),allowCredentials:p},f={};if(c){if(!await u())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete*='webauthn']").length<1)throw Error('No <input> with `"webauthn"` in its `autocomplete` attribute was detected');f.mediation="conditional",h.allowCredentials=[]}let b;f.publicKey=h,f.signal=l.createNewAbortSignal();try{b=await navigator.credentials.get(f)}catch(e){throw function({error:e,options:t}){var r;const{publicKey:n}=t;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(t.signal===(new AbortController).signal)return new a("Authentication ceremony was sent an abort signal","AbortError")}else{if("NotAllowedError"===e.name)return(null===(r=n.allowCredentials)||void 0===r?void 0:r.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:f})}if(!b)throw new Error("Authentication was not completed");const{id:y,rawId:g,response:m,type:v}=b;let E;var A;return m.userHandle&&(A=m.userHandle,E=new TextDecoder("utf-8").decode(A)),{id:y,rawId:t(g),response:{authenticatorData:t(m.authenticatorData),clientDataJSON:t(m.clientDataJSON),signature:t(m.signature),userHandle:E},type:v,clientExtensionResults:s(b),authenticatorAttachment:b.authenticatorAttachment}},e.startRegistration=async function(e){if(!n())throw new Error("WebAuthn is not supported in this browser");var u;const c={publicKey:{...e,challenge:r(e.challenge),user:{...e.user,id:(u=e.user.id,(new TextEncoder).encode(u))},excludeCredentials:e.excludeCredentials.map(o)}};let d;c.signal=l.createNewAbortSignal();try{d=await navigator.credentials.create(c)}catch(e){throw function({error:e,options:t}){var r,n;const{publicKey:o}=t;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(t.signal===(new AbortController).signal)return new a("Registration ceremony was sent an abort signal","AbortError")}else if("ConstraintError"===e.name){if(!0===(null===(r=o.authenticatorSelection)||void 0===r?void 0:r.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:c})}if(!d)throw new Error("Registration was not completed");const{id:w,rawId:p,response:h,type:f}=d,b={id:w,rawId:t(p),response:{attestationObject:t(h.attestationObject),clientDataJSON:t(h.clientDataJSON)},type:f,clientExtensionResults:s(d),authenticatorAttachment:d.authenticatorAttachment};return"function"==typeof h.getTransports&&(b.transports=h.getTransports()),b},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ /* [@simplewebauthn/browser@7.0.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 r="";for(const e of t)r+=String.fromCharCode(e);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function r(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),r=(4-t.length%4)%4,n=t.padEnd(t.length+r,"="),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:t}=e;return{...e,id:r(t),transports:e.transports}}function i(e){return"localhost"===e||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(e)}class a extends Error{constructor(e,t="WebAuthnError"){super(e),this.name=t}}const l=new class{createNewAbortSignal(){this.controller&&this.controller.abort("Cancelling existing WebAuthn API call for new one");const e=new AbortController;return this.controller=e,e.signal}},s=["cross-platform","platform"];function c(e){if(e&&!(s.indexOf(e)<0))return e}async function u(){const e=window.PublicKeyCredential;return void 0!==e.isConditionalMediationAvailable&&e.isConditionalMediationAvailable()}e.browserSupportsWebAuthn=n,e.browserSupportsWebAuthnAutofill=u,e.platformAuthenticatorIsAvailable=async function(){return!!n()&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()},e.startAuthentication=async function(e,s=!1){var d,w;if(!n())throw new Error("WebAuthn is not supported in this browser");let p;0!==(null===(d=e.allowCredentials)||void 0===d?void 0:d.length)&&(p=null===(w=e.allowCredentials)||void 0===w?void 0:w.map(o));const h={...e,challenge:r(e.challenge),allowCredentials:p},f={};if(s){if(!await u())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete*='webauthn']").length<1)throw Error('No <input> with `"webauthn"` in its `autocomplete` attribute was detected');f.mediation="conditional",h.allowCredentials=[]}let b;f.publicKey=h,f.signal=l.createNewAbortSignal();try{b=await navigator.credentials.get(f)}catch(e){throw function({error:e,options:t}){var r;const{publicKey:n}=t;if(!n)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(t.signal===(new AbortController).signal)return new a("Authentication ceremony was sent an abort signal","AbortError")}else{if("NotAllowedError"===e.name)return(null===(r=n.allowCredentials)||void 0===r?void 0:r.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:f})}if(!b)throw new Error("Authentication was not completed");const{id:y,rawId:g,response:m,type:E}=b;let A;var v;return m.userHandle&&(v=m.userHandle,A=new TextDecoder("utf-8").decode(v)),{id:y,rawId:t(g),response:{authenticatorData:t(m.authenticatorData),clientDataJSON:t(m.clientDataJSON),signature:t(m.signature),userHandle:A},type:E,clientExtensionResults:b.getClientExtensionResults(),authenticatorAttachment:c(b.authenticatorAttachment)}},e.startRegistration=async function(e){var s,u;if(!n())throw new Error("WebAuthn is not supported in this browser");const d={publicKey:{...e,challenge:r(e.challenge),user:{...e.user,id:(u=e.user.id,(new TextEncoder).encode(u))},excludeCredentials:null===(s=e.excludeCredentials)||void 0===s?void 0:s.map(o)}};let w;d.signal=l.createNewAbortSignal();try{w=await navigator.credentials.create(d)}catch(e){throw function({error:e,options:t}){var r,n;const{publicKey:o}=t;if(!o)throw Error("options was missing required publicKey property");if("AbortError"===e.name){if(t.signal===(new AbortController).signal)return new a("Registration ceremony was sent an abort signal","AbortError")}else if("ConstraintError"===e.name){if(!0===(null===(r=o.authenticatorSelection)||void 0===r?void 0:r.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:d})}if(!w)throw new Error("Registration was not completed");const{id:p,rawId:h,response:f,type:b}=w;let y;return"function"==typeof f.getTransports&&(y=f.getTransports()),{id:p,rawId:t(h),response:{attestationObject:t(f.attestationObject),clientDataJSON:t(f.clientDataJSON),transports:y},type:b,clientExtensionResults:w.getClientExtensionResults(),authenticatorAttachment:c(w.authenticatorAttachment)}},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -0,0 +1,2 @@
1
+ import { AuthenticatorAttachment } from '@simplewebauthn/typescript-types';
2
+ export declare function toAuthenticatorAttachment(attachment: string | null): AuthenticatorAttachment | undefined;
@@ -1,2 +1,2 @@
1
- import { PublicKeyCredentialRequestOptionsJSON, AuthenticationCredentialJSON } from '@simplewebauthn/typescript-types';
2
- export declare function startAuthentication(requestOptionsJSON: PublicKeyCredentialRequestOptionsJSON, useBrowserAutofill?: boolean): Promise<AuthenticationCredentialJSON>;
1
+ import { PublicKeyCredentialRequestOptionsJSON, AuthenticationResponseJSON } from '@simplewebauthn/typescript-types';
2
+ export declare function startAuthentication(requestOptionsJSON: PublicKeyCredentialRequestOptionsJSON, useBrowserAutofill?: boolean): Promise<AuthenticationResponseJSON>;
@@ -1,2 +1,2 @@
1
- import { PublicKeyCredentialCreationOptionsJSON, RegistrationCredentialJSON } from '@simplewebauthn/typescript-types';
2
- export declare function startRegistration(creationOptionsJSON: PublicKeyCredentialCreationOptionsJSON): Promise<RegistrationCredentialJSON>;
1
+ import { PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON } from '@simplewebauthn/typescript-types';
2
+ export declare function startRegistration(creationOptionsJSON: PublicKeyCredentialCreationOptionsJSON): Promise<RegistrationResponseJSON>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplewebauthn/browser",
3
- "version": "6.3.0-alpha.1",
3
+ "version": "7.0.0",
4
4
  "description": "SimpleWebAuthn for Browsers",
5
5
  "main": "dist/bundle/index.js",
6
6
  "unpkg": "dist/bundle/index.umd.min.js",
@@ -33,11 +33,11 @@
33
33
  "devDependencies": {
34
34
  "@rollup/plugin-node-resolve": "^13.0.0",
35
35
  "@rollup/plugin-typescript": "^8.2.1",
36
- "@simplewebauthn/typescript-types": "^6.3.0-alpha.1",
36
+ "@simplewebauthn/typescript-types": "^7.0.0",
37
37
  "rollup": "^2.52.1",
38
38
  "rollup-plugin-terser": "^7.0.2",
39
39
  "rollup-plugin-version-injector": "^1.3.3"
40
40
  },
41
41
  "type": "module",
42
- "gitHead": "cffd994e0fc757c58b15f3e130f50b6b927915a7"
42
+ "gitHead": "b4a3c2a17e003f245b53d3c1ce5c231ec551457d"
43
43
  }
@@ -1,2 +0,0 @@
1
- import { AuthenticationExtensionsClientOutputsJSON, RegistrationCredential, AuthenticationCredential } from "@simplewebauthn/typescript-types";
2
- export declare function parseClientExtensionResults(credential: AuthenticationCredential | RegistrationCredential): AuthenticationExtensionsClientOutputsJSON;