@zeroledger/vycrypt
Version:
TS Development Kit for ZeroLeger Protocol
33 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mulPrivateKey = exports.mulPublicKey = void 0;
const secp256k1_1 = require("@noble/curves/secp256k1");
const viem_1 = require("viem");
const { Point, CURVE } = secp256k1_1.secp256k1;
/**
* @notice Returns new PublicKey prefixed with 0x04
* @param value number to multiply by
* @returns 64 bytes length public key padded with 0x
*/
const mulPublicKey = (publicKey, number, isCompressed = false) => {
// Perform the multiplication
const publicKey_ = Point.fromHex(publicKey.slice(2)).multiply(number);
return `0x${publicKey_.toHex(isCompressed)}`;
};
exports.mulPublicKey = mulPublicKey;
/**
* @notice Returns new KeyPair instance after multiplying this private key by some value
* @param value number to multiply by
* @returns 32 byte length private key, padded with 0x
*/
const mulPrivateKey = (pk, number) => {
/**
* Get new private key.
* Multiplication gives us an arbitrarily large number that is not necessarily in the domain
* of the secp256k1 curve, so then we use modulus operation to get in the correct range.
*/
const privateKeyBigInt = (BigInt(pk) * number) % CURVE.n;
return (0, viem_1.toHex)(privateKeyBigInt, { size: 32 }); // convert to 32 byte hex
};
exports.mulPrivateKey = mulPrivateKey;
//# sourceMappingURL=elliptic.js.map