@toon-protocol/core 2.0.0 → 2.1.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.ts CHANGED
@@ -1946,7 +1946,13 @@ interface GenesisPeer {
1946
1946
  ilpAddress: string;
1947
1947
  btpEndpoint: string;
1948
1948
  }
1949
- /** Load and validate genesis peers from the bundled JSON file. */
1949
+ /**
1950
+ * Load and validate genesis peers from the bundled JSON file.
1951
+ *
1952
+ * The `TOON_GENESIS_PEERS` environment variable, when set, REPLACES the
1953
+ * bundled seed entirely (same JSON array format). Set it to `[]` to disable
1954
+ * bundled genesis peers — e.g. for private networks or hermetic tests.
1955
+ */
1950
1956
  declare function loadGenesisPeers(): GenesisPeer[];
1951
1957
  /** Parse and validate additional peers from a JSON string. */
1952
1958
  declare function loadAdditionalPeers(json: string): GenesisPeer[];
@@ -2332,6 +2338,12 @@ interface IlpClient {
2332
2338
  amount: string;
2333
2339
  data: string;
2334
2340
  timeout?: number;
2341
+ /**
2342
+ * Per-packet expiry as an ISO 8601 string. When set, the transport
2343
+ * MUST use exactly this expiry for the outgoing PREPARE. When absent,
2344
+ * the transport applies its default (timeout-derived).
2345
+ */
2346
+ expiresAt?: string;
2335
2347
  }): Promise<IlpSendResult>;
2336
2348
  /**
2337
2349
  * Optional: Send ILP packet with signed balance proof claim (BTP only).
@@ -2342,6 +2354,8 @@ interface IlpClient {
2342
2354
  amount: string;
2343
2355
  data: string;
2344
2356
  timeout?: number;
2357
+ /** Per-packet expiry as an ISO 8601 string (see sendIlpPacket). */
2358
+ expiresAt?: string;
2345
2359
  }, claim: unknown): Promise<IlpSendResult>;
2346
2360
  }
2347
2361
  /**
@@ -4098,7 +4112,12 @@ interface BuildIlpPrepareParams {
4098
4112
  amount: bigint;
4099
4113
  /** TOON-encoded event as raw bytes. */
4100
4114
  data: Uint8Array;
4101
- /** Packet expiry. Default: 30 seconds from now. */
4115
+ /**
4116
+ * Per-packet expiry. When provided, it is propagated onto the produced
4117
+ * PREPARE (as an ISO 8601 string) so the transport sets exactly this
4118
+ * expiry on the wire. When omitted, the transport applies its own
4119
+ * default (typically derived from the request timeout, ~30s).
4120
+ */
4102
4121
  expiresAt?: Date;
4103
4122
  }
4104
4123
  /**
@@ -4115,12 +4134,20 @@ interface IlpPreparePacket {
4115
4134
  amount: string;
4116
4135
  /** TOON-encoded event as base64 string. */
4117
4136
  data: string;
4137
+ /**
4138
+ * Packet expiry as an ISO 8601 string. Present only when the caller
4139
+ * supplied `expiresAt`; absent means the transport picks its default
4140
+ * (timeout-derived). Matches the connector's `POST /admin/ilp/send`
4141
+ * request field.
4142
+ */
4143
+ expiresAt?: string;
4118
4144
  }
