fix context backing name

This commit is contained in:
Marin Petrunić 2020-11-23 14:42:04 +01:00
parent 0d273a7d36
commit 135625ccc0
No known key found for this signature in database
GPG Key ID: 834D07135E110DA5
1 changed files with 11 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { IBls } from "./interface";
export type Backing = "herumi" | "blst-native" | "blst-wasm";
let backing: Backing|undefined = undefined;
let contextBacking: Backing|undefined = undefined;
let context: IBls|undefined = undefined;
//to maintain api compatible, add all backing context to return type
@ -13,7 +13,7 @@ export async function init(backing: Backing = "herumi"): Promise<IBls> {
switch(backing) {
case "herumi": {
context = await herumiToIBls();
backing = backing;
contextBacking = backing;
} break;
default: throw new Error(`Unsupported backing - ${backing}`)
}
@ -27,7 +27,7 @@ export function destroy(): void {
context.destroy();
}
context = undefined;
backing = undefined;
contextBacking = undefined;
}
export function getContext(): IBls {
@ -36,3 +36,11 @@ export function getContext(): IBls {
}
return context;
}
export function getContextBacking(): Backing {
if (!context) {
throw new Error("BLS not initialized");
}
return contextBacking;
}