@com-chain/jsc3l 2.0.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +45 -0
  3. package/build/bcRead.d.ts +15 -0
  4. package/build/bcRead.js +123 -0
  5. package/build/bcRead.js.map +1 -0
  6. package/build/bcTransaction.d.ts +10 -0
  7. package/build/bcTransaction.js +135 -0
  8. package/build/bcTransaction.js.map +1 -0
  9. package/build/blockies.d.ts +1 -0
  10. package/build/blockies.js +91 -0
  11. package/build/blockies.js.map +1 -0
  12. package/build/config.d.ts +6 -0
  13. package/build/config.js +25 -0
  14. package/build/config.js.map +1 -0
  15. package/build/connection.d.ts +58 -0
  16. package/build/connection.js +204 -0
  17. package/build/connection.js.map +1 -0
  18. package/build/customization.d.ts +37 -0
  19. package/build/customization.js +129 -0
  20. package/build/customization.js.map +1 -0
  21. package/build/ethereum/cipher.d.ts +3 -0
  22. package/build/ethereum/cipher.js +94 -0
  23. package/build/ethereum/cipher.js.map +1 -0
  24. package/build/ethereum/ethFuncs.d.ts +12 -0
  25. package/build/ethereum/ethFuncs.js +70 -0
  26. package/build/ethereum/ethFuncs.js.map +1 -0
  27. package/build/ethereum/etherUnits.d.ts +5 -0
  28. package/build/ethereum/etherUnits.js +60 -0
  29. package/build/ethereum/etherUnits.js.map +1 -0
  30. package/build/ethereum/myetherwallet.d.ts +47 -0
  31. package/build/ethereum/myetherwallet.js +294 -0
  32. package/build/ethereum/myetherwallet.js.map +1 -0
  33. package/build/ethereum/uiFuncs.d.ts +3 -0
  34. package/build/ethereum/uiFuncs.js +51 -0
  35. package/build/ethereum/uiFuncs.js.map +1 -0
  36. package/build/index.d.ts +111 -0
  37. package/build/index.js +310 -0
  38. package/build/index.js.map +1 -0
  39. package/build/memo.d.ts +6 -0
  40. package/build/memo.js +24 -0
  41. package/build/memo.js.map +1 -0
  42. package/build/qr.d.ts +8 -0
  43. package/build/qr.js +35 -0
  44. package/build/qr.js.map +1 -0
  45. package/build/rest/ajaxReq.d.ts +31 -0
  46. package/build/rest/ajaxReq.js +127 -0
  47. package/build/rest/ajaxReq.js.map +1 -0
  48. package/build/rest/endpoint.d.ts +18 -0
  49. package/build/rest/endpoint.js +26 -0
  50. package/build/rest/endpoint.js.map +1 -0
  51. package/build/rest/http.d.ts +10 -0
  52. package/build/rest/http.js +60 -0
  53. package/build/rest/http.js.map +1 -0
  54. package/build/rest/serializer.d.ts +1 -0
  55. package/build/rest/serializer.js +94 -0
  56. package/build/rest/serializer.js.map +1 -0
  57. package/build/type.d.ts +24 -0
  58. package/build/type.js +9 -0
  59. package/build/type.js.map +1 -0
  60. package/build/wallet.d.ts +35 -0
  61. package/build/wallet.js +162 -0
  62. package/build/wallet.js.map +1 -0
  63. package/package.json +41 -0
  64. package/src/bcRead.ts +184 -0
  65. package/src/bcTransaction.ts +157 -0
  66. package/src/blockies.ts +113 -0
  67. package/src/config.ts +33 -0
  68. package/src/connection.ts +243 -0
  69. package/src/customization.ts +156 -0
  70. package/src/ethereum/cipher.ts +118 -0
  71. package/src/ethereum/ethFuncs.ts +73 -0
  72. package/src/ethereum/etherUnits.ts +66 -0
  73. package/src/ethereum/myetherwallet.ts +354 -0
  74. package/src/ethereum/uiFuncs.ts +55 -0
  75. package/src/index.ts +366 -0
  76. package/src/memo.ts +37 -0
  77. package/src/qr.ts +34 -0
  78. package/src/rest/ajaxReq.ts +160 -0
  79. package/src/rest/endpoint.ts +31 -0
  80. package/src/rest/http.ts +69 -0
  81. package/src/rest/serializer.ts +99 -0
  82. package/src/type.ts +37 -0
  83. package/src/wallet.ts +200 -0
  84. package/tsconfig.json +31 -0
