minauth-erc721-timelock-plugin
Version:
This package contains an implementation of a MinAuth plugin that combines zero-knowledge Merkle "membership" proofs with the ability to register into to a Merkle tree with locking an Ethereum NFT.
55 lines (54 loc) • 2.63 kB
TypeScript
import { BytesLike, ethers } from 'ethers';
import { ERC721TimeLock as ERC721TimeLockContract } from './typechain/contracts/ERC721TimeLock.js';
import { MerkleTree } from './merkle-tree.js';
import { UserCommitmentHex } from './commitment-types.js';
import { Logger } from 'minauth/dist/plugin/logger.js';
import { ERC721Mock } from './typechain/index.js';
export interface IErc721TimeLock {
fetchEligibleCommitments(): Promise<{
commitments: UserCommitmentHex[];
}>;
buildCommitmentTree(): Promise<MerkleTree>;
lockToken(tokenId: number, hash: UserCommitmentHex): Promise<void>;
unlockToken(index: number): Promise<void>;
get lockContractAddress(): string;
get erc721ContractAddress(): string;
get ethereumProvider(): ethers.BrowserProvider | ethers.JsonRpcProvider;
}
export declare class Erc721TimeLock implements IErc721TimeLock {
private readonly signer;
readonly lockContractAddress: string;
readonly erc721ContractAddress: string;
readonly ethereumProvider: ethers.BrowserProvider | ethers.JsonRpcProvider;
private readonly logger?;
protected contract: ERC721TimeLockContract;
protected nftContract: ERC721Mock;
constructor(signer: ethers.JsonRpcSigner, lockContractAddress: string, erc721ContractAddress: string, ethereumProvider: ethers.BrowserProvider | ethers.JsonRpcProvider, logger?: Logger | undefined);
static initialize(addresses: {
lockContractAddress: string;
nftContractAddress: string;
}, ethereumProvider: ethers.BrowserProvider | ethers.JsonRpcProvider, logger?: Logger): Promise<Erc721TimeLock>;
/**
* Fetch the TokenLocked and TokenUnlocked events to get the hashes of currently locked tokens.
*/
fetchEligibleCommitments(): Promise<{
commitments: UserCommitmentHex[];
}>;
/**
* Locks a token by first approving its transfer and then interacting with the lock contract.
* @param tokenId The ID of the token to be locked.
* @param hash The hash representing the token's commitment.
*/
lockToken(tokenId: number, { commitmentHex }: UserCommitmentHex): Promise<void>;
/**
* Unlocks a token by interacting with the lock contract.
* @param index The index of the token in the locked tokens array.
*/
unlockToken(index: number): Promise<void>;
/**
* Fetch the commitments from the events and build a merkle tree.
*/
buildCommitmentTree: () => Promise<MerkleTree>;
}
export declare function hexlify(bytes: BytesLike): string;
export declare function hexToUInt8Array(hexString: string, size?: number): Uint8Array;