@@ -48,7 +48,18 @@ type Nip07Provider = {
48
48
signEvent ( event : UnsignedEvent ) : Promise < Event > ;
49
49
} ;
50
50
51
+ type Nip47GetInfoResponse = {
52
+ alias : string ;
53
+ color : string ;
54
+ pubkey : string ;
55
+ network : string ;
56
+ block_height : number ;
57
+ block_hash : string ;
58
+ methods : string [ ] ;
59
+ } ;
60
+
51
61
const nip47ToWeblnRequestMap = {
62
+ get_info : "getInfo" ,
52
63
get_balance : "getBalance" ,
53
64
make_invoice : "makeInvoice" ,
54
65
pay_invoice : "sendPayment" ,
@@ -215,18 +226,41 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
215
226
// WebLN compatible response
216
227
// TODO: use NIP-47 get_info call
217
228
async getInfo ( ) : Promise < GetInfoResponse > {
218
- return {
219
- methods : [
220
- "getInfo" ,
221
- "sendPayment" ,
222
- "makeInvoice" ,
223
- "getBalance" ,
224
- "lookupInvoice" ,
225
- ] ,
226
- node : { } as WebLNNode ,
227
- supports : [ "lightning" ] ,
228
- version : "NWC" ,
229
- } ;
229
+ this . checkConnected ( ) ;
230
+
231
+ const supports = [ "lightning" , "nostr" ] ;
232
+ const version = "Alby JS SDK" ;
233
+
234
+ try {
235
+ return this . executeNip47Request < GetInfoResponse , Nip47GetInfoResponse > (
236
+ "get_info" ,
237
+ undefined ,
238
+ ( result ) => ! ! result . methods ,
239
+ ( result ) => ( {
240
+ methods : result . methods . map (
241
+ ( key ) =>
242
+ nip47ToWeblnRequestMap [
243
+ key as keyof typeof nip47ToWeblnRequestMap
244
+ ] ,
245
+ ) ,
246
+ node : {
247
+ alias : result . alias ,
248
+ pubkey : result . pubkey ,
249
+ color : result . color ,
250
+ } as WebLNNode ,
251
+ supports,
252
+ version,
253
+ } ) ,
254
+ ) ;
255
+ } catch ( error ) {
256
+ console . error ( "Failed to request get_info" , error ) ;
257
+ return {
258
+ methods : [ "sendPayment" ] ,
259
+ node : { } as WebLNNode ,
260
+ supports,
261
+ version,
262
+ } ;
263
+ }
230
264
}
231
265
232
266
getBalance ( ) {
0 commit comments