@elisym/sdk 0.4.0 → 0.5.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/dist/index.d.cts CHANGED
@@ -1,8 +1,144 @@
1
1
  import { Address, TransactionSigner, Rpc, SolanaRpcApi } from '@solana/kit';
2
- import { P as PaymentRequestData, a as PaymentValidationError, V as VerifyOptions, b as VerifyResult, S as SubCloser, N as Network, A as Agent, E as ElisymIdentity, C as CapabilityCard, c as SubmitJobOptions, J as JobSubscriptionOptions, d as Job, e as PingResult, f as ElisymClientConfig, g as AgentConfig } from './types-CII4k_8d.cjs';
3
- export { h as Capability, I as Identity, i as JobStatus, j as JobUpdateCallbacks, L as LlmConfig, k as NetworkStats, l as PaymentAddress, m as PaymentInfo, n as PaymentValidationCode, W as WalletConfig } from './types-CII4k_8d.cjs';
4
2
  import { Filter, Event } from 'nostr-tools';
5
3
 
4
+ declare class ElisymIdentity {
5
+ private _secretKey;
6
+ readonly publicKey: string;
7
+ readonly npub: string;
8
+ get secretKey(): Uint8Array;
9
+ private constructor();
10
+ static generate(): ElisymIdentity;
11
+ static fromSecretKey(sk: Uint8Array): ElisymIdentity;
12
+ toJSON(): {
13
+ publicKey: string;
14
+ npub: string;
15
+ };
16
+ /** Best-effort scrub of the secret key bytes in memory. */
17
+ scrub(): void;
18
+ static fromHex(hex: string): ElisymIdentity;
19
+ }
20
+
21
+ interface SubCloser {
22
+ close: (reason?: string) => void;
23
+ }
24
+ /** Capability card published to Nostr (NIP-89). */
25
+ interface CapabilityCard {
26
+ name: string;
27
+ description: string;
28
+ capabilities: string[];
29
+ payment?: PaymentInfo;
30
+ image?: string;
31
+ static?: boolean;
32
+ }
33
+ /** Payment info embedded in capability card (legacy format for on-network events). */
34
+ interface PaymentInfo {
35
+ chain: string;
36
+ network: string;
37
+ address: string;
38
+ /** Price in lamports (must be non-negative integer). */
39
+ job_price?: number;
40
+ }
41
+ /** Agent discovered from the network. */
42
+ interface Agent {
43
+ pubkey: string;
44
+ npub: string;
45
+ cards: CapabilityCard[];
46
+ eventId: string;
47
+ supportedKinds: number[];
48
+ lastSeen: number;
49
+ picture?: string;
50
+ name?: string;
51
+ about?: string;
52
+ }
53
+ type Network = 'mainnet' | 'devnet';
54
+ /**
55
+ * Job lifecycle status.
56
+ * Note: for broadcast jobs (no providerPubkey, no bid), fetchRecentJobs() keeps
57
+ * status as 'processing' even if a provider sent 'payment-required' feedback,
58
+ * because the customer hasn't committed to that provider yet. The real-time
59
+ * payment-required transition is handled by subscribeToJobUpdates().
60
+ */
61
+ type JobStatus = 'payment-required' | 'payment-completed' | 'processing' | 'error' | 'success' | 'partial' | 'unknown';
62
+ interface Job {
63
+ eventId: string;
64
+ customer: string;
65
+ agentPubkey?: string;
66
+ capability?: string;
67
+ bid?: number;
68
+ status: JobStatus;
69
+ result?: string;
70
+ resultEventId?: string;
71
+ amount?: number;
72
+ txHash?: string;
73
+ createdAt: number;
74
+ }
75
+ interface SubmitJobOptions {
76
+ /** Job input text. Sent unencrypted if providerPubkey is not set. */
77
+ input: string;
78
+ capability: string;
79
+ /** Target provider pubkey. If omitted, job is broadcast unencrypted and visible to all relays. */
80
+ providerPubkey?: string;
81
+ /** Kind offset (default 100 - kind 5100). */
82
+ kindOffset?: number;
83
+ }
84
+ interface JobUpdateCallbacks {
85
+ onFeedback?: (status: string, amount?: number, paymentRequest?: string, senderPubkey?: string) => void;
86
+ onResult?: (content: string, eventId: string) => void;
87
+ onError?: (error: string) => void;
88
+ }
89
+ interface JobSubscriptionOptions {
90
+ jobEventId: string;
91
+ providerPubkey?: string;
92
+ customerPublicKey: string;
93
+ callbacks: JobUpdateCallbacks;
94
+ timeoutMs?: number;
95
+ customerSecretKey?: Uint8Array;
96
+ kindOffsets?: number[];
97
+ sinceOverride?: number;
98
+ }
99
+ interface PingResult {
100
+ online: boolean;
101
+ /** The identity used for the ping session - reuse for job submission so pubkeys match. */
102
+ identity: ElisymIdentity | null;
103
+ }
104
+ interface PaymentRequestData {
105
+ recipient: string;
106
+ /** Total amount in lamports (must be positive integer). */
107
+ amount: number;
108
+ reference: string;
109
+ description?: string;
110
+ fee_address?: string;
111
+ fee_amount?: number;
112
+ /** Creation timestamp (Unix seconds). */
113
+ created_at: number;
114
+ /** Expiry duration in seconds. */
115
+ expiry_secs: number;
116
+ }
117
+ interface VerifyResult {
118
+ verified: boolean;
119
+ txSignature?: string;
120
+ error?: string;
121
+ }
122
+ interface VerifyOptions {
123
+ retries?: number;
124
+ intervalMs?: number;
125
+ txSignature?: string;
126
+ }
127
+ type PaymentValidationCode = 'invalid_json' | 'invalid_amount' | 'missing_recipient' | 'invalid_recipient_address' | 'missing_reference' | 'invalid_reference_address' | 'recipient_mismatch' | 'expired' | 'future_timestamp' | 'fee_address_mismatch' | 'fee_amount_mismatch' | 'missing_fee' | 'invalid_fee_params';
128
+ interface PaymentValidationError {
129
+ code: PaymentValidationCode;
130
+ message: string;
131
+ }
132
+ interface NetworkStats {
133
+ totalAgentCount: number;
134
+ agentCount: number;
135
+ jobCount: number;
136
+ totalLamports: number;
137
+ }
138
+ interface ElisymClientConfig {
139
+ relays?: string[];
140
+ }
141
+
6
142
  /**
7
143
  * Protocol fee + treasury inputs for building a payment request.
8
144
  *
@@ -386,14 +522,10 @@ declare function timeAgo(unix: number): string;
386
522
  declare function truncateKey(hex: string, chars?: number): string;
387
523
 
388
524
  /**
389
- * Shared agent config - validation and serialization.
525
+ * Agent-name validation shared between CLI and MCP.
390
526
  * Browser-safe - no Node.js imports.
391
- * parseConfig lives in config-node.ts (exported from @elisym/sdk/node).
392
527
  */
