@toon-protocol/client 0.14.11 → 0.14.12
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 +31 -3
- package/dist/index.js +46 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1373,6 +1373,26 @@ declare class ConnectorError extends ToonClientError {
|
|
|
1373
1373
|
declare class ValidationError extends ToonClientError {
|
|
1374
1374
|
constructor(message: string, cause?: Error);
|
|
1375
1375
|
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Thrown when the one-time on-chain payment-channel OPEN reverts because the
|
|
1378
|
+
* local settlement wallet has no native gas to pay for its own
|
|
1379
|
+
* approve/openChannel/setTotalDeposit transactions. This is the channel OPEN
|
|
1380
|
+
* only — per-write settlement rides ILP-over-HTTP and never spends gas. We
|
|
1381
|
+
* remap ONLY this case so callers get an actionable message (fund the wallet)
|
|
1382
|
+
* instead of the raw viem "...exceeds the balance of the account" string
|
|
1383
|
+
* (toon-meta#65). Retryable once the wallet is funded; the underlying viem/RPC
|
|
1384
|
+
* error is preserved as `cause`.
|
|
1385
|
+
*/
|
|
1386
|
+
declare class ChannelFundingError extends ToonClientError {
|
|
1387
|
+
readonly retryable = true;
|
|
1388
|
+
constructor(message: string, cause?: Error);
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* True when `err` (or any error in its nested `cause` chain) is an
|
|
1392
|
+
* insufficient-native-gas revert. viem wraps the node error one or more levels
|
|
1393
|
+
* deep, so the whole chain is flattened and scanned.
|
|
1394
|
+
*/
|
|
1395
|
+
declare function isInsufficientGasError(err: unknown): boolean;
|
|
1376
1396
|
|
|
1377
1397
|
/**
|
|
1378
1398
|
* Configuration options for HttpRuntimeClient.
|
|
@@ -2316,14 +2336,22 @@ declare class OnChainChannelClient implements ConnectorChannelClient {
|
|
|
2316
2336
|
*/
|
|
2317
2337
|
private openMinaChannel;
|
|
2318
2338
|
/**
|
|
2319
|
-
* Opens an EVM payment channel on-chain
|
|
2339
|
+
* Opens an EVM payment channel on-chain, remapping the one-time
|
|
2340
|
+
* insufficient-native-gas revert into an actionable {@link ChannelFundingError}
|
|
2341
|
+
* so callers surface "fund the wallet" instead of the raw viem
|
|
2342
|
+
* "...exceeds the balance of the account" string (toon-meta#65). Only the gas
|
|
2343
|
+
* case is remapped; every other error propagates unchanged.
|
|
2344
|
+
*/
|
|
2345
|
+
private openEvmChannel;
|
|
2346
|
+
/**
|
|
2347
|
+
* Raw EVM channel-open (no gas-error remapping — see {@link openEvmChannel}).
|
|
2320
2348
|
*
|
|
2321
2349
|
* 1. Approve token spend if needed
|
|
2322
2350
|
* 2. Call TokenNetwork.openChannel()
|
|
2323
2351
|
* 3. Extract channelId from ChannelOpened event
|
|
2324
2352
|
* 4. Deposit initial funds if specified
|
|
2325
2353
|
*/
|
|
2326
|
-
private
|
|
2354
|
+
private openEvmChannelUnchecked;
|
|
2327
2355
|
/**
|
|
2328
2356
|
* Gets the current state of a payment channel from on-chain data.
|
|
2329
2357
|
*/
|
|
@@ -3551,4 +3579,4 @@ declare function loadKeystore(path: string, password: string): string;
|
|
|
3551
3579
|
*/
|
|
3552
3580
|
declare function writeKeystoreFile(path: string, keystore: EncryptedKeystore): void;
|
|
3553
3581
|
|
|
3554
|
-
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 };
|
|
3582
|
+
export { type BackupPayload, type BalanceProofParams, BtpRuntimeClient, type BtpRuntimeClientConfig, type ChainMetadata, type ChainSigner, ChannelFundingError, 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, isInsufficientGasError, 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
|
@@ -80,6 +80,29 @@ var PeerAlreadyExistsError = class extends ToonClientError {
|
|
|
80
80
|
this.name = "PeerAlreadyExistsError";
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
+
var ChannelFundingError = class extends ToonClientError {
|
|
84
|
+
retryable = true;
|
|
85
|
+
constructor(message, cause) {
|
|
86
|
+
super(message, "CHANNEL_FUNDING", cause);
|
|
87
|
+
this.name = "ChannelFundingError";
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var INSUFFICIENT_GAS_MARKERS = [
|
|
91
|
+
"exceeds the balance of the account",
|
|
92
|
+
"insufficient funds for gas",
|
|
93
|
+
"insufficient funds for intrinsic transaction cost",
|
|
94
|
+
"insufficient funds for transfer"
|
|
95
|
+
];
|
|
96
|
+
function isInsufficientGasError(err) {
|
|
97
|
+
const parts = [];
|
|
98
|
+
let cur = err;
|
|
99
|
+
for (let i = 0; i < 10 && cur != null; i++) {
|
|
100
|
+
parts.push(cur instanceof Error ? cur.message : String(cur));
|
|
101
|
+
cur = cur instanceof Error ? cur.cause : void 0;
|
|
102
|
+
}
|
|
103
|
+
const text = parts.join(" | ").toLowerCase();
|
|
104
|
+
return INSUFFICIENT_GAS_MARKERS.some((m) => text.includes(m));
|
|
105
|
+
}
|
|
83
106
|
|
|
84
107
|
// src/keys/KeyDerivation.ts
|
|
85
108
|
import { generateSecretKey, getPublicKey } from "nostr-tools/pure";
|
|
@@ -2790,14 +2813,33 @@ var OnChainChannelClient = class {
|
|
|
2790
2813
|
};
|
|
2791
2814
|
}
|
|
2792
2815
|
/**
|
|
2793
|
-
* Opens an EVM payment channel on-chain
|
|
2816
|
+
* Opens an EVM payment channel on-chain, remapping the one-time
|
|
2817
|
+
* insufficient-native-gas revert into an actionable {@link ChannelFundingError}
|
|
2818
|
+
* so callers surface "fund the wallet" instead of the raw viem
|
|
2819
|
+
* "...exceeds the balance of the account" string (toon-meta#65). Only the gas
|
|
2820
|
+
* case is remapped; every other error propagates unchanged.
|
|
2821
|
+
*/
|
|
2822
|
+
async openEvmChannel(params) {
|
|
2823
|
+
try {
|
|
2824
|
+
return await this.openEvmChannelUnchecked(params);
|
|
2825
|
+
} catch (err) {
|
|
2826
|
+
if (!isInsufficientGasError(err)) throw err;
|
|
2827
|
+
const chainFamily = params.chain.split(":")[0] || params.chain;
|
|
2828
|
+
throw new ChannelFundingError(
|
|
2829
|
+
`Settlement wallet ${this.evmSigner.address} has no gas on ${chainFamily} to open a payment channel. Run toon_fund_wallet (or fund the wallet) and retry.`,
|
|
2830
|
+
err instanceof Error ? err : void 0
|
|
2831
|
+
);
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* Raw EVM channel-open (no gas-error remapping — see {@link openEvmChannel}).
|
|
2794
2836
|
*
|
|
2795
2837
|
* 1. Approve token spend if needed
|
|
2796
2838
|
* 2. Call TokenNetwork.openChannel()
|
|
2797
2839
|
* 3. Extract channelId from ChannelOpened event
|
|
2798
2840
|
* 4. Deposit initial funds if specified
|
|
2799
2841
|
*/
|
|
2800
|
-
async
|
|
2842
|
+
async openEvmChannelUnchecked(params) {
|
|
2801
2843
|
const {
|
|
2802
2844
|
chain,
|
|
2803
2845
|
tokenNetwork,
|
|
@@ -7100,6 +7142,7 @@ function writeKeystoreFile(path, keystore) {
|
|
|
7100
7142
|
}
|
|
7101
7143
|
export {
|
|
7102
7144
|
BtpRuntimeClient,
|
|
7145
|
+
ChannelFundingError,
|
|
7103
7146
|
ChannelManager,
|
|
7104
7147
|
ConnectorError,
|
|
7105
7148
|
EvmSigner,
|
|
@@ -7157,6 +7200,7 @@ export {
|
|
|
7157
7200
|
guardedRenderDispatch,
|
|
7158
7201
|
httpEndpointToBtpUrl,
|
|
7159
7202
|
importKeystore,
|
|
7203
|
+
isInsufficientGasError,
|
|
7160
7204
|
isPrfSupported,
|
|
7161
7205
|
isTrustDowngrade,
|
|
7162
7206
|
loadKeystore,
|