UNPKG

@zeroledger/vycrypt

Version:

TS Development Kit for ZeroLeger Protocol

27 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deriveStealthAccount = exports.createStealth = void 0; const utils = require("@noble/curves/abstract/utils"); const utils_1 = require("@noble/hashes/utils"); const viem_1 = require("viem"); const accounts_1 = require("viem/accounts"); const elliptic_1 = require("./elliptic"); const createStealth = (publicKey) => { const random = utils.bytesToNumberBE((0, utils_1.randomBytes)(16)); const stealthPublicKey = (0, elliptic_1.mulPublicKey)(publicKey, random); const stealthAddress = (0, viem_1.getAddress)(`0x${(0, viem_1.keccak256)(("0x" + stealthPublicKey.substring(4))).substring(26)}`); if (!(0, viem_1.isAddress)(stealthAddress)) { throw new Error("STEALTH_ADDRESS_GENERATION_FAIL"); } return { stealthAddress, random, }; }; exports.createStealth = createStealth; const deriveStealthAccount = (pk, random) => { const stealthPk = (0, elliptic_1.mulPrivateKey)(pk, (0, viem_1.hexToBigInt)(random)); return (0, accounts_1.privateKeyToAccount)(stealthPk); }; exports.deriveStealthAccount = deriveStealthAccount; //# sourceMappingURL=stealth.js.map