@forgesworn/moneyer 0.2.0 → 0.2.1
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/CHANGELOG.md +12 -0
- package/dist/backends/fake.d.ts +2 -0
- package/dist/backends/fake.js +31 -4
- package/dist/config.d.ts +1 -0
- package/dist/server.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.1] - 2026-08-22
|
|
4
|
+
|
|
5
|
+
- `moneyer --dev` settles its invoices a moment after issuing them rather
|
|
6
|
+
than at the instant of issuance. Settling immediately made the mint
|
|
7
|
+
report an invoice nobody had paid as already settled, which on the wire
|
|
8
|
+
is indistinguishable from a mint handing out a note before it has been
|
|
9
|
+
paid for - the conformance grader failed it on exactly that, and was
|
|
10
|
+
right to. A dev mint should behave like a fast payer, not one that pays
|
|
11
|
+
before being asked. `autoSettleAfterMs` sets the delay; it defaults to
|
|
12
|
+
1.5 seconds, which nobody developing against a local mint notices.
|
|
13
|
+
A freshly started `--dev` mint now grades 24 passed, 0 failed.
|
|
14
|
+
|
|
3
15
|
## [0.2.0] - 2026-08-22
|
|
4
16
|
|
|
5
17
|
While LUD-25 is a draft, a `0.x` minor bump may be breaking; this one is
|
package/dist/backends/fake.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type LightningBackend } from './types.ts';
|
|
2
2
|
export type FakePayMode = 'succeed' | 'fail-clean' | 'fail-then-paid' | 'ambiguous-paid' | 'ambiguous-unpaid' | 'ambiguous-pending';
|
|
3
|
+
export declare const DEFAULT_AUTO_SETTLE_AFTER_MS = 1500;
|
|
3
4
|
export type FakeBackendOptions = {
|
|
4
5
|
autoSettle?: boolean;
|
|
6
|
+
autoSettleAfterMs?: number;
|
|
5
7
|
};
|
|
6
8
|
export type FakeBackend = LightningBackend & {
|
|
7
9
|
control: {
|
package/dist/backends/fake.js
CHANGED
|
@@ -4,10 +4,28 @@ import { hexToBytes } from '@noble/hashes/utils.js';
|
|
|
4
4
|
import { bolt11PaymentHash } from 'farrier-kit/bolt11';
|
|
5
5
|
import { fakeBolt11 } from "./fake-bolt11.js";
|
|
6
6
|
import { PaymentAlreadyKnownError, PaymentFailedError, PaymentPendingError } from "./types.js";
|
|
7
|
+
// Long enough that an unpaid invoice reads as unpaid to anything looking
|
|
8
|
+
// at it in the same breath it was issued, short enough that nobody
|
|
9
|
+
// developing against a dev mint notices the wait.
|
|
10
|
+
export const DEFAULT_AUTO_SETTLE_AFTER_MS = 1_500;
|
|
11
|
+
// An invoice is paid if something paid it, or if autoSettle's moment has
|
|
12
|
+
// arrived. Read rather than scheduled: no timer to leak when a mint is
|
|
13
|
+
// closed, and a test that fakes the clock sees the same answer.
|
|
14
|
+
const isSettled = (invoice) => {
|
|
15
|
+
if (!invoice)
|
|
16
|
+
return false;
|
|
17
|
+
if (invoice.settled)
|
|
18
|
+
return true;
|
|
19
|
+
return invoice.settleAt !== null && Date.now() >= invoice.settleAt;
|
|
20
|
+
};
|
|
7
21
|
// One bitcoin, so a development mint covers anything it is likely to mint.
|
|
8
22
|
export const FAKE_LOCAL_BALANCE_MSAT = 100_000_000_000;
|
|
9
23
|
export const createFakeBackend = (options = {}) => {
|
|
10
24
|
const autoSettle = options.autoSettle === true;
|
|
25
|
+
const autoSettleAfterMs = options.autoSettleAfterMs ?? DEFAULT_AUTO_SETTLE_AFTER_MS;
|
|
26
|
+
// `settleAt` is when autoSettle starts calling this invoice paid; null
|
|
27
|
+
// for an invoice only control.settleInvoice can settle, which is every
|
|
28
|
+
// invoice unless autoSettle is on.
|
|
11
29
|
const invoices = new Map();
|
|
12
30
|
const payments = new Map();
|
|
13
31
|
const knownPreimages = new Map();
|
|
@@ -18,7 +36,12 @@ export const createFakeBackend = (options = {}) => {
|
|
|
18
36
|
async createInvoice({ amountMsat, preimageHex, memo }) {
|
|
19
37
|
const paymentHashHex = bytesToHex(sha256(hexToBytes(preimageHex)));
|
|
20
38
|
const pr = fakeBolt11({ amountMsat, paymentHashHex, memo });
|
|
21
|
-
invoices.set(paymentHashHex, {
|
|
39
|
+
invoices.set(paymentHashHex, {
|
|
40
|
+
preimageHex,
|
|
41
|
+
amountMsat,
|
|
42
|
+
settled: false,
|
|
43
|
+
settleAt: autoSettle ? Date.now() + autoSettleAfterMs : null
|
|
44
|
+
});
|
|
22
45
|
return { pr };
|
|
23
46
|
},
|
|
24
47
|
async payInvoice({ pr, amountMsat }) {
|
|
@@ -63,11 +86,11 @@ export const createFakeBackend = (options = {}) => {
|
|
|
63
86
|
return payment.status === 'complete';
|
|
64
87
|
},
|
|
65
88
|
async isInvoiceSettled(paymentHashHex) {
|
|
66
|
-
return invoices.get(paymentHashHex)
|
|
89
|
+
return isSettled(invoices.get(paymentHashHex));
|
|
67
90
|
},
|
|
68
91
|
async invoicePreimage(paymentHashHex) {
|
|
69
92
|
const invoice = invoices.get(paymentHashHex);
|
|
70
|
-
return invoice
|
|
93
|
+
return isSettled(invoice) ? invoice.preimageHex : null;
|
|
71
94
|
},
|
|
72
95
|
async paymentPreimage(paymentHashHex) {
|
|
73
96
|
const payment = payments.get(paymentHashHex);
|
|
@@ -113,7 +136,11 @@ export const createFakeBackend = (options = {}) => {
|
|
|
113
136
|
localBalanceMsat = msat;
|
|
114
137
|
},
|
|
115
138
|
invoiceByHash(paymentHashHex) {
|
|
116
|
-
|
|
139
|
+
const invoice = invoices.get(paymentHashHex);
|
|
140
|
+
// `settled` here answers "is it paid now", so autoSettle's moment
|
|
141
|
+
// counts. A caller reading the stored flag would see false for an
|
|
142
|
+
// invoice the mint itself treats as paid.
|
|
143
|
+
return invoice && { ...invoice, settled: isSettled(invoice) };
|
|
117
144
|
}
|
|
118
145
|
}
|
|
119
146
|
};
|
package/dist/config.d.ts
CHANGED
package/dist/server.js
CHANGED
|
@@ -49,7 +49,12 @@ const wholeSatFloor = (msat) => Math.floor(msat / 1000) * 1000;
|
|
|
49
49
|
const backendFor = (config) => {
|
|
50
50
|
switch (config.backend.kind) {
|
|
51
51
|
case 'fake':
|
|
52
|
-
return createFakeBackend({
|
|
52
|
+
return createFakeBackend({
|
|
53
|
+
autoSettle: config.backend.autoSettle === true,
|
|
54
|
+
...(config.backend.autoSettleAfterMs === undefined
|
|
55
|
+
? {}
|
|
56
|
+
: { autoSettleAfterMs: config.backend.autoSettleAfterMs })
|
|
57
|
+
});
|
|
53
58
|
case 'cln':
|
|
54
59
|
return createClnBackend(config.backend);
|
|
55
60
|
case 'lnd':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgesworn/moneyer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "An LNURLcash (LUD-25) mint - strikes Lightning bearer notes. Independent implementation, cln/lnd funding sources, SQLite, zero HTTP framework.",
|
|
5
5
|
"author": "TheCryptoDonkey",
|
|
6
6
|
"license": "MIT",
|