4119
4145
  /**
4120
4146
  * Build an ILP PREPARE packet from the given parameters.
4121
4147
  *
4122
4148
  * Converts the bigint amount to a string, encodes the TOON data to base64,
4123
- * and passes through the destination. This is deliberately simple -- the
4149
+ * passes through the destination, and when supplied serializes the
4150
+ * per-packet expiry to ISO 8601. This is deliberately simple -- the
4124
4151
  * value is in having ONE function both the x402 and ILP paths call, not
4125
4152
  * in complex logic.
4126
4153
  *
package/dist/index.js CHANGED
@@ -2234,10 +2234,10 @@ var NostrPeerDiscovery = class {
2234
2234
  // src/discovery/genesis-peers.json
2235
2235
  var genesis_peers_default = [
2236
2236
  {
2237
- pubkey: "522e93098bf650f141a07f0ecfc1ace0f5d0397932afc01826e9ef46888b7bce",
2237
+ pubkey: "2813187eb66741f9509de2055161f328a0f04e01e1fc20188610b8dbd0591ea5",
2238
2238
  relayUrl: "wss://relay-ws.devnet.toonprotocol.dev",
2239
- ilpAddress: "g.proxy.relay.store",
2240
- btpEndpoint: "wss://proxy.store.devnet.toonprotocol.dev:443"
2239
+ ilpAddress: "g.proxy",
2240
+ btpEndpoint: "wss://proxy.devnet.toonprotocol.dev:443"
2241
2241
  }
2242
2242
  ];
2243
2243
 
@@ -2269,6 +2269,29 @@ function deduplicateByPubkey(peers) {
2269
2269
  return [...map.values()];
2270
2270
  }
2271
2271
  function loadGenesisPeers() {
2272
+ const envOverride = process.env["TOON_GENESIS_PEERS"];
2273
+ if (envOverride !== void 0) {
2274
+ let parsed;
2275
+ try {
2276
+ parsed = JSON.parse(envOverride);
2277
+ } catch {
2278
+ console.warn("Failed to parse TOON_GENESIS_PEERS JSON:", envOverride);
2279
+ return [];
2280
+ }
2281
+ if (!Array.isArray(parsed)) {
2282
+ console.warn("TOON_GENESIS_PEERS JSON is not an array");
2283
+ return [];
2284
+ }
2285
+ const valid2 = [];
2286
+ for (const entry of parsed) {
2287
+ if (isValidGenesisPeer(entry)) {
2288
+ valid2.push(entry);
2289
+ } else {
2290
+ console.warn("Skipping invalid TOON_GENESIS_PEERS entry:", entry);
2291
+ }
2292
+ }
2293
+ return deduplicateByPubkey(valid2);
2294
+ }
2272
2295
  const raw = genesis_peers_default;
2273
2296
  const valid = [];
2274
2297
  for (const entry of raw) {
@@ -4004,7 +4027,10 @@ function createHttpIlpClient(baseUrl) {
4004
4027
  destination: params.destination,
4005
4028
  amount: params.amount,
4006
4029
  data: params.data,
4007
- ...params.timeout !== void 0 && { timeout: params.timeout }
4030
+ ...params.timeout !== void 0 && { timeout: params.timeout },
4031
+ ...params.expiresAt !== void 0 && {
4032
+ expiresAt: params.expiresAt
4033
+ }
4008
4034
  })
4009
4035
  });
4010
4036
  } catch (error) {
@@ -4039,11 +4065,17 @@ function createDirectIlpClient(connector, _config) {
4039
4065
  try {
4040
4066
  const amount = BigInt(params.amount);
4041
4067
  const data = Uint8Array.from(Buffer.from(params.data, "base64"));
4068
+ const expiresAt = params.expiresAt ? new Date(params.expiresAt) : new Date(Date.now() + 3e4);
4069
+ if (Number.isNaN(expiresAt.getTime())) {
4070
+ throw new BootstrapError(
4071
+ `Invalid expiresAt: ${params.expiresAt} is not a parseable date`
4072
+ );
4073
+ }
4042
4074
  const result = await connector.sendPacket({
4043
4075
  destination: params.destination,
4044
4076
  amount,
4045
4077
  data,
4046
- expiresAt: new Date(Date.now() + 3e4)
4078
+ expiresAt
4047
4079
  });
4048
4080
  if (result.type === "fulfill" || result.type === 13) {
4049
4081
  return {
@@ -4210,7 +4242,10 @@ function createHttpIlpClient2(connectorUrl) {
4210
4242
  body: JSON.stringify({
4211
4243
  destination: params.destination,
4212
4244
  amount: params.amount,
4213
- data: params.data
4245
+ data: params.data,
4246
+ ...params.expiresAt !== void 0 && {
4247
+ expiresAt: params.expiresAt
4248
+ }
4214
4249
  }),
4215
4250
  signal: params.timeout ? AbortSignal.timeout(params.timeout) : void 0
4216
4251
  });
@@ -4974,7 +5009,10 @@ function buildIlpPrepare(params) {
4974
5009
  return {
4975
5010
  destination: params.destination,
4976
5011
  amount: String(params.amount),
4977
- data: Buffer.from(params.data).toString("base64")
5012
+ data: Buffer.from(params.data).toString("base64"),
5013
+ ...params.expiresAt !== void 0 && {
5014
+ expiresAt: params.expiresAt.toISOString()
5015
+ }
4978
5016
  };
4979
5017
  }
4980
5018