@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.
- package/LICENSE +661 -0
- package/README.md +45 -0
- package/build/bcRead.d.ts +15 -0
- package/build/bcRead.js +123 -0
- package/build/bcRead.js.map +1 -0
- package/build/bcTransaction.d.ts +10 -0
- package/build/bcTransaction.js +135 -0
- package/build/bcTransaction.js.map +1 -0
- package/build/blockies.d.ts +1 -0
- package/build/blockies.js +91 -0
- package/build/blockies.js.map +1 -0
- package/build/config.d.ts +6 -0
- package/build/config.js +25 -0
- package/build/config.js.map +1 -0
- package/build/connection.d.ts +58 -0
- package/build/connection.js +204 -0
- package/build/connection.js.map +1 -0
- package/build/customization.d.ts +37 -0
- package/build/customization.js +129 -0
- package/build/customization.js.map +1 -0
- package/build/ethereum/cipher.d.ts +3 -0
- package/build/ethereum/cipher.js +94 -0
- package/build/ethereum/cipher.js.map +1 -0
- package/build/ethereum/ethFuncs.d.ts +12 -0
- package/build/ethereum/ethFuncs.js +70 -0
- package/build/ethereum/ethFuncs.js.map +1 -0
- package/build/ethereum/etherUnits.d.ts +5 -0
- package/build/ethereum/etherUnits.js +60 -0
- package/build/ethereum/etherUnits.js.map +1 -0
- package/build/ethereum/myetherwallet.d.ts +47 -0
- package/build/ethereum/myetherwallet.js +294 -0
- package/build/ethereum/myetherwallet.js.map +1 -0
- package/build/ethereum/uiFuncs.d.ts +3 -0
- package/build/ethereum/uiFuncs.js +51 -0
- package/build/ethereum/uiFuncs.js.map +1 -0
- package/build/index.d.ts +111 -0
- package/build/index.js +310 -0
- package/build/index.js.map +1 -0
- package/build/memo.d.ts +6 -0
- package/build/memo.js +24 -0
- package/build/memo.js.map +1 -0
- package/build/qr.d.ts +8 -0
- package/build/qr.js +35 -0
- package/build/qr.js.map +1 -0
- package/build/rest/ajaxReq.d.ts +31 -0
- package/build/rest/ajaxReq.js +127 -0
- package/build/rest/ajaxReq.js.map +1 -0
- package/build/rest/endpoint.d.ts +18 -0
- package/build/rest/endpoint.js +26 -0
- package/build/rest/endpoint.js.map +1 -0
- package/build/rest/http.d.ts +10 -0
- package/build/rest/http.js +60 -0
- package/build/rest/http.js.map +1 -0
- package/build/rest/serializer.d.ts +1 -0
- package/build/rest/serializer.js +94 -0
- package/build/rest/serializer.js.map +1 -0
- package/build/type.d.ts +24 -0
- package/build/type.js +9 -0
- package/build/type.js.map +1 -0
- package/build/wallet.d.ts +35 -0
- package/build/wallet.js +162 -0
- package/build/wallet.js.map +1 -0
- package/package.json +41 -0
- package/src/bcRead.ts +184 -0
- package/src/bcTransaction.ts +157 -0
- package/src/blockies.ts +113 -0
- package/src/config.ts +33 -0
- package/src/connection.ts +243 -0
- package/src/customization.ts +156 -0
- package/src/ethereum/cipher.ts +118 -0
- package/src/ethereum/ethFuncs.ts +73 -0
- package/src/ethereum/etherUnits.ts +66 -0
- package/src/ethereum/myetherwallet.ts +354 -0
- package/src/ethereum/uiFuncs.ts +55 -0
- package/src/index.ts +366 -0
- package/src/memo.ts +37 -0
- package/src/qr.ts +34 -0
- package/src/rest/ajaxReq.ts +160 -0
- package/src/rest/endpoint.ts +31 -0
- package/src/rest/http.ts +69 -0
- package/src/rest/serializer.ts +99 -0
- package/src/type.ts +37 -0
- package/src/wallet.ts +200 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import * as config from './config';
|
|
2
|
+
class ConnectionAbstract {
|
|
3
|
+
///
|
|
4
|
+
// [High level] Look for an available IPFS/IPNS node and return it
|
|
5
|
+
///
|
|
6
|
+
async lookupAvailableComChainRepo(storedEndPointsSuggestion) {
|
|
7
|
+
// 1. Check if a list of endpoint is stored locally (avoid a IPNS slow call)
|
|
8
|
+
const storedEndPoints = storedEndPointsSuggestion || [];
|
|
9
|
+
const endPointLists = [
|
|
10
|
+
storedEndPoints,
|
|
11
|
+
config.confEndPointsOur,
|
|
12
|
+
config.confEndPointsOther // 3. As a backup try standard ipfs servers (slow)
|
|
13
|
+
];
|
|
14
|
+
for (let i = 0; i < endPointLists.length; i++) {
|
|
15
|
+
const repo = await this.checkRepo(endPointLists[i]);
|
|
16
|
+
if (repo)
|
|
17
|
+
return repo;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
///
|
|
22
|
+
// [High level] Get the list of endpoints and randomly select a up
|
|
23
|
+
// and running one
|
|
24
|
+
///
|
|
25
|
+
async acquireEndPoint(repo) {
|
|
26
|
+
const apiNodes = await this.getCCEndPointList(repo);
|
|
27
|
+
if (!apiNodes)
|
|
28
|
+
return false;
|
|
29
|
+
const endpoint = await this.selectEndPoint(apiNodes);
|
|
30
|
+
return { apiNodes, endpoint };
|
|
31
|
+
}
|
|
32
|
+
///
|
|
33
|
+
// [Lower level] Get the list of ComChain end-points from given repo
|
|
34
|
+
///
|
|
35
|
+
getCCEndPointList(repo) {
|
|
36
|
+
return this.http.get(repo + config.nodesRepo, { _: new Date().getTime() });
|
|
37
|
+
}
|
|
38
|
+
///
|
|
39
|
+
// [Lower level] Select a ComChain end-point with up and running APIs
|
|
40
|
+
///
|
|
41
|
+
async selectEndPoint(nodes) {
|
|
42
|
+
while (nodes.length > 0) {
|
|
43
|
+
// randomly select a node (poor man's load balancing)
|
|
44
|
+
const id = Math.floor((Math.random() * nodes.length));
|
|
45
|
+
const node = nodes[id];
|
|
46
|
+
// check the node is up and running
|
|
47
|
+
const success = await this.testNode(node);
|
|
48
|
+
if (success)
|
|
49
|
+
return node;
|
|
50
|
+
nodes.splice(id, 1);
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
///
|
|
55
|
+
// [Lower level] Test if a end-point has up and running APIs
|
|
56
|
+
///
|
|
57
|
+
async testNode(apiAddress) {
|
|
58
|
+
const result = await this.testDbApi(apiAddress);
|
|
59
|
+
if (!result)
|
|
60
|
+
return false;
|
|
61
|
+
return this.testApi(apiAddress);
|
|
62
|
+
}
|
|
63
|
+
// //////////////////////////////////////////////////////////////////////////
|
|
64
|
+
async checkRepo(repoList) {
|
|
65
|
+
while (repoList === null || repoList === void 0 ? void 0 : repoList.length) {
|
|
66
|
+
const id = Math.floor((Math.random() * repoList.length));
|
|
67
|
+
const repo = repoList[id];
|
|
68
|
+
try {
|
|
69
|
+
await this.http.get(repo + config.ping, null, { timeout: 3000 });
|
|
70
|
+
console.log(`Connection OK to ${repo}`);
|
|
71
|
+
return repo;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
console.log(`Failed to make contact ${repo} in less that 3s`);
|
|
75
|
+
console.log(` Reason: ${err}`);
|
|
76
|
+
repoList.splice(id, 1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
async testApi(apiAddress) {
|
|
82
|
+
try {
|
|
83
|
+
const answer = await this.http.get(apiAddress + '/api.php', null, { timeout: 5000 });
|
|
84
|
+
return answer !== 'null' && !answer.error && answer;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.log(`API Check: HTTP request to ${apiAddress} failed`, err);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async testDbApi(apiAddress) {
|
|
92
|
+
try {
|
|
93
|
+
const answer = await this.http.get(apiAddress + '/dbcheck.php', null, { timeout: 5000 });
|
|
94
|
+
return answer === 'pong';
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
console.log(`DbAPI Check: HTTP request to ${apiAddress} failed`, err);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets the configuration for the given currency
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
async getConfJSON(repo, currencyName) {
|
|
106
|
+
try {
|
|
107
|
+
return await this.http.get(`${repo}${config.configRepo}/${currencyName}.json`, { _: new Date().getTime() });
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Manages Persistent Store to keep list of nodes and avoid IPFS lookup
|
|
116
|
+
* when possible.
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
export default class ConnectionMgrAbstract extends ConnectionAbstract {
|
|
120
|
+
/**
|
|
121
|
+
* This lookup will store result in memory for speeding other methods.
|
|
122
|
+
*/
|
|
123
|
+
async lookupAvailableComChainRepo(storedEndPointsSuggestion) {
|
|
124
|
+
if (!storedEndPointsSuggestion) {
|
|
125
|
+
const apiNodeSuggestions = this.persistentStore.get('ApiNodes', '[]');
|
|
126
|
+
storedEndPointsSuggestion = JSON.parse(apiNodeSuggestions);
|
|
127
|
+
}
|
|
128
|
+
const repo = await super.lookupAvailableComChainRepo(storedEndPointsSuggestion);
|
|
129
|
+
if (!repo) {
|
|
130
|
+
throw new Error('No repository available.');
|
|
131
|
+
}
|
|
132
|
+
this.repo = repo;
|
|
133
|
+
return repo;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* This lookup will store result in memory for speeding other methods.
|
|
137
|
+
* and saves the result in persistentStore for faster calls.
|
|
138
|
+
*/
|
|
139
|
+
async acquireEndPoint(repo) {
|
|
140
|
+
if (!repo) {
|
|
141
|
+
if (!this.repo) {
|
|
142
|
+
// Will have a look in the persistent store for suggestions,
|
|
143
|
+
// and save in `this.repo` the result for other methods.
|
|
144
|
+
await this.lookupAvailableComChainRepo();
|
|
145
|
+
}
|
|
146
|
+
repo = this.repo;
|
|
147
|
+
}
|
|
148
|
+
const apiNodesEndpoint = await super.acquireEndPoint(repo);
|
|
149
|
+
if (!apiNodesEndpoint) {
|
|
150
|
+
throw new Error('Endpoint list retrieval failed.');
|
|
151
|
+
}
|
|
152
|
+
const { apiNodes, endpoint } = apiNodesEndpoint;
|
|
153
|
+
if (typeof endpoint !== 'string') {
|
|
154
|
+
throw new Error('No endpoint in list seems available.');
|
|
155
|
+
}
|
|
156
|
+
this.persistentStore.set('ApiNodes', JSON.stringify(apiNodes));
|
|
157
|
+
this.endpoint = endpoint;
|
|
158
|
+
return { apiNodes, endpoint };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* This lookup will store result in memory for speeding other methods.
|
|
162
|
+
* and saves the result in persistentStore for faster calls.
|
|
163
|
+
* - If argument `repo` is not provided, it'll use the last one in memory
|
|
164
|
+
* leaved by a previous call of `lookupAvailableComChainRepo()`.
|
|
165
|
+
* - If no previous call was made, it'll do one.
|
|
166
|
+
*/
|
|
167
|
+
async getConfJSON(currencyName, repo) {
|
|
168
|
+
if (!repo) {
|
|
169
|
+
if (!this.repo) {
|
|
170
|
+
// Will have a look in the persistent store for suggestions,
|
|
171
|
+
// and save in `this.repo` the result for other methods.
|
|
172
|
+
await this.lookupAvailableComChainRepo();
|
|
173
|
+
}
|
|
174
|
+
repo = this.repo;
|
|
175
|
+
}
|
|
176
|
+
const conf = await super.getConfJSON(repo, currencyName);
|
|
177
|
+
if (!conf) {
|
|
178
|
+
throw new Error('Failed to get conf.');
|
|
179
|
+
}
|
|
180
|
+
this.persistentStore.set('ServerConf', JSON.stringify(conf));
|
|
181
|
+
this.conf = conf;
|
|
182
|
+
// Completing with other informations
|
|
183
|
+
conf.repo = repo;
|
|
184
|
+
conf.custoRepo = repo + config.custoRepo;
|
|
185
|
+
return conf;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Return conf stored in memory or persistent storage (need to
|
|
189
|
+
* be not async).
|
|
190
|
+
*/
|
|
191
|
+
getLocalConfJSON() {
|
|
192
|
+
if (this.conf)
|
|
193
|
+
return this.conf;
|
|
194
|
+
const cfgJson = this.persistentStore.get('ServerConf');
|
|
195
|
+
if (!cfgJson)
|
|
196
|
+
return null;
|
|
197
|
+
const cfg = JSON.parse(cfgJson);
|
|
198
|
+
// Completing with other informations
|
|
199
|
+
cfg.repo = this.repo;
|
|
200
|
+
cfg.custoRepo = this.repo + config.custoRepo;
|
|
201
|
+
return cfg;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAKlC,MAAe,kBAAkB;IAK/B,GAAG;IACH,kEAAkE;IAClE,GAAG;IAEI,KAAK,CAAC,2BAA2B,CAAE,yBAAoC;QAC5E,4EAA4E;QAC5E,MAAM,eAAe,GAAG,yBAAyB,IAAI,EAAE,CAAA;QAEvD,MAAM,aAAa,GAAG;YACpB,eAAe;YACf,MAAM,CAAC,gBAAgB;YACvB,MAAM,CAAC,kBAAkB,CAAC,kDAAkD;SAC7E,CAAA;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC7C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;YACnD,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAA;SACtB;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,GAAG;IACH,kEAAkE;IAClE,kBAAkB;IAClB,GAAG;IACI,KAAK,CAAC,eAAe,CAAE,IAAY;QACxC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;QACnD,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;QAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;QACpD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA;IAC/B,CAAC;IAED,GAAG;IACH,oEAAoE;IACpE,GAAG;IACH,iBAAiB,CAAE,IAAY;QAC7B,OAAO,IAAI,CAAC,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;QACxC,OAAO,IAAI,CAAA;IACb,CAAC;IAGD;;;OAGG;IACI,gBAAgB;QACrB,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,IAAI,CAAA;QAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACtD,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC/B,qCAAqC;QACrC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACpB,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,SAAS,CAAA;QAC5C,OAAO,GAAG,CAAA;IACZ,CAAC;CAEF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default abstract class CustomizationAbstract {
|
|
2
|
+
abstract cfg: any;
|
|
3
|
+
localDefaultConf: any;
|
|
4
|
+
/**
|
|
5
|
+
* Pre-requisite: the variable confLocale should store an object with
|
|
6
|
+
* at least the following infos:
|
|
7
|
+
* localDefaultConf.server.lang
|
|
8
|
+
* localDefaultConf.server.notes
|
|
9
|
+
* localDefaultConf.server.url_Css
|
|
10
|
+
*/
|
|
11
|
+
constructor(localDefaultConf: any);
|
|
12
|
+
getCurrencyName(): any;
|
|
13
|
+
getContract1(): any;
|
|
14
|
+
getContract2(): any;
|
|
15
|
+
getContract3(): any;
|
|
16
|
+
getHelpUrl(): any;
|
|
17
|
+
getCondUrl(): any;
|
|
18
|
+
getUnlockUrl(): any;
|
|
19
|
+
getHowToUrl(): any;
|
|
20
|
+
getWalletAddress(): any;
|
|
21
|
+
getCreationMessage(): any;
|
|
22
|
+
getLang(): any;
|
|
23
|
+
getNoteValues(): any;
|
|
24
|
+
hasBn(): boolean;
|
|
25
|
+
hasNant(): any;
|
|
26
|
+
hasCM(): any;
|
|
27
|
+
hasAutor(): any;
|
|
28
|
+
hasDeleg(): any;
|
|
29
|
+
hasPayRequest(): any;
|
|
30
|
+
passwordAutocomplete(): number;
|
|
31
|
+
getCurrencies(): any;
|
|
32
|
+
getServerConfig(configName: any): any;
|
|
33
|
+
getServerConfigSwitch(configName: any, defaultValue: any): any;
|
|
34
|
+
getCurrencyAssetBaseUrl(currencyName?: string): string;
|
|
35
|
+
getCssUrl(currencyName?: string): any;
|
|
36
|
+
getCurrencyLogoUrl(currencyName?: string): string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export default class CustomizationAbstract {
|
|
2
|
+
/**
|
|
3
|
+
* Pre-requisite: the variable confLocale should store an object with
|
|
4
|
+
* at least the following infos:
|
|
5
|
+
* localDefaultConf.server.lang
|
|
6
|
+
* localDefaultConf.server.notes
|
|
7
|
+
* localDefaultConf.server.url_Css
|
|
8
|
+
*/
|
|
9
|
+
constructor(localDefaultConf) {
|
|
10
|
+
this.localDefaultConf = localDefaultConf;
|
|
11
|
+
}
|
|
12
|
+
// [High level] Get the individual configuration
|
|
13
|
+
///
|
|
14
|
+
getCurrencyName() {
|
|
15
|
+
return this.getServerConfig('name');
|
|
16
|
+
}
|
|
17
|
+
getContract1() {
|
|
18
|
+
return this.getServerConfig('contract_1');
|
|
19
|
+
}
|
|
20
|
+
getContract2() {
|
|
21
|
+
return this.getServerConfig('contract_2');
|
|
22
|
+
}
|
|
23
|
+
getContract3() {
|
|
24
|
+
return this.getServerConfig('contract_3');
|
|
25
|
+
}
|
|
26
|
+
getHelpUrl() {
|
|
27
|
+
return this.getServerConfig('url_help');
|
|
28
|
+
}
|
|
29
|
+
getCondUrl() {
|
|
30
|
+
return this.getServerConfig('url_cond');
|
|
31
|
+
}
|
|
32
|
+
getUnlockUrl() {
|
|
33
|
+
return this.getServerConfig('url_unlock');
|
|
34
|
+
}
|
|
35
|
+
getHowToUrl() {
|
|
36
|
+
return this.getServerConfig('url_howto');
|
|
37
|
+
}
|
|
38
|
+
getWalletAddress() {
|
|
39
|
+
return this.getServerConfig('address');
|
|
40
|
+
}
|
|
41
|
+
getCreationMessage() {
|
|
42
|
+
return this.getServerConfig('creat_message');
|
|
43
|
+
}
|
|
44
|
+
getLang() {
|
|
45
|
+
var _a;
|
|
46
|
+
return this.getServerConfig('lang') || ((_a = this.localDefaultConf.server) === null || _a === void 0 ? void 0 : _a.lang);
|
|
47
|
+
}
|
|
48
|
+
getNoteValues() {
|
|
49
|
+
var _a;
|
|
50
|
+
return this.getServerConfig('notes') || ((_a = this.localDefaultConf.server) === null || _a === void 0 ? void 0 : _a.notes);
|
|
51
|
+
}
|
|
52
|
+
hasBn() {
|
|
53
|
+
return !!this.getNoteValues();
|
|
54
|
+
}
|
|
55
|
+
hasNant() {
|
|
56
|
+
return this.getServerConfigSwitch('nant', false);
|
|
57
|
+
}
|
|
58
|
+
hasCM() {
|
|
59
|
+
return this.getServerConfigSwitch('CM', false);
|
|
60
|
+
}
|
|
61
|
+
hasAutor() {
|
|
62
|
+
return this.getServerConfigSwitch('autor', false);
|
|
63
|
+
}
|
|
64
|
+
hasDeleg() {
|
|
65
|
+
return this.getServerConfigSwitch('deleg', false);
|
|
66
|
+
}
|
|
67
|
+
hasPayRequest() {
|
|
68
|
+
return this.getServerConfigSwitch('payReq', false);
|
|
69
|
+
}
|
|
70
|
+
passwordAutocomplete() {
|
|
71
|
+
let number = 10000;
|
|
72
|
+
try {
|
|
73
|
+
if (this.cfg.server.passwordAutocomplete &&
|
|
74
|
+
this.cfg.server.passwordAutocomplete > 0) {
|
|
75
|
+
number = this.cfg.server.passwordAutocomplete;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
}
|
|
80
|
+
return number;
|
|
81
|
+
}
|
|
82
|
+
getCurrencies() {
|
|
83
|
+
return this.getServerConfig('currencies');
|
|
84
|
+
}
|
|
85
|
+
// ///////////////////////////////////////////////////////////////////////////
|
|
86
|
+
getServerConfig(configName) {
|
|
87
|
+
try {
|
|
88
|
+
return this.cfg.server[configName];
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
getServerConfigSwitch(configName, defaultValue) {
|
|
95
|
+
try {
|
|
96
|
+
return this.cfg.server[configName].toString().toLowerCase() === 'true';
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
return defaultValue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ///////////////////////////////////////////////////////////////////////////
|
|
103
|
+
getCurrencyAssetBaseUrl(currencyName) {
|
|
104
|
+
if (!currencyName) {
|
|
105
|
+
currencyName = this.cfg.server.name;
|
|
106
|
+
}
|
|
107
|
+
return `${this.cfg.custoRepo}${currencyName}`;
|
|
108
|
+
}
|
|
109
|
+
getCssUrl(currencyName) {
|
|
110
|
+
try {
|
|
111
|
+
// XXXvlab: I guess that we don't need to keep 'etherwallet' css names
|
|
112
|
+
return `${this.getCurrencyAssetBaseUrl(currencyName)}/css/etherwallet-master.min.css`;
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
return this.localDefaultConf.server.url_Css;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getCurrencyLogoUrl(currencyName) {
|
|
119
|
+
try {
|
|
120
|
+
// XXXvlab: I guess that 'lem' stands for leman here. Shouldn't that
|
|
121
|
+
// be agnostic ?
|
|
122
|
+
return `${this.getCurrencyAssetBaseUrl(currencyName)}/images/lem.png`;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=customization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customization.js","sourceRoot":"","sources":["../src/customization.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,OAAgB,qBAAqB;IAKjD;;;;;;OAMG;IACH,YAAa,gB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,MAAM,CAAA;SACvE;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,YAAY,CAAA;SACpB;IACH,CAAC;IAED,8EAA8E;IAEvE,uBAAuB,CAAE,YAAqB;QACnD,IAAI,CAAC,YAAY,EAAE;YACjB,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;SACpC;QACD,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,YAAY,EAAE,CAAA;IAC/C,CAAC;IAEM,SAAS,CAAE,YAAqB;QACrC,IAAI;YACF,sEAAsE;YACtE,OAAO,GAAG,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,iCAAiC,CAAA;SACtF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAA;SAC5C;IACH,CAAC;IAEM,kBAAkB,CAAE,YAAqB;QAC9C,IAAI;YACF,oEAAoE;YACpE,gBAAgB;YAChB,OAAO,GAAG,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,iBAAiB,CAAA;SACtE;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,EAAE,CAAA;SACV;IACH,CAAC;CAEF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { ec as EC } from 'elliptic';
|
|
3
|
+
/// Code adapted from https://github.com/LimelabsTech/eth-ecies
|
|
4
|
+
const ec = new EC('secp256k1');
|
|
5
|
+
function AES256CbcEncrypt(iv, key, plaintext) {
|
|
6
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
|
|
7
|
+
const firstChunk = cipher.update(plaintext);
|
|
8
|
+
const secondChunk = cipher.final();
|
|
9
|
+
return Buffer.concat([firstChunk, secondChunk]);
|
|
10
|
+
}
|
|
11
|
+
function AES256CbcDecrypt(iv, key, ciphertext) {
|
|
12
|
+
const cipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
|
|
13
|
+
const firstChunk = cipher.update(ciphertext);
|
|
14
|
+
const secondChunk = cipher.final();
|
|
15
|
+
return Buffer.concat([firstChunk, secondChunk]);
|
|
16
|
+
}
|
|
17
|
+
function BufferEqual(b1, b2) {
|
|
18
|
+
if (b1.length !== b2.length) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
let res = 0;
|
|
22
|
+
for (let i = 0; i < b1.length; i++) {
|
|
23
|
+
res |= b1[i] ^ b2[i];
|
|
24
|
+
}
|
|
25
|
+
return res === 0;
|
|
26
|
+
}
|
|
27
|
+
function Encrypt(publicKey, plaintext) {
|
|
28
|
+
/* DEBUG */
|
|
29
|
+
const pubKeyTo = Buffer.from(publicKey);
|
|
30
|
+
const ephemPrivKey = ec.keyFromPrivate(crypto.randomBytes(32));
|
|
31
|
+
const ephemPubKey = ephemPrivKey.getPublic();
|
|
32
|
+
const ephemPubKeyEncoded = Buffer.from(ephemPubKey.encode());
|
|
33
|
+
// Every EC public key begins with the 0x04 prefix before giving
|
|
34
|
+
// the location of the two point on the curve
|
|
35
|
+
const concatenated = Buffer.concat([Buffer.from([0x04]), pubKeyTo]);
|
|
36
|
+
const keys = ec.keyFromPublic(concatenated);
|
|
37
|
+
const pub = keys.getPublic();
|
|
38
|
+
const px = ephemPrivKey.derive(pub);
|
|
39
|
+
const hash = crypto.createHash('sha512')
|
|
40
|
+
.update(Buffer.from(px.toArray())).digest();
|
|
41
|
+
const iv = crypto.randomBytes(16);
|
|
42
|
+
const encryptionKey = hash.slice(0, 32);
|
|
43
|
+
const macKey = hash.slice(32);
|
|
44
|
+
const ciphertext = AES256CbcEncrypt(iv, encryptionKey, plaintext);
|
|
45
|
+
const dataToMac = Buffer.concat([iv, ephemPubKeyEncoded, ciphertext]);
|
|
46
|
+
const mac = crypto.createHmac('sha256', macKey).update(dataToMac).digest();
|
|
47
|
+
const serializedCiphertext = Buffer.concat([
|
|
48
|
+
iv,
|
|
49
|
+
ephemPubKeyEncoded,
|
|
50
|
+
mac,
|
|
51
|
+
ciphertext
|
|
52
|
+
]);
|
|
53
|
+
return serializedCiphertext.toString('hex');
|
|
54
|
+
}
|
|
55
|
+
function Decrypt(privateKey, encrypted) {
|
|
56
|
+
const encryptedBuff = Buffer.from(encrypted, 'hex');
|
|
57
|
+
const privateKeyBuff = Buffer.from(privateKey);
|
|
58
|
+
// Read iv, ephemPubKey, mac, ciphertext from encrypted message
|
|
59
|
+
const iv = encryptedBuff.slice(0, 16);
|
|
60
|
+
const ephemPubKeyEncoded = encryptedBuff.slice(16, 81);
|
|
61
|
+
const mac = encryptedBuff.slice(81, 113);
|
|
62
|
+
const ciphertext = encryptedBuff.slice(113);
|
|
63
|
+
const ephemPubKey = ec.keyFromPublic(ephemPubKeyEncoded).getPublic();
|
|
64
|
+
const px = ec.keyFromPrivate(privateKeyBuff).derive(ephemPubKey);
|
|
65
|
+
const hash = crypto.createHash('sha512')
|
|
66
|
+
.update(Buffer.from(px.toArray())).digest();
|
|
67
|
+
const encryptionKey = hash.slice(0, 32);
|
|
68
|
+
const macKey = hash.slice(32);
|
|
69
|
+
const dataToMac = Buffer.concat([iv, ephemPubKeyEncoded, ciphertext]);
|
|
70
|
+
const computedMac = crypto.createHmac('sha256', macKey)
|
|
71
|
+
.update(dataToMac).digest();
|
|
72
|
+
// Verify mac
|
|
73
|
+
if (!BufferEqual(computedMac, mac)) {
|
|
74
|
+
throw new Error('MAC mismatch');
|
|
75
|
+
}
|
|
76
|
+
const plaintext = AES256CbcDecrypt(iv, encryptionKey, ciphertext);
|
|
77
|
+
return plaintext.toString();
|
|
78
|
+
}
|
|
79
|
+
export function shortenAddress(address) {
|
|
80
|
+
if (address.toLowerCase().substring(0, 2) === '0x') {
|
|
81
|
+
address = address.substr(2);
|
|
82
|
+
}
|
|
83
|
+
return address;
|
|
84
|
+
}
|
|
85
|
+
export function cipherMsg(publicKey, message) {
|
|
86
|
+
const msgBuff = Buffer.from(message);
|
|
87
|
+
const key = Buffer.from(shortenAddress(publicKey), 'hex');
|
|
88
|
+
return Encrypt(key, msgBuff);
|
|
89
|
+
}
|
|
90
|
+
export function decipherMsg(privateKey, ciphered) {
|
|
91
|
+
const key = Buffer.from(shortenAddress(privateKey), 'hex');
|
|
92
|
+
return Decrypt(key, ciphered);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=cipher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cipher.js","sourceRoot":"","sources":["../../src/ethereum/cipher.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,UAAU,CAAA;AAEnC,+DAA+D;AAE/D,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,WAAW,CAAC,CAAA;AAE9B,SAAS,gBAAgB,CAAE,EAAE,EAAE,GAAG,EAAE,SAAS;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;IAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC3C,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;IAElC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAE,EAAE,EAAE,GAAG,EAAE,UAAU;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;IAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;IAC5C,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;IAElC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,WA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CAAC;AAED,MAAM,UAAU,SAAS,CAAE,SAAS,EAAE,OAAO;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAA;IACzD,OAAO,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,WAAW,CAAE,UAAU,EAAE,QAAQ;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAA;IAC1D,OAAO,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function validateEtherAddress(address: any): boolean;
|
|
2
|
+
export declare function validateHexString(str: any): boolean;
|
|
3
|
+
export declare function sanitizeHex(hex: any): string;
|
|
4
|
+
export declare function addTinyMoreToGas(hex: any): any;
|
|
5
|
+
export declare function decimalToHex(dec: any): any;
|
|
6
|
+
export declare function getNakedAddress(address: any): any;
|
|
7
|
+
export declare function padLeft(n: any, width: any, z?: any): any;
|
|
8
|
+
export declare function getDataObj(to: any, func: any, arrVals: any): {
|
|
9
|
+
to: any;
|
|
10
|
+
data: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function encodeNumber(number: any): any;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import ethUtil from 'ethereumjs-util';
|
|
3
|
+
import * as etherUnits from './etherUnits';
|
|
4
|
+
function isChecksumAddress(address) {
|
|
5
|
+
return address === ethUtil.toChecksumAddress(address);
|
|
6
|
+
}
|
|
7
|
+
export function validateEtherAddress(address) {
|
|
8
|
+
if (address.substring(0, 2) !== '0x')
|
|
9
|
+
return false;
|
|
10
|
+
else if (!/^(0x)?[0-9a-f]{40}$/i.test(address))
|
|
11
|
+
return false;
|
|
12
|
+
else if (/^(0x)?[0-9a-f]{40}$/.test(address) ||
|
|
13
|
+
/^(0x)?[0-9A-F]{40}$/.test(address))
|
|
14
|
+
return true;
|
|
15
|
+
else {
|
|
16
|
+
return isChecksumAddress(address);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function validateHexString(str) {
|
|
20
|
+
if (str === '')
|
|
21
|
+
return true;
|
|
22
|
+
str = str.substring(0, 2) === '0x'
|
|
23
|
+
? str.substring(2).toUpperCase()
|
|
24
|
+
: str.toUpperCase();
|
|
25
|
+
const re = /^[0-9A-F]+$/g;
|
|
26
|
+
return re.test(str);
|
|
27
|
+
}
|
|
28
|
+
export function sanitizeHex(hex) {
|
|
29
|
+
hex = hex.substring(0, 2) === '0x' ? hex.substring(2) : hex;
|
|
30
|
+
if (hex === '')
|
|
31
|
+
return '';
|
|
32
|
+
return '0x' + padLeftEven(hex);
|
|
33
|
+
}
|
|
34
|
+
function padLeftEven(hex) {
|
|
35
|
+
hex = hex.length % 2 !== 0 ? '0' + hex : hex;
|
|
36
|
+
return hex;
|
|
37
|
+
}
|
|
38
|
+
export function addTinyMoreToGas(hex) {
|
|
39
|
+
hex = this.sanitizeHex(hex);
|
|
40
|
+
return new BigNumber(hex).plus(etherUnits.getValueOfUnit('gwei'))
|
|
41
|
+
.toDigits(2).toString(16);
|
|
42
|
+
}
|
|
43
|
+
export function decimalToHex(dec) {
|
|
44
|
+
return new BigNumber(dec).toString(16);
|
|
45
|
+
}
|
|
46
|
+
export function getNakedAddress(address) {
|
|
47
|
+
return address.toLowerCase().replace('0x', '');
|
|
48
|
+
}
|
|
49
|
+
export function padLeft(n, width, z) {
|
|
50
|
+
z = z || '0';
|
|
51
|
+
n = n + '';
|
|
52
|
+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
53
|
+
}
|
|
54
|
+
export function getDataObj(to, func, arrVals) {
|
|
55
|
+
let val = '';
|
|
56
|
+
for (let i = 0; i < arrVals.length; i++)
|
|
57
|
+
val += padLeft(arrVals[i], 64);
|
|
58
|
+
return { to: to, data: func + val };
|
|
59
|
+
}
|
|
60
|
+
export function encodeNumber(number) {
|
|
61
|
+
let valueHex;
|
|
62
|
+
if (number < 0) {
|
|
63
|
+
valueHex = padLeft(new BigNumber(16).pow(64).plus(number).toString(16), 64);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
valueHex = padLeft(new BigNumber(number).toString(16), 64);
|
|
67
|
+
}
|
|
68
|
+
return valueHex;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=ethFuncs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethFuncs.js","sourceRoot":"","sources":["../../src/ethereum/ethFuncs.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAA;AACpC,OAAO,OAAO,MAAM,iBAAiB,CAAA;AAErC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAA;AAE1C,SAAS,iBAAiB,CAAE,OAAO;IACjC,OAAO,OAAO,KAAK,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;AACvD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAE,OAAO;IAC3C,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;SAC7C,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;SACvD,IAAI,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC;QACnC,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;SACpD;QAAE,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAA;KAAE;AAC5C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAE,GAAG;IACpC,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO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AE,EAAE,CAAC,CAAA;KAC3D;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getValueOfUnit(unit: any): any;
|
|
2
|
+
export declare function fiatToWei(number: any, pricePerEther: any): any;
|
|
3
|
+
export declare function toFiat(number: any, unit: any, multi: any): any;
|
|
4
|
+
export declare function toEther(number: any, unit: any): any;
|
|
5
|
+
export declare function toWei(number: any, unit: any): any;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
const unitMap = {
|
|
3
|
+
wei: '1',
|
|
4
|
+
kwei: '1000',
|
|
5
|
+
ada: '1000',
|
|
6
|
+
femtoether: '1000',
|
|
7
|
+
mwei: '1000000',
|
|
8
|
+
babbage: '1000000',
|
|
9
|
+
picoether: '1000000',
|
|
10
|
+
gwei: '1000000000',
|
|
11
|
+
shannon: '1000000000',
|
|
12
|
+
nanoether: '1000000000',
|
|
13
|
+
nano: '1000000000',
|
|
14
|
+
szabo: '1000000000000',
|
|
15
|
+
microether: '1000000000000',
|
|
16
|
+
micro: '1000000000000',
|
|
17
|
+
finney: '1000000000000000',
|
|
18
|
+
milliether: '1000000000000000',
|
|
19
|
+
milli: '1000000000000000',
|
|
20
|
+
ether: '1000000000000000000',
|
|
21
|
+
kether: '1000000000000000000000',
|
|
22
|
+
grand: '1000000000000000000000',
|
|
23
|
+
einstein: '1000000000000000000000',
|
|
24
|
+
mether: '1000000000000000000000000',
|
|
25
|
+
gether: '1000000000000000000000000000',
|
|
26
|
+
tether: '1000000000000000000000000000000'
|
|
27
|
+
};
|
|
28
|
+
export function getValueOfUnit(unit) {
|
|
29
|
+
unit = unit ? unit.toLowerCase() : 'ether';
|
|
30
|
+
const unitValue = unitMap[unit];
|
|
31
|
+
if (unitValue === undefined) {
|
|
32
|
+
throw new Error("This unit doesn't exists, please use the " +
|
|
33
|
+
'one of the following units ' + JSON.stringify(unitMap, null, 2));
|
|
34
|
+
}
|
|
35
|
+
return new BigNumber(unitValue, 10);
|
|
36
|
+
}
|
|
37
|
+
export function fiatToWei(number, pricePerEther) {
|
|
38
|
+
return new BigNumber(String(number))
|
|
39
|
+
.div(pricePerEther)
|
|
40
|
+
.times(this.getValueOfUnit('ether'))
|
|
41
|
+
.round(0)
|
|
42
|
+
.toString(10);
|
|
43
|
+
}
|
|
44
|
+
export function toFiat(number, unit, multi) {
|
|
45
|
+
return new BigNumber(this.toEther(number, unit))
|
|
46
|
+
.times(multi)
|
|
47
|
+
.round(5)
|
|
48
|
+
.toString(10);
|
|
49
|
+
}
|
|
50
|
+
export function toEther(number, unit) {
|
|
51
|
+
return new BigNumber(this.toWei(number, unit))
|
|
52
|
+
.div(this.getValueOfUnit('ether'))
|
|
53
|
+
.toString(10);
|
|
54
|
+
}
|
|
55
|
+
export function toWei(number, unit) {
|
|
56
|
+
return new BigNumber(String(number))
|
|
57
|
+
.times(this.getValueOfUnit(unit))
|
|
58
|
+
.toString(10);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=etherUnits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"etherUnits.js","sourceRoot":"","sources":["../../src/ethereum/etherUnits.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,MAAM,OAAO,GAAG;IACd,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,MAAM;IACX,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,SAAS;IACpB,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,YAAY;IACrB,SAAS,EAAE,YAAY;IACvB,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,eAAe;IACtB,UAAU,EAAE,eAAe;IAC3B,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE,kBAAkB;IAC1B,UAAU,EAAE,kBAAkB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