Simplify loading of the emscripten lib.
This removes an ugly hack and makes it possible to access the emscripten compiled library from within nodejs test cases more easily.
This commit is contained in:
parent
67a5051321
commit
d381226f21
4
emscripten/README
Normal file
4
emscripten/README
Normal file
@ -0,0 +1,4 @@
|
||||
The taler-emscripten-lib.js is compiled from C using emscripten.
|
||||
|
||||
See https://git.taler.net/libtalerutil-emscripten.git for automated build
|
||||
instructions and the functions exported from this module.
|
@ -53,7 +53,7 @@ const po2json = require("po2json");
|
||||
const paths = {
|
||||
ts: {
|
||||
src: [
|
||||
"src/**/*.{ts,tsx}",
|
||||
"src/**/*.{ts,tsx,js}",
|
||||
"!src/**/*-test*.ts",
|
||||
],
|
||||
decl: [
|
||||
@ -112,6 +112,8 @@ const tsBaseArgs = {
|
||||
strict: true,
|
||||
outDir: "build/src/",
|
||||
noImplicitAny: true,
|
||||
allowJs: true,
|
||||
checkJs: true,
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {CryptoApi} from "./cryptoApi";
|
||||
import {ReserveRecord, DenominationRecord, DenominationStatus} from "./types";
|
||||
import {ReserveRecord, DenominationRecord, DenominationStatus} from "../types";
|
||||
import {test, TestLib} from "talertest";
|
||||
|
||||
let masterPub1: string = "CQQZ9DY3MZ1ARMN5K1VKDETS04Y2QCKMMCFHZSWJWWVN82BTTH00";
|
@ -33,11 +33,11 @@ import {
|
||||
RefreshSessionRecord,
|
||||
WireFee,
|
||||
PayCoinInfo,
|
||||
} from "./types";
|
||||
} from "../types";
|
||||
import {
|
||||
OfferRecord,
|
||||
CoinWithDenom,
|
||||
} from "./wallet";
|
||||
} from "../wallet";
|
||||
|
||||
|
||||
/**
|
@ -22,27 +22,34 @@
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
import * as native from "./emscriptif";
|
||||
import {
|
||||
PreCoinRecord,
|
||||
PayCoinInfo,
|
||||
AmountJson,
|
||||
RefreshSessionRecord,
|
||||
RefreshPreCoinRecord,
|
||||
ReserveRecord,
|
||||
Amounts,
|
||||
CoinPaySig,
|
||||
CoinRecord,
|
||||
CoinStatus,
|
||||
DenominationRecord,
|
||||
PayCoinInfo,
|
||||
PaybackRequest,
|
||||
} from "./types";
|
||||
PreCoinRecord,
|
||||
RefreshPreCoinRecord,
|
||||
RefreshSessionRecord,
|
||||
ReserveRecord,
|
||||
WireFee,
|
||||
} from "../types";
|
||||
import create = chrome.alarms.create;
|
||||
import {OfferRecord} from "./wallet";
|
||||
import {CoinWithDenom} from "./wallet";
|
||||
import {CoinPaySig, CoinRecord} from "./types";
|
||||
import {DenominationRecord, Amounts, WireFee} from "./types";
|
||||
import {Amount} from "./emscriptif";
|
||||
import {HashContext} from "./emscriptif";
|
||||
import {RefreshMeltCoinAffirmationPS} from "./emscriptif";
|
||||
import {EddsaPublicKey} from "./emscriptif";
|
||||
import {HashCode} from "./emscriptif";
|
||||
import {
|
||||
CoinWithDenom,
|
||||
OfferRecord,
|
||||
} from "../wallet";
|
||||
import * as native from "./emscInterface";
|
||||
import {
|
||||
Amount,
|
||||
EddsaPublicKey,
|
||||
HashCode,
|
||||
HashContext,
|
||||
RefreshMeltCoinAffirmationPS,
|
||||
} from "./emscInterface";
|
||||
|
||||
|
||||
namespace RpcFunctions {
|
@ -1,5 +1,5 @@
|
||||
import {test, TestLib} from "talertest";
|
||||
import * as native from "./emscriptif";
|
||||
import * as native from "./emscInterface";
|
||||
|
||||
test("string hashing", (t: TestLib) => {
|
||||
let x = native.ByteArray.fromStringWithNull("hello taler");
|
@ -26,8 +26,11 @@
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
import {AmountJson} from "./types";
|
||||
import * as emscLib from "./emscripten/taler-emscripten-lib";
|
||||
import {AmountJson} from "../types";
|
||||
import {getLib, EmscFunGen} from "./emscLoader";
|
||||
|
||||
|
||||
const emscLib = getLib();
|
||||
|
||||
|
||||
/**
|
||||
@ -45,7 +48,7 @@ const GNUNET_SYSERR = -1;
|
||||
/**
|
||||
* Get an emscripten-compiled function.
|
||||
*/
|
||||
const getEmsc: emscLib.EmscFunGen = (name: string, ret: any, argTypes: any[]) => {
|
||||
const getEmsc: EmscFunGen = (name: string, ret: any, argTypes: any[]) => {
|
||||
return (...args: any[]) => {
|
||||
return emscLib.ccall(name, ret, argTypes, args);
|
||||
}
|
@ -14,6 +14,9 @@
|
||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
|
||||
declare function getLib(): EmscLib;
|
||||
|
||||
export interface EmscFunGen {
|
||||
(name: string,
|
||||
ret: string,
|
||||
@ -30,23 +33,22 @@ export interface EmscFunGen {
|
||||
}
|
||||
|
||||
|
||||
export var cwrap: EmscFunGen;
|
||||
interface EmscLib {
|
||||
cwrap: EmscFunGen;
|
||||
|
||||
export function ccall(name: string, ret:"number"|"string", argTypes: any[], args: any[]): any
|
||||
ccall(name: string, ret:"number"|"string", argTypes: any[], args: any[]): any
|
||||
|
||||
export function stringToUTF8(s: string, addr: number, maxLength: number): void
|
||||
stringToUTF8(s: string, addr: number, maxLength: number): void
|
||||
|
||||
export function _free(ptr: number): void;
|
||||
_free(ptr: number): void;
|
||||
|
||||
export function _malloc(n: number): number;
|
||||
_malloc(n: number): number;
|
||||
|
||||
export function Pointer_stringify(p: number, len?: number): string;
|
||||
Pointer_stringify(p: number, len?: number): string;
|
||||
|
||||
export function getValue(ptr: number, type: string, noSafe?: boolean): number;
|
||||
getValue(ptr: number, type: string, noSafe?: boolean): number;
|
||||
|
||||
export function setValue(ptr: number, value: number, type: string,
|
||||
noSafe?: boolean): void;
|
||||
setValue(ptr: number, value: number, type: string, noSafe?: boolean): void;
|
||||
|
||||
export function writeStringToMemory(s: string,
|
||||
buffer: number,
|
||||
dontAddNull?: boolean): void;
|
||||
writeStringToMemory(s: string, buffer: number, dontAddNull?: boolean): void;
|
||||
}
|
38
src/crypto/emscLoader.js
Normal file
38
src/crypto/emscLoader.js
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
This file is part of TALER
|
||||
(C) 2017 Inria and GNUnet e.V.
|
||||
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* Load the taler emscripten lib.
|
||||
*
|
||||
* If in a WebWorker, importScripts is used. Inside a browser,
|
||||
* the module must be globally available.
|
||||
*/
|
||||
export default function getLib() {
|
||||
if (window.TalerEmscriptenLib) {
|
||||
return TalerEmscriptenLib;
|
||||
}
|
||||
if (importScripts) {
|
||||
importScripts('/src/emscripten/taler-emscripten-lib.js')
|
||||
if (TalerEmscriptenLib) {
|
||||
throw Error("can't import TalerEmscriptenLib");
|
||||
}
|
||||
return TalerEmscriptenLib
|
||||
}
|
||||
throw Error("Can't find TalerEmscriptenLib.");
|
||||
}
|
@ -72,7 +72,7 @@ import {
|
||||
flatMap,
|
||||
getTalerStampSec,
|
||||
} from "./helpers";
|
||||
import {CryptoApi} from "./cryptoApi";
|
||||
import {CryptoApi} from "./crypto/cryptoApi";
|
||||
import URI = require("urijs");
|
||||
|
||||
|
||||
|
@ -14,7 +14,9 @@
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"strict": true,
|
||||
"outDir": "build/src/",
|
||||
"noImplicitAny": true
|
||||
"noImplicitAny": true,
|
||||
"allowJs": true,
|
||||
"checkJs": true
|
||||
},
|
||||
"files": [
|
||||
"decl/chrome/chrome.d.ts",
|
||||
@ -25,12 +27,13 @@
|
||||
"src/chromeBadge.ts",
|
||||
"src/components.ts",
|
||||
"src/content_scripts/notify.ts",
|
||||
"src/cryptoApi-test.ts",
|
||||
"src/cryptoApi.ts",
|
||||
"src/cryptoWorker.ts",
|
||||
"src/emscripten/taler-emscripten-lib.d.ts",
|
||||
"src/emscriptif-test.ts",
|
||||
"src/emscriptif.ts",
|
||||
"src/crypto/cryptoApi-test.ts",
|
||||
"src/crypto/cryptoApi.ts",
|
||||
"src/crypto/cryptoWorker.ts",
|
||||
"src/crypto/emscInterface-test.ts",
|
||||
"src/crypto/emscInterface.ts",
|
||||
"src/crypto/emscLoader.d.ts",
|
||||
"src/crypto/emscLoader.js",
|
||||
"src/helpers-test.ts",
|
||||
"src/helpers.ts",
|
||||
"src/http.ts",
|
||||
|
@ -34,13 +34,8 @@ module.exports = function (env) {
|
||||
base.plugins.push(new webpack.LoaderOptionsPlugin({minimize: true}));
|
||||
}
|
||||
const configWebWorker = {
|
||||
entry: {"cryptoWorker": "./src/cryptoWorker.ts"},
|
||||
entry: {"cryptoWorker": "./src/crypto/cryptoWorker.ts"},
|
||||
target: "webworker",
|
||||
externals: {
|
||||
// A big hack to load taler-emscripten-lib from the environment,
|
||||
// because we exclude it from the bundle.
|
||||
"./emscripten/taler-emscripten-lib": "(self.TalerEmscriptenLib = {}, importScripts('/src/emscripten/taler-emscripten-lib.js'), TalerEmscriptenLib)",
|
||||
},
|
||||
};
|
||||
|
||||
const configBackground = {
|
||||
|
Loading…
Reference in New Issue
Block a user