@toon-protocol/client 0.14.1 → 0.14.3
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 +25 -5
- package/dist/index.js +18 -12
- 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**
|
|
@@ -2972,9 +2977,24 @@ interface FundWalletResult {
|
|
|
2972
2977
|
interface FundWalletOptions {
|
|
2973
2978
|
/** Custom fetch implementation (for testing / custom transports). */
|
|
2974
2979
|
fetchImpl?: typeof fetch;
|
|
2975
|
-
/**
|
|
2980
|
+
/**
|
|
2981
|
+
* Request timeout in milliseconds. Defaults to {@link defaultFaucetTimeout}
|
|
2982
|
+
* for the chain (fast 30s for evm/solana, a longer 120s for the slow-settling
|
|
2983
|
+
* mina faucet).
|
|
2984
|
+
*/
|
|
2976
2985
|
timeout?: number;
|
|
2977
2986
|
}
|
|
2987
|
+
/**
|
|
2988
|
+
* Default faucet request timeout (ms) for a chain.
|
|
2989
|
+
*
|
|
2990
|
+
* EVM and Solana faucets respond in a few seconds, so 30s is plenty. The Mina
|
|
2991
|
+
* faucet sends native MINA *and* mints USDC on a chain that settles much more
|
|
2992
|
+
* slowly: the drip routinely succeeds server-side (the faucet logs
|
|
2993
|
+
* `✅ Mina faucet request completed`) but takes well over 30s to answer the
|
|
2994
|
+
* HTTP request, so a flat 30s budget makes the client give up on a request that
|
|
2995
|
+
* actually worked. Give mina a much longer budget.
|
|
2996
|
+
*/
|
|
2997
|
+
declare function defaultFaucetTimeout(chain: FaucetChain): number;
|
|
2978
2998
|
/**
|
|
2979
2999
|
* Drip test funds to `address` on `chain` from the devnet `faucetUrl`.
|
|
2980
3000
|
*
|
|
@@ -3336,4 +3356,4 @@ declare function loadKeystore(path: string, password: string): string;
|
|
|
3336
3356
|
*/
|
|
3337
3357
|
declare function writeKeystoreFile(path: string, keystore: EncryptedKeystore): void;
|
|
3338
3358
|
|
|
3339
|
-
export { type BackupPayload, type BalanceProofParams, BtpRuntimeClient, type BtpRuntimeClientConfig, type ChainMetadata, type ChainSigner, ChannelManager, type ClaimMessage, type ClaimResolver, ConnectorError, type DiscoveredIlpPeer, type EVMClaimMessage, type EncryptedKeystore, EvmSigner, type FaucetChain, type FundWalletOptions, type FundWalletResult, type H402FetchOptions, Http402Client, type Http402ClientConfig, HttpConnectorAdmin, type HttpConnectorAdminConfig, HttpIlpClient, type HttpIlpClientConfig, type HttpIlpClientFactory, HttpRuntimeClient, type HttpRuntimeClientConfig, ILP_CLAIM_HEADER, ILP_CLAIM_WRAPPED_HEADER, ILP_PEER_ID_HEADER, type IlpTransportChoice, type InteractionResultContent, KeyManager, type KeyManagerConfig, type MinaClaimMessage, type MinaDepositReader, MinaSigner, type MinaSignerOptions, NetworkError, OnChainChannelClient, type OnChainChannelClientConfig, type ParsedFulfillHttp, type ParsedX402Challenge, 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 StatValues, type ToonChannelAccept, ToonClient, type ToonClientConfig, ToonClientError, type ToonIdentity, type ToonSigners, type ToonStartResult, type UnsignedNostrEvent, ValidationError, type VaultData, applyDefaults, applyNetworkPresets, buildBackupEvent, buildBackupFilter, buildPetInteractionRequest, buildPetListingEvent, buildPetPurchaseRequest, buildSettlementInfo, buildStoreWriteEnvelope, decryptMnemonic, deriveFromNsec, deriveFullIdentity, deriveNostrKeyFromMnemonic, encryptMnemonic, filterPetDvmProviders, filterPetListings, fundWallet, generateKeystore, generateMnemonic, generateRandomIdentity, getNetworkStatus, httpEndpointToBtpUrl, importKeystore, isPrfSupported, loadKeystore, parseBackupPayload, parseFulfillHttp, parseFulfillHttpBytes, parseHttpResponse, parsePetInteractionEvent, parsePetInteractionResult, parsePetListing, parseX402Body, parseX402Challenge, proxyIlpEndpoint, readDiscoveredIlpPeer, readMinaDepositTotal, requestBlobStorage, selectIlpTransport, serializeHttpRequest, validateConfig, validateMnemonic, withRetry, writeKeystoreFile };
|
|
3359
|
+
export { type BackupPayload, type BalanceProofParams, BtpRuntimeClient, type BtpRuntimeClientConfig, type ChainMetadata, type ChainSigner, ChannelManager, type ClaimMessage, type ClaimResolver, ConnectorError, type DiscoveredIlpPeer, type EVMClaimMessage, type EncryptedKeystore, EvmSigner, type FaucetChain, type FundWalletOptions, type FundWalletResult, type H402FetchOptions, Http402Client, type Http402ClientConfig, HttpConnectorAdmin, type HttpConnectorAdminConfig, HttpIlpClient, type HttpIlpClientConfig, type HttpIlpClientFactory, HttpRuntimeClient, type HttpRuntimeClientConfig, ILP_CLAIM_HEADER, ILP_CLAIM_WRAPPED_HEADER, ILP_PEER_ID_HEADER, type IlpTransportChoice, type InteractionResultContent, KeyManager, type KeyManagerConfig, type MinaClaimMessage, type MinaDepositReader, MinaSigner, type MinaSignerOptions, NetworkError, OnChainChannelClient, type OnChainChannelClientConfig, type ParsedFulfillHttp, type ParsedX402Challenge, 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 StatValues, type ToonChannelAccept, ToonClient, type ToonClientConfig, ToonClientError, type ToonIdentity, type ToonSigners, type ToonStartResult, type UnsignedNostrEvent, ValidationError, type VaultData, applyDefaults, applyNetworkPresets, buildBackupEvent, buildBackupFilter, buildPetInteractionRequest, buildPetListingEvent, buildPetPurchaseRequest, buildSettlementInfo, buildStoreWriteEnvelope, decryptMnemonic, defaultFaucetTimeout, deriveFromNsec, deriveFullIdentity, deriveNostrKeyFromMnemonic, encryptMnemonic, filterPetDvmProviders, filterPetListings, fundWallet, generateKeystore, generateMnemonic, generateRandomIdentity, getNetworkStatus, httpEndpointToBtpUrl, importKeystore, isPrfSupported, loadKeystore, parseBackupPayload, parseFulfillHttp, parseFulfillHttpBytes, parseHttpResponse, parsePetInteractionEvent, parsePetInteractionResult, parsePetListing, parseX402Body, parseX402Challenge, proxyIlpEndpoint, readDiscoveredIlpPeer, readMinaDepositTotal, requestBlobStorage, selectIlpTransport, serializeHttpRequest, validateConfig, validateMnemonic, withRetry, writeKeystoreFile };
|
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];
|
|
@@ -5412,6 +5414,9 @@ function buildPetPurchaseRequest(params) {
|
|
|
5412
5414
|
}
|
|
5413
5415
|
|
|
5414
5416
|
// src/faucet.ts
|
|
5417
|
+
function defaultFaucetTimeout(chain) {
|
|
5418
|
+
return chain === "mina" ? 12e4 : 3e4;
|
|
5419
|
+
}
|
|
5415
5420
|
function faucetPath(chain) {
|
|
5416
5421
|
switch (chain) {
|
|
5417
5422
|
case "evm":
|
|
@@ -5432,7 +5437,7 @@ async function fundWallet(faucetUrl, address, chain, options = {}) {
|
|
|
5432
5437
|
const base = faucetUrl.replace(/\/+$/, "");
|
|
5433
5438
|
const url = `${base}${faucetPath(chain)}`;
|
|
5434
5439
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
5435
|
-
const timeout = options.timeout ??
|
|
5440
|
+
const timeout = options.timeout ?? defaultFaucetTimeout(chain);
|
|
5436
5441
|
const controller = new AbortController();
|
|
5437
5442
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
5438
5443
|
let response;
|
|
@@ -6555,6 +6560,7 @@ export {
|
|
|
6555
6560
|
buildUiCoordinate,
|
|
6556
6561
|
classifyIntent,
|
|
6557
6562
|
decryptMnemonic2 as decryptMnemonic,
|
|
6563
|
+
defaultFaucetTimeout,
|
|
6558
6564
|
deriveFromNsec,
|
|
6559
6565
|
deriveFullIdentity,
|
|
6560
6566
|
deriveNostrKeyFromMnemonic,
|