@breeztech/breez-sdk-spark 0.19.2 → 0.21.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/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +170 -12
- package/bundler/breez_sdk_spark_wasm.js +1 -1
- package/bundler/breez_sdk_spark_wasm_bg.js +186 -44
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +11 -0
- package/deno/breez_sdk_spark_wasm.d.ts +170 -12
- package/deno/breez_sdk_spark_wasm.js +186 -44
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +11 -0
- package/itest/.gitignore +2 -0
- package/itest/helpers/assert.test.js +70 -0
- package/itest/helpers/faucet.js +68 -0
- package/itest/helpers/lnurl-fixture.js +229 -0
- package/itest/helpers/scenario.js +444 -0
- package/itest/package-lock.json +519 -0
- package/itest/package.json +18 -0
- package/itest/scenarios.test.js +47 -0
- package/itest/smoke.test.js +184 -0
- package/nodejs/breez_sdk_spark_wasm.d.ts +170 -12
- package/nodejs/breez_sdk_spark_wasm.js +188 -44
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +11 -0
- package/nodejs/index.mjs +2 -0
- package/nodejs/mysql-token-store/index.cjs +302 -205
- package/nodejs/mysql-tree-store/index.cjs +43 -24
- package/nodejs/postgres-token-store/index.cjs +284 -205
- package/nodejs/postgres-tree-store/index.cjs +33 -17
- package/package.json +1 -1
- package/ssr/index.js +12 -0
- package/web/breez_sdk_spark_wasm.d.ts +181 -12
- package/web/breez_sdk_spark_wasm.js +186 -44
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +11 -0
- package/web/passkey-prf-provider/index.d.ts +9 -2
- package/web/passkey-prf-provider/index.js +49 -11
|
@@ -35,6 +35,16 @@ export class BitcoinChainServiceHandle {
|
|
|
35
35
|
const ret = wasm.bitcoinchainservicehandle_broadcastTransaction(this.__wbg_ptr, ptr0, len0);
|
|
36
36
|
return ret;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} address
|
|
40
|
+
* @returns {Promise<any>}
|
|
41
|
+
*/
|
|
42
|
+
getAddressTxos(address) {
|
|
43
|
+
const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
44
|
+
const len0 = WASM_VECTOR_LEN;
|
|
45
|
+
const ret = wasm.bitcoinchainservicehandle_getAddressTxos(this.__wbg_ptr, ptr0, len0);
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
38
48
|
/**
|
|
39
49
|
* @param {string} address
|
|
40
50
|
* @returns {Promise<any>}
|
|
@@ -45,6 +55,17 @@ export class BitcoinChainServiceHandle {
|
|
|
45
55
|
const ret = wasm.bitcoinchainservicehandle_getAddressUtxos(this.__wbg_ptr, ptr0, len0);
|
|
46
56
|
return ret;
|
|
47
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} txid
|
|
60
|
+
* @param {number} vout
|
|
61
|
+
* @returns {Promise<any>}
|
|
62
|
+
*/
|
|
63
|
+
getOutspend(txid, vout) {
|
|
64
|
+
const ptr0 = passStringToWasm0(txid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
65
|
+
const len0 = WASM_VECTOR_LEN;
|
|
66
|
+
const ret = wasm.bitcoinchainservicehandle_getOutspend(this.__wbg_ptr, ptr0, len0, vout);
|
|
67
|
+
return ret;
|
|
68
|
+
}
|
|
48
69
|
/**
|
|
49
70
|
* @param {string} txid
|
|
50
71
|
* @returns {Promise<any>}
|
|
@@ -116,6 +137,14 @@ export class BreezSdk {
|
|
|
116
137
|
const ret = wasm.breezsdk_authorizeLightningAddressTransfer(this.__wbg_ptr, request);
|
|
117
138
|
return ret;
|
|
118
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* @param {BuildUnsignedBatchPackageRequest} request
|
|
142
|
+
* @returns {Promise<UnsignedTransferPackage>}
|
|
143
|
+
*/
|
|
144
|
+
buildUnsignedBatchPackage(request) {
|
|
145
|
+
const ret = wasm.breezsdk_buildUnsignedBatchPackage(this.__wbg_ptr, request);
|
|
146
|
+
return ret;
|
|
147
|
+
}
|
|
119
148
|
/**
|
|
120
149
|
* @param {BuildUnsignedLnurlPayPackageRequest} request
|
|
121
150
|
* @returns {Promise<UnsignedTransferPackage>}
|
|
@@ -360,6 +389,14 @@ export class BreezSdk {
|
|
|
360
389
|
const ret = wasm.breezsdk_prepareLnurlPay(this.__wbg_ptr, request);
|
|
361
390
|
return ret;
|
|
362
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* @param {PrepareSendBatchRequest} request
|
|
394
|
+
* @returns {Promise<PrepareSendBatchResponse>}
|
|
395
|
+
*/
|
|
396
|
+
prepareSendBatch(request) {
|
|
397
|
+
const ret = wasm.breezsdk_prepareSendBatch(this.__wbg_ptr, request);
|
|
398
|
+
return ret;
|
|
399
|
+
}
|
|
363
400
|
/**
|
|
364
401
|
* @param {PrepareSendPaymentRequest} request
|
|
365
402
|
* @returns {Promise<PrepareSendPaymentResponse>}
|
|
@@ -368,6 +405,14 @@ export class BreezSdk {
|
|
|
368
405
|
const ret = wasm.breezsdk_prepareSendPayment(this.__wbg_ptr, request);
|
|
369
406
|
return ret;
|
|
370
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* @param {PrepareUnilateralExitRequest} request
|
|
410
|
+
* @returns {Promise<PrepareUnilateralExitResponse>}
|
|
411
|
+
*/
|
|
412
|
+
prepareUnilateralExit(request) {
|
|
413
|
+
const ret = wasm.breezsdk_prepareUnilateralExit(this.__wbg_ptr, request);
|
|
414
|
+
return ret;
|
|
415
|
+
}
|
|
371
416
|
/**
|
|
372
417
|
* @param {PublishSignedLnurlPayPackageRequest} request
|
|
373
418
|
* @returns {Promise<PublishSignedLnurlPayResponse>}
|
|
@@ -408,7 +453,7 @@ export class BreezSdk {
|
|
|
408
453
|
return ret;
|
|
409
454
|
}
|
|
410
455
|
/**
|
|
411
|
-
* @returns {Promise<
|
|
456
|
+
* @returns {Promise<RefundPendingConversionsResponse>}
|
|
412
457
|
*/
|
|
413
458
|
refundPendingConversions() {
|
|
414
459
|
const ret = wasm.breezsdk_refundPendingConversions(this.__wbg_ptr);
|
|
@@ -440,6 +485,14 @@ export class BreezSdk {
|
|
|
440
485
|
const ret = wasm.breezsdk_removeEventListener(this.__wbg_ptr, ptr0, len0);
|
|
441
486
|
return ret;
|
|
442
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* @param {SendBatchRequest} request
|
|
490
|
+
* @returns {Promise<SendBatchResponse>}
|
|
491
|
+
*/
|
|
492
|
+
sendBatch(request) {
|
|
493
|
+
const ret = wasm.breezsdk_sendBatch(this.__wbg_ptr, request);
|
|
494
|
+
return ret;
|
|
495
|
+
}
|
|
443
496
|
/**
|
|
444
497
|
* @param {SendPaymentRequest} request
|
|
445
498
|
* @returns {Promise<SendPaymentResponse>}
|
|
@@ -464,6 +517,15 @@ export class BreezSdk {
|
|
|
464
517
|
const ret = wasm.breezsdk_syncWallet(this.__wbg_ptr, request);
|
|
465
518
|
return ret;
|
|
466
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* @param {UnilateralExitRequest} request
|
|
522
|
+
* @param {CpfpSigner} signer
|
|
523
|
+
* @returns {Promise<UnilateralExitResponse>}
|
|
524
|
+
*/
|
|
525
|
+
unilateralExit(request, signer) {
|
|
526
|
+
const ret = wasm.breezsdk_unilateralExit(this.__wbg_ptr, request, signer);
|
|
527
|
+
return ret;
|
|
528
|
+
}
|
|
467
529
|
/**
|
|
468
530
|
* @param {UnregisterWebhookRequest} request
|
|
469
531
|
* @returns {Promise<void>}
|
|
@@ -491,6 +553,39 @@ export class BreezSdk {
|
|
|
491
553
|
}
|
|
492
554
|
if (Symbol.dispose) BreezSdk.prototype[Symbol.dispose] = BreezSdk.prototype.free;
|
|
493
555
|
|
|
556
|
+
/**
|
|
557
|
+
* A CPFP signer matching the `CpfpSigner` TypeScript interface.
|
|
558
|
+
*/
|
|
559
|
+
export class DefaultCpfpSigner {
|
|
560
|
+
static __wrap(ptr) {
|
|
561
|
+
const obj = Object.create(DefaultCpfpSigner.prototype);
|
|
562
|
+
obj.__wbg_ptr = ptr;
|
|
563
|
+
DefaultCpfpSignerFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
564
|
+
return obj;
|
|
565
|
+
}
|
|
566
|
+
__destroy_into_raw() {
|
|
567
|
+
const ptr = this.__wbg_ptr;
|
|
568
|
+
this.__wbg_ptr = 0;
|
|
569
|
+
DefaultCpfpSignerFinalization.unregister(this);
|
|
570
|
+
return ptr;
|
|
571
|
+
}
|
|
572
|
+
free() {
|
|
573
|
+
const ptr = this.__destroy_into_raw();
|
|
574
|
+
wasm.__wbg_defaultcpfpsigner_free(ptr, 0);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* @param {Uint8Array} psbt_bytes
|
|
578
|
+
* @returns {Promise<Uint8Array>}
|
|
579
|
+
*/
|
|
580
|
+
signPsbt(psbt_bytes) {
|
|
581
|
+
const ptr0 = passArray8ToWasm0(psbt_bytes, wasm.__wbindgen_malloc);
|
|
582
|
+
const len0 = WASM_VECTOR_LEN;
|
|
583
|
+
const ret = wasm.defaultcpfpsigner_signPsbt(this.__wbg_ptr, ptr0, len0);
|
|
584
|
+
return ret;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (Symbol.dispose) DefaultCpfpSigner.prototype[Symbol.dispose] = DefaultCpfpSigner.prototype.free;
|
|
588
|
+
|
|
494
589
|
/**
|
|
495
590
|
* A JS handle to a backend's own session store (from `defaultSessionStore`),
|
|
496
591
|
* exposing the same `getSession` / `setSession` interface. Wrap it in a JS
|
|
@@ -880,6 +975,17 @@ export class ExternalSparkSignerHandle {
|
|
|
880
975
|
const ret = wasm.externalsparksignerhandle_signFrost(this.__wbg_ptr, ptr0, len0);
|
|
881
976
|
return ret;
|
|
882
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* @param {ExternalTreeNodeId} leaf_id
|
|
980
|
+
* @param {Uint8Array} sighash
|
|
981
|
+
* @returns {Promise<SchnorrSignatureBytes>}
|
|
982
|
+
*/
|
|
983
|
+
signLeafRefundSpend(leaf_id, sighash) {
|
|
984
|
+
const ptr0 = passArray8ToWasm0(sighash, wasm.__wbindgen_malloc);
|
|
985
|
+
const len0 = WASM_VECTOR_LEN;
|
|
986
|
+
const ret = wasm.externalsparksignerhandle_signLeafRefundSpend(this.__wbg_ptr, leaf_id, ptr0, len0);
|
|
987
|
+
return ret;
|
|
988
|
+
}
|
|
883
989
|
/**
|
|
884
990
|
* @param {Uint8Array} message
|
|
885
991
|
* @returns {Promise<EcdsaSignatureBytes>}
|
|
@@ -1794,6 +1900,21 @@ export function postgresStorage(config) {
|
|
|
1794
1900
|
return WasmStorageConfig.__wrap(ret);
|
|
1795
1901
|
}
|
|
1796
1902
|
|
|
1903
|
+
/**
|
|
1904
|
+
* Creates a default CPFP signer backed by a single private key.
|
|
1905
|
+
* @param {Uint8Array} secret_key_bytes
|
|
1906
|
+
* @returns {DefaultCpfpSigner}
|
|
1907
|
+
*/
|
|
1908
|
+
export function singleKeyCpfpSigner(secret_key_bytes) {
|
|
1909
|
+
const ptr0 = passArray8ToWasm0(secret_key_bytes, wasm.__wbindgen_malloc);
|
|
1910
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1911
|
+
const ret = wasm.singleKeyCpfpSigner(ptr0, len0);
|
|
1912
|
+
if (ret[2]) {
|
|
1913
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1914
|
+
}
|
|
1915
|
+
return DefaultCpfpSigner.__wrap(ret[0]);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1797
1918
|
/**
|
|
1798
1919
|
* Runs automatically when the wasm module is instantiated. Installs the
|
|
1799
1920
|
* panic hook so Rust panics surface as readable `console.error` output
|
|
@@ -2103,8 +2224,8 @@ function __wbg_get_imports() {
|
|
|
2103
2224
|
const ret = createMysqlTreeStoreWithPool(arg0, getArrayU8FromWasm0(arg1, arg2), arg3, arg4, arg5 !== 0);
|
|
2104
2225
|
return ret;
|
|
2105
2226
|
}, arguments); },
|
|
2106
|
-
|
|
2107
|
-
const ret = arg0.createPasskey(arg1);
|
|
2227
|
+
__wbg_createPasskey_37eb4d30fdaf2a3f: function() { return handleError(function (arg0, arg1, arg2) {
|
|
2228
|
+
const ret = arg0.createPasskey(arg1, arg2);
|
|
2108
2229
|
return ret;
|
|
2109
2230
|
}, arguments); },
|
|
2110
2231
|
__wbg_createPostgresPool_3c396c7ab2f0eab2: function() { return handleError(function (arg0) {
|
|
@@ -2329,6 +2450,18 @@ function __wbg_get_imports() {
|
|
|
2329
2450
|
const ret = Array.from(arg0);
|
|
2330
2451
|
return ret;
|
|
2331
2452
|
},
|
|
2453
|
+
__wbg_getAddressTxos_3ca1c4b39dd84911: function() { return handleError(function (arg0, arg1, arg2) {
|
|
2454
|
+
let deferred0_0;
|
|
2455
|
+
let deferred0_1;
|
|
2456
|
+
try {
|
|
2457
|
+
deferred0_0 = arg1;
|
|
2458
|
+
deferred0_1 = arg2;
|
|
2459
|
+
const ret = arg0.getAddressTxos(getStringFromWasm0(arg1, arg2));
|
|
2460
|
+
return ret;
|
|
2461
|
+
} finally {
|
|
2462
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
2463
|
+
}
|
|
2464
|
+
}, arguments); },
|
|
2332
2465
|
__wbg_getAddressUtxos_9526b6d8078b867e: function() { return handleError(function (arg0, arg1, arg2) {
|
|
2333
2466
|
let deferred0_0;
|
|
2334
2467
|
let deferred0_1;
|
|
@@ -2394,6 +2527,18 @@ function __wbg_get_imports() {
|
|
|
2394
2527
|
const ret = arg0.getLeaves();
|
|
2395
2528
|
return ret;
|
|
2396
2529
|
}, arguments); },
|
|
2530
|
+
__wbg_getOutspend_4b3c117972515790: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
2531
|
+
let deferred0_0;
|
|
2532
|
+
let deferred0_1;
|
|
2533
|
+
try {
|
|
2534
|
+
deferred0_0 = arg1;
|
|
2535
|
+
deferred0_1 = arg2;
|
|
2536
|
+
const ret = arg0.getOutspend(getStringFromWasm0(arg1, arg2), arg3 >>> 0);
|
|
2537
|
+
return ret;
|
|
2538
|
+
} finally {
|
|
2539
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
2540
|
+
}
|
|
2541
|
+
}, arguments); },
|
|
2397
2542
|
__wbg_getPaymentById_6d677ada5879df99: function() { return handleError(function (arg0, arg1, arg2) {
|
|
2398
2543
|
let deferred0_0;
|
|
2399
2544
|
let deferred0_1;
|
|
@@ -2947,38 +3092,28 @@ function __wbg_get_imports() {
|
|
|
2947
3092
|
const ret = module.require;
|
|
2948
3093
|
return ret;
|
|
2949
3094
|
}, arguments); },
|
|
2950
|
-
|
|
3095
|
+
__wbg_reserveTokenOutputsByOutpoints_2b3aa01becdba378: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
2951
3096
|
let deferred0_0;
|
|
2952
3097
|
let deferred0_1;
|
|
2953
|
-
let deferred1_0;
|
|
2954
|
-
let deferred1_1;
|
|
2955
3098
|
try {
|
|
2956
|
-
deferred0_0 =
|
|
2957
|
-
deferred0_1 =
|
|
2958
|
-
|
|
2959
|
-
deferred1_1 = arg5;
|
|
2960
|
-
const ret = arg0.reserveTokenOutputsByOutpoints(getStringFromWasm0(arg1, arg2), arg3, getStringFromWasm0(arg4, arg5));
|
|
3099
|
+
deferred0_0 = arg2;
|
|
3100
|
+
deferred0_1 = arg3;
|
|
3101
|
+
const ret = arg0.reserveTokenOutputsByOutpoints(arg1, getStringFromWasm0(arg2, arg3));
|
|
2961
3102
|
return ret;
|
|
2962
3103
|
} finally {
|
|
2963
3104
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
2964
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
2965
3105
|
}
|
|
2966
3106
|
}, arguments); },
|
|
2967
|
-
|
|
3107
|
+
__wbg_reserveTokenOutputs_17ba3b5fcc91b000: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
2968
3108
|
let deferred0_0;
|
|
2969
3109
|
let deferred0_1;
|
|
2970
|
-
let deferred1_0;
|
|
2971
|
-
let deferred1_1;
|
|
2972
3110
|
try {
|
|
2973
|
-
deferred0_0 =
|
|
2974
|
-
deferred0_1 =
|
|
2975
|
-
|
|
2976
|
-
deferred1_1 = arg5;
|
|
2977
|
-
const ret = arg0.reserveTokenOutputs(getStringFromWasm0(arg1, arg2), arg3, getStringFromWasm0(arg4, arg5), arg6, arg7);
|
|
3111
|
+
deferred0_0 = arg2;
|
|
3112
|
+
deferred0_1 = arg3;
|
|
3113
|
+
const ret = arg0.reserveTokenOutputs(arg1, getStringFromWasm0(arg2, arg3), arg4, arg5);
|
|
2978
3114
|
return ret;
|
|
2979
3115
|
} finally {
|
|
2980
3116
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
2981
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
2982
3117
|
}
|
|
2983
3118
|
}, arguments); },
|
|
2984
3119
|
__wbg_resolve_9feb5d906ca62419: function(arg0) {
|
|
@@ -2992,17 +3127,9 @@ function __wbg_get_imports() {
|
|
|
2992
3127
|
const ret = SdkBuilder.__wrap(arg0);
|
|
2993
3128
|
return ret;
|
|
2994
3129
|
},
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
try {
|
|
2999
|
-
deferred0_0 = arg1;
|
|
3000
|
-
deferred0_1 = arg2;
|
|
3001
|
-
const ret = arg0.selectTokenOutputs(getStringFromWasm0(arg1, arg2), arg3, arg4, arg5);
|
|
3002
|
-
return ret;
|
|
3003
|
-
} finally {
|
|
3004
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
3005
|
-
}
|
|
3130
|
+
__wbg_selectTokenOutputs_378aebd65f866d1b: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
3131
|
+
const ret = arg0.selectTokenOutputs(arg1, arg2, arg3);
|
|
3132
|
+
return ret;
|
|
3006
3133
|
}, arguments); },
|
|
3007
3134
|
__wbg_send_0edb796d05cd3239: function() { return handleError(function (arg0, arg1, arg2) {
|
|
3008
3135
|
arg0.send(getStringFromWasm0(arg1, arg2));
|
|
@@ -3223,12 +3350,24 @@ function __wbg_get_imports() {
|
|
|
3223
3350
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
3224
3351
|
}
|
|
3225
3352
|
}, arguments); },
|
|
3353
|
+
__wbg_signLeafRefundSpend_dc0eea305a0dde9c: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
3354
|
+
var v0 = getArrayU8FromWasm0(arg2, arg3).slice();
|
|
3355
|
+
wasm.__wbindgen_free(arg2, arg3 * 1, 1);
|
|
3356
|
+
const ret = arg0.signLeafRefundSpend(arg1, v0);
|
|
3357
|
+
return ret;
|
|
3358
|
+
}, arguments); },
|
|
3226
3359
|
__wbg_signMessage_80ec0b0dfc7f00ee: function() { return handleError(function (arg0, arg1, arg2) {
|
|
3227
3360
|
var v0 = getArrayU8FromWasm0(arg1, arg2).slice();
|
|
3228
3361
|
wasm.__wbindgen_free(arg1, arg2 * 1, 1);
|
|
3229
3362
|
const ret = arg0.signMessage(v0);
|
|
3230
3363
|
return ret;
|
|
3231
3364
|
}, arguments); },
|
|
3365
|
+
__wbg_signPsbt_625c8cbdec488cc6: function() { return handleError(function (arg0, arg1, arg2) {
|
|
3366
|
+
var v0 = getArrayU8FromWasm0(arg1, arg2).slice();
|
|
3367
|
+
wasm.__wbindgen_free(arg1, arg2 * 1, 1);
|
|
3368
|
+
const ret = arg0.signPsbt(v0);
|
|
3369
|
+
return ret;
|
|
3370
|
+
}, arguments); },
|
|
3232
3371
|
__wbg_signSparkInvoice_cca6c7f35b5e85d2: function() { return handleError(function (arg0, arg1) {
|
|
3233
3372
|
const ret = arg0.signSparkInvoice(arg1);
|
|
3234
3373
|
return ret;
|
|
@@ -3440,62 +3579,62 @@ function __wbg_get_imports() {
|
|
|
3440
3579
|
return ret;
|
|
3441
3580
|
},
|
|
3442
3581
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
3443
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
3582
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
3444
3583
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h21f6855640435575);
|
|
3445
3584
|
return ret;
|
|
3446
3585
|
},
|
|
3447
3586
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
3448
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
3587
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 392, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3449
3588
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h3120db8c4a8a92b2);
|
|
3450
3589
|
return ret;
|
|
3451
3590
|
},
|
|
3452
3591
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
3453
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx:
|
|
3592
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 392, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3454
3593
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h3120db8c4a8a92b2_2);
|
|
3455
3594
|
return ret;
|
|
3456
3595
|
},
|
|
3457
3596
|
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
3458
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("ErrorEvent")], shim_idx:
|
|
3597
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("ErrorEvent")], shim_idx: 392, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3459
3598
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h3120db8c4a8a92b2_3);
|
|
3460
3599
|
return ret;
|
|
3461
3600
|
},
|
|
3462
3601
|
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
|
3463
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx:
|
|
3602
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 392, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3464
3603
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h3120db8c4a8a92b2_4);
|
|
3465
3604
|
return ret;
|
|
3466
3605
|
},
|
|
3467
3606
|
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
|
|
3468
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx:
|
|
3607
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 392, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3469
3608
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h3120db8c4a8a92b2_5);
|
|
3470
3609
|
return ret;
|
|
3471
3610
|
},
|
|
3472
3611
|
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
|
|
3473
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("SessionStore")], shim_idx:
|
|
3612
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("SessionStore")], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
3474
3613
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h21f6855640435575_6);
|
|
3475
3614
|
return ret;
|
|
3476
3615
|
},
|
|
3477
3616
|
__wbindgen_cast_0000000000000008: function(arg0, arg1) {
|
|
3478
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Storage")], shim_idx:
|
|
3617
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Storage")], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
3479
3618
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h21f6855640435575_7);
|
|
3480
3619
|
return ret;
|
|
3481
3620
|
},
|
|
3482
3621
|
__wbindgen_cast_0000000000000009: function(arg0, arg1) {
|
|
3483
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("TokenStore")], shim_idx:
|
|
3622
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("TokenStore")], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
3484
3623
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h21f6855640435575_8);
|
|
3485
3624
|
return ret;
|
|
3486
3625
|
},
|
|
3487
3626
|
__wbindgen_cast_000000000000000a: function(arg0, arg1) {
|
|
3488
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("TreeStore")], shim_idx:
|
|
3627
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("TreeStore")], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
3489
3628
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h21f6855640435575_9);
|
|
3490
3629
|
return ret;
|
|
3491
3630
|
},
|
|
3492
3631
|
__wbindgen_cast_000000000000000b: function(arg0, arg1) {
|
|
3493
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx:
|
|
3632
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 397, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
3494
3633
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h1d6669a7b693932a);
|
|
3495
3634
|
return ret;
|
|
3496
3635
|
},
|
|
3497
3636
|
__wbindgen_cast_000000000000000c: function(arg0, arg1) {
|
|
3498
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx:
|
|
3637
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 427, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
|
3499
3638
|
const ret = makeClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h0fa3f876e31d2a3e);
|
|
3500
3639
|
return ret;
|
|
3501
3640
|
},
|
|
@@ -3680,6 +3819,9 @@ const BitcoinChainServiceHandleFinalization = (typeof FinalizationRegistry === '
|
|
|
3680
3819
|
const BreezSdkFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
3681
3820
|
? { register: () => {}, unregister: () => {} }
|
|
3682
3821
|
: new FinalizationRegistry(ptr => wasm.__wbg_breezsdk_free(ptr, 1));
|
|
3822
|
+
const DefaultCpfpSignerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
3823
|
+
? { register: () => {}, unregister: () => {} }
|
|
3824
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_defaultcpfpsigner_free(ptr, 1));
|
|
3683
3825
|
const DefaultSessionStoreFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
3684
3826
|
? { register: () => {}, unregister: () => {} }
|
|
3685
3827
|
: new FinalizationRegistry(ptr => wasm.__wbg_defaultsessionstore_free(ptr, 1));
|
|
Binary file
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_bitcoinchainservicehandle_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_breezsdk_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_defaultcpfpsigner_free: (a: number, b: number) => void;
|
|
6
7
|
export const __wbg_externalsigners_free: (a: number, b: number) => void;
|
|
7
8
|
export const __wbg_passkeyclient_free: (a: number, b: number) => void;
|
|
8
9
|
export const __wbg_passkeylabels_free: (a: number, b: number) => void;
|
|
@@ -11,13 +12,16 @@ export const __wbg_tokenissuer_free: (a: number, b: number) => void;
|
|
|
11
12
|
export const __wbg_wasmsdkcontext_free: (a: number, b: number) => void;
|
|
12
13
|
export const __wbg_wasmstorageconfig_free: (a: number, b: number) => void;
|
|
13
14
|
export const bitcoinchainservicehandle_broadcastTransaction: (a: number, b: number, c: number) => any;
|
|
15
|
+
export const bitcoinchainservicehandle_getAddressTxos: (a: number, b: number, c: number) => any;
|
|
14
16
|
export const bitcoinchainservicehandle_getAddressUtxos: (a: number, b: number, c: number) => any;
|
|
17
|
+
export const bitcoinchainservicehandle_getOutspend: (a: number, b: number, c: number, d: number) => any;
|
|
15
18
|
export const bitcoinchainservicehandle_getTransactionHex: (a: number, b: number, c: number) => any;
|
|
16
19
|
export const bitcoinchainservicehandle_getTransactionStatus: (a: number, b: number, c: number) => any;
|
|
17
20
|
export const bitcoinchainservicehandle_recommendedFees: (a: number) => any;
|
|
18
21
|
export const breezsdk_addContact: (a: number, b: any) => any;
|
|
19
22
|
export const breezsdk_addEventListener: (a: number, b: any) => any;
|
|
20
23
|
export const breezsdk_authorizeLightningAddressTransfer: (a: number, b: any) => any;
|
|
24
|
+
export const breezsdk_buildUnsignedBatchPackage: (a: number, b: any) => any;
|
|
21
25
|
export const breezsdk_buildUnsignedLnurlPayPackage: (a: number, b: any) => any;
|
|
22
26
|
export const breezsdk_buildUnsignedTransferPackage: (a: number, b: any) => any;
|
|
23
27
|
export const breezsdk_buyBitcoin: (a: number, b: any) => any;
|
|
@@ -49,7 +53,9 @@ export const breezsdk_lnurlWithdraw: (a: number, b: any) => any;
|
|
|
49
53
|
export const breezsdk_optimizeLeaves: (a: number, b: any) => any;
|
|
50
54
|
export const breezsdk_parse: (a: number, b: number, c: number) => any;
|
|
51
55
|
export const breezsdk_prepareLnurlPay: (a: number, b: any) => any;
|
|
56
|
+
export const breezsdk_prepareSendBatch: (a: number, b: any) => any;
|
|
52
57
|
export const breezsdk_prepareSendPayment: (a: number, b: any) => any;
|
|
58
|
+
export const breezsdk_prepareUnilateralExit: (a: number, b: any) => any;
|
|
53
59
|
export const breezsdk_publishSignedLnurlPayPackage: (a: number, b: any) => any;
|
|
54
60
|
export const breezsdk_publishSignedTransferPackage: (a: number, b: any) => any;
|
|
55
61
|
export const breezsdk_receivePayment: (a: number, b: any) => any;
|
|
@@ -59,9 +65,11 @@ export const breezsdk_refundPendingConversions: (a: number) => any;
|
|
|
59
65
|
export const breezsdk_registerLightningAddress: (a: number, b: any) => any;
|
|
60
66
|
export const breezsdk_registerWebhook: (a: number, b: any) => any;
|
|
61
67
|
export const breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
|
|
68
|
+
export const breezsdk_sendBatch: (a: number, b: any) => any;
|
|
62
69
|
export const breezsdk_sendPayment: (a: number, b: any) => any;
|
|
63
70
|
export const breezsdk_signMessage: (a: number, b: any) => any;
|
|
64
71
|
export const breezsdk_syncWallet: (a: number, b: any) => any;
|
|
72
|
+
export const breezsdk_unilateralExit: (a: number, b: any, c: any) => any;
|
|
65
73
|
export const breezsdk_unregisterWebhook: (a: number, b: any) => any;
|
|
66
74
|
export const breezsdk_updateContact: (a: number, b: any) => any;
|
|
67
75
|
export const breezsdk_updateUserSettings: (a: number, b: any) => any;
|
|
@@ -77,6 +85,7 @@ export const defaultPostgresStorageConfig: (a: number, b: number) => any;
|
|
|
77
85
|
export const defaultServerConfig: (a: any) => any;
|
|
78
86
|
export const defaultSessionStore: (a: number, b: any, c: number, d: number) => any;
|
|
79
87
|
export const defaultStorage: (a: number, b: number) => number;
|
|
88
|
+
export const defaultcpfpsigner_signPsbt: (a: number, b: number, c: number) => any;
|
|
80
89
|
export const defaultsessionstore_getSession: (a: number, b: number, c: number) => any;
|
|
81
90
|
export const defaultsessionstore_setSession: (a: number, b: number, c: number, d: any) => any;
|
|
82
91
|
export const externalbreezsignerhandle_decryptEcies: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
@@ -103,6 +112,7 @@ export const externalsparksignerhandle_prepareTokenTransaction: (a: number, b: a
|
|
|
103
112
|
export const externalsparksignerhandle_prepareTransfer: (a: number, b: any) => any;
|
|
104
113
|
export const externalsparksignerhandle_signAuthenticationChallenge: (a: number, b: number, c: number) => any;
|
|
105
114
|
export const externalsparksignerhandle_signFrost: (a: number, b: number, c: number) => any;
|
|
115
|
+
export const externalsparksignerhandle_signLeafRefundSpend: (a: number, b: any, c: number, d: number) => any;
|
|
106
116
|
export const externalsparksignerhandle_signMessage: (a: number, b: number, c: number) => any;
|
|
107
117
|
export const externalsparksignerhandle_signSparkInvoice: (a: number, b: any) => any;
|
|
108
118
|
export const externalsparksignerhandle_signStaticDepositRefund: (a: number, b: any) => any;
|
|
@@ -139,6 +149,7 @@ export const sdkbuilder_withSessionStore: (a: number, b: any) => number;
|
|
|
139
149
|
export const sdkbuilder_withSharedContext: (a: number, b: number) => number;
|
|
140
150
|
export const sdkbuilder_withStorage: (a: number, b: any) => number;
|
|
141
151
|
export const sdkbuilder_withStorageBackend: (a: number, b: number) => number;
|
|
152
|
+
export const singleKeyCpfpSigner: (a: number, b: number) => [number, number, number];
|
|
142
153
|
export const start: () => void;
|
|
143
154
|
export const tokenissuer_burnIssuerToken: (a: number, b: any) => any;
|
|
144
155
|
export const tokenissuer_createIssuerToken: (a: number, b: any) => any;
|
package/itest/.gitignore
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Pure tests for the tolerant JSON evaluator; no network. Mirrors the unit
|
|
4
|
+
// tests in crates/breez-sdk/cli/tests/harness/assert.rs.
|
|
5
|
+
|
|
6
|
+
const assert = require('node:assert/strict')
|
|
7
|
+
const test = require('node:test')
|
|
8
|
+
|
|
9
|
+
const { checkMatcher, extractJsonDocs, interpolate, lookupPath } = require('./scenario')
|
|
10
|
+
|
|
11
|
+
test('extracts pretty and inline docs and skips noise', () => {
|
|
12
|
+
const chunk = 'Breez SDK: noise\n{\n "a": 1\n}\nError: nope\n{"b": 2}\nEvent: {"c": 3}\n'
|
|
13
|
+
assert.deepEqual(extractJsonDocs(chunk), [{ a: 1 }, { b: 2 }])
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('path matches across casings', () => {
|
|
17
|
+
const rust = { payment_request: { amount_msat: 5 } }
|
|
18
|
+
const wasm = { paymentRequest: { amountMsat: 5 } }
|
|
19
|
+
for (const doc of [rust, wasm]) {
|
|
20
|
+
assert.equal(lookupPath(doc, 'payment_request.amount_msat'), 5)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('path bridges enum tags', () => {
|
|
25
|
+
const rust = { Bolt11Invoice: { amount_msat: 7 } }
|
|
26
|
+
const wasm = { type: 'bolt11Invoice', amountMsat: 7 }
|
|
27
|
+
for (const doc of [rust, wasm]) {
|
|
28
|
+
assert.equal(lookupPath(doc, 'bolt11_invoice.amount_msat'), 7)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('empty path addresses the document', () => {
|
|
33
|
+
assert.deepEqual(lookupPath({}, ''), {})
|
|
34
|
+
checkMatcher({}, lookupPath({}, ''))
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('path indexes arrays', () => {
|
|
38
|
+
const doc = { payments: [{ id: 'x' }, { id: 'y' }] }
|
|
39
|
+
assert.equal(lookupPath(doc, 'payments.1.id'), 'y')
|
|
40
|
+
assert.equal(lookupPath(doc, 'payments.2.id'), undefined)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('equality tolerates case and bigint strings', () => {
|
|
44
|
+
checkMatcher('completed', 'Completed')
|
|
45
|
+
checkMatcher('1000', 1000)
|
|
46
|
+
checkMatcher(1000, '1000')
|
|
47
|
+
assert.throws(() => checkMatcher('completed', 'failed'))
|
|
48
|
+
assert.throws(() => checkMatcher('completed', undefined))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('gte accepts numbers and numeric strings', () => {
|
|
52
|
+
checkMatcher({ gte: 10 }, 11)
|
|
53
|
+
checkMatcher({ gte: 10 }, '10')
|
|
54
|
+
assert.throws(() => checkMatcher({ gte: 10 }, 9))
|
|
55
|
+
assert.throws(() => checkMatcher({ gte: 10 }, 'abc'))
|
|
56
|
+
assert.throws(() => checkMatcher({ gte: 10 }, undefined))
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('exists checks presence and null', () => {
|
|
60
|
+
checkMatcher({ exists: true }, 'x')
|
|
61
|
+
checkMatcher({ exists: false }, undefined)
|
|
62
|
+
checkMatcher({ exists: false }, null)
|
|
63
|
+
assert.throws(() => checkMatcher({ exists: true }, null))
|
|
64
|
+
assert.throws(() => checkMatcher({ exists: true }, undefined))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('interpolation substitutes known vars and rejects unknown', () => {
|
|
68
|
+
assert.equal(interpolate('pay -r ${addr} -a 5', { addr: 'spark1x' }), 'pay -r spark1x -a 5')
|
|
69
|
+
assert.throws(() => interpolate('${missing}', {}))
|
|
70
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Minimal client for the Lightspark regtest faucet, mirroring the Rust
|
|
4
|
+
// harness (crates/breez-sdk/cli/tests/harness/faucet.rs).
|
|
5
|
+
|
|
6
|
+
const DEFAULT_URL = 'https://api.lightspark.com/graphql/spark/rc'
|
|
7
|
+
const MAX_RETRIES = 3
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fund a regtest bitcoin address, returning the funding txid. Retries with
|
|
11
|
+
* exponential backoff. Reads FAUCET_URL, FAUCET_USERNAME, and
|
|
12
|
+
* FAUCET_PASSWORD from the environment.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} address
|
|
15
|
+
* @param {number} amountSats
|
|
16
|
+
* @returns {Promise<string>}
|
|
17
|
+
*/
|
|
18
|
+
async function fundAddress(address, amountSats) {
|
|
19
|
+
let lastError
|
|
20
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
21
|
+
if (attempt > 0) {
|
|
22
|
+
await new Promise((resolve) => setTimeout(resolve, 2 ** attempt * 1000))
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return await tryFundAddress(address, amountSats)
|
|
26
|
+
} catch (e) {
|
|
27
|
+
lastError = e
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw lastError
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function tryFundAddress(address, amountSats) {
|
|
34
|
+
const url = process.env.FAUCET_URL || DEFAULT_URL
|
|
35
|
+
const headers = { 'Content-Type': 'application/json' }
|
|
36
|
+
const { FAUCET_USERNAME, FAUCET_PASSWORD } = process.env
|
|
37
|
+
if (FAUCET_USERNAME && FAUCET_PASSWORD) {
|
|
38
|
+
const credentials = Buffer.from(`${FAUCET_USERNAME}:${FAUCET_PASSWORD}`).toString('base64')
|
|
39
|
+
headers.Authorization = `Basic ${credentials}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers,
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
operationName: 'RequestRegtestFunds',
|
|
47
|
+
variables: { amount_sats: amountSats, address },
|
|
48
|
+
query:
|
|
49
|
+
'mutation RequestRegtestFunds($address: String!, $amount_sats: Long!) { ' +
|
|
50
|
+
'request_regtest_funds(input: {address: $address, amount_sats: $amount_sats}) ' +
|
|
51
|
+
'{ transaction_hash}}'
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
const body = await response.text()
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(`faucet request failed with status ${response.status}: ${body}`)
|
|
57
|
+
}
|
|
58
|
+
const parsed = JSON.parse(body)
|
|
59
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
60
|
+
throw new Error(`faucet returned errors: ${parsed.errors.map((e) => e.message).join(', ')}`)
|
|
61
|
+
}
|
|
62
|
+
if (!parsed.data) {
|
|
63
|
+
throw new Error(`faucet response has no data: ${body}`)
|
|
64
|
+
}
|
|
65
|
+
return parsed.data.request_regtest_funds.transaction_hash
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { fundAddress }
|