@toon-protocol/client 0.14.1 → 0.14.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/dist/index.d.ts +8 -3
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1067,6 +1067,9 @@ declare class ToonClient {
|
|
|
1067
1067
|
destination?: string;
|
|
1068
1068
|
claim?: SignedBalanceProof;
|
|
1069
1069
|
ilpAmount?: bigint;
|
|
1070
|
+
/** HTTP request-target the payment-proxy replays (default '/write', the
|
|
1071
|
+
* relay; use '/store' for the Arweave store/DVM backend). */
|
|
1072
|
+
proxyPath?: string;
|
|
1070
1073
|
}): Promise<PublishEventResult>;
|
|
1071
1074
|
/**
|
|
1072
1075
|
* Payment-aware HTTP fetch over TOON (issue #50). A `fetch()`-like method that
|
|
@@ -2367,14 +2370,16 @@ declare function withRetry<T>(operation: () => Promise<T>, options: RetryOptions
|
|
|
2367
2370
|
*/
|
|
2368
2371
|
|
|
2369
2372
|
/**
|
|
2370
|
-
* Wrap a signed Nostr event in the
|
|
2371
|
-
*
|
|
2373
|
+
* Wrap a signed Nostr event in the HTTP envelope the deployed payment-proxy
|
|
2374
|
+
* reverse-proxies to its backend. Defaults to the relay's `POST /write`; pass
|
|
2375
|
+
* `requestTarget: '/store'` for the Arweave store/DVM backend.
|
|
2372
2376
|
*
|
|
2373
2377
|
* @param event - A finalized (signed) Nostr event — passed through to the store
|
|
2374
2378
|
* as the JSON `event` field verbatim (the store re-verifies the signature).
|
|
2379
|
+
* @param requestTarget - HTTP request-target the proxy replays (default `/write`).
|
|
2375
2380
|
* @returns The envelope bytes to use as the ILP PREPARE `data`.
|
|
2376
2381
|
*/
|
|
2377
|
-
declare function buildStoreWriteEnvelope(event: NostrEvent): Uint8Array;
|
|
2382
|
+
declare function buildStoreWriteEnvelope(event: NostrEvent, requestTarget?: string): Uint8Array;
|
|
2378
2383
|
|
|
2379
2384
|
/**
|
|
2380
2385
|
* Shared parser for the HTTP-over-ILP response carried in an ILP **FULFILL**
|
package/dist/index.js
CHANGED
|
@@ -510,11 +510,11 @@ function isBase64(str) {
|
|
|
510
510
|
}
|
|
511
511
|
|
|
512
512
|
// src/utils/store-envelope.ts
|
|
513
|
-
var
|
|
513
|
+
var DEFAULT_REQUEST_TARGET = "/write";
|
|
514
514
|
var HEADERS = ["Host: relay", "Content-Type: application/json"];
|
|
515
|
-
function buildStoreWriteEnvelope(event) {
|
|
515
|
+
function buildStoreWriteEnvelope(event, requestTarget = DEFAULT_REQUEST_TARGET) {
|
|
516
516
|
const body = JSON.stringify({ event });
|
|
517
|
-
const head = [
|
|
517
|
+
const head = [`POST ${requestTarget} HTTP/1.1`, ...HEADERS].join("\r\n");
|
|
518
518
|
return encodeUtf8(head + "\r\n\r\n" + body);
|
|
519
519
|
}
|
|
520
520
|
|
|
@@ -2351,12 +2351,12 @@ var OnChainChannelClient = class {
|
|
|
2351
2351
|
*/
|
|
2352
2352
|
parseChainId(chain) {
|
|
2353
2353
|
const parts = chain.split(":");
|
|
2354
|
-
if (parts.length <
|
|
2354
|
+
if (parts.length < 2) {
|
|
2355
2355
|
throw new Error(
|
|
2356
|
-
`Invalid chain format: "${chain}". Expected "evm:{network}:{chainId}".`
|
|
2356
|
+
`Invalid chain format: "${chain}". Expected "evm:{network}:{chainId}" or "evm:{chainId}".`
|
|
2357
2357
|
);
|
|
2358
2358
|
}
|
|
2359
|
-
const chainIdStr = parts[2];
|
|
2359
|
+
const chainIdStr = parts.length >= 3 ? parts[2] : parts[1];
|
|
2360
2360
|
if (!chainIdStr) {
|
|
2361
2361
|
throw new Error(
|
|
2362
2362
|
`Invalid chain format: "${chain}". Expected "evm:{network}:{chainId}".`
|
|
@@ -3582,7 +3582,9 @@ async function requestBlobStorage(client, secretKey, params) {
|
|
|
3582
3582
|
const result = await client.publishEvent(event, {
|
|
3583
3583
|
destination: params.destination,
|
|
3584
3584
|
claim: params.claim,
|
|
3585
|
-
ilpAmount: params.ilpAmount
|
|
3585
|
+
ilpAmount: params.ilpAmount,
|
|
3586
|
+
// The store/DVM backend serves POST /store (not the relay's /write).
|
|
3587
|
+
proxyPath: "/store"
|
|
3586
3588
|
});
|
|
3587
3589
|
if (!result.success) {
|
|
3588
3590
|
return {
|
|
@@ -4086,7 +4088,7 @@ var ToonClient = class {
|
|
|
4086
4088
|
if (result.negotiatedChain && result.settlementAddress) {
|
|
4087
4089
|
const chainType = result.negotiatedChain.split(":")[0] ?? "evm";
|
|
4088
4090
|
const parts = result.negotiatedChain.split(":");
|
|
4089
|
-
const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : 0;
|
|
4091
|
+
const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : parts.length >= 2 ? parseInt(parts[1] ?? "0", 10) : 0;
|
|
4090
4092
|
const r = result;
|
|
4091
4093
|
this.peerNegotiations.set(result.registeredPeerId, {
|
|
4092
4094
|
chain: result.negotiatedChain,
|
|
@@ -4104,7 +4106,7 @@ var ToonClient = class {
|
|
|
4104
4106
|
if (matchedChain) {
|
|
4105
4107
|
const peerAddr = peerInfo.settlementAddresses?.[matchedChain];
|
|
4106
4108
|
const parts = matchedChain.split(":");
|
|
4107
|
-
const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : 0;
|
|
4109
|
+
const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : parts.length >= 2 ? parseInt(parts[1] ?? "0", 10) : 0;
|
|
4108
4110
|
if (peerAddr) {
|
|
4109
4111
|
this.peerNegotiations.set(result.registeredPeerId, {
|
|
4110
4112
|
chain: matchedChain,
|
|
@@ -4189,7 +4191,7 @@ var ToonClient = class {
|
|
|
4189
4191
|
const toonData = this.config.toonEncoder(event);
|
|
4190
4192
|
const basePricePerByte = 10n;
|
|
4191
4193
|
const amount = options?.ilpAmount !== void 0 ? String(options.ilpAmount) : String(BigInt(toonData.length) * basePricePerByte);
|
|
4192
|
-
const writeData = buildStoreWriteEnvelope(event);
|
|
4194
|
+
const writeData = buildStoreWriteEnvelope(event, options?.proxyPath);
|
|
4193
4195
|
const destination = options?.destination ?? this.config.destinationAddress;
|
|
4194
4196
|
const transport = this.getClaimTransport();
|
|
4195
4197
|
let claimMessage;
|
|
@@ -4561,7 +4563,7 @@ var ToonClient = class {
|
|
|
4561
4563
|
getChainContext(negotiatedChain) {
|
|
4562
4564
|
if (!negotiatedChain) return void 0;
|
|
4563
4565
|
const parts = negotiatedChain.split(":");
|
|
4564
|
-
const chainIdPart = parts.length >= 3 ? parts[2] : void 0;
|
|
4566
|
+
const chainIdPart = parts.length >= 3 ? parts[2] : parts.length >= 2 ? parts[1] : void 0;
|
|
4565
4567
|
const numericChainId = chainIdPart !== void 0 ? parseInt(chainIdPart, 10) : NaN;
|
|
4566
4568
|
if (isNaN(numericChainId)) return void 0;
|
|
4567
4569
|
const tokenNetworkAddress = this.config.tokenNetworks?.[negotiatedChain];
|