@fedimint/core-web 0.0.9 → 0.0.10

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.
@@ -1,4 +1,3 @@
1
- import type { MSats } from '../types';
2
1
  import { WorkerClient } from '../worker';
3
2
  /**
4
3
  * Balance Service
@@ -16,7 +15,7 @@ export declare class BalanceService {
16
15
  * const balance = await wallet.balance.getBalance()
17
16
  * ```
18
17
  */
19
- getBalance(): Promise<MSats>;
18
+ getBalance(): Promise<number>;
20
19
  /**
21
20
  * Subscribe to the balance of the current wallet in milli-satoshis (MSats)
22
21
  *
@@ -30,6 +29,6 @@ export declare class BalanceService {
30
29
  * unsubscribe()
31
30
  * ```
32
31
  */
33
- subscribeBalance(onSuccess?: (balance: MSats) => void, onError?: (error: string) => void): import("../types").CancelFunction;
32
+ subscribeBalance(onSuccess?: (balanceMsats: number) => void, onError?: (error: string) => void): import("..").CancelFunction;
34
33
  }
35
34
  //# sourceMappingURL=BalanceService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BalanceService.d.ts","sourceRoot":"","sources":["../../../src/services/BalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;;GAIG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAExC;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC;IAIlC;;;;;;;;;;;;OAYG;IACH,gBAAgB,CACd,SAAS,GAAE,CAAC,OAAO,EAAE,KAAK,KAAK,IAAe,EAC9C,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;CAY9C"}
