@fedimint/core-web 0.1.0 → 0.1.2
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.
- package/README.md +20 -9
- package/index.d.ts +1 -0
- package/index.js +15 -0
- package/package.json +12 -35
- package/dist/dts/FedimintWallet.d.ts +0 -51
- package/dist/dts/FedimintWallet.d.ts.map +0 -1
- package/dist/dts/WalletDirector.d.ts +0 -78
- package/dist/dts/WalletDirector.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -4
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/services/BalanceService.d.ts +0 -15
- package/dist/dts/services/BalanceService.d.ts.map +0 -1
- package/dist/dts/services/FederationService.d.ts +0 -13
- package/dist/dts/services/FederationService.d.ts.map +0 -1
- package/dist/dts/services/LightningService.d.ts +0 -48
- package/dist/dts/services/LightningService.d.ts.map +0 -1
- package/dist/dts/services/MintService.d.ts +0 -23
- package/dist/dts/services/MintService.d.ts.map +0 -1
- package/dist/dts/services/RecoveryService.d.ts +0 -13
- package/dist/dts/services/RecoveryService.d.ts.map +0 -1
- package/dist/dts/services/WalletService.d.ts +0 -13
- package/dist/dts/services/WalletService.d.ts.map +0 -1
- package/dist/dts/services/index.d.ts +0 -7
- package/dist/dts/services/index.d.ts.map +0 -1
- package/dist/dts/transport/TransportClient.d.ts +0 -55
- package/dist/dts/transport/TransportClient.d.ts.map +0 -1
- package/dist/dts/transport/index.d.ts +0 -3
- package/dist/dts/transport/index.d.ts.map +0 -1
- package/dist/dts/transport/wasmTransport/WasmWorkerTransport.d.ts +0 -12
- package/dist/dts/transport/wasmTransport/WasmWorkerTransport.d.ts.map +0 -1
- package/dist/dts/types/index.d.ts +0 -4
- package/dist/dts/types/index.d.ts.map +0 -1
- package/dist/dts/types/transport.d.ts +0 -35
- package/dist/dts/types/transport.d.ts.map +0 -1
- package/dist/dts/types/utils.d.ts +0 -23
- package/dist/dts/types/utils.d.ts.map +0 -1
- package/dist/dts/types/wallet.d.ts +0 -241
- package/dist/dts/types/wallet.d.ts.map +0 -1
- package/dist/dts/utils/logger.d.ts +0 -24
- package/dist/dts/utils/logger.d.ts.map +0 -1
- package/dist/index.d.ts +0 -609
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/worker.js +0 -2
- package/dist/worker.js.map +0 -1
- package/src/FedimintWallet.test.ts +0 -73
- package/src/FedimintWallet.ts +0 -119
- package/src/WalletDirector.ts +0 -118
- package/src/index.ts +0 -3
- package/src/services/BalanceService.test.ts +0 -26
- package/src/services/BalanceService.ts +0 -29
- package/src/services/FederationService.test.ts +0 -58
- package/src/services/FederationService.ts +0 -216
- package/src/services/LightningService.test.ts +0 -265
- package/src/services/LightningService.ts +0 -289
- package/src/services/MintService.test.ts +0 -74
- package/src/services/MintService.ts +0 -129
- package/src/services/RecoveryService.ts +0 -28
- package/src/services/WalletService.test.ts +0 -59
- package/src/services/WalletService.ts +0 -50
- package/src/services/index.ts +0 -6
- package/src/test/TestFedimintWallet.ts +0 -31
- package/src/test/TestWalletDirector.ts +0 -14
- package/src/test/TestingService.ts +0 -79
- package/src/test/crypto.ts +0 -44
- package/src/test/fixtures.test.ts +0 -18
- package/src/test/fixtures.ts +0 -88
- package/src/transport/TransportClient.test.ts +0 -6
- package/src/transport/TransportClient.ts +0 -251
- package/src/transport/index.ts +0 -2
- package/src/transport/wasmTransport/WasmWorkerTransport.ts +0 -39
- package/src/transport/wasmTransport/worker.js +0 -167
- package/src/transport/wasmTransport/worker.test.ts +0 -90
- package/src/types/index.ts +0 -3
- package/src/types/transport.ts +0 -54
- package/src/types/utils.ts +0 -29
- package/src/types/wallet.ts +0 -298
- package/src/utils/logger.ts +0 -69
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { TransportClient } from '../transport'
|
|
2
|
-
import type {
|
|
3
|
-
CreateBolt11Response,
|
|
4
|
-
GatewayInfo,
|
|
5
|
-
JSONObject,
|
|
6
|
-
LightningGateway,
|
|
7
|
-
LnInternalPayState,
|
|
8
|
-
LnPayState,
|
|
9
|
-
LnReceiveState,
|
|
10
|
-
OutgoingLightningPayment,
|
|
11
|
-
} from '../types'
|
|
12
|
-
|
|
13
|
-
export class LightningService {
|
|
14
|
-
constructor(private client: TransportClient) {}
|
|
15
|
-
|
|
16
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
|
|
17
|
-
async createInvoice(
|
|
18
|
-
amountMsats: number,
|
|
19
|
-
description: string,
|
|
20
|
-
expiryTime?: number, // in seconds
|
|
21
|
-
gatewayInfo?: GatewayInfo,
|
|
22
|
-
extraMeta?: JSONObject,
|
|
23
|
-
) {
|
|
24
|
-
const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
|
|
25
|
-
return await this.client.rpcSingle<CreateBolt11Response>(
|
|
26
|
-
'ln',
|
|
27
|
-
'create_bolt11_invoice',
|
|
28
|
-
{
|
|
29
|
-
amount: amountMsats,
|
|
30
|
-
description,
|
|
31
|
-
expiry_time: expiryTime ?? null,
|
|
32
|
-
extra_meta: extraMeta ?? {},
|
|
33
|
-
gateway,
|
|
34
|
-
},
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async createInvoiceTweaked(
|
|
39
|
-
amountMsats: number,
|
|
40
|
-
description: string,
|
|
41
|
-
tweakKey: string,
|
|
42
|
-
index: number,
|
|
43
|
-
expiryTime?: number, // in seconds
|
|
44
|
-
gatewayInfo?: GatewayInfo,
|
|
45
|
-
extraMeta?: JSONObject,
|
|
46
|
-
) {
|
|
47
|
-
const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
|
|
48
|
-
return await this.client.rpcSingle<CreateBolt11Response>(
|
|
49
|
-
'ln',
|
|
50
|
-
'create_bolt11_invoice_for_user_tweaked',
|
|
51
|
-
{
|
|
52
|
-
amount: amountMsats,
|
|
53
|
-
description,
|
|
54
|
-
expiry_time: expiryTime ?? null,
|
|
55
|
-
user_key: tweakKey,
|
|
56
|
-
index,
|
|
57
|
-
extra_meta: extraMeta ?? {},
|
|
58
|
-
gateway,
|
|
59
|
-
},
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Returns the operation ids of payments received to the tweaks of the user secret key
|
|
64
|
-
async scanReceivesForTweaks(
|
|
65
|
-
tweakKey: string,
|
|
66
|
-
indices: number[],
|
|
67
|
-
extraMeta?: JSONObject,
|
|
68
|
-
) {
|
|
69
|
-
return await this.client.rpcSingle<string[]>(
|
|
70
|
-
'ln',
|
|
71
|
-
'scan_receive_for_user_tweaked',
|
|
72
|
-
{
|
|
73
|
-
user_key: tweakKey,
|
|
74
|
-
indices,
|
|
75
|
-
extra_meta: extraMeta ?? {},
|
|
76
|
-
},
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private async _getDefaultGatewayInfo() {
|
|
81
|
-
await this.updateGatewayCache()
|
|
82
|
-
const gateways = await this.listGateways()
|
|
83
|
-
return gateways[0]?.info
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
|
|
87
|
-
async payInvoice(
|
|
88
|
-
invoice: string,
|
|
89
|
-
gatewayInfo?: GatewayInfo,
|
|
90
|
-
extraMeta?: JSONObject,
|
|
91
|
-
) {
|
|
92
|
-
const gateway = gatewayInfo ?? (await this._getDefaultGatewayInfo())
|
|
93
|
-
return await this.client.rpcSingle<OutgoingLightningPayment>(
|
|
94
|
-
'ln',
|
|
95
|
-
'pay_bolt11_invoice',
|
|
96
|
-
{
|
|
97
|
-
maybe_gateway: gateway,
|
|
98
|
-
invoice,
|
|
99
|
-
extra_meta: extraMeta ?? {},
|
|
100
|
-
},
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoicesync-invoice-string */
|
|
105
|
-
async payInvoiceSync(
|
|
106
|
-
invoice: string,
|
|
107
|
-
timeoutMs: number = 10000,
|
|
108
|
-
gatewayInfo?: GatewayInfo,
|
|
109
|
-
extraMeta?: JSONObject,
|
|
110
|
-
) {
|
|
111
|
-
return new Promise<
|
|
112
|
-
| { success: false; error?: string }
|
|
113
|
-
| {
|
|
114
|
-
success: true
|
|
115
|
-
data: { feeMsats: number; preimage: string }
|
|
116
|
-
}
|
|
117
|
-
>(async (resolve, reject) => {
|
|
118
|
-
const { contract_id, fee } = await this.payInvoice(
|
|
119
|
-
invoice,
|
|
120
|
-
gatewayInfo,
|
|
121
|
-
extraMeta,
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
// TODO: handle error handling for other subscription statuses
|
|
125
|
-
const unsubscribe = this.subscribeLnPay(contract_id, (res) => {
|
|
126
|
-
if (typeof res !== 'string' && 'success' in res) {
|
|
127
|
-
clearTimeout(timeoutId)
|
|
128
|
-
unsubscribe()
|
|
129
|
-
resolve({
|
|
130
|
-
success: true,
|
|
131
|
-
data: { feeMsats: fee, preimage: res.success.preimage },
|
|
132
|
-
})
|
|
133
|
-
} else if (typeof res !== 'string' && 'unexpected_error' in res) {
|
|
134
|
-
reject(new Error(res.unexpected_error.error_message))
|
|
135
|
-
}
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
const timeoutId = setTimeout(() => {
|
|
139
|
-
unsubscribe()
|
|
140
|
-
resolve({ success: false, error: 'Payment timeout' })
|
|
141
|
-
}, timeoutMs)
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
subscribeInternalPayment(
|
|
146
|
-
operation_id: string,
|
|
147
|
-
onSuccess: (state: LnInternalPayState) => void = () => {},
|
|
148
|
-
onError: (error: string) => void = () => {},
|
|
149
|
-
) {
|
|
150
|
-
return this.client.rpcStream(
|
|
151
|
-
'ln',
|
|
152
|
-
'subscribe_internal_pay',
|
|
153
|
-
{ operation_id: operation_id },
|
|
154
|
-
onSuccess,
|
|
155
|
-
onError,
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// TODO: Document
|
|
160
|
-
subscribeLnClaim(
|
|
161
|
-
operationId: string,
|
|
162
|
-
onSuccess: (state: LnReceiveState) => void = () => {},
|
|
163
|
-
onError: (error: string) => void = () => {},
|
|
164
|
-
) {
|
|
165
|
-
return this.client.rpcStream(
|
|
166
|
-
'ln',
|
|
167
|
-
'subscribe_ln_claim',
|
|
168
|
-
{ operation_id: operationId },
|
|
169
|
-
onSuccess,
|
|
170
|
-
onError,
|
|
171
|
-
)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// TODO: Document (for external payments only)
|
|
175
|
-
// TODO: Make this work for BOTH internal and external payments
|
|
176
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
|
|
177
|
-
subscribeLnPay(
|
|
178
|
-
operationId: string,
|
|
179
|
-
onSuccess: (state: LnPayState) => void = () => {},
|
|
180
|
-
onError: (error: string) => void = () => {},
|
|
181
|
-
) {
|
|
182
|
-
return this.client.rpcStream(
|
|
183
|
-
'ln',
|
|
184
|
-
'subscribe_ln_pay',
|
|
185
|
-
{ operation_id: operationId },
|
|
186
|
-
onSuccess,
|
|
187
|
-
onError,
|
|
188
|
-
)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
|
|
192
|
-
async waitForPay(operationId: string) {
|
|
193
|
-
return new Promise<
|
|
194
|
-
| { success: false; error?: string }
|
|
195
|
-
| { success: true; data: { preimage: string } }
|
|
196
|
-
>((resolve, reject) => {
|
|
197
|
-
let unsubscribe: () => void
|
|
198
|
-
const timeoutId = setTimeout(() => {
|
|
199
|
-
resolve({ success: false, error: 'Waiting for receive timeout' })
|
|
200
|
-
}, 15000)
|
|
201
|
-
|
|
202
|
-
unsubscribe = this.subscribeLnPay(
|
|
203
|
-
operationId,
|
|
204
|
-
(res) => {
|
|
205
|
-
if (typeof res !== 'string' && 'success' in res) {
|
|
206
|
-
clearTimeout(timeoutId)
|
|
207
|
-
unsubscribe()
|
|
208
|
-
resolve({
|
|
209
|
-
success: true,
|
|
210
|
-
data: { preimage: res.success.preimage },
|
|
211
|
-
})
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
(error) => {
|
|
215
|
-
clearTimeout(timeoutId)
|
|
216
|
-
unsubscribe()
|
|
217
|
-
reject(error)
|
|
218
|
-
},
|
|
219
|
-
)
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
|
|
224
|
-
subscribeLnReceive(
|
|
225
|
-
operationId: string,
|
|
226
|
-
onSuccess: (state: LnReceiveState) => void = () => {},
|
|
227
|
-
onError: (error: string) => void = () => {},
|
|
228
|
-
) {
|
|
229
|
-
return this.client.rpcStream(
|
|
230
|
-
'ln',
|
|
231
|
-
'subscribe_ln_receive',
|
|
232
|
-
{ operation_id: operationId },
|
|
233
|
-
onSuccess,
|
|
234
|
-
onError,
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
|
|
239
|
-
async waitForReceive(operationId: string, timeoutMs: number = 15000) {
|
|
240
|
-
return new Promise<LnReceiveState>((resolve, reject) => {
|
|
241
|
-
let unsubscribe: () => void
|
|
242
|
-
const timeoutId = setTimeout(() => {
|
|
243
|
-
reject(new Error('Timeout waiting for receive'))
|
|
244
|
-
}, timeoutMs)
|
|
245
|
-
|
|
246
|
-
unsubscribe = this.subscribeLnReceive(
|
|
247
|
-
operationId,
|
|
248
|
-
(res) => {
|
|
249
|
-
if (res === 'claimed') {
|
|
250
|
-
clearTimeout(timeoutId)
|
|
251
|
-
unsubscribe()
|
|
252
|
-
resolve(res)
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
(error) => {
|
|
256
|
-
clearTimeout(timeoutId)
|
|
257
|
-
unsubscribe()
|
|
258
|
-
reject(error)
|
|
259
|
-
},
|
|
260
|
-
)
|
|
261
|
-
})
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async getGateway(
|
|
265
|
-
gatewayId: string | null = null,
|
|
266
|
-
forceInternal: boolean = false,
|
|
267
|
-
) {
|
|
268
|
-
return await this.client.rpcSingle<LightningGateway | null>(
|
|
269
|
-
'ln',
|
|
270
|
-
'get_gateway',
|
|
271
|
-
{
|
|
272
|
-
gateway_id: gatewayId,
|
|
273
|
-
force_internal: forceInternal,
|
|
274
|
-
},
|
|
275
|
-
)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async listGateways() {
|
|
279
|
-
return await this.client.rpcSingle<LightningGateway[]>(
|
|
280
|
-
'ln',
|
|
281
|
-
'list_gateways',
|
|
282
|
-
{},
|
|
283
|
-
)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
async updateGatewayCache() {
|
|
287
|
-
return await this.client.rpcSingle('ln', 'update_gateway_cache', {})
|
|
288
|
-
}
|
|
289
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { expect } from 'vitest'
|
|
2
|
-
import { walletTest } from '../test/fixtures'
|
|
3
|
-
|
|
4
|
-
walletTest('redeemEcash should error on invalid ecash', async ({ wallet }) => {
|
|
5
|
-
expect(wallet).toBeDefined()
|
|
6
|
-
expect(wallet.isOpen()).toBe(true)
|
|
7
|
-
|
|
8
|
-
await expect(wallet.mint.redeemEcash('test')).rejects.toThrow()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
walletTest(
|
|
12
|
-
'reissueExternalNotes should throw if wallet is empty',
|
|
13
|
-
async ({ wallet }) => {
|
|
14
|
-
expect(wallet).toBeDefined()
|
|
15
|
-
expect(wallet.isOpen()).toBe(true)
|
|
16
|
-
|
|
17
|
-
await expect(wallet.mint.reissueExternalNotes('test')).rejects.toThrow()
|
|
18
|
-
},
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
walletTest('spendNotes should throw if wallet is empty', async ({ wallet }) => {
|
|
22
|
-
expect(wallet).toBeDefined()
|
|
23
|
-
expect(wallet.isOpen()).toBe(true)
|
|
24
|
-
|
|
25
|
-
await expect(wallet.mint.spendNotes(100)).rejects.toThrow()
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
walletTest('parseNotes should parse notes', async ({ wallet }) => {
|
|
29
|
-
expect(wallet).toBeDefined()
|
|
30
|
-
expect(wallet.isOpen()).toBe(true)
|
|
31
|
-
|
|
32
|
-
await expect(wallet.mint.reissueExternalNotes('test')).rejects.toThrow()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
walletTest(
|
|
36
|
-
'getNotesByDenomination should return empty object if wallet is empty',
|
|
37
|
-
async ({ wallet }) => {
|
|
38
|
-
expect(wallet).toBeDefined()
|
|
39
|
-
expect(wallet.isOpen()).toBe(true)
|
|
40
|
-
|
|
41
|
-
const notes = await wallet.mint.getNotesByDenomination()
|
|
42
|
-
const balance = await wallet.balance.getBalance()
|
|
43
|
-
expect(balance).toEqual(0)
|
|
44
|
-
expect(notes).toBeDefined()
|
|
45
|
-
expect(notes).toEqual({})
|
|
46
|
-
},
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
walletTest(
|
|
50
|
-
'getNotesByDenomination should get notes by denomination',
|
|
51
|
-
async ({ fundedWallet }) => {
|
|
52
|
-
expect(fundedWallet).toBeDefined()
|
|
53
|
-
expect(fundedWallet.isOpen()).toBe(true)
|
|
54
|
-
|
|
55
|
-
const notes = await fundedWallet.mint.getNotesByDenomination()
|
|
56
|
-
const balance = await fundedWallet.balance.getBalance()
|
|
57
|
-
expect(balance).toEqual(10000)
|
|
58
|
-
expect(notes).toBeDefined()
|
|
59
|
-
expect(notes).toEqual({
|
|
60
|
-
'1': 2,
|
|
61
|
-
'1024': 3,
|
|
62
|
-
'128': 2,
|
|
63
|
-
'16': 3,
|
|
64
|
-
'2': 3,
|
|
65
|
-
'2048': 2,
|
|
66
|
-
'256': 3,
|
|
67
|
-
'32': 2,
|
|
68
|
-
'4': 2,
|
|
69
|
-
'512': 3,
|
|
70
|
-
'64': 2,
|
|
71
|
-
'8': 2,
|
|
72
|
-
})
|
|
73
|
-
},
|
|
74
|
-
)
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { TransportClient } from '../transport'
|
|
2
|
-
import type {
|
|
3
|
-
Duration,
|
|
4
|
-
JSONObject,
|
|
5
|
-
JSONValue,
|
|
6
|
-
MintSpendNotesResponse,
|
|
7
|
-
MSats,
|
|
8
|
-
NoteCountByDenomination,
|
|
9
|
-
ReissueExternalNotesState,
|
|
10
|
-
SpendNotesState,
|
|
11
|
-
} from '../types'
|
|
12
|
-
|
|
13
|
-
export class MintService {
|
|
14
|
-
constructor(private client: TransportClient) {}
|
|
15
|
-
|
|
16
|
-
/** https://web.fedimint.org/core/FedimintWallet/MintService/redeemEcash */
|
|
17
|
-
async redeemEcash(notes: string) {
|
|
18
|
-
return await this.client.rpcSingle<string>(
|
|
19
|
-
'mint',
|
|
20
|
-
'reissue_external_notes',
|
|
21
|
-
{
|
|
22
|
-
oob_notes: notes, // "out of band notes"
|
|
23
|
-
extra_meta: null,
|
|
24
|
-
},
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async reissueExternalNotes(oobNotes: string, extraMeta: JSONObject = {}) {
|
|
29
|
-
return await this.client.rpcSingle<string>(
|
|
30
|
-
'mint',
|
|
31
|
-
'reissue_external_notes',
|
|
32
|
-
{
|
|
33
|
-
oob_notes: oobNotes,
|
|
34
|
-
extra_meta: extraMeta,
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
subscribeReissueExternalNotes(
|
|
40
|
-
operationId: string,
|
|
41
|
-
onSuccess: (state: ReissueExternalNotesState) => void = () => {},
|
|
42
|
-
onError: (error: string) => void = () => {},
|
|
43
|
-
) {
|
|
44
|
-
const unsubscribe = this.client.rpcStream<ReissueExternalNotesState>(
|
|
45
|
-
'mint',
|
|
46
|
-
'subscribe_reissue_external_notes',
|
|
47
|
-
{ operation_id: operationId },
|
|
48
|
-
onSuccess,
|
|
49
|
-
onError,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
return unsubscribe
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** https://web.fedimint.org/core/FedimintWallet/MintService/spendNotes */
|
|
56
|
-
async spendNotes(
|
|
57
|
-
amountMsats: number,
|
|
58
|
-
// Tells the wallet to automatically try to cancel the spend if it hasn't completed
|
|
59
|
-
// after the specified number of seconds. If the receiver has already redeemed
|
|
60
|
-
// the notes at this time, the notes will not be cancelled.
|
|
61
|
-
tryCancelAfter: number | Duration = 3600 * 24, // defaults to 1 day
|
|
62
|
-
includeInvite: boolean = false,
|
|
63
|
-
extraMeta: JSONValue = {},
|
|
64
|
-
) {
|
|
65
|
-
const duration =
|
|
66
|
-
typeof tryCancelAfter === 'number'
|
|
67
|
-
? { nanos: 0, secs: tryCancelAfter }
|
|
68
|
-
: tryCancelAfter
|
|
69
|
-
|
|
70
|
-
const res = await this.client.rpcSingle<MintSpendNotesResponse>(
|
|
71
|
-
'mint',
|
|
72
|
-
'spend_notes',
|
|
73
|
-
{
|
|
74
|
-
amount: amountMsats,
|
|
75
|
-
try_cancel_after: duration,
|
|
76
|
-
include_invite: includeInvite,
|
|
77
|
-
extra_meta: extraMeta,
|
|
78
|
-
},
|
|
79
|
-
)
|
|
80
|
-
const notes = res[1]
|
|
81
|
-
const operationId = res[0]
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
notes,
|
|
85
|
-
operation_id: operationId,
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** https://web.fedimint.org/core/FedimintWallet/MintService/parseEcash */
|
|
90
|
-
async parseNotes(oobNotes: string) {
|
|
91
|
-
return await this.client.rpcSingle<MSats>('mint', 'validate_notes', {
|
|
92
|
-
oob_notes: oobNotes,
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async tryCancelSpendNotes(operationId: string) {
|
|
97
|
-
await this.client.rpcSingle('mint', 'try_cancel_spend_notes', {
|
|
98
|
-
operation_id: operationId,
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
subscribeSpendNotes(
|
|
103
|
-
operationId: string,
|
|
104
|
-
onSuccess: (state: SpendNotesState) => void = () => {},
|
|
105
|
-
onError: (error: string) => void = () => {},
|
|
106
|
-
) {
|
|
107
|
-
return this.client.rpcStream<SpendNotesState>(
|
|
108
|
-
'mint',
|
|
109
|
-
'subscribe_spend_notes',
|
|
110
|
-
{ operation_id: operationId },
|
|
111
|
-
(res) => onSuccess(res),
|
|
112
|
-
onError,
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async awaitSpendOobRefund(operationId: string) {
|
|
117
|
-
return await this.client.rpcSingle('mint', 'await_spend_oob_refund', {
|
|
118
|
-
operation_id: operationId,
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async getNotesByDenomination() {
|
|
123
|
-
return await this.client.rpcSingle<NoteCountByDenomination>(
|
|
124
|
-
'mint',
|
|
125
|
-
'note_counts_by_denomination',
|
|
126
|
-
{},
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { JSONValue } from '../types'
|
|
2
|
-
import { TransportClient } from '../transport'
|
|
3
|
-
|
|
4
|
-
export class RecoveryService {
|
|
5
|
-
constructor(private client: TransportClient) {}
|
|
6
|
-
|
|
7
|
-
async hasPendingRecoveries() {
|
|
8
|
-
return await this.client.rpcSingle<boolean>(
|
|
9
|
-
'',
|
|
10
|
-
'has_pending_recoveries',
|
|
11
|
-
{},
|
|
12
|
-
)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async waitForAllRecoveries() {
|
|
16
|
-
await this.client.rpcSingle('', 'wait_for_all_recoveries', {})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
subscribeToRecoveryProgress(
|
|
20
|
-
onSuccess: (progress: { module_id: number; progress: JSONValue }) => void,
|
|
21
|
-
onError: (error: string) => void,
|
|
22
|
-
) {
|
|
23
|
-
return this.client.rpcStream<{
|
|
24
|
-
module_id: number
|
|
25
|
-
progress: JSONValue
|
|
26
|
-
}>('', 'subscribe_to_recovery_progress', {}, onSuccess, onError)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { expect } from 'vitest'
|
|
2
|
-
import { walletTest } from '../test/fixtures'
|
|
3
|
-
import { TxOutputSummary, WalletSummary } from '../types'
|
|
4
|
-
|
|
5
|
-
walletTest(
|
|
6
|
-
'getWalletSummary should return empty object if wallet is empty',
|
|
7
|
-
async ({ wallet }) => {
|
|
8
|
-
expect(wallet).toBeDefined()
|
|
9
|
-
expect(wallet.isOpen()).toBe(true)
|
|
10
|
-
|
|
11
|
-
const balance = await wallet.balance.getBalance()
|
|
12
|
-
expect(balance).toEqual(0)
|
|
13
|
-
|
|
14
|
-
const summary = await wallet.wallet.getWalletSummary()
|
|
15
|
-
const expectedSummary = {
|
|
16
|
-
spendable_utxos: expect.any(Array<TxOutputSummary>),
|
|
17
|
-
unsigned_peg_out_txos: expect.any(Array<TxOutputSummary>),
|
|
18
|
-
unsigned_change_utxos: expect.any(Array<TxOutputSummary>),
|
|
19
|
-
unconfirmed_peg_out_txos: expect.any(Array<TxOutputSummary>),
|
|
20
|
-
unconfirmed_change_utxos: expect.any(Array<TxOutputSummary>),
|
|
21
|
-
} satisfies WalletSummary
|
|
22
|
-
expect(summary).toEqual(expect.objectContaining(expectedSummary))
|
|
23
|
-
},
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
walletTest(
|
|
27
|
-
'generateAddress should always return an address',
|
|
28
|
-
async ({ wallet }) => {
|
|
29
|
-
expect(wallet).toBeDefined()
|
|
30
|
-
expect(wallet.isOpen()).toBe(true)
|
|
31
|
-
const response = await wallet.wallet.generateAddress()
|
|
32
|
-
|
|
33
|
-
expect(response, 'generateAddress').toEqual({
|
|
34
|
-
deposit_address: expect.any(String),
|
|
35
|
-
operation_id: expect.any(String),
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
walletTest(
|
|
41
|
-
'sendOnchain should return an operation ID after sending funds',
|
|
42
|
-
async ({ fundedWalletBeefy }) => {
|
|
43
|
-
expect(fundedWalletBeefy).toBeDefined()
|
|
44
|
-
expect(fundedWalletBeefy.isOpen()).toBe(true)
|
|
45
|
-
|
|
46
|
-
const amountSat = 100
|
|
47
|
-
const address =
|
|
48
|
-
'bcrt1qphk8q2v8he2autevdcefnnwjl4yc2hm74uuvhaa6nhrnkd3gfrwq6mnr76'
|
|
49
|
-
|
|
50
|
-
const response = await fundedWalletBeefy.wallet.sendOnchain(
|
|
51
|
-
amountSat,
|
|
52
|
-
address,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
expect(response, 'send onchain').toEqual({
|
|
56
|
-
operation_id: expect.any(String),
|
|
57
|
-
})
|
|
58
|
-
},
|
|
59
|
-
)
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
JSONValue,
|
|
3
|
-
WalletSummary,
|
|
4
|
-
GenerateAddressResponse,
|
|
5
|
-
WalletDepositState,
|
|
6
|
-
} from '../types'
|
|
7
|
-
import { TransportClient } from '../transport'
|
|
8
|
-
|
|
9
|
-
export class WalletService {
|
|
10
|
-
constructor(private client: TransportClient) {}
|
|
11
|
-
|
|
12
|
-
async getWalletSummary(): Promise<WalletSummary> {
|
|
13
|
-
return await this.client.rpcSingle('wallet', 'get_wallet_summary', {})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async generateAddress(extraMeta: JSONValue = {}) {
|
|
17
|
-
return await this.client.rpcSingle<GenerateAddressResponse>(
|
|
18
|
-
'wallet',
|
|
19
|
-
'peg_in',
|
|
20
|
-
{
|
|
21
|
-
extra_meta: extraMeta,
|
|
22
|
-
},
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async sendOnchain(
|
|
27
|
-
amountSat: number,
|
|
28
|
-
address: string,
|
|
29
|
-
extraMeta: JSONValue = {},
|
|
30
|
-
): Promise<{ operation_id: string }> {
|
|
31
|
-
return await this.client.rpcSingle('wallet', 'peg_out', {
|
|
32
|
-
amount_sat: amountSat,
|
|
33
|
-
destination_address: address,
|
|
34
|
-
extra_meta: extraMeta,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
subscribeDeposit(
|
|
38
|
-
operation_id: string,
|
|
39
|
-
onSuccess: (state: WalletDepositState) => void = () => {},
|
|
40
|
-
onError: (error: string) => void = () => {},
|
|
41
|
-
) {
|
|
42
|
-
return this.client.rpcStream(
|
|
43
|
-
'ln',
|
|
44
|
-
'subscribe_deposit',
|
|
45
|
-
{ operation_id: operation_id },
|
|
46
|
-
onSuccess,
|
|
47
|
-
onError,
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/services/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { MintService } from './MintService'
|
|
2
|
-
export { BalanceService } from './BalanceService'
|
|
3
|
-
export { LightningService } from './LightningService'
|
|
4
|
-
export { RecoveryService } from './RecoveryService'
|
|
5
|
-
export { FederationService } from './FederationService'
|
|
6
|
-
export { WalletService } from './WalletService'
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FedimintWallet } from '../FedimintWallet'
|
|
2
|
-
import { TransportClient } from '../transport/TransportClient'
|
|
3
|
-
import { TestingService } from './TestingService'
|
|
4
|
-
|
|
5
|
-
export class TestFedimintWallet extends FedimintWallet {
|
|
6
|
-
public testing: TestingService
|
|
7
|
-
|
|
8
|
-
constructor(_client: TransportClient) {
|
|
9
|
-
super(_client)
|
|
10
|
-
this.testing = new TestingService(_client, this.lightning)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async fundWallet(amountMSats: number) {
|
|
14
|
-
const info = await this.testing.getFaucetGatewayInfo()
|
|
15
|
-
const invoice = await this.lightning.createInvoice(
|
|
16
|
-
amountMSats,
|
|
17
|
-
'',
|
|
18
|
-
1000,
|
|
19
|
-
info,
|
|
20
|
-
)
|
|
21
|
-
await Promise.all([
|
|
22
|
-
this.testing.payFaucetInvoice(invoice.invoice),
|
|
23
|
-
this.lightning.waitForReceive(invoice.operation_id),
|
|
24
|
-
])
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Method to expose the TransportClient
|
|
28
|
-
getTransportClient(): TransportClient {
|
|
29
|
-
return this['_client']
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { WasmWorkerTransport } from '../transport/wasmTransport/WasmWorkerTransport'
|
|
2
|
-
import { Transport } from '../types'
|
|
3
|
-
import { WalletDirector } from '../WalletDirector'
|
|
4
|
-
import { TestFedimintWallet } from './TestFedimintWallet'
|
|
5
|
-
|
|
6
|
-
export class TestWalletDirector extends WalletDirector {
|
|
7
|
-
constructor(client: Transport = new WasmWorkerTransport()) {
|
|
8
|
-
super(client)
|
|
9
|
-
}
|
|
10
|
-
async createTestWallet() {
|
|
11
|
-
await this._client.initialize()
|
|
12
|
-
return new TestFedimintWallet(this._client)
|
|
13
|
-
}
|
|
14
|
-
}
|