@o3co/auth-provider-passkey 0.0.0 → 0.18.0-rc.1

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.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +2 -3
  3. package/mfa-webauthn/README.md +24 -0
  4. package/mfa-webauthn/src/kind.d.ts +12 -0
  5. package/mfa-webauthn/src/kind.js +105 -0
  6. package/mfa-webauthn/src/module.d.ts +2 -0
  7. package/mfa-webauthn/src/module.js +16 -0
  8. package/mfa-webauthn/src/name.d.ts +5 -0
  9. package/mfa-webauthn/src/name.js +7 -0
  10. package/mfa-webauthn/src/section.d.ts +10 -0
  11. package/mfa-webauthn/src/section.js +10 -0
  12. package/package.json +57 -3
  13. package/passkey-registration/README.md +27 -0
  14. package/passkey-registration/src/module.d.ts +2 -0
  15. package/passkey-registration/src/module.js +11 -0
  16. package/passkey-registration/src/routes.d.ts +13 -0
  17. package/passkey-registration/src/routes.js +84 -0
  18. package/passkey-registration/src/section.d.ts +6 -0
  19. package/passkey-registration/src/section.js +17 -0
  20. package/webauthn/README.md +47 -0
  21. package/webauthn/config.example +7 -0
  22. package/webauthn/src/ceremony/README.md +24 -0
  23. package/webauthn/src/ceremony/ceremony.d.ts +11 -0
  24. package/webauthn/src/ceremony/ceremony.js +190 -0
  25. package/webauthn/src/contract.d.ts +90 -0
  26. package/webauthn/src/contract.js +6 -0
  27. package/webauthn/src/module.d.ts +2 -0
  28. package/webauthn/src/module.js +35 -0
  29. package/webauthn/src/passkeys.d.ts +10 -0
  30. package/webauthn/src/passkeys.js +49 -0
  31. package/webauthn/src/records.d.ts +47 -0
  32. package/webauthn/src/records.js +188 -0
  33. package/webauthn/src/registration/README.md +19 -0
  34. package/webauthn/src/registration/registrations.d.ts +14 -0
  35. package/webauthn/src/registration/registrations.js +31 -0
  36. package/webauthn/src/section.d.ts +15 -0
  37. package/webauthn/src/section.js +32 -0
  38. package/webauthn/src/store.d.ts +55 -0
  39. package/webauthn/src/store.js +17 -0
  40. package/webauthn/src/testing.d.ts +147 -0
  41. package/webauthn/src/testing.js +354 -0
  42. package/webauthn-login/README.md +39 -0
  43. package/webauthn-login/src/audit-events.d.ts +7 -0
  44. package/webauthn-login/src/audit-events.js +7 -0
  45. package/webauthn-login/src/contract.d.ts +3 -0
  46. package/webauthn-login/src/contract.js +3 -0
  47. package/webauthn-login/src/grant.d.ts +14 -0
  48. package/webauthn-login/src/grant.js +95 -0
  49. package/webauthn-login/src/module.d.ts +2 -0
  50. package/webauthn-login/src/module.js +24 -0
  51. package/webauthn-login/src/options.d.ts +5 -0
  52. package/webauthn-login/src/options.js +29 -0
  53. package/webauthn-login/src/section.d.ts +6 -0
  54. package/webauthn-login/src/section.js +6 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 1o1 Co. Ltd.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # @o3co/auth-provider-passkey
2
2
 
3
- This version is a placeholder, published only to bind the package to its trusted
4
- publisher. It has no contents. Use 0.18.0-rc.1 or later.
3
+ Part of auth-provider 0.18.0-rc.1, built from `modules/passkey` of https://github.com/o3co/auth.provider. Its modules, settings and documentation are there.
5
4
 
