Skip to content
Merged
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
2 changes: 2 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IRequestTracer } from '../../api';
import { CreateLightningInvoiceParams, LightningInvoiceResponse } from '../../lightning';
import {
IBaseCoin,
ITransactionRecipient,
Expand Down Expand Up @@ -1139,6 +1140,7 @@ export interface IWallet {
removePolicyRule(params?: RemovePolicyRuleOptions): Promise<any>;
remove(params?: Record<string, never>): Promise<any>;
toJSON(): WalletData;
createLightningInvoice(params: CreateLightningInvoiceParams): Promise<LightningInvoiceResponse>;
toTradingAccount(): ITradingAccount;
toStakingWallet(): IStakingWallet;
toGoStakingWallet(): IGoStakingWallet;
Expand Down
34 changes: 34 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
KeychainWithEncryptedPrv,
KeyIndices,
} from '../keychain';
import { CreateLightningInvoiceParams, LightningInvoiceResponse } from '../../lightning';
import { getLightningAuthKey } from '../lightning/lightningWalletUtil';
import { IPendingApproval, PendingApproval, PendingApprovals } from '../pendingApproval';
import { GoStakingWallet, StakingWallet } from '../staking';
Expand Down Expand Up @@ -3180,6 +3181,39 @@ export class Wallet implements IWallet {
return this._wallet;
}

/**
* Create a lightning invoice for this wallet.
* Supported for OFC (trading) and BTC wallets.
* Uses the same wallet-platform endpoint as lnbtc wallets.
* @param params.valueSat - Invoice value in satoshis - if not provided, a zero-value invoice is created
* @param params.memo - Optional memo/description
* @param params.expiry - Optional expiry in seconds (not supported for trading wallets)
*/
async createLightningInvoice(params: CreateLightningInvoiceParams): Promise<LightningInvoiceResponse> {
const family = this.baseCoin.getFamily();
if (family !== 'ofc' && family !== 'btc') {
throw new Error('createLightningInvoice is only supported for OFC and BTC wallets');
}

const body: Record<string, unknown> = {};
if (params.valueSat !== undefined) {
body.valueSat = params.valueSat;
}
if (params.memo !== undefined) {
body.memo = params.memo;
}
if (params.expiry !== undefined) {
body.expiry = params.expiry;
}

const response = await this.bitgo
.post(this.bitgo.url(`/wallet/${this.id()}/lightning/invoice`, 2))
.send(body)
.result();

return response as LightningInvoiceResponse;
}

/**
* Create a trading account from this wallet
*/
Expand Down
20 changes: 20 additions & 0 deletions modules/sdk-core/src/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ export function isBolt11Invoice(value: unknown): value is string {
}
return false;
}

export interface CreateLightningInvoiceParams {
valueSat?: number;
memo?: string;
expiry?: number;
}

export interface LightningInvoiceResponse {
valueMsat: bigint;
paymentHash: string;
invoice: string;
walletId: string;
status: 'open' | 'settled' | 'canceled';
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
valueSat?: number;
memo?: string;
amtPaidMsat?: bigint;
}
Loading