File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
sdk-core/src/bitgo/wallet Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ import { strict as assert } from 'assert' ;
2+ import { TestBitGo } from '@bitgo/sdk-test' ;
3+ import { BitGo } from '../../../src' ;
4+ import { Wallet } from '@bitgo/sdk-core' ;
5+
6+ describe ( 'LightningV2 Wallet:' , function ( ) {
7+ const bitgo = TestBitGo . decorate ( BitGo , { env : 'test' } ) ;
8+ bitgo . initializeTestVars ( ) ;
9+
10+ it ( 'should allow lightningV2 wallets to be created for supported coins' , function ( ) {
11+ const lnbtcWallet = new Wallet ( bitgo , bitgo . coin ( 'lnbtc' ) , {
12+ id : '123' ,
13+ coin : 'lnbtc' ,
14+ } ) ;
15+
16+ const tlntcWallet = new Wallet ( bitgo , bitgo . coin ( 'tlnbtc' ) , {
17+ id : '123' ,
18+ coin : 'tlntc' ,
19+ } ) ;
20+
21+ assert ( lnbtcWallet . lightningV2 ( ) , 'lnbtc wallet should support lightningV2' ) ;
22+ assert ( tlntcWallet . lightningV2 ( ) , 'tlnbtc wallet should support lightningV2' ) ;
23+ } ) ;
24+
25+ it ( 'should throw error when creating lightningV2 wallet for unsupported coins' , function ( ) {
26+ const btcWallet = new Wallet ( bitgo , bitgo . coin ( 'btc' ) , {
27+ id : '123' ,
28+ coin : 'btc' ,
29+ } ) ;
30+
31+ assert . throws ( ( ) => {
32+ btcWallet . lightningV2 ( ) ;
33+ } , / L i g h t n i n g n o t s u p p o r t e d f o r b t c / ) ;
34+ } ) ;
35+ } ) ;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import { ILightning } from '../lightning/custodial';
3232import { SerializedNtilde } from '../../account-lib/mpc/tss/ecdsa/types' ;
3333import { IAddressBook } from '../address-book' ;
3434import { WalletUser } from '@bitgo/public-types' ;
35+ import { ILightningWallet } from './lightning' ;
3536
3637export interface MaximumSpendableOptions {
3738 minValue ?: number | string ;
@@ -882,6 +883,7 @@ export interface IWallet {
882883 sendTokenEnablement ( params ?: PrebuildAndSignTransactionOptions ) : Promise < any > ;
883884 sendTokenEnablements ( params ?: BuildTokenEnablementOptions ) : Promise < any > ;
884885 lightning ( ) : ILightning ;
886+ lightningV2 ( ) : ILightningWallet ;
885887 signMessage ( params : WalletSignMessageOptions ) : Promise < SignedMessage > ;
886888 signTypedData ( params : WalletSignTypedDataOptions ) : Promise < SignedMessage > ;
887889 fetchCrossChainUTXOs ( params : FetchCrossChainUTXOsOptions ) : Promise < CrossChainUTXO [ ] > ;
Original file line number Diff line number Diff line change 1+ import { IWallet } from './iWallet' ;
2+
3+ export interface ILightningWallet {
4+ /**
5+ * Creates a lightning invoice
6+ * @param params Invoice parameters (to be defined)
7+ */
8+ createInvoice ( params : unknown ) : Promise < unknown > ;
9+
10+ /**
11+ * Pay a lightning invoice
12+ * @param params Payment parameters (to be defined)
13+ */
14+ payInvoice ( params : unknown ) : Promise < unknown > ;
15+ }
16+
17+ export class SelfCustodialLightningWallet implements ILightningWallet {
18+ public wallet : IWallet ;
19+
20+ constructor ( wallet : IWallet ) {
21+ this . wallet = wallet ;
22+ }
23+
24+ async createInvoice ( params : unknown ) : Promise < unknown > {
25+ throw new Error ( 'Method not implemented.' ) ;
26+ }
27+
28+ async payInvoice ( params : unknown ) : Promise < unknown > {
29+ throw new Error ( 'Method not implemented.' ) ;
30+ }
31+ }
Original file line number Diff line number Diff line change @@ -111,6 +111,8 @@ import { TxSendBody } from '@bitgo/public-types';
111111import { AddressBook , IAddressBook } from '../address-book' ;
112112import { IRequestTracer } from '../../api' ;
113113import { getTxRequestApiVersion , validateTxRequestApiVersion } from '../utils/txRequest' ;
114+ import { ILightningWallet , SelfCustodialLightningWallet } from './lightning' ;
115+ import { isLightningCoinName } from '../lightning' ;
114116
115117const debug = require ( 'debug' ) ( 'bitgo:v2:wallet' ) ;
116118
@@ -3075,6 +3077,16 @@ export class Wallet implements IWallet {
30753077 return new Lightning ( this . bitgo , this ) ;
30763078 }
30773079
3080+ /**
3081+ * Return a lightwallet instance if the coin supports it
3082+ */
3083+ public lightningV2 ( ) : ILightningWallet {
3084+ if ( ! isLightningCoinName ( this . baseCoin . getChain ( ) ) ) {
3085+ throw new Error ( `Lightning not supported for ${ this . coin ( ) } ` ) ;
3086+ }
3087+ return new SelfCustodialLightningWallet ( this ) ;
3088+ }
3089+
30783090 /* MARK: TSS Helpers */
30793091
30803092 /**
You can’t perform that action at this time.
0 commit comments