1
+ {"version":3,"file":"BalanceService.d.ts","sourceRoot":"","sources":["../../../src/services/BalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;;GAIG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAExC;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;;;;;;;;;;OAYG;IACH,gBAAgB,CACd,SAAS,GAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAe,EACpD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;CAY9C"}
@@ -1,19 +1,36 @@
1
1
  import { WorkerClient } from '../worker';
2
- import type { CreateBolt11Response, GatewayInfo, JSONObject, JSONValue, LightningGateway, LnPayState, LnReceiveState, MSats, OutgoingLightningPayment } from '../types';
2
+ import type { CreateBolt11Response, GatewayInfo, JSONObject, JSONValue, LightningGateway, LnPayState, LnReceiveState, OutgoingLightningPayment } from '../types';
3
3
  export declare class LightningService {
4
4
  private client;
5
5
  constructor(client: WorkerClient);
6
- createInvoice(amount: MSats, description: string, expiryTime?: number, // in seconds
6
+ createInvoice(amountMsats: number, description: string, expiryTime?: number, // in seconds
7
7
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
8
- createInvoiceTweaked(amount: MSats, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
8
+ createInvoiceTweaked(amountMsats: number, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
9
9
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
10
10
  scanReceivesForTweaks(tweakKey: string, indices: number[], extraMeta?: JSONObject): Promise<string[]>;
11
11
  private _getDefaultGatewayInfo;
12
12
  payInvoice(invoice: string, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
13
+ payInvoiceSync(invoice: string, timeoutMs?: number, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<{
14
+ success: false;
15
+ } | {
16
+ success: true;
17
+ data: {
18
+ feeMsats: number;
19
+ preimage: string;
20
+ };
21
+ }>;
13
22
  subscribeLnClaim(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
14
23
  subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
24
+ waitForPay(operationId: string): Promise<{
25
+ success: false;
26
+ } | {
27
+ success: true;
28
+ data: {
29
+ preimage: string;
30
+ };
31
+ }>;
15
32
  subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
16
- waitForReceive(operationId: string): Promise<LnReceiveState>;
33
+ waitForReceive(operationId: string, timeoutMs?: number): Promise<LnReceiveState>;
17
34
  getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
18
35
  listGateways(): Promise<LightningGateway[]>;
19
36
  updateGatewayCache(): Promise<JSONValue>;
@@ -1 +1 @@
1
- {"version":3,"file":"LightningService.d.ts","sourceRoot":"","sources":["../../../src/services/LightningService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,KAAK,EACL,wBAAwB,EACzB,MAAM,UAAU,CAAA;AAEjB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,aAAa,CACjB,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,aAAa;IAClC,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU,GACrB,OAAO,CAAC,oBAAoB,CAAC;IAW1B,oBAAoB,CACxB,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,E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M,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAA;KAC7C,CACJ;IA2BD,gBAAgB,CACd,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAe,EACrD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAe7C,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAe,EACjD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAavC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAC1C;QAAE,OAAO,EAAE,KAAK,CAAA;KAAE,GAClB;QACE,OAAO,EAAE,IAAI,CAAA;QACb,IAAI,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAA;KAC3B,CACJ;IA6BD,kBAAkB,CAChB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAe,EACrD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAavC,cAAc,CAClB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,MAAc,GACxB,OAAO,CAAC,cAAc,CAAC;IAyBpB,UAAU,CACd,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,aAAa,GAAE,OAAe,GAC7B,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAO7B,YAAY,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI3C,kBAAkB,IAAI,OAAO,CAAC,SAAS,CAAC;CAG/C"}
@@ -6,7 +6,7 @@ export declare class MintService {
6
6
  redeemEcash(notes: string): Promise<void>;
7
7
  reissueExternalNotes(oobNotes: string, extraMeta?: JSONObject): Promise<string>;
8
8
  subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): import("../types").CancelFunction;
9
- spendNotes(minAmount: MSats, tryCancelAfter?: number | Duration, // defaults to 1 day
9
+ spendNotes(amountMsats: number, tryCancelAfter?: number | Duration, // defaults to 1 day
10
10
  includeInvite?: boolean, extraMeta?: JSONValue): Promise<MintSpendNotesResponse>;
11
11
  parseNotes(oobNotes: string): Promise<MSats>;
12
12
  tryCancelSpendNotes(operationId: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"MintService.d.ts","sourceRoot":"","sources":["../../../src/services/MintService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,KAAK,EAEN,MAAM,UAAU,CAAA;AAEjB,qBAAa,WAAW;IACV,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,oBAAoB,CACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,UAAe,GACzB,OAAO,CAAC,MAAM,CAAC;IAOlB,6BAA6B,CAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAe,EAChD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAavC,UAAU,CACd,SAAS,EAAE,KAAK,EAIhB,cAAc,GAAE,MAAM,GAAG,QAAoB,EAAE,oBAAoB;IACnE,aAAa,GAAE,OAAe,EAC9B,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,sBAAsB,CAAC;IAyB5B,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAM5C,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7D,mBAAmB,CACjB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,SAAS,KAA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MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAKnE"}
package/dist/index.d.ts CHANGED
@@ -156,7 +156,7 @@ declare class MintService {
156
156
  redeemEcash(notes: string): Promise<void>;
157
157
  reissueExternalNotes(oobNotes: string, extraMeta?: JSONObject): Promise<string>;
158
158
  subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): CancelFunction;
159
- spendNotes(minAmount: MSats, tryCancelAfter?: number | Duration, // defaults to 1 day
159
+ spendNotes(amountMsats: number, tryCancelAfter?: number | Duration, // defaults to 1 day
160
160
  includeInvite?: boolean, extraMeta?: JSONValue): Promise<MintSpendNotesResponse>;
161
161
  parseNotes(oobNotes: string): Promise<MSats>;
162
162
  tryCancelSpendNotes(operationId: string): Promise<void>;
@@ -180,7 +180,7 @@ declare class BalanceService {
180
180
  * const balance = await wallet.balance.getBalance()
181
181
  * ```
182
182
  */
183
- getBalance(): Promise<MSats>;
183
+ getBalance(): Promise<number>;
184
184
  /**
185
185
  * Subscribe to the balance of the current wallet in milli-satoshis (MSats)
186
186
  *
@@ -194,23 +194,40 @@ declare class BalanceService {
194
194
  * unsubscribe()
195
195
  * ```
196
196
  */
197
- subscribeBalance(onSuccess?: (balance: MSats) => void, onError?: (error: string) => void): CancelFunction;
197
+ subscribeBalance(onSuccess?: (balanceMsats: number) => void, onError?: (error: string) => void): CancelFunction;
198
198
  }
199
199
 
200
200
  declare class LightningService {
201
201
  private client;
202
202
  constructor(client: WorkerClient);
203
- createInvoice(amount: MSats, description: string, expiryTime?: number, // in seconds
203
+ createInvoice(amountMsats: number, description: string, expiryTime?: number, // in seconds
204
204
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
205
- createInvoiceTweaked(amount: MSats, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
205
+ createInvoiceTweaked(amountMsats: number, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
206
206
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
207
207
  scanReceivesForTweaks(tweakKey: string, indices: number[], extraMeta?: JSONObject): Promise<string[]>;
208
208
  private _getDefaultGatewayInfo;
209
209
  payInvoice(invoice: string, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
210
+ payInvoiceSync(invoice: string, timeoutMs?: number, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<{
211
+ success: false;
212
+ } | {
213
+ success: true;
214
+ data: {
215
+ feeMsats: number;
216
+ preimage: string;
217
+ };
218
+ }>;
210
219
  subscribeLnClaim(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
211
220
  subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): CancelFunction;
221
+ waitForPay(operationId: string): Promise<{
222
+ success: false;
223
+ } | {
224
+ success: true;
225
+ data: {
226
+ preimage: string;
227
+ };
228
+ }>;
212
229
  subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
213
- waitForReceive(operationId: string): Promise<LnReceiveState>;
230
+ waitForReceive(operationId: string, timeoutMs?: number): Promise<LnReceiveState>;
214
231
  getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
215
232
  listGateways(): Promise<LightningGateway[]>;
216
233
  updateGatewayCache(): Promise<JSONValue>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- const e=["debug","info","warn","error","none"];const t=new class{constructor(e="none"){this.level=e}setLevel(e){this.level=e}coerceLevel(t){return e.includes(t.toLocaleUpperCase())?t.toLocaleUpperCase():"info"}log(e,t,...i){const n=this.coerceLevel(e);if(!this.shouldLog(n))return;(0,console[n])(`[${n.toUpperCase()}] ${t}`,...i)}debug(e,...t){this.log("debug",e,...t)}info(e,...t){this.log("info",e,...t)}warn(e,...t){this.log("warn",e,...t)}error(e,...t){this.log("error",e,...t)}shouldLog(e){const t=["debug","info","warn","error","none"],i=t.indexOf(e);return t.indexOf(this.level)<=i&&"none"!==this.level&&"none"!==e}};class i{constructor(){this.requestCounter=0,this.requestCallbacks=new Map,this.initPromise=void 0,this.worker=new Worker(new URL("./worker.js",import.meta.url),{type:"module"}),this.worker.onmessage=this.handleWorkerMessage.bind(this),this.worker.onerror=this.handleWorkerError.bind(this),t.info("WorkerClient instantiated"),t.debug("WorkerClient",this.worker)}initialize(){return this.initPromise||(this.initPromise=this.sendSingleMessage("init")),this.initPromise}handleWorkerLogs(e){const{type:i,level:n,message:s,...r}=e.data;t.log(n,s,...r)}handleWorkerError(e){t.error("Worker error",e)}handleWorkerMessage(e){const{type:i,requestId:n,...s}=e.data;"log"===i&&this.handleWorkerLogs(e.data);const r=this.requestCallbacks.get(n);t.debug("WorkerClient - handleWorkerMessage",e.data),r?r(s):t.warn("WorkerClient - handleWorkerMessage - received message with no callback",n,e.data)}sendSingleMessage(e,i){return new Promise(((n,s)=>{const r=++this.requestCounter;t.debug("WorkerClient - sendSingleMessage",r,e,i),this.requestCallbacks.set(r,(e=>{this.requestCallbacks.delete(r),t.debug("WorkerClient - sendSingleMessage - response",r,e),e.data?n(e.data):e.error?s(e.error):t.warn("WorkerClient - sendSingleMessage - malformed response",r,e)})),this.worker.postMessage({type:e,payload:i,requestId:r})}))}rpcStream(e,i,n,s,r,a=()=>{}){const o=++this.requestCounter;t.debug("WorkerClient - rpcStream",o,e,i,n);let c=()=>{},l=!1;const u=new Promise((e=>{c=()=>{l?e():setTimeout((()=>c()),0)}}));return this._rpcStreamInner(o,e,i,n,s,r,a,u).then((()=>{l=!0})),c}async _rpcStreamInner(e,t,i,n,s,r,a=()=>{},o){this.requestCallbacks.set(e,(t=>{void 0!==t.error?r(t.error):void 0!==t.data?s(t.data):void 0!==t.end&&(this.requestCallbacks.delete(e),a())})),this.worker.postMessage({type:"rpc",payload:{module:t,method:i,body:n},requestId:e}),o.then((()=>{this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}rpcSingle(e,i,n){return t.debug("WorkerClient - rpcSingle",e,i,n),new Promise(((t,s)=>{this.rpcStream(e,i,n,t,s)}))}async cleanup(){await this.sendSingleMessage("cleanup"),this.requestCounter=0,this.initPromise=void 0,this.requestCallbacks.clear()}_getRequestCounter(){return this.requestCounter}_getRequestCallbackMap(){return this.requestCallbacks}}class n{constructor(e){this.client=e}async redeemEcash(e){await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:null})}async reissueExternalNotes(e,t={}){return await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:t})}subscribeReissueExternalNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_reissue_external_notes",{operation_id:e},t,i)}async spendNotes(e,t=86400,i=!1,n={}){const s="number"==typeof t?{nanos:0,secs:t}:t,r=await this.client.rpcSingle("mint","spend_notes",{min_amount:e,try_cancel_after:s,include_invite:i,extra_meta:n});return{notes:r[1],operation_id:r[0]}}async parseNotes(e){return await this.client.rpcSingle("mint","validate_notes",{oob_notes:e})}async tryCancelSpendNotes(e){await this.client.rpcSingle("mint","try_cancel_spend_notes",{operation_id:e})}subscribeSpendNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_spend_notes",{operation_id:e},(e=>t(e)),i)}async awaitSpendOobRefund(e){return await this.client.rpcSingle("mint","await_spend_oob_refund",{operation_id:e})}}class s{constructor(e){this.client=e}async getBalance(){return await this.client.rpcSingle("","get_balance",{})}subscribeBalance(e=()=>{},t=()=>{}){return this.client.rpcStream("","subscribe_balance_changes",{},(t=>e(parseInt(t))),t)}}class r{constructor(e){this.client=e}async createInvoice(e,t,i,n,s){const r=n??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i??null,extra_meta:s??{},gateway:r})}async createInvoiceTweaked(e,t,i,n,s,r,a){const o=r??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice_for_user_tweaked",{amount:e,description:t,expiry_time:s??null,user_key:i,index:n,extra_meta:a??{},gateway:o})}async scanReceivesForTweaks(e,t,i){return await this.client.rpcSingle("ln","scan_receive_for_user_tweaked",{user_key:e,indices:t,extra_meta:i??{}})}async _getDefaultGatewayInfo(){await this.updateGatewayCache();const e=await this.listGateways();return e[0]?.info}async payInvoice(e,t,i){const n=t??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:n,invoice:e,extra_meta:i??{}})}subscribeLnClaim(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_claim",{operation_id:e},t,i)}subscribeLnPay(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_pay",{operation_id:e},t,i)}subscribeLnReceive(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_receive",{operation_id:e},t,i)}async waitForReceive(e){return new Promise(((t,i)=>{let n;const s=setTimeout((()=>{i(new Error("Timeout waiting for receive"))}),15e3);n=this.subscribeLnReceive(e,(e=>{"claimed"===e&&(clearTimeout(s),n(),t(e))}),(e=>{clearTimeout(s),n(),i(e)}))}))}async getGateway(e=null,t=!1){return await this.client.rpcSingle("ln","get_gateway",{gateway_id:e,force_internal:t})}async listGateways(){return await this.client.rpcSingle("ln","list_gateways",{})}async updateGatewayCache(){return await this.client.rpcSingle("ln","update_gateway_cache",{})}}class a{constructor(e){this.client=e}async hasPendingRecoveries(){return await this.client.rpcSingle("","has_pending_recoveries",{})}async waitForAllRecoveries(){await this.client.rpcSingle("","wait_for_all_recoveries",{})}subscribeToRecoveryProgress(e,t){return this.client.rpcStream("","subscribe_to_recovery_progress",{},e,t)}}class o{constructor(e){this.client=e}async getConfig(){return await this.client.rpcSingle("","get_config",{})}async getFederationId(){return await this.client.rpcSingle("","get_federation_id",{})}async getInviteCode(e){return await this.client.rpcSingle("","get_invite_code",{peer:e})}async listOperations(){return await this.client.rpcSingle("","list_operations",{})}}const c="fm-default";class l{constructor(e=!1){this._openPromise=void 0,this._resolveOpen=()=>{},this._isOpen=!1,this._openPromise=new Promise((e=>{this._resolveOpen=e})),this._client=new i,this.mint=new n(this._client),this.lightning=new r(this._client),this.balance=new s(this._client),this.federation=new o(this._client),this.recovery=new a(this._client),t.info("FedimintWallet instantiated"),e||this.initialize()}async initialize(){t.info("Initializing WorkerClient"),await this._client.initialize(),t.info("WorkerClient initialized")}async waitForOpen(){return this._isOpen?Promise.resolve():this._openPromise}async open(e=c){if(await this._client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open.");const{success:t}=await this._client.sendSingleMessage("open",{clientName:e});return t&&(this._isOpen=!!t,this._resolveOpen()),t}async joinFederation(e,i=c){if(await this._client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open. You can only call `joinFederation` on closed clients.");try{const t=await this._client.sendSingleMessage("join",{inviteCode:e,clientName:i});return t.success&&(this._isOpen=!0,this._resolveOpen()),t.success}catch(e){return t.error("Error joining federation",e),!1}}async cleanup(){this._openPromise=void 0,this._isOpen=!1,await this._client.cleanup()}isOpen(){return this._isOpen}setLogLevel(e){t.setLevel(e),t.info(`Log level set to ${e}.`)}}export{l as FedimintWallet};
1
+ const e=["debug","info","warn","error","none"];const t=new class{constructor(e="none"){this.level=e}setLevel(e){this.level=e}coerceLevel(t){return e.includes(t.toLocaleUpperCase())?t.toLocaleUpperCase():"info"}log(e,t,...i){const n=this.coerceLevel(e);if(!this.shouldLog(n))return;(0,console[n])(`[${n.toUpperCase()}] ${t}`,...i)}debug(e,...t){this.log("debug",e,...t)}info(e,...t){this.log("info",e,...t)}warn(e,...t){this.log("warn",e,...t)}error(e,...t){this.log("error",e,...t)}shouldLog(e){const t=["debug","info","warn","error","none"],i=t.indexOf(e);return t.indexOf(this.level)<=i&&"none"!==this.level&&"none"!==e}};class i{constructor(){this.requestCounter=0,this.requestCallbacks=new Map,this.initPromise=void 0,this.worker=new Worker(new URL("./worker.js",import.meta.url),{type:"module"}),this.worker.onmessage=this.handleWorkerMessage.bind(this),this.worker.onerror=this.handleWorkerError.bind(this),t.info("WorkerClient instantiated"),t.debug("WorkerClient",this.worker)}initialize(){return this.initPromise||(this.initPromise=this.sendSingleMessage("init")),this.initPromise}handleWorkerLogs(e){const{type:i,level:n,message:s,...r}=e.data;t.log(n,s,...r)}handleWorkerError(e){t.error("Worker error",e)}handleWorkerMessage(e){const{type:i,requestId:n,...s}=e.data;"log"===i&&this.handleWorkerLogs(e.data);const r=this.requestCallbacks.get(n);t.debug("WorkerClient - handleWorkerMessage",e.data),r?r(s):t.warn("WorkerClient - handleWorkerMessage - received message with no callback",n,e.data)}sendSingleMessage(e,i){return new Promise(((n,s)=>{const r=++this.requestCounter;t.debug("WorkerClient - sendSingleMessage",r,e,i),this.requestCallbacks.set(r,(e=>{this.requestCallbacks.delete(r),t.debug("WorkerClient - sendSingleMessage - response",r,e),e.data?n(e.data):e.error?s(e.error):t.warn("WorkerClient - sendSingleMessage - malformed response",r,e)})),this.worker.postMessage({type:e,payload:i,requestId:r})}))}rpcStream(e,i,n,s,r,a=()=>{}){const o=++this.requestCounter;t.debug("WorkerClient - rpcStream",o,e,i,n);let c=()=>{},l=!1;const u=new Promise((e=>{c=()=>{l?e():setTimeout((()=>c()),0)}}));return this._rpcStreamInner(o,e,i,n,s,r,a,u).then((()=>{l=!0})),c}async _rpcStreamInner(e,t,i,n,s,r,a=()=>{},o){this.requestCallbacks.set(e,(t=>{void 0!==t.error?r(t.error):void 0!==t.data?s(t.data):void 0!==t.end&&(this.requestCallbacks.delete(e),a())})),this.worker.postMessage({type:"rpc",payload:{module:t,method:i,body:n},requestId:e}),o.then((()=>{this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}rpcSingle(e,i,n){return t.debug("WorkerClient - rpcSingle",e,i,n),new Promise(((t,s)=>{this.rpcStream(e,i,n,t,s)}))}async cleanup(){await this.sendSingleMessage("cleanup"),this.requestCounter=0,this.initPromise=void 0,this.requestCallbacks.clear()}_getRequestCounter(){return this.requestCounter}_getRequestCallbackMap(){return this.requestCallbacks}}class n{constructor(e){this.client=e}async redeemEcash(e){await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:null})}async reissueExternalNotes(e,t={}){return await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:t})}subscribeReissueExternalNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_reissue_external_notes",{operation_id:e},t,i)}async spendNotes(e,t=86400,i=!1,n={}){const s="number"==typeof t?{nanos:0,secs:t}:t,r=await this.client.rpcSingle("mint","spend_notes",{min_amount:e,try_cancel_after:s,include_invite:i,extra_meta:n});return{notes:r[1],operation_id:r[0]}}async parseNotes(e){return await this.client.rpcSingle("mint","validate_notes",{oob_notes:e})}async tryCancelSpendNotes(e){await this.client.rpcSingle("mint","try_cancel_spend_notes",{operation_id:e})}subscribeSpendNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_spend_notes",{operation_id:e},(e=>t(e)),i)}async awaitSpendOobRefund(e){return await this.client.rpcSingle("mint","await_spend_oob_refund",{operation_id:e})}}class s{constructor(e){this.client=e}async getBalance(){return await this.client.rpcSingle("","get_balance",{})}subscribeBalance(e=()=>{},t=()=>{}){return this.client.rpcStream("","subscribe_balance_changes",{},(t=>e(parseInt(t))),t)}}class r{constructor(e){this.client=e}async createInvoice(e,t,i,n,s){const r=n??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i??null,extra_meta:s??{},gateway:r})}async createInvoiceTweaked(e,t,i,n,s,r,a){const o=r??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice_for_user_tweaked",{amount:e,description:t,expiry_time:s??null,user_key:i,index:n,extra_meta:a??{},gateway:o})}async scanReceivesForTweaks(e,t,i){return await this.client.rpcSingle("ln","scan_receive_for_user_tweaked",{user_key:e,indices:t,extra_meta:i??{}})}async _getDefaultGatewayInfo(){await this.updateGatewayCache();const e=await this.listGateways();return e[0]?.info}async payInvoice(e,t,i){const n=t??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:n,invoice:e,extra_meta:i??{}})}async payInvoiceSync(e,t=1e4,i,n){return new Promise((async(s,r)=>{const{contract_id:a,fee:o}=await this.payInvoice(e,i,n),c=this.subscribeLnPay(a,(e=>{"string"!=typeof e&&"success"in e&&(clearTimeout(l),c(),s({success:!0,data:{feeMsats:o,preimage:e.success.preimage}}))})),l=setTimeout((()=>{c(),r(new Error("Timeout waiting for pay"))}),t)}))}subscribeLnClaim(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_claim",{operation_id:e},t,i)}subscribeLnPay(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_pay",{operation_id:e},t,i)}async waitForPay(e){return new Promise(((t,i)=>{let n;const s=setTimeout((()=>{i(new Error("Timeout waiting for receive"))}),15e3);n=this.subscribeLnPay(e,(e=>{"string"!=typeof e&&"success"in e&&(clearTimeout(s),n(),t({success:!0,data:{preimage:e.success.preimage}}))}),(e=>{clearTimeout(s),n(),i(e)}))}))}subscribeLnReceive(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_receive",{operation_id:e},t,i)}async waitForReceive(e,t=15e3){return new Promise(((i,n)=>{let s;const r=setTimeout((()=>{n(new Error("Timeout waiting for receive"))}),t);s=this.subscribeLnReceive(e,(e=>{"claimed"===e&&(clearTimeout(r),s(),i(e))}),(e=>{clearTimeout(r),s(),n(e)}))}))}async getGateway(e=null,t=!1){return await this.client.rpcSingle("ln","get_gateway",{gateway_id:e,force_internal:t})}async listGateways(){return await this.client.rpcSingle("ln","list_gateways",{})}async updateGatewayCache(){return await this.client.rpcSingle("ln","update_gateway_cache",{})}}class a{constructor(e){this.client=e}async hasPendingRecoveries(){return await this.client.rpcSingle("","has_pending_recoveries",{})}async waitForAllRecoveries(){await this.client.rpcSingle("","wait_for_all_recoveries",{})}subscribeToRecoveryProgress(e,t){return this.client.rpcStream("","subscribe_to_recovery_progress",{},e,t)}}class o{constructor(e){this.client=e}async getConfig(){return await this.client.rpcSingle("","get_config",{})}async getFederationId(){return await this.client.rpcSingle("","get_federation_id",{})}async getInviteCode(e){return await this.client.rpcSingle("","get_invite_code",{peer:e})}async listOperations(){return await this.client.rpcSingle("","list_operations",{})}}const c="fm-default";class l{constructor(e=!1){this._openPromise=void 0,this._resolveOpen=()=>{},this._isOpen=!1,this._openPromise=new Promise((e=>{this._resolveOpen=e})),this._client=new i,this.mint=new n(this._client),this.lightning=new r(this._client),this.balance=new s(this._client),this.federation=new o(this._client),this.recovery=new a(this._client),t.info("FedimintWallet instantiated"),e||this.initialize()}async initialize(){t.info("Initializing WorkerClient"),await this._client.initialize(),t.info("WorkerClient initialized")}async waitForOpen(){return this._isOpen?Promise.resolve():this._openPromise}async open(e=c){if(await this._client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open.");const{success:t}=await this._client.sendSingleMessage("open",{clientName:e});return t&&(this._isOpen=!!t,this._resolveOpen()),t}async joinFederation(e,i=c){if(await this._client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open. You can only call `joinFederation` on closed clients.");try{const t=await this._client.sendSingleMessage("join",{inviteCode:e,clientName:i});return t.success&&(this._isOpen=!0,this._resolveOpen()),t.success}catch(e){return t.error("Error joining federation",e),!1}}async cleanup(){this._openPromise=void 0,this._isOpen=!1,await this._client.cleanup()}isOpen(){return this._isOpen}setLogLevel(e){t.setLevel(e),t.info(`Log level set to ${e}.`)}}export{l as FedimintWallet};
2
2
  //# sourceMappingURL=index.js.map
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","minAmount","tryCancelAfter","includeInvite","duration","nanos","secs","res","min_amount","try_cancel_after","include_invite","parseNotes","tryCancelSpendNotes","subscribeSpendNotes","awaitSpendOobRefund","BalanceService","getBalance","subscribeBalance","parseInt","LightningService","createInvoice","amount","description","expiryTime","gatewayInfo","gateway","_getDefaultGatewayInfo","expiry_time","createInvoiceTweaked","tweakKey","index","user_key","scanReceivesForTweaks","indices","updateGatewayCache","gateways","listGateways","payInvoice","invoice","maybe_gateway","subscribeLnClaim","subscribeLnPay","subscribeLnReceive","waitForReceive","timeoutId","Error","clearTimeout","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","success","joinFederation","inviteCode","e","isOpen","setLogLevel"],"mappings":"AAAA,MAAMA,EAAY,CAAC,QAAS,OA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IrB,SAFMlJ,KAAKwJ,QAAQnH,aAEfrC,KAAKuJ,QACP,MAAM,IAAItB,MACR,6FAEJ,IACE,MAAM/E,QAAiBlD,KAAKwJ,QAAQlH,kBAEjC,OAAQ,CAAE6H,aAAYH,eAMzB,OALI9G,EAAS+G,UACXjK,KAAKuJ,SAAU,EACfvJ,KAAKsJ,gBAGApG,EAAS+G,OACjB,CAAC,MAAOG,GAEP,OADAvK,EAAOmB,MAAM,2BAA4BoJ,IAClC,CACR,CACF,CAMD,aAAMhG,GACJpE,KAAKqJ,kBAAe3H,EACpB1B,KAAKuJ,SAAU,QACTvJ,KAAKwJ,QAAQpF,SACpB,CAED,MAAAiG,GACE,OAAOrK,KAAKuJ,OACb,CAMD,WAAAe,CAAYvK,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","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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KAAKgK,QAAgBlH,QAAQC,UAC1B/C,KAAK8J,YACb,CAED,UAAMU,CAAKC,EAAqBd,GAG9B,SAFM3J,KAAKiK,QAAQ5H,aAEfrC,KAAKgK,QAAS,MAAM,IAAIzB,MAAM,uCAClC,MAAMH,QAAEA,SAAkBpI,KAAKiK,QAAQ3H,kBAEpC,OAAQ,CAAEmI,eAKb,OAJIrC,IACFpI,KAAKgK,UAAY5B,EACjBpI,KAAK+J,gBAEA3B,CACR,CAED,oBAAMsC,CACJC,EACAF,EAAqBd,GAIrB,SAFM3J,KAAKiK,QAAQ5H,aAEfrC,KAAKgK,QACP,MAAM,IAAIzB,MACR,6FAEJ,IACE,MAAMrF,QAAiBlD,KAAKiK,QAAQ3H,kBAEjC,OAAQ,CAAEqI,aAAYF,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"}
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.9",
4
+ "version": "0.0.10",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/fedimint/fedimint-web-sdk.git",
@@ -1,4 +1,3 @@
1
- import type { MSats } from '../types'
2
1
  import { WorkerClient } from '../worker'
3
2
 
4
3
  /**
@@ -17,7 +16,7 @@ export class BalanceService {
17
16
  * const balance = await wallet.balance.getBalance()
18
17
  * ```
19
18
  */
20
- async getBalance(): Promise<MSats> {
19
+ async getBalance(): Promise<number> {
21
20
  return await this.client.rpcSingle('', 'get_balance', {})
22
21
  }
23
22
 
@@ -35,7 +34,7 @@ export class BalanceService {
35
34
  * ```
36
35
  */
37
36
  subscribeBalance(
38
- onSuccess: (balance: MSats) => void = () => {},
37
+ onSuccess: (balanceMsats: number) => void = () => {},
39
38
  onError: (error: string) => void = () => {},
40
39
  ) {
41
40
  const unsubscribe = this.client.rpcStream<string>(
@@ -7,7 +7,6 @@ import type {
7
7
  LightningGateway,
8
8
  LnPayState,
9
9
  LnReceiveState,
10
- MSats,
11
10
  OutgoingLightningPayment,
12
11
  } from '../types'
13
12
 
@@ -15,7 +14,7 @@ export class LightningService {
15
14
  constructor(private client: WorkerClient) {}
16
15
 
17
16
  async createInvoice(
18
- amount: MSats,
17
+ amountMsats: number,
19
18
  description: string,
20
19
  expiryTime?: number, // in seconds
21
20
  gatewayInfo?: GatewayInfo,
@@ -23,7 +22,7 @@ export class LightningService {
23
22
  ): Promise<CreateBolt11Response> {
24
23
  const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
25
24
  return await this.client.rpcSingle('ln', 'create_bolt11_invoice', {
26
- amount,
25
+ amount: amountMsats,
27
26
  description,
28
27
  expiry_time: expiryTime ?? null,
29
28
  extra_meta: extraMeta ?? {},
@@ -32,7 +31,7 @@ export class LightningService {
32
31
  }
33
32
 
34
33
  async createInvoiceTweaked(
35
- amount: MSats,
34
+ amountMsats: number,
36
35
  description: string,
37
36
  tweakKey: string,
38
37
  index: number,
@@ -45,7 +44,7 @@ export class LightningService {
45
44
  'ln',
46
45
  'create_bolt11_invoice_for_user_tweaked',
47
46
  {
48
- amount,
47
+ amount: amountMsats,
49
48
  description,
50
49
  expiry_time: expiryTime ?? null,
51
50
  user_key: tweakKey,
@@ -88,6 +87,43 @@ export class LightningService {
88
87
  })
89
88
  }
90
89
 
90
+ async payInvoiceSync(
91
+ invoice: string,
92
+ timeoutMs: number = 10000,
93
+ gatewayInfo?: GatewayInfo,
94
+ 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) => {
103
+ const { contract_id, fee } = await this.payInvoice(
104
+ invoice,
105
+ gatewayInfo,
106
+ extraMeta,
107
+ )
108
+
109
+ const unsubscribe = this.subscribeLnPay(contract_id, (res) => {
110
+ if (typeof res !== 'string' && 'success' in res) {
111
+ clearTimeout(timeoutId)
112
+ unsubscribe()
113
+ resolve({
114
+ success: true,
115
+ data: { feeMsats: fee, preimage: res.success.preimage },
116
+ })
117
+ }
118
+ })
119
+
120
+ const timeoutId = setTimeout(() => {
121
+ unsubscribe()
122
+ reject(new Error('Timeout waiting for pay'))
123
+ }, timeoutMs)
124
+ })
125
+ }
126
+
91
127
  // TODO: Document
92
128
  subscribeLnClaim(
93
129
  operationId: string,
@@ -123,6 +159,40 @@ export class LightningService {
123
159
  return unsubscribe
124
160
  }
125
161
 
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) => {
170
+ let unsubscribe: () => void
171
+ const timeoutId = setTimeout(() => {
172
+ reject(new Error('Timeout waiting for receive'))
173
+ }, 15000)
174
+
175
+ unsubscribe = this.subscribeLnPay(
176
+ operationId,
177
+ (res) => {
178
+ if (typeof res !== 'string' && 'success' in res) {
179
+ clearTimeout(timeoutId)
180
+ unsubscribe()
181
+ resolve({
182
+ success: true,
183
+ data: { preimage: res.success.preimage },
184
+ })
185
+ }
186
+ },
187
+ (error) => {
188
+ clearTimeout(timeoutId)
189
+ unsubscribe()
190
+ reject(error)
191
+ },
192
+ )
193
+ })
194
+ }
195
+
126
196
  // TODO: Document
127
197
  subscribeLnReceive(
128
198
  operationId: string,
@@ -140,13 +210,15 @@ export class LightningService {
140
210
  return unsubscribe
141
211
  }
142
212
 
143
- // TODO: Document
144
- async waitForReceive(operationId: string): Promise<LnReceiveState> {
213
+ async waitForReceive(
214
+ operationId: string,
215
+ timeoutMs: number = 15000,
216
+ ): Promise<LnReceiveState> {
145
217
  return new Promise((resolve, reject) => {
146
218
  let unsubscribe: () => void
147
219
  const timeoutId = setTimeout(() => {
148
220
  reject(new Error('Timeout waiting for receive'))
149
- }, 15000)
221
+ }, timeoutMs)
150
222
 
151
223
  unsubscribe = this.subscribeLnReceive(
152
224
  operationId,
@@ -45,7 +45,7 @@ export class MintService {
45
45
  }
46
46
 
47
47
  async spendNotes(
48
- minAmount: MSats,
48
+ amountMsats: number,
49
49
  // Tells the wallet to automatically try to cancel the spend if it hasn't completed
50
50
  // after the specified number of seconds. If the receiver has already redeemed
51
51
  // the notes at this time, the notes will not be cancelled.
@@ -62,7 +62,7 @@ export class MintService {
62
62
  'mint',
63
63
  'spend_notes',
64
64
  {
65
- min_amount: minAmount,
65
+ min_amount: amountMsats,
66
66
  try_cancel_after: duration,
67
67
  include_invite: includeInvite,
68
68
  extra_meta: extraMeta,