From a04a9d0424564d942872ba1137eac413a169f0f2 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 10 Feb 2016 02:03:31 +0100 Subject: refactoring / cosmetic changes --- extension/background/main.ts | 10 +- extension/content_scripts/notify.js | 2 +- extension/content_scripts/notify.ts | 6 +- extension/gulpfile.js | 2 + extension/lib/decl/mithril.d.ts | 879 +++++++++++++++++++++++++++++ extension/lib/mithril.d.ts | 879 ----------------------------- extension/lib/wallet/emscriptif.ts | 2 +- extension/lib/wallet/types.ts | 200 ------- extension/lib/wallet/wallet.ts | 404 +++++++++---- extension/lib/wallet/wxmessaging.js | 28 +- extension/lib/wallet/wxmessaging.ts | 16 +- extension/lib/web-common.ts | 3 +- extension/manifest.json | 2 +- extension/pages/confirm-contract.js | 3 +- extension/pages/confirm-create-reserve.js | 16 +- extension/pages/confirm-create-reserve.tsx | 3 +- extension/popup/popup.tsx | 2 +- extension/tsconfig.json | 5 +- 18 files changed, 1223 insertions(+), 1239 deletions(-) create mode 100644 extension/lib/decl/mithril.d.ts delete mode 100644 extension/lib/mithril.d.ts delete mode 100644 extension/lib/wallet/types.ts diff --git a/extension/background/main.ts b/extension/background/main.ts index 7d607aa49..5fdee658e 100644 --- a/extension/background/main.ts +++ b/extension/background/main.ts @@ -20,16 +20,22 @@ "use strict"; +// TypeScript does not allow ".js" extensions in the +// module name, so SystemJS must add it. System.config({ defaultJSExtensions: true, }); -var Module: any; - +// We expect that in the manifest, the emscripten js is loaded +// becore the background page. +// Currently it is not possible to use SystemJS to load the emscripten js. +declare var Module: any; if ("object" !== typeof Module) { throw Error("emscripten not loaded, no 'Module' defined"); } +// Manually register the emscripten js as a SystemJS, so that +// we can use it from TypeScript by importing it. let mod = System.newModule({Module: Module}); let modName = System.normalizeSync("../lib/emscripten/emsc"); console.log("registering", modName); diff --git a/extension/content_scripts/notify.js b/extension/content_scripts/notify.js index 7791f86e1..e99dabc32 100644 --- a/extension/content_scripts/notify.js +++ b/extension/content_scripts/notify.js @@ -14,11 +14,11 @@ TALER; see the file COPYING. If not, If not, see */ /// +"use strict"; /** * Script that is injected into (all!) pages to allow them * to interact with the GNU Taler wallet via DOM Events. */ -"use strict"; // Make sure we don't pollute the namespace too much. var TalerNotify; (function (TalerNotify) { diff --git a/extension/content_scripts/notify.ts b/extension/content_scripts/notify.ts index c2dd5ab64..47f57b6a0 100644 --- a/extension/content_scripts/notify.ts +++ b/extension/content_scripts/notify.ts @@ -16,14 +16,14 @@ /// +"use strict"; + + /** * Script that is injected into (all!) pages to allow them * to interact with the GNU Taler wallet via DOM Events. */ - -"use strict"; - // Make sure we don't pollute the namespace too much. namespace TalerNotify { const PROTOCOL_VERSION = 1; diff --git a/extension/gulpfile.js b/extension/gulpfile.js index 9981de939..8017df684 100644 --- a/extension/gulpfile.js +++ b/extension/gulpfile.js @@ -71,6 +71,8 @@ const tsBaseArgs = { module: "system", sourceMap: true, noLib: true, + noImplicitReturns: true, + noFallthroughCasesInSwitch: true, }; diff --git a/extension/lib/decl/mithril.d.ts b/extension/lib/decl/mithril.d.ts new file mode 100644 index 000000000..d2646cbef --- /dev/null +++ b/extension/lib/decl/mithril.d.ts @@ -0,0 +1,879 @@ +// Mithril type definitions for Typescript + +/** + * This is the module containing all the types/declarations/etc. for Mithril + */ +declare interface MithrilStatic { + /** + * Creates a virtual element for use with m.render, m.mount, etc. + * + * @param selector A simple CSS selector. May include SVG tags. Nested + * selectors are not supported. + * @param attributes Attributes to add. Any DOM attribute may be used + * as an attribute, although innerHTML and the like may be overwritten + * silently. + * @param children Child elements, components, and text to add. + * @return A virtual element. + * + * @see m.render + * @see m.mount + * @see m.component + */ + (selector: string, + attributes: MithrilAttributes, + ...children: Array | + MithrilComponent>): MithrilVirtualElement; + + /** + * Initializes a component for use with m.render, m.mount, etc. + * + * @param component A component. + * @param args Arguments to optionally pass to the component. + * @return A component. + * + * @see m.render + * @see m.mount + * @see m + */ + (component: MithrilComponent, + ...args: any[]): MithrilComponent; + + /** + * Creates a virtual element for use with m.render, m.mount, etc. + * + * @param selector A simple CSS selector. Nested selectors are not + * supported. + * @param children Child elements, components, and text to add. + * @return A virtual element. + * + * @see m.render + * @see m.mount + * @see m.component + */ + (selector: string, + ...children: Array | + MithrilComponent>): MithrilVirtualElement; + + /** + * Initializes a component for use with m.render, m.mount, etc. + * Shorthand for m.component. + * + * @param selector A component. + * @param args Arguments to optionally pass to the component. + * @return A component. + * + * @see m.render + * @see m.mount + * @see m.component + */ + (component: MithrilComponent, + ...args: any[]): MithrilComponent; + + /** + * Creates a getter-setter function that wraps a Mithril promise. Useful + * for uniform data access, m.withAttr, etc. + * + * @param promise A thennable to initialize the property with. It may + * optionally be a Mithril promise. + * @return A getter-setter function wrapping the promise. + * + * @see m.withAttr + */ + prop(promise: Thennable) : MithrilPromiseProperty; + + /** + * Creates a getter-setter function that wraps a simple value. Useful + * for uniform data access, m.withAttr, etc. + * + * @param value A value to initialize the property with + * @return A getter-setter function wrapping the value. + * + * @see m.withAttr + */ + prop(value: T): MithrilBasicProperty; + + /** + * Creates a getter-setter function that wraps a simple value. Useful + * for uniform data access, m.withAttr, etc. + * + * @return A getter-setter function wrapping the value. + * + * @see m.withAttr + */ + prop(): MithrilBasicProperty; + + /** + * Returns a event handler that can be bound to an element, firing with + * the specified property. + * + * @param property The property to get from the event. + * @param callback The handler to use the value from the event. + * @return A function suitable for listening to an event. + */ + withAttr(property: string, + callback: (value: any) => void, + callbackThis: any): (e: Event) => any; + + /** + * @deprecated Use m.mount instead + */ + module(rootElement: Node, + component: MithrilComponent): T; + + /** + * Mounts a component to a base DOM node. + * + * @param rootElement The base node. + * @param component The component to mount. + * @return An instance of the top-level component's controller + */ + mount(rootElement: Node, + component: MithrilComponent): T; + + /** + * Initializes a component for use with m.render, m.mount, etc. + * + * @param selector A component. + * @param args Arguments to optionally pass to the component. + * @return A component. + * + * @see m.render + * @see m.mount + * @see m + */ + component(component: MithrilComponent, + ...args: any[]): MithrilComponent; + + /** + * Trust this string of HTML. + * + * @param html The HTML to trust + * @return A String object instance with an added internal flag to mark + * it as trusted. + */ + trust(html: string): MithrilTrustedString; + + /** + * Render a virtual DOM tree. + * + * @param rootElement The base element/node to render the tree from. + * @param children One or more child nodes to add to the tree. + * @param forceRecreation If true, overwrite the entire tree without + * diffing against it. + */ + render(rootElement: Element, + children: MithrilVirtualElement|MithrilVirtualElement[], + forceRecreation?: boolean): void; + + redraw: { + /** + * Force a redraw the active component. It redraws asynchronously by + * default to allow for simultaneous events to run before redrawing, + * such as the event combination keypress + input frequently used for + * input. + * + * @param force If true, redraw synchronously. + */ + (force?: boolean): void; + + strategy: { + /** + * Gets the current redraw strategy, which returns one of the + * following: + * + * "all" - recreates the DOM tree from scratch + * "diff" - recreates the DOM tree from scratch + * "none" - leaves the DOM tree intact + * + * This is useful for event handlers, which may want to cancel + * the next redraw if the event doesn't update the UI. + * + * @return The current strategy + */ + (): string; + + /** + * Sets the current redraw strategy. The parameter must be one of + * the following values: + * + * "all" - recreates the DOM tree from scratch + * "diff" - recreates the DOM tree from scratch + * "none" - leaves the DOM tree intact + * + * This is useful for event handlers, which may want to cancel + * the next redraw if the event doesn't update the UI. + * + * @param value The value to set + * @return The new strategy + */ + (value: string): string; + + /** + * @private + * Implementation detail - it's a MithrilBasicProperty instance + */ + toJSON(): string; + } + } + + route: { + /** + * Enable routing, mounting a controller based on the route. It + * automatically mounts the components for you, starting with the one + * specified by the default route. + * + * @param rootElement The element to mount the active controller to. + * @param defaultRoute The route to start with. + * @param routes A key-value mapping of pathname to controller. + */ + (rootElement: Element, + defaultRoute: string, + routes: MithrilRoutes): void; + + /** + * This allows m.route to be used as the `config` attribute for a + * virtual element, particularly useful for cases like this: + * + * ```ts + * // Note that the '#' is not required in `href`, thanks to the + * `config` setting. + * m("a[href='/dashboard/alicesmith']", {config: m.route}); + * ``` + */ + (element: Element, + isInitialized: boolean, + context?: MithrilContext, + vdom?: MithrilVirtualElement): void; + + /** + * Programmatically redirect to another route. + * + * @param path The route to go to. + * @param params Parameters to pass as a query string. + * @param shouldReplaceHistory Whether to replace the current history + * instead of adding a new one. + */ + (path: string, params?: any, shouldReplaceHistory?: boolean): void; + + /** + * Gets the current route. + * + * @return The current route. + */ + (): string; + + /** + * Gets a route parameter. + * + * @param key The key to get. + * @return The value associated with the parameter key. + */ + param(key: string): string; + + /** + * The current routing mode. This may be changed before calling + * m.route to change the part of the URL used to perform the routing. + * + * The value can be set to one of the following, defaulting to + * "hash": + * + * "search" - Uses the query string. This allows for named anchors to + * work on the page, but changes cause IE8 and lower to refresh the + * page. + * + * "hash" - Uses the hash. This is the only routing mode that does + * not cause page refreshes on any browser, but it does not support + * named anchors. + * + * "pathname" - Uses the URL pathname. This requires server-side + * setup to support bookmarking and page refreshes. It always causes + * page refreshes on IE8 and lower. Note that this requires that the + * application to be run from the root of the URL. + */ + mode: string; + + /** + * Serialize an object into a query string. + * + * @param data The data to serialize. + * @return The serialized string. + */ + buildQueryString(data: Object): String + + /** + * Parse a query string into an object. + * + * @param data The data to parse. + * @return The parsed object data. + */ + parseQueryString(data: String): Object + } + + /** + * Send a request to a server to server. Note that the `url` option is + * required. + * + * @param options The options to use + * @return A promise to the returned data for "GET" requests, or a void + * promise for any other request type. + * + * @see MithrilXHROptions for the available options. + */ + request(options: MithrilXHROptions): MithrilPromise; + + deferred: { + /** + * Create a Mithril deferred object. It behaves synchronously if + * possible, an intentional deviation from Promises/A+. Note that + * deferreds are completely separate from the redrawing system, and + * never trigger a redraw on their own. + * + * @return A new Mithril deferred instance. + * + * @see m.deferred.onerror for the error callback called for Error + * subclasses + */ + (): MithrilDeferred; + + /** + * A callback for all uncaught native Error subclasses in deferreds. + * This defaults to synchronously rethrowing all errors, a deviation + * from Promises/A+, but the behavior is configurable. To restore + * Promises/A+-compatible behavior. simply set this to a no-op. + */ + onerror(e: Error): void; + } + + /** + * Takes a list of promises or thennables and returns a Mithril promise + * that resolves once all in the list are resolved, or rejects if any of + * them reject. + * + * @param promises A list of promises to try to resolve. + * @return A promise that resolves to all the promises if all resolve, or + * rejects with the error contained in the first rejection. + */ + sync(promises: Thennable[]): MithrilPromise; + + /** + * Use this and endComputation if your views aren't redrawing after + * calls to third-party libraries. For integrating asynchronous code, + * this should be called before any asynchronous work is done. For + * synchronous code, this should be called at the beginning of the + * problematic segment. Note that these calls must be balanced, much like + * braces and parentheses. This is mostly used internally. Prefer + * m.redraw where possible, especially when making repeated calls. + * + * @see endComputation + * @see m.render + */ + startComputation(): void; + + /** + * Use startComputation and this if your views aren't redrawing after + * calls to third-party libraries. For integrating asynchronous code, + * this should be called after all asynchronous work completes. For + * synchronous code, this should be called at the end of the problematic + * segment. Note that these calls must be balanced, much like braces and + * parentheses. This is mostly used internally. Prefer m.redraw where + * possible, especially when making repeated calls. + * + * @see startComputation + * @see m.render + */ + endComputation(): void; + + /** + * This overwrites the internal version of window used by Mithril. + * It's mostly useful for testing, and is also used internally by + * Mithril to test itself. By default Mithril uses `window` for the + * dependency. + * + * @param mockWindow The mock to use for the window. + * @return The mock that was passed in. + */ + deps(mockWindow: Window): Window; +} + +interface MithrilTrustedString extends String { + /** @private Implementation detail. Don't depend on it. */ + $trusted: boolean; +} + +/** + * The interface for a virtual element. It's best to consider this immutable + * for most use cases. + * + * @see m + */ +interface MithrilVirtualElement { + /** + * A key to optionally associate with this element. + */ + key?: number; + + /** + * The tag name of this element. + */ + tag?: string; + + /** + * The attributes of this element. + */ + attrs?: MithrilAttributes; + + /** + * The children of this element. + */ + children?: Array|MithrilComponent>; +} + +/** + * An event passed by Mithril to unload event handlers. + */ +interface MithrilEvent { + /** + * Prevent the default behavior of scrolling the page and updating the + * URL on next route change. + */ + preventDefault(): void; +} + +/** + * A context object for configuration functions. + * + * @see MithrilElementConfig + */ +interface MithrilContext { + /** + * A function to call when the node is unloaded. Useful for cleanup. + */ + onunload?(): any; + + /** + * Set true if the backing DOM node needs to be retained between route + * changes if possible. Set false if this node needs to be recreated + * every single time, regardless of how "different" it is. + */ + retain?: boolean; +} + +/** + * This represents a callback function for a virtual element's config + * attribute. It's a low-level function useful for extra cleanup after + * removal from the tree, storing instances of third-party classes that + * need to be associated with the DOM, etc. + * + * @see MithrilAttributes + * @see MithrilContext + */ +interface MithrilElementConfig { + /** + * A callback function for a virtual element's config attribute. + * + * @param element The associated DOM element. + * @param isInitialized Whether this is the first call for the virtual + * element or not. + * @param context The associated context for this element. + * @param vdom The associated virtual element. + */ + (element: Element, + isInitialized: boolean, + context: MithrilContext, + vdom: MithrilVirtualElement): void; +} + +/** + * This represents the attributes available for configuring virtual elements, + * beyond the applicable DOM attributes. + * + * @see m + */ +interface MithrilAttributes { + /** + * The class name(s) for this virtual element, as a space-separated list. + */ + className?: string; + + /** + * The class name(s) for this virtual element, as a space-separated list. + */ + class?: string; + + /** + * A custom, low-level configuration in case this element needs special + * cleanup after removal from the tree. + * + * @see MithrilElementConfig + */ + config?: MithrilElementConfig; + + /** + * Any other virtual element properties including attributes and + * event handlers + */ + [property: string]: any; +} + +/** + * The basis of a Mithril controller instance. + */ +interface MithrilController { + /** + * An optional handler to call when the associated virtual element is + * destroyed. + * + * @param evt An associated event. + */ + onunload?(evt: MithrilEvent): any; +} + +/** + * This represents a controller function. + * + * @see MithrilControllerConstructor + */ +interface MithrilControllerFunction { + (): T; +} + +/** + * This represents a controller constructor. + * + * @see MithrilControllerFunction + */ +interface MithrilControllerConstructor { + new(): T; +} + +/** + * This represents a view factory. + */ +interface MithrilView { + /** + * Creates a view out of virtual elements. + */ + (ctrl: T): MithrilVirtualElement; +} + +/** + * This represents a Mithril component. + * + * @see m + * @see m.component + */ +interface MithrilComponent { + /** + * The component's controller. + * + * @see m.component + */ + controller?: MithrilControllerFunction | + MithrilControllerConstructor; + + /** + * Creates a view out of virtual elements. + * + * @see m.component + */ + view(ctrl: T): MithrilVirtualElement; +} + +/** + * This is the base interface for property getter-setters + * + * @see m.prop + */ +interface MithrilProperty { + /** + * Gets the contained value. + * + * @return The contained value. + */ + (): T; + + /** + * Sets the contained value. + * + * @param value The new value to set. + * @return The newly set value. + */ + (value: T): T; +} + +/** + * This represents a non-promise getter-setter functions. + * + * @see m.prop which returns objects that implement this interface. + */ +interface MithrilBasicProperty extends MithrilProperty { + /** + * Makes this serializable to JSON. + */ + toJSON(): T; +} + +/** + * This represents a promise getter-setter function. + * + * @see m.prop which returns objects that implement this interface. + */ +interface MithrilPromiseProperty extends MithrilPromise, + MithrilProperty> { + /** + * Gets the contained promise. + * + * @return The contained value. + */ + (): MithrilPromise; + + /** + * Sets the contained promise. + * + * @param value The new value to set. + * @return The newly set value. + */ + (value: MithrilPromise): MithrilPromise; + + /** + * Sets the contained wrapped value. + * + * @param value The new value to set. + * @return The newly set value. + */ + (value: T): MithrilPromise; +} + +/** + * This represents a key-value mapping linking routes to components. + */ +interface MithrilRoutes { + /** + * The key represents the route. The value represents the corresponding + * component. + */ + [key: string]: MithrilComponent; +} + +/** + * This represents a Mithril deferred object. + */ +interface MithrilDeferred { + /** + * Resolve this deferred's promise with a value. + * + * @param value The value to resolve the promise with. + */ + resolve(value?: T): void; + + /** + * Reject this deferred with an error. + * + * @param value The reason for rejecting the promise. + */ + reject(reason?: any): void; + + /** + * The backing promise. + * + * @see MithrilPromise + */ + promise: MithrilPromise; +} + +/** + * This represents a thennable success callback. + */ +interface MithrilSuccessCallback { + (value: T): U | Thennable; +} + +/** + * This represents a thennable error callback. + */ +interface MithrilErrorCallback { + (value: Error): T | Thennable; +} + +/** + * This represents a thennable. + */ +interface Thennable { + then(success: (value: T) => U): Thennable; + then(success: (value: T) => U, + error: (value: Error) => V): Thennable|Thennable; + catch?: (error: (value: Error) => U) => Thennable; +} + +/** + * This represents a Mithril promise object. + */ +interface MithrilPromise extends Thennable, MithrilProperty> { + /** + * Chain this promise with a simple success callback, propogating + * rejections. + * + * @param success The callback to call when the promise is resolved. + * @return The chained promise. + */ + then(success: MithrilSuccessCallback): MithrilPromise; + + /** + * Chain this promise with a success callback and error callback, without + * propogating rejections. + * + * @param success The callback to call when the promise is resolved. + * @param error The callback to call when the promise is rejected. + * @return The chained promise. + */ + then(success: MithrilSuccessCallback, + error: MithrilErrorCallback): MithrilPromise | MithrilPromise; + + /** + * Chain this promise with a single error callback, without propogating + * rejections. + * + * @param error The callback to call when the promise is rejected. + * @return The chained promise. + */ + catch(error: MithrilErrorCallback): MithrilPromise | + MithrilPromise; +} + +/** + * This represents the available options for configuring m.request. + * + * @see m.request + */ +interface MithrilXHROptions { + /** + * This represents the HTTP method used, one of the following: + * + * - "GET" (default) + * - "POST" + * - "PUT" + * - "DELETE" + * - "HEAD" + * - "OPTIONS" + */ + method?: string; + + /** + * The URL to send the request to. + */ + url: string; + + /** + * The username for HTTP authentication. + */ + user?: string; + + /** + * The password for HTTP authentication. + */ + password?: string; + + /** + * The data to be sent. It's automatically serialized in the right format + * depending on the method (with exception of HTML5 FormData), and put in + * the appropriate section of the request. + */ + data?: any; + + /** + * Whether to run it in the background, i.e. true if it doesn't affect + * template rendering. + */ + background?: boolean; + + /** + * Set an initial value while the request is working, to populate the + * promise getter-setter. + */ + initialValue?: T; + + /** + * An optional preprocessor function to unwrap a successful response, in + * case the response contains metadata wrapping the data. + * + * @param data The data to unwrap. + * @return The unwrapped result. + */ + unwrapSuccess?(data: any): T; + + /** + * An optional preprocessor function to unwrap an unsuccessful response, + * in case the response contains metadata wrapping the data. + * + * @param data The data to unwrap. + * @return The unwrapped result. + */ + unwrapError?(data: any): T; + + /** + * An optional function to serialize the data. This defaults to + * `JSON.stringify`. + * + * @param dataToSerialize The data to serialize. + * @return The serialized form as a string. + */ + serialize?(dataToSerialize: any): string; + + /** + * An optional function to deserialize the data. This defaults to + * `JSON.parse`. + * + * @param dataToSerialize The data to parse. + * @return The parsed form. + */ + deserialize?(dataToDeserialize: string): any; + + /** + * An optional function to extract the data from a raw XMLHttpRequest, + * useful if the relevant data is in a response header or the status + * field. + * + * @param xhr The associated XMLHttpRequest. + * @param options The options passed to this request. + * @return string The serialized format. + */ + extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; + + /** + * The parsed data, or its children if it's an array, will be passed to + * this class constructor if it's given, to parse it into classes. + * + * @param data The data to parse. + * @return The new instance for the list. + */ + type?: new (data: Object) => any; + + /** + * An optional function to run between `open` and `send`, useful for + * adding request headers or using XHR2 features such as the `upload` + * property. It is even possible to override the XHR altogether with a + * similar object, such as an XDomainRequest instance. + * + * @param xhr The associated XMLHttpRequest. + * @param options The options passed to this request. + * @return The new XMLHttpRequest, or nothing if the same one is kept. + */ + config?(xhr: XMLHttpRequest, options: MithrilXHROptions): any; + + /** + * For JSONP requests, this must be the string "jsonp". Otherwise, it's + * ignored. + */ + dataType?: string; + + /** + * For JSONP requests, this is the query string key for the JSONP + * request. This is useful for APIs that don't use common conventions, + * such as `www.example.com/?jsonpCallback=doSomething`. It defaults to + * `callback` for JSONP requests, and is ignored for any other kind of + * request. + */ + callbackKey?: string; +} diff --git a/extension/lib/mithril.d.ts b/extension/lib/mithril.d.ts deleted file mode 100644 index d2646cbef..000000000 --- a/extension/lib/mithril.d.ts +++ /dev/null @@ -1,879 +0,0 @@ -// Mithril type definitions for Typescript - -/** - * This is the module containing all the types/declarations/etc. for Mithril - */ -declare interface MithrilStatic { - /** - * Creates a virtual element for use with m.render, m.mount, etc. - * - * @param selector A simple CSS selector. May include SVG tags. Nested - * selectors are not supported. - * @param attributes Attributes to add. Any DOM attribute may be used - * as an attribute, although innerHTML and the like may be overwritten - * silently. - * @param children Child elements, components, and text to add. - * @return A virtual element. - * - * @see m.render - * @see m.mount - * @see m.component - */ - (selector: string, - attributes: MithrilAttributes, - ...children: Array | - MithrilComponent>): MithrilVirtualElement; - - /** - * Initializes a component for use with m.render, m.mount, etc. - * - * @param component A component. - * @param args Arguments to optionally pass to the component. - * @return A component. - * - * @see m.render - * @see m.mount - * @see m - */ - (component: MithrilComponent, - ...args: any[]): MithrilComponent; - - /** - * Creates a virtual element for use with m.render, m.mount, etc. - * - * @param selector A simple CSS selector. Nested selectors are not - * supported. - * @param children Child elements, components, and text to add. - * @return A virtual element. - * - * @see m.render - * @see m.mount - * @see m.component - */ - (selector: string, - ...children: Array | - MithrilComponent>): MithrilVirtualElement; - - /** - * Initializes a component for use with m.render, m.mount, etc. - * Shorthand for m.component. - * - * @param selector A component. - * @param args Arguments to optionally pass to the component. - * @return A component. - * - * @see m.render - * @see m.mount - * @see m.component - */ - (component: MithrilComponent, - ...args: any[]): MithrilComponent; - - /** - * Creates a getter-setter function that wraps a Mithril promise. Useful - * for uniform data access, m.withAttr, etc. - * - * @param promise A thennable to initialize the property with. It may - * optionally be a Mithril promise. - * @return A getter-setter function wrapping the promise. - * - * @see m.withAttr - */ - prop(promise: Thennable) : MithrilPromiseProperty; - - /** - * Creates a getter-setter function that wraps a simple value. Useful - * for uniform data access, m.withAttr, etc. - * - * @param value A value to initialize the property with - * @return A getter-setter function wrapping the value. - * - * @see m.withAttr - */ - prop(value: T): MithrilBasicProperty; - - /** - * Creates a getter-setter function that wraps a simple value. Useful - * for uniform data access, m.withAttr, etc. - * - * @return A getter-setter function wrapping the value. - * - * @see m.withAttr - */ - prop(): MithrilBasicProperty; - - /** - * Returns a event handler that can be bound to an element, firing with - * the specified property. - * - * @param property The property to get from the event. - * @param callback The handler to use the value from the event. - * @return A function suitable for listening to an event. - */ - withAttr(property: string, - callback: (value: any) => void, - callbackThis: any): (e: Event) => any; - - /** - * @deprecated Use m.mount instead - */ - module(rootElement: Node, - component: MithrilComponent): T; - - /** - * Mounts a component to a base DOM node. - * - * @param rootElement The base node. - * @param component The component to mount. - * @return An instance of the top-level component's controller - */ - mount(rootElement: Node, - component: MithrilComponent): T; - - /** - * Initializes a component for use with m.render, m.mount, etc. - * - * @param selector A component. - * @param args Arguments to optionally pass to the component. - * @return A component. - * - * @see m.render - * @see m.mount - * @see m - */ - component(component: MithrilComponent, - ...args: any[]): MithrilComponent; - - /** - * Trust this string of HTML. - * - * @param html The HTML to trust - * @return A String object instance with an added internal flag to mark - * it as trusted. - */ - trust(html: string): MithrilTrustedString; - - /** - * Render a virtual DOM tree. - * - * @param rootElement The base element/node to render the tree from. - * @param children One or more child nodes to add to the tree. - * @param forceRecreation If true, overwrite the entire tree without - * diffing against it. - */ - render(rootElement: Element, - children: MithrilVirtualElement|MithrilVirtualElement[], - forceRecreation?: boolean): void; - - redraw: { - /** - * Force a redraw the active component. It redraws asynchronously by - * default to allow for simultaneous events to run before redrawing, - * such as the event combination keypress + input frequently used for - * input. - * - * @param force If true, redraw synchronously. - */ - (force?: boolean): void; - - strategy: { - /** - * Gets the current redraw strategy, which returns one of the - * following: - * - * "all" - recreates the DOM tree from scratch - * "diff" - recreates the DOM tree from scratch - * "none" - leaves the DOM tree intact - * - * This is useful for event handlers, which may want to cancel - * the next redraw if the event doesn't update the UI. - * - * @return The current strategy - */ - (): string; - - /** - * Sets the current redraw strategy. The parameter must be one of - * the following values: - * - * "all" - recreates the DOM tree from scratch - * "diff" - recreates the DOM tree from scratch - * "none" - leaves the DOM tree intact - * - * This is useful for event handlers, which may want to cancel - * the next redraw if the event doesn't update the UI. - * - * @param value The value to set - * @return The new strategy - */ - (value: string): string; - - /** - * @private - * Implementation detail - it's a MithrilBasicProperty instance - */ - toJSON(): string; - } - } - - route: { - /** - * Enable routing, mounting a controller based on the route. It - * automatically mounts the components for you, starting with the one - * specified by the default route. - * - * @param rootElement The element to mount the active controller to. - * @param defaultRoute The route to start with. - * @param routes A key-value mapping of pathname to controller. - */ - (rootElement: Element, - defaultRoute: string, - routes: MithrilRoutes): void; - - /** - * This allows m.route to be used as the `config` attribute for a - * virtual element, particularly useful for cases like this: - * - * ```ts - * // Note that the '#' is not required in `href`, thanks to the - * `config` setting. - * m("a[href='/dashboard/alicesmith']", {config: m.route}); - * ``` - */ - (element: Element, - isInitialized: boolean, - context?: MithrilContext, - vdom?: MithrilVirtualElement): void; - - /** - * Programmatically redirect to another route. - * - * @param path The route to go to. - * @param params Parameters to pass as a query string. - * @param shouldReplaceHistory Whether to replace the current history - * instead of adding a new one. - */ - (path: string, params?: any, shouldReplaceHistory?: boolean): void; - - /** - * Gets the current route. - * - * @return The current route. - */ - (): string; - - /** - * Gets a route parameter. - * - * @param key The key to get. - * @return The value associated with the parameter key. - */ - param(key: string): string; - - /** - * The current routing mode. This may be changed before calling - * m.route to change the part of the URL used to perform the routing. - * - * The value can be set to one of the following, defaulting to - * "hash": - * - * "search" - Uses the query string. This allows for named anchors to - * work on the page, but changes cause IE8 and lower to refresh the - * page. - * - * "hash" - Uses the hash. This is the only routing mode that does - * not cause page refreshes on any browser, but it does not support - * named anchors. - * - * "pathname" - Uses the URL pathname. This requires server-side - * setup to support bookmarking and page refreshes. It always causes - * page refreshes on IE8 and lower. Note that this requires that the - * application to be run from the root of the URL. - */ - mode: string; - - /** - * Serialize an object into a query string. - * - * @param data The data to serialize. - * @return The serialized string. - */ - buildQueryString(data: Object): String - - /** - * Parse a query string into an object. - * - * @param data The data to parse. - * @return The parsed object data. - */ - parseQueryString(data: String): Object - } - - /** - * Send a request to a server to server. Note that the `url` option is - * required. - * - * @param options The options to use - * @return A promise to the returned data for "GET" requests, or a void - * promise for any other request type. - * - * @see MithrilXHROptions for the available options. - */ - request(options: MithrilXHROptions): MithrilPromise; - - deferred: { - /** - * Create a Mithril deferred object. It behaves synchronously if - * possible, an intentional deviation from Promises/A+. Note that - * deferreds are completely separate from the redrawing system, and - * never trigger a redraw on their own. - * - * @return A new Mithril deferred instance. - * - * @see m.deferred.onerror for the error callback called for Error - * subclasses - */ - (): MithrilDeferred; - - /** - * A callback for all uncaught native Error subclasses in deferreds. - * This defaults to synchronously rethrowing all errors, a deviation - * from Promises/A+, but the behavior is configurable. To restore - * Promises/A+-compatible behavior. simply set this to a no-op. - */ - onerror(e: Error): void; - } - - /** - * Takes a list of promises or thennables and returns a Mithril promise - * that resolves once all in the list are resolved, or rejects if any of - * them reject. - * - * @param promises A list of promises to try to resolve. - * @return A promise that resolves to all the promises if all resolve, or - * rejects with the error contained in the first rejection. - */ - sync(promises: Thennable[]): MithrilPromise; - - /** - * Use this and endComputation if your views aren't redrawing after - * calls to third-party libraries. For integrating asynchronous code, - * this should be called before any asynchronous work is done. For - * synchronous code, this should be called at the beginning of the - * problematic segment. Note that these calls must be balanced, much like - * braces and parentheses. This is mostly used internally. Prefer - * m.redraw where possible, especially when making repeated calls. - * - * @see endComputation - * @see m.render - */ - startComputation(): void; - - /** - * Use startComputation and this if your views aren't redrawing after - * calls to third-party libraries. For integrating asynchronous code, - * this should be called after all asynchronous work completes. For - * synchronous code, this should be called at the end of the problematic - * segment. Note that these calls must be balanced, much like braces and - * parentheses. This is mostly used internally. Prefer m.redraw where - * possible, especially when making repeated calls. - * - * @see startComputation - * @see m.render - */ - endComputation(): void; - - /** - * This overwrites the internal version of window used by Mithril. - * It's mostly useful for testing, and is also used internally by - * Mithril to test itself. By default Mithril uses `window` for the - * dependency. - * - * @param mockWindow The mock to use for the window. - * @return The mock that was passed in. - */ - deps(mockWindow: Window): Window; -} - -interface MithrilTrustedString extends String { - /** @private Implementation detail. Don't depend on it. */ - $trusted: boolean; -} - -/** - * The interface for a virtual element. It's best to consider this immutable - * for most use cases. - * - * @see m - */ -interface MithrilVirtualElement { - /** - * A key to optionally associate with this element. - */ - key?: number; - - /** - * The tag name of this element. - */ - tag?: string; - - /** - * The attributes of this element. - */ - attrs?: MithrilAttributes; - - /** - * The children of this element. - */ - children?: Array|MithrilComponent>; -} - -/** - * An event passed by Mithril to unload event handlers. - */ -interface MithrilEvent { - /** - * Prevent the default behavior of scrolling the page and updating the - * URL on next route change. - */ - preventDefault(): void; -} - -/** - * A context object for configuration functions. - * - * @see MithrilElementConfig - */ -interface MithrilContext { - /** - * A function to call when the node is unloaded. Useful for cleanup. - */ - onunload?(): any; - - /** - * Set true if the backing DOM node needs to be retained between route - * changes if possible. Set false if this node needs to be recreated - * every single time, regardless of how "different" it is. - */ - retain?: boolean; -} - -/** - * This represents a callback function for a virtual element's config - * attribute. It's a low-level function useful for extra cleanup after - * removal from the tree, storing instances of third-party classes that - * need to be associated with the DOM, etc. - * - * @see MithrilAttributes - * @see MithrilContext - */ -interface MithrilElementConfig { - /** - * A callback function for a virtual element's config attribute. - * - * @param element The associated DOM element. - * @param isInitialized Whether this is the first call for the virtual - * element or not. - * @param context The associated context for this element. - * @param vdom The associated virtual element. - */ - (element: Element, - isInitialized: boolean, - context: MithrilContext, - vdom: MithrilVirtualElement): void; -} - -/** - * This represents the attributes available for configuring virtual elements, - * beyond the applicable DOM attributes. - * - * @see m - */ -interface MithrilAttributes { - /** - * The class name(s) for this virtual element, as a space-separated list. - */ - className?: string; - - /** - * The class name(s) for this virtual element, as a space-separated list. - */ - class?: string; - - /** - * A custom, low-level configuration in case this element needs special - * cleanup after removal from the tree. - * - * @see MithrilElementConfig - */ - config?: MithrilElementConfig; - - /** - * Any other virtual element properties including attributes and - * event handlers - */ - [property: string]: any; -} - -/** - * The basis of a Mithril controller instance. - */ -interface MithrilController { - /** - * An optional handler to call when the associated virtual element is - * destroyed. - * - * @param evt An associated event. - */ - onunload?(evt: MithrilEvent): any; -} - -/** - * This represents a controller function. - * - * @see MithrilControllerConstructor - */ -interface MithrilControllerFunction { - (): T; -} - -/** - * This represents a controller constructor. - * - * @see MithrilControllerFunction - */ -interface MithrilControllerConstructor { - new(): T; -} - -/** - * This represents a view factory. - */ -interface MithrilView { - /** - * Creates a view out of virtual elements. - */ - (ctrl: T): MithrilVirtualElement; -} - -/** - * This represents a Mithril component. - * - * @see m - * @see m.component - */ -interface MithrilComponent { - /** - * The component's controller. - * - * @see m.component - */ - controller?: MithrilControllerFunction | - MithrilControllerConstructor; - - /** - * Creates a view out of virtual elements. - * - * @see m.component - */ - view(ctrl: T): MithrilVirtualElement; -} - -/** - * This is the base interface for property getter-setters - * - * @see m.prop - */ -interface MithrilProperty { - /** - * Gets the contained value. - * - * @return The contained value. - */ - (): T; - - /** - * Sets the contained value. - * - * @param value The new value to set. - * @return The newly set value. - */ - (value: T): T; -} - -/** - * This represents a non-promise getter-setter functions. - * - * @see m.prop which returns objects that implement this interface. - */ -interface MithrilBasicProperty extends MithrilProperty { - /** - * Makes this serializable to JSON. - */ - toJSON(): T; -} - -/** - * This represents a promise getter-setter function. - * - * @see m.prop which returns objects that implement this interface. - */ -interface MithrilPromiseProperty extends MithrilPromise, - MithrilProperty> { - /** - * Gets the contained promise. - * - * @return The contained value. - */ - (): MithrilPromise; - - /** - * Sets the contained promise. - * - * @param value The new value to set. - * @return The newly set value. - */ - (value: MithrilPromise): MithrilPromise; - - /** - * Sets the contained wrapped value. - * - * @param value The new value to set. - * @return The newly set value. - */ - (value: T): MithrilPromise; -} - -/** - * This represents a key-value mapping linking routes to components. - */ -interface MithrilRoutes { - /** - * The key represents the route. The value represents the corresponding - * component. - */ - [key: string]: MithrilComponent; -} - -/** - * This represents a Mithril deferred object. - */ -interface MithrilDeferred { - /** - * Resolve this deferred's promise with a value. - * - * @param value The value to resolve the promise with. - */ - resolve(value?: T): void; - - /** - * Reject this deferred with an error. - * - * @param value The reason for rejecting the promise. - */ - reject(reason?: any): void; - - /** - * The backing promise. - * - * @see MithrilPromise - */ - promise: MithrilPromise; -} - -/** - * This represents a thennable success callback. - */ -interface MithrilSuccessCallback { - (value: T): U | Thennable; -} - -/** - * This represents a thennable error callback. - */ -interface MithrilErrorCallback { - (value: Error): T | Thennable; -} - -/** - * This represents a thennable. - */ -interface Thennable { - then(success: (value: T) => U): Thennable; - then(success: (value: T) => U, - error: (value: Error) => V): Thennable|Thennable; - catch?: (error: (value: Error) => U) => Thennable; -} - -/** - * This represents a Mithril promise object. - */ -interface MithrilPromise extends Thennable, MithrilProperty> { - /** - * Chain this promise with a simple success callback, propogating - * rejections. - * - * @param success The callback to call when the promise is resolved. - * @return The chained promise. - */ - then(success: MithrilSuccessCallback): MithrilPromise; - - /** - * Chain this promise with a success callback and error callback, without - * propogating rejections. - * - * @param success The callback to call when the promise is resolved. - * @param error The callback to call when the promise is rejected. - * @return The chained promise. - */ - then(success: MithrilSuccessCallback, - error: MithrilErrorCallback): MithrilPromise | MithrilPromise; - - /** - * Chain this promise with a single error callback, without propogating - * rejections. - * - * @param error The callback to call when the promise is rejected. - * @return The chained promise. - */ - catch(error: MithrilErrorCallback): MithrilPromise | - MithrilPromise; -} - -/** - * This represents the available options for configuring m.request. - * - * @see m.request - */ -interface MithrilXHROptions { - /** - * This represents the HTTP method used, one of the following: - * - * - "GET" (default) - * - "POST" - * - "PUT" - * - "DELETE" - * - "HEAD" - * - "OPTIONS" - */ - method?: string; - - /** - * The URL to send the request to. - */ - url: string; - - /** - * The username for HTTP authentication. - */ - user?: string; - - /** - * The password for HTTP authentication. - */ - password?: string; - - /** - * The data to be sent. It's automatically serialized in the right format - * depending on the method (with exception of HTML5 FormData), and put in - * the appropriate section of the request. - */ - data?: any; - - /** - * Whether to run it in the background, i.e. true if it doesn't affect - * template rendering. - */ - background?: boolean; - - /** - * Set an initial value while the request is working, to populate the - * promise getter-setter. - */ - initialValue?: T; - - /** - * An optional preprocessor function to unwrap a successful response, in - * case the response contains metadata wrapping the data. - * - * @param data The data to unwrap. - * @return The unwrapped result. - */ - unwrapSuccess?(data: any): T; - - /** - * An optional preprocessor function to unwrap an unsuccessful response, - * in case the response contains metadata wrapping the data. - * - * @param data The data to unwrap. - * @return The unwrapped result. - */ - unwrapError?(data: any): T; - - /** - * An optional function to serialize the data. This defaults to - * `JSON.stringify`. - * - * @param dataToSerialize The data to serialize. - * @return The serialized form as a string. - */ - serialize?(dataToSerialize: any): string; - - /** - * An optional function to deserialize the data. This defaults to - * `JSON.parse`. - * - * @param dataToSerialize The data to parse. - * @return The parsed form. - */ - deserialize?(dataToDeserialize: string): any; - - /** - * An optional function to extract the data from a raw XMLHttpRequest, - * useful if the relevant data is in a response header or the status - * field. - * - * @param xhr The associated XMLHttpRequest. - * @param options The options passed to this request. - * @return string The serialized format. - */ - extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; - - /** - * The parsed data, or its children if it's an array, will be passed to - * this class constructor if it's given, to parse it into classes. - * - * @param data The data to parse. - * @return The new instance for the list. - */ - type?: new (data: Object) => any; - - /** - * An optional function to run between `open` and `send`, useful for - * adding request headers or using XHR2 features such as the `upload` - * property. It is even possible to override the XHR altogether with a - * similar object, such as an XDomainRequest instance. - * - * @param xhr The associated XMLHttpRequest. - * @param options The options passed to this request. - * @return The new XMLHttpRequest, or nothing if the same one is kept. - */ - config?(xhr: XMLHttpRequest, options: MithrilXHROptions): any; - - /** - * For JSONP requests, this must be the string "jsonp". Otherwise, it's - * ignored. - */ - dataType?: string; - - /** - * For JSONP requests, this is the query string key for the JSONP - * request. This is useful for APIs that don't use common conventions, - * such as `www.example.com/?jsonpCallback=doSomething`. It defaults to - * `callback` for JSONP requests, and is ignored for any other kind of - * request. - */ - callbackKey?: string; -} diff --git a/extension/lib/wallet/emscriptif.ts b/extension/lib/wallet/emscriptif.ts index b11d845f0..16c883451 100644 --- a/extension/lib/wallet/emscriptif.ts +++ b/extension/lib/wallet/emscriptif.ts @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, If not, see */ -import {AmountJson} from "./types"; +import {AmountJson} from "./wallet"; import * as EmscWrapper from "../emscripten/emsc"; /** diff --git a/extension/lib/wallet/types.ts b/extension/lib/wallet/types.ts deleted file mode 100644 index 4f512800e..000000000 --- a/extension/lib/wallet/types.ts +++ /dev/null @@ -1,200 +0,0 @@ -/* - This file is part of TALER - (C) 2016 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, If not, see - */ - -import {EddsaPublicKey} from "./emscriptif"; -import {Checkable} from "./checkable"; -"use strict"; - -// TODO: factor into multiple files - -export interface Mint { - baseUrl: string; - keys: Keys -} - -export interface CoinWithDenom { - coin: Coin; - denom: Denomination; -} - -export interface Keys { - denoms: Denomination[]; -} - -export interface Denomination { - value: AmountJson; - denom_pub: string; - fee_withdraw: AmountJson; - fee_deposit: AmountJson; -} - -export interface PreCoin { - coinPub: string; - coinPriv: string; - reservePub: string; - denomPub: string; - blindingKey: string; - withdrawSig: string; - coinEv: string; - mintBaseUrl: string; - coinValue: AmountJson; -} - -export interface Coin { - coinPub: string; - coinPriv: string; - denomPub: string; - denomSig: string; - currentAmount: AmountJson; - mintBaseUrl: string; -} - - -@Checkable.Class -export class AmountJson { - @Checkable.Number - value: number; - - @Checkable.Number - fraction: number; - - @Checkable.String - currency: string; - - static checked: (obj: any) => AmountJson; -} - - -@Checkable.Class -export class CreateReserveRequest { - /** - * The initial amount for the reserve. - */ - @Checkable.Value(AmountJson) - amount: AmountJson; - - /** - * Mint URL where the bank should create the reserve. - */ - @Checkable.String - mint: string; - - static checked: (obj: any) => CreateReserveRequest; -} - - -@Checkable.Class -export class CreateReserveResponse { - /** - * Mint URL where the bank should create the reserve. - * The URL is canonicalized in the response. - */ - @Checkable.String - mint: string; - - @Checkable.String - reservePub: string; - - static checked: (obj: any) => CreateReserveResponse; -} - - -@Checkable.Class -export class ConfirmReserveRequest { - /** - * Public key of then reserve that should be marked - * as confirmed. - */ - @Checkable.String - reservePub: string; - - static checked: (obj: any) => ConfirmReserveRequest; -} - - -@Checkable.Class -export class MintInfo { - @Checkable.String - master_pub: string; - - @Checkable.String - url: string; - - static checked: (obj: any) => MintInfo; -} - - -@Checkable.Class -export class Contract { - @Checkable.String - H_wire: string; - - @Checkable.Value(AmountJson) - amount: AmountJson; - - @Checkable.List(Checkable.AnyObject) - auditors: any[]; - - @Checkable.String - expiry: string; - - @Checkable.Any - locations: any; - - @Checkable.Value(AmountJson) - max_fee: AmountJson; - - @Checkable.Any - merchant: any; - - @Checkable.String - merchant_pub: string; - - @Checkable.List(Checkable.Value(MintInfo)) - mints: MintInfo[]; - - @Checkable.List(Checkable.AnyObject) - products: any[]; - - @Checkable.String - refund_deadline: string; - - @Checkable.String - timestamp: string; - - @Checkable.Number - transaction_id: number; - - @Checkable.String - fulfillment_url: string; - - static checked: (obj: any) => Contract; -} - - -@Checkable.Class -export class Offer { - @Checkable.Value(Contract) - contract: Contract; - - @Checkable.String - merchant_sig: string; - - @Checkable.String - H_contract: string; - - static checked: (obj: any) => Offer; -} \ No newline at end of file diff --git a/extension/lib/wallet/wallet.ts b/extension/lib/wallet/wallet.ts index 62d67b40c..0a9fbe191 100644 --- a/extension/lib/wallet/wallet.ts +++ b/extension/lib/wallet/wallet.ts @@ -21,41 +21,195 @@ * @author Florian Dold */ -import {Amount} from "./emscriptif" -import {CoinWithDenom} from "./types"; -import {DepositRequestPS_Args} from "./emscriptif"; -import {HashCode} from "./emscriptif"; -import {EddsaPublicKey} from "./emscriptif"; -import {Coin} from "./types"; -import {AbsoluteTimeNbo} from "./emscriptif"; -import {UInt64} from "./emscriptif"; -import {DepositRequestPS} from "./emscriptif"; -import {eddsaSign} from "./emscriptif"; -import {EddsaPrivateKey} from "./emscriptif"; -import {CreateReserveRequest} from "./types"; -import {RsaPublicKey} from "./emscriptif"; -import {Denomination} from "./types"; -import {RsaBlindingKey} from "./emscriptif"; -import {ByteArray} from "./emscriptif"; -import {rsaBlind} from "./emscriptif"; -import {WithdrawRequestPS} from "./emscriptif"; -import {PreCoin} from "./types"; -import {rsaUnblind} from "./emscriptif"; -import {RsaSignature} from "./emscriptif"; -import {Mint} from "./types"; -import {HttpResponse} from "./http"; -import {RequestException} from "./http"; +import * as native from "./emscriptif"; +import {HttpResponse, RequestException} from "./http"; import {Query} from "./query"; -import {AmountJson} from "./types"; -import {ConfirmReserveRequest} from "./types"; -import {Offer} from "./types"; -import {Contract} from "./types"; -import {MintInfo} from "./types"; -import {CreateReserveResponse} from "./types"; +import {Checkable} from "./checkable"; "use strict"; +export interface Mint { + baseUrl: string; + keys: Keys +} + +export interface CoinWithDenom { + coin: Coin; + denom: Denomination; +} + +export interface Keys { + denoms: Denomination[]; +} + +export interface Denomination { + value: AmountJson; + denom_pub: string; + fee_withdraw: AmountJson; + fee_deposit: AmountJson; + stamp_expire_withdraw: string; +} + +export interface PreCoin { + coinPub: string; + coinPriv: string; + reservePub: string; + denomPub: string; + blindingKey: string; + withdrawSig: string; + coinEv: string; + mintBaseUrl: string; + coinValue: AmountJson; +} + +export interface Coin { + coinPub: string; + coinPriv: string; + denomPub: string; + denomSig: string; + currentAmount: AmountJson; + mintBaseUrl: string; +} + + +@Checkable.Class +export class AmountJson { + @Checkable.Number + value: number; + + @Checkable.Number + fraction: number; + + @Checkable.String + currency: string; + + static checked: (obj: any) => AmountJson; +} + + +@Checkable.Class +export class CreateReserveRequest { + /** + * The initial amount for the reserve. + */ + @Checkable.Value(AmountJson) + amount: AmountJson; + + /** + * Mint URL where the bank should create the reserve. + */ + @Checkable.String + mint: string; + + static checked: (obj: any) => CreateReserveRequest; +} + + +@Checkable.Class +export class CreateReserveResponse { + /** + * Mint URL where the bank should create the reserve. + * The URL is canonicalized in the response. + */ + @Checkable.String + mint: string; + + @Checkable.String + reservePub: string; + + static checked: (obj: any) => CreateReserveResponse; +} + + +@Checkable.Class +export class ConfirmReserveRequest { + /** + * Public key of then reserve that should be marked + * as confirmed. + */ + @Checkable.String + reservePub: string; + + static checked: (obj: any) => ConfirmReserveRequest; +} + + +@Checkable.Class +export class MintInfo { + @Checkable.String + master_pub: string; + + @Checkable.String + url: string; + + static checked: (obj: any) => MintInfo; +} + + +@Checkable.Class +export class Contract { + @Checkable.String + H_wire: string; + + @Checkable.Value(AmountJson) + amount: AmountJson; + + @Checkable.List(Checkable.AnyObject) + auditors: any[]; + + @Checkable.String + expiry: string; + + @Checkable.Any + locations: any; + + @Checkable.Value(AmountJson) + max_fee: AmountJson; + + @Checkable.Any + merchant: any; + + @Checkable.String + merchant_pub: string; + + @Checkable.List(Checkable.Value(MintInfo)) + mints: MintInfo[]; + + @Checkable.List(Checkable.AnyObject) + products: any[]; + + @Checkable.String + refund_deadline: string; + + @Checkable.String + timestamp: string; + + @Checkable.Number + transaction_id: number; + + @Checkable.String + fulfillment_url: string; + + static checked: (obj: any) => Contract; +} + + +@Checkable.Class +export class Offer { + @Checkable.Value(Contract) + contract: Contract; + + @Checkable.String + merchant_sig: string; + + @Checkable.String + H_contract: string; + + static checked: (obj: any) => Offer; +} + + interface ConfirmPayRequest { offer: Offer; } @@ -93,10 +247,29 @@ export interface Badge { setColor(c: string): void; } - type PayCoinInfo = Array<{ updatedCoin: Coin, sig: CoinPaySig }>; +function getTalerStampSec(stamp: string) { + const m = stamp.match(/\/?Date\(([0-9]*)\)\/?/); + if (!m) { + return null; + } + return parseInt(m[1]); +} + + +function isWithdrawableDenom(d: Denomination) { + const now_sec = (new Date).getTime() / 1000; + const stamp_withdraw_sec = getTalerStampSec(d.stamp_expire_withdraw); + // Withdraw if still possible to withdraw within a minute + if (stamp_withdraw_sec + 60 > now_sec) { + return true; + } + return false; +} + + /** * See http://api.taler.net/wallet.html#general */ @@ -111,6 +284,7 @@ function canonicalizeBaseUrl(url) { return x.href() } + function parsePrettyAmount(pretty: string): AmountJson { const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty); if (!res) { @@ -144,8 +318,8 @@ function copy(o) { function rankDenom(denom1: any, denom2: any) { // Slow ... we should find a better way than to convert it evert time. - let v1 = new Amount(denom1.value); - let v2 = new Amount(denom2.value); + let v1 = new native.Amount(denom1.value); + let v2 = new native.Amount(denom2.value); return (-1) * v1.cmp(v2); } @@ -161,11 +335,11 @@ export class Wallet { this.badge = badge; } - static signDeposit(offer: Offer, - cds: CoinWithDenom[]): PayCoinInfo { + private static signDeposit(offer: Offer, + cds: CoinWithDenom[]): PayCoinInfo { let ret = []; - let amountSpent = Amount.getZero(cds[0].coin.currentAmount.currency); - let amountRemaining = new Amount(offer.contract.amount); + let amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency); + let amountRemaining = new native.Amount(offer.contract.amount); cds = copy(cds); for (let cd of cds) { let coinSpend; @@ -174,36 +348,36 @@ export class Wallet { break; } - if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) { - coinSpend = new Amount(amountRemaining.toJson()); + if (amountRemaining.cmp(new native.Amount(cd.coin.currentAmount)) < 0) { + coinSpend = new native.Amount(amountRemaining.toJson()); } else { - coinSpend = new Amount(cd.coin.currentAmount); + coinSpend = new native.Amount(cd.coin.currentAmount); } amountSpent.add(coinSpend); amountRemaining.sub(coinSpend); - let newAmount = new Amount(cd.coin.currentAmount); + let newAmount = new native.Amount(cd.coin.currentAmount); newAmount.sub(coinSpend); cd.coin.currentAmount = newAmount.toJson(); - let args: DepositRequestPS_Args = { - h_contract: HashCode.fromCrock(offer.H_contract), - h_wire: HashCode.fromCrock(offer.contract.H_wire), + let args: native.DepositRequestPS_Args = { + h_contract: native.HashCode.fromCrock(offer.H_contract), + h_wire: native.HashCode.fromCrock(offer.contract.H_wire), amount_with_fee: coinSpend.toNbo(), - coin_pub: EddsaPublicKey.fromCrock(cd.coin.coinPub), - deposit_fee: new Amount(cd.denom.fee_deposit).toNbo(), - merchant: EddsaPublicKey.fromCrock(offer.contract.merchant_pub), - refund_deadline: AbsoluteTimeNbo.fromTalerString(offer.contract.refund_deadline), - timestamp: AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp), - transaction_id: UInt64.fromNumber(offer.contract.transaction_id), + coin_pub: native.EddsaPublicKey.fromCrock(cd.coin.coinPub), + deposit_fee: new native.Amount(cd.denom.fee_deposit).toNbo(), + merchant: native.EddsaPublicKey.fromCrock(offer.contract.merchant_pub), + refund_deadline: native.AbsoluteTimeNbo.fromTalerString(offer.contract.refund_deadline), + timestamp: native.AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp), + transaction_id: native.UInt64.fromNumber(offer.contract.transaction_id), }; - let d = new DepositRequestPS(args); + let d = new native.DepositRequestPS(args); - let coinSig = eddsaSign(d.toPurpose(), - EddsaPrivateKey.fromCrock(cd.coin.coinPriv)) - .toCrock(); + let coinSig = native.eddsaSign(d.toPurpose(), + native.EddsaPrivateKey.fromCrock(cd.coin.coinPriv)) + .toCrock(); let s: CoinPaySig = { coin_sig: coinSig, @@ -225,9 +399,9 @@ export class Wallet { * @param depositFeeLimit * @param allowedMints */ - getPossibleMintCoins(paymentAmount: AmountJson, - depositFeeLimit: AmountJson, - allowedMints: MintInfo[]): Promise { + private getPossibleMintCoins(paymentAmount: AmountJson, + depositFeeLimit: AmountJson, + allowedMints: MintInfo[]): Promise { let m: MintCoins = {}; @@ -263,19 +437,19 @@ export class Wallet { nextMint: for (let key in m) { let coins = m[key].map((x) => ({ - a: new Amount(x.denom.fee_deposit), + a: new native.Amount(x.denom.fee_deposit), c: x })); // Sort by ascending deposit fee coins.sort((o1, o2) => o1.a.cmp(o2.a)); - let maxFee = new Amount(depositFeeLimit); - let minAmount = new Amount(paymentAmount); - let accFee = new Amount(coins[0].c.denom.fee_deposit); - let accAmount = Amount.getZero(coins[0].c.coin.currentAmount.currency); + let maxFee = new native.Amount(depositFeeLimit); + let minAmount = new native.Amount(paymentAmount); + let accFee = new native.Amount(coins[0].c.denom.fee_deposit); + let accAmount = native.Amount.getZero(coins[0].c.coin.currentAmount.currency); let usableCoins: CoinWithDenom[] = []; nextCoin: for (let i = 0; i < coins.length; i++) { - let coinAmount = new Amount(coins[i].c.coin.currentAmount); + let coinAmount = new native.Amount(coins[i].c.coin.currentAmount); let coinFee = coins[i].a; if (coinAmount.cmp(coinFee) <= 0) { continue nextCoin; @@ -298,9 +472,13 @@ export class Wallet { } - executePay(offer: Offer, - payCoinInfo: PayCoinInfo, - chosenMint: string): Promise { + /** + * Record all information that is necessary to + * pay for a contract in the wallet's database. + */ + private recordConfirmPay(offer: Offer, + payCoinInfo: PayCoinInfo, + chosenMint: string): Promise { let payReq = {}; payReq["amount"] = offer.contract.amount; payReq["coins"] = payCoinInfo.map((x) => x.sig); @@ -332,14 +510,14 @@ export class Wallet { .put("transactions", t) .put("history", historyEntry) .putAll("coins", payCoinInfo.map((pci) => pci.updatedCoin)) - .finish() - .then(() => { - return { - success: true - }; - }); + .finish(); } + + /** + * Add a contract to the wallet and sign coins, + * but do not send them yet. + */ confirmPay(offer: Offer): Promise { return Promise.resolve().then(() => { return this.getPossibleMintCoins(offer.contract.amount, @@ -348,18 +526,22 @@ export class Wallet { }).then((mcs) => { if (Object.keys(mcs).length == 0) { return { - success: false, - message: "Not enough coins", + error: "coins-insufficient", }; } let mintUrl = Object.keys(mcs)[0]; let ds = Wallet.signDeposit(offer, mcs[mintUrl]); - return this - .executePay(offer, ds, mintUrl); + return this.recordConfirmPay(offer, ds, mintUrl) + .then((() => ({}))); }); } - doPayment(H_contract): Promise { + + /** + * Retrieve all necessary information for looking up the contract + * with the given hash. + */ + executePayment(H_contract): Promise { return Promise.resolve().then(() => { return Query(this.db) .get("transactions", H_contract) @@ -385,7 +567,7 @@ export class Wallet { * First fetch information requred to withdraw from the reserve, * then deplete the reserve, withdrawing coins until it is empty. */ - initReserve(reserveRecord) { + private initReserve(reserveRecord) { this.updateMintFromUrl(reserveRecord.mint_base_url) .then((mint) => this.updateReserve(reserveRecord.reserve_pub, mint) @@ -411,7 +593,7 @@ export class Wallet { * Create a reserve, but do not flag it as confirmed yet. */ createReserve(req: CreateReserveRequest): Promise { - const reservePriv = EddsaPrivateKey.create(); + const reservePriv = native.EddsaPrivateKey.create(); const reservePub = reservePriv.getPublicKey(); const now = (new Date).getTime(); @@ -486,29 +668,31 @@ export class Wallet { } - withdrawPrepare(denom: Denomination, - reserve: Reserve): Promise { - let reservePriv = new EddsaPrivateKey(); + private withdrawPrepare(denom: Denomination, + reserve: Reserve): Promise { + let reservePriv = new native.EddsaPrivateKey(); reservePriv.loadCrock(reserve.reserve_priv); - let reservePub = new EddsaPublicKey(); + let reservePub = new native.EddsaPublicKey(); reservePub.loadCrock(reserve.reserve_pub); - let denomPub = RsaPublicKey.fromCrock(denom.denom_pub); - let coinPriv = EddsaPrivateKey.create(); + let denomPub = native.RsaPublicKey.fromCrock(denom.denom_pub); + let coinPriv = native.EddsaPrivateKey.create(); let coinPub = coinPriv.getPublicKey(); - let blindingFactor = RsaBlindingKey.create(1024); - let pubHash: HashCode = coinPub.hash(); - let ev: ByteArray = rsaBlind(pubHash, blindingFactor, denomPub); + let blindingFactor = native.RsaBlindingKey.create(1024); + let pubHash: native.HashCode = coinPub.hash(); + let ev: native.ByteArray = native.rsaBlind(pubHash, + blindingFactor, + denomPub); if (!denom.fee_withdraw) { throw Error("Field fee_withdraw missing"); } - let amountWithFee = new Amount(denom.value); - amountWithFee.add(new Amount(denom.fee_withdraw)); - let withdrawFee = new Amount(denom.fee_withdraw); + let amountWithFee = new native.Amount(denom.value); + amountWithFee.add(new native.Amount(denom.fee_withdraw)); + let withdrawFee = new native.Amount(denom.fee_withdraw); // Signature - let withdrawRequest = new WithdrawRequestPS({ + let withdrawRequest = new native.WithdrawRequestPS({ reserve_pub: reservePub, amount_with_fee: amountWithFee.toNbo(), withdraw_fee: withdrawFee.toNbo(), @@ -516,7 +700,7 @@ export class Wallet { h_coin_envelope: ev.hash() }); - var sig = eddsaSign(withdrawRequest.toPurpose(), reservePriv); + var sig = native.eddsaSign(withdrawRequest.toPurpose(), reservePriv); let preCoin: PreCoin = { reservePub: reservePub.toCrock(), @@ -534,7 +718,7 @@ export class Wallet { } - withdrawExecute(pc: PreCoin): Promise { + private withdrawExecute(pc: PreCoin): Promise { return Query(this.db) .get("reserves", pc.reservePub) .then((r) => { @@ -554,9 +738,9 @@ export class Wallet { }); } let r = JSON.parse(resp.responseText); - let denomSig = rsaUnblind(RsaSignature.fromCrock(r.ev_sig), - RsaBlindingKey.fromCrock(pc.blindingKey), - RsaPublicKey.fromCrock(pc.denomPub)); + let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(r.ev_sig), + native.RsaBlindingKey.fromCrock(pc.blindingKey), + native.RsaPublicKey.fromCrock(pc.denomPub)); let coin: Coin = { coinPub: pc.coinPub, coinPriv: pc.coinPriv, @@ -609,7 +793,7 @@ export class Wallet { } - withdraw(denom, reserve): Promise { + private withdraw(denom, reserve): Promise { return this.withdrawPrepare(denom, reserve) .then((pc) => this.withdrawExecute(pc)) .then((c) => this.storeCoin(c)); @@ -619,16 +803,19 @@ export class Wallet { /** * Withdraw coins from a reserve until it is empty. */ - depleteReserve(reserve, mint): Promise { - let denoms = copy(mint.keys.denoms); - let remaining = new Amount(reserve.current_amount); + private depleteReserve(reserve, mint: Mint): Promise { + let denoms: Denomination[] = copy(mint.keys.denoms); + let remaining = new native.Amount(reserve.current_amount); + + denoms = denoms.filter(isWithdrawableDenom); + denoms.sort(rankDenom); let workList = []; for (let i = 0; i < 1000; i++) { let found = false; for (let d of denoms) { - let cost = new Amount(d.value); - cost.add(new Amount(d.fee_withdraw)); + let cost = new native.Amount(d.value); + cost.add(new native.Amount(d.fee_withdraw)); if (remaining.cmp(cost) < 0) { continue; } @@ -665,8 +852,7 @@ export class Wallet { } - updateReserve(reservePub: string, - mint): Promise { + private updateReserve(reservePub: string, mint): Promise { return Query(this.db) .get("reserves", reservePub) .then((reserve) => { @@ -706,7 +892,7 @@ export class Wallet { * Optionally link the reserve entry to the new or existing * mint entry in then DB. */ - updateMintFromUrl(baseUrl) { + private updateMintFromUrl(baseUrl): Promise { let reqUrl = URI("keys").absoluteTo(baseUrl); return this.http.get(reqUrl).then((resp) => { if (resp.status != 200) { @@ -729,10 +915,10 @@ export class Wallet { function collectBalances(c: Coin, byCurrency) { let acc: AmountJson = byCurrency[c.currentAmount.currency]; if (!acc) { - acc = Amount.getZero(c.currentAmount.currency).toJson(); + acc = native.Amount.getZero(c.currentAmount.currency).toJson(); } - let am = new Amount(c.currentAmount); - am.add(new Amount(acc)); + let am = new native.Amount(c.currentAmount); + am.add(new native.Amount(acc)); byCurrency[c.currentAmount.currency] = am.toJson(); return byCurrency; } diff --git a/extension/lib/wallet/wxmessaging.js b/extension/lib/wallet/wxmessaging.js index 1e1029be0..f5819b197 100644 --- a/extension/lib/wallet/wxmessaging.js +++ b/extension/lib/wallet/wxmessaging.js @@ -13,9 +13,10 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, If not, see */ -System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { +System.register(["./wallet", "./db", "./http"], function(exports_1, context_1) { "use strict"; - var types_1, wallet_1, db_1, db_2, db_3, http_1, types_2, types_3; + var __moduleName = context_1 && context_1.id; + var wallet_1, db_1, http_1; var ChromeBadge; /** * Messaging for the WebExtensions wallet. Should contain @@ -44,7 +45,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { for (var i = 0; i < db.objectStoreNames.length; i++) { tx.objectStore(db.objectStoreNames[i]).clear(); } - db_2.deleteDb(); + db_1.deleteDb(); chrome.browserAction.setBadgeText({ text: "" }); console.log("reset done"); // Response is synchronous @@ -55,7 +56,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { mint: detail.mint, amount: detail.amount, }; - var req = types_2.CreateReserveRequest.checked(d); + var req = wallet_1.CreateReserveRequest.checked(d); wallet.createReserve(req) .then(function (resp) { sendResponse(resp); @@ -72,7 +73,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { var d = { reservePub: detail.reservePub }; - var req = types_1.ConfirmReserveRequest.checked(d); + var req = wallet_1.ConfirmReserveRequest.checked(d); wallet.confirmReserve(req) .then(function (resp) { sendResponse(resp); @@ -85,10 +86,10 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { return true; }, _a["confirm-pay"] = function (db, detail, sendResponse) { - var offer = types_3.Offer.checked(detail.offer); + var offer = wallet_1.Offer.checked(detail.offer); wallet.confirmPay(offer) - .then(function (r) { - sendResponse(r); + .then(function () { + sendResponse({}); }) .catch(function (e) { console.error("exception during 'confirm-pay'"); @@ -98,7 +99,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { return true; }, _a["execute-payment"] = function (db, detail, sendResponse) { - wallet.doPayment(detail.H_contract) + wallet.executePayment(detail.H_contract) .then(function (r) { sendResponse(r); }) @@ -131,7 +132,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { } function wxMain() { chrome.browserAction.setBadgeText({ text: "" }); - db_3.openTalerDb() + db_1.openTalerDb() .then(function (db) { var http = new http_1.BrowserHttpLib(); var badge = new ChromeBadge(); @@ -154,18 +155,11 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { exports_1("wxMain", wxMain); return { setters:[ - function (types_1_1) { - types_1 = types_1_1; - types_2 = types_1_1; - types_3 = types_1_1; - }, function (wallet_1_1) { wallet_1 = wallet_1_1; }, function (db_1_1) { db_1 = db_1_1; - db_2 = db_1_1; - db_3 = db_1_1; }, function (http_1_1) { http_1 = http_1_1; diff --git a/extension/lib/wallet/wxmessaging.ts b/extension/lib/wallet/wxmessaging.ts index 9af63eb2f..045145716 100644 --- a/extension/lib/wallet/wxmessaging.ts +++ b/extension/lib/wallet/wxmessaging.ts @@ -15,15 +15,9 @@ */ -import {ConfirmReserveRequest} from "./types"; -import {Wallet} from "./wallet"; -import {exportDb} from "./db"; -import {deleteDb} from "./db"; -import {openTalerDb} from "./db"; +import {Wallet, Offer, Badge, ConfirmReserveRequest, CreateReserveRequest} from "./wallet"; +import {deleteDb, exportDb, openTalerDb} from "./db"; import {BrowserHttpLib} from "./http"; -import {Badge} from "./wallet"; -import {CreateReserveRequest} from "./types"; -import {Offer} from "./types"; "use strict"; @@ -99,8 +93,8 @@ function makeHandlers(wallet: Wallet) { ["confirm-pay"]: function(db, detail, sendResponse) { const offer = Offer.checked(detail.offer); wallet.confirmPay(offer) - .then((r) => { - sendResponse(r) + .then(() => { + sendResponse({}) }) .catch((e) => { console.error("exception during 'confirm-pay'"); @@ -110,7 +104,7 @@ function makeHandlers(wallet: Wallet) { return true; }, ["execute-payment"]: function(db, detail, sendResponse) { - wallet.doPayment(detail.H_contract) + wallet.executePayment(detail.H_contract) .then((r) => { sendResponse(r); }) diff --git a/extension/lib/web-common.ts b/extension/lib/web-common.ts index 96f9b61b7..79ff4b13e 100644 --- a/extension/lib/web-common.ts +++ b/extension/lib/web-common.ts @@ -14,7 +14,8 @@ TALER; see the file COPYING. If not, If not, see */ -import {AmountJson} from "./wallet/types"; +import {AmountJson} from "./wallet/wallet"; + export function substituteFulfillmentUrl(url: string, vars) { url = url.replace("${H_contract}", vars.H_contract); url = url.replace("${$}", "$"); diff --git a/extension/manifest.json b/extension/manifest.json index b228cc0cc..1eeeea6a6 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -2,7 +2,7 @@ "description": "Privacy preserving and transparent payments", "manifest_version": 2, "name": "GNU Taler Wallet (git)", - "version": "0.5.5", + "version": "0.5.6", "applications": { "gecko": { diff --git a/extension/pages/confirm-contract.js b/extension/pages/confirm-contract.js index 70ecff399..d715985b5 100644 --- a/extension/pages/confirm-contract.js +++ b/extension/pages/confirm-contract.js @@ -13,9 +13,10 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, If not, see */ -System.register(["../lib/web-common"], function(exports_1) { +System.register(["../lib/web-common"], function(exports_1, context_1) { /// "use strict"; + var __moduleName = context_1 && context_1.id; var web_common_1; function prettyAmount(amount) { var v = amount.value + amount.fraction / 1e6; diff --git a/extension/pages/confirm-create-reserve.js b/extension/pages/confirm-create-reserve.js index a53833f04..3ac757249 100644 --- a/extension/pages/confirm-create-reserve.js +++ b/extension/pages/confirm-create-reserve.js @@ -13,14 +13,15 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, If not, see */ -System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1) { +System.register(["../lib/web-common", "../lib/wallet/wallet"], function(exports_1, context_1) { "use strict"; - var types_1, web_common_1, types_2; + var __moduleName = context_1 && context_1.id; + var web_common_1, wallet_1; function main() { function updateAmount() { var showAmount = document.getElementById("show-amount"); console.log("Query is " + JSON.stringify(query)); - var amount = types_1.AmountJson.checked(JSON.parse(query.amount)); + var amount = wallet_1.AmountJson.checked(JSON.parse(query.amount)); showAmount.textContent = web_common_1.amountToPretty(amount); } var url = URI(document.location.href); @@ -44,7 +45,7 @@ System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1 throw Error("empty response"); } if (!rawResp.error) { - var resp = types_2.CreateReserveResponse.checked(rawResp); + var resp = wallet_1.CreateReserveResponse.checked(rawResp); var q = { mint: resp.mint, reserve_pub: resp.reservePub, @@ -67,12 +68,11 @@ System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1 exports_1("main", main); return { setters:[ - function (types_1_1) { - types_1 = types_1_1; - types_2 = types_1_1; - }, function (web_common_1_1) { web_common_1 = web_common_1_1; + }, + function (wallet_1_1) { + wallet_1 = wallet_1_1; }], execute: function() { "use strict"; diff --git a/extension/pages/confirm-create-reserve.tsx b/extension/pages/confirm-create-reserve.tsx index e4d2d27e6..6a130eeff 100644 --- a/extension/pages/confirm-create-reserve.tsx +++ b/extension/pages/confirm-create-reserve.tsx @@ -14,9 +14,8 @@ TALER; see the file COPYING. If not, If not, see */ -import {AmountJson} from "../lib/wallet/types"; import {amountToPretty} from "../lib/web-common"; -import {CreateReserveResponse} from "../lib/wallet/types"; +import {AmountJson, CreateReserveResponse} from "../lib/wallet/wallet"; "use strict"; diff --git a/extension/popup/popup.tsx b/extension/popup/popup.tsx index a9579f18c..ebd77dd2e 100644 --- a/extension/popup/popup.tsx +++ b/extension/popup/popup.tsx @@ -15,7 +15,7 @@ */ -/// +/// /// "use strict"; diff --git a/extension/tsconfig.json b/extension/tsconfig.json index 18539aa4e..5c2883da4 100644 --- a/extension/tsconfig.json +++ b/extension/tsconfig.json @@ -5,7 +5,9 @@ "experimentalDecorators": true, "module": "system", "sourceMap": true, - "noLib": true + "noLib": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true }, "files": [ "lib/i18n.ts", @@ -16,7 +18,6 @@ "lib/wallet/emscriptif.ts", "lib/wallet/http.ts", "lib/wallet/query.ts", - "lib/wallet/types.ts", "lib/wallet/wallet.ts", "lib/wallet/wxmessaging.ts", "background/main.ts", -- cgit v1.2.3