From 69690c3a79dddb3395e1a50354c56f30a344a41e Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 8 Sep 2024 18:32:25 +0200 Subject: [PATCH 1/3] NUT-05: description for invoice, integration test without bolt11 decode --- src/CashuWallet.ts | 9 ++++++--- src/model/types/wallet/payloads.ts | 4 ++++ test/integration.test.ts | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/CashuWallet.ts b/src/CashuWallet.ts index 0442bb04..5e9cf89e 100644 --- a/src/CashuWallet.ts +++ b/src/CashuWallet.ts @@ -20,7 +20,8 @@ import { type TokenEntry, CheckStateEnum, SerializedBlindedSignature, - MeltQuoteState + MeltQuoteState, + MintQuoteResponse } from './model/types/index.js'; import { bytesToNumber, @@ -331,12 +332,14 @@ class CashuWallet { /** * Requests a mint quote form the mint. Response returns a Lightning payment request for the requested given amount and unit. * @param amount Amount requesting for mint. + * @param description optional description for the mint quote * @returns the mint will return a mint quote with a Lightning invoice for minting tokens of the specified amount and unit */ - async createMintQuote(amount: number) { + async createMintQuote(amount: number, description?: string) { const mintQuotePayload: MintQuotePayload = { unit: this._unit, - amount: amount + amount: amount, + description: description || null, }; return await this.mint.createMintQuote(mintQuotePayload); } diff --git a/src/model/types/wallet/payloads.ts b/src/model/types/wallet/payloads.ts index 43539a91..70855dea 100644 --- a/src/model/types/wallet/payloads.ts +++ b/src/model/types/wallet/payloads.ts @@ -98,6 +98,10 @@ export type MintQuotePayload = { * Amount to be minted */ amount: number; + /** + * Description for the invoice + */ + description: string | null; }; /** diff --git a/test/integration.test.ts b/test/integration.test.ts index 2d069392..936c8245 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -61,6 +61,13 @@ describe('mint api', () => { // because local invoice, fee should be 0 expect(fee).toBe(0); }); + test('invoice with description', async () => { + const mint = new CashuMint(mintUrl); + const wallet = new CashuWallet(mint, { unit }); + const quote = await wallet.createMintQuote(100, 'test description'); + expect(quote).toBeDefined(); + console.log(`invoice with description: ${quote.request}`); + }); test('get fee for external invoice', async () => { const mint = new CashuMint(mintUrl); const wallet = new CashuWallet(mint, { unit }); From 87d91b028105eda705edfac399b0f03557629e1a Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 8 Sep 2024 18:34:05 +0200 Subject: [PATCH 2/3] npm run format --- src/CashuWallet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CashuWallet.ts b/src/CashuWallet.ts index 5e9cf89e..4e783bf5 100644 --- a/src/CashuWallet.ts +++ b/src/CashuWallet.ts @@ -339,7 +339,7 @@ class CashuWallet { const mintQuotePayload: MintQuotePayload = { unit: this._unit, amount: amount, - description: description || null, + description: description || null }; return await this.mint.createMintQuote(mintQuotePayload); } From 56ee3ddb1e1b5d0ffbb8a56fff1c1329992e84f0 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 8 Sep 2024 22:14:54 +0200 Subject: [PATCH 3/3] use description? --- src/CashuWallet.ts | 2 +- src/model/types/wallet/payloads.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CashuWallet.ts b/src/CashuWallet.ts index 4e783bf5..2518664a 100644 --- a/src/CashuWallet.ts +++ b/src/CashuWallet.ts @@ -339,7 +339,7 @@ class CashuWallet { const mintQuotePayload: MintQuotePayload = { unit: this._unit, amount: amount, - description: description || null + description: description }; return await this.mint.createMintQuote(mintQuotePayload); } diff --git a/src/model/types/wallet/payloads.ts b/src/model/types/wallet/payloads.ts index 70855dea..7e8b6766 100644 --- a/src/model/types/wallet/payloads.ts +++ b/src/model/types/wallet/payloads.ts @@ -101,7 +101,7 @@ export type MintQuotePayload = { /** * Description for the invoice */ - description: string | null; + description?: string; }; /**