@blockrun/clawrouter 0.11.14 → 0.12.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/README.md +6 -6
- package/dist/cli.js +619 -47
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +51 -3
- package/dist/index.js +965 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -53,7 +53,8 @@ function createPayFetchWithPreAuth(baseFetch, client, ttlMs = DEFAULT_TTL_MS, op
|
|
|
53
53
|
cache.set(urlPath, { paymentRequired, cachedAt: Date.now() });
|
|
54
54
|
} catch (error) {
|
|
55
55
|
throw new Error(
|
|
56
|
-
`Failed to parse payment requirements: ${error instanceof Error ? error.message : "Unknown error"}
|
|
56
|
+
`Failed to parse payment requirements: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
57
|
+
{ cause: error }
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
60
|
const payload = await client.createPaymentPayload(paymentRequired);
|
|
@@ -2982,7 +2983,10 @@ var SolanaBalanceMonitor = class {
|
|
|
2982
2983
|
}
|
|
2983
2984
|
return total;
|
|
2984
2985
|
} catch (err) {
|
|
2985
|
-
throw new Error(
|
|
2986
|
+
throw new Error(
|
|
2987
|
+
`Failed to fetch Solana USDC balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
2988
|
+
{ cause: err }
|
|
2989
|
+
);
|
|
2986
2990
|
} finally {
|
|
2987
2991
|
clearTimeout(timer);
|
|
2988
2992
|
}
|
|
@@ -3009,9 +3013,507 @@ import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
|
3009
3013
|
import { HDKey } from "@scure/bip32";
|
|
3010
3014
|
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic } from "@scure/bip39";
|
|
3011
3015
|
import { wordlist as english } from "@scure/bip39/wordlists/english";
|
|
3016
|
+
|
|
3017
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
3018
|
+
function isBytes(a) {
|
|
3019
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
3020
|
+
}
|
|
3021
|
+
function anumber(n) {
|
|
3022
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
3023
|
+
throw new Error("positive integer expected, got " + n);
|
|
3024
|
+
}
|
|
3025
|
+
function abytes(b, ...lengths) {
|
|
3026
|
+
if (!isBytes(b))
|
|
3027
|
+
throw new Error("Uint8Array expected");
|
|
3028
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
3029
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
3030
|
+
}
|
|
3031
|
+
function ahash(h) {
|
|
3032
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
3033
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
3034
|
+
anumber(h.outputLen);
|
|
3035
|
+
anumber(h.blockLen);
|
|
3036
|
+
}
|
|
3037
|
+
function aexists(instance, checkFinished = true) {
|
|
3038
|
+
if (instance.destroyed)
|
|
3039
|
+
throw new Error("Hash instance has been destroyed");
|
|
3040
|
+
if (checkFinished && instance.finished)
|
|
3041
|
+
throw new Error("Hash#digest() has already been called");
|
|
3042
|
+
}
|
|
3043
|
+
function aoutput(out, instance) {
|
|
3044
|
+
abytes(out);
|
|
3045
|
+
const min = instance.outputLen;
|
|
3046
|
+
if (out.length < min) {
|
|
3047
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
function clean(...arrays) {
|
|
3051
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
3052
|
+
arrays[i].fill(0);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
function createView(arr) {
|
|
3056
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
3057
|
+
}
|
|
3058
|
+
function utf8ToBytes(str) {
|
|
3059
|
+
if (typeof str !== "string")
|
|
3060
|
+
throw new Error("string expected");
|
|
3061
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
3062
|
+
}
|
|
3063
|
+
function toBytes(data) {
|
|
3064
|
+
if (typeof data === "string")
|
|
3065
|
+
data = utf8ToBytes(data);
|
|
3066
|
+
abytes(data);
|
|
3067
|
+
return data;
|
|
3068
|
+
}
|
|
3069
|
+
var Hash = class {
|
|
3070
|
+
};
|
|
3071
|
+
function createHasher(hashCons) {
|
|
3072
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
3073
|
+
const tmp = hashCons();
|
|
3074
|
+
hashC.outputLen = tmp.outputLen;
|
|
3075
|
+
hashC.blockLen = tmp.blockLen;
|
|
3076
|
+
hashC.create = () => hashCons();
|
|
3077
|
+
return hashC;
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
// node_modules/@noble/hashes/esm/hmac.js
|
|
3081
|
+
var HMAC = class extends Hash {
|
|
3082
|
+
constructor(hash, _key) {
|
|
3083
|
+
super();
|
|
3084
|
+
this.finished = false;
|
|
3085
|
+
this.destroyed = false;
|
|
3086
|
+
ahash(hash);
|
|
3087
|
+
const key = toBytes(_key);
|
|
3088
|
+
this.iHash = hash.create();
|
|
3089
|
+
if (typeof this.iHash.update !== "function")
|
|
3090
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
3091
|
+
this.blockLen = this.iHash.blockLen;
|
|
3092
|
+
this.outputLen = this.iHash.outputLen;
|
|
3093
|
+
const blockLen = this.blockLen;
|
|
3094
|
+
const pad = new Uint8Array(blockLen);
|
|
3095
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
3096
|
+
for (let i = 0; i < pad.length; i++)
|
|
3097
|
+
pad[i] ^= 54;
|
|
3098
|
+
this.iHash.update(pad);
|
|
3099
|
+
this.oHash = hash.create();
|
|
3100
|
+
for (let i = 0; i < pad.length; i++)
|
|
3101
|
+
pad[i] ^= 54 ^ 92;
|
|
3102
|
+
this.oHash.update(pad);
|
|
3103
|
+
clean(pad);
|
|
3104
|
+
}
|
|
3105
|
+
update(buf) {
|
|
3106
|
+
aexists(this);
|
|
3107
|
+
this.iHash.update(buf);
|
|
3108
|
+
return this;
|
|
3109
|
+
}
|
|
3110
|
+
digestInto(out) {
|
|
3111
|
+
aexists(this);
|
|
3112
|
+
abytes(out, this.outputLen);
|
|
3113
|
+
this.finished = true;
|
|
3114
|
+
this.iHash.digestInto(out);
|
|
3115
|
+
this.oHash.update(out);
|
|
3116
|
+
this.oHash.digestInto(out);
|
|
3117
|
+
this.destroy();
|
|
3118
|
+
}
|
|
3119
|
+
digest() {
|
|
3120
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
3121
|
+
this.digestInto(out);
|
|
3122
|
+
return out;
|
|
3123
|
+
}
|
|
3124
|
+
_cloneInto(to) {
|
|
3125
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
3126
|
+
const { oHash, iHash, finished: finished2, destroyed, blockLen, outputLen } = this;
|
|
3127
|
+
to = to;
|
|
3128
|
+
to.finished = finished2;
|
|
3129
|
+
to.destroyed = destroyed;
|
|
3130
|
+
to.blockLen = blockLen;
|
|
3131
|
+
to.outputLen = outputLen;
|
|
3132
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
3133
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
3134
|
+
return to;
|
|
3135
|
+
}
|
|
3136
|
+
clone() {
|
|
3137
|
+
return this._cloneInto();
|
|
3138
|
+
}
|
|
3139
|
+
destroy() {
|
|
3140
|
+
this.destroyed = true;
|
|
3141
|
+
this.oHash.destroy();
|
|
3142
|
+
this.iHash.destroy();
|
|
3143
|
+
}
|
|
3144
|
+
};
|
|
3145
|
+
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
3146
|
+
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
3147
|
+
|
|
3148
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
3149
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
3150
|
+
if (typeof view.setBigUint64 === "function")
|
|
3151
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
3152
|
+
const _32n2 = BigInt(32);
|
|
3153
|
+
const _u32_max = BigInt(4294967295);
|
|
3154
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
3155
|
+
const wl = Number(value & _u32_max);
|
|
3156
|
+
const h = isLE ? 4 : 0;
|
|
3157
|
+
const l = isLE ? 0 : 4;
|
|
3158
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
3159
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
3160
|
+
}
|
|
3161
|
+
var HashMD = class extends Hash {
|
|
3162
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
3163
|
+
super();
|
|
3164
|
+
this.finished = false;
|
|
3165
|
+
this.length = 0;
|
|
3166
|
+
this.pos = 0;
|
|
3167
|
+
this.destroyed = false;
|
|
3168
|
+
this.blockLen = blockLen;
|
|
3169
|
+
this.outputLen = outputLen;
|
|
3170
|
+
this.padOffset = padOffset;
|
|
3171
|
+
this.isLE = isLE;
|
|
3172
|
+
this.buffer = new Uint8Array(blockLen);
|
|
3173
|
+
this.view = createView(this.buffer);
|
|
3174
|
+
}
|
|
3175
|
+
update(data) {
|
|
3176
|
+
aexists(this);
|
|
3177
|
+
data = toBytes(data);
|
|
3178
|
+
abytes(data);
|
|
3179
|
+
const { view, buffer, blockLen } = this;
|
|
3180
|
+
const len = data.length;
|
|
3181
|
+
for (let pos = 0; pos < len; ) {
|
|
3182
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
3183
|
+
if (take === blockLen) {
|
|
3184
|
+
const dataView = createView(data);
|
|
3185
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
3186
|
+
this.process(dataView, pos);
|
|
3187
|
+
continue;
|
|
3188
|
+
}
|
|
3189
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
3190
|
+
this.pos += take;
|
|
3191
|
+
pos += take;
|
|
3192
|
+
if (this.pos === blockLen) {
|
|
3193
|
+
this.process(view, 0);
|
|
3194
|
+
this.pos = 0;
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
this.length += data.length;
|
|
3198
|
+
this.roundClean();
|
|
3199
|
+
return this;
|
|
3200
|
+
}
|
|
3201
|
+
digestInto(out) {
|
|
3202
|
+
aexists(this);
|
|
3203
|
+
aoutput(out, this);
|
|
3204
|
+
this.finished = true;
|
|
3205
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
3206
|
+
let { pos } = this;
|
|
3207
|
+
buffer[pos++] = 128;
|
|
3208
|
+
clean(this.buffer.subarray(pos));
|
|
3209
|
+
if (this.padOffset > blockLen - pos) {
|
|
3210
|
+
this.process(view, 0);
|
|
3211
|
+
pos = 0;
|
|
3212
|
+
}
|
|
3213
|
+
for (let i = pos; i < blockLen; i++)
|
|
3214
|
+
buffer[i] = 0;
|
|
3215
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
3216
|
+
this.process(view, 0);
|
|
3217
|
+
const oview = createView(out);
|
|
3218
|
+
const len = this.outputLen;
|
|
3219
|
+
if (len % 4)
|
|
3220
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
3221
|
+
const outLen = len / 4;
|
|
3222
|
+
const state = this.get();
|
|
3223
|
+
if (outLen > state.length)
|
|
3224
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
3225
|
+
for (let i = 0; i < outLen; i++)
|
|
3226
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
3227
|
+
}
|
|
3228
|
+
digest() {
|
|
3229
|
+
const { buffer, outputLen } = this;
|
|
3230
|
+
this.digestInto(buffer);
|
|
3231
|
+
const res = buffer.slice(0, outputLen);
|
|
3232
|
+
this.destroy();
|
|
3233
|
+
return res;
|
|
3234
|
+
}
|
|
3235
|
+
_cloneInto(to) {
|
|
3236
|
+
to || (to = new this.constructor());
|
|
3237
|
+
to.set(...this.get());
|
|
3238
|
+
const { blockLen, buffer, length, finished: finished2, destroyed, pos } = this;
|
|
3239
|
+
to.destroyed = destroyed;
|
|
3240
|
+
to.finished = finished2;
|
|
3241
|
+
to.length = length;
|
|
3242
|
+
to.pos = pos;
|
|
3243
|
+
if (length % blockLen)
|
|
3244
|
+
to.buffer.set(buffer);
|
|
3245
|
+
return to;
|
|
3246
|
+
}
|
|
3247
|
+
clone() {
|
|
3248
|
+
return this._cloneInto();
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
3251
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
3252
|
+
1779033703,
|
|
3253
|
+
4089235720,
|
|
3254
|
+
3144134277,
|
|
3255
|
+
2227873595,
|
|
3256
|
+
1013904242,
|
|
3257
|
+
4271175723,
|
|
3258
|
+
2773480762,
|
|
3259
|
+
1595750129,
|
|
3260
|
+
1359893119,
|
|
3261
|
+
2917565137,
|
|
3262
|
+
2600822924,
|
|
3263
|
+
725511199,
|
|
3264
|
+
528734635,
|
|
3265
|
+
4215389547,
|
|
3266
|
+
1541459225,
|
|
3267
|
+
327033209
|
|
3268
|
+
]);
|
|
3269
|
+
|
|
3270
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
3271
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
3272
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
3273
|
+
function fromBig(n, le = false) {
|
|
3274
|
+
if (le)
|
|
3275
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
3276
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
3277
|
+
}
|
|
3278
|
+
function split(lst, le = false) {
|
|
3279
|
+
const len = lst.length;
|
|
3280
|
+
let Ah = new Uint32Array(len);
|
|
3281
|
+
let Al = new Uint32Array(len);
|
|
3282
|
+
for (let i = 0; i < len; i++) {
|
|
3283
|
+
const { h, l } = fromBig(lst[i], le);
|
|
3284
|
+
[Ah[i], Al[i]] = [h, l];
|
|
3285
|
+
}
|
|
3286
|
+
return [Ah, Al];
|
|
3287
|
+
}
|
|
3288
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
3289
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
3290
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
3291
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
3292
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
3293
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
3294
|
+
function add(Ah, Al, Bh, Bl) {
|
|
3295
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
3296
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
3297
|
+
}
|
|
3298
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
3299
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
3300
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
3301
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
3302
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
3303
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
3304
|
+
|
|
3305
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
3306
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
3307
|
+
"0x428a2f98d728ae22",
|
|
3308
|
+
"0x7137449123ef65cd",
|
|
3309
|
+
"0xb5c0fbcfec4d3b2f",
|
|
3310
|
+
"0xe9b5dba58189dbbc",
|
|
3311
|
+
"0x3956c25bf348b538",
|
|
3312
|
+
"0x59f111f1b605d019",
|
|
3313
|
+
"0x923f82a4af194f9b",
|
|
3314
|
+
"0xab1c5ed5da6d8118",
|
|
3315
|
+
"0xd807aa98a3030242",
|
|
3316
|
+
"0x12835b0145706fbe",
|
|
3317
|
+
"0x243185be4ee4b28c",
|
|
3318
|
+
"0x550c7dc3d5ffb4e2",
|
|
3319
|
+
"0x72be5d74f27b896f",
|
|
3320
|
+
"0x80deb1fe3b1696b1",
|
|
3321
|
+
"0x9bdc06a725c71235",
|
|
3322
|
+
"0xc19bf174cf692694",
|
|
3323
|
+
"0xe49b69c19ef14ad2",
|
|
3324
|
+
"0xefbe4786384f25e3",
|
|
3325
|
+
"0x0fc19dc68b8cd5b5",
|
|
3326
|
+
"0x240ca1cc77ac9c65",
|
|
3327
|
+
"0x2de92c6f592b0275",
|
|
3328
|
+
"0x4a7484aa6ea6e483",
|
|
3329
|
+
"0x5cb0a9dcbd41fbd4",
|
|
3330
|
+
"0x76f988da831153b5",
|
|
3331
|
+
"0x983e5152ee66dfab",
|
|
3332
|
+
"0xa831c66d2db43210",
|
|
3333
|
+
"0xb00327c898fb213f",
|
|
3334
|
+
"0xbf597fc7beef0ee4",
|
|
3335
|
+
"0xc6e00bf33da88fc2",
|
|
3336
|
+
"0xd5a79147930aa725",
|
|
3337
|
+
"0x06ca6351e003826f",
|
|
3338
|
+
"0x142929670a0e6e70",
|
|
3339
|
+
"0x27b70a8546d22ffc",
|
|
3340
|
+
"0x2e1b21385c26c926",
|
|
3341
|
+
"0x4d2c6dfc5ac42aed",
|
|
3342
|
+
"0x53380d139d95b3df",
|
|
3343
|
+
"0x650a73548baf63de",
|
|
3344
|
+
"0x766a0abb3c77b2a8",
|
|
3345
|
+
"0x81c2c92e47edaee6",
|
|
3346
|
+
"0x92722c851482353b",
|
|
3347
|
+
"0xa2bfe8a14cf10364",
|
|
3348
|
+
"0xa81a664bbc423001",
|
|
3349
|
+
"0xc24b8b70d0f89791",
|
|
3350
|
+
"0xc76c51a30654be30",
|
|
3351
|
+
"0xd192e819d6ef5218",
|
|
3352
|
+
"0xd69906245565a910",
|
|
3353
|
+
"0xf40e35855771202a",
|
|
3354
|
+
"0x106aa07032bbd1b8",
|
|
3355
|
+
"0x19a4c116b8d2d0c8",
|
|
3356
|
+
"0x1e376c085141ab53",
|
|
3357
|
+
"0x2748774cdf8eeb99",
|
|
3358
|
+
"0x34b0bcb5e19b48a8",
|
|
3359
|
+
"0x391c0cb3c5c95a63",
|
|
3360
|
+
"0x4ed8aa4ae3418acb",
|
|
3361
|
+
"0x5b9cca4f7763e373",
|
|
3362
|
+
"0x682e6ff3d6b2b8a3",
|
|
3363
|
+
"0x748f82ee5defb2fc",
|
|
3364
|
+
"0x78a5636f43172f60",
|
|
3365
|
+
"0x84c87814a1f0ab72",
|
|
3366
|
+
"0x8cc702081a6439ec",
|
|
3367
|
+
"0x90befffa23631e28",
|
|
3368
|
+
"0xa4506cebde82bde9",
|
|
3369
|
+
"0xbef9a3f7b2c67915",
|
|
3370
|
+
"0xc67178f2e372532b",
|
|
3371
|
+
"0xca273eceea26619c",
|
|
3372
|
+
"0xd186b8c721c0c207",
|
|
3373
|
+
"0xeada7dd6cde0eb1e",
|
|
3374
|
+
"0xf57d4f7fee6ed178",
|
|
3375
|
+
"0x06f067aa72176fba",
|
|
3376
|
+
"0x0a637dc5a2c898a6",
|
|
3377
|
+
"0x113f9804bef90dae",
|
|
3378
|
+
"0x1b710b35131c471b",
|
|
3379
|
+
"0x28db77f523047d84",
|
|
3380
|
+
"0x32caab7b40c72493",
|
|
3381
|
+
"0x3c9ebe0a15c9bebc",
|
|
3382
|
+
"0x431d67c49c100d4c",
|
|
3383
|
+
"0x4cc5d4becb3e42b6",
|
|
3384
|
+
"0x597f299cfc657e2a",
|
|
3385
|
+
"0x5fcb6fab3ad6faec",
|
|
3386
|
+
"0x6c44198c4a475817"
|
|
3387
|
+
].map((n) => BigInt(n))))();
|
|
3388
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
3389
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
3390
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
3391
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
3392
|
+
var SHA512 = class extends HashMD {
|
|
3393
|
+
constructor(outputLen = 64) {
|
|
3394
|
+
super(128, outputLen, 16, false);
|
|
3395
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
3396
|
+
this.Al = SHA512_IV[1] | 0;
|
|
3397
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
3398
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
3399
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
3400
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
3401
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
3402
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
3403
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
3404
|
+
this.El = SHA512_IV[9] | 0;
|
|
3405
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
3406
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
3407
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
3408
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
3409
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
3410
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
3411
|
+
}
|
|
3412
|
+
// prettier-ignore
|
|
3413
|
+
get() {
|
|
3414
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
3415
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
3416
|
+
}
|
|
3417
|
+
// prettier-ignore
|
|
3418
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
3419
|
+
this.Ah = Ah | 0;
|
|
3420
|
+
this.Al = Al | 0;
|
|
3421
|
+
this.Bh = Bh | 0;
|
|
3422
|
+
this.Bl = Bl | 0;
|
|
3423
|
+
this.Ch = Ch | 0;
|
|
3424
|
+
this.Cl = Cl | 0;
|
|
3425
|
+
this.Dh = Dh | 0;
|
|
3426
|
+
this.Dl = Dl | 0;
|
|
3427
|
+
this.Eh = Eh | 0;
|
|
3428
|
+
this.El = El | 0;
|
|
3429
|
+
this.Fh = Fh | 0;
|
|
3430
|
+
this.Fl = Fl | 0;
|
|
3431
|
+
this.Gh = Gh | 0;
|
|
3432
|
+
this.Gl = Gl | 0;
|
|
3433
|
+
this.Hh = Hh | 0;
|
|
3434
|
+
this.Hl = Hl | 0;
|
|
3435
|
+
}
|
|
3436
|
+
process(view, offset) {
|
|
3437
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
3438
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
3439
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
3440
|
+
}
|
|
3441
|
+
for (let i = 16; i < 80; i++) {
|
|
3442
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
3443
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
3444
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
3445
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
3446
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
3447
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
3448
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
3449
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
3450
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
3451
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
3452
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
3453
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
3454
|
+
}
|
|
3455
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
3456
|
+
for (let i = 0; i < 80; i++) {
|
|
3457
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
3458
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
3459
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
3460
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
3461
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
3462
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
3463
|
+
const T1l = T1ll | 0;
|
|
3464
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
3465
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
3466
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
3467
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
3468
|
+
Hh = Gh | 0;
|
|
3469
|
+
Hl = Gl | 0;
|
|
3470
|
+
Gh = Fh | 0;
|
|
3471
|
+
Gl = Fl | 0;
|
|
3472
|
+
Fh = Eh | 0;
|
|
3473
|
+
Fl = El | 0;
|
|
3474
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
3475
|
+
Dh = Ch | 0;
|
|
3476
|
+
Dl = Cl | 0;
|
|
3477
|
+
Ch = Bh | 0;
|
|
3478
|
+
Cl = Bl | 0;
|
|
3479
|
+
Bh = Ah | 0;
|
|
3480
|
+
Bl = Al | 0;
|
|
3481
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
3482
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
3483
|
+
Al = All | 0;
|
|
3484
|
+
}
|
|
3485
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
3486
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
3487
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
3488
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
3489
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
3490
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
3491
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
3492
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
3493
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
3494
|
+
}
|
|
3495
|
+
roundClean() {
|
|
3496
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
3497
|
+
}
|
|
3498
|
+
destroy() {
|
|
3499
|
+
clean(this.buffer);
|
|
3500
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
3501
|
+
}
|
|
3502
|
+
};
|
|
3503
|
+
var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
3504
|
+
|
|
3505
|
+
// node_modules/@noble/hashes/esm/sha512.js
|
|
3506
|
+
var sha5122 = sha512;
|
|
3507
|
+
|
|
3508
|
+
// src/wallet.ts
|
|
3012
3509
|
import { privateKeyToAccount } from "viem/accounts";
|
|
3013
3510
|
var ETH_DERIVATION_PATH = "m/44'/60'/0'/0/0";
|
|
3014
|
-
var
|
|
3511
|
+
var SOLANA_HARDENED_INDICES = [
|
|
3512
|
+
44 + 2147483648,
|
|
3513
|
+
501 + 2147483648,
|
|
3514
|
+
0 + 2147483648,
|
|
3515
|
+
0 + 2147483648
|
|
3516
|
+
];
|
|
3015
3517
|
function generateWalletMnemonic() {
|
|
3016
3518
|
return generateMnemonic(english, 256);
|
|
3017
3519
|
}
|
|
@@ -3028,10 +3530,29 @@ function deriveEvmKey(mnemonic) {
|
|
|
3028
3530
|
return { privateKey: hex, address: account.address };
|
|
3029
3531
|
}
|
|
3030
3532
|
function deriveSolanaKeyBytes(mnemonic) {
|
|
3533
|
+
const seed = mnemonicToSeedSync(mnemonic);
|
|
3534
|
+
let I = hmac(sha5122, "ed25519 seed", seed);
|
|
3535
|
+
let key = I.slice(0, 32);
|
|
3536
|
+
let chainCode = I.slice(32);
|
|
3537
|
+
for (const index of SOLANA_HARDENED_INDICES) {
|
|
3538
|
+
const data = new Uint8Array(37);
|
|
3539
|
+
data[0] = 0;
|
|
3540
|
+
data.set(key, 1);
|
|
3541
|
+
data[33] = index >>> 24 & 255;
|
|
3542
|
+
data[34] = index >>> 16 & 255;
|
|
3543
|
+
data[35] = index >>> 8 & 255;
|
|
3544
|
+
data[36] = index & 255;
|
|
3545
|
+
I = hmac(sha5122, chainCode, data);
|
|
3546
|
+
key = I.slice(0, 32);
|
|
3547
|
+
chainCode = I.slice(32);
|
|
3548
|
+
}
|
|
3549
|
+
return new Uint8Array(key);
|
|
3550
|
+
}
|
|
3551
|
+
function deriveSolanaKeyBytesLegacy(mnemonic) {
|
|
3031
3552
|
const seed = mnemonicToSeedSync(mnemonic);
|
|
3032
3553
|
const hdKey = HDKey.fromMasterSeed(seed);
|
|
3033
|
-
const derived = hdKey.derive(
|
|
3034
|
-
if (!derived.privateKey) throw new Error("Failed to derive Solana private key");
|
|
3554
|
+
const derived = hdKey.derive("m/44'/501'/0'/0'");
|
|
3555
|
+
if (!derived.privateKey) throw new Error("Failed to derive legacy Solana private key");
|
|
3035
3556
|
return new Uint8Array(derived.privateKey);
|
|
3036
3557
|
}
|
|
3037
3558
|
function deriveAllKeys(mnemonic) {
|
|
@@ -3139,6 +3660,29 @@ async function generateAndSaveWallet() {
|
|
|
3139
3660
|
solanaPrivateKeyBytes: derived.solanaPrivateKeyBytes
|
|
3140
3661
|
};
|
|
3141
3662
|
}
|
|
3663
|
+
async function logMigrationWarning(legacyKeyBytes, newKeyBytes) {
|
|
3664
|
+
try {
|
|
3665
|
+
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
3666
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
3667
|
+
createKeyPairSignerFromPrivateKeyBytes(legacyKeyBytes),
|
|
3668
|
+
createKeyPairSignerFromPrivateKeyBytes(newKeyBytes)
|
|
3669
|
+
]);
|
|
3670
|
+
console.log(`[ClawRouter]`);
|
|
3671
|
+
console.log(`[ClawRouter] \u26A0 SOLANA WALLET MIGRATION DETECTED`);
|
|
3672
|
+
console.log(`[ClawRouter] \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|
|
3673
|
+
console.log(`[ClawRouter] Old address (secp256k1): ${oldSigner.address}`);
|
|
3674
|
+
console.log(`[ClawRouter] New address (SLIP-10): ${newSigner.address}`);
|
|
3675
|
+
console.log(`[ClawRouter]`);
|
|
3676
|
+
console.log(`[ClawRouter] Your Solana wallet derivation has been fixed to use`);
|
|
3677
|
+
console.log(`[ClawRouter] SLIP-10 Ed25519 (Phantom/Solflare compatible).`);
|
|
3678
|
+
console.log(`[ClawRouter]`);
|
|
3679
|
+
console.log(`[ClawRouter] If you had funds in the old wallet, run:`);
|
|
3680
|
+
console.log(`[ClawRouter] /wallet migrate-solana`);
|
|
3681
|
+
console.log(`[ClawRouter] \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|
|
3682
|
+
console.log(`[ClawRouter]`);
|
|
3683
|
+
} catch {
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3142
3686
|
async function resolveOrGenerateWalletKey() {
|
|
3143
3687
|
const saved = await loadSavedWallet();
|
|
3144
3688
|
if (saved) {
|
|
@@ -3146,13 +3690,19 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3146
3690
|
const mnemonic = await loadMnemonic();
|
|
3147
3691
|
if (mnemonic) {
|
|
3148
3692
|
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
3149
|
-
|
|
3693
|
+
const result2 = {
|
|
3150
3694
|
key: saved,
|
|
3151
3695
|
address: account.address,
|
|
3152
3696
|
source: "saved",
|
|
3153
3697
|
mnemonic,
|
|
3154
3698
|
solanaPrivateKeyBytes: solanaKeyBytes
|
|
3155
3699
|
};
|
|
3700
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy(mnemonic);
|
|
3701
|
+
if (Buffer.from(legacyKeyBytes).toString("hex") !== Buffer.from(solanaKeyBytes).toString("hex")) {
|
|
3702
|
+
result2.legacySolanaKeyBytes = legacyKeyBytes;
|
|
3703
|
+
await logMigrationWarning(legacyKeyBytes, solanaKeyBytes);
|
|
3704
|
+
}
|
|
3705
|
+
return result2;
|
|
3156
3706
|
}
|
|
3157
3707
|
return { key: saved, address: account.address, source: "saved" };
|
|
3158
3708
|
}
|
|
@@ -3162,13 +3712,19 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3162
3712
|
const mnemonic = await loadMnemonic();
|
|
3163
3713
|
if (mnemonic) {
|
|
3164
3714
|
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
3165
|
-
|
|
3715
|
+
const result2 = {
|
|
3166
3716
|
key: envKey,
|
|
3167
3717
|
address: account.address,
|
|
3168
3718
|
source: "env",
|
|
3169
3719
|
mnemonic,
|
|
3170
3720
|
solanaPrivateKeyBytes: solanaKeyBytes
|
|
3171
3721
|
};
|
|
3722
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy(mnemonic);
|
|
3723
|
+
if (Buffer.from(legacyKeyBytes).toString("hex") !== Buffer.from(solanaKeyBytes).toString("hex")) {
|
|
3724
|
+
result2.legacySolanaKeyBytes = legacyKeyBytes;
|
|
3725
|
+
await logMigrationWarning(legacyKeyBytes, solanaKeyBytes);
|
|
3726
|
+
}
|
|
3727
|
+
return result2;
|
|
3172
3728
|
}
|
|
3173
3729
|
return { key: envKey, address: account.address, source: "env" };
|
|
3174
3730
|
}
|
|
@@ -4906,7 +5462,9 @@ async function startProxy(options) {
|
|
|
4906
5462
|
const paymentChain = options.paymentChain ?? await resolvePaymentChain();
|
|
4907
5463
|
const apiBase = options.apiBase ?? (paymentChain === "solana" && solanaPrivateKeyBytes ? BLOCKRUN_SOLANA_API : BLOCKRUN_API);
|
|
4908
5464
|
if (paymentChain === "solana" && !solanaPrivateKeyBytes) {
|
|
4909
|
-
console.warn(
|
|
5465
|
+
console.warn(
|
|
5466
|
+
`[ClawRouter] Payment chain is Solana but no Solana keys provided. Using Base (EVM).`
|
|
5467
|
+
);
|
|
4910
5468
|
} else if (paymentChain === "solana") {
|
|
4911
5469
|
console.log(`[ClawRouter] Payment chain: Solana (${BLOCKRUN_SOLANA_API})`);
|
|
4912
5470
|
}
|
|
@@ -4927,7 +5485,9 @@ async function startProxy(options) {
|
|
|
4927
5485
|
);
|
|
4928
5486
|
}
|
|
4929
5487
|
} else if (paymentChain !== "base") {
|
|
4930
|
-
console.warn(
|
|
5488
|
+
console.warn(
|
|
5489
|
+
`[ClawRouter] Existing proxy on port ${listenPort} does not report paymentChain (pre-v0.11 instance). Assuming Base.`
|
|
5490
|
+
);
|
|
4931
5491
|
throw new Error(
|
|
4932
5492
|
`Existing proxy on port ${listenPort} is a pre-v0.11 instance (assumed Base) but ${paymentChain} was requested. Stop the existing proxy first or use a different port.`
|
|
4933
5493
|
);
|
|
@@ -5126,7 +5686,11 @@ async function startProxy(options) {
|
|
|
5126
5686
|
const existingProxy2 = await checkExistingProxy(listenPort);
|
|
5127
5687
|
if (existingProxy2) {
|
|
5128
5688
|
console.log(`[ClawRouter] Existing proxy detected on port ${listenPort}, reusing`);
|
|
5129
|
-
rejectAttempt({
|
|
5689
|
+
rejectAttempt({
|
|
5690
|
+
code: "REUSE_EXISTING",
|
|
5691
|
+
wallet: existingProxy2.wallet,
|
|
5692
|
+
existingChain: existingProxy2.paymentChain
|
|
5693
|
+
});
|
|
5130
5694
|
return;
|
|
5131
5695
|
}
|
|
5132
5696
|
if (attempt < PORT_RETRY_ATTEMPTS) {
|
|
@@ -5161,7 +5725,8 @@ async function startProxy(options) {
|
|
|
5161
5725
|
if (error.code === "REUSE_EXISTING" && error.wallet) {
|
|
5162
5726
|
if (error.existingChain && error.existingChain !== paymentChain) {
|
|
5163
5727
|
throw new Error(
|
|
5164
|
-
`Existing proxy on port ${listenPort} is using ${error.existingChain} but ${paymentChain} was requested. Stop the existing proxy first or use a different port
|
|
5728
|
+
`Existing proxy on port ${listenPort} is using ${error.existingChain} but ${paymentChain} was requested. Stop the existing proxy first or use a different port.`,
|
|
5729
|
+
{ cause: err }
|
|
5165
5730
|
);
|
|
5166
5731
|
}
|
|
5167
5732
|
const baseUrl2 = `http://127.0.0.1:${listenPort}`;
|
|
@@ -5269,15 +5834,12 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
|
|
|
5269
5834
|
} catch {
|
|
5270
5835
|
}
|
|
5271
5836
|
try {
|
|
5272
|
-
const response = await payFetch(
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
signal
|
|
5279
|
-
}
|
|
5280
|
-
);
|
|
5837
|
+
const response = await payFetch(upstreamUrl, {
|
|
5838
|
+
method,
|
|
5839
|
+
headers,
|
|
5840
|
+
body: requestBody.length > 0 ? new Uint8Array(requestBody) : void 0,
|
|
5841
|
+
signal
|
|
5842
|
+
});
|
|
5281
5843
|
if (response.status !== 200) {
|
|
5282
5844
|
const errorBody = await response.text();
|
|
5283
5845
|
const isProviderErr = isProviderError(response.status, errorBody);
|
|
@@ -6228,7 +6790,14 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6228
6790
|
if (balanceFallbackNotice) {
|
|
6229
6791
|
const noticeChunk = {
|
|
6230
6792
|
...baseChunk,
|
|
6231
|
-
choices: [
|
|
6793
|
+
choices: [
|
|
6794
|
+
{
|
|
6795
|
+
index,
|
|
6796
|
+
delta: { content: balanceFallbackNotice },
|
|
6797
|
+
logprobs: null,
|
|
6798
|
+
finish_reason: null
|
|
6799
|
+
}
|
|
6800
|
+
]
|
|
6232
6801
|
};
|
|
6233
6802
|
const noticeData = `data: ${JSON.stringify(noticeChunk)}
|
|
6234
6803
|
|
|
@@ -6697,28 +7266,26 @@ async function analyzeWithAI(diagnostics, userQuestion, model = "sonnet") {
|
|
|
6697
7266
|
const x402 = new x402Client2();
|
|
6698
7267
|
registerExactEvmScheme2(x402, { signer: evmSigner });
|
|
6699
7268
|
const paymentFetch = wrapFetchWithPayment(fetch, x402);
|
|
6700
|
-
const response = await paymentFetch(
|
|
6701
|
-
"
|
|
6702
|
-
{
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
role: "system",
|
|
6711
|
-
content: `You are a technical support expert for BlockRun and ClawRouter.
|
|
7269
|
+
const response = await paymentFetch("https://blockrun.ai/api/v1/chat/completions", {
|
|
7270
|
+
method: "POST",
|
|
7271
|
+
headers: { "Content-Type": "application/json" },
|
|
7272
|
+
body: JSON.stringify({
|
|
7273
|
+
model: modelConfig.id,
|
|
7274
|
+
stream: false,
|
|
7275
|
+
messages: [
|
|
7276
|
+
{
|
|
7277
|
+
role: "system",
|
|
7278
|
+
content: `You are a technical support expert for BlockRun and ClawRouter.
|
|
6712
7279
|
Analyze the diagnostics and:
|
|
6713
7280
|
1. Identify the root cause of any issues
|
|
6714
7281
|
2. Provide specific, actionable fix commands (bash)
|
|
6715
7282
|
3. Explain why the issue occurred briefly
|
|
6716
7283
|
4. Be concise but thorough
|
|
6717
7284
|
5. Format commands in code blocks`
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
7285
|
+
},
|
|
7286
|
+
{
|
|
7287
|
+
role: "user",
|
|
7288
|
+
content: userQuestion ? `Here are my system diagnostics:
|
|
6722
7289
|
|
|
6723
7290
|
${JSON.stringify(diagnostics, null, 2)}
|
|
6724
7291
|
|
|
@@ -6727,12 +7294,11 @@ User's question: ${userQuestion}` : `Here are my system diagnostics:
|
|
|
6727
7294
|
${JSON.stringify(diagnostics, null, 2)}
|
|
6728
7295
|
|
|
6729
7296
|
Please analyze and help me fix any issues.`
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
);
|
|
7297
|
+
}
|
|
7298
|
+
],
|
|
7299
|
+
max_tokens: 1e3
|
|
7300
|
+
})
|
|
7301
|
+
});
|
|
6736
7302
|
if (!response.ok) {
|
|
6737
7303
|
const text = await response.text();
|
|
6738
7304
|
console.log(`Error: ${response.status} - ${text}`);
|
|
@@ -7000,19 +7566,20 @@ ClawRouter Partner APIs (v${VERSION})
|
|
|
7000
7566
|
console.error(`[ClawRouter] Need help? Run: npx @blockrun/clawrouter doctor`);
|
|
7001
7567
|
}
|
|
7002
7568
|
});
|
|
7003
|
-
const
|
|
7569
|
+
const paymentChain = await resolvePaymentChain();
|
|
7570
|
+
const displayAddress = paymentChain === "solana" && proxy.solanaAddress ? proxy.solanaAddress : wallet.address;
|
|
7004
7571
|
try {
|
|
7005
|
-
const balance = await
|
|
7572
|
+
const balance = await proxy.balanceMonitor.checkBalance();
|
|
7006
7573
|
if (balance.isEmpty) {
|
|
7007
7574
|
console.log(`[ClawRouter] Wallet balance: $0.00 (using FREE model)`);
|
|
7008
|
-
console.log(`[ClawRouter] Fund wallet for premium models: ${
|
|
7575
|
+
console.log(`[ClawRouter] Fund wallet for premium models: ${displayAddress}`);
|
|
7009
7576
|
} else if (balance.isLow) {
|
|
7010
7577
|
console.log(`[ClawRouter] Wallet balance: ${balance.balanceUSD} (low)`);
|
|
7011
7578
|
} else {
|
|
7012
7579
|
console.log(`[ClawRouter] Wallet balance: ${balance.balanceUSD}`);
|
|
7013
7580
|
}
|
|
7014
7581
|
} catch {
|
|
7015
|
-
console.log(`[ClawRouter] Wallet: ${
|
|
7582
|
+
console.log(`[ClawRouter] Wallet: ${displayAddress} (balance check pending)`);
|
|
7016
7583
|
}
|
|
7017
7584
|
console.log(`[ClawRouter] Ready - Ctrl+C to stop`);
|
|
7018
7585
|
const shutdown = async (signal) => {
|
|
@@ -7037,4 +7604,9 @@ main().catch((err) => {
|
|
|
7037
7604
|
console.error(`[ClawRouter] Need help? Run: npx @blockrun/clawrouter doctor`);
|
|
7038
7605
|
process.exit(1);
|
|
7039
7606
|
});
|
|
7607
|
+
/*! Bundled license information:
|
|
7608
|
+
|
|
7609
|
+
@noble/hashes/esm/utils.js:
|
|
7610
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7611
|
+
*/
|
|
7040
7612
|
//# sourceMappingURL=cli.js.map
|