@toon-protocol/client 0.9.2 → 0.10.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 +357 -100
- package/dist/index.js +345 -70
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _toon_protocol_core from '@toon-protocol/core';
|
|
2
2
|
import { IlpPeerInfo, NetworkFamilyStatus, IlpSendResult, IlpClient, ConnectorAdminClient, ConnectorChannelClient, OpenChannelParams, OpenChannelResult, ChannelState } from '@toon-protocol/core';
|
|
3
|
-
import { NostrEvent } from 'nostr-tools/pure';
|
|
3
|
+
import { NostrEvent, EventTemplate } from 'nostr-tools/pure';
|
|
4
4
|
import { PrivateKeyAccount } from 'viem/accounts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -199,6 +199,27 @@ interface ToonClientConfig {
|
|
|
199
199
|
btpAuthToken?: string;
|
|
200
200
|
/** Peer ID for BTP connection (used in connector env var BTP_PEER_{ID}_SECRET) */
|
|
201
201
|
btpPeerId?: string;
|
|
202
|
+
/**
|
|
203
|
+
* ILP-over-HTTP one-shot endpoint of the uplink connector (the `POST /ilp`
|
|
204
|
+
* URL, e.g. "http://localhost:3000/ilp"). When set, the client prefers the
|
|
205
|
+
* stateless {@link HttpIlpClient} transport for one-shot writes instead of
|
|
206
|
+
* opening a persistent BTP WebSocket.
|
|
207
|
+
*
|
|
208
|
+
* This mirrors the `httpEndpoint` field a peer advertises in discovery
|
|
209
|
+
* (`IlpPeerInfo`, toon PR #29). It is surfaced here as explicit config so the
|
|
210
|
+
* default runtime can opt into ILP-over-HTTP before connectors advertise the
|
|
211
|
+
* field on-wire. Leave unset to keep the existing BTP-only behavior (the safe
|
|
212
|
+
* default — no connector advertises an httpEndpoint until the connector + a
|
|
213
|
+
* core release with these fields ship).
|
|
214
|
+
*/
|
|
215
|
+
connectorHttpEndpoint?: string;
|
|
216
|
+
/**
|
|
217
|
+
* Whether the uplink connector accepts a BTP `Upgrade` over its HTTP endpoint
|
|
218
|
+
* (mirrors `IlpPeerInfo.supportsUpgrade`, toon PR #29). Only consulted when
|
|
219
|
+
* `connectorHttpEndpoint` is set and a duplex session is required. Defaults to
|
|
220
|
+
* false (no upgrade) when omitted.
|
|
221
|
+
*/
|
|
222
|
+
connectorSupportsUpgrade?: boolean;
|
|
202
223
|
/**
|
|
203
224
|
* ILP destination address for event publishing.
|
|
204
225
|
* Defaults to the connector's local address (derived from connectorUrl host).
|
|
@@ -391,6 +412,103 @@ type ClientTransportConfig = {
|
|
|
391
412
|
gatewayUrl: string;
|
|
392
413
|
};
|
|
393
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Client-side helper for kind:5094 Arweave blob storage DVM requests.
|
|
417
|
+
*
|
|
418
|
+
* This composes the three steps a caller previously had to wire by hand:
|
|
419
|
+
* 1. Build the kind:5094 event via `buildBlobStorageRequest()` (@toon-protocol/core).
|
|
420
|
+
* 2. Publish it to the DVM destination over ILP via `ToonClient.publishEvent()`
|
|
421
|
+
* (reusing the existing claim / channel plumbing).
|
|
422
|
+
* 3. Decode the FULFILL `data` field into the Arweave transaction ID.
|
|
423
|
+
*
|
|
424
|
+
* ## FULFILL data contract
|
|
425
|
+
*
|
|
426
|
+
* For a successful single-packet (non-chunked) blob upload, the DVM provider
|
|
427
|
+
* returns the Arweave transaction ID as a **UTF-8 string, base64-encoded** in
|
|
428
|
+
* the ILP FULFILL `data` field (the connector validates that FULFILL data is
|
|
429
|
+
* base64). An Arweave tx ID is a 43-character base64url string (32 raw bytes).
|
|
430
|
+
*
|
|
431
|
+
* So the decode is:
|
|
432
|
+
* `txId = utf8(base64decode(result.data))`
|
|
433
|
+
*
|
|
434
|
+
* See `packages/sdk/src/arweave/arweave-dvm-handler.ts` for the server side and
|
|
435
|
+
* `packages/client/tests/e2e/docker-arweave-dvm-e2e.test.ts` for the reference
|
|
436
|
+
* end-to-end flow this helper mirrors.
|
|
437
|
+
*
|
|
438
|
+
* Chunked uploads (multi-packet, via `uploadId` / `chunkIndex` / `totalChunks`
|
|
439
|
+
* params) are intentionally out of scope for this single-packet helper — the
|
|
440
|
+
* provider returns `ack:<n>` for intermediate chunks and the tx ID only on the
|
|
441
|
+
* final chunk. Callers needing chunking should drive `publishEvent()` directly
|
|
442
|
+
* (see the chunked case in the reference E2E test). Tracked as a follow-up.
|
|
443
|
+
*/
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Parameters for {@link requestBlobStorage}.
|
|
447
|
+
*/
|
|
448
|
+
interface RequestBlobStorageParams {
|
|
449
|
+
/** The raw blob data to store on Arweave. */
|
|
450
|
+
blobData: Uint8Array;
|
|
451
|
+
/**
|
|
452
|
+
* MIME type of the blob. Defaults to `'application/octet-stream'`
|
|
453
|
+
* (matching `buildBlobStorageRequest`).
|
|
454
|
+
*/
|
|
455
|
+
contentType?: string;
|
|
456
|
+
/**
|
|
457
|
+
* Bid amount in USDC micro-units, as a string (declared in the event's
|
|
458
|
+
* `bid` tag). Defaults to the stringified `ilpAmount` when omitted.
|
|
459
|
+
*
|
|
460
|
+
* At least one of `bid` / `ilpAmount` should be provided so the declared
|
|
461
|
+
* bid and the paid ILP amount agree.
|
|
462
|
+
*/
|
|
463
|
+
bid?: string;
|
|
464
|
+
/**
|
|
465
|
+
* ILP destination address of the DVM that performs the upload
|
|
466
|
+
* (e.g. `'g.toon.peer1'`). Falls back to the client's configured
|
|
467
|
+
* `destinationAddress` when omitted.
|
|
468
|
+
*/
|
|
469
|
+
destination?: string;
|
|
470
|
+
/**
|
|
471
|
+
* Pre-signed balance proof claim for this packet. When omitted, the
|
|
472
|
+
* client's channel manager auto-opens a channel and auto-signs a claim
|
|
473
|
+
* (same lazy-channel behavior as `publishEvent`).
|
|
474
|
+
*/
|
|
475
|
+
claim?: SignedBalanceProof;
|
|
476
|
+
/**
|
|
477
|
+
* Explicit ILP payment amount (bigint micro-units). When omitted,
|
|
478
|
+
* `publishEvent` computes it from the encoded event size. When `bid`
|
|
479
|
+
* is omitted, this value is stringified to populate the event's bid tag.
|
|
480
|
+
*/
|
|
481
|
+
ilpAmount?: bigint;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Typed result of {@link requestBlobStorage}.
|
|
485
|
+
*/
|
|
486
|
+
interface RequestBlobStorageResult {
|
|
487
|
+
/** Whether the upload succeeded and a tx ID was decoded. */
|
|
488
|
+
success: boolean;
|
|
489
|
+
/** The Arweave transaction ID (43-char base64url) when `success` is true. */
|
|
490
|
+
txId?: string;
|
|
491
|
+
/** The id of the kind:5094 event that was published. */
|
|
492
|
+
eventId?: string;
|
|
493
|
+
/** Error message when `success` is false. */
|
|
494
|
+
error?: string;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Requests permanent Arweave blob storage from a DVM in a single ILP packet.
|
|
498
|
+
*
|
|
499
|
+
* Mirrors the single-packet flow in
|
|
500
|
+
* `packages/client/tests/e2e/docker-arweave-dvm-e2e.test.ts`: builds a signed
|
|
501
|
+
* kind:5094 event, publishes it through the supplied {@link ToonClient}
|
|
502
|
+
* (reusing its claim/channel plumbing), and decodes the FULFILL `data` field
|
|
503
|
+
* into an Arweave transaction ID.
|
|
504
|
+
*
|
|
505
|
+
* @param client - A started `ToonClient` (call `client.start()` first).
|
|
506
|
+
* @param secretKey - The Nostr secret key used to sign the kind:5094 event.
|
|
507
|
+
* @param params - Blob, content type, bid, destination, and payment options.
|
|
508
|
+
* @returns `{ success, txId?, eventId?, error? }`.
|
|
509
|
+
*/
|
|
510
|
+
declare function requestBlobStorage(client: ToonClient, secretKey: Uint8Array, params: RequestBlobStorageParams): Promise<RequestBlobStorageResult>;
|
|
511
|
+
|
|
394
512
|
/**
|
|
395
513
|
* ToonClient - High-level client for interacting with TOON network.
|
|
396
514
|
*
|
|
@@ -469,6 +587,30 @@ declare class ToonClient {
|
|
|
469
587
|
* Works before start() is called.
|
|
470
588
|
*/
|
|
471
589
|
getPublicKey(): string;
|
|
590
|
+
/**
|
|
591
|
+
* Sign an unsigned Nostr event template with the client's Nostr secret key,
|
|
592
|
+
* returning a fully-signed event (id + pubkey + sig).
|
|
593
|
+
*
|
|
594
|
+
* This is the key primitive behind the daemon's sign-and-publish path: a UI
|
|
595
|
+
* or agent supplies only `{ kind, content, tags, created_at }` and never holds
|
|
596
|
+
* the private key — signing happens here, inside the key owner.
|
|
597
|
+
*/
|
|
598
|
+
signEvent(template: EventTemplate): NostrEvent;
|
|
599
|
+
/**
|
|
600
|
+
* Upload bytes to Arweave via the kind:5094 blob-storage DVM (single-packet),
|
|
601
|
+
* signing the request with this client's Nostr key and paying through its
|
|
602
|
+
* existing channel. Returns the Arweave tx id on success.
|
|
603
|
+
*
|
|
604
|
+
* Backs the daemon's `upload-media` path: the key and claim/channel plumbing
|
|
605
|
+
* stay inside the client; callers pass only the bytes.
|
|
606
|
+
*/
|
|
607
|
+
uploadBlob(params: {
|
|
608
|
+
blobData: Uint8Array;
|
|
609
|
+
contentType?: string;
|
|
610
|
+
bid?: string;
|
|
611
|
+
destination?: string;
|
|
612
|
+
ilpAmount?: bigint;
|
|
613
|
+
}): Promise<RequestBlobStorageResult>;
|
|
472
614
|
/**
|
|
473
615
|
* Per-chain settlement readiness for the configured `network` tier, mirroring
|
|
474
616
|
* the townhouse node's status. Returns `undefined` when no named `network` is
|
|
@@ -1112,6 +1254,216 @@ declare class BtpRuntimeClient implements IlpClient {
|
|
|
1112
1254
|
private _sendIlpPacketWithClaimOnce;
|
|
1113
1255
|
}
|
|
1114
1256
|
|
|
1257
|
+
/**
|
|
1258
|
+
* ILP-over-HTTP (RFC-0035) transport for the TOON client.
|
|
1259
|
+
*
|
|
1260
|
+
* The connector now serves ILP-over-HTTP on the SAME port as BTP (connector
|
|
1261
|
+
* PR #181). This adapter lets a client do stateless one-shot writes over HTTP
|
|
1262
|
+
* (`POST /ilp`) and upgrade to a duplex BTP session when it needs to receive
|
|
1263
|
+
* server-initiated packets or act as a peer.
|
|
1264
|
+
*
|
|
1265
|
+
* Wire contract (targets connector PR #181's `/ilp`):
|
|
1266
|
+
* - One-shot write: `POST /ilp`
|
|
1267
|
+
* body: OER-encoded ILP PREPARE (`application/octet-stream`)
|
|
1268
|
+
* header: `ILP-Payment-Channel-Claim: base64(JSON of the claim)` — the
|
|
1269
|
+
* SAME claim JSON the BTP path attaches as the
|
|
1270
|
+
* `payment-channel-claim` protocolData entry.
|
|
1271
|
+
* optional: `ILP-Peer-Id` + `Authorization: Bearer <secret>` identity.
|
|
1272
|
+
* response: `200 OK` with an OER FULFILL or REJECT body. HTTP non-2xx is
|
|
1273
|
+
* reserved for TRANSPORT errors (400/401/413/5xx); ILP-level
|
|
1274
|
+
* rejects come back as a 200 + REJECT body.
|
|
1275
|
+
* - Upgrade to BTP: standard HTTP `Upgrade` with `Sec-WebSocket-Protocol: btp`
|
|
1276
|
+
* plus the same `ILP-Peer-Id` + `Authorization` headers. The connector
|
|
1277
|
+
* pre-authenticates the BTP session from those headers (continuity), so
|
|
1278
|
+
* after `101` we send BTP frames WITHOUT a separate in-band auth frame.
|
|
1279
|
+
* Omitting the auth headers falls back to the normal BTP auth-frame flow.
|
|
1280
|
+
*
|
|
1281
|
+
* Reuses `serializeIlpPrepare`/`deserializeIlpPacket` from `btp/protocol.ts` —
|
|
1282
|
+
* the SAME OER codec the BTP path uses. Claim signing/construction is owned by
|
|
1283
|
+
* the caller (BootstrapService); this transport never builds or signs claims.
|
|
1284
|
+
*/
|
|
1285
|
+
|
|
1286
|
+
/** Header carrying the base64(JSON) payment-channel claim. */
|
|
1287
|
+
declare const ILP_CLAIM_HEADER = "ILP-Payment-Channel-Claim";
|
|
1288
|
+
/** Header carrying a NIP-59 wrapped (gift-wrapped) claim. */
|
|
1289
|
+
declare const ILP_CLAIM_WRAPPED_HEADER = "ILP-Payment-Channel-Claim-Wrapped";
|
|
1290
|
+
/** Header carrying the peer identity. */
|
|
1291
|
+
declare const ILP_PEER_ID_HEADER = "ILP-Peer-Id";
|
|
1292
|
+
interface HttpIlpClientConfig {
|
|
1293
|
+
/** The peer's `POST /ilp` URL (the `httpEndpoint` from discovery). */
|
|
1294
|
+
httpEndpoint: string;
|
|
1295
|
+
/**
|
|
1296
|
+
* Optional peer identity. With no `peerId`/`authToken` the connector treats
|
|
1297
|
+
* the request as an anonymous no-auth peer (permissionless default) and
|
|
1298
|
+
* derives an ephemeral id from the claim signer.
|
|
1299
|
+
*/
|
|
1300
|
+
peerId?: string;
|
|
1301
|
+
/** Bearer secret for `Authorization`. Omit for the no-auth peer path. */
|
|
1302
|
+
authToken?: string;
|
|
1303
|
+
/** Request timeout in milliseconds (default: 30000). */
|
|
1304
|
+
timeout?: number;
|
|
1305
|
+
/** Max retry attempts for transport-level network failures (default: 3). */
|
|
1306
|
+
maxRetries?: number;
|
|
1307
|
+
/** Initial retry delay in milliseconds (default: 1000). */
|
|
1308
|
+
retryDelay?: number;
|
|
1309
|
+
/** Custom fetch implementation (SOCKS5 mode / testing). */
|
|
1310
|
+
httpClient?: typeof fetch;
|
|
1311
|
+
/**
|
|
1312
|
+
* Custom WebSocket constructor for the BTP upgrade path (SOCKS5 mode).
|
|
1313
|
+
* Forwarded to the underlying BtpRuntimeClient.
|
|
1314
|
+
*/
|
|
1315
|
+
createWebSocket?: (url: string) => WebSocket;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Stateless ILP-over-HTTP transport implementing `IlpClient`.
|
|
1319
|
+
*
|
|
1320
|
+
* Use this for pure one-shot consumers (publish-and-forget writes). When the
|
|
1321
|
+
* client needs a duplex session — to receive server-initiated packets or to act
|
|
1322
|
+
* as a peer — call {@link upgradeToBtp} to obtain a connected BtpRuntimeClient
|
|
1323
|
+
* that reuses the existing BTP code path.
|
|
1324
|
+
*/
|
|
1325
|
+
declare class HttpIlpClient implements IlpClient {
|
|
1326
|
+
private readonly httpEndpoint;
|
|
1327
|
+
private readonly peerId;
|
|
1328
|
+
private readonly authToken;
|
|
1329
|
+
private readonly timeout;
|
|
1330
|
+
private readonly retryConfig;
|
|
1331
|
+
private readonly httpClient;
|
|
1332
|
+
private readonly createWebSocket;
|
|
1333
|
+
constructor(config: HttpIlpClientConfig);
|
|
1334
|
+
/**
|
|
1335
|
+
* Send an ILP PREPARE via `POST /ilp` WITHOUT a claim. The connector accepts
|
|
1336
|
+
* this only on free/zero-amount routes; paid writes must use
|
|
1337
|
+
* {@link sendIlpPacketWithClaim}. Satisfies the IlpClient interface.
|
|
1338
|
+
*/
|
|
1339
|
+
sendIlpPacket(params: {
|
|
1340
|
+
destination: string;
|
|
1341
|
+
amount: string;
|
|
1342
|
+
data: string;
|
|
1343
|
+
timeout?: number;
|
|
1344
|
+
}): Promise<IlpSendResult>;
|
|
1345
|
+
/**
|
|
1346
|
+
* Send an ILP PREPARE via `POST /ilp` with the payment-channel claim attached
|
|
1347
|
+
* as the `ILP-Payment-Channel-Claim` header. `claim` is the SAME JSON object
|
|
1348
|
+
* the BTP path attaches as the `payment-channel-claim` protocolData entry —
|
|
1349
|
+
* we base64(JSON.stringify(claim)) it, byte-for-byte identical to BTP.
|
|
1350
|
+
*/
|
|
1351
|
+
sendIlpPacketWithClaim(params: {
|
|
1352
|
+
destination: string;
|
|
1353
|
+
amount: string;
|
|
1354
|
+
data: string;
|
|
1355
|
+
timeout?: number;
|
|
1356
|
+
}, claim: unknown): Promise<IlpSendResult>;
|
|
1357
|
+
/**
|
|
1358
|
+
* Upgrade to a duplex BTP session over the SAME endpoint.
|
|
1359
|
+
*
|
|
1360
|
+
* Derives the `ws(s)://` URL from `httpEndpoint`, opens a WebSocket with
|
|
1361
|
+
* `Sec-WebSocket-Protocol: btp` and the same `ILP-Peer-Id` + `Authorization`
|
|
1362
|
+
* headers, and returns a connected {@link BtpRuntimeClient}. When auth headers
|
|
1363
|
+
* are present the connector pre-authenticates the session (no in-band auth
|
|
1364
|
+
* frame); without them the BtpRuntimeClient falls back to the normal BTP
|
|
1365
|
+
* auth-frame flow.
|
|
1366
|
+
*
|
|
1367
|
+
* NOTE: passing per-connection headers + a subprotocol to a WebSocket is
|
|
1368
|
+
* Node-only (the `ws` package). Browsers cannot set arbitrary request headers
|
|
1369
|
+
* on a WebSocket handshake, so a browser consumer must use the gateway
|
|
1370
|
+
* transport or BTP-with-auth-frame instead.
|
|
1371
|
+
*/
|
|
1372
|
+
upgradeToBtp(): Promise<BtpRuntimeClient>;
|
|
1373
|
+
private authHeaders;
|
|
1374
|
+
/**
|
|
1375
|
+
* Single attempt: serialize the PREPARE, POST it, and map the response.
|
|
1376
|
+
* @throws {NetworkError} On connection/timeout failures (retried).
|
|
1377
|
+
* @throws {ConnectorError} On non-retryable transport errors (5xx / unexpected).
|
|
1378
|
+
*/
|
|
1379
|
+
private postPrepare;
|
|
1380
|
+
/**
|
|
1381
|
+
* Map a `200 OK` body (OER FULFILL/REJECT) to an IlpSendResult; map a non-2xx
|
|
1382
|
+
* to a transport error. Per the wire contract, ILP-level rejects arrive as a
|
|
1383
|
+
* 200 + REJECT body — only HTTP non-2xx means a transport-layer failure.
|
|
1384
|
+
*/
|
|
1385
|
+
private mapResponse;
|
|
1386
|
+
private mapTransportError;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Derive the BTP WebSocket URL from a `POST /ilp` HTTP endpoint. The connector
|
|
1390
|
+
* serves BTP on the SAME path, so we only swap the scheme (http→ws, https→wss).
|
|
1391
|
+
*/
|
|
1392
|
+
declare function httpEndpointToBtpUrl(httpEndpoint: string): string;
|
|
1393
|
+
|
|
1394
|
+
/**
|
|
1395
|
+
* Transport selection policy for the client ILP layer.
|
|
1396
|
+
*
|
|
1397
|
+
* The connector serves ILP-over-HTTP (`POST /ilp`) and BTP on the SAME port
|
|
1398
|
+
* (connector PR #181). A peer advertises this in discovery via the toon-core
|
|
1399
|
+
* `IlpPeerInfo` fields added in toon PR #29:
|
|
1400
|
+
* - `httpEndpoint?: string` — the `POST /ilp` URL.
|
|
1401
|
+
* - `supportsUpgrade?: boolean` — whether the host accepts the BTP upgrade.
|
|
1402
|
+
*
|
|
1403
|
+
* Those fields may not yet exist on the installed `@toon-protocol/core`
|
|
1404
|
+
* `IlpPeerInfo` type, so we read them defensively here (see `DiscoveredIlpPeer`).
|
|
1405
|
+
*
|
|
1406
|
+
* Policy:
|
|
1407
|
+
* - Pure one-shot consumers (`needsDuplex: false`) prefer HTTP when the peer
|
|
1408
|
+
* advertises an `httpEndpoint` — stateless, no persistent socket.
|
|
1409
|
+
* - Clients that must receive server-initiated packets or act as a peer
|
|
1410
|
+
* (`needsDuplex: true`) use BTP. If the peer only exposes `httpEndpoint`
|
|
1411
|
+
* and `supportsUpgrade` is true, we go HTTP-then-upgrade; otherwise we
|
|
1412
|
+
* connect to the BTP endpoint directly.
|
|
1413
|
+
*/
|
|
1414
|
+
/**
|
|
1415
|
+
* The subset of discovery fields this policy reads. Structurally compatible with
|
|
1416
|
+
* core's `IlpPeerInfo`; `httpEndpoint`/`supportsUpgrade` are optional so a
|
|
1417
|
+
* pre-PR-#29 `IlpPeerInfo` can be passed through a cast.
|
|
1418
|
+
*/
|
|
1419
|
+
interface DiscoveredIlpPeer {
|
|
1420
|
+
/** BTP WebSocket endpoint (always present on a TOON peer). */
|
|
1421
|
+
btpEndpoint?: string;
|
|
1422
|
+
/** `POST /ilp` URL (toon PR #29). */
|
|
1423
|
+
httpEndpoint?: string;
|
|
1424
|
+
/** Whether the host accepts the BTP upgrade over the HTTP endpoint (toon PR #29). */
|
|
1425
|
+
supportsUpgrade?: boolean;
|
|
1426
|
+
}
|
|
1427
|
+
type IlpTransportChoice =
|
|
1428
|
+
/** Stateless one-shot writes via `POST /ilp`. */
|
|
1429
|
+
{
|
|
1430
|
+
kind: 'http';
|
|
1431
|
+
httpEndpoint: string;
|
|
1432
|
+
canUpgrade: boolean;
|
|
1433
|
+
}
|
|
1434
|
+
/** Duplex BTP session via the WebSocket endpoint. */
|
|
1435
|
+
| {
|
|
1436
|
+
kind: 'btp';
|
|
1437
|
+
btpEndpoint: string;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Open HTTP first (one-shot writes) but upgrade to BTP when duplex is needed.
|
|
1441
|
+
* Only chosen when the peer exposes `httpEndpoint` + `supportsUpgrade` and no
|
|
1442
|
+
* separate `btpEndpoint`.
|
|
1443
|
+
*/
|
|
1444
|
+
| {
|
|
1445
|
+
kind: 'http-upgradable';
|
|
1446
|
+
httpEndpoint: string;
|
|
1447
|
+
};
|
|
1448
|
+
interface SelectIlpTransportOptions {
|
|
1449
|
+
/**
|
|
1450
|
+
* Whether the client needs a duplex session (receive server-initiated
|
|
1451
|
+
* packets / act as a peer). Default: false (pure one-shot consumer).
|
|
1452
|
+
*/
|
|
1453
|
+
needsDuplex?: boolean;
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Read discovery fields defensively from a (possibly pre-PR-#29) peer info
|
|
1457
|
+
* object. Accepts core's `IlpPeerInfo` or any structurally-compatible shape.
|
|
1458
|
+
*/
|
|
1459
|
+
declare function readDiscoveredIlpPeer(peer: unknown): DiscoveredIlpPeer;
|
|
1460
|
+
/**
|
|
1461
|
+
* Choose the ILP transport for a discovered peer given the consumer's needs.
|
|
1462
|
+
*
|
|
1463
|
+
* @throws {Error} If the peer advertises no usable endpoint at all.
|
|
1464
|
+
*/
|
|
1465
|
+
declare function selectIlpTransport(peer: DiscoveredIlpPeer, options?: SelectIlpTransportOptions): IlpTransportChoice;
|
|
1466
|
+
|
|
1115
1467
|
/**
|
|
1116
1468
|
* Chain-specific metadata (discriminated union).
|
|
1117
1469
|
*/
|
|
@@ -1918,7 +2270,7 @@ declare function validateConfig(config: ToonClientConfig): void;
|
|
|
1918
2270
|
* The resolved config type after defaults are applied.
|
|
1919
2271
|
* secretKey is guaranteed to be present (auto-generated if omitted).
|
|
1920
2272
|
*/
|
|
1921
|
-
type ResolvedConfig = Required<Omit<ToonClientConfig, 'connector' | 'mnemonic' | 'mnemonicAccountIndex' | 'evmPrivateKey' | 'network' | 'supportedChains' | 'settlementAddresses' | 'preferredTokens' | 'tokenNetworks' | 'btpUrl' | 'btpAuthToken' | 'btpPeerId' | 'chainRpcUrls' | 'initialDeposit' | 'settlementTimeout' | 'solanaChannel' | 'minaChannel' | 'channelStorePath' | 'knownPeers' | 'destinationAddress' | 'transport' | 'managedAnonProxy' | 'managedAnonSocksPort'>> & {
|
|
2273
|
+
type ResolvedConfig = Required<Omit<ToonClientConfig, 'connector' | 'mnemonic' | 'mnemonicAccountIndex' | 'evmPrivateKey' | 'network' | 'supportedChains' | 'settlementAddresses' | 'preferredTokens' | 'tokenNetworks' | 'btpUrl' | 'btpAuthToken' | 'btpPeerId' | 'connectorHttpEndpoint' | 'connectorSupportsUpgrade' | 'chainRpcUrls' | 'initialDeposit' | 'settlementTimeout' | 'solanaChannel' | 'minaChannel' | 'channelStorePath' | 'knownPeers' | 'destinationAddress' | 'transport' | 'managedAnonProxy' | 'managedAnonSocksPort'>> & {
|
|
1922
2274
|
connector?: unknown;
|
|
1923
2275
|
/** Always present after applyDefaults() — derived from secretKey if not explicitly provided */
|
|
1924
2276
|
evmPrivateKey: string | Uint8Array;
|
|
@@ -1949,6 +2301,8 @@ type ResolvedConfig = Required<Omit<ToonClientConfig, 'connector' | 'mnemonic' |
|
|
|
1949
2301
|
btpUrl?: string;
|
|
1950
2302
|
btpAuthToken?: string;
|
|
1951
2303
|
btpPeerId?: string;
|
|
2304
|
+
connectorHttpEndpoint?: string;
|
|
2305
|
+
connectorSupportsUpgrade?: boolean;
|
|
1952
2306
|
chainRpcUrls?: Record<string, string>;
|
|
1953
2307
|
initialDeposit?: string;
|
|
1954
2308
|
settlementTimeout?: number;
|
|
@@ -2374,103 +2728,6 @@ declare function filterPetListings(events: NostrEventLike[], options?: PetListin
|
|
|
2374
2728
|
*/
|
|
2375
2729
|
declare function buildPetPurchaseRequest(params: PetPurchaseRequestParams): UnsignedNostrEvent;
|
|
2376
2730
|
|
|
2377
|
-
/**
|
|
2378
|
-
* Client-side helper for kind:5094 Arweave blob storage DVM requests.
|
|
2379
|
-
*
|
|
2380
|
-
* This composes the three steps a caller previously had to wire by hand:
|
|
2381
|
-
* 1. Build the kind:5094 event via `buildBlobStorageRequest()` (@toon-protocol/core).
|
|
2382
|
-
* 2. Publish it to the DVM destination over ILP via `ToonClient.publishEvent()`
|
|
2383
|
-
* (reusing the existing claim / channel plumbing).
|
|
2384
|
-
* 3. Decode the FULFILL `data` field into the Arweave transaction ID.
|
|
2385
|
-
*
|
|
2386
|
-
* ## FULFILL data contract
|
|
2387
|
-
*
|
|
2388
|
-
* For a successful single-packet (non-chunked) blob upload, the DVM provider
|
|
2389
|
-
* returns the Arweave transaction ID as a **UTF-8 string, base64-encoded** in
|
|
2390
|
-
* the ILP FULFILL `data` field (the connector validates that FULFILL data is
|
|
2391
|
-
* base64). An Arweave tx ID is a 43-character base64url string (32 raw bytes).
|
|
2392
|
-
*
|
|
2393
|
-
* So the decode is:
|
|
2394
|
-
* `txId = utf8(base64decode(result.data))`
|
|
2395
|
-
*
|
|
2396
|
-
* See `packages/sdk/src/arweave/arweave-dvm-handler.ts` for the server side and
|
|
2397
|
-
* `packages/client/tests/e2e/docker-arweave-dvm-e2e.test.ts` for the reference
|
|
2398
|
-
* end-to-end flow this helper mirrors.
|
|
2399
|
-
*
|
|
2400
|
-
* Chunked uploads (multi-packet, via `uploadId` / `chunkIndex` / `totalChunks`
|
|
2401
|
-
* params) are intentionally out of scope for this single-packet helper — the
|
|
2402
|
-
* provider returns `ack:<n>` for intermediate chunks and the tx ID only on the
|
|
2403
|
-
* final chunk. Callers needing chunking should drive `publishEvent()` directly
|
|
2404
|
-
* (see the chunked case in the reference E2E test). Tracked as a follow-up.
|
|
2405
|
-
*/
|
|
2406
|
-
|
|
2407
|
-
/**
|
|
2408
|
-
* Parameters for {@link requestBlobStorage}.
|
|
2409
|
-
*/
|
|
2410
|
-
interface RequestBlobStorageParams {
|
|
2411
|
-
/** The raw blob data to store on Arweave. */
|
|
2412
|
-
blobData: Uint8Array;
|
|
2413
|
-
/**
|
|
2414
|
-
* MIME type of the blob. Defaults to `'application/octet-stream'`
|
|
2415
|
-
* (matching `buildBlobStorageRequest`).
|
|
2416
|
-
*/
|
|
2417
|
-
contentType?: string;
|
|
2418
|
-
/**
|
|
2419
|
-
* Bid amount in USDC micro-units, as a string (declared in the event's
|
|
2420
|
-
* `bid` tag). Defaults to the stringified `ilpAmount` when omitted.
|
|
2421
|
-
*
|
|
2422
|
-
* At least one of `bid` / `ilpAmount` should be provided so the declared
|
|
2423
|
-
* bid and the paid ILP amount agree.
|
|
2424
|
-
*/
|
|
2425
|
-
bid?: string;
|
|
2426
|
-
/**
|
|
2427
|
-
* ILP destination address of the DVM that performs the upload
|
|
2428
|
-
* (e.g. `'g.toon.peer1'`). Falls back to the client's configured
|
|
2429
|
-
* `destinationAddress` when omitted.
|
|
2430
|
-
*/
|
|
2431
|
-
destination?: string;
|
|
2432
|
-
/**
|
|
2433
|
-
* Pre-signed balance proof claim for this packet. When omitted, the
|
|
2434
|
-
* client's channel manager auto-opens a channel and auto-signs a claim
|
|
2435
|
-
* (same lazy-channel behavior as `publishEvent`).
|
|
2436
|
-
*/
|
|
2437
|
-
claim?: SignedBalanceProof;
|
|
2438
|
-
/**
|
|
2439
|
-
* Explicit ILP payment amount (bigint micro-units). When omitted,
|
|
2440
|
-
* `publishEvent` computes it from the encoded event size. When `bid`
|
|
2441
|
-
* is omitted, this value is stringified to populate the event's bid tag.
|
|
2442
|
-
*/
|
|
2443
|
-
ilpAmount?: bigint;
|
|
2444
|
-
}
|
|
2445
|
-
/**
|
|
2446
|
-
* Typed result of {@link requestBlobStorage}.
|
|
2447
|
-
*/
|
|
2448
|
-
interface RequestBlobStorageResult {
|
|
2449
|
-
/** Whether the upload succeeded and a tx ID was decoded. */
|
|
2450
|
-
success: boolean;
|
|
2451
|
-
/** The Arweave transaction ID (43-char base64url) when `success` is true. */
|
|
2452
|
-
txId?: string;
|
|
2453
|
-
/** The id of the kind:5094 event that was published. */
|
|
2454
|
-
eventId?: string;
|
|
2455
|
-
/** Error message when `success` is false. */
|
|
2456
|
-
error?: string;
|
|
2457
|
-
}
|
|
2458
|
-
/**
|
|
2459
|
-
* Requests permanent Arweave blob storage from a DVM in a single ILP packet.
|
|
2460
|
-
*
|
|
2461
|
-
* Mirrors the single-packet flow in
|
|
2462
|
-
* `packages/client/tests/e2e/docker-arweave-dvm-e2e.test.ts`: builds a signed
|
|
2463
|
-
* kind:5094 event, publishes it through the supplied {@link ToonClient}
|
|
2464
|
-
* (reusing its claim/channel plumbing), and decodes the FULFILL `data` field
|
|
2465
|
-
* into an Arweave transaction ID.
|
|
2466
|
-
*
|
|
2467
|
-
* @param client - A started `ToonClient` (call `client.start()` first).
|
|
2468
|
-
* @param secretKey - The Nostr secret key used to sign the kind:5094 event.
|
|
2469
|
-
* @param params - Blob, content type, bid, destination, and payment options.
|
|
2470
|
-
* @returns `{ success, txId?, eventId?, error? }`.
|
|
2471
|
-
*/
|
|
2472
|
-
declare function requestBlobStorage(client: ToonClient, secretKey: Uint8Array, params: RequestBlobStorageParams): Promise<RequestBlobStorageResult>;
|
|
2473
|
-
|
|
2474
2731
|
/**
|
|
2475
2732
|
* Full multi-chain identity derived from a single BIP-39 mnemonic.
|
|
2476
2733
|
*/
|
|
@@ -2820,4 +3077,4 @@ declare function loadKeystore(path: string, password: string): string;
|
|
|
2820
3077
|
*/
|
|
2821
3078
|
declare function writeKeystoreFile(path: string, keystore: EncryptedKeystore): void;
|
|
2822
3079
|
|
|
2823
|
-
export { ANON_ASSETS, ANON_VERSION, type AnonAsset, type BackupPayload, type BalanceProofParams, BtpRuntimeClient, type BtpRuntimeClientConfig, type ChainMetadata, type ChainSigner, ChannelManager, type ClaimMessage, type ClientTransportConfig, ConnectorError, type EVMClaimMessage, type EncryptedKeystore, EvmSigner, HS_HOSTNAME_MAX_LENGTH, HS_HOSTNAME_REGEX, HttpConnectorAdmin, type HttpConnectorAdminConfig, HttpRuntimeClient, type HttpRuntimeClientConfig, type InteractionResultContent, KeyManager, type KeyManagerConfig, type ManagedAnonProxy, type MinaClaimMessage, type MinaDepositReader, MinaSigner, type MinaSignerOptions, NetworkError, OnChainChannelClient, type OnChainChannelClientConfig, type PasskeyInfo, type PetDvmProvider, type PetInteractionEventData, type PetInteractionRequestParams, type PetInteractionResultData, type PetListing, type PetListingFilterOptions, type PetListingParams, type PetPurchaseRequestParams, type ProofStatus, type PublishEventResult, type RequestBlobStorageParams, type RequestBlobStorageResult, type RetryOptions, type SignedBalanceProof, type SolanaChannelClientOptions, type SolanaClaimMessage, SolanaSigner, type StartManagedAnonProxyOptions, type StatValues, ToonClient, type ToonClientConfig, ToonClientError, type ToonIdentity, type ToonSigners, type ToonStartResult, type UnsignedNostrEvent, ValidationError, type VaultData, applyDefaults, applyNetworkPresets, assertRoutableHsHostname, buildBackupEvent, buildBackupFilter, buildPetInteractionRequest, buildPetListingEvent, buildPetPurchaseRequest, buildSettlementInfo, decryptMnemonic, deriveFromNsec, deriveFullIdentity, deriveNostrKeyFromMnemonic, encryptMnemonic, filterPetDvmProviders, filterPetListings, generateKeystore, generateMnemonic, generateRandomIdentity, getNetworkStatus, importKeystore, isPrfSupported, isRoutableHsHostname, loadKeystore, parseBackupPayload, parsePetInteractionEvent, parsePetInteractionResult, parsePetListing, readMinaDepositTotal, requestBlobStorage, selectAnonAsset, startManagedAnonProxy, validateConfig, validateMnemonic, withRetry, writeKeystoreFile };
|
|
3080
|
+
export { ANON_ASSETS, ANON_VERSION, type AnonAsset, type BackupPayload, type BalanceProofParams, BtpRuntimeClient, type BtpRuntimeClientConfig, type ChainMetadata, type ChainSigner, ChannelManager, type ClaimMessage, type ClientTransportConfig, ConnectorError, type DiscoveredIlpPeer, type EVMClaimMessage, type EncryptedKeystore, EvmSigner, HS_HOSTNAME_MAX_LENGTH, HS_HOSTNAME_REGEX, HttpConnectorAdmin, type HttpConnectorAdminConfig, HttpIlpClient, type HttpIlpClientConfig, HttpRuntimeClient, type HttpRuntimeClientConfig, ILP_CLAIM_HEADER, ILP_CLAIM_WRAPPED_HEADER, ILP_PEER_ID_HEADER, type IlpTransportChoice, type InteractionResultContent, KeyManager, type KeyManagerConfig, type ManagedAnonProxy, type MinaClaimMessage, type MinaDepositReader, MinaSigner, type MinaSignerOptions, NetworkError, OnChainChannelClient, type OnChainChannelClientConfig, type PasskeyInfo, type PetDvmProvider, type PetInteractionEventData, type PetInteractionRequestParams, type PetInteractionResultData, type PetListing, type PetListingFilterOptions, type PetListingParams, type PetPurchaseRequestParams, type ProofStatus, type PublishEventResult, type RequestBlobStorageParams, type RequestBlobStorageResult, type RetryOptions, type SelectIlpTransportOptions, type SignedBalanceProof, type SolanaChannelClientOptions, type SolanaClaimMessage, SolanaSigner, type StartManagedAnonProxyOptions, type StatValues, ToonClient, type ToonClientConfig, ToonClientError, type ToonIdentity, type ToonSigners, type ToonStartResult, type UnsignedNostrEvent, ValidationError, type VaultData, applyDefaults, applyNetworkPresets, assertRoutableHsHostname, buildBackupEvent, buildBackupFilter, buildPetInteractionRequest, buildPetListingEvent, buildPetPurchaseRequest, buildSettlementInfo, decryptMnemonic, deriveFromNsec, deriveFullIdentity, deriveNostrKeyFromMnemonic, encryptMnemonic, filterPetDvmProviders, filterPetListings, generateKeystore, generateMnemonic, generateRandomIdentity, getNetworkStatus, httpEndpointToBtpUrl, importKeystore, isPrfSupported, isRoutableHsHostname, loadKeystore, parseBackupPayload, parsePetInteractionEvent, parsePetInteractionResult, parsePetListing, readDiscoveredIlpPeer, readMinaDepositTotal, requestBlobStorage, selectAnonAsset, selectIlpTransport, startManagedAnonProxy, validateConfig, validateMnemonic, withRetry, writeKeystoreFile };
|