@buildonspark/spark-sdk 0.2.10 → 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 +9 -1
- package/dist/bare/chunk-P6AVV7VD.js +34 -0
- package/dist/bare/index.cjs +337 -271
- package/dist/bare/index.d.cts +15 -2
- package/dist/bare/index.d.ts +15 -2
- package/dist/bare/index.js +51 -42
- 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-MWBK6QBF.js → chunk-3WBPICWC.js} +1 -1
- package/dist/chunk-NX5KPN5F.js +34 -0
- package/dist/{chunk-JXLWOQK5.js → chunk-QNYJGFPD.js} +49 -41
- package/dist/debug.cjs +333 -268
- package/dist/debug.d.cts +5 -2
- package/dist/debug.d.ts +5 -2
- package/dist/debug.js +2 -1
- package/dist/index.cjs +386 -319
- 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 +386 -319
- 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 +383 -316
- package/dist/native/index.d.cts +15 -2
- package/dist/native/index.d.ts +15 -2
- package/dist/native/index.js +143 -135
- 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_bindings/wasm/index.ts +21 -0
- 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/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/debug.cjs
CHANGED
|
@@ -1043,6 +1043,43 @@ var init_spark_bindings = __esm({
|
|
|
1043
1043
|
}
|
|
1044
1044
|
});
|
|
1045
1045
|
|
|
1046
|
+
// src/utils/logging.ts
|
|
1047
|
+
var import_core11, LOGGER_NAMES, SparkSdkLogger;
|
|
1048
|
+
var init_logging = __esm({
|
|
1049
|
+
"src/utils/logging.ts"() {
|
|
1050
|
+
"use strict";
|
|
1051
|
+
init_buffer();
|
|
1052
|
+
import_core11 = require("@lightsparkdev/core");
|
|
1053
|
+
LOGGER_NAMES = {
|
|
1054
|
+
wasm: "wasm"
|
|
1055
|
+
};
|
|
1056
|
+
SparkSdkLogger = class {
|
|
1057
|
+
static loggers = /* @__PURE__ */ new Map();
|
|
1058
|
+
static get(name) {
|
|
1059
|
+
if (!this.loggers.has(name)) {
|
|
1060
|
+
this.loggers.set(name, new import_core11.Logger(name));
|
|
1061
|
+
}
|
|
1062
|
+
return this.loggers.get(name);
|
|
1063
|
+
}
|
|
1064
|
+
static setLevel(name, level) {
|
|
1065
|
+
this.get(name).setLevel(level);
|
|
1066
|
+
}
|
|
1067
|
+
static setAllLevels(level) {
|
|
1068
|
+
this.loggers.forEach((logger) => logger.setLevel(level));
|
|
1069
|
+
}
|
|
1070
|
+
static setEnabled(name, enabled) {
|
|
1071
|
+
this.get(name).setEnabled(enabled);
|
|
1072
|
+
}
|
|
1073
|
+
static setAllEnabled(enabled) {
|
|
1074
|
+
this.loggers.forEach((logger) => logger.setEnabled(enabled));
|
|
1075
|
+
}
|
|
1076
|
+
static {
|
|
1077
|
+
Object.values(LOGGER_NAMES).forEach((name) => this.get(name));
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1046
1083
|
// src/spark_bindings/wasm/index.ts
|
|
1047
1084
|
var wasm_exports = {};
|
|
1048
1085
|
__export(wasm_exports, {
|
|
@@ -1073,6 +1110,13 @@ function signFrost({
|
|
|
1073
1110
|
statechainCommitments,
|
|
1074
1111
|
adaptorPubKey
|
|
1075
1112
|
}) {
|
|
1113
|
+
SparkSdkLogger.get(LOGGER_NAMES.wasm).trace("signFrost", {
|
|
1114
|
+
message: (0, import_utils4.bytesToHex)(message),
|
|
1115
|
+
keyPackage,
|
|
1116
|
+
nonce,
|
|
1117
|
+
selfCommitment,
|
|
1118
|
+
statechainCommitments
|
|
1119
|
+
});
|
|
1076
1120
|
return wasm_sign_frost(
|
|
1077
1121
|
message,
|
|
1078
1122
|
createKeyPackage(keyPackage),
|
|
@@ -1093,6 +1137,17 @@ function aggregateFrost({
|
|
|
1093
1137
|
verifyingKey,
|
|
1094
1138
|
adaptorPubKey
|
|
1095
1139
|
}) {
|
|
1140
|
+
SparkSdkLogger.get(LOGGER_NAMES.wasm).trace("aggregateFrost", {
|
|
1141
|
+
message: (0, import_utils4.bytesToHex)(message),
|
|
1142
|
+
statechainCommitments,
|
|
1143
|
+
selfCommitment,
|
|
1144
|
+
statechainSignatures,
|
|
1145
|
+
selfSignature: (0, import_utils4.bytesToHex)(selfSignature),
|
|
1146
|
+
statechainPublicKeys,
|
|
1147
|
+
selfPublicKey: (0, import_utils4.bytesToHex)(selfPublicKey),
|
|
1148
|
+
verifyingKey: (0, import_utils4.bytesToHex)(verifyingKey),
|
|
1149
|
+
adaptorPubKey: adaptorPubKey ? (0, import_utils4.bytesToHex)(adaptorPubKey) : void 0
|
|
1150
|
+
});
|
|
1096
1151
|
return wasm_aggregate_frost(
|
|
1097
1152
|
message,
|
|
1098
1153
|
statechainCommitments,
|
|
@@ -1123,11 +1178,14 @@ function decryptEcies({
|
|
|
1123
1178
|
}) {
|
|
1124
1179
|
return decrypt_ecies(encryptedMsg, privateKey);
|
|
1125
1180
|
}
|
|
1181
|
+
var import_utils4;
|
|
1126
1182
|
var init_wasm = __esm({
|
|
1127
1183
|
"src/spark_bindings/wasm/index.ts"() {
|
|
1128
1184
|
"use strict";
|
|
1129
1185
|
init_buffer();
|
|
1186
|
+
import_utils4 = require("@noble/curves/utils");
|
|
1130
1187
|
init_spark_bindings();
|
|
1188
|
+
init_logging();
|
|
1131
1189
|
}
|
|
1132
1190
|
});
|
|
1133
1191
|
|
|
@@ -1201,7 +1259,7 @@ function XHRTransport(config) {
|
|
|
1201
1259
|
bodyBuffer = chunk;
|
|
1202
1260
|
break;
|
|
1203
1261
|
}
|
|
1204
|
-
requestBody = bodyBuffer;
|
|
1262
|
+
requestBody = bodyBuffer.slice();
|
|
1205
1263
|
} else {
|
|
1206
1264
|
let iterator;
|
|
1207
1265
|
requestBody = new ReadableStream({
|
|
@@ -1215,7 +1273,7 @@ function XHRTransport(config) {
|
|
|
1215
1273
|
if (done) {
|
|
1216
1274
|
controller.close();
|
|
1217
1275
|
} else {
|
|
1218
|
-
controller.enqueue(value);
|
|
1276
|
+
controller.enqueue(value.slice());
|
|
1219
1277
|
}
|
|
1220
1278
|
},
|
|
1221
1279
|
async cancel() {
|
|
@@ -1315,8 +1373,8 @@ init_buffer();
|
|
|
1315
1373
|
|
|
1316
1374
|
// src/spark-wallet/spark-wallet.ts
|
|
1317
1375
|
init_buffer();
|
|
1318
|
-
var
|
|
1319
|
-
var
|
|
1376
|
+
var import_core13 = require("@lightsparkdev/core");
|
|
1377
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
|
1320
1378
|
var import_secp256k115 = require("@noble/curves/secp256k1");
|
|
1321
1379
|
var import_bip392 = require("@scure/bip39");
|
|
1322
1380
|
var import_english2 = require("@scure/bip39/wordlists/english");
|
|
@@ -17670,13 +17728,13 @@ init_buffer();
|
|
|
17670
17728
|
// src/signer/signer.ts
|
|
17671
17729
|
init_buffer();
|
|
17672
17730
|
var import_secp256k14 = require("@bitcoinerlab/secp256k1");
|
|
17673
|
-
var
|
|
17731
|
+
var import_utils5 = require("@noble/curves/abstract/utils");
|
|
17674
17732
|
var import_secp256k15 = require("@noble/curves/secp256k1");
|
|
17675
17733
|
var import_sha22 = require("@noble/hashes/sha2");
|
|
17676
17734
|
var import_bip32 = require("@scure/bip32");
|
|
17677
17735
|
var import_bip39 = require("@scure/bip39");
|
|
17678
17736
|
var import_english = require("@scure/bip39/wordlists/english");
|
|
17679
|
-
var
|
|
17737
|
+
var import_utils6 = require("@scure/btc-signer/utils");
|
|
17680
17738
|
var ecies = __toESM(require("eciesjs"), 1);
|
|
17681
17739
|
|
|
17682
17740
|
// src/constants.ts
|
|
@@ -17684,7 +17742,7 @@ init_buffer();
|
|
|
17684
17742
|
var import_core10 = require("@lightsparkdev/core");
|
|
17685
17743
|
var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
17686
17744
|
var isBun = globalThis.Bun !== void 0;
|
|
17687
|
-
var packageVersion = true ? "0.2.
|
|
17745
|
+
var packageVersion = true ? "0.2.11" : "unknown";
|
|
17688
17746
|
var baseEnvStr = "unknown";
|
|
17689
17747
|
if (isBun) {
|
|
17690
17748
|
const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
|
|
@@ -17714,9 +17772,9 @@ function addPublicKeys(a, b) {
|
|
|
17714
17772
|
expected: 33
|
|
17715
17773
|
});
|
|
17716
17774
|
}
|
|
17717
|
-
const pubkeyA = import_secp256k1.secp256k1.
|
|
17718
|
-
const pubkeyB = import_secp256k1.secp256k1.
|
|
17719
|
-
return pubkeyA.add(pubkeyB).
|
|
17775
|
+
const pubkeyA = import_secp256k1.secp256k1.Point.fromHex(a);
|
|
17776
|
+
const pubkeyB = import_secp256k1.secp256k1.Point.fromHex(b);
|
|
17777
|
+
return pubkeyA.add(pubkeyB).toBytes(true);
|
|
17720
17778
|
}
|
|
17721
17779
|
function applyAdditiveTweakToPublicKey(pubkey, tweak) {
|
|
17722
17780
|
if (pubkey.length !== 33) {
|
|
@@ -17733,11 +17791,11 @@ function applyAdditiveTweakToPublicKey(pubkey, tweak) {
|
|
|
17733
17791
|
expected: 32
|
|
17734
17792
|
});
|
|
17735
17793
|
}
|
|
17736
|
-
const pubkeyPoint = import_secp256k1.secp256k1.
|
|
17794
|
+
const pubkeyPoint = import_secp256k1.secp256k1.Point.fromHex(pubkey);
|
|
17737
17795
|
const privTweek = import_secp256k1.secp256k1.utils.normPrivateKeyToScalar(tweak);
|
|
17738
17796
|
const pubTweek = import_secp256k1.secp256k1.getPublicKey(privTweek, true);
|
|
17739
|
-
const tweekPoint = import_secp256k1.secp256k1.
|
|
17740
|
-
return pubkeyPoint.add(tweekPoint).
|
|
17797
|
+
const tweekPoint = import_secp256k1.secp256k1.Point.fromHex(pubTweek);
|
|
17798
|
+
return pubkeyPoint.add(tweekPoint).toBytes(true);
|
|
17741
17799
|
}
|
|
17742
17800
|
function subtractPublicKeys(a, b) {
|
|
17743
17801
|
if (a.length !== 33 || b.length !== 33) {
|
|
@@ -17747,9 +17805,9 @@ function subtractPublicKeys(a, b) {
|
|
|
17747
17805
|
expected: 33
|
|
17748
17806
|
});
|
|
17749
17807
|
}
|
|
17750
|
-
const pubkeyA = import_secp256k1.secp256k1.
|
|
17751
|
-
const pubkeyB = import_secp256k1.secp256k1.
|
|
17752
|
-
return pubkeyA.subtract(pubkeyB).
|
|
17808
|
+
const pubkeyA = import_secp256k1.secp256k1.Point.fromHex(a);
|
|
17809
|
+
const pubkeyB = import_secp256k1.secp256k1.Point.fromHex(b);
|
|
17810
|
+
return pubkeyA.subtract(pubkeyB).toBytes(true);
|
|
17753
17811
|
}
|
|
17754
17812
|
function addPrivateKeys(a, b) {
|
|
17755
17813
|
if (a.length !== 32 || b.length !== 32) {
|
|
@@ -17904,11 +17962,11 @@ function generatePolynomialForSecretSharing(fieldModulus, secret, degree) {
|
|
|
17904
17962
|
const coefficients = new Array(degree);
|
|
17905
17963
|
const proofs = new Array(degree);
|
|
17906
17964
|
coefficients[0] = secret;
|
|
17907
|
-
proofs[0] = import_secp256k12.secp256k1.
|
|
17965
|
+
proofs[0] = import_secp256k12.secp256k1.Point.fromPrivateKey(secret).toBytes(true);
|
|
17908
17966
|
for (let i = 1; i < degree; i++) {
|
|
17909
17967
|
const coefficient = getRandomBigInt(fieldModulus);
|
|
17910
17968
|
coefficients[i] = coefficient;
|
|
17911
|
-
proofs[i] = import_secp256k12.secp256k1.
|
|
17969
|
+
proofs[i] = import_secp256k12.secp256k1.Point.fromPrivateKey(coefficient).toBytes(true);
|
|
17912
17970
|
}
|
|
17913
17971
|
return {
|
|
17914
17972
|
fieldModulus,
|
|
@@ -17980,9 +18038,9 @@ function recoverSecret(shares) {
|
|
|
17980
18038
|
return result;
|
|
17981
18039
|
}
|
|
17982
18040
|
function validateShare(share) {
|
|
17983
|
-
const targetPubkey = import_secp256k12.secp256k1.
|
|
17984
|
-
|
|
17985
|
-
)
|
|
18041
|
+
const targetPubkey = import_secp256k12.secp256k1.Point.fromPrivateKey(share.share).toBytes(
|
|
18042
|
+
true
|
|
18043
|
+
);
|
|
17986
18044
|
let resultPubkey = share.proofs[0];
|
|
17987
18045
|
if (!resultPubkey) {
|
|
17988
18046
|
throw new ValidationError("Result pubkey is not valid", {
|
|
@@ -18001,8 +18059,8 @@ function validateShare(share) {
|
|
|
18001
18059
|
});
|
|
18002
18060
|
}
|
|
18003
18061
|
const value = share.index ** BigInt(i) % share.fieldModulus;
|
|
18004
|
-
const scaledPoint = import_secp256k12.secp256k1.
|
|
18005
|
-
resultPubkey = import_secp256k12.secp256k1.
|
|
18062
|
+
const scaledPoint = import_secp256k12.secp256k1.Point.fromHex(pubkey).multiply(value);
|
|
18063
|
+
resultPubkey = import_secp256k12.secp256k1.Point.fromHex(resultPubkey).add(scaledPoint).toBytes(true);
|
|
18006
18064
|
}
|
|
18007
18065
|
if (!(0, import_utils3.equalBytes)(resultPubkey, targetPubkey)) {
|
|
18008
18066
|
throw new ValidationError("Share is not valid", {
|
|
@@ -18196,7 +18254,7 @@ var DefaultSparkSigner = class {
|
|
|
18196
18254
|
});
|
|
18197
18255
|
}
|
|
18198
18256
|
const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
|
|
18199
|
-
(0,
|
|
18257
|
+
(0, import_utils5.bytesToHex)(this.identityKey.privateKey)
|
|
18200
18258
|
);
|
|
18201
18259
|
const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
|
|
18202
18260
|
return privateKey;
|
|
@@ -18330,7 +18388,7 @@ var DefaultSparkSigner = class {
|
|
|
18330
18388
|
threshold,
|
|
18331
18389
|
numShares
|
|
18332
18390
|
}) {
|
|
18333
|
-
const secretAsInt = (0,
|
|
18391
|
+
const secretAsInt = (0, import_utils5.bytesToNumberBE)(secret);
|
|
18334
18392
|
return splitSecretWithProofs(secretAsInt, curveOrder, threshold, numShares);
|
|
18335
18393
|
}
|
|
18336
18394
|
async signFrost({
|
|
@@ -18366,7 +18424,7 @@ var DefaultSparkSigner = class {
|
|
|
18366
18424
|
publicKey,
|
|
18367
18425
|
verifyingKey
|
|
18368
18426
|
};
|
|
18369
|
-
const logMessage = (0,
|
|
18427
|
+
const logMessage = (0, import_utils5.bytesToHex)(message);
|
|
18370
18428
|
const result = await SparkFrost.signFrost({
|
|
18371
18429
|
message,
|
|
18372
18430
|
keyPackage,
|
|
@@ -18408,7 +18466,7 @@ var DefaultSparkSigner = class {
|
|
|
18408
18466
|
}
|
|
18409
18467
|
async createSparkWalletFromSeed(seed, accountNumber) {
|
|
18410
18468
|
if (typeof seed === "string") {
|
|
18411
|
-
seed = (0,
|
|
18469
|
+
seed = (0, import_utils5.hexToBytes)(seed);
|
|
18412
18470
|
}
|
|
18413
18471
|
const {
|
|
18414
18472
|
identityKey,
|
|
@@ -18420,7 +18478,7 @@ var DefaultSparkSigner = class {
|
|
|
18420
18478
|
this.depositKey = depositKey;
|
|
18421
18479
|
this.signingKey = signingKey.hdKey;
|
|
18422
18480
|
this.staticDepositKey = staticDepositKey.hdKey;
|
|
18423
|
-
return (0,
|
|
18481
|
+
return (0, import_utils5.bytesToHex)(identityKey.publicKey);
|
|
18424
18482
|
}
|
|
18425
18483
|
async signMessageWithIdentityKey(message, compact) {
|
|
18426
18484
|
if (!this.identityKey?.privateKey) {
|
|
@@ -18441,7 +18499,7 @@ var DefaultSparkSigner = class {
|
|
|
18441
18499
|
});
|
|
18442
18500
|
}
|
|
18443
18501
|
const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
|
|
18444
|
-
(0,
|
|
18502
|
+
(0, import_utils5.bytesToHex)(this.identityKey.privateKey)
|
|
18445
18503
|
);
|
|
18446
18504
|
const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
|
|
18447
18505
|
const publicKey = import_secp256k15.secp256k1.getPublicKey(privateKey);
|
|
@@ -18465,15 +18523,15 @@ var DefaultSparkSigner = class {
|
|
|
18465
18523
|
}
|
|
18466
18524
|
signTransactionIndex(tx, index, publicKey) {
|
|
18467
18525
|
let privateKey;
|
|
18468
|
-
if ((0,
|
|
18526
|
+
if ((0, import_utils5.equalBytes)(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
|
|
18469
18527
|
privateKey = this.identityKey?.privateKey;
|
|
18470
|
-
} else if ((0,
|
|
18528
|
+
} else if ((0, import_utils5.equalBytes)(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
|
|
18471
18529
|
privateKey = this.depositKey?.privateKey;
|
|
18472
18530
|
}
|
|
18473
18531
|
if (!privateKey) {
|
|
18474
18532
|
throw new ValidationError("Private key not found for public key", {
|
|
18475
18533
|
field: "privateKey",
|
|
18476
|
-
value: (0,
|
|
18534
|
+
value: (0, import_utils5.bytesToHex)(publicKey)
|
|
18477
18535
|
});
|
|
18478
18536
|
}
|
|
18479
18537
|
tx.signIdx(privateKey, index);
|
|
@@ -18885,7 +18943,7 @@ var WalletConfigService = class {
|
|
|
18885
18943
|
|
|
18886
18944
|
// src/services/connection.ts
|
|
18887
18945
|
init_buffer();
|
|
18888
|
-
var
|
|
18946
|
+
var import_core12 = require("@lightsparkdev/core");
|
|
18889
18947
|
var import_sha23 = require("@noble/hashes/sha2");
|
|
18890
18948
|
var import_nice_grpc_client_middleware_retry = require("nice-grpc-client-middleware-retry");
|
|
18891
18949
|
var import_nice_grpc_common2 = require("nice-grpc-common");
|
|
@@ -22643,7 +22701,7 @@ var ConnectionManager = class {
|
|
|
22643
22701
|
async createMockClient(address2) {
|
|
22644
22702
|
const channel = await this.createChannelWithTLS(address2);
|
|
22645
22703
|
const isNodeChannel = "close" in channel;
|
|
22646
|
-
if (
|
|
22704
|
+
if (import_core12.isNode && isNodeChannel && !isBun) {
|
|
22647
22705
|
const grpcModule = await import("nice-grpc");
|
|
22648
22706
|
const { createClient } = "default" in grpcModule ? grpcModule.default : grpcModule;
|
|
22649
22707
|
const client = createClient(MockServiceDefinition, channel);
|
|
@@ -22660,7 +22718,7 @@ var ConnectionManager = class {
|
|
|
22660
22718
|
}
|
|
22661
22719
|
async createChannelWithTLS(address2, certPath) {
|
|
22662
22720
|
try {
|
|
22663
|
-
if (
|
|
22721
|
+
if (import_core12.isNode && !isBun) {
|
|
22664
22722
|
const grpcModule = await import("nice-grpc");
|
|
22665
22723
|
const { ChannelCredentials, createChannel } = "default" in grpcModule ? grpcModule.default : grpcModule;
|
|
22666
22724
|
if (certPath) {
|
|
@@ -22691,7 +22749,7 @@ var ConnectionManager = class {
|
|
|
22691
22749
|
const { XHRTransport: XHRTransport2 } = await Promise.resolve().then(() => (init_xhr_transport(), xhr_transport_exports));
|
|
22692
22750
|
return createChannel(
|
|
22693
22751
|
address2,
|
|
22694
|
-
|
|
22752
|
+
import_core12.isBare ? (0, import_nice_grpc_web.NodeHttpTransport)() : isReactNative ? XHRTransport2() : FetchTransport()
|
|
22695
22753
|
);
|
|
22696
22754
|
}
|
|
22697
22755
|
} catch (error) {
|
|
@@ -22797,7 +22855,7 @@ var ConnectionManager = class {
|
|
|
22797
22855
|
sparkAuthnClient.close?.();
|
|
22798
22856
|
return verifyResp.sessionToken;
|
|
22799
22857
|
} catch (error) {
|
|
22800
|
-
if ((0,
|
|
22858
|
+
if ((0, import_core12.isError)(error)) {
|
|
22801
22859
|
sparkAuthnClient?.close?.();
|
|
22802
22860
|
if (error.message.includes("challenge expired")) {
|
|
22803
22861
|
console.warn(
|
|
@@ -22848,7 +22906,7 @@ var ConnectionManager = class {
|
|
|
22848
22906
|
);
|
|
22849
22907
|
}
|
|
22850
22908
|
createAuthnMiddleware() {
|
|
22851
|
-
if (
|
|
22909
|
+
if (import_core12.isNode) {
|
|
22852
22910
|
return async function* (call, options) {
|
|
22853
22911
|
const metadata = (0, import_nice_grpc_common2.Metadata)(options.metadata).set(
|
|
22854
22912
|
"X-Client-Env",
|
|
@@ -22870,14 +22928,14 @@ var ConnectionManager = class {
|
|
|
22870
22928
|
}
|
|
22871
22929
|
}
|
|
22872
22930
|
createMiddleware(address2, authToken) {
|
|
22873
|
-
if (
|
|
22931
|
+
if (import_core12.isNode) {
|
|
22874
22932
|
return this.createNodeMiddleware(address2, authToken);
|
|
22875
22933
|
} else {
|
|
22876
22934
|
return this.createBrowserMiddleware(address2, authToken);
|
|
22877
22935
|
}
|
|
22878
22936
|
}
|
|
22879
22937
|
async *handleMiddlewareError(error, address2, call, metadata, options) {
|
|
22880
|
-
if ((0,
|
|
22938
|
+
if ((0, import_core12.isError)(error)) {
|
|
22881
22939
|
if (error.message.includes("token has expired")) {
|
|
22882
22940
|
const newAuthToken = await this.authenticate(address2);
|
|
22883
22941
|
const clientData = this.clients.get(address2);
|
|
@@ -22948,7 +23006,7 @@ var ConnectionManager = class {
|
|
|
22948
23006
|
};
|
|
22949
23007
|
let options = {};
|
|
22950
23008
|
const isNodeChannel = "close" in channel;
|
|
22951
|
-
if (
|
|
23009
|
+
if (import_core12.isNode && isNodeChannel && !isBun) {
|
|
22952
23010
|
const grpcModule = await import("nice-grpc");
|
|
22953
23011
|
const { openTelemetryClientMiddleware } = await import("nice-grpc-opentelemetry");
|
|
22954
23012
|
const { createClientFactory } = "default" in grpcModule ? grpcModule.default : grpcModule;
|
|
@@ -22998,7 +23056,7 @@ var import_uuidv72 = require("uuidv7");
|
|
|
22998
23056
|
|
|
22999
23057
|
// src/utils/bitcoin.ts
|
|
23000
23058
|
init_buffer();
|
|
23001
|
-
var
|
|
23059
|
+
var import_utils7 = require("@noble/curves/abstract/utils");
|
|
23002
23060
|
var import_secp256k16 = require("@noble/curves/secp256k1");
|
|
23003
23061
|
var import_sha24 = require("@noble/hashes/sha2");
|
|
23004
23062
|
var btc2 = __toESM(require("@scure/btc-signer"), 1);
|
|
@@ -23011,10 +23069,10 @@ function computeTaprootKeyNoScript(pubkey) {
|
|
|
23011
23069
|
});
|
|
23012
23070
|
}
|
|
23013
23071
|
const taggedHash = import_secp256k16.schnorr.utils.taggedHash("TapTweak", pubkey);
|
|
23014
|
-
const tweak = (0,
|
|
23072
|
+
const tweak = (0, import_utils7.bytesToNumberBE)(taggedHash);
|
|
23015
23073
|
const P = import_secp256k16.schnorr.utils.lift_x(import_secp256k16.schnorr.utils.bytesToNumberBE(pubkey));
|
|
23016
|
-
const Q = P.add(import_secp256k16.secp256k1.
|
|
23017
|
-
return Q.
|
|
23074
|
+
const Q = P.add(import_secp256k16.secp256k1.Point.fromPrivateKey(tweak));
|
|
23075
|
+
return Q.toBytes();
|
|
23018
23076
|
}
|
|
23019
23077
|
function getP2TRScriptFromPublicKey(pubKey, network) {
|
|
23020
23078
|
if (pubKey.length !== 33) {
|
|
@@ -23024,9 +23082,9 @@ function getP2TRScriptFromPublicKey(pubKey, network) {
|
|
|
23024
23082
|
expected: 33
|
|
23025
23083
|
});
|
|
23026
23084
|
}
|
|
23027
|
-
const internalKey = import_secp256k16.secp256k1.
|
|
23085
|
+
const internalKey = import_secp256k16.secp256k1.Point.fromHex(pubKey);
|
|
23028
23086
|
const script = btc2.p2tr(
|
|
23029
|
-
internalKey.
|
|
23087
|
+
internalKey.toBytes().slice(1, 33),
|
|
23030
23088
|
void 0,
|
|
23031
23089
|
getNetwork(network)
|
|
23032
23090
|
).script;
|
|
@@ -23046,9 +23104,9 @@ function getP2TRAddressFromPublicKey(pubKey, network) {
|
|
|
23046
23104
|
expected: 33
|
|
23047
23105
|
});
|
|
23048
23106
|
}
|
|
23049
|
-
const internalKey = import_secp256k16.secp256k1.
|
|
23107
|
+
const internalKey = import_secp256k16.secp256k1.Point.fromHex(pubKey);
|
|
23050
23108
|
const address2 = btc2.p2tr(
|
|
23051
|
-
internalKey.
|
|
23109
|
+
internalKey.toBytes().slice(1, 33),
|
|
23052
23110
|
void 0,
|
|
23053
23111
|
getNetwork(network)
|
|
23054
23112
|
).address;
|
|
@@ -23064,7 +23122,7 @@ function getP2TRAddressFromPkScript(pkScript, network) {
|
|
|
23064
23122
|
if (pkScript.length !== 34 || pkScript[0] !== 81 || pkScript[1] !== 32) {
|
|
23065
23123
|
throw new ValidationError("Invalid pkscript", {
|
|
23066
23124
|
field: "pkScript",
|
|
23067
|
-
value: (0,
|
|
23125
|
+
value: (0, import_utils7.bytesToHex)(pkScript),
|
|
23068
23126
|
expected: "34 bytes starting with 0x51 0x20"
|
|
23069
23127
|
});
|
|
23070
23128
|
}
|
|
@@ -23089,7 +23147,7 @@ function getP2WPKHAddressFromPublicKey(pubKey, network) {
|
|
|
23089
23147
|
return address2;
|
|
23090
23148
|
}
|
|
23091
23149
|
function getTxFromRawTxHex(rawTxHex) {
|
|
23092
|
-
const txBytes = (0,
|
|
23150
|
+
const txBytes = (0, import_utils7.hexToBytes)(rawTxHex);
|
|
23093
23151
|
const tx = btc2.Transaction.fromRaw(txBytes, {
|
|
23094
23152
|
allowUnknownOutputs: true
|
|
23095
23153
|
});
|
|
@@ -23136,10 +23194,10 @@ function getSigHashFromTx(tx, inputIndex, prevOutput) {
|
|
|
23136
23194
|
);
|
|
23137
23195
|
}
|
|
23138
23196
|
function getTxId(tx) {
|
|
23139
|
-
return (0,
|
|
23197
|
+
return (0, import_utils7.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))).reverse());
|
|
23140
23198
|
}
|
|
23141
23199
|
function getTxIdNoReverse(tx) {
|
|
23142
|
-
return (0,
|
|
23200
|
+
return (0, import_utils7.bytesToHex)((0, import_sha24.sha256)((0, import_sha24.sha256)(tx.toBytes(true))));
|
|
23143
23201
|
}
|
|
23144
23202
|
function getTxEstimatedVbytesSizeByNumberOfInputsOutputs(numInputs, numOutputs) {
|
|
23145
23203
|
const TX_OVERHEAD = 10;
|
|
@@ -23487,7 +23545,7 @@ function getEphemeralAnchorOutput() {
|
|
|
23487
23545
|
|
|
23488
23546
|
// src/services/transfer.ts
|
|
23489
23547
|
init_buffer();
|
|
23490
|
-
var
|
|
23548
|
+
var import_utils9 = require("@noble/curves/abstract/utils");
|
|
23491
23549
|
var import_secp256k17 = require("@noble/curves/secp256k1");
|
|
23492
23550
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
23493
23551
|
var import_btc_signer2 = require("@scure/btc-signer");
|
|
@@ -23496,7 +23554,7 @@ var import_uuidv7 = require("uuidv7");
|
|
|
23496
23554
|
|
|
23497
23555
|
// src/utils/transfer_package.ts
|
|
23498
23556
|
init_buffer();
|
|
23499
|
-
var
|
|
23557
|
+
var import_utils8 = require("@noble/curves/abstract/utils");
|
|
23500
23558
|
var import_sha25 = require("@noble/hashes/sha2");
|
|
23501
23559
|
function getTransferPackageSigningPayload(transferID, transferPackage) {
|
|
23502
23560
|
const encryptedPayload = transferPackage.keyTweakPackage;
|
|
@@ -23505,7 +23563,7 @@ function getTransferPackageSigningPayload(transferID, transferPackage) {
|
|
|
23505
23563
|
).map(([key, value]) => ({ key, value }));
|
|
23506
23564
|
pairs.sort((a, b) => a.key.localeCompare(b.key));
|
|
23507
23565
|
const encoder = new TextEncoder();
|
|
23508
|
-
let message = (0,
|
|
23566
|
+
let message = (0, import_utils8.hexToBytes)(transferID.replaceAll("-", ""));
|
|
23509
23567
|
for (const pair of pairs) {
|
|
23510
23568
|
const keyPart = encoder.encode(pair.key + ":");
|
|
23511
23569
|
const separator = encoder.encode(";");
|
|
@@ -23885,7 +23943,7 @@ var BaseTransferService = class {
|
|
|
23885
23943
|
}
|
|
23886
23944
|
async prepareSendTransferKeyTweaks(transferID, receiverIdentityPubkey, leaves, cpfpRefundSignatureMap, directRefundSignatureMap, directFromCpfpRefundSignatureMap) {
|
|
23887
23945
|
const receiverEciesPubKey = ecies2.PublicKey.fromHex(
|
|
23888
|
-
(0,
|
|
23946
|
+
(0, import_utils9.bytesToHex)(receiverIdentityPubkey)
|
|
23889
23947
|
);
|
|
23890
23948
|
const leavesTweaksMap = /* @__PURE__ */ new Map();
|
|
23891
23949
|
for (const leaf of leaves) {
|
|
@@ -23926,7 +23984,7 @@ var BaseTransferService = class {
|
|
|
23926
23984
|
throw new Error(`Share not found for operator ${operator.id}`);
|
|
23927
23985
|
}
|
|
23928
23986
|
const pubkeyTweak = import_secp256k17.secp256k1.getPublicKey(
|
|
23929
|
-
(0,
|
|
23987
|
+
(0, import_utils9.numberToBytesBE)(share.share, 32),
|
|
23930
23988
|
true
|
|
23931
23989
|
);
|
|
23932
23990
|
pubkeySharesTweak.set(identifier, pubkeyTweak);
|
|
@@ -23951,7 +24009,7 @@ var BaseTransferService = class {
|
|
|
23951
24009
|
leafTweaksMap.set(identifier, {
|
|
23952
24010
|
leafId: leaf.leaf.id,
|
|
23953
24011
|
secretShareTweak: {
|
|
23954
|
-
secretShare: (0,
|
|
24012
|
+
secretShare: (0, import_utils9.numberToBytesBE)(share.share, 32),
|
|
23955
24013
|
proofs: share.proofs
|
|
23956
24014
|
},
|
|
23957
24015
|
pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak),
|
|
@@ -23974,7 +24032,7 @@ var BaseTransferService = class {
|
|
|
23974
24032
|
return void 0;
|
|
23975
24033
|
}
|
|
23976
24034
|
compareTransfers(transfer1, transfer2) {
|
|
23977
|
-
return transfer1.id === transfer2.id && (0,
|
|
24035
|
+
return transfer1.id === transfer2.id && (0, import_utils9.equalBytes)(
|
|
23978
24036
|
transfer1.senderIdentityPublicKey,
|
|
23979
24037
|
transfer2.senderIdentityPublicKey
|
|
23980
24038
|
) && transfer1.status === transfer2.status && transfer1.totalValue === transfer2.totalValue && transfer1.expiryTime?.getTime() === transfer2.expiryTime?.getTime() && transfer1.leaves.length === transfer2.leaves.length;
|
|
@@ -24273,7 +24331,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24273
24331
|
}
|
|
24274
24332
|
const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
|
|
24275
24333
|
const cpfpNodeOutPoint = {
|
|
24276
|
-
txid: (0,
|
|
24334
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
|
|
24277
24335
|
index: 0
|
|
24278
24336
|
};
|
|
24279
24337
|
let directNodeTx;
|
|
@@ -24281,7 +24339,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24281
24339
|
if (leaf.leaf.directTx.length > 0) {
|
|
24282
24340
|
directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
|
|
24283
24341
|
directNodeOutPoint = {
|
|
24284
|
-
txid: (0,
|
|
24342
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(directNodeTx)),
|
|
24285
24343
|
index: 0
|
|
24286
24344
|
};
|
|
24287
24345
|
}
|
|
@@ -24415,7 +24473,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24415
24473
|
throw new Error(`Share not found for operator ${operator.id}`);
|
|
24416
24474
|
}
|
|
24417
24475
|
const pubkeyTweak = import_secp256k17.secp256k1.getPublicKey(
|
|
24418
|
-
(0,
|
|
24476
|
+
(0, import_utils9.numberToBytesBE)(share.share, 32)
|
|
24419
24477
|
);
|
|
24420
24478
|
pubkeySharesTweak.set(identifier, pubkeyTweak);
|
|
24421
24479
|
}
|
|
@@ -24428,7 +24486,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24428
24486
|
leafTweaksMap.set(identifier, {
|
|
24429
24487
|
leafId: leaf.leaf.id,
|
|
24430
24488
|
secretShareTweak: {
|
|
24431
|
-
secretShare: (0,
|
|
24489
|
+
secretShare: (0, import_utils9.numberToBytesBE)(share.share, 32),
|
|
24432
24490
|
proofs: share.proofs
|
|
24433
24491
|
},
|
|
24434
24492
|
pubkeySharesTweak: Object.fromEntries(pubkeySharesTweak)
|
|
@@ -24614,13 +24672,13 @@ var TransferService = class extends BaseTransferService {
|
|
|
24614
24672
|
});
|
|
24615
24673
|
}
|
|
24616
24674
|
const newCpfpRefundOutPoint = {
|
|
24617
|
-
txid: (0,
|
|
24675
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(cpfpNodeTx)),
|
|
24618
24676
|
index: 0
|
|
24619
24677
|
};
|
|
24620
24678
|
let newDirectRefundOutPoint;
|
|
24621
24679
|
if (newDirectNodeTx) {
|
|
24622
24680
|
newDirectRefundOutPoint = {
|
|
24623
|
-
txid: (0,
|
|
24681
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(newDirectNodeTx)),
|
|
24624
24682
|
index: 0
|
|
24625
24683
|
};
|
|
24626
24684
|
}
|
|
@@ -24748,7 +24806,7 @@ var TransferService = class extends BaseTransferService {
|
|
|
24748
24806
|
const refundTx = getTxFromRawTxBytes(node.refundTx);
|
|
24749
24807
|
const refundSequence = refundTx.getInput(0).sequence || 0;
|
|
24750
24808
|
const newNodeOutPoint = {
|
|
24751
|
-
txid: (0,
|
|
24809
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
|
|
24752
24810
|
index: 0
|
|
24753
24811
|
};
|
|
24754
24812
|
const {
|
|
@@ -24785,13 +24843,13 @@ var TransferService = class extends BaseTransferService {
|
|
|
24785
24843
|
});
|
|
24786
24844
|
}
|
|
24787
24845
|
const newCpfpRefundOutPoint = {
|
|
24788
|
-
txid: (0,
|
|
24846
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(newNodeTx)),
|
|
24789
24847
|
index: 0
|
|
24790
24848
|
};
|
|
24791
24849
|
let newDirectRefundOutPoint;
|
|
24792
24850
|
if (newDirectNodeTx) {
|
|
24793
24851
|
newDirectRefundOutPoint = {
|
|
24794
|
-
txid: (0,
|
|
24852
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(newDirectNodeTx)),
|
|
24795
24853
|
index: 0
|
|
24796
24854
|
};
|
|
24797
24855
|
}
|
|
@@ -25025,13 +25083,13 @@ var TransferService = class extends BaseTransferService {
|
|
|
25025
25083
|
};
|
|
25026
25084
|
const signingPublicKey = await this.config.signer.getPublicKeyFromDerivation(keyDerivation);
|
|
25027
25085
|
const cpfpRefundOutPoint = {
|
|
25028
|
-
txid: (0,
|
|
25086
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(nodeTx)),
|
|
25029
25087
|
index: 0
|
|
25030
25088
|
};
|
|
25031
25089
|
let directRefundOutPoint;
|
|
25032
25090
|
if (directNodeTx) {
|
|
25033
25091
|
directRefundOutPoint = {
|
|
25034
|
-
txid: (0,
|
|
25092
|
+
txid: (0, import_utils9.hexToBytes)(getTxId(directNodeTx)),
|
|
25035
25093
|
index: 0
|
|
25036
25094
|
};
|
|
25037
25095
|
}
|
|
@@ -25407,9 +25465,9 @@ var CoopExitService = class extends BaseTransferService {
|
|
|
25407
25465
|
init_buffer();
|
|
25408
25466
|
var import_secp256k18 = require("@noble/curves/secp256k1");
|
|
25409
25467
|
var import_sha28 = require("@noble/hashes/sha2");
|
|
25410
|
-
var
|
|
25468
|
+
var import_utils10 = require("@noble/hashes/utils");
|
|
25411
25469
|
var import_btc_signer4 = require("@scure/btc-signer");
|
|
25412
|
-
var
|
|
25470
|
+
var import_utils11 = require("@scure/btc-signer/utils");
|
|
25413
25471
|
|
|
25414
25472
|
// src/utils/proof.ts
|
|
25415
25473
|
init_buffer();
|
|
@@ -25476,7 +25534,7 @@ var DepositService = class {
|
|
|
25476
25534
|
if (operator.identifier === this.config.getCoordinatorIdentifier()) {
|
|
25477
25535
|
continue;
|
|
25478
25536
|
}
|
|
25479
|
-
const operatorPubkey2 = (0,
|
|
25537
|
+
const operatorPubkey2 = (0, import_utils10.hexToBytes)(operator.identityPublicKey);
|
|
25480
25538
|
const operatorSig = address2.depositAddressProof.addressSignatures[operator.identifier];
|
|
25481
25539
|
if (!operatorSig) {
|
|
25482
25540
|
throw new ValidationError("Operator signature not found", {
|
|
@@ -25485,7 +25543,11 @@ var DepositService = class {
|
|
|
25485
25543
|
});
|
|
25486
25544
|
}
|
|
25487
25545
|
const sig = import_secp256k18.secp256k1.Signature.fromDER(operatorSig);
|
|
25488
|
-
const isVerified2 = import_secp256k18.secp256k1.verify(
|
|
25546
|
+
const isVerified2 = import_secp256k18.secp256k1.verify(
|
|
25547
|
+
sig.toCompactRawBytes(),
|
|
25548
|
+
addrHash,
|
|
25549
|
+
operatorPubkey2
|
|
25550
|
+
);
|
|
25489
25551
|
if (!isVerified2) {
|
|
25490
25552
|
throw new ValidationError("Operator signature verification failed", {
|
|
25491
25553
|
field: "operatorSignature",
|
|
@@ -25561,7 +25623,7 @@ var DepositService = class {
|
|
|
25561
25623
|
});
|
|
25562
25624
|
}
|
|
25563
25625
|
const depositOutPoint = {
|
|
25564
|
-
txid: (0,
|
|
25626
|
+
txid: (0, import_utils10.hexToBytes)(getTxId(depositTx)),
|
|
25565
25627
|
index: vout
|
|
25566
25628
|
};
|
|
25567
25629
|
const depositTxOut = {
|
|
@@ -25580,8 +25642,8 @@ var DepositService = class {
|
|
|
25580
25642
|
const { cpfpRefundTx, directRefundTx, directFromCpfpRefundTx } = createRefundTxs({
|
|
25581
25643
|
sequence: INITIAL_SEQUENCE,
|
|
25582
25644
|
directSequence: INITIAL_DIRECT_SEQUENCE,
|
|
25583
|
-
input: { txid: (0,
|
|
25584
|
-
directInput: { txid: (0,
|
|
25645
|
+
input: { txid: (0, import_utils10.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
|
|
25646
|
+
directInput: { txid: (0, import_utils10.hexToBytes)(getTxId(directRootTx)), index: 0 },
|
|
25585
25647
|
amountSats: amount,
|
|
25586
25648
|
receivingPubkey: signingPubKey,
|
|
25587
25649
|
network: this.config.getNetwork()
|
|
@@ -25711,7 +25773,7 @@ var DepositService = class {
|
|
|
25711
25773
|
}
|
|
25712
25774
|
);
|
|
25713
25775
|
}
|
|
25714
|
-
if (!(0,
|
|
25776
|
+
if (!(0, import_utils11.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
|
|
25715
25777
|
throw new ValidationError("Verifying key mismatch", {
|
|
25716
25778
|
field: "verifyingKey",
|
|
25717
25779
|
value: treeResp.rootNodeSignatureShares.verifyingKey,
|
|
@@ -25875,7 +25937,7 @@ var DepositService = class {
|
|
|
25875
25937
|
});
|
|
25876
25938
|
}
|
|
25877
25939
|
const depositOutPoint = {
|
|
25878
|
-
txid: (0,
|
|
25940
|
+
txid: (0, import_utils10.hexToBytes)(getTxId(depositTx)),
|
|
25879
25941
|
index: vout
|
|
25880
25942
|
};
|
|
25881
25943
|
const depositTxOut = {
|
|
@@ -25888,7 +25950,7 @@ var DepositService = class {
|
|
|
25888
25950
|
const signingPubKey = await this.config.signer.getPublicKeyFromDerivation(keyDerivation);
|
|
25889
25951
|
const { cpfpRefundTx } = createRefundTxs({
|
|
25890
25952
|
sequence: INITIAL_SEQUENCE,
|
|
25891
|
-
input: { txid: (0,
|
|
25953
|
+
input: { txid: (0, import_utils10.hexToBytes)(getTxId(cpfpRootTx)), index: 0 },
|
|
25892
25954
|
amountSats: amount,
|
|
25893
25955
|
receivingPubkey: signingPubKey,
|
|
25894
25956
|
network: this.config.getNetwork()
|
|
@@ -25958,7 +26020,7 @@ var DepositService = class {
|
|
|
25958
26020
|
}
|
|
25959
26021
|
);
|
|
25960
26022
|
}
|
|
25961
|
-
if (!(0,
|
|
26023
|
+
if (!(0, import_utils11.equalBytes)(treeResp.rootNodeSignatureShares.verifyingKey, verifyingKey)) {
|
|
25962
26024
|
throw new ValidationError("Verifying key mismatch", {
|
|
25963
26025
|
field: "verifyingKey",
|
|
25964
26026
|
value: treeResp.rootNodeSignatureShares.verifyingKey,
|
|
@@ -26034,7 +26096,7 @@ var DepositService = class {
|
|
|
26034
26096
|
|
|
26035
26097
|
// src/services/lightning.ts
|
|
26036
26098
|
init_buffer();
|
|
26037
|
-
var
|
|
26099
|
+
var import_utils12 = require("@noble/curves/abstract/utils");
|
|
26038
26100
|
var import_secp256k19 = require("@noble/curves/secp256k1");
|
|
26039
26101
|
var import_sha29 = require("@noble/hashes/sha2");
|
|
26040
26102
|
var import_uuidv73 = require("uuidv7");
|
|
@@ -26121,8 +26183,8 @@ var LightningService = class {
|
|
|
26121
26183
|
}) {
|
|
26122
26184
|
const crypto = getCrypto();
|
|
26123
26185
|
const randBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
26124
|
-
const preimage = (0,
|
|
26125
|
-
(0,
|
|
26186
|
+
const preimage = (0, import_utils12.numberToBytesBE)(
|
|
26187
|
+
(0, import_utils12.bytesToNumberBE)(randBytes) % import_secp256k19.secp256k1.CURVE.n,
|
|
26126
26188
|
32
|
|
26127
26189
|
);
|
|
26128
26190
|
return await this.createLightningInvoiceWithPreImage({
|
|
@@ -26177,12 +26239,12 @@ var LightningService = class {
|
|
|
26177
26239
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
26178
26240
|
operator.address
|
|
26179
26241
|
);
|
|
26180
|
-
const userIdentityPublicKey = receiverIdentityPubkey ? (0,
|
|
26242
|
+
const userIdentityPublicKey = receiverIdentityPubkey ? (0, import_utils12.hexToBytes)(receiverIdentityPubkey) : await this.config.signer.getIdentityPublicKey();
|
|
26181
26243
|
try {
|
|
26182
26244
|
await sparkClient.store_preimage_share({
|
|
26183
26245
|
paymentHash,
|
|
26184
26246
|
preimageShare: {
|
|
26185
|
-
secretShare: (0,
|
|
26247
|
+
secretShare: (0, import_utils12.numberToBytesBE)(share.share, 32),
|
|
26186
26248
|
proofs: share.proofs
|
|
26187
26249
|
},
|
|
26188
26250
|
threshold: this.config.getThreshold(),
|
|
@@ -26383,15 +26445,18 @@ var LightningService = class {
|
|
|
26383
26445
|
|
|
26384
26446
|
// src/services/token-transactions.ts
|
|
26385
26447
|
init_buffer();
|
|
26386
|
-
var
|
|
26448
|
+
var import_utils17 = require("@noble/curves/abstract/utils");
|
|
26387
26449
|
var import_secp256k112 = require("@noble/curves/secp256k1");
|
|
26388
|
-
var
|
|
26450
|
+
var import_utils18 = require("@noble/hashes/utils");
|
|
26389
26451
|
|
|
26390
26452
|
// src/utils/address.ts
|
|
26391
26453
|
init_buffer();
|
|
26454
|
+
var import_wire8 = require("@bufbuild/protobuf/wire");
|
|
26455
|
+
var import_utils13 = require("@noble/curves/abstract/utils");
|
|
26392
26456
|
var import_secp256k110 = require("@noble/curves/secp256k1");
|
|
26393
|
-
var
|
|
26457
|
+
var import_utils14 = require("@noble/hashes/utils");
|
|
26394
26458
|
var import_base2 = require("@scure/base");
|
|
26459
|
+
var import_uuidv74 = require("uuidv7");
|
|
26395
26460
|
|
|
26396
26461
|
// src/utils/invoice-hashing.ts
|
|
26397
26462
|
init_buffer();
|
|
@@ -26561,9 +26626,6 @@ function uint64be(value) {
|
|
|
26561
26626
|
}
|
|
26562
26627
|
|
|
26563
26628
|
// src/utils/address.ts
|
|
26564
|
-
var import_uuidv74 = require("uuidv7");
|
|
26565
|
-
var import_utils13 = require("@noble/curves/abstract/utils");
|
|
26566
|
-
var import_wire8 = require("@bufbuild/protobuf/wire");
|
|
26567
26629
|
var BECH32M_LIMIT = 1024;
|
|
26568
26630
|
var AddressNetwork = {
|
|
26569
26631
|
MAINNET: "sp",
|
|
@@ -26578,7 +26640,7 @@ function encodeSparkAddress(payload) {
|
|
|
26578
26640
|
function encodeSparkAddressWithSignature(payload, signature) {
|
|
26579
26641
|
try {
|
|
26580
26642
|
isValidPublicKey(payload.identityPublicKey);
|
|
26581
|
-
const identityPublicKey = (0,
|
|
26643
|
+
const identityPublicKey = (0, import_utils14.hexToBytes)(payload.identityPublicKey);
|
|
26582
26644
|
let sparkInvoiceFields;
|
|
26583
26645
|
if (payload.sparkInvoiceFields) {
|
|
26584
26646
|
validateSparkInvoiceFields(payload.sparkInvoiceFields);
|
|
@@ -26622,8 +26684,8 @@ function decodeSparkAddress(address2, network) {
|
|
|
26622
26684
|
}
|
|
26623
26685
|
const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
|
|
26624
26686
|
const { identityPublicKey, sparkInvoiceFields, signature } = payload;
|
|
26625
|
-
const identityPubkeyHex = (0,
|
|
26626
|
-
const signatureHex = signature ? (0,
|
|
26687
|
+
const identityPubkeyHex = (0, import_utils14.bytesToHex)(identityPublicKey);
|
|
26688
|
+
const signatureHex = signature ? (0, import_utils14.bytesToHex)(signature) : void 0;
|
|
26627
26689
|
isValidPublicKey(identityPubkeyHex);
|
|
26628
26690
|
return {
|
|
26629
26691
|
identityPublicKey: identityPubkeyHex,
|
|
@@ -26633,7 +26695,7 @@ function decodeSparkAddress(address2, network) {
|
|
|
26633
26695
|
id: import_uuidv74.UUID.ofInner(sparkInvoiceFields.id).toString(),
|
|
26634
26696
|
paymentType: sparkInvoiceFields.paymentType ? sparkInvoiceFields.paymentType.$case === "tokensPayment" ? {
|
|
26635
26697
|
type: "tokens",
|
|
26636
|
-
tokenIdentifier: sparkInvoiceFields.paymentType.tokensPayment.tokenIdentifier ? (0,
|
|
26698
|
+
tokenIdentifier: sparkInvoiceFields.paymentType.tokensPayment.tokenIdentifier ? (0, import_utils14.bytesToHex)(
|
|
26637
26699
|
sparkInvoiceFields.paymentType.tokensPayment.tokenIdentifier
|
|
26638
26700
|
) : void 0,
|
|
26639
26701
|
amount: sparkInvoiceFields.paymentType.tokensPayment.amount ? (0, import_utils13.bytesToNumberBE)(
|
|
@@ -26644,7 +26706,7 @@ function decodeSparkAddress(address2, network) {
|
|
|
26644
26706
|
amount: sparkInvoiceFields.paymentType.satsPayment.amount
|
|
26645
26707
|
} : void 0 : void 0,
|
|
26646
26708
|
memo: sparkInvoiceFields.memo,
|
|
26647
|
-
senderPublicKey: sparkInvoiceFields.senderPublicKey ? (0,
|
|
26709
|
+
senderPublicKey: sparkInvoiceFields.senderPublicKey ? (0, import_utils14.bytesToHex)(sparkInvoiceFields.senderPublicKey) : void 0,
|
|
26648
26710
|
expiryTime: sparkInvoiceFields.expiryTime
|
|
26649
26711
|
},
|
|
26650
26712
|
signature: signatureHex
|
|
@@ -26693,7 +26755,7 @@ function isValidSparkAddress(address2) {
|
|
|
26693
26755
|
}
|
|
26694
26756
|
function isValidPublicKey(publicKey) {
|
|
26695
26757
|
try {
|
|
26696
|
-
const point = import_secp256k110.secp256k1.
|
|
26758
|
+
const point = import_secp256k110.secp256k1.Point.fromHex(publicKey);
|
|
26697
26759
|
point.assertValidity();
|
|
26698
26760
|
} catch (error) {
|
|
26699
26761
|
throw new ValidationError(
|
|
@@ -26728,7 +26790,7 @@ function validateSparkInvoiceFields(sparkInvoiceFields) {
|
|
|
26728
26790
|
}
|
|
26729
26791
|
if (senderPublicKey) {
|
|
26730
26792
|
try {
|
|
26731
|
-
isValidPublicKey((0,
|
|
26793
|
+
isValidPublicKey((0, import_utils14.bytesToHex)(senderPublicKey));
|
|
26732
26794
|
} catch (error) {
|
|
26733
26795
|
throw new ValidationError(
|
|
26734
26796
|
"Invalid sender public key",
|
|
@@ -28883,12 +28945,12 @@ function validateTokenTransaction(finalTokenTransaction, partialTokenTransaction
|
|
|
28883
28945
|
|
|
28884
28946
|
// src/utils/token-transactions.ts
|
|
28885
28947
|
init_buffer();
|
|
28886
|
-
var
|
|
28887
|
-
var
|
|
28948
|
+
var import_utils15 = require("@noble/curves/abstract/utils");
|
|
28949
|
+
var import_utils16 = require("@scure/btc-signer/utils");
|
|
28888
28950
|
function sumAvailableTokens(outputs) {
|
|
28889
28951
|
try {
|
|
28890
28952
|
return outputs.reduce(
|
|
28891
|
-
(sum, output) => sum + BigInt((0,
|
|
28953
|
+
(sum, output) => sum + BigInt((0, import_utils15.bytesToNumberBE)(output.output.tokenAmount)),
|
|
28892
28954
|
BigInt(0)
|
|
28893
28955
|
);
|
|
28894
28956
|
} catch (error) {
|
|
@@ -28919,7 +28981,7 @@ function filterTokenBalanceForTokenIdentifier(tokenBalances, tokenIdentifier) {
|
|
|
28919
28981
|
}
|
|
28920
28982
|
const tokenIdentifierBytes = decodeBech32mTokenIdentifier(tokenIdentifier).tokenIdentifier;
|
|
28921
28983
|
const tokenBalance = [...tokenBalances.entries()].find(
|
|
28922
|
-
([, info]) => (0,
|
|
28984
|
+
([, info]) => (0, import_utils16.equalBytes)(info.tokenMetadata.rawTokenIdentifier, tokenIdentifierBytes)
|
|
28923
28985
|
);
|
|
28924
28986
|
if (!tokenBalance) {
|
|
28925
28987
|
return {
|
|
@@ -29022,14 +29084,14 @@ var TokenTransactionService = class {
|
|
|
29022
29084
|
}
|
|
29023
29085
|
if (this.config.getTokenTransactionVersion() !== "V0" && receiverAddress.sparkInvoiceFields) {
|
|
29024
29086
|
return {
|
|
29025
|
-
receiverPublicKey: (0,
|
|
29087
|
+
receiverPublicKey: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
|
|
29026
29088
|
rawTokenIdentifier,
|
|
29027
29089
|
tokenAmount: transfer.tokenAmount,
|
|
29028
29090
|
sparkInvoice: transfer.receiverSparkAddress
|
|
29029
29091
|
};
|
|
29030
29092
|
}
|
|
29031
29093
|
return {
|
|
29032
|
-
receiverPublicKey: (0,
|
|
29094
|
+
receiverPublicKey: (0, import_utils18.hexToBytes)(receiverAddress.identityPublicKey),
|
|
29033
29095
|
rawTokenIdentifier,
|
|
29034
29096
|
tokenPublicKey,
|
|
29035
29097
|
// Remove for full v0 deprecation
|
|
@@ -29068,7 +29130,7 @@ var TokenTransactionService = class {
|
|
|
29068
29130
|
const tokenOutputs = tokenOutputData.map((output) => ({
|
|
29069
29131
|
ownerPublicKey: output.receiverPublicKey,
|
|
29070
29132
|
tokenPublicKey: output.tokenPublicKey,
|
|
29071
|
-
tokenAmount: (0,
|
|
29133
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
|
|
29072
29134
|
}));
|
|
29073
29135
|
if (availableTokenAmount > totalRequestedAmount) {
|
|
29074
29136
|
const changeAmount = availableTokenAmount - totalRequestedAmount;
|
|
@@ -29076,7 +29138,7 @@ var TokenTransactionService = class {
|
|
|
29076
29138
|
tokenOutputs.push({
|
|
29077
29139
|
ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
29078
29140
|
tokenPublicKey: firstTokenPublicKey,
|
|
29079
|
-
tokenAmount: (0,
|
|
29141
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
|
|
29080
29142
|
});
|
|
29081
29143
|
}
|
|
29082
29144
|
return {
|
|
@@ -29107,7 +29169,7 @@ var TokenTransactionService = class {
|
|
|
29107
29169
|
(output) => ({
|
|
29108
29170
|
ownerPublicKey: output.receiverPublicKey,
|
|
29109
29171
|
tokenIdentifier: output.rawTokenIdentifier,
|
|
29110
|
-
tokenAmount: (0,
|
|
29172
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(output.tokenAmount, 16)
|
|
29111
29173
|
})
|
|
29112
29174
|
);
|
|
29113
29175
|
if (availableTokenAmount > totalRequestedAmount) {
|
|
@@ -29116,7 +29178,7 @@ var TokenTransactionService = class {
|
|
|
29116
29178
|
tokenOutputs.push({
|
|
29117
29179
|
ownerPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
29118
29180
|
tokenIdentifier: firstTokenIdentifierBytes,
|
|
29119
|
-
tokenAmount: (0,
|
|
29181
|
+
tokenAmount: (0, import_utils17.numberToBytesBE)(changeAmount, 16)
|
|
29120
29182
|
});
|
|
29121
29183
|
}
|
|
29122
29184
|
return {
|
|
@@ -29143,7 +29205,7 @@ var TokenTransactionService = class {
|
|
|
29143
29205
|
for (const [_, operator] of Object.entries(
|
|
29144
29206
|
this.config.getSigningOperators()
|
|
29145
29207
|
)) {
|
|
29146
|
-
operatorKeys.push((0,
|
|
29208
|
+
operatorKeys.push((0, import_utils18.hexToBytes)(operator.identityPublicKey));
|
|
29147
29209
|
}
|
|
29148
29210
|
return operatorKeys;
|
|
29149
29211
|
}
|
|
@@ -29227,7 +29289,7 @@ var TokenTransactionService = class {
|
|
|
29227
29289
|
{
|
|
29228
29290
|
field: "revocationCommitment",
|
|
29229
29291
|
value: derivedRevocationCommitment,
|
|
29230
|
-
expected: (0,
|
|
29292
|
+
expected: (0, import_utils17.bytesToHex)(outputsToSpendCommitments[outputIndex]),
|
|
29231
29293
|
outputIndex
|
|
29232
29294
|
}
|
|
29233
29295
|
)
|
|
@@ -29253,7 +29315,7 @@ var TokenTransactionService = class {
|
|
|
29253
29315
|
threshold
|
|
29254
29316
|
);
|
|
29255
29317
|
}
|
|
29256
|
-
return (0,
|
|
29318
|
+
return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
|
|
29257
29319
|
}
|
|
29258
29320
|
async broadcastTokenTransactionV1(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
|
|
29259
29321
|
const { finalTokenTransaction, finalTokenTransactionHash, threshold } = await this.startTokenTransaction(
|
|
@@ -29267,7 +29329,7 @@ var TokenTransactionService = class {
|
|
|
29267
29329
|
finalTokenTransactionHash,
|
|
29268
29330
|
signingOperators
|
|
29269
29331
|
);
|
|
29270
|
-
return (0,
|
|
29332
|
+
return (0, import_utils17.bytesToHex)(finalTokenTransactionHash);
|
|
29271
29333
|
}
|
|
29272
29334
|
async startTokenTransactionV0(tokenTransaction, signingOperators, outputsToSpendSigningPublicKeys, outputsToSpendCommitments) {
|
|
29273
29335
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
@@ -29491,7 +29553,7 @@ var TokenTransactionService = class {
|
|
|
29491
29553
|
const identityPublicKey = await this.config.signer.getIdentityPublicKey();
|
|
29492
29554
|
const payload = {
|
|
29493
29555
|
finalTokenTransactionHash,
|
|
29494
|
-
operatorIdentityPublicKey: (0,
|
|
29556
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
29495
29557
|
};
|
|
29496
29558
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
29497
29559
|
let operatorSpecificSignatures = [];
|
|
@@ -29706,8 +29768,8 @@ var TokenTransactionService = class {
|
|
|
29706
29768
|
this.config.getCoordinatorAddress()
|
|
29707
29769
|
);
|
|
29708
29770
|
let queryParams = {
|
|
29709
|
-
tokenPublicKeys: issuerPublicKeys?.map(
|
|
29710
|
-
ownerPublicKeys: ownerPublicKeys?.map(
|
|
29771
|
+
tokenPublicKeys: issuerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29772
|
+
ownerPublicKeys: ownerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29711
29773
|
tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
|
|
29712
29774
|
const { tokenIdentifier } = decodeBech32mTokenIdentifier(
|
|
29713
29775
|
identifier,
|
|
@@ -29715,7 +29777,7 @@ var TokenTransactionService = class {
|
|
|
29715
29777
|
);
|
|
29716
29778
|
return tokenIdentifier;
|
|
29717
29779
|
}),
|
|
29718
|
-
tokenTransactionHashes: tokenTransactionHashes?.map(
|
|
29780
|
+
tokenTransactionHashes: tokenTransactionHashes?.map(import_utils18.hexToBytes),
|
|
29719
29781
|
outputIds: outputIds || [],
|
|
29720
29782
|
limit: pageSize,
|
|
29721
29783
|
offset
|
|
@@ -29774,8 +29836,8 @@ var TokenTransactionService = class {
|
|
|
29774
29836
|
this.config.getCoordinatorAddress()
|
|
29775
29837
|
);
|
|
29776
29838
|
let queryParams = {
|
|
29777
|
-
issuerPublicKeys: issuerPublicKeys?.map(
|
|
29778
|
-
ownerPublicKeys: ownerPublicKeys?.map(
|
|
29839
|
+
issuerPublicKeys: issuerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29840
|
+
ownerPublicKeys: ownerPublicKeys?.map(import_utils18.hexToBytes),
|
|
29779
29841
|
tokenIdentifiers: tokenIdentifiers?.map((identifier) => {
|
|
29780
29842
|
const { tokenIdentifier } = decodeBech32mTokenIdentifier(
|
|
29781
29843
|
identifier,
|
|
@@ -29783,7 +29845,7 @@ var TokenTransactionService = class {
|
|
|
29783
29845
|
);
|
|
29784
29846
|
return tokenIdentifier;
|
|
29785
29847
|
}),
|
|
29786
|
-
tokenTransactionHashes: tokenTransactionHashes?.map(
|
|
29848
|
+
tokenTransactionHashes: tokenTransactionHashes?.map(import_utils18.hexToBytes),
|
|
29787
29849
|
outputIds: outputIds || [],
|
|
29788
29850
|
limit: pageSize,
|
|
29789
29851
|
offset
|
|
@@ -29818,7 +29880,7 @@ var TokenTransactionService = class {
|
|
|
29818
29880
|
});
|
|
29819
29881
|
}
|
|
29820
29882
|
const exactMatch = tokenOutputs.find(
|
|
29821
|
-
(item) => (0,
|
|
29883
|
+
(item) => (0, import_utils17.bytesToNumberBE)(item.output.tokenAmount) === tokenAmount
|
|
29822
29884
|
);
|
|
29823
29885
|
if (exactMatch) {
|
|
29824
29886
|
return [exactMatch];
|
|
@@ -29829,7 +29891,7 @@ var TokenTransactionService = class {
|
|
|
29829
29891
|
for (const outputWithPreviousTransactionData of tokenOutputs) {
|
|
29830
29892
|
if (remainingAmount <= 0n) break;
|
|
29831
29893
|
selectedOutputs.push(outputWithPreviousTransactionData);
|
|
29832
|
-
remainingAmount -= (0,
|
|
29894
|
+
remainingAmount -= (0, import_utils17.bytesToNumberBE)(
|
|
29833
29895
|
outputWithPreviousTransactionData.output.tokenAmount
|
|
29834
29896
|
);
|
|
29835
29897
|
}
|
|
@@ -29845,13 +29907,13 @@ var TokenTransactionService = class {
|
|
|
29845
29907
|
if (strategy === "SMALL_FIRST") {
|
|
29846
29908
|
tokenOutputs.sort((a, b) => {
|
|
29847
29909
|
return Number(
|
|
29848
|
-
(0,
|
|
29910
|
+
(0, import_utils17.bytesToNumberBE)(a.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(b.output.tokenAmount)
|
|
29849
29911
|
);
|
|
29850
29912
|
});
|
|
29851
29913
|
} else {
|
|
29852
29914
|
tokenOutputs.sort((a, b) => {
|
|
29853
29915
|
return Number(
|
|
29854
|
-
(0,
|
|
29916
|
+
(0, import_utils17.bytesToNumberBE)(b.output.tokenAmount) - (0, import_utils17.bytesToNumberBE)(a.output.tokenAmount)
|
|
29855
29917
|
);
|
|
29856
29918
|
});
|
|
29857
29919
|
}
|
|
@@ -29859,7 +29921,7 @@ var TokenTransactionService = class {
|
|
|
29859
29921
|
// Helper function for deciding if the signer public key is the identity public key
|
|
29860
29922
|
async signMessageWithKey(message, publicKey) {
|
|
29861
29923
|
const tokenSignatures = this.config.getTokenSignatures();
|
|
29862
|
-
if ((0,
|
|
29924
|
+
if ((0, import_utils17.bytesToHex)(publicKey) === (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())) {
|
|
29863
29925
|
if (tokenSignatures === "SCHNORR") {
|
|
29864
29926
|
return await this.config.signer.signSchnorrWithIdentityKey(message);
|
|
29865
29927
|
} else {
|
|
@@ -29868,8 +29930,8 @@ var TokenTransactionService = class {
|
|
|
29868
29930
|
} else {
|
|
29869
29931
|
throw new ValidationError("Invalid public key", {
|
|
29870
29932
|
field: "publicKey",
|
|
29871
|
-
value: (0,
|
|
29872
|
-
expected: (0,
|
|
29933
|
+
value: (0, import_utils17.bytesToHex)(publicKey),
|
|
29934
|
+
expected: (0, import_utils17.bytesToHex)(await this.config.signer.getIdentityPublicKey())
|
|
29873
29935
|
});
|
|
29874
29936
|
}
|
|
29875
29937
|
}
|
|
@@ -29932,7 +29994,7 @@ var TokenTransactionService = class {
|
|
|
29932
29994
|
}
|
|
29933
29995
|
const payload = {
|
|
29934
29996
|
finalTokenTransactionHash,
|
|
29935
|
-
operatorIdentityPublicKey: (0,
|
|
29997
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
29936
29998
|
};
|
|
29937
29999
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
29938
30000
|
const ownerSignature = await this.signMessageWithKey(
|
|
@@ -29954,7 +30016,7 @@ var TokenTransactionService = class {
|
|
|
29954
30016
|
}
|
|
29955
30017
|
const payload = {
|
|
29956
30018
|
finalTokenTransactionHash,
|
|
29957
|
-
operatorIdentityPublicKey: (0,
|
|
30019
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
29958
30020
|
};
|
|
29959
30021
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
29960
30022
|
const ownerSignature = await this.signMessageWithKey(
|
|
@@ -29970,7 +30032,7 @@ var TokenTransactionService = class {
|
|
|
29970
30032
|
for (let i = 0; i < transferInput.outputsToSpend.length; i++) {
|
|
29971
30033
|
const payload = {
|
|
29972
30034
|
finalTokenTransactionHash,
|
|
29973
|
-
operatorIdentityPublicKey: (0,
|
|
30035
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
29974
30036
|
};
|
|
29975
30037
|
const payloadHash = await hashOperatorSpecificTokenTransactionSignablePayload(payload);
|
|
29976
30038
|
let ownerSignature;
|
|
@@ -29987,7 +30049,7 @@ var TokenTransactionService = class {
|
|
|
29987
30049
|
}
|
|
29988
30050
|
inputTtxoSignaturesPerOperator.push({
|
|
29989
30051
|
ttxoSignatures,
|
|
29990
|
-
operatorIdentityPublicKey: (0,
|
|
30052
|
+
operatorIdentityPublicKey: (0, import_utils18.hexToBytes)(operator.identityPublicKey)
|
|
29991
30053
|
});
|
|
29992
30054
|
}
|
|
29993
30055
|
return inputTtxoSignaturesPerOperator;
|
|
@@ -30000,23 +30062,23 @@ function isTokenTransaction(tokenTransaction) {
|
|
|
30000
30062
|
// src/utils/adaptor-signature.ts
|
|
30001
30063
|
init_buffer();
|
|
30002
30064
|
var import_modular = require("@noble/curves/abstract/modular");
|
|
30003
|
-
var
|
|
30065
|
+
var import_utils19 = require("@noble/curves/abstract/utils");
|
|
30004
30066
|
var import_secp256k113 = require("@noble/curves/secp256k1");
|
|
30005
30067
|
function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
|
|
30006
30068
|
const { r, s: s2 } = parseSignature(signature);
|
|
30007
|
-
const sBigInt = (0,
|
|
30008
|
-
const tBigInt = (0,
|
|
30069
|
+
const sBigInt = (0, import_utils19.bytesToNumberBE)(s2);
|
|
30070
|
+
const tBigInt = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKeyBytes);
|
|
30009
30071
|
const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
|
|
30010
|
-
const newSignature = new Uint8Array([...r, ...(0,
|
|
30072
|
+
const newSignature = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
|
|
30011
30073
|
return newSignature;
|
|
30012
30074
|
}
|
|
30013
30075
|
function generateAdaptorFromSignature(signature) {
|
|
30014
30076
|
const adaptorPrivateKey = import_secp256k113.secp256k1.utils.randomPrivateKey();
|
|
30015
30077
|
const { r, s: s2 } = parseSignature(signature);
|
|
30016
|
-
const sBigInt = (0,
|
|
30017
|
-
const tBigInt = (0,
|
|
30078
|
+
const sBigInt = (0, import_utils19.bytesToNumberBE)(s2);
|
|
30079
|
+
const tBigInt = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKey);
|
|
30018
30080
|
const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k113.secp256k1.CURVE.n);
|
|
30019
|
-
const newSignature = new Uint8Array([...r, ...(0,
|
|
30081
|
+
const newSignature = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
|
|
30020
30082
|
return {
|
|
30021
30083
|
adaptorSignature: newSignature,
|
|
30022
30084
|
adaptorPrivateKey
|
|
@@ -30033,10 +30095,10 @@ function validateOutboundAdaptorSignature(pubkey, hash, signature, adaptorPubkey
|
|
|
30033
30095
|
}
|
|
30034
30096
|
function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes) {
|
|
30035
30097
|
const { r, s: s2 } = parseSignature(signature);
|
|
30036
|
-
const sBigInt = (0,
|
|
30037
|
-
const adaptorPrivateKey = (0,
|
|
30098
|
+
const sBigInt = (0, import_utils19.bytesToNumberBE)(s2);
|
|
30099
|
+
const adaptorPrivateKey = (0, import_utils19.bytesToNumberBE)(adaptorPrivateKeyBytes);
|
|
30038
30100
|
const newS = (0, import_modular.mod)(sBigInt + adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
|
|
30039
|
-
const newSig = new Uint8Array([...r, ...(0,
|
|
30101
|
+
const newSig = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(newS, 32)]);
|
|
30040
30102
|
try {
|
|
30041
30103
|
if (import_secp256k113.schnorr.verify(newSig, hash, pubkey)) {
|
|
30042
30104
|
return newSig;
|
|
@@ -30045,7 +30107,7 @@ function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes
|
|
|
30045
30107
|
console.error("[applyAdaptorToSignature] Addition verification failed:", e);
|
|
30046
30108
|
}
|
|
30047
30109
|
const altS = (0, import_modular.mod)(sBigInt - adaptorPrivateKey, import_secp256k113.secp256k1.CURVE.n);
|
|
30048
|
-
const altSig = new Uint8Array([...r, ...(0,
|
|
30110
|
+
const altSig = new Uint8Array([...r, ...(0, import_utils19.numberToBytesBE)(altS, 32)]);
|
|
30049
30111
|
try {
|
|
30050
30112
|
if (import_secp256k113.schnorr.verify(altSig, hash, pubkey)) {
|
|
30051
30113
|
return altSig;
|
|
@@ -30062,39 +30124,37 @@ function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, i
|
|
|
30062
30124
|
if (hash.length !== 32) {
|
|
30063
30125
|
throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
|
|
30064
30126
|
}
|
|
30065
|
-
const pubKey = import_secp256k113.schnorr.utils.lift_x((0,
|
|
30127
|
+
const pubKey = import_secp256k113.schnorr.utils.lift_x((0, import_utils19.bytesToNumberBE)(pubKeyBytes));
|
|
30066
30128
|
pubKey.assertValidity();
|
|
30067
30129
|
const { r, s: s2 } = parseSignature(signature);
|
|
30068
30130
|
const commitmenet = import_secp256k113.schnorr.utils.taggedHash(
|
|
30069
30131
|
"BIP0340/challenge",
|
|
30070
30132
|
r,
|
|
30071
|
-
pubKey.
|
|
30133
|
+
pubKey.toBytes().slice(1),
|
|
30072
30134
|
hash
|
|
30073
30135
|
);
|
|
30074
30136
|
if (commitmenet.length > 32) {
|
|
30075
30137
|
throw new Error("hash of (r || P || m) too big");
|
|
30076
30138
|
}
|
|
30077
|
-
const e = (0, import_modular.mod)((0,
|
|
30139
|
+
const e = (0, import_modular.mod)((0, import_utils19.bytesToNumberBE)(commitmenet), import_secp256k113.secp256k1.CURVE.n);
|
|
30078
30140
|
const negE = (0, import_modular.mod)(-e, import_secp256k113.secp256k1.CURVE.n);
|
|
30079
|
-
const
|
|
30080
|
-
|
|
30081
|
-
|
|
30082
|
-
|
|
30083
|
-
|
|
30084
|
-
if (!R) {
|
|
30085
|
-
throw new Error("R is undefined");
|
|
30141
|
+
const sG = import_secp256k113.secp256k1.Point.BASE.multiplyUnsafe((0, import_utils19.bytesToNumberBE)(s2));
|
|
30142
|
+
const eP = pubKey.multiplyUnsafe(negE);
|
|
30143
|
+
const R = sG.add(eP);
|
|
30144
|
+
if (R.is0()) {
|
|
30145
|
+
throw new Error("R is zero");
|
|
30086
30146
|
}
|
|
30087
30147
|
R.assertValidity();
|
|
30088
|
-
const adaptorPoint = import_secp256k113.secp256k1.
|
|
30148
|
+
const adaptorPoint = import_secp256k113.secp256k1.Point.fromHex(adaptorPubkey);
|
|
30089
30149
|
const newR = R.add(adaptorPoint);
|
|
30090
|
-
if (!inbound && newR.equals(import_secp256k113.secp256k1.
|
|
30150
|
+
if (!inbound && newR.equals(import_secp256k113.secp256k1.Point.ZERO)) {
|
|
30091
30151
|
throw new Error("calculated R point is the point at infinity");
|
|
30092
30152
|
}
|
|
30093
30153
|
newR.assertValidity();
|
|
30094
|
-
if (
|
|
30154
|
+
if (newR.y % 2n !== 0n) {
|
|
30095
30155
|
throw new Error("calculated R y-value is odd");
|
|
30096
30156
|
}
|
|
30097
|
-
const rNum = (0,
|
|
30157
|
+
const rNum = (0, import_utils19.bytesToNumberBE)(r);
|
|
30098
30158
|
if (newR.toAffine().x !== rNum) {
|
|
30099
30159
|
throw new Error("calculated R point was not given R");
|
|
30100
30160
|
}
|
|
@@ -30115,15 +30175,15 @@ function parseSignature(signature) {
|
|
|
30115
30175
|
}
|
|
30116
30176
|
const r = signature.slice(0, 32);
|
|
30117
30177
|
const s2 = signature.slice(32, 64);
|
|
30118
|
-
if ((0,
|
|
30178
|
+
if ((0, import_utils19.bytesToNumberBE)(r) >= import_secp256k113.secp256k1.CURVE.Fp.ORDER) {
|
|
30119
30179
|
throw new ValidationError("Invalid signature: r >= field prime", {
|
|
30120
|
-
rValue: (0,
|
|
30180
|
+
rValue: (0, import_utils19.bytesToNumberBE)(r),
|
|
30121
30181
|
fieldPrime: import_secp256k113.secp256k1.CURVE.Fp.ORDER
|
|
30122
30182
|
});
|
|
30123
30183
|
}
|
|
30124
|
-
if ((0,
|
|
30184
|
+
if ((0, import_utils19.bytesToNumberBE)(s2) >= import_secp256k113.secp256k1.CURVE.n) {
|
|
30125
30185
|
throw new ValidationError("Invalid signature: s >= group order", {
|
|
30126
|
-
sValue: (0,
|
|
30186
|
+
sValue: (0, import_utils19.bytesToNumberBE)(s2),
|
|
30127
30187
|
groupOrder: import_secp256k113.secp256k1.CURVE.n
|
|
30128
30188
|
});
|
|
30129
30189
|
}
|
|
@@ -30139,7 +30199,7 @@ var import_nice_grpc_common3 = require("nice-grpc-common");
|
|
|
30139
30199
|
|
|
30140
30200
|
// src/services/signing.ts
|
|
30141
30201
|
init_buffer();
|
|
30142
|
-
var
|
|
30202
|
+
var import_utils20 = require("@noble/curves/abstract/utils");
|
|
30143
30203
|
var SigningService = class {
|
|
30144
30204
|
config;
|
|
30145
30205
|
constructor(config) {
|
|
@@ -30195,7 +30255,7 @@ var SigningService = class {
|
|
|
30195
30255
|
}
|
|
30196
30256
|
const nodeTx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
|
|
30197
30257
|
const cpfpNodeOutPoint = {
|
|
30198
|
-
txid: (0,
|
|
30258
|
+
txid: (0, import_utils20.hexToBytes)(getTxId(nodeTx)),
|
|
30199
30259
|
index: 0
|
|
30200
30260
|
};
|
|
30201
30261
|
const currRefundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
|
|
@@ -30221,7 +30281,7 @@ var SigningService = class {
|
|
|
30221
30281
|
if (leaf.leaf.directTx.length > 0) {
|
|
30222
30282
|
directNodeTx = getTxFromRawTxBytes(leaf.leaf.directTx);
|
|
30223
30283
|
directNodeOutPoint = {
|
|
30224
|
-
txid: (0,
|
|
30284
|
+
txid: (0, import_utils20.hexToBytes)(getTxId(directNodeTx)),
|
|
30225
30285
|
index: 0
|
|
30226
30286
|
};
|
|
30227
30287
|
}
|
|
@@ -30305,15 +30365,15 @@ var SigningService = class {
|
|
|
30305
30365
|
|
|
30306
30366
|
// src/tests/utils/test-faucet.ts
|
|
30307
30367
|
init_buffer();
|
|
30308
|
-
var
|
|
30368
|
+
var import_utils21 = require("@noble/curves/abstract/utils");
|
|
30309
30369
|
var import_secp256k114 = require("@noble/curves/secp256k1");
|
|
30310
30370
|
var btc3 = __toESM(require("@scure/btc-signer"), 1);
|
|
30311
30371
|
var import_btc_signer5 = require("@scure/btc-signer");
|
|
30312
|
-
var
|
|
30313
|
-
var STATIC_FAUCET_KEY = (0,
|
|
30372
|
+
var import_utils22 = require("@scure/btc-signer/utils");
|
|
30373
|
+
var STATIC_FAUCET_KEY = (0, import_utils21.hexToBytes)(
|
|
30314
30374
|
"deadbeef1337cafe4242424242424242deadbeef1337cafe4242424242424242"
|
|
30315
30375
|
);
|
|
30316
|
-
var STATIC_MINING_KEY = (0,
|
|
30376
|
+
var STATIC_MINING_KEY = (0, import_utils21.hexToBytes)(
|
|
30317
30377
|
"1337cafe4242deadbeef4242424242421337cafe4242deadbeef424242424242"
|
|
30318
30378
|
);
|
|
30319
30379
|
var SATS_PER_BTC = 1e8;
|
|
@@ -30376,7 +30436,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30376
30436
|
if (!scanResult.success || scanResult.unspents.length === 0) {
|
|
30377
30437
|
const blockHash = await this.generateToAddress(1, address2);
|
|
30378
30438
|
const block = await this.getBlock(blockHash[0]);
|
|
30379
|
-
const fundingTx = import_btc_signer5.Transaction.fromRaw((0,
|
|
30439
|
+
const fundingTx = import_btc_signer5.Transaction.fromRaw((0, import_utils21.hexToBytes)(block.tx[0].hex), {
|
|
30380
30440
|
allowUnknownOutputs: true
|
|
30381
30441
|
});
|
|
30382
30442
|
await this.generateToAddress(100, this.miningAddress);
|
|
@@ -30438,13 +30498,13 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30438
30498
|
},
|
|
30439
30499
|
STATIC_MINING_KEY
|
|
30440
30500
|
);
|
|
30441
|
-
await this.broadcastTx((0,
|
|
30501
|
+
await this.broadcastTx((0, import_utils21.bytesToHex)(signedSplitTx.extract()));
|
|
30442
30502
|
const splitTxId = signedSplitTx.id;
|
|
30443
30503
|
for (let i = 0; i < numCoinsToCreate; i++) {
|
|
30444
30504
|
this.coins.push({
|
|
30445
30505
|
key: STATIC_FAUCET_KEY,
|
|
30446
30506
|
outpoint: {
|
|
30447
|
-
txid: (0,
|
|
30507
|
+
txid: (0, import_utils21.hexToBytes)(splitTxId),
|
|
30448
30508
|
index: i
|
|
30449
30509
|
},
|
|
30450
30510
|
txout: signedSplitTx.getOutput(i)
|
|
@@ -30472,7 +30532,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30472
30532
|
coinToSend.txout,
|
|
30473
30533
|
coinToSend.key
|
|
30474
30534
|
);
|
|
30475
|
-
await this.broadcastTx((0,
|
|
30535
|
+
await this.broadcastTx((0, import_utils21.bytesToHex)(signedTx.extract()));
|
|
30476
30536
|
}
|
|
30477
30537
|
async signFaucetCoin(unsignedTx, fundingTxOut, key) {
|
|
30478
30538
|
const pubKey = import_secp256k114.secp256k1.getPublicKey(key);
|
|
@@ -30492,7 +30552,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30492
30552
|
new Array(unsignedTx.inputsLength).fill(fundingTxOut.amount)
|
|
30493
30553
|
);
|
|
30494
30554
|
const merkleRoot = new Uint8Array();
|
|
30495
|
-
const tweakedKey = (0,
|
|
30555
|
+
const tweakedKey = (0, import_utils22.taprootTweakPrivKey)(key, merkleRoot);
|
|
30496
30556
|
if (!tweakedKey)
|
|
30497
30557
|
throw new Error("Invalid private key for taproot tweaking");
|
|
30498
30558
|
const signature = import_secp256k114.schnorr.sign(sighash, tweakedKey);
|
|
@@ -30592,7 +30652,7 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30592
30652
|
});
|
|
30593
30653
|
}
|
|
30594
30654
|
const signedTx = await this.signFaucetCoin(tx, coin.txout, coin.key);
|
|
30595
|
-
const txHex = (0,
|
|
30655
|
+
const txHex = (0, import_utils21.bytesToHex)(signedTx.extract());
|
|
30596
30656
|
await this.broadcastTx(txHex);
|
|
30597
30657
|
const randomKey = import_secp256k114.secp256k1.utils.randomPrivateKey();
|
|
30598
30658
|
const randomPubKey = import_secp256k114.secp256k1.getPublicKey(randomKey);
|
|
@@ -30610,18 +30670,18 @@ var BitcoinFaucet = class _BitcoinFaucet {
|
|
|
30610
30670
|
|
|
30611
30671
|
// src/types/sdk-types.ts
|
|
30612
30672
|
init_buffer();
|
|
30613
|
-
var
|
|
30673
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
|
30614
30674
|
function mapTreeNodeToWalletLeaf(proto) {
|
|
30615
30675
|
return {
|
|
30616
30676
|
id: proto.id,
|
|
30617
30677
|
treeId: proto.treeId,
|
|
30618
30678
|
value: proto.value,
|
|
30619
30679
|
parentNodeId: proto.parentNodeId,
|
|
30620
|
-
nodeTx: (0,
|
|
30621
|
-
refundTx: (0,
|
|
30680
|
+
nodeTx: (0, import_utils23.bytesToHex)(proto.nodeTx),
|
|
30681
|
+
refundTx: (0, import_utils23.bytesToHex)(proto.refundTx),
|
|
30622
30682
|
vout: proto.vout,
|
|
30623
|
-
verifyingPublicKey: (0,
|
|
30624
|
-
ownerIdentityPublicKey: (0,
|
|
30683
|
+
verifyingPublicKey: (0, import_utils23.bytesToHex)(proto.verifyingPublicKey),
|
|
30684
|
+
ownerIdentityPublicKey: (0, import_utils23.bytesToHex)(proto.ownerIdentityPublicKey),
|
|
30625
30685
|
signingKeyshare: proto.signingKeyshare,
|
|
30626
30686
|
status: proto.status,
|
|
30627
30687
|
network: Network[proto.network]
|
|
@@ -30630,14 +30690,14 @@ function mapTreeNodeToWalletLeaf(proto) {
|
|
|
30630
30690
|
function mapTransferLeafToWalletTransferLeaf(proto) {
|
|
30631
30691
|
return {
|
|
30632
30692
|
leaf: proto.leaf ? mapTreeNodeToWalletLeaf(proto.leaf) : void 0,
|
|
30633
|
-
secretCipher: (0,
|
|
30634
|
-
signature: (0,
|
|
30635
|
-
intermediateRefundTx: (0,
|
|
30693
|
+
secretCipher: (0, import_utils23.bytesToHex)(proto.secretCipher),
|
|
30694
|
+
signature: (0, import_utils23.bytesToHex)(proto.signature),
|
|
30695
|
+
intermediateRefundTx: (0, import_utils23.bytesToHex)(proto.intermediateRefundTx)
|
|
30636
30696
|
};
|
|
30637
30697
|
}
|
|
30638
30698
|
function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
|
|
30639
|
-
const receiverIdentityPublicKey = (0,
|
|
30640
|
-
const senderIdentityPublicKey = (0,
|
|
30699
|
+
const receiverIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.receiverIdentityPublicKey);
|
|
30700
|
+
const senderIdentityPublicKey = (0, import_utils23.bytesToHex)(proto.senderIdentityPublicKey);
|
|
30641
30701
|
return {
|
|
30642
30702
|
id: proto.id,
|
|
30643
30703
|
senderIdentityPublicKey,
|
|
@@ -30829,7 +30889,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
30829
30889
|
try {
|
|
30830
30890
|
if (event?.$case === "transfer" && event.transfer.transfer && event.transfer.transfer.type !== 40 /* COUNTER_SWAP */) {
|
|
30831
30891
|
const { senderIdentityPublicKey, receiverIdentityPublicKey } = event.transfer.transfer;
|
|
30832
|
-
if (event.transfer.transfer && !(0,
|
|
30892
|
+
if (event.transfer.transfer && !(0, import_utils24.equalBytes)(senderIdentityPublicKey, receiverIdentityPublicKey)) {
|
|
30833
30893
|
await this.claimTransfer({
|
|
30834
30894
|
transfer: event.transfer.transfer,
|
|
30835
30895
|
emit: true,
|
|
@@ -30898,7 +30958,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
30898
30958
|
setTimeout(maybeUnref, 100);
|
|
30899
30959
|
}
|
|
30900
30960
|
};
|
|
30901
|
-
if (
|
|
30961
|
+
if (import_core13.isNode) {
|
|
30902
30962
|
maybeUnref();
|
|
30903
30963
|
}
|
|
30904
30964
|
const claimedTransfersIds = await this.claimTransfers();
|
|
@@ -30994,10 +31054,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
30994
31054
|
leavesToIgnore.add(nodeId);
|
|
30995
31055
|
continue;
|
|
30996
31056
|
}
|
|
30997
|
-
if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0,
|
|
31057
|
+
if (leaf.status !== operatorLeaf.status || !leaf.signingKeyshare || !operatorLeaf.signingKeyshare || !(0, import_utils24.equalBytes)(
|
|
30998
31058
|
leaf.signingKeyshare.publicKey,
|
|
30999
31059
|
operatorLeaf.signingKeyshare.publicKey
|
|
31000
|
-
) || !(0,
|
|
31060
|
+
) || !(0, import_utils24.equalBytes)(leaf.nodeTx, operatorLeaf.nodeTx)) {
|
|
31001
31061
|
leavesToIgnore.add(nodeId);
|
|
31002
31062
|
}
|
|
31003
31063
|
}
|
|
@@ -31048,7 +31108,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31048
31108
|
});
|
|
31049
31109
|
}
|
|
31050
31110
|
verifyKey(pubkey1, pubkey2, verifyingKey) {
|
|
31051
|
-
return (0,
|
|
31111
|
+
return (0, import_utils24.equalBytes)(addPublicKeys(pubkey1, pubkey2), verifyingKey);
|
|
31052
31112
|
}
|
|
31053
31113
|
async selectLeaves(targetAmounts) {
|
|
31054
31114
|
if (targetAmounts.length === 0) {
|
|
@@ -31206,7 +31266,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31206
31266
|
* @returns {Promise<string>} The identity public key as a hex string.
|
|
31207
31267
|
*/
|
|
31208
31268
|
async getIdentityPublicKey() {
|
|
31209
|
-
return (0,
|
|
31269
|
+
return (0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey());
|
|
31210
31270
|
}
|
|
31211
31271
|
/**
|
|
31212
31272
|
* Gets the Spark address of the wallet.
|
|
@@ -31216,7 +31276,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31216
31276
|
async getSparkAddress() {
|
|
31217
31277
|
if (!this.sparkAddress) {
|
|
31218
31278
|
this.sparkAddress = encodeSparkAddress({
|
|
31219
|
-
identityPublicKey: (0,
|
|
31279
|
+
identityPublicKey: (0, import_utils24.bytesToHex)(
|
|
31220
31280
|
await this.config.signer.getIdentityPublicKey()
|
|
31221
31281
|
),
|
|
31222
31282
|
network: this.config.getNetworkType()
|
|
@@ -31279,7 +31339,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31279
31339
|
$case: "tokensPayment",
|
|
31280
31340
|
tokensPayment: {
|
|
31281
31341
|
tokenIdentifier: decodedTokenIdentifier ?? void 0,
|
|
31282
|
-
amount: amount ? (0,
|
|
31342
|
+
amount: amount ? (0, import_utils24.numberToVarBytesBE)(amount) : void 0
|
|
31283
31343
|
}
|
|
31284
31344
|
};
|
|
31285
31345
|
const invoiceFields = {
|
|
@@ -31287,7 +31347,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31287
31347
|
id: (0, import_uuidv75.uuidv7obj)().bytes,
|
|
31288
31348
|
paymentType: protoPayment,
|
|
31289
31349
|
memo: memo ?? void 0,
|
|
31290
|
-
senderPublicKey: senderPublicKey ? (0,
|
|
31350
|
+
senderPublicKey: senderPublicKey ? (0, import_utils24.hexToBytes)(senderPublicKey) : void 0,
|
|
31291
31351
|
expiryTime: expiryTime ?? void 0
|
|
31292
31352
|
};
|
|
31293
31353
|
validateSparkInvoiceFields(invoiceFields);
|
|
@@ -31300,7 +31360,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31300
31360
|
const signature = await this.config.signer.signSchnorrWithIdentityKey(hash);
|
|
31301
31361
|
return encodeSparkAddressWithSignature(
|
|
31302
31362
|
{
|
|
31303
|
-
identityPublicKey: (0,
|
|
31363
|
+
identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
|
|
31304
31364
|
network: this.config.getNetworkType(),
|
|
31305
31365
|
sparkInvoiceFields: invoiceFields
|
|
31306
31366
|
},
|
|
@@ -31346,7 +31406,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31346
31406
|
mnemonic = mnemonicOrSeed;
|
|
31347
31407
|
seed = await this.config.signer.mnemonicToSeed(mnemonicOrSeed);
|
|
31348
31408
|
} else {
|
|
31349
|
-
seed = (0,
|
|
31409
|
+
seed = (0, import_utils24.hexToBytes)(mnemonicOrSeed);
|
|
31350
31410
|
}
|
|
31351
31411
|
}
|
|
31352
31412
|
await this.initWalletFromSeed(seed, accountNumber);
|
|
@@ -31368,7 +31428,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31368
31428
|
});
|
|
31369
31429
|
}
|
|
31370
31430
|
this.sparkAddress = encodeSparkAddress({
|
|
31371
|
-
identityPublicKey: (0,
|
|
31431
|
+
identityPublicKey: (0, import_utils24.bytesToHex)(identityPublicKey),
|
|
31372
31432
|
network: this.config.getNetworkType()
|
|
31373
31433
|
});
|
|
31374
31434
|
return this.sparkAddress;
|
|
@@ -31488,7 +31548,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31488
31548
|
directFromCpfpSignatureMap
|
|
31489
31549
|
} = await this.transferService.startSwapSignRefund(
|
|
31490
31550
|
leafKeyTweaks,
|
|
31491
|
-
(0,
|
|
31551
|
+
(0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey()),
|
|
31492
31552
|
new Date(Date.now() + 2 * 60 * 1e3)
|
|
31493
31553
|
);
|
|
31494
31554
|
try {
|
|
@@ -31548,18 +31608,18 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31548
31608
|
const userLeaves = [];
|
|
31549
31609
|
userLeaves.push({
|
|
31550
31610
|
leaf_id: transfer.leaves[0].leaf.id,
|
|
31551
|
-
raw_unsigned_refund_transaction: (0,
|
|
31611
|
+
raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31552
31612
|
transfer.leaves[0].intermediateRefundTx
|
|
31553
31613
|
),
|
|
31554
|
-
direct_raw_unsigned_refund_transaction: (0,
|
|
31614
|
+
direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31555
31615
|
transfer.leaves[0].intermediateDirectRefundTx
|
|
31556
31616
|
),
|
|
31557
|
-
direct_from_cpfp_raw_unsigned_refund_transaction: (0,
|
|
31617
|
+
direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31558
31618
|
transfer.leaves[0].intermediateDirectFromCpfpRefundTx
|
|
31559
31619
|
),
|
|
31560
|
-
adaptor_added_signature: (0,
|
|
31561
|
-
direct_adaptor_added_signature: (0,
|
|
31562
|
-
direct_from_cpfp_adaptor_added_signature: (0,
|
|
31620
|
+
adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpAdaptorSignature),
|
|
31621
|
+
direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directAdaptorSignature),
|
|
31622
|
+
direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
|
|
31563
31623
|
directFromCpfpAdaptorSignature
|
|
31564
31624
|
)
|
|
31565
31625
|
});
|
|
@@ -31612,24 +31672,24 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31612
31672
|
}
|
|
31613
31673
|
userLeaves.push({
|
|
31614
31674
|
leaf_id: leaf.leaf.id,
|
|
31615
|
-
raw_unsigned_refund_transaction: (0,
|
|
31675
|
+
raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31616
31676
|
leaf.intermediateRefundTx
|
|
31617
31677
|
),
|
|
31618
|
-
direct_raw_unsigned_refund_transaction: (0,
|
|
31678
|
+
direct_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31619
31679
|
leaf.intermediateDirectRefundTx
|
|
31620
31680
|
),
|
|
31621
|
-
direct_from_cpfp_raw_unsigned_refund_transaction: (0,
|
|
31681
|
+
direct_from_cpfp_raw_unsigned_refund_transaction: (0, import_utils24.bytesToHex)(
|
|
31622
31682
|
leaf.intermediateDirectFromCpfpRefundTx
|
|
31623
31683
|
),
|
|
31624
|
-
adaptor_added_signature: (0,
|
|
31625
|
-
direct_adaptor_added_signature: (0,
|
|
31626
|
-
direct_from_cpfp_adaptor_added_signature: (0,
|
|
31684
|
+
adaptor_added_signature: (0, import_utils24.bytesToHex)(cpfpSignature),
|
|
31685
|
+
direct_adaptor_added_signature: (0, import_utils24.bytesToHex)(directSignature),
|
|
31686
|
+
direct_from_cpfp_adaptor_added_signature: (0, import_utils24.bytesToHex)(
|
|
31627
31687
|
directFromCpfpSignature
|
|
31628
31688
|
)
|
|
31629
31689
|
});
|
|
31630
31690
|
}
|
|
31631
31691
|
const sspClient = this.getSspClient();
|
|
31632
|
-
const cpfpAdaptorPubkey = (0,
|
|
31692
|
+
const cpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
|
|
31633
31693
|
import_secp256k115.secp256k1.getPublicKey(cpfpAdaptorPrivateKey)
|
|
31634
31694
|
);
|
|
31635
31695
|
if (!cpfpAdaptorPubkey) {
|
|
@@ -31637,13 +31697,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31637
31697
|
}
|
|
31638
31698
|
let directAdaptorPubkey;
|
|
31639
31699
|
if (directAdaptorPrivateKey.length > 0) {
|
|
31640
|
-
directAdaptorPubkey = (0,
|
|
31700
|
+
directAdaptorPubkey = (0, import_utils24.bytesToHex)(
|
|
31641
31701
|
import_secp256k115.secp256k1.getPublicKey(directAdaptorPrivateKey)
|
|
31642
31702
|
);
|
|
31643
31703
|
}
|
|
31644
31704
|
let directFromCpfpAdaptorPubkey;
|
|
31645
31705
|
if (directFromCpfpAdaptorPrivateKey.length > 0) {
|
|
31646
|
-
directFromCpfpAdaptorPubkey = (0,
|
|
31706
|
+
directFromCpfpAdaptorPubkey = (0, import_utils24.bytesToHex)(
|
|
31647
31707
|
import_secp256k115.secp256k1.getPublicKey(directFromCpfpAdaptorPrivateKey)
|
|
31648
31708
|
);
|
|
31649
31709
|
}
|
|
@@ -31703,7 +31763,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31703
31763
|
throw new Error(`Leaf not found for node ${nodeId}`);
|
|
31704
31764
|
}
|
|
31705
31765
|
const cpfpNodeTx = getTxFromRawTxBytes(node.nodeTx);
|
|
31706
|
-
const cpfpRefundTxBytes = (0,
|
|
31766
|
+
const cpfpRefundTxBytes = (0, import_utils24.hexToBytes)(leaf.rawUnsignedRefundTransaction);
|
|
31707
31767
|
const cpfpRefundTx = getTxFromRawTxBytes(cpfpRefundTxBytes);
|
|
31708
31768
|
const cpfpSighash = getSigHashFromTx(
|
|
31709
31769
|
cpfpRefundTx,
|
|
@@ -31712,7 +31772,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31712
31772
|
);
|
|
31713
31773
|
const nodePublicKey = node.verifyingPublicKey;
|
|
31714
31774
|
const taprootKey = computeTaprootKeyNoScript(nodePublicKey.slice(1));
|
|
31715
|
-
const cpfpAdaptorSignatureBytes = (0,
|
|
31775
|
+
const cpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
|
|
31716
31776
|
leaf.adaptorSignedSignature
|
|
31717
31777
|
);
|
|
31718
31778
|
applyAdaptorToSignature(
|
|
@@ -31723,7 +31783,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31723
31783
|
);
|
|
31724
31784
|
if (leaf.directRawUnsignedRefundTransaction) {
|
|
31725
31785
|
const directNodeTx = getTxFromRawTxBytes(node.directTx);
|
|
31726
|
-
const directRefundTxBytes = (0,
|
|
31786
|
+
const directRefundTxBytes = (0, import_utils24.hexToBytes)(
|
|
31727
31787
|
leaf.directRawUnsignedRefundTransaction
|
|
31728
31788
|
);
|
|
31729
31789
|
const directRefundTx = getTxFromRawTxBytes(directRefundTxBytes);
|
|
@@ -31737,7 +31797,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31737
31797
|
`Direct adaptor signed signature missing for node ${nodeId}`
|
|
31738
31798
|
);
|
|
31739
31799
|
}
|
|
31740
|
-
const directAdaptorSignatureBytes = (0,
|
|
31800
|
+
const directAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
|
|
31741
31801
|
leaf.directAdaptorSignedSignature
|
|
31742
31802
|
);
|
|
31743
31803
|
applyAdaptorToSignature(
|
|
@@ -31748,7 +31808,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31748
31808
|
);
|
|
31749
31809
|
}
|
|
31750
31810
|
if (leaf.directFromCpfpRawUnsignedRefundTransaction) {
|
|
31751
|
-
const directFromCpfpRefundTxBytes = (0,
|
|
31811
|
+
const directFromCpfpRefundTxBytes = (0, import_utils24.hexToBytes)(
|
|
31752
31812
|
leaf.directFromCpfpRawUnsignedRefundTransaction
|
|
31753
31813
|
);
|
|
31754
31814
|
const directFromCpfpRefundTx = getTxFromRawTxBytes(
|
|
@@ -31764,7 +31824,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31764
31824
|
`Direct adaptor signed signature missing for node ${nodeId}`
|
|
31765
31825
|
);
|
|
31766
31826
|
}
|
|
31767
|
-
const directFromCpfpAdaptorSignatureBytes = (0,
|
|
31827
|
+
const directFromCpfpAdaptorSignatureBytes = (0, import_utils24.hexToBytes)(
|
|
31768
31828
|
leaf.directFromCpfpAdaptorSignedSignature
|
|
31769
31829
|
);
|
|
31770
31830
|
applyAdaptorToSignature(
|
|
@@ -31783,9 +31843,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31783
31843
|
directFromCpfpSignatureMap
|
|
31784
31844
|
);
|
|
31785
31845
|
const completeResponse = await sspClient.completeLeaveSwap({
|
|
31786
|
-
adaptorSecretKey: (0,
|
|
31787
|
-
directAdaptorSecretKey: (0,
|
|
31788
|
-
directFromCpfpAdaptorSecretKey: (0,
|
|
31846
|
+
adaptorSecretKey: (0, import_utils24.bytesToHex)(cpfpAdaptorPrivateKey),
|
|
31847
|
+
directAdaptorSecretKey: (0, import_utils24.bytesToHex)(directAdaptorPrivateKey),
|
|
31848
|
+
directFromCpfpAdaptorSecretKey: (0, import_utils24.bytesToHex)(
|
|
31789
31849
|
directFromCpfpAdaptorPrivateKey
|
|
31790
31850
|
),
|
|
31791
31851
|
userOutboundTransferExternalId: transfer.id,
|
|
@@ -31880,12 +31940,12 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
31880
31940
|
let tokenMetadataMap = /* @__PURE__ */ new Map();
|
|
31881
31941
|
for (const [tokenIdentifier, metadata] of this.tokenMetadata) {
|
|
31882
31942
|
tokenMetadataMap.set(tokenIdentifier, {
|
|
31883
|
-
tokenPublicKey: (0,
|
|
31943
|
+
tokenPublicKey: (0, import_utils24.bytesToHex)(metadata.issuerPublicKey),
|
|
31884
31944
|
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
31885
31945
|
tokenName: metadata.tokenName,
|
|
31886
31946
|
tokenTicker: metadata.tokenTicker,
|
|
31887
31947
|
decimals: metadata.decimals,
|
|
31888
|
-
maxSupply: (0,
|
|
31948
|
+
maxSupply: (0, import_utils24.bytesToNumberBE)(metadata.maxSupply)
|
|
31889
31949
|
});
|
|
31890
31950
|
}
|
|
31891
31951
|
return tokenMetadataMap;
|
|
@@ -32009,7 +32069,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32009
32069
|
offset
|
|
32010
32070
|
});
|
|
32011
32071
|
return response.utxos.map((utxo) => ({
|
|
32012
|
-
txid: (0,
|
|
32072
|
+
txid: (0, import_utils24.bytesToHex)(utxo.txid),
|
|
32013
32073
|
vout: utxo.vout
|
|
32014
32074
|
})) ?? [];
|
|
32015
32075
|
} catch (error) {
|
|
@@ -32079,7 +32139,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32079
32139
|
if (network === BitcoinNetwork_default.FUTURE_VALUE) {
|
|
32080
32140
|
network = BitcoinNetwork_default.REGTEST;
|
|
32081
32141
|
}
|
|
32082
|
-
const depositSecretKey = (0,
|
|
32142
|
+
const depositSecretKey = (0, import_utils24.bytesToHex)(
|
|
32083
32143
|
await this.config.signer.getStaticDepositSecretKey(0)
|
|
32084
32144
|
);
|
|
32085
32145
|
const message = await this.getStaticDepositSigningPayload(
|
|
@@ -32092,7 +32152,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32092
32152
|
);
|
|
32093
32153
|
const hashBuffer = (0, import_sha212.sha256)(message);
|
|
32094
32154
|
const signatureBytes = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
|
|
32095
|
-
const signature = (0,
|
|
32155
|
+
const signature = (0, import_utils24.bytesToHex)(signatureBytes);
|
|
32096
32156
|
const response = await this.sspClient.claimStaticDeposit({
|
|
32097
32157
|
transactionId,
|
|
32098
32158
|
outputIndex,
|
|
@@ -32244,7 +32304,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32244
32304
|
networkJSON.toLowerCase(),
|
|
32245
32305
|
2 /* Refund */,
|
|
32246
32306
|
creditAmountSats,
|
|
32247
|
-
(0,
|
|
32307
|
+
(0, import_utils24.bytesToHex)(spendTxSighash)
|
|
32248
32308
|
);
|
|
32249
32309
|
const hashBuffer = (0, import_sha212.sha256)(message);
|
|
32250
32310
|
const swapResponseUserSignature = await this.config.signer.signMessageWithIdentityKey(hashBuffer);
|
|
@@ -32253,7 +32313,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32253
32313
|
);
|
|
32254
32314
|
const swapResponse = await sparkClient.initiate_static_deposit_utxo_refund({
|
|
32255
32315
|
onChainUtxo: {
|
|
32256
|
-
txid: (0,
|
|
32316
|
+
txid: (0, import_utils24.hexToBytes)(depositTransactionId),
|
|
32257
32317
|
vout: outputIndex,
|
|
32258
32318
|
network: networkType
|
|
32259
32319
|
},
|
|
@@ -32322,7 +32382,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32322
32382
|
creditAmountView.setUint32(0, lowerHalf, true);
|
|
32323
32383
|
creditAmountView.setUint32(4, upperHalf, true);
|
|
32324
32384
|
parts.push(new Uint8Array(creditAmountBuffer));
|
|
32325
|
-
parts.push((0,
|
|
32385
|
+
parts.push((0, import_utils24.hexToBytes)(sspSignature));
|
|
32326
32386
|
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
32327
32387
|
const payload = new Uint8Array(totalLength);
|
|
32328
32388
|
let offset = 0;
|
|
@@ -32727,9 +32787,9 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32727
32787
|
});
|
|
32728
32788
|
}
|
|
32729
32789
|
const signerIdentityPublicKey = await this.config.signer.getIdentityPublicKey();
|
|
32730
|
-
const isSelfTransfer = (0,
|
|
32790
|
+
const isSelfTransfer = (0, import_utils24.equalBytes)(
|
|
32731
32791
|
signerIdentityPublicKey,
|
|
32732
|
-
(0,
|
|
32792
|
+
(0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
|
|
32733
32793
|
);
|
|
32734
32794
|
return await this.withLeaves(async () => {
|
|
32735
32795
|
let leavesToSend = (await this.selectLeaves([amountSats])).get(
|
|
@@ -32751,7 +32811,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32751
32811
|
);
|
|
32752
32812
|
const transfer = await this.transferService.sendTransferWithKeyTweaks(
|
|
32753
32813
|
leafKeyTweaks,
|
|
32754
|
-
(0,
|
|
32814
|
+
(0, import_utils24.hexToBytes)(receiverAddress.identityPublicKey)
|
|
32755
32815
|
);
|
|
32756
32816
|
const leavesToRemove = new Set(leavesToSend.map((leaf) => leaf.id));
|
|
32757
32817
|
this.leaves = this.leaves.filter((leaf) => !leavesToRemove.has(leaf.id));
|
|
@@ -32767,7 +32827,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
32767
32827
|
}
|
|
32768
32828
|
return mapTransferToWalletTransfer(
|
|
32769
32829
|
transfer,
|
|
32770
|
-
(0,
|
|
32830
|
+
(0, import_utils24.bytesToHex)(await this.config.signer.getIdentityPublicKey())
|
|
32771
32831
|
);
|
|
32772
32832
|
});
|
|
32773
32833
|
}
|
|
@@ -33123,7 +33183,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33123
33183
|
const invoice2 = await sspClient.requestLightningReceive({
|
|
33124
33184
|
amountSats: amountSats2,
|
|
33125
33185
|
network: bitcoinNetwork,
|
|
33126
|
-
paymentHash: (0,
|
|
33186
|
+
paymentHash: (0, import_utils24.bytesToHex)(paymentHash),
|
|
33127
33187
|
expirySecs: expirySeconds,
|
|
33128
33188
|
memo: memo2,
|
|
33129
33189
|
includeSparkAddress,
|
|
@@ -33232,7 +33292,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33232
33292
|
const sparkFallbackAddress = decodedInvoice.fallbackAddress;
|
|
33233
33293
|
const paymentHash = decodedInvoice.paymentHash;
|
|
33234
33294
|
if (preferSpark) {
|
|
33235
|
-
if (sparkFallbackAddress === void 0 || isValidSparkFallback((0,
|
|
33295
|
+
if (sparkFallbackAddress === void 0 || isValidSparkFallback((0, import_utils24.hexToBytes)(sparkFallbackAddress)) === false) {
|
|
33236
33296
|
console.warn(
|
|
33237
33297
|
"No valid spark address found in invoice. Defaulting to lightning."
|
|
33238
33298
|
);
|
|
@@ -33286,10 +33346,10 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33286
33346
|
);
|
|
33287
33347
|
const swapResponse = await this.lightningService.swapNodesForPreimage({
|
|
33288
33348
|
leaves: leavesToSend,
|
|
33289
|
-
receiverIdentityPubkey: (0,
|
|
33349
|
+
receiverIdentityPubkey: (0, import_utils24.hexToBytes)(
|
|
33290
33350
|
this.config.getSspIdentityPublicKey()
|
|
33291
33351
|
),
|
|
33292
|
-
paymentHash: (0,
|
|
33352
|
+
paymentHash: (0, import_utils24.hexToBytes)(paymentHash),
|
|
33293
33353
|
isInboundPayment: false,
|
|
33294
33354
|
invoiceString: invoice,
|
|
33295
33355
|
feeSats: feeEstimate,
|
|
@@ -33407,7 +33467,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33407
33467
|
});
|
|
33408
33468
|
await this.syncTokenOutputs();
|
|
33409
33469
|
const bech32mTokenIdentifier = encodeBech32mTokenIdentifier({
|
|
33410
|
-
tokenIdentifier: (0,
|
|
33470
|
+
tokenIdentifier: (0, import_utils24.hexToBytes)(firstTokenIdentifierHexSeen),
|
|
33411
33471
|
network: this.config.getNetworkType()
|
|
33412
33472
|
});
|
|
33413
33473
|
const receiverOutputs = decoded.map((d) => ({
|
|
@@ -33438,7 +33498,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33438
33498
|
if (!feeEstimate) {
|
|
33439
33499
|
throw new Error("Failed to get lightning send fee estimate");
|
|
33440
33500
|
}
|
|
33441
|
-
const satsFeeEstimate = (0,
|
|
33501
|
+
const satsFeeEstimate = (0, import_core13.mapCurrencyAmount)(feeEstimate.feeEstimate);
|
|
33442
33502
|
return Math.ceil(satsFeeEstimate.sats);
|
|
33443
33503
|
}
|
|
33444
33504
|
// ***** Cooperative Exit Flow *****
|
|
@@ -33595,11 +33655,11 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33595
33655
|
const connectorOutputs = [];
|
|
33596
33656
|
for (let i = 0; i < connectorTx.outputsLength - 1; i++) {
|
|
33597
33657
|
connectorOutputs.push({
|
|
33598
|
-
txid: (0,
|
|
33658
|
+
txid: (0, import_utils24.hexToBytes)(connectorTxId),
|
|
33599
33659
|
index: i
|
|
33600
33660
|
});
|
|
33601
33661
|
}
|
|
33602
|
-
const sspPubIdentityKey = (0,
|
|
33662
|
+
const sspPubIdentityKey = (0, import_utils24.hexToBytes)(this.config.getSspIdentityPublicKey());
|
|
33603
33663
|
const transfer = await this.coopExitService.getConnectorRefundSignatures({
|
|
33604
33664
|
leaves: leafKeyTweaks,
|
|
33605
33665
|
exitTxId: coopExitTxId,
|
|
@@ -33653,7 +33713,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33653
33713
|
return transfers?.[0];
|
|
33654
33714
|
}
|
|
33655
33715
|
async constructTransfersWithUserRequest(transfers) {
|
|
33656
|
-
const identityPublicKey = (0,
|
|
33716
|
+
const identityPublicKey = (0, import_utils24.bytesToHex)(
|
|
33657
33717
|
await this.config.signer.getIdentityPublicKey()
|
|
33658
33718
|
);
|
|
33659
33719
|
const userRequests = await this.sspClient?.getTransfers(
|
|
@@ -33897,7 +33957,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33897
33957
|
hash,
|
|
33898
33958
|
compact
|
|
33899
33959
|
);
|
|
33900
|
-
return (0,
|
|
33960
|
+
return (0, import_utils24.bytesToHex)(signature);
|
|
33901
33961
|
}
|
|
33902
33962
|
/**
|
|
33903
33963
|
* Validates a message with the identity key.
|
|
@@ -33909,7 +33969,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33909
33969
|
async validateMessageWithIdentityKey(message, signature) {
|
|
33910
33970
|
const hash = (0, import_sha212.sha256)(message);
|
|
33911
33971
|
if (typeof signature === "string") {
|
|
33912
|
-
signature = (0,
|
|
33972
|
+
signature = (0, import_utils24.hexToBytes)(signature);
|
|
33913
33973
|
}
|
|
33914
33974
|
return this.config.signer.validateMessageWithIdentityKey(hash, signature);
|
|
33915
33975
|
}
|
|
@@ -33922,7 +33982,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33922
33982
|
*/
|
|
33923
33983
|
async signTransaction(txHex, keyType = "auto-detect") {
|
|
33924
33984
|
try {
|
|
33925
|
-
const tx = import_btc_signer6.Transaction.fromRaw((0,
|
|
33985
|
+
const tx = import_btc_signer6.Transaction.fromRaw((0, import_utils24.hexToBytes)(txHex));
|
|
33926
33986
|
let publicKey;
|
|
33927
33987
|
switch (keyType.toLowerCase()) {
|
|
33928
33988
|
case "identity":
|
|
@@ -33955,7 +34015,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33955
34015
|
publicKey,
|
|
33956
34016
|
this.config.getNetwork()
|
|
33957
34017
|
);
|
|
33958
|
-
if ((0,
|
|
34018
|
+
if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
|
|
33959
34019
|
try {
|
|
33960
34020
|
this.config.signer.signTransactionIndex(tx, i, publicKey);
|
|
33961
34021
|
inputsSigned++;
|
|
@@ -33999,13 +34059,13 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
33999
34059
|
depositPubKey,
|
|
34000
34060
|
this.config.getNetwork()
|
|
34001
34061
|
);
|
|
34002
|
-
if ((0,
|
|
34062
|
+
if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(identityScript)) {
|
|
34003
34063
|
return {
|
|
34004
34064
|
publicKey: identityPubKey,
|
|
34005
34065
|
keyType: "identity"
|
|
34006
34066
|
};
|
|
34007
34067
|
}
|
|
34008
|
-
if ((0,
|
|
34068
|
+
if ((0, import_utils24.bytesToHex)(script) === (0, import_utils24.bytesToHex)(depositScript)) {
|
|
34009
34069
|
return {
|
|
34010
34070
|
publicKey: depositPubKey,
|
|
34011
34071
|
keyType: "deposit"
|
|
@@ -34348,7 +34408,7 @@ var SparkWallet = class _SparkWallet extends import_eventemitter3.EventEmitter {
|
|
|
34348
34408
|
} catch (error) {
|
|
34349
34409
|
if (error instanceof Error) {
|
|
34350
34410
|
error.message += ` [traceId: ${traceId}]`;
|
|
34351
|
-
} else if ((0,
|
|
34411
|
+
} else if ((0, import_core13.isObject)(error)) {
|
|
34352
34412
|
error["traceId"] = traceId;
|
|
34353
34413
|
}
|
|
34354
34414
|
throw error;
|
|
@@ -34424,9 +34484,11 @@ __export(utils_exports, {
|
|
|
34424
34484
|
DIRECT_TIMELOCK_OFFSET: () => DIRECT_TIMELOCK_OFFSET,
|
|
34425
34485
|
INITIAL_DIRECT_SEQUENCE: () => INITIAL_DIRECT_SEQUENCE,
|
|
34426
34486
|
INITIAL_SEQUENCE: () => INITIAL_SEQUENCE,
|
|
34487
|
+
LOGGER_NAMES: () => LOGGER_NAMES,
|
|
34427
34488
|
LRC_WALLET_NETWORK: () => LRC_WALLET_NETWORK,
|
|
34428
34489
|
Network: () => Network2,
|
|
34429
34490
|
NetworkToProto: () => NetworkToProto,
|
|
34491
|
+
SparkSdkLogger: () => SparkSdkLogger,
|
|
34430
34492
|
TEST_UNILATERAL_DIRECT_SEQUENCE: () => TEST_UNILATERAL_DIRECT_SEQUENCE,
|
|
34431
34493
|
TEST_UNILATERAL_SEQUENCE: () => TEST_UNILATERAL_SEQUENCE,
|
|
34432
34494
|
addPrivateKeys: () => addPrivateKeys,
|
|
@@ -34573,7 +34635,7 @@ async function isTxBroadcast(txid, baseUrl, network) {
|
|
|
34573
34635
|
|
|
34574
34636
|
// src/utils/unilateral-exit.ts
|
|
34575
34637
|
init_buffer();
|
|
34576
|
-
var
|
|
34638
|
+
var import_utils25 = require("@noble/curves/abstract/utils");
|
|
34577
34639
|
var import_legacy = require("@noble/hashes/legacy");
|
|
34578
34640
|
var import_sha213 = require("@noble/hashes/sha2");
|
|
34579
34641
|
var btc4 = __toESM(require("@scure/btc-signer"), 1);
|
|
@@ -34588,7 +34650,7 @@ function isEphemeralAnchorOutput(script, amount) {
|
|
|
34588
34650
|
}
|
|
34589
34651
|
async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network) {
|
|
34590
34652
|
const result = [];
|
|
34591
|
-
const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0,
|
|
34653
|
+
const nodes = nodeHexStrings.map((hex) => TreeNode.decode((0, import_utils25.hexToBytes)(hex)));
|
|
34592
34654
|
const nodeMap = /* @__PURE__ */ new Map();
|
|
34593
34655
|
for (const node of nodes) {
|
|
34594
34656
|
nodeMap.set(node.id, node);
|
|
@@ -34644,10 +34706,10 @@ async function constructUnilateralExitTxs(nodeHexStrings, sparkClient, network)
|
|
|
34644
34706
|
}
|
|
34645
34707
|
}
|
|
34646
34708
|
for (const chainNode of chain) {
|
|
34647
|
-
const nodeTx = (0,
|
|
34709
|
+
const nodeTx = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
|
|
34648
34710
|
transactions.push(nodeTx);
|
|
34649
34711
|
if (chainNode.id === node.id) {
|
|
34650
|
-
const refundTx = (0,
|
|
34712
|
+
const refundTx = (0, import_utils25.bytesToHex)(chainNode.refundTx);
|
|
34651
34713
|
transactions.push(refundTx);
|
|
34652
34714
|
}
|
|
34653
34715
|
}
|
|
@@ -34677,7 +34739,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34677
34739
|
`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.`
|
|
34678
34740
|
);
|
|
34679
34741
|
}
|
|
34680
|
-
const nodeBytes = (0,
|
|
34742
|
+
const nodeBytes = (0, import_utils25.hexToBytes)(hex);
|
|
34681
34743
|
const node = TreeNode.decode(nodeBytes);
|
|
34682
34744
|
if (!node.id) {
|
|
34683
34745
|
throw new Error(
|
|
@@ -34753,7 +34815,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34753
34815
|
}
|
|
34754
34816
|
}
|
|
34755
34817
|
for (const chainNode of chain) {
|
|
34756
|
-
let nodeTxHex = (0,
|
|
34818
|
+
let nodeTxHex = (0, import_utils25.bytesToHex)(chainNode.nodeTx);
|
|
34757
34819
|
try {
|
|
34758
34820
|
const txObj = getTxFromRawTxHex(nodeTxHex);
|
|
34759
34821
|
const txid = getTxId(txObj);
|
|
@@ -34770,7 +34832,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34770
34832
|
for (let i = txObj.outputsLength - 1; i >= 0; i--) {
|
|
34771
34833
|
const output = txObj.getOutput(i);
|
|
34772
34834
|
if (output?.amount === 0n && output.script) {
|
|
34773
|
-
anchorOutputScriptHex = (0,
|
|
34835
|
+
anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
|
|
34774
34836
|
break;
|
|
34775
34837
|
}
|
|
34776
34838
|
}
|
|
@@ -34791,11 +34853,11 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34791
34853
|
usedUtxos,
|
|
34792
34854
|
correctedParentTx
|
|
34793
34855
|
} = constructFeeBumpTx(nodeTxHex, availableUtxos, feeRate, void 0);
|
|
34794
|
-
const feeBumpTx = btc4.Transaction.fromPSBT((0,
|
|
34856
|
+
const feeBumpTx = btc4.Transaction.fromPSBT((0, import_utils25.hexToBytes)(nodeFeeBumpPsbt));
|
|
34795
34857
|
var feeBumpOut = feeBumpTx.outputsLength === 1 ? feeBumpTx.getOutput(0) : null;
|
|
34796
34858
|
var feeBumpOutPubKey = null;
|
|
34797
34859
|
for (const usedUtxo of usedUtxos) {
|
|
34798
|
-
if (feeBumpOut && (0,
|
|
34860
|
+
if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
|
|
34799
34861
|
feeBumpOutPubKey = usedUtxo.publicKey;
|
|
34800
34862
|
}
|
|
34801
34863
|
const index = availableUtxos.findIndex(
|
|
@@ -34810,20 +34872,20 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34810
34872
|
txid: getTxId(feeBumpTx),
|
|
34811
34873
|
vout: 0,
|
|
34812
34874
|
value: feeBumpOut.amount,
|
|
34813
|
-
script: (0,
|
|
34875
|
+
script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
|
|
34814
34876
|
publicKey: feeBumpOutPubKey
|
|
34815
34877
|
});
|
|
34816
34878
|
const finalNodeTx = correctedParentTx || nodeTxHex;
|
|
34817
34879
|
txPackages.push({ tx: finalNodeTx, feeBumpPsbt: nodeFeeBumpPsbt });
|
|
34818
34880
|
if (chainNode.id === node.id) {
|
|
34819
|
-
let refundTxHex = (0,
|
|
34881
|
+
let refundTxHex = (0, import_utils25.bytesToHex)(chainNode.refundTx);
|
|
34820
34882
|
try {
|
|
34821
34883
|
const txObj = getTxFromRawTxHex(refundTxHex);
|
|
34822
34884
|
let anchorOutputScriptHex;
|
|
34823
34885
|
for (let i = txObj.outputsLength - 1; i >= 0; i--) {
|
|
34824
34886
|
const output = txObj.getOutput(i);
|
|
34825
34887
|
if (output?.amount === 0n && output.script) {
|
|
34826
|
-
anchorOutputScriptHex = (0,
|
|
34888
|
+
anchorOutputScriptHex = (0, import_utils25.bytesToHex)(output.script);
|
|
34827
34889
|
break;
|
|
34828
34890
|
}
|
|
34829
34891
|
}
|
|
@@ -34846,12 +34908,12 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34846
34908
|
void 0
|
|
34847
34909
|
);
|
|
34848
34910
|
const feeBumpTx2 = btc4.Transaction.fromPSBT(
|
|
34849
|
-
(0,
|
|
34911
|
+
(0, import_utils25.hexToBytes)(refundFeeBump.feeBumpPsbt)
|
|
34850
34912
|
);
|
|
34851
34913
|
var feeBumpOut = feeBumpTx2.outputsLength === 1 ? feeBumpTx2.getOutput(0) : null;
|
|
34852
34914
|
var feeBumpOutPubKey = null;
|
|
34853
34915
|
for (const usedUtxo of usedUtxos) {
|
|
34854
|
-
if (feeBumpOut && (0,
|
|
34916
|
+
if (feeBumpOut && (0, import_utils25.bytesToHex)(feeBumpOut.script) == usedUtxo.script) {
|
|
34855
34917
|
feeBumpOutPubKey = usedUtxo.publicKey;
|
|
34856
34918
|
}
|
|
34857
34919
|
const index = availableUtxos.findIndex(
|
|
@@ -34866,7 +34928,7 @@ async function constructUnilateralExitFeeBumpPackages(nodeHexStrings, utxos, fee
|
|
|
34866
34928
|
txid: getTxId(feeBumpTx2),
|
|
34867
34929
|
vout: 0,
|
|
34868
34930
|
value: feeBumpOut.amount,
|
|
34869
|
-
script: (0,
|
|
34931
|
+
script: (0, import_utils25.bytesToHex)(feeBumpOut.script),
|
|
34870
34932
|
publicKey: feeBumpOutPubKey
|
|
34871
34933
|
});
|
|
34872
34934
|
txPackages.push({
|
|
@@ -34961,10 +35023,10 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
|
|
|
34961
35023
|
if (!fundingUtxo) {
|
|
34962
35024
|
throw new Error(`UTXO at index ${i} is undefined`);
|
|
34963
35025
|
}
|
|
34964
|
-
const pubKeyHash = hash160((0,
|
|
35026
|
+
const pubKeyHash = hash160((0, import_utils25.hexToBytes)(fundingUtxo.publicKey));
|
|
34965
35027
|
const scriptToUse = new Uint8Array([0, 20, ...pubKeyHash]);
|
|
34966
|
-
const providedScript = (0,
|
|
34967
|
-
if ((0,
|
|
35028
|
+
const providedScript = (0, import_utils25.hexToBytes)(fundingUtxo.script);
|
|
35029
|
+
if ((0, import_utils25.bytesToHex)(scriptToUse) !== (0, import_utils25.bytesToHex)(providedScript)) {
|
|
34968
35030
|
throw new Error(
|
|
34969
35031
|
`\u274C Derived script doesn't match provided script for UTXO ${i + 1}.`
|
|
34970
35032
|
);
|
|
@@ -35029,7 +35091,7 @@ function constructFeeBumpTx(txHex, utxos, feeRate, previousFeeBumpTx) {
|
|
|
35029
35091
|
}
|
|
35030
35092
|
let psbtHex;
|
|
35031
35093
|
try {
|
|
35032
|
-
psbtHex = (0,
|
|
35094
|
+
psbtHex = (0, import_utils25.bytesToHex)(builder.toPSBT());
|
|
35033
35095
|
} catch (error) {
|
|
35034
35096
|
throw new Error(`Failed to extract transaction: ${error}`);
|
|
35035
35097
|
}
|
|
@@ -35071,6 +35133,9 @@ function getSparkAddressFromTaproot(taprootAddress) {
|
|
|
35071
35133
|
throw new ValidationError("Invalid taproot address");
|
|
35072
35134
|
}
|
|
35073
35135
|
|
|
35136
|
+
// src/utils/index.ts
|
|
35137
|
+
init_logging();
|
|
35138
|
+
|
|
35074
35139
|
// src/debug.ts
|
|
35075
35140
|
var s = {
|
|
35076
35141
|
SparkWallet,
|