@motebit/crypto-appattest 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,206 @@
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 describing the origin of the Work and
141
+ 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 Motebit, Inc.
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.
202
+
203
+ "Motebit" is a trademark of Motebit, Inc. The Apache License grants rights to
204
+ this software, not to any Motebit trademarks, logos, or branding. You may not
205
+ use Motebit branding in a way that suggests endorsement or affiliation without
206
+ written permission.
package/NOTICE ADDED
@@ -0,0 +1,19 @@
1
+ Motebit
2
+ Copyright 2026 Motebit, Inc.
3
+
4
+ This product includes software developed at Motebit, Inc. (https://motebit.com).
5
+
6
+ The permissive-floor packages (the protocol, SDK, cryptographic primitives,
7
+ platform-attestation verifier leaves, scaffolding CLI, and GitHub Action) are
8
+ licensed under the Apache License, Version 2.0. See LICENSE files in each
9
+ `packages/*/` subdirectory and in `spec/` for the full license text.
10
+
11
+ The remaining packages, apps, and services are licensed under the Business
12
+ Source License 1.1 and convert to the Apache License, Version 2.0 four years
13
+ after each version's first public release. See `LICENSE` at the repository
14
+ root and `LICENSING.md` for the full license boundary.
15
+
16
+ "Motebit" is a trademark of Motebit, Inc. The licenses granted here cover
17
+ this software only, not Motebit trademarks, logos, or branding. Use of
18
+ Motebit branding in a way that suggests endorsement or affiliation requires
19
+ written permission.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @motebit/crypto-appattest
2
+
3
+ Offline Apache-2.0 verifier for Apple App Attest hardware-attestation credentials.
4
+
5
+ ```bash
6
+ npm i @motebit/crypto-appattest
7
+ ```
8
+
9
+ Plugs into [`@motebit/crypto`](https://www.npmjs.com/package/@motebit/crypto)'s `HardwareAttestationVerifiers` dispatcher as the `deviceCheck` verifier — called when a credential declares `platform: "device_check"`.
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { verify } from "@motebit/crypto";
15
+ import { deviceCheckVerifier } from "@motebit/crypto-appattest";
16
+
17
+ const result = await verify(credential, {
18
+ hardwareAttestation: {
19
+ deviceCheck: deviceCheckVerifier({ expectedBundleId: "com.motebit.app" }),
20
+ },
21
+ });
22
+ ```
23
+
24
+ ## What it verifies
25
+
26
+ 1. The CBOR attestation object Apple emits from `DCAppAttestService.attestKey`.
27
+ 2. The leaf + intermediate X.509 chain against the **pinned Apple App Attest root CA** — every non-leaf must carry `basicConstraints.cA === true`, every signature verified, every cert within its validity window, terminal cert DER byte-equal to the pinned root.
28
+ 3. The receipt extension OID `1.2.840.113635.100.8.2` binds `SHA256(authData || clientDataHash)`.
29
+ 4. `authData.rpIdHash === SHA256(bundleId)` (bundle binding).
30
+ 5. **Identity binding.** The transmitted `clientDataHash` must equal `SHA-256(canonicalJson({ motebit_id, device_id, identity_public_key, attested_at, platform: "device_check", version: "1" }))` — the same body the iOS mint path signs over. A malicious native client that substitutes any other body fails here.
31
+
32
+ ## Why pinned
33
+
34
+ A verifier that dynamically fetches CA certificates has no sovereign story. The pinned root is the self-attesting contract — third parties audit `APPLE_APPATTEST_ROOT_PEM` and know what chain this library accepts. Zero network; chain path, clock-skew, and OID extraction are all deterministic from Apple's published spec.
35
+
36
+ ## Related
37
+
38
+ - [`@motebit/crypto`](https://www.npmjs.com/package/@motebit/crypto) — dispatcher (pure permissive-floor; zero deps)
39
+ - [`@motebit/crypto-play-integrity`](https://www.npmjs.com/package/@motebit/crypto-play-integrity) — Android sibling
40
+ - [`@motebit/crypto-tpm`](https://www.npmjs.com/package/@motebit/crypto-tpm) — TPM 2.0 sibling
41
+ - [`@motebit/crypto-webauthn`](https://www.npmjs.com/package/@motebit/crypto-webauthn) — browser sibling
42
+ - [`@motebit/verify`](https://www.npmjs.com/package/@motebit/verify) — canonical CLI bundling all four leaves with motebit defaults
43
+
44
+ ## License
45
+
46
+ Apache-2.0 — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
47
+
48
+ "Motebit" is a trademark. The Apache License grants rights to this software, not to any Motebit trademarks, logos, or branding. You may not use Motebit branding in a way that suggests endorsement or affiliation without written permission.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Pinned Apple App Attest root certificate.
3
+ *
4
+ * This PEM is the root of trust for every `platform: "device_check"`
5
+ * hardware-attestation claim. Pinning is the self-attesting contract
6
+ * — a verifier that dynamically fetched the Apple CA would have no
7
+ * sovereign story, because a third party auditing our output could
8
+ * never reproduce the decision without trusting our fetch path. By
9
+ * committing the exact bytes of the CA we accept, anyone can audit
10
+ * this file, pin the same bytes in their own verifier, and reach the
11
+ * same yes/no answer.
12
+ *
13
+ * Source: Apple's published App Attest CA (Apple App Attestation Root
14
+ * CA). SHA-256 fingerprint of this certificate is the attestor the
15
+ * chain-verification routine requires the leaf's intermediate CA to
16
+ * chain to.
17
+ *
18
+ * If Apple rotates this root (they have every right to — they publish
19
+ * rotation schedules in their developer documentation), an additive
20
+ * PEM constant and a dispatch arm on expiry date land here. That's a
21
+ * judgment call; it belongs in BSL with the rest of the chain-validation
22
+ * policy.
23
+ */
24
+ /**
25
+ * Apple App Attestation Root CA — the single pinned anchor this package
26
+ * chains App Attest leaves to.
27
+ *
28
+ * Byte-for-byte match of Apple's published certificate. Canonical
29
+ * fingerprint (SHA-256): `bf eb 88 ce 0c 59 eb b8 9e b1 9f ab 8d 8f 6d
30
+ * 2b 6e 83 87 27 4e 71 83 9a 2c a7 9d 43 37 1d 7f d6`.
31
+ */
32
+ export declare const APPLE_APPATTEST_ROOT_PEM = "-----BEGIN CERTIFICATE-----\nMIICITCCAaegAwIBAgIQC/O+DvHN0uD7jG5yH2IXmDAKBggqhkjOPQQDAzBSMSYw\nJAYDVQQDDB1BcHBsZSBBcHAgQXR0ZXN0YXRpb24gUm9vdCBDQTETMBEGA1UECgwK\nQXBwbGUgSW5jLjETMBEGA1UECAwKQ2FsaWZvcm5pYTAeFw0yMDAzMTgxODMyNTNa\nFw00NTAzMTUwMDAwMDBaMFIxJjAkBgNVBAMMHUFwcGxlIEFwcCBBdHRlc3RhdGlv\nbiBSb290IENBMRMwEQYDVQQKDApBcHBsZSBJbmMuMRMwEQYDVQQIDApDYWxpZm9y\nbmlhMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAERTHhmLW07ATaFQIEVwTtT4dyctdh\nNbJhFs/Ii2FdCgAHGbpphY3+d8qjuDngIN3WVhQUBHAoMeQ/cLiP1sOUtgjqK9au\nYen1mMEvRq9Sk3Jm5X8U62H+xTD3FE9TgS41o0IwQDAPBgNVHRMBAf8EBTADAQH/\nMB0GA1UdDgQWBBSskRBTM72+aEH/pwyp5frq5eWKoTAOBgNVHQ8BAf8EBAMCAQYw\nCgYIKoZIzj0EAwMDaAAwZQIwQgFGnByvsiVbpTKwSga0kP0e8EeDS4+sQmTvb7vn\n53O5+FRXgeLhpJ06ysC5PrOyAjEAp5U4xDgEgllF7En3VcE3iexZZtKeYnpqtijV\noyFraWVIyd/dganmrduC1bmTBGwD\n-----END CERTIFICATE-----\n";
33
+ /**
34
+ * Apple's published App Attest production RP ID / bundle-check domain.
35
+ * Not used directly by this package — the consumer passes its own
36
+ * bundle ID, which the verifier hashes and asserts equals the
37
+ * authData.rpIdHash field. Exposed here as a labeled constant so the
38
+ * audit trail is obvious.
39
+ */
40
+ export declare const APPLE_APPATTEST_FMT = "apple-appattest";
41
+ //# sourceMappingURL=apple-root.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apple-root.d.ts","sourceRoot":"","sources":["../src/apple-root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,izBAcpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Pinned Apple App Attest root certificate.
3
+ *
4
+ * This PEM is the root of trust for every `platform: "device_check"`
5
+ * hardware-attestation claim. Pinning is the self-attesting contract
6
+ * — a verifier that dynamically fetched the Apple CA would have no
7
+ * sovereign story, because a third party auditing our output could
8
+ * never reproduce the decision without trusting our fetch path. By
9
+ * committing the exact bytes of the CA we accept, anyone can audit
10
+ * this file, pin the same bytes in their own verifier, and reach the
11
+ * same yes/no answer.
12
+ *
13
+ * Source: Apple's published App Attest CA (Apple App Attestation Root
14
+ * CA). SHA-256 fingerprint of this certificate is the attestor the
15
+ * chain-verification routine requires the leaf's intermediate CA to
16
+ * chain to.
17
+ *
18
+ * If Apple rotates this root (they have every right to — they publish
19
+ * rotation schedules in their developer documentation), an additive
20
+ * PEM constant and a dispatch arm on expiry date land here. That's a
21
+ * judgment call; it belongs in BSL with the rest of the chain-validation
22
+ * policy.
23
+ */
24
+ /**
25
+ * Apple App Attestation Root CA — the single pinned anchor this package
26
+ * chains App Attest leaves to.
27
+ *
28
+ * Byte-for-byte match of Apple's published certificate. Canonical
29
+ * fingerprint (SHA-256): `bf eb 88 ce 0c 59 eb b8 9e b1 9f ab 8d 8f 6d
30
+ * 2b 6e 83 87 27 4e 71 83 9a 2c a7 9d 43 37 1d 7f d6`.
31
+ */
32
+ export const APPLE_APPATTEST_ROOT_PEM = `-----BEGIN CERTIFICATE-----
33
+ MIICITCCAaegAwIBAgIQC/O+DvHN0uD7jG5yH2IXmDAKBggqhkjOPQQDAzBSMSYw
34
+ JAYDVQQDDB1BcHBsZSBBcHAgQXR0ZXN0YXRpb24gUm9vdCBDQTETMBEGA1UECgwK
35
+ QXBwbGUgSW5jLjETMBEGA1UECAwKQ2FsaWZvcm5pYTAeFw0yMDAzMTgxODMyNTNa
36
+ Fw00NTAzMTUwMDAwMDBaMFIxJjAkBgNVBAMMHUFwcGxlIEFwcCBBdHRlc3RhdGlv
37
+ biBSb290IENBMRMwEQYDVQQKDApBcHBsZSBJbmMuMRMwEQYDVQQIDApDYWxpZm9y
38
+ bmlhMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAERTHhmLW07ATaFQIEVwTtT4dyctdh
39
+ NbJhFs/Ii2FdCgAHGbpphY3+d8qjuDngIN3WVhQUBHAoMeQ/cLiP1sOUtgjqK9au
40
+ Yen1mMEvRq9Sk3Jm5X8U62H+xTD3FE9TgS41o0IwQDAPBgNVHRMBAf8EBTADAQH/
41
+ MB0GA1UdDgQWBBSskRBTM72+aEH/pwyp5frq5eWKoTAOBgNVHQ8BAf8EBAMCAQYw
42
+ CgYIKoZIzj0EAwMDaAAwZQIwQgFGnByvsiVbpTKwSga0kP0e8EeDS4+sQmTvb7vn
43
+ 53O5+FRXgeLhpJ06ysC5PrOyAjEAp5U4xDgEgllF7En3VcE3iexZZtKeYnpqtijV
44
+ oyFraWVIyd/dganmrduC1bmTBGwD
45
+ -----END CERTIFICATE-----
46
+ `;
47
+ /**
48
+ * Apple's published App Attest production RP ID / bundle-check domain.
49
+ * Not used directly by this package — the consumer passes its own
50
+ * bundle ID, which the verifier hashes and asserts equals the
51
+ * authData.rpIdHash field. Exposed here as a labeled constant so the
52
+ * audit trail is obvious.
53
+ */
54
+ export const APPLE_APPATTEST_FMT = "apple-appattest";
55
+ //# sourceMappingURL=apple-root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apple-root.js","sourceRoot":"","sources":["../src/apple-root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;CAcvC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC"}
package/dist/cbor.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Thin CBOR decoder for Apple's App Attest attestation object.
3
+ *
4
+ * Apple's `DCAppAttestService.attestKey` returns a CBOR-encoded
5
+ * attestation object with the W3C WebAuthn-compatible shape:
6
+ *
7
+ * {
8
+ * fmt: "apple-appattest",
9
+ * attStmt: { x5c: [leafDer, intermediateDer], receipt: <bytes> },
10
+ * authData: <bytes>
11
+ * }
12
+ *
13
+ * Delegating to `cbor2` lets us parse that without writing a full CBOR
14
+ * implementation. We expose a typed `parseAppAttestCbor` so the verifier
15
+ * never touches raw `unknown` shapes — every field is validated as it's
16
+ * lifted out.
17
+ */
18
+ export interface AppAttestCbor {
19
+ readonly fmt: string;
20
+ readonly x5c: readonly Uint8Array[];
21
+ readonly receipt: Uint8Array | null;
22
+ readonly authData: Uint8Array;
23
+ }
24
+ /**
25
+ * Parse a CBOR-encoded App Attest attestation object.
26
+ *
27
+ * Returns a typed view or throws on malformed / unexpected shape. The
28
+ * caller (`verify.ts`) catches the throw and converts to the
29
+ * `{ valid: false, errors: [...] }` result shape.
30
+ */
31
+ export declare function parseAppAttestCbor(attestationObjectBytes: Uint8Array): AppAttestCbor;
32
+ //# sourceMappingURL=cbor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbor.d.ts","sourceRoot":"","sources":["../src/cbor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,SAAS,UAAU,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,sBAAsB,EAAE,UAAU,GAAG,aAAa,CAkDpF"}
package/dist/cbor.js ADDED
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Thin CBOR decoder for Apple's App Attest attestation object.
3
+ *
4
+ * Apple's `DCAppAttestService.attestKey` returns a CBOR-encoded
5
+ * attestation object with the W3C WebAuthn-compatible shape:
6
+ *
7
+ * {
8
+ * fmt: "apple-appattest",
9
+ * attStmt: { x5c: [leafDer, intermediateDer], receipt: <bytes> },
10
+ * authData: <bytes>
11
+ * }
12
+ *
13
+ * Delegating to `cbor2` lets us parse that without writing a full CBOR
14
+ * implementation. We expose a typed `parseAppAttestCbor` so the verifier
15
+ * never touches raw `unknown` shapes — every field is validated as it's
16
+ * lifted out.
17
+ */
18
+ import { decode as cborDecode } from "cbor2";
19
+ /**
20
+ * Parse a CBOR-encoded App Attest attestation object.
21
+ *
22
+ * Returns a typed view or throws on malformed / unexpected shape. The
23
+ * caller (`verify.ts`) catches the throw and converts to the
24
+ * `{ valid: false, errors: [...] }` result shape.
25
+ */
26
+ export function parseAppAttestCbor(attestationObjectBytes) {
27
+ // cbor2's `decode` accepts ArrayBuffer-like; `Uint8Array` satisfies.
28
+ const decoded = cborDecode(attestationObjectBytes);
29
+ if (decoded === null || typeof decoded !== "object") {
30
+ throw new Error("attestation object is not a CBOR map");
31
+ }
32
+ // cbor2 returns JS `Map` for CBOR maps by default for non-string keys;
33
+ // but Apple's outer map uses string keys so we accept either `Map` or
34
+ // plain `Record`.
35
+ const getFromAny = (key) => {
36
+ if (decoded instanceof Map)
37
+ return decoded.get(key);
38
+ return decoded[key];
39
+ };
40
+ const fmt = getFromAny("fmt");
41
+ if (typeof fmt !== "string")
42
+ throw new Error("attestation `fmt` missing or not a string");
43
+ const attStmt = getFromAny("attStmt");
44
+ if (attStmt === null || typeof attStmt !== "object") {
45
+ throw new Error("attestation `attStmt` missing or not an object");
46
+ }
47
+ const attStmtGet = (key) => {
48
+ if (attStmt instanceof Map)
49
+ return attStmt.get(key);
50
+ return attStmt[key];
51
+ };
52
+ const x5cRaw = attStmtGet("x5c");
53
+ if (!Array.isArray(x5cRaw) || x5cRaw.length === 0) {
54
+ throw new Error("attestation `attStmt.x5c` missing or empty");
55
+ }
56
+ const x5c = [];
57
+ for (const entry of x5cRaw) {
58
+ const bytes = coerceBytes(entry);
59
+ if (!bytes)
60
+ throw new Error("attestation `attStmt.x5c` entry is not bytes");
61
+ x5c.push(bytes);
62
+ }
63
+ const receiptRaw = attStmtGet("receipt");
64
+ const receipt = receiptRaw === undefined ? null : coerceBytes(receiptRaw);
65
+ if (receiptRaw !== undefined && receipt === null) {
66
+ throw new Error("attestation `attStmt.receipt` present but not bytes");
67
+ }
68
+ const authDataRaw = getFromAny("authData");
69
+ const authData = coerceBytes(authDataRaw);
70
+ if (!authData)
71
+ throw new Error("attestation `authData` missing or not bytes");
72
+ return { fmt, x5c, receipt, authData };
73
+ }
74
+ /**
75
+ * cbor2 can surface byte strings as `Uint8Array` or, in some Node
76
+ * builds, as `Buffer` (which is also a Uint8Array subclass). This
77
+ * helper collapses both shapes into a plain `Uint8Array` copy the
78
+ * rest of the verifier operates on.
79
+ */
80
+ function coerceBytes(v) {
81
+ if (v instanceof Uint8Array) {
82
+ // Normalize to a detached copy — downstream crypto libs expect
83
+ // tight-bounded views and Buffer's offset+length can surprise them.
84
+ return new Uint8Array(v.buffer, v.byteOffset, v.byteLength).slice();
85
+ }
86
+ return null;
87
+ }
88
+ //# sourceMappingURL=cbor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbor.js","sourceRoot":"","sources":["../src/cbor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAS7C;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,sBAAkC;IACnE,qEAAqE;IACrE,MAAM,OAAO,GAAY,UAAU,CAAC,sBAAsB,CAAC,CAAC;IAE5D,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,uEAAuE;IACvE,sEAAsE;IACtE,kBAAkB;IAClB,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;QAC1C,IAAI,OAAO,YAAY,GAAG;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpD,OAAQ,OAAmC,CAAC,GAAG,CAAC,CAAC;IACnD,CAA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IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAE9E,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,CAAU;IAC7B,IAAI,CAAC,YAAY,UAAU,EAAE,CAAC;QAC5B,+DAA+D;QAC/D,oEAAoE;QACpE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @motebit/crypto-appattest — Apple App Attest chain-verification
3
+ * adapter for motebit hardware-attestation claims.
4
+ *
5
+ * The metabolic leaf `@motebit/crypto` delegates to when a
6
+ * `HardwareAttestationClaim` declares `platform: "device_check"`.
7
+ * Dep-thin `@motebit/crypto` stays permissive-floor-pure; this package,
8
+ * also on the permissive floor (Apache-2.0), metabolizes `@peculiar/x509`
9
+ * + `cbor2` to judge whether Apple's published CA rooted the leaf that
10
+ * signed the caller's attestation.
11
+ *
12
+ * Wiring from a consumer:
13
+ *
14
+ * ```ts
15
+ * import { verify } from "@motebit/crypto";
16
+ * import { deviceCheckVerifier } from "@motebit/crypto-appattest";
17
+ *
18
+ * const result = await verify(credential, {
19
+ * hardwareAttestation: { deviceCheck: deviceCheckVerifier({ expectedBundleId: "com.motebit.app" }) },
20
+ * });
21
+ * ```
22
+ *
23
+ * This package exports no global state, no side-effect registrations;
24
+ * the injection is call-site only.
25
+ */
26
+ import type { HardwareAttestationClaim } from "@motebit/protocol";
27
+ import type { AppAttestVerifyResult } from "./verify.js";
28
+ export { parseAppAttestCbor, type AppAttestCbor } from "./cbor.js";
29
+ export { APPLE_APPATTEST_ROOT_PEM, APPLE_APPATTEST_FMT } from "./apple-root.js";
30
+ export { verifyAppAttestReceipt } from "./verify.js";
31
+ export type { AppAttestVerifyOptions, AppAttestVerifyResult, AppAttestVerifyError, } from "./verify.js";
32
+ /**
33
+ * Shape the optional verifier injected into `@motebit/crypto`'s
34
+ * `HardwareAttestationVerifiers.deviceCheck` slot carries — mirrors the
35
+ * sync-or-async return shape the dispatcher supports.
36
+ */
37
+ export interface DeviceCheckVerifyResult {
38
+ readonly valid: boolean;
39
+ readonly platform: "device_check";
40
+ readonly errors: ReadonlyArray<{
41
+ readonly message: string;
42
+ }>;
43
+ readonly attestation_detail?: AppAttestVerifyResult;
44
+ }
45
+ /**
46
+ * Context fields the dispatcher lifts out of the credential subject and
47
+ * threads through to the verifier. All three participate in the JCS
48
+ * body the Swift mint path signs, so the verifier re-derives the body
49
+ * from them and byte-compares against the transmitted clientDataHash
50
+ * (see `verify.ts::buildCanonicalAttestationBody`).
51
+ *
52
+ * All fields optional: a caller that omits one loses the
53
+ * identity-binding channel but still gets chain / nonce / bundle
54
+ * binding results — the verifier reports the missing channel
55
+ * explicitly rather than silently passing.
56
+ */
57
+ export interface DeviceCheckVerifierContext {
58
+ readonly expectedMotebitId?: string;
59
+ readonly expectedDeviceId?: string;
60
+ readonly expectedAttestedAt?: number;
61
+ }
62
+ export interface DeviceCheckVerifierConfig {
63
+ /** iOS bundle identifier the receipt must bind to. */
64
+ readonly expectedBundleId: string;
65
+ /** Optional: override the pinned Apple root (tests fabricate their own). */
66
+ readonly rootPem?: string;
67
+ /** Optional: inject a fixed clock for deterministic chain-validity checks. */
68
+ readonly now?: () => number;
69
+ /** Optional: override the accepted attestation-format string. */
70
+ readonly expectedFmt?: string;
71
+ }
72
+ /**
73
+ * Factory — build a `deviceCheck` verifier bound to a specific bundle
74
+ * and (optionally) a test root / clock / fmt. The returned function
75
+ * matches the `HardwareAttestationVerifiers.deviceCheck` signature the
76
+ * `@motebit/crypto` dispatcher expects.
77
+ *
78
+ * Signature widened 2026-04-22: the third `context` parameter carries
79
+ * the motebit_id / device_id / attested_at fields the VC subject
80
+ * declares so the verifier can re-derive the JCS body Apple signed
81
+ * over and cryptographically bind it to the caller's Ed25519 identity
82
+ * (see `verify.ts` step 6). Pre-existing call sites that pass only
83
+ * `(claim, expectedIdentityHex)` still compile — the context is
84
+ * optional — but they lose the identity-binding channel and receive
85
+ * `identity_bound: false` in the result.
86
+ *
87
+ * Kept as a factory rather than a free function so the consumer's
88
+ * bundle ID is captured once at wiring time, not repeated at every
89
+ * call site — every subsequent `verify()` call inherits the same
90
+ * binding.
91
+ */
92
+ export declare function deviceCheckVerifier(config: DeviceCheckVerifierConfig): (claim: HardwareAttestationClaim, expectedIdentityHex: string, context?: DeviceCheckVerifierContext) => Promise<DeviceCheckVerifyResult>;
93
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAElE,OAAO,KAAK,EAA0B,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGjF,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH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