@ocap/mcrypto 1.30.9 → 1.30.11

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.
@@ -2,7 +2,19 @@ import _default$1 from "../protocols/signer.mjs";
2
2
  import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
3
3
 
4
4
  //#region src/signer/passkey.d.ts
5
-
5
+ type PasskeyVerifyOptions = {
6
+ /**
7
+ * Whether to require the UV (user verification) flag in authenticatorData.
8
+ * Defaults to true. The UP (user presence) flag and ceremony type
9
+ * (webauthn.get) are always enforced — these are required by the WebAuthn
10
+ * spec and have no compatibility cost.
11
+ *
12
+ * Origin / RP ID / counter checks are intentionally NOT exposed here:
13
+ * blockchain verification is permissionless (no canonical RP/origin) and
14
+ * many platform authenticators (e.g. Apple) report counter=0 always.
15
+ */
16
+ requireUserVerification?: boolean;
17
+ };
6
18
  /**
7
19
  * Signer implementation for passkey, based on `@noble/curves`
8
20
  * Since passkey supports only verification, we do not need to implement the sign method
@@ -20,10 +32,12 @@ declare class PasskeySigner extends _default$1 {
20
32
  * @param {string|buffer} challenge - the challenge sent to passkey, should be txHash when signing a transaction
21
33
  * @param {string|buffer} signature - signature from passkey
22
34
  * @param {string|buffer} pk - credentialPublicKey from passkey, must be parsed with `parseAuthenticatorData`
35
+ * @param {string} extra - JSON string with authenticatorData and clientDataJSON
36
+ * @param {PasskeyVerifyOptions} [options] - optional verification policy
23
37
  * @returns {bool}
24
38
  */
25
- verify(challenge: BytesType, signature: BytesType, pk: BytesType, extra: string): Promise<boolean>;
39
+ verify(challenge: BytesType, signature: BytesType, pk: BytesType, extra: string, options?: PasskeyVerifyOptions): Promise<boolean>;
26
40
  }
27
41
  declare const _default: PasskeySigner;
28
42
  //#endregion
29
- export { PasskeySigner, _default as default };
43
+ export { PasskeySigner, PasskeyVerifyOptions, _default as default };
@@ -1,5 +1,5 @@
1
1
  import signer_default from "../protocols/signer.mjs";
2
- import { decodeClientDataJSON, isoBase64URL, isoUint8Array, toHash, verifySignature } from "../webauthn.mjs";
2
+ import { decodeClientDataJSON, isoBase64URL, isoUint8Array, parseAuthenticatorData, toHash, verifySignature } from "../webauthn.mjs";
3
3
  import { fromBase64, toBase64, toBuffer, toUint8Array } from "@ocap/util";
4
4
 
5
5
  //#region src/signer/passkey.ts
