Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
05815be
Add missing C sources
martindale Apr 16, 2026
509d886
Update install report
martindale Apr 16, 2026
ca26005
Add a variety of new Lightning tests
martindale Apr 20, 2026
f7da76a
Add missing require statements
martindale Apr 20, 2026
7b564b1
Removed bolt12 semantic unit test
martindale Apr 20, 2026
e00df04
Rework imports
martindale Apr 20, 2026
74c9ac6
Add additional BOLT12 semantics test
martindale Apr 20, 2026
7374237
Rework the secure memory
martindale Apr 20, 2026
090ca70
Update package-lock.json
martindale Apr 21, 2026
21ff49d
Fix regression in environment detection
martindale Apr 21, 2026
2faa6ce
Address various issues, expand tests
martindale Apr 22, 2026
429af98
Address a number of comments
martindale Apr 22, 2026
e510e99
Update install report
martindale Apr 23, 2026
360e5f6
Specify uuid version to fix jayson
martindale Apr 23, 2026
16cdecc
Update package-lock.json
martindale Apr 24, 2026
450a520
Update install report, package-lock.json
martindale Apr 28, 2026
bb868b2
Update INVENTORY-related API
martindale Apr 28, 2026
f7d8745
Add missing fabricDocumentOfferEnvelope function
martindale Apr 28, 2026
39bd835
Update package-lock.json
martindale Apr 29, 2026
9419d6d
Continue hardening environment
martindale Apr 29, 2026
cb161b0
Update package-lock.json, environment tests
martindale Apr 30, 2026
20663cc
Update packages
martindale May 1, 2026
641ff39
Update reports, package-lock.json
martindale May 5, 2026
f93d3f1
Update package-lock.json
martindale May 6, 2026
0444633
Further polish of Environment, Keygen
martindale May 7, 2026
4c86ff8
Update package-lock.json
martindale May 9, 2026
612180e
General update to C implementation, re-work NOISE
martindale May 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@ src/*
!src/cli.h
!src/cli_main.c
!src/constants.h
!src/crypto.c
!src/datadir.h
!src/errors.c
!src/errors.h
!src/message.c
!src/message.h
!src/memory.h
!src/noise.h
!src/noise.c
!src/p2p.c
!src/peer.c
!src/peer.h
!src/protocol.c
!src/protocol.h
!src/random.h
!src/scoring.c
!src/scoring.h
!src/secure_memory.c
!src/secure_memory.h
!src/secure_random.c
!src/secure_random.h
!src/security.c
!src/sha2.c
!src/sha2.h
!src/taproot.c
!src/taproot.h
!src/threads.c
Expand Down
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ See also [GOALS.md][goals].
- [ ] Tests passing on Travis
- [ ] Tests passing on GitHub Actions
- [ ] Test Coverage 70%
- [ ] Clean install from @portal/feed
- [ ] Clean install from @fabric/fiat
- [x] Install Time < 300s
- [ ] Install Time < 30s

## Annoyances:
Upon running `rm -rf node_modules && npm i` from `@portal/feed` repo:
Upon running `rm -rf node_modules && npm i` from `@fabric/fiat` repo:
```
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
Expand Down
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"src/binding.cc",
"src/crypto.c",
"src/protocol.c",
"src/noise.c",
"src/p2p.c"
],
"include_dirs": [
Expand Down
3 changes: 3 additions & 0 deletions examples/http.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// # Exposing ARCs with HTTP
// Downstream apps set `path` to their `assets/` (or similar). Files there are served first; unhandled
// paths fall through to the packaged `@fabric/http` `assets/` (e.g. Fomantic / semantic) — no extra
// settings required. See `FabricHTTPServer` in `@fabric/http` `types/server.js` static middleware order.
// Fabric makes it easy to publish applications to the Web,
// giving downstream users access to a hosted instance of the
// application.
Expand Down
161 changes: 161 additions & 0 deletions functions/bolt12Semantics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
'use strict';

/**
* BOLT #12 semantic helpers for interpreting **`Lightning#decodeLightning`** (`decode` RPC) JSON from Core Lightning.
*
* **BIP-340 signatures (BOLT #12 § Signature calculation):**
* - **Offers** (`lno1…`) do **not** carry a signature TLV.
* - **`invoice_request`** and **`invoice`** streams include **signature** (TLV type **240**…1000), keyed with
* `SIG("lightning" ‖ stream ‖ field, Merkle_root, key)` per the spec ([BOLT #12](https://github.com/lightning/bolts/blob/master/12-offer-encoding.md)).
* - This module does **not** verify Schnorr signatures; use **`lightningd`** / **`decode`** and payment flows for that.
*
* **Recurrence:** TLVs such as `offer_recurrence_optional` / `_compulsory`, `invreq_recurrence_*`, `invoice_recurrence_basetime`
* are summarized from flat **`decode`** objects when present.
*
* @module functions/bolt12Semantics
* @see docs/LIGHTNING_COMPAT.md
*/

