[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-wallet-webex] branch master updated: Simplify loadin
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-wallet-webex] branch master updated: Simplify loading of the emscripten lib. |
Date: |
Sat, 27 May 2017 18:44:01 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-webex.
The following commit(s) were added to refs/heads/master by this push:
new d381226f Simplify loading of the emscripten lib.
d381226f is described below
commit d381226f21f1d0605d06ccae56c38ab6b12f88f0
Author: Florian Dold <address@hidden>
AuthorDate: Sat May 27 18:43:11 2017 +0200
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.
---
emscripten/README | 4 +++
.../taler-emscripten-lib.js | 0
gulpfile.js | 4 ++-
src/{ => crypto}/cryptoApi-test.ts | 2 +-
src/{ => crypto}/cryptoApi.ts | 4 +--
src/{ => crypto}/cryptoWorker.ts | 39 +++++++++++++---------
.../emscInterface-test.ts} | 2 +-
src/{emscriptif.ts => crypto/emscInterface.ts} | 9 +++--
.../emscLoader.d.ts} | 26 ++++++++-------
src/crypto/emscLoader.js | 38 +++++++++++++++++++++
src/wallet.ts | 2 +-
tsconfig.json | 17 ++++++----
webpack.config.js | 7 +---
13 files changed, 104 insertions(+), 50 deletions(-)
diff --git a/emscripten/README b/emscripten/README
new file mode 100644
index 00000000..e13ea8ed
--- /dev/null
+++ b/emscripten/README
@@ -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.
diff --git a/src/emscripten/taler-emscripten-lib.js
b/emscripten/taler-emscripten-lib.js
similarity index 100%
rename from src/emscripten/taler-emscripten-lib.js
rename to emscripten/taler-emscripten-lib.js
diff --git a/gulpfile.js b/gulpfile.js
index ec8321dc..56830061 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -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,
};
diff --git a/src/cryptoApi-test.ts b/src/crypto/cryptoApi-test.ts
similarity index 99%
rename from src/cryptoApi-test.ts
rename to src/crypto/cryptoApi-test.ts
index 8350defb..89b74d77 100644
--- a/src/cryptoApi-test.ts
+++ b/src/crypto/cryptoApi-test.ts
@@ -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";
diff --git a/src/cryptoApi.ts b/src/crypto/cryptoApi.ts
similarity index 99%
rename from src/cryptoApi.ts
rename to src/crypto/cryptoApi.ts
index 45efb63e..a386eab4 100644
--- a/src/cryptoApi.ts
+++ b/src/crypto/cryptoApi.ts
@@ -33,11 +33,11 @@ import {
RefreshSessionRecord,
WireFee,
PayCoinInfo,
-} from "./types";
+} from "../types";
import {
OfferRecord,
CoinWithDenom,
-} from "./wallet";
+} from "../wallet";
/**
diff --git a/src/cryptoWorker.ts b/src/crypto/cryptoWorker.ts
similarity index 96%
rename from src/cryptoWorker.ts
rename to src/crypto/cryptoWorker.ts
index bf802a32..36b3b924 100644
--- a/src/cryptoWorker.ts
+++ b/src/crypto/cryptoWorker.ts
@@ -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 {
diff --git a/src/emscriptif-test.ts b/src/crypto/emscInterface-test.ts
similarity index 99%
rename from src/emscriptif-test.ts
rename to src/crypto/emscInterface-test.ts
index 8b7a9eff..4f57bf80 100644
--- a/src/emscriptif-test.ts
+++ b/src/crypto/emscInterface-test.ts
@@ -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");
diff --git a/src/emscriptif.ts b/src/crypto/emscInterface.ts
similarity index 99%
rename from src/emscriptif.ts
rename to src/crypto/emscInterface.ts
index 60653b66..52c6c965 100644
--- a/src/emscriptif.ts
+++ b/src/crypto/emscInterface.ts
@@ -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);
}
diff --git a/src/emscripten/taler-emscripten-lib.d.ts
b/src/crypto/emscLoader.d.ts
similarity index 63%
rename from src/emscripten/taler-emscripten-lib.d.ts
rename to src/crypto/emscLoader.d.ts
index 25cfc623..e46ed7f1 100644
--- a/src/emscripten/taler-emscripten-lib.d.ts
+++ b/src/crypto/emscLoader.d.ts
@@ -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;
+}
diff --git a/src/crypto/emscLoader.js b/src/crypto/emscLoader.js
new file mode 100644
index 00000000..723b8ae3
--- /dev/null
+++ b/src/crypto/emscLoader.js
@@ -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.");
+}
diff --git a/src/wallet.ts b/src/wallet.ts
index f48fcc76..a2a9e83f 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -72,7 +72,7 @@ import {
flatMap,
getTalerStampSec,
} from "./helpers";
-import {CryptoApi} from "./cryptoApi";
+import {CryptoApi} from "./crypto/cryptoApi";
import URI = require("urijs");
diff --git a/tsconfig.json b/tsconfig.json
index 7409f2b8..0c684214 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -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",
diff --git a/webpack.config.js b/webpack.config.js
index a99d2a7c..deca2ae7 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -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 = {
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-wallet-webex] branch master updated: Simplify loading of the emscripten lib.,
gnunet <=