@breeztech/breez-sdk-spark 0.27.2 → 0.28.0
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 +9 -8
- package/bundler/breez_sdk_spark_wasm.d.ts +141 -16
- package/bundler/breez_sdk_spark_wasm.js +1 -1
- package/bundler/breez_sdk_spark_wasm_bg.js +190 -40
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +23 -11
- package/bundler/index.js +6 -13
- package/bundler/storage/index.js +89 -17
- package/deno/breez_sdk_spark_wasm.d.ts +141 -16
- package/deno/breez_sdk_spark_wasm.js +190 -40
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +23 -11
- package/nodejs/breez_sdk_spark_wasm.d.ts +141 -16
- package/nodejs/breez_sdk_spark_wasm.js +194 -40
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +23 -11
- package/nodejs/index.d.mts +3 -0
- package/nodejs/index.js +30 -120
- package/nodejs/index.mjs +4 -0
- package/nodejs/mysql-session-store/index.cjs +24 -7
- package/nodejs/mysql-session-store/migrations.cjs +6 -0
- package/nodejs/mysql-storage/index.cjs +36 -19
- package/nodejs/mysql-storage/migrations.cjs +24 -9
- package/nodejs/mysql-token-store/index.cjs +28 -18
- package/nodejs/postgres-session-store/index.cjs +25 -7
- package/nodejs/postgres-session-store/migrations.cjs +12 -9
- package/nodejs/postgres-storage/index.cjs +36 -19
- package/nodejs/postgres-storage/migrations.cjs +24 -9
- package/nodejs/postgres-token-store/index.cjs +32 -18
- package/nodejs/postgres-token-store/migrations.cjs +5 -9
- package/nodejs/postgres-tree-store/migrations.cjs +5 -9
- package/nodejs/storage/index.cjs +35 -14
- package/nodejs/storage/migrations.cjs +25 -15
- package/nodejs/tree-store/index.cjs +1 -1
- package/nodejs/tree-store/migrations.cjs +6 -13
- package/package.json +27 -6
- package/ssr/index.js +24 -0
- package/web/breez_sdk_spark_wasm.d.ts +164 -27
- package/web/breez_sdk_spark_wasm.js +190 -40
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +23 -11
- package/web/index.js +6 -13
- package/web/passkey-prf-provider/index.js +1 -0
- package/web/storage/index.js +89 -17
- package/breez-sdk-spark.tgz +0 -0
- package/itest/.gitignore +0 -2
- package/itest/database-drivers.test.js +0 -45
- package/itest/helpers/assert.test.js +0 -70
- package/itest/helpers/faucet.js +0 -68
- package/itest/helpers/lnurl-fixture.js +0 -229
- package/itest/helpers/scenario.js +0 -444
- package/itest/package-lock.json +0 -519
- package/itest/package.json +0 -18
- package/itest/scenarios.test.js +0 -47
- package/itest/smoke.test.js +0 -184
package/itest/smoke.test.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// Smoke test for the npm package API, exercised the way the reference web
|
|
4
|
-
// app uses it (packages/wasm/examples/web): SdkBuilder + default storage,
|
|
5
|
-
// events, receive, parse, send between two instances, payment listing, and
|
|
6
|
-
// lnurl-pay against the docker LNURL fixture. Deep per-command behavior
|
|
7
|
-
// lives in the shared CLI scenarios; this pins the API surface itself.
|
|
8
|
-
|
|
9
|
-
require('dotenv').config()
|
|
10
|
-
|
|
11
|
-
const assert = require('node:assert/strict')
|
|
12
|
-
const fs = require('fs')
|
|
13
|
-
const os = require('os')
|
|
14
|
-
const path = require('path')
|
|
15
|
-
const test = require('node:test')
|
|
16
|
-
|
|
17
|
-
const { defaultConfig, SdkBuilder } = require('@breeztech/breez-sdk-spark/nodejs')
|
|
18
|
-
|
|
19
|
-
const { fundAddress } = require('./helpers/faucet')
|
|
20
|
-
const { LnurlFixture, dockerAvailable } = require('./helpers/lnurl-fixture')
|
|
21
|
-
|
|
22
|
-
function sleep(ms) {
|
|
23
|
-
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Queue-backed event listener with a predicate wait. */
|
|
27
|
-
class EventQueue {
|
|
28
|
-
constructor() {
|
|
29
|
-
this.events = []
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
onEvent(event) {
|
|
33
|
-
this.events.push(event)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async waitFor(predicate, timeoutMs) {
|
|
37
|
-
const deadline = Date.now() + timeoutMs
|
|
38
|
-
for (;;) {
|
|
39
|
-
const event = this.events.find(predicate)
|
|
40
|
-
if (event !== undefined) {
|
|
41
|
-
return event
|
|
42
|
-
}
|
|
43
|
-
if (Date.now() >= deadline) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`timed out waiting for event; seen: ${this.events.map((e) => e.type).join(', ')}`
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
await sleep(200)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function connectWallet(name, lnurlDomain) {
|
|
54
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), `breez-smoke-${name}-`))
|
|
55
|
-
let sdk
|
|
56
|
-
try {
|
|
57
|
-
const config = defaultConfig('regtest')
|
|
58
|
-
if (lnurlDomain !== undefined) {
|
|
59
|
-
config.lnurlDomain = lnurlDomain
|
|
60
|
-
}
|
|
61
|
-
const mnemonic = require('bip39').generateMnemonic()
|
|
62
|
-
let builder = SdkBuilder.new(config, { type: 'mnemonic', mnemonic })
|
|
63
|
-
builder = await builder.withDefaultStorage(dir)
|
|
64
|
-
sdk = await builder.build()
|
|
65
|
-
const events = new EventQueue()
|
|
66
|
-
await sdk.addEventListener(events)
|
|
67
|
-
return { sdk, events, dir }
|
|
68
|
-
} catch (e) {
|
|
69
|
-
// Partial failure leaves nothing behind: the caller only cleans up
|
|
70
|
-
// wallets it received.
|
|
71
|
-
await sdk?.disconnect().catch(() => {})
|
|
72
|
-
fs.rmSync(dir, { recursive: true, force: true })
|
|
73
|
-
throw e
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function waitForBalance(sdk, floorSats, timeoutMs) {
|
|
78
|
-
const deadline = Date.now() + timeoutMs
|
|
79
|
-
for (;;) {
|
|
80
|
-
const info = await sdk.getInfo({ ensureSynced: true })
|
|
81
|
-
if (info.balanceSats >= floorSats) {
|
|
82
|
-
return info
|
|
83
|
-
}
|
|
84
|
-
if (Date.now() >= deadline) {
|
|
85
|
-
throw new Error(`balance stayed below ${floorSats} (last: ${info.balanceSats})`)
|
|
86
|
-
}
|
|
87
|
-
await sleep(5000)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
test('npm API smoke: connect, receive, parse, pay, list, lnurl-pay', async (t) => {
|
|
92
|
-
if (!process.env.FAUCET_USERNAME) {
|
|
93
|
-
t.skip('FAUCET_USERNAME not set')
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
const haveDocker = dockerAvailable()
|
|
97
|
-
|
|
98
|
-
let lnurl
|
|
99
|
-
const wallets = []
|
|
100
|
-
try {
|
|
101
|
-
if (haveDocker) {
|
|
102
|
-
lnurl = await LnurlFixture.start()
|
|
103
|
-
}
|
|
104
|
-
const alice = await connectWallet('alice')
|
|
105
|
-
wallets.push(alice)
|
|
106
|
-
const bob = await connectWallet('bob', lnurl?.httpUrl)
|
|
107
|
-
wallets.push(bob)
|
|
108
|
-
|
|
109
|
-
// Balance and event surface on a fresh wallet.
|
|
110
|
-
const info = await alice.sdk.getInfo({ ensureSynced: true })
|
|
111
|
-
assert.equal(info.balanceSats, 0)
|
|
112
|
-
assert.equal(typeof info.identityPubkey, 'string')
|
|
113
|
-
await alice.events.waitFor((e) => e.type === 'synced', 30_000)
|
|
114
|
-
|
|
115
|
-
// Receive requests and parsing.
|
|
116
|
-
const bolt11 = await alice.sdk.receivePayment({
|
|
117
|
-
paymentMethod: { type: 'bolt11Invoice', description: 'smoke test', amountSats: 2500 }
|
|
118
|
-
})
|
|
119
|
-
const parsed = await alice.sdk.parse(bolt11.paymentRequest)
|
|
120
|
-
assert.equal(parsed.type, 'bolt11Invoice')
|
|
121
|
-
assert.equal(parsed.amountMsat, 2_500_000)
|
|
122
|
-
assert.equal(parsed.description, 'smoke test')
|
|
123
|
-
|
|
124
|
-
const bobAddress = await bob.sdk.receivePayment({ paymentMethod: { type: 'sparkAddress' } })
|
|
125
|
-
assert.equal((await bob.sdk.parse(bobAddress.paymentRequest)).type, 'sparkAddress')
|
|
126
|
-
|
|
127
|
-
// Fund alice through an on-chain deposit and wait for the auto-claim.
|
|
128
|
-
const deposit = await alice.sdk.receivePayment({ paymentMethod: { type: 'bitcoinAddress' } })
|
|
129
|
-
await fundAddress(deposit.paymentRequest, 50_000)
|
|
130
|
-
await waitForBalance(alice.sdk, 40_000, 180_000)
|
|
131
|
-
|
|
132
|
-
// Spark payment alice -> bob.
|
|
133
|
-
const prepared = await alice.sdk.prepareSendPayment({
|
|
134
|
-
paymentRequest: { type: 'input', input: bobAddress.paymentRequest },
|
|
135
|
-
amount: 1000n
|
|
136
|
-
})
|
|
137
|
-
assert.equal(prepared.paymentMethod.type, 'sparkAddress')
|
|
138
|
-
const sent = await alice.sdk.sendPayment({ prepareResponse: prepared })
|
|
139
|
-
assert.equal(sent.payment.status, 'completed')
|
|
140
|
-
assert.equal(sent.payment.paymentType, 'send')
|
|
141
|
-
|
|
142
|
-
const fetched = await alice.sdk.getPayment({ paymentId: sent.payment.id })
|
|
143
|
-
assert.equal(fetched.payment.id, sent.payment.id)
|
|
144
|
-
const listed = await alice.sdk.listPayments({})
|
|
145
|
-
assert.ok(listed.payments.some((p) => p.id === sent.payment.id))
|
|
146
|
-
|
|
147
|
-
await waitForBalance(bob.sdk, 1000, 90_000)
|
|
148
|
-
|
|
149
|
-
// lnurl-pay against the local LNURL server (docker only).
|
|
150
|
-
if (haveDocker) {
|
|
151
|
-
const registered = await bob.sdk.registerLightningAddress({
|
|
152
|
-
username: 'smoketest',
|
|
153
|
-
description: 'smoke test address'
|
|
154
|
-
})
|
|
155
|
-
const lnAddress = await alice.sdk.parse(registered.lightningAddress)
|
|
156
|
-
assert.equal(lnAddress.type, 'lightningAddress')
|
|
157
|
-
const preparedLnurl = await alice.sdk.prepareLnurlPay({
|
|
158
|
-
amount: 1500n,
|
|
159
|
-
payRequest: lnAddress.payRequest,
|
|
160
|
-
comment: 'smoke comment'
|
|
161
|
-
})
|
|
162
|
-
// The payment can return pending: completion needs the receiver to
|
|
163
|
-
// claim, so poll until the preimage is released.
|
|
164
|
-
const paid = await alice.sdk.lnurlPay({ prepareResponse: preparedLnurl })
|
|
165
|
-
const deadline = Date.now() + 120_000
|
|
166
|
-
let status = paid.payment.status
|
|
167
|
-
while (status !== 'completed') {
|
|
168
|
-
if (Date.now() >= deadline) {
|
|
169
|
-
throw new Error(`lnurl payment stayed ${status}`)
|
|
170
|
-
}
|
|
171
|
-
await sleep(5000)
|
|
172
|
-
status = (await alice.sdk.getPayment({ paymentId: paid.payment.id })).payment.status
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
console.error('skipping lnurl-pay part: docker not available')
|
|
176
|
-
}
|
|
177
|
-
} finally {
|
|
178
|
-
for (const wallet of wallets) {
|
|
179
|
-
await wallet.sdk.disconnect().catch(() => {})
|
|
180
|
-
fs.rmSync(wallet.dir, { recursive: true, force: true })
|
|
181
|
-
}
|
|
182
|
-
lnurl?.stop()
|
|
183
|
-
}
|
|
184
|
-
})
|