Update bls-eth-wasm types

This commit is contained in:
dapplion 2020-11-25 14:00:18 +00:00
parent 6b1fdb0971
commit cd5b7cba47
3 changed files with 98 additions and 112 deletions

97
src/herumi/bls-eth-wasm.d.ts vendored Normal file
View File

@ -0,0 +1,97 @@
declare module "bls-eth-wasm" {
export class Common {
constructor(size: number);
deserializeHexStr(s: string): void;
serializeToHexStr(): string;
dump(msg?: string): string;
clear(): void;
clone(): this;
isEqual(rhs: this): boolean;
deserialize(v: Uint8Array): void;
serialize(): Uint8Array;
add(rhs: this): void;
}
export class SecretKeyType extends Common {
constructor();
setInt(x: number): void;
isZero(): boolean;
setHashOf(a: Uint8Array): void;
setLittleEndian(a: Uint8Array): void;
setLittleEndianMod(a: Uint8Array): void;
setByCSPRNG(): void;
getPublicKey(): PublicKeyType;
sign(m: string | Uint8Array): SignatureType;
}
export class PublicKeyType extends Common {
constructor();
isZero(): boolean;
deserializeUncompressed(s: Uint8Array): void;
serializeUncompressed(): Uint8Array;
isValidOrder(): boolean;
verify(signature: SignatureType, m: Uint8Array | string): boolean;
}
export class SignatureType extends Common {
constructor();
deserializeUncompressed(s: Uint8Array): void;
serializeUncompressed(): Uint8Array;
isValidOrder(): boolean;
aggregate(others: SignatureType[]): boolean;
fastAggregateVerify(publicKeys: PublicKeyType[], message: Uint8Array): boolean;
aggregateVerifyNoCheck(publicKeys: PublicKeyType[], messages: Uint8Array): boolean;
}
export function init(curveType: CurveType): Promise<void>;
export function blsInit(curveType: CurveType): void;
export function setETHmode(mode: EthMode): void;
export function toHex(a: Uint8Array, start: number, length: number): string;
export function toHexStr(a: Uint8Array): string;
export function fromHexStr(s: string): Uint8Array;
export function deserializeHexStrToSecretKey(s: string): SecretKeyType;
export function deserializeHexStrToPublicKey(s: string): PublicKeyType;
export function deserializeHexStrToSignature(s: string): SignatureType;
export function getCurveOrder(): string;
export function getFieldOrder(): string;
export function verifySignatureOrder(doVerify: boolean): void;
export function verifyPublicKeyOrder(doVerify: boolean): void;
/**
*
* @param msgs single array with concatenated messages
* @param msgSize defaults to MSG_SIZE
*/
export function areAllMsgDifferent(msgs: Uint8Array, msgSize?: number): boolean;
/**
* return true if all pub[i].verify(sigs[i], msgs[i])
* @param msgs msgs is a concatenation of arrays of 32-byte Uint8Array
*/
export function multiVerify(pubs: PublicKeyType[], sigs: SignatureType[], msgs: Uint8Array[]): boolean;
export const SecretKey: typeof SecretKeyType;
export const PublicKey: typeof PublicKeyType;
export const Signature: typeof SignatureType;
export enum EthMode {
DRAFT_07 = 3,
}
export enum CurveType {
BN254 = 0,
BLS12_381 = 5,
}
export const BN254 = CurveType.BN254;
export const BLS12_381 = CurveType.BLS12_381;
export const ethMode = true;
export const ETH_MODE_DRAFT_07 = EthMode.DRAFT_07;
export const MSG_SIZE = 32;
}

View File

@ -7,7 +7,7 @@ let blsGlobalPromise: Promise<void> | null = null;
export async function setupBls(): Promise<void> { export async function setupBls(): Promise<void> {
if (!blsGlobal) { if (!blsGlobal) {
await bls.init(); await bls.init(bls.BLS12_381);
blsGlobal = bls; blsGlobal = bls;
} }
} }

View File

@ -1,111 +0,0 @@
declare module "bls-eth-wasm" {
export class Common {
constructor(size: number);
deserializeHexStr(s: string): void;
serializeToHexStr(): string;
dump(msg?: string): string;
clear(): void;
clone(): this;
isEqual(rhs: this): boolean
deserialize(v: Uint8Array): void;
serialize(): Uint8Array;
add(rhs: this): void;
}
export class SecretKeyType extends Common {
constructor();
setInt(x: number): void;
setHashOf(a: Uint8Array): void;
setLittleEndian(a: Uint8Array): void;
setByCSPRNG(): void;
getPublicKey(): PublicKeyType;
sign(m: string | Uint8Array): SignatureType;
/**
*
* @param m must have 40 bytes
*/
signHashWithDomain(m: Uint8Array): SignatureType;
}
export class PublicKeyType extends Common {
constructor();
verify(signature: SignatureType, m: Uint8Array | string): boolean;
isValidOrder(): boolean;
deserializeUncompressed (s: Uint8Array): void;
serializeUncompressed (): Uint8Array;
deserializeUncompressedHexStr (s:string): void;
serializeUncompressedToHexStr(): string;
/**
*
* @param signature
* @param m must have 40 bytes
*/
verifyHashWithDomain(signature: SignatureType, m: Uint8Array): boolean;
}
export class SignatureType extends Common {
constructor();
deserializeUncompressed (s: Uint8Array): void;
serializeUncompressed (): Uint8Array;
deserializeUncompressedHexStr (s:string): void;
serializeUncompressedToHexStr(): string;
isValidOrder(): boolean;
aggregate(others: SignatureType[]): boolean;
aggregateVerifyNoCheck(publicKeys: PublicKeyType[], messages: Uint8Array): boolean;
fastAggregateVerify(publicKeys: PublicKeyType[], message: Uint8Array): boolean;
/**
*
* @param publicKeys
* @param messages each message must have 40bytes
*/
verifyAggregatedHashWithDomain(publicKeys: PublicKeyType[], messages: Uint8Array[]): boolean
}
export function init(): Promise<void>;
export function toHex(a: Uint8Array, start: number, length: number): string;
export function toHexStr(a: Uint8Array): string;
export function fromHexStr(s: string): Uint8Array;
export function getCurveOrder(): string;
export function getFieldOrder(): string;
export function verifySignatureOrder(doVerify: boolean): void;
export function verifyPublicKeyOrder(doVerify: boolean): void;
/**
*
* @param msgs single array with concatenated messages
* @param msgSize defaults to MSG_SIZE
*/
export function areAllMsgDifferent(msgs: Uint8Array, msgSize?: number): boolean;
export function shouldVerifyBlsSignatureOrder(b: string): void;
export function shouldVerifyBlsPublicKeyOrder(b: string): void;
export function deserializeHexStrToSecretKey(s: string): SecretKeyType;
export function deserializeHexStrToPublicKey(s: string): PublicKeyType;
export function deserializeHexStrToSignature(s: string): SignatureType;
export const SecretKey: typeof SecretKeyType;
export const PublicKey: typeof PublicKeyType;
export const Signature: typeof SignatureType;
}