From ab2e237086b6a07c6a3ee1a8e96efc4a76169101 Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Fri, 23 Jan 2026 11:15:48 -0500 Subject: [PATCH] feat(abstract-lightning): make valueMsat optional add valueSat support The CreateInvoiceBody type is updated to: 1. Make valueMsat field optional instead of required 2. Add new optional valueSat field (numeric representation) 3. Simplify the type definition structure Also adds valueSat field to the Invoice type as a backward compatibility measure with older API versions. BTC-2775 TICKET: BTC-2775 --- .../src/codecs/api/invoice.ts | 21 ++++++++----------- .../lightning/lightningInvoiceRoutes.test.ts | 4 +--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/modules/abstract-lightning/src/codecs/api/invoice.ts b/modules/abstract-lightning/src/codecs/api/invoice.ts index ec0a9b2838..27cdf1a6c8 100644 --- a/modules/abstract-lightning/src/codecs/api/invoice.ts +++ b/modules/abstract-lightning/src/codecs/api/invoice.ts @@ -18,18 +18,12 @@ export const InvoiceStatus = t.union( ); export type InvoiceStatus = t.TypeOf; -export const CreateInvoiceBody = t.intersection( - [ - t.type({ - valueMsat: BigIntFromString, - }), - t.partial({ - memo: t.string, - expiry: t.number, - }), - ], - 'CreateInvoiceBody' -); +export const CreateInvoiceBody = t.partial({ + valueMsat: BigIntFromString, + valueSat: t.number, + memo: t.string, + expiry: t.number, +}); export type CreateInvoiceBody = t.TypeOf; /** @@ -52,6 +46,9 @@ export const Invoice = t.intersection( updatedAt: DateFromISOString, }), t.partial({ + // Keep valueSat for backward compatibility with older versions of the API + // Will be moved up to required fields in the future + valueSat: t.number, memo: t.string, amtPaidMsat: BigIntFromString, }), diff --git a/modules/express/test/unit/lightning/lightningInvoiceRoutes.test.ts b/modules/express/test/unit/lightning/lightningInvoiceRoutes.test.ts index 0c9c06fc17..32aac395e1 100644 --- a/modules/express/test/unit/lightning/lightningInvoiceRoutes.test.ts +++ b/modules/express/test/unit/lightning/lightningInvoiceRoutes.test.ts @@ -101,9 +101,7 @@ describe('Lightning Invoice Routes', () => { }); req.bitgo = bitgo; - await should(handleCreateLightningInvoice(req)).be.rejectedWith( - /^Invalid request body to create lightning invoice/ - ); + await should(handleCreateLightningInvoice(req)).be.rejected(); }); });