@getalby/lightning-tools
Version:
Collection of helpful building blocks and tools to develop Bitcoin Lightning web apps
212 lines (204 loc) • 5.97 kB
TypeScript
import { WebLNProvider, SendPaymentResponse } from '@webbtc/webln-types';
type LnUrlRawData = {
tag: string;
callback: string;
minSendable: number;
maxSendable: number;
metadata: string;
payerData?: LUD18ServicePayerData;
commentAllowed?: number;
allowsNostr?: boolean;
};
type LnUrlPayResponse = {
callback: string;
fixed: boolean;
min: number;
max: number;
domain?: string;
metadata: Array<Array<string>>;
metadataHash: string;
identifier: string;
email: string;
description: string;
image: string;
commentAllowed?: number;
rawData: LnUrlRawData;
allowsNostr: boolean;
payerData?: LUD18ServicePayerData;
};
type LUD18ServicePayerData = Partial<{
name: {
mandatory: boolean;
};
pubkey: {
mandatory: boolean;
};
identifier: {
mandatory: boolean;
};
email: {
mandatory: boolean;
};
auth: {
mandatory: boolean;
k1: string;
};
}> & Record<string, unknown>;
type LUD18PayerData = Partial<{
name?: string;
pubkey?: string;
identifier?: string;
email?: string;
auth?: {
key: string;
sig: string;
};
}> & Record<string, unknown>;
type NostrResponse = {
names: Record<string, string>;
relays: Record<string, string[]>;
};
type Event = {
id?: string;
kind: number;
pubkey?: string;
content: string;
tags: string[][];
created_at: number;
sig?: string;
};
type ZapArgs = {
satoshi: number;
comment?: string;
relays: string[];
p?: string;
e?: string;
};
type NostrProvider = {
getPublicKey(): Promise<string>;
signEvent(event: Event & {
pubkey: string;
id: string;
}): Promise<Event>;
};
type ZapOptions = {
nostr?: NostrProvider;
};
type RequestInvoiceArgs = {
satoshi: number;
comment?: string;
payerdata?: LUD18PayerData;
};
type KeysendResponse = {
customKey: string;
customValue: string;
destination: string;
};
type KeySendRawData = {
tag: string;
status: string;
customData?: {
customKey?: string;
customValue?: string;
}[];
pubkey: string;
};
declare const parseKeysendResponse: (data: KeySendRawData) => KeysendResponse;
declare function generateZapEvent({ satoshi, comment, p, e, relays }: ZapArgs, options?: ZapOptions): Promise<Event>;
declare function validateEvent(event: Event): boolean;
declare function serializeEvent(evt: Event): string;
declare function getEventHash(event: Event): string;
declare function parseNostrResponse(nostrData: NostrResponse, username: string | undefined): readonly [NostrResponse, string | undefined, string[] | undefined];
declare const isUrl: (url: string | null) => url is string;
declare const isValidAmount: ({ amount, min, max, }: {
amount: number;
min: number;
max: number;
}) => boolean;
declare const parseLnUrlPayResponse: (data: LnUrlRawData) => Promise<LnUrlPayResponse>;
type InvoiceArgs = {
pr: string;
verify?: string;
preimage?: string;
successAction?: SuccessAction;
};
type SuccessAction = {
tag: "message";
message: string;
} | {
tag: "url";
description: string;
url: string;
};
declare class Invoice {
paymentRequest: string;
paymentHash: string;
preimage: string | null;
verify: string | null;
satoshi: number;
expiry: number | undefined;
timestamp: number;
createdDate: Date;
expiryDate: Date | undefined;
description: string | null;
successAction: SuccessAction | null;
constructor(args: InvoiceArgs);
isPaid(): Promise<boolean>;
validatePreimage(preimage: string): boolean;
verifyPayment(): Promise<boolean>;
hasExpired(): boolean;
}
type Boost = {
action: string;
value_msat: number;
value_msat_total: number;
app_name: string;
app_version: string;
feedId: string;
podcast: string;
episode: string;
ts: number;
name: string;
sender_name: string;
};
declare const LN_ADDRESS_REGEX: RegExp;
declare const DEFAULT_PROXY = "https://api.getalby.com/lnurl";
type LightningAddressOptions = {
proxy?: string | false;
webln?: WebLNProvider;
};
declare class LightningAddress {
address: string;
options: LightningAddressOptions;
username: string | undefined;
domain: string | undefined;
pubkey: string | undefined;
lnurlpData: LnUrlPayResponse | undefined;
keysendData: KeysendResponse | undefined;
nostrData: NostrResponse | undefined;
nostrPubkey: string | undefined;
nostrRelays: string[] | undefined;
webln: WebLNProvider | undefined;
constructor(address: string, options?: LightningAddressOptions);
parse(): void;
getWebLN(): any;
fetch(): Promise<void>;
fetchWithProxy(): Promise<void>;
fetchWithoutProxy(): Promise<void>;
fetchLnurlData(): Promise<void>;
fetchKeysendData(): Promise<void>;
fetchNostrData(): Promise<void>;
lnurlpUrl(): string;
keysendUrl(): string;
nostrUrl(): string;
generateInvoice(params: Record<string, string>): Promise<Invoice>;
requestInvoice(args: RequestInvoiceArgs): Promise<Invoice>;
boost(boost: Boost, amount?: number): Promise<SendPaymentResponse>;
zapInvoice({ satoshi, comment, relays, e }: ZapArgs, options?: ZapOptions): Promise<Invoice>;
zap(args: ZapArgs, options?: ZapOptions): Promise<SendPaymentResponse>;
private parseLnUrlPayResponse;
private parseKeysendResponse;
private parseNostrResponse;
}
export { DEFAULT_PROXY, LN_ADDRESS_REGEX, LightningAddress, generateZapEvent, getEventHash, isUrl, isValidAmount, parseKeysendResponse, parseLnUrlPayResponse, parseNostrResponse, serializeEvent, validateEvent };
export type { Event, KeySendRawData, KeysendResponse, LUD18PayerData, LUD18ServicePayerData, LnUrlPayResponse, LnUrlRawData, NostrProvider, NostrResponse, RequestInvoiceArgs, ZapArgs, ZapOptions };