Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: objects for multiple input requests #30

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file added wrappers/fedimint-ts/bun.lockb
Binary file not shown.
62 changes: 7 additions & 55 deletions wrappers/fedimint-ts/src/FedimintClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,10 @@ export class FedimintClient {
* Creates a lightning invoice to receive payment via gateway
*/
createInvoice: async (
amountMsat: number,
description: string,
expiryTime?: number,
request: LightningInvoiceRequest,
gatewayId?: string,
federationId?: string
): Promise<LightningInvoiceResponse> => {
const request: LightningInvoiceRequest = {
amountMsat,
description,
expiryTime,
};

return await this.postWithGatewayIdAndFederationId<LightningInvoiceResponse>(
"/ln/invoice",
request,
Expand All @@ -425,22 +417,10 @@ export class FedimintClient {
* @param federationId - The ID of the federation to use for the invoice, if not provided will use the active federation ID
*/
createInvoiceForPubkeyTweak: async (
pubkey: string,
tweak: number,
amountMsat: number,
description: string,
expiryTime?: number,
request: LightningInvoiceExternalPubkeyTweakedRequest,
gatewayId?: string,
federationId?: string
): Promise<LightningInvoiceResponse> => {
const request: LightningInvoiceExternalPubkeyTweakedRequest = {
externalPubkey: pubkey,
tweak,
amountMsat,
description,
expiryTime,
};

return await this.postWithGatewayIdAndFederationId<LightningInvoiceExternalPubkeyTweakedResponse>(
"/ln/invoice-external-pubkey-tweaked",
request,
Expand All @@ -457,15 +437,9 @@ export class FedimintClient {
* @param federationId - The ID of the federation to claim the contracts in. Contracts are on specific federations so this is required.
*/
claimPubkeyTweakReceives: async (
privateKey: string,
tweaks: number[],
request: LightningClaimPubkeyTweakReceivesRequest,
federationId: string
): Promise<InfoResponse> => {
const request: LightningClaimPubkeyTweakReceivesRequest = {
privateKey,
tweaks,
};

return await this.postWithFederationId<InfoResponse>(
"/ln/claim-external-receive-tweaked",
request,
Expand Down Expand Up @@ -495,18 +469,10 @@ export class FedimintClient {
* Pays a lightning invoice or Lightningurl via a gateway
*/
pay: async (
paymentInfo: string,
amountMsat?: number,
LightningurlComment?: string,
request: LightningPayRequest,
gatewayId?: string,
federationId?: string
): Promise<LightningPayResponse> => {
const request: LightningPayRequest = {
paymentInfo,
amountMsat,
LightningurlComment,
};

return await this.postWithGatewayIdAndFederationId<LightningPayResponse>(
"/ln/pay",
request,
Expand All @@ -529,9 +495,7 @@ export class FedimintClient {
/**
* Decodes hex encoded binary ecash notes to json
*/
decodeNotes: async (
notes: string
): Promise<MintDecodeNotesResponse> => {
decodeNotes: async (notes: string): Promise<MintDecodeNotesResponse> => {
const request: MintDecodeNotesRequest = {
notes,
};
Expand Down Expand Up @@ -587,19 +551,9 @@ export class FedimintClient {
* @param federationId - The ID of the federation to spend the note in, if not provided will use the active federation ID
*/
spend: async (
amountMsat: number,
allowOverpay: boolean,
timeout: number,
includeInvite: boolean,
request: MintSpendRequest,
federationId?: string
): Promise<MintSpendResponse> => {
const request: MintSpendRequest = {
amountMsat,
allowOverpay,
timeout,
includeInvite,
};

return await this.postWithFederationId<MintSpendResponse>(
"/mint/spend",
request,
Expand Down Expand Up @@ -637,9 +591,7 @@ export class FedimintClient {
* Combines ecash notes into a single note string.
* @param notesVec - The notes to combine
*/
combine: async (
notesVec: string[]
): Promise<MintCombineResponse> => {
combine: async (notesVec: string[]): Promise<MintCombineResponse> => {
const request: MintCombineRequest = { notesVec };

return await this.post<MintCombineResponse>("/mint/combine", request);
Expand Down
56 changes: 44 additions & 12 deletions wrappers/fedimint-ts/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import dotenv from "dotenv";
import { randomBytes } from "crypto";
import * as secp256k1 from "secp256k1";
import { FedimintClientBuilder } from "../src";
import {
FedimintClientBuilder,
LightningClaimPubkeyReceiveTweakedRequest,
LightningInvoiceExternalPubkeyTweakedRequest,
LightningInvoiceRequest,
LightningPayRequest,
MintSpendRequest,
} from "../src";

dotenv.config();

Expand Down Expand Up @@ -98,29 +105,41 @@ async function main() {
logInputAndOutput({}, data);
// `/v2/ln/invoice`
logMethod("/v2/ln/invoice");
let lightningInvoiceRequest: LightningInvoiceRequest = {
amountMsat: 10000,
description: "test",
expiryTime: 3600,
};
let { operationId, invoice } = await fedimintClient.lightning.createInvoice(
10000,
"test"
lightningInvoiceRequest
);
logInputAndOutput(
{ amountMsat: 10000, description: "test" },
{ operationId, invoice }
);
// `/v2/ln/pay`
logMethod("/v2/ln/pay");
let payResponse = await fedimintClient.lightning.pay(invoice);
let lightningPayRequest: LightningPayRequest = {
paymentInfo: invoice,
};
let payResponse = await fedimintClient.lightning.pay(lightningPayRequest);
logInputAndOutput({ paymentInfo: invoice }, payResponse);
// `/v2/ln/await-invoice`
logMethod("/v2/ln/await-invoice");
data = await fedimintClient.lightning.awaitInvoice(operationId);
logInputAndOutput({ operationId }, data);
// `/v1/ln/invoice-external-pubkey-tweaked`
logMethod("/v1/ln/invoice-external-pubkey-tweaked");
let lightningInvoiceExternalPubkeyTweakedRequest: LightningInvoiceExternalPubkeyTweakedRequest =
{
externalPubkey: keyPair.publicKey,
tweak: 1,
amountMsat: 1000,
description: "test",
expiryTime: 3600,
};
data = await fedimintClient.lightning.createInvoiceForPubkeyTweak(
keyPair.publicKey,
1,
1000,
"test"
lightningInvoiceExternalPubkeyTweakedRequest
);
logInputAndOutput(
{
Expand All @@ -132,20 +151,33 @@ async function main() {
data
);
// pay the invoice
payResponse = await fedimintClient.lightning.pay(data.invoice);
let payRequest: LightningPayRequest = {
paymentInfo: data.invoice,
};
payResponse = await fedimintClient.lightning.pay(payRequest);
// `/v1/ln/claim-external-pubkey-tweaked`
logMethod("/v1/ln/claim-external-pubkey-tweaked");
let lightningClaimPubkeyTweakedRequest: LightningClaimPubkeyReceiveTweakedRequest =
{
privateKey: keyPair.privateKey,
tweaks: [1],
};
data = await fedimintClient.lightning.claimPubkeyTweakReceives(
keyPair.privateKey,
[1],
lightningClaimPubkeyTweakedRequest,
fedimintClient.getActiveFederationId()
);
logInputAndOutput({ privateKey: keyPair.privateKey, tweaks: [1] }, data);

// MINT METHODS
// `/v2/mint/spend`
logMethod("/v2/mint/spend");
let mintData = await fedimintClient.mint.spend(3000, true, 1000, false);
let spendRequest: MintSpendRequest = {
amountMsat: 3000,
allowOverpay: true,
timeout: 1000,
includeInvite: true,
};
let mintData = await fedimintClient.mint.spend(spendRequest);
logInputAndOutput(
{ amountMsat: 3000, allowOverpay: true, timeout: 1000 },
data
Expand Down
Loading