@motebit/crypto-tpm 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,49 @@
1
+ # @motebit/crypto-tpm
2
+
3
+ Offline Apache-2.0 verifier for TPM 2.0 Endorsement-Key hardware-attestation credentials.
4
+
5
+ ```bash
6
+ npm i @motebit/crypto-tpm
7
+ ```
8
+
9
+ Plugs into [`@motebit/crypto`](https://www.npmjs.com/package/@motebit/crypto)'s `HardwareAttestationVerifiers` dispatcher as the `tpm` verifier — called when a credential declares `platform: "tpm"` (Windows 11 hosts, Linux-on-x86 with `/dev/tpm0`, Mac-with-T2 exposing a TPM interface).
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { verify } from "@motebit/crypto";
15
+ import { tpmVerifier } from "@motebit/crypto-tpm";
16
+
17
+ const result = await verify(credential, {
18
+ hardwareAttestation: { tpm: tpmVerifier() },
19
+ });
20
+ ```
21
+
22
+ ## What it verifies
23
+
24
+ 1. The TPM-marshaled `TPMS_ATTEST` structure (magic `0xff544347`, type `TPM_ST_ATTEST_QUOTE = 0x8018`, qualified_signer, extraData, clock_info, firmware_version, attested quote body) — hand-rolled binary parser in `src/tpm-parse.ts`.
25
+ 2. The TPM Attestation Key signature over `SHA-256(TPMS_ATTEST)`.
26
+ 3. The AK certificate chain against the **pinned vendor EK roots** — Infineon, Nuvoton, STMicroelectronics, Intel PTT. Every non-leaf must carry `basicConstraints.cA === true`, terminal cert DER byte-equal to one of the pinned roots.
27
+ 4. **Identity binding.** The quote's `extraData` must byte-equal `SHA-256(canonicalJson({ attested_at, device_id, identity_public_key, motebit_id, platform: "tpm", version: "1" }))` — the same body the desktop mint path composes. A malicious client that substitutes any other body fails here.
28
+
29
+ ## Why pinned
30
+
31
+ A verifier that dynamically fetched vendor CAs has no sovereign story. The pinned vendor roots are the self-attesting contract — third parties audit `DEFAULT_PINNED_TPM_ROOTS` and know which EK CAs this library accepts. Adding a vendor is additive (one PEM constant + one accept-set entry), not a policy rewrite.
32
+
33
+ ## Why a hand-rolled parser
34
+
35
+ TPM 2.0's `TPMS_ATTEST` structure is ~100 lines of big-endian length-prefixed marshaling. Pulling a full TPM library for that would cross a larger surface area than the struct we actually parse. Scoped to exactly what verification needs.
36
+
37
+ ## Related
38
+
39
+ - [`@motebit/crypto`](https://www.npmjs.com/package/@motebit/crypto) — dispatcher (pure permissive-floor; zero deps)
40
+ - [`@motebit/crypto-appattest`](https://www.npmjs.com/package/@motebit/crypto-appattest) — iOS sibling
41
+ - [`@motebit/crypto-play-integrity`](https://www.npmjs.com/package/@motebit/crypto-play-integrity) — Android sibling
42
+ - [`@motebit/crypto-webauthn`](https://www.npmjs.com/package/@motebit/crypto-webauthn) — browser sibling
43
+ - [`@motebit/verify`](https://www.npmjs.com/package/@motebit/verify) — canonical CLI bundling all four leaves with motebit defaults
44
+
45
+ ## License
46
+
47
+ Apache-2.0 — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
48
+
49
+ "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,94 @@
1
+ /**
2
+ * @motebit/crypto-tpm — TPM 2.0 quote chain-verification adapter for
3
+ * motebit hardware-attestation claims.
4
+ *
5
+ * The metabolic leaf `@motebit/crypto` delegates to when a
6
+ * `HardwareAttestationClaim` declares `platform: "tpm"`. Dep-thin
7
+ * `@motebit/crypto` stays permissive-floor-pure; this package, also on
8
+ * the permissive floor (Apache-2.0), metabolizes `@peculiar/x509` plus
9
+ * a minimal hand-rolled TPM parser to judge whether a vendor-published
10
+ * Endorsement-Key CA rooted the Attestation Key that signed the caller's
11
+ * TPM2_Quote.
12
+ *
13
+ * Wiring from a consumer:
14
+ *
15
+ * ```ts
16
+ * import { verify } from "@motebit/crypto";
17
+ * import { tpmVerifier } from "@motebit/crypto-tpm";
18
+ *
19
+ * const result = await verify(credential, {
20
+ * hardwareAttestation: { tpm: tpmVerifier() },
21
+ * });
22
+ * ```
23
+ *
24
+ * This package exports no global state, no side-effect registrations;
25
+ * the injection is call-site only. Pinned vendor roots live in
26
+ * `./tpm-roots.ts` and are the self-attesting audit surface.
27
+ */
28
+ import type { HardwareAttestationClaim } from "@motebit/protocol";
29
+ import type { TpmVerifyResult } from "./verify.js";
30
+ export { verifyTpmQuote } from "./verify.js";
31
+ export type { TpmVerifyOptions, TpmVerifyResult, TpmVerifyError } from "./verify.js";
32
+ export { parseTpmsAttest, composeTpmsAttestForTest, TPM_GENERATED_VALUE, TPM_ST_ATTEST_QUOTE, type TpmsAttest, } from "./tpm-parse.js";
33
+ export { DEFAULT_PINNED_TPM_ROOTS, INFINEON_TPM_EK_ROOT_PEM, NUVOTON_TPM_EK_ROOT_PEM, STMICRO_TPM_EK_ROOT_PEM, INTEL_PTT_EK_ROOT_PEM, TPM_PLATFORM, } from "./tpm-roots.js";
34
+ /**
35
+ * Shape the optional verifier injected into `@motebit/crypto`'s
36
+ * `HardwareAttestationVerifiers.tpm` slot carries — mirrors the
37
+ * sync-or-async return shape the dispatcher supports.
38
+ */
39
+ export interface TpmVerifierResult {
40
+ readonly valid: boolean;
41
+ readonly platform: "tpm";
42
+ readonly errors: ReadonlyArray<{
43
+ readonly message: string;
44
+ }>;
45
+ readonly attestation_detail?: TpmVerifyResult;
46
+ }
47
+ /**
48
+ * VC-subject fields that participate in the JCS body the TPM's
49
+ * extraData binds. motebit_id / device_id / attested_at participate
50
+ * alongside identity_public_key; without them the verifier cannot tie
51
+ * the quote to the caller's Ed25519 identity.
52
+ *
53
+ * All fields optional: a caller that omits one loses the
54
+ * identity-binding channel but still gets chain / signature / shape
55
+ * results — the verifier reports the missing channel explicitly
56
+ * rather than silently passing.
57
+ *
58
+ * The canonical path threads these per-credential through the
59
+ * `@motebit/crypto::verify` dispatcher: the dispatcher lifts them from
60
+ * `credentialSubject` and passes them as the third argument to the
61
+ * `tpm` verifier slot. Consumers wiring `tpmVerifier()` into
62
+ * `hardwareAttestation.tpm` get identity binding for free. An
63
+ * alternative path — baking a context into the factory via
64
+ * `TpmVerifierConfig.context` — is retained for direct callers and
65
+ * tests; the dispatcher-supplied context wins when both are present.
66
+ */
67
+ export interface TpmVerifierContext {
68
+ readonly expectedMotebitId?: string;
69
+ readonly expectedDeviceId?: string;
70
+ readonly expectedAttestedAt?: number;
71
+ }
72
+ export interface TpmVerifierConfig {
73
+ /** Optional: override the pinned vendor roots (tests fabricate their own). */
74
+ readonly rootPems?: readonly string[];
75
+ /** Optional: inject a fixed clock for deterministic chain-validity checks. */
76
+ readonly now?: () => number;
77
+ /**
78
+ * Optional: VC-subject context pre-baked at wiring time. See
79
+ * `TpmVerifierContext`. Useful for direct callers of the returned
80
+ * function that skip the `@motebit/crypto::verify` dispatcher. When
81
+ * the dispatcher passes a per-credential context, its fields take
82
+ * precedence over the pre-baked ones — per-credential always wins.
83
+ */
84
+ readonly context?: TpmVerifierContext;
85
+ }
86
+ /**
87
+ * Factory — build a `tpm` verifier bound to an optional test-root /
88
+ * clock / context override. The returned function matches the
89
+ * `HardwareAttestationVerifiers.tpm` three-arg signature the
90
+ * `@motebit/crypto` dispatcher calls — `(claim, expectedIdentityHex,
91
+ * context?)`.
92
+ */
93
+ export declare function tpmVerifier(config?: TpmVerifierConfig): (claim: HardwareAttestationClaim, expectedIdentityHex: string, context?: TpmVerifierContext) => Promise<TpmVerifierResult>;
94
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAGlE,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,QAAQ,CAAC,kBAAkB,CAAC,EAAE,eAAe,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC;CACvC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,MAAM,CAAC,EAAE,iBAAiB,GACzB,CACD,KAAK,EAAE,wBAAwB,EAC/B,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE,kBAAkB,KACzB,OAAO,CAAC,iBAAiB,CAAC,CAwB9B"}
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @motebit/crypto-tpm — TPM 2.0 quote chain-verification adapter for
3
+ * motebit hardware-attestation claims.
4
+ *
5
+ * The metabolic leaf `@motebit/crypto` delegates to when a
6
+ * `HardwareAttestationClaim` declares `platform: "tpm"`. Dep-thin
7
+ * `@motebit/crypto` stays permissive-floor-pure; this package, also on
8
+ * the permissive floor (Apache-2.0), metabolizes `@peculiar/x509` plus
9
+ * a minimal hand-rolled TPM parser to judge whether a vendor-published
10
+ * Endorsement-Key CA rooted the Attestation Key that signed the caller's
11
+ * TPM2_Quote.
12
+ *
13
+ * Wiring from a consumer:
14
+ *
15
+ * ```ts
16
+ * import { verify } from "@motebit/crypto";
17
+ * import { tpmVerifier } from "@motebit/crypto-tpm";
18
+ *
19
+ * const result = await verify(credential, {
20
+ * hardwareAttestation: { tpm: tpmVerifier() },
21
+ * });
22
+ * ```
23
+ *
24
+ * This package exports no global state, no side-effect registrations;
25
+ * the injection is call-site only. Pinned vendor roots live in
26
+ * `./tpm-roots.ts` and are the self-attesting audit surface.
27
+ */
28
+ import { verifyTpmQuote } from "./verify.js";
29
+ export { verifyTpmQuote } from "./verify.js";
30
+ export { parseTpmsAttest, composeTpmsAttestForTest, TPM_GENERATED_VALUE, TPM_ST_ATTEST_QUOTE, } from "./tpm-parse.js";
31
+ export { DEFAULT_PINNED_TPM_ROOTS, INFINEON_TPM_EK_ROOT_PEM, NUVOTON_TPM_EK_ROOT_PEM, STMICRO_TPM_EK_ROOT_PEM, INTEL_PTT_EK_ROOT_PEM, TPM_PLATFORM, } from "./tpm-roots.js";
32
+ /**
33
+ * Factory — build a `tpm` verifier bound to an optional test-root /
34
+ * clock / context override. The returned function matches the
35
+ * `HardwareAttestationVerifiers.tpm` three-arg signature the
36
+ * `@motebit/crypto` dispatcher calls — `(claim, expectedIdentityHex,
37
+ * context?)`.
38
+ */
39
+ export function tpmVerifier(config) {
40
+ return async (claim, expectedIdentityHex, context) => {
41
+ // Per-call context (from the dispatcher) wins over factory-time
42
+ // context. Either can be omitted; the verifier reports the missing
43
+ // fields in `errors` rather than passing silently.
44
+ const motebitId = context?.expectedMotebitId ?? config?.context?.expectedMotebitId;
45
+ const deviceId = context?.expectedDeviceId ?? config?.context?.expectedDeviceId;
46
+ const attestedAt = context?.expectedAttestedAt ?? config?.context?.expectedAttestedAt;
47
+ const opts = {
48
+ expectedIdentityPublicKeyHex: expectedIdentityHex,
49
+ ...(config?.rootPems !== undefined ? { rootPems: config.rootPems } : {}),
50
+ ...(config?.now !== undefined ? { now: config.now } : {}),
51
+ ...(motebitId !== undefined ? { expectedMotebitId: motebitId } : {}),
52
+ ...(deviceId !== undefined ? { expectedDeviceId: deviceId } : {}),
53
+ ...(attestedAt !== undefined ? { expectedAttestedAt: attestedAt } : {}),
54
+ };
55
+ const detail = await verifyTpmQuote(claim, opts);
56
+ return {
57
+ valid: detail.valid,
58
+ platform: "tpm",
59
+ errors: detail.errors,
60
+ attestation_detail: detail,
61
+ };
62
+ };
63
+ }
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAC;AAuDxB;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,MAA0B;IAM1B,OAAO,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,EAAE;QACnD,gEAAgE;QAChE,mEAAmE;QACnE,mDAAmD;QACnD,MAAM,SAAS,GAAG,OAAO,EAAE,iBAAiB,IAAI,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC;QACnF,MAAM,QAAQ,GAAG,OAAO,EAAE,gBAAgB,IAAI,MAAM,EAAE,OAAO,EAAE,gBAAgB,CAAC;QAChF,MAAM,UAAU,GAAG,OAAO,EAAE,kBAAkB,IAAI,MAAM,EAAE,OAAO,EAAE,kBAAkB,CAAC;QACtF,MAAM,IAAI,GAAqB;YAC7B,4BAA4B,EAAE,mBAAmB;YACjD,GAAG,CAAC,MAAM,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxE,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzD,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjE,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxE,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACjD,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,kBAAkB,EAAE,MAAM;SAC3B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Minimal TPM 2.0 binary-format parser.
3
+ *
4
+ * The TPM marshals structured data as big-endian size-prefixed bytes —
5
+ * distinct from CBOR / DER / JSON and wholly specific to the TCG's TPM
6
+ * Structures specification. Verification of a TPM quote requires
7
+ * extracting exactly three fields from the `TPMS_ATTEST` structure:
8
+ *
9
+ * - `magic` — 4-byte constant, must equal `TPM_GENERATED_VALUE`.
10
+ * - `type` — 2-byte constant, `TPM_ST_ATTEST_QUOTE` for quotes.
11
+ * - `qualifiedSigner` — length-prefixed `TPM2B_NAME`, identifies the AK.
12
+ * - `extraData` — length-prefixed `TPM2B_DATA`, this is where
13
+ * motebit threads the identity binding.
14
+ *
15
+ * We deliberately skip the remainder (clockInfo, firmwareVersion, the
16
+ * attested quote body containing PCR digests) — motebit's claim is
17
+ * about identity binding, not platform-state attestation. The body's
18
+ * signature (produced by TPM2_Quote using the AK) covers the entire
19
+ * serialized `TPMS_ATTEST`; any byte drift would invalidate it.
20
+ *
21
+ * Hand-rolled over `node-tpm2-pts`: the parser is ~80 LOC and covers
22
+ * exactly our needs. Pulling a dep for that would cross a larger
23
+ * attack surface than the struct we parse.
24
+ *
25
+ * References:
26
+ * - TCG TPM 2.0 Library, Part 2: Structures — §10.12 `TPMS_ATTEST`.
27
+ * - TCG TPM 2.0 Library, Part 1: Architecture — §36.1 `TPM2B_*` types.
28
+ */
29
+ /** Constant magic value every TPM-signed attest carries. */
30
+ export declare const TPM_GENERATED_VALUE = 4283712327;
31
+ /** `TPM_ST_ATTEST_QUOTE` — the structure-tag identifying a quote attestation. */
32
+ export declare const TPM_ST_ATTEST_QUOTE = 32792;
33
+ /**
34
+ * Parsed view of a `TPMS_ATTEST` structure's header + identity-binding
35
+ * fields. Callers verify signature bytes against the full structure;
36
+ * this view exposes only the fields participating in motebit's
37
+ * verification rules.
38
+ */
39
+ export interface TpmsAttest {
40
+ /** Must equal `TPM_GENERATED_VALUE` (`0xff544347`). */
41
+ readonly magic: number;
42
+ /** Structure tag, e.g. `TPM_ST_ATTEST_QUOTE`. */
43
+ readonly type: number;
44
+ /** Qualified signer name — `TPM2B_NAME` bytes (hash-alg + digest). */
45
+ readonly qualifiedSigner: Uint8Array;
46
+ /** Caller-supplied extra-data — `TPM2B_DATA` bytes. Identity binding lives here. */
47
+ readonly extraData: Uint8Array;
48
+ /** The rest of the serialized body, kept so callers can re-verify the signature. */
49
+ readonly trailer: Uint8Array;
50
+ }
51
+ /**
52
+ * Parse a TPM 2.0 `TPMS_ATTEST` structure. Throws on malformed input;
53
+ * the outer `verify.ts` catches and converts to the fail-closed result
54
+ * shape.
55
+ *
56
+ * Wire layout:
57
+ * uint32 magic ; 4 bytes
58
+ * uint16 type ; 2 bytes
59
+ * TPM2B_NAME qualifiedSigner ; uint16 size || bytes
60
+ * TPM2B_DATA extraData ; uint16 size || bytes
61
+ * TPMS_CLOCK_INFO clockInfo ; 17 bytes (fixed)
62
+ * uint64 firmwareVersion ; 8 bytes
63
+ * TPMU_ATTEST attested ; variable, tag-specific
64
+ *
65
+ * We extract magic / type / qualifiedSigner / extraData and stash the
66
+ * rest in `trailer` so the caller can reconstruct the full signed
67
+ * bytes when verifying the AK signature. The caller retains the
68
+ * original buffer; this view points into it via length-accurate
69
+ * subarray copies.
70
+ */
71
+ export declare function parseTpmsAttest(bytes: Uint8Array): TpmsAttest;
72
+ /**
73
+ * Build a minimal `TPMS_ATTEST` byte sequence for tests.
74
+ *
75
+ * Tests fabricate a valid-shape attest so the verifier's parsing +
76
+ * extraData-binding code paths exercise without a real TPM. Production
77
+ * minting lives in the Rust bridge — never call `composeTpmsAttest`
78
+ * outside `__tests__/` or you'll drift from what a real TPM would sign.
79
+ *
80
+ * `trailer` defaults to a deterministic 17-byte clockInfo + 8-byte
81
+ * firmwareVersion filler + 4-byte quote filler so the resulting bytes
82
+ * pass the minimum-length check during parsing; tests that need the
83
+ * real trailing fields can override.
84
+ */
85
+ export declare function composeTpmsAttestForTest(input: {
86
+ readonly magic?: number;
87
+ readonly type?: number;
88
+ readonly qualifiedSigner: Uint8Array;
89
+ readonly extraData: Uint8Array;
90
+ readonly trailer?: Uint8Array;
91
+ }): Uint8Array;
92
+ //# sourceMappingURL=tpm-parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tpm-parse.d.ts","sourceRoot":"","sources":["../src/tpm-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,4DAA4D;AAC5D,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAE9C,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IACrC,oFAAoF;IACpF,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAe7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;CAC/B,GAAG,UAAU,CAYb"}