@xyo-network/service-kit-protocol 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -95,3 +95,20 @@ Missing content is unavailable, not proof of nonexistence or revocation.
95
95
  See the [normative contract](../../papers/B1_PUBLIC_OBJECT_RESOLUTION.md) and
96
96
  [verification status](../../docs/IMPLEMENTATION_STATUS.md) for the exact B1
97
97
  boundary, dated verification results and remaining broader work.
98
+
99
+ ## Local B4 primitives
100
+
101
+ The unpublished local 0.2.1 candidate additionally exports `verifyFleetPayload`
102
+ and `resolveFleetPayload` for original SDK-root verification and configured
103
+ bounded content resolution; `foldFleetControls`/`matchFleetPublisher` for a pure
104
+ caller-validated lifecycle fold; and `createLocalFleetConfigurationStore` for
105
+ volatile opaque private provision. These surfaces do not change B1's data-hash
106
+ contract. The fold reports `validated-input-only`, without authenticated carrying
107
+ correspondence or complete finalized history. Private acknowledgments report
108
+ `private-provision-only` and confer no publication grant. See the
109
+ [selected local profiles and gate results](../../docs/B4_LOCAL_PRIMITIVES_2026-10-11.md).
110
+ Authenticated composition belongs to the existing XL1 adapter under its
111
+ [selected local profile](../../docs/B4_AUTHENTICATED_LOCAL_PROFILE_2026-10-11.md).
112
+ The supported strict public profiles are Node and browser; supplemental ES-only
113
+ dependency diagnostics remain an unsupported baseline. These protocol primitives
114
+ retain their narrower assurances. This candidate is unpublished and local.
@@ -0,0 +1,32 @@
1
+ export interface LocalFleetConfigurationProfile {
2
+ readonly fleetRoot: string;
3
+ readonly maxConfigurationBytes: number;
4
+ readonly maxMembers: number;
5
+ readonly maxRevisionBytes: number;
6
+ readonly maxTotalBytes: number;
7
+ readonly owner: string;
8
+ }
9
+ export interface OpaqueFleetConfiguration {
10
+ readonly bytes: Uint8Array;
11
+ readonly memberRoot: string;
12
+ readonly revision: string;
13
+ }
14
+ export interface FleetConfigurationAcknowledgment {
15
+ readonly assurance: 'private-provision-only';
16
+ readonly memberRoot: string;
17
+ readonly revision: string;
18
+ readonly status: 'acknowledged' | 'stale' | 'missing';
19
+ }
20
+ export interface LocalFleetConfigurationStore {
21
+ acknowledge(memberRoot: string, revision: string): FleetConfigurationAcknowledgment;
22
+ acknowledgment(memberRoot: string): FleetConfigurationAcknowledgment | undefined;
23
+ /** Return an independent opaque byte copy. No parser or public authority is applied. */
24
+ provide(memberRoot: string): OpaqueFleetConfiguration | undefined;
25
+ provision(configuration: OpaqueFleetConfiguration): void;
26
+ }
27
+ /**
28
+ * Volatile one-realm private provision profile. The configured local manager controls calls;
29
+ * it is not a remote authentication protocol, a public grant, or a persistent backend.
30
+ */
31
+ export declare function createLocalFleetConfigurationStore(configurationProfile: LocalFleetConfigurationProfile): LocalFleetConfigurationStore;
32
+ //# sourceMappingURL=fleetConfiguration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleetConfiguration.d.ts","sourceRoot":"","sources":["../../src/fleetConfiguration.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAA;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AACD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AACD,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,SAAS,EAAE,wBAAwB,CAAA;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,GAAG,SAAS,CAAA;CACtD;AACD,MAAM,WAAW,4BAA4B;IAC3C,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gCAAgC,CAAA;IACnF,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,gCAAgC,GAAG,SAAS,CAAA;IAChF,wFAAwF;IACxF,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAAA;IACjE,SAAS,CAAC,aAAa,EAAE,wBAAwB,GAAG,IAAI,CAAA;CACzD;AA+CD;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,oBAAoB,EAAE,8BAA8B,GAAG,4BAA4B,CA8CrI"}
@@ -0,0 +1,77 @@
1
+ import type { FleetControl, FleetPayload } from '@xyo-network/service-kit-schemas';
2
+ import type { VerificationLimits } from './types.js';
3
+ export interface FleetFoldLimits extends VerificationLimits {
4
+ readonly maxControls: number;
5
+ readonly maxDeclarations: number;
6
+ readonly maxGrants: number;
7
+ readonly maxMembers: number;
8
+ }
9
+ export interface FleetDeclarationFact {
10
+ readonly payload: Readonly<FleetPayload>;
11
+ readonly root: string;
12
+ }
13
+ /** Caller-validated native occurrence facts. This interface itself proves no signatures or completeness. */
14
+ export interface FleetControlFact extends FleetDeclarationFact {
15
+ readonly authorizer: string;
16
+ readonly block: number;
17
+ readonly chainId: string;
18
+ readonly payload: Readonly<FleetControl>;
19
+ readonly payloadIndex: number;
20
+ readonly transactionIndex: number;
21
+ }
22
+ export interface FoldFleetControlsOptions {
23
+ readonly chainId: string;
24
+ readonly controls: readonly FleetControlFact[];
25
+ readonly declarations: readonly FleetDeclarationFact[];
26
+ readonly fleetRoot: string;
27
+ readonly genesisRoot: string;
28
+ readonly limits: FleetFoldLimits;
29
+ readonly owner: string;
30
+ readonly publicationBlock: number;
31
+ readonly signal?: AbortSignal;
32
+ }
33
+ export interface FleetMemberState {
34
+ readonly active: boolean;
35
+ readonly roleId: string;
36
+ readonly root: string;
37
+ }
38
+ export interface FleetGrantState {
39
+ readonly controlRoot: string;
40
+ readonly expiresAtBlock?: number;
41
+ readonly memberRoot: string;
42
+ readonly publisherAddress: string;
43
+ readonly scopeRoot: string;
44
+ }
45
+ export interface FoldedFleetView {
46
+ readonly assurance: 'validated-input-only';
47
+ readonly chainId: string;
48
+ readonly fleetActive: boolean;
49
+ readonly fleetRoot: string;
50
+ readonly genesisRoot: string;
51
+ readonly grants: readonly FleetGrantState[];
52
+ readonly headRoot?: string;
53
+ readonly members: readonly FleetMemberState[];
54
+ readonly owner: string;
55
+ readonly publicationBlock: number;
56
+ readonly status: 'folded';
57
+ }
58
+ export interface FleetFoldFailure {
59
+ readonly assurance: 'validated-input-only';
60
+ readonly reason: 'resource-limit' | 'missing-declaration' | 'invalid-input' | 'invalid-transition' | 'missing-predecessor' | 'bootstrap' | 'successor' | 'definition' | 'cancelled';
61
+ readonly status: 'incomplete' | 'conflict' | 'unsupported' | 'aborted';
62
+ }
63
+ export type FleetFoldResult = FoldedFleetView | FleetFoldFailure;
64
+ /**
65
+ * Pure B4 lifecycle fold of caller-validated facts. It never claims authenticated or complete history.
66
+ * A native finalized-evidence composition must prove original root/signature/carrying correspondence,
67
+ * every height's fork identity, the exact anchor and complete enumeration before using it as authority.
68
+ */
69
+ export declare function foldFleetControls(options: FoldFleetControlsOptions): FleetFoldResult;
70
+ export interface FleetPublisherMatch {
71
+ readonly assurance: 'validated-input-only';
72
+ readonly grant?: FleetGrantState;
73
+ readonly status: 'matched' | 'absent' | 'conflict';
74
+ }
75
+ /** Match only within the supplied fold; this supplies no public authorization or completeness claim. */
76
+ export declare function matchFleetPublisher(view: FoldedFleetView, scopeRoot: string, publisherAddress: string): FleetPublisherMatch;
77
+ //# sourceMappingURL=fleetFold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleetFold.d.ts","sourceRoot":"","sources":["../../src/f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AqB,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,CAAA;IACnL,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,CAAA;CACvE;AACD,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,gBAAgB,CAAA;AAwLhE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,eAAe,CAqBpF;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAA;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAA;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAA;CACnD;AACD,wGAAwG;AACxG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,mBAAmB,CAU3H"}
@@ -0,0 +1,5 @@
1
+ /** Native-brand admission without consulting shadowable caller instance properties. */
2
+ export declare function captureFleetSignal(value: unknown): AbortSignal | undefined;
3
+ export declare function fleetSignalAborted(signal: AbortSignal): boolean;
4
+ export declare function listenFleetAbort(signal: AbortSignal | undefined, listener: () => void): () => void;
5
+ //# sourceMappingURL=fleetSignal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleetSignal.d.ts","sourceRoot":"","sources":["../../src/fleetSignal.ts"],"names":[],"mappings":"AAOA,uFAAuF;AACvF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAK1E;AACD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAG/D;AACD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAMlG"}
@@ -1,5 +1,9 @@
1
+ export * from './fleetConfiguration.js';
2
+ export * from './fleetFold.js';
1
3
  export { DEFAULT_RESOLUTION_LIMITS, DEFAULT_VERIFICATION_LIMITS } from './limits.js';
4
+ export * from './resolveFleetPayload.js';
2
5
  export { resolveObject } from './resolveObject.js';
3
6
  export type { AbortedResolution, AttemptStatus, ConfiguredSeed, ContentPayload, InvalidObject, JsonObject, JsonValue, ObjectResolutionResult, ObjectVerificationFailureReason, ObjectVerificationResult, PublicObjectReader, PublicObjectReadOptions, ResolutionAttempt, ResolutionLimits, ResolvedObject, ResolveObjectOptions, UnavailableObject, VerificationLimits, VerifiedObject, } from './types.js';
7
+ export * from './verifyFleetPayload.js';
4
8
  export { verifyObject } from './verifyObject.js';
5
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AACpF,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,YAAY,CAAA;AACnB,cAAc,yBAAyB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1,90 +1,5 @@
1
- // src/limits.ts
2
- var MAX_TIMER_DELAY_MS = 2147483647;
3
- var DEFAULT_VERIFICATION_LIMITS = Object.freeze({
4
- maxBodyBytes: 65536,
5
- maxDepth: 32,
6
- maxNodes: 1e4
7
- });
8
- var DEFAULT_RESOLUTION_LIMITS = Object.freeze({
9
- ...DEFAULT_VERIFICATION_LIMITS,
10
- maxSeeds: 16,
11
- maxCandidatesPerSeed: 16,
12
- attemptTimeoutMs: 2e3,
13
- totalTimeoutMs: 1e4
14
- });
15
- function positiveInteger(value, name) {
16
- if (!Number.isSafeInteger(value) || value <= 0) {
17
- throw new RangeError(name + " must be a positive safe integer");
18
- }
19
- }
20
- function verificationLimits(options = {}) {
21
- const limits = { ...DEFAULT_VERIFICATION_LIMITS, ...options };
22
- positiveInteger(limits.maxBodyBytes, "maxBodyBytes");
23
- positiveInteger(limits.maxDepth, "maxDepth");
24
- positiveInteger(limits.maxNodes, "maxNodes");
25
- return Object.freeze(limits);
26
- }
27
- function resolutionLimits(options = {}) {
28
- const limits = { ...DEFAULT_RESOLUTION_LIMITS, ...options };
29
- verificationLimits(limits);
30
- positiveInteger(limits.maxSeeds, "maxSeeds");
31
- positiveInteger(limits.maxCandidatesPerSeed, "maxCandidatesPerSeed");
32
- positiveInteger(limits.attemptTimeoutMs, "attemptTimeoutMs");
33
- positiveInteger(limits.totalTimeoutMs, "totalTimeoutMs");
34
- if (limits.attemptTimeoutMs > MAX_TIMER_DELAY_MS || limits.totalTimeoutMs > MAX_TIMER_DELAY_MS) {
35
- throw new RangeError("Timeouts must fit a signed 32-bit millisecond timer");
36
- }
37
- return Object.freeze(limits);
38
- }
39
-
40
- // src/resolveObject.ts
41
- import { ObjectReferenceZod as ObjectReferenceZod2 } from "@xyo-network/service-kit-schemas";
42
-
43
- // src/clock.ts
44
- function monotonicClock() {
45
- const clock = "performance" in globalThis ? globalThis.performance : void 0;
46
- if (typeof clock !== "object" || clock === null || !("now" in clock) || typeof clock.now !== "function") {
47
- throw new TypeError("Object resolution requires performance.now()");
48
- }
49
- const read = clock.now.bind(clock);
50
- return () => {
51
- const now = read();
52
- if (typeof now !== "number" || !Number.isFinite(now)) throw new TypeError("Invalid monotonic clock");
53
- return now;
54
- };
55
- }
56
- function scheduleDeadline(now, deadline, expired) {
57
- let cancelled = false;
58
- let timer;
59
- const tick = () => {
60
- if (cancelled) return;
61
- if (now() >= deadline) {
62
- cancelled = true;
63
- expired();
64
- } else {
65
- arm();
66
- }
67
- };
68
- const arm = () => {
69
- const delay = Math.min(MAX_TIMER_DELAY_MS, Math.max(1, Math.ceil(deadline - now())));
70
- timer = setTimeout(tick, delay);
71
- };
72
- arm();
73
- return () => {
74
- cancelled = true;
75
- clearTimeout(timer);
76
- };
77
- }
78
-
79
- // src/verifyObject.ts
80
- import { isAnyPayload, PayloadBuilder } from "@xyo-network/sdk-protocol";
81
- import {
82
- DataLakeLocatorSchema,
83
- DataLakeLocatorZod,
84
- ObjectReferenceZod,
85
- ServiceAdvertisementSchema,
86
- ServiceAdvertisementZod
87
- } from "@xyo-network/service-kit-schemas";
1
+ // src/fleetConfiguration.ts
2
+ import { AddressZod, HashZod } from "@xyo-network/service-kit-schemas";
88
3
 
89
4
  // src/jsonSnapshot.ts
90
5
  var ObjectInputError = class extends Error {
@@ -185,7 +100,603 @@ function snapshotJson(candidate, limits) {
185
100
  }, 0);
186
101
  }
187
102
 
