@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/index.js
CHANGED
|
@@ -95,7 +95,10 @@ var init_solana_balance = __esm({
|
|
|
95
95
|
}
|
|
96
96
|
return total;
|
|
97
97
|
} catch (err) {
|
|
98
|
-
throw new Error(
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Failed to fetch Solana USDC balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
100
|
+
{ cause: err }
|
|
101
|
+
);
|
|
99
102
|
} finally {
|
|
100
103
|
clearTimeout(timer);
|
|
101
104
|
}
|
|
@@ -114,12 +117,546 @@ var init_solana_balance = __esm({
|
|
|
114
117
|
}
|
|
115
118
|
});
|
|
116
119
|
|
|
120
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
121
|
+
function isBytes(a) {
|
|
122
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
123
|
+
}
|
|
124
|
+
function anumber(n) {
|
|
125
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
126
|
+
throw new Error("positive integer expected, got " + n);
|
|
127
|
+
}
|
|
128
|
+
function abytes(b, ...lengths) {
|
|
129
|
+
if (!isBytes(b))
|
|
130
|
+
throw new Error("Uint8Array expected");
|
|
131
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
132
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
133
|
+
}
|
|
134
|
+
function ahash(h) {
|
|
135
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
136
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
137
|
+
anumber(h.outputLen);
|
|
138
|
+
anumber(h.blockLen);
|
|
139
|
+
}
|
|
140
|
+
function aexists(instance, checkFinished = true) {
|
|
141
|
+
if (instance.destroyed)
|
|
142
|
+
throw new Error("Hash instance has been destroyed");
|
|
143
|
+
if (checkFinished && instance.finished)
|
|
144
|
+
throw new Error("Hash#digest() has already been called");
|
|
145
|
+
}
|
|
146
|
+
function aoutput(out, instance) {
|
|
147
|
+
abytes(out);
|
|
148
|
+
const min = instance.outputLen;
|
|
149
|
+
if (out.length < min) {
|
|
150
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function clean(...arrays) {
|
|
154
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
155
|
+
arrays[i].fill(0);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function createView(arr) {
|
|
159
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
160
|
+
}
|
|
161
|
+
function utf8ToBytes(str) {
|
|
162
|
+
if (typeof str !== "string")
|
|
163
|
+
throw new Error("string expected");
|
|
164
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
165
|
+
}
|
|
166
|
+
function toBytes(data) {
|
|
167
|
+
if (typeof data === "string")
|
|
168
|
+
data = utf8ToBytes(data);
|
|
169
|
+
abytes(data);
|
|
170
|
+
return data;
|
|
171
|
+
}
|
|
172
|
+
function createHasher(hashCons) {
|
|
173
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
174
|
+
const tmp = hashCons();
|
|
175
|
+
hashC.outputLen = tmp.outputLen;
|
|
176
|
+
hashC.blockLen = tmp.blockLen;
|
|
177
|
+
hashC.create = () => hashCons();
|
|
178
|
+
return hashC;
|
|
179
|
+
}
|
|
180
|
+
var Hash;
|
|
181
|
+
var init_utils = __esm({
|
|
182
|
+
"node_modules/@noble/hashes/esm/utils.js"() {
|
|
183
|
+
"use strict";
|
|
184
|
+
Hash = class {
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// node_modules/@noble/hashes/esm/hmac.js
|
|
190
|
+
var HMAC, hmac;
|
|
191
|
+
var init_hmac = __esm({
|
|
192
|
+
"node_modules/@noble/hashes/esm/hmac.js"() {
|
|
193
|
+
"use strict";
|
|
194
|
+
init_utils();
|
|
195
|
+
HMAC = class extends Hash {
|
|
196
|
+
constructor(hash, _key) {
|
|
197
|
+
super();
|
|
198
|
+
this.finished = false;
|
|
199
|
+
this.destroyed = false;
|
|
200
|
+
ahash(hash);
|
|
201
|
+
const key = toBytes(_key);
|
|
202
|
+
this.iHash = hash.create();
|
|
203
|
+
if (typeof this.iHash.update !== "function")
|
|
204
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
205
|
+
this.blockLen = this.iHash.blockLen;
|
|
206
|
+
this.outputLen = this.iHash.outputLen;
|
|
207
|
+
const blockLen = this.blockLen;
|
|
208
|
+
const pad = new Uint8Array(blockLen);
|
|
209
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
210
|
+
for (let i = 0; i < pad.length; i++)
|
|
211
|
+
pad[i] ^= 54;
|
|
212
|
+
this.iHash.update(pad);
|
|
213
|
+
this.oHash = hash.create();
|
|
214
|
+
for (let i = 0; i < pad.length; i++)
|
|
215
|
+
pad[i] ^= 54 ^ 92;
|
|
216
|
+
this.oHash.update(pad);
|
|
217
|
+
clean(pad);
|
|
218
|
+
}
|
|
219
|
+
update(buf) {
|
|
220
|
+
aexists(this);
|
|
221
|
+
this.iHash.update(buf);
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
digestInto(out) {
|
|
225
|
+
aexists(this);
|
|
226
|
+
abytes(out, this.outputLen);
|
|
227
|
+
this.finished = true;
|
|
228
|
+
this.iHash.digestInto(out);
|
|
229
|
+
this.oHash.update(out);
|
|
230
|
+
this.oHash.digestInto(out);
|
|
231
|
+
this.destroy();
|
|
232
|
+
}
|
|
233
|
+
digest() {
|
|
234
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
235
|
+
this.digestInto(out);
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
_cloneInto(to) {
|
|
239
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
240
|
+
const { oHash, iHash, finished: finished2, destroyed, blockLen, outputLen } = this;
|
|
241
|
+
to = to;
|
|
242
|
+
to.finished = finished2;
|
|
243
|
+
to.destroyed = destroyed;
|
|
244
|
+
to.blockLen = blockLen;
|
|
245
|
+
to.outputLen = outputLen;
|
|
246
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
247
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
248
|
+
return to;
|
|
249
|
+
}
|
|
250
|
+
clone() {
|
|
251
|
+
return this._cloneInto();
|
|
252
|
+
}
|
|
253
|
+
destroy() {
|
|
254
|
+
this.destroyed = true;
|
|
255
|
+
this.oHash.destroy();
|
|
256
|
+
this.iHash.destroy();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
260
|
+
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
265
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
266
|
+
if (typeof view.setBigUint64 === "function")
|
|
267
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
268
|
+
const _32n2 = BigInt(32);
|
|
269
|
+
const _u32_max = BigInt(4294967295);
|
|
270
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
271
|
+
const wl = Number(value & _u32_max);
|
|
272
|
+
const h = isLE ? 4 : 0;
|
|
273
|
+
const l = isLE ? 0 : 4;
|
|
274
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
275
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
276
|
+
}
|
|
277
|
+
var HashMD, SHA512_IV;
|
|
278
|
+
var init_md = __esm({
|
|
279
|
+
"node_modules/@noble/hashes/esm/_md.js"() {
|
|
280
|
+
"use strict";
|
|
281
|
+
init_utils();
|
|
282
|
+
HashMD = class extends Hash {
|
|
283
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
284
|
+
super();
|
|
285
|
+
this.finished = false;
|
|
286
|
+
this.length = 0;
|
|
287
|
+
this.pos = 0;
|
|
288
|
+
this.destroyed = false;
|
|
289
|
+
this.blockLen = blockLen;
|
|
290
|
+
this.outputLen = outputLen;
|
|
291
|
+
this.padOffset = padOffset;
|
|
292
|
+
this.isLE = isLE;
|
|
293
|
+
this.buffer = new Uint8Array(blockLen);
|
|
294
|
+
this.view = createView(this.buffer);
|
|
295
|
+
}
|
|
296
|
+
update(data) {
|
|
297
|
+
aexists(this);
|
|
298
|
+
data = toBytes(data);
|
|
299
|
+
abytes(data);
|
|
300
|
+
const { view, buffer, blockLen } = this;
|
|
301
|
+
const len = data.length;
|
|
302
|
+
for (let pos = 0; pos < len; ) {
|
|
303
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
304
|
+
if (take === blockLen) {
|
|
305
|
+
const dataView = createView(data);
|
|
306
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
307
|
+
this.process(dataView, pos);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
311
|
+
this.pos += take;
|
|
312
|
+
pos += take;
|
|
313
|
+
if (this.pos === blockLen) {
|
|
314
|
+
this.process(view, 0);
|
|
315
|
+
this.pos = 0;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
this.length += data.length;
|
|
319
|
+
this.roundClean();
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
digestInto(out) {
|
|
323
|
+
aexists(this);
|
|
324
|
+
aoutput(out, this);
|
|
325
|
+
this.finished = true;
|
|
326
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
327
|
+
let { pos } = this;
|
|
328
|
+
buffer[pos++] = 128;
|
|
329
|
+
clean(this.buffer.subarray(pos));
|
|
330
|
+
if (this.padOffset > blockLen - pos) {
|
|
331
|
+
this.process(view, 0);
|
|
332
|
+
pos = 0;
|
|
333
|
+
}
|
|
334
|
+
for (let i = pos; i < blockLen; i++)
|
|
335
|
+
buffer[i] = 0;
|
|
336
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
337
|
+
this.process(view, 0);
|
|
338
|
+
const oview = createView(out);
|
|
339
|
+
const len = this.outputLen;
|
|
340
|
+
if (len % 4)
|
|
341
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
342
|
+
const outLen = len / 4;
|
|
343
|
+
const state = this.get();
|
|
344
|
+
if (outLen > state.length)
|
|
345
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
346
|
+
for (let i = 0; i < outLen; i++)
|
|
347
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
348
|
+
}
|
|
349
|
+
digest() {
|
|
350
|
+
const { buffer, outputLen } = this;
|
|
351
|
+
this.digestInto(buffer);
|
|
352
|
+
const res = buffer.slice(0, outputLen);
|
|
353
|
+
this.destroy();
|
|
354
|
+
return res;
|
|
355
|
+
}
|
|
356
|
+
_cloneInto(to) {
|
|
357
|
+
to || (to = new this.constructor());
|
|
358
|
+
to.set(...this.get());
|
|
359
|
+
const { blockLen, buffer, length, finished: finished2, destroyed, pos } = this;
|
|
360
|
+
to.destroyed = destroyed;
|
|
361
|
+
to.finished = finished2;
|
|
362
|
+
to.length = length;
|
|
363
|
+
to.pos = pos;
|
|
364
|
+
if (length % blockLen)
|
|
365
|
+
to.buffer.set(buffer);
|
|
366
|
+
return to;
|
|
367
|
+
}
|
|
368
|
+
clone() {
|
|
369
|
+
return this._cloneInto();
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
373
|
+
1779033703,
|
|
374
|
+
4089235720,
|
|
375
|
+
3144134277,
|
|
376
|
+
2227873595,
|
|
377
|
+
1013904242,
|
|
378
|
+
4271175723,
|
|
379
|
+
2773480762,
|
|
380
|
+
1595750129,
|
|
381
|
+
1359893119,
|
|
382
|
+
2917565137,
|
|
383
|
+
2600822924,
|
|
384
|
+
725511199,
|
|
385
|
+
528734635,
|
|
386
|
+
4215389547,
|
|
387
|
+
1541459225,
|
|
388
|
+
327033209
|
|
389
|
+
]);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
394
|
+
function fromBig(n, le = false) {
|
|
395
|
+
if (le)
|
|
396
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
397
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
398
|
+
}
|
|
399
|
+
function split(lst, le = false) {
|
|
400
|
+
const len = lst.length;
|
|
401
|
+
let Ah = new Uint32Array(len);
|
|
402
|
+
let Al = new Uint32Array(len);
|
|
403
|
+
for (let i = 0; i < len; i++) {
|
|
404
|
+
const { h, l } = fromBig(lst[i], le);
|
|
405
|
+
[Ah[i], Al[i]] = [h, l];
|
|
406
|
+
}
|
|
407
|
+
return [Ah, Al];
|
|
408
|
+
}
|
|
409
|
+
function add(Ah, Al, Bh, Bl) {
|
|
410
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
411
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
412
|
+
}
|
|
413
|
+
var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H;
|
|
414
|
+
var init_u64 = __esm({
|
|
415
|
+
"node_modules/@noble/hashes/esm/_u64.js"() {
|
|
416
|
+
"use strict";
|
|
417
|
+
U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
418
|
+
_32n = /* @__PURE__ */ BigInt(32);
|
|
419
|
+
shrSH = (h, _l, s) => h >>> s;
|
|
420
|
+
shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
421
|
+
rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
422
|
+
rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
423
|
+
rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
424
|
+
rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
425
|
+
add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
426
|
+
add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
427
|
+
add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
428
|
+
add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
429
|
+
add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
430
|
+
add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
435
|
+
var K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha512;
|
|
436
|
+
var init_sha2 = __esm({
|
|
437
|
+
"node_modules/@noble/hashes/esm/sha2.js"() {
|
|
438
|
+
"use strict";
|
|
439
|
+
init_md();
|
|
440
|
+
init_u64();
|
|
441
|
+
init_utils();
|
|
442
|
+
K512 = /* @__PURE__ */ (() => split([
|
|
443
|
+
"0x428a2f98d728ae22",
|
|
444
|
+
"0x7137449123ef65cd",
|
|
445
|
+
"0xb5c0fbcfec4d3b2f",
|
|
446
|
+
"0xe9b5dba58189dbbc",
|
|
447
|
+
"0x3956c25bf348b538",
|
|
448
|
+
"0x59f111f1b605d019",
|
|
449
|
+
"0x923f82a4af194f9b",
|
|
450
|
+
"0xab1c5ed5da6d8118",
|
|
451
|
+
"0xd807aa98a3030242",
|
|
452
|
+
"0x12835b0145706fbe",
|
|
453
|
+
"0x243185be4ee4b28c",
|
|
454
|
+
"0x550c7dc3d5ffb4e2",
|
|
455
|
+
"0x72be5d74f27b896f",
|
|
456
|
+
"0x80deb1fe3b1696b1",
|
|
457
|
+
"0x9bdc06a725c71235",
|
|
458
|
+
"0xc19bf174cf692694",
|
|
459
|
+
"0xe49b69c19ef14ad2",
|
|
460
|
+
"0xefbe4786384f25e3",
|
|
461
|
+
"0x0fc19dc68b8cd5b5",
|
|
462
|
+
"0x240ca1cc77ac9c65",
|
|
463
|
+
"0x2de92c6f592b0275",
|
|
464
|
+
"0x4a7484aa6ea6e483",
|
|
465
|
+
"0x5cb0a9dcbd41fbd4",
|
|
466
|
+
"0x76f988da831153b5",
|
|
467
|
+
"0x983e5152ee66dfab",
|
|
468
|
+
"0xa831c66d2db43210",
|
|
469
|
+
"0xb00327c898fb213f",
|
|
470
|
+
"0xbf597fc7beef0ee4",
|
|
471
|
+
"0xc6e00bf33da88fc2",
|
|
472
|
+
"0xd5a79147930aa725",
|
|
473
|
+
"0x06ca6351e003826f",
|
|
474
|
+
"0x142929670a0e6e70",
|
|
475
|
+
"0x27b70a8546d22ffc",
|
|
476
|
+
"0x2e1b21385c26c926",
|
|
477
|
+
"0x4d2c6dfc5ac42aed",
|
|
478
|
+
"0x53380d139d95b3df",
|
|
479
|
+
"0x650a73548baf63de",
|
|
480
|
+
"0x766a0abb3c77b2a8",
|
|
481
|
+
"0x81c2c92e47edaee6",
|
|
482
|
+
"0x92722c851482353b",
|
|
483
|
+
"0xa2bfe8a14cf10364",
|
|
484
|
+
"0xa81a664bbc423001",
|
|
485
|
+
"0xc24b8b70d0f89791",
|
|
486
|
+
"0xc76c51a30654be30",
|
|
487
|
+
"0xd192e819d6ef5218",
|
|
488
|
+
"0xd69906245565a910",
|
|
489
|
+
"0xf40e35855771202a",
|
|
490
|
+
"0x106aa07032bbd1b8",
|
|
491
|
+
"0x19a4c116b8d2d0c8",
|
|
492
|
+
"0x1e376c085141ab53",
|
|
493
|
+
"0x2748774cdf8eeb99",
|
|
494
|
+
"0x34b0bcb5e19b48a8",
|
|
495
|
+
"0x391c0cb3c5c95a63",
|
|
496
|
+
"0x4ed8aa4ae3418acb",
|
|
497
|
+
"0x5b9cca4f7763e373",
|
|
498
|
+
"0x682e6ff3d6b2b8a3",
|
|
499
|
+
"0x748f82ee5defb2fc",
|
|
500
|
+
"0x78a5636f43172f60",
|
|
501
|
+
"0x84c87814a1f0ab72",
|
|
502
|
+
"0x8cc702081a6439ec",
|
|
503
|
+
"0x90befffa23631e28",
|
|
504
|
+
"0xa4506cebde82bde9",
|
|
505
|
+
"0xbef9a3f7b2c67915",
|
|
506
|
+
"0xc67178f2e372532b",
|
|
507
|
+
"0xca273eceea26619c",
|
|
508
|
+
"0xd186b8c721c0c207",
|
|
509
|
+
"0xeada7dd6cde0eb1e",
|
|
510
|
+
"0xf57d4f7fee6ed178",
|
|
511
|
+
"0x06f067aa72176fba",
|
|
512
|
+
"0x0a637dc5a2c898a6",
|
|
513
|
+
"0x113f9804bef90dae",
|
|
514
|
+
"0x1b710b35131c471b",
|
|
515
|
+
"0x28db77f523047d84",
|
|
516
|
+
"0x32caab7b40c72493",
|
|
517
|
+
"0x3c9ebe0a15c9bebc",
|
|
518
|
+
"0x431d67c49c100d4c",
|
|
519
|
+
"0x4cc5d4becb3e42b6",
|
|
520
|
+
"0x597f299cfc657e2a",
|
|
521
|
+
"0x5fcb6fab3ad6faec",
|
|
522
|
+
"0x6c44198c4a475817"
|
|
523
|
+
].map((n) => BigInt(n))))();
|
|
524
|
+
SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
525
|
+
SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
526
|
+
SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
527
|
+
SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
528
|
+
SHA512 = class extends HashMD {
|
|
529
|
+
constructor(outputLen = 64) {
|
|
530
|
+
super(128, outputLen, 16, false);
|
|
531
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
532
|
+
this.Al = SHA512_IV[1] | 0;
|
|
533
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
534
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
535
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
536
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
537
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
538
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
539
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
540
|
+
this.El = SHA512_IV[9] | 0;
|
|
541
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
542
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
543
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
544
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
545
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
546
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
547
|
+
}
|
|
548
|
+
// prettier-ignore
|
|
549
|
+
get() {
|
|
550
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
551
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
552
|
+
}
|
|
553
|
+
// prettier-ignore
|
|
554
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
555
|
+
this.Ah = Ah | 0;
|
|
556
|
+
this.Al = Al | 0;
|
|
557
|
+
this.Bh = Bh | 0;
|
|
558
|
+
this.Bl = Bl | 0;
|
|
559
|
+
this.Ch = Ch | 0;
|
|
560
|
+
this.Cl = Cl | 0;
|
|
561
|
+
this.Dh = Dh | 0;
|
|
562
|
+
this.Dl = Dl | 0;
|
|
563
|
+
this.Eh = Eh | 0;
|
|
564
|
+
this.El = El | 0;
|
|
565
|
+
this.Fh = Fh | 0;
|
|
566
|
+
this.Fl = Fl | 0;
|
|
567
|
+
this.Gh = Gh | 0;
|
|
568
|
+
this.Gl = Gl | 0;
|
|
569
|
+
this.Hh = Hh | 0;
|
|
570
|
+
this.Hl = Hl | 0;
|
|
571
|
+
}
|
|
572
|
+
process(view, offset) {
|
|
573
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
574
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
575
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
576
|
+
}
|
|
577
|
+
for (let i = 16; i < 80; i++) {
|
|
578
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
579
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
580
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
581
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
582
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
583
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
584
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
585
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
586
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
587
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
588
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
589
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
590
|
+
}
|
|
591
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
592
|
+
for (let i = 0; i < 80; i++) {
|
|
593
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
594
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
595
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
596
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
597
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
598
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
599
|
+
const T1l = T1ll | 0;
|
|
600
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
601
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
602
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
603
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
604
|
+
Hh = Gh | 0;
|
|
605
|
+
Hl = Gl | 0;
|
|
606
|
+
Gh = Fh | 0;
|
|
607
|
+
Gl = Fl | 0;
|
|
608
|
+
Fh = Eh | 0;
|
|
609
|
+
Fl = El | 0;
|
|
610
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
611
|
+
Dh = Ch | 0;
|
|
612
|
+
Dl = Cl | 0;
|
|
613
|
+
Ch = Bh | 0;
|
|
614
|
+
Cl = Bl | 0;
|
|
615
|
+
Bh = Ah | 0;
|
|
616
|
+
Bl = Al | 0;
|
|
617
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
618
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
619
|
+
Al = All | 0;
|
|
620
|
+
}
|
|
621
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
622
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
623
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
624
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
625
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
626
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
627
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
628
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
629
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
630
|
+
}
|
|
631
|
+
roundClean() {
|
|
632
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
633
|
+
}
|
|
634
|
+
destroy() {
|
|
635
|
+
clean(this.buffer);
|
|
636
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
// node_modules/@noble/hashes/esm/sha512.js
|
|
644
|
+
var sha5122;
|
|
645
|
+
var init_sha512 = __esm({
|
|
646
|
+
"node_modules/@noble/hashes/esm/sha512.js"() {
|
|
647
|
+
"use strict";
|
|
648
|
+
init_sha2();
|
|
649
|
+
sha5122 = sha512;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
|
|
117
653
|
// src/wallet.ts
|
|
118
654
|
var wallet_exports = {};
|
|
119
655
|
__export(wallet_exports, {
|
|
120
656
|
deriveAllKeys: () => deriveAllKeys,
|
|
121
657
|
deriveEvmKey: () => deriveEvmKey,
|
|
122
658
|
deriveSolanaKeyBytes: () => deriveSolanaKeyBytes,
|
|
659
|
+
deriveSolanaKeyBytesLegacy: () => deriveSolanaKeyBytesLegacy,
|
|
123
660
|
generateWalletMnemonic: () => generateWalletMnemonic,
|
|
124
661
|
isValidMnemonic: () => isValidMnemonic
|
|
125
662
|
});
|
|
@@ -143,10 +680,29 @@ function deriveEvmKey(mnemonic) {
|
|
|
143
680
|
return { privateKey: hex, address: account.address };
|
|
144
681
|
}
|
|
145
682
|
function deriveSolanaKeyBytes(mnemonic) {
|
|
683
|
+
const seed = mnemonicToSeedSync(mnemonic);
|
|
684
|
+
let I = hmac(sha5122, "ed25519 seed", seed);
|
|
685
|
+
let key = I.slice(0, 32);
|
|
686
|
+
let chainCode = I.slice(32);
|
|
687
|
+
for (const index of SOLANA_HARDENED_INDICES) {
|
|
688
|
+
const data = new Uint8Array(37);
|
|
689
|
+
data[0] = 0;
|
|
690
|
+
data.set(key, 1);
|
|
691
|
+
data[33] = index >>> 24 & 255;
|
|
692
|
+
data[34] = index >>> 16 & 255;
|
|
693
|
+
data[35] = index >>> 8 & 255;
|
|
694
|
+
data[36] = index & 255;
|
|
695
|
+
I = hmac(sha5122, chainCode, data);
|
|
696
|
+
key = I.slice(0, 32);
|
|
697
|
+
chainCode = I.slice(32);
|
|
698
|
+
}
|
|
699
|
+
return new Uint8Array(key);
|
|
700
|
+
}
|
|
701
|
+
function deriveSolanaKeyBytesLegacy(mnemonic) {
|
|
146
702
|
const seed = mnemonicToSeedSync(mnemonic);
|
|
147
703
|
const hdKey = HDKey.fromMasterSeed(seed);
|
|
148
|
-
const derived = hdKey.derive(
|
|
149
|
-
if (!derived.privateKey) throw new Error("Failed to derive Solana private key");
|
|
704
|
+
const derived = hdKey.derive("m/44'/501'/0'/0'");
|
|
705
|
+
if (!derived.privateKey) throw new Error("Failed to derive legacy Solana private key");
|
|
150
706
|
return new Uint8Array(derived.privateKey);
|
|
151
707
|
}
|
|
152
708
|
function deriveAllKeys(mnemonic) {
|
|
@@ -154,12 +710,241 @@ function deriveAllKeys(mnemonic) {
|
|
|
154
710
|
const solanaPrivateKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
155
711
|
return { mnemonic, evmPrivateKey, evmAddress, solanaPrivateKeyBytes };
|
|
156
712
|
}
|
|
157
|
-
var ETH_DERIVATION_PATH,
|
|
713
|
+
var ETH_DERIVATION_PATH, SOLANA_HARDENED_INDICES;
|
|
158
714
|
var init_wallet = __esm({
|
|
159
715
|
"src/wallet.ts"() {
|
|
160
716
|
"use strict";
|
|
717
|
+
init_hmac();
|
|
718
|
+
init_sha512();
|
|
161
719
|
ETH_DERIVATION_PATH = "m/44'/60'/0'/0/0";
|
|
162
|
-
|
|
720
|
+
SOLANA_HARDENED_INDICES = [
|
|
721
|
+
44 + 2147483648,
|
|
722
|
+
501 + 2147483648,
|
|
723
|
+
0 + 2147483648,
|
|
724
|
+
0 + 2147483648
|
|
725
|
+
];
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
// src/solana-sweep.ts
|
|
730
|
+
var solana_sweep_exports = {};
|
|
731
|
+
__export(solana_sweep_exports, {
|
|
732
|
+
sweepSolanaWallet: () => sweepSolanaWallet
|
|
733
|
+
});
|
|
734
|
+
import {
|
|
735
|
+
address as solAddress2,
|
|
736
|
+
createSolanaRpc as createSolanaRpc2,
|
|
737
|
+
createSolanaRpcSubscriptions,
|
|
738
|
+
createKeyPairSignerFromPrivateKeyBytes,
|
|
739
|
+
pipe,
|
|
740
|
+
createTransactionMessage,
|
|
741
|
+
setTransactionMessageFeePayer,
|
|
742
|
+
setTransactionMessageLifetimeUsingBlockhash,
|
|
743
|
+
appendTransactionMessageInstructions,
|
|
744
|
+
signTransactionMessageWithSigners,
|
|
745
|
+
getSignatureFromTransaction,
|
|
746
|
+
sendAndConfirmTransactionFactory,
|
|
747
|
+
getProgramDerivedAddress,
|
|
748
|
+
getAddressEncoder
|
|
749
|
+
} from "@solana/kit";
|
|
750
|
+
async function getAssociatedTokenAddress(owner, mint) {
|
|
751
|
+
const encoder = getAddressEncoder();
|
|
752
|
+
const [ata] = await getProgramDerivedAddress({
|
|
753
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM,
|
|
754
|
+
seeds: [encoder.encode(owner), encoder.encode(TOKEN_PROGRAM), encoder.encode(mint)]
|
|
755
|
+
});
|
|
756
|
+
return ata;
|
|
757
|
+
}
|
|
758
|
+
function buildCreateAtaIdempotentInstruction(payer, ata, owner, mint) {
|
|
759
|
+
return {
|
|
760
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM,
|
|
761
|
+
accounts: [
|
|
762
|
+
{
|
|
763
|
+
address: payer,
|
|
764
|
+
role: 3
|
|
765
|
+
/* writable signer */
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
address: ata,
|
|
769
|
+
role: 1
|
|
770
|
+
/* writable */
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
address: owner,
|
|
774
|
+
role: 0
|
|
775
|
+
/* readonly */
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
address: mint,
|
|
779
|
+
role: 0
|
|
780
|
+
/* readonly */
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
address: SYSTEM_PROGRAM,
|
|
784
|
+
role: 0
|
|
785
|
+
/* readonly */
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
address: TOKEN_PROGRAM,
|
|
789
|
+
role: 0
|
|
790
|
+
/* readonly */
|
|
791
|
+
}
|
|
792
|
+
],
|
|
793
|
+
data: new Uint8Array([1])
|
|
794
|
+
// instruction index 1 = CreateIdempotent
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
function buildTokenTransferInstruction(source, destination, authority, amount) {
|
|
798
|
+
const data = new Uint8Array(9);
|
|
799
|
+
data[0] = 3;
|
|
800
|
+
const view = new DataView(data.buffer, data.byteOffset);
|
|
801
|
+
view.setBigUint64(1, amount, true);
|
|
802
|
+
return {
|
|
803
|
+
programAddress: TOKEN_PROGRAM,
|
|
804
|
+
accounts: [
|
|
805
|
+
{
|
|
806
|
+
address: source,
|
|
807
|
+
role: 1
|
|
808
|
+
/* writable */
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
address: destination,
|
|
812
|
+
role: 1
|
|
813
|
+
/* writable */
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
address: authority,
|
|
817
|
+
role: 2
|
|
818
|
+
/* signer */
|
|
819
|
+
}
|
|
820
|
+
],
|
|
821
|
+
data
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
async function sweepSolanaWallet(oldKeyBytes, newAddress, rpcUrl) {
|
|
825
|
+
const url = rpcUrl || process["env"].CLAWROUTER_SOLANA_RPC_URL || SOLANA_DEFAULT_RPC2;
|
|
826
|
+
const rpc = createSolanaRpc2(url);
|
|
827
|
+
const oldSigner = await createKeyPairSignerFromPrivateKeyBytes(oldKeyBytes);
|
|
828
|
+
const oldAddress = oldSigner.address;
|
|
829
|
+
const mint = solAddress2(SOLANA_USDC_MINT2);
|
|
830
|
+
const newOwner = solAddress2(newAddress);
|
|
831
|
+
let solBalance;
|
|
832
|
+
try {
|
|
833
|
+
const solResp = await rpc.getBalance(solAddress2(oldAddress)).send();
|
|
834
|
+
solBalance = solResp.value;
|
|
835
|
+
} catch (err) {
|
|
836
|
+
return {
|
|
837
|
+
error: `Failed to check SOL balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
838
|
+
oldAddress,
|
|
839
|
+
newAddress
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
let usdcBalance = 0n;
|
|
843
|
+
let oldTokenAccount;
|
|
844
|
+
try {
|
|
845
|
+
const response = await rpc.getTokenAccountsByOwner(
|
|
846
|
+
solAddress2(oldAddress),
|
|
847
|
+
{ mint },
|
|
848
|
+
{ encoding: "jsonParsed" }
|
|
849
|
+
).send();
|
|
850
|
+
if (response.value.length > 0) {
|
|
851
|
+
for (const account of response.value) {
|
|
852
|
+
const parsed = account.account.data;
|
|
853
|
+
const amount = BigInt(parsed.parsed.info.tokenAmount.amount);
|
|
854
|
+
if (amount > 0n) {
|
|
855
|
+
usdcBalance += amount;
|
|
856
|
+
oldTokenAccount = account.pubkey;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
} catch (err) {
|
|
861
|
+
return {
|
|
862
|
+
error: `Failed to check USDC balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
863
|
+
oldAddress,
|
|
864
|
+
newAddress
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
if (usdcBalance === 0n) {
|
|
868
|
+
return {
|
|
869
|
+
error: "No USDC found in old wallet. Nothing to sweep.",
|
|
870
|
+
oldAddress,
|
|
871
|
+
newAddress,
|
|
872
|
+
solBalance,
|
|
873
|
+
usdcBalance: 0n
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
const MIN_SOL_FOR_GAS = 5000000n;
|
|
877
|
+
if (solBalance < MIN_SOL_FOR_GAS) {
|
|
878
|
+
const needed = Number(MIN_SOL_FOR_GAS - solBalance) / 1e9;
|
|
879
|
+
return {
|
|
880
|
+
error: `Insufficient SOL for transaction fees. Send ~${needed.toFixed(4)} SOL to ${oldAddress} to cover gas. Current SOL balance: ${(Number(solBalance) / 1e9).toFixed(6)} SOL`,
|
|
881
|
+
oldAddress,
|
|
882
|
+
newAddress,
|
|
883
|
+
solBalance,
|
|
884
|
+
usdcBalance
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
if (!oldTokenAccount) {
|
|
888
|
+
return {
|
|
889
|
+
error: "Could not find USDC token account in old wallet.",
|
|
890
|
+
oldAddress,
|
|
891
|
+
newAddress
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
try {
|
|
895
|
+
const newAta = await getAssociatedTokenAddress(newOwner, mint);
|
|
896
|
+
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
897
|
+
const createAtaIx = buildCreateAtaIdempotentInstruction(
|
|
898
|
+
oldSigner.address,
|
|
899
|
+
newAta,
|
|
900
|
+
newOwner,
|
|
901
|
+
mint
|
|
902
|
+
);
|
|
903
|
+
const transferIx = buildTokenTransferInstruction(
|
|
904
|
+
solAddress2(oldTokenAccount),
|
|
905
|
+
newAta,
|
|
906
|
+
oldSigner.address,
|
|
907
|
+
usdcBalance
|
|
908
|
+
);
|
|
909
|
+
const txMessage = pipe(
|
|
910
|
+
createTransactionMessage({ version: 0 }),
|
|
911
|
+
(msg) => setTransactionMessageFeePayer(oldSigner.address, msg),
|
|
912
|
+
(msg) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, msg),
|
|
913
|
+
(msg) => appendTransactionMessageInstructions([createAtaIx, transferIx], msg)
|
|
914
|
+
);
|
|
915
|
+
const signedTx = await signTransactionMessageWithSigners(txMessage);
|
|
916
|
+
const txSignature = getSignatureFromTransaction(signedTx);
|
|
917
|
+
const wsUrl = url.replace("https://", "wss://").replace("http://", "ws://");
|
|
918
|
+
const rpcSubscriptions = createSolanaRpcSubscriptions(wsUrl);
|
|
919
|
+
const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
|
|
920
|
+
await sendAndConfirm(signedTx, { commitment: "confirmed" });
|
|
921
|
+
const dollars = Number(usdcBalance) / 1e6;
|
|
922
|
+
return {
|
|
923
|
+
transferred: `$${dollars.toFixed(2)}`,
|
|
924
|
+
transferredMicros: usdcBalance,
|
|
925
|
+
txSignature,
|
|
926
|
+
oldAddress,
|
|
927
|
+
newAddress
|
|
928
|
+
};
|
|
929
|
+
} catch (err) {
|
|
930
|
+
return {
|
|
931
|
+
error: `Transaction failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
932
|
+
oldAddress,
|
|
933
|
+
newAddress,
|
|
934
|
+
solBalance,
|
|
935
|
+
usdcBalance
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
var SOLANA_USDC_MINT2, SOLANA_DEFAULT_RPC2, TOKEN_PROGRAM, ASSOCIATED_TOKEN_PROGRAM, SYSTEM_PROGRAM;
|
|
940
|
+
var init_solana_sweep = __esm({
|
|
941
|
+
"src/solana-sweep.ts"() {
|
|
942
|
+
"use strict";
|
|
943
|
+
SOLANA_USDC_MINT2 = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
944
|
+
SOLANA_DEFAULT_RPC2 = "https://api.mainnet-beta.solana.com";
|
|
945
|
+
TOKEN_PROGRAM = "TokenkegQfeN4jV6bme4LphiJbfPe2VopRsimuVSoZ5K";
|
|
946
|
+
ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
947
|
+
SYSTEM_PROGRAM = "11111111111111111111111111111111";
|
|
163
948
|
}
|
|
164
949
|
});
|
|
165
950
|
|
|
@@ -859,7 +1644,8 @@ function createPayFetchWithPreAuth(baseFetch, client, ttlMs = DEFAULT_TTL_MS, op
|
|
|
859
1644
|
cache.set(urlPath, { paymentRequired, cachedAt: Date.now() });
|
|
860
1645
|
} catch (error) {
|
|
861
1646
|
throw new Error(
|
|
862
|
-
`Failed to parse payment requirements: ${error instanceof Error ? error.message : "Unknown error"}
|
|
1647
|
+
`Failed to parse payment requirements: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1648
|
+
{ cause: error }
|
|
863
1649
|
);
|
|
864
1650
|
}
|
|
865
1651
|
const payload = await client.createPaymentPayload(paymentRequired);
|
|
@@ -3329,6 +4115,29 @@ async function generateAndSaveWallet() {
|
|
|
3329
4115
|
solanaPrivateKeyBytes: derived.solanaPrivateKeyBytes
|
|
3330
4116
|
};
|
|
3331
4117
|
}
|
|
4118
|
+
async function logMigrationWarning(legacyKeyBytes, newKeyBytes) {
|
|
4119
|
+
try {
|
|
4120
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
4121
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
4122
|
+
createKeyPairSignerFromPrivateKeyBytes2(legacyKeyBytes),
|
|
4123
|
+
createKeyPairSignerFromPrivateKeyBytes2(newKeyBytes)
|
|
4124
|
+
]);
|
|
4125
|
+
console.log(`[ClawRouter]`);
|
|
4126
|
+
console.log(`[ClawRouter] \u26A0 SOLANA WALLET MIGRATION DETECTED`);
|
|
4127
|
+
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`);
|
|
4128
|
+
console.log(`[ClawRouter] Old address (secp256k1): ${oldSigner.address}`);
|
|
4129
|
+
console.log(`[ClawRouter] New address (SLIP-10): ${newSigner.address}`);
|
|
4130
|
+
console.log(`[ClawRouter]`);
|
|
4131
|
+
console.log(`[ClawRouter] Your Solana wallet derivation has been fixed to use`);
|
|
4132
|
+
console.log(`[ClawRouter] SLIP-10 Ed25519 (Phantom/Solflare compatible).`);
|
|
4133
|
+
console.log(`[ClawRouter]`);
|
|
4134
|
+
console.log(`[ClawRouter] If you had funds in the old wallet, run:`);
|
|
4135
|
+
console.log(`[ClawRouter] /wallet migrate-solana`);
|
|
4136
|
+
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`);
|
|
4137
|
+
console.log(`[ClawRouter]`);
|
|
4138
|
+
} catch {
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
3332
4141
|
async function resolveOrGenerateWalletKey() {
|
|
3333
4142
|
const saved = await loadSavedWallet();
|
|
3334
4143
|
if (saved) {
|
|
@@ -3336,13 +4145,19 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3336
4145
|
const mnemonic = await loadMnemonic();
|
|
3337
4146
|
if (mnemonic) {
|
|
3338
4147
|
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
3339
|
-
|
|
4148
|
+
const result2 = {
|
|
3340
4149
|
key: saved,
|
|
3341
4150
|
address: account.address,
|
|
3342
4151
|
source: "saved",
|
|
3343
4152
|
mnemonic,
|
|
3344
4153
|
solanaPrivateKeyBytes: solanaKeyBytes
|
|
3345
4154
|
};
|
|
4155
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy(mnemonic);
|
|
4156
|
+
if (Buffer.from(legacyKeyBytes).toString("hex") !== Buffer.from(solanaKeyBytes).toString("hex")) {
|
|
4157
|
+
result2.legacySolanaKeyBytes = legacyKeyBytes;
|
|
4158
|
+
await logMigrationWarning(legacyKeyBytes, solanaKeyBytes);
|
|
4159
|
+
}
|
|
4160
|
+
return result2;
|
|
3346
4161
|
}
|
|
3347
4162
|
return { key: saved, address: account.address, source: "saved" };
|
|
3348
4163
|
}
|
|
@@ -3352,13 +4167,19 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3352
4167
|
const mnemonic = await loadMnemonic();
|
|
3353
4168
|
if (mnemonic) {
|
|
3354
4169
|
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
3355
|
-
|
|
4170
|
+
const result2 = {
|
|
3356
4171
|
key: envKey,
|
|
3357
4172
|
address: account.address,
|
|
3358
4173
|
source: "env",
|
|
3359
4174
|
mnemonic,
|
|
3360
4175
|
solanaPrivateKeyBytes: solanaKeyBytes
|
|
3361
4176
|
};
|
|
4177
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy(mnemonic);
|
|
4178
|
+
if (Buffer.from(legacyKeyBytes).toString("hex") !== Buffer.from(solanaKeyBytes).toString("hex")) {
|
|
4179
|
+
result2.legacySolanaKeyBytes = legacyKeyBytes;
|
|
4180
|
+
await logMigrationWarning(legacyKeyBytes, solanaKeyBytes);
|
|
4181
|
+
}
|
|
4182
|
+
return result2;
|
|
3362
4183
|
}
|
|
3363
4184
|
return { key: envKey, address: account.address, source: "env" };
|
|
3364
4185
|
}
|
|
@@ -3374,9 +4195,7 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3374
4195
|
async function setupSolana() {
|
|
3375
4196
|
const existing = await loadMnemonic();
|
|
3376
4197
|
if (existing) {
|
|
3377
|
-
throw new Error(
|
|
3378
|
-
"Solana wallet already set up. Mnemonic file exists at " + MNEMONIC_FILE
|
|
3379
|
-
);
|
|
4198
|
+
throw new Error("Solana wallet already set up. Mnemonic file exists at " + MNEMONIC_FILE);
|
|
3380
4199
|
}
|
|
3381
4200
|
const savedKey = await loadSavedWallet();
|
|
3382
4201
|
if (!savedKey) {
|
|
@@ -5121,7 +5940,9 @@ async function startProxy(options) {
|
|
|
5121
5940
|
const paymentChain = options.paymentChain ?? await resolvePaymentChain();
|
|
5122
5941
|
const apiBase = options.apiBase ?? (paymentChain === "solana" && solanaPrivateKeyBytes ? BLOCKRUN_SOLANA_API : BLOCKRUN_API);
|
|
5123
5942
|
if (paymentChain === "solana" && !solanaPrivateKeyBytes) {
|
|
5124
|
-
console.warn(
|
|
5943
|
+
console.warn(
|
|
5944
|
+
`[ClawRouter] Payment chain is Solana but no Solana keys provided. Using Base (EVM).`
|
|
5945
|
+
);
|
|
5125
5946
|
} else if (paymentChain === "solana") {
|
|
5126
5947
|
console.log(`[ClawRouter] Payment chain: Solana (${BLOCKRUN_SOLANA_API})`);
|
|
5127
5948
|
}
|
|
@@ -5142,15 +5963,17 @@ async function startProxy(options) {
|
|
|
5142
5963
|
);
|
|
5143
5964
|
}
|
|
5144
5965
|
} else if (paymentChain !== "base") {
|
|
5145
|
-
console.warn(
|
|
5966
|
+
console.warn(
|
|
5967
|
+
`[ClawRouter] Existing proxy on port ${listenPort} does not report paymentChain (pre-v0.11 instance). Assuming Base.`
|
|
5968
|
+
);
|
|
5146
5969
|
throw new Error(
|
|
5147
5970
|
`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.`
|
|
5148
5971
|
);
|
|
5149
5972
|
}
|
|
5150
5973
|
let reuseSolanaAddress;
|
|
5151
5974
|
if (solanaPrivateKeyBytes) {
|
|
5152
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
5153
|
-
const solanaSigner = await
|
|
5975
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
5976
|
+
const solanaSigner = await createKeyPairSignerFromPrivateKeyBytes2(solanaPrivateKeyBytes);
|
|
5154
5977
|
reuseSolanaAddress = solanaSigner.address;
|
|
5155
5978
|
}
|
|
5156
5979
|
const balanceMonitor2 = paymentChain === "solana" && reuseSolanaAddress ? new SolanaBalanceMonitor(reuseSolanaAddress) : new BalanceMonitor(account2.address);
|
|
@@ -5173,8 +5996,8 @@ async function startProxy(options) {
|
|
|
5173
5996
|
let solanaAddress;
|
|
5174
5997
|
if (solanaPrivateKeyBytes) {
|
|
5175
5998
|
const { registerExactSvmScheme } = await import("@x402/svm/exact/client");
|
|
5176
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
5177
|
-
const solanaSigner = await
|
|
5999
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
6000
|
+
const solanaSigner = await createKeyPairSignerFromPrivateKeyBytes2(solanaPrivateKeyBytes);
|
|
5178
6001
|
solanaAddress = solanaSigner.address;
|
|
5179
6002
|
registerExactSvmScheme(x402, { signer: solanaSigner });
|
|
5180
6003
|
console.log(`[ClawRouter] Solana x402 scheme registered: ${solanaAddress}`);
|
|
@@ -5341,7 +6164,11 @@ async function startProxy(options) {
|
|
|
5341
6164
|
const existingProxy2 = await checkExistingProxy(listenPort);
|
|
5342
6165
|
if (existingProxy2) {
|
|
5343
6166
|
console.log(`[ClawRouter] Existing proxy detected on port ${listenPort}, reusing`);
|
|
5344
|
-
rejectAttempt({
|
|
6167
|
+
rejectAttempt({
|
|
6168
|
+
code: "REUSE_EXISTING",
|
|
6169
|
+
wallet: existingProxy2.wallet,
|
|
6170
|
+
existingChain: existingProxy2.paymentChain
|
|
6171
|
+
});
|
|
5345
6172
|
return;
|
|
5346
6173
|
}
|
|
5347
6174
|
if (attempt < PORT_RETRY_ATTEMPTS) {
|
|
@@ -5376,7 +6203,8 @@ async function startProxy(options) {
|
|
|
5376
6203
|
if (error.code === "REUSE_EXISTING" && error.wallet) {
|
|
5377
6204
|
if (error.existingChain && error.existingChain !== paymentChain) {
|
|
5378
6205
|
throw new Error(
|
|
5379
|
-
`Existing proxy on port ${listenPort} is using ${error.existingChain} but ${paymentChain} was requested. Stop the existing proxy first or use a different port
|
|
6206
|
+
`Existing proxy on port ${listenPort} is using ${error.existingChain} but ${paymentChain} was requested. Stop the existing proxy first or use a different port.`,
|
|
6207
|
+
{ cause: err }
|
|
5380
6208
|
);
|
|
5381
6209
|
}
|
|
5382
6210
|
const baseUrl2 = `http://127.0.0.1:${listenPort}`;
|
|
@@ -5484,15 +6312,12 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
|
|
|
5484
6312
|
} catch {
|
|
5485
6313
|
}
|
|
5486
6314
|
try {
|
|
5487
|
-
const response = await payFetch(
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
signal
|
|
5494
|
-
}
|
|
5495
|
-
);
|
|
6315
|
+
const response = await payFetch(upstreamUrl, {
|
|
6316
|
+
method,
|
|
6317
|
+
headers,
|
|
6318
|
+
body: requestBody.length > 0 ? new Uint8Array(requestBody) : void 0,
|
|
6319
|
+
signal
|
|
6320
|
+
});
|
|
5496
6321
|
if (response.status !== 200) {
|
|
5497
6322
|
const errorBody = await response.text();
|
|
5498
6323
|
const isProviderErr = isProviderError(response.status, errorBody);
|
|
@@ -6443,7 +7268,14 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6443
7268
|
if (balanceFallbackNotice) {
|
|
6444
7269
|
const noticeChunk = {
|
|
6445
7270
|
...baseChunk,
|
|
6446
|
-
choices: [
|
|
7271
|
+
choices: [
|
|
7272
|
+
{
|
|
7273
|
+
index,
|
|
7274
|
+
delta: { content: balanceFallbackNotice },
|
|
7275
|
+
logprobs: null,
|
|
7276
|
+
finish_reason: null
|
|
7277
|
+
}
|
|
7278
|
+
]
|
|
6447
7279
|
};
|
|
6448
7280
|
const noticeData = `data: ${JSON.stringify(noticeChunk)}
|
|
6449
7281
|
|
|
@@ -7009,6 +7841,7 @@ function formatDuration(seconds) {
|
|
|
7009
7841
|
|
|
7010
7842
|
// src/index.ts
|
|
7011
7843
|
init_wallet();
|
|
7844
|
+
init_solana_sweep();
|
|
7012
7845
|
|
|
7013
7846
|
// src/retry.ts
|
|
7014
7847
|
var DEFAULT_RETRY_CONFIG = {
|
|
@@ -7363,7 +8196,8 @@ async function startProxyInBackground(api) {
|
|
|
7363
8196
|
activeProxyHandle = proxy;
|
|
7364
8197
|
api.logger.info(`ClawRouter ready \u2014 smart routing enabled`);
|
|
7365
8198
|
api.logger.info(`Pricing: Simple ~$0.001 | Code ~$0.01 | Complex ~$0.05 | Free: $0`);
|
|
7366
|
-
const
|
|
8199
|
+
const currentChain = await resolvePaymentChain();
|
|
8200
|
+
const displayAddress = currentChain === "solana" && proxy.solanaAddress ? proxy.solanaAddress : wallet.address;
|
|
7367
8201
|
proxy.balanceMonitor.checkBalance().then((balance) => {
|
|
7368
8202
|
if (balance.isEmpty) {
|
|
7369
8203
|
api.logger.info(`Wallet: ${displayAddress} | Balance: $0.00`);
|
|
@@ -7448,8 +8282,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7448
8282
|
hasMnemonic = true;
|
|
7449
8283
|
const { deriveSolanaKeyBytes: deriveSolanaKeyBytes2 } = await Promise.resolve().then(() => (init_wallet(), wallet_exports));
|
|
7450
8284
|
const solKeyBytes = deriveSolanaKeyBytes2(mnemonic);
|
|
7451
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
7452
|
-
const signer = await
|
|
8285
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8286
|
+
const signer = await createKeyPairSignerFromPrivateKeyBytes2(solKeyBytes);
|
|
7453
8287
|
lines.push(
|
|
7454
8288
|
"",
|
|
7455
8289
|
"**Solana:**",
|
|
@@ -7490,8 +8324,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7490
8324
|
await savePaymentChain("solana");
|
|
7491
8325
|
const { deriveSolanaKeyBytes: deriveSolanaKeyBytes2 } = await Promise.resolve().then(() => (init_wallet(), wallet_exports));
|
|
7492
8326
|
const solKeyBytes = deriveSolanaKeyBytes2(existingMnemonic);
|
|
7493
|
-
const { createKeyPairSignerFromPrivateKeyBytes:
|
|
7494
|
-
const signer2 = await
|
|
8327
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes3 } = await import("@solana/kit");
|
|
8328
|
+
const signer2 = await createKeyPairSignerFromPrivateKeyBytes3(solKeyBytes);
|
|
7495
8329
|
solanaAddr = signer2.address;
|
|
7496
8330
|
return {
|
|
7497
8331
|
text: [
|
|
@@ -7505,8 +8339,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7505
8339
|
}
|
|
7506
8340
|
const { solanaPrivateKeyBytes } = await setupSolana();
|
|
7507
8341
|
await savePaymentChain("solana");
|
|
7508
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
7509
|
-
const signer = await
|
|
8342
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8343
|
+
const signer = await createKeyPairSignerFromPrivateKeyBytes2(solanaPrivateKeyBytes);
|
|
7510
8344
|
return {
|
|
7511
8345
|
text: [
|
|
7512
8346
|
"**Solana Wallet Set Up**",
|
|
@@ -7527,6 +8361,88 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7527
8361
|
};
|
|
7528
8362
|
}
|
|
7529
8363
|
}
|
|
8364
|
+
if (subcommand === "migrate-solana") {
|
|
8365
|
+
try {
|
|
8366
|
+
if (!existsSync2(MNEMONIC_FILE)) {
|
|
8367
|
+
return {
|
|
8368
|
+
text: "No mnemonic file found. Solana wallet not set up \u2014 nothing to migrate.",
|
|
8369
|
+
isError: true
|
|
8370
|
+
};
|
|
8371
|
+
}
|
|
8372
|
+
const mnemonic = readTextFileSync(MNEMONIC_FILE).trim();
|
|
8373
|
+
if (!mnemonic) {
|
|
8374
|
+
return { text: "Mnemonic file is empty.", isError: true };
|
|
8375
|
+
}
|
|
8376
|
+
const { deriveSolanaKeyBytes: deriveSolanaKeyBytes2, deriveSolanaKeyBytesLegacy: deriveSolanaKeyBytesLegacy2 } = await Promise.resolve().then(() => (init_wallet(), wallet_exports));
|
|
8377
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8378
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy2(mnemonic);
|
|
8379
|
+
const newKeyBytes = deriveSolanaKeyBytes2(mnemonic);
|
|
8380
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
8381
|
+
createKeyPairSignerFromPrivateKeyBytes2(legacyKeyBytes),
|
|
8382
|
+
createKeyPairSignerFromPrivateKeyBytes2(newKeyBytes)
|
|
8383
|
+
]);
|
|
8384
|
+
if (oldSigner.address === newSigner.address) {
|
|
8385
|
+
return { text: "Legacy and new Solana addresses are the same. No migration needed." };
|
|
8386
|
+
}
|
|
8387
|
+
let oldUsdcText = "unknown";
|
|
8388
|
+
try {
|
|
8389
|
+
const { SolanaBalanceMonitor: SolanaBalanceMonitor2 } = await Promise.resolve().then(() => (init_solana_balance(), solana_balance_exports));
|
|
8390
|
+
const monitor = new SolanaBalanceMonitor2(oldSigner.address);
|
|
8391
|
+
const balance = await monitor.checkBalance();
|
|
8392
|
+
oldUsdcText = balance.balanceUSD;
|
|
8393
|
+
if (balance.isEmpty) {
|
|
8394
|
+
return {
|
|
8395
|
+
text: [
|
|
8396
|
+
"**Solana Migration Status**",
|
|
8397
|
+
"",
|
|
8398
|
+
`Old wallet (secp256k1): \`${oldSigner.address}\``,
|
|
8399
|
+
` USDC: $0.00`,
|
|
8400
|
+
"",
|
|
8401
|
+
`New wallet (SLIP-10): \`${newSigner.address}\``,
|
|
8402
|
+
"",
|
|
8403
|
+
"No USDC in old wallet. Nothing to sweep.",
|
|
8404
|
+
"Your new SLIP-10 address is Phantom/Solflare compatible."
|
|
8405
|
+
].join("\n")
|
|
8406
|
+
};
|
|
8407
|
+
}
|
|
8408
|
+
} catch {
|
|
8409
|
+
}
|
|
8410
|
+
const { sweepSolanaWallet: sweepSolanaWallet2 } = await Promise.resolve().then(() => (init_solana_sweep(), solana_sweep_exports));
|
|
8411
|
+
const result = await sweepSolanaWallet2(legacyKeyBytes, newSigner.address);
|
|
8412
|
+
if ("error" in result) {
|
|
8413
|
+
return {
|
|
8414
|
+
text: [
|
|
8415
|
+
"**Solana Migration Failed**",
|
|
8416
|
+
"",
|
|
8417
|
+
`Old wallet: \`${result.oldAddress}\` (USDC: ${oldUsdcText})`,
|
|
8418
|
+
`New wallet: \`${result.newAddress || newSigner.address}\``,
|
|
8419
|
+
"",
|
|
8420
|
+
`Error: ${result.error}`
|
|
8421
|
+
].join("\n"),
|
|
8422
|
+
isError: true
|
|
8423
|
+
};
|
|
8424
|
+
}
|
|
8425
|
+
return {
|
|
8426
|
+
text: [
|
|
8427
|
+
"**Solana Migration Complete**",
|
|
8428
|
+
"",
|
|
8429
|
+
`Swept **${result.transferred}** USDC from old to new wallet.`,
|
|
8430
|
+
"",
|
|
8431
|
+
`Old wallet: \`${result.oldAddress}\``,
|
|
8432
|
+
`New wallet: \`${result.newAddress}\``,
|
|
8433
|
+
`TX: https://solscan.io/tx/${result.txSignature}`,
|
|
8434
|
+
"",
|
|
8435
|
+
"Your new SLIP-10 address is Phantom/Solflare compatible.",
|
|
8436
|
+
"You can recover it from your 24-word mnemonic in any standard wallet."
|
|
8437
|
+
].join("\n")
|
|
8438
|
+
};
|
|
8439
|
+
} catch (err) {
|
|
8440
|
+
return {
|
|
8441
|
+
text: `Migration failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
8442
|
+
isError: true
|
|
8443
|
+
};
|
|
8444
|
+
}
|
|
8445
|
+
}
|
|
7530
8446
|
if (subcommand === "base") {
|
|
7531
8447
|
try {
|
|
7532
8448
|
await savePaymentChain("base");
|
|
@@ -7540,7 +8456,7 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7540
8456
|
};
|
|
7541
8457
|
}
|
|
7542
8458
|
}
|
|
7543
|
-
let evmBalanceText
|
|
8459
|
+
let evmBalanceText;
|
|
7544
8460
|
try {
|
|
7545
8461
|
const monitor = new BalanceMonitor(address);
|
|
7546
8462
|
const balance = await monitor.checkBalance();
|
|
@@ -7555,8 +8471,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7555
8471
|
const mnemonic = readTextFileSync(MNEMONIC_FILE).trim();
|
|
7556
8472
|
if (mnemonic) {
|
|
7557
8473
|
const solKeyBytes = deriveSolanaKeyBytes2(mnemonic);
|
|
7558
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
7559
|
-
const signer = await
|
|
8474
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8475
|
+
const signer = await createKeyPairSignerFromPrivateKeyBytes2(solKeyBytes);
|
|
7560
8476
|
const solAddr = signer.address;
|
|
7561
8477
|
let solBalanceText = "Balance: (checking...)";
|
|
7562
8478
|
try {
|
|
@@ -7598,7 +8514,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7598
8514
|
"\u2022 `/wallet export` - Export private key for backup",
|
|
7599
8515
|
!solanaSection ? "\u2022 `/wallet solana` - Enable Solana payments" : "",
|
|
7600
8516
|
solanaSection ? "\u2022 `/wallet base` - Switch to Base (EVM)" : "",
|
|
7601
|
-
solanaSection ? "\u2022 `/wallet solana` - Switch to Solana" : ""
|
|
8517
|
+
solanaSection ? "\u2022 `/wallet solana` - Switch to Solana" : "",
|
|
8518
|
+
solanaSection ? "\u2022 `/wallet migrate-solana` - Sweep funds from old Solana wallet" : ""
|
|
7602
8519
|
].filter(Boolean).join("\n")
|
|
7603
8520
|
};
|
|
7604
8521
|
}
|
|
@@ -7774,6 +8691,7 @@ export {
|
|
|
7774
8691
|
deriveAllKeys,
|
|
7775
8692
|
deriveEvmKey,
|
|
7776
8693
|
deriveSolanaKeyBytes,
|
|
8694
|
+
deriveSolanaKeyBytesLegacy,
|
|
7777
8695
|
fetchWithRetry,
|
|
7778
8696
|
formatDuration,
|
|
7779
8697
|
formatStatsAscii,
|
|
@@ -7801,6 +8719,12 @@ export {
|
|
|
7801
8719
|
route,
|
|
7802
8720
|
savePaymentChain,
|
|
7803
8721
|
setupSolana,
|
|
7804
|
-
startProxy
|
|
8722
|
+
startProxy,
|
|
8723
|
+
sweepSolanaWallet
|
|
7805
8724
|
};
|
|
8725
|
+
/*! Bundled license information:
|
|
8726
|
+
|
|
8727
|
+
@noble/hashes/esm/utils.js:
|
|
8728
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8729
|
+
*/
|
|
7806
8730
|
//# sourceMappingURL=index.js.map
|