@desig/web3
Version:
Desig: The Blockchain-Agnostic Multisig Solution
50 lines • 1.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAddress = exports.isBase58 = exports.isHex = exports.ec = exports.toSmallNumber = void 0;
const core_1 = require("@desig/core");
const supported_chains_1 = require("@desig/supported-chains");
const ed25519_1 = require("@noble/ed25519");
const bn_js_1 = __importDefault(require("bn.js"));
const bs58_1 = require("bs58");
const toSmallNumber = (a, en = 'le') => {
return new bn_js_1.default(a, 16, en).toNumber();
};
exports.toSmallNumber = toSmallNumber;
exports.ec = {
[supported_chains_1.Curve.ed25519]: core_1.EdCurve,
[supported_chains_1.Curve.secp256k1]: core_1.ECCurve,
};
const isHex = (hex) => {
const ok = /^(0x|0X)?[a-fA-F0-9]+$/.test(hex) && hex.length % 2 === 0;
if (!ok)
return 0;
return /^(0x|0X)/.test(hex) ? (hex.length - 2) / 2 : hex.length / 2;
};
exports.isHex = isHex;
const isBase58 = (str) => {
try {
if (!str)
return false;
return str === (0, bs58_1.encode)((0, bs58_1.decode)(str));
}
catch (er) {
return false;
}
};
exports.isBase58 = isBase58;
const isAddress = (pubkey) => {
try {
if (!pubkey)
return false;
ed25519_1.Point.fromHex((0, bs58_1.decode)(pubkey));
return true;
}
catch (er) {
return false;
}
};
exports.isAddress = isAddress;
//# sourceMappingURL=utils.js.map