@toon-protocol/client 2.1.1 → 3.0.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/dist/anon-daemon-ZFBL6EYA.js +230 -0
- package/dist/anon-daemon-ZFBL6EYA.js.map +1 -0
- package/dist/chunk-32MD3CXE.js +27 -0
- package/dist/chunk-32MD3CXE.js.map +1 -0
- package/dist/{chunk-DD7TJKP6.js → chunk-4I3JQ7KA.js} +2 -2
- package/dist/{chunk-J6JVCKNV.js → chunk-7MPONJW5.js} +39 -1
- package/dist/chunk-7MPONJW5.js.map +1 -0
- package/dist/{chunk-ENNSPYP4.js → chunk-GDWZ736I.js} +289 -143
- package/dist/chunk-GDWZ736I.js.map +1 -0
- package/dist/chunk-GOLBDUNV.js +143 -0
- package/dist/chunk-GOLBDUNV.js.map +1 -0
- package/dist/cli/main.js +63 -11
- package/dist/cli/main.js.map +1 -1
- package/dist/{client-ACUZCR5A.js → client-TEP26FMO.js} +4 -3
- package/dist/index.d.ts +328 -126
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/socks-CCMHMB35.js +15 -0
- package/dist/socks-CCMHMB35.js.map +1 -0
- package/dist/transport/hidden-service.d.ts +116 -0
- package/dist/transport/hidden-service.js +15 -0
- package/dist/transport/hidden-service.js.map +1 -0
- package/package.json +7 -1
- package/dist/chunk-ENNSPYP4.js.map +0 -1
- package/dist/chunk-J6JVCKNV.js.map +0 -1
- /package/dist/{chunk-DD7TJKP6.js.map → chunk-4I3JQ7KA.js.map} +0 -0
- /package/dist/{client-ACUZCR5A.js.map → client-TEP26FMO.js.map} +0 -0
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEVNET,
|
|
3
|
+
assertRoutableHsHostname,
|
|
3
4
|
base58Decode,
|
|
4
5
|
base58Encode,
|
|
5
6
|
defaultRpcUrl,
|
|
6
7
|
deriveFullIdentity,
|
|
7
|
-
evmIdentityFromKey
|
|
8
|
-
|
|
8
|
+
evmIdentityFromKey,
|
|
9
|
+
isHiddenServiceUrl
|
|
10
|
+
} from "./chunk-7MPONJW5.js";
|
|
11
|
+
import {
|
|
12
|
+
validateSocks5hUrl
|
|
13
|
+
} from "./chunk-32MD3CXE.js";
|
|
9
14
|
|
|
10
15
|
// src/client/errors.ts
|
|
11
16
|
var ToonClientError = class extends Error {
|
|
@@ -312,12 +317,11 @@ function decodeGeneralizedTime(buf, offset) {
|
|
|
312
317
|
return { value, bytesRead: GENERALIZED_TIME_LENGTH };
|
|
313
318
|
}
|
|
314
319
|
function serializeIlpPrepare(packet) {
|
|
315
|
-
const condition = packet.executionCondition.length === 32 ? packet.executionCondition : new Uint8Array(32);
|
|
316
320
|
return concat(
|
|
317
321
|
writeUint8(ILPPacketType.PREPARE),
|
|
318
322
|
encodeVarUInt(packet.amount),
|
|
319
323
|
encodeGeneralizedTime(packet.expiresAt),
|
|
320
|
-
|
|
324
|
+
writeUint8(packet.greeting ? 1 : 0),
|
|
321
325
|
encodeVarOctetString(textEncoder.encode(packet.destination)),
|
|
322
326
|
encodeVarOctetString(packet.data)
|
|
323
327
|
);
|
|
@@ -336,11 +340,17 @@ function deserializeIlpPrepare(buf) {
|
|
|
336
340
|
offset
|
|
337
341
|
);
|
|
338
342
|
offset += timeBytes;
|
|
339
|
-
if (offset
|
|
340
|
-
throw new Error("Buffer underflow reading PREPARE
|
|
343
|
+
if (offset >= buf.length) {
|
|
344
|
+
throw new Error("Buffer underflow reading PREPARE greeting flag");
|
|
341
345
|
}
|
|
342
|
-
const
|
|
343
|
-
|
|
346
|
+
const greetingByte = buf[offset];
|
|
347
|
+
if (greetingByte !== 0 && greetingByte !== 1) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
`Malformed PREPARE greeting flag: expected 0x00 or 0x01, got 0x${greetingByte.toString(16).padStart(2, "0")}`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
const greeting = greetingByte === 1;
|
|
353
|
+
offset += 1;
|
|
344
354
|
const { value: destinationBytes, bytesRead: destBytes } = decodeVarOctetString(buf, offset);
|
|
345
355
|
offset += destBytes;
|
|
346
356
|
const destination = textDecoder.decode(destinationBytes);
|
|
@@ -349,7 +359,7 @@ function deserializeIlpPrepare(buf) {
|
|
|
349
359
|
type: ILPPacketType.PREPARE,
|
|
350
360
|
amount,
|
|
351
361
|
destination,
|
|
352
|
-
|
|
362
|
+
greeting,
|
|
353
363
|
expiresAt,
|
|
354
364
|
data
|
|
355
365
|
};
|
|
@@ -676,53 +686,45 @@ function decodeUtf8(bytes) {
|
|
|
676
686
|
return new TextDecoder().decode(bytes);
|
|
677
687
|
}
|
|
678
688
|
|
|
679
|
-
// src/utils/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
689
|
+
// src/utils/fulfillment.ts
|
|
690
|
+
var FULFILLMENT_LENGTH = 32;
|
|
691
|
+
function fulfillmentMatches(returned, expected) {
|
|
692
|
+
if (returned === void 0 || returned.length !== FULFILLMENT_LENGTH) {
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
if (expected.length !== FULFILLMENT_LENGTH) return false;
|
|
696
|
+
for (let i = 0; i < FULFILLMENT_LENGTH; i++) {
|
|
697
|
+
if (returned[i] !== expected[i]) return false;
|
|
687
698
|
}
|
|
688
699
|
return true;
|
|
689
700
|
}
|
|
690
|
-
function
|
|
691
|
-
if (
|
|
701
|
+
function assertValidFulfillment(fulfillment) {
|
|
702
|
+
if (fulfillment.length !== FULFILLMENT_LENGTH) {
|
|
692
703
|
throw new Error(
|
|
693
|
-
`
|
|
704
|
+
`an expected fulfillment must be exactly ${FULFILLMENT_LENGTH} bytes, got ${fulfillment.length}`
|
|
694
705
|
);
|
|
695
706
|
}
|
|
696
707
|
}
|
|
697
|
-
function fulfillmentMatchesCondition(fulfillment, condition) {
|
|
698
|
-
if (fulfillment === void 0 || fulfillment.length !== CONDITION_LENGTH) {
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
const digest = sha256(fulfillment);
|
|
702
|
-
for (let i = 0; i < CONDITION_LENGTH; i++) {
|
|
703
|
-
if (digest[i] !== condition[i]) return false;
|
|
704
|
-
}
|
|
705
|
-
return true;
|
|
706
|
-
}
|
|
707
708
|
|
|
708
709
|
// src/ilp/ilp-send.ts
|
|
709
|
-
function
|
|
710
|
-
if (
|
|
711
|
-
return typeof
|
|
710
|
+
function resolveExpectedFulfillment(fulfillment) {
|
|
711
|
+
if (fulfillment === void 0) return void 0;
|
|
712
|
+
return typeof fulfillment === "string" ? fromBase64(fulfillment) : fulfillment;
|
|
712
713
|
}
|
|
714
|
+
var PACKET_EXPIRY_HEADROOM_MS = 15e3;
|
|
713
715
|
function resolveExpiresAt(expiresAt, timeoutMs) {
|
|
714
|
-
if (expiresAt === void 0) return new Date(Date.now() + timeoutMs);
|
|
716
|
+
if (expiresAt === void 0) return new Date(Date.now() + timeoutMs + PACKET_EXPIRY_HEADROOM_MS);
|
|
715
717
|
return expiresAt instanceof Date ? new Date(expiresAt.getTime()) : new Date(expiresAt);
|
|
716
718
|
}
|
|
717
719
|
var FULFILLMENT_MISMATCH_CODE = "F99";
|
|
718
|
-
var FULFILLMENT_MISMATCH_MESSAGE = "FULFILL fulfillment
|
|
719
|
-
function mapIlpResponse(packet,
|
|
720
|
+
var FULFILLMENT_MISMATCH_MESSAGE = "FULFILL fulfillment is not the one this packet's sealed secret derives (ADR 0019) \u2014 packet counted failed";
|
|
721
|
+
function mapIlpResponse(packet, expectedFulfillment) {
|
|
720
722
|
if (packet.type === ILPPacketType.FULFILL) {
|
|
721
723
|
const dataField = packet.data.length > 0 ? { data: toBase64(packet.data) } : {};
|
|
722
|
-
if (
|
|
724
|
+
if (expectedFulfillment === void 0) {
|
|
723
725
|
return { accepted: true, ...dataField };
|
|
724
726
|
}
|
|
725
|
-
if (!
|
|
727
|
+
if (!fulfillmentMatches(packet.fulfillment, expectedFulfillment)) {
|
|
726
728
|
return {
|
|
727
729
|
accepted: false,
|
|
728
730
|
code: FULFILLMENT_MISMATCH_CODE,
|
|
@@ -1320,11 +1322,10 @@ var BtpRuntimeClient = class {
|
|
|
1320
1322
|
* Sends an ILP packet via BTP with auto-reconnect on connection errors.
|
|
1321
1323
|
* Satisfies IlpClient interface.
|
|
1322
1324
|
*
|
|
1323
|
-
* `params` may carry
|
|
1324
|
-
* `
|
|
1325
|
-
*
|
|
1326
|
-
*
|
|
1327
|
-
* as a failed result — see `mapIlpResponse`.
|
|
1325
|
+
* `params` may carry an `expectedFulfillment` (the sender's end-to-end
|
|
1326
|
+
* check, ADR 0069), a `greeting` flag and an explicit `expiresAt`. With an
|
|
1327
|
+
* expected fulfilment the FULFILL preimage is compared against it and a
|
|
1328
|
+
* mismatch is surfaced as a failed result — see `mapIlpResponse`.
|
|
1328
1329
|
*/
|
|
1329
1330
|
async sendIlpPacket(params) {
|
|
1330
1331
|
return withRetry(() => this._sendIlpPacketOnce(params), {
|
|
@@ -1341,8 +1342,8 @@ var BtpRuntimeClient = class {
|
|
|
1341
1342
|
* Sends a balance proof claim via BTP protocol data, then sends an ILP packet.
|
|
1342
1343
|
* Auto-reconnects on connection errors.
|
|
1343
1344
|
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1345
|
+
* `expectedFulfillment` / `greeting` / `expiresAt` semantics are identical
|
|
1346
|
+
* to {@link sendIlpPacket}.
|
|
1346
1347
|
*/
|
|
1347
1348
|
async sendIlpPacketWithClaim(params, claim) {
|
|
1348
1349
|
return withRetry(() => this._sendIlpPacketWithClaimOnce(params, claim), {
|
|
@@ -1386,27 +1387,29 @@ var BtpRuntimeClient = class {
|
|
|
1386
1387
|
);
|
|
1387
1388
|
}
|
|
1388
1389
|
/**
|
|
1389
|
-
* Build the ILP PREPARE for a send, applying the
|
|
1390
|
-
* explicit expiry when provided
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1390
|
+
* Build the ILP PREPARE for a send, applying the
|
|
1391
|
+
* explicit expiry when provided, carrying the `greeting` flag ADR 0069 put
|
|
1392
|
+
* where the execution condition used to be, and validating that an expected
|
|
1393
|
+
* fulfilment is exactly 32 bytes (a wrong-length one could never match a
|
|
1394
|
+
* real FULFILL, so every delivery would be counted failed).
|
|
1394
1395
|
*/
|
|
1395
1396
|
buildPrepare(params) {
|
|
1396
|
-
const
|
|
1397
|
-
|
|
1398
|
-
|
|
1397
|
+
const expectedFulfillment = resolveExpectedFulfillment(
|
|
1398
|
+
params.expectedFulfillment
|
|
1399
|
+
);
|
|
1400
|
+
if (expectedFulfillment !== void 0) {
|
|
1401
|
+
assertValidFulfillment(expectedFulfillment);
|
|
1399
1402
|
}
|
|
1400
1403
|
return {
|
|
1401
1404
|
prepare: {
|
|
1402
1405
|
type: 12,
|
|
1403
1406
|
amount: BigInt(params.amount),
|
|
1404
1407
|
destination: params.destination,
|
|
1405
|
-
|
|
1408
|
+
greeting: params.greeting ?? false,
|
|
1406
1409
|
expiresAt: resolveExpiresAt(params.expiresAt, params.timeout ?? 3e4),
|
|
1407
1410
|
data: fromBase64(params.data)
|
|
1408
1411
|
},
|
|
1409
|
-
|
|
1412
|
+
expectedFulfillment
|
|
1410
1413
|
};
|
|
1411
1414
|
}
|
|
1412
1415
|
/**
|
|
@@ -1416,10 +1419,10 @@ var BtpRuntimeClient = class {
|
|
|
1416
1419
|
if (!this._isConnected) {
|
|
1417
1420
|
await this.reconnect();
|
|
1418
1421
|
}
|
|
1419
|
-
const { prepare,
|
|
1422
|
+
const { prepare, expectedFulfillment } = this.buildPrepare(params);
|
|
1420
1423
|
const response = await this.btpClient.sendPacket(prepare);
|
|
1421
1424
|
return {
|
|
1422
|
-
...mapIlpResponse(response.packet,
|
|
1425
|
+
...mapIlpResponse(response.packet, expectedFulfillment),
|
|
1423
1426
|
...readResponseMeta(response.protocolData)
|
|
1424
1427
|
};
|
|
1425
1428
|
}
|
|
@@ -1440,10 +1443,10 @@ var BtpRuntimeClient = class {
|
|
|
1440
1443
|
data: encodeUtf8(JSON.stringify(claim))
|
|
1441
1444
|
}
|
|
1442
1445
|
];
|
|
1443
|
-
const { prepare,
|
|
1446
|
+
const { prepare, expectedFulfillment } = this.buildPrepare(params);
|
|
1444
1447
|
const response = await this.btpClient.sendPacket(prepare, protocolData);
|
|
1445
1448
|
return {
|
|
1446
|
-
...mapIlpResponse(response.packet,
|
|
1449
|
+
...mapIlpResponse(response.packet, expectedFulfillment),
|
|
1447
1450
|
...readResponseMeta(response.protocolData)
|
|
1448
1451
|
};
|
|
1449
1452
|
}
|
|
@@ -1611,11 +1614,10 @@ var HttpIlpClient = class {
|
|
|
1611
1614
|
* this only on free/zero-amount routes; paid writes must use
|
|
1612
1615
|
* {@link sendIlpPacketWithClaim}. Satisfies the IlpClient interface.
|
|
1613
1616
|
*
|
|
1614
|
-
* `params` may carry
|
|
1615
|
-
* `
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
* as a failed result — see {@link mapIlpResponse}.
|
|
1617
|
+
* `params` may carry an `expectedFulfillment` (the sender's end-to-end
|
|
1618
|
+
* check, ADR 0069), a `greeting` flag and an explicit `expiresAt`. With an
|
|
1619
|
+
* expected fulfilment the FULFILL preimage is compared against it and a
|
|
1620
|
+
* mismatch is surfaced as a failed result — see {@link mapIlpResponse}.
|
|
1619
1621
|
*/
|
|
1620
1622
|
async sendIlpPacket(params) {
|
|
1621
1623
|
return withRetry(() => this.postPrepare(params), {
|
|
@@ -1631,8 +1633,8 @@ var HttpIlpClient = class {
|
|
|
1631
1633
|
* the BTP path attaches as the `payment-channel-claim` protocolData entry —
|
|
1632
1634
|
* we base64(JSON.stringify(claim)) it, byte-for-byte identical to BTP.
|
|
1633
1635
|
*
|
|
1634
|
-
*
|
|
1635
|
-
*
|
|
1636
|
+
* `expectedFulfillment` / `greeting` / `expiresAt` semantics are identical
|
|
1637
|
+
* to {@link sendIlpPacket}.
|
|
1636
1638
|
*/
|
|
1637
1639
|
async sendIlpPacketWithClaim(params, claim) {
|
|
1638
1640
|
return withRetry(() => this.postPrepare(params, claim), {
|
|
@@ -1710,15 +1712,17 @@ var HttpIlpClient = class {
|
|
|
1710
1712
|
*/
|
|
1711
1713
|
async postPrepare(params, claim) {
|
|
1712
1714
|
const requestTimeout = params.timeout ?? this.timeout;
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1715
|
-
|
|
1715
|
+
const expectedFulfillment = resolveExpectedFulfillment(
|
|
1716
|
+
params.expectedFulfillment
|
|
1717
|
+
);
|
|
1718
|
+
if (expectedFulfillment !== void 0) {
|
|
1719
|
+
assertValidFulfillment(expectedFulfillment);
|
|
1716
1720
|
}
|
|
1717
1721
|
const prepare = serializeIlpPrepare({
|
|
1718
1722
|
type: ILPPacketType.PREPARE,
|
|
1719
1723
|
amount: BigInt(params.amount),
|
|
1720
1724
|
destination: params.destination,
|
|
1721
|
-
|
|
1725
|
+
greeting: params.greeting ?? false,
|
|
1722
1726
|
expiresAt: resolveExpiresAt(params.expiresAt, requestTimeout),
|
|
1723
1727
|
data: fromBase64(params.data)
|
|
1724
1728
|
});
|
|
@@ -1740,7 +1744,7 @@ var HttpIlpClient = class {
|
|
|
1740
1744
|
signal: controller.signal
|
|
1741
1745
|
});
|
|
1742
1746
|
clearTimeout(timeoutId);
|
|
1743
|
-
return await this.mapResponse(response,
|
|
1747
|
+
return await this.mapResponse(response, expectedFulfillment);
|
|
1744
1748
|
} catch (error) {
|
|
1745
1749
|
clearTimeout(timeoutId);
|
|
1746
1750
|
throw this.mapTransportError(error, requestTimeout);
|
|
@@ -1751,11 +1755,11 @@ var HttpIlpClient = class {
|
|
|
1751
1755
|
* to a transport error. Per the wire contract, ILP-level rejects arrive as a
|
|
1752
1756
|
* 200 + REJECT body — only HTTP non-2xx means a transport-layer failure.
|
|
1753
1757
|
*
|
|
1754
|
-
* When `
|
|
1755
|
-
* it; a mismatch yields `accepted: false` (shared `mapIlpResponse`
|
|
1756
|
-
* identical to the BTP path).
|
|
1758
|
+
* When `expectedFulfillment` is given the FULFILL preimage is compared
|
|
1759
|
+
* against it; a mismatch yields `accepted: false` (shared `mapIlpResponse`
|
|
1760
|
+
* logic, identical to the BTP path).
|
|
1757
1761
|
*/
|
|
1758
|
-
async mapResponse(response,
|
|
1762
|
+
async mapResponse(response, expectedFulfillment) {
|
|
1759
1763
|
if (response.ok) {
|
|
1760
1764
|
const buf = new Uint8Array(await response.arrayBuffer());
|
|
1761
1765
|
if (buf.length === 0) {
|
|
@@ -1764,7 +1768,7 @@ var HttpIlpClient = class {
|
|
|
1764
1768
|
);
|
|
1765
1769
|
}
|
|
1766
1770
|
return {
|
|
1767
|
-
...mapIlpResponse(deserializeIlpPacket(buf),
|
|
1771
|
+
...mapIlpResponse(deserializeIlpPacket(buf), expectedFulfillment),
|
|
1768
1772
|
...readResponseMeta2(response.headers)
|
|
1769
1773
|
};
|
|
1770
1774
|
}
|
|
@@ -2219,16 +2223,18 @@ var ConnectorEdgeClient = class {
|
|
|
2219
2223
|
async probe(endpoint, params, claim) {
|
|
2220
2224
|
const base = connectorEdgeBaseUrl(endpoint);
|
|
2221
2225
|
const url = `${base}/ilp/probe`;
|
|
2222
|
-
const
|
|
2223
|
-
|
|
2224
|
-
|
|
2226
|
+
const expectedFulfillment = resolveExpectedFulfillment(
|
|
2227
|
+
params.expectedFulfillment
|
|
2228
|
+
);
|
|
2229
|
+
if (expectedFulfillment !== void 0) {
|
|
2230
|
+
assertValidFulfillment(expectedFulfillment);
|
|
2225
2231
|
}
|
|
2226
2232
|
const timeout = params.timeout ?? this.timeout;
|
|
2227
2233
|
const prepare = serializeIlpPrepare({
|
|
2228
2234
|
type: ILPPacketType.PREPARE,
|
|
2229
2235
|
amount: BigInt(params.amount),
|
|
2230
2236
|
destination: params.destination,
|
|
2231
|
-
|
|
2237
|
+
greeting: params.greeting ?? false,
|
|
2232
2238
|
expiresAt: resolveExpiresAt(params.expiresAt, timeout),
|
|
2233
2239
|
data: fromBase64(params.data)
|
|
2234
2240
|
});
|
|
@@ -2276,7 +2282,7 @@ var ConnectorEdgeClient = class {
|
|
|
2276
2282
|
);
|
|
2277
2283
|
}
|
|
2278
2284
|
return {
|
|
2279
|
-
...mapIlpResponse(deserializeIlpPacket(body),
|
|
2285
|
+
...mapIlpResponse(deserializeIlpPacket(body), expectedFulfillment),
|
|
2280
2286
|
...readResponseMeta2(response.headers)
|
|
2281
2287
|
};
|
|
2282
2288
|
}
|
|
@@ -2336,13 +2342,11 @@ var ConnectorEdgeClient = class {
|
|
|
2336
2342
|
);
|
|
2337
2343
|
}
|
|
2338
2344
|
const base = connectorEdgeBaseUrl(endpoint);
|
|
2339
|
-
const condition = new Uint8Array(32);
|
|
2340
|
-
condition[0] = 1;
|
|
2341
2345
|
const prepare = serializeIlpPrepare({
|
|
2342
2346
|
type: ILPPacketType.PREPARE,
|
|
2343
2347
|
amount: 0n,
|
|
2344
2348
|
destination,
|
|
2345
|
-
|
|
2349
|
+
greeting: false,
|
|
2346
2350
|
expiresAt: new Date(Date.now() + 3e4),
|
|
2347
2351
|
data: new Uint8Array(0)
|
|
2348
2352
|
});
|
|
@@ -2653,11 +2657,11 @@ function parseConnectorRouteTerms(body) {
|
|
|
2653
2657
|
|
|
2654
2658
|
// src/btp/transport-select.ts
|
|
2655
2659
|
function selectTransport(description, preference = "auto", baseUrl = description.readFrom) {
|
|
2656
|
-
const
|
|
2660
|
+
const http2 = resolveEndpoint2(description.httpEndpoint, baseUrl);
|
|
2657
2661
|
const btp = resolveEndpoint2(description.btpEndpoint, baseUrl);
|
|
2658
2662
|
const required = description.requiredTransport;
|
|
2659
2663
|
if (preference === "http" || preference === "btp") {
|
|
2660
|
-
const url = preference === "http" ?
|
|
2664
|
+
const url = preference === "http" ? http2 : btp;
|
|
2661
2665
|
if (url === void 0) {
|
|
2662
2666
|
throw new TransportRequiredError(
|
|
2663
2667
|
`the connector publishes no ${preference} endpoint` + (required !== void 0 ? `; its self-description requires the ${required} transport` : ""),
|
|
@@ -2667,7 +2671,7 @@ function selectTransport(description, preference = "auto", baseUrl = description
|
|
|
2667
2671
|
return { kind: preference, url };
|
|
2668
2672
|
}
|
|
2669
2673
|
if (required !== void 0) {
|
|
2670
|
-
const url = required === "http" ?
|
|
2674
|
+
const url = required === "http" ? http2 : btp;
|
|
2671
2675
|
if (url === void 0) {
|
|
2672
2676
|
throw new TransportRequiredError(
|
|
2673
2677
|
`the connector requires the ${required} transport but publishes no ${required} endpoint`,
|
|
@@ -2676,7 +2680,7 @@ function selectTransport(description, preference = "auto", baseUrl = description
|
|
|
2676
2680
|
}
|
|
2677
2681
|
return { kind: required, url };
|
|
2678
2682
|
}
|
|
2679
|
-
if (
|
|
2683
|
+
if (http2 !== void 0) return { kind: "http", url: http2 };
|
|
2680
2684
|
if (btp !== void 0) return { kind: "btp", url: btp };
|
|
2681
2685
|
throw new TransportRequiredError(
|
|
2682
2686
|
"the connector publishes neither an httpEndpoint nor a btpEndpoint"
|
|
@@ -3518,11 +3522,25 @@ var ChannelManager = class _ChannelManager {
|
|
|
3518
3522
|
// src/channel/OnChainChannelClient.ts
|
|
3519
3523
|
import { ed25519 as ed255192 } from "@noble/curves/ed25519.js";
|
|
3520
3524
|
|
|
3525
|
+
// src/transport/rpc.ts
|
|
3526
|
+
import { http } from "viem";
|
|
3527
|
+
function rpcTransport(url, dispatcher, options = {}) {
|
|
3528
|
+
const { timeout, retryCount } = options;
|
|
3529
|
+
return http(url, {
|
|
3530
|
+
...timeout !== void 0 ? { timeout } : {},
|
|
3531
|
+
...retryCount !== void 0 ? { retryCount } : {},
|
|
3532
|
+
...dispatcher !== void 0 ? { fetchOptions: { dispatcher } } : {}
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3535
|
+
function rpcFetch(dispatcher, fetchImpl = globalThis.fetch) {
|
|
3536
|
+
if (dispatcher === void 0) return fetchImpl;
|
|
3537
|
+
return ((input, init) => fetchImpl(input, { ...init, dispatcher }));
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3521
3540
|
// src/channel/evm/TokenNetworkClient.ts
|
|
3522
3541
|
import {
|
|
3523
3542
|
createPublicClient,
|
|
3524
3543
|
createWalletClient,
|
|
3525
|
-
http,
|
|
3526
3544
|
maxUint256,
|
|
3527
3545
|
decodeEventLog,
|
|
3528
3546
|
defineChain
|
|
@@ -3721,10 +3739,13 @@ var TokenNetworkClient = class {
|
|
|
3721
3739
|
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
|
|
3722
3740
|
rpcUrls: { default: { http: [config.rpcUrl] } }
|
|
3723
3741
|
});
|
|
3724
|
-
this.publicClient = createPublicClient({
|
|
3742
|
+
this.publicClient = createPublicClient({
|
|
3743
|
+
transport: rpcTransport(config.rpcUrl, config.rpcDispatcher),
|
|
3744
|
+
chain: viemChain
|
|
3745
|
+
});
|
|
3725
3746
|
this.walletClient = createWalletClient({
|
|
3726
3747
|
account: config.signer.account,
|
|
3727
|
-
transport:
|
|
3748
|
+
transport: rpcTransport(config.rpcUrl, config.rpcDispatcher),
|
|
3728
3749
|
chain: viemChain
|
|
3729
3750
|
});
|
|
3730
3751
|
}
|
|
@@ -4126,7 +4147,7 @@ function sleep2(ms) {
|
|
|
4126
4147
|
|
|
4127
4148
|
// src/channel/solana/payment-channel.ts
|
|
4128
4149
|
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
4129
|
-
import { sha256
|
|
4150
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
4130
4151
|
var TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
4131
4152
|
var SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
4132
4153
|
var RENT_SYSVAR_ID = "SysvarRent111111111111111111111111111111111";
|
|
@@ -4221,7 +4242,7 @@ function findProgramAddress(seeds, programId) {
|
|
|
4221
4242
|
input.set(programId, offset);
|
|
4222
4243
|
offset += programId.length;
|
|
4223
4244
|
input.set(PDA_MARKER, offset);
|
|
4224
|
-
const hash =
|
|
4245
|
+
const hash = sha256(input);
|
|
4225
4246
|
if (!isOnCurve(hash)) return { pda: hash, bump };
|
|
4226
4247
|
}
|
|
4227
4248
|
throw new Error("Could not find a viable PDA bump seed");
|
|
@@ -4287,8 +4308,13 @@ function isAccountNotFoundError(err) {
|
|
|
4287
4308
|
err.rpcMessage
|
|
4288
4309
|
);
|
|
4289
4310
|
}
|
|
4311
|
+
function resolveRpcTarget(target) {
|
|
4312
|
+
if (typeof target === "string") return { url: target, fetchImpl: globalThis.fetch };
|
|
4313
|
+
return { url: target.url, fetchImpl: target.fetchImpl ?? globalThis.fetch };
|
|
4314
|
+
}
|
|
4290
4315
|
async function solanaRpc(rpcUrl, method, params = []) {
|
|
4291
|
-
const
|
|
4316
|
+
const { url, fetchImpl } = resolveRpcTarget(rpcUrl);
|
|
4317
|
+
const res = await fetchImpl(url, {
|
|
4292
4318
|
method: "POST",
|
|
4293
4319
|
headers: { "Content-Type": "application/json" },
|
|
4294
4320
|
body: JSON.stringify({
|
|
@@ -4861,8 +4887,15 @@ var DEFAULT_CHALLENGE_DURATION = 3600n;
|
|
|
4861
4887
|
var SolanaChannelClient = class {
|
|
4862
4888
|
constructor(config) {
|
|
4863
4889
|
this.config = config;
|
|
4890
|
+
this.rpc = config.rpcFetch === void 0 ? config.rpcUrl : { url: config.rpcUrl, fetchImpl: config.rpcFetch };
|
|
4864
4891
|
}
|
|
4865
4892
|
config;
|
|
4893
|
+
/**
|
|
4894
|
+
* Where this client's JSON-RPC goes, and through which `fetch`. Built once:
|
|
4895
|
+
* every call below passes it straight to `payment-channel.js`, which is the
|
|
4896
|
+
* only place that looks inside it.
|
|
4897
|
+
*/
|
|
4898
|
+
rpc;
|
|
4866
4899
|
/**
|
|
4867
4900
|
* The channel PDA for a counterparty — the claim's `channelAccount`, and the
|
|
4868
4901
|
* account the connector reads. Deterministic from the pair and the mint, and
|
|
@@ -4909,7 +4942,7 @@ var SolanaChannelClient = class {
|
|
|
4909
4942
|
payerTokenAccount: params.payerTokenAccount ?? this.ownTokenAccount()
|
|
4910
4943
|
} : void 0;
|
|
4911
4944
|
const result = await openSolanaChannel({
|
|
4912
|
-
rpcUrl: this.
|
|
4945
|
+
rpcUrl: this.rpc,
|
|
4913
4946
|
programId: this.config.programId,
|
|
4914
4947
|
tokenMint: this.config.tokenMint,
|
|
4915
4948
|
payerSeed: this.config.payerSeed,
|
|
@@ -4927,7 +4960,7 @@ var SolanaChannelClient = class {
|
|
|
4927
4960
|
/** Add collateral to an existing channel. Incremental, not a target. */
|
|
4928
4961
|
async deposit(channelId, amount, payerTokenAccount) {
|
|
4929
4962
|
const { depositTxSignature } = await depositSolanaChannel({
|
|
4930
|
-
rpcUrl: this.
|
|
4963
|
+
rpcUrl: this.rpc,
|
|
4931
4964
|
programId: this.config.programId,
|
|
4932
4965
|
channelPDA: channelId,
|
|
4933
4966
|
payerSeed: this.config.payerSeed,
|
|
@@ -4943,7 +4976,7 @@ var SolanaChannelClient = class {
|
|
|
4943
4976
|
*/
|
|
4944
4977
|
async close(channelId) {
|
|
4945
4978
|
const { closeTxSignature } = await closeSolanaChannel({
|
|
4946
|
-
rpcUrl: this.
|
|
4979
|
+
rpcUrl: this.rpc,
|
|
4947
4980
|
programId: this.config.programId,
|
|
4948
4981
|
channelPDA: channelId,
|
|
4949
4982
|
closerSeed: this.config.payerSeed,
|
|
@@ -4973,7 +5006,7 @@ var SolanaChannelClient = class {
|
|
|
4973
5006
|
}
|
|
4974
5007
|
const mint = account.tokenMint ?? this.config.tokenMint;
|
|
4975
5008
|
const { settleTxSignature } = await settleSolanaChannel({
|
|
4976
|
-
rpcUrl: this.
|
|
5009
|
+
rpcUrl: this.rpc,
|
|
4977
5010
|
programId: this.config.programId,
|
|
4978
5011
|
channelPDA: channelId,
|
|
4979
5012
|
callerSeed: this.config.payerSeed,
|
|
@@ -4990,7 +5023,7 @@ var SolanaChannelClient = class {
|
|
|
4990
5023
|
*/
|
|
4991
5024
|
async redeem(params) {
|
|
4992
5025
|
const { claimTxSignature } = await claimFromSolanaChannel({
|
|
4993
|
-
rpcUrl: this.
|
|
5026
|
+
rpcUrl: this.rpc,
|
|
4994
5027
|
programId: this.config.programId,
|
|
4995
5028
|
channelPDA: params.channelId,
|
|
4996
5029
|
claimerPubkey: params.claimer,
|
|
@@ -5012,7 +5045,7 @@ var SolanaChannelClient = class {
|
|
|
5012
5045
|
* reads an amply-funded vault as our own headroom.
|
|
5013
5046
|
*/
|
|
5014
5047
|
async read(channelId) {
|
|
5015
|
-
const account = await getChannelAccountState(this.
|
|
5048
|
+
const account = await getChannelAccountState(this.rpc, channelId);
|
|
5016
5049
|
const weAreA = account.participantA === this.config.payerPubkey;
|
|
5017
5050
|
const deadline = settleableAt(account);
|
|
5018
5051
|
return {
|
|
@@ -5037,6 +5070,7 @@ var OnChainChannelClient = class {
|
|
|
5037
5070
|
chainRpcUrls;
|
|
5038
5071
|
solanaConfig;
|
|
5039
5072
|
readConsistency;
|
|
5073
|
+
rpcDispatcher;
|
|
5040
5074
|
channelContext = /* @__PURE__ */ new Map();
|
|
5041
5075
|
evmClients = /* @__PURE__ */ new Map();
|
|
5042
5076
|
solanaClients = /* @__PURE__ */ new Map();
|
|
@@ -5045,6 +5079,7 @@ var OnChainChannelClient = class {
|
|
|
5045
5079
|
this.chainRpcUrls = config.chainRpcUrls;
|
|
5046
5080
|
this.solanaConfig = config.solanaConfig;
|
|
5047
5081
|
this.readConsistency = config.readConsistency;
|
|
5082
|
+
this.rpcDispatcher = config.rpcDispatcher;
|
|
5048
5083
|
}
|
|
5049
5084
|
/**
|
|
5050
5085
|
* Late-bind the Solana config. The Ed25519 keypair is derived asynchronously
|
|
@@ -5092,7 +5127,8 @@ var OnChainChannelClient = class {
|
|
|
5092
5127
|
chain,
|
|
5093
5128
|
rpcUrl,
|
|
5094
5129
|
signer: this.evmSigner,
|
|
5095
|
-
...this.readConsistency ? { readConsistency: this.readConsistency } : {}
|
|
5130
|
+
...this.readConsistency ? { readConsistency: this.readConsistency } : {},
|
|
5131
|
+
...this.rpcDispatcher !== void 0 ? { rpcDispatcher: this.rpcDispatcher } : {}
|
|
5096
5132
|
});
|
|
5097
5133
|
this.evmClients.set(chain, client);
|
|
5098
5134
|
return client;
|
|
@@ -5307,6 +5343,7 @@ var OnChainChannelClient = class {
|
|
|
5307
5343
|
const payerSeed = cfg.keypair.slice(0, 32);
|
|
5308
5344
|
const client = new SolanaChannelClient({
|
|
5309
5345
|
rpcUrl: cfg.rpcUrl,
|
|
5346
|
+
...cfg.rpcFetch ? { rpcFetch: cfg.rpcFetch } : {},
|
|
5310
5347
|
programId: program,
|
|
5311
5348
|
tokenMint: mint,
|
|
5312
5349
|
payerSeed,
|
|
@@ -5727,8 +5764,8 @@ function decodeEnvelope(buf, direction) {
|
|
|
5727
5764
|
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
5728
5765
|
import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
5729
5766
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
5730
|
-
import { sha256 as
|
|
5731
|
-
import { randomBytes
|
|
5767
|
+
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
5768
|
+
import { randomBytes } from "@noble/hashes/utils.js";
|
|
5732
5769
|
var GIFTWRAP_NONCE_LENGTH = 12;
|
|
5733
5770
|
var GIFTWRAP_SECRET_LENGTH = 32;
|
|
5734
5771
|
var GIFTWRAP_PUBLIC_KEY_LENGTH = 65;
|
|
@@ -5774,7 +5811,7 @@ function concat3(parts) {
|
|
|
5774
5811
|
return out;
|
|
5775
5812
|
}
|
|
5776
5813
|
function hkdfKey(ikm, info) {
|
|
5777
|
-
return hkdf(
|
|
5814
|
+
return hkdf(sha2562, ikm, void 0, info, 32);
|
|
5778
5815
|
}
|
|
5779
5816
|
function encryptWithNonce(key, plaintext, nonce) {
|
|
5780
5817
|
return concat3([nonce, chacha20poly1305(key, nonce).encrypt(plaintext)]);
|
|
@@ -5841,8 +5878,8 @@ function sealRequestWithRandomness(plaintext, receiverPublicKey, ephemeralSecret
|
|
|
5841
5878
|
}
|
|
5842
5879
|
function sealRequest(plaintext, receiverPublicKey) {
|
|
5843
5880
|
const ephemeralSecretKey = secp256k1.utils.randomSecretKey();
|
|
5844
|
-
const sharedSecret =
|
|
5845
|
-
const nonce =
|
|
5881
|
+
const sharedSecret = randomBytes(GIFTWRAP_SECRET_LENGTH);
|
|
5882
|
+
const nonce = randomBytes(GIFTWRAP_NONCE_LENGTH);
|
|
5846
5883
|
return {
|
|
5847
5884
|
wrapped: sealRequestWithRandomness(
|
|
5848
5885
|
plaintext,
|
|
@@ -5901,7 +5938,7 @@ function sealResponse(sharedSecret, plaintext) {
|
|
|
5901
5938
|
return sealResponseWithRandomness(
|
|
5902
5939
|
sharedSecret,
|
|
5903
5940
|
plaintext,
|
|
5904
|
-
|
|
5941
|
+
randomBytes(GIFTWRAP_NONCE_LENGTH)
|
|
5905
5942
|
);
|
|
5906
5943
|
}
|
|
5907
5944
|
function openResponse(sharedSecret, bytes) {
|
|
@@ -5928,9 +5965,6 @@ function deriveFulfillment(sharedSecret) {
|
|
|
5928
5965
|
}
|
|
5929
5966
|
return hkdfKey(sharedSecret, FULFILLMENT_INFO);
|
|
5930
5967
|
}
|
|
5931
|
-
function deriveCondition(fulfillment) {
|
|
5932
|
-
return sha2563(fulfillment);
|
|
5933
|
-
}
|
|
5934
5968
|
|
|
5935
5969
|
// src/wire/sealed-exchange.ts
|
|
5936
5970
|
var SealedResponseError = class extends Error {
|
|
@@ -5948,12 +5982,10 @@ function sealExchange(request, connectorPublicKey) {
|
|
|
5948
5982
|
encodeEnvelopeRequest(request),
|
|
5949
5983
|
connectorPublicKey
|
|
5950
5984
|
);
|
|
5951
|
-
const fulfillment = deriveFulfillment(sharedSecret);
|
|
5952
5985
|
return {
|
|
5953
5986
|
data: wrapped,
|
|
5954
|
-
condition: deriveCondition(fulfillment),
|
|
5955
5987
|
sharedSecret,
|
|
5956
|
-
fulfillment
|
|
5988
|
+
fulfillment: deriveFulfillment(sharedSecret)
|
|
5957
5989
|
};
|
|
5958
5990
|
}
|
|
5959
5991
|
function readExchangeOutcome(result, data, sharedSecret) {
|
|
@@ -6193,10 +6225,13 @@ var InMemoryChannelStore = class {
|
|
|
6193
6225
|
|
|
6194
6226
|
// src/client/config.ts
|
|
6195
6227
|
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
6228
|
+
var DEFAULT_HS_TIMEOUT_MS = 12e4;
|
|
6196
6229
|
var DEFAULT_DEPOSIT = 100000n;
|
|
6197
6230
|
var DEFAULT_SETTLEMENT_TIMEOUT = 86400;
|
|
6198
6231
|
function resolveConfig(config) {
|
|
6199
6232
|
const connector = resolveConnector(config.connector);
|
|
6233
|
+
const connectorIsHiddenService = isHiddenServiceUrl(connector);
|
|
6234
|
+
const socksProxy = resolveSocksProxy(config.socksProxy, connector, connectorIsHiddenService);
|
|
6200
6235
|
const accountIndex = resolveAccountIndex(config.accountIndex);
|
|
6201
6236
|
const keyDerivation = config.keyDerivation ?? "standard";
|
|
6202
6237
|
const identity = resolveIdentity(config, keyDerivation, accountIndex);
|
|
@@ -6217,7 +6252,7 @@ function resolveConfig(config) {
|
|
|
6217
6252
|
);
|
|
6218
6253
|
}
|
|
6219
6254
|
const deposit = resolveDeposit(config.deposit);
|
|
6220
|
-
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
6255
|
+
const timeoutMs = config.timeoutMs ?? (connectorIsHiddenService ? DEFAULT_HS_TIMEOUT_MS : DEFAULT_TIMEOUT_MS2);
|
|
6221
6256
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
6222
6257
|
throw new ConfigError(`timeoutMs must be a positive number; got ${String(timeoutMs)}.`);
|
|
6223
6258
|
}
|
|
@@ -6242,6 +6277,10 @@ function resolveConfig(config) {
|
|
|
6242
6277
|
transport,
|
|
6243
6278
|
senderId: config.senderId,
|
|
6244
6279
|
deposit,
|
|
6280
|
+
connectorIsHiddenService,
|
|
6281
|
+
socksProxy,
|
|
6282
|
+
proxyRpc: config.proxyRpc ?? true,
|
|
6283
|
+
rpcDispatcher: void 0,
|
|
6245
6284
|
settlementTimeout,
|
|
6246
6285
|
autoOpenChannel: config.autoOpenChannel ?? true,
|
|
6247
6286
|
timeoutMs,
|
|
@@ -6282,8 +6321,41 @@ function resolveConnector(connector) {
|
|
|
6282
6321
|
`connector ${JSON.stringify(connector)} must be an http(s) URL; got ${JSON.stringify(base)}.`
|
|
6283
6322
|
);
|
|
6284
6323
|
}
|
|
6324
|
+
const host = new URL(base).hostname;
|
|
6325
|
+
if (/\.(anon|onion)$/.test(host)) {
|
|
6326
|
+
try {
|
|
6327
|
+
assertRoutableHsHostname(host);
|
|
6328
|
+
} catch (error) {
|
|
6329
|
+
throw new ConfigError(
|
|
6330
|
+
`connector ${JSON.stringify(connector)} is not reachable: ` + (error instanceof Error ? error.message : String(error)),
|
|
6331
|
+
error instanceof Error ? error : void 0
|
|
6332
|
+
);
|
|
6333
|
+
}
|
|
6334
|
+
}
|
|
6285
6335
|
return base;
|
|
6286
6336
|
}
|
|
6337
|
+
function resolveSocksProxy(socksProxy, connector, connectorIsHiddenService) {
|
|
6338
|
+
if (socksProxy === void 0) {
|
|
6339
|
+
if (!connectorIsHiddenService) return void 0;
|
|
6340
|
+
throw new ConfigError(
|
|
6341
|
+
`connector ${JSON.stringify(connector)} is a hidden service, which is reachable only through a SOCKS5h proxy. Set \`socksProxy\` to a running Anyone Protocol \`anon\` daemon (e.g. "socks5h://127.0.0.1:9050"), or use the \`toon\` CLI, which can start one for you.`
|
|
6342
|
+
);
|
|
6343
|
+
}
|
|
6344
|
+
if (!connectorIsHiddenService) {
|
|
6345
|
+
throw new ConfigError(
|
|
6346
|
+
`socksProxy is set, but connector ${JSON.stringify(connector)} is a clearnet address, so nothing would ride the proxy. Point \`connector\` at the node's .anyone address, or drop \`socksProxy\`.`
|
|
6347
|
+
);
|
|
6348
|
+
}
|
|
6349
|
+
try {
|
|
6350
|
+
validateSocks5hUrl(socksProxy);
|
|
6351
|
+
} catch (error) {
|
|
6352
|
+
throw new ConfigError(
|
|
6353
|
+
error instanceof Error ? error.message : String(error),
|
|
6354
|
+
error instanceof Error ? error : void 0
|
|
6355
|
+
);
|
|
6356
|
+
}
|
|
6357
|
+
return socksProxy;
|
|
6358
|
+
}
|
|
6287
6359
|
function resolveAccountIndex(accountIndex) {
|
|
6288
6360
|
const index = accountIndex ?? 0;
|
|
6289
6361
|
if (!Number.isInteger(index) || index < 0) {
|
|
@@ -6679,7 +6751,7 @@ function localStatus(state) {
|
|
|
6679
6751
|
}
|
|
6680
6752
|
|
|
6681
6753
|
// src/wallet/balances.ts
|
|
6682
|
-
import { createPublicClient as createPublicClient2,
|
|
6754
|
+
import { createPublicClient as createPublicClient2, defineChain as defineChain2 } from "viem";
|
|
6683
6755
|
var ERC20_READ_ABI = [
|
|
6684
6756
|
{ name: "balanceOf", type: "function", stateMutability: "view", inputs: [{ name: "account", type: "address" }], outputs: [{ type: "uint256" }] },
|
|
6685
6757
|
{ name: "decimals", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "uint8" }] },
|
|
@@ -6706,7 +6778,10 @@ function rpcAbortSignal() {
|
|
|
6706
6778
|
async function readEvmTokenBalance(opts) {
|
|
6707
6779
|
const chainId = parseEvmChainId2(opts.chainKey);
|
|
6708
6780
|
const client = createPublicClient2({
|
|
6709
|
-
transport:
|
|
6781
|
+
transport: rpcTransport(opts.rpcUrl, opts.rpcDispatcher, {
|
|
6782
|
+
...rpcTimeoutMs() ? { timeout: rpcTimeoutMs() } : {},
|
|
6783
|
+
retryCount: 1
|
|
6784
|
+
}),
|
|
6710
6785
|
chain: defineChain2({
|
|
6711
6786
|
id: chainId,
|
|
6712
6787
|
name: opts.chainKey,
|
|
@@ -6729,7 +6804,10 @@ async function readEvmTokenBalance(opts) {
|
|
|
6729
6804
|
async function readEvmNativeBalance(opts) {
|
|
6730
6805
|
const chainId = parseEvmChainId2(opts.chainKey);
|
|
6731
6806
|
const client = createPublicClient2({
|
|
6732
|
-
transport:
|
|
6807
|
+
transport: rpcTransport(opts.rpcUrl, opts.rpcDispatcher, {
|
|
6808
|
+
...rpcTimeoutMs() ? { timeout: rpcTimeoutMs() } : {},
|
|
6809
|
+
retryCount: 1
|
|
6810
|
+
}),
|
|
6733
6811
|
chain: defineChain2({
|
|
6734
6812
|
id: chainId,
|
|
6735
6813
|
name: opts.chainKey,
|
|
@@ -6813,14 +6891,14 @@ async function readWalletBalances(sources) {
|
|
|
6813
6891
|
const { fetchImpl } = sources;
|
|
6814
6892
|
const tasks = [];
|
|
6815
6893
|
if (sources.evm) {
|
|
6816
|
-
const { chainKey, rpcUrl, owner, tokenAddress } = sources.evm;
|
|
6894
|
+
const { chainKey, rpcUrl, owner, tokenAddress, rpcDispatcher } = sources.evm;
|
|
6817
6895
|
tasks.push(
|
|
6818
6896
|
(async () => {
|
|
6819
6897
|
const out = { chain: "evm", chainKey, address: owner, tokens: [] };
|
|
6820
6898
|
const errors = [];
|
|
6821
6899
|
const [nativeR, tokenR] = await Promise.allSettled([
|
|
6822
|
-
readEvmNativeBalance({ rpcUrl, chainKey, owner }),
|
|
6823
|
-
tokenAddress ? readEvmTokenBalance({ rpcUrl, chainKey, tokenAddress, owner }) : Promise.resolve(void 0)
|
|
6900
|
+
readEvmNativeBalance({ rpcUrl, chainKey, owner, rpcDispatcher }),
|
|
6901
|
+
tokenAddress ? readEvmTokenBalance({ rpcUrl, chainKey, tokenAddress, owner, rpcDispatcher }) : Promise.resolve(void 0)
|
|
6824
6902
|
]);
|
|
6825
6903
|
foldNative(out, nativeR, errors);
|
|
6826
6904
|
foldToken(out, tokenR, tokenAddress, errors);
|
|
@@ -6856,7 +6934,6 @@ async function readWalletBalances(sources) {
|
|
|
6856
6934
|
import {
|
|
6857
6935
|
createPublicClient as createPublicClient3,
|
|
6858
6936
|
createWalletClient as createWalletClient2,
|
|
6859
|
-
http as http3,
|
|
6860
6937
|
defineChain as defineChain3
|
|
6861
6938
|
} from "viem";
|
|
6862
6939
|
import { ed25519 as ed255195 } from "@noble/curves/ed25519.js";
|
|
@@ -6940,6 +7017,9 @@ var ERC20_TRANSFER_ABI = [
|
|
|
6940
7017
|
outputs: [{ type: "bool" }]
|
|
6941
7018
|
}
|
|
6942
7019
|
];
|
|
7020
|
+
function solanaRpcTarget(cfg) {
|
|
7021
|
+
return cfg.rpcFetch === void 0 ? cfg.rpcUrl : { url: cfg.rpcUrl, fetchImpl: cfg.rpcFetch };
|
|
7022
|
+
}
|
|
6943
7023
|
function evmClients(cfg) {
|
|
6944
7024
|
const chainId = parseEvmChainId2(cfg.chainKey);
|
|
6945
7025
|
const viemChain = defineChain3({
|
|
@@ -6949,12 +7029,12 @@ function evmClients(cfg) {
|
|
|
6949
7029
|
rpcUrls: { default: { http: [cfg.rpcUrl] } }
|
|
6950
7030
|
});
|
|
6951
7031
|
const publicClient = createPublicClient3({
|
|
6952
|
-
transport:
|
|
7032
|
+
transport: rpcTransport(cfg.rpcUrl, cfg.rpcDispatcher),
|
|
6953
7033
|
chain: viemChain
|
|
6954
7034
|
});
|
|
6955
7035
|
const walletClient = createWalletClient2({
|
|
6956
7036
|
account: cfg.signer.account,
|
|
6957
|
-
transport:
|
|
7037
|
+
transport: rpcTransport(cfg.rpcUrl, cfg.rpcDispatcher),
|
|
6958
7038
|
chain: viemChain
|
|
6959
7039
|
});
|
|
6960
7040
|
return { publicClient, walletClient };
|
|
@@ -7058,20 +7138,21 @@ async function sendSolanaTransfer(cfg, params, amount) {
|
|
|
7058
7138
|
);
|
|
7059
7139
|
const payer = { publicKey: base58Decode(payerPubkey), privateKey: payerSeed };
|
|
7060
7140
|
const timeoutMs = params.confirmTimeoutMs ?? DEFAULT_SOLANA_CONFIRM_TIMEOUT_MS;
|
|
7141
|
+
const rpc = solanaRpcTarget(cfg);
|
|
7061
7142
|
if (params.asset === "native") {
|
|
7062
|
-
const lamports2 = await getLamports(
|
|
7143
|
+
const lamports2 = await getLamports(rpc, payerPubkey);
|
|
7063
7144
|
const need = amount + SOLANA_LAMPORTS_PER_SIGNATURE;
|
|
7064
7145
|
if (lamports2 < need) {
|
|
7065
7146
|
throw new InsufficientBalanceError(
|
|
7066
7147
|
`Solana wallet ${payerPubkey} holds ${lamports2} lamports, short of the ${amount}-lamport transfer plus the ${SOLANA_LAMPORTS_PER_SIGNATURE}-lamport signature fee.`
|
|
7067
7148
|
);
|
|
7068
7149
|
}
|
|
7069
|
-
const readDest2 = () => getLamports(
|
|
7150
|
+
const readDest2 = () => getLamports(rpc, params.to);
|
|
7070
7151
|
const before2 = await readDest2();
|
|
7071
7152
|
const data = new Uint8Array(12);
|
|
7072
7153
|
new DataView(data.buffer).setUint32(0, 2, true);
|
|
7073
7154
|
writeU64LE2(data, 4, amount);
|
|
7074
|
-
const txHash2 = await buildAndSendTransaction(
|
|
7155
|
+
const txHash2 = await buildAndSendTransaction(rpc, payer, [
|
|
7075
7156
|
{
|
|
7076
7157
|
programId: SOLANA_SYSTEM_PROGRAM_ID,
|
|
7077
7158
|
keys: [
|
|
@@ -7105,20 +7186,20 @@ async function sendSolanaTransfer(cfg, params, amount) {
|
|
|
7105
7186
|
);
|
|
7106
7187
|
}
|
|
7107
7188
|
const senderAta = deriveAssociatedTokenAccount(payerPubkey, cfg.tokenMint);
|
|
7108
|
-
const senderBalance = await getTokenAccountBalance(
|
|
7189
|
+
const senderBalance = await getTokenAccountBalance(rpc, senderAta);
|
|
7109
7190
|
if (senderBalance === null || senderBalance < amount) {
|
|
7110
7191
|
throw new InsufficientBalanceError(
|
|
7111
7192
|
`Solana token account ${senderAta} holds ${senderBalance ?? 0n} base units of ${cfg.tokenMint}, short of the ${amount} transfer.`
|
|
7112
7193
|
);
|
|
7113
7194
|
}
|
|
7114
|
-
const lamports = await getLamports(
|
|
7195
|
+
const lamports = await getLamports(rpc, payerPubkey);
|
|
7115
7196
|
if (lamports < SOLANA_LAMPORTS_PER_SIGNATURE) {
|
|
7116
7197
|
throw new InsufficientBalanceError(
|
|
7117
7198
|
`Solana wallet ${payerPubkey} holds ${lamports} lamports, below the ${SOLANA_LAMPORTS_PER_SIGNATURE}-lamport fee this token transfer needs.`
|
|
7118
7199
|
);
|
|
7119
7200
|
}
|
|
7120
7201
|
const destAta = deriveAssociatedTokenAccount(params.to, cfg.tokenMint);
|
|
7121
|
-
const readDest = async () => await getTokenAccountBalance(
|
|
7202
|
+
const readDest = async () => await getTokenAccountBalance(rpc, destAta) ?? 0n;
|
|
7122
7203
|
const before = await readDest();
|
|
7123
7204
|
const createAtaIx = {
|
|
7124
7205
|
programId: SOLANA_ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -7144,7 +7225,7 @@ async function sendSolanaTransfer(cfg, params, amount) {
|
|
|
7144
7225
|
],
|
|
7145
7226
|
data: transferData
|
|
7146
7227
|
};
|
|
7147
|
-
const txHash = await buildAndSendTransaction(
|
|
7228
|
+
const txHash = await buildAndSendTransaction(rpc, payer, [
|
|
7148
7229
|
createAtaIx,
|
|
7149
7230
|
transferIx
|
|
7150
7231
|
]);
|
|
@@ -7255,6 +7336,10 @@ async function fundWallet(faucetUrl, address, chain, options = {}) {
|
|
|
7255
7336
|
}
|
|
7256
7337
|
|
|
7257
7338
|
// src/client/wallet-facade.ts
|
|
7339
|
+
function solanaRpcFetch(config) {
|
|
7340
|
+
if (config.socksProxy === void 0) return config.fetch;
|
|
7341
|
+
return config.rpcDispatcher !== void 0 ? config.fetch : globalThis.fetch;
|
|
7342
|
+
}
|
|
7258
7343
|
var ClientWalletFacade = class {
|
|
7259
7344
|
deps;
|
|
7260
7345
|
evmSigner;
|
|
@@ -7273,7 +7358,9 @@ var ClientWalletFacade = class {
|
|
|
7273
7358
|
const { config } = this.deps;
|
|
7274
7359
|
const settlements = await this.settlements();
|
|
7275
7360
|
const wanted = chain !== void 0 ? [chain] : ["evm", "solana"];
|
|
7276
|
-
const sources = {
|
|
7361
|
+
const sources = {
|
|
7362
|
+
fetchImpl: solanaRpcFetch(config)
|
|
7363
|
+
};
|
|
7277
7364
|
for (const kind of wanted) {
|
|
7278
7365
|
const entry = settlements.get(kind);
|
|
7279
7366
|
if (kind === "evm" && config.identity.evm) {
|
|
@@ -7281,6 +7368,7 @@ var ClientWalletFacade = class {
|
|
|
7281
7368
|
chainKey: entry?.chain ?? "evm",
|
|
7282
7369
|
rpcUrl: config.rpcUrls.evm,
|
|
7283
7370
|
owner: config.identity.evm.address,
|
|
7371
|
+
...config.rpcDispatcher !== void 0 ? { rpcDispatcher: config.rpcDispatcher } : {},
|
|
7284
7372
|
...entry?.tokenAddress ? { tokenAddress: entry.tokenAddress } : {}
|
|
7285
7373
|
};
|
|
7286
7374
|
}
|
|
@@ -7321,12 +7409,14 @@ var ClientWalletFacade = class {
|
|
|
7321
7409
|
chainKey: entry?.kind === "evm" ? entry.chain : "evm",
|
|
7322
7410
|
rpcUrl: config.rpcUrls.evm,
|
|
7323
7411
|
signer: this.signer(),
|
|
7412
|
+
...config.rpcDispatcher !== void 0 ? { rpcDispatcher: config.rpcDispatcher } : {},
|
|
7324
7413
|
...entry?.tokenAddress ? { tokenAddress: entry.tokenAddress } : {}
|
|
7325
7414
|
}
|
|
7326
7415
|
} : {},
|
|
7327
7416
|
...config.identity.solana ? {
|
|
7328
7417
|
solana: {
|
|
7329
7418
|
rpcUrl: config.rpcUrls.solana,
|
|
7419
|
+
...config.rpcDispatcher !== void 0 ? { rpcFetch: solanaRpcFetch(config) } : {},
|
|
7330
7420
|
keypair: config.identity.solana.secretKey,
|
|
7331
7421
|
...entry?.tokenAddress ? { tokenMint: entry.tokenAddress } : {}
|
|
7332
7422
|
}
|
|
@@ -7471,7 +7561,7 @@ async function attempt(context, params) {
|
|
|
7471
7561
|
destination: params.destination,
|
|
7472
7562
|
amount: params.amount.toString(),
|
|
7473
7563
|
data: toBase64(params.exchange.data),
|
|
7474
|
-
|
|
7564
|
+
expectedFulfillment: params.exchange.fulfillment,
|
|
7475
7565
|
timeout: params.timeoutMs
|
|
7476
7566
|
},
|
|
7477
7567
|
claim
|
|
@@ -7495,7 +7585,7 @@ async function attemptUnpaid(context, params) {
|
|
|
7495
7585
|
destination: params.destination,
|
|
7496
7586
|
amount: params.amount.toString(),
|
|
7497
7587
|
data: toBase64(params.exchange.data),
|
|
7498
|
-
|
|
7588
|
+
expectedFulfillment: params.exchange.fulfillment,
|
|
7499
7589
|
timeout: params.timeoutMs
|
|
7500
7590
|
});
|
|
7501
7591
|
return { result: toSendResult(result, params, void 0), channelId: void 0 };
|
|
@@ -7654,9 +7744,11 @@ var ToonClient = class _ToonClient {
|
|
|
7654
7744
|
onChain;
|
|
7655
7745
|
carriage;
|
|
7656
7746
|
btpSession;
|
|
7747
|
+
hiddenService;
|
|
7657
7748
|
closed = false;
|
|
7658
7749
|
constructor(init) {
|
|
7659
7750
|
this.config = init.config;
|
|
7751
|
+
this.hiddenService = init.hiddenService;
|
|
7660
7752
|
this.edge = init.edge;
|
|
7661
7753
|
this.channels = init.channels;
|
|
7662
7754
|
this.description = init.description;
|
|
@@ -7691,7 +7783,9 @@ var ToonClient = class _ToonClient {
|
|
|
7691
7783
|
* @throws {NetworkError} the connector could not be reached.
|
|
7692
7784
|
*/
|
|
7693
7785
|
static async create(config) {
|
|
7694
|
-
const
|
|
7786
|
+
const base = resolveConfig(config);
|
|
7787
|
+
const hiddenService = await openHiddenService(base, config);
|
|
7788
|
+
const resolved = hiddenService?.config ?? base;
|
|
7695
7789
|
const edge = new ConnectorEdgeClient({
|
|
7696
7790
|
fetch: resolved.fetch,
|
|
7697
7791
|
timeout: resolved.timeoutMs
|
|
@@ -7721,7 +7815,15 @@ var ToonClient = class _ToonClient {
|
|
|
7721
7815
|
)
|
|
7722
7816
|
);
|
|
7723
7817
|
}
|
|
7724
|
-
return new _ToonClient({
|
|
7818
|
+
return new _ToonClient({
|
|
7819
|
+
config: resolved,
|
|
7820
|
+
edge,
|
|
7821
|
+
channels,
|
|
7822
|
+
description,
|
|
7823
|
+
chain,
|
|
7824
|
+
senderId,
|
|
7825
|
+
...hiddenService ? { hiddenService: hiddenService.transport } : {}
|
|
7826
|
+
});
|
|
7725
7827
|
}
|
|
7726
7828
|
/**
|
|
7727
7829
|
* The node's `GET /ilp`, cached for the life of this client.
|
|
@@ -7793,7 +7895,7 @@ var ToonClient = class _ToonClient {
|
|
|
7793
7895
|
destination,
|
|
7794
7896
|
amount: "0",
|
|
7795
7897
|
data: toBase64(exchange.data),
|
|
7796
|
-
|
|
7898
|
+
expectedFulfillment: exchange.fulfillment,
|
|
7797
7899
|
timeout: this.config.timeoutMs
|
|
7798
7900
|
},
|
|
7799
7901
|
claim
|
|
@@ -7870,8 +7972,27 @@ var ToonClient = class _ToonClient {
|
|
|
7870
7972
|
this.btpSession = void 0;
|
|
7871
7973
|
this.carriage = void 0;
|
|
7872
7974
|
if (session) await session.disconnect();
|
|
7975
|
+
if (this.hiddenService) await this.hiddenService.close();
|
|
7873
7976
|
}
|
|
7874
7977
|
// ─── Private ──────────────────────────────────────────────────────────────
|
|
7978
|
+
/**
|
|
7979
|
+
* Refuse an endpoint this client has no way to dial.
|
|
7980
|
+
*
|
|
7981
|
+
* A node's endpoints are its own strings, and a hidden-service node may publish
|
|
7982
|
+
* absolute `.anyone` ones. The configured client edge always wins on *whether*
|
|
7983
|
+
* we can reach the node — but a carriage resolved from the description can
|
|
7984
|
+
* still point somewhere the configured transport cannot go. Without a proxy
|
|
7985
|
+
* that address does not merely fail: the hostname goes out in a plaintext DNS
|
|
7986
|
+
* query first, which is precisely what a hidden service exists to prevent. So
|
|
7987
|
+
* this fails loudly, naming the proxy, before anything dials.
|
|
7988
|
+
*/
|
|
7989
|
+
assertEndpointReachable(endpoint) {
|
|
7990
|
+
if (this.config.socksProxy !== void 0) return;
|
|
7991
|
+
if (!isHiddenServiceUrl(endpoint)) return;
|
|
7992
|
+
throw new ConfigError(
|
|
7993
|
+
`The connector published the endpoint ${JSON.stringify(endpoint)}, which is a hidden service, but this client has no \`socksProxy\` to reach it through. Set one to a running Anyone Protocol \`anon\` daemon (e.g. "socks5h://127.0.0.1:9050"), or ask the operator for a clearnet endpoint.`
|
|
7994
|
+
);
|
|
7995
|
+
}
|
|
7875
7996
|
/** The port {@link send} runs against. */
|
|
7876
7997
|
sendContext() {
|
|
7877
7998
|
return {
|
|
@@ -7939,9 +8060,13 @@ var ToonClient = class _ToonClient {
|
|
|
7939
8060
|
const client = new OnChainChannelClient({
|
|
7940
8061
|
evmSigner: new EvmSigner(this.requireEvmKey()),
|
|
7941
8062
|
chainRpcUrls,
|
|
8063
|
+
...this.config.rpcDispatcher !== void 0 ? { rpcDispatcher: this.config.rpcDispatcher } : {},
|
|
7942
8064
|
...this.config.identity.solana ? {
|
|
7943
8065
|
solanaConfig: {
|
|
7944
8066
|
rpcUrl: this.config.rpcUrls.solana,
|
|
8067
|
+
// Same condition as the EVM dispatcher: proxied only when there is
|
|
8068
|
+
// a proxy and the caller has not opted RPC out of it.
|
|
8069
|
+
...this.config.rpcDispatcher !== void 0 ? { rpcFetch: this.config.fetch } : {},
|
|
7945
8070
|
keypair: this.config.identity.solana.secretKey,
|
|
7946
8071
|
// The DEFAULT only. Each channel opens under the program its own
|
|
7947
8072
|
// terms name, because ADR 0053 binds that program into the signed
|
|
@@ -7986,14 +8111,17 @@ var ToonClient = class _ToonClient {
|
|
|
7986
8111
|
}
|
|
7987
8112
|
if (this.carriage) return this.carriage;
|
|
7988
8113
|
const choice = selectTransport(description, this.config.transport);
|
|
7989
|
-
const
|
|
7990
|
-
|
|
8114
|
+
const httpEndpoint = choice.kind === "http" ? choice.url : httpEndpointOf(description, this.connector);
|
|
8115
|
+
this.assertEndpointReachable(choice.url);
|
|
8116
|
+
this.assertEndpointReachable(httpEndpoint);
|
|
8117
|
+
const http2 = new HttpIlpClient({
|
|
8118
|
+
httpEndpoint,
|
|
7991
8119
|
timeout: this.config.timeoutMs,
|
|
7992
8120
|
httpClient: this.config.fetch,
|
|
7993
8121
|
...this.config.createWebSocket ? { createWebSocket: this.config.createWebSocket } : {}
|
|
7994
8122
|
});
|
|
7995
8123
|
if (choice.kind === "http") {
|
|
7996
|
-
const carriage2 = { kind: "http", transport:
|
|
8124
|
+
const carriage2 = { kind: "http", transport: http2 };
|
|
7997
8125
|
this.carriage = carriage2;
|
|
7998
8126
|
return carriage2;
|
|
7999
8127
|
}
|
|
@@ -8017,7 +8145,7 @@ var ToonClient = class _ToonClient {
|
|
|
8017
8145
|
// HTTP fallback only where the node did not REQUIRE btp: falling back
|
|
8018
8146
|
// onto a carriage the route refuses would turn a recoverable socket
|
|
8019
8147
|
// outage into a `402` per request.
|
|
8020
|
-
...description.requiredTransport === "btp" ? {} : { fallback:
|
|
8148
|
+
...description.requiredTransport === "btp" ? {} : { fallback: http2 },
|
|
8021
8149
|
...this.config.btp.maxReconnectAttempts !== void 0 ? { maxReconnectAttempts: this.config.btp.maxReconnectAttempts } : {},
|
|
8022
8150
|
...this.config.btp.reconnectDelay !== void 0 ? { reconnectDelay: this.config.btp.reconnectDelay } : {}
|
|
8023
8151
|
})
|
|
@@ -8103,6 +8231,22 @@ function httpEndpointOf(description, connector) {
|
|
|
8103
8231
|
if (published === void 0) return `${connector}/ilp`;
|
|
8104
8232
|
return /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(published) ? published : new URL(published, connector).toString();
|
|
8105
8233
|
}
|
|
8234
|
+
async function openHiddenService(resolved, config) {
|
|
8235
|
+
const socksProxy = resolved.socksProxy;
|
|
8236
|
+
if (socksProxy === void 0) return void 0;
|
|
8237
|
+
const { createHiddenServiceTransport, probeSocks5Proxy } = await import("./socks-CCMHMB35.js");
|
|
8238
|
+
await probeSocks5Proxy(socksProxy);
|
|
8239
|
+
const transport = createHiddenServiceTransport(socksProxy);
|
|
8240
|
+
return {
|
|
8241
|
+
transport,
|
|
8242
|
+
config: {
|
|
8243
|
+
...resolved,
|
|
8244
|
+
fetch: config.fetch ?? transport.fetch,
|
|
8245
|
+
createWebSocket: config.createWebSocket ?? transport.createWebSocket,
|
|
8246
|
+
rpcDispatcher: resolved.proxyRpc ? transport.dispatcher : void 0
|
|
8247
|
+
}
|
|
8248
|
+
};
|
|
8249
|
+
}
|
|
8106
8250
|
|
|
8107
8251
|
export {
|
|
8108
8252
|
ToonClientError,
|
|
@@ -8146,7 +8290,8 @@ export {
|
|
|
8146
8290
|
toHex,
|
|
8147
8291
|
encodeUtf8,
|
|
8148
8292
|
decodeUtf8,
|
|
8149
|
-
|
|
8293
|
+
resolveExpectedFulfillment,
|
|
8294
|
+
PACKET_EXPIRY_HEADROOM_MS,
|
|
8150
8295
|
resolveExpiresAt,
|
|
8151
8296
|
FULFILLMENT_MISMATCH_CODE,
|
|
8152
8297
|
FULFILLMENT_MISMATCH_MESSAGE,
|
|
@@ -8187,6 +8332,8 @@ export {
|
|
|
8187
8332
|
sameSettlementAddress,
|
|
8188
8333
|
counterpartyMatch,
|
|
8189
8334
|
ChannelManager,
|
|
8335
|
+
rpcTransport,
|
|
8336
|
+
rpcFetch,
|
|
8190
8337
|
TOKEN_NETWORK_ABI,
|
|
8191
8338
|
TOKEN_NETWORK_REGISTRY_ABI,
|
|
8192
8339
|
ERC20_ABI,
|
|
@@ -8228,7 +8375,6 @@ export {
|
|
|
8228
8375
|
openResponse,
|
|
8229
8376
|
looksLikeSealedResponse,
|
|
8230
8377
|
deriveFulfillment,
|
|
8231
|
-
deriveCondition,
|
|
8232
8378
|
SealedResponseError,
|
|
8233
8379
|
sealExchange,
|
|
8234
8380
|
readExchangeOutcome,
|
|
@@ -8258,4 +8404,4 @@ export {
|
|
|
8258
8404
|
toEnvelopeRequest,
|
|
8259
8405
|
ToonClient
|
|
8260
8406
|
};
|
|
8261
|
-
//# sourceMappingURL=chunk-
|
|
8407
|
+
//# sourceMappingURL=chunk-GDWZ736I.js.map
|