@keri-ts/verifier 0.0.0-stage → 2.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 +202 -0
- package/README.md +76 -2
- package/esm/package.json +3 -0
- package/esm/verifier/npm/src/mod.js +5 -0
- package/esm/verifier/npm/src/src/acdc-v2.js +239 -0
- package/esm/verifier/npm/src/src/agent.js +515 -0
- package/esm/verifier/npm/src/src/cue-store.js +134 -0
- package/esm/verifier/npm/src/src/policy.js +45 -0
- package/esm/verifier/npm/src/src/webhook.js +58 -0
- package/package.json +43 -4
- package/types/mod.d.ts +7 -0
- package/types/mod.d.ts.map +1 -0
- package/types/src/acdc-v2.d.ts +58 -0
- package/types/src/acdc-v2.d.ts.map +1 -0
- package/types/src/agent.d.ts +139 -0
- package/types/src/agent.d.ts.map +1 -0
- package/types/src/cue-store.d.ts +48 -0
- package/types/src/cue-store.d.ts.map +1 -0
- package/types/src/policy.d.ts +16 -0
- package/types/src/policy.d.ts.map +1 -0
- package/types/src/webhook.d.ts +14 -0
- package/types/src/webhook.d.ts.map +1 -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 [yyyy] [name of copyright owner]
|
|
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,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @keri-ts/verifier
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Credential verifier application policy, webhook projection and workflow storage.
|
|
4
|
+
The package borrows public `keri-ts/runtime`, `keri-ts/db` and `cesr-ts` operations;
|
|
5
|
+
it does not start a host, open protocol stores, register CLI commands or own
|
|
6
|
+
protocol acceptance. The agent retains its legacy credential/TEL workflow and optionally composes
|
|
7
|
+
`AcdcV2Verifier` for authenticated ACDC v2 Grant views.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createVerifierCueBaser, VerifierAgent } from "@keri-ts/verifier";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Composition supplies the Habery, Reger, protocol processor, application cue Deck,
|
|
14
|
+
scoped HTTP client and epoch-millisecond clock. The caller owns scheduling and
|
|
15
|
+
closes the cue sidecar before its enclosing protocol stores. `VerifierAgent`
|
|
16
|
+
keeps pending/ready issuance and revocation webhook work in `VerifierCueBaser`;
|
|
17
|
+
HTTP success markers are local workflow history, not KERI receipts or business
|
|
18
|
+
acknowledgements. Schema-specific validators decide business policy separately
|
|
19
|
+
from authenticated protocol evidence.
|
|
20
|
+
|
|
21
|
+
`tufa verifier run` remains the CLI composition. `@keri-ts/hosting` exposes
|
|
22
|
+
the concrete HTTP host; verifier applications import this package directly.
|
|
23
|
+
|
|
24
|
+
Run `deno task check`, `deno task test` and `deno task build:npm` from this directory.
|
|
25
|
+
Licensed under Apache-2.0; see the repository's `LICENSE`.
|
|
26
|
+
|
|
27
|
+
## ACDC v2 retained views and current use
|
|
28
|
+
|
|
29
|
+
`AcdcV2Verifier(hby, hab, exc, registrar, http, options)` borrows the actual Exchanger,
|
|
30
|
+
public evidence acceptor, local query signer and ordinary runtime HTTP client.
|
|
31
|
+
Options select one HTTPS observer cache URL (`source`), maximum observation age,
|
|
32
|
+
finite request deadline and a clock. The runtime's normal certificate trust and
|
|
33
|
+
URL hostname verification authenticate HTTPS; requests refuse redirects. The URL
|
|
34
|
+
must have no credentials, query or fragment. Queries never trigger registrar acquisition.
|
|
35
|
+
KEL/TEL proof authentication remains
|
|
36
|
+
independent of response-source authentication. Matching source/head/age establishes
|
|
37
|
+
only recent observation from that configured endpoint, never global latest state.
|
|
38
|
+
|
|
39
|
+
`inspectHistorical(grant)` authenticates the retained exact-route Grant through
|
|
40
|
+
historical inspection, returning its unchanged origin and view references without
|
|
41
|
+
queries, graph approval, current-standing claims, cues or reporting writes.
|
|
42
|
+
`verifyCurrent(grant)` acquires current public evidence, requires an issued origin
|
|
43
|
+
and the shared graph evaluator's explicit true with current per-node states.
|
|
44
|
+
A legitimately revoked far node is known False and may satisfy NOR/NAND; missing,
|
|
45
|
+
malformed or opaque evidence remains unresolved. Authenticated current public
|
|
46
|
+
openings are transient proof inputs, never enrichment of retained credential views.
|
|
47
|
+
|
|
48
|
+
Pass this concrete owner as `VerifierAgentOptions.acdcV2`. ACDC v2 workflow rows
|
|
49
|
+
reuse the existing cue tables keyed by Grant SAID, keeping partial/full views of
|
|
50
|
+
the same credential distinct. Every attempted ACDC v2 delivery rechecks current
|
|
51
|
+
policy: a previously ready webhook cannot bypass a later opaque head. Historical
|
|
52
|
+
accepted views and delivered markers remain history after revocation. ACDC v2
|
|
53
|
+
payloads identify the Grant, presenter, verifier and configured observations.
|
|
54
|
+
Transport failures retain ordinary pending webhook work; genuine cleanup/storage
|
|
55
|
+
failures remain visible. No exactly-once delivery is claimed.
|
|
56
|
+
|
|
57
|
+
`tufa verifier run --acdc-v2 --alias NAME --config verifier.json --hook URL`
|
|
58
|
+
composes this owner with `runtime.http`. Observation selection and freshness are
|
|
59
|
+
application policy in the existing schema-policy configuration:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"observation": {
|
|
64
|
+
"url": "https://observer.example/",
|
|
65
|
+
"maximumAgeMs": 15000,
|
|
66
|
+
"requestTimeoutMs": 5000
|
|
67
|
+
},
|
|
68
|
+
"requireKnownSchemas": false,
|
|
69
|
+
"schemas": {}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
ACDC v2 requires `observation.url`. Omitted durations retain the 15,000 ms age
|
|
74
|
+
and 5,000 ms deadline defaults; supplied durations must be finite and positive.
|
|
75
|
+
Configure HTTPS trust through the runtime/platform trust settings. A missing or
|
|
76
|
+
expired observation cannot approve current use; unrelated cancellation, cleanup
|
|
77
|
+
and storage failures remain visible. Omitting `--acdc-v2` preserves the legacy lane.
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Verifier application package entrypoint. */
|
|
2
|
+
export { AcdcV2Verifier, } from "./src/acdc-v2.js";
|
|
3
|
+
export { VerifierAgent } from "./src/agent.js";
|
|
4
|
+
export { createVerifierCueBaser, VerifierCueBaser, } from "./src/cue-store.js";
|
|
5
|
+
export { validatorsFromVerifierConfig, } from "./src/policy.js";
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { BlindState, BoundState, bytesEqual, concatBytes, Counter, Diger, Vrsn_2_0 } from "cesr-ts";
|
|
2
|
+
import { call } from "effection";
|
|
3
|
+
import { loadNests } from "keri-ts/db";
|
|
4
|
+
import { acceptedRegistryEvidence, authenticateIpexNode, envelopeFromFrame, evaluateChain, isCesrContentType, issuedNodeVerdict, query, timestampMicros, TransportError, ValidationError, vetBinds, walkIpexGraph, } from "keri-ts/runtime";
|
|
5
|
+
/** Borrow accepted exchange/public evidence owners; acquire no stores, parser or background worker. */
|
|
6
|
+
export class AcdcV2Verifier {
|
|
7
|
+
constructor(hby, hab, exc, evidence, http, options) {
|
|
8
|
+
Object.defineProperty(this, "hby", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: hby
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "hab", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: hab
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "exc", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: exc
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "evidence", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: evidence
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "http", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: http
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "options", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: options
|
|
43
|
+
});
|
|
44
|
+
if (exc.hby !== hby || hab.db !== hby.db || evidence.processor.kvy.db !== hby.db) {
|
|
45
|
+
throw new ValidationError("ACDC v2 verifier requires its actual local evidence owners.");
|
|
46
|
+
}
|
|
47
|
+
if (![options.maximumAgeMs, options.requestTimeoutMs].every(value => Number.isFinite(value) && value > 0)) {
|
|
48
|
+
throw new ValidationError("Source age and request timeout must be finite and positive.");
|
|
49
|
+
}
|
|
50
|
+
const source = new URL(options.source);
|
|
51
|
+
if (source.protocol !== "https:" || source.username || source.password || source.search || source.hash) {
|
|
52
|
+
throw new ValidationError("Observation source must be HTTPS without credentials, query or fragment.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Inspect the immutable retained nested material without querying, reporting or applying graph policy. */
|
|
56
|
+
inspectHistorical(grant) {
|
|
57
|
+
const body = this.hby.db.exns.get([grant]);
|
|
58
|
+
if (!body || body.route !== "/ipex/grant" || body.pvrsn.major !== 2
|
|
59
|
+
|| !this.exc.verifyAccepted(grant, "/ipex/grant", { historical: true }))
|
|
60
|
+
throw new ValidationError("Authenticated retained ACDC v2 Grant is required.");
|
|
61
|
+
const nodes = loadNests(this.hby.db, grant), origins = body.sad.a.o;
|
|
62
|
+
if (!Array.isArray(origins) || origins.length > 1) {
|
|
63
|
+
throw new ValidationError("Verifier requires zero or one retained origin.");
|
|
64
|
+
}
|
|
65
|
+
const credential = origins.length ? nodes.find(node => node.body.said === origins[0])?.body : null;
|
|
66
|
+
if (origins.length && !credential)
|
|
67
|
+
throw new ValidationError("Retained origin is missing.");
|
|
68
|
+
return {
|
|
69
|
+
purpose: "historical-evidence",
|
|
70
|
+
proofValidity: "valid",
|
|
71
|
+
currentStanding: "not-evaluated",
|
|
72
|
+
grant,
|
|
73
|
+
credential: credential,
|
|
74
|
+
recordedRegistryStates: [...this.hby.db.exrs.getTopItemIter([grant])]
|
|
75
|
+
.filter(([keys]) => nodes.some((node) => node.body.said === keys[1]))
|
|
76
|
+
.map(([keys, { regid, said, sn, state, stamp }]) => ({ node: keys[1], regid, said, sn, state, stamp })),
|
|
77
|
+
views: nodes.map(node => ({
|
|
78
|
+
credential: node.body.said,
|
|
79
|
+
view: new Diger({ raw: Diger.digest(node.body.raw, "E"), code: "E" }).qb64,
|
|
80
|
+
})),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Authenticate one complete source response and its exact accepted head, never infer global latest state. */
|
|
84
|
+
*observe(regid) {
|
|
85
|
+
const { source, maximumAgeMs, requestTimeoutMs, now } = this.options;
|
|
86
|
+
const wire = this.hab.endorse(query("tels", { i: regid }, { pre: this.hab.pre, version: Vrsn_2_0 }), {
|
|
87
|
+
gvrsn: Vrsn_2_0,
|
|
88
|
+
});
|
|
89
|
+
const deadline = new AbortController(), expired = new Error("Observation request deadline expired");
|
|
90
|
+
const timer = setTimeout(() => deadline.abort(expired), requestTimeoutMs);
|
|
91
|
+
let response;
|
|
92
|
+
try {
|
|
93
|
+
response = yield* this.http.request(source, {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: { "Content-Type": "application/cesr" },
|
|
96
|
+
body: wire,
|
|
97
|
+
redirect: "error",
|
|
98
|
+
signal: deadline.signal,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof TransportError || (deadline.signal.aborted && error === expired))
|
|
103
|
+
return null;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
}
|
|
109
|
+
const stamp = response.headers.get("Observer-Observed-At"), head = response.headers.get("Observer-Registry-Head");
|
|
110
|
+
const micros = timestampMicros(stamp), age = micros === null ? NaN : now() - Number(micros) / 1000;
|
|
111
|
+
if (response.status !== 200 || !isCesrContentType(response.headers.get("content-type"))
|
|
112
|
+
|| response.headers.get("Observer-Evidence-State") !== "fresh" || !stamp || !Number.isFinite(age) || age < 0
|
|
113
|
+
|| age > maximumAgeMs || !head)
|
|
114
|
+
return null;
|
|
115
|
+
const result = yield* call(() => this.evidence.ingest(concatBytes(Counter.makeGVC(Vrsn_2_0), response.body)));
|
|
116
|
+
if (Object.keys(result.pending).length || Object.keys(result.rejected).length || result.heads[regid] !== head
|
|
117
|
+
|| this.evidence.store.head(regid)?.qb64 !== head)
|
|
118
|
+
return null;
|
|
119
|
+
return { registry: regid, source, head, observedAt: stamp };
|
|
120
|
+
}
|
|
121
|
+
/** Require shared graph approval and full current standing over the exact retained credential views. */
|
|
122
|
+
*verifyCurrent(grant) {
|
|
123
|
+
const inspected = this.inspectHistorical(grant), observations = [];
|
|
124
|
+
const result = (kind) => ({
|
|
125
|
+
kind,
|
|
126
|
+
credential: inspected.credential,
|
|
127
|
+
observations,
|
|
128
|
+
});
|
|
129
|
+
if (!inspected.credential)
|
|
130
|
+
return result("refused");
|
|
131
|
+
const graph = walkIpexGraph(inspected.credential.said, loadNests(this.hby.db, grant), true);
|
|
132
|
+
if (!graph)
|
|
133
|
+
return result("refused");
|
|
134
|
+
const registrations = new Map();
|
|
135
|
+
const verdicts = new Map();
|
|
136
|
+
const missing = () => ({
|
|
137
|
+
kind: "unknown",
|
|
138
|
+
retryable: true,
|
|
139
|
+
reason: "Missing current registry evidence.",
|
|
140
|
+
schemas: [],
|
|
141
|
+
});
|
|
142
|
+
const registries = new Set();
|
|
143
|
+
for (const { body } of graph.nodes.values()) {
|
|
144
|
+
if (body.regid)
|
|
145
|
+
registries.add(body.regid);
|
|
146
|
+
// W06's attribute declaration is already authenticated by the IPEX handler; aggregate pairs are data.
|
|
147
|
+
const attrs = body.attrib;
|
|
148
|
+
if (body.regid && attrs && typeof attrs === "object" && !Array.isArray(attrs)
|
|
149
|
+
&& typeof attrs.rd === "string"
|
|
150
|
+
&& typeof attrs.i === "string")
|
|
151
|
+
registries.add(attrs.rd);
|
|
152
|
+
}
|
|
153
|
+
const unavailable = new Set();
|
|
154
|
+
for (const regid of registries) {
|
|
155
|
+
const observation = yield* this.observe(regid);
|
|
156
|
+
if (observation)
|
|
157
|
+
observations.push(observation);
|
|
158
|
+
else
|
|
159
|
+
unavailable.add(regid);
|
|
160
|
+
}
|
|
161
|
+
for (const [said, node] of graph.nodes) {
|
|
162
|
+
const auth = authenticateIpexNode(node.body, envelopeFromFrame(node), this.hby.db, this.evidence.store, true);
|
|
163
|
+
verdicts.set(said, issuedNodeVerdict(auth));
|
|
164
|
+
if (auth.kind !== "authenticated" || !node.body.regid)
|
|
165
|
+
continue;
|
|
166
|
+
if (unavailable.has(node.body.regid)) {
|
|
167
|
+
verdicts.set(said, missing());
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const chain = acceptedRegistryEvidence(this.evidence.store, node.body.regid);
|
|
171
|
+
if (!chain) {
|
|
172
|
+
verdicts.set(said, missing());
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const envelope = envelopeFromFrame(node), proofs = new Map();
|
|
176
|
+
for (const proof of [...envelope.bsqs, ...envelope.bsss])
|
|
177
|
+
proofs.set(proof.d.nonce, proof);
|
|
178
|
+
const encoded = (proof) => "bn" in proof ? BoundState.qb64b(proof) : BlindState.qb64b(proof);
|
|
179
|
+
// Public source proofs may establish current standing; retained node bytes and historical selection stay unchanged.
|
|
180
|
+
let conflict = false;
|
|
181
|
+
for (const event of chain.updates) {
|
|
182
|
+
const proof = this.evidence.store.publicOpening(event.said);
|
|
183
|
+
if (!proof)
|
|
184
|
+
continue;
|
|
185
|
+
const previous = proofs.get(proof.d.nonce);
|
|
186
|
+
if (previous && !bytesEqual(encoded(previous), encoded(proof)))
|
|
187
|
+
conflict = true;
|
|
188
|
+
proofs.set(proof.d.nonce, proof);
|
|
189
|
+
}
|
|
190
|
+
if (conflict) {
|
|
191
|
+
verdicts.set(said, { kind: "invalid" });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const state = vetBinds({
|
|
195
|
+
...chain,
|
|
196
|
+
db: this.hby.db,
|
|
197
|
+
blinders: [...proofs.values()],
|
|
198
|
+
target: node.body.said,
|
|
199
|
+
acdc: node.body,
|
|
200
|
+
});
|
|
201
|
+
if (state.kind !== "verified") {
|
|
202
|
+
verdicts.set(said, state.kind === "missing" ? missing() : { kind: "invalid" });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
registrations.set(said, state.state);
|
|
206
|
+
verdicts.set(said, issuedNodeVerdict({ kind: "authenticated", registration: state.state }));
|
|
207
|
+
}
|
|
208
|
+
// Freshness failures belong to their node, so an optional branch can remain unused.
|
|
209
|
+
for (const observation of observations) {
|
|
210
|
+
const age = this.options.now() - Number(timestampMicros(observation.observedAt)) / 1000;
|
|
211
|
+
if (age < 0 || age > this.options.maximumAgeMs
|
|
212
|
+
|| this.evidence.store.head(observation.registry)?.qb64 !== observation.head)
|
|
213
|
+
unavailable.add(observation.registry);
|
|
214
|
+
}
|
|
215
|
+
for (const [said, { body }] of graph.nodes) {
|
|
216
|
+
const attrs = body.attrib;
|
|
217
|
+
const presentation = attrs && typeof attrs === "object" && !Array.isArray(attrs)
|
|
218
|
+
? attrs.rd
|
|
219
|
+
: null;
|
|
220
|
+
if ((body.regid && unavailable.has(body.regid))
|
|
221
|
+
|| (typeof presentation === "string" && unavailable.has(presentation))) {
|
|
222
|
+
if (registrations.has(said) || verdicts.get(said)?.kind !== "invalid")
|
|
223
|
+
verdicts.set(said, missing());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const truth = evaluateChain(graph, verdicts, this.hby.db);
|
|
227
|
+
const rootState = registrations.get(inspected.credential.said)?.state;
|
|
228
|
+
if (!truth)
|
|
229
|
+
return result("refused");
|
|
230
|
+
if (rootState === "revoked" && verdicts.get(inspected.credential.said)?.kind === "invalid") {
|
|
231
|
+
return result("revoked");
|
|
232
|
+
}
|
|
233
|
+
if (truth.kind === "valid")
|
|
234
|
+
return result("issued");
|
|
235
|
+
if (truth.kind === "unknown")
|
|
236
|
+
return result("missing");
|
|
237
|
+
return result("refused");
|
|
238
|
+
}
|
|
239
|
+
}
|