@protonsale/sdk
Version:
Proton Sale SDK
58 lines • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.decimalToHexReverse = exports.decimalToHex = exports.strToHex = exports.getRanDomModuleNameHex = void 0;
/**
*
* @param account Address of user
* @returns hex string of modules
* Define struct contain 6 parameter struct abcdef { ABCDEF {} }
*/
const getRanDomModuleNameHex = (account) => {
const upperCase = ["41", "42", "43", "44", "45", "46", "47", "48", "49",
"4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a"];
const lowerCase = ["61", "62", "63", "64", "65", "66", "67", "68", "69",
"6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a"];
const one = lowerCase[Math.floor(Math.random() * lowerCase.length)];
const two = lowerCase[Math.floor(Math.random() * lowerCase.length)];
const three = lowerCase[Math.floor(Math.random() * lowerCase.length)];
const four = lowerCase[Math.floor(Math.random() * lowerCase.length)];
const five = lowerCase[Math.floor(Math.random() * lowerCase.length)];
const six = lowerCase[Math.floor(Math.random() * lowerCase.length)];
const One = upperCase[Math.floor(Math.random() * upperCase.length)];
const Two = upperCase[Math.floor(Math.random() * upperCase.length)];
const Three = upperCase[Math.floor(Math.random() * upperCase.length)];
const Four = upperCase[Math.floor(Math.random() * upperCase.length)];
const Five = upperCase[Math.floor(Math.random() * upperCase.length)];
const Six = upperCase[Math.floor(Math.random() * upperCase.length)];
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
const result = "a11ceb0b050000000501000202020407061e0824200a44050000000100000a7072745f" +
`${one}${two}${three}${four}${five}${six}06${One}${Two}${Three}${Four}${Five}${Six}` +
`0b64756d6d795f6669656c64${account.noPrefix()}000201020100`;
const moduleName = Buffer.from(`${one}${two}${three}${four}${five}${six}`, "hex");
const structName = Buffer.from(`${One}${Two}${Three}${Four}${Five}${Six}`, "hex");
const data = `prt_${moduleName.toString("utf8")}::${structName.toString("utf8")}`;
return [result, data];
};
exports.getRanDomModuleNameHex = getRanDomModuleNameHex;
const strToHex = (str) => {
let result = "";
for (let i = 0; i < str.length; i += 1) {
result += str.charCodeAt(i).toString(16);
}
return result;
};
exports.strToHex = strToHex;
const decimalToHex = (d) => {
let a = Number(d).toString(16);
if (a.length % 2 === 1)
a = `0${a}`;
return a;
};
exports.decimalToHex = decimalToHex;
const decimalToHexReverse = (d) => {
const a = (0, exports.decimalToHex)(d);
const buf = Buffer.from(a, "hex");
return buf.reverse().toString("hex");
};
exports.decimalToHexReverse = decimalToHexReverse;
//# sourceMappingURL=util.js.map