@fedimint/core-web 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/dts/FedimintWallet.d.ts +50 -0
  2. package/dist/dts/FedimintWallet.d.ts.map +1 -1
  3. package/dist/dts/services/BalanceService.d.ts +2 -21
  4. package/dist/dts/services/BalanceService.d.ts.map +1 -1
  5. package/dist/dts/services/FederationService.d.ts +1 -1
  6. package/dist/dts/services/FederationService.d.ts.map +1 -1
  7. package/dist/dts/services/LightningService.d.ts +11 -2
  8. package/dist/dts/services/LightningService.d.ts.map +1 -1
  9. package/dist/dts/services/MintService.d.ts +12 -6
  10. package/dist/dts/services/MintService.d.ts.map +1 -1
  11. package/dist/dts/services/RecoveryService.d.ts +1 -1
  12. package/dist/dts/services/RecoveryService.d.ts.map +1 -1
  13. package/dist/dts/types/utils.d.ts +8 -1
  14. package/dist/dts/types/utils.d.ts.map +1 -1
  15. package/dist/dts/types/wallet.d.ts +4 -10
  16. package/dist/dts/types/wallet.d.ts.map +1 -1
  17. package/dist/dts/types/worker.d.ts +1 -1
  18. package/dist/dts/types/worker.d.ts.map +1 -1
  19. package/dist/dts/worker/WorkerClient.d.ts +1 -1
  20. package/dist/dts/worker/WorkerClient.d.ts.map +1 -1
  21. package/dist/index.d.ts +87 -40
  22. package/dist/index.js +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/worker.js +1 -1
  25. package/dist/worker.js.map +1 -1
  26. package/package.json +8 -8
  27. package/src/FedimintWallet.ts +58 -0
  28. package/src/services/BalanceService.ts +5 -26
  29. package/src/services/FederationService.ts +9 -7
  30. package/src/services/LightningService.ts +81 -65
  31. package/src/services/MintService.ts +32 -25
  32. package/src/services/RecoveryService.ts +9 -7
  33. package/src/types/utils.ts +5 -1
  34. package/src/types/wallet.ts +12 -9
  35. package/src/types/worker.ts +2 -0
  36. package/src/worker/WorkerClient.ts +8 -9
  37. package/src/worker/worker.js +34 -0
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/utils/logger.ts","../src/worker/WorkerClient.ts","../src/services/MintService.ts","../src/services/BalanceService.ts","../src/services/LightningService.ts","../src/services/RecoveryService.ts","../src/services/FederationService.ts","../src/FedimintWallet.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":["logLevels","logger","constructor","level","this","setLevel","coerceLevel","includes","toLocaleUpperCase","log","message","args","logLevel","shouldLog","consoleFn","console","toUpperCase","debug","info","warn","error","messageLevel","levels","messageLevelIndex","indexOf","WorkerClient","requestCounter","requestCallbacks","Map","initPromise","undefined","worker","Worker","URL","url","type","onmessage","handleWorkerMessage","bind","onerror","handleWorkerError","initialize","sendSingleMessage","handleWorkerLogs","event","data","requestId","streamCallback","get","payload","Promise","resolve","reject","set","response","delete","postMessage","rpcStream","module","method","body","onSuccess","onError","onEnd","unsubscribe","isSubscribed","unsubscribePromise","setTimeout","_rpcStreamInner","then","end","rpcSingle","cleanup","clear","_getRequestCounter","_getRequestCallbackMap","MintService","client","redeemEcash","notes","oob_notes","extra_meta","reissueExternalNotes","oobNotes","extraMeta","subscribeReissueExternalNotes","operationId","operation_id","spendNotes","amountMsats","tryCancelAfter","includeInvite","duration","nanos","secs","res","min_amount","try_cancel_after","include_invite","parseNotes","tryCancelSpendNotes","subscribeSpendNotes","awaitSpendOobRefund","BalanceService","getBalance","subscribeBalance","parseInt","LightningService","createInvoice","description","expiryTime","gatewayInfo","gateway","_getDefaultGatewayInfo","amount","expiry_time","createInvoiceTweaked","tweakKey","index","user_key","scanReceivesForTweaks","indices","updateGatewayCache","gateways","listGateways","payInvoice","invoice","maybe_gateway","payInvoiceSync","timeoutMs","async","contract_id","fee","subscribeLnPay","clearTimeout","timeoutId","success","feeMsats","preimage","Error","subscribeLnClaim","waitForPay","subscribeLnReceive","waitForReceive","getGateway","gatewayId","forceInternal","gateway_id","force_internal","RecoveryService","hasPendingRecoveries","waitForAllRecoveries","subscribeToRecoveryProgress","FederationService","getConfig","getFederationId","getInviteCode","peer","listOperations","DEFAULT_CLIENT_NAME","FedimintWallet","lazy","_openPromise","_resolveOpen","_isOpen","_client","mint","lightning","balance","federation","recovery","waitForOpen","open","clientName","joinFederation","inviteCode","e","isOpen","setLogLevel"],"mappings":"AAAA,MAAMA,EAAY,CAAC,QAAS,OAAQ,OAAQ,QAAS,QA4D9C,MAAMC,EAAS,UAtDpB,WAAAC,CAAYC,EAAkB,QAC5BC,KAAKD,MAAQA,CACd,CAED,QAAAE,CAASF,GACPC,KAAKD,MAAQA,CACd,CAED,WAAAG,CAAYH,GACV,OAAIH,EAAUO,SAASJ,EAAMK,qBACpBL,EAAMK,oBAER,MACR,CAED,GAAAC,CAAIN,EAAeO,KAAoBC,GACrC,MAAMC,EAAWR,KAAKE,YAAYH,GAClC,IAAKC,KAAKS,UAAUD,GAClB,QAGFE,EADkBC,QAAQH,IAChB,IAAIA,EAASI,kBAAkBN,OAAcC,EACxD,CAED,KAAAM,CAAMP,KAAoBC,GACxBP,KAAKK,IAAI,QAASC,KAAYC,EAC/B,CAED,IAAAO,CAAKR,KAAoBC,GACvBP,KAAKK,IAAI,OAAQC,KAAYC,EAC9B,CAED,IAAAQ,CAAKT,KAAoBC,GACvBP,KAAKK,IAAI,OAAQC,KAAYC,EAC9B,CAED,KAAAS,CAAMV,KAAoBC,GACxBP,KAAKK,IAAI,QAASC,KAAYC,EAC/B,CAEO,SAAAE,CACNQ,GAEA,MAAMC,EAAqB,CAAC,QAAS,OAAQ,OAAQ,QAAS,QACxDC,EAAoBD,EAAOE,QAAQH,GAEzC,OAD0BC,EAAOE,QAAQpB,KAAKD,QAEvBoB,GACN,SAAfnB,KAAKD,OACY,SAAjBkB,CAEH,SC7CUI,EAMX,WAAAvB,GAJQE,KAAcsB,eAAG,EACjBtB,KAAAuB,iBAAmB,IAAIC,IACvBxB,KAAWyB,iBAAiCC,EAIlD1B,KAAK2B,OAAS,IAAIC,OAAO,I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YF,eAMzB,OALIvH,EAASkF,UACXpI,KAAKgK,SAAU,EACfhK,KAAK+J,gBAGA7G,EAASkF,OACjB,CAAC,MAAOwC,GAEP,OADA/K,EAAOmB,MAAM,2BAA4B4J,IAClC,CACR,CACF,CAMD,aAAMxG,GACJpE,KAAK8J,kBAAepI,EACpB1B,KAAKgK,SAAU,QACThK,KAAKiK,QAAQ7F,SACpB,CAED,MAAAyG,GACE,OAAO7K,KAAKgK,OACb,CAMD,WAAAc,CAAY/K,GACVF,EAAOI,SAASF,GAChBF,EAAOiB,KAAK,oBAAoBf,KACjC"}
1
+ {"version":3,"file":"index.js","sources":["../src/utils/logger.ts","../src/worker/WorkerClient.ts","../src/services/MintService.ts","../src/services/BalanceService.ts","../src/services/LightningService.ts","../src/services/RecoveryService.ts","../src/services/FederationService.ts","../src/FedimintWallet.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":["logLevels","logger","constructor","level","this","setLevel","coerceLevel","includes","toLocaleUpperCase","log","message","args","logLevel","shouldLog","consoleFn","console","toUpperCase","debug","info","warn","error","messageLevel","levels","messageLevelIndex","indexOf","WorkerClient","requestCounter","requestCallbacks","Map","initPromise","undefined","worker","Worker","URL","url","type","onmessage","handleWorkerMessage","bind","onerror","handleWorkerError","initialize","sendSingleMessage","handleWorkerLogs","event","data","requestId","streamCallback","get","payload","Promise","resolve","reject","set","response","delete","postMessage","rpcStream","module","method","body","onSuccess","onError","onEnd","unsubscribe","isSubscribed","unsubscribePromise","setTimeout","_rpcStreamInner","then","end","rpcSingle","cleanup","clear","_getRequestCounter","_getRequestCallbackMap","MintService","client","redeemEcash","notes","oob_notes","extra_meta","reissueExternalNotes","oobNotes","extraMeta","subscribeReissueExternalNotes","operationId","operation_id","spendNotes","amountMsats","tryCancelAfter","includeInvite","duration","nanos","secs","res","amount","try_cancel_after","include_invite","parseNotes","tryCancelSpendNotes","subscribeSpendNotes","awaitSpendOobRefund","BalanceService","getBalance","subscribeBalance","parseInt","LightningService","createInvoice","description","expiryTime","gatewayInfo","gateway","_getDefaultGatewayInfo","expiry_time","createInvoiceTweaked","tweakKey","index","user_key","scanReceivesForTweaks","indices","updateGatewayCache","gateways","listGateways","payInvoice","invoice","maybe_gateway","payInvoiceSync","timeoutMs","async","contract_id","fee","subscribeLnPay","clearTimeout","timeoutId","success","feeMsats","preimage","Error","unexpected_error","error_message","subscribeLnClaim","waitForPay","subscribeLnReceive","waitForReceive","getGateway","gatewayId","forceInternal","gateway_id","force_internal","RecoveryService","hasPendingRecoveries","waitForAllRecoveries","subscribeToRecoveryProgress","FederationService","getConfig","getFederationId","getInviteCode","peer","listOperations","DEFAULT_CLIENT_NAME","FedimintWallet","lazy","_openPromise","_resolveOpen","_isOpen","_client","mint","lightning","balance","federation","recovery","waitForOpen","open","clientName","joinFederation","inviteCode","e","isOpen","setLogLevel","parseInviteCode","parseBolt11Invoice","invoiceStr"],"mappings":"AAAA,MAAMA,EAAY,CAAC,QAAS,OAAQ,OAAQ,QAAS,QA4D9C,MAAMC,EAAS,UAtDpB,WAAAC,CAAYC,EAAkB,QAC5BC,KAAKD,MAAQA,EAGf,QAAAE,CAASF,GACPC,KAAKD,MAAQA,EAGf,WAAAG,CAAYH,GACV,OAAIH,EAAUO,SAASJ,EAAMK,qBACpBL,EAAMK,oBAER,OAGT,GAAAC,CAAIN,EAAeO,KAAoBC,GACrC,MAAMC,EAAWR,KAAKE,YAAYH,GAClC,IAAKC,KAAKS,UAAUD,GAClB,QAGFE,EADkBC,QAAQH,IAChB,IAAIA,EAASI,kBAAkBN,OAAcC,GAGzD,KAAAM,CAAMP,KAAoBC,GACxBP,KAAKK,IAAI,QAASC,KAAYC,GAGhC,IAAAO,CAAKR,KAAoBC,GACvBP,KAAKK,IAAI,OAAQC,KAAYC,GAG/B,IAAAQ,CAAKT,KAAoBC,GACvBP,KAAKK,IAAI,OAAQC,KAAYC,GAG/B,KAAAS,CAAMV,KAAoBC,GACxBP,KAAKK,IAAI,QAASC,KAAYC,GAGxB,SAAA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FAEJ,IACE,MAAMpF,QAAiBlD,KAAKkK,QAAQ5H,kBAEjC,OAAQ,CAAEsI,aAAYF,eAMzB,OALIxH,EAASiF,UACXnI,KAAKiK,SAAU,EACfjK,KAAKgK,gBAGA9G,EAASiF,QAChB,MAAO0C,GAEP,OADAhL,EAAOmB,MAAM,2BAA4B6J,IAClC,GAQX,aAAMzG,GACJpE,KAAK+J,kBAAerI,EACpB1B,KAAKiK,SAAU,QACTjK,KAAKkK,QAAQ9F,UAGrB,MAAA0G,GACE,OAAO9K,KAAKiK,QAOd,WAAAc,CAAYhL,GACVF,EAAOI,SAASF,GAChBF,EAAOiB,KAAK,oBAAoBf,MAsBlC,qBAAMiL,CAAgBJ,GAMpB,aALuB5K,KAAKkK,QAAQ5H,kBAIjC,kBAAmB,CAAEsI,eAwB1B,wBAAMK,CAAmBC,GAMvB,aALuBlL,KAAKkK,QAAQ5H,kBAIjC,qBAAsB,CAAE4I"}
package/dist/worker.js CHANGED
@@ -1,2 +1,2 @@
1
- globalThis.__vitest_browser_runner__={wrapDynamicImport:e=>e()};let e=null,s=null;const t=new Map;console.log("Worker - init"),self.onmessage=async o=>{const{type:r,payload:n,requestId:a}=o.data;try{if("init"===r)e=(await import("@fedimint/fedimint-client-wasm-bundler")).WasmClient,self.postMessage({type:"initialized",data:{},requestId:a});else if("open"===r){const{clientName:t}=n;s=await e.open(t)||null,self.postMessage({type:"open",data:{success:!!s},requestId:a})}else if("join"===r){const{inviteCode:t,clientName:o}=n;try{s=await e.join_federation(o,t),self.postMessage({type:"join",data:{success:!!s},requestId:a})}catch(e){self.postMessage({type:"error",error:e.message,requestId:a})}}else if("rpc"===r){const{module:e,method:o,body:r}=n;if(console.log("RPC received",e,o,r),!s)return void self.postMessage({type:"error",error:"WasmClient not initialized",requestId:a});const i=await s.rpc(e,o,JSON.stringify(r),(e=>{console.log("RPC response",a,e);const s=JSON.parse(e);if(self.postMessage({type:"rpcResponse",requestId:a,...s}),void 0!==s.end){const e=t.get(a);e?.free()}}));t.set(a,i)}else if("unsubscribe"===r){const e=t.get(a);e&&(e.cancel(),e.free(),t.delete(a))}else"cleanup"===r?(console.log("cleanup message received"),s?.free(),self.postMessage({type:"cleanup",data:{},requestId:a}),close()):self.postMessage({type:"error",error:"Unknown message type",requestId:a})}catch(e){console.error("ERROR",e),self.postMessage({type:"error",error:e,requestId:a})}};
1
+ globalThis.__vitest_browser_runner__={wrapDynamicImport:e=>e()};let e=null,s=null;const t=new Map;console.log("Worker - init"),self.onmessage=async o=>{const{type:r,payload:a,requestId:n}=o.data;try{if("init"===r)e=(await import("@fedimint/fedimint-client-wasm-bundler")).WasmClient,self.postMessage({type:"initialized",data:{},requestId:n});else if("open"===r){const{clientName:t}=a;s=await e.open(t)||null,self.postMessage({type:"open",data:{success:!!s},requestId:n})}else if("join"===r){const{inviteCode:t,clientName:o}=a;try{s=await e.join_federation(o,t),self.postMessage({type:"join",data:{success:!!s},requestId:n})}catch(e){self.postMessage({type:"error",error:e.message,requestId:n})}}else if("rpc"===r){const{module:e,method:o,body:r}=a;if(console.log("RPC received",e,o,r),!s)return void self.postMessage({type:"error",error:"WasmClient not initialized",requestId:n});const i=await s.rpc(e,o,JSON.stringify(r),(e=>{console.log("RPC response",n,e);const s=JSON.parse(e);if(self.postMessage({type:"rpcResponse",requestId:n,...s}),void 0!==s.end){const e=t.get(n);e?.free()}}));t.set(n,i)}else if("unsubscribe"===r){const e=t.get(n);e&&(e.cancel(),e.free(),t.delete(n))}else if("cleanup"===r)console.log("cleanup message received"),s?.free(),self.postMessage({type:"cleanup",data:{},requestId:n}),close();else if("parseInviteCode"===r){const{inviteCode:s}=a;try{const t=e.parse_invite_code(s),o=JSON.parse(t);self.postMessage({type:"parseInviteCode",data:o,requestId:n})}catch(e){self.postMessage({type:"error",error:`Failed to parse invite code: ${e.message}`,requestId:n})}}else if("parseBolt11Invoice"===r){const{invoiceStr:s}=a;try{const t=e.parse_bolt11_invoice(s),o=JSON.parse(t);self.postMessage({type:"parseBolt11Invoice",data:o,requestId:n})}catch(e){self.postMessage({type:"error",error:`Failed to parse invoice: ${e.message}`,requestId:n})}}else self.postMessage({type:"error",error:"Unknown message type",requestId:n})}catch(e){console.error("ERROR",e),self.postMessage({type:"error",error:e,requestId:n})}};
2
2
  //# sourceMappingURL=worker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker.js","sources":["../src/worker/worker.js"],"sourcesContent":["// Web Worker for fedimint-client-wasm to run in the browser\n\n// HACK: Fixes vitest browser runner\n// TODO: remove once https://github.com/vitest-dev/vitest/pull/6569 lands in a release\nglobalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() }\n\n// dynamically imported Constructor for WasmClient\nlet WasmClient = null\n// client instance\nlet client = null\n\nconst streamCancelMap = new Map()\n\nconst handleFree = (requestId) => {\n streamCancelMap.delete(requestId)\n}\n\nconsole.log('Worker - init')\n\nself.onmessage = async (event) => {\n const { type, payload, requestId } = event.data\n\n try {\n if (type === 'init') {\n WasmClient = (await import('@fedimint/fedimint-client-wasm-bundler'))\n .WasmClient\n self.postMessage({ type: 'initialized', data: {}, requestId })\n } else if (type === 'open') {\n const { clientName } = payload\n client = (await WasmClient.open(clientName)) || null\n self.postMessage({\n type: 'open',\n data: { success: !!client },\n requestId,\n })\n } else if (type === 'join') {\n const { inviteCode, clientName: joinClientName } = payload\n try {\n client = await WasmClient.join_federation(joinClientName, inviteCode)\n self.postMessage({\n type: 'join',\n data: { success: !!client },\n requestId,\n })\n } catch (e) {\n self.postMessage({ type: 'error', error: e.message, requestId })\n }\n } else if (type === 'rpc') {\n const { module, method, body } = payload\n console.log('RPC received', module, method, body)\n if (!client) {\n self.postMessage({\n type: 'error',\n error: 'WasmClient not initialized',\n requestId,\n })\n return\n }\n const rpcHandle = await client.rpc(\n module,\n method,\n JSON.stringify(body),\n (res) => {\n console.log('RPC response', requestId, res)\n const data = JSON.parse(res)\n self.postMessage({ type: 'rpcResponse', requestId, ...data })\n\n if (data.end !== undefined) {\n // Handle stream ending\n const handle = streamCancelMap.get(requestId)\n handle?.free()\n }\n },\n )\n streamCancelMap.set(requestId, rpcHandle)\n } else if (type === 'unsubscribe') {\n const rpcHandle = streamCancelMap.get(requestId)\n if (rpcHandle) {\n rpcHandle.cancel()\n rpcHandle.free()\n streamCancelMap.delete(requestId)\n }\n } else if (type === 'cleanup') {\n console.log('cleanup message received')\n client?.free()\n self.postMessage({\n type: 'cleanup',\n data: {},\n requestId,\n })\n close()\n } else {\n self.postMessage({\n type: 'error',\n error: 'Unknown message type',\n requestId,\n })\n }\n } catch (e) {\n console.error('ERROR', e)\n self.postMessage({ type: 'error', error: e, requestId })\n }\n}\n\n// self.postMessage({ type: 'init', data: {} })\n"],"names":["globalThis","__vitest_browser_runner__","wrapDynamicImport","foo","WasmClient","client","streamCancelMap","Map","console","log","self","onmessage","async","event","type","payload","requestId","data","import","postMessage","clientName","open","success","inviteCode","joinClientName","join_federation","e","error","message","module","method","body","rpcHandle","rpc","JSON","stringify","res","parse","undefined","end","handle","get","free","set","cancel","delete","close"],"mappings":"AAIAA,WAAWC,0BAA4B,CAAEC,kBAAoBC,GAAQA,KAGrE,IAAIC,EAAa,KAEbC,EAAS,KAEb,MAAMC,EAAkB,IAAIC,IAM5BC,QAAQC,IAAI,iBAEZC,KAAKC,UAAYC,MAAOC,IACtB,MAAMC,KAAEA,EAAIC,QAAEA,EAAOC,UAAEA,GAAcH,EAAMI,KAE3C,IACE,GAAa,SAATH,EACFV,SAAoBc,OAAO,2CACxBd,WACHM,KAAKS,YAAY,CAAEL,KAAM,cAAeG,KAAM,CAAA,EAAID,mBAC7C,GAAa,SAATF,EAAiB,CAC1B,MAAMM,WAAEA,GAAeL,EACvBV,QAAgBD,EAAWiB,KAAKD,IAAgB,KAChDV,KAAKS,YAAY,CACfL,KAAM,OACNG,KAAM,CAAEK,UAAWjB,GACnBW,aAER,MAAW,GAAa,SAATF,EAAiB,CAC1B,MAAMS,WAAEA,EAAYH,WAAYI,GAAmBT,EACnD,IACEV,QAAeD,EAAWqB,gBAAgBD,EAAgBD,GAC1Db,KAAKS,YAAY,CACfL,KAAM,OACNG,KAAM,CAAEK,UAAWjB,GACnBW,aAEH,CAAC,MAAOU,GACPhB,KAAKS,YAAY,CAAEL,KAAM,QAASa,MAAOD,EAAEE,QAASZ,aACrD,CACP,MAAW,GAAa,QAATF,EAAgB,CACzB,MAAMe,OAAEA,EAAMC,OAAEA,EAAMC,KAAEA,GAAShB,EAEjC,GADAP,QAAQC,IAAI,eAAgBoB,EAAQC,EAAQC,IACvC1B,EAMH,YALAK,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,6BACPX,cAIJ,MAAMgB,QAAkB3B,EAAO4B,IAC7BJ,EACAC,EACAI,KAAKC,UAAUJ,IACdK,IACC5B,QAAQC,IAAI,eAAgBO,EAAWoB,GACvC,MAAMnB,EAAOiB,KAAKG,MAAMD,GAGxB,GAFA1B,KAAKS,YAAY,CAAEL,KAAM,cAAeE,eAAcC,SAErCqB,IAAbrB,EAAKsB,IAAmB,CAE1B,MAAMC,EAASlC,EAAgBmC,IAAIzB,GACnCwB,GAAQE,MACT,KAGLpC,EAAgBqC,IAAI3B,EAAWgB,EACrC,MAAW,GAAa,gBAATlB,EAAwB,CACjC,MAAMkB,EAAY1B,EAAgBmC,IAAIzB,GAClCgB,IACFA,EAAUY,SACVZ,EAAUU,OACVpC,EAAgBuC,OAAO7B,GAE/B,KAAwB,YAATF,GACTN,QAAQC,IAAI,4BACZJ,GAAQqC,OACRhC,KAAKS,YAAY,CACfL,KAAM,UACNG,KAAM,CAAE,EACRD,cAEF8B,SAEApC,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,uBACPX,aAGL,CAAC,MAAOU,GACPlB,QAAQmB,MAAM,QAASD,GACvBhB,KAAKS,YAAY,CAAEL,KAAM,QAASa,MAAOD,EAAGV,aAC7C"}
1
+ {"version":3,"file":"worker.js","sources":["../src/worker/worker.js"],"sourcesContent":["// Web Worker for fedimint-client-wasm to run in the browser\n\n// HACK: Fixes vitest browser runner\n// TODO: remove once https://github.com/vitest-dev/vitest/pull/6569 lands in a release\nglobalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() }\n\n// dynamically imported Constructor for WasmClient\nlet WasmClient = null\n// client instance\nlet client = null\n\nconst streamCancelMap = new Map()\n\nconst handleFree = (requestId) => {\n streamCancelMap.delete(requestId)\n}\n\nconsole.log('Worker - init')\n\nself.onmessage = async (event) => {\n const { type, payload, requestId } = event.data\n\n try {\n if (type === 'init') {\n WasmClient = (await import('@fedimint/fedimint-client-wasm-bundler'))\n .WasmClient\n self.postMessage({ type: 'initialized', data: {}, requestId })\n } else if (type === 'open') {\n const { clientName } = payload\n client = (await WasmClient.open(clientName)) || null\n self.postMessage({\n type: 'open',\n data: { success: !!client },\n requestId,\n })\n } else if (type === 'join') {\n const { inviteCode, clientName: joinClientName } = payload\n try {\n client = await WasmClient.join_federation(joinClientName, inviteCode)\n self.postMessage({\n type: 'join',\n data: { success: !!client },\n requestId,\n })\n } catch (e) {\n self.postMessage({ type: 'error', error: e.message, requestId })\n }\n } else if (type === 'rpc') {\n const { module, method, body } = payload\n console.log('RPC received', module, method, body)\n if (!client) {\n self.postMessage({\n type: 'error',\n error: 'WasmClient not initialized',\n requestId,\n })\n return\n }\n const rpcHandle = await client.rpc(\n module,\n method,\n JSON.stringify(body),\n (res) => {\n console.log('RPC response', requestId, res)\n const data = JSON.parse(res)\n self.postMessage({ type: 'rpcResponse', requestId, ...data })\n\n if (data.end !== undefined) {\n // Handle stream ending\n const handle = streamCancelMap.get(requestId)\n handle?.free()\n }\n },\n )\n streamCancelMap.set(requestId, rpcHandle)\n } else if (type === 'unsubscribe') {\n const rpcHandle = streamCancelMap.get(requestId)\n if (rpcHandle) {\n rpcHandle.cancel()\n rpcHandle.free()\n streamCancelMap.delete(requestId)\n }\n } else if (type === 'cleanup') {\n console.log('cleanup message received')\n client?.free()\n self.postMessage({\n type: 'cleanup',\n data: {},\n requestId,\n })\n close()\n } else if (type === 'parseInviteCode') {\n const { inviteCode } = payload\n try {\n const res = WasmClient.parse_invite_code(inviteCode)\n const parsedRes = JSON.parse(res)\n self.postMessage({\n type: 'parseInviteCode',\n data: parsedRes,\n requestId,\n })\n } catch (error) {\n self.postMessage({\n type: 'error',\n error: `Failed to parse invite code: ${error.message}`,\n requestId,\n })\n }\n } else if (type === 'parseBolt11Invoice') {\n const { invoiceStr } = payload\n try {\n const res = WasmClient.parse_bolt11_invoice(invoiceStr)\n const parsedRes = JSON.parse(res)\n self.postMessage({\n type: 'parseBolt11Invoice',\n data: parsedRes,\n requestId,\n })\n } catch (error) {\n self.postMessage({\n type: 'error',\n error: `Failed to parse invoice: ${error.message}`,\n requestId,\n })\n }\n } else {\n self.postMessage({\n type: 'error',\n error: 'Unknown message type',\n requestId,\n })\n }\n } catch (e) {\n console.error('ERROR', e)\n self.postMessage({ type: 'error', error: e, requestId })\n }\n}\n\n// self.postMessage({ type: 'init', data: {} })\n"],"names":["globalThis","__vitest_browser_runner__","wrapDynamicImport","foo","WasmClient","client","streamCancelMap","Map","console","log","self","onmessage","async","event","type","payload","requestId","data","import","postMessage","clientName","open","success","inviteCode","joinClientName","join_federation","e","error","message","module","method","body","rpcHandle","rpc","JSON","stringify","res","parse","undefined","end","handle","get","free","set","cancel","delete","close","parse_invite_code","parsedRes","invoiceStr","parse_bolt11_invoice"],"mappings":"AAIAA,WAAWC,0BAA4B,CAAEC,kBAAoBC,GAAQA,KAGrE,IAAIC,EAAa,KAEbC,EAAS,KAEb,MAAMC,EAAkB,IAAIC,IAM5BC,QAAQC,IAAI,iBAEZC,KAAKC,UAAYC,MAAOC,IACtB,MAAMC,KAAEA,EAAIC,QAAEA,EAAOC,UAAEA,GAAcH,EAAMI,KAE3C,IACE,GAAa,SAATH,EACFV,SAAoBc,OAAO,2CACxBd,WACHM,KAAKS,YAAY,CAAEL,KAAM,cAAeG,KAAM,CAAE,EAAED,mBAC7C,GAAa,SAATF,EAAiB,CAC1B,MAA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C,MAAMS,WAAEA,GAAeR,EACvB,IACE,MAAMqB,EAAMhC,EAAW2C,kBAAkBxB,GACnCyB,EAAYd,KAAKG,MAAMD,GAC7B1B,KAAKS,YAAY,CACfL,KAAM,kBACNG,KAAM+B,EACNhC,aAEH,CAAC,MAAOW,GACPjB,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,gCAAgCA,EAAMC,UAC7CZ,aAEV,CACA,MAAW,GAAa,uBAATF,EAA+B,CACxC,MAAMmC,WAAEA,GAAelC,EACvB,IACE,MAAMqB,EAAMhC,EAAW8C,qBAAqBD,GACtCD,EAAYd,KAAKG,MAAMD,GAC7B1B,KAAKS,YAAY,CACfL,KAAM,qBACNG,KAAM+B,EACNhC,aAEH,CAAC,MAAOW,GACPjB,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,4BAA4BA,EAAMC,UACzCZ,aAEV,CACA,MACMN,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,uBACPX,aAGL,CAAC,MAAOU,GACPlB,QAAQmB,MAAM,QAASD,GACvBhB,KAAKS,YAAY,CAAEL,KAAM,QAASa,MAAOD,EAAGV,aAChD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fedimint/core-web",
3
3
  "description": "Library for building web apps with a fedimint client",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/fedimint/fedimint-web-sdk.git",
@@ -19,19 +19,19 @@
19
19
  "main": "./dist/index.js",
20
20
  "types": "./dist/index.d.ts",
21
21
  "dependencies": {
22
- "@fedimint/fedimint-client-wasm-bundler": "0.0.2"
22
+ "@fedimint/fedimint-client-wasm-bundler": "0.0.3"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@rollup/plugin-terser": "^0.4.4",
26
26
  "@rollup/plugin-typescript": "^11.1.6",
27
- "@types/node": "^20.16.10",
27
+ "@types/node": "^20.17.49",
28
28
  "@types/secp256k1": "^4.0.6",
29
- "rollup": "^4.24.0",
30
- "rollup-plugin-dts": "^6.1.1",
29
+ "rollup": "^4.41.0",
30
+ "rollup-plugin-dts": "^6.2.1",
31
31
  "rollup-plugin-typescript2": "^0.36.0",
32
- "secp256k1": "^5.0.0",
33
- "tslib": "^2.7.0",
34
- "typescript": "^5.6.2"
32
+ "secp256k1": "^5.0.1",
33
+ "tslib": "^2.8.1",
34
+ "typescript": "^5.8.3"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "rollup --config",
@@ -7,6 +7,7 @@ import {
7
7
  RecoveryService,
8
8
  } from './services'
9
9
  import { logger, type LogLevel } from './utils/logger'
10
+ import { JSONValue } from './types'
10
11
 
11
12
  const DEFAULT_CLIENT_NAME = 'fm-default' as const
12
13
 
@@ -143,4 +144,61 @@ export class FedimintWallet {
143
144
  logger.setLevel(level)
144
145
  logger.info(`Log level set to ${level}.`)
145
146
  }
147
+
148
+ /**
149
+ * Parses a federation invite code and retrieves its details.
150
+ *
151
+ * This method sends the provided invite code to the WorkerClient for parsing.
152
+ * The response includes the federation_id and url.
153
+ *
154
+ * @param {string} inviteCode - The invite code to be parsed.
155
+ * @returns {Promise<{ federation_id: string, url: string}>}
156
+ * A promise that resolves to an object containing:
157
+ * - `federation_id`: The id of the feder.
158
+ * - `url`: One of the apipoints to connect to the federation
159
+ *
160
+ * @throws {Error} If the WorkerClient encounters an issue during the parsing process.
161
+ *
162
+ * @example
163
+ * const inviteCode = "example-invite-code";
164
+ * const parsedCode = await wallet.parseInviteCode(inviteCode);
165
+ * console.log(parsedCode.federation_id, parsedCode.url);
166
+ */
167
+ async parseInviteCode(inviteCode: string) {
168
+ const response = await this._client.sendSingleMessage<{
169
+ type: string
170
+ data: JSONValue
171
+ requestId: number
172
+ }>('parseInviteCode', { inviteCode })
173
+ return response
174
+ }
175
+
176
+ /**
177
+ * Parses a BOLT11 Lightning invoice and retrieves its details.
178
+ *
179
+ * This method sends the provided invoice string to the WorkerClient for parsing.
180
+ * The response includes details such as the amount, expiry, and memo.
181
+ *
182
+ * @param {string} invoiceStr - The BOLT11 invoice string to be parsed.
183
+ * @returns {Promise<{ amount: string, expiry: number, memo: string }>}
184
+ * A promise that resolves to an object containing:
185
+ * - `amount`: The amount specified in the invoice.
186
+ * - `expiry`: The expiry time of the invoice in seconds.
187
+ * - `memo`: A description or memo attached to the invoice.
188
+ *
189
+ * @throws {Error} If the WorkerClient encounters an issue during the parsing process.
190
+ *
191
+ * @example
192
+ * const invoiceStr = "lnbc1...";
193
+ * const parsedInvoice = await wallet.parseBolt11Invoice(invoiceStr);
194
+ * console.log(parsedInvoice.amount, parsedInvoice.expiry, parsedInvoice.memo);
195
+ */
196
+ async parseBolt11Invoice(invoiceStr: string) {
197
+ const response = await this._client.sendSingleMessage<{
198
+ type: string
199
+ data: JSONValue
200
+ requestId: number
201
+ }>('parseBolt11Invoice', { invoiceStr })
202
+ return response
203
+ }
146
204
  }
@@ -8,43 +8,22 @@ import { WorkerClient } from '../worker'
8
8
  export class BalanceService {
9
9
  constructor(private client: WorkerClient) {}
10
10
 
11
- /**
12
- * Get the balance of the current wallet in milli-satoshis (MSats)
13
- *
14
- * @example
15
- * ```ts
16
- * const balance = await wallet.balance.getBalance()
17
- * ```
18
- */
19
- async getBalance(): Promise<number> {
20
- return await this.client.rpcSingle('', 'get_balance', {})
11
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
12
+ async getBalance() {
13
+ return await this.client.rpcSingle<number>('', 'get_balance', {})
21
14
  }
22
15
 
23
- /**
24
- * Subscribe to the balance of the current wallet in milli-satoshis (MSats)
25
- *
26
- * @example
27
- * ```ts
28
- * const unsubscribe = wallet.balance.subscribeBalance((balance) => {
29
- * console.log(balance)
30
- * })
31
- *
32
- * // ...Cleanup Later
33
- * unsubscribe()
34
- * ```
35
- */
16
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
36
17
  subscribeBalance(
37
18
  onSuccess: (balanceMsats: number) => void = () => {},
38
19
  onError: (error: string) => void = () => {},
39
20
  ) {
40
- const unsubscribe = this.client.rpcStream<string>(
21
+ return this.client.rpcStream<string>(
41
22
  '',
42
23
  'subscribe_balance_changes',
43
24
  {},
44
25
  (res) => onSuccess(parseInt(res)),
45
26
  onError,
46
27
  )
47
-
48
- return unsubscribe
49
28
  }
50
29
  }
@@ -4,19 +4,21 @@ import { WorkerClient } from '../worker'
4
4
  export class FederationService {
5
5
  constructor(private client: WorkerClient) {}
6
6
 
7
- async getConfig(): Promise<JSONValue> {
7
+ async getConfig() {
8
8
  return await this.client.rpcSingle('', 'get_config', {})
9
9
  }
10
10
 
11
- async getFederationId(): Promise<string> {
12
- return await this.client.rpcSingle('', 'get_federation_id', {})
11
+ async getFederationId() {
12
+ return await this.client.rpcSingle<string>('', 'get_federation_id', {})
13
13
  }
14
14
 
15
- async getInviteCode(peer: number): Promise<string | null> {
16
- return await this.client.rpcSingle('', 'get_invite_code', { peer })
15
+ async getInviteCode(peer: number = 0) {
16
+ return await this.client.rpcSingle<string | null>('', 'get_invite_code', {
17
+ peer,
18
+ })
17
19
  }
18
20
 
19
- async listOperations(): Promise<JSONValue[]> {
20
- return await this.client.rpcSingle('', 'list_operations', {})
21
+ async listOperations() {
22
+ return await this.client.rpcSingle<JSONValue[]>('', 'list_operations', {})
21
23
  }
22
24
  }
@@ -3,7 +3,6 @@ import type {
3
3
  CreateBolt11Response,
4
4
  GatewayInfo,
5
5
  JSONObject,
6
- JSONValue,
7
6
  LightningGateway,
8
7
  LnPayState,
9
8
  LnReceiveState,
@@ -13,21 +12,26 @@ import type {
13
12
  export class LightningService {
14
13
  constructor(private client: WorkerClient) {}
15
14
 
15
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
16
16
  async createInvoice(
17
17
  amountMsats: number,
18
18
  description: string,
19
19
  expiryTime?: number, // in seconds
20
20
  gatewayInfo?: GatewayInfo,
21
21
  extraMeta?: JSONObject,
22
- ): Promise<CreateBolt11Response> {
22
+ ) {
23
23
  const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
24
- return await this.client.rpcSingle('ln', 'create_bolt11_invoice', {
25
- amount: amountMsats,
26
- description,
27
- expiry_time: expiryTime ?? null,
28
- extra_meta: extraMeta ?? {},
29
- gateway,
30
- })
24
+ return await this.client.rpcSingle<CreateBolt11Response>(
25
+ 'ln',
26
+ 'create_bolt11_invoice',
27
+ {
28
+ amount: amountMsats,
29
+ description,
30
+ expiry_time: expiryTime ?? null,
31
+ extra_meta: extraMeta ?? {},
32
+ gateway,
33
+ },
34
+ )
31
35
  }
32
36
 
33
37
  async createInvoiceTweaked(
@@ -38,9 +42,9 @@ export class LightningService {
38
42
  expiryTime?: number, // in seconds
39
43
  gatewayInfo?: GatewayInfo,
40
44
  extraMeta?: JSONObject,
41
- ): Promise<CreateBolt11Response> {
45
+ ) {
42
46
  const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
43
- return await this.client.rpcSingle(
47
+ return await this.client.rpcSingle<CreateBolt11Response>(
44
48
  'ln',
45
49
  'create_bolt11_invoice_for_user_tweaked',
46
50
  {
@@ -60,52 +64,63 @@ export class LightningService {
60
64
  tweakKey: string,
61
65
  indices: number[],
62
66
  extraMeta?: JSONObject,
63
- ): Promise<string[]> {
64
- return await this.client.rpcSingle('ln', 'scan_receive_for_user_tweaked', {
65
- user_key: tweakKey,
66
- indices,
67
- extra_meta: extraMeta ?? {},
68
- })
67
+ ) {
68
+ return await this.client.rpcSingle<string[]>(
69
+ 'ln',
70
+ 'scan_receive_for_user_tweaked',
71
+ {
72
+ user_key: tweakKey,
73
+ indices,
74
+ extra_meta: extraMeta ?? {},
75
+ },
76
+ )
69
77
  }
70
78
 
71
- private async _getDefaultGatewayInfo(): Promise<GatewayInfo> {
79
+ private async _getDefaultGatewayInfo() {
72
80
  await this.updateGatewayCache()
73
81
  const gateways = await this.listGateways()
74
82
  return gateways[0]?.info
75
83
  }
76
84
 
85
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
77
86
  async payInvoice(
78
87
  invoice: string,
79
88
  gatewayInfo?: GatewayInfo,
80
89
  extraMeta?: JSONObject,
81
- ): Promise<OutgoingLightningPayment> {
90
+ ) {
82
91
  const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
83
- return await this.client.rpcSingle('ln', 'pay_bolt11_invoice', {
84
- maybe_gateway: gateway,
85
- invoice,
86
- extra_meta: extraMeta ?? {},
87
- })
92
+ return await this.client.rpcSingle<OutgoingLightningPayment>(
93
+ 'ln',
94
+ 'pay_bolt11_invoice',
95
+ {
96
+ maybe_gateway: gateway,
97
+ invoice,
98
+ extra_meta: extraMeta ?? {},
99
+ },
100
+ )
88
101
  }
89
102
 
103
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoicesync-invoice-string */
90
104
  async payInvoiceSync(
91
105
  invoice: string,
92
106
  timeoutMs: number = 10000,
93
107
  gatewayInfo?: GatewayInfo,
94
108
  extraMeta?: JSONObject,
95
- ): Promise<
96
- | { success: false }
97
- | {
98
- success: true
99
- data: { feeMsats: number; preimage: string }
100
- }
101
- > {
102
- return new Promise(async (resolve, reject) => {
109
+ ) {
110
+ return new Promise<
111
+ | { success: false; error?: string }
112
+ | {
113
+ success: true
114
+ data: { feeMsats: number; preimage: string }
115
+ }
116
+ >(async (resolve, reject) => {
103
117
  const { contract_id, fee } = await this.payInvoice(
104
118
  invoice,
105
119
  gatewayInfo,
106
120
  extraMeta,
107
121
  )
108
122
 
123
+ // TODO: handle error handling for other subscription statuses
109
124
  const unsubscribe = this.subscribeLnPay(contract_id, (res) => {
110
125
  if (typeof res !== 'string' && 'success' in res) {
111
126
  clearTimeout(timeoutId)
@@ -114,12 +129,14 @@ export class LightningService {
114
129
  success: true,
115
130
  data: { feeMsats: fee, preimage: res.success.preimage },
116
131
  })
132
+ } else if (typeof res !== 'string' && 'unexpected_error' in res) {
133
+ reject(new Error(res.unexpected_error.error_message))
117
134
  }
118
135
  })
119
136
 
120
137
  const timeoutId = setTimeout(() => {
121
138
  unsubscribe()
122
- reject(new Error('Timeout waiting for pay'))
139
+ resolve({ success: false, error: 'Payment timeout' })
123
140
  }, timeoutMs)
124
141
  })
125
142
  }
@@ -130,46 +147,41 @@ export class LightningService {
130
147
  onSuccess: (state: LnReceiveState) => void = () => {},
131
148
  onError: (error: string) => void = () => {},
132
149
  ) {
133
- const unsubscribe = this.client.rpcStream(
150
+ return this.client.rpcStream(
134
151
  'ln',
135
152
  'subscribe_ln_claim',
136
153
  { operation_id: operationId },
137
154
  onSuccess,
138
155
  onError,
139
156
  )
140
-
141
- return unsubscribe
142
157
  }
143
158
 
144
159
  // TODO: Document (for external payments only)
145
160
  // TODO: Make this work for BOTH internal and external payments
161
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
146
162
  subscribeLnPay(
147
163
  operationId: string,
148
164
  onSuccess: (state: LnPayState) => void = () => {},
149
165
  onError: (error: string) => void = () => {},
150
166
  ) {
151
- const unsubscribe = this.client.rpcStream(
167
+ return this.client.rpcStream(
152
168
  'ln',
153
169
  'subscribe_ln_pay',
154
170
  { operation_id: operationId },
155
171
  onSuccess,
156
172
  onError,
157
173
  )
158
-
159
- return unsubscribe
160
174
  }
161
175
 
162
- async waitForPay(operationId: string): Promise<
163
- | { success: false }
164
- | {
165
- success: true
166
- data: { preimage: string }
167
- }
168
- > {
169
- return new Promise((resolve, reject) => {
176
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
177
+ async waitForPay(operationId: string) {
178
+ return new Promise<
179
+ | { success: false; error?: string }
180
+ | { success: true; data: { preimage: string } }
181
+ >((resolve, reject) => {
170
182
  let unsubscribe: () => void
171
183
  const timeoutId = setTimeout(() => {
172
- reject(new Error('Timeout waiting for receive'))
184
+ resolve({ success: false, error: 'Waiting for receive timeout' })
173
185
  }, 15000)
174
186
 
175
187
  unsubscribe = this.subscribeLnPay(
@@ -193,28 +205,24 @@ export class LightningService {
193
205
  })
194
206
  }
195
207
 
196
- // TODO: Document
208
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
197
209
  subscribeLnReceive(
198
210
  operationId: string,
199
211
  onSuccess: (state: LnReceiveState) => void = () => {},
200
212
  onError: (error: string) => void = () => {},
201
213
  ) {
202
- const unsubscribe = this.client.rpcStream(
214
+ return this.client.rpcStream(
203
215
  'ln',
204
216
  'subscribe_ln_receive',
205
217
  { operation_id: operationId },
206
218
  onSuccess,
207
219
  onError,
208
220
  )
209
-
210
- return unsubscribe
211
221
  }
212
222
 
213
- async waitForReceive(
214
- operationId: string,
215
- timeoutMs: number = 15000,
216
- ): Promise<LnReceiveState> {
217
- return new Promise((resolve, reject) => {
223
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
224
+ async waitForReceive(operationId: string, timeoutMs: number = 15000) {
225
+ return new Promise<LnReceiveState>((resolve, reject) => {
218
226
  let unsubscribe: () => void
219
227
  const timeoutId = setTimeout(() => {
220
228
  reject(new Error('Timeout waiting for receive'))
@@ -241,18 +249,26 @@ export class LightningService {
241
249
  async getGateway(
242
250
  gatewayId: string | null = null,
243
251
  forceInternal: boolean = false,
244
- ): Promise<LightningGateway | null> {
245
- return await this.client.rpcSingle('ln', 'get_gateway', {
246
- gateway_id: gatewayId,
247
- force_internal: forceInternal,
248
- })
252
+ ) {
253
+ return await this.client.rpcSingle<LightningGateway | null>(
254
+ 'ln',
255
+ 'get_gateway',
256
+ {
257
+ gateway_id: gatewayId,
258
+ force_internal: forceInternal,
259
+ },
260
+ )
249
261
  }
250
262
 
251
- async listGateways(): Promise<LightningGateway[]> {
252
- return await this.client.rpcSingle('ln', 'list_gateways', {})
263
+ async listGateways() {
264
+ return await this.client.rpcSingle<LightningGateway[]>(
265
+ 'ln',
266
+ 'list_gateways',
267
+ {},
268
+ )
253
269
  }
254
270
 
255
- async updateGatewayCache(): Promise<JSONValue> {
271
+ async updateGatewayCache() {
256
272
  return await this.client.rpcSingle('ln', 'update_gateway_cache', {})
257
273
  }
258
274
  }