@elisym/sdk 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +327 -0
- package/dist/index.cjs +1199 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +290 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.js +1145 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { Filter, Event } from 'nostr-tools';
|
|
2
|
+
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
3
|
+
|
|
4
|
+
type SubCloser = {
|
|
5
|
+
close: (reason?: string) => void;
|
|
6
|
+
};
|
|
7
|
+
declare class NostrPool {
|
|
8
|
+
private pool;
|
|
9
|
+
private relays;
|
|
10
|
+
constructor(relays?: string[]);
|
|
11
|
+
querySync(filter: Filter): Promise<Event[]>;
|
|
12
|
+
queryBatched(filter: Omit<Filter, "authors">, keys: string[], batchSize?: number): Promise<Event[]>;
|
|
13
|
+
queryBatchedByTag(filter: Filter, tagName: string, values: string[], batchSize?: number): Promise<Event[]>;
|
|
14
|
+
publish(event: Event): Promise<void>;
|
|
15
|
+
/** Publish to all relays and wait for all to settle. Throws if none accepted. */
|
|
16
|
+
publishAll(event: Event): Promise<void>;
|
|
17
|
+
subscribe(filter: Filter, onEvent: (event: Event) => void): SubCloser;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe and wait until at least one relay confirms the subscription
|
|
20
|
+
* is active (EOSE). Resolves on the first relay that responds.
|
|
21
|
+
* Essential for ephemeral events where the subscription must be live
|
|
22
|
+
* before publishing.
|
|
23
|
+
*/
|
|
24
|
+
subscribeAndWait(filter: Filter, onEvent: (event: Event) => void, timeoutMs?: number): Promise<SubCloser>;
|
|
25
|
+
/**
|
|
26
|
+
* Tear down pool and create a fresh one.
|
|
27
|
+
* Works around nostr-tools `onerror → skipReconnection = true` bug
|
|
28
|
+
* that permanently kills subscriptions. Callers must re-subscribe.
|
|
29
|
+
*/
|
|
30
|
+
reset(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Lightweight connectivity probe. Returns true if at least one relay responds.
|
|
33
|
+
*/
|
|
34
|
+
probe(timeoutMs?: number): Promise<boolean>;
|
|
35
|
+
getRelays(): string[];
|
|
36
|
+
close(): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare class ElisymIdentity {
|
|
40
|
+
readonly secretKey: Uint8Array;
|
|
41
|
+
readonly publicKey: string;
|
|
42
|
+
readonly npub: string;
|
|
43
|
+
private constructor();
|
|
44
|
+
static generate(): ElisymIdentity;
|
|
45
|
+
static fromSecretKey(sk: Uint8Array): ElisymIdentity;
|
|
46
|
+
static fromHex(hex: string): ElisymIdentity;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface PaymentInfo {
|
|
50
|
+
chain: string;
|
|
51
|
+
network: string;
|
|
52
|
+
address: string;
|
|
53
|
+
job_price?: number;
|
|
54
|
+
}
|
|
55
|
+
interface CapabilityCard {
|
|
56
|
+
name: string;
|
|
57
|
+
description: string;
|
|
58
|
+
capabilities: string[];
|
|
59
|
+
payment?: PaymentInfo;
|
|
60
|
+
image?: string;
|
|
61
|
+
static?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface Agent {
|
|
64
|
+
pubkey: string;
|
|
65
|
+
npub: string;
|
|
66
|
+
cards: CapabilityCard[];
|
|
67
|
+
eventId: string;
|
|
68
|
+
supportedKinds: number[];
|
|
69
|
+
lastSeen: number;
|
|
70
|
+
picture?: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
about?: string;
|
|
73
|
+
}
|
|
74
|
+
type JobStatus = "payment-required" | "payment-completed" | "processing" | "error" | "success" | "partial";
|
|
75
|
+
interface Job {
|
|
76
|
+
eventId: string;
|
|
77
|
+
customer: string;
|
|
78
|
+
agentPubkey?: string;
|
|
79
|
+
capability?: string;
|
|
80
|
+
bid?: number;
|
|
81
|
+
status: JobStatus | string;
|
|
82
|
+
result?: string;
|
|
83
|
+
resultEventId?: string;
|
|
84
|
+
amount?: number;
|
|
85
|
+
txHash?: string;
|
|
86
|
+
createdAt: number;
|
|
87
|
+
}
|
|
88
|
+
interface NetworkStats {
|
|
89
|
+
totalAgentCount: number;
|
|
90
|
+
agentCount: number;
|
|
91
|
+
jobCount: number;
|
|
92
|
+
totalLamports: number;
|
|
93
|
+
}
|
|
94
|
+
type Network = "mainnet" | "devnet";
|
|
95
|
+
interface PingResult {
|
|
96
|
+
online: boolean;
|
|
97
|
+
/** The identity used for the ping session — reuse for job submission so pubkeys match. */
|
|
98
|
+
identity: ElisymIdentity | null;
|
|
99
|
+
}
|
|
100
|
+
interface PaymentRequestData {
|
|
101
|
+
recipient: string;
|
|
102
|
+
amount: number;
|
|
103
|
+
reference: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
fee_address?: string;
|
|
106
|
+
fee_amount?: number;
|
|
107
|
+
/** Creation timestamp (Unix seconds). */
|
|
108
|
+
created_at: number;
|
|
109
|
+
/** Expiry duration in seconds. */
|
|
110
|
+
expiry_secs: number;
|
|
111
|
+
}
|
|
112
|
+
interface ElisymClientConfig {
|
|
113
|
+
relays?: string[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Convert a capability name to its Nostr d-tag form. */
|
|
117
|
+
declare function toDTag(name: string): string;
|
|
118
|
+
declare class DiscoveryService {
|
|
119
|
+
private pool;
|
|
120
|
+
private allSeenAgents;
|
|
121
|
+
constructor(pool: NostrPool);
|
|
122
|
+
/** Count elisym agents (kind:31990 with "elisym" tag). */
|
|
123
|
+
fetchAllAgentCount(): Promise<number>;
|
|
124
|
+
/**
|
|
125
|
+
* Fetch a single page of elisym agents with relay-side pagination.
|
|
126
|
+
* Uses `until` cursor for Nostr cursor-based pagination.
|
|
127
|
+
* Does NOT fetch activity (faster than fetchAgents).
|
|
128
|
+
*/
|
|
129
|
+
fetchAgentsPage(network?: Network, limit?: number, until?: number): Promise<{
|
|
130
|
+
agents: Agent[];
|
|
131
|
+
oldestCreatedAt: number | null;
|
|
132
|
+
rawEventCount: number;
|
|
133
|
+
}>;
|
|
134
|
+
/** Enrich agents with kind:0 metadata (name, picture, about). Mutates in place and returns the same array. */
|
|
135
|
+
enrichWithMetadata(agents: Agent[]): Promise<Agent[]>;
|
|
136
|
+
/** Fetch elisym agents filtered by network. */
|
|
137
|
+
fetchAgents(network?: Network, limit?: number): Promise<Agent[]>;
|
|
138
|
+
/** Publish a capability card (kind:31990) as a provider. */
|
|
139
|
+
publishCapability(identity: ElisymIdentity, card: CapabilityCard, kinds?: number[]): Promise<string>;
|
|
140
|
+
/** Publish a Nostr profile (kind:0) as a provider. */
|
|
141
|
+
publishProfile(identity: ElisymIdentity, name: string, about: string, picture?: string): Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Delete a capability by publishing a tombstone replacement.
|
|
144
|
+
* Since kind:31990 is a parameterized replaceable event,
|
|
145
|
+
* publishing a new event with the same `d` tag and `"deleted":true`
|
|
146
|
+
* content replaces the old one on all relays.
|
|
147
|
+
*/
|
|
148
|
+
deleteCapability(identity: ElisymIdentity, capabilityName: string): Promise<string>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface SubmitJobOptions {
|
|
152
|
+
input: string;
|
|
153
|
+
capability: string;
|
|
154
|
+
providerPubkey?: string;
|
|
155
|
+
/** Kind offset (default 100 → kind 5100). */
|
|
156
|
+
kindOffset?: number;
|
|
157
|
+
}
|
|
158
|
+
interface JobUpdateCallbacks {
|
|
159
|
+
onFeedback?: (status: string, amount?: number, paymentRequest?: string) => void;
|
|
160
|
+
onResult?: (content: string, eventId: string) => void;
|
|
161
|
+
onError?: (error: string) => void;
|
|
162
|
+
}
|
|
163
|
+
declare class MarketplaceService {
|
|
164
|
+
private pool;
|
|
165
|
+
constructor(pool: NostrPool);
|
|
166
|
+
/** Submit a job request with NIP-44 encrypted input. Returns the event ID. */
|
|
167
|
+
submitJobRequest(identity: ElisymIdentity, options: SubmitJobOptions): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Subscribe to job updates (feedback + results) for a given job.
|
|
170
|
+
* Returns a cleanup function.
|
|
171
|
+
*/
|
|
172
|
+
subscribeToJobUpdates(jobEventId: string, providerPubkey: string | undefined, customerPublicKey: string, callbacks: JobUpdateCallbacks, timeoutMs?: number, customerSecretKey?: Uint8Array,
|
|
173
|
+
/** Kind offsets to listen for (default [100]). */
|
|
174
|
+
kindOffsets?: number[]): () => void;
|
|
175
|
+
/** Submit payment confirmation feedback. */
|
|
176
|
+
submitPaymentConfirmation(identity: ElisymIdentity, jobEventId: string, providerPubkey: string, txSignature: string): Promise<void>;
|
|
177
|
+
/** Submit rating feedback for a job. */
|
|
178
|
+
submitFeedback(identity: ElisymIdentity, jobEventId: string, providerPubkey: string, positive: boolean, capability?: string): Promise<void>;
|
|
179
|
+
/** Subscribe to incoming job requests for specific kinds. */
|
|
180
|
+
subscribeToJobRequests(identity: ElisymIdentity, kinds: number[], onRequest: (event: Event) => void): SubCloser;
|
|
181
|
+
/** Submit a job result with NIP-44 encrypted content. Result kind is derived from the request kind. */
|
|
182
|
+
submitJobResult(identity: ElisymIdentity, requestEvent: Event, content: string, amount?: number): Promise<string>;
|
|
183
|
+
/** Submit payment-required feedback with a payment request. */
|
|
184
|
+
submitPaymentRequiredFeedback(identity: ElisymIdentity, requestEvent: Event, amount: number, paymentRequestJson: string): Promise<void>;
|
|
185
|
+
/** Fetch recent jobs from the network. */
|
|
186
|
+
fetchRecentJobs(agentPubkeys?: Set<string>, limit?: number, since?: number,
|
|
187
|
+
/** Kind offsets to query (default [100]). */
|
|
188
|
+
kindOffsets?: number[]): Promise<Job[]>;
|
|
189
|
+
/** Subscribe to live elisym events (requests, results, feedback). */
|
|
190
|
+
subscribeToEvents(kinds: number[], onEvent: (event: Event) => void): SubCloser;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
declare class MessagingService {
|
|
194
|
+
private pool;
|
|
195
|
+
private sessionIdentity;
|
|
196
|
+
private pingCache;
|
|
197
|
+
private pendingPings;
|
|
198
|
+
private static PING_CACHE_TTL;
|
|
199
|
+
constructor(pool: NostrPool);
|
|
200
|
+
/**
|
|
201
|
+
* Ping an agent via ephemeral Nostr events (kind 20200/20201).
|
|
202
|
+
* Uses a persistent session identity to avoid relay rate-limiting.
|
|
203
|
+
* Publishes to ALL relays for maximum delivery reliability.
|
|
204
|
+
* Caches results for 30s to prevent redundant publishes.
|
|
205
|
+
*/
|
|
206
|
+
pingAgent(agentPubkey: string, timeoutMs?: number, signal?: AbortSignal): Promise<PingResult>;
|
|
207
|
+
private _doPing;
|
|
208
|
+
/**
|
|
209
|
+
* Subscribe to incoming ephemeral ping events (kind 20200).
|
|
210
|
+
* No `since` filter needed - ephemeral events are never stored.
|
|
211
|
+
*/
|
|
212
|
+
subscribeToPings(identity: ElisymIdentity, onPing: (senderPubkey: string, nonce: string) => void): SubCloser;
|
|
213
|
+
/** Send an ephemeral pong response to ALL relays. */
|
|
214
|
+
sendPong(identity: ElisymIdentity, recipientPubkey: string, nonce: string): Promise<void>;
|
|
215
|
+
/** Send a NIP-17 DM. */
|
|
216
|
+
sendMessage(identity: ElisymIdentity, recipientPubkey: string, content: string): Promise<void>;
|
|
217
|
+
/** Fetch historical NIP-17 DMs from relays. Returns decrypted messages sorted by time. */
|
|
218
|
+
fetchMessageHistory(identity: ElisymIdentity, since: number): Promise<{
|
|
219
|
+
senderPubkey: string;
|
|
220
|
+
content: string;
|
|
221
|
+
createdAt: number;
|
|
222
|
+
rumorId: string;
|
|
223
|
+
}[]>;
|
|
224
|
+
/** Subscribe to incoming NIP-17 DMs. */
|
|
225
|
+
subscribeToMessages(identity: ElisymIdentity, onMessage: (senderPubkey: string, content: string, createdAt: number, rumorId: string) => void, since?: number): SubCloser;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
declare class PaymentService {
|
|
229
|
+
/**
|
|
230
|
+
* Calculate protocol fee using Decimal basis-point math (no floats).
|
|
231
|
+
* Returns ceil(amount * PROTOCOL_FEE_BPS / 10000).
|
|
232
|
+
*/
|
|
233
|
+
static calculateProtocolFee(amount: number): number;
|
|
234
|
+
/**
|
|
235
|
+
* Validate that a payment request has the correct recipient and protocol fee.
|
|
236
|
+
* Returns an error message if invalid, null if OK.
|
|
237
|
+
*/
|
|
238
|
+
static validatePaymentFee(requestJson: string, expectedRecipient?: string): string | null;
|
|
239
|
+
/**
|
|
240
|
+
* Build a Solana transaction from a payment request.
|
|
241
|
+
* The caller must sign and send via wallet adapter.
|
|
242
|
+
*/
|
|
243
|
+
static buildPaymentTransaction(payerPubkey: PublicKey, paymentRequest: PaymentRequestData): Transaction;
|
|
244
|
+
/**
|
|
245
|
+
* Create a payment request with auto-calculated protocol fee.
|
|
246
|
+
* Used by providers to generate payment requests for customers.
|
|
247
|
+
*/
|
|
248
|
+
static createPaymentRequest(recipientAddress: string, amount: number, expirySecs?: number): PaymentRequestData;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
declare function formatSol(lamports: number): string;
|
|
252
|
+
declare function timeAgo(unix: number): string;
|
|
253
|
+
declare function truncateKey(hex: string, chars?: number): string;
|
|
254
|
+
|
|
255
|
+
declare function makeNjumpUrl(eventId: string, relays?: string[]): string;
|
|
256
|
+
|
|
257
|
+
declare const RELAYS: string[];
|
|
258
|
+
declare const KIND_APP_HANDLER = 31990;
|
|
259
|
+
declare const KIND_JOB_REQUEST_BASE = 5000;
|
|
260
|
+
declare const KIND_JOB_RESULT_BASE = 6000;
|
|
261
|
+
declare const KIND_JOB_FEEDBACK = 7000;
|
|
262
|
+
declare const DEFAULT_KIND_OFFSET = 100;
|
|
263
|
+
declare const KIND_GIFT_WRAP = 1059;
|
|
264
|
+
/** Default job request kind (5000 + 100). */
|
|
265
|
+
declare const KIND_JOB_REQUEST: number;
|
|
266
|
+
/** Default job result kind (6000 + 100). */
|
|
267
|
+
declare const KIND_JOB_RESULT: number;
|
|
268
|
+
/** Compute a job request kind from an offset (5000 + offset). */
|
|
269
|
+
declare function jobRequestKind(offset: number): number;
|
|
270
|
+
/** Compute a job result kind from an offset (6000 + offset). */
|
|
271
|
+
declare function jobResultKind(offset: number): number;
|
|
272
|
+
/** Ephemeral ping/pong kinds (not stored by relays, forwarded in real-time). */
|
|
273
|
+
declare const KIND_PING = 20200;
|
|
274
|
+
declare const KIND_PONG = 20201;
|
|
275
|
+
declare const LAMPORTS_PER_SOL = 1000000000;
|
|
276
|
+
/** Protocol fee in basis points (300 = 3%). */
|
|
277
|
+
declare const PROTOCOL_FEE_BPS = 300;
|
|
278
|
+
/** Solana address of the protocol treasury. */
|
|
279
|
+
declare const PROTOCOL_TREASURY = "GY7vnWMkKpftU4nQ16C2ATkj1JwrQpHhknkaBUn67VTy";
|
|
280
|
+
|
|
281
|
+
declare class ElisymClient {
|
|
282
|
+
readonly pool: NostrPool;
|
|
283
|
+
readonly discovery: DiscoveryService;
|
|
284
|
+
readonly marketplace: MarketplaceService;
|
|
285
|
+
readonly messaging: MessagingService;
|
|
286
|
+
constructor(config?: ElisymClientConfig);
|
|
287
|
+
close(): void;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { type Agent, type CapabilityCard, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, type ElisymClientConfig, ElisymIdentity, type Job, type JobStatus, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_GIFT_WRAP, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, MarketplaceService, MessagingService, type Network, type NetworkStats, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_TREASURY, type PaymentInfo, type PaymentRequestData, PaymentService, type PingResult, RELAYS, type SubCloser, type SubmitJobOptions, formatSol, jobRequestKind, jobResultKind, makeNjumpUrl, timeAgo, toDTag, truncateKey };
|