103
+ // src/fleetConfiguration.ts
104
+ function selectedProfile(configuration) {
105
+ const profile = snapshotJson(configuration, {
106
+ maxBodyBytes: 1024,
107
+ maxDepth: 2,
108
+ maxNodes: 16
109
+ });
110
+ const keys = ["fleetRoot", "maxConfigurationBytes", "maxMembers", "maxRevisionBytes", "maxTotalBytes", "owner"];
111
+ if (Object.keys(profile).toSorted().join(",") !== keys.join(",")) throw new TypeError("Select a strict complete private configuration profile");
112
+ AddressZod.parse(profile.owner);
113
+ HashZod.parse(profile.fleetRoot);
114
+ for (const value of [profile.maxConfigurationBytes, profile.maxMembers, profile.maxRevisionBytes, profile.maxTotalBytes]) {
115
+ if (!Number.isSafeInteger(value) || value <= 0) throw new RangeError("Select finite positive private configuration limits");
116
+ }
117
+ if (profile.maxConfigurationBytes > profile.maxTotalBytes) throw new RangeError("Configuration cap must fit total storage cap");
118
+ return Object.freeze({ ...profile });
119
+ }
120
+ function pinConfiguration(configuration) {
121
+ const keys = ["bytes", "memberRoot", "revision"];
122
+ if (Reflect.ownKeys(configuration).length !== keys.length) throw new TypeError("Opaque provision requires a closed data record");
123
+ const values = {};
124
+ for (const key of keys) {
125
+ const property = Object.getOwnPropertyDescriptor(configuration, key);
126
+ if (property?.enumerable !== true || !("value" in property)) throw new TypeError("Opaque provision requires own data properties");
127
+ values[key] = property.value;
128
+ }
129
+ return Object.freeze(values);
130
+ }
131
+ function copyBytes(bytes, maxBytes) {
132
+ if (!(bytes instanceof Uint8Array) || Object.getPrototypeOf(bytes) !== Uint8Array.prototype) throw new TypeError("Opaque configuration must be plain Uint8Array");
133
+ if (bytes.byteLength > maxBytes) throw new RangeError("Opaque configuration exceeds selected cap");
134
+ return Uint8Array.from(bytes);
135
+ }
136
+ var encoder2 = new TextEncoder();
137
+ function checkRevision(revision, maximum) {
138
+ if (typeof revision !== "string" || revision.length === 0 || revision.length > maximum || encoder2.encode(revision).byteLength > maximum) {
139
+ throw new RangeError("Opaque revision must fit its selected byte cap");
140
+ }
141
+ }
142
+ function sameBytes(left, right) {
143
+ return left.length === right.length && left.every((value, index) => value === right[index]);
144
+ }
145
+ function createLocalFleetConfigurationStore(configurationProfile) {
146
+ const profile = selectedProfile(configurationProfile);
147
+ const desired = /* @__PURE__ */ new Map();
148
+ const received = /* @__PURE__ */ new Map();
149
+ let totalBytes = 0;
150
+ const provide = (memberRoot) => {
151
+ HashZod.parse(memberRoot);
152
+ const current = desired.get(memberRoot);
153
+ return current === void 0 ? void 0 : Object.freeze({
154
+ memberRoot,
155
+ revision: current.revision,
156
+ bytes: Uint8Array.from(current.bytes)
157
+ });
158
+ };
159
+ const provision = (input) => {
160
+ const configuration = pinConfiguration(input);
161
+ HashZod.parse(configuration.memberRoot);
162
+ checkRevision(configuration.revision, profile.maxRevisionBytes);
163
+ const bytes = copyBytes(configuration.bytes, profile.maxConfigurationBytes);
164
+ const prior = desired.get(configuration.memberRoot);
165
+ if (prior?.revision === configuration.revision && !sameBytes(prior.bytes, bytes)) throw new TypeError("An opaque revision cannot name different bytes");
166
+ if (prior === void 0 && desired.size >= profile.maxMembers) throw new RangeError("Private member capacity exceeded");
167
+ const nextBytes = totalBytes - (prior?.bytes.byteLength ?? 0) + bytes.byteLength;
168
+ if (nextBytes > profile.maxTotalBytes) throw new RangeError("Private storage capacity exceeded");
169
+ if (prior?.revision !== configuration.revision) received.delete(configuration.memberRoot);
170
+ desired.set(configuration.memberRoot, { revision: configuration.revision, bytes });
171
+ totalBytes = nextBytes;
172
+ };
173
+ const acknowledge = (memberRoot, revision) => {
174
+ HashZod.parse(memberRoot);
175
+ checkRevision(revision, profile.maxRevisionBytes);
176
+ const current = desired.get(memberRoot);
177
+ const status = current === void 0 ? "missing" : current.revision === revision ? "acknowledged" : "stale";
178
+ const result = Object.freeze({
179
+ status,
180
+ assurance: "private-provision-only",
181
+ memberRoot,
182
+ revision
183
+ });
184
+ if (status === "acknowledged") received.set(memberRoot, result);
185
+ return result;
186
+ };
187
+ const acknowledgment = (memberRoot) => {
188
+ HashZod.parse(memberRoot);
189
+ return received.get(memberRoot);
190
+ };
191
+ return Object.freeze({
192
+ provide,
193
+ provision,
194
+ acknowledge,
195
+ acknowledgment
196
+ });
197
+ }
198
+
199
+ // src/fleetFold.ts
200
+ import {
201
+ AddressZod as AddressZod2,
202
+ ChainIdZod,
203
+ FleetControlSchema,
204
+ FleetControlZod,
205
+ FleetMemberZod,
206
+ FleetPublicationScopeZod,
207
+ FleetZod,
208
+ HashZod as HashZod2,
209
+ parseFleetPayload
210
+ } from "@xyo-network/service-kit-schemas";
211
+
212
+ // src/fleetSignal.ts
213
+ var abortedDescriptor = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted");
214
+ var abortedGetter = Reflect.get(abortedDescriptor ?? {}, "get");
215
+ var nativeEvents = EventTarget.prototype;
216
+ var addListener = nativeEvents.addEventListener;
217
+ var removeListener = nativeEvents.removeEventListener;
218
+ var apply = Reflect.apply;
219
+ function captureFleetSignal(value) {
220
+ if (value === void 0) return;
221
+ if (typeof abortedGetter !== "function") throw new TypeError("Native AbortSignal is required");
222
+ apply(abortedGetter, value, []);
223
+ return value;
224
+ }
225
+ function fleetSignalAborted(signal) {
226
+ if (typeof abortedGetter !== "function") throw new TypeError("Native AbortSignal is required");
227
+ return apply(abortedGetter, signal, []);
228
+ }
229
+ function listenFleetAbort(signal, listener) {
230
+ if (signal === void 0) return () => {
231
+ };
232
+ apply(addListener, signal, ["abort", listener, { once: true }]);
233
+ return () => {
234
+ apply(removeListener, signal, ["abort", listener]);
235
+ };
236
+ }
237
+
238
+ // src/limits.ts
239
+ var MAX_TIMER_DELAY_MS = 2147483647;
240
+ var DEFAULT_VERIFICATION_LIMITS = Object.freeze({
241
+ maxBodyBytes: 65536,
242
+ maxDepth: 32,
243
+ maxNodes: 1e4
244
+ });
245
+ var DEFAULT_RESOLUTION_LIMITS = Object.freeze({
246
+ ...DEFAULT_VERIFICATION_LIMITS,
247
+ maxSeeds: 16,
248
+ maxCandidatesPerSeed: 16,
249
+ attemptTimeoutMs: 2e3,
250
+ totalTimeoutMs: 1e4
251
+ });
252
+ function positiveInteger(value, name) {
253
+ if (!Number.isSafeInteger(value) || value <= 0) {
254
+ throw new RangeError(name + " must be a positive safe integer");
255
+ }
256
+ }
257
+ function verificationLimits(options = {}) {
258
+ const limits = { ...DEFAULT_VERIFICATION_LIMITS, ...options };
259
+ positiveInteger(limits.maxBodyBytes, "maxBodyBytes");
260
+ positiveInteger(limits.maxDepth, "maxDepth");
261
+ positiveInteger(limits.maxNodes, "maxNodes");
262
+ return Object.freeze(limits);
263
+ }
264
+ function resolutionLimits(options = {}) {
265
+ const limits = { ...DEFAULT_RESOLUTION_LIMITS, ...options };
266
+ verificationLimits(limits);
267
+ positiveInteger(limits.maxSeeds, "maxSeeds");
268
+ positiveInteger(limits.maxCandidatesPerSeed, "maxCandidatesPerSeed");
269
+ positiveInteger(limits.attemptTimeoutMs, "attemptTimeoutMs");
270
+ positiveInteger(limits.totalTimeoutMs, "totalTimeoutMs");
271
+ if (limits.attemptTimeoutMs > MAX_TIMER_DELAY_MS || limits.totalTimeoutMs > MAX_TIMER_DELAY_MS) {
272
+ throw new RangeError("Timeouts must fit a signed 32-bit millisecond timer");
273
+ }
274
+ return Object.freeze(limits);
275
+ }
276
+
277
+ // src/fleetFold.ts
278
+ function failure(status, reason) {
279
+ return Object.freeze({
280
+ status,
281
+ reason,
282
+ assurance: "validated-input-only"
283
+ });
284
+ }
285
+ function safeBlock(value) {
286
+ return Number.isSafeInteger(value) && value >= 0;
287
+ }
288
+ function selectedLimits(limits) {
289
+ const pinned = snapshotJson(limits, {
290
+ maxBodyBytes: 1024,
291
+ maxDepth: 2,
292
+ maxNodes: 16
293
+ });
294
+ const keys = ["maxBodyBytes", "maxControls", "maxDeclarations", "maxDepth", "maxGrants", "maxMembers", "maxNodes"];
295
+ if (Object.keys(pinned).toSorted().join(",") !== keys.join(",")) throw new TypeError("Select a strict complete fleet fold profile");
296
+ verificationLimits(pinned);
297
+ for (const value of [pinned.maxControls, pinned.maxDeclarations, pinned.maxGrants, pinned.maxMembers]) {
298
+ if (!Number.isSafeInteger(value) || value <= 0) throw new RangeError("Select finite positive fold limits");
299
+ }
300
+ return Object.freeze({ ...pinned });
301
+ }
302
+ function boundedSlots(values, maximum) {
303
+ if (!Array.isArray(values) || values.length > maximum) throw new RangeError("Fleet input exceeds selected limit");
304
+ return Object.freeze(Array.from({ length: values.length }, (_, index) => {
305
+ const descriptor = Object.getOwnPropertyDescriptor(values, String(index));
306
+ if (descriptor?.enumerable !== true || !("value" in descriptor)) throw new TypeError("Fleet inputs require dense own data slots");
307
+ return descriptor.value;
308
+ }));
309
+ }
310
+ function declarationMap(facts, limits) {
311
+ const declarations = /* @__PURE__ */ new Map();
312
+ for (const input of facts) {
313
+ const fact = snapshotJson(input, limits);
314
+ HashZod2.parse(fact.root);
315
+ const payload = parseFleetPayload(fact.payload);
316
+ if (payload === void 0 || payload.schema === FleetControlSchema || declarations.has(fact.root)) throw new TypeError("Invalid fleet declaration fact");
317
+ declarations.set(fact.root, payload);
318
+ }
319
+ return declarations;
320
+ }
321
+ function positionAfter(left, right) {
322
+ return left.block > right.block || left.block === right.block && (left.transactionIndex > right.transactionIndex || left.transactionIndex === right.transactionIndex && left.payloadIndex > right.payloadIndex);
323
+ }
324
+ function controlFact(fact, limits) {
325
+ const pinned = snapshotJson(fact, limits);
326
+ const isValidPosition = safeBlock(pinned.block) && safeBlock(pinned.transactionIndex) && safeBlock(pinned.payloadIndex);
327
+ const hasCanonicalLabels = AddressZod2.safeParse(pinned.authorizer).success && ChainIdZod.safeParse(pinned.chainId).success && HashZod2.safeParse(pinned.root).success;
328
+ if (!isValidPosition || !hasCanonicalLabels) return;
329
+ const parsed = FleetControlZod.safeParse(pinned.payload);
330
+ return parsed.success ? { ...pinned, payload: parsed.data } : void 0;
331
+ }
332
+ function member(state, root, fleetRoot) {
333
+ const parsed = FleetMemberZod.safeParse(state.declarations.get(root));
334
+ return parsed.success && parsed.data.fleetRoot === fleetRoot ? parsed.data : void 0;
335
+ }
336
+ function scope(state, root, fleetRoot) {
337
+ const parsed = FleetPublicationScopeZod.safeParse(state.declarations.get(root));
338
+ return parsed.success && parsed.data.fleetRoot === fleetRoot ? parsed.data : void 0;
339
+ }
340
+ function clearMemberGrants(state, memberRoot) {
341
+ for (const [key, grant] of state.grants) {
342
+ if (grant.memberRoot === memberRoot) state.grants.delete(key);
343
+ }
344
+ }
345
+ function grantKey(payload) {
346
+ return `${payload.memberRoot}:${payload.scopeRoot}:${payload.publisherAddress}`;
347
+ }
348
+ function changeMember(state, payload, limits) {
349
+ if (member(state, payload.memberRoot, payload.fleetRoot) === void 0) return failure("incomplete", "missing-declaration");
350
+ if (payload.operation === "activate-member" && !state.active) return failure("incomplete", "invalid-transition");
351
+ state.members.set(payload.memberRoot, payload.operation === "activate-member");
352
+ if (state.members.size > limits.maxMembers) return failure("incomplete", "resource-limit");
353
+ if (payload.operation === "remove-member") clearMemberGrants(state, payload.memberRoot);
354
+ }
355
+ function changeGrant(state, fact, payload, limits) {
356
+ const selectedMember = member(state, payload.memberRoot, payload.fleetRoot);
357
+ const selectedScope = scope(state, payload.scopeRoot, payload.fleetRoot);
358
+ if (selectedMember === void 0 || selectedScope === void 0) return failure("incomplete", "missing-declaration");
359
+ if (selectedMember.roleId !== selectedScope.roleId) return failure("incomplete", "invalid-transition");
360
+ const key = grantKey(payload);
361
+ if (payload.operation === "remove-publisher") {
362
+ state.grants.delete(key);
363
+ return;
364
+ }
365
+ if (!state.active || state.members.get(payload.memberRoot) !== true) return failure("incomplete", "invalid-transition");
366
+ const activation = fact.block + 1;
367
+ if (!Number.isSafeInteger(activation) || payload.expiresAtBlock !== void 0 && payload.expiresAtBlock <= activation) {
368
+ return failure("incomplete", "invalid-transition");
369
+ }
370
+ state.grants.set(key, Object.freeze({
371
+ memberRoot: payload.memberRoot,
372
+ scopeRoot: payload.scopeRoot,
373
+ publisherAddress: payload.publisherAddress,
374
+ controlRoot: fact.root,
375
+ ...payload.expiresAtBlock !== void 0 && { expiresAtBlock: payload.expiresAtBlock }
376
+ }));
377
+ if (state.grants.size > limits.maxGrants) return failure("incomplete", "resource-limit");
378
+ }
379
+ function applyControl(state, fact, limits) {
380
+ const payload = fact.payload;
381
+ switch (payload.operation) {
382
+ case "activate-fleet": {
383
+ state.active = true;
384
+ return;
385
+ }
386
+ case "remove-fleet": {
387
+ state.active = false;
388
+ state.grants.clear();
389
+ return;
390
+ }
391
+ case "activate-member":
392
+ case "remove-member": {
393
+ return changeMember(state, payload, limits);
394
+ }
395
+ case "grant-publisher":
396
+ case "remove-publisher": {
397
+ return changeGrant(state, fact, payload, limits);
398
+ }
399
+ }
400
+ }
401
+ function advance(state, fact, limits) {
402
+ if (state.seen.has(fact.root)) return;
403
+ const previous = fact.payload.previousControlRoot;
404
+ if (state.head === void 0 && (previous !== void 0 || fact.payload.operation !== "activate-fleet")) return failure("incomplete", "missing-predecessor");
405
+ if (previous === void 0 && state.head !== void 0) return failure("conflict", "bootstrap");
406
+ if (state.head !== void 0 && previous !== state.head) {
407
+ return state.seen.has(previous ?? "") ? failure("conflict", "successor") : failure("incomplete", "missing-predecessor");
408
+ }
409
+ const error = applyControl(state, fact, limits);
410
+ if (error !== void 0) return error;
411
+ state.head = fact.root;
412
+ state.seen.add(fact.root);
413
+ }
414
+ function foldedView(state, options) {
415
+ const members = [...state.members].map(([root, active]) => {
416
+ const declaration = member(state, root, options.fleetRoot);
417
+ if (declaration === void 0) throw new TypeError("Missing applied member");
418
+ return Object.freeze({
419
+ root,
420
+ active,
421
+ roleId: declaration.roleId
422
+ });
423
+ });
424
+ const grants = state.grants.values().filter((grant) => grant.expiresAtBlock === void 0 || options.publicationBlock < grant.expiresAtBlock).toArray();
425
+ return Object.freeze({
426
+ status: "folded",
427
+ assurance: "validated-input-only",
428
+ owner: options.owner,
429
+ fleetRoot: options.fleetRoot,
430
+ chainId: options.chainId,
431
+ genesisRoot: options.genesisRoot,
432
+ publicationBlock: options.publicationBlock,
433
+ fleetActive: state.active,
434
+ ...state.head !== void 0 && { headRoot: state.head },
435
+ members: Object.freeze(members),
436
+ grants: Object.freeze(grants)
437
+ });
438
+ }
439
+ function foldFacts(state, facts, options, limits) {
440
+ let previous;
441
+ for (const input of facts) {
442
+ if (options.signal !== void 0 && fleetSignalAborted(options.signal)) return failure("aborted", "cancelled");
443
+ const fact = controlFact(input, limits);
444
+ if (fact === void 0) return failure("unsupported", "definition");
445
+ if (fact.block > options.publicationBlock || previous !== void 0 && !positionAfter(fact, previous)) return failure("incomplete", "invalid-input");
446
+ previous = fact;
447
+ if (fact.chainId !== options.chainId || fact.authorizer !== options.owner || fact.payload.fleetRoot !== options.fleetRoot || fact.block === options.publicationBlock) continue;
448
+ const error = advance(state, fact, limits);
449
+ if (error !== void 0) return error;
450
+ }
451
+ return foldedView(state, options);
452
+ }
453
+ function foldFleetControls(options) {
454
+ const limits = selectedLimits(options.limits);
455
+ const signal = captureFleetSignal(options.signal);
456
+ AddressZod2.parse(options.owner);
457
+ HashZod2.parse(options.fleetRoot);
458
+ HashZod2.parse(options.genesisRoot);
459
+ ChainIdZod.parse(options.chainId);
460
+ if (!safeBlock(options.publicationBlock)) throw new RangeError("Publication block must be a nonnegative safe integer");
461
+ if (options.signal !== void 0 && fleetSignalAborted(options.signal)) return failure("aborted", "cancelled");
462
+ try {
463
+ const declarations = declarationMap(boundedSlots(options.declarations, limits.maxDeclarations), limits);
464
+ const fleet = FleetZod.safeParse(declarations.get(options.fleetRoot));
465
+ if (!fleet.success) return failure("incomplete", "missing-declaration");
466
+ if (fleet.data.owner !== options.owner) return failure("incomplete", "invalid-input");
467
+ const state = {
468
+ active: false,
469
+ declarations,
470
+ grants: /* @__PURE__ */ new Map(),
471
+ members: /* @__PURE__ */ new Map(),
472
+ seen: /* @__PURE__ */ new Set()
473
+ };
474
+ return foldFacts(state, boundedSlots(options.controls, limits.maxControls), { ...options, signal }, limits);
475
+ } catch (error) {
476
+ return failure("incomplete", error instanceof RangeError ? "resource-limit" : "invalid-input");
477
+ }
478
+ }
479
+ function matchFleetPublisher(view, scopeRoot, publisherAddress) {
480
+ HashZod2.parse(scopeRoot);
481
+ AddressZod2.parse(publisherAddress);
482
+ const matching = view.fleetActive ? view.grants.filter((grant) => grant.scopeRoot === scopeRoot && grant.publisherAddress === publisherAddress) : [];
483
+ if (matching.length > 1) return Object.freeze({ status: "conflict", assurance: "validated-input-only" });
484
+ return matching.length === 0 ? Object.freeze({ status: "absent", assurance: "validated-input-only" }) : Object.freeze({
485
+ status: "matched",
486
+ assurance: "validated-input-only",
487
+ grant: matching[0]
488
+ });
489
+ }
490
+
491
+ // src/resolveFleetPayload.ts
492
+ import { HashZod as HashZod4 } from "@xyo-network/service-kit-schemas";
493
+
494
+ // src/clock.ts
495
+ function monotonicClock() {
496
+ const clock = "performance" in globalThis ? globalThis.performance : void 0;
497
+ if (typeof clock !== "object" || clock === null || !("now" in clock) || typeof clock.now !== "function") {
498
+ throw new TypeError("Object resolution requires performance.now()");
499
+ }
500
+ const read = clock.now.bind(clock);
501
+ return () => {
502
+ const now = read();
503
+ if (typeof now !== "number" || !Number.isFinite(now)) throw new TypeError("Invalid monotonic clock");
504
+ return now;
505
+ };
506
+ }
507
+ function scheduleDeadline(now, deadline, expired) {
508
+ let cancelled = false;
509
+ let timer;
510
+ const tick = () => {
511
+ if (cancelled) return;
512
+ if (now() >= deadline) {
513
+ cancelled = true;
514
+ expired();
515
+ } else {
516
+ arm();
517
+ }
518
+ };
519
+ const arm = () => {
520
+ const delay = Math.min(MAX_TIMER_DELAY_MS, Math.max(1, Math.ceil(deadline - now())));
521
+ timer = setTimeout(tick, delay);
522
+ };
523
+ arm();
524
+ return () => {
525
+ cancelled = true;
526
+ clearTimeout(timer);
527
+ };
528
+ }
529
+
530
+ // src/verifyFleetPayload.ts
531
+ import { isAnyPayload, PayloadBuilder } from "@xyo-network/sdk-protocol";
532
+ import {
533
+ FLEET_PAYLOAD_VERSION,
534
+ HashZod as HashZod3,
535
+ parseFleetPayload as parseFleetPayload2
536
+ } from "@xyo-network/service-kit-schemas";
537
+ async function verifyFleetPayload(root, family, candidate, options = {}) {
538
+ HashZod3.parse(root);
539
+ const limits = verificationLimits(options);
540
+ try {
541
+ const snapshot = snapshotJson(candidate, limits);
542
+ if (snapshot === null || typeof snapshot !== "object" || Array.isArray(snapshot) || !isAnyPayload(snapshot)) {
543
+ return Object.freeze({ status: "invalid", reason: "invalid-envelope" });
544
+ }
545
+ if (await PayloadBuilder.hash(snapshot) !== root) return Object.freeze({ status: "invalid", reason: "hash-mismatch" });
546
+ if (snapshot.schema !== family) return Object.freeze({ status: "unsupported", reason: "family" });
547
+ if (snapshot.$version !== FLEET_PAYLOAD_VERSION) return Object.freeze({ status: "unsupported", reason: "version" });
548
+ const body = PayloadBuilder.omitStorageMeta(snapshot);
549
+ if (parseFleetPayload2(body) === void 0) return Object.freeze({ status: "invalid", reason: "invalid-envelope" });
550
+ return Object.freeze({
551
+ status: "verified",
552
+ assurance: "sdk-root-verified",
553
+ root,
554
+ nativePayload: snapshot,
555
+ payload: snapshotJson(body, limits)
556
+ });
557
+ } catch (error) {
558
+ const reason = error instanceof ObjectInputError && (error.reason === "body-too-large" || error.reason === "structure-limit") ? error.reason : "invalid-json";
559
+ return Object.freeze({ status: "invalid", reason });
560
+ }
561
+ }
562
+
563
+ // src/resolveFleetPayload.ts
564
+ function pinSeeds(value, maxSeeds) {
565
+ if (!Array.isArray(value) || value.length === 0 || value.length > maxSeeds) throw new RangeError("Explicit bounded readers required");
566
+ const ids = /* @__PURE__ */ new Set();
567
+ return Object.freeze(Array.from({ length: value.length }, (_, index) => {
568
+ const slot = Object.getOwnPropertyDescriptor(value, String(index));
569
+ if (slot?.enumerable !== true || !("value" in slot)) throw new TypeError("Reader slots must be dense own data");
570
+ const seed = slot.value;
571
+ const idSlot = Object.getOwnPropertyDescriptor(seed, "id");
572
+ const readerSlot = Object.getOwnPropertyDescriptor(seed, "reader");
573
+ if (idSlot === void 0 || readerSlot === void 0 || !("value" in idSlot) || !("value" in readerSlot)) {
574
+ throw new TypeError("Reader configuration must use own data properties");
575
+ }
576
+ const id = idSlot.value;
577
+ if (typeof id !== "string" || id.length === 0 || id.length > 128 || id.trim() !== id || ids.has(id)) {
578
+ throw new TypeError("Each reader requires a unique bounded ID");
579
+ }
580
+ const reader = readerSlot.value;
581
+ if (typeof reader !== "object" || reader === null) throw new TypeError("Each reader requires get");
582
+ const methodSlot = Object.getOwnPropertyDescriptor(reader, "get");
583
+ if (methodSlot === void 0 || !("value" in methodSlot) || typeof methodSlot.value !== "function") {
584
+ throw new TypeError("Each reader requires an own data get method");
585
+ }
586
+ const get = methodSlot.value;
587
+ ids.add(id);
588
+ return Object.freeze({ id, get: get.bind(reader) });
589
+ }));
590
+ }
591
+ async function readSeed(seed, root, family, limits, signal, expired) {
592
+ if (fleetSignalAborted(signal) || expired()) return { status: "timeout" };
593
+ const response = await seed.get([root], { signal, maxBodyBytes: limits.maxBodyBytes });
594
+ if (fleetSignalAborted(signal) || expired()) return { status: "timeout" };
595
+ if (!Array.isArray(response) || response.length > limits.maxCandidatesPerSeed) return { status: "resource-limit" };
596
+ const candidates = Array.from({ length: response.length }, (_, index) => Object.getOwnPropertyDescriptor(response, String(index)));
597
+ let status = candidates.length === 0 ? "missing" : "invalid";
598
+ for (const slot of candidates) {
599
+ if (fleetSignalAborted(signal) || expired()) return { status: "timeout" };
600
+ if (slot?.enumerable !== true || !("value" in slot)) continue;
601
+ const result = await verifyFleetPayload(root, family, slot.value, limits);
602
+ if (fleetSignalAborted(signal) || expired()) return { status: "timeout" };
603
+ if (result.status === "verified") return { status: "resolved", payload: result };
604
+ if (result.status === "unsupported") status = "unsupported";
605
+ }
606
+ return { status };
607
+ }
608
+ function attemptSeed(seed, root, family, limits, signal, now, totalDeadline) {
609
+ const deadline = Math.min(totalDeadline, now() + limits.attemptTimeoutMs);
610
+ const expired = () => now() >= deadline;
611
+ return new Promise((resolve) => {
612
+ const controller = new AbortController();
613
+ let isSettled = false;
614
+ const finish = (result) => {
615
+ if (isSettled) return;
616
+ isSettled = true;
617
+ cancelTimer();
618
+ unlisten();
619
+ controller.abort();
620
+ resolve(expired() ? { status: "timeout" } : result);
621
+ };
622
+ const onAbort = () => finish({ status: "timeout" });
623
+ const cancelTimer = scheduleDeadline(now, deadline, () => finish({ status: "timeout" }));
624
+ const unlisten = listenFleetAbort(signal, onAbort);
625
+ if (fleetSignalAborted(signal)) {
626
+ onAbort();
627
+ return;
628
+ }
629
+ queueMicrotask(() => {
630
+ void (async () => {
631
+ let result;
632
+ try {
633
+ result = await readSeed(seed, root, family, limits, controller.signal, expired);
634
+ } catch {
635
+ result = { status: "reader-error" };
636
+ }
637
+ finish(result);
638
+ })();
639
+ });
640
+ });
641
+ }
642
+ async function resolveFleetPayload(root, family, options) {
643
+ HashZod4.parse(root);
644
+ const limits = resolutionLimits(options.limits);
645
+ const seeds = pinSeeds(options.seeds, limits.maxSeeds);
646
+ const signal = captureFleetSignal(options.signal);
647
+ const now = monotonicClock();
648
+ const deadline = now() + limits.totalTimeoutMs;
649
+ const attempts = [];
650
+ const controller = new AbortController();
651
+ const state = {};
652
+ const terminate = (reason) => {
653
+ state.terminal ??= reason;
654
+ controller.abort();
655
+ };
656
+ const onAbort = () => terminate("aborted");
657
+ const unlisten = listenFleetAbort(signal, onAbort);
658
+ if (signal !== void 0 && fleetSignalAborted(signal)) onAbort();
659
+ const cancelTotal = scheduleDeadline(now, deadline, () => terminate("deadline"));
660
+ try {
661
+ for (const seed of seeds) {
662
+ if (now() >= deadline) terminate("deadline");
663
+ if (state.terminal !== void 0) break;
664
+ const result = await attemptSeed(seed, root, family, limits, controller.signal, now, deadline);
665
+ attempts.push(Object.freeze({ seedId: seed.id, status: result.status }));
666
+ if (now() >= deadline) terminate("deadline");
667
+ if (state.terminal !== void 0) break;
668
+ if (result.payload !== void 0) return Object.freeze({ ...result.payload, attempts: Object.freeze(attempts) });
669
+ if (result.status === "resource-limit") return Object.freeze({
670
+ status: "incomplete",
671
+ reason: "resource-limit",
672
+ attempts: Object.freeze(attempts)
673
+ });
674
+ }
675
+ const frozen = Object.freeze(attempts);
676
+ return state.terminal === "aborted" ? Object.freeze({ status: "aborted", attempts: frozen }) : Object.freeze({
677
+ status: "incomplete",
678
+ reason: state.terminal === "deadline" ? "deadline" : "unavailable",
679
+ attempts: frozen
680
+ });
681
+ } finally {
682
+ cancelTotal();
683
+ controller.abort();
684
+ unlisten();
685
+ }
686
+ }
687
+
688
+ // src/resolveObject.ts
689
+ import { ObjectReferenceZod as ObjectReferenceZod2 } from "@xyo-network/service-kit-schemas";
690
+
188
691
  // src/verifyObject.ts
