utils.js 944 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.computePublicKeyHash = exports.hexToBytes = exports.bytesToHex = void 0;
  4. const assert = require("assert");
  5. const hashjs = require("hash.js");
  6. const BN = require("bn.js");
  7. function bytesToHex(a) {
  8. return a
  9. .map((byteValue) => {
  10. const hex = byteValue.toString(16).toUpperCase();
  11. return hex.length > 1 ? hex : `0${hex}`;
  12. })
  13. .join('');
  14. }
  15. exports.bytesToHex = bytesToHex;
  16. function hexToBytes(a) {
  17. assert.ok(a.length % 2 === 0);
  18. return new BN(a, 16).toArray(null, a.length / 2);
  19. }
  20. exports.hexToBytes = hexToBytes;
  21. function computePublicKeyHash(publicKeyBytes) {
  22. const hash256 = hashjs.sha256().update(publicKeyBytes).digest();
  23. const hash160 = hashjs.ripemd160().update(hash256).digest();
  24. return Buffer.from(hash160);
  25. }
  26. exports.computePublicKeyHash = computePublicKeyHash;
  27. //# sourceMappingURL=utils.js.map