Skip to content

Commit de83cdf

Browse files
Merge pull request #8877 from BitGo/T1-3473
feat(sdk-core): create invoice from standard wallet
2 parents 03bcc23 + e828947 commit de83cdf

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IRequestTracer } from '../../api';
2+
import { CreateLightningInvoiceParams, LightningInvoiceResponse } from '../../lightning';
23
import {
34
IBaseCoin,
45
ITransactionRecipient,
@@ -1139,6 +1140,7 @@ export interface IWallet {
11391140
removePolicyRule(params?: RemovePolicyRuleOptions): Promise<any>;
11401141
remove(params?: Record<string, never>): Promise<any>;
11411142
toJSON(): WalletData;
1143+
createLightningInvoice(params: CreateLightningInvoiceParams): Promise<LightningInvoiceResponse>;
11421144
toTradingAccount(): ITradingAccount;
11431145
toStakingWallet(): IStakingWallet;
11441146
toGoStakingWallet(): IGoStakingWallet;

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
KeychainWithEncryptedPrv,
4040
KeyIndices,
4141
} from '../keychain';
42+
import { CreateLightningInvoiceParams, LightningInvoiceResponse } from '../../lightning';
4243
import { getLightningAuthKey } from '../lightning/lightningWalletUtil';
4344
import { IPendingApproval, PendingApproval, PendingApprovals } from '../pendingApproval';
4445
import { GoStakingWallet, StakingWallet } from '../staking';
@@ -3180,6 +3181,39 @@ export class Wallet implements IWallet {
31803181
return this._wallet;
31813182
}
31823183

3184+
/**
3185+
* Create a lightning invoice for this wallet.
3186+
* Supported for OFC (trading) and BTC wallets.
3187+
* Uses the same wallet-platform endpoint as lnbtc wallets.
3188+
* @param params.valueSat - Invoice value in satoshis - if not provided, a zero-value invoice is created
3189+
* @param params.memo - Optional memo/description
3190+
* @param params.expiry - Optional expiry in seconds (not supported for trading wallets)
3191+
*/
3192+
async createLightningInvoice(params: CreateLightningInvoiceParams): Promise<LightningInvoiceResponse> {
3193+
const family = this.baseCoin.getFamily();
3194+
if (family !== 'ofc' && family !== 'btc') {
3195+
throw new Error('createLightningInvoice is only supported for OFC and BTC wallets');
3196+
}
3197+
3198+
const body: Record<string, unknown> = {};
3199+
if (params.valueSat !== undefined) {
3200+
body.valueSat = params.valueSat;
3201+
}
3202+
if (params.memo !== undefined) {
3203+
body.memo = params.memo;
3204+
}
3205+
if (params.expiry !== undefined) {
3206+
body.expiry = params.expiry;
3207+
}
3208+
3209+
const response = await this.bitgo
3210+
.post(this.bitgo.url(`/wallet/${this.id()}/lightning/invoice`, 2))
3211+
.send(body)
3212+
.result();
3213+
3214+
return response as LightningInvoiceResponse;
3215+
}
3216+
31833217
/**
31843218
* Create a trading account from this wallet
31853219
*/

modules/sdk-core/src/lightning.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,23 @@ export function isBolt11Invoice(value: unknown): value is string {
77
}
88
return false;
99
}
10+
11+
export interface CreateLightningInvoiceParams {
12+
valueSat?: number;
13+
memo?: string;
14+
expiry?: number;
15+
}
16+
17+
export interface LightningInvoiceResponse {
18+
valueMsat: bigint;
19+
paymentHash: string;
20+
invoice: string;
21+
walletId: string;
22+
status: 'open' | 'settled' | 'canceled';
23+
expiresAt: Date;
24+
createdAt: Date;
25+
updatedAt: Date;
26+
valueSat?: number;
27+
memo?: string;
28+
amtPaidMsat?: bigint;
29+
}

0 commit comments

Comments
 (0)