@blockrun/clawrouter 0.11.14 → 0.12.1

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
@@ -760,6 +760,8 @@ type WalletResolution = {
760
760
  source: "saved" | "env" | "generated";
761
761
  mnemonic?: string;
762
762
  solanaPrivateKeyBytes?: Uint8Array;
763
+ /** Legacy (secp256k1) Solana key bytes, present when migration is needed. */
764
+ legacySolanaKeyBytes?: Uint8Array;
763
765
  };
764
766
  /**
765
767
  * Set up Solana wallet for existing EVM-only users.
@@ -1050,6 +1052,9 @@ declare function formatDuration(seconds: number): string;
1050
1052
  *
1051
1053
  * BIP-39 mnemonic generation + BIP-44 HD key derivation for EVM and Solana.
1052
1054
  * Absorbed from @blockrun/clawwallet. No file I/O here - auth.ts handles persistence.
1055
+ *
1056
+ * Solana uses SLIP-10 Ed25519 derivation (Phantom/Solflare/Backpack compatible).
1057
+ * EVM uses standard BIP-32 secp256k1 derivation.
1053
1058
  */
1054
1059
  interface DerivedKeys {
1055
1060
  mnemonic: string;
@@ -1074,15 +1079,62 @@ declare function deriveEvmKey(mnemonic: string): {
1074
1079
  address: string;
1075
1080
  };
1076
1081
  /**
1077
- * Derive 32-byte Solana private key from a BIP-39 mnemonic.
1078
- * Path: m/44'/501'/0'/0' (standard Solana derivation)
1082
+ * Derive 32-byte Solana private key using SLIP-10 Ed25519 derivation.
1083
+ * Path: m/44'/501'/0'/0' (Phantom / Solflare / Backpack compatible)
1084
+ *
1085
+ * Algorithm (SLIP-0010 for Ed25519):
1086
+ * 1. Master: HMAC-SHA512(key="ed25519 seed", data=bip39_seed) → IL=key, IR=chainCode
1087
+ * 2. For each hardened child index:
1088
+ * HMAC-SHA512(key=chainCode, data=0x00 || key || ser32(index)) → split again
1089
+ * 3. Final IL (32 bytes) = Ed25519 private key seed
1079
1090
  */
1080
1091
  declare function deriveSolanaKeyBytes(mnemonic: string): Uint8Array;
1092
+ /**
1093
+ * Legacy Solana key derivation using secp256k1 BIP-32 (incorrect for Solana).
1094
+ * Kept for migration: sweeping funds from wallets derived with the old method.
1095
+ */
1096
+ declare function deriveSolanaKeyBytesLegacy(mnemonic: string): Uint8Array;
1081
1097
  /**
1082
1098
  * Derive both EVM and Solana keys from a single mnemonic.
1083
1099
  */
1084
1100
  declare function deriveAllKeys(mnemonic: string): DerivedKeys;
1085
1101
 
1102
+ /**
1103
+ * Solana Wallet Sweep — migrate USDC from legacy (secp256k1) to new (SLIP-10) wallet.
1104
+ *
1105
+ * Used when upgrading from the old BIP-32 secp256k1 derivation to correct
1106
+ * SLIP-10 Ed25519 derivation. Transfers all USDC from the old address to the new one.
1107
+ *
1108
+ * Uses raw instruction encoding to avoid @solana-program/token dependency.
1109
+ */
1110
+ type SweepResult = {
1111
+ transferred: string;
1112
+ transferredMicros: bigint;
1113
+ txSignature: string;
1114
+ oldAddress: string;
1115
+ newAddress: string;
1116
+ };
1117
+ type SweepError = {
1118
+ error: string;
1119
+ oldAddress: string;
1120
+ newAddress?: string;
1121
+ solBalance?: bigint;
1122
+ usdcBalance?: bigint;
1123
+ };
1124
+ /**
1125
+ * Sweep all USDC from old (legacy secp256k1) wallet to new (SLIP-10) wallet.
1126
+ *
1127
+ * The NEW wallet pays gas fees (not the old one). Users can't access the old
1128
+ * wallet from Phantom/Solflare, so they can't send SOL to it. Instead they
1129
+ * fund the new (Phantom-compatible) wallet with a tiny bit of SOL for gas.
1130
+ *
1131
+ * @param oldKeyBytes - 32-byte private key from legacy derivation
1132
+ * @param newKeyBytes - 32-byte private key from SLIP-10 derivation (pays gas)
1133
+ * @param rpcUrl - Optional RPC URL override
1134
+ * @returns SweepResult on success, SweepError on failure
1135
+ */
1136
+ declare function sweepSolanaWallet(oldKeyBytes: Uint8Array, newKeyBytes: Uint8Array, rpcUrl?: string): Promise<SweepResult | SweepError>;
1137
+
1086
1138
  /**
1087
1139
  * Typed Error Classes for ClawRouter
1088
1140
  *
@@ -1328,4 +1380,4 @@ declare function buildPartnerTools(proxyBaseUrl: string): PartnerToolDefinition[
1328
1380
 
1329
1381
  declare const plugin: OpenClawPluginDefinition;
1330
1382
 
1331
- export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PARTNER_SERVICES, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type Tier, type UsageEntry, type WalletConfig, type WalletResolution, blockrunProvider, buildPartnerTools, buildProviderModels, calculateModelCost, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, resolveModelAlias, resolvePaymentChain, route, savePaymentChain, setupSolana, startProxy };
1383
+ export { type AggregatedStats, BALANCE_THRESHOLDS, BLOCKRUN_MODELS, type BalanceInfo, BalanceMonitor, type CachedLLMResponse, type CachedResponse, type CheckResult, DEFAULT_RETRY_CONFIG, DEFAULT_ROUTING_CONFIG, DEFAULT_SESSION_CONFIG, type DailyStats, type DerivedKeys, EmptyWalletError, FileSpendControlStorage, InMemorySpendControlStorage, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, MODEL_ALIASES, OPENCLAW_MODELS, PARTNER_SERVICES, type PartnerServiceDefinition, type PartnerToolDefinition, type PaymentChain, type ProxyHandle, type ProxyOptions, RequestDeduplicator, ResponseCache, type ResponseCacheConfig, type RetryConfig, type RoutingConfig, type RoutingDecision, RpcError, type SessionConfig, type SessionEntry, SessionStore, type SolanaBalanceInfo, SolanaBalanceMonitor, SpendControl, type SpendControlOptions, type SpendControlStorage, type SpendLimits, type SpendRecord, type SpendWindow, type SpendingStatus, type SufficiencyResult, type SweepError, type SweepResult, type Tier, type UsageEntry, type WalletConfig, type WalletResolution, blockrunProvider, buildPartnerTools, buildProviderModels, calculateModelCost, plugin as default, deriveAllKeys, deriveEvmKey, deriveSolanaKeyBytes, deriveSolanaKeyBytesLegacy, fetchWithRetry, formatDuration, formatStatsAscii, generateWalletMnemonic, getAgenticModels, getFallbackChain, getFallbackChainFiltered, getModelContextWindow, getPartnerService, getProxyPort, getSessionId, getStats, hashRequestContent, isAgenticModel, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, isValidMnemonic, loadPaymentChain, logUsage, resolveModelAlias, resolvePaymentChain, route, savePaymentChain, setupSolana, startProxy, sweepSolanaWallet };