@keri-ts/observer 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 +21 -2
- package/esm/observer/npm/src/_dnt.polyfills.js +15 -0
- package/esm/observer/npm/src/mod.js +4 -0
- package/esm/observer/npm/src/src/observer.js +226 -0
- package/esm/observer/npm/src/src/storing.js +43 -0
- package/esm/package.json +3 -0
- package/package.json +44 -4
- package/types/_dnt.polyfills.d.ts +12 -0
- package/types/_dnt.polyfills.d.ts.map +1 -0
- package/types/mod.d.ts +5 -0
- package/types/mod.d.ts.map +1 -0
- package/types/src/observer.d.ts +47 -0
- package/types/src/observer.d.ts.map +1 -0
- package/types/src/storing.d.ts +24 -0
- package/types/src/storing.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,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Configured-source observer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The observer borrows its actual ProtocolProcessor, ACDC v2 RegistryStore and a
|
|
4
|
+
separately owned ObservationBaser. Supply fixed HTTPS sources, allowed reader
|
|
5
|
+
AIDs and an explicit observation age. Callers own store and host lifetime.
|
|
6
|
+
|
|
7
|
+
`pullOnce` makes signed bulk requests to those fixed sources. `run` repeats that
|
|
8
|
+
operation on a fixed cadence; incoming queries never initiate or accelerate it.
|
|
9
|
+
CA/URL-hostname verification and optional IP-to-DNS certificate mapping authenticate
|
|
10
|
+
the configured response source. Redirects cannot acquire observation credit.
|
|
11
|
+
|
|
12
|
+
Only complete, clean source responses renew URL-keyed accepted heads and local
|
|
13
|
+
completed time. Returned membership includes prior successful membership; unresolved
|
|
14
|
+
ordinals affect only their registry/scope. Old records/evidence survive failure or
|
|
15
|
+
restart, but an old prefix cannot renew a newer cached head. Cache-only signed
|
|
16
|
+
`tels`/`tels/head` responses require an exact current head and sufficiently recent
|
|
17
|
+
configured-source observation. The existing Observer-* headers report that local
|
|
18
|
+
fact; they make no global-latest or absence-of-withheld-updates claim.
|
|
19
|
+
|
|
20
|
+
Selected Python service: kf-observer feec9004, declaring KERIpy 7ea525ba. Its dedicated
|
|
21
|
+
public TLS test fixtures are reused here; no sibling Python checkout is needed for
|
|
22
|
+
same-language unit tests. The independent npm package exposes the service and observation-store lifecycle; it adds no Tufa CLI.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
2
|
+
if (!Object.hasOwn) {
|
|
3
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
4
|
+
value: function (object, property) {
|
|
5
|
+
if (object == null) {
|
|
6
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
7
|
+
}
|
|
8
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
9
|
+
},
|
|
10
|
+
configurable: true,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/** Configured-source freshness over ordinary v2 acceptance; queries never acquire evidence. */
|
|
2
|
+
import { sourceRequest, SourceTrust } from "@keri-ts/hosting";
|
|
3
|
+
import { Registrar } from "@keri-ts/registrar";
|
|
4
|
+
import { concatBytes, Counter, parseBytes, ParserError, SerderKERI, Vrsn_2_0 } from "cesr-ts";
|
|
5
|
+
import { call, sleep } from "effection";
|
|
6
|
+
import { CESR_CONTENT_TYPE, envelopeFromFrame, isCesrContentType, Kramer, query, readCesrRequestBytes, TransportError, ValidationError, } from "keri-ts/runtime";
|
|
7
|
+
/** Finite positive deployment durations, not protocol constants or automatic lifetime caps. */
|
|
8
|
+
function duration(value) {
|
|
9
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
10
|
+
throw new ValidationError("Observer duration must be finite and positive.");
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
/** Signed query attributes must be an object before their named fields are read. */
|
|
15
|
+
function record(value) {
|
|
16
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
/** Cache-only HTTP refusal contains no observation credit. */
|
|
19
|
+
function unavailable(message, status = 503) {
|
|
20
|
+
return new Response(message, { status, headers: { "Content-Type": "text/plain" } });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Own URL observations and fixed acquisition scheduling, borrowing protocol and storage owners.
|
|
24
|
+
* Source record shape/scope follows kf-observer feec9004; it declares KERIpy 7ea525ba.
|
|
25
|
+
* Current selected KERIpy c4 is a later qualification input, not an implicit service repin.
|
|
26
|
+
*/
|
|
27
|
+
export class Observer {
|
|
28
|
+
constructor(processor, store, observations, options) {
|
|
29
|
+
Object.defineProperty(this, "processor", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: processor
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "store", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: store
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "observations", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: observations
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "sources", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "readers", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "maximumAgeMs", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "now", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "evidence", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: void 0
|
|
76
|
+
});
|
|
77
|
+
/** Authenticate a reader and serve only an exact, sufficiently recent observation of this cache head. */
|
|
78
|
+
Object.defineProperty(this, "handle", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: async (req) => {
|
|
83
|
+
const path = new URL(req.url).pathname;
|
|
84
|
+
if (path === "/health" && req.method === "GET")
|
|
85
|
+
return Response.json({ status: "ok" });
|
|
86
|
+
if (path !== "/" || req.method !== "POST")
|
|
87
|
+
return unavailable("Not Found", 404);
|
|
88
|
+
if (!isCesrContentType(req.headers.get("content-type"))) {
|
|
89
|
+
await req.body?.cancel();
|
|
90
|
+
return unavailable("Unacceptable content type", 415);
|
|
91
|
+
}
|
|
92
|
+
let frames;
|
|
93
|
+
try {
|
|
94
|
+
frames = parseBytes(await readCesrRequestBytes(req));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!(error instanceof ParserError))
|
|
98
|
+
throw error;
|
|
99
|
+
return unavailable("Expected one signed query", 400);
|
|
100
|
+
}
|
|
101
|
+
const frame = frames[0], body = frame?.body;
|
|
102
|
+
if (frames.length !== 1 || !(body instanceof SerderKERI) || body.ilk !== "qry"
|
|
103
|
+
|| body.pvrsn.major !== 2 || body.pvrsn.minor !== 0)
|
|
104
|
+
return unavailable("Expected one KERI v2 signed query", 400);
|
|
105
|
+
if (!body.pre || !this.readers.has(body.pre) || !["tels", "tels/head"].includes(body.route ?? "")) {
|
|
106
|
+
return unavailable("Reader or route is not authorized", 403);
|
|
107
|
+
}
|
|
108
|
+
const kramer = this.processor.kvy.kramer;
|
|
109
|
+
if (!(kramer instanceof Kramer))
|
|
110
|
+
return unavailable("Request authentication unavailable");
|
|
111
|
+
const authenticated = kramer.intake(envelopeFromFrame(frame));
|
|
112
|
+
if (authenticated.kind !== "ready")
|
|
113
|
+
return unavailable("KRAM refused query", 401);
|
|
114
|
+
if (!authenticated.receiverTime)
|
|
115
|
+
return unavailable("Enabled non-exempt request authentication required");
|
|
116
|
+
const q = authenticated.envelope.serder.sad?.q;
|
|
117
|
+
if (!record(q) || typeof q.i !== "string" || !q.i || Object.hasOwn(q, "vcid"))
|
|
118
|
+
return unavailable("q.i must identify one registry", 400);
|
|
119
|
+
const regid = q.i, sn = q.sn ?? 0;
|
|
120
|
+
if (!Number.isSafeInteger(sn) || Number(sn) < 0)
|
|
121
|
+
return unavailable("sn must be a nonnegative integer", 400);
|
|
122
|
+
if (this.pendingInScope([regid]))
|
|
123
|
+
return unavailable("Registry dependencies are pending");
|
|
124
|
+
const head = this.store.head(regid);
|
|
125
|
+
if (!head)
|
|
126
|
+
return unavailable("Unknown registry in local cache", 404);
|
|
127
|
+
const completed = this.sources.map(source => this.observations.observations.get([source.url]))
|
|
128
|
+
.filter(record => record?.heads[regid] === head.qb64).map(record => record.completed).sort().at(-1);
|
|
129
|
+
if (!completed)
|
|
130
|
+
return unavailable("No completed source observation for accepted head");
|
|
131
|
+
const age = this.now() - Date.parse(completed);
|
|
132
|
+
if (!Number.isFinite(age) || age < 0 || age > this.maximumAgeMs)
|
|
133
|
+
return unavailable("Cached observation is stale");
|
|
134
|
+
const rip = this.store.seqEvent(regid, 0), issuer = this.processor.kvy.db.getKever(rip.issuer);
|
|
135
|
+
if (!issuer)
|
|
136
|
+
return unavailable("Supporting controller evidence unavailable");
|
|
137
|
+
const evidence = concatBytes(Counter.makeGVC(Vrsn_2_0), ...this.processor.kvy.db.cloneDelegation(issuer, Vrsn_2_0), ...this.processor.kvy.db.clonePreIter(rip.issuer, 0, Vrsn_2_0), this.store.cloneTel(regid, Number(sn)));
|
|
138
|
+
return new Response(new Uint8Array(evidence).buffer, {
|
|
139
|
+
headers: {
|
|
140
|
+
"Content-Type": CESR_CONTENT_TYPE,
|
|
141
|
+
"Observer-Observed-At": completed,
|
|
142
|
+
"Observer-Evidence-State": "fresh",
|
|
143
|
+
"Observer-Registry-Head": head.qb64,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (!options.sources.length) {
|
|
149
|
+
throw new ValidationError("Observer needs configured sources.");
|
|
150
|
+
}
|
|
151
|
+
this.sources = options.sources.map(source => new SourceTrust(source));
|
|
152
|
+
if (new Set(this.sources.map(source => source.url)).size !== this.sources.length) {
|
|
153
|
+
throw new ValidationError("Duplicate observer source URL.");
|
|
154
|
+
}
|
|
155
|
+
this.readers = new Set(options.readers);
|
|
156
|
+
this.maximumAgeMs = duration(options.maximumAgeMs ?? 15000);
|
|
157
|
+
this.now = options.now ?? Date.now;
|
|
158
|
+
this.evidence = new Registrar(processor, store);
|
|
159
|
+
}
|
|
160
|
+
/** Publish a service-owner enrollment change; an empty reader set denies every query. */
|
|
161
|
+
setReader(aid, enabled) {
|
|
162
|
+
if (enabled)
|
|
163
|
+
this.readers.add(aid);
|
|
164
|
+
else
|
|
165
|
+
this.readers.delete(aid);
|
|
166
|
+
}
|
|
167
|
+
/** Ignore unresolved sightings only when their exact ordinal already has an accepted event. */
|
|
168
|
+
pendingInScope(registries) {
|
|
169
|
+
const scope = new Set(registries);
|
|
170
|
+
for (const table of [this.store.baser.maes, this.store.baser.ooes]) {
|
|
171
|
+
for (const [keys, sn] of table.getTopItemIter()) {
|
|
172
|
+
if (scope.has(keys[0]) && !this.store.seqSaider(keys[0], sn))
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
/** Record only a completed authenticated response with its returned/prior source scope intact. */
|
|
179
|
+
async observe(source, raw) {
|
|
180
|
+
// The selected source profile, like Python Parser(version=2), fixes attachment genus independently of legacy bodies.
|
|
181
|
+
const result = await this.evidence.ingest(concatBytes(Counter.makeGVC(Vrsn_2_0), raw));
|
|
182
|
+
const previous = this.observations.observations.get([source.url]);
|
|
183
|
+
const heads = result.heads, prior = Object.keys(previous?.heads ?? {}), scope = new Set([...Object.keys(heads), ...prior]);
|
|
184
|
+
if (!Object.keys(result.rejected).length && !Object.keys(result.pending).length && !this.pendingInScope(scope)
|
|
185
|
+
&& prior.every(regid => Object.hasOwn(heads, regid))
|
|
186
|
+
&& Object.entries(heads).every(([regid, said]) => this.store.head(regid)?.qb64 === said)) {
|
|
187
|
+
this.observations.observations.pin([source.url], { completed: new Date(this.now()).toISOString(), heads });
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
/** Pull each fixed URL in sequence; only HTTPS success can reach observation publication. */
|
|
193
|
+
*pullOnce(hab, { timeoutMs = 5000 } = {}) {
|
|
194
|
+
duration(timeoutMs);
|
|
195
|
+
if (hab.db !== this.processor.kvy.db) {
|
|
196
|
+
throw new ValidationError("Observer requires its actual local signing habitat.");
|
|
197
|
+
}
|
|
198
|
+
let completed = 0;
|
|
199
|
+
for (const source of this.sources) {
|
|
200
|
+
const body = hab.endorse(query("tels/bulk", {}, { pre: hab.pre, version: Vrsn_2_0 }), { gvrsn: Vrsn_2_0 });
|
|
201
|
+
try {
|
|
202
|
+
const response = yield* sourceRequest(source, body, timeoutMs);
|
|
203
|
+
if (response.status !== 200 || !isCesrContentType(response.headers.get("content-type")))
|
|
204
|
+
continue;
|
|
205
|
+
if (yield* call(() => this.observe(source, response.body)))
|
|
206
|
+
completed++;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (!(error instanceof TransportError))
|
|
210
|
+
throw error;
|
|
211
|
+
// A failed source cannot renew its record or stop independently configured peers.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return completed;
|
|
215
|
+
}
|
|
216
|
+
/** Fixed scheduled acquisition independent of incoming reader activity; scope cancellation joins I/O. */
|
|
217
|
+
*run(hab, { intervalMs = 5000, timeoutMs = 5000 } = {}) {
|
|
218
|
+
duration(intervalMs);
|
|
219
|
+
duration(timeoutMs);
|
|
220
|
+
while (true) {
|
|
221
|
+
const started = performance.now();
|
|
222
|
+
yield* this.pullOnce(hab, { timeoutMs });
|
|
223
|
+
yield* sleep(Math.max(0, intervalMs - (performance.now() - started)));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Komer, LMDBer } from "keri-ts/db";
|
|
2
|
+
import { DatabaseNotOpenError, RawRecord } from "keri-ts/runtime";
|
|
3
|
+
/** Ordinary application record, with no evidence or validation ledger. */
|
|
4
|
+
export class ObservationRecord extends RawRecord {
|
|
5
|
+
}
|
|
6
|
+
/** Caller-owned source observations, physically separate from public registry evidence. */
|
|
7
|
+
export class ObservationBaser extends LMDBer {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super(options, {
|
|
10
|
+
tailDirPath: "keri/observer",
|
|
11
|
+
cleanTailDirPath: "keri/clean/observer",
|
|
12
|
+
altTailDirPath: ".tufa/observer",
|
|
13
|
+
altCleanTailDirPath: ".tufa/clean/observer",
|
|
14
|
+
tempPrefix: "keri_observer_",
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "observations", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Rebind the unchanged URL-keyed observation records after joined reopen. */
|
|
24
|
+
*reopen(options = {}) {
|
|
25
|
+
if (!(yield* super.reopen(options)))
|
|
26
|
+
return false;
|
|
27
|
+
try {
|
|
28
|
+
this.observations = new Komer(this, { subkey: "observations.", recordClass: ObservationRecord });
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
yield* this.close();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Open only the application's required observation environment. */
|
|
38
|
+
export function* createObservationBaser(options = {}) {
|
|
39
|
+
const db = new ObservationBaser(options);
|
|
40
|
+
if (!(yield* db.reopen()))
|
|
41
|
+
throw new DatabaseNotOpenError("Observation environment could not open.");
|
|
42
|
+
return db;
|
|
43
|
+
}
|
package/esm/package.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keri-ts/observer",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Configured-source ACDC evidence observation and cache-only queries",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/kentbull/keri-ts.git",
|
|
8
|
+
"directory": "packages/observer"
|
|
9
|
+
},
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"main": "./esm/observer/npm/src/mod.js",
|
|
12
|
+
"module": "./esm/observer/npm/src/mod.js",
|
|
13
|
+
"types": "./types/mod.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./types/mod.d.ts",
|
|
17
|
+
"import": "./esm/observer/npm/src/mod.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --version"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"esm",
|
|
27
|
+
"types",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20.3"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@keri-ts/hosting": "2.0.0",
|
|
36
|
+
"@keri-ts/registrar": "2.0.0",
|
|
37
|
+
"cesr-ts": "2.0.0",
|
|
38
|
+
"effection": "^3.6.0",
|
|
39
|
+
"keri-ts": "2.0.0",
|
|
40
|
+
"@deno/shim-deno": "~0.18.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^20.9.0"
|
|
44
|
+
},
|
|
45
|
+
"_generatedBy": "dnt@dev"
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Object {
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether an object has a property with the specified name.
|
|
5
|
+
* @param o An object.
|
|
6
|
+
* @param v A property name.
|
|
7
|
+
*/
|
|
8
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
|
package/types/mod.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Observer application entrypoint; public evidence and HTTP hosting remain separately owned. */
|
|
2
|
+
import "./_dnt.polyfills.js";
|
|
3
|
+
export { Observer, type ObserverOptions } from "./src/observer.js";
|
|
4
|
+
export { createObservationBaser, type Observation, ObservationBaser } from "./src/storing.js";
|
|
5
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,KAAK,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Configured-source freshness over ordinary v2 acceptance; queries never acquire evidence. */
|
|
2
|
+
import { type ProtocolHandler, type SourceConfig, SourceTrust } from "@keri-ts/hosting";
|
|
3
|
+
import { type Operation } from "effection";
|
|
4
|
+
import type { RegistryStore } from "keri-ts/db";
|
|
5
|
+
import { type Hab, type ProtocolProcessor } from "keri-ts/runtime";
|
|
6
|
+
import { ObservationBaser } from "./storing.js";
|
|
7
|
+
/** Only source authority, local age and reader policy belong to the application. */
|
|
8
|
+
export interface ObserverOptions {
|
|
9
|
+
sources: readonly SourceConfig[];
|
|
10
|
+
readers: readonly string[];
|
|
11
|
+
maximumAgeMs?: number;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Own URL observations and fixed acquisition scheduling, borrowing protocol and storage owners.
|
|
16
|
+
* Source record shape/scope follows kf-observer feec9004; it declares KERIpy 7ea525ba.
|
|
17
|
+
* Current selected KERIpy c4 is a later qualification input, not an implicit service repin.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Observer {
|
|
20
|
+
readonly processor: ProtocolProcessor;
|
|
21
|
+
readonly store: RegistryStore;
|
|
22
|
+
readonly observations: ObservationBaser;
|
|
23
|
+
readonly sources: readonly SourceTrust[];
|
|
24
|
+
private readonly readers;
|
|
25
|
+
private readonly maximumAgeMs;
|
|
26
|
+
private readonly now;
|
|
27
|
+
private readonly evidence;
|
|
28
|
+
constructor(processor: ProtocolProcessor, store: RegistryStore, observations: ObservationBaser, options: ObserverOptions);
|
|
29
|
+
/** Publish a service-owner enrollment change; an empty reader set denies every query. */
|
|
30
|
+
setReader(aid: string, enabled: boolean): void;
|
|
31
|
+
/** Ignore unresolved sightings only when their exact ordinal already has an accepted event. */
|
|
32
|
+
pendingInScope(registries: Iterable<string>): boolean;
|
|
33
|
+
/** Record only a completed authenticated response with its returned/prior source scope intact. */
|
|
34
|
+
private observe;
|
|
35
|
+
/** Pull each fixed URL in sequence; only HTTPS success can reach observation publication. */
|
|
36
|
+
pullOnce(hab: Hab, { timeoutMs }?: {
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}): Operation<number>;
|
|
39
|
+
/** Fixed scheduled acquisition independent of incoming reader activity; scope cancellation joins I/O. */
|
|
40
|
+
run(hab: Hab, { intervalMs, timeoutMs }?: {
|
|
41
|
+
intervalMs?: number;
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
}): Operation<void>;
|
|
44
|
+
/** Authenticate a reader and serve only an exact, sufficiently recent observation of this cache head. */
|
|
45
|
+
readonly handle: ProtocolHandler;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=observer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.d.ts","sourceRoot":"","sources":["../../src/src/observer.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAiB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGvG,OAAO,EAAQ,KAAK,SAAS,EAAS,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAGL,KAAK,GAAG,EAGR,KAAK,iBAAiB,EAKvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAiBD;;;;GAIG;AACH,qBAAa,QAAQ;IAQjB,QAAQ,CAAC,SAAS,EAAE,iBAAiB;IACrC,QAAQ,CAAC,KAAK,EAAE,aAAa;IAC7B,QAAQ,CAAC,YAAY,EAAE,gBAAgB;IATzC,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAY;gBAG1B,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,gBAAgB,EACvC,OAAO,EAAE,eAAe;IAe1B,yFAAyF;IACzF,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAK9C,+FAA+F;IAC/F,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO;IAUrD,kGAAkG;YACpF,OAAO;IAkBrB,6FAA6F;IAC5F,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,SAAgB,EAAE,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,SAAS,CAAC,MAAM,CAAC;IAoBzF,yGAAyG;IACxG,GAAG,CACF,GAAG,EAAE,GAAG,EACR,EAAE,UAAiB,EAAE,SAAgB,EAAE,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACxF,SAAS,CAAC,IAAI,CAAC;IAUlB,yGAAyG;IACzG,QAAQ,CAAC,MAAM,EAAE,eAAe,CA0D9B;CACH"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Completed configured-source observations; protocol acceptance remains in v2 stores. */
|
|
2
|
+
import type { Operation } from "effection";
|
|
3
|
+
import { Komer, LMDBer, type LMDBerOptions } from "keri-ts/db";
|
|
4
|
+
import { RawRecord } from "keri-ts/runtime";
|
|
5
|
+
/** Local completed-pull time and exact returned accepted heads for one configured URL. */
|
|
6
|
+
export interface Observation {
|
|
7
|
+
completed: string;
|
|
8
|
+
heads: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/** Ordinary application record, with no evidence or validation ledger. */
|
|
11
|
+
export declare class ObservationRecord extends RawRecord<Observation> implements Observation {
|
|
12
|
+
completed: string;
|
|
13
|
+
heads: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/** Caller-owned source observations, physically separate from public registry evidence. */
|
|
16
|
+
export declare class ObservationBaser extends LMDBer {
|
|
17
|
+
observations: Komer<ObservationRecord>;
|
|
18
|
+
constructor(options?: LMDBerOptions);
|
|
19
|
+
/** Rebind the unchanged URL-keyed observation records after joined reopen. */
|
|
20
|
+
reopen(options?: Partial<LMDBerOptions>): Operation<boolean>;
|
|
21
|
+
}
|
|
22
|
+
/** Open only the application's required observation environment. */
|
|
23
|
+
export declare function createObservationBaser(options?: LMDBerOptions): Operation<ObservationBaser>;
|
|
24
|
+
//# sourceMappingURL=storing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storing.d.ts","sourceRoot":"","sources":["../../src/src/storing.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAwB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElE,0FAA0F;AAC1F,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AACD,0EAA0E;AAC1E,qBAAa,iBAAkB,SAAQ,SAAS,CAAC,WAAW,CAAE,YAAW,WAAW;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AACD,2FAA2F;AAC3F,qBAAa,gBAAiB,SAAQ,MAAM;IAC1C,YAAY,EAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBAC5B,OAAO,GAAE,aAAkB;IASvC,8EAA8E;IACpE,MAAM,CAAC,OAAO,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,SAAS,CAAC,OAAO,CAAC;CAU3E;AACD,oEAAoE;AACpE,wBAAiB,sBAAsB,CAAC,OAAO,GAAE,aAAkB,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAIhG"}
|