diff --git a/modules/sdk-core/src/bitgo/wallet/iWallet.ts b/modules/sdk-core/src/bitgo/wallet/iWallet.ts index f98e985d7d..d884ead5be 100644 --- a/modules/sdk-core/src/bitgo/wallet/iWallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/iWallet.ts @@ -1,4 +1,5 @@ import { IRequestTracer } from '../../api'; +import { CreateLightningInvoiceParams, LightningInvoiceResponse } from '../../lightning'; import { IBaseCoin, ITransactionRecipient, @@ -1139,6 +1140,7 @@ export interface IWallet { removePolicyRule(params?: RemovePolicyRuleOptions): Promise; remove(params?: Record): Promise; toJSON(): WalletData; + createLightningInvoice(params: CreateLightningInvoiceParams): Promise; toTradingAccount(): ITradingAccount; toStakingWallet(): IStakingWallet; toGoStakingWallet(): IGoStakingWallet; diff --git a/modules/sdk-core/src/bitgo/wallet/wallet.ts b/modules/sdk-core/src/bitgo/wallet/wallet.ts index c5ccbd4336..592914ec66 100644 --- a/modules/sdk-core/src/bitgo/wallet/wallet.ts +++ b/modules/sdk-core/src/bitgo/wallet/wallet.ts @@ -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'; @@ -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 { + 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 = {}; + 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 */ diff --git a/modules/sdk-core/src/lightning.ts b/modules/sdk-core/src/lightning.ts index 234fe7499e..4abb105da3 100644 --- a/modules/sdk-core/src/lightning.ts +++ b/modules/sdk-core/src/lightning.ts @@ -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; +}