beignet 0.3.0 → 0.4.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 +22 -0
- package/dist/cli/auth.js +238 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/beignet-node.js +15 -10
- package/dist/cli/beignet-node.js.map +1 -1
- package/dist/cli/cli.js +57 -3
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/config.js +25 -1
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/daemon.js +57 -23
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/index.js +6 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/openapi.js +63 -2
- package/dist/cli/openapi.js.map +1 -1
- package/dist/electrum/index.js +2 -2
- package/dist/electrum/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lightning/backup/scb.js.map +1 -1
- package/dist/lightning/chain/chain-monitor.js.map +1 -1
- package/dist/lightning/chain/output-resolver.js +11 -9
- package/dist/lightning/chain/output-resolver.js.map +1 -1
- package/dist/lightning/channel/channel-manager.js +27 -24
- package/dist/lightning/channel/channel-manager.js.map +1 -1
- package/dist/lightning/channel/channel.js +0 -2
- package/dist/lightning/channel/channel.js.map +1 -1
- package/dist/lightning/channel/commitment-builder.js +4 -7
- package/dist/lightning/channel/commitment-builder.js.map +1 -1
- package/dist/lightning/channel/splice-tx.js.map +1 -1
- package/dist/lightning/keys/signer.js +24 -3
- package/dist/lightning/keys/signer.js.map +1 -1
- package/dist/lightning/node/lightning-node.js +10 -1
- package/dist/lightning/node/lightning-node.js.map +1 -1
- package/dist/lightning/node/types.js.map +1 -1
- package/dist/lightning/storage/sqlite-storage.js +28 -10
- package/dist/lightning/storage/sqlite-storage.js.map +1 -1
- package/dist/lightning/watchtower/blob.js +92 -6
- package/dist/lightning/watchtower/blob.js.map +1 -1
- package/dist/lightning/watchtower/index.js +1 -1
- package/dist/lightning/watchtower/index.js.map +1 -1
- package/dist/lightning/watchtower/justice.js +120 -30
- package/dist/lightning/watchtower/justice.js.map +1 -1
- package/dist/lightning/watchtower/watchtower-client.js +188 -118
- package/dist/lightning/watchtower/watchtower-client.js.map +1 -1
- package/dist/logger.js +41 -0
- package/dist/logger.js.map +1 -0
- package/dist/types/cli/auth.d.ts +34 -0
- package/dist/types/cli/beignet-node.d.ts +4 -1
- package/dist/types/cli/daemon.d.ts +3 -0
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/cli/types.d.ts +7 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lightning/channel/channel-manager.d.ts +4 -0
- package/dist/types/lightning/channel/channel.d.ts +5 -5
- package/dist/types/lightning/channel/commitment-builder.d.ts +7 -7
- package/dist/types/lightning/channel/splice-tx.d.ts +2 -2
- package/dist/types/lightning/keys/signer.d.ts +18 -1
- package/dist/types/lightning/node/lightning-node.d.ts +4 -0
- package/dist/types/lightning/node/types.d.ts +4 -0
- package/dist/types/lightning/storage/sqlite-storage.d.ts +1 -1
- package/dist/types/lightning/watchtower/blob.d.ts +14 -0
- package/dist/types/lightning/watchtower/justice.d.ts +2 -1
- package/dist/types/lightning/watchtower/types.d.ts +3 -1
- package/dist/types/lightning/watchtower/watchtower-client.d.ts +3 -2
- package/dist/types/logger.d.ts +17 -0
- package/dist/types/types/wallet.d.ts +2 -0
- package/dist/types/wallet/index.d.ts +2 -0
- package/dist/types/wallet.js.map +1 -1
- package/dist/utils/electrum.js +4 -2
- package/dist/utils/electrum.js.map +1 -1
- package/dist/wallet/index.js +24 -22
- package/dist/wallet/index.js.map +1 -1
- package/docs/ROADMAP.md +86 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Beignet provides two layers of Bitcoin wallet functionality:
|
|
|
13
13
|
|
|
14
14
|
1. [Getting Started](#getting-started)
|
|
15
15
|
2. [On-Chain Wallet](#on-chain-wallet)
|
|
16
|
+
- [Leveled Logging](#leveled-logging)
|
|
16
17
|
3. [Lightning Network](#lightning-network)
|
|
17
18
|
- [Lightning Quick Start (BeignetNode)](#lightning-quick-start-beignetnode)
|
|
18
19
|
- [Decision-Support APIs](#decision-support-apis)
|
|
@@ -341,6 +342,27 @@ const wallet = await Wallet.create({
|
|
|
341
342
|
});
|
|
342
343
|
```
|
|
343
344
|
|
|
345
|
+
### Leveled Logging
|
|
346
|
+
|
|
347
|
+
Diagnostic output (debug/info/warn/error) flows through a small injectable logger, kept separate from the Lightning node's persisted structured action log (`getActionLog`). The `ILogger` interface is four methods, `debug`/`info`/`warn`/`error`(`message: string, meta?: unknown`), with level filtering `debug < info < warn < error` plus `'silent'`:
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
import { Wallet, createConsoleLogger, noopLogger } from 'beignet';
|
|
351
|
+
|
|
352
|
+
const wallet = await Wallet.create({
|
|
353
|
+
mnemonic,
|
|
354
|
+
logger: createConsoleLogger('warn'), // only warn + error reach the console
|
|
355
|
+
// logger: noopLogger, // fully silent
|
|
356
|
+
// logger: myLogger, // any ILogger: route into your own stack
|
|
357
|
+
// ...
|
|
358
|
+
});
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
- **`Wallet.create({ logger })`** defaults to `createConsoleLogger('info')`, which preserves the wallet's historical console output. `disableMessages` is independent and keeps its existing meaning: it only gates `onMessage` callbacks.
|
|
362
|
+
- **`LightningNode`** accepts `logger` in `INodeConfig` / `fromMnemonic` options and defaults to `noopLogger` (the node prints nothing, as before). Every structured action-log entry is additionally mirrored to `logger.debug('category:action', data)`.
|
|
363
|
+
- **`BeignetNode.create({ logger, logLevel })`**: log entries that pass `logLevel` are forwarded to the injected logger (in addition to the `'log'` event), and the logger is injected into the underlying `Wallet` and `LightningNode`. Without `logger`, behavior is unchanged (events only).
|
|
364
|
+
- **Daemon:** `beignet start --log-level <debug|info|warn|error|silent>` (or `BEIGNET_LOG_LEVEL`, or `logLevel` in `~/.beignet/config.json`) prints leveled diagnostics to stderr. Unset keeps the daemon silent (the default); stdout stays reserved for command output.
|
|
365
|
+
|
|
344
366
|
## Lightning Network
|
|
345
367
|
|
|
346
368
|
### Lightning Quick Start (BeignetNode)
|
package/dist/cli/auth.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiKeyAuthenticator = exports.scopesAllowRoute = exports.getRouteScopes = exports.ROUTE_SCOPES = exports.API_SCOPES = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
exports.API_SCOPES = new Set([
|
|
7
|
+
'readonly',
|
|
8
|
+
'invoice',
|
|
9
|
+
'admin'
|
|
10
|
+
]);
|
|
11
|
+
exports.ROUTE_SCOPES = {
|
|
12
|
+
'GET /info': ['readonly'],
|
|
13
|
+
'GET /balance': ['readonly'],
|
|
14
|
+
'GET /peers': ['readonly'],
|
|
15
|
+
'GET /channels': ['readonly'],
|
|
16
|
+
'GET /channels/ready': ['readonly'],
|
|
17
|
+
'GET /payments': ['readonly'],
|
|
18
|
+
'GET /payment': ['readonly'],
|
|
19
|
+
'GET /payment/proof': ['readonly'],
|
|
20
|
+
'GET /payment/verify-proof': ['readonly'],
|
|
21
|
+
'GET /forwards': ['readonly'],
|
|
22
|
+
'GET /forwards/summary': ['readonly'],
|
|
23
|
+
'GET /readiness': ['readonly'],
|
|
24
|
+
'GET /stats': ['readonly'],
|
|
25
|
+
'GET /spend-limit': ['readonly'],
|
|
26
|
+
'GET /liquidity': ['readonly'],
|
|
27
|
+
'GET /watchtowers': ['readonly'],
|
|
28
|
+
'GET /advisor/recommendations': ['readonly'],
|
|
29
|
+
'GET /fees': ['readonly'],
|
|
30
|
+
'GET /fees/estimates': ['readonly'],
|
|
31
|
+
'GET /transactions': ['readonly'],
|
|
32
|
+
'GET /transactions/boostable': ['readonly'],
|
|
33
|
+
'GET /utxos': ['readonly'],
|
|
34
|
+
'GET /address/labels': ['readonly'],
|
|
35
|
+
'GET /wallet/descriptors': ['readonly'],
|
|
36
|
+
'GET /channel': ['readonly'],
|
|
37
|
+
'GET /channel/health': ['readonly'],
|
|
38
|
+
'GET /channel/policy': ['readonly'],
|
|
39
|
+
'GET /channel/diagnostics': ['readonly'],
|
|
40
|
+
'GET /channel/suggestions': ['readonly'],
|
|
41
|
+
'GET /logs': ['readonly'],
|
|
42
|
+
'GET /node/uri': ['readonly'],
|
|
43
|
+
'GET /trusted-peers': ['readonly'],
|
|
44
|
+
'GET /can-send': ['readonly'],
|
|
45
|
+
'GET /graph/info': ['readonly'],
|
|
46
|
+
'GET /graph/node': ['readonly'],
|
|
47
|
+
'GET /graph/channel': ['readonly'],
|
|
48
|
+
'GET /graph/describe': ['readonly'],
|
|
49
|
+
'GET /backup/scb': ['readonly'],
|
|
50
|
+
'GET /backup/peer-retrieved': ['readonly'],
|
|
51
|
+
'GET /queue': ['readonly'],
|
|
52
|
+
'POST /route/estimate': ['readonly'],
|
|
53
|
+
'POST /route/query': ['readonly'],
|
|
54
|
+
'POST /payment/estimate': ['readonly'],
|
|
55
|
+
'POST /message/verify': ['readonly'],
|
|
56
|
+
'POST /address/validate': ['readonly'],
|
|
57
|
+
'POST /node/wait-ready': ['readonly'],
|
|
58
|
+
'POST /channel/wait-ready': ['readonly'],
|
|
59
|
+
'GET /invoices': ['readonly', 'invoice'],
|
|
60
|
+
'GET /invoice': ['readonly', 'invoice'],
|
|
61
|
+
'GET /invoices/held': ['readonly', 'invoice'],
|
|
62
|
+
'GET /offers': ['readonly', 'invoice'],
|
|
63
|
+
'GET /can-receive': ['readonly', 'invoice'],
|
|
64
|
+
'GET /events': ['readonly', 'invoice'],
|
|
65
|
+
'POST /invoice/decode': ['readonly', 'invoice'],
|
|
66
|
+
'POST /invoice/validate': ['readonly', 'invoice'],
|
|
67
|
+
'POST /offer/decode': ['readonly', 'invoice'],
|
|
68
|
+
'POST /payment/wait': ['readonly', 'invoice'],
|
|
69
|
+
'POST /invoice/create': ['invoice'],
|
|
70
|
+
'POST /invoice/create-hold': ['invoice'],
|
|
71
|
+
'POST /invoice/settle-hold': ['invoice'],
|
|
72
|
+
'POST /invoice/cancel-hold': ['invoice'],
|
|
73
|
+
'POST /offer/create': ['invoice'],
|
|
74
|
+
'POST /address/new': ['invoice'],
|
|
75
|
+
'GET /mnemonic': [],
|
|
76
|
+
'GET /webhooks': [],
|
|
77
|
+
'POST /send': [],
|
|
78
|
+
'POST /send-max': [],
|
|
79
|
+
'POST /tx/bump-fee': [],
|
|
80
|
+
'POST /tx/boost': [],
|
|
81
|
+
'POST /consolidate': [],
|
|
82
|
+
'POST /invoice/pay': [],
|
|
83
|
+
'POST /invoice/pay-safe': [],
|
|
84
|
+
'POST /invoice/pay-async': [],
|
|
85
|
+
'POST /invoice/pay-retry': [],
|
|
86
|
+
'POST /keysend': [],
|
|
87
|
+
'POST /keysend/safe': [],
|
|
88
|
+
'POST /offer/pay': [],
|
|
89
|
+
'POST /payment/send-to-route': [],
|
|
90
|
+
'POST /payment/cancel': [],
|
|
91
|
+
'POST /queue/add': [],
|
|
92
|
+
'POST /queue/cancel': [],
|
|
93
|
+
'POST /rebalance': [],
|
|
94
|
+
'POST /advisor/execute-rebalances': [],
|
|
95
|
+
'POST /recover-fallback-funds': [],
|
|
96
|
+
'POST /utxo/freeze': [],
|
|
97
|
+
'POST /utxo/unfreeze': [],
|
|
98
|
+
'POST /address/label': [],
|
|
99
|
+
'POST /wallet/refresh': [],
|
|
100
|
+
'POST /psbt/build': [],
|
|
101
|
+
'POST /psbt/import-signed': [],
|
|
102
|
+
'POST /psbt/combine': [],
|
|
103
|
+
'POST /peer/connect': [],
|
|
104
|
+
'POST /peer/disconnect': [],
|
|
105
|
+
'POST /peers/bootstrap': [],
|
|
106
|
+
'POST /peers/connect-seeds': [],
|
|
107
|
+
'POST /trusted-peer/add': [],
|
|
108
|
+
'POST /trusted-peer/remove': [],
|
|
109
|
+
'POST /channel/open': [],
|
|
110
|
+
'POST /channel/open-zeroconf': [],
|
|
111
|
+
'POST /channel/open-v2': [],
|
|
112
|
+
'POST /channel/open-and-wait': [],
|
|
113
|
+
'POST /channel/connect-and-open': [],
|
|
114
|
+
'POST /channels/ensure-minimum': [],
|
|
115
|
+
'POST /channel/close': [],
|
|
116
|
+
'POST /channel/forceclose': [],
|
|
117
|
+
'POST /channel/splice-in': [],
|
|
118
|
+
'POST /channel/splice-out': [],
|
|
119
|
+
'POST /channel/update-commitment-feerate': [],
|
|
120
|
+
'POST /channel/update-fee': [],
|
|
121
|
+
'POST /channel/update-policy': [],
|
|
122
|
+
'POST /message/sign': [],
|
|
123
|
+
'POST /gossip/sync': [],
|
|
124
|
+
'POST /gossip/sync-rapid': [],
|
|
125
|
+
'POST /route/probe': [],
|
|
126
|
+
'POST /payment/metadata': [],
|
|
127
|
+
'POST /backup': [],
|
|
128
|
+
'POST /backup/trigger': [],
|
|
129
|
+
'POST /restore/scb': [],
|
|
130
|
+
'POST /watchtower/add': [],
|
|
131
|
+
'DELETE /watchtower/remove': [],
|
|
132
|
+
'POST /webhooks/register': [],
|
|
133
|
+
'DELETE /webhooks/unregister': [],
|
|
134
|
+
'POST /stop': [],
|
|
135
|
+
'GET /auth/keys': [],
|
|
136
|
+
'POST /auth/keys/revoke': []
|
|
137
|
+
};
|
|
138
|
+
function getRouteScopes(routeKey) {
|
|
139
|
+
return exports.ROUTE_SCOPES[routeKey] ?? [];
|
|
140
|
+
}
|
|
141
|
+
exports.getRouteScopes = getRouteScopes;
|
|
142
|
+
function scopesAllowRoute(scopes, routeKey) {
|
|
143
|
+
if (scopes.has('admin'))
|
|
144
|
+
return true;
|
|
145
|
+
return getRouteScopes(routeKey).some((s) => scopes.has(s));
|
|
146
|
+
}
|
|
147
|
+
exports.scopesAllowRoute = scopesAllowRoute;
|
|
148
|
+
function sha256(input) {
|
|
149
|
+
return (0, crypto_1.createHash)('sha256').update(input, 'utf8').digest();
|
|
150
|
+
}
|
|
151
|
+
class ApiKeyAuthenticator {
|
|
152
|
+
constructor(apiToken, apiKeys) {
|
|
153
|
+
this.candidates = [];
|
|
154
|
+
this.revoked = new Set();
|
|
155
|
+
this.keyNames = [];
|
|
156
|
+
if (apiToken) {
|
|
157
|
+
this.candidates.push({
|
|
158
|
+
name: null,
|
|
159
|
+
digest: sha256(apiToken),
|
|
160
|
+
scopes: new Set(['admin'])
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
for (const def of apiKeys ?? []) {
|
|
164
|
+
this.addKeyDefinition(def, apiToken);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
addKeyDefinition(def, apiToken) {
|
|
168
|
+
if (!def || typeof def.name !== 'string' || def.name.trim() === '') {
|
|
169
|
+
throw new errors_1.BeignetError('INVALID_PARAMS', 'apiKeys entries require a non-empty name');
|
|
170
|
+
}
|
|
171
|
+
if (typeof def.key !== 'string' || def.key === '') {
|
|
172
|
+
throw new errors_1.BeignetError('INVALID_PARAMS', `apiKeys entry "${def.name}" requires a non-empty key`);
|
|
173
|
+
}
|
|
174
|
+
if (!Array.isArray(def.scopes) ||
|
|
175
|
+
def.scopes.length === 0 ||
|
|
176
|
+
def.scopes.some((s) => !exports.API_SCOPES.has(s))) {
|
|
177
|
+
throw new errors_1.BeignetError('INVALID_PARAMS', `apiKeys entry "${def.name}" requires scopes from: readonly, invoice, admin`);
|
|
178
|
+
}
|
|
179
|
+
if (this.keyNames.includes(def.name)) {
|
|
180
|
+
throw new errors_1.BeignetError('INVALID_PARAMS', `Duplicate apiKeys name "${def.name}"`);
|
|
181
|
+
}
|
|
182
|
+
if (apiToken !== undefined && def.key === apiToken) {
|
|
183
|
+
throw new errors_1.BeignetError('INVALID_PARAMS', `apiKeys entry "${def.name}" duplicates the legacy apiToken value`);
|
|
184
|
+
}
|
|
185
|
+
const digest = sha256(def.key);
|
|
186
|
+
for (const existing of this.candidates) {
|
|
187
|
+
if (existing.name !== null && (0, crypto_1.timingSafeEqual)(existing.digest, digest)) {
|
|
188
|
+
throw new errors_1.BeignetError('INVALID_PARAMS', `apiKeys entry "${def.name}" duplicates the key of "${existing.name}"`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
this.keyNames.push(def.name);
|
|
192
|
+
this.candidates.push({
|
|
193
|
+
name: def.name,
|
|
194
|
+
digest,
|
|
195
|
+
scopes: new Set(def.scopes)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
get enabled() {
|
|
199
|
+
return this.candidates.length > 0;
|
|
200
|
+
}
|
|
201
|
+
authenticate(header) {
|
|
202
|
+
if (!header)
|
|
203
|
+
return { ok: false };
|
|
204
|
+
const match = header.match(/^bearer\s+(.+)$/i);
|
|
205
|
+
if (!match)
|
|
206
|
+
return { ok: false };
|
|
207
|
+
const presented = sha256(match[1]);
|
|
208
|
+
let matched = null;
|
|
209
|
+
for (const candidate of this.candidates) {
|
|
210
|
+
const equal = (0, crypto_1.timingSafeEqual)(candidate.digest, presented);
|
|
211
|
+
if (equal &&
|
|
212
|
+
matched === null &&
|
|
213
|
+
(candidate.name === null || !this.revoked.has(candidate.name))) {
|
|
214
|
+
matched = candidate;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!matched)
|
|
218
|
+
return { ok: false };
|
|
219
|
+
return { ok: true, keyName: matched.name, scopes: matched.scopes };
|
|
220
|
+
}
|
|
221
|
+
revoke(name) {
|
|
222
|
+
if (!this.keyNames.includes(name))
|
|
223
|
+
return false;
|
|
224
|
+
this.revoked.add(name);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
listKeys() {
|
|
228
|
+
return this.candidates
|
|
229
|
+
.filter((c) => c.name !== null)
|
|
230
|
+
.map((c) => ({
|
|
231
|
+
name: c.name,
|
|
232
|
+
scopes: [...c.scopes],
|
|
233
|
+
revoked: this.revoked.has(c.name)
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.ApiKeyAuthenticator = ApiKeyAuthenticator;
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pE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;SACjC,CAAC,CAAC,CAAC;IACN,CAAC;CACD;AA1HD,kDA0HC"}
|
package/dist/cli/beignet-node.js
CHANGED
|
@@ -33,6 +33,7 @@ const instance_lock_1 = require("./instance-lock");
|
|
|
33
33
|
const crypto = __importStar(require("crypto"));
|
|
34
34
|
const events_1 = require("events");
|
|
35
35
|
const wallet_1 = require("../wallet");
|
|
36
|
+
const logger_1 = require("../logger");
|
|
36
37
|
const helpers_1 = require("../utils/helpers");
|
|
37
38
|
const conversion_1 = require("../utils/conversion");
|
|
38
39
|
const wallet_2 = require("../types/wallet");
|
|
@@ -145,13 +146,6 @@ async function resolveHostToIPv4(host) {
|
|
|
145
146
|
return host;
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
|
-
const LOG_PRIORITY = {
|
|
149
|
-
debug: 0,
|
|
150
|
-
info: 1,
|
|
151
|
-
warn: 2,
|
|
152
|
-
error: 3,
|
|
153
|
-
silent: 4
|
|
154
|
-
};
|
|
155
149
|
class BeignetNode extends events_1.EventEmitter {
|
|
156
150
|
on(event, listener) {
|
|
157
151
|
return super.on(event, listener);
|
|
@@ -187,10 +181,13 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
187
181
|
this.dataDir = dataDir;
|
|
188
182
|
}
|
|
189
183
|
log(level, message, data) {
|
|
190
|
-
if (
|
|
184
|
+
if (logger_1.LOG_LEVEL_PRIORITY[level] < logger_1.LOG_LEVEL_PRIORITY[this.logLevel])
|
|
191
185
|
return;
|
|
192
186
|
const entry = { level, message, data, timestamp: Date.now() };
|
|
193
187
|
this.emit('log', entry);
|
|
188
|
+
if (this.logger && level !== 'silent') {
|
|
189
|
+
this.logger[level](message, data);
|
|
190
|
+
}
|
|
194
191
|
}
|
|
195
192
|
static async create(opts = {}) {
|
|
196
193
|
const mnemonic = opts.mnemonic || (0, helpers_1.generateMnemonic)();
|
|
@@ -204,6 +201,8 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
204
201
|
async init(opts) {
|
|
205
202
|
if (opts.logLevel)
|
|
206
203
|
this.logLevel = opts.logLevel;
|
|
204
|
+
if (opts.logger)
|
|
205
|
+
this.logger = opts.logger;
|
|
207
206
|
this.autoGossipSync = opts.autoGossipSync ?? true;
|
|
208
207
|
this.peerStorageEnabled = opts.peerStorageEnabled ?? true;
|
|
209
208
|
this.rapidGossipSync = opts.rapidGossipSync ?? true;
|
|
@@ -247,9 +246,13 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
247
246
|
if (!opts.dataDir) {
|
|
248
247
|
const legacyDb = path.join(DEFAULT_DATA_DIR, `${networkName}.db`);
|
|
249
248
|
if (fs.existsSync(legacyDb) && !fs.existsSync(dbPath)) {
|
|
250
|
-
|
|
249
|
+
const legacyMsg = `[beignet] Found a legacy shared database at ${legacyDb}. ` +
|
|
251
250
|
`Storage is now per-wallet (${dbPath}), so it is no longer auto-loaded. ` +
|
|
252
|
-
`If it held this wallet's channels, re-run with dataDir set to "${DEFAULT_DATA_DIR}" to use it
|
|
251
|
+
`If it held this wallet's channels, re-run with dataDir set to "${DEFAULT_DATA_DIR}" to use it.`;
|
|
252
|
+
this.log('warn', legacyMsg);
|
|
253
|
+
if (!this.logger) {
|
|
254
|
+
console.warn(legacyMsg);
|
|
255
|
+
}
|
|
253
256
|
}
|
|
254
257
|
}
|
|
255
258
|
let encryptionKey;
|
|
@@ -280,6 +283,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
280
283
|
servers: electrumServer
|
|
281
284
|
},
|
|
282
285
|
disableMessagesOnCreate: true,
|
|
286
|
+
...(this.logger ? { logger: this.logger } : {}),
|
|
283
287
|
rbf: true,
|
|
284
288
|
storage: (0, wallet_storage_1.createWalletStorage)(this.storage)
|
|
285
289
|
});
|
|
@@ -383,6 +387,7 @@ class BeignetNode extends events_1.EventEmitter {
|
|
|
383
387
|
largeChannels: opts.largeChannels,
|
|
384
388
|
chainBackend: electrumBackend,
|
|
385
389
|
feeEstimator: electrumBackend,
|
|
390
|
+
logger: this.logger,
|
|
386
391
|
sweepDestinationScript,
|
|
387
392
|
socks5Proxy,
|
|
388
393
|
peerStorageEnabled: this.peerStorageEnabled,
|