@rarible/types
Version:
`@rarible/types` is a TypeScript library that provides type definitions and interfaces for the Rarible ecosystem. This package is designed to facilitate seamless integration with Rarible's APIs and services, ensuring type safety and improved developer exp
42 lines (41 loc) • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomTezosAddress = exports.TEZOS_ZERO_ADDRESS = exports.toTezosAddressSafe = exports.toTezosAddress = exports.tezosAddressValidator = exports.isTezosAddress = void 0;
const address_js_1 = require("../../common/address.js");
const common_js_1 = require("../../common/common.js");
const domain_js_1 = require("../../union/enum/domain.js");
// Tezos addresses start with tz1, tz2, tz3 (for user accounts) and are Base58 encoded, exactly 36 characters long.
const tezosAddressRegExp = new RegExp(/^tz[1-3][1-9A-HJ-NP-Za-km-z]{33}/);
function isTezosAddress(address) {
return tezosAddressRegExp.test(address);
}
exports.isTezosAddress = isTezosAddress;
exports.tezosAddressValidator = (0, common_js_1.createLayer1fulValidator)(domain_js_1.BlockchainLayer1Enum.TEZOS, isTezosAddress);
function toTezosAddress(address) {
const safe = toTezosAddressSafe(address);
if (!safe)
throw new address_js_1.InvalidAddressError(domain_js_1.BlockchainLayer1Enum.TEZOS, address);
return safe;
}
exports.toTezosAddress = toTezosAddress;
function toTezosAddressSafe(address) {
if (isTezosAddress(address))
return address;
return undefined;
}
exports.toTezosAddressSafe = toTezosAddressSafe;
// Example of a Tezos zero address - this is just a placeholder
// @note TEZOS doesn't really have a concept of ZERO address
exports.TEZOS_ZERO_ADDRESS = toTezosAddress("tz1ZZZZZZZZZZZZZZZZZZZZZZZZZZZZNkiRg");
function randomTezosAddress() {
const prefixOptions = ["tz1", "tz2", "tz3"];
const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
let address = prefixOptions[Math.floor(Math.random() * prefixOptions.length)];
// Ensuring the total length is exactly 36 characters
for (let i = 0; i < 33; i++) {
const randomIndex = Math.floor(Math.random() * base58Chars.length);
address += base58Chars[randomIndex];
}
return toTezosAddress(address);
}
exports.randomTezosAddress = randomTezosAddress;