@dynamic-labs-wallet/btc-utils 0.0.0-pr658.0 → 0.0.255
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/index.cjs.js +51 -19
- package/index.esm.js +51 -20
- package/package.json +2 -2
- package/src/extractPublicKeyHex/extractPublicKeyHex.d.ts +10 -0
- package/src/extractPublicKeyHex/extractPublicKeyHex.d.ts.map +1 -0
- package/src/extractPublicKeyHex/index.d.ts +2 -0
- package/src/extractPublicKeyHex/index.d.ts.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -173,14 +173,14 @@ var currentEcc = null;
|
|
|
173
173
|
|
|
174
174
|
// Type for ECDSA public key (matches EcdsaPublicKey from lib-mpc-core)
|
|
175
175
|
// This is defined locally since btc-utils is environment-agnostic
|
|
176
|
-
function _instanceof$
|
|
176
|
+
function _instanceof$8(left, right) {
|
|
177
177
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
178
178
|
return !!right[Symbol.hasInstance](left);
|
|
179
179
|
} else {
|
|
180
180
|
return left instanceof right;
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
function _type_of(obj) {
|
|
183
|
+
function _type_of$1(obj) {
|
|
184
184
|
"@swc/helpers - typeof";
|
|
185
185
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
186
186
|
}
|
|
@@ -195,7 +195,7 @@ function _type_of(obj) {
|
|
|
195
195
|
if (Buffer.isBuffer(actualPubkey)) {
|
|
196
196
|
return actualPubkey;
|
|
197
197
|
}
|
|
198
|
-
if (_instanceof$
|
|
198
|
+
if (_instanceof$8(actualPubkey, Uint8Array)) {
|
|
199
199
|
return Buffer.from(actualPubkey);
|
|
200
200
|
}
|
|
201
201
|
if (typeof actualPubkey === 'string') {
|
|
@@ -205,7 +205,7 @@ function _type_of(obj) {
|
|
|
205
205
|
}
|
|
206
206
|
return result;
|
|
207
207
|
}
|
|
208
|
-
if ((typeof actualPubkey === "undefined" ? "undefined" : _type_of(actualPubkey)) === 'object' && actualPubkey !== null) {
|
|
208
|
+
if ((typeof actualPubkey === "undefined" ? "undefined" : _type_of$1(actualPubkey)) === 'object' && actualPubkey !== null) {
|
|
209
209
|
return convertObjectToBuffer(actualPubkey);
|
|
210
210
|
}
|
|
211
211
|
throw new Error('Invalid public key format');
|
|
@@ -340,7 +340,7 @@ var convertObjectToBuffer = function(actualPubkey) {
|
|
|
340
340
|
};
|
|
341
341
|
};
|
|
342
342
|
|
|
343
|
-
function _instanceof$
|
|
343
|
+
function _instanceof$7(left, right) {
|
|
344
344
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
345
345
|
return !!right[Symbol.hasInstance](left);
|
|
346
346
|
} else {
|
|
@@ -359,7 +359,7 @@ function _instanceof$6(left, right) {
|
|
|
359
359
|
var normalizedKey = normalizePublicKey(pubKey, addressType);
|
|
360
360
|
if (addressType === core.BitcoinAddressType.TAPROOT) {
|
|
361
361
|
var sigBuffer;
|
|
362
|
-
if (_instanceof$
|
|
362
|
+
if (_instanceof$7(signature, Uint8Array) || Buffer.isBuffer(signature)) {
|
|
363
363
|
sigBuffer = Buffer.from(signature);
|
|
364
364
|
} else {
|
|
365
365
|
var r = signature.r;
|
|
@@ -393,7 +393,7 @@ function _instanceof$6(left, right) {
|
|
|
393
393
|
return bip322Js.BIP322.encodeWitness(toSignPsbt);
|
|
394
394
|
};
|
|
395
395
|
|
|
396
|
-
function _instanceof$
|
|
396
|
+
function _instanceof$6(left, right) {
|
|
397
397
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
398
398
|
return !!right[Symbol.hasInstance](left);
|
|
399
399
|
} else {
|
|
@@ -458,11 +458,11 @@ function _instanceof$5(left, right) {
|
|
|
458
458
|
return wif;
|
|
459
459
|
} catch (error) {
|
|
460
460
|
// Re-throw with more context
|
|
461
|
-
throw new Error("Failed to convert private key to WIF: ".concat(_instanceof$
|
|
461
|
+
throw new Error("Failed to convert private key to WIF: ".concat(_instanceof$6(error, Error) ? error.message : String(error)));
|
|
462
462
|
}
|
|
463
463
|
};
|
|
464
464
|
|
|
465
|
-
function _instanceof$
|
|
465
|
+
function _instanceof$5(left, right) {
|
|
466
466
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
467
467
|
return !!right[Symbol.hasInstance](left);
|
|
468
468
|
} else {
|
|
@@ -520,7 +520,7 @@ function _instanceof$4(left, right) {
|
|
|
520
520
|
// 7. Convert to hex string
|
|
521
521
|
return Buffer.from(privateKeyBytes).toString('hex');
|
|
522
522
|
} catch (error) {
|
|
523
|
-
throw new Error("Invalid WIF format: ".concat(_instanceof$
|
|
523
|
+
throw new Error("Invalid WIF format: ".concat(_instanceof$5(error, Error) ? error.message : String(error), ". Only WIF format is supported."));
|
|
524
524
|
}
|
|
525
525
|
};
|
|
526
526
|
|
|
@@ -553,7 +553,7 @@ function _async_to_generator$2(fn) {
|
|
|
553
553
|
});
|
|
554
554
|
};
|
|
555
555
|
}
|
|
556
|
-
function _instanceof$
|
|
556
|
+
function _instanceof$4(left, right) {
|
|
557
557
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
558
558
|
return !!right[Symbol.hasInstance](left);
|
|
559
559
|
} else {
|
|
@@ -696,7 +696,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
696
696
|
];
|
|
697
697
|
}
|
|
698
698
|
} catch (error) {
|
|
699
|
-
throw new Error("Failed to derive public key from private key: ".concat(_instanceof$
|
|
699
|
+
throw new Error("Failed to derive public key from private key: ".concat(_instanceof$4(error, Error) ? error.message : String(error)));
|
|
700
700
|
}
|
|
701
701
|
return [
|
|
702
702
|
2
|
|
@@ -708,7 +708,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
708
708
|
};
|
|
709
709
|
}();
|
|
710
710
|
|
|
711
|
-
function _instanceof$
|
|
711
|
+
function _instanceof$3(left, right) {
|
|
712
712
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
713
713
|
return !!right[Symbol.hasInstance](left);
|
|
714
714
|
} else {
|
|
@@ -721,8 +721,8 @@ function _instanceof$2(left, right) {
|
|
|
721
721
|
* @param signature - The ECDSA signature
|
|
722
722
|
* @returns The DER encoded signature
|
|
723
723
|
*/ var convertSignatureToDER = function(signature) {
|
|
724
|
-
var r = _instanceof$
|
|
725
|
-
var s = _instanceof$
|
|
724
|
+
var r = _instanceof$3(signature.r, Uint8Array) ? signature.r : new Uint8Array(signature.r);
|
|
725
|
+
var s = _instanceof$3(signature.s, Uint8Array) ? signature.s : new Uint8Array(signature.s);
|
|
726
726
|
var r32 = new Uint8Array(32);
|
|
727
727
|
var rSource = r.length > 32 ? r.slice(-32) : r;
|
|
728
728
|
r32.set(rSource, 32 - rSource.length);
|
|
@@ -1192,7 +1192,7 @@ function _ts_generator(thisArg, body) {
|
|
|
1192
1192
|
return Buffer.from(tweakHash).toString('hex');
|
|
1193
1193
|
};
|
|
1194
1194
|
|
|
1195
|
-
function _instanceof$
|
|
1195
|
+
function _instanceof$2(left, right) {
|
|
1196
1196
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1197
1197
|
return !!right[Symbol.hasInstance](left);
|
|
1198
1198
|
} else {
|
|
@@ -1205,7 +1205,7 @@ function _instanceof$1(left, right) {
|
|
|
1205
1205
|
* @param signature - The signature from MPC (can be Uint8Array, Buffer, or EcdsaSignature object)
|
|
1206
1206
|
* @returns A Buffer containing the 64-byte Schnorr signature
|
|
1207
1207
|
*/ var convertSignatureToTaprootBuffer = function(signature) {
|
|
1208
|
-
if (_instanceof$
|
|
1208
|
+
if (_instanceof$2(signature, Uint8Array) || Buffer.isBuffer(signature)) {
|
|
1209
1209
|
return Buffer.from(signature);
|
|
1210
1210
|
}
|
|
1211
1211
|
var r = signature.r;
|
|
@@ -1240,7 +1240,7 @@ function _instanceof$1(left, right) {
|
|
|
1240
1240
|
};
|
|
1241
1241
|
};
|
|
1242
1242
|
|
|
1243
|
-
function _instanceof(left, right) {
|
|
1243
|
+
function _instanceof$1(left, right) {
|
|
1244
1244
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1245
1245
|
return !!right[Symbol.hasInstance](left);
|
|
1246
1246
|
} else {
|
|
@@ -1282,12 +1282,43 @@ function _instanceof(left, right) {
|
|
|
1282
1282
|
console.log('[doesInputBelongToAddress] Error checking input', {
|
|
1283
1283
|
address: address,
|
|
1284
1284
|
network: network,
|
|
1285
|
-
error: _instanceof(error, Error) ? error.message : String(error)
|
|
1285
|
+
error: _instanceof$1(error, Error) ? error.message : String(error)
|
|
1286
1286
|
});
|
|
1287
1287
|
return false;
|
|
1288
1288
|
}
|
|
1289
1289
|
};
|
|
1290
1290
|
|
|
1291
|
+
function _instanceof(left, right) {
|
|
1292
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1293
|
+
return !!right[Symbol.hasInstance](left);
|
|
1294
|
+
} else {
|
|
1295
|
+
return left instanceof right;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
function _type_of(obj) {
|
|
1299
|
+
"@swc/helpers - typeof";
|
|
1300
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Extracts the hex string representation of a public key from various formats.
|
|
1304
|
+
* Handles Uint8Array, objects with pubKeyAsHex method, and string formats.
|
|
1305
|
+
*
|
|
1306
|
+
* @param rawPublicKey - The raw public key in various formats
|
|
1307
|
+
* @returns The public key as a hex string
|
|
1308
|
+
* @throws Error if the public key format is invalid
|
|
1309
|
+
*/ var extractPublicKeyHex = function(rawPublicKey) {
|
|
1310
|
+
if (_instanceof(rawPublicKey, Uint8Array)) {
|
|
1311
|
+
return Buffer.from(rawPublicKey).toString('hex');
|
|
1312
|
+
}
|
|
1313
|
+
if (rawPublicKey && (typeof rawPublicKey === "undefined" ? "undefined" : _type_of(rawPublicKey)) === 'object' && 'pubKeyAsHex' in rawPublicKey && typeof rawPublicKey.pubKeyAsHex === 'function') {
|
|
1314
|
+
return rawPublicKey.pubKeyAsHex();
|
|
1315
|
+
}
|
|
1316
|
+
if (typeof rawPublicKey === 'string') {
|
|
1317
|
+
return rawPublicKey;
|
|
1318
|
+
}
|
|
1319
|
+
throw new Error('Invalid public key format');
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1291
1322
|
exports.calculateBip322Hash = calculateBip322Hash;
|
|
1292
1323
|
exports.calculateTaprootTweak = calculateTaprootTweak;
|
|
1293
1324
|
exports.collectPSBTInputData = collectPSBTInputData;
|
|
@@ -1295,6 +1326,7 @@ exports.convertSignatureToDER = convertSignatureToDER;
|
|
|
1295
1326
|
exports.convertSignatureToTaprootBuffer = convertSignatureToTaprootBuffer;
|
|
1296
1327
|
exports.doesInputBelongToAddress = doesInputBelongToAddress;
|
|
1297
1328
|
exports.encodeBip322Signature = encodeBip322Signature;
|
|
1329
|
+
exports.extractPublicKeyHex = extractPublicKeyHex;
|
|
1298
1330
|
exports.getAddressTypeFromDerivationPath = getAddressTypeFromDerivationPath;
|
|
1299
1331
|
exports.getBitcoinNetwork = getBitcoinNetwork;
|
|
1300
1332
|
exports.getDefaultRpcUrl = getDefaultRpcUrl;
|
package/index.esm.js
CHANGED
|
@@ -153,14 +153,14 @@ var currentEcc = null;
|
|
|
153
153
|
|
|
154
154
|
// Type for ECDSA public key (matches EcdsaPublicKey from lib-mpc-core)
|
|
155
155
|
// This is defined locally since btc-utils is environment-agnostic
|
|
156
|
-
function _instanceof$
|
|
156
|
+
function _instanceof$8(left, right) {
|
|
157
157
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
158
158
|
return !!right[Symbol.hasInstance](left);
|
|
159
159
|
} else {
|
|
160
160
|
return left instanceof right;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
function _type_of(obj) {
|
|
163
|
+
function _type_of$1(obj) {
|
|
164
164
|
"@swc/helpers - typeof";
|
|
165
165
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
166
166
|
}
|
|
@@ -175,7 +175,7 @@ function _type_of(obj) {
|
|
|
175
175
|
if (Buffer.isBuffer(actualPubkey)) {
|
|
176
176
|
return actualPubkey;
|
|
177
177
|
}
|
|
178
|
-
if (_instanceof$
|
|
178
|
+
if (_instanceof$8(actualPubkey, Uint8Array)) {
|
|
179
179
|
return Buffer.from(actualPubkey);
|
|
180
180
|
}
|
|
181
181
|
if (typeof actualPubkey === 'string') {
|
|
@@ -185,7 +185,7 @@ function _type_of(obj) {
|
|
|
185
185
|
}
|
|
186
186
|
return result;
|
|
187
187
|
}
|
|
188
|
-
if ((typeof actualPubkey === "undefined" ? "undefined" : _type_of(actualPubkey)) === 'object' && actualPubkey !== null) {
|
|
188
|
+
if ((typeof actualPubkey === "undefined" ? "undefined" : _type_of$1(actualPubkey)) === 'object' && actualPubkey !== null) {
|
|
189
189
|
return convertObjectToBuffer(actualPubkey);
|
|
190
190
|
}
|
|
191
191
|
throw new Error('Invalid public key format');
|
|
@@ -320,7 +320,7 @@ var convertObjectToBuffer = function(actualPubkey) {
|
|
|
320
320
|
};
|
|
321
321
|
};
|
|
322
322
|
|
|
323
|
-
function _instanceof$
|
|
323
|
+
function _instanceof$7(left, right) {
|
|
324
324
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
325
325
|
return !!right[Symbol.hasInstance](left);
|
|
326
326
|
} else {
|
|
@@ -339,7 +339,7 @@ function _instanceof$6(left, right) {
|
|
|
339
339
|
var normalizedKey = normalizePublicKey(pubKey, addressType);
|
|
340
340
|
if (addressType === BitcoinAddressType.TAPROOT) {
|
|
341
341
|
var sigBuffer;
|
|
342
|
-
if (_instanceof$
|
|
342
|
+
if (_instanceof$7(signature, Uint8Array) || Buffer.isBuffer(signature)) {
|
|
343
343
|
sigBuffer = Buffer.from(signature);
|
|
344
344
|
} else {
|
|
345
345
|
var r = signature.r;
|
|
@@ -373,7 +373,7 @@ function _instanceof$6(left, right) {
|
|
|
373
373
|
return BIP322.encodeWitness(toSignPsbt);
|
|
374
374
|
};
|
|
375
375
|
|
|
376
|
-
function _instanceof$
|
|
376
|
+
function _instanceof$6(left, right) {
|
|
377
377
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
378
378
|
return !!right[Symbol.hasInstance](left);
|
|
379
379
|
} else {
|
|
@@ -438,11 +438,11 @@ function _instanceof$5(left, right) {
|
|
|
438
438
|
return wif;
|
|
439
439
|
} catch (error) {
|
|
440
440
|
// Re-throw with more context
|
|
441
|
-
throw new Error("Failed to convert private key to WIF: ".concat(_instanceof$
|
|
441
|
+
throw new Error("Failed to convert private key to WIF: ".concat(_instanceof$6(error, Error) ? error.message : String(error)));
|
|
442
442
|
}
|
|
443
443
|
};
|
|
444
444
|
|
|
445
|
-
function _instanceof$
|
|
445
|
+
function _instanceof$5(left, right) {
|
|
446
446
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
447
447
|
return !!right[Symbol.hasInstance](left);
|
|
448
448
|
} else {
|
|
@@ -500,7 +500,7 @@ function _instanceof$4(left, right) {
|
|
|
500
500
|
// 7. Convert to hex string
|
|
501
501
|
return Buffer.from(privateKeyBytes).toString('hex');
|
|
502
502
|
} catch (error) {
|
|
503
|
-
throw new Error("Invalid WIF format: ".concat(_instanceof$
|
|
503
|
+
throw new Error("Invalid WIF format: ".concat(_instanceof$5(error, Error) ? error.message : String(error), ". Only WIF format is supported."));
|
|
504
504
|
}
|
|
505
505
|
};
|
|
506
506
|
|
|
@@ -533,7 +533,7 @@ function _async_to_generator$2(fn) {
|
|
|
533
533
|
});
|
|
534
534
|
};
|
|
535
535
|
}
|
|
536
|
-
function _instanceof$
|
|
536
|
+
function _instanceof$4(left, right) {
|
|
537
537
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
538
538
|
return !!right[Symbol.hasInstance](left);
|
|
539
539
|
} else {
|
|
@@ -676,7 +676,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
676
676
|
];
|
|
677
677
|
}
|
|
678
678
|
} catch (error) {
|
|
679
|
-
throw new Error("Failed to derive public key from private key: ".concat(_instanceof$
|
|
679
|
+
throw new Error("Failed to derive public key from private key: ".concat(_instanceof$4(error, Error) ? error.message : String(error)));
|
|
680
680
|
}
|
|
681
681
|
return [
|
|
682
682
|
2
|
|
@@ -688,7 +688,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
688
688
|
};
|
|
689
689
|
}();
|
|
690
690
|
|
|
691
|
-
function _instanceof$
|
|
691
|
+
function _instanceof$3(left, right) {
|
|
692
692
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
693
693
|
return !!right[Symbol.hasInstance](left);
|
|
694
694
|
} else {
|
|
@@ -701,8 +701,8 @@ function _instanceof$2(left, right) {
|
|
|
701
701
|
* @param signature - The ECDSA signature
|
|
702
702
|
* @returns The DER encoded signature
|
|
703
703
|
*/ var convertSignatureToDER = function(signature) {
|
|
704
|
-
var r = _instanceof$
|
|
705
|
-
var s = _instanceof$
|
|
704
|
+
var r = _instanceof$3(signature.r, Uint8Array) ? signature.r : new Uint8Array(signature.r);
|
|
705
|
+
var s = _instanceof$3(signature.s, Uint8Array) ? signature.s : new Uint8Array(signature.s);
|
|
706
706
|
var r32 = new Uint8Array(32);
|
|
707
707
|
var rSource = r.length > 32 ? r.slice(-32) : r;
|
|
708
708
|
r32.set(rSource, 32 - rSource.length);
|
|
@@ -1172,7 +1172,7 @@ function _ts_generator(thisArg, body) {
|
|
|
1172
1172
|
return Buffer.from(tweakHash).toString('hex');
|
|
1173
1173
|
};
|
|
1174
1174
|
|
|
1175
|
-
function _instanceof$
|
|
1175
|
+
function _instanceof$2(left, right) {
|
|
1176
1176
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1177
1177
|
return !!right[Symbol.hasInstance](left);
|
|
1178
1178
|
} else {
|
|
@@ -1185,7 +1185,7 @@ function _instanceof$1(left, right) {
|
|
|
1185
1185
|
* @param signature - The signature from MPC (can be Uint8Array, Buffer, or EcdsaSignature object)
|
|
1186
1186
|
* @returns A Buffer containing the 64-byte Schnorr signature
|
|
1187
1187
|
*/ var convertSignatureToTaprootBuffer = function(signature) {
|
|
1188
|
-
if (_instanceof$
|
|
1188
|
+
if (_instanceof$2(signature, Uint8Array) || Buffer.isBuffer(signature)) {
|
|
1189
1189
|
return Buffer.from(signature);
|
|
1190
1190
|
}
|
|
1191
1191
|
var r = signature.r;
|
|
@@ -1220,7 +1220,7 @@ function _instanceof$1(left, right) {
|
|
|
1220
1220
|
};
|
|
1221
1221
|
};
|
|
1222
1222
|
|
|
1223
|
-
function _instanceof(left, right) {
|
|
1223
|
+
function _instanceof$1(left, right) {
|
|
1224
1224
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1225
1225
|
return !!right[Symbol.hasInstance](left);
|
|
1226
1226
|
} else {
|
|
@@ -1262,10 +1262,41 @@ function _instanceof(left, right) {
|
|
|
1262
1262
|
console.log('[doesInputBelongToAddress] Error checking input', {
|
|
1263
1263
|
address: address,
|
|
1264
1264
|
network: network,
|
|
1265
|
-
error: _instanceof(error, Error) ? error.message : String(error)
|
|
1265
|
+
error: _instanceof$1(error, Error) ? error.message : String(error)
|
|
1266
1266
|
});
|
|
1267
1267
|
return false;
|
|
1268
1268
|
}
|
|
1269
1269
|
};
|
|
1270
1270
|
|
|
1271
|
-
|
|
1271
|
+
function _instanceof(left, right) {
|
|
1272
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1273
|
+
return !!right[Symbol.hasInstance](left);
|
|
1274
|
+
} else {
|
|
1275
|
+
return left instanceof right;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
function _type_of(obj) {
|
|
1279
|
+
"@swc/helpers - typeof";
|
|
1280
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Extracts the hex string representation of a public key from various formats.
|
|
1284
|
+
* Handles Uint8Array, objects with pubKeyAsHex method, and string formats.
|
|
1285
|
+
*
|
|
1286
|
+
* @param rawPublicKey - The raw public key in various formats
|
|
1287
|
+
* @returns The public key as a hex string
|
|
1288
|
+
* @throws Error if the public key format is invalid
|
|
1289
|
+
*/ var extractPublicKeyHex = function(rawPublicKey) {
|
|
1290
|
+
if (_instanceof(rawPublicKey, Uint8Array)) {
|
|
1291
|
+
return Buffer.from(rawPublicKey).toString('hex');
|
|
1292
|
+
}
|
|
1293
|
+
if (rawPublicKey && (typeof rawPublicKey === "undefined" ? "undefined" : _type_of(rawPublicKey)) === 'object' && 'pubKeyAsHex' in rawPublicKey && typeof rawPublicKey.pubKeyAsHex === 'function') {
|
|
1294
|
+
return rawPublicKey.pubKeyAsHex();
|
|
1295
|
+
}
|
|
1296
|
+
if (typeof rawPublicKey === 'string') {
|
|
1297
|
+
return rawPublicKey;
|
|
1298
|
+
}
|
|
1299
|
+
throw new Error('Invalid public key format');
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
export { calculateBip322Hash, calculateTaprootTweak, collectPSBTInputData, convertSignatureToDER, convertSignatureToTaprootBuffer, doesInputBelongToAddress, encodeBip322Signature, extractPublicKeyHex, getAddressTypeFromDerivationPath, getBitcoinNetwork, getDefaultRpcUrl, getFeeRates, getPublicKeyFromPrivateKey, getUTXOs, initEccLib, normalizePublicKey, privateKeyToWIF, publicKeyToBitcoinAddress, selectUTXOs, wifToPrivateKey };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/btc-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.255",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@dynamic-labs-wallet/core": "0.0.
|
|
8
|
+
"@dynamic-labs-wallet/core": "0.0.255",
|
|
9
9
|
"bitcoinjs-lib": "^7.0.0",
|
|
10
10
|
"bip322-js": "^3.0.0",
|
|
11
11
|
"@noble/hashes": "1.7.1",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the hex string representation of a public key from various formats.
|
|
3
|
+
* Handles Uint8Array, objects with pubKeyAsHex method, and string formats.
|
|
4
|
+
*
|
|
5
|
+
* @param rawPublicKey - The raw public key in various formats
|
|
6
|
+
* @returns The public key as a hex string
|
|
7
|
+
* @throws Error if the public key format is invalid
|
|
8
|
+
*/
|
|
9
|
+
export declare const extractPublicKeyHex: (rawPublicKey: unknown) => string;
|
|
10
|
+
//# sourceMappingURL=extractPublicKeyHex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractPublicKeyHex.d.ts","sourceRoot":"","sources":["../../src/extractPublicKeyHex/extractPublicKeyHex.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,iBAAkB,OAAO,KAAG,MAmB3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extractPublicKeyHex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/src/index.d.ts
CHANGED
|
@@ -17,5 +17,6 @@ export { collectPSBTInputData } from './collectPSBTInputData/index.js';
|
|
|
17
17
|
export { doesInputBelongToAddress } from './doesInputBelongToAddress/index.js';
|
|
18
18
|
export { getBitcoinNetwork } from './getBitcoinNetwork/index.js';
|
|
19
19
|
export { initEccLib } from './initEccLib/index.js';
|
|
20
|
+
export { extractPublicKeyHex } from './extractPublicKeyHex/index.js';
|
|
20
21
|
export type { UTXO } from './types.js';
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|