@toon-protocol/core 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -6
- package/dist/index.d.ts +1343 -166
- package/dist/index.js +1521 -196
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,337 @@ declare const TEXT_TO_SPEECH_KIND = 5300;
|
|
|
84
84
|
* Optional provider support -- not all nodes are required to handle this kind.
|
|
85
85
|
*/
|
|
86
86
|
declare const TRANSLATION_KIND = 5302;
|
|
87
|
+
/**
|
|
88
|
+
* Workflow Chain definition (kind 10040).
|
|
89
|
+
* Replaceable event defining a multi-step DVM pipeline where each step's
|
|
90
|
+
* output feeds into the next step's input. Uses a unique `d` tag per
|
|
91
|
+
* workflow instance for NIP-33 parameterized replaceable semantics.
|
|
92
|
+
* In the TOON-specific replaceable range (10032-10099).
|
|
93
|
+
*/
|
|
94
|
+
declare const WORKFLOW_CHAIN_KIND = 10040;
|
|
95
|
+
/**
|
|
96
|
+
* Job Review (kind 31117)
|
|
97
|
+
* NIP-33 parameterized replaceable event for post-job reviews.
|
|
98
|
+
* `d` tag = job request event ID enforces one review per job per reviewer.
|
|
99
|
+
* Rating tag contains integer 1-5. Role tag indicates 'customer' or 'provider'.
|
|
100
|
+
*/
|
|
101
|
+
declare const JOB_REVIEW_KIND = 31117;
|
|
102
|
+
/**
|
|
103
|
+
* Web of Trust declaration (kind 30382)
|
|
104
|
+
* NIP-33 parameterized replaceable event endorsing a provider pubkey.
|
|
105
|
+
* `d` tag = target provider pubkey enforces one WoT declaration per
|
|
106
|
+
* declarer per target. Used for reputation scoring sybil defense.
|
|
107
|
+
*/
|
|
108
|
+
declare const WEB_OF_TRUST_KIND = 30382;
|
|
109
|
+
/**
|
|
110
|
+
* Prefix Claim (kind 10034)
|
|
111
|
+
* Replaceable event requesting a prefix claim from an upstream node.
|
|
112
|
+
* The content field contains a PrefixClaimContent JSON payload with the
|
|
113
|
+
* requested prefix string. Payment is carried in the ILP PREPARE packet.
|
|
114
|
+
*/
|
|
115
|
+
declare const PREFIX_CLAIM_KIND = 10034;
|
|
116
|
+
/**
|
|
117
|
+
* Prefix Grant (kind 10037)
|
|
118
|
+
* Replaceable event confirming a prefix claim was accepted by the upstream node.
|
|
119
|
+
* Published by the upstream node after validating payment and prefix availability.
|
|
120
|
+
* Contains the granted prefix, claimer's pubkey, and derived ILP address.
|
|
121
|
+
*/
|
|
122
|
+
declare const PREFIX_GRANT_KIND = 10037;
|
|
123
|
+
/**
|
|
124
|
+
* ILP root prefix for the TOON network.
|
|
125
|
+
* `g.` is the ILP global allocation prefix (standard ILP convention).
|
|
126
|
+
* `toon` is the TOON network identifier.
|
|
127
|
+
* The genesis node uses this directly -- it does not derive its address from a pubkey.
|
|
128
|
+
* All other nodes derive addresses as children of their upstream peer's prefix.
|
|
129
|
+
*/
|
|
130
|
+
/**
|
|
131
|
+
* Blob Storage DVM kind (kind 5094).
|
|
132
|
+
* Used for permanent blob storage requests (e.g., Arweave uploads).
|
|
133
|
+
* The blob data is base64-encoded in the `i` tag with type `blob`.
|
|
134
|
+
* Payment is carried in the ILP PREPARE packet (prepaid model).
|
|
135
|
+
*/
|
|
136
|
+
declare const BLOB_STORAGE_REQUEST_KIND = 5094;
|
|
137
|
+
/**
|
|
138
|
+
* Blob Storage Result DVM kind (kind 6094).
|
|
139
|
+
* Reserved for informational result events. In the prepaid model,
|
|
140
|
+
* the Arweave tx ID is returned in the ILP FULFILL data field,
|
|
141
|
+
* NOT as a kind:6094 event.
|
|
142
|
+
*/
|
|
143
|
+
declare const BLOB_STORAGE_RESULT_KIND = 6094;
|
|
144
|
+
/**
|
|
145
|
+
* Pet Interaction Request DVM kind (kind 5900).
|
|
146
|
+
* Used for pet interaction requests (feed, play, clean, etc.).
|
|
147
|
+
* Kind 5900 chosen to leave room for future DVM kinds in 5000-5899 range.
|
|
148
|
+
* Payment is carried in the ILP PREPARE packet (prepaid model).
|
|
149
|
+
*/
|
|
150
|
+
declare const PET_INTERACTION_REQUEST_KIND = 5900;
|
|
151
|
+
/**
|
|
152
|
+
* Pet Interaction Result DVM kind (kind 6900).
|
|
153
|
+
* Result kind = request kind + 1000 per NIP-90 convention.
|
|
154
|
+
* In the prepaid model, the new pet state is returned in the ILP FULFILL
|
|
155
|
+
* data field as base64-encoded JSON.
|
|
156
|
+
*/
|
|
157
|
+
declare const PET_INTERACTION_RESULT_KIND = 6900;
|
|
158
|
+
/**
|
|
159
|
+
* Pet Interaction Event kind (kind 14919).
|
|
160
|
+
* Optimistic interaction event published to relays after processing.
|
|
161
|
+
* Contains action details, stat changes, and brain hash.
|
|
162
|
+
* No proof or mina_tx tags -- those are added by the proof settlement
|
|
163
|
+
* pipeline after ZK proof generation.
|
|
164
|
+
*/
|
|
165
|
+
declare const PET_INTERACTION_EVENT_KIND = 14919;
|
|
166
|
+
declare const ILP_ROOT_PREFIX = "g.toon";
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Shared ILP address validation utilities.
|
|
170
|
+
*
|
|
171
|
+
* Centralizes ILP address structure validation used by both
|
|
172
|
+
* `derive-child-address.ts` and `btp-prefix-exchange.ts`.
|
|
173
|
+
*
|
|
174
|
+
* @module
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Returns `true` if the string is a structurally valid ILP address
|
|
178
|
+
* (dot-separated, non-empty segments, valid characters only).
|
|
179
|
+
*/
|
|
180
|
+
declare function isValidIlpAddressStructure(address: string): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Validates that a string is a valid ILP address. Throws a `ToonError`
|
|
183
|
+
* with code `ADDRESS_INVALID_PREFIX` on any structural violation.
|
|
184
|
+
*
|
|
185
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PREFIX` if the address
|
|
186
|
+
* contains empty segments or invalid characters.
|
|
187
|
+
*/
|
|
188
|
+
declare function validateIlpAddress(address: string): void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Deterministic ILP address derivation from Nostr pubkeys.
|
|
192
|
+
*
|
|
193
|
+
* Derives a child ILP address by appending the first 8 hex characters
|
|
194
|
+
* of a Nostr pubkey as a new segment to a parent ILP address prefix.
|
|
195
|
+
*
|
|
196
|
+
* @module
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Derives a child ILP address by appending the first 8 hex characters of a
|
|
200
|
+
* Nostr pubkey as a new segment to a parent ILP address prefix.
|
|
201
|
+
*
|
|
202
|
+
* @param parentPrefix - The parent ILP address prefix (e.g., `g.toon` or `g.toon.ef567890`)
|
|
203
|
+
* @param childPubkey - The child's Nostr pubkey (hex string, at least 8 characters)
|
|
204
|
+
* @returns The derived child ILP address (e.g., `g.toon.abcd1234`)
|
|
205
|
+
*
|
|
206
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PREFIX` if `parentPrefix` is empty or
|
|
207
|
+
* contains invalid ILP address characters.
|
|
208
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PUBKEY` if `childPubkey` is shorter than
|
|
209
|
+
* 8 hex characters or contains non-hex characters.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* deriveChildAddress('g.toon', 'abcd1234abcd1234...') // => 'g.toon.abcd1234'
|
|
214
|
+
* deriveChildAddress('g.toon.ef567890', '11aabb22...') // => 'g.toon.ef567890.11aabb22'
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
declare function deriveChildAddress(parentPrefix: string, childPubkey: string): string;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* BTP handshake prefix exchange utilities.
|
|
221
|
+
*
|
|
222
|
+
* Provides extraction, building, and validation functions for the prefix
|
|
223
|
+
* data exchanged during BTP handshake. This module defines the structural
|
|
224
|
+
* type for prefix extension data but does NOT modify the BTP wire protocol
|
|
225
|
+
* (which lives in @toon-protocol/connector).
|
|
226
|
+
*
|
|
227
|
+
* @module
|
|
228
|
+
*/
|
|
229
|
+
/**
|
|
230
|
+
* Shape of prefix data in BTP handshake messages.
|
|
231
|
+
* Upstream peers include this in their handshake response so that
|
|
232
|
+
* connecting nodes can derive their own ILP address.
|
|
233
|
+
*/
|
|
234
|
+
interface BtpHandshakeExtension {
|
|
235
|
+
prefix: string;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Extracts and validates the prefix field from BTP handshake response data.
|
|
239
|
+
*
|
|
240
|
+
* Fail-closed behavior: throws if the prefix is absent, empty, or invalid.
|
|
241
|
+
* This is the critical safety contract -- nodes MUST NOT fall back to
|
|
242
|
+
* hardcoded addresses when the upstream peer omits the prefix.
|
|
243
|
+
*
|
|
244
|
+
* @param handshakeData - The handshake response data object
|
|
245
|
+
* @returns The validated prefix string
|
|
246
|
+
*
|
|
247
|
+
* @throws {ToonError} With code `ADDRESS_MISSING_PREFIX` if the `prefix` field
|
|
248
|
+
* is absent or empty.
|
|
249
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PREFIX` if the prefix fails
|
|
250
|
+
* ILP address validation.
|
|
251
|
+
*/
|
|
252
|
+
declare function extractPrefixFromHandshake(handshakeData: Record<string, unknown>): string;
|
|
253
|
+
/**
|
|
254
|
+
* Constructs the prefix extension data that upstream peers include
|
|
255
|
+
* in their handshake response.
|
|
256
|
+
*
|
|
257
|
+
* Validates the address before building the handshake data to ensure
|
|
258
|
+
* upstream peers never send structurally invalid prefixes.
|
|
259
|
+
*
|
|
260
|
+
* @param ownIlpAddress - The upstream peer's own ILP address
|
|
261
|
+
* @returns The handshake extension data containing the prefix
|
|
262
|
+
*
|
|
263
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PREFIX` if the address
|
|
264
|
+
* is not a valid ILP address.
|
|
265
|
+
*/
|
|
266
|
+
declare function buildPrefixHandshakeData(ownIlpAddress: string): BtpHandshakeExtension;
|
|
267
|
+
/**
|
|
268
|
+
* Cross-validates the handshake prefix against the upstream peer's
|
|
269
|
+
* kind:10032 advertised address.
|
|
270
|
+
*
|
|
271
|
+
* When both values are available and they do not match, throws a
|
|
272
|
+
* ToonError indicating potential prefix spoofing. When the advertised
|
|
273
|
+
* prefix is undefined (kind:10032 not yet discovered), validation is
|
|
274
|
+
* deferred (no-op).
|
|
275
|
+
*
|
|
276
|
+
* @param handshakePrefix - The prefix received during BTP handshake
|
|
277
|
+
* @param advertisedPrefix - The upstream peer's kind:10032 advertised address (optional)
|
|
278
|
+
*
|
|
279
|
+
* @throws {ToonError} With code `ADDRESS_PREFIX_MISMATCH` if both values
|
|
280
|
+
* are available and do not match.
|
|
281
|
+
*/
|
|
282
|
+
declare function validatePrefixConsistency(handshakePrefix: string, advertisedPrefix?: string): void;
|
|
283
|
+
/**
|
|
284
|
+
* Checks whether a derived address collides with any known peer addresses.
|
|
285
|
+
*
|
|
286
|
+
* Safety net for the 8-char truncation collision case (exceedingly unlikely
|
|
287
|
+
* at < 9,292 peers, but the check exists per E7-R001).
|
|
288
|
+
*
|
|
289
|
+
* @param derivedAddress - The newly derived ILP address
|
|
290
|
+
* @param knownPeerAddresses - List of existing peer addresses to check against
|
|
291
|
+
*
|
|
292
|
+
* @throws {ToonError} With code `ADDRESS_COLLISION` if the derived address
|
|
293
|
+
* already exists in the known peer list.
|
|
294
|
+
*/
|
|
295
|
+
declare function checkAddressCollision(derivedAddress: string, knownPeerAddresses: string[]): void;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Address assignment orchestration layer.
|
|
299
|
+
*
|
|
300
|
+
* Combines BTP prefix extraction with deterministic address derivation
|
|
301
|
+
* to assign ILP addresses during the handshake process.
|
|
302
|
+
*
|
|
303
|
+
* @module
|
|
304
|
+
*/
|
|
305
|
+
/**
|
|
306
|
+
* Orchestrates address assignment from BTP handshake data:
|
|
307
|
+
* 1. Extracts and validates the prefix from handshake data
|
|
308
|
+
* 2. Derives the child address using `deriveChildAddress(prefix, ownPubkey)`
|
|
309
|
+
*
|
|
310
|
+
* @param handshakeData - The BTP handshake response data object
|
|
311
|
+
* @param ownPubkey - The connecting node's Nostr pubkey (hex string)
|
|
312
|
+
* @returns The derived ILP address
|
|
313
|
+
*
|
|
314
|
+
* @throws {ToonError} With code `ADDRESS_MISSING_PREFIX` if the handshake
|
|
315
|
+
* data lacks a prefix field (fail-closed behavior).
|
|
316
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PREFIX` if the prefix is
|
|
317
|
+
* not a valid ILP address.
|
|
318
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PUBKEY` if the pubkey is
|
|
319
|
+
* shorter than 8 hex characters or contains non-hex characters.
|
|
320
|
+
*/
|
|
321
|
+
declare function assignAddressFromHandshake(handshakeData: Record<string, unknown>, ownPubkey: string): string;
|
|
322
|
+
/**
|
|
323
|
+
* Determines whether a node configuration represents a genesis node.
|
|
324
|
+
*
|
|
325
|
+
* Genesis nodes use `ILP_ROOT_PREFIX` (`g.toon`) directly without
|
|
326
|
+
* derivation -- they are the root of the address hierarchy and do
|
|
327
|
+
* not need a handshake to learn their prefix.
|
|
328
|
+
*
|
|
329
|
+
* @param config - Node configuration with optional ilpAddress
|
|
330
|
+
* @returns `true` if the node's configured address equals `ILP_ROOT_PREFIX`
|
|
331
|
+
*/
|
|
332
|
+
declare function isGenesisNode(config: {
|
|
333
|
+
ilpAddress?: string;
|
|
334
|
+
}): boolean;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* AddressRegistry tracks upstream prefix -> derived ILP address mappings.
|
|
338
|
+
*
|
|
339
|
+
* Used by multi-peered nodes to manage address lifecycle: when an upstream
|
|
340
|
+
* peer connects, the node derives and registers an address; when the peer
|
|
341
|
+
* disconnects, the address is removed and kind:10032 republished.
|
|
342
|
+
*
|
|
343
|
+
* Addresses are returned in insertion order so that the primary address
|
|
344
|
+
* (first inserted) is stable across lifecycle events.
|
|
345
|
+
*
|
|
346
|
+
* @module
|
|
347
|
+
*/
|
|
348
|
+
/**
|
|
349
|
+
* Tracks the mapping from upstream ILP prefix to derived ILP address.
|
|
350
|
+
*
|
|
351
|
+
* Uses a `Map<string, string>` internally, which preserves insertion order
|
|
352
|
+
* per the ECMAScript specification.
|
|
353
|
+
*/
|
|
354
|
+
declare class AddressRegistry {
|
|
355
|
+
private readonly prefixToAddress;
|
|
356
|
+
/**
|
|
357
|
+
* Registers a new upstream prefix -> derived address mapping.
|
|
358
|
+
*
|
|
359
|
+
* @param upstreamPrefix - The upstream peer's ILP address prefix
|
|
360
|
+
* @param derivedAddress - The derived ILP address for this node under that prefix
|
|
361
|
+
*/
|
|
362
|
+
addAddress(upstreamPrefix: string, derivedAddress: string): void;
|
|
363
|
+
/**
|
|
364
|
+
* Removes the mapping for the given upstream prefix.
|
|
365
|
+
*
|
|
366
|
+
* @param upstreamPrefix - The upstream prefix to remove
|
|
367
|
+
* @returns The removed derived address, or `undefined` if the prefix was not found
|
|
368
|
+
*/
|
|
369
|
+
removeAddress(upstreamPrefix: string): string | undefined;
|
|
370
|
+
/**
|
|
371
|
+
* Returns all derived addresses in insertion order.
|
|
372
|
+
*/
|
|
373
|
+
getAddresses(): string[];
|
|
374
|
+
/**
|
|
375
|
+
* Returns `true` if the given upstream prefix is registered.
|
|
376
|
+
*/
|
|
377
|
+
hasPrefix(upstreamPrefix: string): boolean;
|
|
378
|
+
/**
|
|
379
|
+
* Returns the number of registered addresses.
|
|
380
|
+
*/
|
|
381
|
+
get size(): number;
|
|
382
|
+
/**
|
|
383
|
+
* Returns the primary (first inserted) address.
|
|
384
|
+
*
|
|
385
|
+
* @returns The first address, or `undefined` if the registry is empty
|
|
386
|
+
*/
|
|
387
|
+
getPrimaryAddress(): string | undefined;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Prefix validation utility for the TOON prefix claim marketplace.
|
|
392
|
+
*
|
|
393
|
+
* Validates requested prefix strings against naming rules:
|
|
394
|
+
* lowercase alphanumeric only, length constraints, no reserved words.
|
|
395
|
+
*/
|
|
396
|
+
/**
|
|
397
|
+
* Result of prefix validation.
|
|
398
|
+
*/
|
|
399
|
+
interface PrefixValidationResult {
|
|
400
|
+
/** Whether the prefix is valid. */
|
|
401
|
+
valid: boolean;
|
|
402
|
+
/** Reason for rejection (only present when valid is false). */
|
|
403
|
+
reason?: string;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Validates a prefix string for use in the prefix claim marketplace.
|
|
407
|
+
*
|
|
408
|
+
* Rules:
|
|
409
|
+
* - Lowercase alphanumeric only (`[a-z0-9]`)
|
|
410
|
+
* - Minimum 2 characters
|
|
411
|
+
* - Maximum 16 characters
|
|
412
|
+
* - No reserved words (`toon`, `ilp`, `local`, `peer`, `test`)
|
|
413
|
+
*
|
|
414
|
+
* @param prefix - The prefix string to validate
|
|
415
|
+
* @returns Validation result with valid flag and optional reason
|
|
416
|
+
*/
|
|
417
|
+
declare function validatePrefix(prefix: string): PrefixValidationResult;
|
|
87
418
|
|
|
88
419
|
/**
|
|
89
420
|
* TypeScript interfaces for ILP-related Nostr events.
|
|
@@ -97,6 +428,8 @@ interface IlpPeerInfo {
|
|
|
97
428
|
pubkey?: string;
|
|
98
429
|
/** ILP address of the peer's connector (e.g., "g.example.connector") */
|
|
99
430
|
ilpAddress: string;
|
|
431
|
+
/** All ILP addresses of this peer (one per upstream peering). When absent (pre-Epic-7 events), consumers should default to [ilpAddress]. */
|
|
432
|
+
ilpAddresses?: string[];
|
|
100
433
|
/** BTP WebSocket endpoint URL for packet exchange */
|
|
101
434
|
btpEndpoint: string;
|
|
102
435
|
/** Optional BLS HTTP endpoint for direct packet delivery (bootstrap only) */
|
|
@@ -115,6 +448,12 @@ interface IlpPeerInfo {
|
|
|
115
448
|
preferredTokens?: Record<string, string>;
|
|
116
449
|
/** Maps chain identifier to TokenNetwork contract address (EVM-specific) */
|
|
117
450
|
tokenNetworks?: Record<string, string>;
|
|
451
|
+
/** Routing fee per byte charged by this node as an intermediary, serialized as a non-negative integer string (e.g., '2'). Defaults to '0' (free routing) when absent. */
|
|
452
|
+
feePerByte?: string;
|
|
453
|
+
/** Prefix pricing for prefix claim marketplace. basePrice is in USDC micro-units as a non-negative integer string. */
|
|
454
|
+
prefixPricing?: {
|
|
455
|
+
basePrice: string;
|
|
456
|
+
};
|
|
118
457
|
}
|
|
119
458
|
/**
|
|
120
459
|
* Subscription handle for real-time event updates.
|
|
@@ -221,9 +560,17 @@ declare function parseIlpPeerInfo(event: NostrEvent): IlpPeerInfo;
|
|
|
221
560
|
/**
|
|
222
561
|
* Builds and signs a kind:10032 Nostr event from IlpPeerInfo data.
|
|
223
562
|
*
|
|
563
|
+
* When `ilpAddresses` is present, validates that the array is non-empty and
|
|
564
|
+
* that all elements are structurally valid ILP addresses. Normalizes
|
|
565
|
+
* `ilpAddress` (singular) to equal `ilpAddresses[0]` for backward compatibility.
|
|
566
|
+
*
|
|
224
567
|
* @param info - The ILP peer info to serialize into the event
|
|
225
568
|
* @param secretKey - The secret key to sign the event with
|
|
226
569
|
* @returns A signed Nostr event
|
|
570
|
+
*
|
|
571
|
+
* @throws {ToonError} With code `INVALID_FEE` if `feePerByte` is not a non-negative integer string
|
|
572
|
+
* @throws {ToonError} With code `ADDRESS_EMPTY_ADDRESSES` if `ilpAddresses` is an empty array
|
|
573
|
+
* @throws {ToonError} With code `ADDRESS_INVALID_PREFIX` if any element of `ilpAddresses` is invalid
|
|
227
574
|
*/
|
|
228
575
|
declare function buildIlpPeerInfoEvent(info: IlpPeerInfo, secretKey: Uint8Array): NostrEvent;
|
|
229
576
|
|
|
@@ -271,6 +618,184 @@ declare function buildSeedRelayListEvent(secretKey: Uint8Array, entries: SeedRel
|
|
|
271
618
|
*/
|
|
272
619
|
declare function parseSeedRelayList(event: NostrEvent): SeedRelayEntry[];
|
|
273
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Event builders, parsers, and reputation scoring for DVM reputation system.
|
|
623
|
+
*
|
|
624
|
+
* Defines two new event kinds:
|
|
625
|
+
* - Kind 31117 (Job Review): NIP-33 parameterized replaceable event for
|
|
626
|
+
* post-job reviews with integer 1-5 ratings.
|
|
627
|
+
* - Kind 30382 (Web of Trust): NIP-33 parameterized replaceable event for
|
|
628
|
+
* endorsing provider pubkeys.
|
|
629
|
+
*
|
|
630
|
+
* Also provides:
|
|
631
|
+
* - `ReputationScoreCalculator`: Pure logic class computing composite
|
|
632
|
+
* reputation scores from pre-gathered signals.
|
|
633
|
+
* - `hasMinReputation()`: Utility for extracting `min_reputation` parameter
|
|
634
|
+
* from parsed job request params.
|
|
635
|
+
*/
|
|
636
|
+
|
|
637
|
+
/** Parameters for building a Kind 31117 Job Review event. */
|
|
638
|
+
interface JobReviewParams {
|
|
639
|
+
/** 64-char hex event ID of the original Kind 5xxx job request. */
|
|
640
|
+
jobRequestEventId: string;
|
|
641
|
+
/** 64-char hex pubkey of the target provider being reviewed. */
|
|
642
|
+
targetPubkey: string;
|
|
643
|
+
/** Integer rating 1-5. */
|
|
644
|
+
rating: number;
|
|
645
|
+
/** Role of the reviewer: 'customer' or 'provider'. */
|
|
646
|
+
role: 'customer' | 'provider';
|
|
647
|
+
/** Optional text review content. */
|
|
648
|
+
content?: string;
|
|
649
|
+
}
|
|
650
|
+
/** Parsed result from a Kind 31117 Job Review event. */
|
|
651
|
+
interface ParsedJobReview {
|
|
652
|
+
/** Job request event ID from the `d` tag. */
|
|
653
|
+
jobRequestEventId: string;
|
|
654
|
+
/** Target provider pubkey from the `p` tag. */
|
|
655
|
+
targetPubkey: string;
|
|
656
|
+
/** Integer rating 1-5. */
|
|
657
|
+
rating: number;
|
|
658
|
+
/** Role of the reviewer. */
|
|
659
|
+
role: 'customer' | 'provider';
|
|
660
|
+
/** Review text content. */
|
|
661
|
+
content: string;
|
|
662
|
+
}
|
|
663
|
+
/** Parameters for building a Kind 30382 Web of Trust declaration event. */
|
|
664
|
+
interface WotDeclarationParams {
|
|
665
|
+
/** 64-char hex pubkey of the target provider being endorsed. */
|
|
666
|
+
targetPubkey: string;
|
|
667
|
+
/** Optional endorsement reason. */
|
|
668
|
+
content?: string;
|
|
669
|
+
}
|
|
670
|
+
/** Parsed result from a Kind 30382 Web of Trust declaration event. */
|
|
671
|
+
interface ParsedWotDeclaration {
|
|
672
|
+
/** Target provider pubkey from the `p` tag. */
|
|
673
|
+
targetPubkey: string;
|
|
674
|
+
/** Declarer pubkey from the event's pubkey field. */
|
|
675
|
+
declarerPubkey: string;
|
|
676
|
+
/** Endorsement content. */
|
|
677
|
+
content: string;
|
|
678
|
+
}
|
|
679
|
+
/** Individual reputation signal values. */
|
|
680
|
+
interface ReputationSignals {
|
|
681
|
+
/** Count of WoT declarations from non-zero-volume declarers. */
|
|
682
|
+
trustedBy: number;
|
|
683
|
+
/** Total USDC settled through the provider's payment channels. */
|
|
684
|
+
channelVolumeUsdc: number;
|
|
685
|
+
/** Count of Kind 6xxx result events published by the provider. */
|
|
686
|
+
jobsCompleted: number;
|
|
687
|
+
/** Mean rating from verified customer reviews (0 when no reviews). */
|
|
688
|
+
avgRating: number;
|
|
689
|
+
}
|
|
690
|
+
/** Composite reputation score with individual signal values. */
|
|
691
|
+
interface ReputationScore {
|
|
692
|
+
/** The composite reputation score. */
|
|
693
|
+
score: number;
|
|
694
|
+
/** Individual signal values used to compute the score. */
|
|
695
|
+
signals: ReputationSignals;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Builds a Kind 31117 Job Review event (NIP-33 parameterized replaceable).
|
|
699
|
+
*
|
|
700
|
+
* The `d` tag = job request event ID enforces one review per job per reviewer.
|
|
701
|
+
* Tags: `d` (job request ID), `p` (target pubkey), `rating`, `role`.
|
|
702
|
+
*
|
|
703
|
+
* @param params - The job review parameters.
|
|
704
|
+
* @param secretKey - The secret key to sign the event with.
|
|
705
|
+
* @returns A signed Nostr event.
|
|
706
|
+
* @throws ToonError for invalid inputs.
|
|
707
|
+
*/
|
|
708
|
+
declare function buildJobReviewEvent(params: JobReviewParams, secretKey: Uint8Array): NostrEvent;
|
|
709
|
+
/**
|
|
710
|
+
* Parses a Kind 31117 event into a ParsedJobReview.
|
|
711
|
+
*
|
|
712
|
+
* Returns `null` for malformed events (wrong kind, missing tags, invalid rating).
|
|
713
|
+
*
|
|
714
|
+
* @param event - The Nostr event to parse.
|
|
715
|
+
* @returns The parsed job review, or null if invalid.
|
|
716
|
+
*/
|
|
717
|
+
declare function parseJobReview(event: NostrEvent): ParsedJobReview | null;
|
|
718
|
+
/**
|
|
719
|
+
* Builds a Kind 30382 Web of Trust declaration event (NIP-33 parameterized replaceable).
|
|
720
|
+
*
|
|
721
|
+
* The `d` tag = target pubkey enforces one WoT declaration per declarer per target.
|
|
722
|
+
*
|
|
723
|
+
* @param params - The WoT declaration parameters.
|
|
724
|
+
* @param secretKey - The secret key to sign the event with.
|
|
725
|
+
* @returns A signed Nostr event.
|
|
726
|
+
* @throws ToonError for invalid inputs.
|
|
727
|
+
*/
|
|
728
|
+
declare function buildWotDeclarationEvent(params: WotDeclarationParams, secretKey: Uint8Array): NostrEvent;
|
|
729
|
+
/**
|
|
730
|
+
* Parses a Kind 30382 event into a ParsedWotDeclaration.
|
|
731
|
+
*
|
|
732
|
+
* Returns `null` for malformed events (wrong kind, missing tags,
|
|
733
|
+
* d tag not matching p tag).
|
|
734
|
+
*
|
|
735
|
+
* @param event - The Nostr event to parse.
|
|
736
|
+
* @returns The parsed WoT declaration, or null if invalid.
|
|
737
|
+
*/
|
|
738
|
+
declare function parseWotDeclaration(event: NostrEvent): ParsedWotDeclaration | null;
|
|
739
|
+
/**
|
|
740
|
+
* Pure logic class for computing composite reputation scores.
|
|
741
|
+
*
|
|
742
|
+
* Receives pre-computed signals (WoT declarations, reviews, channel volume,
|
|
743
|
+
* job count) and calculates the composite score. Does NOT perform relay
|
|
744
|
+
* queries or on-chain reads. The caller is responsible for gathering signals.
|
|
745
|
+
*
|
|
746
|
+
* Formula: score = (trusted_by x 100) + (log10(max(1, channel_volume_usdc)) x 10)
|
|
747
|
+
* + (jobs_completed x 5) + (avg_rating x 20)
|
|
748
|
+
*/
|
|
749
|
+
declare class ReputationScoreCalculator {
|
|
750
|
+
/**
|
|
751
|
+
* Computes the composite reputation score from pre-computed signals.
|
|
752
|
+
*
|
|
753
|
+
* @param signals - The individual signal values.
|
|
754
|
+
* @returns The composite score with individual signals.
|
|
755
|
+
*/
|
|
756
|
+
calculateScore(signals: ReputationSignals): ReputationScore;
|
|
757
|
+
/**
|
|
758
|
+
* Computes the threshold-filtered trusted_by count from WoT declarations.
|
|
759
|
+
*
|
|
760
|
+
* Declarers with non-zero channel volume contribute 1 to the count.
|
|
761
|
+
* Declarers with zero channel volume contribute 0 (sybil defense).
|
|
762
|
+
*
|
|
763
|
+
* @param wotDeclarations - Parsed WoT declarations targeting the provider.
|
|
764
|
+
* @param getChannelVolume - Callback to look up a declarer's channel volume.
|
|
765
|
+
* @returns The count of WoT declarations from non-zero-volume declarers.
|
|
766
|
+
*/
|
|
767
|
+
computeTrustedBy(wotDeclarations: ParsedWotDeclaration[], getChannelVolume: (pubkey: string) => number): number;
|
|
768
|
+
/**
|
|
769
|
+
* Computes the average rating from verified customer reviews only.
|
|
770
|
+
*
|
|
771
|
+
* Reviews are provided as tuples of `{ review, reviewerPubkey }` so the
|
|
772
|
+
* calculator can filter by the verified customer set. Reviews from pubkeys
|
|
773
|
+
* NOT in `verifiedCustomerPubkeys` are excluded entirely (customer-gate
|
|
774
|
+
* sybil defense per E6-R013).
|
|
775
|
+
*
|
|
776
|
+
* @param reviews - Parsed job reviews with reviewer pubkeys.
|
|
777
|
+
* @param verifiedCustomerPubkeys - Set of pubkeys that authored Kind 5xxx requests.
|
|
778
|
+
* @returns The mean rating from verified reviews, or 0 when no verified reviews exist.
|
|
779
|
+
*/
|
|
780
|
+
computeAvgRating(reviews: {
|
|
781
|
+
review: ParsedJobReview;
|
|
782
|
+
reviewerPubkey: string;
|
|
783
|
+
}[], verifiedCustomerPubkeys: Set<string>): number;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Extracts the `min_reputation` parameter value from parsed job request params.
|
|
787
|
+
*
|
|
788
|
+
* Follows the same pattern as `hasRequireAttestation()`.
|
|
789
|
+
*
|
|
790
|
+
* @param params - The params array from a parsed job request.
|
|
791
|
+
* @returns The numeric threshold value, null if not present, or throws on invalid value.
|
|
792
|
+
* @throws ToonError with code REPUTATION_INVALID_MIN_REPUTATION if value is non-numeric.
|
|
793
|
+
*/
|
|
794
|
+
declare function hasMinReputation(params: {
|
|
795
|
+
key: string;
|
|
796
|
+
value: string;
|
|
797
|
+
}[]): number | null;
|
|
798
|
+
|
|
274
799
|
/**
|
|
275
800
|
* Event builder and parser for kind:10035 Service Discovery events.
|
|
276
801
|
*
|
|
@@ -312,6 +837,8 @@ interface SkillDescriptor {
|
|
|
312
837
|
models?: string[];
|
|
313
838
|
/** Placeholder for Epic 6 TEE attestation integration. */
|
|
314
839
|
attestation?: Record<string, unknown>;
|
|
840
|
+
/** Composite reputation score with individual signal values (Story 6.4). */
|
|
841
|
+
reputation?: ReputationScore;
|
|
315
842
|
}
|
|
316
843
|
/** Content payload for a kind:10035 Service Discovery event. */
|
|
317
844
|
interface ServiceDiscoveryContent {
|
|
@@ -547,6 +1074,8 @@ interface JobResultParams {
|
|
|
547
1074
|
amount: string;
|
|
548
1075
|
/** Result data (text, URL, etc.). */
|
|
549
1076
|
content: string;
|
|
1077
|
+
/** Optional 64-char hex event ID of the provider's latest kind:10033 attestation event. */
|
|
1078
|
+
attestationEventId?: string;
|
|
550
1079
|
}
|
|
551
1080
|
/**
|
|
552
1081
|
* Parameters for building a Kind 7000 DVM job feedback event.
|
|
@@ -611,6 +1140,8 @@ interface ParsedJobResult {
|
|
|
611
1140
|
amount: string;
|
|
612
1141
|
/** Result data from the content field. */
|
|
613
1142
|
content: string;
|
|
1143
|
+
/** Optional event ID of the provider's kind:10033 attestation event. */
|
|
1144
|
+
attestationEventId?: string;
|
|
614
1145
|
}
|
|
615
1146
|
/**
|
|
616
1147
|
* Parsed result from a Kind 7000 DVM job feedback event.
|
|
@@ -688,6 +1219,12 @@ declare function parseJobRequest(event: NostrEvent): ParsedJobRequest | null;
|
|
|
688
1219
|
* NIP-90 tags: `e` (request event ID), `p` (customer pubkey), and `amount`
|
|
689
1220
|
* (compute cost + currency).
|
|
690
1221
|
*
|
|
1222
|
+
* The `amount` tag is **informational** (a receipt of the agreed price).
|
|
1223
|
+
* In the prepaid protocol model, payment is sent with the job request
|
|
1224
|
+
* (via `publishEvent()` with the `amount` option), NOT triggered by
|
|
1225
|
+
* parsing the result event's amount tag. The amount tag serves as a
|
|
1226
|
+
* record of what was agreed upon, not as a payment trigger.
|
|
1227
|
+
*
|
|
691
1228
|
* Returns `null` for malformed events. Follows the lenient parse pattern.
|
|
692
1229
|
*
|
|
693
1230
|
* @param event - The Nostr event to parse.
|
|
@@ -702,13 +1239,529 @@ declare function parseJobResult(event: NostrEvent): ParsedJobResult | null;
|
|
|
702
1239
|
* (job state). The status value must be one of: `'processing'`, `'error'`,
|
|
703
1240
|
* `'success'`, `'partial'`.
|
|
704
1241
|
*
|
|
705
|
-
* Returns `null` for malformed events or invalid status values.
|
|
706
|
-
* Follows the lenient parse pattern.
|
|
1242
|
+
* Returns `null` for malformed events or invalid status values.
|
|
1243
|
+
* Follows the lenient parse pattern.
|
|
1244
|
+
*
|
|
1245
|
+
* @param event - The Nostr event to parse.
|
|
1246
|
+
* @returns The parsed job feedback, or null if invalid.
|
|
1247
|
+
*/
|
|
1248
|
+
declare function parseJobFeedback(event: NostrEvent): ParsedJobFeedback | null;
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Event builder and parser for Workflow Chain events (kind:10040).
|
|
1252
|
+
*
|
|
1253
|
+
* Workflow chains define multi-step DVM pipelines where each step's output
|
|
1254
|
+
* automatically feeds into the next step's input. The workflow definition
|
|
1255
|
+
* event contains an ordered list of steps, initial input, and a total bid
|
|
1256
|
+
* that is split across steps.
|
|
1257
|
+
*
|
|
1258
|
+
* Kind:10040 is in the TOON-specific replaceable range (10032-10099).
|
|
1259
|
+
* Each workflow instance uses a unique `d` tag to avoid unintentional
|
|
1260
|
+
* replacement of in-progress workflows.
|
|
1261
|
+
*
|
|
1262
|
+
* Tag reference (kind:10040):
|
|
1263
|
+
* Content: JSON-serialized workflow definition body
|
|
1264
|
+
* Required: ['d', uniqueWorkflowId], ['bid', totalBid, 'usdc']
|
|
1265
|
+
* Content JSON: { steps: WorkflowStep[], initialInput: { data, type }, totalBid }
|
|
1266
|
+
*/
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* A single step in a workflow chain.
|
|
1270
|
+
*
|
|
1271
|
+
* Each step specifies a DVM kind (5000-5999) and a description.
|
|
1272
|
+
* Optionally, a step can target a specific provider and allocate
|
|
1273
|
+
* an explicit portion of the total bid.
|
|
1274
|
+
*/
|
|
1275
|
+
interface WorkflowStep {
|
|
1276
|
+
/** DVM job request kind (5000-5999 range). */
|
|
1277
|
+
kind: number;
|
|
1278
|
+
/** Human-readable description of the step's purpose. */
|
|
1279
|
+
description: string;
|
|
1280
|
+
/** Optional 64-char hex pubkey of a specific target provider. */
|
|
1281
|
+
targetProvider?: string;
|
|
1282
|
+
/** Optional explicit bid allocation in USDC micro-units as string. */
|
|
1283
|
+
bidAllocation?: string;
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Parameters for building a kind:10040 Workflow Chain event.
|
|
1287
|
+
*/
|
|
1288
|
+
interface WorkflowDefinitionParams {
|
|
1289
|
+
/** Ordered list of workflow steps (at least one required). */
|
|
1290
|
+
steps: WorkflowStep[];
|
|
1291
|
+
/** Initial input for the first step. */
|
|
1292
|
+
initialInput: {
|
|
1293
|
+
/** The input data (text, JSON, etc.). */
|
|
1294
|
+
data: string;
|
|
1295
|
+
/** Input type identifier (e.g., 'text', 'json'). */
|
|
1296
|
+
type: string;
|
|
1297
|
+
};
|
|
1298
|
+
/** Total bid for the entire workflow in USDC micro-units as string. */
|
|
1299
|
+
totalBid: string;
|
|
1300
|
+
/** Optional body text for the event content field. */
|
|
1301
|
+
content?: string;
|
|
1302
|
+
/** Optional workflow ID for deterministic `d` tag (defaults to timestamp-based). */
|
|
1303
|
+
workflowId?: string;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Parsed result from a kind:10040 Workflow Chain event.
|
|
1307
|
+
*/
|
|
1308
|
+
interface ParsedWorkflowDefinition {
|
|
1309
|
+
/** Ordered list of workflow steps. */
|
|
1310
|
+
steps: WorkflowStep[];
|
|
1311
|
+
/** Initial input for the first step. */
|
|
1312
|
+
initialInput: {
|
|
1313
|
+
/** The input data. */
|
|
1314
|
+
data: string;
|
|
1315
|
+
/** Input type identifier. */
|
|
1316
|
+
type: string;
|
|
1317
|
+
};
|
|
1318
|
+
/** Total bid for the entire workflow in USDC micro-units as string. */
|
|
1319
|
+
totalBid: string;
|
|
1320
|
+
/** Event content field (JSON-serialized workflow body). */
|
|
1321
|
+
content: string;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Builds a kind:10040 Workflow Chain event.
|
|
1325
|
+
*
|
|
1326
|
+
* Validates steps, initial input, total bid, and per-step bid allocations
|
|
1327
|
+
* (if provided). Serializes the workflow definition as JSON content.
|
|
1328
|
+
*
|
|
1329
|
+
* @param params - The workflow definition parameters.
|
|
1330
|
+
* @param secretKey - The secret key to sign the event with.
|
|
1331
|
+
* @returns A signed Nostr event.
|
|
1332
|
+
* @throws ToonError if validation fails.
|
|
1333
|
+
*/
|
|
1334
|
+
declare function buildWorkflowDefinitionEvent(params: WorkflowDefinitionParams, secretKey: Uint8Array): NostrEvent;
|
|
1335
|
+
/**
|
|
1336
|
+
* Parses a kind:10040 event into a ParsedWorkflowDefinition.
|
|
1337
|
+
*
|
|
1338
|
+
* Validates the event kind, parses JSON content, validates the steps
|
|
1339
|
+
* array, initialInput, and totalBid. Returns `null` for malformed events.
|
|
1340
|
+
*
|
|
1341
|
+
* @param event - The Nostr event to parse.
|
|
1342
|
+
* @returns The parsed workflow definition, or null if invalid.
|
|
1343
|
+
*/
|
|
1344
|
+
declare function parseWorkflowDefinition(event: NostrEvent): ParsedWorkflowDefinition | null;
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* Event builders and parsers for DVM Agent Swarm events (Story 6.2).
|
|
1348
|
+
*
|
|
1349
|
+
* Swarm events extend NIP-90 DVM events with competitive bidding tags:
|
|
1350
|
+
* - `['swarm', maxProviders]` -- maximum number of providers in the swarm
|
|
1351
|
+
* - `['judge', judgeIdentifier]` -- who selects the winner (default: 'customer')
|
|
1352
|
+
*
|
|
1353
|
+
* Swarm request events are standard Kind 5xxx events with additional tags.
|
|
1354
|
+
* Non-swarm-aware providers can still participate via the standard Kind 5xxx path.
|
|
1355
|
+
*
|
|
1356
|
+
* Selection events are Kind 7000 feedback events with a `winner` tag
|
|
1357
|
+
* referencing the winning Kind 6xxx result event ID.
|
|
1358
|
+
*
|
|
1359
|
+
* Tag reference (swarm-specific additions):
|
|
1360
|
+
*
|
|
1361
|
+
* Kind 5xxx (Swarm Job Request):
|
|
1362
|
+
* Standard NIP-90 tags + ['swarm', maxProviders], ['judge', judgeId]
|
|
1363
|
+
*
|
|
1364
|
+
* Kind 7000 (Swarm Selection):
|
|
1365
|
+
* Standard NIP-90 feedback tags + ['winner', winnerResultEventId]
|
|
1366
|
+
*/
|
|
1367
|
+
|
|
1368
|
+
/**
|
|
1369
|
+
* Parameters for building a swarm request event (Kind 5xxx with swarm tags).
|
|
1370
|
+
*
|
|
1371
|
+
* Extends `JobRequestParams` with swarm-specific fields:
|
|
1372
|
+
* - `maxProviders`: Maximum number of providers in the competitive swarm (>= 1).
|
|
1373
|
+
* - `judge`: Who selects the winner (default: 'customer'). Can be 'customer',
|
|
1374
|
+
* 'auto', or a specific pubkey.
|
|
1375
|
+
*/
|
|
1376
|
+
interface SwarmRequestParams extends JobRequestParams {
|
|
1377
|
+
/** Maximum number of providers to collect submissions from (>= 1). */
|
|
1378
|
+
maxProviders: number;
|
|
1379
|
+
/** Who selects the winner (default: 'customer'). */
|
|
1380
|
+
judge?: string;
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Parameters for building a swarm selection event (Kind 7000 with winner tag).
|
|
1384
|
+
*/
|
|
1385
|
+
interface SwarmSelectionParams {
|
|
1386
|
+
/** 64-char hex event ID of the original swarm request. */
|
|
1387
|
+
swarmRequestEventId: string;
|
|
1388
|
+
/** 64-char hex event ID of the winning Kind 6xxx result. */
|
|
1389
|
+
winnerResultEventId: string;
|
|
1390
|
+
/** 64-char hex pubkey of the customer who posted the swarm request. */
|
|
1391
|
+
customerPubkey: string;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Parsed result from a Kind 5xxx swarm request event.
|
|
1395
|
+
* Extends `ParsedJobRequest` with swarm-specific fields.
|
|
1396
|
+
*/
|
|
1397
|
+
interface ParsedSwarmRequest extends ParsedJobRequest {
|
|
1398
|
+
/** Maximum number of providers in the swarm. */
|
|
1399
|
+
maxProviders: number;
|
|
1400
|
+
/** Who selects the winner. */
|
|
1401
|
+
judge: string;
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Parsed result from a Kind 7000 swarm selection event.
|
|
1405
|
+
*/
|
|
1406
|
+
interface ParsedSwarmSelection {
|
|
1407
|
+
/** Event ID of the original swarm request. */
|
|
1408
|
+
swarmRequestEventId: string;
|
|
1409
|
+
/** Event ID of the winning Kind 6xxx result. */
|
|
1410
|
+
winnerResultEventId: string;
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Builds a Kind 5xxx swarm request event.
|
|
1414
|
+
*
|
|
1415
|
+
* Delegates to `buildJobRequestEvent()` for the base NIP-90 event, then
|
|
1416
|
+
* appends swarm-specific tags: `swarm` (max providers) and `judge` (selector).
|
|
1417
|
+
*
|
|
1418
|
+
* The resulting event is a valid Kind 5xxx event that non-swarm-aware
|
|
1419
|
+
* providers can also parse via `parseJobRequest()`.
|
|
1420
|
+
*
|
|
1421
|
+
* @param params - The swarm request parameters.
|
|
1422
|
+
* @param secretKey - The secret key to sign the event with.
|
|
1423
|
+
* @returns A signed Nostr event.
|
|
1424
|
+
* @throws ToonError if maxProviders < 1 or base params are invalid.
|
|
1425
|
+
*/
|
|
1426
|
+
declare function buildSwarmRequestEvent(params: SwarmRequestParams, secretKey: Uint8Array): NostrEvent;
|
|
1427
|
+
/**
|
|
1428
|
+
* Builds a Kind 7000 swarm selection event.
|
|
1429
|
+
*
|
|
1430
|
+
* Creates a feedback event with `status: 'success'`, an `e` tag referencing
|
|
1431
|
+
* the swarm request, and a `winner` tag referencing the winning result.
|
|
1432
|
+
*
|
|
1433
|
+
* @param params - The swarm selection parameters.
|
|
1434
|
+
* @param secretKey - The secret key to sign the event with.
|
|
1435
|
+
* @returns A signed Nostr event.
|
|
1436
|
+
* @throws ToonError if event IDs or pubkey are not valid 64-char hex.
|
|
1437
|
+
*/
|
|
1438
|
+
declare function buildSwarmSelectionEvent(params: SwarmSelectionParams, secretKey: Uint8Array): NostrEvent;
|
|
1439
|
+
/**
|
|
1440
|
+
* Parses a Kind 5xxx event into a ParsedSwarmRequest.
|
|
1441
|
+
*
|
|
1442
|
+
* Delegates to `parseJobRequest()` for base fields, then extracts the
|
|
1443
|
+
* `swarm` and `judge` tags. Returns `null` if the event is not a valid
|
|
1444
|
+
* swarm request (missing `swarm` tag, invalid kind range, etc.).
|
|
1445
|
+
*
|
|
1446
|
+
* @param event - The Nostr event to parse.
|
|
1447
|
+
* @returns The parsed swarm request, or null if invalid/not a swarm request.
|
|
1448
|
+
*/
|
|
1449
|
+
declare function parseSwarmRequest(event: NostrEvent): ParsedSwarmRequest | null;
|
|
1450
|
+
/**
|
|
1451
|
+
* Parses a Kind 7000 event into a ParsedSwarmSelection.
|
|
1452
|
+
*
|
|
1453
|
+
* Validates the event kind is exactly 7000 and extracts the `winner` tag
|
|
1454
|
+
* and `e` tag (swarm request reference). Returns `null` if the event is
|
|
1455
|
+
* not a valid swarm selection (missing `winner` tag, wrong kind, etc.).
|
|
1456
|
+
*
|
|
1457
|
+
* @param event - The Nostr event to parse.
|
|
1458
|
+
* @returns The parsed swarm selection, or null if invalid.
|
|
1459
|
+
*/
|
|
1460
|
+
declare function parseSwarmSelection(event: NostrEvent): ParsedSwarmSelection | null;
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* Event builders and parsers for prefix claim (kind 10034) and
|
|
1464
|
+
* prefix grant (kind 10037) events.
|
|
1465
|
+
*
|
|
1466
|
+
* Prefix claims are part of the TOON prefix marketplace: a node sends a
|
|
1467
|
+
* kind 10034 event with payment to claim a prefix from an upstream peer.
|
|
1468
|
+
* The upstream responds with a kind 10037 grant confirmation.
|
|
1469
|
+
*/
|
|
1470
|
+
|
|
1471
|
+
/** Content payload for a kind 10034 prefix claim event. */
|
|
1472
|
+
interface PrefixClaimContent {
|
|
1473
|
+
/** The prefix string being requested (e.g., 'useast'). */
|
|
1474
|
+
requestedPrefix: string;
|
|
1475
|
+
}
|
|
1476
|
+
/** Content payload for a kind 10037 prefix grant event. */
|
|
1477
|
+
interface PrefixGrantContent {
|
|
1478
|
+
/** The prefix that was granted. */
|
|
1479
|
+
grantedPrefix: string;
|
|
1480
|
+
/** Pubkey of the node that received the prefix. */
|
|
1481
|
+
claimerPubkey: string;
|
|
1482
|
+
/** The ILP address derived from the granted prefix. */
|
|
1483
|
+
ilpAddress: string;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Builds and signs a kind 10034 prefix claim event.
|
|
1487
|
+
*
|
|
1488
|
+
* @param content - The prefix claim content with the requested prefix
|
|
1489
|
+
* @param secretKey - The 32-byte secret key to sign the event with
|
|
1490
|
+
* @returns A signed Nostr event of kind 10034
|
|
1491
|
+
*/
|
|
1492
|
+
declare function buildPrefixClaimEvent(content: PrefixClaimContent, secretKey: Uint8Array): NostrEvent;
|
|
1493
|
+
/**
|
|
1494
|
+
* Parses a kind 10034 prefix claim event into PrefixClaimContent.
|
|
1495
|
+
*
|
|
1496
|
+
* Returns null for malformed events. Follows the lenient parse pattern.
|
|
1497
|
+
*
|
|
1498
|
+
* @param event - The Nostr event to parse
|
|
1499
|
+
* @returns The parsed prefix claim content, or null if invalid
|
|
1500
|
+
*/
|
|
1501
|
+
declare function parsePrefixClaimEvent(event: NostrEvent): PrefixClaimContent | null;
|
|
1502
|
+
/**
|
|
1503
|
+
* Builds and signs a kind 10037 prefix grant event.
|
|
1504
|
+
*
|
|
1505
|
+
* @param content - The prefix grant content with granted prefix details
|
|
1506
|
+
* @param secretKey - The 32-byte secret key to sign the event with
|
|
1507
|
+
* @returns A signed Nostr event of kind 10037
|
|
1508
|
+
*/
|
|
1509
|
+
declare function buildPrefixGrantEvent(content: PrefixGrantContent, secretKey: Uint8Array): NostrEvent;
|
|
1510
|
+
/**
|
|
1511
|
+
* Parses a kind 10037 prefix grant event into PrefixGrantContent.
|
|
1512
|
+
*
|
|
1513
|
+
* Returns null for malformed events. Follows the lenient parse pattern.
|
|
1514
|
+
*
|
|
1515
|
+
* @param event - The Nostr event to parse
|
|
1516
|
+
* @returns The parsed prefix grant content, or null if invalid
|
|
1517
|
+
*/
|
|
1518
|
+
declare function parsePrefixGrantEvent(event: NostrEvent): PrefixGrantContent | null;
|
|
1519
|
+
|
|
1520
|
+
/**
|
|
1521
|
+
* AttestationVerifier -- TEE attestation verification, state lifecycle,
|
|
1522
|
+
* and attestation-aware peer ranking for Story 4.3.
|
|
1523
|
+
*
|
|
1524
|
+
* This is a pure logic class with no transport layer. It receives parsed
|
|
1525
|
+
* attestation data and returns verification results. The transport layer
|
|
1526
|
+
* (subscribing to kind:10033 events on relays) is a Story 4.6 concern.
|
|
1527
|
+
*
|
|
1528
|
+
* The AttestationVerifier is the single source of truth for attestation
|
|
1529
|
+
* state (R-E4-008). Both the kind:10033 Nostr event path and the /health
|
|
1530
|
+
* HTTP endpoint derive their TEE state from the same verifier instance.
|
|
1531
|
+
*
|
|
1532
|
+
* Attestation State Machine (Decision 12):
|
|
1533
|
+
* VALID (within validitySeconds)
|
|
1534
|
+
* -> STALE (within graceSeconds after validity expires)
|
|
1535
|
+
* -> UNATTESTED (after grace period expires)
|
|
1536
|
+
*
|
|
1537
|
+
* Trust degrades; money doesn't -- attestation state changes never
|
|
1538
|
+
* trigger payment channel closure.
|
|
1539
|
+
*/
|
|
1540
|
+
|
|
1541
|
+
/**
|
|
1542
|
+
* Attestation lifecycle state.
|
|
1543
|
+
*
|
|
1544
|
+
* Transitions: VALID -> STALE -> UNATTESTED.
|
|
1545
|
+
* A peer that was never attested starts as UNATTESTED.
|
|
1546
|
+
*/
|
|
1547
|
+
declare enum AttestationState {
|
|
1548
|
+
/** Attestation is within validity period. */
|
|
1549
|
+
VALID = "valid",
|
|
1550
|
+
/** Attestation has expired but is within the grace period. */
|
|
1551
|
+
STALE = "stale",
|
|
1552
|
+
/** Attestation has expired past the grace period or was never attested. */
|
|
1553
|
+
UNATTESTED = "unattested"
|
|
1554
|
+
}
|
|
1555
|
+
/** Result of PCR verification against a known-good registry. */
|
|
1556
|
+
interface VerificationResult {
|
|
1557
|
+
valid: boolean;
|
|
1558
|
+
reason?: string;
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* Descriptor for a peer in the attestation-aware ranking system.
|
|
1562
|
+
* Used by `rankPeers()` to order peers by attestation status.
|
|
1563
|
+
*/
|
|
1564
|
+
interface PeerDescriptor {
|
|
1565
|
+
pubkey: string;
|
|
1566
|
+
relayUrl: string;
|
|
1567
|
+
attested: boolean;
|
|
1568
|
+
attestationTimestamp?: number;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Configuration for the AttestationVerifier.
|
|
1572
|
+
*/
|
|
1573
|
+
interface AttestationVerifierConfig {
|
|
1574
|
+
/** Map of known-good PCR values. Key is PCR hash, value is trust status. */
|
|
1575
|
+
knownGoodPcrs: Map<string, boolean>;
|
|
1576
|
+
/** Attestation validity period in seconds (default: 300). */
|
|
1577
|
+
validitySeconds?: number;
|
|
1578
|
+
/** Grace period in seconds after validity expires before marking as unattested (default: 30). */
|
|
1579
|
+
graceSeconds?: number;
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Verifies TEE attestations, computes attestation lifecycle state,
|
|
1583
|
+
* and ranks peers by attestation status.
|
|
1584
|
+
*
|
|
1585
|
+
* Single source of truth for attestation state (R-E4-008).
|
|
1586
|
+
*/
|
|
1587
|
+
declare class AttestationVerifier {
|
|
1588
|
+
private readonly knownGoodPcrs;
|
|
1589
|
+
private readonly validitySeconds;
|
|
1590
|
+
private readonly graceSeconds;
|
|
1591
|
+
constructor(config: AttestationVerifierConfig);
|
|
1592
|
+
/**
|
|
1593
|
+
* Verifies a TEE attestation's PCR values against the known-good registry.
|
|
1594
|
+
*
|
|
1595
|
+
* All three PCR values (pcr0, pcr1, pcr2) must be present and truthy in
|
|
1596
|
+
* the registry for verification to pass.
|
|
1597
|
+
*
|
|
1598
|
+
* @param attestation - The TEE attestation to verify.
|
|
1599
|
+
* @returns Verification result with `valid: true` or `valid: false` with reason.
|
|
1600
|
+
*/
|
|
1601
|
+
verify(attestation: TeeAttestation): VerificationResult;
|
|
1602
|
+
/**
|
|
1603
|
+
* Computes the attestation lifecycle state based on timing.
|
|
1604
|
+
*
|
|
1605
|
+
* Boundary behavior:
|
|
1606
|
+
* - At exactly `attestedAt + validitySeconds`: VALID (inclusive <=)
|
|
1607
|
+
* - At exactly `attestedAt + validitySeconds + graceSeconds`: STALE (inclusive <=)
|
|
1608
|
+
* - After grace expires: UNATTESTED
|
|
1609
|
+
*
|
|
1610
|
+
* @param _attestation - The TEE attestation (unused, reserved for future per-attestation logic).
|
|
1611
|
+
* @param attestedAt - Unix timestamp when the attestation was created.
|
|
1612
|
+
* @param now - Optional current unix timestamp (defaults to real clock).
|
|
1613
|
+
* @returns The current attestation state.
|
|
1614
|
+
*/
|
|
1615
|
+
getAttestationState(_attestation: TeeAttestation, attestedAt: number, now?: number): AttestationState;
|
|
1616
|
+
/**
|
|
1617
|
+
* Ranks peers by attestation status: attested peers first, then non-attested.
|
|
1618
|
+
*
|
|
1619
|
+
* Preserves relative order within each group (stable sort via filter).
|
|
1620
|
+
* Does NOT mutate the input array -- returns a new sorted array.
|
|
1621
|
+
*
|
|
1622
|
+
* Attestation is a preference, not a requirement. Non-attested peers
|
|
1623
|
+
* remain in the result and are connectable.
|
|
1624
|
+
*
|
|
1625
|
+
* @param peers - Array of peer descriptors to rank.
|
|
1626
|
+
* @returns New array with attested peers first, preserving relative order.
|
|
1627
|
+
*/
|
|
1628
|
+
rankPeers(peers: PeerDescriptor[]): PeerDescriptor[];
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* Customer-side attestation result verifier for TEE-attested DVM results.
|
|
1633
|
+
*
|
|
1634
|
+
* Verifies that a Kind 6xxx DVM result was computed in a valid TEE enclave
|
|
1635
|
+
* by checking the referenced kind:10033 attestation event. Three checks:
|
|
1636
|
+
* 1. Pubkey match: kind:10033 author === Kind 6xxx author (same provider)
|
|
1637
|
+
* 2. PCR validity: PCR values pass AttestationVerifier.verify()
|
|
1638
|
+
* 3. Time validity: attestation was VALID at result creation time
|
|
1639
|
+
*
|
|
1640
|
+
* This is a pure logic class with no transport concerns. The caller is
|
|
1641
|
+
* responsible for fetching the attestation event from the relay.
|
|
1642
|
+
*/
|
|
1643
|
+
|
|
1644
|
+
/** Configuration for constructing an AttestedResultVerifier. */
|
|
1645
|
+
interface AttestedResultVerificationOptions {
|
|
1646
|
+
/** The AttestationVerifier instance for PCR and state checks. */
|
|
1647
|
+
attestationVerifier: AttestationVerifier;
|
|
1648
|
+
}
|
|
1649
|
+
/** Result of verifying an attested DVM result. */
|
|
1650
|
+
interface AttestedResultVerificationResult {
|
|
1651
|
+
/** Whether the attestation verification passed all checks. */
|
|
1652
|
+
valid: boolean;
|
|
1653
|
+
/** Reason for failure (undefined when valid). */
|
|
1654
|
+
reason?: string;
|
|
1655
|
+
/** Attestation lifecycle state (undefined when verification fails before state check). */
|
|
1656
|
+
attestationState?: AttestationState;
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Verifies TEE attestation on Kind 6xxx DVM result events.
|
|
1660
|
+
*
|
|
1661
|
+
* Follows the same pure-logic pattern as AttestationVerifier (Story 4.3).
|
|
1662
|
+
* Time injection is NOT at construction -- `resultEvent.created_at` is
|
|
1663
|
+
* used as the `now` parameter at call site.
|
|
1664
|
+
*/
|
|
1665
|
+
declare class AttestedResultVerifier {
|
|
1666
|
+
private readonly attestationVerifier;
|
|
1667
|
+
constructor(options: AttestedResultVerificationOptions);
|
|
1668
|
+
/**
|
|
1669
|
+
* Verifies that a Kind 6xxx result was computed in a valid TEE enclave.
|
|
1670
|
+
*
|
|
1671
|
+
* Performs three checks:
|
|
1672
|
+
* (a) Pubkey match: attestationEvent.pubkey === resultEvent.pubkey
|
|
1673
|
+
* (b) PCR validity: AttestationVerifier.verify(parsedAttestation.attestation)
|
|
1674
|
+
* (c) Time validity: attestation was VALID at resultEvent.created_at
|
|
1675
|
+
*
|
|
1676
|
+
* @param resultEvent - The Kind 6xxx result Nostr event.
|
|
1677
|
+
* @param _parsedResult - The parsed job result (reserved for future use).
|
|
1678
|
+
* @param attestationEvent - The kind:10033 attestation Nostr event.
|
|
1679
|
+
* @param parsedAttestation - The parsed attestation data.
|
|
1680
|
+
* @returns Verification result with valid flag, reason, and attestation state.
|
|
1681
|
+
*/
|
|
1682
|
+
verifyAttestedResult(resultEvent: NostrEvent, _parsedResult: ParsedJobResult, attestationEvent: NostrEvent, parsedAttestation: ParsedAttestation): AttestedResultVerificationResult;
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Checks whether a parsed job request's params include `require_attestation=true`.
|
|
1686
|
+
*
|
|
1687
|
+
* @param params - The params array from a parsed job request.
|
|
1688
|
+
* @returns true if `require_attestation` is set to `'true'`.
|
|
1689
|
+
*/
|
|
1690
|
+
declare function hasRequireAttestation(params: {
|
|
1691
|
+
key: string;
|
|
1692
|
+
value: string;
|
|
1693
|
+
}[]): boolean;
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* Event builders and parsers for kind:5094 Blob Storage DVM requests.
|
|
1697
|
+
*
|
|
1698
|
+
* Kind 5094 is a NIP-90 DVM job request for permanent blob storage (Arweave).
|
|
1699
|
+
* The blob data is base64-encoded in the `i` tag with type `blob`.
|
|
1700
|
+
* Payment is carried in the ILP PREPARE packet (prepaid model, D7-001).
|
|
1701
|
+
*
|
|
1702
|
+
* Tag layout:
|
|
1703
|
+
* Required: ['i', base64Blob, 'blob'], ['bid', amount, 'usdc'], ['output', contentType]
|
|
1704
|
+
* Optional: ['param', 'uploadId', uuid], ['param', 'chunkIndex', idx],
|
|
1705
|
+
* ['param', 'totalChunks', total], ['param', 'contentType', type]
|
|
1706
|
+
*/
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* Parameters for building a kind:5094 Blob Storage DVM request event.
|
|
1710
|
+
*/
|
|
1711
|
+
interface BlobStorageRequestParams {
|
|
1712
|
+
/** The raw blob data to store. */
|
|
1713
|
+
blobData: Buffer;
|
|
1714
|
+
/** MIME type of the blob (default: 'application/octet-stream'). */
|
|
1715
|
+
contentType?: string;
|
|
1716
|
+
/** Bid amount in USDC micro-units as string (bigint-compatible). */
|
|
1717
|
+
bid: string;
|
|
1718
|
+
/** Optional key-value parameters (e.g., uploadId, chunkIndex, totalChunks). */
|
|
1719
|
+
params?: {
|
|
1720
|
+
key: string;
|
|
1721
|
+
value: string;
|
|
1722
|
+
}[];
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Parsed result from a kind:5094 Blob Storage DVM request event.
|
|
1726
|
+
*/
|
|
1727
|
+
interface ParsedBlobStorageRequest {
|
|
1728
|
+
/** The decoded blob data. */
|
|
1729
|
+
blobData: Buffer;
|
|
1730
|
+
/** MIME type of the blob. */
|
|
1731
|
+
contentType: string;
|
|
1732
|
+
/** Upload ID for chunked uploads. */
|
|
1733
|
+
uploadId?: string;
|
|
1734
|
+
/** Chunk index for chunked uploads. */
|
|
1735
|
+
chunkIndex?: number;
|
|
1736
|
+
/** Total number of chunks for chunked uploads. */
|
|
1737
|
+
totalChunks?: number;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Builds a kind:5094 Blob Storage DVM request event.
|
|
1741
|
+
*
|
|
1742
|
+
* Constructs a signed Nostr event with the blob base64-encoded in the `i` tag,
|
|
1743
|
+
* a `bid` tag for payment declaration, and an `output` tag for content type.
|
|
1744
|
+
*
|
|
1745
|
+
* @param params - The blob storage request parameters.
|
|
1746
|
+
* @param secretKey - The secret key to sign the event with.
|
|
1747
|
+
* @returns A signed Nostr event.
|
|
1748
|
+
* @throws ToonError if required params are missing.
|
|
1749
|
+
*/
|
|
1750
|
+
declare function buildBlobStorageRequest(params: BlobStorageRequestParams, secretKey: Uint8Array): NostrEvent;
|
|
1751
|
+
/**
|
|
1752
|
+
* Parses a kind:5094 event into a ParsedBlobStorageRequest.
|
|
1753
|
+
*
|
|
1754
|
+
* Validates the event kind is 5094, extracts the base64-encoded blob from the
|
|
1755
|
+
* `i` tag, the content type from the `output` tag, and optional chunked upload
|
|
1756
|
+
* params from `param` tags.
|
|
1757
|
+
*
|
|
1758
|
+
* Returns `null` for malformed events (wrong kind, missing required tags,
|
|
1759
|
+
* invalid base64). Follows the lenient parse pattern.
|
|
707
1760
|
*
|
|
708
1761
|
* @param event - The Nostr event to parse.
|
|
709
|
-
* @returns The parsed
|
|
1762
|
+
* @returns The parsed blob storage request, or null if invalid.
|
|
710
1763
|
*/
|
|
711
|
-
declare function
|
|
1764
|
+
declare function parseBlobStorageRequest(event: NostrEvent): ParsedBlobStorageRequest | null;
|
|
712
1765
|
|
|
713
1766
|
/**
|
|
714
1767
|
* Peer discovery using Nostr NIP-02 follow lists.
|
|
@@ -980,36 +2033,32 @@ declare function publishSeedRelayEntry(config: PublishSeedRelayConfig): Promise<
|
|
|
980
2033
|
}>;
|
|
981
2034
|
|
|
982
2035
|
/**
|
|
983
|
-
* Pure
|
|
984
|
-
* No I/O or side effects — used during peer registration to determine
|
|
985
|
-
* the best matching settlement chain and token.
|
|
986
|
-
*/
|
|
987
|
-
/**
|
|
988
|
-
* Negotiates the best matching settlement chain between requester and responder.
|
|
2036
|
+
* Pure function for calculating ILP PREPARE amount including intermediary routing fees.
|
|
989
2037
|
*
|
|
990
|
-
*
|
|
991
|
-
* 1. Chain in intersection with requester's preferred token
|
|
992
|
-
* 2. Chain in intersection with responder's preferred token
|
|
993
|
-
* 3. First chain in intersection (requester's order preserved)
|
|
2038
|
+
* Formula: totalAmount = basePricePerByte * packetBytes + SUM(hopFees[i] * packetBytes)
|
|
994
2039
|
*
|
|
995
|
-
*
|
|
996
|
-
* @param responderChains - Chain identifiers the responder supports
|
|
997
|
-
* @param requesterPreferredTokens - Requester's preferred tokens by chain
|
|
998
|
-
* @param responderPreferredTokens - Responder's preferred tokens by chain
|
|
999
|
-
* @returns The negotiated chain identifier, or null if no intersection
|
|
2040
|
+
* All arithmetic uses bigint -- no floating point, no overflow risk.
|
|
1000
2041
|
*/
|
|
1001
|
-
declare function negotiateSettlementChain(requesterChains: string[], responderChains: string[], requesterPreferredTokens?: Record<string, string>, responderPreferredTokens?: Record<string, string>): string | null;
|
|
1002
2042
|
/**
|
|
1003
|
-
*
|
|
2043
|
+
* Parameters for route-aware fee calculation.
|
|
2044
|
+
*/
|
|
2045
|
+
interface CalculateRouteAmountParams {
|
|
2046
|
+
/** Base price per byte charged by the destination node. */
|
|
2047
|
+
basePricePerByte: bigint;
|
|
2048
|
+
/** Length of the TOON-encoded packet in bytes. */
|
|
2049
|
+
packetByteLength: number;
|
|
2050
|
+
/** Per-byte fees for each intermediary hop on the route (ordered sender-to-destination). */
|
|
2051
|
+
hopFees: bigint[];
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* Calculates the total ILP PREPARE amount including intermediary routing fees.
|
|
1004
2055
|
*
|
|
1005
|
-
*
|
|
2056
|
+
* For a direct route (empty hopFees), returns basePricePerByte * packetByteLength.
|
|
2057
|
+
* For multi-hop routes, adds each intermediary's feePerByte * packetByteLength.
|
|
1006
2058
|
*
|
|
1007
|
-
* @
|
|
1008
|
-
* @param requesterPreferredTokens - Requester's preferred tokens by chain
|
|
1009
|
-
* @param responderPreferredTokens - Responder's preferred tokens by chain
|
|
1010
|
-
* @returns The token address, or undefined if neither party has a preference
|
|
2059
|
+
* @returns Total amount as bigint.
|
|
1011
2060
|
*/
|
|
1012
|
-
declare function
|
|
2061
|
+
declare function calculateRouteAmount(params: CalculateRouteAmountParams): bigint;
|
|
1013
2062
|
|
|
1014
2063
|
/**
|
|
1015
2064
|
* Bootstrap state machine types, event types, and client interfaces.
|
|
@@ -1055,6 +2104,10 @@ interface BootstrapResult {
|
|
|
1055
2104
|
negotiatedChain?: string;
|
|
1056
2105
|
/** Peer's settlement address */
|
|
1057
2106
|
settlementAddress?: string;
|
|
2107
|
+
/** Token address for the negotiated chain */
|
|
2108
|
+
tokenAddress?: string;
|
|
2109
|
+
/** TokenNetwork/program/zkApp address for the negotiated chain */
|
|
2110
|
+
tokenNetwork?: string;
|
|
1058
2111
|
}
|
|
1059
2112
|
/**
|
|
1060
2113
|
* Callback interface for connector Admin API operations.
|
|
@@ -1150,7 +2203,6 @@ type BootstrapEventListener = (event: BootstrapEvent) => void;
|
|
|
1150
2203
|
*/
|
|
1151
2204
|
interface IlpSendResult {
|
|
1152
2205
|
accepted: boolean;
|
|
1153
|
-
fulfillment?: string;
|
|
1154
2206
|
data?: string;
|
|
1155
2207
|
code?: string;
|
|
1156
2208
|
message?: string;
|
|
@@ -1224,6 +2276,83 @@ interface BootstrapServiceConfig extends BootstrapConfig {
|
|
|
1224
2276
|
basePricePerByte?: bigint;
|
|
1225
2277
|
}
|
|
1226
2278
|
|
|
2279
|
+
/**
|
|
2280
|
+
* Resolves intermediary routing fees from discovered peers using LCA-based
|
|
2281
|
+
* route resolution on the ILP address tree.
|
|
2282
|
+
*
|
|
2283
|
+
* Algorithm:
|
|
2284
|
+
* 1. Split sender and destination ILP addresses into segments.
|
|
2285
|
+
* 2. Find the longest common ancestor (LCA) -- shared prefix of segments.
|
|
2286
|
+
* 3. Intermediaries are the segments on the path from LCA down to destination's parent.
|
|
2287
|
+
* 4. For each intermediary, look up feePerByte from discovered peers.
|
|
2288
|
+
* 5. Unknown intermediaries default to feePerByte 0n with a warning.
|
|
2289
|
+
*/
|
|
2290
|
+
|
|
2291
|
+
/**
|
|
2292
|
+
* Parameters for resolving route fees.
|
|
2293
|
+
*/
|
|
2294
|
+
interface ResolveRouteFeesParams {
|
|
2295
|
+
/** ILP address of the destination node. */
|
|
2296
|
+
destination: string;
|
|
2297
|
+
/** ILP address of the sender (own node). */
|
|
2298
|
+
ownIlpAddress: string;
|
|
2299
|
+
/** All discovered peers (including peered ones) with their ILP peer info. */
|
|
2300
|
+
discoveredPeers: DiscoveredPeer[];
|
|
2301
|
+
}
|
|
2302
|
+
/**
|
|
2303
|
+
* Result of route fee resolution.
|
|
2304
|
+
*/
|
|
2305
|
+
interface ResolveRouteFeesResult {
|
|
2306
|
+
/** Per-byte fees for each intermediary hop, ordered sender-to-destination. */
|
|
2307
|
+
hopFees: bigint[];
|
|
2308
|
+
/** Warning messages for unknown intermediaries that defaulted to 0. */
|
|
2309
|
+
warnings: string[];
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Resolves intermediary routing fees for a route from sender to destination.
|
|
2313
|
+
*
|
|
2314
|
+
* Uses LCA-based route resolution: intermediary hops are the ILP address
|
|
2315
|
+
* segments between the longest common ancestor and the destination's parent.
|
|
2316
|
+
*
|
|
2317
|
+
* The peer lookup map is cached by array reference to avoid rebuilding it
|
|
2318
|
+
* on every call when the same discoveredPeers array is passed repeatedly.
|
|
2319
|
+
*
|
|
2320
|
+
* @returns Hop fees and any warnings about unknown intermediaries.
|
|
2321
|
+
*/
|
|
2322
|
+
declare function resolveRouteFees(params: ResolveRouteFeesParams): ResolveRouteFeesResult;
|
|
2323
|
+
|
|
2324
|
+
/**
|
|
2325
|
+
* Pure functions for settlement chain negotiation.
|
|
2326
|
+
* No I/O or side effects — used during peer registration to determine
|
|
2327
|
+
* the best matching settlement chain and token.
|
|
2328
|
+
*/
|
|
2329
|
+
/**
|
|
2330
|
+
* Negotiates the best matching settlement chain between requester and responder.
|
|
2331
|
+
*
|
|
2332
|
+
* Preference order:
|
|
2333
|
+
* 1. Chain in intersection with requester's preferred token
|
|
2334
|
+
* 2. Chain in intersection with responder's preferred token
|
|
2335
|
+
* 3. First chain in intersection (requester's order preserved)
|
|
2336
|
+
*
|
|
2337
|
+
* @param requesterChains - Chain identifiers the requester supports
|
|
2338
|
+
* @param responderChains - Chain identifiers the responder supports
|
|
2339
|
+
* @param requesterPreferredTokens - Requester's preferred tokens by chain
|
|
2340
|
+
* @param responderPreferredTokens - Responder's preferred tokens by chain
|
|
2341
|
+
* @returns The negotiated chain identifier, or null if no intersection
|
|
2342
|
+
*/
|
|
2343
|
+
declare function negotiateSettlementChain(requesterChains: string[], responderChains: string[], requesterPreferredTokens?: Record<string, string>, responderPreferredTokens?: Record<string, string>): string | null;
|
|
2344
|
+
/**
|
|
2345
|
+
* Resolves which token to use for a given chain.
|
|
2346
|
+
*
|
|
2347
|
+
* Priority: requester's preference > responder's preference > undefined
|
|
2348
|
+
*
|
|
2349
|
+
* @param chain - The chain identifier to resolve token for
|
|
2350
|
+
* @param requesterPreferredTokens - Requester's preferred tokens by chain
|
|
2351
|
+
* @param responderPreferredTokens - Responder's preferred tokens by chain
|
|
2352
|
+
* @returns The token address, or undefined if neither party has a preference
|
|
2353
|
+
*/
|
|
2354
|
+
declare function resolveTokenForChain(chain: string, requesterPreferredTokens?: Record<string, string>, responderPreferredTokens?: Record<string, string>): string | undefined;
|
|
2355
|
+
|
|
1227
2356
|
/**
|
|
1228
2357
|
* Bootstrap service for peer discovery and network initialization.
|
|
1229
2358
|
*
|
|
@@ -1374,6 +2503,19 @@ declare class BootstrapService {
|
|
|
1374
2503
|
* @returns Map of pubkey to IlpPeerInfo for discovered peers
|
|
1375
2504
|
*/
|
|
1376
2505
|
discoverPeersViaRelay(relayUrl: string, excludePubkeys?: string[]): Promise<Map<string, IlpPeerInfo>>;
|
|
2506
|
+
/**
|
|
2507
|
+
* Re-advertise own kind:10032 to all previously bootstrapped peers.
|
|
2508
|
+
*
|
|
2509
|
+
* Called after topology changes (addUpstreamPeer/removeUpstreamPeer) to
|
|
2510
|
+
* propagate updated ILP address lists to the network. Uses the same
|
|
2511
|
+
* ILP-first announcement path as the initial Phase 2 bootstrap.
|
|
2512
|
+
*
|
|
2513
|
+
* For non-ILP mode, publishes directly to each peer's relay URL.
|
|
2514
|
+
*
|
|
2515
|
+
* @param results - The bootstrap results from the initial bootstrap() call
|
|
2516
|
+
* @returns Number of peers successfully re-announced to
|
|
2517
|
+
*/
|
|
2518
|
+
republish(results: BootstrapResult[]): Promise<number>;
|
|
1377
2519
|
/**
|
|
1378
2520
|
* Get our pubkey.
|
|
1379
2521
|
*/
|
|
@@ -1414,6 +2556,8 @@ interface DiscoveryTracker {
|
|
|
1414
2556
|
peerWith(pubkey: string): Promise<void>;
|
|
1415
2557
|
/** Get discovered peers not yet peered with. */
|
|
1416
2558
|
getDiscoveredPeers(): DiscoveredPeer[];
|
|
2559
|
+
/** Get all discovered peers regardless of peering status (for fee calculation). */
|
|
2560
|
+
getAllDiscoveredPeers(): DiscoveredPeer[];
|
|
1417
2561
|
/** Check if a pubkey has been actively peered with. */
|
|
1418
2562
|
isPeered(pubkey: string): boolean;
|
|
1419
2563
|
/** Count of registered (peered) peers. */
|
|
@@ -1428,6 +2572,14 @@ interface DiscoveryTracker {
|
|
|
1428
2572
|
setConnectorAdmin(admin: ConnectorAdminClient): void;
|
|
1429
2573
|
/** Set channel client for payment channel opening (optional). */
|
|
1430
2574
|
setChannelClient(client: ConnectorChannelClient): void;
|
|
2575
|
+
/** Get negotiation metadata for a peer (for lazy channel opening). */
|
|
2576
|
+
getPeerNegotiation(peerId: string): {
|
|
2577
|
+
chain: string;
|
|
2578
|
+
chainType: string;
|
|
2579
|
+
settlementAddress: string;
|
|
2580
|
+
tokenAddress?: string;
|
|
2581
|
+
tokenNetwork?: string;
|
|
2582
|
+
} | undefined;
|
|
1431
2583
|
/** Mark pubkeys as already-peered (e.g., from bootstrap phase). */
|
|
1432
2584
|
addExcludedPubkeys(pubkeys: string[]): void;
|
|
1433
2585
|
}
|
|
@@ -1478,9 +2630,7 @@ interface SendPacketParams {
|
|
|
1478
2630
|
/** Amount as BigInt (not string) */
|
|
1479
2631
|
amount: bigint;
|
|
1480
2632
|
/** Binary data (not base64 string) */
|
|
1481
|
-
data
|
|
1482
|
-
/** 32-byte SHA-256 execution condition */
|
|
1483
|
-
executionCondition?: Uint8Array;
|
|
2633
|
+
data?: Uint8Array;
|
|
1484
2634
|
/**
|
|
1485
2635
|
* Packet expiration. Included for structural compatibility with ConnectorNode
|
|
1486
2636
|
* but is not set by the direct client — callers or the connector provide it
|
|
@@ -1493,15 +2643,13 @@ interface SendPacketParams {
|
|
|
1493
2643
|
*
|
|
1494
2644
|
* Accepts both string discriminants ('fulfill'/'reject') for backward
|
|
1495
2645
|
* compatibility with test mocks, and numeric PacketType enum values
|
|
1496
|
-
* (13 = FULFILL, 14 = REJECT) used by @toon-protocol/connector@
|
|
2646
|
+
* (13 = FULFILL, 14 = REJECT) used by @toon-protocol/connector@2.0.0+.
|
|
1497
2647
|
*/
|
|
1498
2648
|
type SendPacketResult = {
|
|
1499
2649
|
type: 'fulfill';
|
|
1500
|
-
fulfillment: Uint8Array | Buffer;
|
|
1501
2650
|
data?: Uint8Array | Buffer;
|
|
1502
2651
|
} | {
|
|
1503
2652
|
type: 13;
|
|
1504
|
-
fulfillment: Uint8Array | Buffer;
|
|
1505
2653
|
data?: Uint8Array | Buffer;
|
|
1506
2654
|
} | {
|
|
1507
2655
|
type: 'reject';
|
|
@@ -1525,17 +2673,10 @@ interface ConnectorNodeLike {
|
|
|
1525
2673
|
sendPacket(params: SendPacketParams): Promise<SendPacketResult>;
|
|
1526
2674
|
}
|
|
1527
2675
|
/**
|
|
1528
|
-
*
|
|
1529
|
-
*
|
|
1530
|
-
* @deprecated toonDecoder is no longer used for condition computation.
|
|
1531
|
-
* Execution condition is computed directly from raw data bytes:
|
|
1532
|
-
* condition = SHA-256(SHA-256(raw_data_bytes))
|
|
2676
|
+
* @deprecated No longer used. Kept for backward compatibility.
|
|
1533
2677
|
*/
|
|
1534
2678
|
interface DirectRuntimeClientConfig {
|
|
1535
|
-
/**
|
|
1536
|
-
* @deprecated No longer used. Execution condition is computed from raw data
|
|
1537
|
-
* bytes to match the connector's PaymentHandlerAdapter.
|
|
1538
|
-
*/
|
|
2679
|
+
/** @deprecated No longer used. */
|
|
1539
2680
|
toonDecoder?: (bytes: Uint8Array) => {
|
|
1540
2681
|
id: string;
|
|
1541
2682
|
};
|
|
@@ -1548,7 +2689,7 @@ interface DirectRuntimeClientConfig {
|
|
|
1548
2689
|
* @param config - Optional configuration (e.g., toonDecoder for condition computation)
|
|
1549
2690
|
* @returns An IlpClient instance
|
|
1550
2691
|
*/
|
|
1551
|
-
declare function createDirectIlpClient(connector: ConnectorNodeLike,
|
|
2692
|
+
declare function createDirectIlpClient(connector: ConnectorNodeLike, _config?: DirectRuntimeClientConfig): IlpClient;
|
|
1552
2693
|
/**
|
|
1553
2694
|
* @deprecated Use createDirectIlpClient instead
|
|
1554
2695
|
*/
|
|
@@ -1757,117 +2898,6 @@ declare function createHttpIlpClient(connectorUrl: string): IlpClient;
|
|
|
1757
2898
|
*/
|
|
1758
2899
|
declare function createHttpChannelClient(adminUrl: string): ConnectorChannelClient;
|
|
1759
2900
|
|
|
1760
|
-
/**
|
|
1761
|
-
* AttestationVerifier -- TEE attestation verification, state lifecycle,
|
|
1762
|
-
* and attestation-aware peer ranking for Story 4.3.
|
|
1763
|
-
*
|
|
1764
|
-
* This is a pure logic class with no transport layer. It receives parsed
|
|
1765
|
-
* attestation data and returns verification results. The transport layer
|
|
1766
|
-
* (subscribing to kind:10033 events on relays) is a Story 4.6 concern.
|
|
1767
|
-
*
|
|
1768
|
-
* The AttestationVerifier is the single source of truth for attestation
|
|
1769
|
-
* state (R-E4-008). Both the kind:10033 Nostr event path and the /health
|
|
1770
|
-
* HTTP endpoint derive their TEE state from the same verifier instance.
|
|
1771
|
-
*
|
|
1772
|
-
* Attestation State Machine (Decision 12):
|
|
1773
|
-
* VALID (within validitySeconds)
|
|
1774
|
-
* -> STALE (within graceSeconds after validity expires)
|
|
1775
|
-
* -> UNATTESTED (after grace period expires)
|
|
1776
|
-
*
|
|
1777
|
-
* Trust degrades; money doesn't -- attestation state changes never
|
|
1778
|
-
* trigger payment channel closure.
|
|
1779
|
-
*/
|
|
1780
|
-
|
|
1781
|
-
/**
|
|
1782
|
-
* Attestation lifecycle state.
|
|
1783
|
-
*
|
|
1784
|
-
* Transitions: VALID -> STALE -> UNATTESTED.
|
|
1785
|
-
* A peer that was never attested starts as UNATTESTED.
|
|
1786
|
-
*/
|
|
1787
|
-
declare enum AttestationState {
|
|
1788
|
-
/** Attestation is within validity period. */
|
|
1789
|
-
VALID = "valid",
|
|
1790
|
-
/** Attestation has expired but is within the grace period. */
|
|
1791
|
-
STALE = "stale",
|
|
1792
|
-
/** Attestation has expired past the grace period or was never attested. */
|
|
1793
|
-
UNATTESTED = "unattested"
|
|
1794
|
-
}
|
|
1795
|
-
/** Result of PCR verification against a known-good registry. */
|
|
1796
|
-
interface VerificationResult {
|
|
1797
|
-
valid: boolean;
|
|
1798
|
-
reason?: string;
|
|
1799
|
-
}
|
|
1800
|
-
/**
|
|
1801
|
-
* Descriptor for a peer in the attestation-aware ranking system.
|
|
1802
|
-
* Used by `rankPeers()` to order peers by attestation status.
|
|
1803
|
-
*/
|
|
1804
|
-
interface PeerDescriptor {
|
|
1805
|
-
pubkey: string;
|
|
1806
|
-
relayUrl: string;
|
|
1807
|
-
attested: boolean;
|
|
1808
|
-
attestationTimestamp?: number;
|
|
1809
|
-
}
|
|
1810
|
-
/**
|
|
1811
|
-
* Configuration for the AttestationVerifier.
|
|
1812
|
-
*/
|
|
1813
|
-
interface AttestationVerifierConfig {
|
|
1814
|
-
/** Map of known-good PCR values. Key is PCR hash, value is trust status. */
|
|
1815
|
-
knownGoodPcrs: Map<string, boolean>;
|
|
1816
|
-
/** Attestation validity period in seconds (default: 300). */
|
|
1817
|
-
validitySeconds?: number;
|
|
1818
|
-
/** Grace period in seconds after validity expires before marking as unattested (default: 30). */
|
|
1819
|
-
graceSeconds?: number;
|
|
1820
|
-
}
|
|
1821
|
-
/**
|
|
1822
|
-
* Verifies TEE attestations, computes attestation lifecycle state,
|
|
1823
|
-
* and ranks peers by attestation status.
|
|
1824
|
-
*
|
|
1825
|
-
* Single source of truth for attestation state (R-E4-008).
|
|
1826
|
-
*/
|
|
1827
|
-
declare class AttestationVerifier {
|
|
1828
|
-
private readonly knownGoodPcrs;
|
|
1829
|
-
private readonly validitySeconds;
|
|
1830
|
-
private readonly graceSeconds;
|
|
1831
|
-
constructor(config: AttestationVerifierConfig);
|
|
1832
|
-
/**
|
|
1833
|
-
* Verifies a TEE attestation's PCR values against the known-good registry.
|
|
1834
|
-
*
|
|
1835
|
-
* All three PCR values (pcr0, pcr1, pcr2) must be present and truthy in
|
|
1836
|
-
* the registry for verification to pass.
|
|
1837
|
-
*
|
|
1838
|
-
* @param attestation - The TEE attestation to verify.
|
|
1839
|
-
* @returns Verification result with `valid: true` or `valid: false` with reason.
|
|
1840
|
-
*/
|
|
1841
|
-
verify(attestation: TeeAttestation): VerificationResult;
|
|
1842
|
-
/**
|
|
1843
|
-
* Computes the attestation lifecycle state based on timing.
|
|
1844
|
-
*
|
|
1845
|
-
* Boundary behavior:
|
|
1846
|
-
* - At exactly `attestedAt + validitySeconds`: VALID (inclusive <=)
|
|
1847
|
-
* - At exactly `attestedAt + validitySeconds + graceSeconds`: STALE (inclusive <=)
|
|
1848
|
-
* - After grace expires: UNATTESTED
|
|
1849
|
-
*
|
|
1850
|
-
* @param _attestation - The TEE attestation (unused, reserved for future per-attestation logic).
|
|
1851
|
-
* @param attestedAt - Unix timestamp when the attestation was created.
|
|
1852
|
-
* @param now - Optional current unix timestamp (defaults to real clock).
|
|
1853
|
-
* @returns The current attestation state.
|
|
1854
|
-
*/
|
|
1855
|
-
getAttestationState(_attestation: TeeAttestation, attestedAt: number, now?: number): AttestationState;
|
|
1856
|
-
/**
|
|
1857
|
-
* Ranks peers by attestation status: attested peers first, then non-attested.
|
|
1858
|
-
*
|
|
1859
|
-
* Preserves relative order within each group (stable sort via filter).
|
|
1860
|
-
* Does NOT mutate the input array -- returns a new sorted array.
|
|
1861
|
-
*
|
|
1862
|
-
* Attestation is a preference, not a requirement. Non-attested peers
|
|
1863
|
-
* remain in the result and are connectable.
|
|
1864
|
-
*
|
|
1865
|
-
* @param peers - Array of peer descriptors to rank.
|
|
1866
|
-
* @returns New array with attested peers first, preserving relative order.
|
|
1867
|
-
*/
|
|
1868
|
-
rankPeers(peers: PeerDescriptor[]): PeerDescriptor[];
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
2901
|
/**
|
|
1872
2902
|
* AttestationBootstrap -- attestation-first seed relay bootstrap for Story 4.6.
|
|
1873
2903
|
*
|
|
@@ -2023,8 +3053,6 @@ interface HandlePacketRequest {
|
|
|
2023
3053
|
*/
|
|
2024
3054
|
interface HandlePacketAcceptResponse {
|
|
2025
3055
|
accept: true;
|
|
2026
|
-
/** Base64-encoded fulfillment (SHA-256 of event.id) */
|
|
2027
|
-
fulfillment: string;
|
|
2028
3056
|
/** Base64-encoded response data (e.g., TOON-encoded response for relay back in ILP FULFILL) */
|
|
2029
3057
|
data?: string;
|
|
2030
3058
|
metadata?: Record<string, unknown>;
|
|
@@ -2256,7 +3284,7 @@ declare function createToonNode(config: ToonNodeConfig): ToonNode;
|
|
|
2256
3284
|
* The legacy on-chain mock contract on Anvil uses 18 decimals (inherited
|
|
2257
3285
|
* from the original ERC-20 deploy script in the connector repo). The
|
|
2258
3286
|
* constants below reflect production USDC semantics (6 decimals). When
|
|
2259
|
-
* interacting with the Anvil mock contract directly (e.g.,
|
|
3287
|
+
* interacting with the Anvil mock contract directly (e.g., via the
|
|
2260
3288
|
* faucet), use 18 decimals for on-chain amounts. The pricing pipeline
|
|
2261
3289
|
* (basePricePerByte * toonLength) is denomination-agnostic (bigint math)
|
|
2262
3290
|
* and works correctly regardless of on-chain decimals.
|
|
@@ -2314,10 +3342,10 @@ declare const MOCK_USDC_CONFIG: MockUsdcConfig;
|
|
|
2314
3342
|
/**
|
|
2315
3343
|
* Multi-environment chain configuration for TOON relay nodes.
|
|
2316
3344
|
*
|
|
2317
|
-
* Provides chain presets for three
|
|
2318
|
-
* - **
|
|
2319
|
-
* - **
|
|
2320
|
-
* - **
|
|
3345
|
+
* Provides chain presets for three blockchain families:
|
|
3346
|
+
* - **EVM**: Anvil (local dev), Arbitrum Sepolia (staging), Arbitrum One (production)
|
|
3347
|
+
* - **Solana**: solana-devnet (local dev)
|
|
3348
|
+
* - **Mina**: mina-devnet (local dev)
|
|
2321
3349
|
*
|
|
2322
3350
|
* Environment variable overrides:
|
|
2323
3351
|
* - `TOON_CHAIN` overrides the config-level chain parameter
|
|
@@ -2327,11 +3355,27 @@ declare const MOCK_USDC_CONFIG: MockUsdcConfig;
|
|
|
2327
3355
|
* @module
|
|
2328
3356
|
*/
|
|
2329
3357
|
/**
|
|
2330
|
-
*
|
|
3358
|
+
* Blockchain family type. Matches the connector's BlockchainType.
|
|
3359
|
+
*/
|
|
3360
|
+
type ChainType = 'evm' | 'solana' | 'mina';
|
|
3361
|
+
/**
|
|
3362
|
+
* Supported EVM chain preset names (backward-compatible).
|
|
2331
3363
|
*/
|
|
2332
3364
|
type ChainName = 'anvil' | 'arbitrum-sepolia' | 'arbitrum-one';
|
|
2333
3365
|
/**
|
|
2334
|
-
*
|
|
3366
|
+
* Supported Solana chain preset names.
|
|
3367
|
+
*/
|
|
3368
|
+
type SolanaChainName = 'solana-devnet';
|
|
3369
|
+
/**
|
|
3370
|
+
* Supported Mina chain preset names.
|
|
3371
|
+
*/
|
|
3372
|
+
type MinaChainName = 'mina-devnet';
|
|
3373
|
+
/**
|
|
3374
|
+
* All supported chain preset names across all chain types.
|
|
3375
|
+
*/
|
|
3376
|
+
type MultiChainName = ChainName | SolanaChainName | MinaChainName;
|
|
3377
|
+
/**
|
|
3378
|
+
* Resolved EVM chain configuration with all fields populated.
|
|
2335
3379
|
*/
|
|
2336
3380
|
interface ChainPreset {
|
|
2337
3381
|
/** Preset identifier ('anvil' | 'arbitrum-sepolia' | 'arbitrum-one'). */
|
|
@@ -2348,7 +3392,81 @@ interface ChainPreset {
|
|
|
2348
3392
|
registryAddress: string;
|
|
2349
3393
|
}
|
|
2350
3394
|
/**
|
|
2351
|
-
*
|
|
3395
|
+
* Resolved Solana chain configuration.
|
|
3396
|
+
*/
|
|
3397
|
+
interface SolanaChainPreset {
|
|
3398
|
+
/** Preset identifier (e.g., 'solana-devnet'). */
|
|
3399
|
+
name: string;
|
|
3400
|
+
/** Chain type discriminator. */
|
|
3401
|
+
chainType: 'solana';
|
|
3402
|
+
/** Solana cluster RPC endpoint (HTTP). */
|
|
3403
|
+
rpcUrl: string;
|
|
3404
|
+
/** Payment channel program ID (base58-encoded). TBD until deployed. */
|
|
3405
|
+
programId: string;
|
|
3406
|
+
/** Solana cluster name for chain ID namespacing (e.g., 'devnet'). */
|
|
3407
|
+
cluster: string;
|
|
3408
|
+
/** Optional SPL token mint address. */
|
|
3409
|
+
tokenMint?: string;
|
|
3410
|
+
}
|
|
3411
|
+
/**
|
|
3412
|
+
* Resolved Mina chain configuration.
|
|
3413
|
+
*/
|
|
3414
|
+
interface MinaChainPreset {
|
|
3415
|
+
/** Preset identifier (e.g., 'mina-devnet'). */
|
|
3416
|
+
name: string;
|
|
3417
|
+
/** Chain type discriminator. */
|
|
3418
|
+
chainType: 'mina';
|
|
3419
|
+
/** Mina GraphQL endpoint. */
|
|
3420
|
+
graphqlUrl: string;
|
|
3421
|
+
/** zkApp address for the payment channel contract. TBD until deployed. */
|
|
3422
|
+
zkAppAddress: string;
|
|
3423
|
+
/** Mina network name (e.g., 'devnet'). */
|
|
3424
|
+
network: string;
|
|
3425
|
+
/** Optional Mina token ID. */
|
|
3426
|
+
tokenId?: string;
|
|
3427
|
+
}
|
|
3428
|
+
/**
|
|
3429
|
+
* EVM-specific provider configuration entry.
|
|
3430
|
+
*/
|
|
3431
|
+
interface EVMProviderConfigEntry {
|
|
3432
|
+
chainType: 'evm';
|
|
3433
|
+
chainId: string;
|
|
3434
|
+
rpcUrl: string;
|
|
3435
|
+
registryAddress: string;
|
|
3436
|
+
keyId: string;
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* Solana-specific provider configuration entry.
|
|
3440
|
+
*/
|
|
3441
|
+
interface SolanaProviderConfigEntry {
|
|
3442
|
+
chainType: 'solana';
|
|
3443
|
+
chainId: string;
|
|
3444
|
+
rpcUrl: string;
|
|
3445
|
+
programId: string;
|
|
3446
|
+
keyId: string;
|
|
3447
|
+
wsUrl?: string;
|
|
3448
|
+
cluster?: string;
|
|
3449
|
+
tokenMint?: string;
|
|
3450
|
+
}
|
|
3451
|
+
/**
|
|
3452
|
+
* Mina-specific provider configuration entry.
|
|
3453
|
+
*/
|
|
3454
|
+
interface MinaProviderConfigEntry {
|
|
3455
|
+
chainType: 'mina';
|
|
3456
|
+
chainId: string;
|
|
3457
|
+
graphqlUrl: string;
|
|
3458
|
+
zkAppAddress: string;
|
|
3459
|
+
keyId?: string;
|
|
3460
|
+
tokenId?: string;
|
|
3461
|
+
network?: string;
|
|
3462
|
+
}
|
|
3463
|
+
/**
|
|
3464
|
+
* Discriminated union of all chain provider config entries.
|
|
3465
|
+
* Mirrors the connector's ChainProviderConfigEntry type for passthrough.
|
|
3466
|
+
*/
|
|
3467
|
+
type ChainProviderConfigEntry = EVMProviderConfigEntry | SolanaProviderConfigEntry | MinaProviderConfigEntry;
|
|
3468
|
+
/**
|
|
3469
|
+
* Built-in EVM chain presets for supported deployment environments.
|
|
2352
3470
|
*
|
|
2353
3471
|
* Each preset provides the chainId, RPC URL, USDC address, and
|
|
2354
3472
|
* TokenNetwork address for its environment. Fields can be overridden
|
|
@@ -2398,6 +3516,65 @@ declare function buildEip712Domain(config: ChainPreset): {
|
|
|
2398
3516
|
chainId: number;
|
|
2399
3517
|
verifyingContract: string;
|
|
2400
3518
|
};
|
|
3519
|
+
/**
|
|
3520
|
+
* Built-in Solana chain presets.
|
|
3521
|
+
*/
|
|
3522
|
+
declare const SOLANA_CHAIN_PRESETS: Record<SolanaChainName, SolanaChainPreset>;
|
|
3523
|
+
/**
|
|
3524
|
+
* Built-in Mina chain presets.
|
|
3525
|
+
*/
|
|
3526
|
+
declare const MINA_CHAIN_PRESETS: Record<MinaChainName, MinaChainPreset>;
|
|
3527
|
+
/**
|
|
3528
|
+
* Resolve a Solana chain preset by name, with env var overrides.
|
|
3529
|
+
*
|
|
3530
|
+
* Environment variable overrides:
|
|
3531
|
+
* - `SOLANA_RPC_URL` overrides the preset's rpcUrl
|
|
3532
|
+
* - `SOLANA_PROGRAM_ID` overrides the preset's programId
|
|
3533
|
+
*
|
|
3534
|
+
* @param name - Solana chain preset name
|
|
3535
|
+
* @returns Resolved Solana chain preset
|
|
3536
|
+
* @throws ToonError if the name is not recognized
|
|
3537
|
+
*/
|
|
3538
|
+
declare function resolveSolanaChainConfig(name: SolanaChainName): SolanaChainPreset;
|
|
3539
|
+
/**
|
|
3540
|
+
* Resolve a Mina chain preset by name, with env var overrides.
|
|
3541
|
+
*
|
|
3542
|
+
* Environment variable overrides:
|
|
3543
|
+
* - `MINA_GRAPHQL_URL` overrides the preset's graphqlUrl
|
|
3544
|
+
* - `MINA_ZKAPP_ADDRESS` overrides the preset's zkAppAddress
|
|
3545
|
+
*
|
|
3546
|
+
* @param name - Mina chain preset name
|
|
3547
|
+
* @returns Resolved Mina chain preset
|
|
3548
|
+
* @throws ToonError if the name is not recognized
|
|
3549
|
+
*/
|
|
3550
|
+
declare function resolveMinaChainConfig(name: MinaChainName): MinaChainPreset;
|
|
3551
|
+
/**
|
|
3552
|
+
* Build a ChainProviderConfigEntry from a resolved EVM chain preset.
|
|
3553
|
+
*
|
|
3554
|
+
* Converts the TOON-specific ChainPreset into the connector's
|
|
3555
|
+
* ChainProviderConfigEntry format for the `chainProviders` array.
|
|
3556
|
+
*
|
|
3557
|
+
* @param config - Resolved EVM chain preset
|
|
3558
|
+
* @param keyId - Key identifier for signing operations
|
|
3559
|
+
* @returns EVM chain provider config entry
|
|
3560
|
+
*/
|
|
3561
|
+
declare function buildEvmProviderEntry(config: ChainPreset, keyId: string): EVMProviderConfigEntry;
|
|
3562
|
+
/**
|
|
3563
|
+
* Build a ChainProviderConfigEntry from a resolved Solana chain preset.
|
|
3564
|
+
*
|
|
3565
|
+
* @param config - Resolved Solana chain preset
|
|
3566
|
+
* @param keyId - Key identifier for Ed25519 signing operations
|
|
3567
|
+
* @returns Solana chain provider config entry
|
|
3568
|
+
*/
|
|
3569
|
+
declare function buildSolanaProviderEntry(config: SolanaChainPreset, keyId: string): SolanaProviderConfigEntry;
|
|
3570
|
+
/**
|
|
3571
|
+
* Build a ChainProviderConfigEntry from a resolved Mina chain preset.
|
|
3572
|
+
*
|
|
3573
|
+
* @param config - Resolved Mina chain preset
|
|
3574
|
+
* @param keyId - Optional key identifier for signing operations
|
|
3575
|
+
* @returns Mina chain provider config entry
|
|
3576
|
+
*/
|
|
3577
|
+
declare function buildMinaProviderEntry(config: MinaChainPreset, keyId?: string): MinaProviderConfigEntry;
|
|
2401
3578
|
|
|
2402
3579
|
/**
|
|
2403
3580
|
* Shared ILP PREPARE packet construction for the TOON protocol.
|
|
@@ -2847,4 +4024,4 @@ declare function createLogger(config: LoggerConfig): Logger;
|
|
|
2847
4024
|
*/
|
|
2848
4025
|
declare const VERSION = "0.1.0";
|
|
2849
4026
|
|
|
2850
|
-
export { type AgentRuntimeClient, ArDrivePeerRegistry, AttestationBootstrap, type AttestationBootstrapConfig, type AttestationBootstrapEvent, type AttestationBootstrapEventListener, type AttestationBootstrapResult, type AttestationEventOptions, AttestationState, AttestationVerifier, type AttestationVerifierConfig, type BootstrapConfig, BootstrapError, type BootstrapEvent, type BootstrapEventListener, type BootstrapPhase, type BootstrapResult, BootstrapService, type BootstrapServiceConfig, type BuildIlpPrepareParams, CHAIN_PRESETS, type ChainName, type ChainPreset, type ChannelState, type ConnectorAdminClient, type ConnectorAdminLike, type ConnectorChannelClient, type ConnectorChannelLike, type ConnectorNodeLike, type DeriveFromKmsSeedOptions, type DeterminismReport, type DirectRuntimeClientConfig, type DiscoveredPeer, type DiscoveryTracker, type DiscoveryTrackerConfig, type DvmJobStatus, type EmbeddableConnectorLike, type ForbiddenPattern, type GenesisPeer, GenesisPeerLoader, type HandlePacketAcceptResponse, type HandlePacketRejectResponse, type HandlePacketRequest, type HandlePacketResponse, ILP_PEER_INFO_KIND, IMAGE_GENERATION_KIND, type IlpClient, type IlpPeerInfo, type IlpPreparePacket, type IlpSendResult, JOB_FEEDBACK_KIND, JOB_REQUEST_KIND_BASE, JOB_RESULT_KIND_BASE, type JobFeedbackParams, type JobRequestParams, type JobResultParams, KmsIdentityError, type KmsKeypair, type KnownPeer, type LogEntry, type LogLevel, type Logger, type LoggerConfig, MOCK_USDC_ADDRESS, MOCK_USDC_CONFIG, type MockUsdcConfig, type NixBuildResult, NixBuilder, type NixBuilderConfig, NostrPeerDiscovery, type OpenChannelParams, type OpenChannelResult, type PacketHandler, type ParsedAttestation, type ParsedJobFeedback, type ParsedJobRequest, type ParsedJobResult, PcrReproducibilityError, type PcrReproducibilityResult, type PeerDescriptor, type PublishSeedRelayConfig, type RegisterPeerParams, SEED_RELAY_LIST_KIND, SERVICE_DISCOVERY_KIND, SeedRelayDiscovery, type SeedRelayDiscoveryConfig, type SeedRelayDiscoveryResult, type SeedRelayEntry, type SendPacketParams, type SendPacketResult, type ServiceDiscoveryContent, type SettlementConfig, type SkillDescriptor, type SocialDiscoveryEvent, type SocialDiscoveryEventListener, SocialPeerDiscovery, type SocialPeerDiscoveryConfig, type Subscription, TEE_ATTESTATION_KIND, TEXT_GENERATION_KIND, TEXT_TO_SPEECH_KIND, TRANSLATION_KIND, type TeeAttestation, ToonError, type ToonNode, type ToonNodeConfig, type ToonNodeStartResult, USDC_DECIMALS, USDC_NAME, USDC_SYMBOL, VERSION, type VerificationResult, type VerifyOptions, type Violation, analyzeDockerfileForNonDeterminism, buildAttestationEvent, buildEip712Domain, buildIlpPeerInfoEvent, buildIlpPrepare, buildJobFeedbackEvent, buildJobRequestEvent, buildJobResultEvent, buildSeedRelayListEvent, buildServiceDiscoveryEvent, createAgentRuntimeClient, createDirectChannelClient, createDirectConnectorAdmin, createDirectIlpClient, createDirectRuntimeClient, createDiscoveryTracker, createHttpChannelClient, createHttpConnectorAdmin, createHttpIlpClient$1 as createHttpIlpClient, createHttpRuntimeClient, createHttpIlpClient as createHttpRuntimeClientV2, createLogger, createToonNode, deriveFromKmsSeed, negotiateSettlementChain, parseAttestation, parseIlpPeerInfo, parseJobFeedback, parseJobRequest, parseJobResult, parseSeedRelayList, parseServiceDiscovery, publishSeedRelayEntry, readDockerfileNix, resolveChainConfig, resolveTokenForChain, validateChainId, verifyPcrReproducibility };
|
|
4027
|
+
export { AddressRegistry, type AgentRuntimeClient, ArDrivePeerRegistry, AttestationBootstrap, type AttestationBootstrapConfig, type AttestationBootstrapEvent, type AttestationBootstrapEventListener, type AttestationBootstrapResult, type AttestationEventOptions, AttestationState, AttestationVerifier, type AttestationVerifierConfig, type AttestedResultVerificationOptions, type AttestedResultVerificationResult, AttestedResultVerifier, BLOB_STORAGE_REQUEST_KIND, BLOB_STORAGE_RESULT_KIND, type BlobStorageRequestParams, type BootstrapConfig, BootstrapError, type BootstrapEvent, type BootstrapEventListener, type BootstrapPhase, type BootstrapResult, BootstrapService, type BootstrapServiceConfig, type BtpHandshakeExtension, type BuildIlpPrepareParams, CHAIN_PRESETS, type CalculateRouteAmountParams, type ChainName, type ChainPreset, type ChainProviderConfigEntry, type ChainType, type ChannelState, type ConnectorAdminClient, type ConnectorAdminLike, type ConnectorChannelClient, type ConnectorChannelLike, type ConnectorNodeLike, type DeriveFromKmsSeedOptions, type DeterminismReport, type DirectRuntimeClientConfig, type DiscoveredPeer, type DiscoveryTracker, type DiscoveryTrackerConfig, type DvmJobStatus, type EVMProviderConfigEntry, type EmbeddableConnectorLike, type ForbiddenPattern, type GenesisPeer, GenesisPeerLoader, type HandlePacketAcceptResponse, type HandlePacketRejectResponse, type HandlePacketRequest, type HandlePacketResponse, ILP_PEER_INFO_KIND, ILP_ROOT_PREFIX, IMAGE_GENERATION_KIND, type IlpClient, type IlpPeerInfo, type IlpPreparePacket, type IlpSendResult, JOB_FEEDBACK_KIND, JOB_REQUEST_KIND_BASE, JOB_RESULT_KIND_BASE, JOB_REVIEW_KIND, type JobFeedbackParams, type JobRequestParams, type JobResultParams, type JobReviewParams, KmsIdentityError, type KmsKeypair, type KnownPeer, type LogEntry, type LogLevel, type Logger, type LoggerConfig, MINA_CHAIN_PRESETS, MOCK_USDC_ADDRESS, MOCK_USDC_CONFIG, type MinaChainName, type MinaChainPreset, type MinaProviderConfigEntry, type MockUsdcConfig, type MultiChainName, type NixBuildResult, NixBuilder, type NixBuilderConfig, NostrPeerDiscovery, type OpenChannelParams, type OpenChannelResult, PET_INTERACTION_EVENT_KIND, PET_INTERACTION_REQUEST_KIND, PET_INTERACTION_RESULT_KIND, PREFIX_CLAIM_KIND, PREFIX_GRANT_KIND, type PacketHandler, type ParsedAttestation, type ParsedBlobStorageRequest, type ParsedJobFeedback, type ParsedJobRequest, type ParsedJobResult, type ParsedJobReview, type ParsedSwarmRequest, type ParsedSwarmSelection, type ParsedWorkflowDefinition, type ParsedWotDeclaration, PcrReproducibilityError, type PcrReproducibilityResult, type PeerDescriptor, type PrefixClaimContent, type PrefixGrantContent, type PrefixValidationResult, type PublishSeedRelayConfig, type RegisterPeerParams, type ReputationScore, ReputationScoreCalculator, type ReputationSignals, type ResolveRouteFeesParams, type ResolveRouteFeesResult, SEED_RELAY_LIST_KIND, SERVICE_DISCOVERY_KIND, SOLANA_CHAIN_PRESETS, SeedRelayDiscovery, type SeedRelayDiscoveryConfig, type SeedRelayDiscoveryResult, type SeedRelayEntry, type SendPacketParams, type SendPacketResult, type ServiceDiscoveryContent, type SettlementConfig, type SkillDescriptor, type SocialDiscoveryEvent, type SocialDiscoveryEventListener, SocialPeerDiscovery, type SocialPeerDiscoveryConfig, type SolanaChainName, type SolanaChainPreset, type SolanaProviderConfigEntry, type Subscription, type SwarmRequestParams, type SwarmSelectionParams, TEE_ATTESTATION_KIND, TEXT_GENERATION_KIND, TEXT_TO_SPEECH_KIND, TRANSLATION_KIND, type TeeAttestation, ToonError, type ToonNode, type ToonNodeConfig, type ToonNodeStartResult, USDC_DECIMALS, USDC_NAME, USDC_SYMBOL, VERSION, type VerificationResult, type VerifyOptions, type Violation, WEB_OF_TRUST_KIND, WORKFLOW_CHAIN_KIND, type WorkflowDefinitionParams, type WorkflowStep, type WotDeclarationParams, analyzeDockerfileForNonDeterminism, assignAddressFromHandshake, buildAttestationEvent, buildBlobStorageRequest, buildEip712Domain, buildEvmProviderEntry, buildIlpPeerInfoEvent, buildIlpPrepare, buildJobFeedbackEvent, buildJobRequestEvent, buildJobResultEvent, buildJobReviewEvent, buildMinaProviderEntry, buildPrefixClaimEvent, buildPrefixGrantEvent, buildPrefixHandshakeData, buildSeedRelayListEvent, buildServiceDiscoveryEvent, buildSolanaProviderEntry, buildSwarmRequestEvent, buildSwarmSelectionEvent, buildWorkflowDefinitionEvent, buildWotDeclarationEvent, calculateRouteAmount, checkAddressCollision, createAgentRuntimeClient, createDirectChannelClient, createDirectConnectorAdmin, createDirectIlpClient, createDirectRuntimeClient, createDiscoveryTracker, createHttpChannelClient, createHttpConnectorAdmin, createHttpIlpClient$1 as createHttpIlpClient, createHttpRuntimeClient, createHttpIlpClient as createHttpRuntimeClientV2, createLogger, createToonNode, deriveChildAddress, deriveFromKmsSeed, extractPrefixFromHandshake, hasMinReputation, hasRequireAttestation, isGenesisNode, isValidIlpAddressStructure, negotiateSettlementChain, parseAttestation, parseBlobStorageRequest, parseIlpPeerInfo, parseJobFeedback, parseJobRequest, parseJobResult, parseJobReview, parsePrefixClaimEvent, parsePrefixGrantEvent, parseSeedRelayList, parseServiceDiscovery, parseSwarmRequest, parseSwarmSelection, parseWorkflowDefinition, parseWotDeclaration, publishSeedRelayEntry, readDockerfileNix, resolveChainConfig, resolveMinaChainConfig, resolveRouteFees, resolveSolanaChainConfig, resolveTokenForChain, validateChainId, validateIlpAddress, validatePrefix, validatePrefixConsistency, verifyPcrReproducibility };
|