aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-09-12 20:25:56 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-09-12 20:25:56 +0200
commit885285734733b71c88dfb0da513988eb8678aa14 (patch)
treedcaa19022de33210a97266fcb7a91055ea8e42c7 /lib
parente3cc9c59bcc36eee8c3234574cfdfda3f5eea658 (diff)
downloadwallet-core-885285734733b71c88dfb0da513988eb8678aa14.tar.xz
fix compiler warnings
Diffstat (limited to 'lib')
-rw-r--r--lib/decl/systemjs/systemjs.d.ts2
-rw-r--r--lib/emscripten/emsc.d.ts7
-rw-r--r--lib/i18n.ts24
-rw-r--r--lib/wallet/checkable.ts51
-rw-r--r--lib/wallet/cryptoApi.ts7
-rw-r--r--lib/wallet/cryptoLib.ts9
-rw-r--r--lib/wallet/db.ts13
-rw-r--r--lib/wallet/emscriptif.ts50
-rw-r--r--lib/wallet/helpers.ts8
-rw-r--r--lib/wallet/http.ts6
-rw-r--r--lib/wallet/types.ts2
11 files changed, 101 insertions, 78 deletions
diff --git a/lib/decl/systemjs/systemjs.d.ts b/lib/decl/systemjs/systemjs.d.ts
index 1d826aebb..4d84b399c 100644
--- a/lib/decl/systemjs/systemjs.d.ts
+++ b/lib/decl/systemjs/systemjs.d.ts
@@ -9,7 +9,7 @@ interface System {
config: any;
newModule(obj: Object): any;
normalizeSync(name: string): string;
- set(moduleName: string, module: any)
+ set(moduleName: string, module: any): void;
}
diff --git a/lib/emscripten/emsc.d.ts b/lib/emscripten/emsc.d.ts
index c313f240d..19a6990e5 100644
--- a/lib/emscripten/emsc.d.ts
+++ b/lib/emscripten/emsc.d.ts
@@ -33,7 +33,7 @@ export interface EmscFunGen {
export declare namespace Module {
var cwrap: EmscFunGen;
- function _free(ptr: number);
+ function _free(ptr: number): void;
function _malloc(n: number): number;
@@ -41,9 +41,10 @@ export declare namespace Module {
function getValue(ptr: number, type: string, noSafe?: boolean): number;
- function setValue(ptr: number, value: number, type: string, noSafe?: boolean);
+ function setValue(ptr: number, value: number, type: string,
+ noSafe?: boolean): void;
function writeStringToMemory(s: string,
buffer: number,
- dontAddNull?: boolean);
+ dontAddNull?: boolean): void;
} \ No newline at end of file
diff --git a/lib/i18n.ts b/lib/i18n.ts
index bba3e14c6..ce13a3292 100644
--- a/lib/i18n.ts
+++ b/lib/i18n.ts
@@ -24,14 +24,14 @@ document.addEventListener(
declare var i18n: any;
-const JedModule = window["Jed"];
-var jed;
+const JedModule: any = (window as any)["Jed"];
+var jed: any;
class PluralNumber {
n: number;
- constructor(n) {
+ constructor(n: number) {
this.n = n;
}
@@ -62,7 +62,7 @@ function init () {
/** Convert template strings to a msgid */
-function toI18nString(strings) {
+function toI18nString(strings: string[]) {
let str = "";
for (let i = 0; i < strings.length; i++) {
str += strings[i];
@@ -75,7 +75,7 @@ function toI18nString(strings) {
/** Use the first number in values to determine plural form */
-function getPluralValue (values) {
+function getPluralValue (values: any) {
let n = null;
for (let i = 0; i < values.length; i++) {
if ("number" === typeof values[i] || values[i] instanceof PluralNumber) {
@@ -88,11 +88,11 @@ function getPluralValue (values) {
}
-var i18n = <any>function i18n(strings, ...values) {
+var i18n = <any>function i18n(strings: string[], ...values: any[]) {
init();
if ("object" !== typeof jed) {
// Fallback implementation in case i18n lib is not there
- return String.raw(strings, ...values);
+ return String.raw(strings as any, ...values);
}
let str = toI18nString (strings);
@@ -109,11 +109,11 @@ i18n.strings = {};
* Interpolate i18nized values with arbitrary objects.
* @return Array of strings/objects.
*/
-i18n.parts = function(strings, ...values) {
+i18n.parts = function(strings: string[], ...values: any[]) {
init();
if ("object" !== typeof jed) {
// Fallback implementation in case i18n lib is not there
- let parts = [];
+ let parts: string[] = [];
for (let i = 0; i < strings.length; i++) {
parts.push(strings[i]);
@@ -127,7 +127,7 @@ i18n.parts = function(strings, ...values) {
let str = toI18nString (strings);
let n = getPluralValue (values);
let tr = jed.ngettext(str, str, n).split(/%(\d+)\$s/);
- let parts = [];
+ let parts: string[] = [];
for (let i = 0; i < tr.length; i++) {
if (0 == i % 2) {
parts.push(tr[i]);
@@ -144,7 +144,7 @@ i18n.parts = function(strings, ...values) {
* Pluralize based on first numeric parameter in the template.
* @todo The plural argument is used for extraction by pogen.js
*/
-i18n.pluralize = function (singular, plural) {
+i18n.pluralize = function (singular: any, plural: any) {
return singular;
};
@@ -154,4 +154,4 @@ i18n.pluralize = function (singular, plural) {
*/
i18n.number = function (n : number) {
return new PluralNumber (n);
-}
+};
diff --git a/lib/wallet/checkable.ts b/lib/wallet/checkable.ts
index a35634e81..9fd816578 100644
--- a/lib/wallet/checkable.ts
+++ b/lib/wallet/checkable.ts
@@ -25,18 +25,39 @@
*/
export namespace Checkable {
- export function SchemaError(message) {
+
+ type Path = (number|string)[];
+
+ interface SchemaErrorConstructor {
+ new (err: string): SchemaError;
+ }
+
+ interface SchemaError {
+ name: string;
+ message: string;
+ }
+
+ interface Prop {
+ propertyKey: any;
+ checker: any;
+ type: any;
+ elementChecker?: any;
+ elementProp?: any;
+ }
+
+ export let SchemaError = (function SchemaError(message: string) {
this.name = 'SchemaError';
this.message = message;
this.stack = (<any>new Error()).stack;
- }
+ }) as any as SchemaErrorConstructor;
+
SchemaError.prototype = new Error;
let chkSym = Symbol("checkable");
- function checkNumber(target, prop, path): any {
+ function checkNumber(target: any, prop: Prop, path: Path): any {
if ((typeof target) !== "number") {
throw new SchemaError(`expected number for ${path}`);
}
@@ -44,7 +65,7 @@ export namespace Checkable {
}
- function checkString(target, prop, path): any {
+ function checkString(target: any, prop: Prop, path: Path): any {
if (typeof target !== "string") {
throw new SchemaError(`expected string for ${path}, got ${typeof target} instead`);
}
@@ -52,7 +73,7 @@ export namespace Checkable {
}
- function checkAnyObject(target, prop, path): any {
+ function checkAnyObject(target: any, prop: Prop, path: Path): any {
if (typeof target !== "object") {
throw new SchemaError(`expected (any) object for ${path}, got ${typeof target} instead`);
}
@@ -60,12 +81,12 @@ export namespace Checkable {
}
- function checkAny(target, prop, path): any {
+ function checkAny(target: any, prop: Prop, path: Path): any {
return target;
}
- function checkList(target, prop, path): any {
+ function checkList(target: any, prop: Prop, path: Path): any {
if (!Array.isArray(target)) {
throw new SchemaError(`array expected for ${path}, got ${typeof target} instead`);
}
@@ -77,7 +98,7 @@ export namespace Checkable {
}
- function checkOptional(target, prop, path): any {
+ function checkOptional(target: any, prop: Prop, path: Path): any {
console.assert(prop.propertyKey);
prop.elementChecker(target,
prop.elementProp,
@@ -86,7 +107,7 @@ export namespace Checkable {
}
- function checkValue(target, prop, path): any {
+ function checkValue(target: any, prop: Prop, path: Path): any {
let type = prop.type;
if (!type) {
throw Error(`assertion failed (prop is ${JSON.stringify(prop)})`);
@@ -123,8 +144,8 @@ export namespace Checkable {
}
- export function Class(target) {
- target.checked = (v) => {
+ export function Class(target: any) {
+ target.checked = (v: any) => {
return checkValue(v, {
propertyKey: "(root)",
type: target,
@@ -135,7 +156,7 @@ export namespace Checkable {
}
- export function Value(type) {
+ export function Value(type: any) {
if (!type) {
throw Error("Type does not exist yet (wrong order of definitions?)");
}
@@ -152,7 +173,7 @@ export namespace Checkable {
}
- export function List(type) {
+ export function List(type: any) {
let stub = {};
type(stub, "(list-element)");
let elementProp = mkChk(stub).props[0];
@@ -174,7 +195,7 @@ export namespace Checkable {
}
- export function Optional(type) {
+ export function Optional(type: any) {
let stub = {};
type(stub, "(optional-element)");
let elementProp = mkChk(stub).props[0];
@@ -230,7 +251,7 @@ export namespace Checkable {
}
- function mkChk(target) {
+ function mkChk(target: any) {
let chk = target[chkSym];
if (!chk) {
chk = {props: []};
diff --git a/lib/wallet/cryptoApi.ts b/lib/wallet/cryptoApi.ts
index a0113b2ea..2a2a7d319 100644
--- a/lib/wallet/cryptoApi.ts
+++ b/lib/wallet/cryptoApi.ts
@@ -27,9 +27,10 @@ import {Denomination} from "./types";
import {Offer} from "./wallet";
import {CoinWithDenom} from "./wallet";
import {PayCoinInfo} from "./types";
+type RegistryEntry = {resolve: any; reject: any};
export class CryptoApi {
private nextRpcId: number = 1;
- private rpcRegistry = {};
+ private rpcRegistry: {[n: number]: RegistryEntry} = {};
private cryptoWorker: Worker;
@@ -52,14 +53,14 @@ export class CryptoApi {
}
- private registerRpcId(resolve, reject): number {
+ private registerRpcId(resolve: any, reject: any): number {
let id = this.nextRpcId++;
this.rpcRegistry[id] = {resolve, reject};
return id;
}
- private doRpc<T>(methodName: string, ...args): Promise<T> {
+ private doRpc<T>(methodName: string, ...args: any[]): Promise<T> {
return new Promise<T>((resolve, reject) => {
let msg = {
operation: methodName,
diff --git a/lib/wallet/cryptoLib.ts b/lib/wallet/cryptoLib.ts
index 1acbdaa16..1ca7b856f 100644
--- a/lib/wallet/cryptoLib.ts
+++ b/lib/wallet/cryptoLib.ts
@@ -28,6 +28,7 @@ import {Offer} from "./wallet";
import {CoinWithDenom} from "./wallet";
import {CoinPaySig} from "./types";
import {Denomination} from "./types";
+import {Amount} from "./emscriptif";
export function main(worker: Worker) {
@@ -43,7 +44,7 @@ export function main(worker: Worker) {
if (typeof msg.data.operation != "string") {
console.error("RPC operation must be string");
}
- let f = RpcFunctions[msg.data.operation];
+ let f = (RpcFunctions as any)[msg.data.operation];
if (!f) {
console.error(`unknown operation: '${msg.data.operation}'`);
return;
@@ -156,7 +157,7 @@ namespace RpcFunctions {
}
- export function rsaUnblind(sig, bk, pk): string {
+ export function rsaUnblind(sig: string, bk: string, pk: string): string {
let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(sig),
native.RsaBlindingKeySecret.fromCrock(bk),
native.RsaPublicKey.fromCrock(pk));
@@ -170,11 +171,11 @@ namespace RpcFunctions {
*/
export function signDeposit(offer: Offer,
cds: CoinWithDenom[]): PayCoinInfo {
- let ret = [];
+ let ret: PayCoinInfo = [];
let amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency);
let amountRemaining = new native.Amount(offer.contract.amount);
for (let cd of cds) {
- let coinSpend;
+ let coinSpend: Amount;
if (amountRemaining.value == 0 && amountRemaining.fraction == 0) {
break;
diff --git a/lib/wallet/db.ts b/lib/wallet/db.ts
index 6cd25ee27..7fe635b9e 100644
--- a/lib/wallet/db.ts
+++ b/lib/wallet/db.ts
@@ -15,6 +15,7 @@
*/
"use strict";
+import Dictionary = _.Dictionary;
/**
* Declarations and helpers for
@@ -83,27 +84,27 @@ export function openTalerDb(): Promise<IDBDatabase> {
}
-export function exportDb(db): Promise<any> {
+export function exportDb(db: IDBDatabase): Promise<any> {
let dump = {
name: db.name,
version: db.version,
- stores: {}
+ stores: {} as Dictionary<any>,
};
return new Promise((resolve, reject) => {
let tx = db.transaction(db.objectStoreNames);
- tx.addEventListener("complete", (e) => {
+ tx.addEventListener("complete", () => {
resolve(dump);
});
for (let i = 0; i < db.objectStoreNames.length; i++) {
let name = db.objectStoreNames[i];
- let storeDump = {};
+ let storeDump = {} as Dictionary<any>;
dump.stores[name] = storeDump;
let store = tx.objectStore(name)
.openCursor()
- .addEventListener("success", (e) => {
- let cursor = e.target.result;
+ .addEventListener("success", (e: Event) => {
+ let cursor = (e.target as any).result;
if (cursor) {
storeDump[cursor.key] = cursor.value;
cursor.continue();
diff --git a/lib/wallet/emscriptif.ts b/lib/wallet/emscriptif.ts
index 8540d15d0..a12128666 100644
--- a/lib/wallet/emscriptif.ts
+++ b/lib/wallet/emscriptif.ts
@@ -36,11 +36,11 @@ const GNUNET_SYSERR = -1;
let Module = EmscWrapper.Module;
-let getEmsc: EmscWrapper.EmscFunGen = (...args) => Module.cwrap.apply(null,
+let getEmsc: EmscWrapper.EmscFunGen = (...args: any[]) => Module.cwrap.apply(null,
args);
var emsc = {
- free: (ptr) => Module._free(ptr),
+ free: (ptr: number) => Module._free(ptr),
get_value: getEmsc('TALER_WR_get_value',
'number',
['number']),
@@ -164,13 +164,12 @@ enum RandomQuality {
abstract class ArenaObject {
- private _nativePtr: number;
+ private _nativePtr: number | undefined = undefined;
arena: Arena;
abstract destroy(): void;
constructor(arena?: Arena) {
- this.nativePtr = null;
if (!arena) {
if (arenaStack.length == 0) {
throw Error("No arena available")
@@ -192,9 +191,9 @@ abstract class ArenaObject {
}
free() {
- if (this.nativePtr !== undefined) {
+ if (this.nativePtr) {
emsc.free(this.nativePtr);
- this.nativePtr = undefined;
+ this._nativePtr = undefined;
}
}
@@ -212,21 +211,22 @@ abstract class ArenaObject {
this._nativePtr = n;
}
- set nativePtr(v) {
+ set nativePtr(v: number) {
this.setNative(v);
}
get nativePtr() {
return this.getNative();
}
-
}
+
interface Arena {
put(obj: ArenaObject): void;
destroy(): void;
}
+
class DefaultArena implements Arena {
heap: Array<ArenaObject>;
@@ -234,7 +234,7 @@ class DefaultArena implements Arena {
this.heap = [];
}
- put(obj) {
+ put(obj: ArenaObject) {
this.heap.push(obj);
}
@@ -269,7 +269,7 @@ class SyncArena extends DefaultArena {
super();
}
- pub(obj) {
+ pub(obj: ArenaObject) {
super.put(obj);
if (!this.isScheduled) {
this.schedule();
@@ -308,14 +308,12 @@ export class Amount extends ArenaObject {
}
destroy() {
- if (this.nativePtr != 0) {
- emsc.free(this.nativePtr);
- }
+ super.free();
}
static getZero(currency: string, a?: Arena): Amount {
- let am = new Amount(null, a);
+ let am = new Amount(undefined, a);
let r = emsc.amount_get_zero(currency, am.getNative());
if (r != GNUNET_OK) {
throw Error("invalid currency");
@@ -442,7 +440,7 @@ abstract class PackedArenaObject extends ArenaObject {
}
alloc() {
- if (this.nativePtr === null) {
+ if (!this.nativePtr) {
this.nativePtr = emscAlloc.malloc(this.size());
}
}
@@ -466,7 +464,7 @@ abstract class PackedArenaObject extends ArenaObject {
b = (b + 256) % 256;
bytes.push("0".concat(b.toString(16)).slice(-2));
}
- let lines = [];
+ let lines: string[] = [];
for (let i = 0; i < bytes.length; i += 8) {
lines.push(bytes.slice(i, i + 8).join(","));
}
@@ -482,7 +480,7 @@ export class AmountNbo extends PackedArenaObject {
toJson(): any {
let a = new DefaultArena();
- let am = new Amount(null, a);
+ let am = new Amount(undefined, a);
am.fromNbo(this);
let json = am.toJson();
a.destroy();
@@ -508,7 +506,7 @@ export class EddsaPrivateKey extends PackedArenaObject {
return obj;
}
- static fromCrock: (string) => EddsaPrivateKey;
+ static fromCrock: (s: string) => EddsaPrivateKey;
}
mixinStatic(EddsaPrivateKey, fromCrock);
@@ -521,7 +519,7 @@ function fromCrock(s: string) {
}
-function mixin(obj, method, name?: string) {
+function mixin(obj: any, method: any, name?: string) {
if (!name) {
name = method.name;
}
@@ -532,7 +530,7 @@ function mixin(obj, method, name?: string) {
}
-function mixinStatic(obj, method, name?: string) {
+function mixinStatic(obj: any, method: any, name?: string) {
if (!name) {
name = method.name;
}
@@ -595,7 +593,7 @@ export class RsaBlindingKeySecret extends PackedArenaObject {
return o;
}
- static fromCrock: (string) => RsaBlindingKeySecret;
+ static fromCrock: (s: string) => RsaBlindingKeySecret;
}
mixinStatic(RsaBlindingKeySecret, fromCrock);
@@ -622,9 +620,9 @@ export class ByteArray extends PackedArenaObject {
return this.allocatedSize;
}
- constructor(desiredSize: number, init: number, a?: Arena) {
+ constructor(desiredSize: number, init?: number, a?: Arena) {
super(a);
- if (init === undefined || init === null) {
+ if (init === undefined) {
this.nativePtr = emscAlloc.malloc(desiredSize);
} else {
this.nativePtr = init;
@@ -642,7 +640,7 @@ export class ByteArray extends PackedArenaObject {
let hstr = emscAlloc.malloc(s.length + 1);
Module.writeStringToMemory(s, hstr);
let decodedLen = Math.floor((s.length * 5) / 8);
- let ba = new ByteArray(decodedLen, null, a);
+ let ba = new ByteArray(decodedLen, undefined, a);
let res = emsc.string_to_data(hstr, s.length, ba.nativePtr, decodedLen);
emsc.free(hstr);
if (res != GNUNET_OK) {
@@ -899,11 +897,11 @@ interface Encodeable {
encode(arena?: Arena): ByteArray;
}
-function makeEncode(encodeFn) {
+function makeEncode(encodeFn: any) {
function encode(arena?: Arena) {
let ptr = emscAlloc.malloc(PTR_SIZE);
let len = encodeFn(this.getNative(), ptr);
- let res = new ByteArray(len, null, arena);
+ let res = new ByteArray(len, undefined, arena);
res.setNative(Module.getValue(ptr, '*'));
emsc.free(ptr);
return res;
diff --git a/lib/wallet/helpers.ts b/lib/wallet/helpers.ts
index fd1650758..5d231fe64 100644
--- a/lib/wallet/helpers.ts
+++ b/lib/wallet/helpers.ts
@@ -24,7 +24,7 @@
import {AmountJson} from "./types";
-export function substituteFulfillmentUrl(url: string, vars) {
+export function substituteFulfillmentUrl(url: string, vars: any) {
url = url.replace("${H_contract}", vars.H_contract);
url = url.replace("${$}", "$");
return url;
@@ -42,7 +42,7 @@ export function amountToPretty(amount: AmountJson): string {
*
* See http://api.taler.net/wallet.html#general
*/
-export function canonicalizeBaseUrl(url) {
+export function canonicalizeBaseUrl(url: string) {
let x = new URI(url);
if (!x.protocol()) {
x.protocol("https");
@@ -54,10 +54,10 @@ export function canonicalizeBaseUrl(url) {
}
-export function parsePrettyAmount(pretty: string): AmountJson {
+export function parsePrettyAmount(pretty: string): AmountJson|undefined {
const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty);
if (!res) {
- return null;
+ return undefined;
}
return {
value: parseInt(res[1], 10),
diff --git a/lib/wallet/http.ts b/lib/wallet/http.ts
index 60f388e4b..8f82ceaff 100644
--- a/lib/wallet/http.ts
+++ b/lib/wallet/http.ts
@@ -66,19 +66,19 @@ export class BrowserHttpLib {
}
- postJson(url: string|uri.URI, body) {
+ postJson(url: string|uri.URI, body: any) {
return this.req("post", url, {req: JSON.stringify(body)});
}
- postForm(url: string|uri.URI, form) {
+ postForm(url: string|uri.URI, form: any) {
return this.req("post", url, {req: form});
}
}
export class RequestException {
- constructor(detail) {
+ constructor(detail: any) {
}
}
diff --git a/lib/wallet/types.ts b/lib/wallet/types.ts
index 2434dca32..e8b7a1e39 100644
--- a/lib/wallet/types.ts
+++ b/lib/wallet/types.ts
@@ -392,5 +392,5 @@ export interface CheckRepurchaseResult {
export interface Notifier {
- notify();
+ notify(): void;
}