isBtcAddress.js 662 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isBtcAddress;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. // supports Bech32 addresses
  9. var bech32 = /^(bc1)[a-z0-9]{25,39}$/;
  10. var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
  11. function isBtcAddress(str) {
  12. (0, _assertString.default)(str); // check for bech32
  13. if (str.startsWith('bc1')) {
  14. return bech32.test(str);
  15. }
  16. return base58.test(str);
  17. }
  18. module.exports = exports.default;
  19. module.exports.default = exports.default;