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';
32
32
import { SerializedNtilde } from '../../account-lib/mpc/tss/ecdsa/types' ;
33
33
import { IAddressBook } from '../address-book' ;
34
34
import { WalletUser } from '@bitgo/public-types' ;
35
+ import { ILightningWallet } from './lightning' ;
35
36
36
37
export interface MaximumSpendableOptions {
37
38
minValue ?: number | string ;
@@ -882,6 +883,7 @@ export interface IWallet {
882
883
sendTokenEnablement ( params ?: PrebuildAndSignTransactionOptions ) : Promise < any > ;
883
884
sendTokenEnablements ( params ?: BuildTokenEnablementOptions ) : Promise < any > ;
884
885
lightning ( ) : ILightning ;
886
+ lightningV2 ( ) : ILightningWallet ;
885
887
signMessage ( params : WalletSignMessageOptions ) : Promise < SignedMessage > ;
886
888
signTypedData ( params : WalletSignTypedDataOptions ) : Promise < SignedMessage > ;
887
889
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';
111
111
import { AddressBook , IAddressBook } from '../address-book' ;
112
112
import { IRequestTracer } from '../../api' ;
113
113
import { getTxRequestApiVersion , validateTxRequestApiVersion } from '../utils/txRequest' ;
114
+ import { ILightningWallet , SelfCustodialLightningWallet } from './lightning' ;
115
+ import { isLightningCoinName } from '../lightning' ;
114
116
115
117
const debug = require ( 'debug' ) ( 'bitgo:v2:wallet' ) ;
116
118
@@ -3075,6 +3077,16 @@ export class Wallet implements IWallet {
3075
3077
return new Lightning ( this . bitgo , this ) ;
3076
3078
}
3077
3079
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
+
3078
3090
/* MARK: TSS Helpers */
3079
3091
3080
3092
/**
You can’t perform that action at this time.
0 commit comments