package/build/index.js ADDED
@@ -0,0 +1,310 @@
1
+ import * as ethFuncs from './ethereum/ethFuncs'; // Utilities to pass on
2
+ import * as memo from './memo';
3
+ // Only required for blockie helper
4
+ import blockies from './blockies';
5
+ import Wallet from './ethereum/myetherwallet';
6
+ // Abstracts
7
+ import HttpAbstract from './rest/http';
8
+ import EndpointAbstract from './rest/endpoint';
9
+ import AjaxReqAbstract from './rest/ajaxReq';
10
+ import ConnectionMgrAbstract from './connection';
11
+ import CustomizationAbstract from './customization';
12
+ import MessagingWalletAbstract from './wallet';
13
+ import BcReadAbstract from './bcRead';
14
+ import BcTransactionAbstract from './bcTransaction';
15
+ function createIcon(address) {
16
+ if (address instanceof Wallet) {
17
+ address = address.getAddressString();
18
+ }
19
+ return blockies({
20
+ seed: address.toLowerCase(),
21
+ size: 8,
22
+ scale: 16
23
+ }).toDataURL();
24
+ }
25
+ class AbstractJsc3l {
26
+ constructor(localDefaultConf) {
27
+ this._currencyMgrPromises = {};
28
+ this.localDefaultConf = localDefaultConf || {};
29
+ }
30
+ /**
31
+ * `connection` facility needs to be lazy loaded as `this` and
32
+ * abstract `httpRequest` is not available in constructor.
33
+ */
34
+ get connection() {
35
+ if (!this._connection) {
36
+ const self = this;
37
+ class ConnectionMgr extends ConnectionMgrAbstract {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.http = self.http;
41
+ this.persistentStore = self.persistentStore;
42
+ }
43
+ }
44
+ this._connection = new ConnectionMgr();
45
+ }
46
+ return this._connection;
47
+ }
48
+ /**
49
+ * `Endpoint` class is a facility that needs to be lazy loaded as
50
+ * `this` and abstract `httpRequest` is not available in
51
+ * constructor.
52
+ */
53
+ get Endpoint() {
54
+ if (!this._Endpoint) {
55
+ const self = this;
56
+ class Endpoint extends EndpointAbstract {
57
+ constructor() {
58
+ super(...arguments);
59
+ this.httpRequest = self.httpRequest;
60
+ }
61
+ }
62
+ this._Endpoint = Endpoint;
63
+ }
64
+ return this._Endpoint;
65
+ }
66
+ /**
67
+ * 'http' facility needs to be lazy loaded as 'this' and abstract
68
+ * httpRequest is not available in constructor.
69
+ */
70
+ get http() {
71
+ if (!this._http) {
72
+ const self = this;
73
+ // ConnectionMgr
74
+ class Http extends HttpAbstract {
75
+ constructor() {
76
+ super(...arguments);
77
+ this.httpRequest = self.httpRequest;
78
+ }
79
+ }
80
+ this._http = new Http();
81
+ }
82
+ return this._http;
83
+ }
84
+ getAjaxReq(endpointUrl) {
85
+ const self = this;
86
+ class AjaxReq extends AjaxReqAbstract {
87
+ constructor() {
88
+ super(...arguments);
89
+ this.endpoint = new self.Endpoint(endpointUrl);
90
+ }
91
+ }
92
+ return new AjaxReq();
93
+ }
94
+ /**
95
+ * `getConfJson` check persistent storage for configuration for
96
+ * given currency, otherwise will use the given repo to fetch
97
+ * it (and save it in persistent storage).
98
+ */
99
+ async getConfig(repo, currencyName) {
100
+ const cfgJson = this.connection.getLocalConfJSON();
101
+ if (cfgJson && cfgJson.server.name === currencyName) {
102
+ return cfgJson;
103
+ }
104
+ return await this.connection.getConfJSON(currencyName, repo);
105
+ }
106
+ /**
107
+ * `getConfJson` check persistent storage for configuration for
108
+ * given currency, otherwise will use the given repo to fetch
109
+ * it (and save it in persistent storage).
110
+ */
111
+ getCustomization(config) {
112
+ class Customization extends CustomizationAbstract {
113
+ constructor() {
114
+ super(...arguments);
115
+ this.cfg = config;
116
+ }
117
+ }
118
+ return new Customization(this.localDefaultConf);
119
+ }
120
+ getWallet(endpointUrl, currencyName, unlockUrl) {
121
+ const self = this;
122
+ class MessagingWallet extends MessagingWalletAbstract {
123
+ constructor() {
124
+ super(...arguments);
125
+ this.ajaxReq = self.getAjaxReq(endpointUrl);
126
+ this.currencyName = currencyName;
127
+ this.unlockUrl = unlockUrl;
128
+ }
129
+ }
130
+ // XXXvlab: should we instanciate this ?
131
+ return MessagingWallet;
132
+ }
133
+ getBcRead(endpointUrl, contracts) {
134
+ const self = this;
135
+ class BcRead extends BcReadAbstract {
136
+ constructor() {
137
+ super(...arguments);
138
+ this.ajaxReq = self.getAjaxReq(endpointUrl);
139
+ this.contracts = contracts;
140
+ }
141
+ }
142
+ return new BcRead();
143
+ }
144
+ getBcTransaction(endpointUrl, contracts) {
145
+ const self = this;
146
+ class BcTransaction extends BcTransactionAbstract {
147
+ constructor() {
148
+ super(...arguments);
149
+ this.ajaxReq = self.getAjaxReq(endpointUrl);
150
+ this.contracts = contracts;
151
+ }
152
+ }
153
+ return new BcTransaction();
154
+ }
155
+ async getCurrencyMgr(currencyName, endpointUrl, repoUrl) {
156
+ const key = Array.from(arguments).join('\0');
157
+ if (!this._currencyMgrPromises[key]) {
158
+ this._currencyMgrPromises[key] =
159
+ this._getCurrencyMgr(currencyName, endpointUrl, repoUrl);
160
+ }
161
+ return await this._currencyMgrPromises[key];
162
+ }
163
+ async _getCurrencyMgr(currencyName, endpointUrl, repoUrl) {
164
+ if (!repoUrl) {
165
+ if (this.connection.repo) {
166
+ repoUrl = this.connection.repo;
167
+ }
168
+ else {
169
+ repoUrl = await this.connection.lookupAvailableComChainRepo();
170
+ }
171
+ }
172
+ if (!endpointUrl) {
173
+ if (this.connection.endpoint) {
174
+ endpointUrl = this.connection.endpoint;
175
+ }
176
+ else {
177
+ endpointUrl = (await this.connection.acquireEndPoint(repoUrl)).endpoint;
178
+ }
179
+ }
180
+ const config = await this.getConfig(repoUrl, currencyName);
181
+ const customization = this.getCustomization(config);
182
+ const contracts = [
183
+ customization.getContract1(),
184
+ customization.getContract2()
185
+ ];
186
+ const self = this;
187
+ const wallet = this.getWallet(endpointUrl, currencyName, customization.getUnlockUrl());
188
+ return {
189
+ // unlockWallet: (jsonData, password) => wallet.getWalletFromPrivKeyFile(jsonData, password),
190
+ jsc3l: this,
191
+ customization,
192
+ ajaxReq: this.getAjaxReq(endpointUrl),
193
+ wallet: wallet,
194
+ bcRead: this.getBcRead(endpointUrl, contracts),
195
+ bcTransaction: this.getBcTransaction(endpointUrl, contracts),
196
+ };
197
+ }
198
+ }
199
+ Object.assign(AbstractJsc3l.prototype, {
200
+ memo,
201
+ ethFuncs,
202
+ createIcon
203
+ });
204
+ class IntegratedJsc3lAbstract extends AbstractJsc3l {
205
+ /**
206
+ * `ajaxReq` depends on a loaded endpoint in
207
+ * `this.connection.endpoint` obtained through
208
+ * `this.endpoint.acquireEndPoint(..)`. XXXvlab: We could cache the
209
+ * result with endpoint being a key.
210
+ */
211
+ get ajaxReq() {
212
+ if (!this.connection.endpoint) {
213
+ throw new Error('An endpoint need to have been acquired.');
214
+ }
215
+ return this.getAjaxReq(this.connection.endpoint);
216
+ }
217
+ /**
218
+ * `customization` depends on a local configuration being available
219
+ * through a previous call to `this.connection.getConfJSON(..)`
220
+ *
221
+ * XXXvlab: We could cache the result with result of
222
+ * `connection.getLocalConf()` being the key.
223
+ */
224
+ get customization() {
225
+ // XXXvlab: Probably don't need a module for that, as the configuration
226
+ // is always re-queried and quite small, we could cache-it in memory.
227
+ const localCfg = this.connection.getLocalConfJSON();
228
+ if (!localCfg) {
229
+ throw new Error('No configuration is available locally.');
230
+ }
231
+ return this.getCustomization(localCfg);
232
+ }
233
+ /**
234
+ * `wallet` depends on both:
235
+ * - a local configuration (only for the `currencyName`) being
236
+ * available through a previous call to
237
+ * `this.connection.getConfJSON(..)`
238
+ * - a loaded endpoint in `this.connection.endpoint` obtained
239
+ * through `this.endpoint.acquireEndPoint(..)`.
240
+ *
241
+ * XXXvlab: We could cache the result with result of
242
+ * `connection.getLocalConf()` and `this.connection.endpoint` being
243
+ * the keys.
244
+ */
245
+ get wallet() {
246
+ if (!this.ajaxReq) {
247
+ throw Error('a connect() is required before accessing wallet');
248
+ }
249
+ let localCfg;
250
+ try {
251
+ localCfg = this.customization;
252
+ }
253
+ catch (e) {
254
+ throw Error('A local conf needs to be available before accessing wallet');
255
+ }
256
+ return this.getWallet(this.ajaxReq.endpoint.baseUrl, localCfg.getCurrencyName(), this.customization.getUnlockUrl());
257
+ }
258
+ /**
259
+ * `bcRead` access depends on both:
260
+ * - a local configuration (only for contracts information) being
261
+ * available through a previous call to
262
+ * `this.connection.getConfJSON(..)`
263
+ * - a loaded endpoint in `this.connection.endpoint` obtained through
264
+ * `this.endpoint.acquireEndPoint(..)`.
265
+ *
266
+ * XXXvlab: We could cache the result with result of
267
+ * `connection.getLocalConf()` and `this.connection.endpoint` being
268
+ * the keys.
269
+ */
270
+ get bcRead() {
271
+ if (!this.ajaxReq) {
272
+ throw Error('an init() is required before accessing bcRead');
273
+ }
274
+ let localCfg;
275
+ try {
276
+ localCfg = this.customization;
277
+ }
278
+ catch (e) {
279
+ throw Error('A local conf needs to be available before accessing wallet');
280
+ }
281
+ return this.getBcRead(this.ajaxReq.endpoint.baseUrl, [localCfg.getContract1(), localCfg.getContract2()]);
282
+ }
283
+ /**
284
+ * `bcTransaction` access depends on both:
285
+ * - a local configuration (only for contracts information) being
286
+ * available through a previous call to
287
+ * `this.connection.getConfJSON(..)`
288
+ * - a loaded endpoint in `this.connection.endpoint` obtained through
289
+ * `this.endpoint.acquireEndPoint(..)`.
290
+ *
291
+ * XXXvlab: We could cache the result with result of
292
+ * `connection.getLocalConf()` and `this.connection.endpoint` being
293
+ * the keys.
294
+ */
295
+ get bcTransaction() {
296
+ if (!this.ajaxReq) {
297
+ throw Error('an init() is required before accessing bcTransaction');
298
+ }
299
+ let localCfg;
300
+ try {
301
+ localCfg = this.customization;
302
+ }
303
+ catch (e) {
304
+ throw Error('A local conf needs to be available before accessing wallet');
305
+ }
306
+ return this.getBcTransaction(this.ajaxReq.endpoint.baseUrl, [localCfg.getContract1(), localCfg.getContract2()]);
307
+ }
308
+ }
309
+ export default IntegratedJsc3lAbstract;
310
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA,CAAE,uBAAuB;AACxE,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAA;AAE9B,mCAAmC;AACnC,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAK7C,YAAY;AAEZ,OAAO,YAAY,MAAM,aAAa,CAAA;AACtC,OAAO,gBAAgB,MAAM,iBAAiB,CAAA;AAC9C,OAAO,e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AAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,KAAK,CAAC,+CAA+C,CAAC,CAAA;SAC7D;QACD,IAAI,QAAa,CAAA;QACjB,IAAI;YACF,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAA;SAC9B;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,KAAK,CAAC,4DAA4D,CAAC,CAAA;SAC1E;QACD,OAAO,IAAI,CAAC,SAAS,CACnB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAC7B,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CACnD,CAAA;IACH,CAAC;IAGD;;;;;;;;;;;OAWG;IACH,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,KAAK,CAAC,sDAAsD,CAAC,CAAA;SACpE;QACD,IAAI,QAAa,CAAA;QACjB,IAAI;YACF,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAA;SAC9B;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,KAAK,CAAC,4DAA4D,CAAC,CAAA;SAC1E;QACD,OAAO,IAAI,CAAC,gBAAgB,CAC1B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAC7B,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CACnD,CAAA;IACH,CAAC;CAEF;AAGD,eAAe,uBAAuB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare function getMyTransactionMemo(msgWallet: any, transaction: any): string;
2
+ export declare function getTransactionMemo(transaction: any, forAddress: any, messageKey: any): string;
3
+ export declare function getTxMemoCipheredData(fromMsgKey: any, toMsgKey: any, msgFrom: any, msgTo: any): {
4
+ memo_to: string;
5
+ memo_from: string;
6
+ };
package/build/memo.js ADDED
@@ -0,0 +1,24 @@
1
+ import { cipherMsg, decipherMsg } from './ethereum/cipher';
2
+ // Used in the test
3
+ export function getMyTransactionMemo(msgWallet, transaction) {
4
+ const key = msgWallet.messageKeysFromWallet();
5
+ const watchedAddress = msgWallet.getAddressString().toLowerCase();
6
+ const { addr_to, message_to, addr_from, message_from } = transaction;
7
+ return getTransactionMemo(transaction, watchedAddress, key);
8
+ }
9
+ export function getTransactionMemo(transaction, forAddress, messageKey) {
10
+ const { addr_to, message_to, addr_from, message_from } = transaction;
11
+ if (addr_to.toLowerCase() === forAddress && message_to) {
12
+ return decipherMsg(messageKey, message_to);
13
+ }
14
+ if (addr_from.toLowerCase() === forAddress && message_from) {
15
+ return decipherMsg(messageKey, message_from);
16
+ }
17
+ return '';
18
+ }
19
+ export function getTxMemoCipheredData(fromMsgKey, toMsgKey, msgFrom, msgTo) {
20
+ return Object.assign(Object.assign({}, (fromMsgKey && msgFrom) &&
21
+ { memo_from: cipherMsg(fromMsgKey, msgFrom) }), (toMsgKey && msgTo) &&
22
+ { memo_to: cipherMsg(toMsgKey, msgTo) });
23
+ }
24
+ //# sourceMappingURL=memo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memo.js","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG1D,mBAAmB;AACnB,MAAM,UAAU,oBAAoB,CAAE,SAAS,EAAE,WAAW;IAC1D,MAAM,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAA;IAC7C,MAAM,cAAc,GAAG,SAAS,CAAC,gBAAgB,EAAE,CAAC,WAAW,EAAE,CAAA;IACjE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,WAAW,CAAA;IAEpE,OAAO,kBAAkB,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,CAAC,CAAA;AAC7D,CAAC;AAGD,MAAM,UAAU,kBAAkB,CAAE,WAAW,EAAE,UAAU,EAAE,UAAU;IACrE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,WAAW,CAAA;IAEpE,IAAI,OAAO,CAAC,WAAW,EAAE,KAAK,UAAU,IAAI,UAAU,EAAE;QACtD,OAAO,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;KAC3C;IAED,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,UAAU,IAAI,YAAY,EAAE;QAC1D,OAAO,WAAW,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;KAC7C;IAED,OAAO,EAAE,CAAA;AACX,CAAC;AAGD,MAAM,UAAU,qBAAqB,CAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK;IACzE,uCACK,CAAC,UAAU,IAAI,OAAO,CAAC;QACxB,EAAE,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,GAC5C,CAAC,QAAQ,IAAI,KAAK,CAAC;QACpB,EAAE,OAAO,EAAE,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAC1C;AACH,CAAC"}
package/build/qr.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export declare function checkSignedQRFromString(qrString: any, intendedRecipientAddress: any): "InvalidFormat" | "InvalidSignature" | "NotForYou" | "Expired" | {
2
+ signature: any;
3
+ data: any;
4
+ };
5
+ export declare function checkSignedQR(data: any, signature: any, intendedRecipientAddress: any): "InvalidFormat" | "InvalidSignature" | "NotForYou" | "Expired" | {
6
+ signature: any;
7
+ data: any;
8
+ };
package/build/qr.js ADDED
@@ -0,0 +1,35 @@
1
+ import ethUtil from 'ethereumjs-util';
2
+ export function checkSignedQRFromString(qrString, intendedRecipientAddress) {
3
+ let data, signature;
4
+ try {
5
+ ({ data, signature } = JSON.parse(qrString));
6
+ }
7
+ catch (e) {
8
+ return 'InvalidFormat';
9
+ }
10
+ return checkSignedQR(data, signature, intendedRecipientAddress);
11
+ }
12
+ export function checkSignedQR(data, signature, intendedRecipientAddress) {
13
+ let hash;
14
+ let publicSignKey;
15
+ let receiverAddress;
16
+ try {
17
+ hash = ethUtil.sha3(JSON.stringify(data));
18
+ publicSignKey = ethUtil.ecrecover(hash, signature.v, signature.r, signature.s);
19
+ receiverAddress = ethUtil.bufferToHex(ethUtil.publicToAddress(publicSignKey));
20
+ }
21
+ catch (e) {
22
+ return 'InvalidFormat';
23
+ }
24
+ if (receiverAddress !== data.address) {
25
+ return 'InvalidSignature';
26
+ }
27
+ if (data.destinary !== intendedRecipientAddress) {
28
+ return 'NotForYou';
29
+ }
30
+ if ((new Date(data.end)).getTime() < (new Date()).getTime()) {
31
+ return 'Expired';
32
+ }
33
+ return { signature, data };
34
+ }
35
+ //# sourceMappingURL=qr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr.js","sourceRoot":"","sources":["../src/qr.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,iBAAiB,CAAA;AAGrC,MAAM,UAAU,uBAAuB,CAAE,QAAQ,EAAE,wBAAwB;IACzE,IAAI,IAAW,EAAE,SAAiB,CAAA;IAClC,IAAI;QACF,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;KAC7C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,eAAe,CAAA;KACvB;IACD,OAAO,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,wBAAwB,CAAC,CAAA;AACjE,CAAC;AAED,MAAM,UAAU,aAAa,CAAE,IAAI,EAAE,SAAS,EAAE,wBAAwB;IACtE,IAAI,IAAY,CAAA;IAChB,IAAI,aAAqB,CAAA;IACzB,IAAI,eAAuB,CAAA;IAC3B,IAAI;QACF,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;QACzC,aAAa,GAAG,OAAO,CAAC,SAAS,CAC/B,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;QAC9C,eAAe,GAAG,OAAO,CAAC,WAAW,CACnC,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAA;KAC1C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,eAAe,CAAA;KACvB;IAED,IAAI,eAAe,KAAK,IAAI,CAAC,OAAO,EAAE;QAAE,OAAO,kBAAkB,CAAA;KAAE;IACnE,IAAI,IAAI,CAAC,SAAS,KAAK,wBAAwB,EAAE;QAAE,OAAO,WAAW,CAAA;KAAE;IACvE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3D,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,31 @@
1
+ export default abstract class AjaxReqAbstract {
2
+ abstract endpoint: any;
3
+ pendingPosts: any[];
4
+ post(data: any): Promise<unknown>;
5
+ queuePost(): void;
6
+ getBalance(addr: any): Promise<unknown>;
7
+ getTransactionData(addr: any): Promise<unknown>;
8
+ sendTx(rawTx: any, additionalData: any): Promise<{
9
+ isError: boolean;
10
+ error: any;
11
+ }>;
12
+ getEstimatedGas(txobj: any): Promise<unknown>;
13
+ getEthCall(txobj: any): Promise<unknown>;
14
+ getEthCallAt(txobj: any, blockNb: any): Promise<unknown>;
15
+ enrollPost(data: any): any;
16
+ validateEnrollmentLetter(id: any, currency: any, signature: any): any;
17
+ enrollAddress(id: any, address: any, currency: any, token: any): any;
18
+ getTransList(id: any, count: any, offset: any): Promise<any>;
19
+ getTransCheck(hash: any): any;
20
+ getExportTransList(id: any, start: any, end: any): any;
21
+ getExportTransListWithId(id: any, start: any, end: any): any;
22
+ getCodesFromAddresses(addresses: any, currency: any, caller: any, signature: any): any;
23
+ getAddressesFromCode(code: any, currency: any, caller: any, signature: any): any;
24
+ getMessageKey(addr: any, withPrivate: any): any;
25
+ publishMessageKey(data: any, sign: any): any;
26
+ requestUnlock(address: any, url: any): any;
27
+ getReqMessages(addFrom: any, addTo: any): any;
28
+ publishReqMessages(data: any, sign: any): any;
29
+ currBlock(): any;
30
+ getBlock(hash: any): Promise<any>;
31
+ }
@@ -0,0 +1,127 @@
1
+ class URL {
2
+ }
3
+ URL.SERVER = 'api.php';
4
+ URL.ENROLL = 'enroll.php';
5
+ URL.TRANLIST = 'trnslist.php';
6
+ URL.TRANCHECK = 'api.php';
7
+ URL.EXPORTTRAN = 'export.php';
8
+ URL.GETCODE = 'getuid.php';
9
+ URL.GETADDRESS = 'getadd.php';
10
+ URL.KEYSTORE = 'keys.php';
11
+ URL.requestMessages = 'requestMessages.php';
12
+ export default class AjaxReqAbstract {
13
+ constructor() {
14
+ this.pendingPosts = [];
15
+ }
16
+ //
17
+ // URL.SERVER POST requests (that are using queuing mecanism)
18
+ //
19
+ post(data) {
20
+ const self = this;
21
+ return new Promise(function (resolve, reject) {
22
+ self.pendingPosts.push({ data, resolve, reject });
23
+ if (self.pendingPosts.length === 1)
24
+ self.queuePost();
25
+ });
26
+ }
27
+ queuePost() {
28
+ const { data, resolve, reject } = this.pendingPosts[0];
29
+ try {
30
+ this.endpoint.post(URL.SERVER, data).then(data => {
31
+ resolve(data.data);
32
+ });
33
+ }
34
+ catch (err) {
35
+ console.log(err);
36
+ reject(err);
37
+ }
38
+ this.pendingPosts.splice(0, 1);
39
+ if (this.pendingPosts.length > 0) {
40
+ this.queuePost();
41
+ }
42
+ }
43
+ getBalance(addr) { return this.post({ balance: addr }); }
44
+ getTransactionData(addr) { return this.post({ txdata: addr }); }
45
+ async sendTx(rawTx, additionalData) {
46
+ const data = await this.post(Object.assign({}, { rawtx: rawTx }, additionalData !== null && additionalData !== void 0 ? additionalData : {}));
47
+ return {
48
+ isError: !!data.error,
49
+ error: data.error ? data.data : data.msg
50
+ };
51
+ }
52
+ getEstimatedGas(txobj) { return this.post({ estimatedGas: txobj }); }
53
+ getEthCall(txobj) { return this.post({ ethCall: txobj }); }
54
+ getEthCallAt(txobj, blockNb) {
55
+ return this.post({ ethCallAt: txobj, blockNb });
56
+ }
57
+ //
58
+ // Other calls
59
+ //
60
+ enrollPost(data) {
61
+ return this.endpoint.post(URL.ENROLL, { data: JSON.stringify(data) });
62
+ }
63
+ validateEnrollmentLetter(id, currency, signature) {
64
+ return this.enrollPost({ id, currency, signature });
65
+ }
66
+ enrollAddress(id, address, currency, token) {
67
+ return this.enrollPost({ id, addresse: address, token, currency });
68
+ }
69
+ async getTransList(id, count, offset) {
70
+ // for some strange reasons, the answer is stringified 2 times,
71
+ // so we need to unpack each entry a second time.
72
+ const data = await this.endpoint.get(URL.TRANLIST, { addr: id, count, offset });
73
+ return data.map((dataJSON) => JSON.parse(dataJSON));
74
+ }
75
+ getTransCheck(hash) {
76
+ return this.endpoint.get(URL.TRANCHECK, { hash });
77
+ }
78
+ getExportTransList(id, start, end) {
79
+ return this.endpoint.get(URL.EXPORTTRAN, { addr: id, start, end });
80
+ }
81
+ getExportTransListWithId(id, start, end) {
82
+ return this.endpoint.get(URL.EXPORTTRAN, { addr: id, start, end });
83
+ }
84
+ getCodesFromAddresses(addresses, currency, caller, signature) {
85
+ return this.endpoint.post(URL.GETCODE, {
86
+ server: currency,
87
+ caller,
88
+ signature,
89
+ addresses
90
+ });
91
+ }
92
+ getAddressesFromCode(code, currency, caller, signature) {
93
+ return this.endpoint.post(URL.GETADDRESS, {
94
+ server: currency,
95
+ caller,
96
+ signature,
97
+ code
98
+ });
99
+ }
100
+ getMessageKey(addr, withPrivate) {
101
+ const data = { addr };
102
+ if (withPrivate)
103
+ data.private = '1';
104
+ return this.endpoint.get(URL.KEYSTORE, data);
105
+ }
106
+ publishMessageKey(data, sign) {
107
+ return this.endpoint.post(URL.KEYSTORE, { data, sign });
108
+ }
109
+ requestUnlock(address, url) {
110
+ return this.endpoint.post(url, { address });
111
+ }
112
+ getReqMessages(addFrom, addTo) {
113
+ return this.endpoint.get(URL.requestMessages, { add_req: addFrom, add_cli: addTo });
114
+ }
115
+ publishReqMessages(data, sign) {
116
+ return this.endpoint.post(URL.requestMessages, { data, sign });
117
+ }
118
+ currBlock() { return this.endpoint.get(URL.SERVER); }
119
+ async getBlock(hash) {
120
+ let res = await this.endpoint.get(URL.SERVER, { hash });
121
+ if (res && typeof res !== 'object') {
122
+ res = JSON.parse(res).transaction;
123
+ }
124
+ return res;
125
+ }
126
+ }
127
+ //# sourceMappingURL=ajaxReq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ajaxReq.js","sourceRoot":"","sources":["../../src/rest/ajaxReq.ts"],"names":[],"mappings":"AACA,MAAM,GAAG;;AACA,UAAM,GAAG,SAAS,CAAC;AACnB,UAAM,GAAG,YAAY,CAAC;AACtB,YAAQ,GAAG,cAAc,CAAC;AAC1B,aAAS,GAAG,SAAS,CAAC;AACtB,cAAU,GAAG,YAAY,CAAC;AAC1B,WAAO,GAAG,YAAY,CAAC;AACvB,cAAU,GAAG,YAAY,CAAC;AAC1B,YAAQ,GAAG,UAAU,CAAC;AACtB,mBAAe,GAAG,qBAAqB,CAAC;AAIjD,MAAM,CAAC,OAAO,OAAgB,eAAe;IAA7C;QAME,iBAAY,GAAG,EAAE,CAAA;IA0InB,CAAC;IAxIC,EAAE;IACF,6DAA6D;IAC7D,EAAE;IAEF,IAAI,CAAE,IAAI;QACR,MAAM,IAAI,GAAG,IAAI,CAAA;QACjB,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;YAC1C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;YACjD,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC;gBAAE,IAAI,CAAC,SAAS,EAAE,CAAA;QACtD,CAAC,CAAC,CAAA;IACJ,CAAC;I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+1,18 @@
1
+ import HttpAbstract from './http';
2
+ /**
3
+ * Serialize data, adds default config and transfer to code http module
4
+ *
5
+ */
6
+ declare abstract class PostSerializedHttpAbstract extends HttpAbstract {
7
+ post(...[url, data, opts]: any[]): Promise<any>;
8
+ }
9
+ /**
10
+ * Prepend endpoint address to url, and support passing data to
11
+ * querystring when method is GET.
12
+ */
13
+ export default abstract class EndpointAbstract extends PostSerializedHttpAbstract {
14
+ baseUrl: string;
15
+ constructor(baseUrl: any);
16
+ request(method: any, url: any, ...args: any[]): Promise<any>;
17
+ }
18
+ export {};
@@ -0,0 +1,26 @@
1
+ import HttpAbstract from './http';
2
+ import postSerializer from './serializer';
3
+ /**
4
+ * Serialize data, adds default config and transfer to code http module
5
+ *
6
+ */
7
+ class PostSerializedHttpAbstract extends HttpAbstract {
8
+ post(...[url, data, opts]) {
9
+ return super.post(url, postSerializer(data), opts);
10
+ }
11
+ }
12
+ /**
13
+ * Prepend endpoint address to url, and support passing data to
14
+ * querystring when method is GET.
15
+ */
16
+ export default class EndpointAbstract extends PostSerializedHttpAbstract {
17
+ constructor(baseUrl) {
18
+ super();
19
+ this.baseUrl = baseUrl;
20
+ }
21
+ request(method, url, ...args) {
22
+ url = url.includes('://') ? url : this.baseUrl + url;
23
+ return super.request(method, url, ...args);
24
+ }
25
+ }
26
+ //# sourceMappingURL=endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/rest/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AACjC,OAAO,cAAc,MAAM,cAAc,CAAA;AAEzC;;;GAGG;AACH,MAAe,0BAA2B,SAAQ,YAAY;IAC5D,IAAI,CAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAQ;QAC/B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;IACpD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAgB,gBAAiB,SAAQ,0BAA0B;IAI/E,YAAa,OAAO;QAClB,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,OAAO,CAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAW;QAClC,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;QACpD,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAC5C,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import * as t from '../type';
2
+ /**
3
+ * Support passing data to querystring when method is GET.
4
+ */
5
+ export default abstract class HttpAbstract {
6
+ protected abstract httpRequest: t.HttpRequest;
7
+ request(...[method, url, data, opts]: any[]): Promise<any>;
8
+ get(...args: any[]): Promise<any>;
9
+ post(...args: any[]): Promise<any>;
10
+ }