Files
zeekay 7d704b1e9b Update @luxfhe packages to latest versions
- @luxfhe/wasm: ^0.2.0
- @luxfhe/kms: ^0.2.0
- @luxfhe/relayer-sdk: ^0.6.0
- @luxfhe/mock-contracts: ^0.6.0
- Remove deprecated Zama dependencies
2026-01-02 10:49:11 -08:00

56 lines
1.7 KiB
TypeScript

import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { Permission } from "@luxfhe/sdk";
import hre, { ethers, network } from "hardhat";
import { HardhatRuntimeEnvironment } from "hardhat/types";
export const getTokensFromFaucet = async (address: string) => {
if (hre.network.name === "localluxfhe") {
if ((await hre.ethers.provider.getBalance(address)).toString() === "0") {
await hre.luxfhe.getFunds(address);
}
}
};
export const takeSnapshot = async (): Promise<string> => {
return network.provider.send("evm_snapshot");
};
export const revertSnapshot = async (snapshot: string) => {
return network.provider.send("evm_revert", [snapshot]);
};
export const withinSnapshot = async <T>(body: () => Promise<T>): Promise<T | undefined> => {
const tmp = await takeSnapshot();
try {
const res = await body();
return res;
} finally {
await revertSnapshot(tmp);
}
};
export const createLuxFHEContractPermission = async (
hre: HardhatRuntimeEnvironment,
signer: SignerWithAddress,
contractAddress: string,
): Promise<Permission> => {
const provider = ethers.provider;
const permit = await hre.luxfhe.generatePermit(contractAddress, provider, signer);
const permission = hre.luxfhe.extractPermitPermission(permit);
return permission;
};
export const unsealMockFheOpsSealed = (sealed: string): bigint => {
const byteArray = new Uint8Array(sealed.split("").map(c => c.charCodeAt(0)));
// Step 2: Convert the Uint8Array to BigInt
let result = BigInt(0);
for (let i = 0; i < byteArray.length; i++) {
result = (result << BigInt(8)) + BigInt(byteArray[i]); // Shift and add each byte
}
return result;
};