@tinfoilsh/passkey-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +127 -0
  3. package/dist/codec.d.ts +12 -0
  4. package/dist/codec.d.ts.map +1 -0
  5. package/dist/codec.js +61 -0
  6. package/dist/codec.js.map +1 -0
  7. package/dist/crypto.d.ts +55 -0
  8. package/dist/crypto.d.ts.map +1 -0
  9. package/dist/crypto.js +105 -0
  10. package/dist/crypto.js.map +1 -0
  11. package/dist/errors.d.ts +23 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +33 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +8 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/kit.d.ts +63 -0
  20. package/dist/kit.d.ts.map +1 -0
  21. package/dist/kit.js +199 -0
  22. package/dist/kit.js.map +1 -0
  23. package/dist/protocol.d.ts +13 -0
  24. package/dist/protocol.d.ts.map +1 -0
  25. package/dist/protocol.js +13 -0
  26. package/dist/protocol.js.map +1 -0
  27. package/dist/storage.d.ts +31 -0
  28. package/dist/storage.d.ts.map +1 -0
  29. package/dist/storage.js +68 -0
  30. package/dist/storage.js.map +1 -0
  31. package/dist/support.d.ts +15 -0
  32. package/dist/support.d.ts.map +1 -0
  33. package/dist/support.js +58 -0
  34. package/dist/support.js.map +1 -0
  35. package/dist/types.d.ts +101 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +2 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/webauthn.d.ts +38 -0
  40. package/dist/webauthn.d.ts.map +1 -0
  41. package/dist/webauthn.js +189 -0
  42. package/dist/webauthn.js.map +1 -0
  43. package/package.json +55 -0
  44. package/src/codec.ts +71 -0
  45. package/src/crypto.ts +161 -0
  46. package/src/errors.ts +41 -0
  47. package/src/index.ts +47 -0
  48. package/src/kit.ts +333 -0
  49. package/src/protocol.ts +15 -0
  50. package/src/storage.ts +69 -0
  51. package/src/support.ts +61 -0
  52. package/src/types.ts +113 -0
  53. package/src/webauthn.ts +258 -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 [yyyy] [name of copyright owner]
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 ADDED
@@ -0,0 +1,127 @@
1
+ # Tinfoil Passkey Kit
2
+
3
+ Cross-platform SDKs for protecting content-encryption keys with passkeys and
4
+ the WebAuthn PRF extension. The JavaScript and Swift implementations share the
5
+ same protocol constants and wire formats, so either client can recover a CEK
6
+ wrapped by the other.
7
+
8
+ - Passkey creation and authentication with PRF
9
+ - HKDF-SHA-256 key-encryption-key derivation
10
+ - AES-256-GCM CEK wrapping and unwrapping
11
+ - Stable CEK key-ID derivation
12
+ - Device-local PRF and credential persistence
13
+
14
+ ## JavaScript
15
+
16
+ Install the browser package:
17
+
18
+ ```sh
19
+ npm install @tinfoilsh/passkey-kit
20
+ ```
21
+
22
+ ```ts
23
+ import { createPasskeyKit, generateCek } from "@tinfoilsh/passkey-kit";
24
+
25
+ const kit = createPasskeyKit({
26
+ rpId: "example.com",
27
+ rpName: "Example App",
28
+ });
29
+
30
+ const cek = generateCek();
31
+ const enrolled = await kit.enroll({
32
+ user: { id: userId, name: email, displayName },
33
+ cek,
34
+ });
35
+
36
+ if (enrolled) {
37
+ await api.saveBundle(enrolled.wrappedCek);
38
+ }
39
+
40
+ const unlocked = await kit.unlock(bundlesFromServer);
41
+ if (unlocked) {
42
+ useCek(unlocked.cek);
43
+ }
44
+ ```
45
+
46
+ High-level ceremony methods return `null` when the user cancels. They throw
47
+ `PrfNotSupportedError` when the authenticator lacks PRF support and
48
+ `PasskeyTimeoutError` when the provider hangs. Classify these errors with
49
+ `instanceof`, not message strings.
50
+
51
+ The kit also provides cached unlock and rewrap flows. Lower-level exports
52
+ include `detectPrfSupport`, `deriveKeyEncryptionKey`, `generateCek`,
53
+ `isValidCek`, `wrapCek`, `unwrapCek`, and `deriveKeyId`.
54
+
55
+ The default storage adapter uses `localStorage` on a best-effort basis. Pass
56
+ `storage: null` to disable persistence or provide a custom `StorageAdapter`.
57
+ Cached PRF output is raw secret key material and must be protected accordingly.
58
+
59
+ ## Swift
60
+
61
+ Add this repository as a Swift Package Manager dependency and link the
62
+ `TinfoilPasskeyKit` product. The package requires iOS 18 or macOS 15.
63
+
64
+ ```swift
65
+ import TinfoilPasskeyKit
66
+
67
+ @MainActor
68
+ func configurePasskeyKit() async throws {
69
+ let store = KeychainPasskeyStateStore(
70
+ service: "example.com",
71
+ account: "com.example.passkey-prf",
72
+ localCredentialIdKey: "com.example.local-passkey-id"
73
+ )
74
+ let kit = PasskeyKit(
75
+ configuration: PasskeyKitConfiguration(
76
+ rpId: "example.com",
77
+ rpName: "Example App",
78
+ stateStore: store
79
+ )
80
+ )
81
+
82
+ let cek = try PasskeyCrypto.generateCEK()
83
+ let enrollment = try await kit.enroll(
84
+ user: PasskeyUser(id: userId, name: email, displayName: displayName),
85
+ cek: cek
86
+ )
87
+ await saveToServer(enrollment.wrappedCEK)
88
+
89
+ let unlocked = try await kit.unlock(wrappedCEKsFromServer)
90
+ useCEK(unlocked.cek)
91
+ }
92
+ ```
93
+
94
+ `KeychainPasskeyStateStore` stores cached PRF output with
95
+ `kSecAttrAccessibleWhenUnlockedThisDeviceOnly`. Pass `stateStore: nil` to
96
+ disable local persistence. The host app must provide the `webcredentials`
97
+ associated-domain entitlement for its relying-party domain.
98
+
99
+ ## Protocol
100
+
101
+ Both implementations default to the Tinfoil v1 PRF salt and HKDF info. These
102
+ values must remain identical across clients that wrap the same CEK. Override
103
+ both values together to establish a separate protocol domain.
104
+
105
+ The server-persisted wrapped bundle contains only:
106
+
107
+ - The unpadded base64url credential ID
108
+ - The 12-byte AES-GCM IV as lowercase hexadecimal
109
+ - The wrapped CEK ciphertext and 16-byte authentication tag as lowercase
110
+ hexadecimal
111
+
112
+ User identity, server persistence, associated-domain configuration, and
113
+ recovery UI remain the host application's responsibility.
114
+
115
+ ## License
116
+
117
+ Apache License 2.0. See [LICENSE](LICENSE).
118
+
119
+ ## Development
120
+
121
+ ```sh
122
+ npm install
123
+ npm test
124
+ npm run typecheck
125
+ npm run build
126
+ swift test
127
+ ```
@@ -0,0 +1,12 @@
1
+ /** Dependency-free binary codecs shared across the SDK. */
2
+ export declare function bytesToHex(bytes: Uint8Array): string;
3
+ export declare function hexToBytes(hex: string): Uint8Array;
4
+ export declare function bytesToBase64(bytes: Uint8Array): string;
5
+ export declare function base64ToBytes(base64: string): Uint8Array;
6
+ export declare function bytesToBase64Url(bytes: Uint8Array): string;
7
+ export declare function base64UrlToBytes(base64url: string): Uint8Array;
8
+ /** Convert a BufferSource (ArrayBuffer or view) to a standalone ArrayBuffer copy. */
9
+ export declare function bufferSourceToArrayBuffer(source: BufferSource): ArrayBuffer;
10
+ /** Normalize a string (UTF-8 encoded) or byte input to bytes. */
11
+ export declare function toBytes(input: string | Uint8Array): Uint8Array;
12
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMpD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAYlD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQvD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAOxD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAK1D;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAI9D;AAED,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAQ3E;AAED,iEAAiE;AACjE,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAE9D"}
package/dist/codec.js ADDED
@@ -0,0 +1,61 @@
1
+ /** Dependency-free binary codecs shared across the SDK. */
2
+ export function bytesToHex(bytes) {
3
+ let out = '';
4
+ for (let i = 0; i < bytes.length; i++) {
5
+ out += bytes[i].toString(16).padStart(2, '0');
6
+ }
7
+ return out;
8
+ }
9
+ export function hexToBytes(hex) {
10
+ if (hex.length % 2 !== 0) {
11
+ throw new Error('passkey-kit: odd-length hex input');
12
+ }
13
+ if (!/^[0-9a-fA-F]*$/.test(hex)) {
14
+ throw new Error('passkey-kit: invalid hex character');
15
+ }
16
+ const out = new Uint8Array(hex.length / 2);
17
+ for (let i = 0; i < out.length; i++) {
18
+ out[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
19
+ }
20
+ return out;
21
+ }
22
+ export function bytesToBase64(bytes) {
23
+ const CHUNK_SIZE = 0x8000;
24
+ const chunks = [];
25
+ for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {
26
+ const chunk = bytes.subarray(i, i + CHUNK_SIZE);
27
+ chunks.push(String.fromCharCode.apply(null, Array.from(chunk)));
28
+ }
29
+ return btoa(chunks.join(''));
30
+ }
31
+ export function base64ToBytes(base64) {
32
+ const binary = atob(base64);
33
+ const bytes = new Uint8Array(binary.length);
34
+ for (let i = 0; i < binary.length; i++) {
35
+ bytes[i] = binary.charCodeAt(i);
36
+ }
37
+ return bytes;
38
+ }
39
+ export function bytesToBase64Url(bytes) {
40
+ return bytesToBase64(bytes)
41
+ .replace(/\+/g, '-')
42
+ .replace(/\//g, '_')
43
+ .replace(/=+$/, '');
44
+ }
45
+ export function base64UrlToBytes(base64url) {
46
+ const base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
47
+ const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
48
+ return base64ToBytes(padded);
49
+ }
50
+ /** Convert a BufferSource (ArrayBuffer or view) to a standalone ArrayBuffer copy. */
51
+ export function bufferSourceToArrayBuffer(source) {
52
+ if (source instanceof ArrayBuffer) {
53
+ return source.slice(0);
54
+ }
55
+ return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
56
+ }
57
+ /** Normalize a string (UTF-8 encoded) or byte input to bytes. */
58
+ export function toBytes(input) {
59
+ return typeof input === 'string' ? new TextEncoder().encode(input) : input;
60
+ }
61
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC/C,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;IACtD,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACvD,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EA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CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC9D,MAAM,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACjE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,yBAAyB,CAAC,MAAoB;IAC5D,IAAI,MAAM,YAAY,WAAW,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CACxB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CACvB,CAAA;AAClB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,OAAO,CAAC,KAA0B;IAChD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AAC5E,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Pure WebCrypto primitives: PRF output → KEK derivation (HKDF-SHA-256)
3
+ * and CEK wrap/unwrap under that KEK (AES-256-GCM).
4
+ *
5
+ * References:
6
+ * - W3C WebAuthn Level 3, §10.1.4 (PRF extension): https://w3c.github.io/webauthn/#prf-extension
7
+ * - RFC 5869 (HKDF): https://tools.ietf.org/html/rfc5869
8
+ */
9
+ import type { WrappedCek } from "./types.js";
10
+ export declare const CEK_BYTES = 32;
11
+ /** Generate a fresh random 32-byte CEK suitable for {@link wrapCek}. */
12
+ export declare function generateCek(): Uint8Array;
13
+ /**
14
+ * Type guard for a well-formed CEK: a Uint8Array of exactly
15
+ * {@link CEK_BYTES} bytes. Useful for validating deserialized input
16
+ * before wrapping.
17
+ */
18
+ export declare function isValidCek(cek: unknown): cek is Uint8Array;
19
+ /**
20
+ * Derive an AES-256-GCM Key Encryption Key (KEK) from PRF output using HKDF.
21
+ *
22
+ * Raw PRF output is treated as Input Keying Material (IKM), not used
23
+ * directly as a key. HKDF with a purpose-binding info string produces the
24
+ * final non-extractable CryptoKey. An empty HKDF salt is used, which is
25
+ * fine for high-entropy IKM (RFC 5869 §3.1).
26
+ *
27
+ * `hkdfInfo` defaults to the Tinfoil v1 protocol constant so standalone
28
+ * callers derive the same interoperable KEK as a default-configured kit.
29
+ */
30
+ export declare function deriveKeyEncryptionKey(prfOutput: ArrayBuffer | Uint8Array, hkdfInfo?: string | Uint8Array): Promise<CryptoKey>;
31
+ /**
32
+ * Wrap a raw 32-byte CEK under a passkey-derived KEK using AES-256-GCM
33
+ * with a fresh random IV. The returned hex fields are safe to persist
34
+ * server-side; only the matching passkey can recover the CEK.
35
+ */
36
+ export declare function wrapCek(opts: {
37
+ credentialId: string;
38
+ kek: CryptoKey;
39
+ cek: Uint8Array;
40
+ }): Promise<WrappedCek>;
41
+ /**
42
+ * Inverse of {@link wrapCek}: recover the raw CEK bytes given the same KEK.
43
+ * Throws on tamper (GCM auth failure) or any shape mismatch.
44
+ */
45
+ export declare function unwrapCek(kek: CryptoKey, wrapped: Pick<WrappedCek, "kekIvHex" | "wrappedKeyHex">): Promise<Uint8Array>;
46
+ /**
47
+ * Derive a stable public identifier for a CEK via HKDF-SHA-256 with an
48
+ * empty salt and a purpose-binding info string. The result identifies the key
49
+ * without revealing it (one-way derivation).
50
+ */
51
+ export declare function deriveKeyId(cek: Uint8Array, opts?: {
52
+ info?: string | Uint8Array;
53
+ lengthBytes?: number;
54
+ }): Promise<Uint8Array>;
55
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,SAAS,KAAK,CAAC;AAI5B,wEAAwE;AACxE,wBAAgB,WAAW,IAAI,UAAU,CAExC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,UAAU,CAE1D;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,WAAW,GAAG,UAAU,EACnC,QAAQ,GAAE,MAAM,GAAG,UAAiC,GACnD,OAAO,CAAC,SAAS,CAAC,CAqBpB;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,SAAS,CAAC;IACf,GAAG,EAAE,UAAU,CAAC;CACjB,GAAG,OAAO,CAAC,UAAU,CAAC,CAiBtB;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAAC,GACtD,OAAO,CAAC,UAAU,CAAC,CAqBrB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,UAAU,EACf,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9D,OAAO,CAAC,UAAU,CAAC,CAyBrB"}
package/dist/crypto.js ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Pure WebCrypto primitives: PRF output → KEK derivation (HKDF-SHA-256)
3
+ * and CEK wrap/unwrap under that KEK (AES-256-GCM).
4
+ *
5
+ * References:
6
+ * - W3C WebAuthn Level 3, §10.1.4 (PRF extension): https://w3c.github.io/webauthn/#prf-extension
7
+ * - RFC 5869 (HKDF): https://tools.ietf.org/html/rfc5869
8
+ */
9
+ import { bytesToHex, hexToBytes, toBytes } from "./codec.js";
10
+ import { PasskeyKitError } from "./errors.js";
11
+ import { TINFOIL_HKDF_INFO_V1, TINFOIL_KEY_ID_INFO_V1 } from "./protocol.js";
12
+ export const CEK_BYTES = 32;
13
+ const AES_GCM_IV_BYTES = 12;
14
+ const DEFAULT_KEY_ID_BYTES = 16;
15
+ /** Generate a fresh random 32-byte CEK suitable for {@link wrapCek}. */
16
+ export function generateCek() {
17
+ return crypto.getRandomValues(new Uint8Array(CEK_BYTES));
18
+ }
19
+ /**
20
+ * Type guard for a well-formed CEK: a Uint8Array of exactly
21
+ * {@link CEK_BYTES} bytes. Useful for validating deserialized input
22
+ * before wrapping.
23
+ */
24
+ export function isValidCek(cek) {
25
+ return cek instanceof Uint8Array && cek.length === CEK_BYTES;
26
+ }
27
+ /**
28
+ * Derive an AES-256-GCM Key Encryption Key (KEK) from PRF output using HKDF.
29
+ *
30
+ * Raw PRF output is treated as Input Keying Material (IKM), not used
31
+ * directly as a key. HKDF with a purpose-binding info string produces the
32
+ * final non-extractable CryptoKey. An empty HKDF salt is used, which is
33
+ * fine for high-entropy IKM (RFC 5869 §3.1).
34
+ *
35
+ * `hkdfInfo` defaults to the Tinfoil v1 protocol constant so standalone
36
+ * callers derive the same interoperable KEK as a default-configured kit.
37
+ */
38
+ export async function deriveKeyEncryptionKey(prfOutput, hkdfInfo = TINFOIL_HKDF_INFO_V1) {
39
+ const masterKey = await crypto.subtle.importKey("raw", prfOutput, "HKDF", false, // non-extractable
40
+ ["deriveKey"]);
41
+ return crypto.subtle.deriveKey({
42
+ name: "HKDF",
43
+ hash: "SHA-256",
44
+ salt: new Uint8Array(),
45
+ info: toBytes(hkdfInfo),
46
+ }, masterKey, { name: "AES-GCM", length: 256 }, false, // non-extractable
47
+ ["encrypt", "decrypt"]);
48
+ }
49
+ /**
50
+ * Wrap a raw 32-byte CEK under a passkey-derived KEK using AES-256-GCM
51
+ * with a fresh random IV. The returned hex fields are safe to persist
52
+ * server-side; only the matching passkey can recover the CEK.
53
+ */
54
+ export async function wrapCek(opts) {
55
+ if (opts.cek.length !== CEK_BYTES) {
56
+ throw new PasskeyKitError(`passkey-kit: CEK must be ${CEK_BYTES} bytes, got ${opts.cek.length}`);
57
+ }
58
+ const iv = crypto.getRandomValues(new Uint8Array(AES_GCM_IV_BYTES));
59
+ const ciphertext = await crypto.subtle.encrypt({ name: "AES-GCM", iv: iv }, opts.kek, opts.cek);
60
+ return {
61
+ credentialId: opts.credentialId,
62
+ kekIvHex: bytesToHex(iv),
63
+ wrappedKeyHex: bytesToHex(new Uint8Array(ciphertext)),
64
+ };
65
+ }
66
+ /**
67
+ * Inverse of {@link wrapCek}: recover the raw CEK bytes given the same KEK.
68
+ * Throws on tamper (GCM auth failure) or any shape mismatch.
69
+ */
70
+ export async function unwrapCek(kek, wrapped) {
71
+ if (!wrapped.kekIvHex || !wrapped.wrappedKeyHex) {
72
+ throw new PasskeyKitError("passkey-kit: missing iv or wrapped key");
73
+ }
74
+ const iv = hexToBytes(wrapped.kekIvHex);
75
+ if (iv.length !== AES_GCM_IV_BYTES) {
76
+ throw new PasskeyKitError("passkey-kit: iv length mismatch");
77
+ }
78
+ const ciphertext = hexToBytes(wrapped.wrappedKeyHex);
79
+ const plaintext = await crypto.subtle.decrypt({ name: "AES-GCM", iv: iv }, kek, ciphertext);
80
+ const cek = new Uint8Array(plaintext);
81
+ if (cek.length !== CEK_BYTES) {
82
+ throw new PasskeyKitError(`passkey-kit: unwrapped CEK has wrong length ${cek.length}`);
83
+ }
84
+ return cek;
85
+ }
86
+ /**
87
+ * Derive a stable public identifier for a CEK via HKDF-SHA-256 with an
88
+ * empty salt and a purpose-binding info string. The result identifies the key
89
+ * without revealing it (one-way derivation).
90
+ */
91
+ export async function deriveKeyId(cek, opts = {}) {
92
+ if (cek.length !== CEK_BYTES) {
93
+ throw new PasskeyKitError(`passkey-kit: CEK must be ${CEK_BYTES} bytes, got ${cek.length}`);
94
+ }
95
+ const lengthBytes = opts.lengthBytes ?? DEFAULT_KEY_ID_BYTES;
96
+ const ikm = await crypto.subtle.importKey("raw", cek, "HKDF", false, ["deriveBits"]);
97
+ const bits = await crypto.subtle.deriveBits({
98
+ name: "HKDF",
99
+ hash: "SHA-256",
100
+ salt: new Uint8Array(0),
101
+ info: toBytes(opts.info ?? TINFOIL_KEY_ID_INFO_V1),
102
+ }, ikm, lengthBytes * 8);
103
+ return new Uint8Array(bits);
104
+ }
105
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG7E,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAC5B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,wEAAwE;AACxE,MAAM,UAAU,WAAW;IACzB,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,OAAO,GAAG,YAAY,UAAU,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;GAUG;AACH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C,MAAM,CAAC,SAAS,CACvC,KAAK,EACL,GAAmB,EACnB,MAAM,EACN,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,CACzC;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAI,UAAU,CAAC,CAAC,CAAiB;QACvC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,sBAAsB,CAAiB;KACnE,EACD,GAAG,EACH,WAAW,GAAG,CAAC,CAChB,CAAC;IACF,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Typed errors thrown by the SDK. Callers should branch on `instanceof`
3
+ * (never on message strings) to drive recovery flows.
4
+ */
5
+ /** Base class for every error the SDK throws on its own behalf. */
6
+ export declare class PasskeyKitError extends Error {
7
+ constructor(message: string);
8
+ }
9
+ /**
10
+ * The authenticator created a credential but does not support the WebAuthn
11
+ * PRF extension, so no key material can be derived from it.
12
+ */
13
+ export declare class PrfNotSupportedError extends PasskeyKitError {
14
+ constructor(message?: string);
15
+ }
16
+ /**
17
+ * The passkey provider never resolved the WebAuthn promise within the
18
+ * SDK's hard timeout (some password-manager browser extensions hang).
19
+ */
20
+ export declare class PasskeyTimeoutError extends PasskeyKitError {
21
+ constructor(message?: string);
22
+ }
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mEAAmE;AACnE,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAKD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,eAAe;gBAErD,OAAO,SAA6G;CAKvH;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,eAAe;gBAEpD,OAAO,SAA0I;CAKpJ"}
package/dist/errors.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Typed errors thrown by the SDK. Callers should branch on `instanceof`
3
+ * (never on message strings) to drive recovery flows.
4
+ */
5
+ /** Base class for every error the SDK throws on its own behalf. */
6
+ export class PasskeyKitError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = 'PasskeyKitError';
10
+ }
11
+ }
12
+ const PROVIDER_SUGGESTION = "Try using iCloud Keychain, Chrome's built-in passkey manager, or the Passwords app in your device settings.";
13
+ /**
14
+ * The authenticator created a credential but does not support the WebAuthn
15
+ * PRF extension, so no key material can be derived from it.
16
+ */
17
+ export class PrfNotSupportedError extends PasskeyKitError {
18
+ constructor(message = `Your passkey provider doesn't support the security features required by this app. ${PROVIDER_SUGGESTION}`) {
19
+ super(message);
20
+ this.name = 'PrfNotSupportedError';
21
+ }
22
+ }
23
+ /**
24
+ * The passkey provider never resolved the WebAuthn promise within the
25
+ * SDK's hard timeout (some password-manager browser extensions hang).
26
+ */
27
+ export class PasskeyTimeoutError extends PasskeyKitError {
28
+ constructor(message = `Your passkey provider took too long to respond. This can happen with some browser extension password managers. ${PROVIDER_SUGGESTION}`) {
29
+ super(message);
30
+ this.name = 'PasskeyTimeoutError';
31
+ }
32
+ }
33
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mEAAmE;AACnE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AAED,MAAM,mBAAmB,GACvB,6GAA6G,CAAA;AAE/G;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IACvD,YACE,OAAO,GAAG,qFAAqF,mBAAmB,EAAE;QAEpH,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IACtD,YACE,OAAO,GAAG,kHAAkH,mBAAmB,EAAE;QAEjJ,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}