blocklock-js
Version:
A library for encrypting and decrypting data for the future
109 lines (108 loc) • 5.04 kB
TypeScript
import { Signer, Provider, BigNumberish, BytesLike } from "ethers";
import { Ciphertext, G2 } from "./crypto/ibe-bn254";
import { TypesLib } from "./generated/BlocklockSender";
export type BigIntPair = {
c0: bigint;
c1: bigint;
};
export type BlockLockPublicKey = {
x: BigIntPair;
y: BigIntPair;
};
export declare const BLOCKLOCK_TESTNET_PUBLIC_KEY: BlockLockPublicKey;
export declare const BLOCKLOCK_MAINNET_PUBLIC_KEY: BlockLockPublicKey;
type GasParams = {
gasLimit: number;
maxFeePerGas: bigint;
maxPriorityFeePerGas: bigint;
};
export declare const FURNACE_TESTNET_CONTRACT_ADDRESS = "0xEd925F96790F11678972b0F2c250498D782DDec9";
export declare const FILECOIN_CALIBNET_CONTRACT_ADDRESS = "0xF00aB3B64c81b6Ce51f8220EB2bFaa2D469cf702";
export declare const FILECOIN_MAINNET_CONTRACT_ADDRESS = "0x34092470CC59A097d770523931E3bC179370B44b";
export declare const BASE_SEPOLIA_CONTRACT_ADDRESS = "0x82Fed730CbdeC5A2D8724F2e3b316a70A565e27e";
export declare const POLYGON_POS_CONTRACT_ADDRESS = "0x82Fed730CbdeC5A2D8724F2e3b316a70A565e27e";
export declare class Blocklock {
private readonly blocklockSenderContractAddress;
private blocklockSender;
private blocklockPublicKey;
private ibeOpts;
private gasParams;
private signer;
constructor(signer: Signer | Provider, blocklockSenderContractAddress: string, chainId: bigint, gasParams?: GasParams, blocklockPublicKey?: BlockLockPublicKey);
static createFilecoinMainnet(rpc: Signer | Provider): Blocklock;
static createFilecoinCalibnet(rpc: Signer | Provider): Blocklock;
static createFurnace(rpc: Signer | Provider): Blocklock;
static createBaseSepolia(rpc: Signer | Provider): Blocklock;
static createPolygonPos(rpc: Signer | Provider): Blocklock;
static createFromChainId(rpc: Signer | Provider, chainId: BigNumberish): Blocklock;
/**
* Request a blocklock decryption at block number blockHeight.
* @param blockHeight time at which the decryption should key should be released
* @param ciphertext encrypted message to store on chain
* @returns blocklock request id as a string
*/
requestBlocklock(blockHeight: bigint, ciphertext: TypesLib.CiphertextStruct): Promise<bigint>;
/**
* Fetch the details of a blocklock request, decryption key / signature excluded.
* This function should be called to fetch pending blocklock requests.
* @param requestId blocklock request id
* @returns details of the blocklock request, undefined if not found
*/
fetchBlocklockRequest(requestId: bigint): Promise<BlocklockRequest | undefined>;
/**
* Fetch all blocklock requests, decryption keys / signatures excluded.
* @returns a map with the details of each blocklock request
*/
fetchAllBlocklockRequests(): Promise<Map<bigint, BlocklockRequest>>;
/**
* Fetch the status of a blocklock request, including the decryption key / signature if available.
* This function should be called to fetch blocklock requests that have been fulfilled, or to check
* whether it has been fulfilled or not.
* @param requestId blocklock request id
* @returns details of the blocklock request, undefined if not found
*/
fetchBlocklockStatus(requestId: bigint): Promise<BlocklockStatus>;
/**
* Encrypt a message that can be decrypted once a certain blockHeight is reached.
* @param message plaintext to encrypt
* @param blockHeight time at which the decryption key should be released
* @param pk public key of the scheme
* @returns encrypted message
*/
encrypt(message: Uint8Array, blockHeight: bigint, pk?: G2): Ciphertext;
/**
* Decrypt a ciphertext using a decryption key.
* @param ciphertext the ciphertext to decrypt
* @param key decryption key
* @returns plaintext
*/
decrypt(ciphertext: Ciphertext, key: Uint8Array): Uint8Array;
/**
* Encrypt a message that can be decrypted once a certain blockHeight is reached.
* @param message plaintext to encrypt
* @param blockHeight time at which the decryption key should be released
* @param pk public key of the scheme
* @returns the identifier of the blocklock request, and the ciphertext
*/
encryptAndRegister(message: Uint8Array, blockHeight: bigint, pk?: G2): Promise<{
id: bigint;
ciphertext: Ciphertext;
}>;
/**
* Try to decrypt a ciphertext with a specific blocklock id.
* @param requestId blocklock id of the ciphertext to decrypt
* @returns the plaintext if the decryption key is available, undefined otherwise
*/
decryptWithId(requestId: bigint): Promise<Uint8Array>;
}
export type BlocklockRequest = {
id: bigint;
blockHeight: bigint;
ciphertext: Ciphertext;
};
export type BlocklockStatus = BlocklockRequest & {
decryptionKey: Uint8Array;
};
export declare function encodeCondition(blockHeight: bigint): Uint8Array;
export declare function decodeCondition(bytes: BytesLike): bigint;
export {};