UNPKG

@stricahq/typhonjs

Version:

Pure JS Cardano Wallet library

44 lines (43 loc) 1.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseAddress = void 0; /* eslint-disable no-bitwise */ const buffer_1 = require("buffer"); const types_1 = require("../types"); const ShelleyTypeAddress_1 = __importDefault(require("./ShelleyTypeAddress")); class BaseAddress extends ShelleyTypeAddress_1.default { constructor(networkId, paymentCredential, stakeCredential) { super(networkId, paymentCredential); this.stakeCredential = stakeCredential; this.computeHex(); } computeHex() { let payload = 0; if (this._paymentCredential.type === types_1.HashType.ADDRESS) { // set 4th bit to 0, which is set by default } else if (this._paymentCredential.type === types_1.HashType.SCRIPT) { const mask = 1 << 4; payload |= mask; } if (this.stakeCredential.type === types_1.HashType.ADDRESS) { // set 5th bit to 0, which is set by default } else if (this.stakeCredential.type === types_1.HashType.SCRIPT) { const mask = 1 << 5; payload |= mask; } payload |= this.networkId; const address = `${payload .toString(16) .padStart(2, "0")}${this._paymentCredential.hash.toString("hex")}${this.stakeCredential.hash.toString("hex")}`; this.addressHex = address; this.addressBytes = buffer_1.Buffer.from(address, "hex"); this.addressBech32 = this.computeBech32(this.addressBytes); } } exports.BaseAddress = BaseAddress; exports.default = BaseAddress;