@hcs-witness/verify 0.0.0-stage → 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/CHANGELOG.md +36 -0
- package/LICENSE +202 -0
- package/README.md +147 -2
- package/bin/hcs-witness-verify.mjs +2 -0
- package/dist/anchor.d.ts +20 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +82 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +46 -0
- package/dist/binding.d.ts +22 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/binding.js +38 -0
- package/dist/check.d.ts +22 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +100 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +103 -0
- package/dist/hash.d.ts +3 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/jcs.d.ts +5 -0
- package/dist/jcs.d.ts.map +1 -0
- package/dist/jcs.js +60 -0
- package/dist/keyset.d.ts +30 -0
- package/dist/keyset.d.ts.map +1 -0
- package/dist/keyset.js +62 -0
- package/dist/merkle.d.ts +26 -0
- package/dist/merkle.d.ts.map +1 -0
- package/dist/merkle.js +120 -0
- package/dist/ots.d.ts +48 -0
- package/dist/ots.d.ts.map +1 -0
- package/dist/ots.js +386 -0
- package/dist/schema.d.ts +74 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +201 -0
- package/dist/verify.d.ts +12 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +145 -0
- package/package.json +71 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Toutes les modifications notables de ce projet sont consignées ici.
|
|
4
|
+
Le format suit [Keep a Changelog](https://keepachangelog.com/fr/1.1.0/)
|
|
5
|
+
et le projet respecte [Semantic Versioning](https://semver.org/lang/fr/).
|
|
6
|
+
|
|
7
|
+
## [1.0.0] - 2026-XX-XX
|
|
8
|
+
|
|
9
|
+
Première publication publique. Succède au paquet interne privé
|
|
10
|
+
`@gateguard/verify` (0.2.0) — même format de preuve, mêmes vérifications.
|
|
11
|
+
|
|
12
|
+
### Ajouté
|
|
13
|
+
|
|
14
|
+
- Vérification hors ligne de preuves HCS Witness v1 et v2 :
|
|
15
|
+
signatures ES256 (P-256, low-S) et ML-DSA-65 (contexte
|
|
16
|
+
`gateguard:proof:v1`), fenêtre de validité des clés, plafond
|
|
17
|
+
`signals`, horodatages cohérents.
|
|
18
|
+
- Vérification d'ancrage : inclusion Merkle RFC 6962 (DTR),
|
|
19
|
+
lecture des fichiers OpenTimestamps embarqués (attestation Bitcoin,
|
|
20
|
+
calendriers en attente) — aucun accès réseau.
|
|
21
|
+
- `checkActionBinding` : lie la preuve à l'action, au contexte (JCS)
|
|
22
|
+
et au texte affiché (NFC) avant exécution.
|
|
23
|
+
- CLI `hcs-witness-verify <proof.json> --keys <keys.json>
|
|
24
|
+
[--now <rfc3339>] [--json]`.
|
|
25
|
+
- Schémas JSON exportés (`proofSchema`, `unsignedProofSchema`,
|
|
26
|
+
`keysetSchema`) et gardes de type (`isProof`, `isUnsignedProof`,
|
|
27
|
+
`isKeyset`) — sans dépendance de validation.
|
|
28
|
+
|
|
29
|
+
### Sécurité / dépendances
|
|
30
|
+
|
|
31
|
+
- Dépendances d'exécution réduites à deux : `@noble/post-quantum` et
|
|
32
|
+
`canonicalize` (épinglées en version exacte).
|
|
33
|
+
- ES256 et SHA-256 passent par `node:crypto` ; le validateur TypeBox
|
|
34
|
+
interne est remplacé par un évaluateur JSON Schema dédié.
|
|
35
|
+
|
|
36
|
+
[1.0.0]: https://github.com/hcs-witness/verify/releases/tag/v1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 AI Solution
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,148 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hcs-witness/verify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Offline verification library and CLI for **HCS Witness** proofs —
|
|
4
|
+
vérificateur hors ligne des preuves HCS Witness.
|
|
5
|
+
|
|
6
|
+
A proof is a signed document attesting that a human approved (or
|
|
7
|
+
refused) a critical action. This package verifies such proofs **without
|
|
8
|
+
any network access**: signatures (ES256 + ML-DSA-65), key validity
|
|
9
|
+
windows, Merkle inclusion, and embedded OpenTimestamps anchors.
|
|
10
|
+
|
|
11
|
+
Runtime dependencies: two — `@noble/post-quantum` and `canonicalize`,
|
|
12
|
+
pinned to exact versions. ES256 and SHA-256 go through `node:crypto`.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --global @hcs-witness/verify # CLI
|
|
18
|
+
npm install @hcs-witness/verify # library
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires Node.js **≥ 22** — no Node-24-only API is used at runtime
|
|
22
|
+
(tested in CI on Node 22 and 24; releases are built on Node 24).
|
|
23
|
+
|
|
24
|
+
## Verify a proof (CLI)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
hcs-witness-verify <proof.json> --keys <keys.json> [--now <rfc3339>] [--json]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- `<proof.json>`: a proof document (`proofs/<proof_id>.json` in an audit
|
|
31
|
+
export, or `GET /v1/proofs/<id>` output).
|
|
32
|
+
- `--keys`: the public keyset (`keys.json` in an export, or
|
|
33
|
+
`/.well-known/hcs-keys.json` on the issuing service).
|
|
34
|
+
- `--now`: reference time for expiry checks (default: none).
|
|
35
|
+
- Exit code: `0` valid, `1` invalid, `2` usage error.
|
|
36
|
+
|
|
37
|
+
```console
|
|
38
|
+
$ hcs-witness-verify proofs/ggp_01JZ….json --keys keys.json
|
|
39
|
+
proof_id: ggp_01JZFXANCH0REDPR00FV2TEST9
|
|
40
|
+
status: VALID
|
|
41
|
+
presence: measured, not yet rated (challenge: numeric, synced passkey)
|
|
42
|
+
anchor: merkle inclusion OK
|
|
43
|
+
anchor: bitcoin block 915042 (attested by the .ots file)
|
|
44
|
+
note: block confirmation is to be done with a node or an explorer
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Library usage
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {
|
|
51
|
+
verifyProof,
|
|
52
|
+
verifyAnchor,
|
|
53
|
+
checkActionBinding,
|
|
54
|
+
} from "@hcs-witness/verify";
|
|
55
|
+
|
|
56
|
+
const result = verifyProof(proofJson, keysetJson, { now: new Date() });
|
|
57
|
+
// → { valid: boolean, errors: VerifyErrorCode[], proof_id? }
|
|
58
|
+
|
|
59
|
+
const anchor = verifyAnchor(proofJson);
|
|
60
|
+
// → { present, inclusion, otsMatchesRoot, bitcoinBlockHeight, pendingCalendars }
|
|
61
|
+
|
|
62
|
+
// Before executing the attested action — mandatory binding check:
|
|
63
|
+
const binding = checkActionBinding(proofJson, {
|
|
64
|
+
action: "armoury.firearm.release",
|
|
65
|
+
context, // same object sent with the approval request
|
|
66
|
+
displayText, // exact text shown to the human (NFC applied)
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The exported JSON Schemas (`proofSchema`, `unsignedProofSchema`,
|
|
71
|
+
`keysetSchema`) are plain JSON Schema documents — usable with any
|
|
72
|
+
validator (e.g. ajv) — and `isProof` / `isUnsignedProof` / `isKeyset`
|
|
73
|
+
are dependency-free type guards.
|
|
74
|
+
|
|
75
|
+
## Verify the package provenance
|
|
76
|
+
|
|
77
|
+
Every release is published from GitHub Actions via **npm trusted
|
|
78
|
+
publishing (OIDC)** with Sigstore provenance — no access token exists
|
|
79
|
+
anywhere.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm audit signatures # in a project that depends on @hcs-witness/verify
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The package page on [npmjs.com/package/@hcs-witness/verify](https://www.npmjs.com/package/@hcs-witness/verify)
|
|
86
|
+
shows the provenance badge linking back to the exact GitHub Actions run
|
|
87
|
+
and commit in [hcs-witness/verify](https://github.com/hcs-witness/verify).
|
|
88
|
+
|
|
89
|
+
## Verify a Bitcoin anchor
|
|
90
|
+
|
|
91
|
+
If the proof carries `anchor.ots` (base64 OpenTimestamps file attesting
|
|
92
|
+
the Merkle root), offline parsing is included; confirming the block on
|
|
93
|
+
the blockchain is done with the public OpenTimestamps tooling:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# save anchors/<batch_id>.ots from the audit export, then:
|
|
97
|
+
ots verify anchors/<batch_id>.ots
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`verifyAnchor` reports `bitcoinBlockHeight` when the .ots embeds a
|
|
101
|
+
Bitcoin attestation, and `pendingCalendars` when it is still awaiting
|
|
102
|
+
confirmation.
|
|
103
|
+
|
|
104
|
+
## Proof format and compatibility
|
|
105
|
+
|
|
106
|
+
- Format versions `v: 1` and `v: 2` (the `presence` block appeared in
|
|
107
|
+
v2) are supported. The package version is **independent** of the
|
|
108
|
+
proof-format version.
|
|
109
|
+
- A new verifier release always keeps verifying all previously
|
|
110
|
+
published format versions; dropping a format version requires a
|
|
111
|
+
major release announced ≥ 12 months in advance.
|
|
112
|
+
- The ML-DSA context string `gateguard:proof:v1` and the JCS (RFC 8785)
|
|
113
|
+
canonicalization are part of the signed format — they are immutable
|
|
114
|
+
and retained verbatim for compatibility.
|
|
115
|
+
- The `presence` block is signed but **never** used for cryptographic
|
|
116
|
+
validity; it is reported for information only.
|
|
117
|
+
|
|
118
|
+
## Security
|
|
119
|
+
|
|
120
|
+
Vulnerability reports: **contact@ia-solution.fr** — see
|
|
121
|
+
[SECURITY.md](SECURITY.md). This package performs **zero network
|
|
122
|
+
access**: any network I/O is a security defect.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Français
|
|
127
|
+
|
|
128
|
+
`@hcs-witness/verify` nécessite Node.js **≥ 22** et vérifie hors ligne les preuves HCS Witness :
|
|
129
|
+
signatures ES256 (P-256, low-S) et ML-DSA-65, fenêtre de validité des
|
|
130
|
+
clés, inclusion Merkle et ancrage OpenTimestamps — **sans aucun accès
|
|
131
|
+
réseau**.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm install --global @hcs-witness/verify
|
|
135
|
+
hcs-witness-verify proofs/<proof_id>.json --keys keys.json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- Codes de sortie : `0` valide, `1` invalide, `2` erreur d'usage.
|
|
139
|
+
- Provenance : `npm audit signatures` + badge de provenance sur la page
|
|
140
|
+
npm ; publication par trusted publishing OIDC depuis GitHub Actions,
|
|
141
|
+
sans aucun jeton.
|
|
142
|
+
- Ancrage Bitcoin : `verifyAnchor` vérifie l'inclusion Merkle et lit le
|
|
143
|
+
fichier `.ots` embarqué ; la confirmation du bloc se fait avec les
|
|
144
|
+
outils publics OpenTimestamps (`ots verify anchors/<batch_id>.ots`).
|
|
145
|
+
- Compatibilité : les formats `v:1` et `v:2` restent vérifiables ; le
|
|
146
|
+
contexte signé `gateguard:proof:v1` et la canonicalisation JCS sont
|
|
147
|
+
immuables.
|
|
148
|
+
- Sécurité : signalement à **contact@ia-solution.fr** (cf. SECURITY.md).
|
package/dist/anchor.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface AnchorResult {
|
|
2
|
+
/** La preuve porte un champ anchor bien formé. */
|
|
3
|
+
readonly present: boolean;
|
|
4
|
+
/** Inclusion Merkle feuille → racine vérifiée hors ligne. */
|
|
5
|
+
readonly inclusion: boolean;
|
|
6
|
+
/** Le fichier .ots atteste bien la racine Merkle. */
|
|
7
|
+
readonly otsMatchesRoot: boolean | undefined;
|
|
8
|
+
/** Hauteur de bloc attestée par l'attestation Bitcoin du .ots. */
|
|
9
|
+
readonly bitcoinBlockHeight: number | undefined;
|
|
10
|
+
/** URIs des calendriers en attestation « pending ». */
|
|
11
|
+
readonly pendingCalendars: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Vérifie hors ligne l'ancrage d'une preuve : inclusion Merkle de la
|
|
15
|
+
* feuille (SHA-256(0x00‖SHA-256(signedPayload))) vers merkle_root, puis
|
|
16
|
+
* lecture du fichier .ots embarqué : sa racine attestée doit égaler
|
|
17
|
+
* merkle_root ; la hauteur de bloc en est extraite. Aucun réseau.
|
|
18
|
+
*/
|
|
19
|
+
export declare function verifyAnchor(proof: unknown): AnchorResult;
|
|
20
|
+
//# sourceMappingURL=anchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../src/anchor.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,qDAAqD;IACrD,QAAQ,CAAC,cAAc,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7C,kEAAkE;IAClE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,uDAAuD;IACvD,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAoBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CA2DzD"}
|
package/dist/anchor.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { merkleLeafHash, verifyMerkleInclusion } from "./merkle.js";
|
|
2
|
+
import { allAttestations, bitcoinBlockHeight, parseOtsFile } from "./ots.js";
|
|
3
|
+
import { isProof, signedPayload } from "./schema.js";
|
|
4
|
+
function b64ToBytes(b64) {
|
|
5
|
+
try {
|
|
6
|
+
return Uint8Array.from(Buffer.from(b64, "base64"));
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function hexToBytes(hex) {
|
|
13
|
+
return Uint8Array.from(hex.match(/../g) ?? [], (pair) => Number.parseInt(pair, 16));
|
|
14
|
+
}
|
|
15
|
+
function bytesEq(a, b) {
|
|
16
|
+
return a.length === b.length && a.every((x, i) => x === b.at(i));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Vérifie hors ligne l'ancrage d'une preuve : inclusion Merkle de la
|
|
20
|
+
* feuille (SHA-256(0x00‖SHA-256(signedPayload))) vers merkle_root, puis
|
|
21
|
+
* lecture du fichier .ots embarqué : sa racine attestée doit égaler
|
|
22
|
+
* merkle_root ; la hauteur de bloc en est extraite. Aucun réseau.
|
|
23
|
+
*/
|
|
24
|
+
export function verifyAnchor(proof) {
|
|
25
|
+
const empty = {
|
|
26
|
+
present: false,
|
|
27
|
+
inclusion: false,
|
|
28
|
+
otsMatchesRoot: undefined,
|
|
29
|
+
bitcoinBlockHeight: undefined,
|
|
30
|
+
pendingCalendars: [],
|
|
31
|
+
};
|
|
32
|
+
if (!isProof(proof)) {
|
|
33
|
+
return empty;
|
|
34
|
+
}
|
|
35
|
+
const p = proof;
|
|
36
|
+
const anchor = p.anchor;
|
|
37
|
+
if (anchor === undefined) {
|
|
38
|
+
return empty;
|
|
39
|
+
}
|
|
40
|
+
const root = hexToBytes(anchor.merkle_root);
|
|
41
|
+
const leaf = merkleLeafHash(signedPayload(p));
|
|
42
|
+
const path = anchor.path.map(hexToBytes);
|
|
43
|
+
// leaf_count n'est pas dans la preuve : on le recherche. Un chemin de
|
|
44
|
+
// longueur L ne peut couvrir qu'un lot dont la taille est dans
|
|
45
|
+
// ]index, index + 2^L] ; la vérification n'aboutit que pour la vraie.
|
|
46
|
+
let inclusion = false;
|
|
47
|
+
const maxCount = anchor.leaf_index + 2 ** path.length;
|
|
48
|
+
for (let count = anchor.leaf_index + 1; count <= maxCount; count += 1) {
|
|
49
|
+
if (verifyMerkleInclusion(leaf, anchor.leaf_index, count, path, root)) {
|
|
50
|
+
inclusion = true;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let otsMatchesRoot;
|
|
55
|
+
let height;
|
|
56
|
+
const pending = [];
|
|
57
|
+
if (anchor.ots !== undefined) {
|
|
58
|
+
const bytes = b64ToBytes(anchor.ots);
|
|
59
|
+
try {
|
|
60
|
+
if (bytes === undefined)
|
|
61
|
+
throw new Error("bad base64");
|
|
62
|
+
const ots = parseOtsFile(bytes);
|
|
63
|
+
otsMatchesRoot = bytesEq(ots.fileDigest, root);
|
|
64
|
+
height = bitcoinBlockHeight(ots.timestamp);
|
|
65
|
+
for (const { attestation } of allAttestations(ots.timestamp)) {
|
|
66
|
+
if (attestation.kind === "pending" && attestation.uri !== undefined) {
|
|
67
|
+
pending.push(attestation.uri);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
otsMatchesRoot = false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
present: true,
|
|
77
|
+
inclusion,
|
|
78
|
+
otsMatchesRoot,
|
|
79
|
+
bitcoinBlockHeight: height,
|
|
80
|
+
pendingCalendars: pending,
|
|
81
|
+
};
|
|
82
|
+
}
|
package/dist/base64.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAOA,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBvD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CA0B9D"}
|
package/dist/base64.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
2
|
+
function rev(ch) {
|
|
3
|
+
// Callers guarantee input matches /^[A-Za-z0-9_-]*$/ first.
|
|
4
|
+
return B64.indexOf(ch);
|
|
5
|
+
}
|
|
6
|
+
export function bytesToB64url(bytes) {
|
|
7
|
+
let out = "";
|
|
8
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
9
|
+
const b0 = bytes.at(i) ?? 0;
|
|
10
|
+
const has1 = i + 1 < bytes.length;
|
|
11
|
+
const has2 = i + 2 < bytes.length;
|
|
12
|
+
const b1 = bytes.at(i + 1) ?? 0;
|
|
13
|
+
const b2 = bytes.at(i + 2) ?? 0;
|
|
14
|
+
out += B64.charAt(b0 >> 2);
|
|
15
|
+
out += B64.charAt(((b0 & 3) << 4) | (b1 >> 4));
|
|
16
|
+
if (has1) {
|
|
17
|
+
out += B64.charAt(((b1 & 0x0f) << 2) | (b2 >> 6));
|
|
18
|
+
}
|
|
19
|
+
if (has2) {
|
|
20
|
+
out += B64.charAt(b2 & 0x3f);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
export function b64urlToBytes(input) {
|
|
26
|
+
if (input.length % 4 === 1 || !/^[A-Za-z0-9_-]*$/.test(input)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const quad = (a, b, c, d) => (rev(a) << 18) | (rev(b) << 12) | (rev(c) << 6) | rev(d);
|
|
30
|
+
const bytes = [];
|
|
31
|
+
const fullGroups = Math.floor(input.length / 4);
|
|
32
|
+
for (let i = 0; i < fullGroups; i += 1) {
|
|
33
|
+
const n = quad(input.charAt(i * 4), input.charAt(i * 4 + 1), input.charAt(i * 4 + 2), input.charAt(i * 4 + 3));
|
|
34
|
+
bytes.push((n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff);
|
|
35
|
+
}
|
|
36
|
+
const tail = input.slice(fullGroups * 4);
|
|
37
|
+
if (tail.length === 2) {
|
|
38
|
+
const n = quad(tail.charAt(0), tail.charAt(1), "A", "A");
|
|
39
|
+
bytes.push((n >> 16) & 0xff);
|
|
40
|
+
}
|
|
41
|
+
else if (tail.length === 3) {
|
|
42
|
+
const n = quad(tail.charAt(0), tail.charAt(1), tail.charAt(2), "A");
|
|
43
|
+
bytes.push((n >> 16) & 0xff, (n >> 8) & 0xff);
|
|
44
|
+
}
|
|
45
|
+
return Uint8Array.from(bytes);
|
|
46
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type BindingErrorCode = "SCHEMA_INVALID" | "ACTION_MISMATCH" | "CONTEXT_MISMATCH" | "DISPLAY_MISMATCH";
|
|
2
|
+
export interface BindingCheck {
|
|
3
|
+
/** Action about to be executed, e.g. "armoury.firearm.release". */
|
|
4
|
+
readonly action: string;
|
|
5
|
+
/** Same context object that was sent with the approval request. */
|
|
6
|
+
readonly context: Record<string, unknown>;
|
|
7
|
+
/** Exact text the human was shown (NFC normalization applied). */
|
|
8
|
+
readonly displayText: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BindingResult {
|
|
11
|
+
readonly valid: boolean;
|
|
12
|
+
readonly errors: readonly BindingErrorCode[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Binds the proof to what is about to be executed: the caller MUST run
|
|
16
|
+
* this check right before performing the action, with the action, the
|
|
17
|
+
* context and the exact display text. It closes the loop between what
|
|
18
|
+
* the human saw on the approval page and what the system executes —
|
|
19
|
+
* a mismatch means the proof was issued for something else.
|
|
20
|
+
*/
|
|
21
|
+
export declare function checkActionBinding(proof: unknown, expected: BindingCheck): BindingResult;
|
|
22
|
+
//# sourceMappingURL=binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,CAAC;AAEvB,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,kEAAkE;IAClE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAC9C;AAMD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,YAAY,GACrB,aAAa,CA6Bf"}
|
package/dist/binding.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { sha256 } from "./hash.js";
|
|
2
|
+
import { canonicalBytes } from "./jcs.js";
|
|
3
|
+
import { isProof } from "./schema.js";
|
|
4
|
+
function hex(bytes) {
|
|
5
|
+
return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Binds the proof to what is about to be executed: the caller MUST run
|
|
9
|
+
* this check right before performing the action, with the action, the
|
|
10
|
+
* context and the exact display text. It closes the loop between what
|
|
11
|
+
* the human saw on the approval page and what the system executes —
|
|
12
|
+
* a mismatch means the proof was issued for something else.
|
|
13
|
+
*/
|
|
14
|
+
export function checkActionBinding(proof, expected) {
|
|
15
|
+
if (!isProof(proof)) {
|
|
16
|
+
return { valid: false, errors: ["SCHEMA_INVALID"] };
|
|
17
|
+
}
|
|
18
|
+
const p = proof;
|
|
19
|
+
const errors = [];
|
|
20
|
+
if (p.action !== expected.action) {
|
|
21
|
+
errors.push("ACTION_MISMATCH");
|
|
22
|
+
}
|
|
23
|
+
let contextHex;
|
|
24
|
+
try {
|
|
25
|
+
contextHex = hex(sha256(canonicalBytes(expected.context)));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
contextHex = "";
|
|
29
|
+
}
|
|
30
|
+
if (contextHex !== p.context_sha256) {
|
|
31
|
+
errors.push("CONTEXT_MISMATCH");
|
|
32
|
+
}
|
|
33
|
+
const displayHex = hex(sha256(new TextEncoder().encode(expected.displayText.normalize("NFC"))));
|
|
34
|
+
if (displayHex !== p.display_sha256) {
|
|
35
|
+
errors.push("DISPLAY_MISMATCH");
|
|
36
|
+
}
|
|
37
|
+
return { valid: errors.length === 0, errors };
|
|
38
|
+
}
|
package/dist/check.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Évaluateur JSON Schema minimal : couvre exactement les constructions
|
|
3
|
+
* des schémas exportés (type, const, anyOf, properties, required,
|
|
4
|
+
* additionalProperties, patternProperties, items, pattern, minLength,
|
|
5
|
+
* minimum). Ce n'est PAS un moteur JSON Schema général — les schémas
|
|
6
|
+
* sont fixes et internes au format de preuve HCS Witness.
|
|
7
|
+
*/
|
|
8
|
+
export interface JsonSchema {
|
|
9
|
+
readonly type?: string;
|
|
10
|
+
readonly const?: unknown;
|
|
11
|
+
readonly anyOf?: readonly JsonSchema[];
|
|
12
|
+
readonly properties?: Record<string, JsonSchema>;
|
|
13
|
+
readonly required?: readonly string[];
|
|
14
|
+
readonly additionalProperties?: boolean;
|
|
15
|
+
readonly patternProperties?: Record<string, JsonSchema>;
|
|
16
|
+
readonly items?: JsonSchema;
|
|
17
|
+
readonly pattern?: string;
|
|
18
|
+
readonly minLength?: number;
|
|
19
|
+
readonly minimum?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function checkSchema(schema: JsonSchema, value: unknown): boolean;
|
|
22
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IACxC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxD,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAsCD,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CA8DvE"}
|