@meshsdk/bitcoin 1.9.0-beta.56 → 1.9.0-beta.58
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/dist/index.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -526,6 +526,9 @@ __export(index_exports, {
|
|
|
526
526
|
},
|
|
527
527
|
bitcoin: function() {
|
|
528
528
|
return bitcoin;
|
|
529
|
+
},
|
|
530
|
+
verifySignature: function() {
|
|
531
|
+
return verifySignature;
|
|
529
532
|
}
|
|
530
533
|
});
|
|
531
534
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -4385,7 +4388,21 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
|
|
|
4385
4388
|
* @returns The signature of the message as a string.
|
|
4386
4389
|
*/ key: "signData",
|
|
4387
4390
|
value: function signData(message) {
|
|
4388
|
-
|
|
4391
|
+
var privateKey = this._wallet.privateKey;
|
|
4392
|
+
if (!privateKey) {
|
|
4393
|
+
throw new Error("Private key is not available for signing.");
|
|
4394
|
+
}
|
|
4395
|
+
var keyPair = ECPair.fromPrivateKey(privateKey, {
|
|
4396
|
+
compressed: true
|
|
4397
|
+
});
|
|
4398
|
+
var messageBuffer = Buffer.from(message, "utf8");
|
|
4399
|
+
var bufferToHash = Buffer.concat([
|
|
4400
|
+
varIntBuffer(messageBuffer.length),
|
|
4401
|
+
messageBuffer
|
|
4402
|
+
]);
|
|
4403
|
+
var hash = bitcoin.crypto.hash256(bufferToHash);
|
|
4404
|
+
var signature = keyPair.sign(hash);
|
|
4405
|
+
return signature.toString("base64");
|
|
4389
4406
|
}
|
|
4390
4407
|
},
|
|
4391
4408
|
{
|
|
@@ -4436,4 +4453,37 @@ function _derive(words) {
|
|
|
4436
4453
|
var child = root.derivePath(path);
|
|
4437
4454
|
return child;
|
|
4438
4455
|
}
|
|
4456
|
+
function varIntBuffer(n) {
|
|
4457
|
+
if (n < 253) return Buffer.from([
|
|
4458
|
+
n
|
|
4459
|
+
]);
|
|
4460
|
+
if (n <= 65535) return Buffer.from([
|
|
4461
|
+
253,
|
|
4462
|
+
n & 255,
|
|
4463
|
+
n >> 8
|
|
4464
|
+
]);
|
|
4465
|
+
if (n <= 4294967295) return Buffer.from([
|
|
4466
|
+
254,
|
|
4467
|
+
n & 255,
|
|
4468
|
+
n >> 8 & 255,
|
|
4469
|
+
n >> 16 & 255,
|
|
4470
|
+
n >> 24 & 255
|
|
4471
|
+
]);
|
|
4472
|
+
throw new Error("Message too long");
|
|
4473
|
+
}
|
|
4474
|
+
function verifySignature(message, signatureBase64, publicKeyHex) {
|
|
4475
|
+
try {
|
|
4476
|
+
var messageBuffer = Buffer.from(message, "utf8");
|
|
4477
|
+
var bufferToHash = Buffer.concat([
|
|
4478
|
+
varIntBuffer(messageBuffer.length),
|
|
4479
|
+
messageBuffer
|
|
4480
|
+
]);
|
|
4481
|
+
var hash = bitcoin.crypto.hash256(bufferToHash);
|
|
4482
|
+
var signature = Buffer.from(signatureBase64, "base64");
|
|
4483
|
+
var publicKey = Buffer.from(publicKeyHex, "hex");
|
|
4484
|
+
return ECPair.fromPublicKey(publicKey).verify(hash, signature);
|
|
4485
|
+
} catch (e) {
|
|
4486
|
+
return false;
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4439
4489
|
//# sourceMappingURL=index.cjs.map
|