Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 11 additions & 4 deletions src/handlers/lnurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,17 @@ export function createLnurlHandlers(deps: LnurlHandlerDeps) {
try {
// Request a quote from the mint selected by this recipient.
const wallet = await deps.walletProvider.getWallet(claim.mint_url);
const quote = await wallet.createMintQuoteBolt11(
Math.floor(amount / 1000), // Convert msats to sats
zapRequest?.raw,
);
const amountSat = Math.floor(amount / 1000);
const quote = zapRequest
? await wallet.mint.createMintQuoteBolt11({
amount: amountSat,
unit: "sat",
description: zapRequest.raw,
description_hash: true,
} as Parameters<typeof wallet.mint.createMintQuoteBolt11>[0] & {
description_hash: true;
})
: await wallet.createMintQuoteBolt11(amountSat);

let quoteExpiry = quote.expiry;
if (zapRequest) {
Expand Down
42 changes: 27 additions & 15 deletions tests/per-recipient-mint.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ test("LNURL discovery advertises NIP-57 only when a zap signer is configured", a
assert.equal(zapResult.data.nostrPubkey, zapPubkey);
});

test("a valid NIP-57 request becomes the mint invoice description", async (t) => {
test("a valid NIP-57 request asks the mint for a description hash", async (t) => {
const db = createTestDatabase(t);
const recipientPubkey = getPublicKey(generateSecretKey());
const senderSecretKey = generateSecretKey();
Expand All @@ -307,14 +307,24 @@ test("a valid NIP-57 request becomes the mint invoice description", async (t) =>
walletProvider: {
async getWallet() {
return {
async createMintQuoteBolt11(amount, description) {
assert.equal(amount, 21);
descriptions.push(description);
return {
quote: "zap-quote",
request: createTestInvoice(amount * 1_000, description),
expiry: null,
};
mint: {
async createMintQuoteBolt11(payload) {
assert.deepEqual(payload, {
amount: 21,
unit: "sat",
description: rawZapRequest,
description_hash: true,
});
descriptions.push(payload.description);
return {
quote: "zap-quote",
request: createTestInvoice(
payload.amount * 1_000,
payload.description,
),
expiry: null,
};
},
},
};
},
Expand Down Expand Up @@ -372,12 +382,14 @@ test("a zap invoice that does not commit to the request is rejected", async (t)
walletProvider: {
async getWallet() {
return {
async createMintQuoteBolt11() {
return {
quote: "bad-zap-quote",
request: createTestInvoice(1_000, "not the zap request"),
expiry: 2_000_000_000,
};
mint: {
async createMintQuoteBolt11() {
return {
quote: "bad-zap-quote",
request: createTestInvoice(1_000, "not the zap request"),
expiry: 2_000_000_000,
};
},
},
};
},
Expand Down