@metamask-previews/passkey-controller 3.0.0-preview-a81bf03 → 3.0.0-preview-12019cffe

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.
package/CHANGELOG.md CHANGED
@@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Added new util, `getAAGUIDFromRegistrationResponse` to read the authenticator AAGUID from a `navigator.credentials.create()` result. ([#9951](https://github.com/MetaMask/core/pull/9951))
13
-
14
10
  ### Changed
15
11
 
16
12
  - Bump `@metamask/keyring-controller` from `^27.1.0` to `^27.1.1` ([#9791](https://github.com/MetaMask/core/pull/9791))
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAAGUIDFromRegistrationResponse = exports.passkeyControllerSelectors = exports.getDefaultPasskeyControllerState = exports.PasskeyController = exports.PasskeyControllerError = exports.PasskeyControllerErrorMessage = exports.PasskeyControllerErrorCode = void 0;
3
+ exports.passkeyControllerSelectors = exports.getDefaultPasskeyControllerState = exports.PasskeyController = exports.PasskeyControllerError = exports.PasskeyControllerErrorMessage = exports.PasskeyControllerErrorCode = void 0;
4
4
  var constants_js_1 = require("./constants.cjs");
5
5
  Object.defineProperty(exports, "PasskeyControllerErrorCode", { enumerable: true, get: function () { return constants_js_1.PasskeyControllerErrorCode; } });
6
6
  Object.defineProperty(exports, "PasskeyControllerErrorMessage", { enumerable: true, get: function () { return constants_js_1.PasskeyControllerErrorMessage; } });
@@ -10,6 +10,4 @@ var PasskeyController_js_1 = require("./PasskeyController.cjs");
10
10
  Object.defineProperty(exports, "PasskeyController", { enumerable: true, get: function () { return PasskeyController_js_1.PasskeyController; } });
11
11
  Object.defineProperty(exports, "getDefaultPasskeyControllerState", { enumerable: true, get: function () { return PasskeyController_js_1.getDefaultPasskeyControllerState; } });
12
12
  Object.defineProperty(exports, "passkeyControllerSelectors", { enumerable: true, get: function () { return PasskeyController_js_1.passkeyControllerSelectors; } });
13
- var verify_registration_response_js_1 = require("./webauthn/verify-registration-response.cjs");
14
- Object.defineProperty(exports, "getAAGUIDFromRegistrationResponse", { enumerable: true, get: function () { return verify_registration_response_js_1.getAAGUIDFromRegistrationResponse; } });
15
13
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAGwB;AAFtB,0HAAA,0BAA0B,OAAA;AAC1B,6HAAA,6BAA6B,OAAA;AAE/B,0CAAqD;AAA5C,mHAAA,sBAAsB,OAAA;AAC/B,gEAIgC;AAH9B,yHAAA,iBAAiB,OAAA;AACjB,wIAAA,gCAAgC,OAAA;AAChC,kIAAA,0BAA0B,OAAA;AAuB5B,+FAA+F;AAAtF,oJAAA,iCAAiC,OAAA","sourcesContent":["export {\n PasskeyControllerErrorCode,\n PasskeyControllerErrorMessage,\n} from './constants.js';\nexport { PasskeyControllerError } from './errors.js';\nexport {\n PasskeyController,\n getDefaultPasskeyControllerState,\n passkeyControllerSelectors,\n} from './PasskeyController.js';\nexport type {\n PasskeyControllerState,\n PasskeyControllerMessenger,\n PasskeyControllerOptions,\n PasskeyControllerGetStateAction,\n PasskeyControllerActions,\n PasskeyControllerStateChangedEvent,\n PasskeyControllerEvents,\n PasskeyCredentialInfo,\n PasskeyDerivationMethod,\n PasskeyKeyDerivation,\n PasskeyRecord,\n PrfEvalExtension,\n PrfClientExtensionResults,\n} from './types.js';\nexport type {\n PasskeyRegistrationOptions,\n PasskeyRegistrationResponse,\n PasskeyAuthenticationOptions,\n PasskeyAuthenticationResponse,\n} from './webauthn/types.js';\nexport { getAAGUIDFromRegistrationResponse } from './webauthn/verify-registration-response.js';\nexport type {\n PasskeyControllerIsPasskeyEnrolledAction,\n PasskeyControllerGenerateRegistrationOptionsAction,\n PasskeyControllerGeneratePostRegistrationAuthenticationOptionsAction,\n PasskeyControllerGenerateAuthenticationOptionsAction,\n PasskeyControllerProtectVaultKeyWithPasskeyAction,\n PasskeyControllerRetrieveVaultKeyWithPasskeyAction,\n PasskeyControllerUnlockWithPasskeyAction,\n PasskeyControllerExportSeedPhraseWithPasskeyAction,\n PasskeyControllerExportAccountsWithPasskeyAction,\n PasskeyControllerVerifyPasskeyAuthenticationAction,\n PasskeyControllerRenewVaultKeyProtectionAction,\n PasskeyControllerChangePasswordWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasswordVerificationAction,\n PasskeyControllerClearStateAction,\n PasskeyControllerDestroyAction,\n} from './PasskeyController-method-action-types.js';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAGwB;AAFtB,0HAAA,0BAA0B,OAAA;AAC1B,6HAAA,6BAA6B,OAAA;AAE/B,0CAAqD;AAA5C,mHAAA,sBAAsB,OAAA;AAC/B,gEAIgC;AAH9B,yHAAA,iBAAiB,OAAA;AACjB,wIAAA,gCAAgC,OAAA;AAChC,kIAAA,0BAA0B,OAAA","sourcesContent":["export {\n PasskeyControllerErrorCode,\n PasskeyControllerErrorMessage,\n} from './constants.js';\nexport { PasskeyControllerError } from './errors.js';\nexport {\n PasskeyController,\n getDefaultPasskeyControllerState,\n passkeyControllerSelectors,\n} from './PasskeyController.js';\nexport type {\n PasskeyControllerState,\n PasskeyControllerMessenger,\n PasskeyControllerOptions,\n PasskeyControllerGetStateAction,\n PasskeyControllerActions,\n PasskeyControllerStateChangedEvent,\n PasskeyControllerEvents,\n PasskeyCredentialInfo,\n PasskeyDerivationMethod,\n PasskeyKeyDerivation,\n PasskeyRecord,\n PrfEvalExtension,\n PrfClientExtensionResults,\n} from './types.js';\nexport type {\n PasskeyRegistrationOptions,\n PasskeyRegistrationResponse,\n PasskeyAuthenticationOptions,\n PasskeyAuthenticationResponse,\n} from './webauthn/types.js';\nexport type {\n PasskeyControllerIsPasskeyEnrolledAction,\n PasskeyControllerGenerateRegistrationOptionsAction,\n PasskeyControllerGeneratePostRegistrationAuthenticationOptionsAction,\n PasskeyControllerGenerateAuthenticationOptionsAction,\n PasskeyControllerProtectVaultKeyWithPasskeyAction,\n PasskeyControllerRetrieveVaultKeyWithPasskeyAction,\n PasskeyControllerUnlockWithPasskeyAction,\n PasskeyControllerExportSeedPhraseWithPasskeyAction,\n PasskeyControllerExportAccountsWithPasskeyAction,\n PasskeyControllerVerifyPasskeyAuthenticationAction,\n PasskeyControllerRenewVaultKeyProtectionAction,\n PasskeyControllerChangePasswordWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasswordVerificationAction,\n PasskeyControllerClearStateAction,\n PasskeyControllerDestroyAction,\n} from './PasskeyController-method-action-types.js';\n"]}
package/dist/index.d.cts CHANGED
@@ -3,6 +3,5 @@ export { PasskeyControllerError } from "./errors.cjs";
3
3
  export { PasskeyController, getDefaultPasskeyControllerState, passkeyControllerSelectors, } from "./PasskeyController.cjs";
4
4
  export type { PasskeyControllerState, PasskeyControllerMessenger, PasskeyControllerOptions, PasskeyControllerGetStateAction, PasskeyControllerActions, PasskeyControllerStateChangedEvent, PasskeyControllerEvents, PasskeyCredentialInfo, PasskeyDerivationMethod, PasskeyKeyDerivation, PasskeyRecord, PrfEvalExtension, PrfClientExtensionResults, } from "./types.cjs";
5
5
  export type { PasskeyRegistrationOptions, PasskeyRegistrationResponse, PasskeyAuthenticationOptions, PasskeyAuthenticationResponse, } from "./webauthn/types.cjs";
6
- export { getAAGUIDFromRegistrationResponse } from "./webauthn/verify-registration-response.cjs";
7
6
  export type { PasskeyControllerIsPasskeyEnrolledAction, PasskeyControllerGenerateRegistrationOptionsAction, PasskeyControllerGeneratePostRegistrationAuthenticationOptionsAction, PasskeyControllerGenerateAuthenticationOptionsAction, PasskeyControllerProtectVaultKeyWithPasskeyAction, PasskeyControllerRetrieveVaultKeyWithPasskeyAction, PasskeyControllerUnlockWithPasskeyAction, PasskeyControllerExportSeedPhraseWithPasskeyAction, PasskeyControllerExportAccountsWithPasskeyAction, PasskeyControllerVerifyPasskeyAuthenticationAction, PasskeyControllerRenewVaultKeyProtectionAction, PasskeyControllerChangePasswordWithPasskeyVerificationAction, PasskeyControllerRemovePasskeyWithPasskeyVerificationAction, PasskeyControllerRemovePasskeyWithPasswordVerificationAction, PasskeyControllerClearStateAction, PasskeyControllerDestroyAction, } from "./PasskeyController-method-action-types.cjs";
8
7
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,wBAAuB;AACxB,OAAO,EAAE,sBAAsB,EAAE,qBAAoB;AACrD,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,0BAA0B,GAC3B,gCAA+B;AAChC,YAAY,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EACxB,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,GAC1B,oBAAmB;AACpB,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,GAC9B,6BAA4B;AAC7B,OAAO,EAAE,iCAAiC,EAAE,oDAAmD;AAC/F,YAAY,EACV,wCAAwC,EACxC,kDAAkD,EAClD,oEAAoE,EACpE,oDAAoD,EACpD,iDAAiD,EACjD,kDAAkD,EAClD,wCAAwC,EACxC,kDAAkD,EAClD,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,4DAA4D,EAC5D,2DAA2D,EAC3D,4DAA4D,EAC5D,iCAAiC,EACjC,8BAA8B,GAC/B,oDAAmD"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,wBAAuB;AACxB,OAAO,EAAE,sBAAsB,EAAE,qBAAoB;AACrD,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,0BAA0B,GAC3B,gCAA+B;AAChC,YAAY,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EACxB,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,GAC1B,oBAAmB;AACpB,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,GAC9B,6BAA4B;AAC7B,YAAY,EACV,wCAAwC,EACxC,kDAAkD,EAClD,oEAAoE,EACpE,oDAAoD,EACpD,iDAAiD,EACjD,kDAAkD,EAClD,wCAAwC,EACxC,kDAAkD,EAClD,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,4DAA4D,EAC5D,2DAA2D,EAC3D,4DAA4D,EAC5D,iCAAiC,EACjC,8BAA8B,GAC/B,oDAAmD"}
package/dist/index.d.mts CHANGED
@@ -3,6 +3,5 @@ export { PasskeyControllerError } from "./errors.mjs";
3
3
  export { PasskeyController, getDefaultPasskeyControllerState, passkeyControllerSelectors, } from "./PasskeyController.mjs";
4
4
  export type { PasskeyControllerState, PasskeyControllerMessenger, PasskeyControllerOptions, PasskeyControllerGetStateAction, PasskeyControllerActions, PasskeyControllerStateChangedEvent, PasskeyControllerEvents, PasskeyCredentialInfo, PasskeyDerivationMethod, PasskeyKeyDerivation, PasskeyRecord, PrfEvalExtension, PrfClientExtensionResults, } from "./types.mjs";
5
5
  export type { PasskeyRegistrationOptions, PasskeyRegistrationResponse, PasskeyAuthenticationOptions, PasskeyAuthenticationResponse, } from "./webauthn/types.mjs";
6
- export { getAAGUIDFromRegistrationResponse } from "./webauthn/verify-registration-response.mjs";
7
6
  export type { PasskeyControllerIsPasskeyEnrolledAction, PasskeyControllerGenerateRegistrationOptionsAction, PasskeyControllerGeneratePostRegistrationAuthenticationOptionsAction, PasskeyControllerGenerateAuthenticationOptionsAction, PasskeyControllerProtectVaultKeyWithPasskeyAction, PasskeyControllerRetrieveVaultKeyWithPasskeyAction, PasskeyControllerUnlockWithPasskeyAction, PasskeyControllerExportSeedPhraseWithPasskeyAction, PasskeyControllerExportAccountsWithPasskeyAction, PasskeyControllerVerifyPasskeyAuthenticationAction, PasskeyControllerRenewVaultKeyProtectionAction, PasskeyControllerChangePasswordWithPasskeyVerificationAction, PasskeyControllerRemovePasskeyWithPasskeyVerificationAction, PasskeyControllerRemovePasskeyWithPasswordVerificationAction, PasskeyControllerClearStateAction, PasskeyControllerDestroyAction, } from "./PasskeyController-method-action-types.mjs";
8
7
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,wBAAuB;AACxB,OAAO,EAAE,sBAAsB,EAAE,qBAAoB;AACrD,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,0BAA0B,GAC3B,gCAA+B;AAChC,YAAY,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EACxB,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,GAC1B,oBAAmB;AACpB,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,GAC9B,6BAA4B;AAC7B,OAAO,EAAE,iCAAiC,EAAE,oDAAmD;AAC/F,YAAY,EACV,wCAAwC,EACxC,kDAAkD,EAClD,oEAAoE,EACpE,oDAAoD,EACpD,iDAAiD,EACjD,kDAAkD,EAClD,wCAAwC,EACxC,kDAAkD,EAClD,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,4DAA4D,EAC5D,2DAA2D,EAC3D,4DAA4D,EAC5D,iCAAiC,EACjC,8BAA8B,GAC/B,oDAAmD"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,wBAAuB;AACxB,OAAO,EAAE,sBAAsB,EAAE,qBAAoB;AACrD,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,0BAA0B,GAC3B,gCAA+B;AAChC,YAAY,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EACxB,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,GAC1B,oBAAmB;AACpB,YAAY,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,GAC9B,6BAA4B;AAC7B,YAAY,EACV,wCAAwC,EACxC,kDAAkD,EAClD,oEAAoE,EACpE,oDAAoD,EACpD,iDAAiD,EACjD,kDAAkD,EAClD,wCAAwC,EACxC,kDAAkD,EAClD,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,4DAA4D,EAC5D,2DAA2D,EAC3D,4DAA4D,EAC5D,iCAAiC,EACjC,8BAA8B,GAC/B,oDAAmD"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  export { PasskeyControllerErrorCode, PasskeyControllerErrorMessage } from "./constants.mjs";
2
2
  export { PasskeyControllerError } from "./errors.mjs";
3
3
  export { PasskeyController, getDefaultPasskeyControllerState, passkeyControllerSelectors } from "./PasskeyController.mjs";
4
- export { getAAGUIDFromRegistrationResponse } from "./webauthn/verify-registration-response.mjs";
5
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC9B,wBAAuB;AACxB,OAAO,EAAE,sBAAsB,EAAE,qBAAoB;AACrD,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,0BAA0B,EAC3B,gCAA+B;AAsBhC,OAAO,EAAE,iCAAiC,EAAE,oDAAmD","sourcesContent":["export {\n PasskeyControllerErrorCode,\n PasskeyControllerErrorMessage,\n} from './constants.js';\nexport { PasskeyControllerError } from './errors.js';\nexport {\n PasskeyController,\n getDefaultPasskeyControllerState,\n passkeyControllerSelectors,\n} from './PasskeyController.js';\nexport type {\n PasskeyControllerState,\n PasskeyControllerMessenger,\n PasskeyControllerOptions,\n PasskeyControllerGetStateAction,\n PasskeyControllerActions,\n PasskeyControllerStateChangedEvent,\n PasskeyControllerEvents,\n PasskeyCredentialInfo,\n PasskeyDerivationMethod,\n PasskeyKeyDerivation,\n PasskeyRecord,\n PrfEvalExtension,\n PrfClientExtensionResults,\n} from './types.js';\nexport type {\n PasskeyRegistrationOptions,\n PasskeyRegistrationResponse,\n PasskeyAuthenticationOptions,\n PasskeyAuthenticationResponse,\n} from './webauthn/types.js';\nexport { getAAGUIDFromRegistrationResponse } from './webauthn/verify-registration-response.js';\nexport type {\n PasskeyControllerIsPasskeyEnrolledAction,\n PasskeyControllerGenerateRegistrationOptionsAction,\n PasskeyControllerGeneratePostRegistrationAuthenticationOptionsAction,\n PasskeyControllerGenerateAuthenticationOptionsAction,\n PasskeyControllerProtectVaultKeyWithPasskeyAction,\n PasskeyControllerRetrieveVaultKeyWithPasskeyAction,\n PasskeyControllerUnlockWithPasskeyAction,\n PasskeyControllerExportSeedPhraseWithPasskeyAction,\n PasskeyControllerExportAccountsWithPasskeyAction,\n PasskeyControllerVerifyPasskeyAuthenticationAction,\n PasskeyControllerRenewVaultKeyProtectionAction,\n PasskeyControllerChangePasswordWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasswordVerificationAction,\n PasskeyControllerClearStateAction,\n PasskeyControllerDestroyAction,\n} from './PasskeyController-method-action-types.js';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC9B,wBAAuB;AACxB,OAAO,EAAE,sBAAsB,EAAE,qBAAoB;AACrD,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,0BAA0B,EAC3B,gCAA+B","sourcesContent":["export {\n PasskeyControllerErrorCode,\n PasskeyControllerErrorMessage,\n} from './constants.js';\nexport { PasskeyControllerError } from './errors.js';\nexport {\n PasskeyController,\n getDefaultPasskeyControllerState,\n passkeyControllerSelectors,\n} from './PasskeyController.js';\nexport type {\n PasskeyControllerState,\n PasskeyControllerMessenger,\n PasskeyControllerOptions,\n PasskeyControllerGetStateAction,\n PasskeyControllerActions,\n PasskeyControllerStateChangedEvent,\n PasskeyControllerEvents,\n PasskeyCredentialInfo,\n PasskeyDerivationMethod,\n PasskeyKeyDerivation,\n PasskeyRecord,\n PrfEvalExtension,\n PrfClientExtensionResults,\n} from './types.js';\nexport type {\n PasskeyRegistrationOptions,\n PasskeyRegistrationResponse,\n PasskeyAuthenticationOptions,\n PasskeyAuthenticationResponse,\n} from './webauthn/types.js';\nexport type {\n PasskeyControllerIsPasskeyEnrolledAction,\n PasskeyControllerGenerateRegistrationOptionsAction,\n PasskeyControllerGeneratePostRegistrationAuthenticationOptionsAction,\n PasskeyControllerGenerateAuthenticationOptionsAction,\n PasskeyControllerProtectVaultKeyWithPasskeyAction,\n PasskeyControllerRetrieveVaultKeyWithPasskeyAction,\n PasskeyControllerUnlockWithPasskeyAction,\n PasskeyControllerExportSeedPhraseWithPasskeyAction,\n PasskeyControllerExportAccountsWithPasskeyAction,\n PasskeyControllerVerifyPasskeyAuthenticationAction,\n PasskeyControllerRenewVaultKeyProtectionAction,\n PasskeyControllerChangePasswordWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasskeyVerificationAction,\n PasskeyControllerRemovePasskeyWithPasswordVerificationAction,\n PasskeyControllerClearStateAction,\n PasskeyControllerDestroyAction,\n} from './PasskeyController-method-action-types.js';\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAAGUIDFromRegistrationResponse = exports.verifyRegistrationResponse = void 0;
3
+ exports.verifyRegistrationResponse = void 0;
4
4
  const tiny_cbor_1 = require("@levischuck/tiny-cbor");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  const sha2_1 = require("@noble/hashes/sha2");
@@ -141,6 +141,14 @@ async function verifyRegistrationResponse(opts) {
141
141
  if (!verified) {
142
142
  return { verified: false };
143
143
  }
144
+ const aaguidHex = (0, encoding_js_1.bytesToHex)(aaguid);
145
+ const aaguidStr = [
146
+ aaguidHex.slice(0, 8),
147
+ aaguidHex.slice(8, 12),
148
+ aaguidHex.slice(12, 16),
149
+ aaguidHex.slice(16, 20),
150
+ aaguidHex.slice(20),
151
+ ].join('-');
144
152
  return {
145
153
  verified: true,
146
154
  registrationInfo: {
@@ -148,56 +156,13 @@ async function verifyRegistrationResponse(opts) {
148
156
  publicKey: credentialPublicKey,
149
157
  counter,
150
158
  transports: attestationResponse.transports,
151
- aaguid: formatAAGUID(aaguid),
159
+ aaguid: aaguidStr,
152
160
  attestationFormat: fmt,
153
161
  userVerified: flags.uv,
154
162
  },
155
163
  };
156
164
  }
157
165
  exports.verifyRegistrationResponse = verifyRegistrationResponse;
158
- /**
159
- * Reads the authenticator AAGUID out of a registration response by decoding its
160
- * attestation object and parsing the attested credential data within
161
- * `authData`.
162
- *
163
- * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google
164
- * Password Manager, a hardware key), so it is useful for telemetry or for
165
- * showing the user where their passkey lives.
166
- *
167
- * Unlike {@link verifyRegistrationResponse}, this reads the response as-is
168
- * without verifying it, so treat the value as untrusted until enrollment
169
- * completes; the verified AAGUID is persisted on
170
- * `passkeyRecord.credential.aaguid`. Note also that many authenticators
171
- * deliberately report an all-zero AAGUID.
172
- *
173
- * @param registrationResponse - Result of `navigator.credentials.create()`.
174
- * @returns The AAGUID as a dashed UUID string, or `undefined` if the
175
- * authenticator data carries no attested credential data.
176
- * @throws If the attestation object or its authenticator data is malformed.
177
- */
178
- function getAAGUIDFromRegistrationResponse(registrationResponse) {
179
- const attestationObject = (0, decode_attestation_object_js_1.decodeAttestationObject)((0, encoding_js_1.base64URLToBytes)(registrationResponse.response.attestationObject));
180
- const { aaguid } = (0, parse_authenticator_data_js_1.parseAuthenticatorData)(attestationObject.get('authData'));
181
- return aaguid ? formatAAGUID(aaguid) : undefined;
182
- }
183
- exports.getAAGUIDFromRegistrationResponse = getAAGUIDFromRegistrationResponse;
184
- /**
185
- * Format the raw 16-byte AAGUID from attested credential data as a dashed
186
- * UUID string (8-4-4-4-12).
187
- *
188
- * @param aaguid - Raw AAGUID bytes.
189
- * @returns The AAGUID in canonical UUID form.
190
- */
191
- function formatAAGUID(aaguid) {
192
- const aaguidHex = (0, encoding_js_1.bytesToHex)(aaguid);
193
- return [
194
- aaguidHex.slice(0, 8),
195
- aaguidHex.slice(8, 12),
196
- aaguidHex.slice(12, 16),
197
- aaguidHex.slice(16, 20),
198
- aaguidHex.slice(20),
199
- ].join('-');
200
- }
201
166
  /**
202
167
  * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate
203
168
  * chain, signature over `authData || SHA-256(clientDataJSON)` verified
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.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ED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,uBAAQ,CAAC,GAAG,CAAW,CAAC;IAC1D,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,kCAAkC,OAAO,EAAE,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,aAAM,EAAC,IAAA,8BAAgB,EAAC,oBAAoB,CAAC,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE9D,OAAO,IAAA,qCAAe,EAAC;QACrB,aAAa;QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types.js';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding.js';\nimport { COSEALG, COSEKEYS } from './constants.js';\nimport { decodeAttestationObject } from './decode-attestation-object.js';\nimport { decodeClientDataJSON } from './decode-client-data-json.js';\nimport { matchExpectedRPID } from './match-expected-rp-id.js';\nimport { parseAuthenticatorData } from './parse-authenticator-data.js';\nimport type { PasskeyRegistrationResponse } from './types.js';\nimport { verifySignature } from './verify-signature.js';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable values for\n * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.\n * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's\n * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n if (expectedRPIDs.length > 0) {\n matchExpectedRPID(rpIdHash, expectedRPIDs);\n }\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: formatAAGUID(aaguid),\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Reads the authenticator AAGUID out of a registration response by decoding its\n * attestation object and parsing the attested credential data within\n * `authData`.\n *\n * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google\n * Password Manager, a hardware key), so it is useful for telemetry or for\n * showing the user where their passkey lives.\n *\n * Unlike {@link verifyRegistrationResponse}, this reads the response as-is\n * without verifying it, so treat the value as untrusted until enrollment\n * completes; the verified AAGUID is persisted on\n * `passkeyRecord.credential.aaguid`. Note also that many authenticators\n * deliberately report an all-zero AAGUID.\n *\n * @param registrationResponse - Result of `navigator.credentials.create()`.\n * @returns The AAGUID as a dashed UUID string, or `undefined` if the\n * authenticator data carries no attested credential data.\n * @throws If the attestation object or its authenticator data is malformed.\n */\nexport function getAAGUIDFromRegistrationResponse(\n registrationResponse: PasskeyRegistrationResponse,\n): string | undefined {\n const attestationObject = decodeAttestationObject(\n base64URLToBytes(registrationResponse.response.attestationObject),\n );\n const { aaguid } = parseAuthenticatorData(attestationObject.get('authData'));\n return aaguid ? formatAAGUID(aaguid) : undefined;\n}\n\n/**\n * Format the raw 16-byte AAGUID from attested credential data as a dashed\n * UUID string (8-4-4-4-12).\n *\n * @param aaguid - Raw AAGUID bytes.\n * @returns The AAGUID in canonical UUID form.\n */\nfunction formatAAGUID(aaguid: Uint8Array): string {\n const aaguidHex = bytesToHex(aaguid);\n return [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
1
+ {"version":3,"file":"verify-registration-response.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":";;;AAAA,qDAA0D;AAC1D,2CAA8C;AAC9C,6CAA4C;AAG5C,uDAI8B;AAC9B,kDAAmD;AACnD,kFAAyE;AACzE,8EAAoE;AACpE,wEAA8D;AAC9D,gFAAuE;AAEvE,gEAAwD;AAiBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,KAAK,UAAU,0BAA0B,CAAC,IAOhD;IACC,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,uBAAuB,GAAG,KAAK,EAC/B,qBAAqB,GAAG,CAAC,sBAAO,CAAC,KAAK,EAAE,sBAAO,CAAC,KAAK,EAAE,sBAAO,CAAC,KAAK,CAAC,GACtE,GAAG,IAAI,CAAC;IAET,MAAM,EACJ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uB,CAAC;IAC5D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAA2B,CAAC;IAC/D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAA6B,CAAC;IAE3D,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,uBAAQ,CAAC,GAAG,CAAW,CAAC;IAC1D,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,kCAAkC,OAAO,EAAE,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,aAAM,EAAC,IAAA,8BAAgB,EAAC,oBAAoB,CAAC,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE9D,OAAO,IAAA,qCAAe,EAAC;QACrB,aAAa;QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types.js';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding.js';\nimport { COSEALG, COSEKEYS } from './constants.js';\nimport { decodeAttestationObject } from './decode-attestation-object.js';\nimport { decodeClientDataJSON } from './decode-client-data-json.js';\nimport { matchExpectedRPID } from './match-expected-rp-id.js';\nimport { parseAuthenticatorData } from './parse-authenticator-data.js';\nimport type { PasskeyRegistrationResponse } from './types.js';\nimport { verifySignature } from './verify-signature.js';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable values for\n * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.\n * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's\n * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n if (expectedRPIDs.length > 0) {\n matchExpectedRPID(rpIdHash, expectedRPIDs);\n }\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n const aaguidHex = bytesToHex(aaguid);\n const aaguidStr = [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: aaguidStr,\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
@@ -57,25 +57,4 @@ export declare function verifyRegistrationResponse(opts: {
57
57
  requireUserVerification?: boolean;
58
58
  supportedAlgorithmIDs?: number[];
59
59
  }): Promise<VerifiedRegistrationResponse>;
60
- /**
61
- * Reads the authenticator AAGUID out of a registration response by decoding its
62
- * attestation object and parsing the attested credential data within
63
- * `authData`.
64
- *
65
- * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google
66
- * Password Manager, a hardware key), so it is useful for telemetry or for
67
- * showing the user where their passkey lives.
68
- *
69
- * Unlike {@link verifyRegistrationResponse}, this reads the response as-is
70
- * without verifying it, so treat the value as untrusted until enrollment
71
- * completes; the verified AAGUID is persisted on
72
- * `passkeyRecord.credential.aaguid`. Note also that many authenticators
73
- * deliberately report an all-zero AAGUID.
74
- *
75
- * @param registrationResponse - Result of `navigator.credentials.create()`.
76
- * @returns The AAGUID as a dashed UUID string, or `undefined` if the
77
- * authenticator data carries no attested credential data.
78
- * @throws If the attestation object or its authenticator data is malformed.
79
- */
80
- export declare function getAAGUIDFromRegistrationResponse(registrationResponse: PasskeyRegistrationResponse): string | undefined;
81
60
  //# sourceMappingURL=verify-registration-response.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.d.cts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAoB;AAWhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAmB;AAG9D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAkLxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iCAAiC,CAC/C,oBAAoB,EAAE,2BAA2B,GAChD,MAAM,GAAG,SAAS,CAMpB"}
1
+ {"version":3,"file":"verify-registration-response.d.cts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAoB;AAWhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAmB;AAG9D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CA2LxC"}
@@ -57,25 +57,4 @@ export declare function verifyRegistrationResponse(opts: {
57
57
  requireUserVerification?: boolean;
58
58
  supportedAlgorithmIDs?: number[];
59
59
  }): Promise<VerifiedRegistrationResponse>;
60
- /**
61
- * Reads the authenticator AAGUID out of a registration response by decoding its
62
- * attestation object and parsing the attested credential data within
63
- * `authData`.
64
- *
65
- * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google
66
- * Password Manager, a hardware key), so it is useful for telemetry or for
67
- * showing the user where their passkey lives.
68
- *
69
- * Unlike {@link verifyRegistrationResponse}, this reads the response as-is
70
- * without verifying it, so treat the value as untrusted until enrollment
71
- * completes; the verified AAGUID is persisted on
72
- * `passkeyRecord.credential.aaguid`. Note also that many authenticators
73
- * deliberately report an all-zero AAGUID.
74
- *
75
- * @param registrationResponse - Result of `navigator.credentials.create()`.
76
- * @returns The AAGUID as a dashed UUID string, or `undefined` if the
77
- * authenticator data carries no attested credential data.
78
- * @throws If the attestation object or its authenticator data is malformed.
79
- */
80
- export declare function getAAGUIDFromRegistrationResponse(registrationResponse: PasskeyRegistrationResponse): string | undefined;
81
60
  //# sourceMappingURL=verify-registration-response.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.d.mts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAoB;AAWhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAmB;AAG9D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAkLxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iCAAiC,CAC/C,oBAAoB,EAAE,2BAA2B,GAChD,MAAM,GAAG,SAAS,CAMpB"}
1
+ {"version":3,"file":"verify-registration-response.d.mts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAoB;AAWhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAmB;AAG9D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CA2LxC"}
@@ -138,6 +138,14 @@ export async function verifyRegistrationResponse(opts) {
138
138
  if (!verified) {
139
139
  return { verified: false };
140
140
  }
141
+ const aaguidHex = bytesToHex(aaguid);
142
+ const aaguidStr = [
143
+ aaguidHex.slice(0, 8),
144
+ aaguidHex.slice(8, 12),
145
+ aaguidHex.slice(12, 16),
146
+ aaguidHex.slice(16, 20),
147
+ aaguidHex.slice(20),
148
+ ].join('-');
141
149
  return {
142
150
  verified: true,
143
151
  registrationInfo: {
@@ -145,54 +153,12 @@ export async function verifyRegistrationResponse(opts) {
145
153
  publicKey: credentialPublicKey,
146
154
  counter,
147
155
  transports: attestationResponse.transports,
148
- aaguid: formatAAGUID(aaguid),
156
+ aaguid: aaguidStr,
149
157
  attestationFormat: fmt,
150
158
  userVerified: flags.uv,
151
159
  },
152
160
  };
153
161
  }
154
- /**
155
- * Reads the authenticator AAGUID out of a registration response by decoding its
156
- * attestation object and parsing the attested credential data within
157
- * `authData`.
158
- *
159
- * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google
160
- * Password Manager, a hardware key), so it is useful for telemetry or for
161
- * showing the user where their passkey lives.
162
- *
163
- * Unlike {@link verifyRegistrationResponse}, this reads the response as-is
164
- * without verifying it, so treat the value as untrusted until enrollment
165
- * completes; the verified AAGUID is persisted on
166
- * `passkeyRecord.credential.aaguid`. Note also that many authenticators
167
- * deliberately report an all-zero AAGUID.
168
- *
169
- * @param registrationResponse - Result of `navigator.credentials.create()`.
170
- * @returns The AAGUID as a dashed UUID string, or `undefined` if the
171
- * authenticator data carries no attested credential data.
172
- * @throws If the attestation object or its authenticator data is malformed.
173
- */
174
- export function getAAGUIDFromRegistrationResponse(registrationResponse) {
175
- const attestationObject = decodeAttestationObject(base64URLToBytes(registrationResponse.response.attestationObject));
176
- const { aaguid } = parseAuthenticatorData(attestationObject.get('authData'));
177
- return aaguid ? formatAAGUID(aaguid) : undefined;
178
- }
179
- /**
180
- * Format the raw 16-byte AAGUID from attested credential data as a dashed
181
- * UUID string (8-4-4-4-12).
182
- *
183
- * @param aaguid - Raw AAGUID bytes.
184
- * @returns The AAGUID in canonical UUID form.
185
- */
186
- function formatAAGUID(aaguid) {
187
- const aaguidHex = bytesToHex(aaguid);
188
- return [
189
- aaguidHex.slice(0, 8),
190
- aaguidHex.slice(8, 12),
191
- aaguidHex.slice(12, 16),
192
- aaguidHex.slice(16, 20),
193
- aaguidHex.slice(20),
194
- ].join('-');
195
- }
196
162
  /**
197
163
  * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate
198
164
  * chain, signature over `authData || SHA-256(clientDataJSON)` verified
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.mjs","sourceRoot":"","sources":["../../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AO,CAAC,GAAG,CAAC,KAAK,CAA2B,CAAC;IAC/D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAA6B,CAAC;IAE3D,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAW,CAAC;IAC1D,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,kCAAkC,OAAO,EAAE,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE9D,OAAO,eAAe,CAAC;QACrB,aAAa;QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types.js';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding.js';\nimport { COSEALG, COSEKEYS } from './constants.js';\nimport { decodeAttestationObject } from './decode-attestation-object.js';\nimport { decodeClientDataJSON } from './decode-client-data-json.js';\nimport { matchExpectedRPID } from './match-expected-rp-id.js';\nimport { parseAuthenticatorData } from './parse-authenticator-data.js';\nimport type { PasskeyRegistrationResponse } from './types.js';\nimport { verifySignature } from './verify-signature.js';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable values for\n * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.\n * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's\n * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n if (expectedRPIDs.length > 0) {\n matchExpectedRPID(rpIdHash, expectedRPIDs);\n }\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: formatAAGUID(aaguid),\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Reads the authenticator AAGUID out of a registration response by decoding its\n * attestation object and parsing the attested credential data within\n * `authData`.\n *\n * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google\n * Password Manager, a hardware key), so it is useful for telemetry or for\n * showing the user where their passkey lives.\n *\n * Unlike {@link verifyRegistrationResponse}, this reads the response as-is\n * without verifying it, so treat the value as untrusted until enrollment\n * completes; the verified AAGUID is persisted on\n * `passkeyRecord.credential.aaguid`. Note also that many authenticators\n * deliberately report an all-zero AAGUID.\n *\n * @param registrationResponse - Result of `navigator.credentials.create()`.\n * @returns The AAGUID as a dashed UUID string, or `undefined` if the\n * authenticator data carries no attested credential data.\n * @throws If the attestation object or its authenticator data is malformed.\n */\nexport function getAAGUIDFromRegistrationResponse(\n registrationResponse: PasskeyRegistrationResponse,\n): string | undefined {\n const attestationObject = decodeAttestationObject(\n base64URLToBytes(registrationResponse.response.attestationObject),\n );\n const { aaguid } = parseAuthenticatorData(attestationObject.get('authData'));\n return aaguid ? formatAAGUID(aaguid) : undefined;\n}\n\n/**\n * Format the raw 16-byte AAGUID from attested credential data as a dashed\n * UUID string (8-4-4-4-12).\n *\n * @param aaguid - Raw AAGUID bytes.\n * @returns The AAGUID in canonical UUID form.\n */\nfunction formatAAGUID(aaguid: Uint8Array): string {\n const aaguidHex = bytesToHex(aaguid);\n return [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
1
+ {"version":3,"file":"verify-registration-response.mjs","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAC9C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACX,8BAA6B;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,wBAAuB;AACnD,OAAO,EAAE,uBAAuB,EAAE,wCA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,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE9D,OAAO,eAAe,CAAC;QACrB,aAAa;QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types.js';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding.js';\nimport { COSEALG, COSEKEYS } from './constants.js';\nimport { decodeAttestationObject } from './decode-attestation-object.js';\nimport { decodeClientDataJSON } from './decode-client-data-json.js';\nimport { matchExpectedRPID } from './match-expected-rp-id.js';\nimport { parseAuthenticatorData } from './parse-authenticator-data.js';\nimport type { PasskeyRegistrationResponse } from './types.js';\nimport { verifySignature } from './verify-signature.js';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable values for\n * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.\n * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's\n * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n if (expectedRPIDs.length > 0) {\n matchExpectedRPID(rpIdHash, expectedRPIDs);\n }\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n const aaguidHex = bytesToHex(aaguid);\n const aaguidStr = [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: aaguidStr,\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/passkey-controller",
3
- "version": "3.0.0-preview-a81bf03",
3
+ "version": "3.0.0-preview-12019cffe",
4
4
  "description": "Controller and utilities for passkey-based wallet unlock",
5
5
  "keywords": [
6
6
  "Ethereum",