393
-
394
528
  declare function validateAgentName(name: string): void;
395
- /** Serialize an AgentConfig to JSON string. */
396
- declare function serializeConfig(config: AgentConfig): string;
397
529
 
398
530
  /** A Set that evicts the oldest entries when it exceeds maxSize. Uses a ring buffer for O(1) eviction. */
399
531
  declare class BoundedSet<T> {
@@ -482,4 +614,4 @@ declare const LIMITS: {
482
614
  readonly MAX_CAPABILITY_LENGTH: 64;
483
615
  };
484
616
 
485
- export { Agent, AgentConfig, BoundedSet, CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type GetProtocolConfigOptions, Job, JobSubscriptionOptions, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, Network, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, PaymentRequestData, type PaymentStrategy, PaymentValidationError, PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, RELAYS, SolanaPaymentStrategy, SubCloser, SubmitJobOptions, VerifyOptions, VerifyResult, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearProtocolConfigCache, createPaymentRequestWithOnchainConfig, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
617
+ export { type Agent, BoundedSet, type CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, type ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type GetProtocolConfigOptions, type Job, type JobStatus, type JobSubscriptionOptions, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, type Network, type NetworkStats, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, type PaymentInfo, type PaymentRequestData, type PaymentStrategy, type PaymentValidationCode, type PaymentValidationError, type PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, RELAYS, SolanaPaymentStrategy, type SubCloser, type SubmitJobOptions, type VerifyOptions, type VerifyResult, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearProtocolConfigCache, createPaymentRequestWithOnchainConfig, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,144 @@
1
1
  import { Address, TransactionSigner, Rpc, SolanaRpcApi } from '@solana/kit';
2
- import { P as PaymentRequestData, a as PaymentValidationError, V as VerifyOptions, b as VerifyResult, S as SubCloser, N as Network, A as Agent, E as ElisymIdentity, C as CapabilityCard, c as SubmitJobOptions, J as JobSubscriptionOptions, d as Job, e as PingResult, f as ElisymClientConfig, g as AgentConfig } from './types-CII4k_8d.js';
3
- export { h as Capability, I as Identity, i as JobStatus, j as JobUpdateCallbacks, L as LlmConfig, k as NetworkStats, l as PaymentAddress, m as PaymentInfo, n as PaymentValidationCode, W as WalletConfig } from './types-CII4k_8d.js';
4
2
  import { Filter, Event } from 'nostr-tools';
5
3
 
4
+ declare class ElisymIdentity {
5
+ private _secretKey;
6
+ readonly publicKey: string;
7
+ readonly npub: string;
8
+ get secretKey(): Uint8Array;
9
+ private constructor();
10
+ static generate(): ElisymIdentity;
11
+ static fromSecretKey(sk: Uint8Array): ElisymIdentity;
12
+ toJSON(): {
13
+ publicKey: string;
14
+ npub: string;
15
+ };
16
+ /** Best-effort scrub of the secret key bytes in memory. */
17
+ scrub(): void;
18
+ static fromHex(hex: string): ElisymIdentity;
19
+ }
20
+
21
+ interface SubCloser {
22
+ close: (reason?: string) => void;
23
+ }
24
+ /** Capability card published to Nostr (NIP-89). */
25
+ interface CapabilityCard {
26
+ name: string;
27
+ description: string;
28
+ capabilities: string[];
29
+ payment?: PaymentInfo;
30
+ image?: string;
31
+ static?: boolean;
32
+ }
33
+ /** Payment info embedded in capability card (legacy format for on-network events). */
34
+ interface PaymentInfo {
35
+ chain: string;
36
+ network: string;
37
+ address: string;
38
+ /** Price in lamports (must be non-negative integer). */
39
+ job_price?: number;
40
+ }
41
+ /** Agent discovered from the network. */
42
+ interface Agent {
43
+ pubkey: string;
44
+ npub: string;
45
+ cards: CapabilityCard[];
46
+ eventId: string;
47
+ supportedKinds: number[];
48
+ lastSeen: number;
49
+ picture?: string;
50
+ name?: string;
51
+ about?: string;
52
+ }
53
+ type Network = 'mainnet' | 'devnet';
54
+ /**
55
+ * Job lifecycle status.
56
+ * Note: for broadcast jobs (no providerPubkey, no bid), fetchRecentJobs() keeps
57
+ * status as 'processing' even if a provider sent 'payment-required' feedback,
58
+ * because the customer hasn't committed to that provider yet. The real-time
59
+ * payment-required transition is handled by subscribeToJobUpdates().
60
+ */
61
+ type JobStatus = 'payment-required' | 'payment-completed' | 'processing' | 'error' | 'success' | 'partial' | 'unknown';
62
+ interface Job {
63
+ eventId: string;
64
+ customer: string;
65
+ agentPubkey?: string;
66
+ capability?: string;
67
+ bid?: number;
68
+ status: JobStatus;
69
+ result?: string;
70
+ resultEventId?: string;
71
+ amount?: number;
72
+ txHash?: string;
73
+ createdAt: number;
74
+ }
75
+ interface SubmitJobOptions {
76
+ /** Job input text. Sent unencrypted if providerPubkey is not set. */
77
+ input: string;
78
+ capability: string;
79
+ /** Target provider pubkey. If omitted, job is broadcast unencrypted and visible to all relays. */
80
+ providerPubkey?: string;
81
+ /** Kind offset (default 100 - kind 5100). */
82
+ kindOffset?: number;
83
+ }
84
+ interface JobUpdateCallbacks {
85
+ onFeedback?: (status: string, amount?: number, paymentRequest?: string, senderPubkey?: string) => void;
86
+ onResult?: (content: string, eventId: string) => void;
87
+ onError?: (error: string) => void;
88
+ }
89
+ interface JobSubscriptionOptions {
90
+ jobEventId: string;
91
+ providerPubkey?: string;
92
+ customerPublicKey: string;
93
+ callbacks: JobUpdateCallbacks;
94
+ timeoutMs?: number;
95
+ customerSecretKey?: Uint8Array;
96
+ kindOffsets?: number[];
97
+ sinceOverride?: number;
98
+ }
99
+ interface PingResult {
100
+ online: boolean;
101
+ /** The identity used for the ping session - reuse for job submission so pubkeys match. */
102
+ identity: ElisymIdentity | null;
103
+ }
104
+ interface PaymentRequestData {
105
+ recipient: string;
106
+ /** Total amount in lamports (must be positive integer). */
107
+ amount: number;
108
+ reference: string;
109
+ description?: string;
110
+ fee_address?: string;
111
+ fee_amount?: number;
112
+ /** Creation timestamp (Unix seconds). */
113
+ created_at: number;
114
+ /** Expiry duration in seconds. */
115
+ expiry_secs: number;
116
+ }
117
+ interface VerifyResult {
118
+ verified: boolean;
119
+ txSignature?: string;
120
+ error?: string;
121
+ }
122
+ interface VerifyOptions {
123
+ retries?: number;
124
+ intervalMs?: number;
125
+ txSignature?: string;
126
+ }
127
+ type PaymentValidationCode = 'invalid_json' | 'invalid_amount' | 'missing_recipient' | 'invalid_recipient_address' | 'missing_reference' | 'invalid_reference_address' | 'recipient_mismatch' | 'expired' | 'future_timestamp' | 'fee_address_mismatch' | 'fee_amount_mismatch' | 'missing_fee' | 'invalid_fee_params';
128
+ interface PaymentValidationError {
129
+ code: PaymentValidationCode;
130
+ message: string;
131
+ }
132
+ interface NetworkStats {
133
+ totalAgentCount: number;
134
+ agentCount: number;
135
+ jobCount: number;
136
+ totalLamports: number;
137
+ }
138
+ interface ElisymClientConfig {
139
+ relays?: string[];
140
+ }
141
+
6
142
  /**
7
143
  * Protocol fee + treasury inputs for building a payment request.
8
144
  *
@@ -386,14 +522,10 @@ declare function timeAgo(unix: number): string;
386
522
  declare function truncateKey(hex: string, chars?: number): string;
387
523
 
388
524
  /**
389
- * Shared agent config - validation and serialization.
525
+ * Agent-name validation shared between CLI and MCP.
390
526
  * Browser-safe - no Node.js imports.
391
- * parseConfig lives in config-node.ts (exported from @elisym/sdk/node).
392
527
  */
393
-
394
528
  declare function validateAgentName(name: string): void;
395
- /** Serialize an AgentConfig to JSON string. */
396
- declare function serializeConfig(config: AgentConfig): string;
397
529
 
398
530
  /** A Set that evicts the oldest entries when it exceeds maxSize. Uses a ring buffer for O(1) eviction. */
399
531
  declare class BoundedSet<T> {
@@ -482,4 +614,4 @@ declare const LIMITS: {
482
614
  readonly MAX_CAPABILITY_LENGTH: 64;
483
615
  };
484
616
 
485
- export { Agent, AgentConfig, BoundedSet, CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type GetProtocolConfigOptions, Job, JobSubscriptionOptions, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, Network, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, PaymentRequestData, type PaymentStrategy, PaymentValidationError, PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, RELAYS, SolanaPaymentStrategy, SubCloser, SubmitJobOptions, VerifyOptions, VerifyResult, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearProtocolConfigCache, createPaymentRequestWithOnchainConfig, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
617
+ export { type Agent, BoundedSet, type CapabilityCard, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, type ElisymClientConfig, type ElisymClientFullConfig, ElisymIdentity, type GetProtocolConfigOptions, type Job, type JobStatus, type JobSubscriptionOptions, type JobUpdateCallbacks, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, type Network, type NetworkStats, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, type PaymentInfo, type PaymentRequestData, type PaymentStrategy, type PaymentValidationCode, type PaymentValidationError, type PingResult, PingService, type ProtocolCluster, type ProtocolConfig, type ProtocolConfigInput, RELAYS, SolanaPaymentStrategy, type SubCloser, type SubmitJobOptions, type VerifyOptions, type VerifyResult, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearProtocolConfigCache, createPaymentRequestWithOnchainConfig, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
package/dist/index.js CHANGED
@@ -292,6 +292,9 @@ var SolanaPaymentStrategy = class {
292
292
  }
293
293
  const expectedFee = calculateProtocolFee(data.amount, config.feeBps);
294
294
  const treasury = config.treasury;
295
+ if (expectedFee === 0) {
296
+ return null;
297
+ }
295
298
  const { fee_address, fee_amount } = data;
296
299
  const hasFeeAddress = typeof fee_address === "string" && fee_address.length > 0;
297
300
  const hasFeeAmount = typeof fee_amount === "number" && fee_amount > 0;
@@ -2267,10 +2270,7 @@ function validateAgentName(name) {
2267
2270
  throw new Error("Agent name must be 1-64 characters, alphanumeric, underscore, or hyphen.");
2268
2271
  }
2269
2272
  }
2270
- function serializeConfig(config) {
2271
- return JSON.stringify(config, null, 2) + "\n";
2272
- }
2273
2273
 
2274
- export { BoundedSet, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymIdentity, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, PingService, RELAYS, SolanaPaymentStrategy, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearProtocolConfigCache, createPaymentRequestWithOnchainConfig, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, serializeConfig, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
2274
+ export { BoundedSet, DEFAULTS, DEFAULT_KIND_OFFSET, DiscoveryService, ElisymClient, ElisymIdentity, KIND_APP_HANDLER, KIND_JOB_FEEDBACK, KIND_JOB_REQUEST, KIND_JOB_REQUEST_BASE, KIND_JOB_RESULT, KIND_JOB_RESULT_BASE, KIND_PING, KIND_PONG, LAMPORTS_PER_SOL, LIMITS, MarketplaceService, MediaService, NostrPool, PROTOCOL_FEE_BPS, PROTOCOL_PROGRAM_ID_DEVNET, PROTOCOL_TREASURY, PingService, RELAYS, SolanaPaymentStrategy, assertExpiry, assertLamports, buildPaymentInstructions, calculateProtocolFee, clearProtocolConfigCache, createPaymentRequestWithOnchainConfig, formatSol, getProtocolConfig, getProtocolProgramId, jobRequestKind, jobResultKind, nip44Decrypt, nip44Encrypt, timeAgo, toDTag, truncateKey, validateAgentName, validateExpiry };
2275
2275
  //# sourceMappingURL=index.js.map
2276
2276
  //# sourceMappingURL=index.js.map