/**
* TLV type numbers for BOLT #12 and Core Lightning `decode` fields (offer / invoice_request / invoice).
* @readonly
*/
const CLN_BOLT12_TLV = Object.freeze({
INVREQ_METADATA: 0,
OFFER_CHAINS: 2,
OFFER_METADATA: 4,
OFFER_CURRENCY: 6,
OFFER_AMOUNT: 8,
OFFER_DESCRIPTION: 10,
OFFER_FEATURES: 12,
OFFER_ABSOLUTE_EXPIRY: 14,
OFFER_PATHS: 16,
OFFER_ISSUER: 18,
OFFER_QUANTITY_MAX: 20,
OFFER_ISSUER_ID: 22,
OFFER_RECURRENCE_COMPULSORY: 24,
OFFER_RECURRENCE_OPTIONAL: 25,
OFFER_RECURRENCE_BASE: 26,
OFFER_RECURRENCE_PAYWINDOW: 27,
OFFER_RECURRENCE_LIMIT: 29,
INVREQ_CHAIN: 80,
INVREQ_AMOUNT: 82,
INVREQ_FEATURES: 84,
INVREQ_QUANTITY: 86,
INVREQ_PAYER_ID: 88,
INVREQ_PAYER_NOTE: 89,
INVREQ_PATHS: 90,
INVREQ_BIP353_NAME: 91,
INVREQ_RECURRENCE_COUNTER: 92,
INVREQ_RECURRENCE_START: 93,
INVREQ_RECURRENCE_CANCEL: 94,
SIGNATURE_MIN: 240,
SIGNATURE_MAX: 1000,
INVOICE_PATHS: 160,
INVOICE_BLINDEDPAY: 162,
INVOICE_CREATED_AT: 164,
INVOICE_RELATIVE_EXPIRY: 166,
INVOICE_PAYMENT_HASH: 168,
INVOICE_AMOUNT: 170,
INVOICE_FALLBACKS: 172,
INVOICE_FEATURES: 174,
INVOICE_NODE_ID: 176,
INVOICE_RECURRENCE_BASETIME: 177
});

/** @deprecated Use {@link CLN_BOLT12_TLV} — name kept for existing imports. */
const BOLT12_TLV = CLN_BOLT12_TLV;

/**
* Normalized kind for a value returned by **`decode`** / **`decodeLightning`**.
* @readonly
* @enum {string}
*/
const Bolt12StreamKind = Object.freeze({
bolt12_offer: 'bolt12_offer',
bolt12_invoice_request: 'bolt12_invoice_request',
bolt12_invoice: 'bolt12_invoice',
bolt11_invoice: 'bolt11_invoice',
unknown: 'unknown'
});

/**
* Classify **`decode`** result from Core Lightning using its **`type`** field (wording varies slightly by version).
* @param {Object|null|undefined} decoded
* @returns {typeof Bolt12StreamKind[keyof typeof Bolt12StreamKind]}
*/
function classifyDecodedBolt12 (decoded) {
if (!decoded || typeof decoded !== 'object') return Bolt12StreamKind.unknown;
const t = decoded.type;
if (typeof t !== 'string') return Bolt12StreamKind.unknown;
const s = t.toLowerCase();
if (s.includes('bolt12') && s.includes('offer') && !s.includes('invoice')) {
return Bolt12StreamKind.bolt12_offer;
}
if (s.includes('invoice_request') || (s.includes('bolt12') && s.includes('invoice') && s.includes('request'))) {
return Bolt12StreamKind.bolt12_invoice_request;
}
if (s.includes('bolt12') && s.includes('invoice') && !s.includes('request')) {
return Bolt12StreamKind.bolt12_invoice;
}
if (s.includes('bolt11') || /^bitcoin\s*invoice/i.test(t)) {
return Bolt12StreamKind.bolt11_invoice;
}
return Bolt12StreamKind.unknown;
}

/**
* Whether BOLT #12 Merkle **BIP-340** signatures apply to this stream (not offers).
* @param {typeof Bolt12StreamKind[keyof typeof Bolt12StreamKind]} kind
* @returns {boolean}
*/
function bip340SignatureApplies (kind) {
return kind === Bolt12StreamKind.bolt12_invoice_request || kind === Bolt12StreamKind.bolt12_invoice;
}