@@ -26,14 +26,22 @@ var PasskeySigner = class extends signer_default {
26
26
  * @param {string|buffer} challenge - the challenge sent to passkey, should be txHash when signing a transaction
27
27
  * @param {string|buffer} signature - signature from passkey
28
28
  * @param {string|buffer} pk - credentialPublicKey from passkey, must be parsed with `parseAuthenticatorData`
29
+ * @param {string} extra - JSON string with authenticatorData and clientDataJSON
30
+ * @param {PasskeyVerifyOptions} [options] - optional verification policy
29
31
  * @returns {bool}
30
32
  */
31
- async verify(challenge, signature, pk, extra) {
33
+ async verify(challenge, signature, pk, extra, options = {}) {
34
+ const { requireUserVerification = true } = options;
32
35
  const parsed = JSON.parse(extra);
33
36
  if (!parsed.authenticatorData || !parsed.clientDataJSON) throw new Error("extra.authenticatorData or extra.clientDataJSON is required for passkey signature verification");
34
37
  const authDataBuffer = toBuffer(fromBase64(parsed.authenticatorData));
35
38
  const clientDataHash = await toHash(isoBase64URL.toBuffer(parsed.clientDataJSON));
36
- if (decodeClientDataJSON(parsed.clientDataJSON).challenge !== toBase64(challenge)) throw new Error("challenge mismatch for passkey signature");
39
+ const clientData = decodeClientDataJSON(parsed.clientDataJSON);
40
+ if (clientData.challenge !== toBase64(challenge)) throw new Error("challenge mismatch for passkey signature");
41
+ if (clientData.type !== "webauthn.get") throw new Error(`expected clientData.type "webauthn.get", got "${clientData.type}"`);
42
+ const { flags } = parseAuthenticatorData(Uint8Array.from(authDataBuffer));
43
+ if (!flags.up) throw new Error("user presence flag (UP) is required for passkey signature");
44
+ if (requireUserVerification && !flags.uv) throw new Error("user verification flag (UV) is required for passkey signature");
37
45
  return verifySignature({
38
46
  signature: isoBase64URL.toBuffer(typeof signature === "string" ? signature : toBase64(signature)),
39
47
  data: isoUint8Array.concat([Uint8Array.from(authDataBuffer), clientDataHash]),
@@ -28,14 +28,22 @@ var PasskeySigner = class extends require_protocols_signer.default {
28
28
  * @param {string|buffer} challenge - the challenge sent to passkey, should be txHash when signing a transaction
29
29
  * @param {string|buffer} signature - signature from passkey
30
30
  * @param {string|buffer} pk - credentialPublicKey from passkey, must be parsed with `parseAuthenticatorData`
31
+ * @param {string} extra - JSON string with authenticatorData and clientDataJSON
32
+ * @param {PasskeyVerifyOptions} [options] - optional verification policy
31
33
  * @returns {bool}
32
34
  */
33
- async verify(challenge, signature, pk, extra) {
35
+ async verify(challenge, signature, pk, extra, options = {}) {
36
+ const { requireUserVerification = true } = options;
34
37
  const parsed = JSON.parse(extra);
35
38
  if (!parsed.authenticatorData || !parsed.clientDataJSON) throw new Error("extra.authenticatorData or extra.clientDataJSON is required for passkey signature verification");
36
39
  const authDataBuffer = (0, _ocap_util.toBuffer)((0, _ocap_util.fromBase64)(parsed.authenticatorData));
37
40
  const clientDataHash = await require_webauthn.toHash(require_webauthn.isoBase64URL.toBuffer(parsed.clientDataJSON));
38
- if (require_webauthn.decodeClientDataJSON(parsed.clientDataJSON).challenge !== (0, _ocap_util.toBase64)(challenge)) throw new Error("challenge mismatch for passkey signature");
41
+ const clientData = require_webauthn.decodeClientDataJSON(parsed.clientDataJSON);
42
+ if (clientData.challenge !== (0, _ocap_util.toBase64)(challenge)) throw new Error("challenge mismatch for passkey signature");
43
+ if (clientData.type !== "webauthn.get") throw new Error(`expected clientData.type "webauthn.get", got "${clientData.type}"`);
44
+ const { flags } = require_webauthn.parseAuthenticatorData(Uint8Array.from(authDataBuffer));
45
+ if (!flags.up) throw new Error("user presence flag (UP) is required for passkey signature");
46
+ if (requireUserVerification && !flags.uv) throw new Error("user verification flag (UV) is required for passkey signature");
39
47
  return require_webauthn.verifySignature({
40
48
  signature: require_webauthn.isoBase64URL.toBuffer(typeof signature === "string" ? signature : (0, _ocap_util.toBase64)(signature)),
41
49
  data: require_webauthn.isoUint8Array.concat([Uint8Array.from(authDataBuffer), clientDataHash]),
@@ -2,7 +2,19 @@ import _default$1 from "../protocols/signer.cjs";
2
2
  import { BytesType, EncodingType, KeyPairType } from "@ocap/util";
3
3
 
4
4
  //#region src/signer/passkey.d.ts
5
-
5
+ type PasskeyVerifyOptions = {
6
+ /**
7
+ * Whether to require the UV (user verification) flag in authenticatorData.
8
+ * Defaults to true. The UP (user presence) flag and ceremony type
9
+ * (webauthn.get) are always enforced — these are required by the WebAuthn
10
+ * spec and have no compatibility cost.
11
+ *
12
+ * Origin / RP ID / counter checks are intentionally NOT exposed here:
13
+ * blockchain verification is permissionless (no canonical RP/origin) and
14
+ * many platform authenticators (e.g. Apple) report counter=0 always.
15
+ */
16
+ requireUserVerification?: boolean;
17
+ };
6
18
  /**
7
19
  * Signer implementation for passkey, based on `@noble/curves`
8
20
  * Since passkey supports only verification, we do not need to implement the sign method
@@ -20,10 +32,12 @@ declare class PasskeySigner extends _default$1 {
20
32
  * @param {string|buffer} challenge - the challenge sent to passkey, should be txHash when signing a transaction
21
33
  * @param {string|buffer} signature - signature from passkey
22
34
  * @param {string|buffer} pk - credentialPublicKey from passkey, must be parsed with `parseAuthenticatorData`
35
+ * @param {string} extra - JSON string with authenticatorData and clientDataJSON
36
+ * @param {PasskeyVerifyOptions} [options] - optional verification policy
23
37
  * @returns {bool}
24
38
  */
25
- verify(challenge: BytesType, signature: BytesType, pk: BytesType, extra: string): Promise<boolean>;
39
+ verify(challenge: BytesType, signature: BytesType, pk: BytesType, extra: string, options?: PasskeyVerifyOptions): Promise<boolean>;
26
40
  }
27
41
  declare const _default: PasskeySigner;
28
42
  //#endregion
29
- export { PasskeySigner, _default as default };
43
+ export { PasskeySigner, PasskeyVerifyOptions, _default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocap/mcrypto",
3
- "version": "1.30.9",
3
+ "version": "1.30.11",
4
4
  "type": "module",
5
5
  "description": "Crypto lib that provides signer,crypter,hasher interface",
6
6
  "keywords": [
@@ -75,7 +75,7 @@
75
75
  "@noble/curves": "^2.2.0",
76
76
  "@noble/ed25519": "^3.0.0",
77
77
  "@noble/hashes": "^2.2.0",
78
- "@ocap/util": "1.30.9",
78
+ "@ocap/util": "1.30.11",
79
79
  "crypto-js": "^4.2.0",
80
80
  "interface": "^1.2.1",
81
81
  "randombytes": "^2.1.0"