6
- Source: https://github.com/o3co/auth.provider (`modules/passkey`)
5
+ Copyright 2026 1o1 Co. Ltd. Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,24 @@
1
+ # mfa-webauthn
2
+
3
+ ## Responsibilities
4
+ - Contributes WebAuthn as a kind of second factor (`webauthn`), on `webauthn`'s ceremonies.
5
+
6
+ ## Not here
7
+ - The ceremonies and their checks (`webauthn`). Keeping factors, challenges and transactions (`mfa`, `mfa-flows`). Passkeys for signing in (`webauthn`).
8
+
9
+ ## Offers
10
+ - Contribution to `mfa`'s factor kinds: `webauthn`, adding `mfa`, not guessable, counting.
11
+ - Enrolment: creation options for a credential that need not be discoverable, excluding the subject's WebAuthn factors, for the subject's user handle, showing its name (`subject-attributes`; well formed, 1 to 64 code points, no control or format character), never its email, else `display-name`; its first proof is the attestation.
12
+ - Challenge: request options for the factor's credential, good until `webauthn`'s end (`challenge-seconds`, 120 by default) or the caller's when earlier; its proof is the assertion, as JSON. A binding's creation is good until `webauthn`'s end.
13
+ - Operator section: `user-verification` (`required`, `preferred` by default, or `discouraged`), `display-name` (the name an authenticator shows for an account with none to show, naming no one; default `Account`).
14
+
15
+ ## Invariants
16
+ - A subject's WebAuthn factors share one user handle, made by `webauthn`'s rule (`freshHandle`), apart from its passkeys'; a subject holding none gets a new one.
17
+ - The amr is `swk` for a credential that may be backed up, else `hwk` (RFC 8176). Here `hwk` means "not backup eligible"; `webauthn-login`'s `hwk` covers every passkey, whatever its backup eligibility.
18
+ - A credential bound twice to one subject is a duplicate. One subject's credential is never compared with another's, even under the same credential id: each factor is checked within its subject's user handle.
19
+ - A factor's credential is read as `webauthn` reads its own (`credentialOf`). A credential, a pending secret or a kept challenge that does not read is unavailable, as a store fault; no challenge kept is invalid. An assertion whose count did not go up is replayed; any other refusal is invalid. The factor keeps the count and backup state the assertion gives.
20
+ - An authenticator that keeps no count answers alike each time: one proof passes once only because the caller hands each kept challenge over once (`mfa-flows` takes it with the attempt).
21
+ - A user who signs in with a passkey can meet this factor with another credential on the same authenticator; to keep the two factors on separate devices, do not compose this module.
22
+
23
+ ## Depends on
24
+ - `kernel`, `mfa`, `subject-attributes` (the name shown), `users` (attribute names), `webauthn` (ceremonies)
@@ -0,0 +1,12 @@
1
+ import type { FactorKind } from "@o3co/auth-provider-second-factor/mfa";
2
+ import type { SubjectAttributes } from "@o3co/auth-provider-identity/subject-attributes";
3
+ import { type Ceremonies, type Verification } from "@o3co/auth-provider-passkey/webauthn";
4
+ export interface KindParts {
5
+ readonly ceremonies: Ceremonies;
6
+ readonly verification: Verification;
7
+ readonly attributes: () => Pick<SubjectAttributes, "of">;
8
+ /** The name shown when the subject has none to show. */
9
+ readonly displayName: string;
10
+ readonly random: (n: number) => Uint8Array;
11
+ }
12
+ export declare function webauthnKind(p: KindParts): FactorKind;
@@ -0,0 +1,105 @@
1
+ import { Unavailable } from "@o3co/auth-provider-foundation/kernel";
2
+ import { userAttribute } from "@o3co/auth-provider-identity/users";
3
+ import { credentialOf, freshHandle, } from "@o3co/auth-provider-passkey/webauthn";
4
+ import { z } from "zod";
5
+ import { showable } from "./name.js";
6
+ /** RFC 8176: a key the authenticator keeps on the device, or one it may copy elsewhere. */
7
+ const hardware = "hwk";
8
+ const software = "swk";
9
+ /**
10
+ * What a factor keeps in its secret: the subject's user handle, and the challenge its binding answers
11
+ * with its end (kept after binding, read by nothing then).
12
+ */
13
+ const secretShape = z.strictObject({
14
+ handle: z.string().min(1),
15
+ challenge: z.string().min(1),
16
+ until: z.number(),
17
+ });
18
+ /** What a challenge keeps for its answer: the challenge, and its end on the kernel's clock. */
19
+ const keptShape = z.strictObject({ challenge: z.string().min(1), until: z.number() });
20
+ const read = (shape, value) => {
21
+ const parsed = shape.safeParse(value);
22
+ return parsed.success ? parsed.data : undefined;
23
+ };
24
+ /** The JSON text's value, or undefined if it is not JSON. */
25
+ const json = (text) => {
26
+ try {
27
+ return JSON.parse(text);
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ };
33
+ const secretOf = (secret) => read(secretShape, json(secret));
34
+ /**
35
+ * What mfa hands back: the factor's credential, its pending secret, or what its challenge kept. mfa
36
+ * gives back only what it sealed, so one that does not read is a store fault, never a refusal.
37
+ */
38
+ const stored = (value) => {
39
+ if (value === undefined)
40
+ throw new Unavailable("mfa-webauthn");
41
+ return value;
42
+ };
43
+ const credentialIn = (state) => stored(credentialOf(state));
44
+ const amrOf = (credential) => [credential.backupEligible ? software : hardware];
45
+ export function webauthnKind(p) {
46
+ /**
47
+ * The subject's name, never its email: an authenticator and a device's passkey list keep what it
48
+ * shows. Else the operator's name, which names no one.
49
+ */
50
+ const nameOf = async (subject) => {
51
+ const answer = await p.attributes().of(subject);
52
+ const known = answer.kind === "known" ? answer.attributes : {};
53
+ return showable(known[userAttribute.name]) ?? p.displayName;
54
+ };
55
+ /** A binding's first proof answers the creation its secret kept. */
56
+ const attestation = async (secret, response) => {
57
+ const { challenge, handle, until } = stored(secretOf(secret));
58
+ const attested = await p.ceremonies.attest(response, challenge, handle, p.verification, until);
59
+ if (attested.kind !== "attested")
60
+ return { kind: "invalid" };
61
+ return { kind: "valid", state: attested.credential, amr: amrOf(attested.credential) };
62
+ };
63
+ /** Any later proof answers the request the factor's last challenge kept. */
64
+ const assertion = async (state, response, kept) => {
65
+ const credential = credentialIn(state);
66
+ // No challenge kept: the proof answers nothing this factor asked, or one already used.
67
+ if (kept === undefined)
68
+ return { kind: "invalid" };
69
+ const { challenge, until } = stored(read(keptShape, json(kept)));
70
+ const asserted = await p.ceremonies.assert(response, challenge, credential, p.verification, until);
71
+ if (asserted.kind === "asserted") {
72
+ return { kind: "valid", state: asserted.credential, amr: amrOf(asserted.credential) };
73
+ }
74
+ // A count that did not go up is an assertion older than one already used.
75
+ return { kind: asserted.reason === "sign-count" ? "replayed" : "invalid" };
76
+ };
77
+ return {
78
+ kind: "webauthn",
79
+ amr: [hardware, software],
80
+ addsSecondFactor: true,
81
+ guessable: false,
82
+ counts: true,
83
+ // The handle is the subject's, so this tells apart only a credential bound twice to one subject.
84
+ uniqueSecret: ({ secret, state }) => {
85
+ const handle = secretOf(secret)?.handle;
86
+ const credential = credentialOf(state);
87
+ return handle && credential ? `${handle}\n${credential.id}` : undefined;
88
+ },
89
+ enroll: async (subject, held) => {
90
+ const handle = held.map((factor) => secretOf(factor.secret)?.handle).find((h) => h !== undefined) ??
91
+ freshHandle(p.random);
92
+ const exclude = held.flatMap((factor) => credentialOf(factor.state)?.id ?? []);
93
+ const { options, challenge, until } = p.ceremonies.creation({ handle, name: await nameOf(subject) }, exclude, p.verification, { discoverable: false });
94
+ return { secret: JSON.stringify({ handle, challenge, until }), show: options };
95
+ },
96
+ // Good until webauthn's end (`challenge-seconds`) or the caller's, whichever comes first.
97
+ challenge: async (_subject, factor, latest) => {
98
+ const credential = credentialIn(factor.state);
99
+ const { options, challenge, until } = p.ceremonies.request([credential], p.verification);
100
+ const kept = JSON.stringify({ challenge, until: Math.min(until, latest) });
101
+ return { kind: "sent", show: options, kept };
102
+ },
103
+ verify: async (secret, state, proof, kept) => state === null ? attestation(secret, json(proof)) : assertion(state, json(proof), kept),
104
+ };
105
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@o3co/auth-provider-foundation/kernel").Module;
2
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { defineModule } from "@o3co/auth-provider-foundation/kernel";
2
+ import { factorKinds } from "@o3co/auth-provider-second-factor/mfa";
3
+ import { subjectAttributes } from "@o3co/auth-provider-identity/subject-attributes";
4
+ import { ceremonies } from "@o3co/auth-provider-passkey/webauthn";
5
+ import { webauthnKind } from "./kind.js";
6
+ import { section } from "./section.js";
7
+ export default defineModule({ name: "mfa-webauthn", section, replicaSafe: true }, (m) => [
8
+ m.contribute(factorKinds).by(async (c) => webauthnKind({
9
+ ceremonies: await c.get(ceremonies),
10
+ verification: c.section["user-verification"],
11
+ // Read at enrolment: subject-attributes reads sessions, whose requirements read factor kinds.
12
+ attributes: c.late(subjectAttributes),
13
+ displayName: c.section["display-name"],
14
+ random: c.random.bytes,
15
+ })),
16
+ ]);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A name an authenticator can show: well formed, 1 to 64 code points, no control or format character
3
+ * (a bidirectional override, say).
4
+ */
5
+ export declare const showable: (value: unknown) => string | undefined;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A name an authenticator can show: well formed, 1 to 64 code points, no control or format character
3
+ * (a bidirectional override, say).
4
+ */
5
+ export const showable = (value) => typeof value === "string" && value.isWellFormed() && /^[^\p{Cc}\p{Cf}]{1,64}$/u.test(value)
6
+ ? value
7
+ : undefined;
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ export declare const section: z.ZodObject<{
3
+ "user-verification": z.ZodDefault<z.ZodEnum<{
4
+ required: "required";
5
+ preferred: "preferred";
6
+ discouraged: "discouraged";
7
+ }>>;
8
+ "display-name": z.ZodDefault<z.ZodString>;
9
+ }, z.core.$strict>;
10
+ export type Settings = z.output<typeof section>;
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ import { showable } from "./name.js";
3
+ export const section = z.strictObject({
4
+ "user-verification": z.enum(["required", "preferred", "discouraged"]).default("preferred"),
5
+ /** The name an authenticator shows for an account with no name to show; it names no one. */
6
+ "display-name": z
7
+ .string()
8
+ .refine((name) => showable(name) !== undefined, "1 to 64 code points, no control or format character")
9
+ .default("Account"),
10
+ });
package/package.json CHANGED
@@ -1,10 +1,64 @@
1
1
  {
2
2
  "name": "@o3co/auth-provider-passkey",
3
- "version": "0.0.0",
3
+ "version": "0.18.0-rc.1",
4
+ "type": "module",
4
5
  "license": "Apache-2.0",
5
6
  "repository": {
6
7
  "type": "git",
7
- "url": "git+https://github.com/o3co/auth.provider.git",
8
+ "url": "https://github.com/o3co/auth.provider",
8
9
  "directory": "modules/passkey"
10
+ },
11
+ "engines": {
12
+ "node": ">=24"
13
+ },
14
+ "exports": {
15
+ "./mfa-webauthn/module": {
16
+ "types": "./mfa-webauthn/src/module.d.ts",
17
+ "default": "./mfa-webauthn/src/module.js"
18
+ },
19
+ "./passkey-registration/module": {
20
+ "types": "./passkey-registration/src/module.d.ts",
21
+ "default": "./passkey-registration/src/module.js"
22
+ },
23
+ "./webauthn": {
24
+ "types": "./webauthn/src/contract.d.ts",
25
+ "default": "./webauthn/src/contract.js"
26
+ },
27
+ "./webauthn/testing": {
28
+ "types": "./webauthn/src/testing.d.ts",
29
+ "default": "./webauthn/src/testing.js"
30
+ },
31
+ "./webauthn/module": {
32
+ "types": "./webauthn/src/module.d.ts",
33
+ "default": "./webauthn/src/module.js"
34
+ },
35
+ "./webauthn-login": {
36
+ "types": "./webauthn-login/src/contract.d.ts",
37
+ "default": "./webauthn-login/src/contract.js"
38
+ },
39
+ "./webauthn-login/module": {
40
+ "types": "./webauthn-login/src/module.d.ts",
41
+ "default": "./webauthn-login/src/module.js"
42
+ },
43
+ "./webauthn-login/audit-events": {
44
+ "types": "./webauthn-login/src/audit-events.d.ts",
45
+ "default": "./webauthn-login/src/audit-events.js"
46
+ }
47
+ },
48
+ "dependencies": {
49
+ "@o3co/auth-provider-foundation": "0.18.0-rc.1",
50
+ "@o3co/auth-provider-identity": "0.18.0-rc.1",
51
+ "@o3co/auth-provider-oauth": "0.18.0-rc.1",
52
+ "@o3co/auth-provider-second-factor": "0.18.0-rc.1",
53
+ "@simplewebauthn/server": "14.0.1",
54
+ "zod": "4.6.5"
55
+ },
56
+ "peerDependencies": {
57
+ "vitest": "5.0.3"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "vitest": {
61
+ "optional": true
62
+ }
9
63
  }
10
- }
64
+ }
@@ -0,0 +1,27 @@
1
+ # passkey-registration
2
+
3
+ ## Responsibilities
4
+ - Registers passkeys from a session: routes that ask `webauthn`'s `registrations` for creation options, then to keep the passkey a response creates.
5
+
6
+ ## Not here
7
+ - The ceremonies, the passkey records, the limit per subject and the user handle (`webauthn`). Whether a session may enter at `credentials` (the entry requirements `session` composes). Logging in with a passkey (`webauthn-login`).
8
+
9
+ ## Offers
10
+ - Composition definition. It comes wherever `webauthn` and `session` are both composed, so a deployment that adds a passkey feature gets it too.
11
+ - Route `POST /oauth/webauthn/registration/options`: `webauthn`'s creation options for the session's subject.
12
+ - Route `POST /oauth/webauthn/registration/verify`: takes `{response, nickname?}`, answers `{credentialId, transports, backedUp}`, with `transports` only when the authenticator names some.
13
+ - Both take JSON or no body, use `csrf`'s policy and `rate-limit`'s requests policy, and enter the session at level `credentials`. Every answer is `no-store`.
14
+ - Errors: `401 unauthorized`, `403` `csrf` or the requirement's answer, `400` (`invalid_request`, `challenge_invalid`, `credential_id_conflict`, `credential_limit`, or the ceremony's refusal: `origin_mismatch`, `top_origin_mismatch`, `challenge_mismatch`, `rp_id_mismatch`, `algorithm_not_allowed`, `attestation_invalid`, `user_verification_required`, `unknown`), `415` for another body, `429 rate_limited`, `503` `temporarily_unavailable` (a store) or `service_unavailable` (requests not counted).
15
+ - Operator section: `requests` (1–100000, default 60) in `window-seconds` (1–86400, default 300), over both routes.
16
+
17
+ ## Invariants
18
+ - The subject comes from the session, never from the body.
19
+ - `response` must be an object, and a `nickname` sent is 1 to 64 UTF-16 code units; otherwise `invalid_request`, before `webauthn` is asked.
20
+ - Client data that does not read is `invalid_request`; `webauthn`'s `no-challenge` is `challenge_invalid`.
21
+ - `credential_id_conflict` tells a signed-in session that some subject lists an id. Ids are high-entropy, made by the authenticator, so this answers only for an id already known.
22
+ - Each refusal of `webauthn` maps to one error word here, and nowhere else.
23
+ - A store that cannot tell is `503`, never a refusal.
24
+ - Entry at `credentials` is `mfa`'s judgement where it is composed; else `session` needs a recent sign-in at a known time.
25
+
26
+ ## Depends on
27
+ - `kernel`, `http`, `webauthn`, `session`, `csrf`, `rate-limit`
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@o3co/auth-provider-foundation/kernel").Module;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { routes } from "@o3co/auth-provider-foundation/http";
2
+ import { defineModule } from "@o3co/auth-provider-foundation/kernel";
3
+ import { sessions } from "@o3co/auth-provider-identity/session";
4
+ import { registrations } from "@o3co/auth-provider-passkey/webauthn";
5
+ import { registrationRoutes } from "./routes.js";
6
+ import { section } from "./section.js";
7
+ export default defineModule({ name: "passkey-registration", section, replicaSafe: true }, (m) => ["options", "verify"].map((name) => m.contribute(routes).by(async (c) => registrationRoutes({
8
+ sessions: await c.get(sessions),
9
+ registrations: await c.get(registrations),
10
+ window: { limit: c.section.requests, ms: c.section["window-seconds"] * 1000 },
11
+ })[name])));
@@ -0,0 +1,13 @@
1
+ import { type Route } from "@o3co/auth-provider-foundation/http";
2
+ import { type Window } from "@o3co/auth-provider-foundation/rate-limit";
3
+ import type { Sessions } from "@o3co/auth-provider-identity/session";
4
+ import type { Registrations } from "@o3co/auth-provider-passkey/webauthn";
5
+ export interface RouteParts {
6
+ readonly sessions: Sessions;
7
+ readonly registrations: Registrations;
8
+ readonly window: Window;
9
+ }
10
+ export declare function registrationRoutes(p: RouteParts): {
11
+ readonly options: Route;
12
+ readonly verify: Route;
13
+ };
@@ -0,0 +1,84 @@
1
+ import { csrfChecked } from "@o3co/auth-provider-identity/csrf";
2
+ import { noStore, use } from "@o3co/auth-provider-foundation/http";
3
+ import { isUnavailable } from "@o3co/auth-provider-foundation/kernel";
4
+ import { requestsPerSource } from "@o3co/auth-provider-foundation/rate-limit";
5
+ /** Each refusal in the words clients of these routes know. */
6
+ const errorOf = {
7
+ origin: "origin_mismatch",
8
+ "top-origin": "top_origin_mismatch",
9
+ challenge: "challenge_mismatch",
10
+ rp: "rp_id_mismatch",
11
+ algorithm: "algorithm_not_allowed",
12
+ signature: "attestation_invalid",
13
+ malformed: "unknown",
14
+ "user-verification": "user_verification_required",
15
+ "sign-count": "unknown",
16
+ "user-handle": "unknown",
17
+ "backup-eligibility": "unknown",
18
+ "no-challenge": "challenge_invalid",
19
+ conflict: "credential_id_conflict",
20
+ full: "credential_limit",
21
+ unreadable: "invalid_request",
22
+ };
23
+ const descriptionOf = {
24
+ conflict: "credential ID already registered",
25
+ unreadable: "unreadable client data",
26
+ };
27
+ const answer = (status, json) => ({
28
+ status,
29
+ headers: noStore,
30
+ body: { json },
31
+ });
32
+ const invalid = (description) => answer(400, { error: "invalid_request", error_description: description });
33
+ /** A nickname is 1 to 64 UTF-16 code units. */
34
+ const isNickname = (value) => typeof value === "string" && value.length >= 1 && value.length <= 64;
35
+ export function registrationRoutes(p) {
36
+ const post = (path, handle) => ({
37
+ method: "POST",
38
+ path,
39
+ uses: [
40
+ use(csrfChecked),
41
+ use(requestsPerSource, { name: "passkey-registration", window: p.window }),
42
+ ],
43
+ takes: ["json", "none"],
44
+ handle: async (request) => {
45
+ try {
46
+ const entry = await p.sessions.enterFor(request, "credentials");
47
+ if (entry.kind === "absent")
48
+ return answer(401, { error: "unauthorized" });
49
+ if (entry.kind === "short")
50
+ return answer(403, entry.answer);
51
+ return await handle(request, entry.session.context.subject);
52
+ }
53
+ catch (error) {
54
+ if (isUnavailable(error))
55
+ return answer(503, { error: "temporarily_unavailable" });
56
+ throw error;
57
+ }
58
+ },
59
+ });
60
+ const options = post("/oauth/webauthn/registration/options", async (_request, subject) => answer(200, (await p.registrations.creation(subject)).options));
61
+ const verify = post("/oauth/webauthn/registration/verify", async (request, subject) => {
62
+ const { response, nickname } = request.json ?? {};
63
+ if (typeof response !== "object" || response === null || Array.isArray(response)) {
64
+ return invalid("response must be an object");
65
+ }
66
+ if (nickname !== undefined && !isNickname(nickname))
67
+ return invalid("invalid nickname");
68
+ const kept = await p.registrations.register(subject, response, nickname);
69
+ if (kept.kind === "refused") {
70
+ const description = descriptionOf[kept.reason];
71
+ return answer(400, {
72
+ error: errorOf[kept.reason],
73
+ ...(description ? { error_description: description } : {}),
74
+ });
75
+ }
76
+ const { credential } = kept;
77
+ return answer(200, {
78
+ credentialId: credential.id,
79
+ ...(credential.transports ? { transports: credential.transports } : {}),
80
+ backedUp: credential.backedUp,
81
+ });
82
+ });
83
+ return { options, verify };
84
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ export declare const section: z.ZodObject<{
3
+ requests: z.ZodDefault<z.ZodNumber>;
4
+ "window-seconds": z.ZodDefault<z.ZodNumber>;
5
+ }, z.core.$strict>;
6
+ export type Settings = z.output<typeof section>;