diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-16 15:03:52 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-16 15:03:52 +0200 |
commit | a1e0fc3b88ed4305f942fadbea66b29a3934721c (patch) | |
tree | cb4887bdb68f76eeeb7c4baecc47e5ceb2d4498c /src/crypto/emscInterface.ts | |
parent | 8f5b6ffd7d02986176c95c8800a8292555e2702b (diff) | |
download | wallet-core-a1e0fc3b88ed4305f942fadbea66b29a3934721c.tar.xz |
crypto worker refactoring
Diffstat (limited to 'src/crypto/emscInterface.ts')
-rw-r--r-- | src/crypto/emscInterface.ts | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/crypto/emscInterface.ts b/src/crypto/emscInterface.ts index 96e94e3fb..0c7edefab 100644 --- a/src/crypto/emscInterface.ts +++ b/src/crypto/emscInterface.ts @@ -28,8 +28,6 @@ */ import { AmountJson } from "../amounts"; -import { EmscFunGen, EmscLib } from "./emscLoader"; - /** * Size of a native pointer. Must match the size * use when compiling via emscripten. @@ -38,6 +36,53 @@ const PTR_SIZE = 4; const GNUNET_OK = 1; + +/** + * Signature of the function that retrieves emscripten + * function implementations. + */ +export interface EmscFunGen { + (name: string, + ret: string, + args: string[]): ((...x: Array<number|string>) => any); + (name: string, + ret: "number", + args: string[]): ((...x: Array<number|string>) => number); + (name: string, + ret: "void", + args: string[]): ((...x: Array<number|string>) => void); + (name: string, + ret: "string", + args: string[]): ((...x: Array<number|string>) => string); +} + + +interface EmscLib { + cwrap: EmscFunGen; + + ccall(name: string, ret: "number"|"string", argTypes: any[], args: any[]): any; + + stringToUTF8(s: string, addr: number, maxLength: number): void; + + onRuntimeInitialized(f: () => void): void; + + readBinary?: (filename: string) => Promise<ArrayBuffer>; + + calledRun?: boolean; + + _free(ptr: number): void; + + _malloc(n: number): number; + + Pointer_stringify(p: number, len?: number): string; + + getValue(ptr: number, type: string, noSafe?: boolean): number; + + setValue(ptr: number, value: number, type: string, noSafe?: boolean): void; + + writeStringToMemory(s: string, buffer: number, dontAddNull?: boolean): void; +} + interface EmscFunctions { amount_add(a1: number, a2: number, a3: number): number; amount_cmp(a1: number, a2: number): number; |