@keri-ts/registrar 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 +24 -2
- package/esm/package.json +3 -0
- package/esm/registrar/npm/src/_dnt.polyfills.js +15 -0
- package/esm/registrar/npm/src/mod.js +3 -0
- package/esm/registrar/npm/src/src/registrar.js +257 -0
- package/package.json +43 -4
- package/types/_dnt.polyfills.d.ts +12 -0
- package/types/_dnt.polyfills.d.ts.map +1 -0
- package/types/mod.d.ts +4 -0
- package/types/mod.d.ts.map +1 -0
- package/types/src/registrar.d.ts +42 -0
- package/types/src/registrar.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,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Public registry registrar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`Registrar(processor, store, {publishers, observers, fullEvidence})` borrows the
|
|
4
|
+
actual `ProtocolProcessor` and its ACDC v2 `RegistryStore`. The caller owns stores,
|
|
5
|
+
KRAM configuration and HTTP host lifetime. The actual KRAM owner must be enabled,
|
|
6
|
+
non-exempt for these queries and have configured cache windows; the test uses the
|
|
7
|
+
selected Python catchall tuple `[1000,5000,60000,300000,5000,60000,300000]`. Pass `registrar.handle` to the public
|
|
8
|
+
hosting package's `createTufaApp({protocolHandler})` or ordinary server composition.
|
|
9
|
+
|
|
10
|
+
POST `/ingest` accepts one allow-listed, KRAM-authenticated KERI v2 `tels/publish`
|
|
11
|
+
query with public CESR text in `q.stream`. The common ACDC v2 processor alone owns
|
|
12
|
+
KEL/TEL acceptance, public openings and persistent pending evidence. Responses
|
|
13
|
+
report 200 accepted, 202 pending or 422 rejected outcomes; publication creates no
|
|
14
|
+
issuer alias, keys, custody or private application records.
|
|
15
|
+
|
|
16
|
+
POST `/` accepts observer-only `tels/bulk` or `regs` queries. `q.i` selects one
|
|
17
|
+
registry, a registry list, or all accepted registries; `q.sn` selects the first TEL
|
|
18
|
+
ordinal. Full evidence includes supporting controller/delegation KEL and framed
|
|
19
|
+
accepted TEL/public openings; the default preserves bare TEL responses. Unknown
|
|
20
|
+
explicit registries and wallet-shaped queries fail closed. Queries never fetch
|
|
21
|
+
upstream evidence. These responses make no freshness or global-latest claim.
|
|
22
|
+
|
|
23
|
+
The selected source is Python kf-registrar `7e934668`, declaring KERIpy `7ea525ba`.
|
|
24
|
+
Local admin authoring, witness administration and deployment/CLI policy are outside
|
|
25
|
+
this cut.
|
package/esm/package.json
ADDED
|
@@ -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,257 @@
|
|
|
1
|
+
import { b, concatBytes, Counter, parseBytes, ParserError, SerderACDC, SerderKERI, Vrsn_2_0, } from "cesr-ts";
|
|
2
|
+
import { run } from "effection";
|
|
3
|
+
import { CESR_CONTENT_TYPE, envelopeFromFrame, isCesrContentType, Kramer, readCesrRequestBytes, } from "keri-ts/runtime";
|
|
4
|
+
/** A SAD object excludes arrays and scalar representations. */
|
|
5
|
+
function record(value) {
|
|
6
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
/** Ordinary service errors carry no evidence or observation claims. */
|
|
9
|
+
function text(message, status) {
|
|
10
|
+
return new Response(message, { status, headers: { "Content-Type": "text/plain" } });
|
|
11
|
+
}
|
|
12
|
+
/** Interpret the existing bulk registry selector; an absent selector means all accepted heads. */
|
|
13
|
+
function registryScope(value, store) {
|
|
14
|
+
if (value === undefined || value === null || value === "") {
|
|
15
|
+
return [...store.baser.heads.getTopItemIter()].map(([keys]) => keys[0]).sort();
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "string")
|
|
18
|
+
return [value];
|
|
19
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string" && item.length > 0)
|
|
20
|
+
? value
|
|
21
|
+
: null;
|
|
22
|
+
}
|
|
23
|
+
/** Query ordinals remain exact safe storage integers; strings retain hexadecimal TEL syntax. */
|
|
24
|
+
function ordinal(value) {
|
|
25
|
+
if (value === undefined || value === null || value === "")
|
|
26
|
+
return 0;
|
|
27
|
+
if (typeof value === "number")
|
|
28
|
+
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
29
|
+
if (typeof value !== "string" || !/^[0-9a-f]+$/.test(value))
|
|
30
|
+
return null;
|
|
31
|
+
const sn = BigInt(`0x${value}`);
|
|
32
|
+
return sn <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(sn) : null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Host foreign public evidence without issuer keys or a second validation path.
|
|
36
|
+
* The caller owns processor/store lifetime, enabled non-exempt KRAM and network hosting.
|
|
37
|
+
* Selected Python reference: kf-registrar 7e934668, declared KERIpy 7ea525ba.
|
|
38
|
+
*/
|
|
39
|
+
export class Registrar {
|
|
40
|
+
constructor(processor, store, options = {}) {
|
|
41
|
+
Object.defineProperty(this, "processor", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: processor
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "store", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: store
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "publishers", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "observers", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "fullEvidence", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
/** Public hosting-compatible handler; it neither opens stores nor starts background work. */
|
|
72
|
+
Object.defineProperty(this, "handle", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: async (req) => {
|
|
77
|
+
const path = new URL(req.url).pathname;
|
|
78
|
+
if (path === "/health" && req.method === "GET")
|
|
79
|
+
return Response.json({ status: "ok" });
|
|
80
|
+
if (path === "/query")
|
|
81
|
+
return text("Registrar does not serve wallet queries", 403);
|
|
82
|
+
if (path !== "/" && path !== "/ingest")
|
|
83
|
+
return text("Not Found", 404);
|
|
84
|
+
if (req.method !== "POST")
|
|
85
|
+
return text("Signed POST query required", 403);
|
|
86
|
+
const publication = path === "/ingest";
|
|
87
|
+
if (!isCesrContentType(req.headers.get("content-type"))) {
|
|
88
|
+
await req.body?.cancel();
|
|
89
|
+
return text("Unacceptable content type", publication ? 415 : 406);
|
|
90
|
+
}
|
|
91
|
+
const authenticated = await this.authenticate(req, publication ? this.publishers : this.observers, publication ? ["tels/publish"] : ["tels/bulk", "regs"]);
|
|
92
|
+
if (authenticated instanceof Response)
|
|
93
|
+
return authenticated;
|
|
94
|
+
const q = authenticated;
|
|
95
|
+
if (publication) {
|
|
96
|
+
if (typeof q.stream !== "string" || !q.stream)
|
|
97
|
+
return text("q.stream must contain public CESR evidence", 400);
|
|
98
|
+
const result = await this.ingest(b(q.stream), req.signal);
|
|
99
|
+
return Response.json(result, {
|
|
100
|
+
status: Object.keys(result.rejected).length ? 422 : Object.keys(result.pending).length ? 202 : 200,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (Object.hasOwn(q, "vcid"))
|
|
104
|
+
return text("Registrar does not serve wallet queries", 403);
|
|
105
|
+
const sn = ordinal(q.sn), registries = registryScope(q.i, this.store);
|
|
106
|
+
if (sn === null || registries === null)
|
|
107
|
+
return text("Invalid bulk registry scope or ordinal", 400);
|
|
108
|
+
if (registries.some((regid) => !this.store.head(regid)))
|
|
109
|
+
return text("Unknown registry", 404);
|
|
110
|
+
const tel = [], kel = [], issuers = new Set();
|
|
111
|
+
for (const regid of registries) {
|
|
112
|
+
const history = [...this.store.cloneTelIter(regid)];
|
|
113
|
+
const events = history.map((wire) => parseBytes(wire)[0].body);
|
|
114
|
+
if (!events.every((event) => event instanceof SerderACDC && ["rip", "bup"].includes(event.ilk ?? ""))) {
|
|
115
|
+
return text("Registry history is outside the supported evidence profile", 422);
|
|
116
|
+
}
|
|
117
|
+
if (this.fullEvidence) {
|
|
118
|
+
const issuer = this.store.seqEvent(regid, 0).issuer;
|
|
119
|
+
if (!issuers.has(issuer)) {
|
|
120
|
+
const kever = this.processor.kvy.db.getKever(issuer);
|
|
121
|
+
if (!kever)
|
|
122
|
+
return text("Supporting controller evidence is unavailable", 503);
|
|
123
|
+
kel.push(...this.processor.kvy.db.cloneDelegation(kever, Vrsn_2_0), ...this.processor.kvy.db.clonePreIter(issuer, 0, Vrsn_2_0));
|
|
124
|
+
issuers.add(issuer);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const [i, event] of events.entries()) {
|
|
128
|
+
if (BigInt(`0x${event.sad.n}`) >= BigInt(sn))
|
|
129
|
+
tel.push(this.fullEvidence ? history[i] : event.raw);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return new Response(new Uint8Array(concatBytes(...(this.fullEvidence ? [Counter.makeGVC(Vrsn_2_0)] : []), ...kel, ...tel)).buffer, {
|
|
133
|
+
headers: { "Content-Type": CESR_CONTENT_TYPE },
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
if (processor.registry?.store !== store) {
|
|
138
|
+
throw new TypeError("Registrar requires its processor's actual registry store.");
|
|
139
|
+
}
|
|
140
|
+
this.publishers = new Set(options.publishers);
|
|
141
|
+
this.observers = new Set(options.observers);
|
|
142
|
+
this.fullEvidence = options.fullEvidence ?? false;
|
|
143
|
+
}
|
|
144
|
+
/** Publish a service-owner authorization change after its durable enrollment write. */
|
|
145
|
+
setPublisher(aid, enabled) {
|
|
146
|
+
if (enabled)
|
|
147
|
+
this.publishers.add(aid);
|
|
148
|
+
else
|
|
149
|
+
this.publishers.delete(aid);
|
|
150
|
+
}
|
|
151
|
+
/** Update the bulk-reader policy; the service owner retains separately configured source access. */
|
|
152
|
+
setObserver(aid, enabled) {
|
|
153
|
+
if (enabled)
|
|
154
|
+
this.observers.add(aid);
|
|
155
|
+
else
|
|
156
|
+
this.observers.delete(aid);
|
|
157
|
+
}
|
|
158
|
+
/** Authenticate exactly one complete query through the actual shared KRAM verifier. */
|
|
159
|
+
async authenticate(req, allowed, routes) {
|
|
160
|
+
const raw = await readCesrRequestBytes(req);
|
|
161
|
+
let frames;
|
|
162
|
+
try {
|
|
163
|
+
frames = parseBytes(raw);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (!(error instanceof ParserError))
|
|
167
|
+
throw error;
|
|
168
|
+
return text("Expected one complete signed query", 400);
|
|
169
|
+
}
|
|
170
|
+
const frame = frames[0], body = frame?.body;
|
|
171
|
+
if (frames.length !== 1 || !(body instanceof SerderKERI) || body.ilk !== "qry"
|
|
172
|
+
|| body.pvrsn.major !== 2 || body.pvrsn.minor !== 0)
|
|
173
|
+
return text("Expected one KERI v2 signed query", 400);
|
|
174
|
+
if (!body.pre || !allowed.has(body.pre) || !routes.includes(body.route ?? "")) {
|
|
175
|
+
return text("Requester or route is not authorized", 403);
|
|
176
|
+
}
|
|
177
|
+
const kramer = this.processor.kvy.kramer;
|
|
178
|
+
if (!(kramer instanceof Kramer))
|
|
179
|
+
return text("Request authentication unavailable", 503);
|
|
180
|
+
const result = kramer.intake(envelopeFromFrame(frame));
|
|
181
|
+
if (result.kind !== "ready")
|
|
182
|
+
return text("KRAM refused query", 401);
|
|
183
|
+
// Disabled/exempt KRAM returns ready without a receiver receipt. Only stageKram's
|
|
184
|
+
// authenticated ready result carries receiverTime; it is never an HTTP claim.
|
|
185
|
+
if (!result.receiverTime)
|
|
186
|
+
return text("Enabled non-exempt request authentication required", 503);
|
|
187
|
+
const q = result.envelope.serder.sad?.q;
|
|
188
|
+
return record(q) ? q : text("Query must be an object", 400);
|
|
189
|
+
}
|
|
190
|
+
/** Ordinary v2 dispatch owns acceptance, durable dependencies and public opening retention. */
|
|
191
|
+
async ingest(raw, signal) {
|
|
192
|
+
const summary = { accepted: {}, pending: {}, rejected: {}, heads: {} };
|
|
193
|
+
let frames;
|
|
194
|
+
try {
|
|
195
|
+
frames = parseBytes(raw);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (!(error instanceof ParserError))
|
|
199
|
+
throw error;
|
|
200
|
+
summary.rejected.stream = "Invalid public evidence framing";
|
|
201
|
+
return summary;
|
|
202
|
+
}
|
|
203
|
+
if (!frames.length || frames.some(({ body }) => body instanceof SerderACDC
|
|
204
|
+
? !["rip", "bup"].includes(body.ilk ?? "")
|
|
205
|
+
: !(body instanceof SerderKERI) || !["icp", "dip", "rot", "drt", "ixn", "rct"].includes(body.ilk ?? ""))) {
|
|
206
|
+
summary.rejected.stream = "Hosting accepts only public KEL and rip/bup evidence";
|
|
207
|
+
return summary;
|
|
208
|
+
}
|
|
209
|
+
const processor = this.processor, refused = new Set();
|
|
210
|
+
await run(function* () {
|
|
211
|
+
for (const frame of frames) {
|
|
212
|
+
signal?.throwIfAborted();
|
|
213
|
+
const result = yield* processor.dispatch(frame);
|
|
214
|
+
if (result.decision && "kind" in result.decision && result.decision.kind === "reject")
|
|
215
|
+
refused.add(frame);
|
|
216
|
+
if (frame.body instanceof SerderKERI && result.decision && "kind" in result.decision) {
|
|
217
|
+
const decision = result.decision;
|
|
218
|
+
if (decision.kind === "reject" || decision.kind === "drop") {
|
|
219
|
+
summary.rejected[`kel:${frame.body.pre}`] = "KEL evidence was refused";
|
|
220
|
+
}
|
|
221
|
+
else if (decision.kind === "escrow")
|
|
222
|
+
summary.pending[`kel:${frame.body.pre}`] = 1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
yield* processor.processEscrowsOnce();
|
|
226
|
+
});
|
|
227
|
+
for (const frame of frames) {
|
|
228
|
+
const event = frame.body;
|
|
229
|
+
if (event instanceof SerderKERI) {
|
|
230
|
+
if (event.pre && event.sn !== null
|
|
231
|
+
&& this.processor.kvy.db.kels.getLast(event.pre, Number(event.sn)) === event.said) {
|
|
232
|
+
delete summary.pending[`kel:${event.pre}`];
|
|
233
|
+
}
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (!(event instanceof SerderACDC))
|
|
237
|
+
continue;
|
|
238
|
+
const regid = event.ilk === "rip" ? event.said : event.regid ?? event.said;
|
|
239
|
+
const sn = ordinal(event.sad.n);
|
|
240
|
+
let bucket = "rejected";
|
|
241
|
+
if (!refused.has(frame) && sn !== null && this.store.seqSaider(regid, sn)?.qb64 === event.said) {
|
|
242
|
+
bucket = "accepted";
|
|
243
|
+
}
|
|
244
|
+
else if (!refused.has(frame) && sn !== null
|
|
245
|
+
&& [this.store.baser.maes, this.store.baser.ooes].some((table) => table.get(regid, sn).some(([said]) => said === event.said)))
|
|
246
|
+
bucket = "pending";
|
|
247
|
+
const values = summary[bucket];
|
|
248
|
+
values[regid] = Number(values[regid] ?? 0) + 1;
|
|
249
|
+
if (bucket === "accepted" && sn !== null) {
|
|
250
|
+
const previous = summary.heads[regid];
|
|
251
|
+
if (!previous || ordinal(this.store.event(previous).sad.n) < sn)
|
|
252
|
+
summary.heads[regid] = event.said;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return summary;
|
|
256
|
+
}
|
|
257
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keri-ts/registrar",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Signed public ACDC registry publication and bulk evidence queries",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/kentbull/keri-ts.git",
|
|
8
|
+
"directory": "packages/registrar"
|
|
9
|
+
},
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"main": "./esm/registrar/npm/src/mod.js",
|
|
12
|
+
"module": "./esm/registrar/npm/src/mod.js",
|
|
13
|
+
"types": "./types/mod.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./types/mod.d.ts",
|
|
17
|
+
"import": "./esm/registrar/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
|
+
"cesr-ts": "2.0.0",
|
|
37
|
+
"effection": "^3.6.0",
|
|
38
|
+
"keri-ts": "2.0.0",
|
|
39
|
+
"@deno/shim-deno": "~0.18.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^20.9.0"
|
|
43
|
+
},
|
|
44
|
+
"_generatedBy": "dnt@dev"
|
|
45
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,iBAAiB,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Signed service routes over the shared public KEL/TEL acceptance owner. */
|
|
2
|
+
import type { ProtocolHandler } from "@keri-ts/hosting";
|
|
3
|
+
import type { RegistryStore } from "keri-ts/db";
|
|
4
|
+
import { type ProtocolProcessor } from "keri-ts/runtime";
|
|
5
|
+
/** Service role allowlists and response profile; authentication remains KRAM's responsibility. */
|
|
6
|
+
export interface RegistrarOptions {
|
|
7
|
+
publishers?: readonly string[];
|
|
8
|
+
observers?: readonly string[];
|
|
9
|
+
/** Include controller/delegation KEL and framed TEL/public openings instead of bare TEL. */
|
|
10
|
+
fullEvidence?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Request-local final protocol outcomes; no application pending queue or acceptance records. */
|
|
13
|
+
export interface PublicationResult {
|
|
14
|
+
accepted: Record<string, number>;
|
|
15
|
+
pending: Record<string, number>;
|
|
16
|
+
rejected: Record<string, number | string>;
|
|
17
|
+
heads: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Host foreign public evidence without issuer keys or a second validation path.
|
|
21
|
+
* The caller owns processor/store lifetime, enabled non-exempt KRAM and network hosting.
|
|
22
|
+
* Selected Python reference: kf-registrar 7e934668, declared KERIpy 7ea525ba.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Registrar {
|
|
25
|
+
readonly processor: ProtocolProcessor;
|
|
26
|
+
readonly store: RegistryStore;
|
|
27
|
+
private readonly publishers;
|
|
28
|
+
private readonly observers;
|
|
29
|
+
private readonly fullEvidence;
|
|
30
|
+
constructor(processor: ProtocolProcessor, store: RegistryStore, options?: RegistrarOptions);
|
|
31
|
+
/** Publish a service-owner authorization change after its durable enrollment write. */
|
|
32
|
+
setPublisher(aid: string, enabled: boolean): void;
|
|
33
|
+
/** Update the bulk-reader policy; the service owner retains separately configured source access. */
|
|
34
|
+
setObserver(aid: string, enabled: boolean): void;
|
|
35
|
+
/** Public hosting-compatible handler; it neither opens stores nor starts background work. */
|
|
36
|
+
readonly handle: ProtocolHandler;
|
|
37
|
+
/** Authenticate exactly one complete query through the actual shared KRAM verifier. */
|
|
38
|
+
private authenticate;
|
|
39
|
+
/** Ordinary v2 dispatch owns acceptance, durable dependencies and public opening retention. */
|
|
40
|
+
ingest(raw: Uint8Array, signal?: AbortSignal): Promise<PublicationResult>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/src/registrar.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAaxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAKL,KAAK,iBAAiB,EAEvB,MAAM,iBAAiB,CAAC;AAEzB,kGAAkG;AAClG,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,4FAA4F;IAC5F,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AACD,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC1C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AA4BD;;;;GAIG;AACH,qBAAa,SAAS;IAKR,QAAQ,CAAC,SAAS,EAAE,iBAAiB;IAAE,QAAQ,CAAC,KAAK,EAAE,aAAa;IAJhF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;gBAElB,SAAS,EAAE,iBAAiB,EAAW,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,gBAAqB;IAShH,uFAAuF;IACvF,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAKjD,oGAAoG;IACpG,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAKhD,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,EAAE,eAAe,CA8D9B;IAEF,uFAAuF;YACzE,YAAY;IAgC1B,+FAA+F;IACzF,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAmEhF"}
|