@meshsdk/bitcoin 1.9.0-beta.55 → 1.9.0-beta.57

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 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);
@@ -1077,6 +1080,9 @@ function toFormData(obj, formData, options) {
1077
1080
  if (utils_default.isDate(value)) {
1078
1081
  return value.toISOString();
1079
1082
  }
1083
+ if (utils_default.isBoolean(value)) {
1084
+ return value.toString();
1085
+ }
1080
1086
  if (!useBlob && utils_default.isBlob(value)) {
1081
1087
  throw new AxiosError_default("Blob is not supported. Use a Buffer instead.");
1082
1088
  }
@@ -2914,7 +2920,7 @@ var fetch_default = isFetchSupported && function(config) {
2914
2920
  }));
2915
2921
  return [
2916
2922
  4,
2917
- fetch(request)
2923
+ fetch(request, fetchOptions)
2918
2924
  ];
2919
2925
  case 4:
2920
2926
  response = _state.sent();
@@ -3076,7 +3082,7 @@ function dispatchRequest(config) {
3076
3082
  });
3077
3083
  }
3078
3084
  // ../../node_modules/axios/lib/env/data.js
3079
- var VERSION = "1.9.0";
3085
+ var VERSION = "1.10.0";
3080
3086
  // ../../node_modules/axios/lib/helpers/validator.js
3081
3087
  var validators = {};
3082
3088
  [
@@ -4382,7 +4388,21 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
4382
4388
  * @returns The signature of the message as a string.
4383
4389
  */ key: "signData",
4384
4390
  value: function signData(message) {
4385
- return "";
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");
4386
4406
  }
4387
4407
  },
4388
4408
  {
@@ -4433,4 +4453,37 @@ function _derive(words) {
4433
4453
  var child = root.derivePath(path);
4434
4454
  return child;
4435
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
+ }
4436
4489
  //# sourceMappingURL=index.cjs.map