/**
* Collect recurrence-related fields from a flat **`decode`** object (snake_case keys as CLN tends to emit).
* @param {Object|null|undefined} decoded
* @returns {Object|null} Plain object copy, or `null` if nothing recurrence-related.
*/
function summarizeBolt12RecurrenceFromDecode (decoded) {
if (!decoded || typeof decoded !== 'object') return null;
/** @type {Record<string, unknown>} */
const out = {};

const offerKeys = [
'offer_recurrence',
'offer_recurrence_compulsory',
'offer_recurrence_optional',
'offer_recurrence_base',
'offer_recurrence_paywindow',
'offer_recurrence_limit'
];
for (const k of offerKeys) {
if (decoded[k] != null) out[k] = decoded[k];
}

const invreqKeys = [
'invreq_recurrence_counter',
'invreq_recurrence_start',
'invreq_recurrence_cancel'
];
for (const k of invreqKeys) {
if (decoded[k] != null) out[k] = decoded[k];
}

if (decoded.invoice_recurrence_basetime != null) {
out.invoice_recurrence_basetime = decoded.invoice_recurrence_basetime;
}

return Object.keys(out).length ? out : null;
}

module.exports = {
BOLT12_TLV,
CLN_BOLT12_TLV,
Bolt12StreamKind,
bip340SignatureApplies,
classifyDecodedBolt12,
summarizeBolt12RecurrenceFromDecode
};
57 changes: 57 additions & 0 deletions functions/fabricDocumentOfferEnvelope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

/**
* Fabric document-offer envelope types (JSON `type` on generic payloads). Conceptually aligned with
* Lightning BOLT12 *offers* (buyer-facing request → seller-facing response); wire remains
* `P2P_INVENTORY_REQUEST` / `P2P_INVENTORY_RESPONSE` opcodes. See `docs/FABRIC_DOCUMENT_OFFER.md`.
*/

/** Canonical JSON `type`: buyer/originator asks for catalog / settlement terms. */
const FABRIC_DOCUMENT_OFFER = 'FABRIC_DOCUMENT_OFFER';
/** Accepted synonym for `FABRIC_DOCUMENT_OFFER`. */
const FABRIC_DOCUMENT_OFFER_REQUEST = 'FABRIC_DOCUMENT_OFFER_REQUEST';

/** Canonical JSON `type`: seller/router replies (items, L1 `contentHash`, optional HTLC hooks). */
const FABRIC_DOCUMENT_OFFER_RESPONSE = 'FABRIC_DOCUMENT_OFFER_RESPONSE';
/** Accepted synonym for `FABRIC_DOCUMENT_OFFER_RESPONSE`. */
const FABRIC_DOCUMENT_OFFER_REPLY = 'FABRIC_DOCUMENT_OFFER_REPLY';

const TO_LEGACY_INVENTORY = Object.freeze({
[FABRIC_DOCUMENT_OFFER]: 'INVENTORY_REQUEST',
[FABRIC_DOCUMENT_OFFER_REQUEST]: 'INVENTORY_REQUEST',
[FABRIC_DOCUMENT_OFFER_RESPONSE]: 'INVENTORY_RESPONSE',
[FABRIC_DOCUMENT_OFFER_REPLY]: 'INVENTORY_RESPONSE'
});

/**
* Map Fabric document-offer envelope `type` strings to legacy handler types (`INVENTORY_*`).
* @param {unknown} type
* @returns {string|null}
*/
function fabricDocumentOfferEnvelopeToLegacy (type) {
if (typeof type !== 'string') return null;
const t = type.trim();
return TO_LEGACY_INVENTORY[t] || null;
}

/**
* Shallow-clone `message` with `type` set to `INVENTORY_REQUEST` / `INVENTORY_RESPONSE` when a Fabric alias is used.
* @param {object} message
* @returns {object}
*/
function normalizeFabricDocumentOfferEnvelopeForHandlers (message) {
if (!message || typeof message !== 'object') return message;
const legacy = fabricDocumentOfferEnvelopeToLegacy(message.type);
if (!legacy) return message;
return Object.assign({}, message, { type: legacy });
}

module.exports = {
FABRIC_DOCUMENT_OFFER,
FABRIC_DOCUMENT_OFFER_REQUEST,
FABRIC_DOCUMENT_OFFER_RESPONSE,
FABRIC_DOCUMENT_OFFER_REPLY,
TO_LEGACY_INVENTORY,
fabricDocumentOfferEnvelopeToLegacy,
normalizeFabricDocumentOfferEnvelopeForHandlers
};
Loading
Loading