@buildonspark/spark-sdk 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/bare/chunk-P6AVV7VD.js +34 -0
- package/dist/bare/index.cjs +341 -279
- package/dist/bare/index.d.cts +15 -2
- package/dist/bare/index.d.ts +15 -2
- package/dist/bare/index.js +55 -50
- package/dist/bare/{wasm-OPXXYRN5.js → wasm-F5QFVBNZ.js} +26 -0
- package/dist/bare/{xhr-transport-6GYJAFWU.js → xhr-transport-EEEC7FYA.js} +2 -2
- package/dist/{chunk-23BBEC25.js → chunk-3WBPICWC.js} +1 -1
- package/dist/chunk-NX5KPN5F.js +34 -0
- package/dist/{chunk-5Y7YILMA.js → chunk-QNYJGFPD.js} +53 -49
- package/dist/debug.cjs +337 -276
- package/dist/debug.d.cts +5 -2
- package/dist/debug.d.ts +5 -2
- package/dist/debug.js +2 -1
- package/dist/index.cjs +390 -327
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -2
- package/dist/index.node.cjs +390 -327
- package/dist/index.node.d.cts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +7 -1
- package/dist/{xchain-address-CNQEwLjR.d.cts → logging-BOAzMqpM.d.cts} +15 -1
- package/dist/{xchain-address-BPwpnmuY.d.ts → logging-Bt_WdZbu.d.ts} +15 -1
- package/dist/native/chunk-D3SZRO65.js +36 -0
- package/dist/native/index.cjs +387 -324
- package/dist/native/index.d.cts +15 -2
- package/dist/native/index.d.ts +15 -2
- package/dist/native/index.js +147 -143
- package/dist/native/{wasm-2KV6XFEP.js → wasm-3YAXKQ7F.js} +25 -0
- package/dist/native/{xhr-transport-WHMS3FGG.js → xhr-transport-TNCG4HTW.js} +2 -2
- package/dist/spark_bindings/wasm/index.cjs +51 -0
- package/dist/spark_bindings/wasm/index.js +25 -0
- package/dist/tests/test-utils.cjs +229 -166
- package/dist/tests/test-utils.js +3 -2
- package/dist/{xhr-transport-RH6LDRXS.js → xhr-transport-IWJPYF7F.js} +2 -2
- package/package.json +1 -1
- package/src/services/deposit.ts +5 -1
- package/src/services/xhr-transport.ts +2 -2
- package/src/spark-wallet/spark-wallet.ts +4 -9
- package/src/spark_bindings/wasm/index.ts +21 -0
- package/src/tests/integration/lightning.test.ts +2 -2
- package/src/tests/integration/ssp/coop-exit-validation.test.ts +2 -2
- package/src/tests/integration/ssp/static_deposit.test.ts +0 -32
- package/src/tests/integration/swap.test.ts +2 -2
- package/src/tests/integration/transfer.test.ts +20 -16
- package/src/tests/integration/watchtower.test.ts +2 -2
- package/src/utils/adaptor-signature.ts +11 -12
- package/src/utils/address.ts +10 -10
- package/src/utils/bitcoin.ts +6 -6
- package/src/utils/index.ts +1 -0
- package/src/utils/keys.ts +9 -9
- package/src/utils/logging.ts +40 -0
- package/src/utils/secret-sharing.ts +9 -11
package/dist/bare/index.cjs
CHANGED
|
@@ -1022,6 +1022,42 @@ var init_spark_bindings = __esm({
|
|
|
1022
1022
|
}
|
|
1023
1023
|
});
|
|
1024
1024
|
|
|
1025
|
+
// src/utils/logging.ts
|
|
1026
|
+
var import_core11, LOGGER_NAMES, SparkSdkLogger;
|
|
1027
|
+
var init_logging = __esm({
|
|
1028
|
+
"src/utils/logging.ts"() {
|
|
1029
|
+
"use strict";
|
|
1030
|
+
import_core11 = require("@lightsparkdev/core");
|
|
1031
|
+
LOGGER_NAMES = {
|
|
1032
|
+
wasm: "wasm"
|
|
1033
|
+
};
|
|
1034
|
+
SparkSdkLogger = class {
|
|
1035
|
+
static loggers = /* @__PURE__ */ new Map();
|
|
1036
|
+
static get(name) {
|
|
1037
|
+
if (!this.loggers.has(name)) {
|
|
1038
|
+
this.loggers.set(name, new import_core11.Logger(name));
|
|
1039
|
+
}
|
|
1040
|
+
return this.loggers.get(name);
|
|
1041
|
+
}
|
|
1042
|
+
static setLevel(name, level) {
|
|
1043
|
+
this.get(name).setLevel(level);
|
|
1044
|
+
}
|
|
1045
|
+
static setAllLevels(level) {
|
|
1046
|
+
this.loggers.forEach((logger) => logger.setLevel(level));
|
|
1047
|
+
}
|
|
1048
|
+
static setEnabled(name, enabled) {
|
|
1049
|
+
this.get(name).setEnabled(enabled);
|
|
1050
|
+
}
|
|
1051
|
+
static setAllEnabled(enabled) {
|
|
1052
|
+
this.loggers.forEach((logger) => logger.setEnabled(enabled));
|
|
1053
|
+
}
|
|
1054
|
+
static {
|
|
1055
|
+
Object.values(LOGGER_NAMES).forEach((name) => this.get(name));
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1025
1061
|
// src/spark_bindings/wasm/index.ts
|
|
1026
1062
|
var wasm_exports = {};
|
|
1027
1063
|
__export(wasm_exports, {
|
|
@@ -1052,6 +1088,13 @@ function signFrost({
|
|
|
1052
1088
|
statechainCommitments,
|
|
1053
1089
|
adaptorPubKey
|
|
1054
1090
|
}) {
|
|
1091
|
+
SparkSdkLogger.get(LOGGER_NAMES.wasm).trace("signFrost", {
|
|
1092
|
+
message: (0, import_utils4.bytesToHex)(message),
|
|
1093
|
+
keyPackage,
|
|
1094
|
+
nonce,
|
|
1095
|
+
selfCommitment,
|
|
1096
|
+
statechainCommitments
|
|
1097
|
+
});
|
|
1055
1098
|
return wasm_sign_frost(
|
|
1056
1099
|
message,
|
|
1057
1100
|
createKeyPackage(keyPackage),
|
|
@@ -1072,6 +1115,17 @@ function aggregateFrost({
|
|
|
1072
1115
|
verifyingKey,
|
|
1073
1116
|
adaptorPubKey
|
|
1074
1117
|
}) {
|
|
1118
|
+
SparkSdkLogger.get(LOGGER_NAMES.wasm).trace("aggregateFrost", {
|
|
1119
|
+
message: (0, import_utils4.bytesToHex)(message),
|
|
1120
|
+
statechainCommitments,
|
|
1121
|
+
selfCommitment,
|
|
1122
|
+
statechainSignatures,
|
|
1123
|
+
selfSignature: (0, import_utils4.bytesToHex)(selfSignature),
|
|
1124
|
+
statechainPublicKeys,
|
|
1125
|
+
selfPublicKey: (0, import_utils4.bytesToHex)(selfPublicKey),
|
|
1126
|
+
verifyingKey: (0, import_utils4.bytesToHex)(verifyingKey),
|
|
1127
|
+
adaptorPubKey: adaptorPubKey ? (0, import_utils4.bytesToHex)(adaptorPubKey) : void 0
|
|
1128
|
+
});
|
|
1075
1129
|
return wasm_aggregate_frost(
|
|
1076
1130
|
message,
|
|
1077
1131
|
statechainCommitments,
|
|
@@ -1102,10 +1156,13 @@ function decryptEcies({
|
|
|
1102
1156
|
}) {
|
|
1103
1157
|
return decrypt_ecies(encryptedMsg, privateKey);
|
|
1104
1158
|
}
|
|
1159
|
+
var import_utils4;
|
|
1105
1160
|
var init_wasm = __esm({
|
|
1106
1161
|
"src/spark_bindings/wasm/index.ts"() {
|
|
1107
1162
|
"use strict";
|
|
1163
|
+
import_utils4 = require("@noble/curves/utils");
|
|
1108
1164
|
init_spark_bindings();
|
|
1165
|
+
init_logging();
|
|
1109
1166
|
}
|
|
1110
1167
|
});
|
|
1111
1168
|
|
|
@@ -1179,7 +1236,7 @@ function XHRTransport(config) {
|
|
|
1179
1236
|
bodyBuffer = chunk;
|
|
1180
1237
|
break;
|
|
1181
1238
|
}
|
|
1182
|
-
requestBody = bodyBuffer;
|
|
1239
|
+
requestBody = bodyBuffer.slice();
|
|
1183
1240
|
} else {
|
|
1184
1241
|
let iterator;
|
|
1185
1242
|
requestBody = new ReadableStream({
|
|
@@ -1193,7 +1250,7 @@ function XHRTransport(config) {
|
|
|
1193
1250
|
if (done) {
|
|
1194
1251
|
controller.close();
|
|
1195
1252
|
} else {
|
|
1196
|
-
controller.enqueue(value);
|
|
1253
|
+
controller.enqueue(value.slice());
|
|
1197
1254
|
}
|
|
1198
1255
|
},
|
|
1199
1256
|
async cancel() {
|
|
@@ -1293,6 +1350,7 @@ __export(index_exports, {
|
|
|
1293
1350
|
INITIAL_DIRECT_SEQUENCE: () => INITIAL_DIRECT_SEQUENCE,
|
|
1294
1351
|
INITIAL_SEQUENCE: () => INITIAL_SEQUENCE,
|
|
1295
1352
|
InternalValidationError: () => InternalValidationError,
|
|
1353
|
+
LOGGER_NAMES: () => LOGGER_NAMES,
|
|
1296
1354
|
LRC_WALLET_NETWORK: () => LRC_WALLET_NETWORK,
|
|
1297
1355
|
Network: () => Network2,
|
|
1298
1356
|
NetworkError: () => NetworkError,
|
|
@@ -1300,6 +1358,7 @@ __export(index_exports, {
|
|
|
1300
1358
|
NotImplementedError: () => NotImplementedError,
|
|
1301
1359
|
RPCError: () => RPCError,
|
|
1302
1360
|
SparkSDKError: () => SparkSDKError,
|
|
1361
|
+
SparkSdkLogger: () => SparkSdkLogger,
|
|
1303
1362
|
SparkWallet: () => SparkWalletBrowser,
|
|
1304
1363
|
TEST_UNILATERAL_DIRECT_SEQUENCE: () => TEST_UNILATERAL_DIRECT_SEQUENCE,
|
|
1305
1364
|
TEST_UNILATERAL_SEQUENCE: () => TEST_UNILATERAL_SEQUENCE,
|
|
@@ -1551,8 +1610,8 @@ var NotImplementedError = class extends SparkSDKError {
|
|
|
1551
1610
|
};
|
|
1552
1611
|
|
|
1553
1612
|
// src/spark-wallet/spark-wallet.ts
|
|
1554
|
-
var
|
|
1555
|
-
var
|
|
1613
|
+
var import_core13 = require("@lightsparkdev/core");
|
|
1614
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
|
1556
1615
|
var import_secp256k115 = require("@noble/curves/secp256k1");
|
|
1557
1616
|
var import_bip392 = require("@scure/bip39");
|
|
1558
1617
|
var import_english2 = require("@scure/bip39/wordlists/english");
|
|
@@ -17676,20 +17735,20 @@ function isSet3(value) {
|
|
|
17676
17735
|
|
|
17677
17736
|
// src/signer/signer.ts
|
|
17678
17737
|
var import_secp256k14 = require("@bitcoinerlab/secp256k1");
|
|
17679
|
-
var
|
|
17738
|
+
var import_utils5 = require("@noble/curves/abstract/utils");
|
|
17680
17739
|
var import_secp256k15 = require("@noble/curves/secp256k1");
|
|
17681
17740
|
var import_sha22 = require("@noble/hashes/sha2");
|
|
17682
17741
|
var import_bip32 = require("@scure/bip32");
|
|
17683
17742
|
var import_bip39 = require("@scure/bip39");
|
|
17684
17743
|
var import_english = require("@scure/bip39/wordlists/english");
|
|
17685
|
-
var
|
|
17744
|
+
var import_utils6 = require("@scure/btc-signer/utils");
|
|
17686
17745
|
var ecies = __toESM(require("eciesjs"), 1);
|
|
17687
17746
|
|
|
17688
17747
|
// src/constants.ts
|
|
17689
17748
|
var import_core10 = require("@lightsparkdev/core");
|
|
17690
17749
|
var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
17691
17750
|
var isBun = globalThis.Bun !== void 0;
|
|
17692
|
-
var packageVersion = true ? "0.2.
|
|
17751
|
+
var packageVersion = true ? "0.2.11" : "unknown";
|
|
17693
17752
|
var baseEnvStr = "unknown";
|
|
17694
17753
|
if (isBun) {
|
|
17695
17754
|
const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
|
|
@@ -17718,9 +17777,9 @@ function addPublicKeys(a, b) {
|
|
|
17718
17777
|
expected: 33
|
|
17719
17778
|
});
|
|
17720
17779
|
}
|
|
17721
|
-
const pubkeyA = import_secp256k1.secp256k1.
|
|
17722
|
-
const pubkeyB = import_secp256k1.secp256k1.
|
|
17723
|
-
return pubkeyA.add(pubkeyB).
|
|
17780
|
+
const pubkeyA = import_secp256k1.secp256k1.Point.fromHex(a);
|
|
17781
|
+
const pubkeyB = import_secp256k1.secp256k1.Point.fromHex(b);
|
|
17782
|
+
return pubkeyA.add(pubkeyB).toBytes(true);
|
|
17724
17783
|
}
|
|
17725
17784
|
function applyAdditiveTweakToPublicKey(pubkey, tweak) {
|
|
17726
17785
|
if (pubkey.length !== 33) {
|
|
@@ -17737,11 +17796,11 @@ function applyAdditiveTweakToPublicKey(pubkey, tweak) {
|
|
|
17737
17796
|
expected: 32
|
|
17738
17797
|
});
|
|
17739
17798
|
}
|
|
17740
|
-
const pubkeyPoint = import_secp256k1.secp256k1.
|
|
17799
|
+
const pubkeyPoint = import_secp256k1.secp256k1.Point.fromHex(pubkey);
|
|
17741
17800
|
const privTweek = import_secp256k1.secp256k1.utils.normPrivateKeyToScalar(tweak);
|
|
17742
17801
|
const pubTweek = import_secp256k1.secp256k1.getPublicKey(privTweek, true);
|
|
17743
|
-
const tweekPoint = import_secp256k1.secp256k1.
|
|
17744
|
-
return pubkeyPoint.add(tweekPoint).
|
|
17802
|
+
const tweekPoint = import_secp256k1.secp256k1.Point.fromHex(pubTweek);
|
|
17803
|
+
return pubkeyPoint.add(tweekPoint).toBytes(true);
|
|
17745
17804
|
}
|
|
17746
17805
|
function subtractPublicKeys(a, b) {
|
|
17747
17806
|
if (a.length !== 33 || b.length !== 33) {
|
|
@@ -17751,9 +17810,9 @@ function subtractPublicKeys(a, b) {
|
|
|
17751
17810
|
expected: 33
|
|
17752
17811
|
});
|
|
17753
17812
|
}
|
|
17754
|
-
const pubkeyA = import_secp256k1.secp256k1.
|
|
17755
|
-
const pubkeyB = import_secp256k1.secp256k1.
|
|
17756
|
-
return pubkeyA.subtract(pubkeyB).
|
|
17813
|
+
const pubkeyA = import_secp256k1.secp256k1.Point.fromHex(a);
|
|
17814
|
+
const pubkeyB = import_secp256k1.secp256k1.Point.fromHex(b);
|
|
17815
|
+
return pubkeyA.subtract(pubkeyB).toBytes(true);
|
|
17757
17816
|
}
|
|
17758
17817
|
function addPrivateKeys(a, b) {
|
|
17759
17818
|
if (a.length !== 32 || b.length !== 32) {
|
|
@@ -17893,11 +17952,11 @@ function generatePolynomialForSecretSharing(fieldModulus, secret, degree) {
|
|
|
17893
17952
|
const coefficients = new Array(degree);
|
|
17894
17953
|
const proofs = new Array(degree);
|
|
17895
17954
|
coefficients[0] = secret;
|
|
17896
|
-
proofs[0] = import_secp256k12.secp256k1.
|
|
17955
|
+
proofs[0] = import_secp256k12.secp256k1.Point.fromPrivateKey(secret).toBytes(true);
|
|
17897
17956
|
for (let i = 1; i < degree; i++) {
|
|
17898
17957
|
const coefficient = getRandomBigInt(fieldModulus);
|
|
17899
17958
|
coefficients[i] = coefficient;
|
|
17900
|
-
proofs[i] = import_secp256k12.secp256k1.
|
|
17959
|
+
proofs[i] = import_secp256k12.secp256k1.Point.fromPrivateKey(coefficient).toBytes(true);
|
|
17901
17960
|
}
|
|
17902
17961
|
return {
|
|
17903
17962
|
fieldModulus,
|
|
@@ -17969,9 +18028,9 @@ function recoverSecret(shares) {
|
|
|
17969
18028
|
return result;
|
|
17970
18029
|
}
|
|
17971
18030
|
function validateShare(share) {
|
|
17972
|
-
const targetPubkey = import_secp256k12.secp256k1.
|
|
17973
|
-
|
|
17974
|
-
)
|
|
18031
|
+
const targetPubkey = import_secp256k12.secp256k1.Point.fromPrivateKey(share.share).toBytes(
|
|
18032
|
+
true
|
|
18033
|
+
);
|
|
17975
18034
|
let resultPubkey = share.proofs[0];
|
|
17976
18035
|
if (!resultPubkey) {
|
|
17977
18036
|
throw new ValidationError("Result pubkey is not valid", {
|
|
@@ -17990,8 +18049,8 @@ function validateShare(share) {
|
|
|
17990
18049
|
});
|
|
17991
18050
|
}
|
|
17992
18051
|
const value = share.index ** BigInt(i) % share.fieldModulus;
|
|
17993
|
-
const scaledPoint = import_secp256k12.secp256k1.
|
|
17994
|
-
resultPubkey = import_secp256k12.secp256k1.
|
|
18052
|
+
const scaledPoint = import_secp256k12.secp256k1.Point.fromHex(pubkey).multiply(value);
|
|
18053
|
+
resultPubkey = import_secp256k12.secp256k1.Point.fromHex(resultPubkey).add(scaledPoint).toBytes(true);
|
|
17995
18054
|
}
|
|
17996
18055
|
if (!(0, import_utils3.equalBytes)(resultPubkey, targetPubkey)) {
|
|
17997
18056
|
throw new ValidationError("Share is not valid", {
|
|
@@ -18160,7 +18219,7 @@ var TaprootOutputKeysGenerator = class {
|
|
|
18160
18219
|
}
|
|
18161
18220
|
const derivationPath = this.useAddressIndex ? `m/86'/0'/0'/0/${accountNumber}` : `m/86'/0'/${accountNumber}'/0/0`;
|
|
18162
18221
|
const taprootInternalKey = hdkey.derive(derivationPath);
|
|
18163
|
-
let tweakedPrivateKey = (0,
|
|
18222
|
+
let tweakedPrivateKey = (0, import_utils6.taprootTweakPrivKey)(taprootInternalKey.privateKey);
|
|
18164
18223
|
let tweakedPublicKey = import_secp256k15.secp256k1.getPublicKey(tweakedPrivateKey);
|
|
18165
18224
|
if (tweakedPublicKey[0] === 3) {
|
|
18166
18225
|
tweakedPrivateKey = (0, import_secp256k14.privateNegate)(tweakedPrivateKey);
|
|
@@ -18238,7 +18297,7 @@ var DefaultSparkSigner = class {
|
|
|
18238
18297
|
});
|
|
18239
18298
|
}
|
|
18240
18299
|
const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
|
|
18241
|
-
(0,
|
|
18300
|
+
(0, import_utils5.bytesToHex)(this.identityKey.privateKey)
|
|
18242
18301
|
);
|
|
18243
18302
|
const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
|
|
18244
18303
|
return privateKey;
|
|
@@ -18372,7 +18431,7 @@ var DefaultSparkSigner = class {
|
|
|
18372
18431
|
threshold,
|
|
18373
18432
|
numShares
|
|
18374
18433
|
}) {
|
|
18375
|
-
const secretAsInt = (0,
|
|
18434
|
+
const secretAsInt = (0, import_utils5.bytesToNumberBE)(secret);
|
|
18376
18435
|
return splitSecretWithProofs(secretAsInt, curveOrder, threshold, numShares);
|
|
18377
18436
|
}
|
|
18378
18437
|
async signFrost({
|
|
@@ -18408,7 +18467,7 @@ var DefaultSparkSigner = class {
|
|
|
18408
18467
|
publicKey,
|
|
18409
18468
|
verifyingKey
|
|
18410
18469
|
};
|
|
18411
|
-
const logMessage = (0,
|
|
18470
|
+
const logMessage = (0, import_utils5.bytesToHex)(message);
|
|
18412
18471
|
const result = await SparkFrost.signFrost({
|
|
18413
18472
|
message,
|
|
18414
18473
|
keyPackage,
|
|
@@ -18450,7 +18509,7 @@ var DefaultSparkSigner = class {
|
|
|
18450
18509
|
}
|
|
18451
18510
|
async createSparkWalletFromSeed(seed, accountNumber) {
|
|
18452
18511
|
if (typeof seed === "string") {
|
|
18453
|
-
seed = (0,
|
|
18512
|
+
seed = (0, import_utils5.hexToBytes)(seed);
|
|
18454
18513
|
}
|
|
18455
18514
|
const {
|
|
18456
18515
|
identityKey,
|
|
@@ -18462,7 +18521,7 @@ var DefaultSparkSigner = class {
|
|
|
18462
18521
|
this.depositKey = depositKey;
|
|
18463
18522
|
this.signingKey = signingKey.hdKey;
|
|
18464
18523
|
this.staticDepositKey = staticDepositKey.hdKey;
|
|
18465
|
-
return (0,
|
|
18524
|
+
return (0, import_utils5.bytesToHex)(identityKey.publicKey);
|
|
18466
18525
|
}
|
|
18467
18526
|
async signMessageWithIdentityKey(message, compact) {
|
|
18468
18527
|
if (!this.identityKey?.privateKey) {
|
|
@@ -18483,7 +18542,7 @@ var DefaultSparkSigner = class {
|
|
|
18483
18542
|
});
|
|
18484
18543
|
}
|
|
18485
18544
|
const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
|
|
18486
|
-
(0,
|
|
18545
|
+
(0, import_utils5.bytesToHex)(this.identityKey.privateKey)
|
|
18487
18546
|
);
|
|
18488
18547
|
const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
|
|
18489
18548
|
const publicKey = import_secp256k15.secp256k1.getPublicKey(privateKey);
|
|
@@ -18507,15 +18566,15 @@ var DefaultSparkSigner = class {
|
|
|
18507
18566
|
}
|
|
18508
18567
|
signTransactionIndex(tx, index, publicKey) {
|
|
18509
18568
|
let privateKey;
|
|
18510
|
-
if ((0,
|
|
18569
|
+
if ((0, import_utils5.equalBytes)(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
|
|
18511
18570
|
privateKey = this.identityKey?.privateKey;
|
|
18512
|
-
} else if ((0,
|
|
18571
|
+
} else if ((0, import_utils5.equalBytes)(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
|
|
18513
18572
|
privateKey = this.depositKey?.privateKey;
|
|
18514
18573
|
}
|
|
18515
18574
|
if (!privateKey) {
|
|
18516
18575
|
throw new ValidationError("Private key not found for public key", {
|
|
18517
18576
|
field: "privateKey",
|
|
18518
|
-
value: (0,
|
|
18577
|
+
value: (0, import_utils5.bytesToHex)(publicKey)
|
|
18519
18578
|
});
|
|
18520
18579
|
}
|
|
18521
18580
|
tx.signIdx(privateKey, index);
|
|
@@ -18986,7 +19045,7 @@ var WalletConfigService = class {
|
|
|
18986
19045
|
};
|
|
18987
19046
|
|
|
18988
19047
|
// src/services/connection.ts
|
|
18989
|
-
var
|
|
19048
|
+
var import_core12 = require("@lightsparkdev/core");
|
|
18990
19049
|
var import_sha23 = require("@noble/hashes/sha2");
|
|
18991
19050
|
var import_nice_grpc_client_middleware_retry = require("nice-grpc-client-middleware-retry");
|
|
18992
19051
|
var import_nice_grpc_common2 = require("nice-grpc-common");
|
|
@@ -22741,7 +22800,7 @@ var ConnectionManager = class {
|
|
|
22741
22800
|
async createMockClient(address2) {
|
|
22742
22801
|
const channel = await this.createChannelWithTLS(address2);
|
|
22743
22802
|
const isNodeChannel = "close" in channel;
|
|
22744
|
-
if (
|
|
22803
|
+
if (import_core12.isNode && isNodeChannel && !isBun) {
|
|
22745
22804
|
const grpcModule = await import("nice-grpc");
|
|
22746
22805
|
const { createClient } = "default" in grpcModule ? grpcModule.default : grpcModule;
|
|
22747
22806
|
const client = createClient(MockServiceDefinition, channel);
|
|
@@ -22758,7 +22817,7 @@ var ConnectionManager = class {
|
|
|
22758
22817
|
}
|
|
22759
22818
|
async createChannelWithTLS(address2, certPath) {
|
|
22760
22819
|
try {
|
|
22761
|
-
if (
|
|
22820
|
+
if (import_core12.isNode && !isBun) {
|
|
22762
22821
|
const grpcModule = await import("nice-grpc");
|
|
22763
22822
|
const { ChannelCredentials, createChannel } = "default" in grpcModule ? grpcModule.default : grpcModule;
|
|
22764
22823
|
if (certPath) {
|
|
@@ -22789,7 +22848,7 @@ var ConnectionManager = class {
|
|
|
22789
22848
|
const { XHRTransport: XHRTransport2 } = await Promise.resolve().then(() => (init_xhr_transport(), xhr_transport_exports));
|
|
22790
22849
|
return createChannel(
|
|
22791
22850
|
address2,
|
|
22792
|
-
|
|
22851
|
+
import_core12.isBare ? (0, import_nice_grpc_web.NodeHttpTransport)() : isReactNative ? XHRTransport2() : FetchTransport()
|
|
22793
22852
|
);
|
|
22794
22853
|
}
|
|
22795
22854
|
} catch (error) {
|
|
@@ -22895,7 +22954,7 @@ var ConnectionManager = class {
|
|
|
22895
22954
|
sparkAuthnClient.close?.();
|
|
22896
22955
|
return verifyResp.sessionToken;
|
|
22897
22956
|
} catch (error) {
|
|
22898
|
-
if ((0,
|
|
22957
|
+
if ((0, import_core12.isError)(error)) {
|
|
22899
22958
|
sparkAuthnClient?.close?.();
|
|
22900
22959
|
if (error.message.includes("challenge expired")) {
|
|
22901
22960
|
console.warn(
|
|
@@ -22946,7 +23005,7 @@ var ConnectionManager = class {
|
|
|
22946
23005
|
);
|
|
22947
23006
|
}
|
|
22948
23007
|
createAuthnMiddleware() {
|
|
22949
|
-
if (
|
|
23008
|
+
if (import_core12.isNode) {
|
|
22950
23009
|
return async function* (call, options) {
|
|
22951
23010
|
const metadata = (0, import_nice_grpc_common2.Metadata)(options.metadata).set(
|
|
22952
23011
|
"X-Client-Env",
|
|
@@ -22968,14 +23027,14 @@ var ConnectionManager = class {
|
|
|
22968
23027
|
}
|
|
22969
23028
|
}
|
|
22970
23029
|
createMiddleware(address2, authToken) {
|
|
22971
|
-
if (
|
|
23030
|
+
if (import_core12.isNode) {
|
|
22972
23031
|
return this.createNodeMiddleware(address2, authToken);
|
|
22973
23032
|
} else {
|
|
22974
23033
|
return this.createBrowserMiddleware(address2, authToken);
|
|
22975
23034
|
}
|
|
22976
23035
|
}
|
|
22977
23036
|
async *handleMiddlewareError(error, address2, call, metadata, options) {
|
|
22978
|
-
if ((0,
|
|
23037
|
+
if ((0, import_core12.isError)(error)) {
|
|
22979
23038
|
if (error.message.includes("token has expired")) {
|
|
22980
23039
|
const newAuthToken = await this.authenticate(address2);
|
|
22981
23040
|
const clientData = this.clients.get(address2);
|
|
@@ -23046,7 +23105,7 @@ var ConnectionManager = class {
|
|
|
23046
23105
|
};
|
|
23047
23106
|
let options = {};
|
|
23048
23107
|
const isNodeChannel = "close" in channel;
|
|
23049
|
-
if (
|
|
23108
|
+
if (import_core12.isNode && isNodeChannel && !isBun) {
|
|
23050
23109
|
const grpcModule = await import("nice-grpc");
|
|
23051
23110
|
const { openTelemetryClientMiddleware } = await import("nice-grpc-opentelemetry");
|
|
23052
23111
|
const { createClientFactory } = "default" in grpcModule ? grpcModule.default : grpcModule;
|
|
@@ -23094,7 +23153,7 @@ var import_btc_signer3 = require("@scure/btc-signer");
|
|
|
23094
23153
|
var import_uuidv72 = require("uuidv7");
|
|
23095
23154
|
|
|
23096
23155
|
// src/utils/bitcoin.ts
|
|
23097
|
-
var
|
|
23156
|
+
var import_utils7 = require("@noble/curves/abstract/utils");
|
|
23098
23157
|
var import_secp256k16 = require("@noble/curves/secp256k1");
|
|
23099
23158
|
var import_sha24 = require("@noble/hashes/sha2");
|
|
23100
23159
|
var btc2 = __toESM(require("@scure/btc-signer"), 1);
|
|
@@ -23107,10 +23166,10 @@ function computeTaprootKeyNoScript(pubkey) {
|
|
|
23107
23166
|
});
|
|
23108
23167
|
}
|
|
23109
23168
|
const taggedHash = import_secp256k16.schnorr.utils.taggedHash("TapTweak", pubkey);
|
|
23110
|
-
const tweak = (0,
|
|
23169
|
+
const tweak = (0, import_utils7.bytesToNumberBE)(taggedHash);
|
|
23111
23170
|
const P = import_secp256k16.schnorr.utils.lift_x(import_secp256k16.schnorr.utils.bytesToNumberBE(pubkey));
|
|
23112
|
-
const Q = P.add(import_secp256k16.secp256k1.
|
|
23113
|
-
return Q.
|
|
23171
|
+
const Q = P.add(import_secp256k16.secp256k1.Point.fromPrivateKey(tweak));
|
|
23172
|
+
return Q.toBytes();
|
|
23114
23173
|
}
|
|
23115
23174
|
function getP2TRScriptFromPublicKey(pubKey, network) {
|
|
23116
23175
|
if (pubKey.length !== 33) {
|
|
@@ -23120,9 +23179,9 @@ function getP2TRScriptFromPublicKey(pubKey, network) {
|
|
|
23120
23179
|
expected: 33
|
|
23121
23180
|
});
|
|
23122
23181
|
}
|
|
23123
|
-
const internalKey = import_secp256k16.secp256k1.
|
|
23182
|
+
const internalKey = import_secp256k16.secp256k1.Point.fromHex(pubKey);
|
|
23124
23183
|
const script = btc2.p2tr(
|
|
23125
|
-
internalKey.
|
|
23184
|
+
internalKey.toBytes().slice(1, 33),
|
|
23126
23185
|
void 0,
|
|
23127
23186
|
getNetwork(network)
|
|
23128
23187
|
).script;
|
|
@@ -23142,9 +23201,9 @@ function getP2TRAddressFromPublicKey(pubKey, network) {
|
|
|
23142
23201
|
expected: 33
|
|
23143
23202
|
});
|
|
23144
23203
|
}
|
|
23145
|
-
const internalKey = import_secp256k16.secp256k1.
|
|
23204
|
+
const internalKey = import_secp256k16.secp256k1.Point.fromHex(pubKey);
|
|
23146
23205
|
const address2 = btc2.p2tr(
|
|
23147
|
-
internalKey.
|
|
23206
|
+
internalKey.toBytes().slice(1, 33),
|
|
23148
23207
|
void 0,
|
|
23149
23208
|
getNetwork(network)
|
|
23150
23209
|
).address;
|
|
@@ -23160,7 +23219,7 @@ function getP2TRAddressFromPkScript(pkScript, network) {
|
|
|
23160
23219
|
if (pkScript.length !== 34 || pkScript[0] !== 81 || pkScript[1] !== 32) {
|
|
23161
23220
|
throw new ValidationError("Invalid pkscript", {
|
|
23162
23221
|
field: "pkScript",
|
|
23163
|
-
value: (0,
|
|
23222
|
+
value: (0, import_utils7.bytesToHex)(pkScript),
|
|
23164
23223
|
expected: "34 bytes starting with 0x51 0x20"
|
|
23165
23224
|
});
|
|
23166
23225
|
}
|
|
@@ -23185,7 +23244,7 @@ function getP2WPKHAddressFromPublicKey(pubKey, network) {
|
|
|
23185
23244
|
return address2;
|
|
23186
23245
|
}
|
|
23187
23246
|
function getTxFromRawTxHex(rawTxHex) {
|
|
23188
|
-
const txBytes = (0,
|
|
23247
|
+
const txBytes = (0, import_utils7.hexToBytes)(rawTxHex);
|
|
23189
23248
|
const tx = btc2.Transaction.fromRaw(txBytes, {
|
|
23190
23249
|
allowUnknownOutputs: true
|
|
23191
23250
|
});
|
|
@@ -23232,10 +23291,10 @@ function getSigHashFromTx(tx, inputIndex, prevOutput) {
|
|
|
23232
23291
|
);
|
|
23233
23292
|
}
|
|
23234
23293
|
function getTxId(tx) {
|
|
23235
|
-
return (0,
|
|
23294
|
+
return (0, import_utils7.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))).reverse());
|
|
23236
23295
|
}
|
|
23237
23296
|
function getTxIdNoReverse(tx) {
|
|
23238
|
-
return (0,
|
|
23297
|
+
return (0, import_utils7.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))));
|
|
23239
23298
|
}
|
|
23240
23299
|
function getTxEstimatedVbytesSizeByNumberOfInputsOutputs(numInputs, numOutputs) {
|
|
23241
23300
|
const TX_OVERHEAD = 10;
|
|
@@ -23581,7 +23640,7 @@ function getEphemeralAnchorOutput() {
|
|
|
23581
23640
|
}
|
|
23582
23641
|
|
|
23583
23642
|
// src/services/transfer.ts
|
|
23584
|
-
var
|
|
23643
|
+
var import_utils9 = require("@noble/curves/abstract/utils");
|
|
23585
23644
|
var import_secp256k17 = require("@noble/curves/secp256k1");
|
|
23586
23645
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
23587
23646
|
var import_btc_signer2 = require("@scure/btc-signer");
|
|
@@ -23589,7 +23648,7 @@ var ecies2 = __toESM(require("eciesjs"), 1);
|
|
|
23589
23648
|
var import_uuidv7 = require("uuidv7");
|
|
23590
23649
|
|
|
23591
23650
|
// src/utils/transfer_package.ts
|
|
23592
|
-
var
|
|
23651
|
+
var import_utils8 = require("@noble/curves/abstract/utils");
|
|
23593
23652
|
var import_sha25 = require("@noble/hashes/sha2");
|
|
23594
23653
|
function getTransferPackageSigningPayload(transferID, transferPackage) {
|
|
23595
23654
|
const encryptedPayload = transferPackage.keyTweakPackage;
|
|
@@ -23598,7 +23657,7 @@ function getTransferPackageSigningPayload(transferID, transferPackage) {
|
|
|
23598
23657
|
).map(([key, value]) => ({ key, value }));
|
|
23599
23658
|
pairs.sort((a, b) => a.key.localeCompare(b.key));
|
|
23600
23659
|
const encoder = new TextEncoder();
|
|
23601
|
-
let message = (0,
|
|
23660
|
+
let message = (0, import_utils8.hexToBytes)(transferID.replaceAll("-", ""));
|
|
23602
23661
|
for (const pair of pairs) {
|
|
23603
23662
|
const keyPart = encoder.encode(pair.key + ":");
|
|
23604
23663
|
const separator = encoder.encode(";");
|
|
@@ -23978,7 +24037,7 @@ var BaseTransferService = class {
|
|
|
23978
24037
|
}
|
|
23979
24038
|
async prepareSendTransferKeyTweaks(transferID, receiverIdentityPubkey, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
|
|
23980
24039
|
const receiverEciesPubKey = ecies2.PublicKey.fromHex(
|
|
23981
|
-
(0,
|
|
24040
|
+
(0, import_utils9.bytesToHex)(receiverIdentityPubkey)
|
|
23982
24041
|
);
|
|
23983
24042
|
const leavesTweaksMap = /* @__PURE__ */ new Map();
|
|
23984
24043
|
for (const leaf of leaves) {
|
|
@@ -24019,7 +24078,7 @@ var BaseTransferService = class {
|
|
|
24019
24078
|
throw new Error(`Share not found for operator ${operator.id}`);
|
|
24020
24079
|
}
|
|
24021
24080
|
const pubkeyTweak = import_secp256k17.secp256k1.getPublicKey(
|
|
24022
|
-
(0,
|
|
24081
|
+
(0, import_utils9.numberToBytesBE)(share.share, 32),
|
|
24023
24082
|
true
|
|
24024
24083
|
);
|
|
24025
24084
|
pubkeySharesTweak.set(identifier, pubkeyTweak);
|
|
@@ -24044,7 +24103,7 @@ var BaseTransferService = class {
|
|
|
24044
24103
|
leafTweaksMap.set(identifier, {
|
|
24045
24104
|
leafId: leaf.leaf.id,
|
|
24046
24105
|
secretShareTweak: {
|
|
24047
|
-
secretShare: (0,
|
|
24106
|
+
secretShare: (0, import_utils9.numberToBytesBE)(share.share, 32),
|
|
24048
24107
|
proofs: share.proofs
|
|
24049
24108
|
},
|
|
24050
24109
|
pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
|
|
@@ -24067,7 +24126,7 @@ var BaseTransferService = class {
|
|
|
24067
24126
|
return void 0;
|
|
24068
24127
|
}
|
|
24069
24128
|
compareTransfers(transfer1, transfer2) {
|
|
24070
|
-
return transfer1.id === transfer2.id && (0,
|
|
24129
|
+
return transfer1.id === transfer2.id && (0, import_utils9.equalBytes)(
|
|
24071
24130
|
transfer1.senderIdentityPublicKey,
|
|
24072
24131
|
transfer2.senderIdentityPublicKey
|
|
24073
24132
|
) && transfer1.status === transfer2.status && transfer1.totalValue === transfer2.totalValue && transfer1.expiryTime?.getTime() === transfer2.expiryTime?.getTime() && transfer1.leaves.length === transfer2.leaves.length;
|
|
@@ -24366,7 +24425,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24366
24425
|
}
|
|
24367
24426
|
const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
|
|
24368
24427
|
const cpfpNodeOutPoint = {
|
|
24369
|
-
txid: (0,
|
|
24428
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
|
|
24370
24429
|
index: 0
|
|
24371
24430
|
};
|
|
24372
24431
|
let directNodeTx;
|
|
@@ -24374,7 +24433,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24374
24433
|
if (leaf.leaf.directTx.length > 0) {
|
|
24375
24434
|
directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
|
|
24376
24435
|
directNodeOutPoint = {
|
|
24377
|
-
txid: (0,
|
|
24436
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(directNodeTx)),
|
|
24378
24437
|
index: 0
|
|
24379
24438
|
};
|
|
24380
24439
|
}
|
|
@@ -24508,7 +24567,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24508
24567
|
throw new Error(`Share not found for operator ${operator.id}`);
|
|
24509
24568
|
}
|
|
24510
24569
|
const pubkeyTweak = import_secp256k17.secp256k1.getPublicKey(
|
|
24511
|
-
(0,
|
|
24570
|
+
(0, import_utils9.numberToBytesBE)(share.share, 32)
|
|
24512
24571
|
);
|
|
24513
24572
|
pubkeySharesTweak.set(identifier, pubkeyTweak);
|
|
24514
24573
|
}
|
|
@@ -24521,7 +24580,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24521
24580
|
leafTweaksMap.set(identifier, {
|
|
24522
24581
|
leafId: leaf.leaf.id,
|
|
24523
24582
|
secretShareTweak: {
|
|
24524
|
-
secretShare: (0,
|
|
24583
|
+
secretShare: (0, import_utils9.numberToBytesBE)(share.share, 32),
|
|
24525
24584
|
proofs: share.proofs
|
|
24526
24585
|
},
|
|
24527
24586
|
pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak)
|
|
@@ -24707,13 +24766,13 @@ var TransferService = class extends BaseTransferService {
|
|
|
24707
24766
|
});
|
|
24708
24767
|
}
|
|
24709
24768
|
const newCpfpRefundOutPoint = {
|
|
24710
|
-
txid: (0,
|
|
24769
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(cpfpNodeTx)),
|
|
24711
24770
|
index: 0
|
|
24712
24771
|
};
|
|
24713
24772
|
let newDirectRefundOutPoint;
|
|
24714
24773
|
if (newDirectNodeTx) {
|
|
24715
24774
|
newDirectRefundOutPoint = {
|
|
24716
|
-
txid: (0,
|
|
24775
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(newDirectNodeTx)),
|
|
24717
24776
|
index: 0
|
|
24718
24777
|
};
|
|
24719
24778
|
}
|
|
@@ -24841,7 +24900,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24841
24900
|
const refundTx = getTxFromRawTxBytes(node.refundTx);
|
|
24842
24901
|
const refundSequence = refundTx.getInput(0).sequence || 0;
|
|
24843
24902
|
const newNodeOutPoint = {
|
|
24844
|
-
txid: (0,
|
|
24903
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
|
|
24845
24904
|
index: 0
|
|
24846
24905
|
};
|
|
24847
24906
|
const {
|
|
@@ -24878,13 +24937,13 @@ var TransferService = class extends BaseTransferService {
|
|
|
24878
24937
|
});
|
|
24879
24938
|
}
|
|
24880
24939
|
const newCpfpRefundOutPoint = {
|
|
24881
|
-
txid: (0,
|
|
24940
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(newNodeTx)),
|
|
24882
24941
|
index: 0
|
|
24883
24942
|
};
|
|
24884
24943
|
let newDirectRefundOutPoint;
|
|
24885
24944
|
if (newDirectNodeTx) {
|
|
24886
24945
|
newDirectRefundOutPoint = {
|
|
24887
|
-
txid: (0,
|
|
24946
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(newDirectNodeTx)),
|
|
24888
24947
|
index: 0
|
|
24889
24948
|
};
|
|
24890
24949
|
}
|
|
@@ -25118,13 +25177,13 @@ var TransferService = class extends BaseTransferService {
|
|
|
25118
25177
|
};
|
|
25119
25178
|
const signingPublicKey = await this.config.signer.getPublicKeyFromDerivation(keyDerivation);
|
|
25120
25179
|
const cpfpRefundOutPoint = {
|
|
25121
|
-
txid: (0,
|
|
25180
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
|
|
25122
25181
|
index: 0
|
|
25123
25182
|
};
|
|
25124
25183
|
let directRefundOutPoint;
|
|
25125
25184
|
if (directNodeTx) {
|
|
25126
25185
|
directRefundOutPoint = {
|
|
25127
|
-
txid: (0,
|
|
25186
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(directNodeTx)),
|
|
25128
25187
|
index: 0
|
|
25129
25188
|
};
|
|
25130
25189
|
}
|
|
@@ -25499,9 +25558,9 @@ var CoopExitService = class extends BaseTransferService {
|
|
|
25499
25558
|
// src/services/deposit.ts
|
|
25500
25559
|
var import_secp256k18 = require("@noble/curves/secp256k1");
|
|
25501
25560
|
var import_sha28 = require("@noble/hashes/sha2");
|
|
25502
|
-
var
|
|
25561
|
+
var import_utils10 = require("@noble/hashes/utils");
|
|
25503
25562
|
var import_btc_signer4 = require("@scure/btc-signer");
|
|
25504
|
-
var
|
|
25563
|
+
var import_utils11 = require("@scure/btc-signer/utils");
|
|
25505
25564
|
|
|
25506
25565
|
// src/utils/proof.ts
|
|
25507
25566
|
var import_sha27 = require("@noble/hashes/sha2");
|
|
@@ -25567,7 +25626,7 @@ var DepositService = class {
|
|
|
25567
25626
|
if (operator.identifier === this.config.getCoordinatorIdentifier()) {
|
|
25568
25627
|
continue;
|
|
25569
25628
|
}
|
|
25570
|
-
const operatorPubkey2 = (0,
|
|
25629
|
+
const operatorPubkey2 = (0, import_utils10.hexToBytes)(operator.identityPublicKey);
|
|
25571
25630
|
const operatorSig = address2.depositAddressProof.addressSignatures[operator.identifier];
|
|
25572
25631
|
if (!operatorSig) {
|
|
25573
25632
|
throw new ValidationError("Operator signature not found", {
|
|
@@ -25576,7 +25635,11 @@ var DepositService = class {
|
|
|
25576
25635
|
});
|
|
25577
25636
|
}
|
|
25578
25637
|
const sig = import_secp256k18.secp256k1.Signature.fromDER(operatorSig);
|
|
25579
|
-
const isVerified2 = import_secp256k18.secp256k1.verify(
|
|
25638
|
+
const isVerified2 = import_secp256k18.secp256k1.verify(
|
|
25639
|
+
sig.toCompactRawBytes(),
|
|
25640
|
+
addrHash,
|
|
25641
|
+
operatorPubkey2
|
|
25642
|
+
);
|
|
25580
25643
|
if (!isVerified2) {
|
|
25581
25644
|
throw new ValidationError("Operator signature verification failed", {
|
|
25582
25645
|
field: "operatorSignature",
|
|
@@ -25652,7 +25715,7 @@ var DepositService = class {
|
|
|
25652
25715
|
});
|
|
25653
25716
|
}
|
|
25654
25717
|
const depositOutPoint = {
|
|
25655
|
-
txid: (0,
|
|
25718
|
+
txid: (0, import_utils10.hexToBytes)(getTxId(depositTx)),
|
|
25656
25719
|
index: vout
|
|
25657
25720
|
};
|
|
25658
25721
|
const depositTxOut = {
|
|
@@ -25671,8 +25734,8 @@ var DepositService = class {
|
|
|
25671
25734
|
const { cpfpRefundTx, directRefundTx, directFromCpfpRefundTx } = createRefundTxs({
|
|
25672
25735
|
sequence: INITIAL_SEQUENCE,
|
|
25673
25736
|
directSequence: INITIAL_DIRECT_SEQUENCE,
|
|
25674
|
-
input: { txid: (0,
|
|
25675
|
-
directInput: { txid: (0,
|
|
25737
|
+
input: { txid: (0, import_utils10.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
|
|
25738
|
+
directInput: { txid: (0, import_utils10.hexToBytes)(getTxId(directRootTx)), index: 0 },
|
|
25676
25739
|
amountSats: amount,
|
|
25677
25740
|
receivingPubkey: signingPubKey,
|
|
25678
25741
|
network: this.config.getNetwork()
|
|
@@ -25802,7 +25865,7 @@ var DepositService = class {
|
|
|
25802
25865
|
}
|
|
25803
25866
|
);
|
|
25804
25867
|
}
|
|
25805
|
-
if (!(0,
|
|
25868
|
+
if (!(0, import_utils11.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
|
|
25806
25869
|
throw new ValidationError("Verifying key mismatch", {
|
|
25807
25870
|
field: "verifyingKey",
|
|
25808
25871
|
value: treeResp.rootNodeSignatureShares.verifyingKey,
|
|
@@ -25966,7 +26029,7 @@ var DepositService = class {
|
|
|
25966
26029
|
});
|
|
25967
26030
|
}
|
|
25968
26031
|
const depositOutPoint = {
|
|
25969
|
-
txid: (0,
|
|
26032
|
+
txid: (0, import_utils10.hexToBytes)(getTxId(depositTx)),
|
|
25970
26033
|
index: vout
|
|
25971
26034
|
};
|
|
25972
26035
|
const depositTxOut = {
|
|
@@ -25979,7 +26042,7 @@ var DepositService = class {
|
|
|
25979
26042
|
const signingPubKey = await this.config.signer.getPublicKeyFromDerivation(keyDerivation);
|
|
25980
26043
|
const { cpfpRefundTx } = createRefundTxs({
|
|
25981
26044
|
sequence: INITIAL_SEQUENCE,
|
|
25982
|
-
input: { txid: (0,
|
|
26045
|
+
input: { txid: (0, import_utils10.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
|
|
25983
26046
|
amountSats: amount,
|
|
25984
26047
|
receivingPubkey: signingPubKey,
|
|
25985
26048
|
network: this.config.getNetwork()
|
|
@@ -26049,7 +26112,7 @@ var DepositService = class {
|
|
|
26049
26112
|
}
|
|
26050
26113
|
);
|
|
26051
26114
|
}
|
|
26052
|
-
if (!(0,
|
|
26115
|
+
if (!(0, import_utils11.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
|
|
26053
26116
|
throw new ValidationError("Verifying key mismatch", {
|
|
26054
26117
|
field: "verifyingKey",
|
|
26055
26118
|
value: treeResp.rootNodeSignatureShares.verifyingKey,
|
|
@@ -26124,7 +26187,7 @@ var DepositService = class {
|
|
|
26124
26187
|
};
|
|
26125
26188
|
|
|
26126
26189
|
// src/services/lightning.ts
|
|
26127
|
-
var
|
|
26190
|
+
var import_utils12 = require("@noble/curves/abstract/utils");
|
|
26128
26191
|
var import_secp256k19 = require("@noble/curves/secp256k1");
|
|
26129
26192
|
var import_sha29 = require("@noble/hashes/sha2");
|
|
26130
26193
|
var import_uuidv73 = require("uuidv7");
|
|
@@ -26210,8 +26273,8 @@ var LightningService = class {
|
|
|
26210
26273
|
}) {
|
|
26211
26274
|
const crypto = getCrypto();
|
|
26212
26275
|
const randBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
26213
|
-
const preimage = (0,
|
|
26214
|
-
(0,
|
|
26276
|
+
const preimage = (0, import_utils12.numberToBytesBE)(
|
|
26277
|
+
(0, import_utils12.bytesToNumberBE)(randBytes) % import_secp256k19.secp256k1.CURVE.n,
|
|
26215
26278
|
32
|
|
26216
26279
|
);
|
|
26217
26280
|
return await this.createLightningInvoiceWithPreImage({
|
|
@@ -26266,12 +26329,12 @@ var LightningService = class {
|
|
|
26266
26329
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
26267
26330
|
operator.address
|
|
26268
26331
|
);
|
|
26269
|
-
const userIdentityPublicKey = receiverIdentityPubkey ? (0,
|
|
26332
|
+
const userIdentityPublicKey = receiverIdentityPubkey ? (0, import_utils12.hexToBytes)(receiverIdentityPubkey) : await this.config.signer.getIdentityPublicKey();
|
|
26270
26333
|
try {
|
|
26271
26334
|
await sparkClient.store_preimage_share({
|
|
26272
26335
|
paymentHash,
|
|
26273
26336
|
preimageShare: {
|
|
26274
|
-
secretShare: (0,
|
|
26337
|
+
secretShare: (0, import_utils12.numberToBytesBE)(share.share, 32),
|
|
26275
26338
|
proofs: share.proofs
|
|
26276
26339
|
},
|
|
26277
26340
|
threshold: this.config.getThreshold(),
|
|
@@ -26471,14 +26534,17 @@ var LightningService = class {
|
|
|
26471
26534
|
};
|
|
26472
26535
|
|
|
26473
26536
|
// src/services/token-transactions.ts
|
|
26474
|
-
var
|
|
26537
|
+
var import_utils17 = require("@noble/curves/abstract/utils");
|
|
26475
26538
|
var import_secp256k112 = require("@noble/curves/secp256k1");
|
|
26476
|
-
var
|
|
26539
|
+
var import_utils18 = require("@noble/hashes/utils");
|
|
26477
26540
|
|
|
26478
26541
|
// src/utils/address.ts
|
|
26542
|
+
var import_wire8 = require("@bufbuild/protobuf/wire");
|
|
26543
|
+
var import_utils13 = require("@noble/curves/abstract/utils");
|
|
26479
26544
|
var import_secp256k110 = require("@noble/curves/secp256k1");
|
|
26480
|
-
var
|
|
26545
|
+
var import_utils14 = require("@noble/hashes/utils");
|
|
26481
26546
|
var import_base2 = require("@scure/base");
|
|
26547
|
+
var import_uuidv74 = require("uuidv7");
|
|
26482
26548
|
|
|
26483
26549
|
// src/utils/invoice-hashing.ts
|
|
26484
26550
|
var import_sha210 = require("@noble/hashes/sha2");
|
|
@@ -26647,9 +26713,6 @@ function uint64be(value) {
|
|
|
26647
26713
|
}
|
|
26648
26714
|
|
|
26649
26715
|
// src/utils/address.ts
|
|
26650
|
-
var import_uuidv74 = require("uuidv7");
|
|
26651
|
-
var import_utils13 = require("@noble/curves/abstract/utils");
|
|
26652
|
-
var import_wire8 = require("@bufbuild/protobuf/wire");
|
|
26653
26716
|
var BECH32M_LIMIT = 1024;
|
|
26654
26717
|
var AddressNetwork = {
|
|
26655
26718
|
MAINNET: "sp",
|
|
@@ -26664,7 +26727,7 @@ function encodeSparkAddress(payload) {
|
|
|
26664
26727
|
function encodeSparkAddressWithSignature(payload, signature) {
|
|
26665
26728
|
try {
|
|
26666
26729
|
isValidPublicKey(payload.identityPublicKey);
|
|
26667
|
-
const identityPublicKey = (0,
|
|
26730
|
+
const identityPublicKey = (0, import_utils14.hexToBytes)(payload.identityPublicKey);
|
|
26668
26731
|
let sparkInvoiceFields;
|
|
26669
26732
|
if (payload.sparkInvoiceFields) {
|
|
26670
26733
|
validateSparkInvoiceFields(payload.sparkInvoiceFields);
|
|
@@ -26708,8 +26771,8 @@ function decodeSparkAddress(address2, network) {
|
|
|
26708
26771
|
}
|
|
26709
26772
|
const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
|
|
26710
26773
|
const { identityPublicKey, sparkInvoiceFields, signature } = payload;
|
|
26711
|
-
const identityPubkeyHex = (0,
|
|
26712
|
-
const signatureHex = signature ? (0,
|
|
26774
|
+
const identityPubkeyHex = (0, import_utils14.bytesToHex)(identityPublicKey);
|
|
26775
|
+
const signatureHex = signature ? (0, import_utils14.bytesToHex)(signature) : void 0;
|
|
26713
26776
|
isValidPublicKey(identityPubkeyHex);
|
|
26714
26777
|
return {
|
|
26715
26778
|
identityPublicKey: identityPubkeyHex,
|
|
@@ -26719,7 +26782,7 @@ function decodeSparkAddress(address2, network) {
|
|
|
26719
26782
|
id: import_uuidv74.UUID.ofInner(sparkInvoiceFields.id).toString(),
|
|
26720
26783
|
paymentType: sparkInvoiceFields.paymentType ? sparkInvoiceFields.paymentType.$case === "tokensPayment" ? {
|
|
26721
26784
|
type: "tokens",
|
|
26722
|
-
tokenIdentifier: sparkInvoiceFields.paymentType.tokensPayment.tokenIdentifier ? (0,
|
|
26785
|
+
tokenIdentifier: sparkInvoiceFields.paymentType.tokensPayment.tokenIdentifier ? (0, import_utils14.bytesToHex)(
|
|
26723
26786
|
sparkInvoiceFields.paymentType.tokensPayment.tokenIdentifier
|
|
26724
26787
|
) : void 0,
|
|
26725
26788
|
amount: sparkInvoiceFields.paymentType.tokensPayment.amount ? (0, import_utils13.bytesToNumberBE)(
|
|
@@ -26730,7 +26793,7 @@ function decodeSparkAddress(address2, network) {
|
|
|
26730
26793
|
amount: sparkInvoiceFields.paymentType.satsPayment.amount
|
|
26731
26794
|
} : void 0 : void 0,
|
|
26732
26795
|
memo: sparkInvoiceFields.memo,
|
|
26733
|
-
senderPublicKey: sparkInvoiceFields.senderPublicKey ? (0,
|
|
26796
|
+
senderPublicKey: sparkInvoiceFields.senderPublicKey ? (0, import_utils14.bytesToHex)(sparkInvoiceFields.senderPublicKey) : void 0,
|
|
26734
26797
|
expiryTime: sparkInvoiceFields.expiryTime
|
|
26735
26798
|
},
|
|
26736
26799
|
signature: signatureHex
|
|
@@ -26779,7 +26842,7 @@ function isValidSparkAddress(address2) {
|
|
|
26779
26842
|
}
|
|
26780
26843
|
function isValidPublicKey(publicKey) {
|
|
26781
26844
|
try {
|
|
26782
|
-
const point = import_secp256k110.secp256k1.
|
|
26845
|
+
const point = import_secp256k110.secp256k1.Point.fromHex(publicKey);
|
|
26783
26846
|
point.assertValidity();
|
|
26784
26847
|
} catch (error) {
|
|
26785
26848
|
throw new ValidationError(
|
|
@@ -26814,7 +26877,7 @@ function validateSparkInvoiceFields(sparkInvoiceFields) {
|
|
|
26814
26877
|
}
|
|
26815
26878
|
if (senderPublicKey) {
|
|
26816
26879
|
try {
|
|
26817
|
-
isValidPublicKey((0,
|
|
26880
|
+
isValidPublicKey((0, import_utils14.bytesToHex)(senderPublicKey));
|
|
26818
26881
|
} catch (error) {
|
|
26819
26882
|
throw new ValidationError(
|
|
26820
26883
|
"Invalid sender public key",
|
|
@@ -28963,12 +29026,12 @@ function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction
|
|
|
28963
29026
|
}
|
|
28964
29027
|
|
|
28965
29028
|
// src/utils/token-transactions.ts
|
|
28966
|
-
var
|
|
28967
|
-
var
|
|
29029
|
+
var import_utils15 = require("@noble/curves/abstract/utils");
|
|
29030
|
+
var import_utils16 = require("@scure/btc-signer/utils");
|
|
28968
29031
|
function sumAvailableTokens(outputs) {
|
|
28969
29032
|
try {
|
|
28970
29033
|
return outputs.reduce(
|
|
28971
|
-
(sum, output) => sum + BigInt((0,
|
|
29034
|
+
(sum, output) => sum + BigInt((0, import_utils15.bytesToNumberBE)(output.output.tokenAmount)),
|
|
28972
29035
|
BigInt(0)
|
|
28973
29036
|
);
|
|
28974
29037
|
} catch (error) {
|
|
@@ -28999,7 +29062,7 @@ function filterTokenBalanceForTokenIdentifier(tokenBalances, tokenIdentifier) {
|
|
|
28999
29062
|
}
|
|
29000
29063
|
const tokenIdentifierBytes = decodeBech32mTokenIdentifier(tokenIdentifier).tokenIdentifier;
|
|
29001
29064
|
const tokenBalance = [...tokenBalances.entries()].find(
|
|
29002
|
-
([, info]) => (0,
|
|
29065
|
+
([, info]) => (0, import_utils16.equalBytes)(info.tokenMetadata.rawTokenIdentifier, tokenIdentifierBytes)
|
|
29003
29066
|
);
|
|
29004
29067
|
if (!tokenBalance) {
|
|
29005
29068
|
return {
|
|
@@ -29102,14 +29165,14 @@ var TokenTransactionService = class {
|
|
|
29102
29165
|
}
|
|
29103
29166
|
if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
|
|
29104
29167
|
return {
|
|
29105
|
-
receiverPublicKey: (0,
|
|
29168
|
+
receiverPublicKey: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
|
|
29106
29169
|
rawTokenIdentifier,
|
|
29107
29170
|
tokenAmount: transfer.tokenAmount,
|
|
29108
29171
|
sparkInvoice: transfer.receiverSparkAddress
|
|
29109
29172
|
};
|
|
29110
29173
|
}
|
|
29111
29174
|
return {
|
|
29112
|
-
receiverPublicKey: (0,
|
|
29175
|
+
receiverPublicKey: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
|
|
29113
29176
|
rawTokenIdentifier,
|
|
29114
29177
|
tokenPublicKey,
|
|
29115
29178
|
// Remove for full v0 deprecation
|
|
@@ -29148,7 +29211,7 @@ var TokenTransactionService = class {
|
|
|
29148
29211
|
const tokenOutputs = tokenOutputData.map((output) => ({
|
|
29149
29212
|
ownerPublicKey: output.receiverPublicKey,
|
|
29150
29213
|
tokenPublicKey: output.tokenPublicKey,
|
|
29151
|
-
tokenAmount: (0,
|
|
29214
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
|
|
29152
29215
|
}));
|
|
29153
29216
|
if (availableTokenAmount > totalRequestedAmount) {
|
|
29154
29217
|
const changeAmount = availableTokenAmount - totalRequestedAmount;
|
|
@@ -29156,7 +29219,7 @@ var TokenTransactionService = class {
|
|
|
29156
29219
|
tokenOutputs.push({
|
|
29157
29220
|
ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
29158
29221
|
tokenPublicKey: firstTokenPublicKey,
|
|
29159
|
-
tokenAmount: (0,
|
|
29222
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
|
|
29160
29223
|
});
|
|
29161
29224
|
}
|
|
29162
29225
|
return {
|
|
@@ -29187,7 +29250,7 @@ var TokenTransactionService = class {
|
|
|
29187
29250
|
(output) => ({
|
|
29188
29251
|
ownerPublicKey: output.receiverPublicKey,
|
|
29189
29252
|
tokenIdentifier: output.rawTokenIdentifier,
|
|
29190
|
-
tokenAmount: (0,
|
|
29253
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
|
|
29191
29254
|
})
|
|
29192
29255
|
);
|
|
29193
29256
|
if (availableTokenAmount > totalRequestedAmount) {
|
|
@@ -29196,7 +29259,7 @@ var TokenTransactionService = class {
|
|
|
29196
29259
|
tokenOutputs.push({
|
|
29197
29260
|
ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
29198
29261
|
tokenIdentifier: firstTokenIdentifierBytes,
|
|
29199
|
-
tokenAmount: (0,
|
|
29262
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
|
|
29200
29263
|
});
|
|
29201
29264
|
}
|
|
29202
29265
|
return {
|
|
@@ -29223,7 +29286,7 @@ var TokenTransactionService = class {
|
|
|
29223
29286
|
for (const [_, operator] of Object.entries(
|
|
29224
29287
|
this.config.getSigningOperators()
|
|
29225
29288
|
)) {
|
|
29226
|
-
operatorKeys.push((0,
|
|
29289
|
+
operatorKeys.push((0, import_utils18.hexToBytes)(operator.identityPublicKey));
|
|
29227
29290
|
}
|
|
29228
29291
|
return operatorKeys;
|
|
29229
29292
|
}
|
|
@@ -29307,7 +29370,7 @@ var TokenTransactionService = class {
|
|
|
29307
29370
|
{
|
|
29308
29371
|
field: "revocationCommitment",
|
|
29309
29372
|
value: derivedRevocationCommitment,
|
|
29310
|
-
expected: (0,
|
|
29373
|
+
expected: (0, import_utils17.bytesToHex)(outputsToSpendCommitments[outputIndex]),
|
|
29311
29374
|
outputIndex
|
|
29312
29375
|
}
|
|
29313
29376
|
)
|
|
@@ -29333,7 +29396,7 @@ var TokenTransactionService = class {
|
|
|
29333
29396
|
threshold
|
|
29334
29397
|
);
|
|
29335
29398
|
}
|
|
29336
|
-
return (0,
|
|
29399
|
+
return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
|
|
29337
29400
|
}
|
|
29338
29401
|
async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
|
|
29339
29402
|
const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
|
|
@@ -29347,7 +29410,7 @@ var TokenTransactionService = class {
|
|
|
29347
29410
|
finalTokenTransactionHash,
|
|
29348
29411
|
signingOperators
|
|
29349
29412
|
);
|
|
29350
|
-
return (0,
|
|
29413
|
+
return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
|
|
29351
29414
|
}
|
|
29352
29415
|
async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
|
|
29353
29416
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
@@ -29571,7 +29634,7 @@ var TokenTransactionService = class {
|
|
|
29571
29634
|
const identityPublicKey = await this.config.signer.getIdentityPublicKey();
|
|
29572
29635
|
const payload = {
|
|
29573
29636
|
finalTokenTransactionHash,
|
|
29574
|
-
operatorIdentityPublicKey: (0,
|
|
29637
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
29575
29638
|
};
|
|
29576
29639
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
29577
29640
|
let operatorSpecificSignatures = [];
|
|
@@ -29786,8 +29849,8 @@ var TokenTransactionService = class {
|
|
|
29786
29849
|
this.config.getCoordinatorAddress()
|
|
29787
29850
|
);
|
|
29788
29851
|
let queryParams = {
|
|
29789
|
-
tokenPublicKeys: issuerPublicKeys?.map(
|
|
29790
|
-
ownerPublicKeys: ownerPublicKeys?.map(
|
|
29852
|
+
tokenPublicKeys: issuerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29853
|
+
ownerPublicKeys: ownerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29791
29854
|
tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
|
|
29792
29855
|
const { tokenIdentifier } = decodeBech32mTokenIdentifier(
|
|
29793
29856
|
identifier,
|
|
@@ -29795,7 +29858,7 @@ var TokenTransactionService = class {
|
|
|
29795
29858
|
);
|
|
29796
29859
|
return tokenIdentifier;
|
|
29797
29860
|
}),
|
|
29798
|
-
tokenTransactionHashes: tokenTransactionHashes?.map(
|
|
29861
|
+
tokenTransactionHashes: tokenTransactionHashes?.map(import_utils18.hexToBytes),
|
|
29799
29862
|
outputIds: outputIds || [],
|
|
29800
29863
|
limit: pageSize,
|
|
29801
29864
|
offset
|
|
@@ -29854,8 +29917,8 @@ var TokenTransactionService = class {
|
|
|
29854
29917
|
this.config.getCoordinatorAddress()
|
|
29855
29918
|
);
|
|
29856
29919
|
let queryParams = {
|
|
29857
|
-
issuerPublicKeys: issuerPublicKeys?.map(
|
|
29858
|
-
ownerPublicKeys: ownerPublicKeys?.map(
|
|
29920
|
+
issuerPublicKeys: issuerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29921
|
+
ownerPublicKeys: ownerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29859
29922
|
tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
|
|
29860
29923
|
const { tokenIdentifier } = decodeBech32mTokenIdentifier(
|
|
29861
29924
|
identifier,
|
|
@@ -29863,7 +29926,7 @@ var TokenTransactionService = class {
|
|
|
29863
29926
|
);
|
|
29864
29927
|
return tokenIdentifier;
|
|
29865
29928
|
}),
|
|
29866
|
-
tokenTransactionHashes: tokenTransactionHashes?.map(
|
|
29929
|
+
tokenTransactionHashes: tokenTransactionHashes?.map(import_utils18.hexToBytes),
|
|
29867
29930
|
outputIds: outputIds || [],
|
|
29868
29931
|
limit: pageSize,
|
|
29869
29932
|
offset
|
|
@@ -29898,7 +29961,7 @@ var TokenTransactionService = class {
|
|
|
29898
29961
|
});
|
|
29899
29962
|
}
|
|
29900
29963
|
const exactMatch = tokenOutputs.find(
|
|
29901
|
-
(item) => (0,
|
|
29964
|
+
(item) => (0, import_utils17.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
|
|
29902
29965
|
);
|
|
29903
29966
|
if (exactMatch) {
|
|
29904
29967
|
return [exactMatch];
|
|
@@ -29909,7 +29972,7 @@ var TokenTransactionService = class {
|
|
|
29909
29972
|
for (const outputWithPreviousTransactionData of tokenOutputs) {
|
|
29910
29973
|
if (remainingAmount <= 0n) break;
|
|
29911
29974
|
selectedOutputs.push(outputWithPreviousTransactionData);
|
|
29912
|
-
remainingAmount -= (0,
|
|
29975
|
+
remainingAmount -= (0, import_utils17.bytesToNumberBE)(
|
|
29913
29976
|
outputWithPreviousTransactionData.output.tokenAmount
|
|
29914
29977
|
);
|
|
29915
29978
|
}
|
|
@@ -29925,13 +29988,13 @@ var TokenTransactionService = class {
|
|
|
29925
29988
|
if (strategy === "SMALL_FIRST") {
|
|
29926
29989
|
tokenOutputs.sort((a, b) => {
|
|
29927
29990
|
return Number(
|
|
29928
|
-
(0,
|
|
29991
|
+
(0, import_utils17.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(b.output.tokenAmount)
|
|
29929
29992
|
);
|
|
29930
29993
|
});
|
|
29931
29994
|
} else {
|
|
29932
29995
|
tokenOutputs.sort((a, b) => {
|
|
29933
29996
|
return Number(
|
|
29934
|
-
(0,
|
|
29997
|
+
(0, import_utils17.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(a.output.tokenAmount)
|
|
29935
29998
|
);
|
|
29936
29999
|
});
|
|
29937
30000
|
}
|
|
@@ -29939,7 +30002,7 @@ var TokenTransactionService = class {
|
|
|
29939
30002
|
// Helper function for deciding if the signer public key is the identity public key
|
|
29940
30003
|
async signMessageWithKey(message, publicKey) {
|
|
29941
30004
|
const tokenSignatures = this.config.getTokenSignatures();
|
|
29942
|
-
if ((0,
|
|
30005
|
+
if ((0, import_utils17.bytesToHex)(publicKey) === (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
|
|
29943
30006
|
if (tokenSignatures === "SCHNORR") {
|
|
29944
30007
|
return await this.config.signer.signSchnorrWithIdentityKey(message);
|
|
29945
30008
|
} else {
|
|
@@ -29948,8 +30011,8 @@ var TokenTransactionService = class {
|
|
|
29948
30011
|
} else {
|
|
29949
30012
|
throw new ValidationError("Invalid public key", {
|
|
29950
30013
|
field: "publicKey",
|
|
29951
|
-
value: (0,
|
|
29952
|
-
expected: (0,
|
|
30014
|
+
value: (0, import_utils17.bytesToHex)(publicKey),
|
|
30015
|
+
expected: (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())
|
|
29953
30016
|
});
|
|
29954
30017
|
}
|
|
29955
30018
|
}
|
|
@@ -30012,7 +30075,7 @@ var TokenTransactionService = class {
|
|
|
30012
30075
|
}
|
|
30013
30076
|
const payload = {
|
|
30014
30077
|
finalTokenTransactionHash,
|
|
30015
|
-
operatorIdentityPublicKey: (0,
|
|
30078
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
30016
30079
|
};
|
|
30017
30080
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
30018
30081
|
const ownerSignature = await this.signMessageWithKey(
|
|
@@ -30034,7 +30097,7 @@ var TokenTransactionService = class {
|
|
|
30034
30097
|
}
|
|
30035
30098
|
const payload = {
|
|
30036
30099
|
finalTokenTransactionHash,
|
|
30037
|
-
operatorIdentityPublicKey: (0,
|
|
30100
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
30038
30101
|
};
|
|
30039
30102
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
30040
30103
|
const ownerSignature = await this.signMessageWithKey(
|
|
@@ -30050,7 +30113,7 @@ var TokenTransactionService = class {
|
|
|
30050
30113
|
for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
|
|
30051
30114
|
const payload = {
|
|
30052
30115
|
finalTokenTransactionHash,
|
|
30053
|
-
operatorIdentityPublicKey: (0,
|
|
30116
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
30054
30117
|
};
|
|
30055
30118
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
30056
30119
|
let ownerSignature;
|
|
@@ -30067,7 +30130,7 @@ var TokenTransactionService = class {
|
|
|
30067
30130
|
}
|
|
30068
30131
|
inputTtxoSignaturesPerOperator.push({
|
|
30069
30132
|
ttxoSignatures,
|
|
30070
|
-
operatorIdentityPublicKey: (0,
|
|
30133
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
30071
30134
|
});
|
|
30072
30135
|
}
|
|
30073
30136
|
return inputTtxoSignaturesPerOperator;
|
|
@@ -30079,23 +30142,23 @@ function isTokenTransaction(tokenTransaction) {
|
|
|
30079
30142
|
|
|
30080
30143
|
// src/utils/adaptor-signature.ts
|
|
30081
30144
|
var import_modular = require("@noble/curves/abstract/modular");
|
|
30082
|
-
var
|
|
30145
|
+
var import_utils19 = require("@noble/curves/abstract/utils");
|
|
30083
30146
|
var import_secp256k113 = require("@noble/curves/secp256k1");
|
|
30084
30147
|
function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
|
|
30085
30148
|
const { r, s } = parseSignature(signature);
|
|
30086
|
-
const sBigInt = (0,
|
|
30087
|
-
const tBigInt = (0,
|
|
30149
|
+
const sBigInt = (0, import_utils19.bytesToNumberBE)(s);
|
|
30150
|
+
const tBigInt = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKeyBytes);
|
|
30088
30151
|
const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
|
|
30089
|
-
const newSignature = new Uint8Array([...r, ...(0,
|
|
30152
|
+
const newSignature = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
|
|
30090
30153
|
return newSignature;
|
|
30091
30154
|
}
|
|
30092
30155
|
function generateAdaptorFromSignature(signature) {
|
|
30093
30156
|
const adaptorPrivateKey = import_secp256k113.secp256k1.utils.randomPrivateKey();
|
|
30094
30157
|
const { r, s } = parseSignature(signature);
|
|
30095
|
-
const sBigInt = (0,
|
|
30096
|
-
const tBigInt = (0,
|
|
30158
|
+
const sBigInt = (0, import_utils19.bytesToNumberBE)(s);
|
|
30159
|
+
const tBigInt = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKey);
|
|
30097
30160
|
const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
|
|
30098
|
-
const newSignature = new Uint8Array([...r, ...(0,
|
|
30161
|
+
const newSignature = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
|
|
30099
30162
|
return {
|
|
30100
30163
|
adaptorSignature: newSignature,
|
|
30101
30164
|
adaptorPrivateKey
|
|
@@ -30112,10 +30175,10 @@ function validateOutboundAdaptorSignature(pubkey, hash, signature, adaptorPubkey
|
|
|
30112
30175
|
}
|
|
30113
30176
|
function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes) {
|
|
30114
30177
|
const { r, s } = parseSignature(signature);
|
|
30115
|
-
const sBigInt = (0,
|
|
30116
|
-
const adaptorPrivateKey = (0,
|
|
30178
|
+
const sBigInt = (0, import_utils19.bytesToNumberBE)(s);
|
|
30179
|
+
const adaptorPrivateKey = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKeyBytes);
|
|
30117
30180
|
const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
|
|
30118
|
-
const newSig = new Uint8Array([...r, ...(0,
|
|
30181
|
+
const newSig = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
|
|
30119
30182
|
try {
|
|
30120
30183
|
if (import_secp256k113.schnorr.verify(newSig, hash, pubkey)) {
|
|
30121
30184
|
return newSig;
|
|
@@ -30124,7 +30187,7 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
|
|
|
30124
30187
|
console.error("[applyAdaptorToSignature] Addition verification failed:", e);
|
|
30125
30188
|
}
|
|
30126
30189
|
const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
|
|
30127
|
-
const altSig = new Uint8Array([...r, ...(0,
|
|
30190
|
+
const altSig = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(altS, 32)]);
|
|
30128
30191
|
try {
|
|
30129
30192
|
if (import_secp256k113.schnorr.verify(altSig, hash, pubkey)) {
|
|
30130
30193
|
return altSig;
|
|
@@ -30141,39 +30204,37 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
|
|
|
30141
30204
|
if (hash.length !== 32) {
|
|
30142
30205
|
throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
|
|
30143
30206
|
}
|
|
30144
|
-
const pubKey = import_secp256k113.schnorr.utils.lift_x((0,
|
|
30207
|
+
const pubKey = import_secp256k113.schnorr.utils.lift_x((0, import_utils19.bytesToNumberBE)(pubKeyBytes));
|
|
30145
30208
|
pubKey.assertValidity();
|
|
30146
30209
|
const { r, s } = parseSignature(signature);
|
|
30147
30210
|
const commitmenet = import_secp256k113.schnorr.utils.taggedHash(
|
|
30148
30211
|
"BIP0340/challenge",
|
|
30149
30212
|
r,
|
|
30150
|
-
pubKey.
|
|
30213
|
+
pubKey.toBytes().slice(1),
|
|
30151
30214
|
hash
|
|
30152
30215
|
);
|
|
30153
30216
|
if (commitmenet.length > 32) {
|
|
30154
30217
|
throw new Error("hash of (r || P || m) too big");
|
|
30155
30218
|
}
|
|
30156
|
-
const e = (0, import_modular.mod)((0,
|
|
30219
|
+
const e = (0, import_modular.mod)((0, import_utils19.bytesToNumberBE)(commitmenet), import_secp256k113.secp256k1.CURVE.n);
|
|
30157
30220
|
const negE = (0, import_modular.mod)(-e, import_secp256k113.secp256k1.CURVE.n);
|
|
30158
|
-
const
|
|
30159
|
-
|
|
30160
|
-
|
|
30161
|
-
|
|
30162
|
-
|
|
30163
|
-
if (!R) {
|
|
30164
|
-
throw new Error("R is undefined");
|
|
30221
|
+
const sG = import_secp256k113.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils19.bytesToNumberBE)(s));
|
|
30222
|
+
const eP = pubKey.multiplyUnsafe(negE);
|
|
30223
|
+
const R = sG.add(eP);
|
|
30224
|
+
if (R.is0()) {
|
|
30225
|
+
throw new Error("R is zero");
|
|
30165
30226
|
}
|
|
30166
30227
|
R.assertValidity();
|
|
30167
|
-
const adaptorPoint = import_secp256k113.secp256k1.
|
|
30228
|
+
const adaptorPoint = import_secp256k113.secp256k1.Point.fromHex(adaptorPubkey);
|
|
30168
30229
|
const newR = R.add(adaptorPoint);
|
|
30169
|
-
if (!inbound && newR.equals(import_secp256k113.secp256k1.
|
|
30230
|
+
if (!inbound && newR.equals(import_secp256k113.secp256k1.Point.ZERO)) {
|
|
30170
30231
|
throw new Error("calculated R point is the point at infinity");
|
|
30171
30232
|
}
|
|
30172
30233
|
newR.assertValidity();
|
|
30173
|
-
if (
|
|
30234
|
+
if (newR.y % 2n !== 0n) {
|
|
30174
30235
|
throw new Error("calculated R y-value is odd");
|
|
30175
30236
|
}
|
|
30176
|
-
const rNum = (0,
|
|
30237
|
+
const rNum = (0, import_utils19.bytesToNumberBE)(r);
|
|
30177
30238
|
if (newR.toAffine().x !== rNum) {
|
|
30178
30239
|
throw new Error("calculated R point was not given R");
|
|
30179
30240
|
}
|
|
@@ -30194,15 +30255,15 @@ function parseSignature(signature) {
|
|
|
30194
30255
|
}
|
|
30195
30256
|
const r = signature.slice(0, 32);
|
|
30196
30257
|
const s = signature.slice(32, 64);
|
|
30197
|
-
if ((0,
|
|
30258
|
+
if ((0, import_utils19.bytesToNumberBE)(r) >= import_secp256k113.secp256k1.CURVE.Fp.ORDER) {
|
|
30198
30259
|
throw new ValidationError("Invalid signature: r >= field prime", {
|
|
30199
|
-
rValue: (0,
|
|
30260
|
+
rValue: (0, import_utils19.bytesToNumberBE)(r),
|
|
30200
30261
|
fieldPrime: import_secp256k113.secp256k1.CURVE.Fp.ORDER
|
|
30201
30262
|
});
|
|
30202
30263
|
}
|
|
30203
|
-
if ((0,
|
|
30264
|
+
if ((0, import_utils19.bytesToNumberBE)(s) >= import_secp256k113.secp256k1.CURVE.n) {
|
|
30204
30265
|
throw new ValidationError("Invalid signature: s >= group order", {
|
|
30205
|
-
sValue: (0,
|
|
30266
|
+
sValue: (0, import_utils19.bytesToNumberBE)(s),
|
|
30206
30267
|
groupOrder: import_secp256k113.secp256k1.CURVE.n
|
|
30207
30268
|
});
|
|
30208
30269
|
}
|
|
@@ -30217,7 +30278,7 @@ var import_eventemitter3 = require("eventemitter3");
|
|
|
30217
30278
|
var import_nice_grpc_common3 = require("nice-grpc-common");
|
|
30218
30279
|
|
|
30219
30280
|
// src/services/signing.ts
|
|
30220
|
-
var
|
|
30281
|
+
var import_utils20 = require("@noble/curves/abstract/utils");
|
|
30221
30282
|
var SigningService = class {
|
|
30222
30283
|
config;
|
|
30223
30284
|
constructor(config) {
|
|
@@ -30273,7 +30334,7 @@ var SigningService = class {
|
|
|
30273
30334
|
}
|
|
30274
30335
|
const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
|
|
30275
30336
|
const cpfpNodeOutPoint = {
|
|
30276
|
-
txid: (0,
|
|
30337
|
+
txid: (0, import_utils20.hexToBytes)(getTxId(nodeTx)),
|
|
30277
30338
|
index: 0
|
|
30278
30339
|
};
|
|
30279
30340
|
const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
|
|
@@ -30299,7 +30360,7 @@ var SigningService = class {
|
|
|
30299
30360
|
if (leaf.leaf.directTx.length > 0) {
|
|
30300
30361
|
directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
|
|
30301
30362
|
directNodeOutPoint = {
|
|
30302
|
-
txid: (0,
|
|
30363
|
+
txid: (0, import_utils20.hexToBytes)(getTxId(directNodeTx)),
|
|
30303
30364
|
index: 0
|
|
30304
30365
|
};
|
|
30305
30366
|
}
|
|
@@ -30382,15 +30443,15 @@ var SigningService = class {
|
|
|
30382
30443
|
};
|
|
30383
30444
|
|
|
30384
30445
|
// src/tests/utils/test-faucet.ts
|
|
30385
|
-
var
|
|
30446
|
+
var import_utils21 = require("@noble/curves/abstract/utils");
|
|
30386
30447
|
var import_secp256k114 = require("@noble/curves/secp256k1");
|
|
30387
30448
|
var btc3 = __toESM(require("@scure/btc-signer"), 1);
|
|
30388
30449
|
var import_btc_signer5 = require("@scure/btc-signer");
|
|
30389
|
-
var
|
|
30390
|
-
var STATIC_FAUCET_KEY = (0,
|
|
30450
|
+
var import_utils22 = require("@scure/btc-signer/utils");
|
|
30451
|
+
var STATIC_FAUCET_KEY = (0, import_utils21.hexToBytes)(
|
|
30391
30452
|
"deadbeef1337cafe4242424242424242deadbeef1337cafe4242424242424242"
|
|
30392
30453
|
);
|
|
30393
|
-
var STATIC_MINING_KEY = (0,
|
|
30454
|
+
var STATIC_MINING_KEY = (0, import_utils21.hexToBytes)(
|
|
30394
30455
|
"1337cafe4242deadbeef4242424242421337cafe4242deadbeef424242424242"
|
|
30395
30456
|
);
|
|
30396
30457
|
var SATS_PER_BTC = 1e8;
|
|
@@ -30453,7 +30514,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30453
30514
|
if (!scanResult.success || scanResult.unspents.length === 0) {
|
|
30454
30515
|
const blockHash = await this.generateToAddress(1, address2);
|
|
30455
30516
|
const block = await this.getBlock(blockHash[0]);
|
|
30456
|
-
const fundingTx = import_btc_signer5.Transaction.fromRaw((0,
|
|
30517
|
+
const fundingTx = import_btc_signer5.Transaction.fromRaw((0, import_utils21.hexToBytes)(block.tx[0].hex), {
|
|
30457
30518
|
allowUnknownOutputs: true
|
|
30458
30519
|
});
|
|
30459
30520
|
await this.generateToAddress(100, this.miningAddress);
|
|
@@ -30515,13 +30576,13 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30515
30576
|
},
|
|
30516
30577
|
STATIC_MINING_KEY
|
|
30517
30578
|
);
|
|
30518
|
-
await this.broadcastTx((0,
|
|
30579
|
+
await this.broadcastTx((0, import_utils21.bytesToHex)(signedSplitTx.extract()));
|
|
30519
30580
|
const splitTxId = signedSplitTx.id;
|
|
30520
30581
|
for (let i = 0; i < numCoinsToCreate; i++) {
|
|
30521
30582
|
this.coins.push({
|
|
30522
30583
|
key: STATIC_FAUCET_KEY,
|
|
30523
30584
|
outpoint: {
|
|
30524
|
-
txid: (0,
|
|
30585
|
+
txid: (0, import_utils21.hexToBytes)(splitTxId),
|
|
30525
30586
|
index: i
|
|
30526
30587
|
},
|
|
30527
30588
|
txout: signedSplitTx.getOutput(i)
|
|
@@ -30549,7 +30610,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30549
30610
|
coinToSend.txout,
|
|
30550
30611
|
coinToSend.key
|
|
30551
30612
|
);
|
|
30552
|
-
await this.broadcastTx((0,
|
|
30613
|
+
await this.broadcastTx((0, import_utils21.bytesToHex)(signedTx.extract()));
|
|
30553
30614
|
}
|
|
30554
30615
|
async signFaucetCoin(unsignedTx, fundingTxOut, key) {
|
|
30555
30616
|
const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
|
|
@@ -30569,7 +30630,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30569
30630
|
new Array(unsignedTx.inputsLength).fill(fundingTxOut.amount)
|
|
30570
30631
|
);
|
|
30571
30632
|
const merkleRoot = new Uint8Array();
|
|
30572
|
-
const tweakedKey = (0,
|
|
30633
|
+
const tweakedKey = (0, import_utils22.taprootTweakPrivKey)(key, merkleRoot);
|
|
30573
30634
|
if (!tweakedKey)
|
|
30574
30635
|
throw new Error("Invalid private key for taproot tweaking");
|
|
30575
30636
|
const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
|
|
@@ -30669,7 +30730,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30669
30730
|
});
|
|
30670
30731
|
}
|
|
30671
30732
|
const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
|
|
30672
|
-
const txHex = (0,
|
|
30733
|
+
const txHex = (0, import_utils21.bytesToHex)(signedTx.extract());
|
|
30673
30734
|
await this.broadcastTx(txHex);
|
|
30674
30735
|
const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
|
|
30675
30736
|
const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
|
|
@@ -30686,18 +30747,18 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30686
30747
|
};
|
|
30687
30748
|
|
|
30688
30749
|
// src/types/sdk-types.ts
|
|
30689
|
-
var
|
|
30750
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
|
30690
30751
|
function mapTreeNodeToWalletLeaf(proto) {
|
|
30691
30752
|
return {
|
|
30692
30753
|
id: proto.id,
|
|
30693
30754
|
treeId: proto.treeId,
|
|
30694
30755
|
value: proto.value,
|
|
30695
30756
|
parentNodeId: proto.parentNodeId,
|
|
30696
|
-
nodeTx: (0,
|
|
30697
|
-
refundTx: (0,
|
|
30757
|
+
nodeTx: (0, import_utils23.bytesToHex)(proto.nodeTx),
|
|
30758
|
+
refundTx: (0, import_utils23.bytesToHex)(proto.refundTx),
|
|
30698
30759
|
vout: proto.vout,
|
|
30699
|
-
verifyingPublicKey: (0,
|
|
30700
|
-
ownerIdentityPublicKey: (0,
|
|
30760
|
+
verifyingPublicKey: (0, import_utils23.bytesToHex)(proto.verifyingPublicKey),
|
|
30761
|
+
ownerIdentityPublicKey: (0, import_utils23.bytesToHex)(proto.ownerIdentityPublicKey),
|
|
30701
30762
|
signingKeyshare: proto.signingKeyshare,
|
|
30702
30763
|
status: proto.status,
|
|
30703
30764
|
network: Network[proto.network]
|
|
@@ -30706,14 +30767,14 @@ function mapTreeNodeToWalletLeaf(proto) {
|
|
|
30706
30767
|
function mapTransferLeafToWalletTransferLeaf(proto) {
|
|
30707
30768
|
return {
|
|
30708
30769
|
leaf: proto.leaf ? mapTreeNodeToWalletLeaf(proto.leaf) : void 0,
|
|
30709
|
-
secretCipher: (0,
|
|
30710
|
-
signature: (0,
|
|
30711
|
-
intermediateRefundTx: (0,
|
|
30770
|
+
secretCipher: (0, import_utils23.bytesToHex)(proto.secretCipher),
|
|
30771
|
+
signature: (0, import_utils23.bytesToHex)(proto.signature),
|
|
30772
|
+
intermediateRefundTx: (0, import_utils23.bytesToHex)(proto.intermediateRefundTx)
|
|
30712
30773
|
};
|
|
30713
30774
|
}
|
|
30714
30775
|
function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
|
|
30715
|
-
const receiverIdentityPublicKey = (0,
|
|
30716
|
-
const senderIdentityPublicKey = (0,
|
|
30776
|
+
const receiverIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.receiverIdentityPublicKey);
|
|
30777
|
+
const senderIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.senderIdentityPublicKey);
|
|
30717
30778
|
return {
|
|
30718
30779
|
id: proto.id,
|
|
30719
30780
|
senderIdentityPublicKey,
|
|
@@ -30903,7 +30964,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
30903
30964
|
try {
|
|
30904
30965
|
if (event?.$case === "transfer" && event.transfer.transfer && event.transfer.transfer.type !== 40 /* COUNTER_SWAP */) {
|
|
30905
30966
|
const { senderIdentityPublicKey, receiverIdentityPublicKey } = event.transfer.transfer;
|
|
30906
|
-
if (event.transfer.transfer && !(0,
|
|
30967
|
+
if (event.transfer.transfer && !(0, import_utils24.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
|
|
30907
30968
|
await this.claimTransfer({
|
|
30908
30969
|
transfer: event.transfer.transfer,
|
|
30909
30970
|
emit: true,
|
|
@@ -30972,7 +31033,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
30972
31033
|
setTimeout(maybeUnref, 100);
|
|
30973
31034
|
}
|
|
30974
31035
|
};
|
|
30975
|
-
if (
|
|
31036
|
+
if (import_core13.isNode) {
|
|
30976
31037
|
maybeUnref();
|
|
30977
31038
|
}
|
|
30978
31039
|
const claimedTransfersIds = await this.claimTransfers();
|
|
@@ -31068,10 +31129,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31068
31129
|
leavesToIgnore.add(nodeId);
|
|
31069
31130
|
continue;
|
|
31070
31131
|
}
|
|
31071
|
-
if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0,
|
|
31132
|
+
if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils24.equalBytes)(
|
|
31072
31133
|
leaf.signingKeyshare.publicKey,
|
|
31073
31134
|
operatorLeaf.signingKeyshare.publicKey
|
|
31074
|
-
) || !(0,
|
|
31135
|
+
) || !(0, import_utils24.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx)) {
|
|
31075
31136
|
leavesToIgnore.add(nodeId);
|
|
31076
31137
|
}
|
|
31077
31138
|
}
|
|
@@ -31122,7 +31183,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31122
31183
|
});
|
|
31123
31184
|
}
|
|
31124
31185
|
verifyKey(pubkey1, pubkey2, verifyingKey) {
|
|
31125
|
-
return (0,
|
|
31186
|
+
return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
|
|
31126
31187
|
}
|
|
31127
31188
|
async selectLeaves(targetAmounts) {
|
|
31128
31189
|
if (targetAmounts.length === 0) {
|
|
@@ -31280,7 +31341,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31280
31341
|
* @returns {Promise<string>} The identity public key as a hex string.
|
|
31281
31342
|
*/
|
|
31282
31343
|
async getIdentityPublicKey() {
|
|
31283
|
-
return (0,
|
|
31344
|
+
return (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey());
|
|
31284
31345
|
}
|
|
31285
31346
|
/**
|
|
31286
31347
|
* Gets the Spark address of the wallet.
|
|
@@ -31290,7 +31351,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31290
31351
|
async getSparkAddress() {
|
|
31291
31352
|
if (!this.sparkAddress) {
|
|
31292
31353
|
this.sparkAddress = encodeSparkAddress({
|
|
31293
|
-
identityPublicKey: (0,
|
|
31354
|
+
identityPublicKey: (0, import_utils24.bytesToHex)(
|
|
31294
31355
|
await this.config.signer.getIdentityPublicKey()
|
|
31295
31356
|
),
|
|
31296
31357
|
network: this.config.getNetworkType()
|
|
@@ -31353,7 +31414,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31353
31414
|
$case: "tokensPayment",
|
|
31354
31415
|
tokensPayment: {
|
|
31355
31416
|
tokenIdentifier: decodedTokenIdentifier ?? void 0,
|
|
31356
|
-
amount: amount ? (0,
|
|
31417
|
+
amount: amount ? (0, import_utils24.numberToVarBytesBE)(amount) : void 0
|
|
31357
31418
|
}
|
|
31358
31419
|
};
|
|
31359
31420
|
const invoiceFields = {
|
|
@@ -31361,7 +31422,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31361
31422
|
id: (0, import_uuidv75.uuidv7obj)().bytes,
|
|
31362
31423
|
paymentType: protoPayment,
|
|
31363
31424
|
memo: memo ?? void 0,
|
|
31364
|
-
senderPublicKey: senderPublicKey ? (0,
|
|
31425
|
+
senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
|
|
31365
31426
|
expiryTime: expiryTime ?? void 0
|
|
31366
31427
|
};
|
|
31367
31428
|
validateSparkInvoiceFields(invoiceFields);
|
|
@@ -31374,7 +31435,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31374
31435
|
const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
|
|
31375
31436
|
return encodeSparkAddressWithSignature(
|
|
31376
31437
|
{
|
|
31377
|
-
identityPublicKey: (0,
|
|
31438
|
+
identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
|
|
31378
31439
|
network: this.config.getNetworkType(),
|
|
31379
31440
|
sparkInvoiceFields: invoiceFields
|
|
31380
31441
|
},
|
|
@@ -31420,7 +31481,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31420
31481
|
mnemonic = mnemonicOrSeed;
|
|
31421
31482
|
seed = await this.config.signer.mnemonicToSeed(mnemonicOrSeed);
|
|
31422
31483
|
} else {
|
|
31423
|
-
seed = (0,
|
|
31484
|
+
seed = (0, import_utils24.hexToBytes)(mnemonicOrSeed);
|
|
31424
31485
|
}
|
|
31425
31486
|
}
|
|
31426
31487
|
await this.initWalletFromSeed(seed, accountNumber);
|
|
@@ -31442,7 +31503,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31442
31503
|
});
|
|
31443
31504
|
}
|
|
31444
31505
|
this.sparkAddress = encodeSparkAddress({
|
|
31445
|
-
identityPublicKey: (0,
|
|
31506
|
+
identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
|
|
31446
31507
|
network: this.config.getNetworkType()
|
|
31447
31508
|
});
|
|
31448
31509
|
return this.sparkAddress;
|
|
@@ -31531,7 +31592,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31531
31592
|
throw new Error("targetAmount or leaves must be provided");
|
|
31532
31593
|
}
|
|
31533
31594
|
leavesToSwap.sort((a, b) => a.value - b.value);
|
|
31534
|
-
const batches = chunkArray(leavesToSwap,
|
|
31595
|
+
const batches = chunkArray(leavesToSwap, 64);
|
|
31535
31596
|
const results = [];
|
|
31536
31597
|
for (const batch of batches) {
|
|
31537
31598
|
const result = await this.processSwapBatch(batch, targetAmounts);
|
|
@@ -31562,7 +31623,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31562
31623
|
directFromCpfpSignatureMap
|
|
31563
31624
|
} = await this.transferService.startSwapSignRefund(
|
|
31564
31625
|
leafKeyTweaks,
|
|
31565
|
-
(0,
|
|
31626
|
+
(0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey()),
|
|
31566
31627
|
new Date(Date.now() + 2 * 60 * 1e3)
|
|
31567
31628
|
);
|
|
31568
31629
|
try {
|
|
@@ -31622,18 +31683,18 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31622
31683
|
const userLeaves = [];
|
|
31623
31684
|
userLeaves.push({
|
|
31624
31685
|
leaf_id: transfer.leaves[0].leaf.id,
|
|
31625
|
-
raw_unsigned_refund_transaction: (0,
|
|
31686
|
+
raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31626
31687
|
transfer.leaves[0].intermediateRefundTx
|
|
31627
31688
|
),
|
|
31628
|
-
direct_raw_unsigned_refund_transaction: (0,
|
|
31689
|
+
direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31629
31690
|
transfer.leaves[0].intermediateDirectRefundTx
|
|
31630
31691
|
),
|
|
31631
|
-
direct_from_cpfp_raw_unsigned_refund_transaction: (0,
|
|
31692
|
+
direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31632
31693
|
transfer.leaves[0].intermediateDirectFromCpfpRefundTx
|
|
31633
31694
|
),
|
|
31634
|
-
adaptor_added_signature: (0,
|
|
31635
|
-
direct_adaptor_added_signature: (0,
|
|
31636
|
-
direct_from_cpfp_adaptor_added_signature: (0,
|
|
31695
|
+
adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpAdaptorSignature),
|
|
31696
|
+
direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directAdaptorSignature),
|
|
31697
|
+
direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
|
|
31637
31698
|
directFromCpfpAdaptorSignature
|
|
31638
31699
|
)
|
|
31639
31700
|
});
|
|
@@ -31686,24 +31747,24 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31686
31747
|
}
|
|
31687
31748
|
userLeaves.push({
|
|
31688
31749
|
leaf_id: leaf.leaf.id,
|
|
31689
|
-
raw_unsigned_refund_transaction: (0,
|
|
31750
|
+
raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31690
31751
|
leaf.intermediateRefundTx
|
|
31691
31752
|
),
|
|
31692
|
-
direct_raw_unsigned_refund_transaction: (0,
|
|
31753
|
+
direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31693
31754
|
leaf.intermediateDirectRefundTx
|
|
31694
31755
|
),
|
|
31695
|
-
direct_from_cpfp_raw_unsigned_refund_transaction: (0,
|
|
31756
|
+
direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31696
31757
|
leaf.intermediateDirectFromCpfpRefundTx
|
|
31697
31758
|
),
|
|
31698
|
-
adaptor_added_signature: (0,
|
|
31699
|
-
direct_adaptor_added_signature: (0,
|
|
31700
|
-
direct_from_cpfp_adaptor_added_signature: (0,
|
|
31759
|
+
adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpSignature),
|
|
31760
|
+
direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directSignature),
|
|
31761
|
+
direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
|
|
31701
31762
|
directFromCpfpSignature
|
|
31702
31763
|
)
|
|
31703
31764
|
});
|
|
31704
31765
|
}
|
|
31705
31766
|
const sspClient = this.getSspClient();
|
|
31706
|
-
const cpfpAdaptorPubkey = (0,
|
|
31767
|
+
const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
|
|
31707
31768
|
import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
|
|
31708
31769
|
);
|
|
31709
31770
|
if (!cpfpAdaptorPubkey) {
|
|
@@ -31711,13 +31772,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31711
31772
|
}
|
|
31712
31773
|
let directAdaptorPubkey;
|
|
31713
31774
|
if (directAdaptorPrivateKey.length > 0) {
|
|
31714
|
-
directAdaptorPubkey = (0,
|
|
31775
|
+
directAdaptorPubkey = (0, import_utils24.bytesToHex)(
|
|
31715
31776
|
import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
|
|
31716
31777
|
);
|
|
31717
31778
|
}
|
|
31718
31779
|
let directFromCpfpAdaptorPubkey;
|
|
31719
31780
|
if (directFromCpfpAdaptorPrivateKey.length > 0) {
|
|
31720
|
-
directFromCpfpAdaptorPubkey = (0,
|
|
31781
|
+
directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
|
|
31721
31782
|
import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
|
|
31722
31783
|
);
|
|
31723
31784
|
}
|
|
@@ -31777,7 +31838,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31777
31838
|
throw new Error(`Leaf not found for node ${nodeId}`);
|
|
31778
31839
|
}
|
|
31779
31840
|
const cpfpNodeTx = getTxFromRawTxBytes(node.nodeTx);
|
|
31780
|
-
const cpfpRefundTxBytes = (0,
|
|
31841
|
+
const cpfpRefundTxBytes = (0, import_utils24.hexToBytes)(leaf.rawUnsignedRefundTransaction);
|
|
31781
31842
|
const cpfpRefundTx = getTxFromRawTxBytes(cpfpRefundTxBytes);
|
|
31782
31843
|
const cpfpSighash = getSigHashFromTx(
|
|
31783
31844
|
cpfpRefundTx,
|
|
@@ -31786,7 +31847,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31786
31847
|
);
|
|
31787
31848
|
const nodePublicKey = node.verifyingPublicKey;
|
|
31788
31849
|
const taprootKey = computeTaprootKeyNoScript(nodePublicKey.slice(1));
|
|
31789
|
-
const cpfpAdaptorSignatureBytes = (0,
|
|
31850
|
+
const cpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
|
|
31790
31851
|
leaf.adaptorSignedSignature
|
|
31791
31852
|
);
|
|
31792
31853
|
applyAdaptorToSignature(
|
|
@@ -31797,7 +31858,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31797
31858
|
);
|
|
31798
31859
|
if (leaf.directRawUnsignedRefundTransaction) {
|
|
31799
31860
|
const directNodeTx = getTxFromRawTxBytes(node.directTx);
|
|
31800
|
-
const directRefundTxBytes = (0,
|
|
31861
|
+
const directRefundTxBytes = (0, import_utils24.hexToBytes)(
|
|
31801
31862
|
leaf.directRawUnsignedRefundTransaction
|
|
31802
31863
|
);
|
|
31803
31864
|
const directRefundTx = getTxFromRawTxBytes(directRefundTxBytes);
|
|
@@ -31811,7 +31872,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31811
31872
|
`Direct adaptor signed signature missing for node ${nodeId}`
|
|
31812
31873
|
);
|
|
31813
31874
|
}
|
|
31814
|
-
const directAdaptorSignatureBytes = (0,
|
|
31875
|
+
const directAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
|
|
31815
31876
|
leaf.directAdaptorSignedSignature
|
|
31816
31877
|
);
|
|
31817
31878
|
applyAdaptorToSignature(
|
|
@@ -31822,7 +31883,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31822
31883
|
);
|
|
31823
31884
|
}
|
|
31824
31885
|
if (leaf.directFromCpfpRawUnsignedRefundTransaction) {
|
|
31825
|
-
const directFromCpfpRefundTxBytes = (0,
|
|
31886
|
+
const directFromCpfpRefundTxBytes = (0, import_utils24.hexToBytes)(
|
|
31826
31887
|
leaf.directFromCpfpRawUnsignedRefundTransaction
|
|
31827
31888
|
);
|
|
31828
31889
|
const directFromCpfpRefundTx = getTxFromRawTxBytes(
|
|
@@ -31838,7 +31899,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31838
31899
|
`Direct adaptor signed signature missing for node ${nodeId}`
|
|
31839
31900
|
);
|
|
31840
31901
|
}
|
|
31841
|
-
const directFromCpfpAdaptorSignatureBytes = (0,
|
|
31902
|
+
const directFromCpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
|
|
31842
31903
|
leaf.directFromCpfpAdaptorSignedSignature
|
|
31843
31904
|
);
|
|
31844
31905
|
applyAdaptorToSignature(
|
|
@@ -31857,9 +31918,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31857
31918
|
directFromCpfpSignatureMap
|
|
31858
31919
|
);
|
|
31859
31920
|
const completeResponse = await sspClient.completeLeaveSwap({
|
|
31860
|
-
adaptorSecretKey: (0,
|
|
31861
|
-
directAdaptorSecretKey: (0,
|
|
31862
|
-
directFromCpfpAdaptorSecretKey: (0,
|
|
31921
|
+
adaptorSecretKey: (0, import_utils24.bytesToHex)(cpfpAdaptorPrivateKey),
|
|
31922
|
+
directAdaptorSecretKey: (0, import_utils24.bytesToHex)(directAdaptorPrivateKey),
|
|
31923
|
+
directFromCpfpAdaptorSecretKey: (0, import_utils24.bytesToHex)(
|
|
31863
31924
|
directFromCpfpAdaptorPrivateKey
|
|
31864
31925
|
),
|
|
31865
31926
|
userOutboundTransferExternalId: transfer.id,
|
|
@@ -31954,12 +32015,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31954
32015
|
let tokenMetadataMap = /* @__PURE__ */ new Map();
|
|
31955
32016
|
for (const [tokenIdentifier, metadata] of this.tokenMetadata) {
|
|
31956
32017
|
tokenMetadataMap.set(tokenIdentifier, {
|
|
31957
|
-
tokenPublicKey: (0,
|
|
32018
|
+
tokenPublicKey: (0, import_utils24.bytesToHex)(metadata.issuerPublicKey),
|
|
31958
32019
|
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
31959
32020
|
tokenName: metadata.tokenName,
|
|
31960
32021
|
tokenTicker: metadata.tokenTicker,
|
|
31961
32022
|
decimals: metadata.decimals,
|
|
31962
|
-
maxSupply: (0,
|
|
32023
|
+
maxSupply: (0, import_utils24.bytesToNumberBE)(metadata.maxSupply)
|
|
31963
32024
|
});
|
|
31964
32025
|
}
|
|
31965
32026
|
return tokenMetadataMap;
|
|
@@ -32083,7 +32144,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32083
32144
|
offset
|
|
32084
32145
|
});
|
|
32085
32146
|
return response.utxos.map((utxo) => ({
|
|
32086
|
-
txid: (0,
|
|
32147
|
+
txid: (0, import_utils24.bytesToHex)(utxo.txid),
|
|
32087
32148
|
vout: utxo.vout
|
|
32088
32149
|
})) ?? [];
|
|
32089
32150
|
} catch (error) {
|
|
@@ -32153,7 +32214,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32153
32214
|
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
32154
32215
|
network = BitcoinNetwork_default.REGTEST;
|
|
32155
32216
|
}
|
|
32156
|
-
const depositSecretKey = (0,
|
|
32217
|
+
const depositSecretKey = (0, import_utils24.bytesToHex)(
|
|
32157
32218
|
await this.config.signer.getStaticDepositSecretKey(0)
|
|
32158
32219
|
);
|
|
32159
32220
|
const message = await this.getStaticDepositSigningPayload(
|
|
@@ -32166,7 +32227,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32166
32227
|
);
|
|
32167
32228
|
const hashBuffer = (0, import_sha212.sha256)(message);
|
|
32168
32229
|
const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
|
|
32169
|
-
const signature = (0,
|
|
32230
|
+
const signature = (0, import_utils24.bytesToHex)(signatureBytes);
|
|
32170
32231
|
const response = await this.sspClient.claimStaticDeposit({
|
|
32171
32232
|
transactionId,
|
|
32172
32233
|
outputIndex,
|
|
@@ -32318,7 +32379,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32318
32379
|
networkJSON.toLowerCase(),
|
|
32319
32380
|
2 /* Refund */,
|
|
32320
32381
|
creditAmountSats,
|
|
32321
|
-
(0,
|
|
32382
|
+
(0, import_utils24.bytesToHex)(spendTxSighash)
|
|
32322
32383
|
);
|
|
32323
32384
|
const hashBuffer = (0, import_sha212.sha256)(message);
|
|
32324
32385
|
const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
|
|
@@ -32327,7 +32388,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32327
32388
|
);
|
|
32328
32389
|
const swapResponse = await sparkClient.initiate_static_deposit_utxo_refund({
|
|
32329
32390
|
onChainUtxo: {
|
|
32330
|
-
txid: (0,
|
|
32391
|
+
txid: (0, import_utils24.hexToBytes)(depositTransactionId),
|
|
32331
32392
|
vout: outputIndex,
|
|
32332
32393
|
network: networkType
|
|
32333
32394
|
},
|
|
@@ -32396,7 +32457,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32396
32457
|
creditAmountView.setUint32(0, lowerHalf, true);
|
|
32397
32458
|
creditAmountView.setUint32(4, upperHalf, true);
|
|
32398
32459
|
parts.push(new Uint8Array(creditAmountBuffer));
|
|
32399
|
-
parts.push((0,
|
|
32460
|
+
parts.push((0, import_utils24.hexToBytes)(sspSignature));
|
|
32400
32461
|
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
32401
32462
|
const payload = new Uint8Array(totalLength);
|
|
32402
32463
|
let offset = 0;
|
|
@@ -32774,11 +32835,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32774
32835
|
field: "receiverSparkAddress"
|
|
32775
32836
|
});
|
|
32776
32837
|
}
|
|
32777
|
-
const
|
|
32838
|
+
const receiverAddress = decodeSparkAddress(
|
|
32778
32839
|
receiverSparkAddress,
|
|
32779
32840
|
this.config.getNetworkType()
|
|
32780
32841
|
);
|
|
32781
|
-
if (
|
|
32842
|
+
if (receiverAddress.sparkInvoiceFields) {
|
|
32782
32843
|
throw new ValidationError(
|
|
32783
32844
|
"Spark address is a Spark invoice. Use fulfillSparkInvoice instead.",
|
|
32784
32845
|
{
|
|
@@ -32800,14 +32861,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32800
32861
|
value: amountSats
|
|
32801
32862
|
});
|
|
32802
32863
|
}
|
|
32803
|
-
const receiverAddress = decodeSparkAddress(
|
|
32804
|
-
receiverSparkAddress,
|
|
32805
|
-
this.config.getNetworkType()
|
|
32806
|
-
);
|
|
32807
32864
|
const signerIdentityPublicKey = await this.config.signer.getIdentityPublicKey();
|
|
32808
|
-
const isSelfTransfer = (0,
|
|
32865
|
+
const isSelfTransfer = (0, import_utils24.equalBytes)(
|
|
32809
32866
|
signerIdentityPublicKey,
|
|
32810
|
-
(0,
|
|
32867
|
+
(0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
|
|
32811
32868
|
);
|
|
32812
32869
|
return await this.withLeaves(async () => {
|
|
32813
32870
|
let leavesToSend = (await this.selectLeaves([amountSats])).get(
|
|
@@ -32829,7 +32886,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32829
32886
|
);
|
|
32830
32887
|
const transfer = await this.transferService.sendTransferWithKeyTweaks(
|
|
32831
32888
|
leafKeyTweaks,
|
|
32832
|
-
(0,
|
|
32889
|
+
(0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
|
|
32833
32890
|
);
|
|
32834
32891
|
const leavesToRemove = new Set(leavesToSend.map((leaf) => leaf.id));
|
|
32835
32892
|
this.leaves = this.leaves.filter((leaf) => !leavesToRemove.has(leaf.id));
|
|
@@ -32845,7 +32902,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32845
32902
|
}
|
|
32846
32903
|
return mapTransferToWalletTransfer(
|
|
32847
32904
|
transfer,
|
|
32848
|
-
(0,
|
|
32905
|
+
(0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey())
|
|
32849
32906
|
);
|
|
32850
32907
|
});
|
|
32851
32908
|
}
|
|
@@ -33201,7 +33258,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33201
33258
|
const invoice2 = await sspClient.requestLightningReceive({
|
|
33202
33259
|
amountSats: amountSats2,
|
|
33203
33260
|
network: bitcoinNetwork,
|
|
33204
|
-
paymentHash: (0,
|
|
33261
|
+
paymentHash: (0, import_utils24.bytesToHex)(paymentHash),
|
|
33205
33262
|
expirySecs: expirySeconds,
|
|
33206
33263
|
memo: memo2,
|
|
33207
33264
|
includeSparkAddress,
|
|
@@ -33310,7 +33367,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33310
33367
|
const sparkFallbackAddress = decodedInvoice.fallbackAddress;
|
|
33311
33368
|
const paymentHash = decodedInvoice.paymentHash;
|
|
33312
33369
|
if (preferSpark) {
|
|
33313
|
-
if (sparkFallbackAddress === void 0 || isValidSparkFallback((0,
|
|
33370
|
+
if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils24.hexToBytes)(sparkFallbackAddress)) === false) {
|
|
33314
33371
|
console.warn(
|
|
33315
33372
|
"No valid spark address found in invoice. Defaulting to lightning."
|
|
33316
33373
|
);
|
|
@@ -33364,10 +33421,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33364
33421
|
);
|
|
33365
33422
|
const swapResponse = await this.lightningService.swapNodesForPreimage({
|
|
33366
33423
|
leaves: leavesToSend,
|
|
33367
|
-
receiverIdentityPubkey: (0,
|
|
33424
|
+
receiverIdentityPubkey: (0, import_utils24.hexToBytes)(
|
|
33368
33425
|
this.config.getSspIdentityPublicKey()
|
|
33369
33426
|
),
|
|
33370
|
-
paymentHash: (0,
|
|
33427
|
+
paymentHash: (0, import_utils24.hexToBytes)(paymentHash),
|
|
33371
33428
|
isInboundPayment: false,
|
|
33372
33429
|
invoiceString: invoice,
|
|
33373
33430
|
feeSats: feeEstimate,
|
|
@@ -33485,7 +33542,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33485
33542
|
});
|
|
33486
33543
|
await this.syncTokenOutputs();
|
|
33487
33544
|
const bech32mTokenIdentifier = encodeBech32mTokenIdentifier({
|
|
33488
|
-
tokenIdentifier: (0,
|
|
33545
|
+
tokenIdentifier: (0, import_utils24.hexToBytes)(firstTokenIdentifierHexSeen),
|
|
33489
33546
|
network: this.config.getNetworkType()
|
|
33490
33547
|
});
|
|
33491
33548
|
const receiverOutputs = decoded.map((d) => ({
|
|
@@ -33516,7 +33573,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33516
33573
|
if (!feeEstimate) {
|
|
33517
33574
|
throw new Error("Failed to get lightning send fee estimate");
|
|
33518
33575
|
}
|
|
33519
|
-
const satsFeeEstimate = (0,
|
|
33576
|
+
const satsFeeEstimate = (0, import_core13.mapCurrencyAmount)(feeEstimate.feeEstimate);
|
|
33520
33577
|
return Math.ceil(satsFeeEstimate.sats);
|
|
33521
33578
|
}
|
|
33522
33579
|
// ***** Cooperative Exit Flow *****
|
|
@@ -33673,11 +33730,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33673
33730
|
const connectorOutputs = [];
|
|
33674
33731
|
for (let i = 0; i < connectorTx.outputsLength - 1; i++) {
|
|
33675
33732
|
connectorOutputs.push({
|
|
33676
|
-
txid: (0,
|
|
33733
|
+
txid: (0, import_utils24.hexToBytes)(connectorTxId),
|
|
33677
33734
|
index: i
|
|
33678
33735
|
});
|
|
33679
33736
|
}
|
|
33680
|
-
const sspPubIdentityKey = (0,
|
|
33737
|
+
const sspPubIdentityKey = (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey());
|
|
33681
33738
|
const transfer = await this.coopExitService.getConnectorRefundSignatures({
|
|
33682
33739
|
leaves: leafKeyTweaks,
|
|
33683
33740
|
exitTxId: coopExitTxId,
|
|
@@ -33731,7 +33788,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33731
33788
|
return transfers?.[0];
|
|
33732
33789
|
}
|
|
33733
33790
|
async constructTransfersWithUserRequest(transfers) {
|
|
33734
|
-
const identityPublicKey = (0,
|
|
33791
|
+
const identityPublicKey = (0, import_utils24.bytesToHex)(
|
|
33735
33792
|
await this.config.signer.getIdentityPublicKey()
|
|
33736
33793
|
);
|
|
33737
33794
|
const userRequests = await this.sspClient?.getTransfers(
|
|
@@ -33975,7 +34032,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33975
34032
|
hash,
|
|
33976
34033
|
compact
|
|
33977
34034
|
);
|
|
33978
|
-
return (0,
|
|
34035
|
+
return (0, import_utils24.bytesToHex)(signature);
|
|
33979
34036
|
}
|
|
33980
34037
|
/**
|
|
33981
34038
|
* Validates a message with the identity key.
|
|
@@ -33987,7 +34044,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33987
34044
|
async validateMessageWithIdentityKey(message, signature) {
|
|
33988
34045
|
const hash = (0, import_sha212.sha256)(message);
|
|
33989
34046
|
if (typeof signature === "string") {
|
|
33990
|
-
signature = (0,
|
|
34047
|
+
signature = (0, import_utils24.hexToBytes)(signature);
|
|
33991
34048
|
}
|
|
33992
34049
|
return this.config.signer.validateMessageWithIdentityKey(hash, signature);
|
|
33993
34050
|
}
|
|
@@ -34000,7 +34057,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34000
34057
|
*/
|
|
34001
34058
|
async signTransaction(txHex, keyType = "auto-detect") {
|
|
34002
34059
|
try {
|
|
34003
|
-
const tx = import_btc_signer6.Transaction.fromRaw((0,
|
|
34060
|
+
const tx = import_btc_signer6.Transaction.fromRaw((0, import_utils24.hexToBytes)(txHex));
|
|
34004
34061
|
let publicKey;
|
|
34005
34062
|
switch (keyType.toLowerCase()) {
|
|
34006
34063
|
case "identity":
|
|
@@ -34033,7 +34090,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34033
34090
|
publicKey,
|
|
34034
34091
|
this.config.getNetwork()
|
|
34035
34092
|
);
|
|
34036
|
-
if ((0,
|
|
34093
|
+
if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
|
|
34037
34094
|
try {
|
|
34038
34095
|
this.config.signer.signTransactionIndex(tx, i, publicKey);
|
|
34039
34096
|
inputsSigned++;
|
|
@@ -34077,13 +34134,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34077
34134
|
depositPubKey,
|
|
34078
34135
|
this.config.getNetwork()
|
|
34079
34136
|
);
|
|
34080
|
-
if ((0,
|
|
34137
|
+
if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
|
|
34081
34138
|
return {
|
|
34082
34139
|
publicKey: identityPubKey,
|
|
34083
34140
|
keyType: "identity"
|
|
34084
34141
|
};
|
|
34085
34142
|
}
|
|
34086
|
-
if ((0,
|
|
34143
|
+
if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(depositScript)) {
|
|
34087
34144
|
return {
|
|
34088
34145
|
publicKey: depositPubKey,
|
|
34089
34146
|
keyType: "deposit"
|
|
@@ -34377,7 +34434,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34377
34434
|
});
|
|
34378
34435
|
Object.assign(aggregatedNodes, response.nodes ?? {});
|
|
34379
34436
|
const received = Object.keys(response.nodes ?? {}).length;
|
|
34380
|
-
if (received < pageSize) {
|
|
34437
|
+
if (received < pageSize || baseRequest.source?.$case === "nodeIds") {
|
|
34381
34438
|
return {
|
|
34382
34439
|
nodes: aggregatedNodes,
|
|
34383
34440
|
offset: response.offset
|
|
@@ -34426,7 +34483,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34426
34483
|
} catch (error) {
|
|
34427
34484
|
if (error instanceof Error) {
|
|
34428
34485
|
error.message += ` [traceId: ${traceId}]`;
|
|
34429
|
-
} else if ((0,
|
|
34486
|
+
} else if ((0, import_core13.isObject)(error)) {
|
|
34430
34487
|
error["traceId"] = traceId;
|
|
34431
34488
|
}
|
|
34432
34489
|
throw error;
|
|
@@ -34499,7 +34556,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34499
34556
|
var import_sdk_trace_web = require("@opentelemetry/sdk-trace-web");
|
|
34500
34557
|
var import_instrumentation = require("@opentelemetry/instrumentation");
|
|
34501
34558
|
var import_instrumentation_fetch = require("@opentelemetry/instrumentation-fetch");
|
|
34502
|
-
var
|
|
34559
|
+
var import_core14 = require("@opentelemetry/core");
|
|
34503
34560
|
var import_api2 = require("@opentelemetry/api");
|
|
34504
34561
|
var SparkWalletBrowser = class _SparkWalletBrowser extends SparkWallet {
|
|
34505
34562
|
static async initialize({
|
|
@@ -34535,7 +34592,7 @@ function initializeTracerEnvBrowser({
|
|
|
34535
34592
|
}) {
|
|
34536
34593
|
const provider = new import_sdk_trace_web.WebTracerProvider({ spanProcessors });
|
|
34537
34594
|
provider.register();
|
|
34538
|
-
import_api2.propagation.setGlobalPropagator(new
|
|
34595
|
+
import_api2.propagation.setGlobalPropagator(new import_core14.W3CTraceContextPropagator());
|
|
34539
34596
|
(0, import_instrumentation.registerInstrumentations)({
|
|
34540
34597
|
instrumentations: [
|
|
34541
34598
|
new import_instrumentation_fetch.FetchInstrumentation({
|
|
@@ -34600,7 +34657,7 @@ async function isTxBroadcast(txid, baseUrl, network) {
|
|
|
34600
34657
|
}
|
|
34601
34658
|
|
|
34602
34659
|
// src/utils/unilateral-exit.ts
|
|
34603
|
-
var
|
|
34660
|
+
var import_utils25 = require("@noble/curves/abstract/utils");
|
|
34604
34661
|
var import_legacy = require("@noble/hashes/legacy");
|
|
34605
34662
|
var import_sha213 = require("@noble/hashes/sha2");
|
|
34606
34663
|
var btc4 = __toESM(require("@scure/btc-signer"), 1);
|
|
@@ -34615,7 +34672,7 @@ function isEphemeralAnchorOutput(script, amount) {
|
|
|
34615
34672
|
}
|
|
34616
34673
|
async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network) {
|
|
34617
34674
|
const result = [];
|
|
34618
|
-
const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0,
|
|
34675
|
+
const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils25.hexToBytes)(hex)));
|
|
34619
34676
|
const nodeMap = /* @__PURE__ */ new Map();
|
|
34620
34677
|
for (const node of nodes) {
|
|
34621
34678
|
nodeMap.set(node.id, node);
|
|
@@ -34671,10 +34728,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
|
|
|
34671
34728
|
}
|
|
34672
34729
|
}
|
|
34673
34730
|
for (const chainNode of chain) {
|
|
34674
|
-
const nodeTx = (0,
|
|
34731
|
+
const nodeTx = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
|
|
34675
34732
|
transactions.push(nodeTx);
|
|
34676
34733
|
if (chainNode.id === node.id) {
|
|
34677
|
-
const refundTx = (0,
|
|
34734
|
+
const refundTx = (0, import_utils25.bytesToHex)(chainNode.refundTx);
|
|
34678
34735
|
transactions.push(refundTx);
|
|
34679
34736
|
}
|
|
34680
34737
|
}
|
|
@@ -34704,7 +34761,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34704
34761
|
`Node hex string at index ${i} appears to be a raw transaction hex, not a TreeNode protobuf. Use 'leafidtohex' command to convert node IDs to proper hex strings.`
|
|
34705
34762
|
);
|
|
34706
34763
|
}
|
|
34707
|
-
const nodeBytes = (0,
|
|
34764
|
+
const nodeBytes = (0, import_utils25.hexToBytes)(hex);
|
|
34708
34765
|
const node = TreeNode.decode(nodeBytes);
|
|
34709
34766
|
if (!node.id) {
|
|
34710
34767
|
throw new Error(
|
|
@@ -34780,7 +34837,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34780
34837
|
}
|
|
34781
34838
|
}
|
|
34782
34839
|
for (const chainNode of chain) {
|
|
34783
|
-
let nodeTxHex = (0,
|
|
34840
|
+
let nodeTxHex = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
|
|
34784
34841
|
try {
|
|
34785
34842
|
const txObj = getTxFromRawTxHex(nodeTxHex);
|
|
34786
34843
|
const txid = getTxId(txObj);
|
|
@@ -34797,7 +34854,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34797
34854
|
for (let i = txObj.outputsLength - 1; i >= 0; i--) {
|
|
34798
34855
|
const output = txObj.getOutput(i);
|
|
34799
34856
|
if (output?.amount === 0n && output.script) {
|
|
34800
|
-
anchorOutputScriptHex = (0,
|
|
34857
|
+
anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
|
|
34801
34858
|
break;
|
|
34802
34859
|
}
|
|
34803
34860
|
}
|
|
@@ -34818,11 +34875,11 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34818
34875
|
usedUtxos,
|
|
34819
34876
|
correctedParentTx
|
|
34820
34877
|
} = constructFeeBumpTx(nodeTxHex, availableUtxos, feeRate, void 0);
|
|
34821
|
-
const feeBumpTx = btc4.Transaction.fromPSBT((0,
|
|
34878
|
+
const feeBumpTx = btc4.Transaction.fromPSBT((0, import_utils25.hexToBytes)(nodeFeeBumpPsbt));
|
|
34822
34879
|
var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
|
|
34823
34880
|
var feeBumpOutPubKey = null;
|
|
34824
34881
|
for (const usedUtxo of usedUtxos) {
|
|
34825
|
-
if (feeBumpOut && (0,
|
|
34882
|
+
if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
|
|
34826
34883
|
feeBumpOutPubKey = usedUtxo.publicKey;
|
|
34827
34884
|
}
|
|
34828
34885
|
const index = availableUtxos.findIndex(
|
|
@@ -34837,20 +34894,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34837
34894
|
txid: getTxId(feeBumpTx),
|
|
34838
34895
|
vout: 0,
|
|
34839
34896
|
value: feeBumpOut.amount,
|
|
34840
|
-
script: (0,
|
|
34897
|
+
script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
|
|
34841
34898
|
publicKey: feeBumpOutPubKey
|
|
34842
34899
|
});
|
|
34843
34900
|
const finalNodeTx = correctedParentTx || nodeTxHex;
|
|
34844
34901
|
txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
|
|
34845
34902
|
if (chainNode.id === node.id) {
|
|
34846
|
-
let refundTxHex = (0,
|
|
34903
|
+
let refundTxHex = (0, import_utils25.bytesToHex)(chainNode.refundTx);
|
|
34847
34904
|
try {
|
|
34848
34905
|
const txObj = getTxFromRawTxHex(refundTxHex);
|
|
34849
34906
|
let anchorOutputScriptHex;
|
|
34850
34907
|
for (let i = txObj.outputsLength - 1; i >= 0; i--) {
|
|
34851
34908
|
const output = txObj.getOutput(i);
|
|
34852
34909
|
if (output?.amount === 0n && output.script) {
|
|
34853
|
-
anchorOutputScriptHex = (0,
|
|
34910
|
+
anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
|
|
34854
34911
|
break;
|
|
34855
34912
|
}
|
|
34856
34913
|
}
|
|
@@ -34873,12 +34930,12 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34873
34930
|
void 0
|
|
34874
34931
|
);
|
|
34875
34932
|
const feeBumpTx2 = btc4.Transaction.fromPSBT(
|
|
34876
|
-
(0,
|
|
34933
|
+
(0, import_utils25.hexToBytes)(refundFeeBump.feeBumpPsbt)
|
|
34877
34934
|
);
|
|
34878
34935
|
var feeBumpOut = feeBumpTx2.outputsLength === 1 ? feeBumpTx2.getOutput(0) : null;
|
|
34879
34936
|
var feeBumpOutPubKey = null;
|
|
34880
34937
|
for (const usedUtxo of usedUtxos) {
|
|
34881
|
-
if (feeBumpOut && (0,
|
|
34938
|
+
if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
|
|
34882
34939
|
feeBumpOutPubKey = usedUtxo.publicKey;
|
|
34883
34940
|
}
|
|
34884
34941
|
const index = availableUtxos.findIndex(
|
|
@@ -34893,7 +34950,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34893
34950
|
txid: getTxId(feeBumpTx2),
|
|
34894
34951
|
vout: 0,
|
|
34895
34952
|
value: feeBumpOut.amount,
|
|
34896
|
-
script: (0,
|
|
34953
|
+
script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
|
|
34897
34954
|
publicKey: feeBumpOutPubKey
|
|
34898
34955
|
});
|
|
34899
34956
|
txPackages.push({
|
|
@@ -34988,10 +35045,10 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
|
|
|
34988
35045
|
if (!fundingUtxo) {
|
|
34989
35046
|
throw new Error(`UTXO at index ${i} is undefined`);
|
|
34990
35047
|
}
|
|
34991
|
-
const pubKeyHash = hash160((0,
|
|
35048
|
+
const pubKeyHash = hash160((0, import_utils25.hexToBytes)(fundingUtxo.publicKey));
|
|
34992
35049
|
const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
|
|
34993
|
-
const providedScript = (0,
|
|
34994
|
-
if ((0,
|
|
35050
|
+
const providedScript = (0, import_utils25.hexToBytes)(fundingUtxo.script);
|
|
35051
|
+
if ((0, import_utils25.bytesToHex)(scriptToUse) !== (0, import_utils25.bytesToHex)(providedScript)) {
|
|
34995
35052
|
throw new Error(
|
|
34996
35053
|
`\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
|
|
34997
35054
|
);
|
|
@@ -35056,7 +35113,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
|
|
|
35056
35113
|
}
|
|
35057
35114
|
let psbtHex;
|
|
35058
35115
|
try {
|
|
35059
|
-
psbtHex = (0,
|
|
35116
|
+
psbtHex = (0, import_utils25.bytesToHex)(builder.toPSBT());
|
|
35060
35117
|
} catch (error) {
|
|
35061
35118
|
throw new Error(`Failed to extract transaction: ${error}`);
|
|
35062
35119
|
}
|
|
@@ -35097,6 +35154,9 @@ function getSparkAddressFromTaproot(taprootAddress) {
|
|
|
35097
35154
|
throw new ValidationError("Invalid taproot address");
|
|
35098
35155
|
}
|
|
35099
35156
|
|
|
35157
|
+
// src/utils/index.ts
|
|
35158
|
+
init_logging();
|
|
35159
|
+
|
|
35100
35160
|
// src/bare/index.ts
|
|
35101
35161
|
globalThis.AbortController = import_cjs_ponyfill.AbortController;
|
|
35102
35162
|
var Headers2 = import_headers.default;
|
|
@@ -35120,6 +35180,7 @@ setFetch(sparkBareFetch, Headers2);
|
|
|
35120
35180
|
INITIAL_DIRECT_SEQUENCE,
|
|
35121
35181
|
INITIAL_SEQUENCE,
|
|
35122
35182
|
InternalValidationError,
|
|
35183
|
+
LOGGER_NAMES,
|
|
35123
35184
|
LRC_WALLET_NETWORK,
|
|
35124
35185
|
Network,
|
|
35125
35186
|
NetworkError,
|
|
@@ -35127,6 +35188,7 @@ setFetch(sparkBareFetch, Headers2);
|
|
|
35127
35188
|
NotImplementedError,
|
|
35128
35189
|
RPCError,
|
|
35129
35190
|
SparkSDKError,
|
|
35191
|
+
SparkSdkLogger,
|
|
35130
35192
|
SparkWallet,
|
|
35131
35193
|
TEST_UNILATERAL_DIRECT_SEQUENCE,
|
|
35132
35194
|
TEST_UNILATERAL_SEQUENCE,
|