Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

utils.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.computePublicKeyHash = exports.hexToBytes = exports.bytesToHex = void 0;
  27. const assert = __importStar(require("assert"));
  28. const hashjs = __importStar(require("hash.js"));
  29. const BN = require("bn.js");
  30. function bytesToHex(a) {
  31. return Array.from(a, (byteValue) => {
  32. const hex = byteValue.toString(16).toUpperCase();
  33. return hex.length > 1 ? hex : `0${hex}`;
  34. }).join('');
  35. }
  36. exports.bytesToHex = bytesToHex;
  37. function hexToBytes(a) {
  38. assert.ok(a.length % 2 === 0);
  39. // Special-case length zero to return [].
  40. // BN.toArray intentionally returns [0] rather than [] for length zero,
  41. // which may make sense for BigNum data, but not for byte strings.
  42. return a.length === 0 ? [] : new BN(a, 16).toArray(null, a.length / 2);
  43. }
  44. exports.hexToBytes = hexToBytes;
  45. function computePublicKeyHash(publicKeyBytes) {
  46. const hash256 = hashjs.sha256().update(publicKeyBytes).digest();
  47. const hash160 = hashjs.ripemd160().update(hash256).digest();
  48. return Buffer.from(hash160);
  49. }
  50. exports.computePublicKeyHash = computePublicKeyHash;
  51. //# sourceMappingURL=utils.js.map