blocklock-js
Version:
A library for encrypting and decrypting data for the future
61 lines (60 loc) • 2.23 kB
TypeScript
import { Fp, Fp12, Fp2 } from '@noble/curves/abstract/tower';
import { AffinePoint } from '@noble/curves/abstract/weierstrass';
import { CHash } from "@noble/curves/abstract/utils";
export type G1 = AffinePoint<Fp>;
export type G2 = AffinePoint<Fp2>;
export type GT = Fp12;
export interface Ciphertext {
U: G2;
V: Uint8Array;
W: Uint8Array;
}
export type IbeOpts = {
hash: CHash;
k: number;
expand_fn: 'xmd' | 'xof';
dsts: DstOpts;
};
export type DstOpts = {
H1_G1: Uint8Array;
H2: Uint8Array;
H3: Uint8Array;
H4: Uint8Array;
};
export declare const DEFAULT_OPTS: IbeOpts;
export declare function get_identity_g1(identity: Uint8Array, opts?: IbeOpts): G1;
export declare function encrypt_towards_identity_g1(m: Uint8Array, identity: Uint8Array, pk_g2: G2, opts?: IbeOpts): Ciphertext;
export declare function decrypt_g1(ciphertext: Ciphertext, decryption_key_g1: G1, opts?: IbeOpts): Uint8Array;
/**
* Decryption function for IBE based on https://www.iacr.org/archive/crypto2001/21390212.pdf Section 6 / https://eprint.iacr.org/2023/189.pdf, Algorithm 1
* with the identity on G1, and the master public key on G2.
*/
export declare function decrypt_g1_with_preprocess(ciphertext: Ciphertext, preprocessed_decryption_key: Uint8Array, opts?: IbeOpts): Uint8Array;
/**
* Preprocess a signature by computing the hash of the pairing, i.e.,
* H_2(e(\pi_\rho, U)).
* @param ciphertext ciphertext to preprocess the decryption key for
* @param decryption_key_g1 decryption key on g1 for the ciphertext
* @param opts IBE scheme options
* @returns preprocessed decryption key
*/
export declare function preprocess_decryption_key_g1(ciphertext: Ciphertext, decryption_key_g1: G1, opts?: IbeOpts): Uint8Array;
/**
* Serialize Ciphertext to ASN.1 structure
* Ciphertext ::= SEQUENCE {
* u SEQUENCE {
* x SEQUENCE {
* c0 INTEGER,
* c1 INTEGER
* },
* y SEQUENCE {
* c0 INTEGER,
* c1 INTEGER
* }
* },
* v OCTET STRING,
* w OCTET STRING
* }
*/
export declare function serializeCiphertext(ct: Ciphertext): Uint8Array;
export declare function deserializeCiphertext(ct: Uint8Array): Ciphertext;