From 5b8b5a900c7c9e8b23e34118a8c1614fccccebb7 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Sat, 23 Mar 2024 10:28:58 -0700 Subject: [PATCH] fix: tests for p2pk and claim --- wrappers/fedimint-ts/FedimintClient.ts | 26 -------------- wrappers/fedimint-ts/test.ts | 48 ++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/wrappers/fedimint-ts/FedimintClient.ts b/wrappers/fedimint-ts/FedimintClient.ts index 81216c5..60dea54 100644 --- a/wrappers/fedimint-ts/FedimintClient.ts +++ b/wrappers/fedimint-ts/FedimintClient.ts @@ -355,32 +355,6 @@ class FedimintClient { federationId ); }, - - /** - * Creates a lightning invoice where the gateway contract locks the ecash to a specific pubkey - * Useful for creating invoices that pay to another user besides yourself - */ - createInvoicePubkey: async ( - pubkey: string, - amountMsat: number, - description: string, - expiryTime?: number, - federationId?: string - ): FedimintResponse => { - const request: LnInvoiceExternalPubkeyRequest = { - externalPubkey: pubkey, - amountMsat, - description, - expiryTime, - }; - - return await this.postWithId( - "/ln/invoice-external-pubkey", - request, - federationId - ); - }, - /** * Waits for a lightning invoice to be paid */ diff --git a/wrappers/fedimint-ts/test.ts b/wrappers/fedimint-ts/test.ts index 9002d4a..1306829 100644 --- a/wrappers/fedimint-ts/test.ts +++ b/wrappers/fedimint-ts/test.ts @@ -53,8 +53,6 @@ async function main() { const keyPair = newKeyPair(); console.log("Generated key pair: ", keyPair); - return; - // ADMIN METHODS // `/v2/admin/config` logMethod("/v2/admin/config"); @@ -107,6 +105,52 @@ async function main() { logMethod("/v2/ln/await-invoice"); data = await fedimintClient.ln.awaitInvoice(operationId); logInputAndOutput({ operationId }, data); + // `/v1/ln/invoice-external-pubkey` + logMethod("/v1/ln/invoice-external-pubkey"); + data = await fedimintClient.ln.createInvoiceForPubkey( + keyPair.publicKey, + 1000, + "test" + ); + logInputAndOutput( + { + externalPubkey: keyPair.publicKey, + amountMsat: 10000, + description: "test", + }, + data + ); + // pay the invoice + payResponse = await fedimintClient.ln.pay(data.invoice); + // `/v1/ln/claim-external-pubkey` + logMethod("/v1/ln/claim-external-pubkey"); + data = await fedimintClient.ln.claimPubkeyReceive(keyPair.privateKey); + logInputAndOutput({ privateKey: keyPair.privateKey }, data); + // `/v1/ln/invoice-external-pubkey-tweaked` + logMethod("/v1/ln/invoice-external-pubkey-tweaked"); + data = await fedimintClient.ln.createInvoiceForPubkeyTweak( + keyPair.publicKey, + 1, + 1000, + "test" + ); + logInputAndOutput( + { + externalPubkey: keyPair.publicKey, + tweak: 1, + amountMsat: 10000, + description: "test", + }, + data + ); + // pay the invoice + payResponse = await fedimintClient.ln.pay(data.invoice); + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked"); + data = await fedimintClient.ln.claimPubkeyReceiveTweaked(keyPair.privateKey, [ + 1, + ]); + logInputAndOutput({ privateKey: keyPair.privateKey, tweaks: [1] }, data); // MINT METHODS // `/v2/mint/spend`