summaryrefslogtreecommitdiff
path: root/dev-wallet-wx.rst
blob: 2fdc7252bb02625a507db76ffbede57b872b962c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
=====================
WebExtensions Wallet
=====================

------------
Introduction
------------

The WebExtensions Wallet (*wxwallet*) can be used to pay with GNU Taler on web
sites from within modern web browsers.  The `WebExtensions
<https://wiki.mozilla.org/WebExtensions>`_ API interface that enables the
development cross-browser extensions.  Google Chrome / Chromium, Mozilla
Firefox, Opera and Microsoft Edge will all offer support for WebExtensions in
the future.

Currently Chrome hast the best support for WebExtensions (since the API is a superset
of Chrome's extension API).

-----------------------
Development Environment
-----------------------

The *wxwallet* mainly written in the `TypeScript
<http://www.typescriptlang.org/>`_ language, which is a statically typed
superset of JavaScript.

While the *wxwallet* is mainly intended to be run from inside a browser, the
logic is implemented in browser-independent modules that can also be called
from other environments such as `nodejs <https://nodejs.org>`_.  This is
especially useful for automatically running unit tests.


-----------------
Project Structure
-----------------

.. parsed-literal::
  
  **manifest.json**               extension configuration
  **package.json**                node.js package configuration
  **tsconfig.json**               TypeScript compiler configuration
  **gulpfile.js**                 Build tasks script
  **lib/**
      **vendor/**                 3rd party libraries
      **wallet/**                 actual application logic
      **emscripten/**             emscripten object file and glue
  **test/**
       **run_tests.js**           nodejs entry point for tests
       **tests/**                 test cases
  **content_scripts/notify.ts**   wallet<->website signaling
  **backgrond/main.ts**           backend entry point
  **img/**                        static image resources
  **style/**                      CSS stylesheets
  **pages/**                      pages shown in browser tabs
  **popup/**                      pages shown the extension popup


-------------------
Building the Wallet
-------------------

To build the extension for use during development, simply run the TypeScript compiler
from the extension directory:

.. code-block:: sh

  $ cd wallet.git/wallet_webextension/extension/
  $ tsc

This will use the ``tsconfig.json`` with development options such as `source map`_ support.

.. _`source map`: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit

When TypeScript source files are added or deleted to the project, make sure that the
globs in ``gulpfile.js`` match them so that they will be compiled.  The ``tsconfig.json``
is generated by running:


.. code-block:: sh

  $ gulp tsconfig

.. caution::

  Do not edit the ``tsconfig.json`` manually.  The source files should be defined in
  one place, and that is ``gulpfile.js``.

To pack the extension in a format that can be uploaded to the Google Webstore, run:

.. code-block:: sh

  $ gulp package

This will build the wallet without source maps, copy resource files (which also need to be
specified in ``gulpfile.js``) and create an archive.


----------
Emscripten
----------

`Emscripten <https://kripken.github.io/emscripten-site/index.html>`_ is C/C++
to JavaScript compiler.  Emscripten is used in the *wxwallet* to access
low-level cryptography from *libgcrypt*, and miscellaneous functionality from
*libgnunetutil* and *libtalerwallet*.

TODO: say things about wrappers


--------------------------------------
Target Environments and Modularization
--------------------------------------

Modules in the wallet are declared in TypeScript with
the ES6 module syntax.  These modules are then compiled
to `SystemJS <https://github.com/systemjs/systemjs>`_ `register` modules.

SystemJS modules can be loaded from the browser as well as from nodejs.
However they require special entry points that configure the module system,
load modules and execute code.  Examples are `backgrond/main.ts` for the
browser and `test/run_tests.js` for nodejs.

Note that special care has to be taken when loading the Emscript code,
as it is not compatible with the SystemJS module, even in the `globals`
compatibility mode.

The TypeScript sources in the *wxwallet* are compiled down to ES5, both to
enable running in node.js without transpilers and to avoid a `bug
<https://github.com/Microsoft/TypeScript/issues/6426>`_ in the TypeScript
compiler.

----------------------------
IndexedDB Query Abstractions
----------------------------

The *wxwallet* uses a fluent-style API for queries on IndexedDB.

TODO: say more about this


-------
Testing
-------

Test cases for the wallet are written in TypeScript and
run with `mochajs <http://mochajs.org/>`_ and the `better-assert <https://github.com/tj/better-assert>`_ assertion
library.

Run the default test suite with ``npm run test``, which will
call `moch` with the right parameters.