692
+ import { isAnyPayload as isAnyPayload2, PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-protocol";
693
+ import {
694
+ DataLakeLocatorSchema,
695
+ DataLakeLocatorZod,
696
+ ObjectReferenceZod,
697
+ ServiceAdvertisementSchema,
698
+ ServiceAdvertisementZod
699
+ } from "@xyo-network/service-kit-schemas";
189
700
  async function verifyObject(reference, candidate, options = {}) {
190
701
  const expected = Object.freeze(ObjectReferenceZod.parse(reference));
191
702
  const limits = verificationLimits(options);
@@ -194,9 +705,9 @@ async function verifyObject(reference, candidate, options = {}) {
194
705
  if (snapshot === null || typeof snapshot !== "object" || Array.isArray(snapshot)) {
195
706
  return { status: "invalid", reason: "not-payload" };
196
707
  }
197
- const data = PayloadBuilder.omitMeta(snapshot);
198
- if (!isAnyPayload(data)) return { status: "invalid", reason: "not-payload" };
199
- const actualHash = await PayloadBuilder.dataHash(data);
708
+ const data = PayloadBuilder2.omitMeta(snapshot);
709
+ if (!isAnyPayload2(data)) return { status: "invalid", reason: "not-payload" };
710
+ const actualHash = await PayloadBuilder2.dataHash(data);
200
711
  if (actualHash !== expected.dataHash) return { status: "invalid", reason: "hash-mismatch" };
201
712
  if (data.schema !== expected.schema) return { status: "invalid", reason: "schema-mismatch" };
202
713
  if (data.schema === ServiceAdvertisementSchema && !ServiceAdvertisementZod.safeParse(data).success) {
@@ -276,7 +787,7 @@ async function readCandidates(seed, reference, limits, signal, expired) {
276
787
  }
277
788
  return { status: "invalid-object", candidateFailures };
278
789
  }
279
- function attemptSeed(seed, reference, limits, outerSignal, now, totalDeadline) {
790
+ function attemptSeed2(seed, reference, limits, outerSignal, now, totalDeadline) {
280
791
  const deadline = Math.min(now() + limits.attemptTimeoutMs, totalDeadline);
281
792
  const expired = () => now() >= deadline;
282
793
  return new Promise((resolve) => {
@@ -348,7 +859,7 @@ async function resolveObject(reference, options) {
348
859
  for (const seed of seeds) {
349
860
  if (now() >= deadline) terminate("deadline-exceeded");
350
861
  if (state.terminal !== void 0) break;
351
- const result = await attemptSeed(seed, expected, limits, controller.signal, now, deadline);
862
+ const result = await attemptSeed2(seed, expected, limits, controller.signal, now, deadline);
352
863
  attempts.push(diagnostic(seed.id, result));
353
864
  if (now() >= deadline) terminate("deadline-exceeded");
354
865
  if (state.terminal !== void 0) break;
@@ -377,7 +888,12 @@ async function resolveObject(reference, options) {
377
888
  export {
378
889
  DEFAULT_RESOLUTION_LIMITS,
379
890
  DEFAULT_VERIFICATION_LIMITS,
891
+ createLocalFleetConfigurationStore,
892
+ foldFleetControls,
893
+ matchFleetPublisher,
894
+ resolveFleetPayload,
380
895
  resolveObject,
896
+ verifyFleetPayload,
381
897
  verifyObject
382
898
  };
383
899
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/limits.ts", "../../src/resolveObject.ts", "../../src/clock.ts", "../../src/verifyObject.ts", "../../src/jsonSnapshot.ts"],
4
- "sourcesContent": ["import type { ResolutionLimits, VerificationLimits } from './types.js'\n\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647\n\nexport const DEFAULT_VERIFICATION_LIMITS: VerificationLimits = Object.freeze({\n maxBodyBytes: 65_536,\n maxDepth: 32,\n maxNodes: 10_000,\n})\n\nexport const DEFAULT_RESOLUTION_LIMITS: ResolutionLimits = Object.freeze({\n ...DEFAULT_VERIFICATION_LIMITS,\n maxSeeds: 16,\n maxCandidatesPerSeed: 16,\n attemptTimeoutMs: 2000,\n totalTimeoutMs: 10_000,\n})\n\nfunction positiveInteger(value: number, name: string) {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new RangeError(name + ' must be a positive safe integer')\n }\n}\n\nexport function verificationLimits(options: Partial<VerificationLimits> = {}): VerificationLimits {\n const limits = { ...DEFAULT_VERIFICATION_LIMITS, ...options }\n positiveInteger(limits.maxBodyBytes, 'maxBodyBytes')\n positiveInteger(limits.maxDepth, 'maxDepth')\n positiveInteger(limits.maxNodes, 'maxNodes')\n return Object.freeze(limits)\n}\n\nexport function resolutionLimits(options: Partial<ResolutionLimits> = {}): ResolutionLimits {\n const limits = { ...DEFAULT_RESOLUTION_LIMITS, ...options }\n verificationLimits(limits)\n positiveInteger(limits.maxSeeds, 'maxSeeds')\n positiveInteger(limits.maxCandidatesPerSeed, 'maxCandidatesPerSeed')\n positiveInteger(limits.attemptTimeoutMs, 'attemptTimeoutMs')\n positiveInteger(limits.totalTimeoutMs, 'totalTimeoutMs')\n if (limits.attemptTimeoutMs > MAX_TIMER_DELAY_MS || limits.totalTimeoutMs > MAX_TIMER_DELAY_MS) {\n throw new RangeError('Timeouts must fit a signed 32-bit millisecond timer')\n }\n return Object.freeze(limits)\n}\n", "import type { ObjectReference } from '@xyo-network/service-kit-schemas'\nimport { ObjectReferenceZod } from '@xyo-network/service-kit-schemas'\n\nimport { monotonicClock, scheduleDeadline } from './clock.js'\nimport { resolutionLimits } from './limits.js'\nimport type {\n AttemptStatus,\n ConfiguredSeed,\n ObjectResolutionResult,\n ObjectVerificationFailureReason,\n ResolutionAttempt,\n ResolutionLimits,\n ResolveObjectOptions,\n VerifiedObject,\n} from './types.js'\nimport { verifyObject } from './verifyObject.js'\n\ninterface SeedResult {\n readonly candidateFailures?: readonly ObjectVerificationFailureReason[]\n readonly object?: VerifiedObject\n readonly status: AttemptStatus\n}\n\nfunction configuredSeeds(seeds: readonly ConfiguredSeed[], limits: ResolutionLimits) {\n if (!Array.isArray(seeds) || seeds.length === 0 || seeds.length > limits.maxSeeds) {\n throw new RangeError('Configure between one and maxSeeds explicit readers')\n }\n const ids = new Set<string>()\n const configured = seeds.map((seed: ConfiguredSeed): ConfiguredSeed => {\n if (typeof seed.id !== 'string' || seed.id.length === 0 || seed.id.length > 128 || seed.id.trim() !== seed.id) {\n throw new TypeError('Seed IDs must be nonempty, trimmed strings of at most 128 characters')\n }\n if (ids.has(seed.id)) throw new TypeError('Seed IDs must be unique')\n if (typeof seed.reader?.get !== 'function') throw new TypeError('Each seed requires a reader.get method')\n ids.add(seed.id)\n // Pin the reader and label before the first await; do not consult mutable seed configuration later.\n return Object.freeze({\n id: seed.id,\n reader: Object.freeze({ get: seed.reader.get.bind(seed.reader) }),\n })\n })\n for (let index = 0; index < configured.length; index++) {\n if (!Object.hasOwn(configured, index)) throw new TypeError('Seed configuration must not contain sparse slots')\n }\n return configured\n}\n\nasync function readCandidates(\n seed: ConfiguredSeed,\n reference: ObjectReference,\n limits: ResolutionLimits,\n signal: AbortSignal,\n expired: () => boolean,\n): Promise<SeedResult> {\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n const response: unknown = await seed.reader.get([reference.dataHash], { signal, maxBodyBytes: limits.maxBodyBytes })\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n if (!Array.isArray(response)) return { status: 'malformed-response' }\n const candidateCount = response.length\n if (!Number.isSafeInteger(candidateCount) || candidateCount < 0) return { status: 'malformed-response' }\n if (candidateCount > limits.maxCandidatesPerSeed) return { status: 'too-many-candidates' }\n if (candidateCount === 0) return { status: 'missing' }\n // Pin the bounded slots before verification yields; a reader must not enlarge the work budget.\n const candidates = Array.from({ length: candidateCount }, (_, index) => Object.getOwnPropertyDescriptor(response, String(index)))\n const candidateFailures: ObjectVerificationFailureReason[] = []\n for (const descriptor of candidates) {\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n if (descriptor === undefined || !('value' in descriptor)) {\n candidateFailures.push('invalid-json')\n continue\n }\n const candidate: unknown = descriptor.value\n const result = await verifyObject(reference, candidate, limits)\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n if (result.status === 'verified') return {\n status: 'resolved', object: result, candidateFailures,\n }\n candidateFailures.push(result.reason)\n }\n return { status: 'invalid-object', candidateFailures }\n}\n\nfunction attemptSeed(\n seed: ConfiguredSeed,\n reference: ObjectReference,\n limits: ResolutionLimits,\n outerSignal: AbortSignal,\n now: () => number,\n totalDeadline: number,\n): Promise<SeedResult> {\n const deadline = Math.min(now() + limits.attemptTimeoutMs, totalDeadline)\n const expired = () => now() >= deadline\n return new Promise((resolve) => {\n const controller = new AbortController()\n let isSettled = false\n const finish = (result: SeedResult) => {\n if (isSettled) return\n // Timer callbacks may be delayed by synchronous work or a busy microtask queue.\n // Reject late completions even when the timer has not had a chance to run.\n const outcome: SeedResult = result.status !== 'aborted' && expired() ? { status: 'timeout' } : result\n isSettled = true\n cancelTimer()\n outerSignal.removeEventListener('abort', onAbort)\n if (outcome.status === 'timeout') controller.abort()\n resolve(outcome)\n }\n const onAbort = () => {\n controller.abort()\n finish({ status: 'aborted' })\n }\n const cancelTimer = scheduleDeadline(now, deadline, () => {\n controller.abort()\n finish({ status: 'timeout' })\n })\n outerSignal.addEventListener('abort', onAbort, { once: true })\n if (outerSignal.aborted) {\n onAbort()\n return\n }\n // Defer the read one microtask so abort and deadline checks win, then settle either outcome.\n // Keep finish outside the rejection path so a failure inside finish is not reported as a reader error.\n queueMicrotask(() => {\n void (async () => {\n let result: SeedResult\n try {\n result = await readCandidates(seed, reference, limits, controller.signal, expired)\n } catch {\n finish({ status: 'reader-error' })\n return\n }\n finish(result)\n })()\n })\n })\n}\n\nfunction diagnostic(seedId: string, result: SeedResult): ResolutionAttempt {\n return Object.freeze({\n seedId,\n status: result.status,\n ...(result.candidateFailures !== undefined && { candidateFailures: Object.freeze([...result.candidateFailures]) }),\n })\n}\n\n/** Resolve exact content through configured readers only; never infer service absence or authority. */\nexport async function resolveObject(\n reference: ObjectReference,\n options: ResolveObjectOptions,\n): Promise<ObjectResolutionResult> {\n const expected = Object.freeze(ObjectReferenceZod.parse(reference))\n const limits = resolutionLimits(options.limits)\n const seeds = configuredSeeds(options.seeds, limits)\n const signal = options.signal\n const attempts: ResolutionAttempt[] = []\n if (signal?.aborted === true) return { status: 'aborted', attempts: Object.freeze(attempts) }\n\n const now = monotonicClock()\n const deadline = now() + limits.totalTimeoutMs\n const controller = new AbortController()\n const state: { terminal?: 'aborted' | 'deadline-exceeded' } = {}\n const terminate = (reason: 'aborted' | 'deadline-exceeded') => {\n if (state.terminal !== undefined) return\n state.terminal = reason\n controller.abort()\n }\n const onAbort = () => terminate('aborted')\n signal?.addEventListener('abort', onAbort, { once: true })\n const cancelTimer = scheduleDeadline(now, deadline, () => terminate('deadline-exceeded'))\n try {\n for (const seed of seeds) {\n if (now() >= deadline) terminate('deadline-exceeded')\n if (state.terminal !== undefined) break\n const result = await attemptSeed(seed, expected, limits, controller.signal, now, deadline)\n attempts.push(diagnostic(seed.id, result))\n if (now() >= deadline) terminate('deadline-exceeded')\n if (state.terminal !== undefined) break\n if (result.object !== undefined) {\n return Object.freeze({\n status: 'resolved',\n assurance: 'content-hash-verified',\n reference: result.object.reference,\n payload: result.object.payload,\n seedId: seed.id,\n attempts: Object.freeze([...attempts]),\n })\n }\n }\n if (state.terminal === 'aborted') return { status: 'aborted', attempts: Object.freeze([...attempts]) }\n return {\n status: 'unavailable',\n reason: state.terminal === 'deadline-exceeded' ? 'deadline-exceeded' : 'seeds-exhausted',\n attempts: Object.freeze([...attempts]),\n }\n } finally {\n cancelTimer()\n signal?.removeEventListener('abort', onAbort)\n }\n}\n", "/** Use the common runtime clock without introducing Node- or DOM-only ambient types. */\nexport function monotonicClock(): () => number {\n const clock: unknown = 'performance' in globalThis ? globalThis.performance : undefined\n if (typeof clock !== 'object' || clock === null || !('now' in clock) || typeof clock.now !== 'function') {\n throw new TypeError('Object resolution requires performance.now()')\n }\n const read = clock.now.bind(clock) as () => unknown\n return () => {\n const now = read()\n if (typeof now !== 'number' || !Number.isFinite(now)) throw new TypeError('Invalid monotonic clock')\n return now\n }\n}\n\n/** Native timers are wake-ups to check a deadline, not proof that its monotonic time has arrived. */\nexport function scheduleDeadline(now: () => number, deadline: number, expired: () => void): () => void {\n let cancelled = false\n let timer: ReturnType<typeof setTimeout> | undefined\n const tick = () => {\n if (cancelled) return\n if (now() >= deadline) {\n cancelled = true\n expired()\n } else {\n arm()\n }\n }\n const arm = () => {\n // Round up and recheck: timer implementations may truncate delays or wake before the deadline.\n const delay = Math.min(MAX_TIMER_DELAY_MS, Math.max(1, Math.ceil(deadline - now())))\n timer = setTimeout(tick, delay)\n }\n arm()\n return () => {\n cancelled = true\n clearTimeout(timer)\n }\n}\nimport { MAX_TIMER_DELAY_MS } from './limits.js'\n", "import { isAnyPayload, PayloadBuilder } from '@xyo-network/sdk-protocol'\nimport type { ObjectReference } from '@xyo-network/service-kit-schemas'\nimport {\n DataLakeLocatorSchema, DataLakeLocatorZod,\n ObjectReferenceZod,\n ServiceAdvertisementSchema, ServiceAdvertisementZod,\n} from '@xyo-network/service-kit-schemas'\n\nimport { ObjectInputError, snapshotJson } from './jsonSnapshot.js'\nimport { verificationLimits } from './limits.js'\nimport type {\n ContentPayload, ObjectVerificationResult, VerificationLimits,\n} from './types.js'\n\n/** Verify content only. No Claim, lifecycle, publisher authority, or freshness is established. */\nexport async function verifyObject(\n reference: ObjectReference,\n candidate: unknown,\n options: Partial<VerificationLimits> = {},\n): Promise<ObjectVerificationResult> {\n const expected = Object.freeze(ObjectReferenceZod.parse(reference))\n const limits = verificationLimits(options)\n try {\n const snapshot = snapshotJson(candidate, limits)\n if (snapshot === null || typeof snapshot !== 'object' || Array.isArray(snapshot)) {\n return { status: 'invalid', reason: 'not-payload' }\n }\n // Metadata is bounded JSON input, but cannot decide the committed Payload representation.\n const data = PayloadBuilder.omitMeta(snapshot)\n // Use a guard, never a parser that strips unknown fields before hashing.\n if (!isAnyPayload(data)) return { status: 'invalid', reason: 'not-payload' }\n const actualHash = await PayloadBuilder.dataHash(data)\n if (actualHash !== expected.dataHash) return { status: 'invalid', reason: 'hash-mismatch' }\n if (data.schema !== expected.schema) return { status: 'invalid', reason: 'schema-mismatch' }\n\n // These are strict validators without coercion, defaults, or transformations.\n // Hash the complete data first, and return the data rather than a parser projection.\n if (data.schema === ServiceAdvertisementSchema && !ServiceAdvertisementZod.safeParse(data).success) {\n return { status: 'invalid', reason: 'invalid-descriptor' }\n }\n if (data.schema === DataLakeLocatorSchema && !DataLakeLocatorZod.safeParse(data).success) {\n return { status: 'invalid', reason: 'invalid-descriptor' }\n }\n const payload = snapshotJson(data, limits) as ContentPayload\n return Object.freeze({\n status: 'verified', assurance: 'content-hash-verified', reference: expected, payload,\n })\n } catch (error) {\n return {\n status: 'invalid',\n reason: error instanceof ObjectInputError ? error.reason : 'invalid-json',\n }\n }\n}\n", "import type {\n JsonValue, ObjectVerificationFailureReason, VerificationLimits,\n} from './types.js'\n\nexport class ObjectInputError extends Error {\n readonly reason: ObjectVerificationFailureReason\n\n constructor(reason: ObjectVerificationFailureReason) {\n super(reason)\n this.name = 'ObjectInputError'\n this.reason = reason\n }\n}\n\ninterface Budget {\n readonly ancestors: WeakSet<object>\n bytes: number\n readonly limits: VerificationLimits\n nodes: number\n}\n\nconst encoder = new TextEncoder()\n\nfunction spend(budget: Budget, bytes: number) {\n budget.bytes += bytes\n if (budget.bytes > budget.limits.maxBodyBytes) throw new ObjectInputError('body-too-large')\n}\n\nfunction textSize(budget: Budget, text: string) {\n // Reject an oversized string before allocating its serialized/encoded copy.\n if (text.length > budget.limits.maxBodyBytes - budget.bytes) throw new ObjectInputError('body-too-large')\n spend(budget, encoder.encode(JSON.stringify(text)).byteLength)\n}\n\nfunction propertyValue(object: object, key: string): unknown {\n const descriptor = Object.getOwnPropertyDescriptor(object, key)\n if (descriptor?.enumerable !== true || !('value' in descriptor)) {\n throw new ObjectInputError('invalid-json')\n }\n return descriptor.value\n}\n\nfunction snapshotArray(value: unknown[], budget: Budget, depth: number): readonly JsonValue[] {\n if (Object.getPrototypeOf(value) !== Array.prototype) throw new ObjectInputError('invalid-json')\n if (value.length > budget.limits.maxNodes - budget.nodes) throw new ObjectInputError('structure-limit')\n // JSON arrays cannot carry holes, symbols, accessors, or extra object fields.\n if (Reflect.ownKeys(value).length !== value.length + 1) throw new ObjectInputError('invalid-json')\n spend(budget, 2)\n const output: JsonValue[] = []\n for (let index = 0; index < value.length; index++) {\n if (index > 0) spend(budget, 1)\n output.push(snapshotValue(propertyValue(value, String(index)), budget, depth + 1))\n }\n return Object.freeze(output)\n}\n\nfunction snapshotObject(value: object, budget: Budget, depth: number): JsonValue {\n const prototype: unknown = Object.getPrototypeOf(value)\n if (prototype !== null && prototype !== Object.prototype) throw new ObjectInputError('invalid-json')\n const keys = Reflect.ownKeys(value)\n if (keys.length > budget.limits.maxNodes - budget.nodes) throw new ObjectInputError('structure-limit')\n spend(budget, 2)\n const entries: [string, JsonValue][] = []\n for (const key of keys) {\n // The SDK's object reconstruction cannot bind a literal __proto__ key reliably.\n if (typeof key !== 'string' || key === '__proto__') throw new ObjectInputError('invalid-json')\n if (entries.length > 0) spend(budget, 1)\n textSize(budget, key)\n spend(budget, 1)\n entries.push([key, snapshotValue(propertyValue(value, key), budget, depth + 1)])\n }\n // Construct own data properties without interpreting object keys as setters.\n return Object.freeze(Object.fromEntries(entries))\n}\n\nfunction snapshotValue(value: unknown, budget: Budget, depth: number): JsonValue {\n budget.nodes++\n if (depth > budget.limits.maxDepth || budget.nodes > budget.limits.maxNodes) {\n throw new ObjectInputError('structure-limit')\n }\n if (value === null) {\n spend(budget, 4)\n return null\n }\n switch (typeof value) {\n case 'string': {\n textSize(budget, value)\n return value\n }\n case 'boolean': {\n spend(budget, value ? 4 : 5)\n return value\n }\n case 'number': {\n if (!Number.isFinite(value)) throw new ObjectInputError('invalid-json')\n spend(budget, JSON.stringify(value).length)\n return value\n }\n case 'object': {\n if (budget.ancestors.has(value)) throw new ObjectInputError('invalid-json')\n budget.ancestors.add(value)\n try {\n return Array.isArray(value)\n ? snapshotArray(value, budget, depth)\n : snapshotObject(value, budget, depth)\n } finally {\n budget.ancestors.delete(value)\n }\n }\n default: {\n throw new ObjectInputError('invalid-json')\n }\n }\n}\n\n/** Bounded, immutable JSON copy. This is not a replacement canonicalization algorithm. */\nexport function snapshotJson(candidate: unknown, limits: VerificationLimits): JsonValue {\n return snapshotValue(candidate, {\n limits, ancestors: new WeakSet<object>(), bytes: 0, nodes: 0,\n }, 0)\n}\n"],
5
- "mappings": ";AAEO,IAAM,qBAAqB;AAE3B,IAAM,8BAAkD,OAAO,OAAO;AAAA,EAC3E,cAAc;AAAA,EACd,UAAU;AAAA,EACV,UAAU;AACZ,CAAC;AAEM,IAAM,4BAA8C,OAAO,OAAO;AAAA,EACvE,GAAG;AAAA,EACH,UAAU;AAAA,EACV,sBAAsB;AAAA,EACtB,kBAAkB;AAAA,EAClB,gBAAgB;AAClB,CAAC;AAED,SAAS,gBAAgB,OAAe,MAAc;AACpD,MAAI,CAAC,OAAO,cAAc,KAAK,KAAK,SAAS,GAAG;AAC9C,UAAM,IAAI,WAAW,OAAO,kCAAkC;AAAA,EAChE;AACF;AAEO,SAAS,mBAAmB,UAAuC,CAAC,GAAuB;AAChG,QAAM,SAAS,EAAE,GAAG,6BAA6B,GAAG,QAAQ;AAC5D,kBAAgB,OAAO,cAAc,cAAc;AACnD,kBAAgB,OAAO,UAAU,UAAU;AAC3C,kBAAgB,OAAO,UAAU,UAAU;AAC3C,SAAO,OAAO,OAAO,MAAM;AAC7B;AAEO,SAAS,iBAAiB,UAAqC,CAAC,GAAqB;AAC1F,QAAM,SAAS,EAAE,GAAG,2BAA2B,GAAG,QAAQ;AAC1D,qB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;AACxB,UAAI,IAAI,KAAK,SAAU,WAAU,mBAAmB;AACpD,UAAI,MAAM,aAAa,OAAW;AAClC,YAAM,SAAS,MAAM,YAAY,MAAM,UAAU,QAAQ,WAAW,QAAQ,KAAK,QAAQ;AACzF,eAAS,KAAK,WAAW,KAAK,IAAI,MAAM,CAAC;AACzC,UAAI,IAAI,KAAK,SAAU,WAAU,mBAAmB;AACpD,UAAI,MAAM,aAAa,OAAW;AAClC,UAAI,OAAO,WAAW,QAAW;AAC/B,eAAO,OAAO,OAAO;AAAA,UACnB,QAAQ;AAAA,UACR,WAAW;AAAA,UACX,WAAW,OAAO,OAAO;AAAA,UACzB,SAAS,OAAO,OAAO;AAAA,UACvB,QAAQ,KAAK;AAAA,UACb,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,CAAC;AAAA,QACvC,CAAC;AAAA,MACH;AAAA,IACF;AACA,QAAI,MAAM,aAAa,UAAW,QAAO,EAAE,QAAQ,WAAW,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE;AACrG,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ,MAAM,aAAa,sBAAsB,sBAAsB;AAAA,MACvE,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,CAAC;AAAA,IACvC;AAAA,EACF,UAAE;AACA,gBAAY;AACZ,YAAQ,oBAAoB,SAAS,OAAO;AAAA,EAC9C;AACF;",
6
- "names": ["ObjectReferenceZod", "ObjectReferenceZod"]
3
+ "sources": ["../../src/fleetConfiguration.ts", "../../src/jsonSnapshot.ts", "../../src/fleetFold.ts", "../../src/fleetSignal.ts", "../../src/limits.ts", "../../src/resolveFleetPayload.ts", "../../src/clock.ts", "../../src/verifyFleetPayload.ts", "../../src/resolveObject.ts", "../../src/verifyObject.ts"],
4
+ "sourcesContent": ["import { AddressZod, HashZod } from '@xyo-network/service-kit-schemas'\n\nimport { snapshotJson } from './jsonSnapshot.js'\n\nexport interface LocalFleetConfigurationProfile {\n readonly fleetRoot: string\n readonly maxConfigurationBytes: number\n readonly maxMembers: number\n readonly maxRevisionBytes: number\n readonly maxTotalBytes: number\n readonly owner: string\n}\nexport interface OpaqueFleetConfiguration {\n readonly bytes: Uint8Array\n readonly memberRoot: string\n readonly revision: string\n}\nexport interface FleetConfigurationAcknowledgment {\n readonly assurance: 'private-provision-only'\n readonly memberRoot: string\n readonly revision: string\n readonly status: 'acknowledged' | 'stale' | 'missing'\n}\nexport interface LocalFleetConfigurationStore {\n acknowledge(memberRoot: string, revision: string): FleetConfigurationAcknowledgment\n acknowledgment(memberRoot: string): FleetConfigurationAcknowledgment | undefined\n /** Return an independent opaque byte copy. No parser or public authority is applied. */\n provide(memberRoot: string): OpaqueFleetConfiguration | undefined\n provision(configuration: OpaqueFleetConfiguration): void\n}\ninterface StoredConfiguration {\n readonly bytes: Uint8Array\n readonly revision: string\n}\n\nfunction selectedProfile(configuration: LocalFleetConfigurationProfile) {\n const profile = snapshotJson(configuration, {\n maxBodyBytes: 1024, maxDepth: 2, maxNodes: 16,\n }) as unknown as LocalFleetConfigurationProfile\n const keys = ['fleetRoot', 'maxConfigurationBytes', 'maxMembers', 'maxRevisionBytes', 'maxTotalBytes', 'owner']\n if (Object.keys(profile).toSorted().join(',') !== keys.join(',')) throw new TypeError('Select a strict complete private configuration profile')\n AddressZod.parse(profile.owner)\n HashZod.parse(profile.fleetRoot)\n for (const value of [profile.maxConfigurationBytes, profile.maxMembers, profile.maxRevisionBytes, profile.maxTotalBytes]) {\n if (!Number.isSafeInteger(value) || value <= 0) throw new RangeError('Select finite positive private configuration limits')\n }\n if (profile.maxConfigurationBytes > profile.maxTotalBytes) throw new RangeError('Configuration cap must fit total storage cap')\n return Object.freeze({ ...profile })\n}\nfunction pinConfiguration(configuration: OpaqueFleetConfiguration) {\n const keys = ['bytes', 'memberRoot', 'revision']\n if (Reflect.ownKeys(configuration).length !== keys.length) throw new TypeError('Opaque provision requires a closed data record')\n const values: Record<string, unknown> = {}\n for (const key of keys) {\n const property = Object.getOwnPropertyDescriptor(configuration, key)\n if (property?.enumerable !== true || !('value' in property)) throw new TypeError('Opaque provision requires own data properties')\n values[key] = property.value\n }\n return Object.freeze(values) as unknown as OpaqueFleetConfiguration\n}\nfunction copyBytes(bytes: Uint8Array, maxBytes: number) {\n if (!(bytes instanceof Uint8Array) || Object.getPrototypeOf(bytes) !== Uint8Array.prototype) throw new TypeError('Opaque configuration must be plain Uint8Array')\n if (bytes.byteLength > maxBytes) throw new RangeError('Opaque configuration exceeds selected cap')\n return Uint8Array.from(bytes)\n}\nconst encoder = new TextEncoder()\n\nfunction checkRevision(revision: string, maximum: number) {\n if (typeof revision !== 'string' || revision.length === 0 || revision.length > maximum || encoder.encode(revision).byteLength > maximum) {\n throw new RangeError('Opaque revision must fit its selected byte cap')\n }\n}\nfunction sameBytes(left: Uint8Array, right: Uint8Array) {\n return left.length === right.length && left.every((value, index) => value === right[index])\n}\n\n/**\n * Volatile one-realm private provision profile. The configured local manager controls calls;\n * it is not a remote authentication protocol, a public grant, or a persistent backend.\n */\nexport function createLocalFleetConfigurationStore(configurationProfile: LocalFleetConfigurationProfile): LocalFleetConfigurationStore {\n const profile = selectedProfile(configurationProfile)\n const desired = new Map<string, StoredConfiguration>()\n const received = new Map<string, FleetConfigurationAcknowledgment>()\n let totalBytes = 0\n const provide = (memberRoot: string): OpaqueFleetConfiguration | undefined => {\n HashZod.parse(memberRoot)\n const current = desired.get(memberRoot)\n return current === undefined\n ? undefined\n : Object.freeze({\n memberRoot, revision: current.revision, bytes: Uint8Array.from(current.bytes),\n })\n }\n const provision = (input: OpaqueFleetConfiguration) => {\n const configuration = pinConfiguration(input)\n HashZod.parse(configuration.memberRoot)\n checkRevision(configuration.revision, profile.maxRevisionBytes)\n const bytes = copyBytes(configuration.bytes, profile.maxConfigurationBytes)\n const prior = desired.get(configuration.memberRoot)\n if (prior?.revision === configuration.revision && !sameBytes(prior.bytes, bytes)) throw new TypeError('An opaque revision cannot name different bytes')\n if (prior === undefined && desired.size >= profile.maxMembers) throw new RangeError('Private member capacity exceeded')\n const nextBytes = totalBytes - (prior?.bytes.byteLength ?? 0) + bytes.byteLength\n if (nextBytes > profile.maxTotalBytes) throw new RangeError('Private storage capacity exceeded')\n if (prior?.revision !== configuration.revision) received.delete(configuration.memberRoot)\n desired.set(configuration.memberRoot, { revision: configuration.revision, bytes })\n totalBytes = nextBytes\n }\n const acknowledge = (memberRoot: string, revision: string): FleetConfigurationAcknowledgment => {\n HashZod.parse(memberRoot)\n checkRevision(revision, profile.maxRevisionBytes)\n const current = desired.get(memberRoot)\n const status = current === undefined ? 'missing' : (current.revision === revision ? 'acknowledged' : 'stale')\n const result = Object.freeze({\n status, assurance: 'private-provision-only' as const, memberRoot, revision,\n })\n if (status === 'acknowledged') received.set(memberRoot, result)\n return result\n }\n const acknowledgment = (memberRoot: string): FleetConfigurationAcknowledgment | undefined => {\n HashZod.parse(memberRoot)\n return received.get(memberRoot)\n }\n return Object.freeze({\n provide, provision, acknowledge, acknowledgment,\n })\n}\n", "import type {\n JsonValue, ObjectVerificationFailureReason, VerificationLimits,\n} from './types.js'\n\nexport class ObjectInputError extends Error {\n readonly reason: ObjectVerificationFailureReason\n\n constructor(reason: ObjectVerificationFailureReason) {\n super(reason)\n this.name = 'ObjectInputError'\n this.reason = reason\n }\n}\n\ninterface Budget {\n readonly ancestors: WeakSet<object>\n bytes: number\n readonly limits: VerificationLimits\n nodes: number\n}\n\nconst encoder = new TextEncoder()\n\nfunction spend(budget: Budget, bytes: number) {\n budget.bytes += bytes\n if (budget.bytes > budget.limits.maxBodyBytes) throw new ObjectInputError('body-too-large')\n}\n\nfunction textSize(budget: Budget, text: string) {\n // Reject an oversized string before allocating its serialized/encoded copy.\n if (text.length > budget.limits.maxBodyBytes - budget.bytes) throw new ObjectInputError('body-too-large')\n spend(budget, encoder.encode(JSON.stringify(text)).byteLength)\n}\n\nfunction propertyValue(object: object, key: string): unknown {\n const descriptor = Object.getOwnPropertyDescriptor(object, key)\n if (descriptor?.enumerable !== true || !('value' in descriptor)) {\n throw new ObjectInputError('invalid-json')\n }\n return descriptor.value\n}\n\nfunction snapshotArray(value: unknown[], budget: Budget, depth: number): readonly JsonValue[] {\n if (Object.getPrototypeOf(value) !== Array.prototype) throw new ObjectInputError('invalid-json')\n if (value.length > budget.limits.maxNodes - budget.nodes) throw new ObjectInputError('structure-limit')\n // JSON arrays cannot carry holes, symbols, accessors, or extra object fields.\n if (Reflect.ownKeys(value).length !== value.length + 1) throw new ObjectInputError('invalid-json')\n spend(budget, 2)\n const output: JsonValue[] = []\n for (let index = 0; index < value.length; index++) {\n if (index > 0) spend(budget, 1)\n output.push(snapshotValue(propertyValue(value, String(index)), budget, depth + 1))\n }\n return Object.freeze(output)\n}\n\nfunction snapshotObject(value: object, budget: Budget, depth: number): JsonValue {\n const prototype: unknown = Object.getPrototypeOf(value)\n if (prototype !== null && prototype !== Object.prototype) throw new ObjectInputError('invalid-json')\n const keys = Reflect.ownKeys(value)\n if (keys.length > budget.limits.maxNodes - budget.nodes) throw new ObjectInputError('structure-limit')\n spend(budget, 2)\n const entries: [string, JsonValue][] = []\n for (const key of keys) {\n // The SDK's object reconstruction cannot bind a literal __proto__ key reliably.\n if (typeof key !== 'string' || key === '__proto__') throw new ObjectInputError('invalid-json')\n if (entries.length > 0) spend(budget, 1)\n textSize(budget, key)\n spend(budget, 1)\n entries.push([key, snapshotValue(propertyValue(value, key), budget, depth + 1)])\n }\n // Construct own data properties without interpreting object keys as setters.\n return Object.freeze(Object.fromEntries(entries))\n}\n\nfunction snapshotValue(value: unknown, budget: Budget, depth: number): JsonValue {\n budget.nodes++\n if (depth > budget.limits.maxDepth || budget.nodes > budget.limits.maxNodes) {\n throw new ObjectInputError('structure-limit')\n }\n if (value === null) {\n spend(budget, 4)\n return null\n }\n switch (typeof value) {\n case 'string': {\n textSize(budget, value)\n return value\n }\n case 'boolean': {\n spend(budget, value ? 4 : 5)\n return value\n }\n case 'number': {\n if (!Number.isFinite(value)) throw new ObjectInputError('invalid-json')\n spend(budget, JSON.stringify(value).length)\n return value\n }\n case 'object': {\n if (budget.ancestors.has(value)) throw new ObjectInputError('invalid-json')\n budget.ancestors.add(value)\n try {\n return Array.isArray(value)\n ? snapshotArray(value, budget, depth)\n : snapshotObject(value, budget, depth)\n } finally {\n budget.ancestors.delete(value)\n }\n }\n default: {\n throw new ObjectInputError('invalid-json')\n }\n }\n}\n\n/** Bounded, immutable JSON copy. This is not a replacement canonicalization algorithm. */\nexport function snapshotJson(candidate: unknown, limits: VerificationLimits): JsonValue {\n return snapshotValue(candidate, {\n limits, ancestors: new WeakSet<object>(), bytes: 0, nodes: 0,\n }, 0)\n}\n", "import type {\n FleetControl, FleetMember, FleetPayload, FleetPublicationScope,\n} from '@xyo-network/service-kit-schemas'\nimport {\n AddressZod, ChainIdZod, FleetControlSchema, FleetControlZod, FleetMemberZod, FleetPublicationScopeZod, FleetZod, HashZod, parseFleetPayload,\n} from '@xyo-network/service-kit-schemas'\n\nimport { captureFleetSignal, fleetSignalAborted } from './fleetSignal.js'\nimport { snapshotJson } from './jsonSnapshot.js'\nimport { verificationLimits } from './limits.js'\nimport type { VerificationLimits } from './types.js'\n\nexport interface FleetFoldLimits extends VerificationLimits {\n readonly maxControls: number\n readonly maxDeclarations: number\n readonly maxGrants: number\n readonly maxMembers: number\n}\nexport interface FleetDeclarationFact {\n readonly payload: Readonly<FleetPayload>\n readonly root: string\n}\n/** Caller-validated native occurrence facts. This interface itself proves no signatures or completeness. */\nexport interface FleetControlFact extends FleetDeclarationFact {\n readonly authorizer: string\n readonly block: number\n readonly chainId: string\n readonly payload: Readonly<FleetControl>\n readonly payloadIndex: number\n readonly transactionIndex: number\n}\nexport interface FoldFleetControlsOptions {\n readonly chainId: string\n readonly controls: readonly FleetControlFact[]\n readonly declarations: readonly FleetDeclarationFact[]\n readonly fleetRoot: string\n readonly genesisRoot: string\n readonly limits: FleetFoldLimits\n readonly owner: string\n readonly publicationBlock: number\n readonly signal?: AbortSignal\n}\nexport interface FleetMemberState {\n readonly active: boolean\n readonly roleId: string\n readonly root: string\n}\nexport interface FleetGrantState {\n readonly controlRoot: string\n readonly expiresAtBlock?: number\n readonly memberRoot: string\n readonly publisherAddress: string\n readonly scopeRoot: string\n}\nexport interface FoldedFleetView {\n readonly assurance: 'validated-input-only'\n readonly chainId: string\n readonly fleetActive: boolean\n readonly fleetRoot: string\n readonly genesisRoot: string\n readonly grants: readonly FleetGrantState[]\n readonly headRoot?: string\n readonly members: readonly FleetMemberState[]\n readonly owner: string\n readonly publicationBlock: number\n readonly status: 'folded'\n}\nexport interface FleetFoldFailure {\n readonly assurance: 'validated-input-only'\n readonly reason: 'resource-limit' | 'missing-declaration' | 'invalid-input' | 'invalid-transition' | 'missing-predecessor' | 'bootstrap' | 'successor' | 'definition' | 'cancelled'\n readonly status: 'incomplete' | 'conflict' | 'unsupported' | 'aborted'\n}\nexport type FleetFoldResult = FoldedFleetView | FleetFoldFailure\n\ninterface State {\n active: boolean\n readonly declarations: Map<string, FleetPayload>\n readonly grants: Map<string, FleetGrantState>\n head?: string\n readonly members: Map<string, boolean>\n readonly seen: Set<string>\n}\n\nfunction failure(status: FleetFoldFailure['status'], reason: FleetFoldFailure['reason']): FleetFoldFailure {\n return Object.freeze({\n status, reason, assurance: 'validated-input-only',\n })\n}\nfunction safeBlock(value: number) {\n return Number.isSafeInteger(value) && value >= 0\n}\nfunction selectedLimits(limits: FleetFoldLimits) {\n const pinned = snapshotJson(limits, {\n maxBodyBytes: 1024, maxDepth: 2, maxNodes: 16,\n }) as unknown as FleetFoldLimits\n const keys = ['maxBodyBytes', 'maxControls', 'maxDeclarations', 'maxDepth', 'maxGrants', 'maxMembers', 'maxNodes']\n if (Object.keys(pinned).toSorted().join(',') !== keys.join(',')) throw new TypeError('Select a strict complete fleet fold profile')\n verificationLimits(pinned)\n for (const value of [pinned.maxControls, pinned.maxDeclarations, pinned.maxGrants, pinned.maxMembers]) {\n if (!Number.isSafeInteger(value) || value <= 0) throw new RangeError('Select finite positive fold limits')\n }\n return Object.freeze({ ...pinned })\n}\nfunction boundedSlots<T>(values: readonly T[], maximum: number): readonly T[] {\n if (!Array.isArray(values) || values.length > maximum) throw new RangeError('Fleet input exceeds selected limit')\n return Object.freeze(Array.from({ length: values.length }, (_, index): T => {\n const descriptor = Object.getOwnPropertyDescriptor(values, String(index))\n if (descriptor?.enumerable !== true || !('value' in descriptor)) throw new TypeError('Fleet inputs require dense own data slots')\n return descriptor.value as T\n }))\n}\nfunction declarationMap(facts: readonly FleetDeclarationFact[], limits: FleetFoldLimits) {\n const declarations = new Map<string, FleetPayload>()\n for (const input of facts) {\n const fact = snapshotJson(input, limits) as unknown as FleetDeclarationFact\n HashZod.parse(fact.root)\n const payload = parseFleetPayload(fact.payload)\n if (payload === undefined || payload.schema === FleetControlSchema || declarations.has(fact.root)) throw new TypeError('Invalid fleet declaration fact')\n declarations.set(fact.root, payload)\n }\n return declarations\n}\nfunction positionAfter(left: FleetControlFact, right: FleetControlFact) {\n return left.block > right.block || (left.block === right.block && (left.transactionIndex > right.transactionIndex\n || (left.transactionIndex === right.transactionIndex && left.payloadIndex > right.payloadIndex)))\n}\nfunction controlFact(fact: FleetControlFact, limits: FleetFoldLimits): FleetControlFact | undefined {\n const pinned = snapshotJson(fact, limits) as unknown as FleetControlFact\n const isValidPosition = safeBlock(pinned.block) && safeBlock(pinned.transactionIndex) && safeBlock(pinned.payloadIndex)\n const hasCanonicalLabels = AddressZod.safeParse(pinned.authorizer).success && ChainIdZod.safeParse(pinned.chainId).success && HashZod.safeParse(pinned.root).success\n if (!isValidPosition || !hasCanonicalLabels) return\n const parsed = FleetControlZod.safeParse(pinned.payload)\n return parsed.success ? { ...pinned, payload: parsed.data } : undefined\n}\nfunction member(state: State, root: string, fleetRoot: string): FleetMember | undefined {\n const parsed = FleetMemberZod.safeParse(state.declarations.get(root))\n return parsed.success && parsed.data.fleetRoot === fleetRoot ? parsed.data : undefined\n}\nfunction scope(state: State, root: string, fleetRoot: string): FleetPublicationScope | undefined {\n const parsed = FleetPublicationScopeZod.safeParse(state.declarations.get(root))\n return parsed.success && parsed.data.fleetRoot === fleetRoot ? parsed.data : undefined\n}\nfunction clearMemberGrants(state: State, memberRoot: string) {\n for (const [key, grant] of state.grants) {\n if (grant.memberRoot === memberRoot) state.grants.delete(key)\n }\n}\nfunction grantKey(payload: { readonly memberRoot: string; readonly publisherAddress: string; readonly scopeRoot: string }) {\n return `${payload.memberRoot}:${payload.scopeRoot}:${payload.publisherAddress}`\n}\nfunction changeMember(state: State, payload: Extract<FleetControl, { operation: 'activate-member' | 'remove-member' }>, limits: FleetFoldLimits) {\n if (member(state, payload.memberRoot, payload.fleetRoot) === undefined) return failure('incomplete', 'missing-declaration')\n if (payload.operation === 'activate-member' && !state.active) return failure('incomplete', 'invalid-transition')\n state.members.set(payload.memberRoot, payload.operation === 'activate-member')\n if (state.members.size > limits.maxMembers) return failure('incomplete', 'resource-limit')\n if (payload.operation === 'remove-member') clearMemberGrants(state, payload.memberRoot)\n}\nfunction changeGrant(state: State, fact: FleetControlFact, payload: Extract<FleetControl, { operation: 'grant-publisher' | 'remove-publisher' }>, limits: FleetFoldLimits) {\n const selectedMember = member(state, payload.memberRoot, payload.fleetRoot)\n const selectedScope = scope(state, payload.scopeRoot, payload.fleetRoot)\n if (selectedMember === undefined || selectedScope === undefined) return failure('incomplete', 'missing-declaration')\n if (selectedMember.roleId !== selectedScope.roleId) return failure('incomplete', 'invalid-transition')\n const key = grantKey(payload)\n if (payload.operation === 'remove-publisher') {\n state.grants.delete(key)\n return\n }\n if (!state.active || state.members.get(payload.memberRoot) !== true) return failure('incomplete', 'invalid-transition')\n const activation = fact.block + 1\n if (!Number.isSafeInteger(activation) || (payload.expiresAtBlock !== undefined && payload.expiresAtBlock <= activation)) {\n return failure('incomplete', 'invalid-transition')\n }\n state.grants.set(key, Object.freeze({\n memberRoot: payload.memberRoot,\n scopeRoot: payload.scopeRoot,\n publisherAddress: payload.publisherAddress,\n controlRoot: fact.root,\n ...(payload.expiresAtBlock !== undefined && { expiresAtBlock: payload.expiresAtBlock }),\n }))\n if (state.grants.size > limits.maxGrants) return failure('incomplete', 'resource-limit')\n}\nfunction applyControl(state: State, fact: FleetControlFact, limits: FleetFoldLimits) {\n const payload = fact.payload\n switch (payload.operation) {\n case 'activate-fleet': {\n state.active = true\n return\n }\n case 'remove-fleet': {\n state.active = false\n state.grants.clear()\n return\n }\n case 'activate-member':\n case 'remove-member': {\n return changeMember(state, payload, limits)\n }\n case 'grant-publisher':\n case 'remove-publisher': {\n return changeGrant(state, fact, payload, limits)\n }\n }\n}\nfunction advance(state: State, fact: FleetControlFact, limits: FleetFoldLimits) {\n if (state.seen.has(fact.root)) return\n const previous = fact.payload.previousControlRoot\n if (state.head === undefined && (previous !== undefined || fact.payload.operation !== 'activate-fleet')) return failure('incomplete', 'missing-predecessor')\n if (previous === undefined && state.head !== undefined) return failure('conflict', 'bootstrap')\n if (state.head !== undefined && previous !== state.head) {\n return state.seen.has(previous ?? '') ? failure('conflict', 'successor') : failure('incomplete', 'missing-predecessor')\n }\n const error = applyControl(state, fact, limits)\n if (error !== undefined) return error\n state.head = fact.root\n state.seen.add(fact.root)\n}\nfunction foldedView(state: State, options: FoldFleetControlsOptions): FoldedFleetView {\n const members = [...state.members].map(([root, active]): FleetMemberState => {\n const declaration = member(state, root, options.fleetRoot)\n if (declaration === undefined) throw new TypeError('Missing applied member')\n return Object.freeze({\n root, active, roleId: declaration.roleId,\n })\n })\n const grants = state.grants.values().filter(grant => grant.expiresAtBlock === undefined || options.publicationBlock < grant.expiresAtBlock).toArray()\n return Object.freeze({\n status: 'folded',\n assurance: 'validated-input-only',\n owner: options.owner,\n fleetRoot: options.fleetRoot,\n chainId: options.chainId,\n genesisRoot: options.genesisRoot,\n publicationBlock: options.publicationBlock,\n fleetActive: state.active,\n ...(state.head !== undefined && { headRoot: state.head }),\n members: Object.freeze(members),\n grants: Object.freeze(grants),\n })\n}\nfunction foldFacts(state: State, facts: readonly FleetControlFact[], options: FoldFleetControlsOptions, limits: FleetFoldLimits): FleetFoldResult {\n let previous: FleetControlFact | undefined\n for (const input of facts) {\n if (options.signal !== undefined && fleetSignalAborted(options.signal)) return failure('aborted', 'cancelled')\n const fact = controlFact(input, limits)\n if (fact === undefined) return failure('unsupported', 'definition')\n if (fact.block > options.publicationBlock || (previous !== undefined && !positionAfter(fact, previous))) return failure('incomplete', 'invalid-input')\n previous = fact\n if (fact.chainId !== options.chainId || fact.authorizer !== options.owner || fact.payload.fleetRoot !== options.fleetRoot\n // Controls carried in the publication block do not affect that block's authority.\n || fact.block === options.publicationBlock) continue\n const error = advance(state, fact, limits)\n if (error !== undefined) return error\n }\n return foldedView(state, options)\n}\n\n/**\n * Pure B4 lifecycle fold of caller-validated facts. It never claims authenticated or complete history.\n * A native finalized-evidence composition must prove original root/signature/carrying correspondence,\n * every height's fork identity, the exact anchor and complete enumeration before using it as authority.\n */\nexport function foldFleetControls(options: FoldFleetControlsOptions): FleetFoldResult {\n const limits = selectedLimits(options.limits)\n const signal = captureFleetSignal(options.signal)\n AddressZod.parse(options.owner)\n HashZod.parse(options.fleetRoot)\n HashZod.parse(options.genesisRoot)\n ChainIdZod.parse(options.chainId)\n if (!safeBlock(options.publicationBlock)) throw new RangeError('Publication block must be a nonnegative safe integer')\n if (options.signal !== undefined && fleetSignalAborted(options.signal)) return failure('aborted', 'cancelled')\n try {\n const declarations = declarationMap(boundedSlots(options.declarations, limits.maxDeclarations), limits)\n const fleet = FleetZod.safeParse(declarations.get(options.fleetRoot))\n if (!fleet.success) return failure('incomplete', 'missing-declaration')\n if (fleet.data.owner !== options.owner) return failure('incomplete', 'invalid-input')\n const state: State = {\n active: false, declarations, grants: new Map(), members: new Map(), seen: new Set(),\n }\n return foldFacts(state, boundedSlots(options.controls, limits.maxControls), { ...options, signal }, limits)\n } catch (error) {\n return failure('incomplete', error instanceof RangeError ? 'resource-limit' : 'invalid-input')\n }\n}\n\nexport interface FleetPublisherMatch {\n readonly assurance: 'validated-input-only'\n readonly grant?: FleetGrantState\n readonly status: 'matched' | 'absent' | 'conflict'\n}\n/** Match only within the supplied fold; this supplies no public authorization or completeness claim. */\nexport function matchFleetPublisher(view: FoldedFleetView, scopeRoot: string, publisherAddress: string): FleetPublisherMatch {\n HashZod.parse(scopeRoot)\n AddressZod.parse(publisherAddress)\n const matching = view.fleetActive ? view.grants.filter(grant => grant.scopeRoot === scopeRoot && grant.publisherAddress === publisherAddress) : []\n if (matching.length > 1) return Object.freeze({ status: 'conflict', assurance: 'validated-input-only' })\n return matching.length === 0\n ? Object.freeze({ status: 'absent', assurance: 'validated-input-only' })\n : Object.freeze({\n status: 'matched', assurance: 'validated-input-only', grant: matching[0],\n })\n}\n", "const abortedDescriptor = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')\nconst abortedGetter: unknown = Reflect.get(abortedDescriptor ?? {}, 'get')\nconst nativeEvents = EventTarget.prototype as unknown as { addEventListener: (this: void, ...args: unknown[]) => void; removeEventListener: (this: void, ...args: unknown[]) => void }\nconst addListener = nativeEvents.addEventListener\nconst removeListener = nativeEvents.removeEventListener\nconst apply = Reflect.apply\n\n/** Native-brand admission without consulting shadowable caller instance properties. */\nexport function captureFleetSignal(value: unknown): AbortSignal | undefined {\n if (value === undefined) return\n if (typeof abortedGetter !== 'function') throw new TypeError('Native AbortSignal is required')\n apply(abortedGetter, value, [])\n return value as AbortSignal\n}\nexport function fleetSignalAborted(signal: AbortSignal): boolean {\n if (typeof abortedGetter !== 'function') throw new TypeError('Native AbortSignal is required')\n return apply(abortedGetter, signal, []) as boolean\n}\nexport function listenFleetAbort(signal: AbortSignal | undefined, listener: () => void): () => void {\n if (signal === undefined) return () => { /* No caller cancellation. */ }\n apply(addListener, signal, ['abort', listener, { once: true }])\n return () => {\n apply(removeListener, signal, ['abort', listener])\n }\n}\n", "import type { ResolutionLimits, VerificationLimits } from './types.js'\n\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647\n\nexport const DEFAULT_VERIFICATION_LIMITS: VerificationLimits = Object.freeze({\n maxBodyBytes: 65_536,\n maxDepth: 32,\n maxNodes: 10_000,\n})\n\nexport const DEFAULT_RESOLUTION_LIMITS: ResolutionLimits = Object.freeze({\n ...DEFAULT_VERIFICATION_LIMITS,\n maxSeeds: 16,\n maxCandidatesPerSeed: 16,\n attemptTimeoutMs: 2000,\n totalTimeoutMs: 10_000,\n})\n\nfunction positiveInteger(value: number, name: string) {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new RangeError(name + ' must be a positive safe integer')\n }\n}\n\nexport function verificationLimits(options: Partial<VerificationLimits> = {}): VerificationLimits {\n const limits = { ...DEFAULT_VERIFICATION_LIMITS, ...options }\n positiveInteger(limits.maxBodyBytes, 'maxBodyBytes')\n positiveInteger(limits.maxDepth, 'maxDepth')\n positiveInteger(limits.maxNodes, 'maxNodes')\n return Object.freeze(limits)\n}\n\nexport function resolutionLimits(options: Partial<ResolutionLimits> = {}): ResolutionLimits {\n const limits = { ...DEFAULT_RESOLUTION_LIMITS, ...options }\n verificationLimits(limits)\n positiveInteger(limits.maxSeeds, 'maxSeeds')\n positiveInteger(limits.maxCandidatesPerSeed, 'maxCandidatesPerSeed')\n positiveInteger(limits.attemptTimeoutMs, 'attemptTimeoutMs')\n positiveInteger(limits.totalTimeoutMs, 'totalTimeoutMs')\n if (limits.attemptTimeoutMs > MAX_TIMER_DELAY_MS || limits.totalTimeoutMs > MAX_TIMER_DELAY_MS) {\n throw new RangeError('Timeouts must fit a signed 32-bit millisecond timer')\n }\n return Object.freeze(limits)\n}\n", "import type { FleetPayloadFamily } from '@xyo-network/service-kit-schemas'\nimport { HashZod } from '@xyo-network/service-kit-schemas'\n\nimport { monotonicClock, scheduleDeadline } from './clock.js'\nimport {\n captureFleetSignal, fleetSignalAborted, listenFleetAbort,\n} from './fleetSignal.js'\nimport { resolutionLimits } from './limits.js'\nimport type {\n ConfiguredSeed, ResolutionLimits, ResolveObjectOptions,\n} from './types.js'\nimport type { VerifiedFleetPayload } from './verifyFleetPayload.js'\nimport { verifyFleetPayload } from './verifyFleetPayload.js'\n\nexport interface FleetResolutionAttempt {\n readonly seedId: string\n readonly status: 'resolved' | 'missing' | 'invalid' | 'unsupported' | 'reader-error' | 'resource-limit' | 'timeout'\n}\nexport type FleetPayloadResolution\n = | (VerifiedFleetPayload & { readonly attempts: readonly FleetResolutionAttempt[] })\n | { readonly attempts: readonly FleetResolutionAttempt[]; readonly reason: 'unavailable' | 'deadline' | 'resource-limit'; readonly status: 'incomplete' }\n | { readonly attempts: readonly FleetResolutionAttempt[]; readonly status: 'aborted' }\n\ninterface PinnedSeed {\n readonly get: ConfiguredSeed['reader']['get']\n readonly id: string\n}\ninterface SeedResult {\n readonly payload?: VerifiedFleetPayload\n readonly status: FleetResolutionAttempt['status']\n}\n\nfunction pinSeeds(value: readonly ConfiguredSeed[], maxSeeds: number) {\n if (!Array.isArray(value) || value.length === 0 || value.length > maxSeeds) throw new RangeError('Explicit bounded readers required')\n const ids = new Set<string>()\n return Object.freeze(Array.from({ length: value.length }, (_, index): PinnedSeed => {\n const slot = Object.getOwnPropertyDescriptor(value, String(index))\n if (slot?.enumerable !== true || !('value' in slot)) throw new TypeError('Reader slots must be dense own data')\n const seed = slot.value as ConfiguredSeed\n const idSlot = Object.getOwnPropertyDescriptor(seed, 'id')\n const readerSlot = Object.getOwnPropertyDescriptor(seed, 'reader')\n if (idSlot === undefined || readerSlot === undefined || !('value' in idSlot) || !('value' in readerSlot)) {\n throw new TypeError('Reader configuration must use own data properties')\n }\n const id: unknown = idSlot.value\n if (typeof id !== 'string' || id.length === 0 || id.length > 128 || id.trim() !== id || ids.has(id)) {\n throw new TypeError('Each reader requires a unique bounded ID')\n }\n const reader: unknown = readerSlot.value\n if (typeof reader !== 'object' || reader === null) throw new TypeError('Each reader requires get')\n const methodSlot = Object.getOwnPropertyDescriptor(reader, 'get')\n if (methodSlot === undefined || !('value' in methodSlot) || typeof methodSlot.value !== 'function') {\n throw new TypeError('Each reader requires an own data get method')\n }\n const get = methodSlot.value as ConfiguredSeed['reader']['get']\n ids.add(id)\n return Object.freeze({ id, get: get.bind(reader) })\n }))\n}\n\nasync function readSeed(seed: PinnedSeed, root: string, family: FleetPayloadFamily, limits: ResolutionLimits, signal: AbortSignal, expired: () => boolean): Promise<SeedResult> {\n if (fleetSignalAborted(signal) || expired()) return { status: 'timeout' }\n const response: unknown = await seed.get([root], { signal, maxBodyBytes: limits.maxBodyBytes })\n if (fleetSignalAborted(signal) || expired()) return { status: 'timeout' }\n if (!Array.isArray(response) || response.length > limits.maxCandidatesPerSeed) return { status: 'resource-limit' }\n const candidates = Array.from({ length: response.length }, (_, index) => Object.getOwnPropertyDescriptor(response, String(index)))\n let status: SeedResult['status'] = candidates.length === 0 ? 'missing' : 'invalid'\n for (const slot of candidates) {\n if (fleetSignalAborted(signal) || expired()) return { status: 'timeout' }\n if (slot?.enumerable !== true || !('value' in slot)) continue\n const result = await verifyFleetPayload(root, family, slot.value, limits)\n if (fleetSignalAborted(signal) || expired()) return { status: 'timeout' }\n if (result.status === 'verified') return { status: 'resolved', payload: result }\n if (result.status === 'unsupported') status = 'unsupported'\n }\n return { status }\n}\n\nfunction attemptSeed(seed: PinnedSeed, root: string, family: FleetPayloadFamily, limits: ResolutionLimits, signal: AbortSignal, now: () => number, totalDeadline: number): Promise<SeedResult> {\n const deadline = Math.min(totalDeadline, now() + limits.attemptTimeoutMs)\n const expired = () => now() >= deadline\n return new Promise((resolve) => {\n const controller = new AbortController()\n let isSettled = false\n const finish = (result: SeedResult) => {\n if (isSettled) return\n isSettled = true\n cancelTimer()\n unlisten()\n controller.abort()\n resolve(expired() ? { status: 'timeout' } : result)\n }\n const onAbort = () => finish({ status: 'timeout' })\n const cancelTimer = scheduleDeadline(now, deadline, () => finish({ status: 'timeout' }))\n const unlisten = listenFleetAbort(signal, onAbort)\n if (fleetSignalAborted(signal)) {\n onAbort()\n return\n }\n queueMicrotask(() => {\n void (async () => {\n let result: SeedResult\n try {\n result = await readSeed(seed, root, family, limits, controller.signal, expired)\n } catch {\n result = { status: 'reader-error' }\n }\n finish(result)\n })()\n })\n })\n}\n\n/** Configured exact-root resolution only; no signer, history completeness or authority assertion. */\nexport async function resolveFleetPayload(root: string, family: FleetPayloadFamily, options: ResolveObjectOptions): Promise<FleetPayloadResolution> {\n HashZod.parse(root)\n const limits = resolutionLimits(options.limits)\n const seeds = pinSeeds(options.seeds, limits.maxSeeds)\n const signal = captureFleetSignal(options.signal)\n const now = monotonicClock()\n const deadline = now() + limits.totalTimeoutMs\n const attempts: FleetResolutionAttempt[] = []\n const controller = new AbortController()\n const state: { terminal?: 'aborted' | 'deadline' } = {}\n const terminate = (reason: 'aborted' | 'deadline') => {\n state.terminal ??= reason\n controller.abort()\n }\n const onAbort = () => terminate('aborted')\n const unlisten = listenFleetAbort(signal, onAbort)\n if (signal !== undefined && fleetSignalAborted(signal)) onAbort()\n const cancelTotal = scheduleDeadline(now, deadline, () => terminate('deadline'))\n try {\n for (const seed of seeds) {\n if (now() >= deadline) terminate('deadline')\n if (state.terminal !== undefined) break\n const result = await attemptSeed(seed, root, family, limits, controller.signal, now, deadline)\n attempts.push(Object.freeze({ seedId: seed.id, status: result.status }))\n if (now() >= deadline) terminate('deadline')\n if (state.terminal !== undefined) break\n if (result.payload !== undefined) return Object.freeze({ ...result.payload, attempts: Object.freeze(attempts) })\n if (result.status === 'resource-limit') return Object.freeze({\n status: 'incomplete', reason: 'resource-limit', attempts: Object.freeze(attempts),\n })\n }\n const frozen = Object.freeze(attempts)\n return state.terminal === 'aborted'\n ? Object.freeze({ status: 'aborted', attempts: frozen })\n : Object.freeze({\n status: 'incomplete', reason: state.terminal === 'deadline' ? 'deadline' : 'unavailable', attempts: frozen,\n })\n } finally {\n cancelTotal()\n controller.abort()\n unlisten()\n }\n}\n", "/** Use the common runtime clock without introducing Node- or DOM-only ambient types. */\nexport function monotonicClock(): () => number {\n const clock: unknown = 'performance' in globalThis ? globalThis.performance : undefined\n if (typeof clock !== 'object' || clock === null || !('now' in clock) || typeof clock.now !== 'function') {\n throw new TypeError('Object resolution requires performance.now()')\n }\n const read = clock.now.bind(clock) as () => unknown\n return () => {\n const now = read()\n if (typeof now !== 'number' || !Number.isFinite(now)) throw new TypeError('Invalid monotonic clock')\n return now\n }\n}\n\n/** Native timers are wake-ups to check a deadline, not proof that its monotonic time has arrived. */\nexport function scheduleDeadline(now: () => number, deadline: number, expired: () => void): () => void {\n let cancelled = false\n let timer: ReturnType<typeof setTimeout> | undefined\n const tick = () => {\n if (cancelled) return\n if (now() >= deadline) {\n cancelled = true\n expired()\n } else {\n arm()\n }\n }\n const arm = () => {\n // Round up and recheck: timer implementations may truncate delays or wake before the deadline.\n const delay = Math.min(MAX_TIMER_DELAY_MS, Math.max(1, Math.ceil(deadline - now())))\n timer = setTimeout(tick, delay)\n }\n arm()\n return () => {\n cancelled = true\n clearTimeout(timer)\n }\n}\nimport { MAX_TIMER_DELAY_MS } from './limits.js'\n", "import { isAnyPayload, PayloadBuilder } from '@xyo-network/sdk-protocol'\nimport type { FleetPayload, FleetPayloadFamily } from '@xyo-network/service-kit-schemas'\nimport {\n FLEET_PAYLOAD_VERSION, HashZod, parseFleetPayload,\n} from '@xyo-network/service-kit-schemas'\n\nimport { ObjectInputError, snapshotJson } from './jsonSnapshot.js'\nimport { verificationLimits } from './limits.js'\nimport type { ContentPayload, VerificationLimits } from './types.js'\n\nexport interface VerifiedFleetPayload {\n readonly assurance: 'sdk-root-verified'\n /** Original bounded snapshot, including client and storage metadata. */\n readonly nativePayload: ContentPayload\n /** Strict body/version view; never the input to root hashing. */\n readonly payload: Readonly<FleetPayload>\n readonly root: string\n readonly status: 'verified'\n}\n\nexport type FleetPayloadVerification\n = | VerifiedFleetPayload\n | { readonly reason: 'family' | 'version'; readonly status: 'unsupported' }\n | { readonly reason: 'invalid-json' | 'body-too-large' | 'structure-limit' | 'hash-mismatch' | 'invalid-envelope'; readonly status: 'invalid' }\n\n/** B4 original-root verification establishes content identity, never signer or public authority. */\nexport async function verifyFleetPayload(\n root: string,\n family: FleetPayloadFamily,\n candidate: unknown,\n options: Partial<VerificationLimits> = {},\n): Promise<FleetPayloadVerification> {\n HashZod.parse(root)\n const limits = verificationLimits(options)\n try {\n const snapshot = snapshotJson(candidate, limits)\n if (snapshot === null || typeof snapshot !== 'object' || Array.isArray(snapshot) || !isAnyPayload(snapshot)) {\n return Object.freeze({ status: 'invalid', reason: 'invalid-envelope' })\n }\n if (await PayloadBuilder.hash(snapshot) !== root) return Object.freeze({ status: 'invalid', reason: 'hash-mismatch' })\n if (snapshot.schema !== family) return Object.freeze({ status: 'unsupported', reason: 'family' })\n if (snapshot.$version !== FLEET_PAYLOAD_VERSION) return Object.freeze({ status: 'unsupported', reason: 'version' })\n // Retain client metadata for closed-envelope dispatch as well as original-root hashing.\n const body = PayloadBuilder.omitStorageMeta(snapshot)\n if (parseFleetPayload(body) === undefined) return Object.freeze({ status: 'invalid', reason: 'invalid-envelope' })\n return Object.freeze({\n status: 'verified',\n assurance: 'sdk-root-verified',\n root,\n nativePayload: snapshot as ContentPayload,\n payload: snapshotJson(body, limits) as unknown as Readonly<FleetPayload>,\n })\n } catch (error) {\n const reason = error instanceof ObjectInputError && (error.reason === 'body-too-large' || error.reason === 'structure-limit')\n ? error.reason\n : 'invalid-json'\n return Object.freeze({ status: 'invalid', reason })\n }\n}\n", "import type { ObjectReference } from '@xyo-network/service-kit-schemas'\nimport { ObjectReferenceZod } from '@xyo-network/service-kit-schemas'\n\nimport { monotonicClock, scheduleDeadline } from './clock.js'\nimport { resolutionLimits } from './limits.js'\nimport type {\n AttemptStatus,\n ConfiguredSeed,\n ObjectResolutionResult,\n ObjectVerificationFailureReason,\n ResolutionAttempt,\n ResolutionLimits,\n ResolveObjectOptions,\n VerifiedObject,\n} from './types.js'\nimport { verifyObject } from './verifyObject.js'\n\ninterface SeedResult {\n readonly candidateFailures?: readonly ObjectVerificationFailureReason[]\n readonly object?: VerifiedObject\n readonly status: AttemptStatus\n}\n\nfunction configuredSeeds(seeds: readonly ConfiguredSeed[], limits: ResolutionLimits) {\n if (!Array.isArray(seeds) || seeds.length === 0 || seeds.length > limits.maxSeeds) {\n throw new RangeError('Configure between one and maxSeeds explicit readers')\n }\n const ids = new Set<string>()\n const configured = seeds.map((seed: ConfiguredSeed): ConfiguredSeed => {\n if (typeof seed.id !== 'string' || seed.id.length === 0 || seed.id.length > 128 || seed.id.trim() !== seed.id) {\n throw new TypeError('Seed IDs must be nonempty, trimmed strings of at most 128 characters')\n }\n if (ids.has(seed.id)) throw new TypeError('Seed IDs must be unique')\n if (typeof seed.reader?.get !== 'function') throw new TypeError('Each seed requires a reader.get method')\n ids.add(seed.id)\n // Pin the reader and label before the first await; do not consult mutable seed configuration later.\n return Object.freeze({\n id: seed.id,\n reader: Object.freeze({ get: seed.reader.get.bind(seed.reader) }),\n })\n })\n for (let index = 0; index < configured.length; index++) {\n if (!Object.hasOwn(configured, index)) throw new TypeError('Seed configuration must not contain sparse slots')\n }\n return configured\n}\n\nasync function readCandidates(\n seed: ConfiguredSeed,\n reference: ObjectReference,\n limits: ResolutionLimits,\n signal: AbortSignal,\n expired: () => boolean,\n): Promise<SeedResult> {\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n const response: unknown = await seed.reader.get([reference.dataHash], { signal, maxBodyBytes: limits.maxBodyBytes })\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n if (!Array.isArray(response)) return { status: 'malformed-response' }\n const candidateCount = response.length\n if (!Number.isSafeInteger(candidateCount) || candidateCount < 0) return { status: 'malformed-response' }\n if (candidateCount > limits.maxCandidatesPerSeed) return { status: 'too-many-candidates' }\n if (candidateCount === 0) return { status: 'missing' }\n // Pin the bounded slots before verification yields; a reader must not enlarge the work budget.\n const candidates = Array.from({ length: candidateCount }, (_, index) => Object.getOwnPropertyDescriptor(response, String(index)))\n const candidateFailures: ObjectVerificationFailureReason[] = []\n for (const descriptor of candidates) {\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n if (descriptor === undefined || !('value' in descriptor)) {\n candidateFailures.push('invalid-json')\n continue\n }\n const candidate: unknown = descriptor.value\n const result = await verifyObject(reference, candidate, limits)\n if (signal.aborted) return { status: 'aborted' }\n if (expired()) return { status: 'timeout' }\n if (result.status === 'verified') return {\n status: 'resolved', object: result, candidateFailures,\n }\n candidateFailures.push(result.reason)\n }\n return { status: 'invalid-object', candidateFailures }\n}\n\nfunction attemptSeed(\n seed: ConfiguredSeed,\n reference: ObjectReference,\n limits: ResolutionLimits,\n outerSignal: AbortSignal,\n now: () => number,\n totalDeadline: number,\n): Promise<SeedResult> {\n const deadline = Math.min(now() + limits.attemptTimeoutMs, totalDeadline)\n const expired = () => now() >= deadline\n return new Promise((resolve) => {\n const controller = new AbortController()\n let isSettled = false\n const finish = (result: SeedResult) => {\n if (isSettled) return\n // Timer callbacks may be delayed by synchronous work or a busy microtask queue.\n // Reject late completions even when the timer has not had a chance to run.\n const outcome: SeedResult = result.status !== 'aborted' && expired() ? { status: 'timeout' } : result\n isSettled = true\n cancelTimer()\n outerSignal.removeEventListener('abort', onAbort)\n if (outcome.status === 'timeout') controller.abort()\n resolve(outcome)\n }\n const onAbort = () => {\n controller.abort()\n finish({ status: 'aborted' })\n }\n const cancelTimer = scheduleDeadline(now, deadline, () => {\n controller.abort()\n finish({ status: 'timeout' })\n })\n outerSignal.addEventListener('abort', onAbort, { once: true })\n if (outerSignal.aborted) {\n onAbort()\n return\n }\n // Defer the read one microtask so abort and deadline checks win, then settle either outcome.\n // Keep finish outside the rejection path so a failure inside finish is not reported as a reader error.\n queueMicrotask(() => {\n void (async () => {\n let result: SeedResult\n try {\n result = await readCandidates(seed, reference, limits, controller.signal, expired)\n } catch {\n finish({ status: 'reader-error' })\n return\n }\n finish(result)\n })()\n })\n })\n}\n\nfunction diagnostic(seedId: string, result: SeedResult): ResolutionAttempt {\n return Object.freeze({\n seedId,\n status: result.status,\n ...(result.candidateFailures !== undefined && { candidateFailures: Object.freeze([...result.candidateFailures]) }),\n })\n}\n\n/** Resolve exact content through configured readers only; never infer service absence or authority. */\nexport async function resolveObject(\n reference: ObjectReference,\n options: ResolveObjectOptions,\n): Promise<ObjectResolutionResult> {\n const expected = Object.freeze(ObjectReferenceZod.parse(reference))\n const limits = resolutionLimits(options.limits)\n const seeds = configuredSeeds(options.seeds, limits)\n const signal = options.signal\n const attempts: ResolutionAttempt[] = []\n if (signal?.aborted === true) return { status: 'aborted', attempts: Object.freeze(attempts) }\n\n const now = monotonicClock()\n const deadline = now() + limits.totalTimeoutMs\n const controller = new AbortController()\n const state: { terminal?: 'aborted' | 'deadline-exceeded' } = {}\n const terminate = (reason: 'aborted' | 'deadline-exceeded') => {\n if (state.terminal !== undefined) return\n state.terminal = reason\n controller.abort()\n }\n const onAbort = () => terminate('aborted')\n signal?.addEventListener('abort', onAbort, { once: true })\n const cancelTimer = scheduleDeadline(now, deadline, () => terminate('deadline-exceeded'))\n try {\n for (const seed of seeds) {\n if (now() >= deadline) terminate('deadline-exceeded')\n if (state.terminal !== undefined) break\n const result = await attemptSeed(seed, expected, limits, controller.signal, now, deadline)\n attempts.push(diagnostic(seed.id, result))\n if (now() >= deadline) terminate('deadline-exceeded')\n if (state.terminal !== undefined) break\n if (result.object !== undefined) {\n return Object.freeze({\n status: 'resolved',\n assurance: 'content-hash-verified',\n reference: result.object.reference,\n payload: result.object.payload,\n seedId: seed.id,\n attempts: Object.freeze([...attempts]),\n })\n }\n }\n if (state.terminal === 'aborted') return { status: 'aborted', attempts: Object.freeze([...attempts]) }\n return {\n status: 'unavailable',\n reason: state.terminal === 'deadline-exceeded' ? 'deadline-exceeded' : 'seeds-exhausted',\n attempts: Object.freeze([...attempts]),\n }\n } finally {\n cancelTimer()\n signal?.removeEventListener('abort', onAbort)\n }\n}\n", "import { isAnyPayload, PayloadBuilder } from '@xyo-network/sdk-protocol'\nimport type { ObjectReference } from '@xyo-network/service-kit-schemas'\nimport {\n DataLakeLocatorSchema, DataLakeLocatorZod,\n ObjectReferenceZod,\n ServiceAdvertisementSchema, ServiceAdvertisementZod,\n} from '@xyo-network/service-kit-schemas'\n\nimport { ObjectInputError, snapshotJson } from './jsonSnapshot.js'\nimport { verificationLimits } from './limits.js'\nimport type {\n ContentPayload, ObjectVerificationResult, VerificationLimits,\n} from './types.js'\n\n/** Verify content only. No Claim, lifecycle, publisher authority, or freshness is established. */\nexport async function verifyObject(\n reference: ObjectReference,\n candidate: unknown,\n options: Partial<VerificationLimits> = {},\n): Promise<ObjectVerificationResult> {\n const expected = Object.freeze(ObjectReferenceZod.parse(reference))\n const limits = verificationLimits(options)\n try {\n const snapshot = snapshotJson(candidate, limits)\n if (snapshot === null || typeof snapshot !== 'object' || Array.isArray(snapshot)) {\n return { status: 'invalid', reason: 'not-payload' }\n }\n // Metadata is bounded JSON input, but cannot decide the committed Payload representation.\n const data = PayloadBuilder.omitMeta(snapshot)\n // Use a guard, never a parser that strips unknown fields before hashing.\n if (!isAnyPayload(data)) return { status: 'invalid', reason: 'not-payload' }\n const actualHash = await PayloadBuilder.dataHash(data)\n if (actualHash !== expected.dataHash) return { status: 'invalid', reason: 'hash-mismatch' }\n if (data.schema !== expected.schema) return { status: 'invalid', reason: 'schema-mismatch' }\n\n // These are strict validators without coercion, defaults, or transformations.\n // Hash the complete data first, and return the data rather than a parser projection.\n if (data.schema === ServiceAdvertisementSchema && !ServiceAdvertisementZod.safeParse(data).success) {\n return { status: 'invalid', reason: 'invalid-descriptor' }\n }\n if (data.schema === DataLakeLocatorSchema && !DataLakeLocatorZod.safeParse(data).success) {\n return { status: 'invalid', reason: 'invalid-descriptor' }\n }\n const payload = snapshotJson(data, limits) as ContentPayload\n return Object.freeze({\n status: 'verified', assurance: 'content-hash-verified', reference: expected, payload,\n })\n } catch (error) {\n return {\n status: 'invalid',\n reason: error instanceof ObjectInputError ? error.reason : 'invalid-json',\n }\n }\n}\n"],
5
+ "mappings": ";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,MAAM,aAAa,sBAAsB,sBAAsB;AAAA,MACvE,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,CAAC;AAAA,IACvC;AAAA,EACF,UAAE;AACA,gBAAY;AACZ,YAAQ,oBAAoB,SAAS,OAAO;AAAA,EAC9C;AACF;",
6
+ "names": ["encoder", "AddressZod", "HashZod", "HashZod", "AddressZod", "HashZod", "HashZod", "parseFleetPayload", "HashZod", "parseFleetPayload", "HashZod", "ObjectReferenceZod", "isAnyPayload", "PayloadBuilder", "PayloadBuilder", "isAnyPayload", "attemptSeed", "ObjectReferenceZod"]
7
7
  }
@@ -0,0 +1,20 @@
1
+ import type { FleetPayloadFamily } from '@xyo-network/service-kit-schemas';
2
+ import type { ResolveObjectOptions } from './types.js';
3
+ import type { VerifiedFleetPayload } from './verifyFleetPayload.js';
4
+ export interface FleetResolutionAttempt {
5
+ readonly seedId: string;
6
+ readonly status: 'resolved' | 'missing' | 'invalid' | 'unsupported' | 'reader-error' | 'resource-limit' | 'timeout';
7
+ }
8
+ export type FleetPayloadResolution = (VerifiedFleetPayload & {
9
+ readonly attempts: readonly FleetResolutionAttempt[];
10
+ }) | {
11
+ readonly attempts: readonly FleetResolutionAttempt[];
12
+ readonly reason: 'unavailable' | 'deadline' | 'resource-limit';
13
+ readonly status: 'incomplete';
14
+ } | {
15
+ readonly attempts: readonly FleetResolutionAttempt[];
16
+ readonly status: 'aborted';
17
+ };
18
+ /** Configured exact-root resolution only; no signer, history completeness or authority assertion. */
19
+ export declare function resolveFleetPayload(root: string, family: FleetPayloadFamily, options: ResolveObjectOptions): Promise<FleetPayloadResolution>;
20
+ //# sourceMappingURL=resolveFleetPayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveFleetPayload.d.ts","sourceRoot":"","sources":["../../src/resolveFleetPayload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAQ1E,OAAO,KAAK,EACwB,oBAAoB,EACvD,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAGnE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,cAAc,GAAG,gBAAgB,GAAG,SAAS,CAAA;CACpH;AACD,MAAM,MAAM,sBAAsB,GAC5B,CAAC,oBAAoB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,sBAAsB,EAAE,CAAA;CAAE,CAAC,GACjF;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,GAAG,gBAAgB,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GACvJ;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAA;AA4F1F,qGAAqG;AACrG,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CA0ClJ"}
@@ -0,0 +1,21 @@
1
+ import type { FleetPayload, FleetPayloadFamily } from '@xyo-network/service-kit-schemas';
2
+ import type { ContentPayload, VerificationLimits } from './types.js';
3
+ export interface VerifiedFleetPayload {
4
+ readonly assurance: 'sdk-root-verified';
5
+ /** Original bounded snapshot, including client and storage metadata. */
6
+ readonly nativePayload: ContentPayload;
7
+ /** Strict body/version view; never the input to root hashing. */
8
+ readonly payload: Readonly<FleetPayload>;
9
+ readonly root: string;
10
+ readonly status: 'verified';
11
+ }
12
+ export type FleetPayloadVerification = VerifiedFleetPayload | {
13
+ readonly reason: 'family' | 'version';
14
+ readonly status: 'unsupported';
15
+ } | {
16
+ readonly reason: 'invalid-json' | 'body-too-large' | 'structure-limit' | 'hash-mismatch' | 'invalid-envelope';
17
+ readonly status: 'invalid';
18
+ };
19
+ /** B4 original-root verification establishes content identity, never signer or public authority. */
20
+ export declare function verifyFleetPayload(root: string, family: FleetPayloadFamily, candidate: unknown, options?: Partial<VerificationLimits>): Promise<FleetPayloadVerification>;
21
+ //# sourceMappingURL=verifyFleetPayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyFleetPayload.d.ts","sourceRoot":"","sources":["../../src/verifyFleetPayload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAOxF,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAA;IACvC,wEAAwE;IACxE,QAAQ,CAAC,aAAa,EAAE,cAAc,CAAA;IACtC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAA;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAC5B;AAED,MAAM,MAAM,wBAAwB,GAC9B,oBAAoB,GACpB;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAAE,GACzE;IAAE,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,eAAe,GAAG,kBAAkB,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAA;AAEnJ,oGAAoG;AACpG,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM,GACxC,OAAO,CAAC,wBAAwB,CAAC,CA2BnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/service-kit-protocol",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Hash-verified public-object resolution through explicit seed readers",
5
5
  "license": "LGPL-3.0-only",
6
6
  "sideEffects": false,
@@ -18,19 +18,19 @@
18
18
  "README.md"
19
19
  ],
20
20
  "dependencies": {
21
- "@xyo-network/service-kit-schemas": "~0.2.0"
21
+ "@xyo-network/service-kit-schemas": "~0.2.2"
22
22
  },
23
23
  "devDependencies": {
24
- "@ariestools/lib-neutral": "~10.1.0",
25
- "@ariestools/toolchain": "~10.1.0",
26
- "@ariestools/tsconfig": "~10.1.0",
27
- "@xyo-network/sdk-protocol": "~8.0.1",
28
- "eslint": "~10.12.0",
24
+ "@ariestools/lib-neutral": "~10.2.1",
25
+ "@ariestools/toolchain": "~10.2.1",
26
+ "@ariestools/tsconfig": "~10.2.1",
27
+ "@xyo-network/sdk-protocol": "~8.0.3",
28
+ "eslint": "~10.13.0",
29
29
  "eslint-import-resolver-typescript": "~4.4.5",
30
30
  "typescript": "~6.0.3",
31
- "vite": "~8.3.2",
32
- "vitest": "~5.0.3",
33
- "zod": "~4.6.5"
31
+ "vite": "~8.3.5",
32
+ "vitest": "~5.0.5",
33
+ "zod": "~4.6.7"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@xyo-network/sdk-protocol": "^8.0",