beignet 0.8.0 → 0.8.2
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/cli/beignet-node.js +58 -7
- package/dist/cli/beignet-node.js.map +1 -1
- package/dist/cli/daemon.js +13 -2
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/errors.js +4 -0
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/http-rate-limiter.js +55 -1
- package/dist/cli/http-rate-limiter.js.map +1 -1
- package/dist/cli/openapi.js +5 -1
- package/dist/cli/openapi.js.map +1 -1
- package/dist/lightning/node/lightning-node.js +13 -7
- package/dist/lightning/node/lightning-node.js.map +1 -1
- package/dist/types/cli/beignet-node.d.ts +5 -0
- package/dist/types/cli/daemon.d.ts +1 -0
- package/dist/types/cli/errors.d.ts +2 -0
- package/dist/types/cli/http-rate-limiter.d.ts +2 -0
- package/dist/types/cli/types.d.ts +4 -0
- package/dist/types/lightning/node/lightning-node.d.ts +1 -0
- package/dist/wallet/index.js +8 -4
- package/dist/wallet/index.js.map +1 -1
- package/docs/AI_AGENT_GUIDE.md +1 -1
- package/package.json +1 -1
package/dist/cli/beignet-node.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.BeignetNode = exports.jsonToRouteHops = exports.routeHopsToJson = exports.parseScid = exports.formatScid = exports.defaultDataDirForMnemonic = void 0;
|
|
26
|
+
exports.BeignetNode = exports.jsonToRouteHops = exports.routeHopsToJson = exports.decodeOfferInput = exports.decodeInvoiceInput = exports.parseScid = exports.formatScid = exports.defaultDataDirForMnemonic = void 0;
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const net = __importStar(require("net"));
|
|
@@ -87,6 +87,24 @@ function parseScid(scid) {
|
|
|
87
87
|
throw new errors_1.BeignetError(errors_1.BeignetErrorCode.INVALID_PARAMS, `Invalid short channel id: ${scid} (expected <block>x<txIndex>x<output> or 16-char hex)`);
|
|
88
88
|
}
|
|
89
89
|
exports.parseScid = parseScid;
|
|
90
|
+
function decodeInvoiceInput(bolt11) {
|
|
91
|
+
try {
|
|
92
|
+
return (0, decode_1.decode)(bolt11);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
throw new errors_1.BeignetError(errors_1.BeignetErrorCode.INVALID_INVOICE, `Invalid invoice: ${err instanceof Error ? err.message : 'failed to decode'}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.decodeInvoiceInput = decodeInvoiceInput;
|
|
99
|
+
function decodeOfferInput(offerStr) {
|
|
100
|
+
try {
|
|
101
|
+
return (0, decode_2.decodeOffer)(offerStr);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
throw new errors_1.BeignetError(errors_1.BeignetErrorCode.INVALID_OFFER, `Invalid offer: ${err instanceof Error ? err.message : 'failed to decode'}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.decodeOfferInput = decodeOfferInput;
|
|
90
108
|
function routeHopsToJson(route) {
|
|
91
109
|
return route.hops.map((hop, idx) => {
|
|
92
110
|
const feeMsat = idx < route.hops.length - 1
|
|
@@ -296,6 +314,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
296
314
|
servers: electrumServer
|
|
297
315
|
},
|
|
298
316
|
disableMessagesOnCreate: true,
|
|
317
|
+
onMessage: (key, data) => this.onWalletMessage(key, data),
|
|
299
318
|
...(this.logger ? { logger: this.logger } : {}),
|
|
300
319
|
rbf: true,
|
|
301
320
|
storage: (0, wallet_storage_1.createWalletStorage)(this.storage)
|
|
@@ -1262,6 +1281,33 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
1262
1281
|
throw new errors_1.BeignetError('REFRESH_FAILED', result.error.message);
|
|
1263
1282
|
}
|
|
1264
1283
|
}
|
|
1284
|
+
onWalletMessage(key, data) {
|
|
1285
|
+
const relayed = {
|
|
1286
|
+
transactionReceived: {
|
|
1287
|
+
event: 'transaction:received',
|
|
1288
|
+
label: 'Transaction received'
|
|
1289
|
+
},
|
|
1290
|
+
transactionSent: {
|
|
1291
|
+
event: 'transaction:sent',
|
|
1292
|
+
label: 'Transaction sent'
|
|
1293
|
+
},
|
|
1294
|
+
transactionConfirmed: {
|
|
1295
|
+
event: 'transaction:confirmed',
|
|
1296
|
+
label: 'Transaction confirmed'
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
if (!(key in relayed))
|
|
1300
|
+
return;
|
|
1301
|
+
const { event, label } = relayed[key];
|
|
1302
|
+
const { transaction } = data;
|
|
1303
|
+
const info = this.toOnchainTxInfo(transaction);
|
|
1304
|
+
this.log('info', label, {
|
|
1305
|
+
txid: info.txid,
|
|
1306
|
+
type: info.type,
|
|
1307
|
+
valueSats: info.valueSats
|
|
1308
|
+
});
|
|
1309
|
+
this.emit(event, info);
|
|
1310
|
+
}
|
|
1265
1311
|
toOnchainTxInfo(tx) {
|
|
1266
1312
|
return {
|
|
1267
1313
|
txid: tx.txid,
|
|
@@ -1612,6 +1658,11 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
1612
1658
|
capacitySats: Number(ch.fundingSatoshis),
|
|
1613
1659
|
isAnchor: (0, types_3.isAnchorChannel)(ch.channelType ?? null)
|
|
1614
1660
|
};
|
|
1661
|
+
if (peerPubkey) {
|
|
1662
|
+
const splice = this.node.peerSupportsSplicing(peerPubkey);
|
|
1663
|
+
if (splice !== null)
|
|
1664
|
+
info.peerSupportsSplicing = splice;
|
|
1665
|
+
}
|
|
1615
1666
|
if (ch.fundingTxid)
|
|
1616
1667
|
info.fundingTxid = ch.fundingTxid;
|
|
1617
1668
|
if (ch.shortChannelId)
|
|
@@ -1731,7 +1782,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
1731
1782
|
});
|
|
1732
1783
|
}
|
|
1733
1784
|
decodeInvoice(bolt11) {
|
|
1734
|
-
const inv = (
|
|
1785
|
+
const inv = decodeInvoiceInput(bolt11);
|
|
1735
1786
|
const result = {
|
|
1736
1787
|
network: inv.network,
|
|
1737
1788
|
timestamp: inv.timestamp,
|
|
@@ -2040,7 +2091,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
2040
2091
|
}
|
|
2041
2092
|
async payInvoice(bolt11, timeoutMs = 60000, maxFeeSats, amountSats, metadata) {
|
|
2042
2093
|
this._checkDraining();
|
|
2043
|
-
const decoded = (
|
|
2094
|
+
const decoded = decodeInvoiceInput(bolt11);
|
|
2044
2095
|
const paymentHashHex = decoded.paymentHash.toString('hex');
|
|
2045
2096
|
const spendAmountSats = amountSats ??
|
|
2046
2097
|
(decoded.amountMsat !== undefined
|
|
@@ -2162,7 +2213,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
2162
2213
|
async payInvoiceWithRetry(bolt11, opts = {}) {
|
|
2163
2214
|
const maxRetries = opts.maxRetries ?? 3;
|
|
2164
2215
|
const backoffMs = opts.backoffMs ?? 2000;
|
|
2165
|
-
const decoded = (
|
|
2216
|
+
const decoded = decodeInvoiceInput(bolt11);
|
|
2166
2217
|
const paymentHashHex = decoded.paymentHash.toString('hex');
|
|
2167
2218
|
let lastError;
|
|
2168
2219
|
for (let attempt = 1; attempt <= maxRetries + 1; attempt++) {
|
|
@@ -2258,7 +2309,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
2258
2309
|
};
|
|
2259
2310
|
}
|
|
2260
2311
|
sendPaymentAsync(bolt11, maxFeeSats, amountSats, metadata) {
|
|
2261
|
-
const decoded = (
|
|
2312
|
+
const decoded = decodeInvoiceInput(bolt11);
|
|
2262
2313
|
const maxFeeMsat = maxFeeSats !== undefined ? BigInt(maxFeeSats) * 1000n : undefined;
|
|
2263
2314
|
const amountMsat = amountSats !== undefined ? BigInt(amountSats) * 1000n : undefined;
|
|
2264
2315
|
if (metadata) {
|
|
@@ -2636,7 +2687,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
2636
2687
|
return result;
|
|
2637
2688
|
}
|
|
2638
2689
|
decodeOfferString(offerStr) {
|
|
2639
|
-
const offer = (
|
|
2690
|
+
const offer = decodeOfferInput(offerStr);
|
|
2640
2691
|
return this.toOfferInfo(offer, offerStr);
|
|
2641
2692
|
}
|
|
2642
2693
|
createOffer(options) {
|
|
@@ -2679,7 +2730,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
2679
2730
|
.map(({ offer, encoded }) => this.toOfferInfo(offer, encoded));
|
|
2680
2731
|
}
|
|
2681
2732
|
async payOffer(offerStr, amountSats, timeoutMs = 60000) {
|
|
2682
|
-
const offer = (
|
|
2733
|
+
const offer = decodeOfferInput(offerStr);
|
|
2683
2734
|
const requestOptions = amountSats !== undefined
|
|
2684
2735
|
? { amount: BigInt(amountSats) * 1000n }
|
|
2685
2736
|
: undefined;
|