• R/O
  • HTTP
  • SSH
  • HTTPS

Bytom-JS-SDK: Commit

It is a project for Bytom Chrome extension JS SDK https://bytom.github.io/Bytom-JS-SDK


Commit MetaInfo

Revision48d2b86afc582d6280dc2599ef553b572ca67615 (tree)
Time2020-11-13 11:08:51
AuthorZhiting Lin <zhiting.fly@gmai...>
CommiterGitHub

Log Message

Merge pull request #2 from Bytom/dev

Dev

Change Summary

Incremental Difference

--- a/package-lock.json
+++ b/package-lock.json
@@ -9,7 +9,7 @@
99 "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz",
1010 "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==",
1111 "requires": {
12- "@babel/highlight": "7.0.0"
12+ "@babel/highlight": "^7.0.0"
1313 }
1414 },
1515 "@babel/highlight": {
@@ -17,11 +17,16 @@
1717 "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz",
1818 "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==",
1919 "requires": {
20- "chalk": "2.4.1",
21- "esutils": "2.0.2",
22- "js-tokens": "4.0.0"
20+ "chalk": "^2.0.0",
21+ "esutils": "^2.0.2",
22+ "js-tokens": "^4.0.0"
2323 }
2424 },
25+ "@types/node": {
26+ "version": "11.11.6",
27+ "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz",
28+ "integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ=="
29+ },
2530 "acorn": {
2631 "version": "5.7.3",
2732 "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz",
@@ -32,7 +37,7 @@
3237 "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-4.1.1.tgz",
3338 "integrity": "sha512-JY+iV6r+cO21KtntVvFkD+iqjtdpRUpGqKWgfkCdZq1R+kbreEl8EcdcJR4SmiIgsIQT33s6QzheQ9a275Q8xw==",
3439 "requires": {
35- "acorn": "5.7.3"
40+ "acorn": "^5.0.3"
3641 }
3742 },
3843 "ajv": {
@@ -40,10 +45,10 @@
4045 "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz",
4146 "integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==",
4247 "requires": {
43- "fast-deep-equal": "2.0.1",
44- "fast-json-stable-stringify": "2.0.0",
45- "json-schema-traverse": "0.4.1",
46- "uri-js": "4.2.2"
48+ "fast-deep-equal": "^2.0.1",
49+ "fast-json-stable-stringify": "^2.0.0",
50+ "json-schema-traverse": "^0.4.1",
51+ "uri-js": "^4.2.2"
4752 }
4853 },
4954 "ajv-keywords": {
@@ -66,7 +71,7 @@
6671 "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
6772 "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
6873 "requires": {
69- "color-convert": "1.9.3"
74+ "color-convert": "^1.9.0"
7075 }
7176 },
7277 "argparse": {
@@ -74,7 +79,7 @@
7479 "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
7580 "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
7681 "requires": {
77- "sprintf-js": "1.0.3"
82+ "sprintf-js": "~1.0.2"
7883 }
7984 },
8085 "array-union": {
@@ -82,7 +87,7 @@
8287 "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz",
8388 "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=",
8489 "requires": {
85- "array-uniq": "1.0.3"
90+ "array-uniq": "^1.0.1"
8691 }
8792 },
8893 "array-uniq": {
@@ -95,13 +100,30 @@
95100 "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz",
96101 "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0="
97102 },
103+ "asn1.js": {
104+ "version": "4.10.1",
105+ "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz",
106+ "integrity": "sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==",
107+ "requires": {
108+ "bn.js": "^4.0.0",
109+ "inherits": "^2.0.1",
110+ "minimalistic-assert": "^1.0.0"
111+ },
112+ "dependencies": {
113+ "bn.js": {
114+ "version": "4.11.8",
115+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
116+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
117+ }
118+ }
119+ },
98120 "axios": {
99121 "version": "0.18.0",
100122 "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
101123 "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
102124 "requires": {
103- "follow-redirects": "1.5.7",
104- "is-buffer": "1.1.6"
125+ "follow-redirects": "^1.3.0",
126+ "is-buffer": "^1.1.5"
105127 }
106128 },
107129 "babylon": {
@@ -120,27 +142,124 @@
120142 "resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.3.tgz",
121143 "integrity": "sha512-yuVFUvrNcoJi0sv5phmqc6P+Fl1HjRDRNOOkHY2X/3LBy2bIGNSFx4fZ95HMaXHupuS7cZR15AsvtmCIF4UEyg=="
122144 },
145+ "bip39": {
146+ "version": "3.0.2",
147+ "resolved": "https://registry.npmjs.org/bip39/-/bip39-3.0.2.tgz",
148+ "integrity": "sha512-J4E1r2N0tUylTKt07ibXvhpT2c5pyAFgvuA5q1H9uDy6dEGpjV8jmymh3MTYJDLCNbIVClSB9FbND49I6N24MQ==",
149+ "requires": {
150+ "@types/node": "11.11.6",
151+ "create-hash": "^1.1.0",
152+ "pbkdf2": "^3.0.9",
153+ "randombytes": "^2.0.1"
154+ }
155+ },
123156 "bluebird": {
124157 "version": "3.5.4",
125158 "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.4.tgz",
126159 "integrity": "sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw==",
127160 "dev": true
128161 },
162+ "bn.js": {
163+ "version": "5.1.1",
164+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.1.1.tgz",
165+ "integrity": "sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA=="
166+ },
129167 "brace-expansion": {
130168 "version": "1.1.11",
131169 "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
132170 "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
133171 "requires": {
134- "balanced-match": "1.0.0",
172+ "balanced-match": "^1.0.0",
135173 "concat-map": "0.0.1"
136174 }
137175 },
176+ "brorand": {
177+ "version": "1.1.0",
178+ "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz",
179+ "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8="
180+ },
181+ "browserify-aes": {
182+ "version": "1.2.0",
183+ "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
184+ "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==",
185+ "requires": {
186+ "buffer-xor": "^1.0.3",
187+ "cipher-base": "^1.0.0",
188+ "create-hash": "^1.1.0",
189+ "evp_bytestokey": "^1.0.3",
190+ "inherits": "^2.0.1",
191+ "safe-buffer": "^5.0.1"
192+ }
193+ },
194+ "browserify-cipher": {
195+ "version": "1.0.1",
196+ "resolved": "https://registry.npmjs.org/browserify-cipher/-/browserify-cipher-1.0.1.tgz",
197+ "integrity": "sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w==",
198+ "requires": {
199+ "browserify-aes": "^1.0.4",
200+ "browserify-des": "^1.0.0",
201+ "evp_bytestokey": "^1.0.0"
202+ }
203+ },
204+ "browserify-des": {
205+ "version": "1.0.2",
206+ "resolved": "https://registry.npmjs.org/browserify-des/-/browserify-des-1.0.2.tgz",
207+ "integrity": "sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A==",
208+ "requires": {
209+ "cipher-base": "^1.0.1",
210+ "des.js": "^1.0.0",
211+ "inherits": "^2.0.1",
212+ "safe-buffer": "^5.1.2"
213+ }
214+ },
215+ "browserify-rsa": {
216+ "version": "4.0.1",
217+ "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
218+ "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=",
219+ "requires": {
220+ "bn.js": "^4.1.0",
221+ "randombytes": "^2.0.1"
222+ },
223+ "dependencies": {
224+ "bn.js": {
225+ "version": "4.11.8",
226+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
227+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
228+ }
229+ }
230+ },
231+ "browserify-sign": {
232+ "version": "4.0.4",
233+ "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.0.4.tgz",
234+ "integrity": "sha1-qk62jl17ZYuqa/alfmMMvXqT0pg=",
235+ "requires": {
236+ "bn.js": "^4.1.1",
237+ "browserify-rsa": "^4.0.0",
238+ "create-hash": "^1.1.0",
239+ "create-hmac": "^1.1.2",
240+ "elliptic": "^6.0.0",
241+ "inherits": "^2.0.1",
242+ "parse-asn1": "^5.0.0"
243+ },
244+ "dependencies": {
245+ "bn.js": {
246+ "version": "4.11.8",
247+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
248+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
249+ }
250+ }
251+ },
252+ "buffer-xor": {
253+ "version": "1.0.3",
254+ "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
255+ "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk="
256+ },
138257 "caller-path": {
139258 "version": "0.1.0",
140259 "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz",
141260 "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=",
142261 "requires": {
143- "callsites": "0.2.0"
262+ "callsites": "^0.2.0"
144263 }
145264 },
146265 "callsites": {
@@ -154,7 +273,7 @@
154273 "integrity": "sha1-mMyJDKZS3S7w5ws3klMQ/56Q/Is=",
155274 "dev": true,
156275 "requires": {
157- "underscore-contrib": "0.3.0"
276+ "underscore-contrib": "~0.3.0"
158277 }
159278 },
160279 "chalk": {
@@ -162,9 +281,9 @@
162281 "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz",
163282 "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==",
164283 "requires": {
165- "ansi-styles": "3.2.1",
166- "escape-string-regexp": "1.0.5",
167- "supports-color": "5.5.0"
284+ "ansi-styles": "^3.2.1",
285+ "escape-string-regexp": "^1.0.5",
286+ "supports-color": "^5.3.0"
168287 }
169288 },
170289 "chardet": {
@@ -172,6 +291,15 @@
172291 "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
173292 "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA=="
174293 },
294+ "cipher-base": {
295+ "version": "1.0.4",
296+ "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz",
297+ "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==",
298+ "requires": {
299+ "inherits": "^2.0.1",
300+ "safe-buffer": "^5.0.1"
301+ }
302+ },
175303 "circular-json": {
176304 "version": "0.3.3",
177305 "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz",
@@ -182,7 +310,7 @@
182310 "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz",
183311 "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=",
184312 "requires": {
185- "restore-cursor": "2.0.0"
313+ "restore-cursor": "^2.0.0"
186314 }
187315 },
188316 "cli-width": {
@@ -208,18 +336,82 @@
208336 "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
209337 "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
210338 },
339+ "create-ecdh": {
340+ "version": "4.0.3",
341+ "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz",
342+ "integrity": "sha512-GbEHQPMOswGpKXM9kCWVrremUcBmjteUaQ01T9rkKCPDXfUHX0IoP9LpHYo2NPFampa4e+/pFDc3jQdxrxQLaw==",
343+ "requires": {
344+ "bn.js": "^4.1.0",
345+ "elliptic": "^6.0.0"
346+ },
347+ "dependencies": {
348+ "bn.js": {
349+ "version": "4.11.8",
350+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
351+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
352+ }
353+ }
354+ },
355+ "create-hash": {
356+ "version": "1.2.0",
357+ "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
358+ "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
359+ "requires": {
360+ "cipher-base": "^1.0.1",
361+ "inherits": "^2.0.1",
362+ "md5.js": "^1.3.4",
363+ "ripemd160": "^2.0.1",
364+ "sha.js": "^2.4.0"
365+ }
366+ },
367+ "create-hmac": {
368+ "version": "1.1.7",
369+ "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
370+ "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
371+ "requires": {
372+ "cipher-base": "^1.0.3",
373+ "create-hash": "^1.1.0",
374+ "inherits": "^2.0.1",
375+ "ripemd160": "^2.0.0",
376+ "safe-buffer": "^5.0.1",
377+ "sha.js": "^2.4.8"
378+ }
379+ },
211380 "cross-spawn": {
212381 "version": "6.0.5",
213382 "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
214383 "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==",
215384 "requires": {
216- "nice-try": "1.0.5",
217- "path-key": "2.0.1",
218- "semver": "5.5.1",
219- "shebang-command": "1.2.0",
220- "which": "1.3.1"
385+ "nice-try": "^1.0.4",
386+ "path-key": "^2.0.1",
387+ "semver": "^5.5.0",
388+ "shebang-command": "^1.2.0",
389+ "which": "^1.2.9"
221390 }
222391 },
392+ "crypto-browserify": {
393+ "version": "3.12.0",
394+ "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz",
395+ "integrity": "sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==",
396+ "requires": {
397+ "browserify-cipher": "^1.0.0",
398+ "browserify-sign": "^4.0.0",
399+ "create-ecdh": "^4.0.0",
400+ "create-hash": "^1.1.0",
401+ "create-hmac": "^1.1.0",
402+ "diffie-hellman": "^5.0.0",
403+ "inherits": "^2.0.1",
404+ "pbkdf2": "^3.0.3",
405+ "public-encrypt": "^4.0.0",
406+ "randombytes": "^2.0.0",
407+ "randomfill": "^1.0.3"
408+ }
409+ },
410+ "crypto-js": {
411+ "version": "4.0.0",
412+ "resolved": "https://registry.npm.taobao.org/crypto-js/download/crypto-js-4.0.0.tgz?cache=0&sync_timestamp=1581509247325&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-js%2Fdownload%2Fcrypto-js-4.0.0.tgz",
413+ "integrity": "sha1-KQSrJnep0EKFai6i74DekuSjbcw="
414+ },
223415 "debug": {
224416 "version": "3.1.0",
225417 "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
@@ -238,13 +430,39 @@
238430 "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz",
239431 "integrity": "sha1-wSyYHQZ4RshLyvhiz/kw2Qf/0ag=",
240432 "requires": {
241- "globby": "5.0.0",
242- "is-path-cwd": "1.0.0",
243- "is-path-in-cwd": "1.0.1",
244- "object-assign": "4.1.1",
245- "pify": "2.3.0",
246- "pinkie-promise": "2.0.1",
247- "rimraf": "2.6.2"
433+ "globby": "^5.0.0",
434+ "is-path-cwd": "^1.0.0",
435+ "is-path-in-cwd": "^1.0.0",
436+ "object-assign": "^4.0.1",
437+ "pify": "^2.0.0",
438+ "pinkie-promise": "^2.0.0",
439+ "rimraf": "^2.2.8"
440+ }
441+ },
442+ "des.js": {
443+ "version": "1.0.1",
444+ "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz",
445+ "integrity": "sha512-Q0I4pfFrv2VPd34/vfLrFOoRmlYj3OV50i7fskps1jZWK1kApMWWT9G6RRUeYedLcBDIhnSDaUvJMb3AhUlaEA==",
446+ "requires": {
447+ "inherits": "^2.0.1",
448+ "minimalistic-assert": "^1.0.0"
449+ }
450+ },
451+ "diffie-hellman": {
452+ "version": "5.0.3",
453+ "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
454+ "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==",
455+ "requires": {
456+ "bn.js": "^4.1.0",
457+ "miller-rabin": "^4.0.0",
458+ "randombytes": "^2.0.0"
459+ },
460+ "dependencies": {
461+ "bn.js": {
462+ "version": "4.11.8",
463+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
464+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
465+ }
248466 }
249467 },
250468 "docdash": {
@@ -258,7 +476,28 @@
258476 "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
259477 "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==",
260478 "requires": {
261- "esutils": "2.0.2"
479+ "esutils": "^2.0.2"
480+ }
481+ },
482+ "elliptic": {
483+ "version": "6.5.2",
484+ "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz",
485+ "integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==",
486+ "requires": {
487+ "bn.js": "^4.4.0",
488+ "brorand": "^1.0.1",
489+ "hash.js": "^1.0.0",
490+ "hmac-drbg": "^1.0.0",
491+ "inherits": "^2.0.1",
492+ "minimalistic-assert": "^1.0.0",
493+ "minimalistic-crypto-utils": "^1.0.0"
494+ },
495+ "dependencies": {
496+ "bn.js": {
497+ "version": "4.11.8",
498+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
499+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
500+ }
262501 }
263502 },
264503 "escape-string-regexp": {
@@ -271,44 +510,44 @@
271510 "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.6.1.tgz",
272511 "integrity": "sha512-hgrDtGWz368b7Wqf+v1Z69O3ZebNR0+GA7PtDdbmuz4rInFVUV9uw7whjZEiWyLzCjVb5Rs5WRN1TAS6eo7AYA==",
273512 "requires": {
274- "@babel/code-frame": "7.0.0",
275- "ajv": "6.5.4",
276- "chalk": "2.4.1",
277- "cross-spawn": "6.0.5",
278- "debug": "4.1.0",
279- "doctrine": "2.1.0",
280- "eslint-scope": "4.0.0",
281- "eslint-utils": "1.3.1",
282- "eslint-visitor-keys": "1.0.0",
283- "espree": "4.0.0",
284- "esquery": "1.0.1",
285- "esutils": "2.0.2",
286- "file-entry-cache": "2.0.0",
287- "functional-red-black-tree": "1.0.1",
288- "glob": "7.1.3",
289- "globals": "11.8.0",
290- "ignore": "4.0.6",
291- "imurmurhash": "0.1.4",
292- "inquirer": "6.2.0",
293- "is-resolvable": "1.1.0",
294- "js-yaml": "3.12.0",
295- "json-stable-stringify-without-jsonify": "1.0.1",
296- "levn": "0.3.0",
297- "lodash": "4.17.11",
298- "minimatch": "3.0.4",
299- "mkdirp": "0.5.1",
300- "natural-compare": "1.4.0",
301- "optionator": "0.8.2",
302- "path-is-inside": "1.0.2",
303- "pluralize": "7.0.0",
304- "progress": "2.0.0",
305- "regexpp": "2.0.1",
306- "require-uncached": "1.0.3",
307- "semver": "5.5.1",
308- "strip-ansi": "4.0.0",
309- "strip-json-comments": "2.0.1",
310- "table": "4.0.3",
311- "text-table": "0.2.0"
513+ "@babel/code-frame": "^7.0.0",
514+ "ajv": "^6.5.3",
515+ "chalk": "^2.1.0",
516+ "cross-spawn": "^6.0.5",
517+ "debug": "^4.0.1",
518+ "doctrine": "^2.1.0",
519+ "eslint-scope": "^4.0.0",
520+ "eslint-utils": "^1.3.1",
521+ "eslint-visitor-keys": "^1.0.0",
522+ "espree": "^4.0.0",
523+ "esquery": "^1.0.1",
524+ "esutils": "^2.0.2",
525+ "file-entry-cache": "^2.0.0",
526+ "functional-red-black-tree": "^1.0.1",
527+ "glob": "^7.1.2",
528+ "globals": "^11.7.0",
529+ "ignore": "^4.0.6",
530+ "imurmurhash": "^0.1.4",
531+ "inquirer": "^6.1.0",
532+ "is-resolvable": "^1.1.0",
533+ "js-yaml": "^3.12.0",
534+ "json-stable-stringify-without-jsonify": "^1.0.1",
535+ "levn": "^0.3.0",
536+ "lodash": "^4.17.5",
537+ "minimatch": "^3.0.4",
538+ "mkdirp": "^0.5.1",
539+ "natural-compare": "^1.4.0",
540+ "optionator": "^0.8.2",
541+ "path-is-inside": "^1.0.2",
542+ "pluralize": "^7.0.0",
543+ "progress": "^2.0.0",
544+ "regexpp": "^2.0.0",
545+ "require-uncached": "^1.0.3",
546+ "semver": "^5.5.1",
547+ "strip-ansi": "^4.0.0",
548+ "strip-json-comments": "^2.0.1",
549+ "table": "^4.0.3",
550+ "text-table": "^0.2.0"
312551 },
313552 "dependencies": {
314553 "debug": {
@@ -316,7 +555,7 @@
316555 "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz",
317556 "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==",
318557 "requires": {
319- "ms": "2.1.1"
558+ "ms": "^2.1.1"
320559 }
321560 },
322561 "ms": {
@@ -331,8 +570,8 @@
331570 "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz",
332571 "integrity": "sha512-1G6UTDi7Jc1ELFwnR58HV4fK9OQK4S6N985f166xqXxpjU6plxFISJa2Ba9KCQuFa8RCnj/lSFJbHo7UFDBnUA==",
333572 "requires": {
334- "esrecurse": "4.2.1",
335- "estraverse": "4.2.0"
573+ "esrecurse": "^4.1.0",
574+ "estraverse": "^4.1.1"
336575 }
337576 },
338577 "eslint-utils": {
@@ -350,8 +589,8 @@
350589 "resolved": "https://registry.npmjs.org/espree/-/espree-4.0.0.tgz",
351590 "integrity": "sha512-kapdTCt1bjmspxStVKX6huolXVV5ZfyZguY1lcfhVVZstce3bqxH9mcLzNn3/mlgW6wQ732+0fuG9v7h0ZQoKg==",
352591 "requires": {
353- "acorn": "5.7.3",
354- "acorn-jsx": "4.1.1"
592+ "acorn": "^5.6.0",
593+ "acorn-jsx": "^4.1.1"
355594 }
356595 },
357596 "esprima": {
@@ -364,7 +603,7 @@
364603 "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz",
365604 "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==",
366605 "requires": {
367- "estraverse": "4.2.0"
606+ "estraverse": "^4.0.0"
368607 }
369608 },
370609 "esrecurse": {
@@ -372,7 +611,7 @@
372611 "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz",
373612 "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==",
374613 "requires": {
375- "estraverse": "4.2.0"
614+ "estraverse": "^4.1.0"
376615 }
377616 },
378617 "estraverse": {
@@ -385,14 +624,23 @@
385624 "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
386625 "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs="
387626 },
627+ "evp_bytestokey": {
628+ "version": "1.0.3",
629+ "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz",
630+ "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==",
631+ "requires": {
632+ "md5.js": "^1.3.4",
633+ "safe-buffer": "^5.1.1"
634+ }
635+ },
388636 "external-editor": {
389637 "version": "3.0.3",
390638 "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz",
391639 "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==",
392640 "requires": {
393- "chardet": "0.7.0",
394- "iconv-lite": "0.4.24",
395- "tmp": "0.0.33"
641+ "chardet": "^0.7.0",
642+ "iconv-lite": "^0.4.24",
643+ "tmp": "^0.0.33"
396644 }
397645 },
398646 "fast-deep-equal": {
@@ -415,7 +663,7 @@
415663 "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
416664 "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=",
417665 "requires": {
418- "escape-string-regexp": "1.0.5"
666+ "escape-string-regexp": "^1.0.5"
419667 }
420668 },
421669 "file-entry-cache": {
@@ -423,8 +671,8 @@
423671 "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz",
424672 "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=",
425673 "requires": {
426- "flat-cache": "1.3.0",
427- "object-assign": "4.1.1"
674+ "flat-cache": "^1.2.1",
675+ "object-assign": "^4.0.1"
428676 }
429677 },
430678 "flat-cache": {
@@ -432,10 +680,10 @@
432680 "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.0.tgz",
433681 "integrity": "sha1-0wMLMrOBVPTjt+nHCfSQ9++XxIE=",
434682 "requires": {
435- "circular-json": "0.3.3",
436- "del": "2.2.2",
437- "graceful-fs": "4.1.11",
438- "write": "0.2.1"
683+ "circular-json": "^0.3.1",
684+ "del": "^2.0.2",
685+ "graceful-fs": "^4.1.2",
686+ "write": "^0.2.1"
439687 }
440688 },
441689 "follow-redirects": {
@@ -443,7 +691,7 @@
443691 "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.7.tgz",
444692 "integrity": "sha512-NONJVIFiX7Z8k2WxfqBjtwqMifx7X42ORLFrOZ2LTKGj71G3C0kfdyTqGqr8fx5zSX6Foo/D95dgGWbPUiwnew==",
445693 "requires": {
446- "debug": "3.1.0"
694+ "debug": "^3.1.0"
447695 }
448696 },
449697 "fs.realpath": {
@@ -461,12 +709,12 @@
461709 "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
462710 "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
463711 "requires": {
464- "fs.realpath": "1.0.0",
465- "inflight": "1.0.6",
466- "inherits": "2.0.3",
467- "minimatch": "3.0.4",
468- "once": "1.4.0",
469- "path-is-absolute": "1.0.1"
712+ "fs.realpath": "^1.0.0",
713+ "inflight": "^1.0.4",
714+ "inherits": "2",
715+ "minimatch": "^3.0.4",
716+ "once": "^1.3.0",
717+ "path-is-absolute": "^1.0.0"
470718 }
471719 },
472720 "globals": {
@@ -479,12 +727,12 @@
479727 "resolved": "https://registry.npmjs.org/globby/-/globby-5.0.0.tgz",
480728 "integrity": "sha1-69hGZ8oNuzMLmbz8aOrCvFQ3Dg0=",
481729 "requires": {
482- "array-union": "1.0.2",
483- "arrify": "1.0.1",
484- "glob": "7.1.3",
485- "object-assign": "4.1.1",
486- "pify": "2.3.0",
487- "pinkie-promise": "2.0.1"
730+ "array-union": "^1.0.1",
731+ "arrify": "^1.0.0",
732+ "glob": "^7.0.3",
733+ "object-assign": "^4.0.1",
734+ "pify": "^2.0.0",
735+ "pinkie-promise": "^2.0.0"
488736 }
489737 },
490738 "graceful-fs": {
@@ -497,12 +745,40 @@
497745 "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
498746 "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
499747 },
748+ "hash-base": {
749+ "version": "3.0.4",
750+ "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz",
751+ "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=",
752+ "requires": {
753+ "inherits": "^2.0.1",
754+ "safe-buffer": "^5.0.1"
755+ }
756+ },
757+ "hash.js": {
758+ "version": "1.1.7",
759+ "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz",
760+ "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==",
761+ "requires": {
762+ "inherits": "^2.0.3",
763+ "minimalistic-assert": "^1.0.1"
764+ }
765+ },
766+ "hmac-drbg": {
767+ "version": "1.0.1",
768+ "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",
769+ "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=",
770+ "requires": {
771+ "hash.js": "^1.0.3",
772+ "minimalistic-assert": "^1.0.0",
773+ "minimalistic-crypto-utils": "^1.0.1"
774+ }
775+ },
500776 "iconv-lite": {
501777 "version": "0.4.24",
502778 "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
503779 "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
504780 "requires": {
505- "safer-buffer": "2.1.2"
781+ "safer-buffer": ">= 2.1.2 < 3"
506782 }
507783 },
508784 "ignore": {
@@ -520,8 +796,8 @@
520796 "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
521797 "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
522798 "requires": {
523- "once": "1.4.0",
524- "wrappy": "1.0.2"
799+ "once": "^1.3.0",
800+ "wrappy": "1"
525801 }
526802 },
527803 "inherits": {
@@ -534,19 +810,19 @@
534810 "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.0.tgz",
535811 "integrity": "sha512-QIEQG4YyQ2UYZGDC4srMZ7BjHOmNk1lR2JQj5UknBapklm6WHA+VVH7N+sUdX3A7NeCfGF8o4X1S3Ao7nAcIeg==",
536812 "requires": {
537- "ansi-escapes": "3.1.0",
538- "chalk": "2.4.1",
539- "cli-cursor": "2.1.0",
540- "cli-width": "2.2.0",
541- "external-editor": "3.0.3",
542- "figures": "2.0.0",
543- "lodash": "4.17.11",
813+ "ansi-escapes": "^3.0.0",
814+ "chalk": "^2.0.0",
815+ "cli-cursor": "^2.1.0",
816+ "cli-width": "^2.0.0",
817+ "external-editor": "^3.0.0",
818+ "figures": "^2.0.0",
819+ "lodash": "^4.17.10",
544820 "mute-stream": "0.0.7",
545- "run-async": "2.3.0",
546- "rxjs": "6.3.3",
547- "string-width": "2.1.1",
548- "strip-ansi": "4.0.0",
549- "through": "2.3.8"
821+ "run-async": "^2.2.0",
822+ "rxjs": "^6.1.0",
823+ "string-width": "^2.1.0",
824+ "strip-ansi": "^4.0.0",
825+ "through": "^2.3.6"
550826 }
551827 },
552828 "is-buffer": {
@@ -569,7 +845,7 @@
569845 "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-1.0.1.tgz",
570846 "integrity": "sha512-FjV1RTW48E7CWM7eE/J2NJvAEEVektecDBVBE5Hh3nM1Jd0kvhHtX68Pr3xsDf857xt3Y4AkwVULK1Vku62aaQ==",
571847 "requires": {
572- "is-path-inside": "1.0.1"
848+ "is-path-inside": "^1.0.0"
573849 }
574850 },
575851 "is-path-inside": {
@@ -577,7 +853,7 @@
577853 "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz",
578854 "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=",
579855 "requires": {
580- "path-is-inside": "1.0.2"
856+ "path-is-inside": "^1.0.1"
581857 }
582858 },
583859 "is-promise": {
@@ -595,6 +871,11 @@
595871 "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
596872 "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
597873 },
874+ "js-sha3": {
875+ "version": "0.8.0",
876+ "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
877+ "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q=="
878+ },
598879 "js-tokens": {
599880 "version": "4.0.0",
600881 "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -605,8 +886,8 @@
605886 "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz",
606887 "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==",
607888 "requires": {
608- "argparse": "1.0.10",
609- "esprima": "4.0.1"
889+ "argparse": "^1.0.7",
890+ "esprima": "^4.0.0"
610891 }
611892 },
612893 "js2xmlparser": {
@@ -615,7 +896,7 @@
615896 "integrity": "sha1-P7YOqgicVED5MZ9RdgzNB+JJlzM=",
616897 "dev": true,
617898 "requires": {
618- "xmlcreate": "1.0.2"
899+ "xmlcreate": "^1.0.1"
619900 }
620901 },
621902 "jsdoc": {
@@ -625,17 +906,17 @@
625906 "dev": true,
626907 "requires": {
627908 "babylon": "7.0.0-beta.19",
628- "bluebird": "3.5.4",
629- "catharsis": "0.8.9",
630- "escape-string-regexp": "1.0.5",
631- "js2xmlparser": "3.0.0",
632- "klaw": "2.0.0",
633- "marked": "0.3.19",
634- "mkdirp": "0.5.1",
635- "requizzle": "0.2.1",
636- "strip-json-comments": "2.0.1",
909+ "bluebird": "~3.5.0",
910+ "catharsis": "~0.8.9",
911+ "escape-string-regexp": "~1.0.5",
912+ "js2xmlparser": "~3.0.0",
913+ "klaw": "~2.0.0",
914+ "marked": "~0.3.6",
915+ "mkdirp": "~0.5.1",
916+ "requizzle": "~0.2.1",
917+ "strip-json-comments": "~2.0.1",
637918 "taffydb": "2.6.2",
638- "underscore": "1.8.3"
919+ "underscore": "~1.8.3"
639920 }
640921 },
641922 "json-schema-traverse": {
@@ -654,7 +935,7 @@
654935 "integrity": "sha1-WcEo4Nxc5BAgEVEZTuucv4WGUPY=",
655936 "dev": true,
656937 "requires": {
657- "graceful-fs": "4.1.11"
938+ "graceful-fs": "^4.1.9"
658939 }
659940 },
660941 "levn": {
@@ -662,14 +943,14 @@
662943 "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
663944 "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=",
664945 "requires": {
665- "prelude-ls": "1.1.2",
666- "type-check": "0.3.2"
946+ "prelude-ls": "~1.1.2",
947+ "type-check": "~0.3.2"
667948 }
668949 },
669950 "lodash": {
670- "version": "4.17.11",
671- "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
672- "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
951+ "version": "4.17.15",
952+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
953+ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
673954 },
674955 "marked": {
675956 "version": "0.3.19",
@@ -677,17 +958,53 @@
677958 "integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==",
678959 "dev": true
679960 },
961+ "md5.js": {
962+ "version": "1.3.5",
963+ "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
964+ "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==",
965+ "requires": {
966+ "hash-base": "^3.0.0",
967+ "inherits": "^2.0.1",
968+ "safe-buffer": "^5.1.2"
969+ }
970+ },
971+ "miller-rabin": {
972+ "version": "4.0.1",
973+ "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz",
974+ "integrity": "sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==",
975+ "requires": {
976+ "bn.js": "^4.0.0",
977+ "brorand": "^1.0.1"
978+ },
979+ "dependencies": {
980+ "bn.js": {
981+ "version": "4.11.8",
982+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
983+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
984+ }
985+ }
986+ },
680987 "mimic-fn": {
681988 "version": "1.2.0",
682989 "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz",
683990 "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ=="
684991 },
992+ "minimalistic-assert": {
993+ "version": "1.0.1",
994+ "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
995+ "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A=="
996+ },
997+ "minimalistic-crypto-utils": {
998+ "version": "1.0.1",
999+ "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz",
1000+ "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo="
1001+ },
6851002 "minimatch": {
6861003 "version": "3.0.4",
6871004 "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
6881005 "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
6891006 "requires": {
690- "brace-expansion": "1.1.11"
1007+ "brace-expansion": "^1.1.7"
6911008 }
6921009 },
6931010 "minimist": {
@@ -733,7 +1050,7 @@
7331050 "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
7341051 "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
7351052 "requires": {
736- "wrappy": "1.0.2"
1053+ "wrappy": "1"
7371054 }
7381055 },
7391056 "onetime": {
@@ -741,7 +1058,7 @@
7411058 "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz",
7421059 "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=",
7431060 "requires": {
744- "mimic-fn": "1.2.0"
1061+ "mimic-fn": "^1.0.0"
7451062 }
7461063 },
7471064 "optionator": {
@@ -749,12 +1066,12 @@
7491066 "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz",
7501067 "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=",
7511068 "requires": {
752- "deep-is": "0.1.3",
753- "fast-levenshtein": "2.0.6",
754- "levn": "0.3.0",
755- "prelude-ls": "1.1.2",
756- "type-check": "0.3.2",
757- "wordwrap": "1.0.0"
1069+ "deep-is": "~0.1.3",
1070+ "fast-levenshtein": "~2.0.4",
1071+ "levn": "~0.3.0",
1072+ "prelude-ls": "~1.1.2",
1073+ "type-check": "~0.3.2",
1074+ "wordwrap": "~1.0.0"
7581075 }
7591076 },
7601077 "os-tmpdir": {
@@ -762,6 +1079,19 @@
7621079 "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
7631080 "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
7641081 },
1082+ "parse-asn1": {
1083+ "version": "5.1.5",
1084+ "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.5.tgz",
1085+ "integrity": "sha512-jkMYn1dcJqF6d5CpU689bq7w/b5ALS9ROVSpQDPrZsqqesUJii9qutvoT5ltGedNXMO2e16YUWIghG9KxaViTQ==",
1086+ "requires": {
1087+ "asn1.js": "^4.0.0",
1088+ "browserify-aes": "^1.0.0",
1089+ "create-hash": "^1.1.0",
1090+ "evp_bytestokey": "^1.0.0",
1091+ "pbkdf2": "^3.0.3",
1092+ "safe-buffer": "^5.1.1"
1093+ }
1094+ },
7651095 "path-is-absolute": {
7661096 "version": "1.0.1",
7671097 "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
@@ -777,6 +1107,18 @@
7771107 "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
7781108 "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
7791109 },
1110+ "pbkdf2": {
1111+ "version": "3.0.17",
1112+ "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz",
1113+ "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==",
1114+ "requires": {
1115+ "create-hash": "^1.1.2",
1116+ "create-hmac": "^1.1.4",
1117+ "ripemd160": "^2.0.1",
1118+ "safe-buffer": "^5.0.1",
1119+ "sha.js": "^2.4.8"
1120+ }
1121+ },
7801122 "pify": {
7811123 "version": "2.3.0",
7821124 "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
@@ -792,7 +1134,7 @@
7921134 "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
7931135 "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
7941136 "requires": {
795- "pinkie": "2.0.4"
1137+ "pinkie": "^2.0.0"
7961138 }
7971139 },
7981140 "pluralize": {
@@ -810,11 +1152,48 @@
8101152 "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz",
8111153 "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8="
8121154 },
1155+ "public-encrypt": {
1156+ "version": "4.0.3",
1157+ "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz",
1158+ "integrity": "sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==",
1159+ "requires": {
1160+ "bn.js": "^4.1.0",
1161+ "browserify-rsa": "^4.0.0",
1162+ "create-hash": "^1.1.0",
1163+ "parse-asn1": "^5.0.0",
1164+ "randombytes": "^2.0.1",
1165+ "safe-buffer": "^5.1.2"
1166+ },
1167+ "dependencies": {
1168+ "bn.js": {
1169+ "version": "4.11.8",
1170+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
1171+ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA=="
1172+ }
1173+ }
1174+ },
8131175 "punycode": {
8141176 "version": "2.1.1",
8151177 "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
8161178 "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
8171179 },
1180+ "randombytes": {
1181+ "version": "2.1.0",
1182+ "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
1183+ "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==",
1184+ "requires": {
1185+ "safe-buffer": "^5.1.0"
1186+ }
1187+ },
1188+ "randomfill": {
1189+ "version": "1.0.4",
1190+ "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.4.tgz",
1191+ "integrity": "sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw==",
1192+ "requires": {
1193+ "randombytes": "^2.0.5",
1194+ "safe-buffer": "^5.1.0"
1195+ }
1196+ },
8181197 "regexpp": {
8191198 "version": "2.0.1",
8201199 "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
@@ -825,8 +1204,8 @@
8251204 "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
8261205 "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=",
8271206 "requires": {
828- "caller-path": "0.1.0",
829- "resolve-from": "1.0.1"
1207+ "caller-path": "^0.1.0",
1208+ "resolve-from": "^1.0.0"
8301209 }
8311210 },
8321211 "requizzle": {
@@ -835,7 +1214,7 @@
8351214 "integrity": "sha1-aUPDUwxNmn5G8c3dUcFY/GcM294=",
8361215 "dev": true,
8371216 "requires": {
838- "underscore": "1.6.0"
1217+ "underscore": "~1.6.0"
8391218 },
8401219 "dependencies": {
8411220 "underscore": {
@@ -856,8 +1235,8 @@
8561235 "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz",
8571236 "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=",
8581237 "requires": {
859- "onetime": "2.0.1",
860- "signal-exit": "3.0.2"
1238+ "onetime": "^2.0.0",
1239+ "signal-exit": "^3.0.2"
8611240 }
8621241 },
8631242 "rimraf": {
@@ -865,7 +1244,16 @@
8651244 "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
8661245 "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
8671246 "requires": {
868- "glob": "7.1.3"
1247+ "glob": "^7.0.5"
1248+ }
1249+ },
1250+ "ripemd160": {
1251+ "version": "2.0.2",
1252+ "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz",
1253+ "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==",
1254+ "requires": {
1255+ "hash-base": "^3.0.0",
1256+ "inherits": "^2.0.1"
8691257 }
8701258 },
8711259 "run-async": {
@@ -873,7 +1261,7 @@
8731261 "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz",
8741262 "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=",
8751263 "requires": {
876- "is-promise": "2.1.0"
1264+ "is-promise": "^2.1.0"
8771265 }
8781266 },
8791267 "rxjs": {
@@ -881,25 +1269,44 @@
8811269 "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
8821270 "integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
8831271 "requires": {
884- "tslib": "1.9.3"
1272+ "tslib": "^1.9.0"
8851273 }
8861274 },
1275+ "safe-buffer": {
1276+ "version": "5.2.0",
1277+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
1278+ "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
1279+ },
8871280 "safer-buffer": {
8881281 "version": "2.1.2",
8891282 "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
8901283 "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
8911284 },
1285+ "scrypt-js": {
1286+ "version": "3.0.0",
1287+ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.0.tgz",
1288+ "integrity": "sha512-7CC7aufwukEvqdmllR0ny0QaSg0+S22xKXrXz3ZahaV6J+fgD2YAtrjtImuoDWog17/Ty9Q4HBmnXEXJ3JkfQA=="
1289+ },
8921290 "semver": {
8931291 "version": "5.5.1",
8941292 "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz",
8951293 "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw=="
8961294 },
1295+ "sha.js": {
1296+ "version": "2.4.11",
1297+ "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
1298+ "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
1299+ "requires": {
1300+ "inherits": "^2.0.1",
1301+ "safe-buffer": "^5.0.1"
1302+ }
1303+ },
8971304 "shebang-command": {
8981305 "version": "1.2.0",
8991306 "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
9001307 "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
9011308 "requires": {
902- "shebang-regex": "1.0.0"
1309+ "shebang-regex": "^1.0.0"
9031310 }
9041311 },
9051312 "shebang-regex": {
@@ -917,7 +1324,7 @@
9171324 "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz",
9181325 "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==",
9191326 "requires": {
920- "is-fullwidth-code-point": "2.0.0"
1327+ "is-fullwidth-code-point": "^2.0.0"
9211328 }
9221329 },
9231330 "sprintf-js": {
@@ -930,8 +1337,8 @@
9301337 "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
9311338 "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
9321339 "requires": {
933- "is-fullwidth-code-point": "2.0.0",
934- "strip-ansi": "4.0.0"
1340+ "is-fullwidth-code-point": "^2.0.0",
1341+ "strip-ansi": "^4.0.0"
9351342 }
9361343 },
9371344 "strip-ansi": {
@@ -939,7 +1346,7 @@
9391346 "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
9401347 "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
9411348 "requires": {
942- "ansi-regex": "3.0.0"
1349+ "ansi-regex": "^3.0.0"
9431350 }
9441351 },
9451352 "strip-json-comments": {
@@ -952,7 +1359,7 @@
9521359 "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
9531360 "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
9541361 "requires": {
955- "has-flag": "3.0.0"
1362+ "has-flag": "^3.0.0"
9561363 }
9571364 },
9581365 "table": {
@@ -960,12 +1367,12 @@
9601367 "resolved": "http://registry.npmjs.org/table/-/table-4.0.3.tgz",
9611368 "integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==",
9621369 "requires": {
963- "ajv": "6.5.4",
964- "ajv-keywords": "3.2.0",
965- "chalk": "2.4.1",
966- "lodash": "4.17.11",
1370+ "ajv": "^6.0.1",
1371+ "ajv-keywords": "^3.0.0",
1372+ "chalk": "^2.1.0",
1373+ "lodash": "^4.17.4",
9671374 "slice-ansi": "1.0.0",
968- "string-width": "2.1.1"
1375+ "string-width": "^2.1.1"
9691376 }
9701377 },
9711378 "taffydb": {
@@ -989,7 +1396,7 @@
9891396 "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
9901397 "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
9911398 "requires": {
992- "os-tmpdir": "1.0.2"
1399+ "os-tmpdir": "~1.0.2"
9931400 }
9941401 },
9951402 "tslib": {
@@ -1002,7 +1409,7 @@
10021409 "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
10031410 "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=",
10041411 "requires": {
1005- "prelude-ls": "1.1.2"
1412+ "prelude-ls": "~1.1.2"
10061413 }
10071414 },
10081415 "underscore": {
@@ -1033,7 +1440,7 @@
10331440 "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",
10341441 "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==",
10351442 "requires": {
1036- "punycode": "2.1.1"
1443+ "punycode": "^2.1.0"
10371444 }
10381445 },
10391446 "which": {
@@ -1041,7 +1448,7 @@
10411448 "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
10421449 "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
10431450 "requires": {
1044- "isexe": "2.0.0"
1451+ "isexe": "^2.0.0"
10451452 }
10461453 },
10471454 "wordwrap": {
@@ -1059,7 +1466,7 @@
10591466 "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz",
10601467 "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=",
10611468 "requires": {
1062- "mkdirp": "0.5.1"
1469+ "mkdirp": "^0.5.1"
10631470 }
10641471 },
10651472 "xmlcreate": {
--- a/package.json
+++ b/package.json
@@ -14,7 +14,16 @@
1414 "dependencies": {
1515 "axios": "^0.18.0",
1616 "bech32": "^1.1.3",
17- "eslint": "^5.6.1"
17+ "bip39": "^3.0.2",
18+ "bn.js": "^5.1.1",
19+ "create-hmac": "^1.1.7",
20+ "crypto-browserify": "^3.12.0",
21+ "crypto-js": "^4.0.0",
22+ "elliptic": "^6.5.2",
23+ "eslint": "^5.6.1",
24+ "js-sha3": "^0.8.0",
25+ "lodash": "^4.17.15",
26+ "scrypt-js": "^3.0.0"
1827 },
1928 "devDependencies": {
2029 "jsdoc": "^3.5.5",
--- a/src/api/accounts.js
+++ b/src/api/accounts.js
@@ -17,7 +17,7 @@ function accountsApi(http) {
1717 * @returns {Promise} Guid, address, label
1818 */
1919 accountsApi.prototype.create = function(params) {
20- return this.http.request('account/create-account', params);
20+ return this.http.request('account/create', params);
2121 };
2222
2323 /**
@@ -55,14 +55,13 @@ accountsApi.prototype.copyAccount = function(params) {
5555 };
5656
5757 /**
58- * Vapor API List Wallet.
58+ * BYTOM API List Wallet.
5959 *
6060 * @param {Object} params - Parameters for Wallet List.
61- * @param {String} params.start - start,
62- * @param {String} params.limit - limit
61+ * @param {String} params.pubkey - pubkey
6362 * @returns {Promise} Array of Object, with Guid, m, n, status, signers.
6463 */
65-accountsApi.prototype.copyAccount = function(params) {
64+accountsApi.prototype.listWallets = function(params) {
6665 return this.http.request('account/list-wallets', params);
6766 };
6867
--- a/src/http.js
+++ b/src/http.js
@@ -1,5 +1,6 @@
11 import axios from 'axios';
22 import {handleApiError, handleAxiosError} from './utils/http';
3+import { camelize } from "./utils/utils";
34
45 // const basePath = 'api/v1/btm';
56
@@ -22,7 +23,7 @@ export function serverHttp(host) {
2223 if (resp.status !== 200 || resp.data.code !== 200) {
2324 throw handleApiError(resp);
2425 } else if (resp.data.code === 200) {
25- return resp.data.result.data;
26+ return camelize(resp.data.data);
2627 }
2728 return resp.data;
2829 }).catch(error=>{
@@ -50,7 +51,7 @@ export function http(baseUrl) {
5051 if (resp.status !== 200 || resp.data.code !== 200) {
5152 throw handleApiError(resp);
5253 } else if (resp.data.code === 200) {
53- return resp.data.result.data;
54+ return camelize(resp.data.data);
5455 }
5556 return resp.data;
5657 }).catch(error=>{
--- a/src/sdk/accounts.js
+++ b/src/sdk/accounts.js
@@ -1,7 +1,4 @@
11 import {getDB} from '../db/db';
2-import {createAccount, createAccountReceiver} from '../wasm/func';
3-import {handleApiError, handleAxiosError} from '../utils/http';
4-
52
63 function accountsSDK(bytom){
74 this.http = bytom.serverHttp;
@@ -14,7 +11,8 @@ function accountsSDK(bytom){
1411 * @returns {Promise} List of Accounts
1512 */
1613 accountsSDK.prototype.listAccountUseServer = function() {
17- let net = this.bytom.net;
14+ let net = 'mainnet';
15+ // let net = 'testnet';
1816 let retPromise = new Promise((resolve, reject) => {
1917 getDB().then(db => {
2018 let transaction = db.transaction(['accounts-server'], 'readonly');
@@ -42,7 +40,6 @@ accountsSDK.prototype.listAccountUseServer = function() {
4240 return retPromise;
4341 };
4442
45-
4643 /**
4744 * List all addresses and the corresponding balances of a wallet.
4845 *
@@ -50,114 +47,30 @@ accountsSDK.prototype.listAccountUseServer = function() {
5047 * @param {String} guid
5148 * @returns {Promise} list of all addresses
5249 */
53-accountsSDK.prototype.listAddressUseServer = function(guid) {
50+accountsSDK.prototype.listAddressUseServer = function(address) {
5451 let net = this.bytom.net;
55- return this.http.request('account/list-addresses', {guid:guid}, net);
56-};
57-/**
58- * Create a new address for a wallet.
59- *
60- * @see https://gist.github.com/HAOYUatHZ/0c7446b8f33e7cddd590256b3824b08f#apiv1btmaccountnew-address
61- * @param {String} guid unique id for each wallet
62- * @param {String} label alias for the address to be created
63- * @returns {Promise}
64- */
65-accountsSDK.prototype.createAccountReceiverUseServer = function(guid, label) {
66- let net = this.bytom.net;
67- let retPromise = new Promise((resolve, reject) => {
68- let pm = {guid: guid};
69- if (label) {
70- pm.label = label;
71- }
72- this.http.request('account/new-address', pm, net).then(resp => {
73- let dbData = resp;
74- dbData.guid = guid;
75- dbData.net = net;
76- getDB().then(db => {
77- let transaction = db.transaction(['addresses-server'], 'readwrite');
78- let objectStore = transaction.objectStore('addresses-server');
79- delete dbData.rootXPub;
80- let request = objectStore.add(dbData);
81- request.onsuccess = function() {
82- resolve(dbData);
83- };
84- request.onerror = function() {
85- reject(request.error);
86- };
87- });
88- }).catch(error => {
89- reject(handleAxiosError(error));
90- });
91- });
92- return retPromise;
52+ return this.http.request(`account/address?address=${address}`, '', net, 'GET');
9353 };
9454
9555 /**
9656 * Create a wallet using a public key. Each wallet is identified by a guid. (by server)
97- *
57+ *
9858 * @see https://gist.github.com/HAOYUatHZ/0c7446b8f33e7cddd590256b3824b08f#endpoints
9959 * @param {String} rootXPub
10060 * @param {String} alias alias for the account
10161 * @param {String} label alias for the first address
10262 * @returns {Promise}
10363 */
104-accountsSDK.prototype.createAccountUseServer = function(rootXPub, alias, label) {
64+accountsSDK.prototype.createNewAccount = function(rootXPub, label) {
10565 let net = this.bytom.net;
106- let that = this;
107- let retPromise = new Promise((resolve, reject) => {
108- getDB().then(db => {
109- let getRequest = db.transaction(['accounts-server'], 'readonly')
110- .objectStore('accounts-server')
111- .index('alias')
112- .get(alias);
113- getRequest.onsuccess = function(e) {
114- if (e.target.result) {
115- reject(new Error('duplicate account alias'));
116- return;
117- }
118- let pm = {pubkey: rootXPub};
119- if (label) {
120- pm.label = label;
121- }
122- that.http.request('account/create', pm, net).then(resp => {
123- let dbData = resp;
124- dbData.rootXPub = rootXPub;
125- dbData.alias = alias;
126- dbData.net = net;
127- getDB().then(db => {
128- let transaction = db.transaction(['accounts-server'], 'readwrite');
129- let objectStore = transaction.objectStore('accounts-server');
130- let request = objectStore.add(dbData);
131- request.onsuccess = function() {
132- let transaction = db.transaction(['addresses-server'], 'readwrite');
133- let objectStore = transaction.objectStore('addresses-server');
134- delete dbData.rootXPub;
135- let request = objectStore.add(dbData);
136- request.onsuccess = function() {
137- resolve(dbData);
138- };
139- request.onerror = function() {
140- reject(request.error);
141- };
142- };
143- request.onerror = function() {
144- reject(request.error);
145- };
146- });
147- }).catch(error => {
148- reject(handleAxiosError(error));
149- });
150- };
151- getRequest.onerror = function() {
152- reject(getRequest.error);
153- };
154- }).catch(err => {
155- reject(err);
156- });
157- });
158- return retPromise;
66+ let pm = {pubkey: rootXPub};
67+ if (label) {
68+ pm.label = label;
69+ }
70+ return this.http.request('account/create', pm, net);
15971 };
16072
73+
16174 /**
16275 * Create a wallet using a public key. Each wallet is identified by a guid. (by server)
16376 *
@@ -167,184 +80,13 @@ accountsSDK.prototype.createAccountUseServer = function(rootXPub, alias, label)
16780 */
16881 accountsSDK.prototype.copyAccountUseServer = function(guid, coin) {
16982 let net = this.bytom.net;
170- let that = this;
171- let retPromise = new Promise((resolve, reject) => {
172- let pm = {guid};
173- if (coin) {
174- pm.coin = coin;
175- }
176-
177- that.http.request('account/copy', pm, net).then(resp => {
178- getDB().then(db => {
179- let objectStore = db.transaction(['accounts-server'], 'readwrite').objectStore('accounts-server');
180- let index = objectStore.index('guid');
181- let keyRange = IDBKeyRange.only(guid);
182- let getRequest = index.openCursor(keyRange);
183-
184- getRequest.onsuccess = function(e) {
185- const cursor = e.target.result;
186- if(cursor){
187- const accountObject = cursor.value;
188-
189- accountObject.vpAddress = resp.address;
190- const request = cursor.update(accountObject);
191- request.onsuccess = function () {
192- resolve(accountObject);
193- };
194- request.onerror = function () {
195- reject(request.error);
196- };
197- }
198- };
199- getRequest.onerror = function() {
200- reject(getRequest.error);
201- };
202- }).catch(err => {
203- throw (err);
204- });
205- }).catch(err => {
206- reject(err);
207- });
208- });
209- return retPromise;
210-};
211-
212-/**
213- * list a wallet using a guid. Each wallet is identified by a guid. (by server)
214- *
215- * @param {String} guid
216- * @param {String} coin type of coin
217- * @returns {Promise}
218- */
219-accountsSDK.prototype.listVaporAccountUseServer = function(guid) {
220- let net = this.bytom.net;
221- let that = this;
222- let retPromise = new Promise((resolve, reject) => {
223- that.http.request('account/list-addresses', {guid:guid}, net).then(resp => {
224- getDB().then(db => {
225- let objectStore = db.transaction(['accounts-server'], 'readwrite').objectStore('accounts-server');
226- let index = objectStore.index('guid');
227- let keyRange = IDBKeyRange.only(guid);
228- let getRequest = index.openCursor(keyRange);
83+ let pm = {guid};
84+ if (coin) {
85+ pm.coin = coin;
86+ }
22987
230- getRequest.onsuccess = function(e) {
231- const cursor = e.target.result;
232- if(cursor){
233- const accountObject = cursor.value;
234-
235- accountObject.vpAddress = resp[0].address;
236- const request = cursor.update(accountObject);
237- request.onsuccess = function () {
238- resolve(accountObject);
239- };
240- request.onerror = function () {
241- reject(request.error);
242- };
243- }
244- };
245- getRequest.onerror = function() {
246- reject(getRequest.error);
247- };
248- }).catch(err => {
249- throw (err);
250- });
251- }).catch(err => {
252- reject(err);
253- });
254- });
255- return retPromise;
88+ return this.http.request('account/copy', pm, net);
25689 };
25790
258-/**
259- * create account
260- *
261- * @param {String} alias
262- * @param {Int} quorum
263- * @param {String} rootXPub
264- * @returns {Promise}
265- */
266-accountsSDK.prototype.createAccount = function(alias, quorum, rootXPub) {
267- let retPromise = new Promise((resolve, reject) => {
268- getDB().then(db => {
269- let transaction = db.transaction(['accounts'], 'readwrite');
270- let objectStore = transaction.objectStore('accounts');
271- let request = objectStore.add({
272- alias:alias,
273- });
274- request.onsuccess = function () {
275- let data = {alias:alias, quorum:quorum, rootXPub:rootXPub, nextIndex:request.result};
276- createAccount(data).then(res => {
277- let jsonData = JSON.parse(res.data);
278- let putTransaction = db.transaction(['accounts'], 'readwrite');
279- let putObjectStore = putTransaction.objectStore('accounts');
280- let putRequest = putObjectStore.put(jsonData, request.result);
281- putRequest.onsuccess = function() {
282- resolve(jsonData);
283- };
284- putRequest.onerror = function() {
285- reject(putRequest.error);
286- };
287- }).catch(error => {
288- reject(error);
289- });
290- };
291- request.onerror = function() {
292- reject(request.error);
293- };
294- }).catch(error => {
295- reject(error);
296- });
297- });
298- return retPromise;
299-};
300-
301-/**
302- * create account address
303- *
304- * @param {Object} account createAccount return account Object val
305- * @param {Int} nextIndex
306- * @returns {Promise}
307- */
308-accountsSDK.prototype.createAccountReceiver = function(account) {
309- let retPromise = new Promise((resolve, reject) => {
310- getDB().then(db => {
311- let transaction = db.transaction(['addresses'], 'readwrite');
312- let objectStore = transaction.objectStore('addresses');
313- let request = objectStore.add({
314- account_id:account.id,
315- account_alias:account.alias,
316- });
317- request.onsuccess = function() {
318- let data = {account:JSON.stringify(account), nextIndex: request.result};
319- createAccountReceiver(data).then(res => {
320- let jsonData = JSON.parse(res.data);
321- let jsonDB = JSON.parse(res.db);
322- let putTransaction = db.transaction(['addresses'], 'readwrite');
323- let putObjectStore = putTransaction.objectStore('addresses');
324- let putRequest = null;
325- for (let key in jsonDB) {
326- if(!jsonDB.hasOwnProperty(key)) continue;
327- let putData = JSON.parse(jsonDB[key]);
328- putRequest = putObjectStore.put(putData, request.result);
329- }
330- putRequest.onsuccess = function() {
331- resolve(jsonData);
332- };
333- putRequest.onerror = function() {
334- reject(putRequest.error);
335- };
336- }).catch(error => {
337- reject(error);
338- });
339- };
340- request.onerror = function() {
341- reject(request.error);
342- };
343- }).catch(error => {
344- reject(error);
345- });
346- });
347- return retPromise;
348-};
34991
35092 export default accountsSDK;
\ No newline at end of file
--- a/src/sdk/keys.js
+++ b/src/sdk/keys.js
@@ -1,186 +1,162 @@
1-import {createKey, resetKeyPassword, createPubkey, signMessage, signTransaction} from '../wasm/func';
2-import {getDB} from '../db/db';
1+import {createkey, isValidMnemonic} from '../utils/key/createKey';
2+import { decryptKey} from '../utils/key/keystore';
3+import { camelize } from '../utils/utils';
4+import CryptoJS from 'crypto-js';
5+import {signMessage as signMJs} from '../utils/transaction/signMessage';
6+import Error from '../utils/error';
37
48
59 function keysSDK() {
610 }
711
812 /**
9- * reset key password
10- *
11- * @param {String}} rootXPub
12- * @param {String} oldPassword
13- * @param {String} newPassword
13+ * Create a new key.
14+ *
15+ * @param {String} alias - User specified, unique identifier.
16+ * @param {String} password - User specified, key password.
1417 */
15-keysSDK.prototype.resetKeyPassword = function(rootXPub, oldPassword, newPassword) {
16- let retPromise = new Promise((resolve, reject) => {
17- let data = {rootXPub: rootXPub, oldPassword:oldPassword, newPassword:newPassword};
18- resetKeyPassword(data).then(res => {
19- getDB().then(db => {
20- let objectStore = db.transaction(['keys'], 'readwrite').objectStore('keys');
21- let index = objectStore.index('xpub');
22- let keyRange = IDBKeyRange.only(rootXPub);
23- let getRequest = index.openCursor(keyRange);
24- getRequest.onsuccess = function (event) {
25- const cursor = event.target.result;
26- if(cursor && cursor.value.xpub === rootXPub) {
27- const updateData = cursor.value;
28- updateData.key = res.data;
29- const request = cursor.update(updateData);
30- request.onsuccess = function() {
31- resolve(true);
32- };
33- request.onerror = function() {
34- reject(new Error('db update error'));
35- };
36- } else {
37- reject(new Error('db update error: not found by rootXPub'));
38- }
39- };
40- getRequest.onerror = function () {
41- reject(new Error('db get error'));
42- };
43- }).catch(error => {
44- reject(error);
45- });
46- }).catch(error => {
47- reject(error);
48- });
49- });
50- return retPromise;
18+keysSDK.prototype.createKey = function(alias, password) {
19+ var normalizedAlias = alias.toLowerCase().trim();
20+
21+ let data = {};
22+ data.alias = normalizedAlias;
23+ data.password = password;
24+ const res = createkey(data);
25+
26+ res.vault = this.encryptMnemonic(res.mnemonic, password, res.keystore);
27+
28+ return res;
5129 };
5230
5331 /**
54- * get key by XPub
55- *
56- * @param {String} xpub
32+ * Create a new key.
33+ *
34+ * @param {String} alias - User specified, unique identifier.
35+ * @param {String} password - User specified, key password.
5736 */
58-keysSDK.prototype.getKeyByXPub = function(xpub) {
59- let retPromise = new Promise((resolve, reject) => {
60- getDB().then(db => {
61- let getRequest = db.transaction(['keys'], 'readonly')
62- .objectStore('keys')
63- .index('xpub')
64- .get(xpub);
65- getRequest.onsuccess = function(e) {
66- if(e.target.result) {
67- resolve(e.target.result.key);
68- } else {
69- reject(new Error('not found by XPub'));
70- }
71- };
72- getRequest.onerror = function() {
73- reject(new Error('db get error'));
74- };
75- }).catch(error => {
76- reject(error);
77- });
78- });
79- return retPromise;
37+keysSDK.prototype.restoreFromMnemonic = function(alias, password, mnemonic) {
38+ var normalizedAlias = alias.toLowerCase().trim();
39+
40+ let data = {};
41+ data.alias = normalizedAlias;
42+ data.password = password;
43+ data.mnemonic = mnemonic;
44+
45+ const res = createkey(data);
46+
47+ res.vault = this.encryptMnemonic(mnemonic, password, res.keystore);
48+ return res;
8049 };
8150
8251 /**
83- * List key
52+ * Create a new key.
8453 *
85- * @returns {Promise}
54+ * @param {String} alias - User specified, unique identifier.
55+ * @param {String} password - User specified, key password.
8656 */
87-keysSDK.prototype.list = function() {
88- let retPromise = new Promise((resolve, reject) => {
89- getDB().then(db => {
90- let transaction = db.transaction(['keys'], 'readonly');
91- let objectStore = transaction.objectStore('keys');
92- let oc = objectStore.openCursor();
93- let ret = [];
94- oc.onsuccess = function (event) {
95- var cursor = event.target.result;
96- if (cursor) {
97- ret.push({alias: cursor.value.alias, xpub: cursor.value.xpub});
98- cursor.continue();
99- } else {
100- resolve(ret);
101- }
102- };
103- oc.onerror = function(e){
104- reject(e);
105- };
106- }).catch(err => {
107- reject(err);
108- });
109- });
110- return retPromise;
57+keysSDK.prototype.restoreFromKeystore = function( password, keystore) {
58+
59+ const result = decryptKey(keystore, password);
60+ result.xpub = result.xPub.toString('hex');
61+ delete result['xPub'];
62+
63+ return result;
11164 };
11265
66+
11367 /**
11468 * Create a new key.
115- *
69+ *
11670 * @param {String} alias - User specified, unique identifier.
11771 * @param {String} password - User specified, key password.
11872 */
119-keysSDK.prototype.create = function(alias, password) {
120- var normalizedAlias = alias.toLowerCase().trim();
121- let retPromise = new Promise((resolve, reject) => {
122- getDB().then(db => {
123- let getRequest = db.transaction(['keys'], 'readonly')
124- .objectStore('keys')
125- .index('alias')
126- .get(normalizedAlias);
127- getRequest.onsuccess = function (e) {
128- if (e.target.result) {
129- reject(new Error('key alias already exists'));
130- return;
131- }
132- let data = {};
133- data.alias = normalizedAlias;
134- data.auth = password;
135- createKey(data).then((res) => {
136- let jsonData = JSON.parse(res.data);
137- let dbData = {
138- key:res.data,
139- xpub:jsonData.xpub,
140- alias:alias,
141- };
142- let request = db.transaction(['keys'], 'readwrite')
143- .objectStore('keys')
144- .add(dbData);
145- request.onsuccess = function () {
146- resolve({xpub:jsonData.xpub, alias: alias});
147- };
148- request.onerror = function () {
149- reject(new Error('db insert error'));
150- };
151- }).catch(error => {
152- reject(error);
153- });
154- };
155- getRequest.onerror = function () {
156- reject(new Error('db get error'));
157- };
158- }).catch(error => {
159- reject(error);
160- });
161- });
162- return retPromise;
73+keysSDK.prototype.encryptMnemonic = function(mnemonic, password, keystore) {
74+
75+ const result = decryptKey(keystore, password);
76+ const xprv = result.xPrv.toString('hex');
77+
78+ const ciphertext = CryptoJS.AES.encrypt(mnemonic, xprv);
79+
80+ return ciphertext.toString();
16381 };
16482
83+/**
84+ * Create a new key.
85+ *
86+ * @param {String} alias - User specified, unique identifier.
87+ * @param {String} password - User specified, key password.
88+ */
89+keysSDK.prototype.decryptMnemonic = function(ciphertext, password, keystore) {
90+
91+ const result = decryptKey(keystore, password);
92+ const xprv = result.xPrv.toString('hex');
93+
94+
95+ const bytes = CryptoJS.AES.decrypt(ciphertext, xprv);
96+ const plaintext = bytes.toString(CryptoJS.enc.Utf8);
97+
98+ return plaintext;
99+};
100+
101+
165102
166103 /**
167104 * Create a new key.
168105 *
169- * @param {String} xpub - xpub.
106+ * @param {String} keystore - User specified, unique identifier.
170107 */
171-keysSDK.prototype.createPubkey = function(xpub) {
172- let retPromise = new Promise((resolve, reject) => {
173- let data = {};
174- data.xpub = xpub;
175- data.seed = 1;
176- createPubkey(data).then((res) => {
177- let jsonData = JSON.parse(res.data);
178- resolve(jsonData);
179- }).catch(error => {
180- reject(error);
181- });
182- });
183- return retPromise;
108+keysSDK.prototype.isValidKeystore = function( keystore ) {
109+
110+ const walletImage = camelize(JSON.parse(keystore));
111+
112+ let keys, key;
113+ if(walletImage.keyImages && walletImage.keyImages.xkeys ){
114+ keys = walletImage.keyImages.xkeys;
115+ }
116+
117+ // match older version of backups keystore files
118+ else if(walletImage['accounts-server']){
119+ keys = walletImage.keys.map(keyItem => JSON.parse( keyItem.key ) );
120+ }else{
121+ key = walletImage;
122+ }
123+
124+ if(keys){
125+ if(keys.length>1){
126+ throw new Error('do not support multiple keystore imported.', 'BTM3004');
127+ }
128+ else if(keys.length === 1){
129+ key = keys[0];
130+ }
131+ }
132+
133+ return key;
134+};
135+
136+/**
137+ * Create a new key.
138+ *
139+ * @param {String} alias - User specified, unique identifier.
140+ * @param {String} password - User specified, key password.
141+ */
142+keysSDK.prototype.isValidMnemonic = function(mnemonic) {
143+
144+ return isValidMnemonic(mnemonic);
145+};
146+
147+/**
148+ * Create a new key.
149+ *
150+ * @param {String} alias - User specified, unique identifier.
151+ * @param {String} password - User specified, key password.
152+ */
153+keysSDK.prototype.verifyPassword = function(keystore, password) {
154+ try{
155+ decryptKey(keystore, password);
156+ }catch (e){
157+ return false;
158+ }
159+ return true;
184160 };
185161
186162 /**
@@ -190,54 +166,21 @@ keysSDK.prototype.createPubkey = function(xpub) {
190166 * @param {String} password - password.
191167 * @param {Object} address - address.
192168 */
193-keysSDK.prototype.signMessage = function(message, password, address) {
169+keysSDK.prototype.signMessageJs = function(message, password, keystore) {
170+ return signMJs(message, password, keystore);
171+};
172+
173+keysSDK.prototype.signMessageJsPromise = function(message, password, keystore) {
194174 let retPromise = new Promise((resolve, reject) => {
195- getDB().then(db => {
196- let getRequest = db.transaction(['accounts-server'], 'readonly')
197- .objectStore('accounts-server')
198- .getAll()
199-
200- getRequest.onsuccess = function (e) {
201- const result = getRequest.result.filter(obj => obj.address === address)
202- if (result.length === 0) {
203- reject(new Error('not found address'));
204- return;
205- }
206-
207- const rootXpub = result[0].rootXPub
208- let keyObject = db.transaction(['keys'], 'readonly')
209- .objectStore('keys')
210- .index('xpub')
211- .get(rootXpub);
212-
213- keyObject.onsuccess = function (e) {
214- if (!e.target.result) {
215- reject(new Error('not found xpub'));
216- return;
217- }
218-
219- let data = {};
220- data.message = message;
221- data.password = password;
222- data.key = e.target.result.key;
223- signMessage(data).then((res) => {
224- let jsonData = JSON.parse(res.data);
225- resolve(jsonData);
226- }).catch(error => {
227- reject(error);
228- });
229- };
230- keyObject.onerror = function () {
231- reject(getRequest.error);
232- };
233- };
234- getRequest.onerror = function () {
235- reject(getRequest.error);
236- };
237- }).catch(error => {
175+ try{
176+ let result = this.signMessageJs(message, password, keystore);
177+ resolve(result);
178+ }
179+ catch(error) {
238180 reject(error);
239- });
181+ }
240182 });
183+
241184 return retPromise;
242185 };
243186
--- a/src/sdk/query.js
+++ b/src/sdk/query.js
@@ -34,7 +34,7 @@ querySDK.prototype.listUtxo = function(object) {
3434 */
3535 querySDK.prototype.getVoteStatus = function() {
3636 let net = this.bytom.net;
37- return this.http.request('q/get-vote-status',null, net, 'GET');
37+ return this.http.request('q/vote-status',null, net, 'GET');
3838 };
3939
4040 export default querySDK;
\ No newline at end of file
--- a/src/sdk/transaction.js
+++ b/src/sdk/transaction.js
@@ -1,6 +1,9 @@
1-import {convertArgument, signTransaction} from '../wasm/func';
2-import { handleApiError, handleAxiosError } from '../utils/http';
3-import { getDB } from '../db/db';
1+import {signTransaction as signJs} from '../utils/transaction/signTransaction';
2+import { camelize } from '../utils/utils';
3+import {convertArgument} from '../utils/convertArguement';
4+import {http} from '../http.js';
5+
6+
47
58 function transactionSDK(bytom) {
69 this.http = bytom.serverHttp;
@@ -19,9 +22,9 @@ function transactionSDK(bytom) {
1922 * @param {Number} limit page limit
2023 * @returns {Promise}
2124 */
22-transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
25+transactionSDK.prototype.list = function(address, filter,sort, start, limit) {
2326 let net = this.bytom.net;
24- let pm = {guid: guid};
27+ let pm = {};
2528
2629 if (filter) {
2730 pm.filter = filter;
@@ -31,7 +34,7 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
3134 pm.sort = sort;
3235 }
3336
34- let url = 'merchant/list-transactions';
37+ let url = 'merchant/transactions';
3538 let args = new URLSearchParams();
3639 if (typeof start !== 'undefined') {
3740 args.append('start', start);
@@ -39,11 +42,43 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
3942 if (limit) {
4043 args.append('limit', limit);
4144 }
45+ if (address) {
46+ args.append('address', address);
47+ }
4248 url = url + '?' + args.toString();
4349 return this.http.request(url, pm, net);
4450 };
4551
4652 /**
53+ * List all the transactions related to a wallet or an address.
54+ *
55+ * @see https://gist.github.com/HAOYUatHZ/0c7446b8f33e7cddd590256b3824b08f#apiv1btmmerchantlist-transactions
56+ * @param {String} baseUrl request url,
57+ * @param {String} address transaction address
58+ * @param {Number} start page start
59+ * @param {Number} limit page limit
60+ * @returns {Promise}
61+ */
62+transactionSDK.prototype.listDelayTransaction = function(baseUrl, address, start, limit) {
63+ const _http = new http(baseUrl)
64+ let pm = {};
65+
66+ let path = '/lingerdesire/v1/list-delay-transfers';
67+ let args = new URLSearchParams();
68+ if (typeof start !== 'undefined') {
69+ args.append('start', start);
70+ }
71+ if (limit) {
72+ args.append('limit', limit);
73+ }
74+ if (address) {
75+ args.append('address', address);
76+ }
77+ path = path + '?' + args.toString();
78+ return _http.request(path, pm);
79+};
80+
81+/**
4782 * Submit a signed transaction to the chain.
4883 *
4984 * @see https://gist.github.com/HAOYUatHZ/0c7446b8f33e7cddd590256b3824b08f#apiv1btmmerchantsubmit-payment
@@ -51,10 +86,10 @@ transactionSDK.prototype.list = function(guid, filter,sort, start, limit) {
5186 * @param {String} raw_transaction raw transaction bytes encoded to string
5287 * @param {Array} signatures signed data of each signing instruction
5388 */
54-transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatures) {
89+transactionSDK.prototype.submitPayment = function(address, raw_transaction, signatures) {
5590 let net = this.bytom.net;
56- let pm = {guid: guid, raw_transaction: raw_transaction, signatures: signatures};
57- return this.http.request('merchant/submit-payment', pm, net);
91+ let pm = {raw_transaction: raw_transaction, signatures: signatures};
92+ return this.http.request(`merchant/submit-payment?address=${address}`, pm, net);
5893 };
5994
6095 /**
@@ -70,16 +105,15 @@ transactionSDK.prototype.submitPayment = function(guid, raw_transaction, signatu
70105 * @param {Number} confirmations - transaction confirmations
71106 * @returns {Promise}
72107 */
73-transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, confirmations, memo, forbidChainTx) {
108+transactionSDK.prototype.buildPayment = function(address, to, asset, amount, confirmations, memo, forbidChainTx) {
74109 let net = this.bytom.net;
75110 let pm = {
76- guid: guid,
77111 asset: asset,
78112 recipients: {},
79113 forbid_chain_tx: false
80114 };
81115
82- pm['recipients'][`${to}`] = amount
116+ pm['recipients'][`${to}`] = amount;
83117
84118 if (memo) {
85119 pm.memo = memo;
@@ -87,13 +121,10 @@ transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, c
87121 if (forbidChainTx) {
88122 pm.forbid_chain_tx = forbidChainTx;
89123 }
90- if (fee) {
91- pm.fee = fee;
92- }
93124 if (confirmations) {
94125 pm.confirmations = confirmations;
95126 }
96- return this.http.request('merchant/build-payment', pm, net);
127+ return this.http.request(`merchant/build-payment?address=${address}`, pm, net);
97128 };
98129
99130 /**
@@ -106,23 +137,22 @@ transactionSDK.prototype.buildPayment = function(guid, to, asset, amount, fee, c
106137 * @param {Number} confirmations - transaction confirmations
107138 * @returns {Promise}
108139 */
109-transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, confirmations, forbidChainTx) {
140+transactionSDK.prototype.buildCrossChain = function(address, to, asset, amount, confirmations, forbidChainTx) {
110141 let net = this.bytom.net;
111142
112143 let pm = {
113- guid: guid,
114144 asset: asset,
115145 recipients: {},
116146 forbid_chain_tx: false
117147 };
118148
119- pm['recipients'][`${to}`] = amount
149+ pm['recipients'][`${to}`] = amount;
120150
121151 if (forbidChainTx) {
122152 pm.forbid_chain_tx = forbidChainTx;
123153 }
124154
125- return this.http.request('merchant/build-crosschain', pm, net);
155+ return this.http.request(`merchant/build-crosschain?address=${address}`, pm, net);
126156 };
127157
128158 /**
@@ -135,9 +165,9 @@ transactionSDK.prototype.buildCrossChain = function(guid, to, asset, amount, con
135165 * @param {Number} confirmations - transaction confirmations
136166 * @returns {Promise}
137167 */
138-transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations, memo, forbidChainTx) {
168+transactionSDK.prototype.buildVote = function(address, vote, amount, confirmations, memo, forbidChainTx) {
139169 let net = this.bytom.net;
140- let pm = {guid, vote, amount: amount, forbid_chain_tx: false};
170+ let pm = {vote, amount: amount, forbid_chain_tx: false};
141171 if (confirmations) {
142172 pm.confirmations = confirmations;
143173 }
@@ -145,10 +175,17 @@ transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations,
145175 pm.memo = memo;
146176 }
147177 if (forbidChainTx) {
148- pm.forbid_chain_tx = forbidChainTx;
178+ pm.forbid_chain_tx = forbidChainTx;
149179 }
150180
151- return this.http.request('merchant/build-vote', pm, net);
181+ return this.http.request(`merchant/build-vote?address=${address}`, pm, net);
182+};
183+
184+transactionSDK.prototype.estimateFee = function(address, asset_amounts, confirmations=1) {
185+ let net = this.bytom.net;
186+ let pm = {asset_amounts, confirmations};
187+
188+ return this.http.request(`merchant/estimate-tx-fee?address=${address}`, pm, net);
152189 };
153190
154191 /**
@@ -161,20 +198,20 @@ transactionSDK.prototype.buildVote = function(guid, vote, amount, confirmations,
161198 * @param {Number} confirmations - transaction confirmations
162199 * @returns {Promise}
163200 */
164-transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations, memo, forbidChainTx) {
201+transactionSDK.prototype.buildVeto = function(address, vote, amount, confirmations, memo, forbidChainTx) {
165202 let net = this.bytom.net;
166- let pm = {guid, vote, amount: amount, forbid_chain_tx: false};
203+ let pm = { vote, amount: amount, forbid_chain_tx: false};
167204 if (confirmations) {
168205 pm.confirmations = confirmations;
169206 }
170207 if (memo) {
171208 pm.memo = memo;
172209 }
173- if (forbidChainTx) {
210+ if (forbidChainTx) {
174211 pm.forbid_chain_tx = forbidChainTx;
175- }
212+ }
176213
177- return this.http.request('merchant/build-veto', pm, net);
214+ return this.http.request(`merchant/build-veto?address=${address}`, pm, net);
178215 };
179216
180217 /**
@@ -185,12 +222,12 @@ transactionSDK.prototype.buildVeto = function(guid, vote, amount, confirmations,
185222 * @param {Number} fee transaction fee amount
186223 * @returns {Promise}
187224 */
188-transactionSDK.prototype.buildTransaction = function(guid, inputs, outputs, fee, confirmations ) {
225+transactionSDK.prototype.buildTransaction = function(address, inputs, outputs, fee, confirmations, forbid_chain_tx = true) {
189226 let net = this.bytom.net;
190227 let pm = {
191- guid,
192228 inputs,
193229 outputs,
230+ forbid_chain_tx
194231 };
195232 if (fee) {
196233 pm.fee = fee;
@@ -198,47 +235,27 @@ transactionSDK.prototype.buildTransaction = function(guid, inputs, outputs, fee,
198235 if (confirmations) {
199236 pm.confirmations = confirmations;
200237 }
201- return this.http.request('merchant/build-transaction', pm, net);
238+ return this.http.request(`merchant/build-advanced-tx?address=${address}`, pm, net);
202239 };
203240
204-/**
205- * sign transaction
206- * @param {String} guid
207- * @param {String} transaction
208- * @param {String} password
209- * @returns {Object} signed data
210- */
211-transactionSDK.prototype.signTransaction = function(guid, transaction, password) {
212- let bytom = this.bytom;
241+
242+transactionSDK.prototype._signTransactionJs = function( transaction, password, key) {
243+ let tx = camelize(JSON.parse(transaction));
244+
245+ return signJs(tx, password, key);
246+};
247+
248+transactionSDK.prototype._signTransactionJsPromise = function( transaction, password, key) {
213249 let retPromise = new Promise((resolve, reject) => {
214- getDB().then(db => {
215- let getRequest = db.transaction(['accounts-server'], 'readonly')
216- .objectStore('accounts-server')
217- .index('guid')
218- .get(guid);
219- getRequest.onsuccess = function(e) {
220- if (!e.target.result) {
221- reject(new Error('not found guid'));
222- return;
223- }
224- bytom.sdk.keys.getKeyByXPub(e.target.result.rootXPub).then(res => {
225- let pm = {transaction: transaction, password: password, key: res};
226- signTransaction(pm).then(res => {
227- resolve(JSON.parse(res.data));
228- }).catch(err => {
229- reject(err);
230- });
231- }).catch(err => {
232- reject(err);
233- });
234- };
235- getRequest.onerror = function() {
236- reject(getRequest.error);
237- };
238- }).catch(error => {
250+ try{
251+ let result = this._signTransactionJs(transaction, password, key);
252+ resolve(result);
253+ }
254+ catch(error) {
239255 reject(error);
240- });
256+ }
241257 });
258+
242259 return retPromise;
243260 };
244261
@@ -253,14 +270,16 @@ transactionSDK.prototype.convertArgument = function(type, value) {
253270 let data = {};
254271 data.type = type;
255272 data.raw_data = JSON.stringify({value});
256- convertArgument(data).then((res) => {
257- let jsonData = JSON.parse(res.data);
258- resolve(jsonData);
259- }).catch(error => {
273+ try{
274+ const result = convertArgument(data).data
275+ resolve(result);
276+ }
277+ catch(error){
260278 reject(error);
261- });
279+ }
262280 });
263281 return retPromise;
264282 };
265283
284+
266285 export default transactionSDK;
\ No newline at end of file
--- a/src/sdk/wallet.js
+++ b/src/sdk/wallet.js
@@ -1,36 +1,14 @@
1-import {initDB, getDB} from '../db/db';
1+import { restoreFromKeyStore } from '../utils/account';
22
33 function walletSDK(bytom) {
4+ this.http = bytom.serverHttp;
45 this.bytom = bytom;
56 }
67
7-let backupDBList = ['keys', 'addresses', 'accounts', 'accounts-server', 'addresses-server'];
8-
9-/**
10- * backup wallet.
11- */
12-walletSDK.prototype.backup = function() {
13- let retPromise = new Promise((resolve, reject) => {
14- initDB().then(() =>{
15- let walletImage = {};
16- let promiseList = [];
17- for (let index = 0; index < backupDBList.length; ++index) {
18- promiseList.push(backupDB(backupDBList[index]));
19- }
20- Promise.all(promiseList).then(res => {
21- for(let index = 0; index < res.length; ++index) {
22- let data = res[index];
23- if (data.length > 0) {
24- walletImage[backupDBList[index]] = data;
25- }
26- }
27- resolve(JSON.stringify(walletImage));
28- }).catch(error => {
29- reject(error);
30- });
31- });
32- });
33- return retPromise;
8+walletSDK.prototype.list = function(pubkey) {
9+ let net = this.bytom.net;
10+ let pm = {pubkey};
11+ return this.http.request('account/wallets', pm, net);
3412 };
3513
3614 /**
@@ -38,94 +16,27 @@ walletSDK.prototype.backup = function() {
3816 *
3917 * @param {String} walletImage
4018 */
41-walletSDK.prototype.restore = function(walletImage) {
42- let retPromise = new Promise((resolve, reject) => {
43- this.bytom.sdk.keys.list().then(keys => {
44- if (keys.length <=0) {
45- let data = JSON.parse(walletImage);
46- let promiseList = [];
47- for (let key in data) {
48- if (!data.hasOwnProperty(key) || backupDBList.indexOf(key) === -1) {
49- continue;
50- }
51- promiseList.push(restoreDB(key, data[key]));
52- }
53- let retData = {};
54-
55- Promise.all(promiseList).then(res => {
56- for(let index = 0; index < res.length; ++index) {
57- let data = res[index];
58- retData[data.name] = data.err;
59- }
60- resolve(retData);
61- }).catch(err => {
62- reject(err);
63- });
64- } else {
65- reject(new Error('The wallet already has account data. Can\'t restore.'));
66- }
67- }).catch(error => {
68- reject(error);
69- });
70- });
71- return retPromise;
72-};
19+walletSDK.prototype.restore = function(keystore, password) {
20+ const walletImage = JSON.parse(keystore);
21+ let net = this.bytom.net;
22+
23+ let keys;
24+ if(walletImage.key_images && walletImage.key_images.xkeys){
25+ keys = walletImage.key_images.xkeys;
26+ }
27+
28+ // match older version of backups keystore files
29+ else{
30+ keys = walletImage.keys.map(keyItem => JSON.parse( keyItem.key ) );
31+ }
32+
33+ let promiseList = [];
34+ for (let index = 0; index< keys.length; index++ ){
35+ const pubkey = restoreFromKeyStore(keys[index], password[index]);
36+ promiseList.push(this.http.request('account/list-wallets', {pubkey}, net).catch(e => {throw e;}));
37+ }
38+ return Promise.all(promiseList).then(resp => resp.guid);
7339
74-function backupDB(dbname) {
75- let ret = new Promise((resolve, reject) => {
76- getDB().then(db => {
77- let transaction = db.transaction([dbname], 'readonly');
78- let objectStore = transaction.objectStore(dbname);
79- let oc = objectStore.openCursor();
80- let data = [];
81- oc.onsuccess = function (event) {
82- var cursor = event.target.result;
83- if (cursor) {
84- data.push(cursor.value);
85- cursor.continue();
86- } else {
87- resolve(data);
88- }
89- };
90- oc.onerror = function(e){
91- reject(e);
92- };
93- }).catch(err => {
94- reject(err);
95- });
96- });
97- return ret;
98-}
99-
100-function restoreDB(dbname, data) {
101- let ret = new Promise((resolve, reject) => {
102- getDB().then(db => {
103- let index = 0;
104- let errList = [];
105- batchAdd();
106-
107- function batchAdd() {
108- if (index >= data.length) {
109- let r = {name: dbname, err: errList};
110- resolve(r);
111- return;
112- }
113- let transaction = db.transaction([dbname], 'readwrite');
114- let objectStore = transaction.objectStore(dbname);
115- let req = objectStore.add(data[index]);
116- req.onsuccess = batchAdd;
117- req.onerror = function() {
118- // if error continue add
119- errList.push(req.error);
120- batchAdd();
121- };
122- index++;
123- }
124- }).catch(err => {
125- reject(err);
126- });
127- });
128- return ret;
129-}
40+};
13041
13142 export default walletSDK;
\ No newline at end of file
--- /dev/null
+++ b/src/utils/account.js
@@ -0,0 +1,6 @@
1+import {decryptKey} from './key/keystore';
2+
3+export function restoreFromKeyStore(v3Keystore, password){
4+ const key = decryptKey(v3Keystore, password)
5+ return key.xPub;
6+}
--- a/src/utils/convertArguement.js
+++ b/src/utils/convertArguement.js
@@ -1,7 +1,8 @@
11 import { hexEncode } from './hex.js';
22 import bech32 from 'bech32';
3+import Error from './error';
34
4-export function convertArguements(obj){
5+export function convertArgument(obj){
56 const type = obj.type;
67 const value = obj.raw_data.value;
78 let convertValue;
@@ -22,7 +23,7 @@ export function convertArguements(obj){
2223 convertValue = convertAddress(value);
2324 break;
2425 default:
25- throw 'Invalid data type.';
26+ throw new Error('Invalid data type.', 'BTM3101');
2627 }
2728 return { data: convertValue };
2829 }
@@ -33,7 +34,7 @@ function convertBoolean(bool) {
3334 }else if(bool === false){
3435 return '';
3536 }else {
36- throw 'Invalid Boolean argument';
37+ throw new Error('Invalid Boolean argument','BTM3102');
3738 }
3839 }
3940
@@ -54,7 +55,7 @@ function convertData(data){
5455 if(/^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/i.test(data)){
5556 return data;
5657 }else{
57- throw 'Invalid hex data';
58+ throw new Error('Invalid hex data','BTM3103');
5859 }
5960 }
6061
--- /dev/null
+++ b/src/utils/ed25519/curve.js
@@ -0,0 +1,89 @@
1+'use strict';
2+
3+const Scalar = require('./scalar');
4+const Point = require('./point');
5+const crypto = require('crypto-browserify');
6+const elliptic = require('elliptic');
7+const EdDSA = elliptic.eddsa;
8+const ec = new EdDSA('ed25519');
9+const BN = require('bn.js');
10+const orderRed = BN.red(ec.curve.n);
11+const group = require('./lib/group');
12+
13+/**
14+ * @module curves/edwards25519/curve
15+ */
16+
17+/**
18+ * Represents an Ed25519 curve
19+ */
20+class Edwards25519 extends group.Group {
21+ constructor() {
22+ super();
23+ this.curve = ec.curve;
24+ this.orderRed = orderRed;
25+ }
26+
27+ /**
28+ * Return the name of the curve
29+ *
30+ * @returns {string}
31+ */
32+ string() {
33+ return 'Ed25519';
34+ }
35+
36+ /**
37+ * Returns 32, the size in bytes of a Scalar on Ed25519 curve
38+ *
39+ * @returns {number}
40+ */
41+ scalarLen() {
42+ return 32;
43+ }
44+
45+ /**
46+ * Returns a new Scalar for the prime-order subgroup of Ed25519 curve
47+ *
48+ * @returns {module:curves/edwards25519/scalar~Scalar}
49+ */
50+ scalar() {
51+ return new Scalar(this, this.orderRed);
52+ }
53+
54+ /**
55+ * Returns 32, the size of a Point on Ed25519 curve
56+ *
57+ * @returns {number}
58+ */
59+ pointLen() {
60+ return 32;
61+ }
62+
63+ /**
64+ * Creates a new point on the Ed25519 curve
65+ *
66+ * @returns {module:curves/edwards25519/point~Point}
67+ */
68+ point() {
69+ return new Point(this);
70+ }
71+
72+ /**
73+ * NewKey returns a formatted Ed25519 key (avoiding subgroup attack by requiring
74+ * it to be a multiple of 8).
75+ * @returns {module:curves/edwards25519/scalar~Scalar}
76+ */
77+ newKey() {
78+ let bytes = crypto.randomBytes(32);
79+ let hash = crypto.createHash('sha512');
80+ hash.update(bytes);
81+ let scalar = Uint8Array.from(hash.digest());
82+ scalar[0] &= 0xf8;
83+ scalar[31] &= 0x3f;
84+ scalar[31] &= 0x40;
85+
86+ return this.scalar().setBytes(scalar);
87+ }
88+}
89+module.exports = Edwards25519;
\ No newline at end of file
--- /dev/null
+++ b/src/utils/ed25519/index.js
@@ -0,0 +1,11 @@
1+'use strict';
2+
3+const Curve = require('./curve');
4+const Point = require('./point');
5+const Scalar = require('./scalar');
6+
7+module.exports = {
8+ Curve,
9+ Point,
10+ Scalar
11+};
\ No newline at end of file
--- /dev/null
+++ b/src/utils/ed25519/lib/constants.js
@@ -0,0 +1,18 @@
1+"use strict";
2+
3+const BN = require("bn.js");
4+
5+/**
6+ * @module constants
7+ */
8+
9+/**
10+ * Constants
11+ * @typedef {Object} constants
12+ * @property {BN.jsObject} zeroBN - BN.js object representing 0
13+ */
14+const constants = {
15+ zeroBN: new BN(0)
16+};
17+
18+module.exports = constants;
\ No newline at end of file
--- /dev/null
+++ b/src/utils/ed25519/lib/group.js
@@ -0,0 +1,158 @@
1+/**
2+ * Group is an abstract class for curves
3+ */
4+class Group {
5+ constructor() {}
6+
7+ scalarLen() {
8+ throw new Error('Not implemented');
9+ }
10+
11+ scalar() {
12+ throw new Error('Not implemented');
13+ }
14+
15+ pointLen() {
16+ throw new Error('Not implemented');
17+ }
18+
19+ point() {
20+ throw new Error('Not implemented');
21+ }
22+}
23+
24+/**
25+ * Point is an abstract class for representing
26+ * a point on an elliptic curve
27+ */
28+class Point {
29+ constructor() {}
30+
31+ equal() {
32+ throw new Error('Not implemented');
33+ }
34+
35+ null() {
36+ throw new Error('Not implemented');
37+ }
38+
39+ base() {
40+ throw new Error('Not implemented');
41+ }
42+
43+ pick(callback) {
44+ throw new Error('Not implemented');
45+ }
46+
47+ set() {
48+ throw new Error('Not implemented');
49+ }
50+
51+ clone() {
52+ throw new Error('Not implemented');
53+ }
54+
55+ embedLen() {
56+ throw new Error('Not implemented');
57+ }
58+
59+ embed(data, callback) {
60+ throw new Error('Not implemented');
61+ }
62+
63+ data() {
64+ throw new Error('Not implemented');
65+ }
66+
67+ add(p1, p2) {
68+ throw new Error('Not implemented');
69+ }
70+
71+ sub(p1, p2) {
72+ throw new Error('Not implemented');
73+ }
74+
75+ neg(p) {
76+ throw new Error('Not implemented');
77+ }
78+
79+ mul(s, p) {
80+ throw new Error('Not implemented');
81+ }
82+
83+ marshalBinary() {
84+ throw new Error('Not implemented');
85+ }
86+
87+ unmarshalBinary(bytes) {
88+ throw new Error('Not implemented');
89+ }
90+}
91+
92+/**
93+ * Scalar is an abstract class for representing a scalar
94+ * to be used in elliptic curve operations
95+ */
96+class Scalar {
97+ marshalBinary() {
98+ throw new Error('Not implemented');
99+ }
100+
101+ unmarshalBinary(bytes) {
102+ throw new Error('Not implemented');
103+ }
104+
105+ equal() {
106+ throw new Error('Not implemented');
107+ }
108+
109+ set(a) {
110+ throw new Error('Not implemented');
111+ }
112+
113+ clone() {
114+ throw new Error('Not implemented');
115+ }
116+
117+ zero() {
118+ throw new Error('Not implemented');
119+ }
120+
121+ add(a, b) {
122+ throw new Error('Not implemented');
123+ }
124+
125+ sub(a, b) {
126+ throw new Error('Not implemented');
127+ }
128+
129+ neg(a) {
130+ throw new Error('Not implemented');
131+ }
132+
133+ div(a, b) {
134+ throw new Error('Not implemented');
135+ }
136+
137+ inv(a) {
138+ throw new Error('Not implemented');
139+ }
140+
141+ inv(a) {
142+ throw new Error('Not implemented');
143+ }
144+
145+ pick(callback) {
146+ throw new Error('Not implemented');
147+ }
148+
149+ setBytes(bytes) {
150+ throw new Error('Not implemented');
151+ }
152+}
153+
154+module.exports = {
155+ Point,
156+ Scalar,
157+ Group
158+};
\ No newline at end of file
--- /dev/null
+++ b/src/utils/ed25519/lib/random.js
@@ -0,0 +1,56 @@
1+const BN = require('bn.js');
2+const constants = require('./constants');
3+
4+/**
5+ * module: random
6+ */
7+
8+/**
9+ * bits choses a random Uint8Array with a maximum bitlength
10+ * If exact is `true`, chose Uint8Array with *exactly* that bitlenght not less
11+ *
12+ * @param {number} bitlen - Bitlength
13+ * @param {boolean} exact
14+ * @param {function} callback - to generate random Uint8Array of given length
15+ * @returns {Uint8Array}
16+ */
17+function bits(bitlen, exact, callback) {
18+ let b = callback((bitlen + 7) >> 3);
19+ let highbits = bitlen & 7;
20+ if (highbits != 0) {
21+ b[0] &= ~(0xff << highbits);
22+ }
23+
24+ if (exact) {
25+ if (highbits !== 0) {
26+ b[0] |= 1 << (highbits - 1);
27+ } else {
28+ b[0] |= 0x80;
29+ }
30+ }
31+ return Uint8Array.from(b);
32+}
33+
34+/**
35+ * int choses a random uniform Uint8Array less than given modulus
36+ *
37+ * @param {BN.jsObject} mod - modulus
38+ * @param {function} callback - to generate a random byte array
39+ * @returns {Uint8Array}
40+ */
41+function int(mod, callback) {
42+ let bitlength = mod.bitLength();
43+ let i;
44+ while (true) {
45+ const bytes = bits(bitlength, false, callback);
46+ i = new BN(bytes);
47+ if (i.cmp(constants.zeroBN) > 0 && i.cmp(mod) < 0) {
48+ return bytes;
49+ }
50+ }
51+}
52+
53+module.exports = {
54+ bits,
55+ int
56+};
\ No newline at end of file
--- /dev/null
+++ b/src/utils/ed25519/point.js
@@ -0,0 +1,339 @@
1+'use strict';
2+
3+const BN = require('bn.js');
4+const crypto = require('crypto-browserify');
5+const Scalar = require('./scalar');
6+const group = require('./lib/group');
7+
8+/**
9+ * @module curves/edwards25519/point
10+ */
11+
12+/**
13+ * Represents a Point on the twisted edwards curve
14+ * (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
15+ *
16+ * The value of the parameters is expcurveted in little endian form if being
17+ * passed as a Uint8Array
18+ * @constructor
19+ *
20+ * @param {module:curves/edwards25519~Edwards25519} curve
21+ * @param {(number|Uint8Array|BN.jsObjcurvet)} X
22+ * @param {(number|Uint8Array|BN.jsObjcurvet)} Y
23+ * @param {(number|Uint8Array|BN.jsObjcurvet)} Z
24+ * @param {(number|Uint8Array|BN.jsObjcurvet)} T
25+ */
26+class Point extends group.Point {
27+ constructor(curve, X, Y, Z, T) {
28+ super();
29+ let _X = X;
30+ let _Y = Y;
31+ let _Z = Z;
32+ let _T = T;
33+
34+ if (X !== undefined && X.constructor === Uint8Array) {
35+ _X = new BN(X, 16, 'le');
36+ }
37+ if (Y !== undefined && Y.constructor === Uint8Array) {
38+ _Y = new BN(Y, 16, 'le');
39+ }
40+ if (Z !== undefined && Z.constructor === Uint8Array) {
41+ _Z = new BN(Z, 16, 'le');
42+ }
43+ if (T !== undefined && T.constructor === Uint8Array) {
44+ _T = new BN(T, 16, 'le');
45+ }
46+ // the point reference is stored in an module:curves/edwards25519/point~Point to make set()
47+ // consistent.
48+ this.ref = {
49+ point: curve.curve.point(_X, _Y, _Z, _T),
50+ curve: curve
51+ };
52+
53+ this.string = this.toString.bind(this);
54+ this.inspect = this.toString.bind(this);
55+ }
56+
57+ /**
58+ * Returns the little endian representation of the y coordinate of
59+ * the Point
60+ *
61+ * @returns {string}
62+ */
63+ toString() {
64+ const bytes = this.marshalBinary();
65+ return Array.from(bytes, b =>
66+ ('0' + (b & 0xff).toString(16)).slice(-2)
67+ ).join('');
68+ }
69+
70+ /**
71+ * Tests for equality between two Points derived from the same group
72+ *
73+ * @param {module:curves/edwards25519/point~Point} p2 Point module:curves/edwards25519/point~Point to compare
74+ * @returns {boolean}
75+ */
76+ equal(p2) {
77+ const b1 = this.marshalBinary();
78+ const b2 = p2.marshalBinary();
79+ for (var i = 0; i < 32; i++) {
80+ if (b1[i] !== b2[i]) {
81+ return false;
82+ }
83+ }
84+ return true;
85+ }
86+
87+ // Set point to be equal to p2
88+
89+ /**
90+ * set Set the current point to be equal to p2
91+ *
92+ * @param {module:curves/edwards25519/point~Point} p2 Point module:curves/edwards25519/point~Point
93+ * @returns {module:curves/edwards25519/point~Point}
94+ */
95+ set(p2) {
96+ this.ref = p2.ref;
97+ return this;
98+ }
99+
100+ /**
101+ * Creates a copy of the current point
102+ *
103+ * @returns {module:curves/edwards25519/point~Point} new Point module:curves/edwards25519/point~Point
104+ */
105+ clone() {
106+ const point = this.ref.point;
107+ return new Point(this.ref.curve, point.x, point.y, point.z, point.t);
108+ }
109+
110+ /**
111+ * Set to the neutral element, which is (0, 1) for twisted Edwards
112+ * Curve
113+ *
114+ * @returns {module:curves/edwards25519/point~Point}
115+ */
116+ null() {
117+ this.ref.point = this.ref.curve.curve.point(0, 1, 1, 0);
118+ return this;
119+ }
120+
121+ /**
122+ * Set to the standard base point for this curve
123+ *
124+ * @returns {module:curves/edwards25519/point~Point}
125+ */
126+ base() {
127+ this.ref.point = this.ref.curve.curve.point(
128+ this.ref.curve.curve.g.getX(),
129+ this.ref.curve.curve.g.getY()
130+ );
131+ return this;
132+ }
133+
134+ /**
135+ * Returns the length (in bytes) of the embedded data
136+ *
137+ * @returns {number}
138+ */
139+ embedLen() {
140+ // Reserve the most-significant 8 bits for pseudo-randomness.
141+ // Reserve the least-significant 8 bits for embedded data length.
142+ // (Hopefully it's unlikely we'll need >=2048-bit curves soon.)
143+ return Math.floor((255 - 8 - 8) / 8);
144+ }
145+
146+ /**
147+ * Returns a Point with data embedded in the y coordinate
148+ *
149+ * @param {Uint8Array} data to embed with length <= embedLen
150+ * @param {function} callback - to generate a random byte array of given length
151+ *
152+ * @throws {TypeError} if data is not Uint8Array
153+ * @throws {Error} if data.length > embedLen
154+ * @returns {module:curves/edwards25519/point~Point}
155+ */
156+ embed(data, callback) {
157+ if (data.constructor !== Uint8Array) {
158+ throw new TypeError('data should be Uint8Array');
159+ }
160+
161+ let dl = this.embedLen();
162+ if (data.length > dl) {
163+ throw new Error('data.length > embedLen');
164+ }
165+
166+ if (dl > data.length) {
167+ dl = data.length;
168+ }
169+
170+ callback = callback || crypto.randomBytes;
171+
172+ let point_obj = new Point(this.ref.curve);
173+ while (true) {
174+ let buff = callback(32);
175+ let bytes = Uint8Array.from(buff);
176+
177+ if (dl > 0) {
178+ bytes[0] = dl; // encode length in lower 8 bits
179+ bytes.set(data, 1); // copy in data to embed
180+ }
181+
182+ let bnp = new BN(bytes, 16, 'le');
183+
184+ //if (bnp.cmp(PFSCALAR) > 0) {
185+ //continue; // try again
186+ //}
187+
188+ try {
189+ point_obj.unmarshalBinary(bytes);
190+ } catch (e) {
191+ continue; // try again
192+ }
193+ if (dl == 0) {
194+ point_obj.ref.point = point_obj.ref.point.mul(new BN(8));
195+ if (point_obj.ref.point.isInfinity()) {
196+ continue; // unlucky
197+ }
198+ return point_obj;
199+ }
200+
201+ let q = point_obj.clone();
202+ q.ref.point = q.ref.point.mul(this.ref.curve.curve.n);
203+ if (q.ref.point.isInfinity()) {
204+ return point_obj;
205+ }
206+ }
207+ }
208+
209+ /**
210+ * Extract embedded data from a point
211+ *
212+ * @throws {Error} when length of embedded data > embedLen
213+ * @returns {Uint8Array}
214+ */
215+ data() {
216+ const bytes = this.marshalBinary();
217+ const dl = bytes[0];
218+ if (dl > this.embedLen()) {
219+ throw new Error('invalid embedded data length');
220+ }
221+ return bytes.slice(1, dl + 1);
222+ }
223+
224+ /**
225+ * Returns the sum of two points on the curve
226+ *
227+ * @param {module:curves/edwards25519/point~Point} p1 Point module:curves/edwards25519/point~Point, addend
228+ * @param {module:curves/edwards25519/point~Point} p2 Point module:curves/edwards25519/point~Point, addend
229+ * @returns {module:curves/edwards25519/point~Point} p1 + p2
230+ */
231+ add(p1, p2) {
232+ const point = p1.ref.point;
233+ this.ref.point = this.ref.curve.curve
234+ .point(point.x, point.y, point.z, point.t)
235+ .add(p2.ref.point);
236+ return this;
237+ }
238+
239+ /**
240+ * Subtract two points
241+ *
242+ * @param {module:curves/edwards25519/point~Point} p1 Point module:curves/edwards25519/point~Point
243+ * @param {module:curves/edwards25519/point~Point} p2 Point module:curves/edwards25519/point~Point
244+ * @returns {module:curves/edwards25519/point~Point} p1 - p2
245+ */
246+ sub(p1, p2) {
247+ const point = p1.ref.point;
248+ this.ref.point = this.ref.curve.curve
249+ .point(point.x, point.y, point.z, point.t)
250+ .add(p2.ref.point.neg());
251+ return this;
252+ }
253+
254+ /**
255+ * Finds the negative of a point p
256+ * For Edwards Curves, the negative of (x, y) is (-x, y)
257+ *
258+ * @param {module:curves/edwards25519/point~Point} p Point to negate
259+ * @returns {module:curves/edwards25519/point~Point} -p
260+ */
261+ neg(p) {
262+ this.ref.point = p.ref.point.neg();
263+ return this;
264+ }
265+
266+ /**
267+ * Multiply point p by scalar s
268+ *
269+ * @param {module:curves/edwards25519/point~Point} s Scalar
270+ * @param {module:curves/edwards25519/point~Point} [p] Point
271+ * @returns {module:curves/edwards25519/point~Point}
272+ */
273+ mul(s, p) {
274+ if (s.constructor !== Scalar) {
275+ throw new TypeError('s should be a Scalar');
276+ }
277+ p = p || null;
278+ const arr = s.ref.arr.fromRed();
279+ this.ref.point =
280+ p !== null ? p.ref.point.mul(arr) : this.ref.curve.curve.g.mul(arr);
281+ return this;
282+ }
283+
284+ /**
285+ * Selects a random point
286+ *
287+ * @param {function} callback - to generate a random byte array of given length
288+ * @returns {module:curves/edwards25519/point~Point}
289+ */
290+ pick(callback) {
291+ return this.embed(new Uint8Array(), callback);
292+ }
293+
294+ marshalSize() {
295+ return 32;
296+ }
297+
298+ /**
299+ * Convert a ed25519 curve point into a byte representation
300+ *
301+ * @returns {Uint8Array} byte representation
302+ */
303+ marshalBinary() {
304+ this.ref.point.normalize();
305+
306+ const buffer = this.ref.point.getY().toArray('le', 32);
307+ buffer[31] ^= (this.ref.point.x.isOdd() ? 1 : 0) << 7;
308+
309+ return Uint8Array.from(buffer);
310+ }
311+
312+ /**
313+ * Convert a Uint8Array back to a ed25519 curve point
314+ * {@link tools.ietf.org/html/rfc8032#scurvetion-5.1.3}
315+ * @param {Uint8Array} bytes
316+ *
317+ * @throws {TypeError} when bytes is not Uint8Array
318+ * @throws {Error} when bytes does not correspond to a valid point
319+ * @returns {module:curves/edwards25519/point~Point}
320+ */
321+ unmarshalBinary(bytes) {
322+ if (bytes.constructor !== Uint8Array) {
323+ throw new TypeError('bytes should be a Uint8Array');
324+ }
325+ // we create a copy bcurveause the array might be modified
326+ const _bytes = new Uint8Array(32);
327+ _bytes.set(bytes, 0);
328+
329+ const odd = _bytes[31] >> 7 === 1;
330+
331+ _bytes[31] &= 0x7f;
332+ let bnp = new BN(_bytes, 16, 'le');
333+ if (bnp.cmp(this.ref.curve.curve.p) >= 0) {
334+ throw new Error('bytes > p');
335+ }
336+ this.ref.point = this.ref.curve.curve.pointFromY(bnp, odd);
337+ }
338+}
339+module.exports = Point;
\ No newline at end of file
--- /dev/null
+++ b/src/utils/ed25519/scalar.js
@@ -0,0 +1,224 @@
1+'use strict';
2+
3+const BN = require('bn.js');
4+const crypto = require('crypto-browserify');
5+const random = require('./lib/random');
6+const group = require('./lib/group');
7+
8+/**
9+ * @module curves/edwards25519/scalar
10+ */
11+
12+/**
13+ * Scalar represents a value in GF(2^252 + 27742317777372353535851937790883648493)
14+ * @Constructor
15+ */
16+class Scalar extends group.Scalar {
17+ constructor(curve, red) {
18+ super();
19+ this.ref = {
20+ arr: new BN(0, 16).toRed(red),
21+ curve: curve,
22+ red: red
23+ };
24+ this.inspect = this.toString.bind(this);
25+ this.string = this.toString.bind(this);
26+ }
27+
28+ /**
29+ * Equality test for two Scalars derived from the same Group
30+ *
31+ * @param {module:curves/edwards25519/scalar~Scalar} s2 Scalar
32+ * @returns {boolean}
33+ */
34+ equal(s2) {
35+ return this.ref.arr.fromRed().cmp(s2.ref.arr.fromRed()) == 0;
36+ }
37+
38+ /**
39+ * Sets the receiver equal to another Scalar a
40+ *
41+ * @param {module:curves/edwards25519/scalar~Scalar} a Scalar
42+ * @returns {module:curves/edwards25519/scalar~Scalar}
43+ */
44+ set(a) {
45+ this.ref = a.ref;
46+ return this;
47+ }
48+
49+ /**
50+ * Returns a copy of the scalar
51+ *
52+ * @returns {module:curves/edwards25519/scalar~Scalar}
53+ */
54+ clone() {
55+ return new Scalar(this.ref.curve, this.ref.red).setBytes(
56+ new Uint8Array(this.ref.arr.fromRed().toArray('le'))
57+ );
58+ }
59+
60+ /**
61+ * Set to the additive identity (0)
62+ *
63+ * @returns {module:curves/edwards25519/scalar~Scalar}
64+ */
65+ zero() {
66+ this.ref.arr = new BN(0, 16).toRed(this.ref.red);
67+ return this;
68+ }
69+
70+ /**
71+ * Set to the modular sums of scalars s1 and s2
72+ *
73+ * @param {module:curves/edwards25519/scalar~Scalar} s1 Scalar
74+ * @param {module:curves/edwards25519/scalar~Scalar} s2 Scalar
75+ * @returns {module:curves/edwards25519/scalar~Scalar} s1 + s2
76+ */
77+ add(s1, s2) {
78+ this.ref.arr = s1.ref.arr.redAdd(s2.ref.arr);
79+ return this;
80+ }
81+
82+ /**
83+ * Set to the modular difference
84+ *
85+ * @param {module:curves/edwards25519/scalar~Scalar} s1 Scalar
86+ * @param {module:curves/edwards25519/scalar~Scalar} s2 Scalar
87+ * @returns {module:curves/edwards25519/scalar~Scalar} s1 - s2
88+ */
89+ sub(s1, s2) {
90+ this.ref.arr = s1.ref.arr.redSub(s2.ref.arr);
91+ return this;
92+ }
93+
94+ /**
95+ * Set to the modular negation of scalar a
96+ *
97+ * @param {module:curves/edwards25519/scalar~Scalar} a Scalar
98+ * @returns {module:curves/edwards25519/scalar~Scalar}
99+ */
100+ neg(a) {
101+ this.ref.arr = a.ref.arr.redNeg();
102+ return this;
103+ }
104+
105+ /**
106+ * Set to the multiplicative identity (1)
107+ *
108+ * @returns {module:curves/edwards25519/scalar~Scalar}
109+ */
110+ one() {
111+ this.ref.arr = new BN(1, 16).toRed(this.ref.red);
112+ return this;
113+ }
114+
115+ /**
116+ * Set to the modular products of scalars s1 and s2
117+ *
118+ * @param {module:curves/edwards25519/scalar~Scalar} s1
119+ * @param {module:curves/edwards25519/scalar~Scalar} s2
120+ * @returns {module:curves/edwards25519/scalar~Scalar}
121+ */
122+ mul(s1, s2) {
123+ this.ref.arr = s1.ref.arr.redMul(s2.ref.arr);
124+ return this;
125+ }
126+
127+ /**
128+ * Set to the modular division of scalar s1 by scalar s2
129+ *
130+ * @param s1
131+ * @param s2
132+ * @returns {module:curves/edwards25519/scalar~Scalar}
133+ */
134+ div(s1, s2) {
135+ this.ref.arr = s1.ref.arr.redMul(s2.ref.arr.redInvm());
136+ return this;
137+ }
138+
139+ /**
140+ * Set to the modular inverse of scalar a
141+ *
142+ * @param a
143+ * @returns {module:curves/edwards25519/scalar~Scalar}
144+ */
145+ inv(a) {
146+ this.ref.arr = a.ref.arr.redInvm();
147+ return this;
148+ }
149+
150+ /**
151+ * Sets the scalar from little-endian Uint8Array
152+ * and reduces to the appropriate modulus
153+ * @param {Uint8Array} b - bytes
154+ *
155+ * @throws {TypeError} when b is not Uint8Array
156+ * @returns {module:curves/edwards25519/scalar~Scalar}
157+ */
158+ setBytes(b) {
159+ if (b.constructor !== Uint8Array) {
160+ throw new TypeError();
161+ }
162+ this.ref.arr = new BN(b, 16, 'le').toRed(this.ref.red);
163+ return this;
164+ }
165+
166+ /**
167+ * Returns a big-endian representation of the scalar
168+ *
169+ * @returns {Uint8Array}
170+ */
171+ bytes() {
172+ return new Uint8Array(this.ref.arr.fromRed().toArray('be'));
173+ }
174+
175+ toString() {
176+ let bytes = this.ref.arr.fromRed().toArray('le', 32);
177+ return Array.from(bytes, b =>
178+ ('0' + (b & 0xff).toString(16)).slice(-2)
179+ ).join('');
180+ }
181+
182+ /**
183+ * Set to a random scalar
184+ *
185+ * @param {function} callback - to generate random byte array of given length
186+ * @returns {module:curves/edwards25519/scalar~Scalar}
187+ */
188+ pick(callback) {
189+ callback = callback || crypto.randomBytes;
190+ const bytes = random.int(this.ref.curve.curve.n, callback);
191+ this.ref.arr = new BN(bytes, 16).toRed(this.ref.red);
192+ return this;
193+ }
194+
195+ marshalSize() {
196+ return 32;
197+ }
198+
199+ /**
200+ * Returns the binary representation (little endian) of the scalar
201+ *
202+ * @returns {Uint8Array}
203+ */
204+ marshalBinary() {
205+ return new Uint8Array(this.ref.arr.fromRed().toArray('le', 32));
206+ }
207+
208+ /**
209+ * Reads the binary representation (little endian) of scalar
210+ *
211+ * @param bytes
212+ */
213+ unmarshalBinary(bytes) {
214+ if (bytes.constructor !== Uint8Array) {
215+ throw new TypeError('bytes should be Uint8Array');
216+ }
217+
218+ if (bytes.length > this.marshalSize()) {
219+ throw new Error('bytes.length > marshalSize');
220+ }
221+ this.ref.arr = new BN(bytes, 16, 'le').toRed(this.ref.red);
222+ }
223+}
224+module.exports = Scalar;
\ No newline at end of file
--- /dev/null
+++ b/src/utils/error.js
@@ -0,0 +1,7 @@
1+export default class Error {
2+
3+ constructor( _message, _code) {
4+ this.message = _message;
5+ this.code = _code;
6+ }
7+}
\ No newline at end of file
--- /dev/null
+++ b/src/utils/key/chainkd.js
@@ -0,0 +1,216 @@
1+let createHmac = require('create-hmac');
2+let ED25519 =require('../ed25519');
3+let Curve25519 = new ED25519.Curve;
4+const nacl = require('../nacl');
5+// If r is nil, crypto/rand.Reader is used.
6+
7+function scalarmult_base (q){
8+ let base = Curve25519.point().base();
9+ let scalar = Curve25519.scalar().setBytes(new Uint8Array(q));
10+ let target = Curve25519.point().mul(scalar, base);
11+
12+ return target.toString();
13+}
14+
15+function XPrv(xprv) {
16+ if (!(this instanceof XPrv)) {
17+ return new XPrv();
18+ }
19+ this.xprv = xprv;
20+}
21+
22+
23+function newXPrv(r) {
24+ let entropy;
25+ if(!r){
26+ entropy = Buffer.alloc(64);
27+ }else{
28+ entropy = r.slice(0, 64);
29+ }
30+ return rootXPrv(entropy);
31+}
32+
33+// rootXPrv takes a seed binary string and produces a new xprv.
34+function rootXPrv(seed){
35+ let h = createHmac('sha512', Buffer.from('Root', 'utf8'))
36+ .update(seed)
37+ .digest();
38+
39+ const hL = h.slice(0, 32);
40+ const hR = h.slice(32);
41+
42+ pruneRootScalar(hL);
43+
44+ let xprv = new XPrv(Buffer.concat( [hL,hR]));
45+
46+ return xprv;
47+}
48+
49+exports.XPrv = XPrv;
50+exports.newXPrv = newXPrv;
51+exports.rootXPrv = rootXPrv;
52+
53+// XPub derives an extended public key from a given xprv.
54+XPrv.prototype.XPub = function() {
55+ const xprv = this.xprv;
56+ const xpub = Buffer.concat([Buffer.from(scalarmult_base(xprv.slice(0, 32)),'hex'), xprv.slice(32, xprv.length)]);
57+
58+ return xpub;
59+};
60+
61+function pruneRootScalar(s) {
62+ s[0] &= 248;
63+ s[31] &= 31; // clear top 3 bits
64+ s[31] |= 64; // set second highest bit
65+}
66+
67+// Clears lowest 3 bits and highest 23 bits of `f`.
68+function pruneIntermediateScalar(f) {
69+ f[0] &= 248; // clear bottom 3 bits
70+ f[29] &= 1; // clear 7 high bits
71+ f[30] = 0; // clear 8 bits
72+ f[31] = 0; // clear 8 bits
73+}
74+
75+XPrv.prototype.Derive = function(path) {
76+ let res = this;
77+ for( let p of path ){
78+ res = res.Child(p, false);
79+ }
80+ return res;
81+};
82+
83+
84+XPrv.prototype.Child = function(sel , hardened ) {
85+ if (hardened) {
86+ return this.hardenedChild(sel);
87+ }
88+ return this.nonhardenedChild(sel);
89+};
90+
91+
92+XPrv.prototype.hardenedChild = function(sel) {
93+ const r = this.xprv.slice(32);
94+ const l = this.xprv.slice(0, 32);
95+ let h = createHmac('sha512', r)
96+ .update(Buffer.from('H', 'utf8'))
97+ .update(l)
98+ .update(sel)
99+ .digest();
100+
101+ const hL = h.slice(0, 32);
102+ const hR = h.slice(32);
103+
104+ pruneRootScalar(hL);
105+
106+ return new XPrv( Buffer.concat( [hL,hR]) );
107+};
108+
109+XPrv.prototype.nonhardenedChild = function(sel){
110+ const xpub = this.XPub();
111+
112+ const r = xpub.slice(32);
113+ const l = xpub.slice(0, 32);
114+ let h = createHmac('sha512', r)
115+ .update(Buffer.from('N', 'utf8'))
116+ .update(l)
117+ .update(sel)
118+ .digest();
119+
120+
121+ const hL = h.slice(0, 32);
122+ const hR = h.slice(32);
123+
124+ pruneIntermediateScalar(hL);
125+
126+ let res = Buffer.concat( [hL,hR]);
127+
128+ let sum = 0;
129+
130+ sum = this.xprv[0] + res[0] + (sum >> 8);
131+ res[0] = sum & 0xff;
132+ sum = this.xprv[1] + res[1] + (sum >> 8);
133+ res[1] = sum & 0xff;
134+ sum = this.xprv[2] + res[2] + (sum >> 8);
135+ res[2] = sum & 0xff;
136+ sum = this.xprv[3] + res[3] + (sum >> 8);
137+ res[3] = sum & 0xff;
138+ sum = this.xprv[4] + res[4] + (sum >> 8);
139+ res[4] = sum & 0xff;
140+ sum = this.xprv[5] + res[5] + (sum >> 8);
141+ res[5] = sum & 0xff;
142+ sum = this.xprv[6] + res[6] + (sum >> 8);
143+ res[6] = sum & 0xff;
144+ sum = this.xprv[7] + res[7] + (sum >> 8);
145+ res[7] = sum & 0xff;
146+ sum = this.xprv[8] + res[8] + (sum >> 8);
147+ res[8] = sum & 0xff;
148+ sum = this.xprv[9] + res[9] + (sum >> 8);
149+ res[9] = sum & 0xff;
150+ sum = this.xprv[10] + res[10] + (sum >> 8);
151+ res[10] = sum & 0xff;
152+ sum = this.xprv[11] + res[11] + (sum >> 8);
153+ res[11] = sum & 0xff;
154+ sum = this.xprv[12] + res[12] + (sum >> 8);
155+ res[12] = sum & 0xff;
156+ sum = this.xprv[13] + res[13] + (sum >> 8);
157+ res[13] = sum & 0xff;
158+ sum = this.xprv[14] + res[14] + (sum >> 8);
159+ res[14] = sum & 0xff;
160+ sum = this.xprv[15] + res[15] + (sum >> 8);
161+ res[15] = sum & 0xff;
162+ sum = this.xprv[16] + res[16] + (sum >> 8);
163+ res[16] = sum & 0xff;
164+ sum = this.xprv[17] + res[17] + (sum >> 8);
165+ res[17] = sum & 0xff;
166+ sum = this.xprv[18] + res[18] + (sum >> 8);
167+ res[18] = sum & 0xff;
168+ sum = this.xprv[19] + res[19] + (sum >> 8);
169+ res[19] = sum & 0xff;
170+ sum = this.xprv[20] + res[20] + (sum >> 8);
171+ res[20] = sum & 0xff;
172+ sum = this.xprv[21] + res[21] + (sum >> 8);
173+ res[21] = sum & 0xff;
174+ sum = this.xprv[22] + res[22] + (sum >> 8);
175+ res[22] = sum & 0xff;
176+ sum = this.xprv[23] + res[23] + (sum >> 8);
177+ res[23] = sum & 0xff;
178+ sum = this.xprv[24] + res[24] + (sum >> 8);
179+ res[24] = sum & 0xff;
180+ sum = this.xprv[25] + res[25] + (sum >> 8);
181+ res[25] = sum & 0xff;
182+ sum = this.xprv[26] + res[26] + (sum >> 8);
183+ res[26] = sum & 0xff;
184+ sum = this.xprv[27] + res[27] + (sum >> 8);
185+ res[27] = sum & 0xff;
186+ sum = this.xprv[28] + res[28] + (sum >> 8);
187+ res[28] = sum & 0xff;
188+ sum = this.xprv[29] + res[29] + (sum >> 8);
189+ res[29] = sum & 0xff;
190+ sum = this.xprv[30] + res[30] + (sum >> 8);
191+ res[30] = sum & 0xff;
192+ sum = this.xprv[31] + res[31] + (sum >> 8);
193+ res[31] = sum & 0xff;
194+
195+ if ((sum >> 8) != 0) {
196+ throw('sum does not fit in 256-bit int');
197+ }
198+ return new XPrv(res);
199+};
200+
201+XPrv.prototype.Sign = function(msg){
202+ const expKey = this.ExpandedPrivateKey()
203+
204+ const publicKey = Buffer.from(scalarmult_base(expKey.slice(0, 32)),'hex');
205+ return nacl.innerSign(msg, expKey, publicKey);
206+};
207+
208+XPrv.prototype.ExpandedPrivateKey = function() {
209+ let h = createHmac('sha512', Buffer.from('Expand', 'utf8'))
210+ .update(this.xprv)
211+ .digest();
212+ const l = this.xprv.slice(0, 32);
213+ const r = h.slice(32);
214+
215+ return Buffer.concat( [l,r]);
216+};
--- /dev/null
+++ b/src/utils/key/createKey.js
@@ -0,0 +1,94 @@
1+const bip39 = require('bip39');
2+const utils = require('./utils');
3+import Error from '../error'
4+
5+const WORDLISTS = {
6+ en: require('bip39/src/wordlists/english.json'),
7+ zh: require('bip39/src/wordlists/chinese_simplified.json')
8+};
9+
10+const keystore = require('./keystore');
11+
12+const EntropyLength = 128;
13+const LightScryptN = 1 << 12;
14+const LightScryptP = 6;
15+
16+function createkey({
17+ alias,
18+ password,
19+ mnemonic,
20+ language
21+}) {
22+ if(!language){
23+ language = 'en';
24+ }
25+
26+ if (mnemonic && mnemonic.length > 0 ){
27+ return importKeyFromMnemonic(alias,password, mnemonic, language);
28+ }
29+
30+ let obj = createNewKey(alias, password, language);
31+ return {alias: obj.alias, xpub: obj.xPub.toString('hex'), keystore: obj.keystore, mnemonic:obj.mnemonic};
32+}
33+
34+function isValidMnemonic(mnemonic, language){
35+ // checksum length = entropy length /32
36+ // mnemonic length = (entropy length + checksum length)/11
37+ let mnemArray = mnemonic.trim().split(' ');
38+ if (mnemArray.length != ((EntropyLength+EntropyLength/32)/11 )){
39+ throw new Error('mnemonic length error', 'BTM3005');
40+ }
41+
42+ // Pre validate that the mnemonic is well formed and only contains words that
43+ // are present in the word list
44+ if (!bip39.validateMnemonic(mnemonic, WORDLISTS[language])) {
45+ throw new Error('mnemonic is invalid', 'BTM3006');
46+ }
47+}
48+
49+function importKeyFromMnemonic(alias, password, mnemonic, language) {
50+ isValidMnemonic(mnemonic, language)
51+
52+ const result = createKeyFromMnemonic(alias, password, mnemonic);
53+ result.xpub = result.xPub;
54+ delete result['xPub'];
55+
56+ return result;
57+}
58+
59+function createKeyFromMnemonic(alias,password, mnemonic) {
60+ // Generate a Bip32 HD wallet for the mnemonic and a user supplied password
61+ let seed = bip39.mnemonicToSeedSync(mnemonic, '');
62+ let {xprv, xpub} = utils.newXKeys(seed);
63+ let key = {
64+ keyType: 'bytom_kd',
65+ xPub: xpub,
66+ xPrv: xprv.xprv,
67+ alias
68+ };
69+ let _keystore = keystore.encryptKey( key, password, LightScryptN, LightScryptP);
70+
71+ return {xPub: xpub.toString('hex'), alias, keystore: _keystore};
72+}
73+
74+function createNewKey(alias, password, language) {
75+ let normalizedAlias = alias.trim().toLowerCase();
76+ return createChainKDKey(normalizedAlias, password, language);
77+}
78+
79+function createChainKDKey(alias,password, language){
80+ // Generate a mnemonic for memorization or user-friendly seeds
81+ let mnemonic = bip39.generateMnemonic(EntropyLength,undefined, WORDLISTS[language]);
82+
83+ let object = createKeyFromMnemonic(alias, password, mnemonic);
84+ object.mnemonic = mnemonic;
85+
86+ return object;
87+}
88+
89+export {
90+ createkey,
91+ importKeyFromMnemonic,
92+ createNewKey,
93+ isValidMnemonic
94+};
--- /dev/null
+++ b/src/utils/key/keystore.js
@@ -0,0 +1,121 @@
1+let cryp = require('crypto-browserify');
2+let scrypt = require('scrypt-js');
3+import {XPrv} from './chainkd';
4+let sha3_256 = require('js-sha3').sha3_256;
5+import _ from 'lodash';
6+import Error from '../error';
7+
8+const scryptDKLen = 32;
9+const scryptR = 8;
10+
11+function encryptKey(key , auth, scryptN, scryptP){
12+ let authArray = new Buffer(auth);
13+ let salt = cryp.randomBytes(32);
14+
15+ let derivedKey = scrypt.syncScrypt(authArray, salt, scryptN, scryptR, scryptP, scryptDKLen);
16+
17+ let encryptKey = derivedKey.slice(0, 16);
18+ let keyBytes = key.xPrv;
19+ let iv = cryp.randomBytes(16);
20+
21+
22+ let cipherText = aesCTRXOR(encryptKey, keyBytes, iv);
23+
24+ let kdfparams = {
25+ n:scryptN,
26+ r:scryptR,
27+ p:scryptP,
28+ dklen:scryptDKLen,
29+ salt:salt.toString('hex')
30+ };
31+
32+ let mac = sha3_256(Buffer.concat([Buffer(derivedKey.slice(16, 32)), cipherText]));
33+
34+
35+ return {
36+ version: 1,
37+ xpub:key.xPub.toString('hex'),
38+ alias:key.alias,
39+ type: key.keyType,
40+ crypto: {
41+ ciphertext: cipherText.toString('hex'),
42+ cipherparams: {
43+ iv: iv.toString('hex')
44+ },
45+ cipher: 'aes-128-ctr',
46+ kdf: 'scrypt',
47+ kdfparams: kdfparams,
48+ mac: mac.toString('hex')
49+ }
50+ };
51+}
52+
53+
54+function aesCTRXOR(key, inText, iv) {
55+ let cipher = cryp.createCipheriv('aes-128-ctr', key, iv);
56+
57+ var ciphertext = Buffer.from([
58+ ...cipher.update(Buffer.from(inText, 'hex')),
59+ ...cipher.final()]
60+ );
61+
62+
63+ return ciphertext;
64+}
65+
66+function decryptKey(v3Keystore, password){
67+ if (!_.isString(password)) {
68+ throw new Error('No password given.', 'BTM3003');
69+ }
70+
71+ let k = (_.isObject(v3Keystore)) ? v3Keystore : JSON.parse(v3Keystore);
72+ const xprv = decrypt(k, password);
73+ const _xprv = new XPrv(xprv)
74+ const xpub = _xprv.XPub()
75+
76+ return {
77+ xPrv: xprv,
78+ xPub: xpub,
79+ keyType: k.type,
80+ alias: k.alias,
81+ };
82+}
83+
84+function decrypt(json, password) {
85+ var derivedKey;
86+ var kdfparams;
87+ if (json.crypto.kdf === 'scrypt') {
88+ kdfparams = json.crypto.kdfparams;
89+
90+ // FIXME: support progress reporting callback
91+ derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
92+ } else if (json.crypto.kdf === 'pbkdf2') {
93+ kdfparams = json.crypto.kdfparams;
94+
95+ if (kdfparams.prf !== 'hmac-sha256') {
96+ throw new Error('Unsupported parameters to PBKDF2', 'BTM3002');
97+ }
98+
99+ derivedKey = cryp.pbkdf2Sync(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.c, kdfparams.dklen, 'sha3256');
100+ } else {
101+ throw new Error('Unsupported key derivation scheme' , 'BTM3001');
102+ }
103+
104+ var ciphertext = Buffer.from(json.crypto.ciphertext, 'hex');
105+
106+ var mac = sha3_256(Buffer.concat([Buffer(derivedKey.slice(16, 32)), ciphertext]));
107+ if (mac !== json.crypto.mac) {
108+ throw new Error('Key derivation failed - possibly wrong password', 'BTM3000');
109+ }
110+
111+ var decipher = cryp.createDecipheriv(json.crypto.cipher, derivedKey.slice(0, 16), Buffer.from(json.crypto.cipherparams.iv, 'hex'));
112+ var privateKey = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
113+
114+ return privateKey;
115+}
116+
117+
118+export{
119+ encryptKey,
120+ decryptKey
121+};
--- /dev/null
+++ b/src/utils/key/utils.js
@@ -0,0 +1,29 @@
1+import {newXPrv} from './chainkd';
2+
3+function newXKeys(r) {
4+ let xprv = newXPrv(r);
5+
6+ return {xprv, xpub: xprv.XPub()};
7+}
8+
9+export{
10+ newXKeys
11+};
12+
13+
14+// function xPubKeys(xpubs) {
15+// res := make([]ed25519.PublicKey, 0, len(xpubs))
16+// for _, xpub := range xpubs {
17+// res = append(res, xpub.PublicKey())
18+// }
19+// return res
20+// }
21+//
22+// function deriveXPubs(xpubs []XPub, path [][]byte) {
23+// res := make([]XPub, 0, len(xpubs))
24+// for _, xpub := range xpubs {
25+// d := xpub.Derive(path)
26+// res = append(res, d)
27+// }
28+// return res
29+// }
\ No newline at end of file
--- /dev/null
+++ b/src/utils/nacl.js
@@ -0,0 +1,1231 @@
1+const crypto = require('crypto-browserify');
2+const BN = require("bn.js");
3+
4+
5+(function(nacl) {
6+ 'use strict';
7+
8+ // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
9+ // Public domain.
10+ //
11+ // Implementation derived from TweetNaCl version 20140427.
12+ // See for details: http://tweetnacl.cr.yp.to/
13+
14+ var u64 = function(h, l) { this.hi = h|0 >>> 0; this.lo = l|0 >>> 0; };
15+ var gf = function(init) {
16+ var i, r = new Float64Array(16);
17+ if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
18+ return r;
19+ };
20+
21+ // Pluggable, initialized in high-level API below.
22+ var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
23+
24+ var _0 = new Uint8Array(16);
25+ var _9 = new Uint8Array(32); _9[0] = 9;
26+
27+ var gf0 = gf(),
28+ gf1 = gf([1]),
29+ _121665 = gf([0xdb41, 1]),
30+ D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
31+ D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
32+ X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
33+ Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
34+ I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
35+
36+ function L32(x, c) { return (x << c) | (x >>> (32 - c)); }
37+
38+ function ld32(x, i) {
39+ var u = x[i+3] & 0xff;
40+ u = (u<<8)|(x[i+2] & 0xff);
41+ u = (u<<8)|(x[i+1] & 0xff);
42+ return (u<<8)|(x[i+0] & 0xff);
43+ }
44+
45+ function dl64(x, i) {
46+ var h = (x[i] << 24) | (x[i+1] << 16) | (x[i+2] << 8) | x[i+3];
47+ var l = (x[i+4] << 24) | (x[i+5] << 16) | (x[i+6] << 8) | x[i+7];
48+ return new u64(h, l);
49+ }
50+
51+ function st32(x, j, u) {
52+ var i;
53+ for (i = 0; i < 4; i++) { x[j+i] = u & 255; u >>>= 8; }
54+ }
55+
56+ function ts64(x, i, u) {
57+ x[i] = (u.hi >> 24) & 0xff;
58+ x[i+1] = (u.hi >> 16) & 0xff;
59+ x[i+2] = (u.hi >> 8) & 0xff;
60+ x[i+3] = u.hi & 0xff;
61+ x[i+4] = (u.lo >> 24) & 0xff;
62+ x[i+5] = (u.lo >> 16) & 0xff;
63+ x[i+6] = (u.lo >> 8) & 0xff;
64+ x[i+7] = u.lo & 0xff;
65+ }
66+
67+ function vn(x, xi, y, yi, n) {
68+ var i,d = 0;
69+ for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
70+ return (1 & ((d - 1) >>> 8)) - 1;
71+ }
72+
73+ function crypto_verify_16(x, xi, y, yi) {
74+ return vn(x,xi,y,yi,16);
75+ }
76+
77+ function crypto_verify_32(x, xi, y, yi) {
78+ return vn(x,xi,y,yi,32);
79+ }
80+
81+ function core(out,inp,k,c,h) {
82+ var w = new Uint32Array(16), x = new Uint32Array(16),
83+ y = new Uint32Array(16), t = new Uint32Array(4);
84+ var i, j, m;
85+
86+ for (i = 0; i < 4; i++) {
87+ x[5*i] = ld32(c, 4*i);
88+ x[1+i] = ld32(k, 4*i);
89+ x[6+i] = ld32(inp, 4*i);
90+ x[11+i] = ld32(k, 16+4*i);
91+ }
92+
93+ for (i = 0; i < 16; i++) y[i] = x[i];
94+
95+ for (i = 0; i < 20; i++) {
96+ for (j = 0; j < 4; j++) {
97+ for (m = 0; m < 4; m++) t[m] = x[(5*j+4*m)%16];
98+ t[1] ^= L32((t[0]+t[3])|0, 7);
99+ t[2] ^= L32((t[1]+t[0])|0, 9);
100+ t[3] ^= L32((t[2]+t[1])|0,13);
101+ t[0] ^= L32((t[3]+t[2])|0,18);
102+ for (m = 0; m < 4; m++) w[4*j+(j+m)%4] = t[m];
103+ }
104+ for (m = 0; m < 16; m++) x[m] = w[m];
105+ }
106+
107+ if (h) {
108+ for (i = 0; i < 16; i++) x[i] = (x[i] + y[i]) | 0;
109+ for (i = 0; i < 4; i++) {
110+ x[5*i] = (x[5*i] - ld32(c, 4*i)) | 0;
111+ x[6+i] = (x[6+i] - ld32(inp, 4*i)) | 0;
112+ }
113+ for (i = 0; i < 4; i++) {
114+ st32(out,4*i,x[5*i]);
115+ st32(out,16+4*i,x[6+i]);
116+ }
117+ } else {
118+ for (i = 0; i < 16; i++) st32(out, 4 * i, (x[i] + y[i]) | 0);
119+ }
120+ }
121+
122+ function crypto_core_salsa20(out,inp,k,c) {
123+ core(out,inp,k,c,false);
124+ return 0;
125+ }
126+
127+ function crypto_core_hsalsa20(out,inp,k,c) {
128+ core(out,inp,k,c,true);
129+ return 0;
130+ }
131+
132+ var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
133+ // "expand 32-byte k"
134+
135+ function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
136+ var z = new Uint8Array(16), x = new Uint8Array(64);
137+ var u, i;
138+ if (!b) return 0;
139+ for (i = 0; i < 16; i++) z[i] = 0;
140+ for (i = 0; i < 8; i++) z[i] = n[i];
141+ while (b >= 64) {
142+ crypto_core_salsa20(x,z,k,sigma);
143+ for (i = 0; i < 64; i++) c[cpos+i] = (m?m[mpos+i]:0) ^ x[i];
144+ u = 1;
145+ for (i = 8; i < 16; i++) {
146+ u = u + (z[i] & 0xff) | 0;
147+ z[i] = u & 0xff;
148+ u >>>= 8;
149+ }
150+ b -= 64;
151+ cpos += 64;
152+ if (m) mpos += 64;
153+ }
154+ if (b > 0) {
155+ crypto_core_salsa20(x,z,k,sigma);
156+ for (i = 0; i < b; i++) c[cpos+i] = (m?m[mpos+i]:0) ^ x[i];
157+ }
158+ return 0;
159+ }
160+
161+ function crypto_stream_salsa20(c,cpos,d,n,k) {
162+ return crypto_stream_salsa20_xor(c,cpos,null,0,d,n,k);
163+ }
164+
165+ function crypto_stream(c,cpos,d,n,k) {
166+ var s = new Uint8Array(32);
167+ crypto_core_hsalsa20(s,n,k,sigma);
168+ return crypto_stream_salsa20(c,cpos,d,n.subarray(16),s);
169+ }
170+
171+ function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
172+ var s = new Uint8Array(32);
173+ crypto_core_hsalsa20(s,n,k,sigma);
174+ return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,n.subarray(16),s);
175+ }
176+
177+ function add1305(h, c) {
178+ var j, u = 0;
179+ for (j = 0; j < 17; j++) {
180+ u = (u + ((h[j] + c[j]) | 0)) | 0;
181+ h[j] = u & 255;
182+ u >>>= 8;
183+ }
184+ }
185+
186+ var minusp = new Uint32Array([
187+ 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252
188+ ]);
189+
190+ function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
191+ var s, i, j, u;
192+ var x = new Uint32Array(17), r = new Uint32Array(17),
193+ h = new Uint32Array(17), c = new Uint32Array(17),
194+ g = new Uint32Array(17);
195+ for (j = 0; j < 17; j++) r[j]=h[j]=0;
196+ for (j = 0; j < 16; j++) r[j]=k[j];
197+ r[3]&=15;
198+ r[4]&=252;
199+ r[7]&=15;
200+ r[8]&=252;
201+ r[11]&=15;
202+ r[12]&=252;
203+ r[15]&=15;
204+
205+ while (n > 0) {
206+ for (j = 0; j < 17; j++) c[j] = 0;
207+ for (j = 0; (j < 16) && (j < n); ++j) c[j] = m[mpos+j];
208+ c[j] = 1;
209+ mpos += j; n -= j;
210+ add1305(h,c);
211+ for (i = 0; i < 17; i++) {
212+ x[i] = 0;
213+ for (j = 0; j < 17; j++) x[i] = (x[i] + (h[j] * ((j <= i) ? r[i - j] : ((320 * r[i + 17 - j])|0))) | 0) | 0;
214+ }
215+ for (i = 0; i < 17; i++) h[i] = x[i];
216+ u = 0;
217+ for (j = 0; j < 16; j++) {
218+ u = (u + h[j]) | 0;
219+ h[j] = u & 255;
220+ u >>>= 8;
221+ }
222+ u = (u + h[16]) | 0; h[16] = u & 3;
223+ u = (5 * (u >>> 2)) | 0;
224+ for (j = 0; j < 16; j++) {
225+ u = (u + h[j]) | 0;
226+ h[j] = u & 255;
227+ u >>>= 8;
228+ }
229+ u = (u + h[16]) | 0; h[16] = u;
230+ }
231+
232+ for (j = 0; j < 17; j++) g[j] = h[j];
233+ add1305(h,minusp);
234+ s = (-(h[16] >>> 7) | 0);
235+ for (j = 0; j < 17; j++) h[j] ^= s & (g[j] ^ h[j]);
236+
237+ for (j = 0; j < 16; j++) c[j] = k[j + 16];
238+ c[16] = 0;
239+ add1305(h,c);
240+ for (j = 0; j < 16; j++) out[outpos+j] = h[j];
241+ return 0;
242+ }
243+
244+ function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
245+ var x = new Uint8Array(16);
246+ crypto_onetimeauth(x,0,m,mpos,n,k);
247+ return crypto_verify_16(h,hpos,x,0);
248+ }
249+
250+ function crypto_secretbox(c,m,d,n,k) {
251+ var i;
252+ if (d < 32) return -1;
253+ crypto_stream_xor(c,0,m,0,d,n,k);
254+ crypto_onetimeauth(c, 16, c, 32, d - 32, c);
255+ for (i = 0; i < 16; i++) c[i] = 0;
256+ return 0;
257+ }
258+
259+ function crypto_secretbox_open(m,c,d,n,k) {
260+ var i;
261+ var x = new Uint8Array(32);
262+ if (d < 32) return -1;
263+ crypto_stream(x,0,32,n,k);
264+ if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
265+ crypto_stream_xor(m,0,c,0,d,n,k);
266+ for (i = 0; i < 32; i++) m[i] = 0;
267+ return 0;
268+ }
269+
270+ function set25519(r, a) {
271+ var i;
272+ for (i = 0; i < 16; i++) r[i] = a[i]|0;
273+ }
274+
275+ function car25519(o) {
276+ var c;
277+ var i;
278+ for (i = 0; i < 16; i++) {
279+ o[i] += 65536;
280+ c = Math.floor(o[i] / 65536);
281+ o[(i+1)*(i<15?1:0)] += c - 1 + 37 * (c-1) * (i===15?1:0);
282+ o[i] -= (c * 65536);
283+ }
284+ }
285+
286+ function sel25519(p, q, b) {
287+ var t, c = ~(b-1);
288+ for (var i = 0; i < 16; i++) {
289+ t = c & (p[i] ^ q[i]);
290+ p[i] ^= t;
291+ q[i] ^= t;
292+ }
293+ }
294+
295+ function pack25519(o, n) {
296+ var i, j, b;
297+ var m = gf(), t = gf();
298+ for (i = 0; i < 16; i++) t[i] = n[i];
299+ car25519(t);
300+ car25519(t);
301+ car25519(t);
302+ for (j = 0; j < 2; j++) {
303+ m[0] = t[0] - 0xffed;
304+ for (i = 1; i < 15; i++) {
305+ m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
306+ m[i-1] &= 0xffff;
307+ }
308+ m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
309+ b = (m[15]>>16) & 1;
310+ m[14] &= 0xffff;
311+ sel25519(t, m, 1-b);
312+ }
313+ for (i = 0; i < 16; i++) {
314+ o[2*i] = t[i] & 0xff;
315+ o[2*i+1] = t[i]>>8;
316+ }
317+ }
318+
319+ function neq25519(a, b) {
320+ var c = new Uint8Array(32), d = new Uint8Array(32);
321+ pack25519(c, a);
322+ pack25519(d, b);
323+ return crypto_verify_32(c, 0, d, 0);
324+ }
325+
326+ function par25519(a) {
327+ var d = new Uint8Array(32);
328+ pack25519(d, a);
329+ return d[0] & 1;
330+ }
331+
332+ function unpack25519(o, n) {
333+ var i;
334+ for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
335+ o[15] &= 0x7fff;
336+ }
337+
338+ function A(o, a, b) {
339+ var i;
340+ for (i = 0; i < 16; i++) o[i] = (a[i] + b[i])|0;
341+ }
342+
343+ function Z(o, a, b) {
344+ var i;
345+ for (i = 0; i < 16; i++) o[i] = (a[i] - b[i])|0;
346+ }
347+
348+ function M(o, a, b) {
349+ var i, j, t = new Float64Array(31);
350+ for (i = 0; i < 31; i++) t[i] = 0;
351+ for (i = 0; i < 16; i++) {
352+ for (j = 0; j < 16; j++) {
353+ t[i+j] += a[i] * b[j];
354+ }
355+ }
356+ for (i = 0; i < 15; i++) {
357+ t[i] += 38 * t[i+16];
358+ }
359+ for (i = 0; i < 16; i++) o[i] = t[i];
360+ car25519(o);
361+ car25519(o);
362+ }
363+
364+ function S(o, a) {
365+ M(o, a, a);
366+ }
367+
368+ function inv25519(o, i) {
369+ var c = gf();
370+ var a;
371+ for (a = 0; a < 16; a++) c[a] = i[a];
372+ for (a = 253; a >= 0; a--) {
373+ S(c, c);
374+ if(a !== 2 && a !== 4) M(c, c, i);
375+ }
376+ for (a = 0; a < 16; a++) o[a] = c[a];
377+ }
378+
379+ function pow2523(o, i) {
380+ var c = gf();
381+ var a;
382+ for (a = 0; a < 16; a++) c[a] = i[a];
383+ for (a = 250; a >= 0; a--) {
384+ S(c, c);
385+ if(a !== 1) M(c, c, i);
386+ }
387+ for (a = 0; a < 16; a++) o[a] = c[a];
388+ }
389+
390+ function crypto_scalarmult(q, n, p) {
391+ var z = new Uint8Array(32);
392+ var x = new Float64Array(80), r, i;
393+ var a = gf(), b = gf(), c = gf(),
394+ d = gf(), e = gf(), f = gf();
395+ for (i = 0; i < 31; i++) z[i] = n[i];
396+ z[31]=(n[31]&127)|64;
397+ z[0]&=248;
398+ unpack25519(x,p);
399+ for (i = 0; i < 16; i++) {
400+ b[i]=x[i];
401+ d[i]=a[i]=c[i]=0;
402+ }
403+ a[0]=d[0]=1;
404+ for (i=254; i>=0; --i) {
405+ r=(z[i>>>3]>>>(i&7))&1;
406+ sel25519(a,b,r);
407+ sel25519(c,d,r);
408+ A(e,a,c);
409+ Z(a,a,c);
410+ A(c,b,d);
411+ Z(b,b,d);
412+ S(d,e);
413+ S(f,a);
414+ M(a,c,a);
415+ M(c,b,e);
416+ A(e,a,c);
417+ Z(a,a,c);
418+ S(b,a);
419+ Z(c,d,f);
420+ M(a,c,_121665);
421+ A(a,a,d);
422+ M(c,c,a);
423+ M(a,d,f);
424+ M(d,b,x);
425+ S(b,e);
426+ sel25519(a,b,r);
427+ sel25519(c,d,r);
428+ }
429+ for (i = 0; i < 16; i++) {
430+ x[i+16]=a[i];
431+ x[i+32]=c[i];
432+ x[i+48]=b[i];
433+ x[i+64]=d[i];
434+ }
435+ var x32 = x.subarray(32);
436+ var x16 = x.subarray(16);
437+ inv25519(x32,x32);
438+ M(x16,x16,x32);
439+ pack25519(q,x16);
440+ return 0;
441+ }
442+
443+ function crypto_scalarmult_base(q, n) {
444+ return crypto_scalarmult(q, n, _9);
445+ }
446+
447+ function crypto_box_keypair(y, x) {
448+ randombytes(x, 32);
449+ return crypto_scalarmult_base(y, x);
450+ }
451+
452+ function crypto_box_beforenm(k, y, x) {
453+ var s = new Uint8Array(32);
454+ crypto_scalarmult(s, x, y);
455+ return crypto_core_hsalsa20(k, _0, s, sigma);
456+ }
457+
458+ var crypto_box_afternm = crypto_secretbox;
459+ var crypto_box_open_afternm = crypto_secretbox_open;
460+
461+ function crypto_box(c, m, d, n, y, x) {
462+ var k = new Uint8Array(32);
463+ crypto_box_beforenm(k, y, x);
464+ return crypto_box_afternm(c, m, d, n, k);
465+ }
466+
467+ function crypto_box_open(m, c, d, n, y, x) {
468+ var k = new Uint8Array(32);
469+ crypto_box_beforenm(k, y, x);
470+ return crypto_box_open_afternm(m, c, d, n, k);
471+ }
472+
473+ function add64() {
474+ var a = 0, b = 0, c = 0, d = 0, m16 = 65535, l, h, i;
475+ for (i = 0; i < arguments.length; i++) {
476+ l = arguments[i].lo;
477+ h = arguments[i].hi;
478+ a += (l & m16); b += (l >>> 16);
479+ c += (h & m16); d += (h >>> 16);
480+ }
481+
482+ b += (a >>> 16);
483+ c += (b >>> 16);
484+ d += (c >>> 16);
485+
486+ return new u64((c & m16) | (d << 16), (a & m16) | (b << 16));
487+ }
488+
489+ function shr64(x, c) {
490+ return new u64((x.hi >>> c), (x.lo >>> c) | (x.hi << (32 - c)));
491+ }
492+
493+ function xor64() {
494+ var l = 0, h = 0, i;
495+ for (i = 0; i < arguments.length; i++) {
496+ l ^= arguments[i].lo;
497+ h ^= arguments[i].hi;
498+ }
499+ return new u64(h, l);
500+ }
501+
502+ function R(x, c) {
503+ var h, l, c1 = 32 - c;
504+ if (c < 32) {
505+ h = (x.hi >>> c) | (x.lo << c1);
506+ l = (x.lo >>> c) | (x.hi << c1);
507+ } else if (c < 64) {
508+ h = (x.lo >>> c) | (x.hi << c1);
509+ l = (x.hi >>> c) | (x.lo << c1);
510+ }
511+ return new u64(h, l);
512+ }
513+
514+ function Ch(x, y, z) {
515+ var h = (x.hi & y.hi) ^ (~x.hi & z.hi),
516+ l = (x.lo & y.lo) ^ (~x.lo & z.lo);
517+ return new u64(h, l);
518+ }
519+
520+ function Maj(x, y, z) {
521+ var h = (x.hi & y.hi) ^ (x.hi & z.hi) ^ (y.hi & z.hi),
522+ l = (x.lo & y.lo) ^ (x.lo & z.lo) ^ (y.lo & z.lo);
523+ return new u64(h, l);
524+ }
525+
526+ function Sigma0(x) { return xor64(R(x,28), R(x,34), R(x,39)); }
527+ function Sigma1(x) { return xor64(R(x,14), R(x,18), R(x,41)); }
528+ function sigma0(x) { return xor64(R(x, 1), R(x, 8), shr64(x,7)); }
529+ function sigma1(x) { return xor64(R(x,19), R(x,61), shr64(x,6)); }
530+
531+ var K = [
532+ new u64(0x428a2f98, 0xd728ae22), new u64(0x71374491, 0x23ef65cd),
533+ new u64(0xb5c0fbcf, 0xec4d3b2f), new u64(0xe9b5dba5, 0x8189dbbc),
534+ new u64(0x3956c25b, 0xf348b538), new u64(0x59f111f1, 0xb605d019),
535+ new u64(0x923f82a4, 0xaf194f9b), new u64(0xab1c5ed5, 0xda6d8118),
536+ new u64(0xd807aa98, 0xa3030242), new u64(0x12835b01, 0x45706fbe),
537+ new u64(0x243185be, 0x4ee4b28c), new u64(0x550c7dc3, 0xd5ffb4e2),
538+ new u64(0x72be5d74, 0xf27b896f), new u64(0x80deb1fe, 0x3b1696b1),
539+ new u64(0x9bdc06a7, 0x25c71235), new u64(0xc19bf174, 0xcf692694),
540+ new u64(0xe49b69c1, 0x9ef14ad2), new u64(0xefbe4786, 0x384f25e3),
541+ new u64(0x0fc19dc6, 0x8b8cd5b5), new u64(0x240ca1cc, 0x77ac9c65),
542+ new u64(0x2de92c6f, 0x592b0275), new u64(0x4a7484aa, 0x6ea6e483),
543+ new u64(0x5cb0a9dc, 0xbd41fbd4), new u64(0x76f988da, 0x831153b5),
544+ new u64(0x983e5152, 0xee66dfab), new u64(0xa831c66d, 0x2db43210),
545+ new u64(0xb00327c8, 0x98fb213f), new u64(0xbf597fc7, 0xbeef0ee4),
546+ new u64(0xc6e00bf3, 0x3da88fc2), new u64(0xd5a79147, 0x930aa725),
547+ new u64(0x06ca6351, 0xe003826f), new u64(0x14292967, 0x0a0e6e70),
548+ new u64(0x27b70a85, 0x46d22ffc), new u64(0x2e1b2138, 0x5c26c926),
549+ new u64(0x4d2c6dfc, 0x5ac42aed), new u64(0x53380d13, 0x9d95b3df),
550+ new u64(0x650a7354, 0x8baf63de), new u64(0x766a0abb, 0x3c77b2a8),
551+ new u64(0x81c2c92e, 0x47edaee6), new u64(0x92722c85, 0x1482353b),
552+ new u64(0xa2bfe8a1, 0x4cf10364), new u64(0xa81a664b, 0xbc423001),
553+ new u64(0xc24b8b70, 0xd0f89791), new u64(0xc76c51a3, 0x0654be30),
554+ new u64(0xd192e819, 0xd6ef5218), new u64(0xd6990624, 0x5565a910),
555+ new u64(0xf40e3585, 0x5771202a), new u64(0x106aa070, 0x32bbd1b8),
556+ new u64(0x19a4c116, 0xb8d2d0c8), new u64(0x1e376c08, 0x5141ab53),
557+ new u64(0x2748774c, 0xdf8eeb99), new u64(0x34b0bcb5, 0xe19b48a8),
558+ new u64(0x391c0cb3, 0xc5c95a63), new u64(0x4ed8aa4a, 0xe3418acb),
559+ new u64(0x5b9cca4f, 0x7763e373), new u64(0x682e6ff3, 0xd6b2b8a3),
560+ new u64(0x748f82ee, 0x5defb2fc), new u64(0x78a5636f, 0x43172f60),
561+ new u64(0x84c87814, 0xa1f0ab72), new u64(0x8cc70208, 0x1a6439ec),
562+ new u64(0x90befffa, 0x23631e28), new u64(0xa4506ceb, 0xde82bde9),
563+ new u64(0xbef9a3f7, 0xb2c67915), new u64(0xc67178f2, 0xe372532b),
564+ new u64(0xca273ece, 0xea26619c), new u64(0xd186b8c7, 0x21c0c207),
565+ new u64(0xeada7dd6, 0xcde0eb1e), new u64(0xf57d4f7f, 0xee6ed178),
566+ new u64(0x06f067aa, 0x72176fba), new u64(0x0a637dc5, 0xa2c898a6),
567+ new u64(0x113f9804, 0xbef90dae), new u64(0x1b710b35, 0x131c471b),
568+ new u64(0x28db77f5, 0x23047d84), new u64(0x32caab7b, 0x40c72493),
569+ new u64(0x3c9ebe0a, 0x15c9bebc), new u64(0x431d67c4, 0x9c100d4c),
570+ new u64(0x4cc5d4be, 0xcb3e42b6), new u64(0x597f299c, 0xfc657e2a),
571+ new u64(0x5fcb6fab, 0x3ad6faec), new u64(0x6c44198c, 0x4a475817)
572+ ];
573+
574+ function crypto_hashblocks(x, m, n) {
575+ var z = [], b = [], a = [], w = [], t, i, j;
576+
577+ for (i = 0; i < 8; i++) z[i] = a[i] = dl64(x, 8*i);
578+
579+ var pos = 0;
580+ while (n >= 128) {
581+ for (i = 0; i < 16; i++) w[i] = dl64(m, 8*i+pos);
582+ for (i = 0; i < 80; i++) {
583+ for (j = 0; j < 8; j++) b[j] = a[j];
584+ t = add64(a[7], Sigma1(a[4]), Ch(a[4], a[5], a[6]), K[i], w[i%16]);
585+ b[7] = add64(t, Sigma0(a[0]), Maj(a[0], a[1], a[2]));
586+ b[3] = add64(b[3], t);
587+ for (j = 0; j < 8; j++) a[(j+1)%8] = b[j];
588+ if (i%16 === 15) {
589+ for (j = 0; j < 16; j++) {
590+ w[j] = add64(w[j], w[(j+9)%16], sigma0(w[(j+1)%16]), sigma1(w[(j+14)%16]));
591+ }
592+ }
593+ }
594+
595+ for (i = 0; i < 8; i++) {
596+ a[i] = add64(a[i], z[i]);
597+ z[i] = a[i];
598+ }
599+
600+ pos += 128;
601+ n -= 128;
602+ }
603+
604+ for (i = 0; i < 8; i++) ts64(x, 8*i, z[i]);
605+ return n;
606+ }
607+
608+ var iv = new Uint8Array([
609+ 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
610+ 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
611+ 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
612+ 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
613+ 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
614+ 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
615+ 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
616+ 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
617+ ]);
618+
619+ function crypto_hash(out, m, n) {
620+ var h = new Uint8Array(64), x = new Uint8Array(256);
621+ var i, b = n;
622+
623+ for (i = 0; i < 64; i++) h[i] = iv[i];
624+
625+ crypto_hashblocks(h, m, n);
626+ n %= 128;
627+
628+ for (i = 0; i < 256; i++) x[i] = 0;
629+ for (i = 0; i < n; i++) x[i] = m[b-n+i];
630+ x[n] = 128;
631+
632+ n = 256-128*(n<112?1:0);
633+ x[n-9] = 0;
634+ ts64(x, n-8, new u64((b / 0x20000000) | 0, b << 3));
635+ crypto_hashblocks(h, x, n);
636+
637+ for (i = 0; i < 64; i++) out[i] = h[i];
638+
639+ return 0;
640+ }
641+
642+ function add(p, q) {
643+ var a = gf(), b = gf(), c = gf(),
644+ d = gf(), e = gf(), f = gf(),
645+ g = gf(), h = gf(), t = gf();
646+
647+ Z(a, p[1], p[0]);
648+ Z(t, q[1], q[0]);
649+ M(a, a, t);
650+ A(b, p[0], p[1]);
651+ A(t, q[0], q[1]);
652+ M(b, b, t);
653+ M(c, p[3], q[3]);
654+ M(c, c, D2);
655+ M(d, p[2], q[2]);
656+ A(d, d, d);
657+ Z(e, b, a);
658+ Z(f, d, c);
659+ A(g, d, c);
660+ A(h, b, a);
661+
662+ M(p[0], e, f);
663+ M(p[1], h, g);
664+ M(p[2], g, f);
665+ M(p[3], e, h);
666+ }
667+
668+ function cswap(p, q, b) {
669+ var i;
670+ for (i = 0; i < 4; i++) {
671+ sel25519(p[i], q[i], b);
672+ }
673+ }
674+
675+ function pack(r, p) {
676+ var tx = gf(), ty = gf(), zi = gf();
677+ inv25519(zi, p[2]);
678+ M(tx, p[0], zi);
679+ M(ty, p[1], zi);
680+ pack25519(r, ty);
681+ r[31] ^= par25519(tx) << 7;
682+ }
683+
684+ function scalarmult(p, q, s) {
685+ var b, i;
686+ set25519(p[0], gf0);
687+ set25519(p[1], gf1);
688+ set25519(p[2], gf1);
689+ set25519(p[3], gf0);
690+ for (i = 255; i >= 0; --i) {
691+ b = (s[(i/8)|0] >> (i&7)) & 1;
692+ cswap(p, q, b);
693+ add(q, p);
694+ add(p, p);
695+ cswap(p, q, b);
696+ }
697+ }
698+
699+ function scalarbase(p, s) {
700+ var q = [gf(), gf(), gf(), gf()];
701+ set25519(q[0], X);
702+ set25519(q[1], Y);
703+ set25519(q[2], gf1);
704+ M(q[3], X, Y);
705+ scalarmult(p, q, s);
706+ }
707+
708+ function crypto_sign_keypair(pk, sk, seeded) {
709+ var d = new Uint8Array(64);
710+ var p = [gf(), gf(), gf(), gf()];
711+ var i;
712+
713+ if (!seeded) randombytes(sk, 32);
714+ crypto_hash(d, sk, 32);
715+ d[0] &= 248;
716+ d[31] &= 127;
717+ d[31] |= 64;
718+
719+ scalarbase(p, d);
720+ pack(pk, p);
721+
722+ for (i = 0; i < 32; i++) sk[i+32] = pk[i];
723+ return 0;
724+ }
725+
726+ var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
727+
728+ function modL(r, x) {
729+ var carry, i, j, k;
730+ for (i = 63; i >= 32; --i) {
731+ carry = 0;
732+ for (j = i - 32, k = i - 12; j < k; ++j) {
733+ x[j] += carry - 16 * x[i] * L[j - (i - 32)];
734+ carry = Math.floor((x[j] + 128) / 256);
735+ x[j] -= carry * 256;
736+ }
737+ x[j] += carry;
738+ x[i] = 0;
739+ }
740+ carry = 0;
741+ for (j = 0; j < 32; j++) {
742+ x[j] += carry - (x[31] >> 4) * L[j];
743+ carry = x[j] >> 8;
744+ x[j] &= 255;
745+ }
746+ for (j = 0; j < 32; j++) x[j] -= carry * L[j];
747+ for (i = 0; i < 32; i++) {
748+ x[i+1] += x[i] >> 8;
749+ r[i] = x[i] & 255;
750+ }
751+ }
752+
753+ function reduce(r) {
754+ var x = new Float64Array(64), i;
755+ for (i = 0; i < 64; i++) x[i] = r[i];
756+ for (i = 0; i < 64; i++) r[i] = 0;
757+ modL(r, x);
758+ }
759+
760+ // Note: difference from C - smlen returned, not passed as argument.
761+ function crypto_sign(sm, m, n, sk) {
762+ var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
763+ var i, j, x = new Float64Array(64);
764+ var p = [gf(), gf(), gf(), gf()];
765+
766+ crypto_hash(d, sk, 32);
767+ d[0] &= 248;
768+ d[31] &= 127;
769+ d[31] |= 64;
770+
771+ var smlen = n + 64;
772+ for (i = 0; i < n; i++) sm[64 + i] = m[i];
773+ for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
774+
775+ crypto_hash(r, sm.subarray(32), n+32);
776+ reduce(r);
777+ scalarbase(p, r);
778+ pack(sm, p);
779+
780+ for (i = 32; i < 64; i++) sm[i] = sk[i];
781+ crypto_hash(h, sm, n + 64);
782+ reduce(h);
783+
784+ for (i = 0; i < 64; i++) x[i] = 0;
785+ for (i = 0; i < 32; i++) x[i] = r[i];
786+ for (i = 0; i < 32; i++) {
787+ for (j = 0; j < 32; j++) {
788+ x[i+j] += h[i] * d[j];
789+ }
790+ }
791+
792+ modL(sm.subarray(32), x);
793+ return smlen;
794+ }
795+
796+ function crypto_inner_sign(sm, m, n, sk, publicKey) {
797+ var p = [gf(), gf(), gf(), gf()];
798+ var i, j, s = new Float64Array(64);
799+ let messageDigest = new Uint8Array(64), hramDigest = new Uint8Array(64);
800+ messageDigest = crypto.createHash('sha512')
801+ .update(sk.subarray(32))
802+ .update(m)
803+ .digest();
804+
805+ let encodedR = new Uint8Array(32);
806+ reduce(messageDigest);
807+ const messageDigestReduced = messageDigest.subarray(0,32);
808+
809+ scalarbase(p, messageDigestReduced);
810+ pack(encodedR, p);
811+
812+ hramDigest = crypto.createHash('sha512')
813+ .update(encodedR)
814+ .update(publicKey)
815+ .update(m)
816+ .digest();
817+
818+ reduce(hramDigest);
819+
820+ let _sk = sk.subarray(0,32);
821+
822+ for ( i = 0; i < 64; i++) s[i] = 0;
823+ for ( i = 0; i < 32; i++) s[i] = messageDigest[i];
824+ for ( i = 0; i < 32; i++) {
825+ for ( j = 0; j < 32; j++) {
826+ s[i+j] += hramDigest[i] * _sk[j];
827+ }
828+ }
829+
830+ modL(sm.subarray(32), s);
831+ for ( i = 0; i < 32; i++) sm[i] = encodedR[i];
832+
833+ }
834+
835+ function unpackneg(r, p) {
836+ var t = gf(), chk = gf(), num = gf(),
837+ den = gf(), den2 = gf(), den4 = gf(),
838+ den6 = gf();
839+
840+ set25519(r[2], gf1);
841+ unpack25519(r[1], p);
842+ S(num, r[1]);
843+ M(den, num, D);
844+ Z(num, num, r[2]);
845+ A(den, r[2], den);
846+
847+ S(den2, den);
848+ S(den4, den2);
849+ M(den6, den4, den2);
850+ M(t, den6, num);
851+ M(t, t, den);
852+
853+ pow2523(t, t);
854+ M(t, t, num);
855+ M(t, t, den);
856+ M(t, t, den);
857+ M(r[0], t, den);
858+
859+ S(chk, r[0]);
860+ M(chk, chk, den);
861+ if (neq25519(chk, num)) M(r[0], r[0], I);
862+
863+ S(chk, r[0]);
864+ M(chk, chk, den);
865+ if (neq25519(chk, num)) return -1;
866+
867+ if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
868+
869+ M(r[3], r[0], r[1]);
870+ return 0;
871+ }
872+
873+ function crypto_sign_open(m, sm, n, pk) {
874+ var i;
875+ var t = new Uint8Array(32), h = new Uint8Array(64);
876+ var p = [gf(), gf(), gf(), gf()],
877+ q = [gf(), gf(), gf(), gf()];
878+
879+ if (n < 64) return -1;
880+
881+ if (unpackneg(q, pk)) return -1;
882+
883+ for (i = 0; i < n; i++) m[i] = sm[i];
884+ for (i = 0; i < 32; i++) m[i+32] = pk[i];
885+ crypto_hash(h, m, n);
886+ reduce(h);
887+ scalarmult(p, q, h);
888+
889+ scalarbase(q, sm.subarray(32));
890+ add(p, q);
891+ pack(t, p);
892+
893+ n -= 64;
894+ if (crypto_verify_32(sm, 0, t, 0)) {
895+ for (i = 0; i < n; i++) m[i] = 0;
896+ return -1;
897+ }
898+
899+ for (i = 0; i < n; i++) m[i] = sm[i + 64];
900+ return n;
901+ }
902+
903+ var crypto_secretbox_KEYBYTES = 32,
904+ crypto_secretbox_NONCEBYTES = 24,
905+ crypto_secretbox_ZEROBYTES = 32,
906+ crypto_secretbox_BOXZEROBYTES = 16,
907+ crypto_scalarmult_BYTES = 32,
908+ crypto_scalarmult_SCALARBYTES = 32,
909+ crypto_box_PUBLICKEYBYTES = 32,
910+ crypto_box_SECRETKEYBYTES = 32,
911+ crypto_box_BEFORENMBYTES = 32,
912+ crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
913+ crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
914+ crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
915+ crypto_sign_BYTES = 64,
916+ crypto_sign_PUBLICKEYBYTES = 32,
917+ crypto_sign_SECRETKEYBYTES = 64,
918+ crypto_sign_SEEDBYTES = 32,
919+ crypto_hash_BYTES = 64;
920+
921+ nacl.lowlevel = {
922+ crypto_core_hsalsa20: crypto_core_hsalsa20,
923+ crypto_stream_xor: crypto_stream_xor,
924+ crypto_stream: crypto_stream,
925+ crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
926+ crypto_stream_salsa20: crypto_stream_salsa20,
927+ crypto_onetimeauth: crypto_onetimeauth,
928+ crypto_onetimeauth_verify: crypto_onetimeauth_verify,
929+ crypto_verify_16: crypto_verify_16,
930+ crypto_verify_32: crypto_verify_32,
931+ crypto_secretbox: crypto_secretbox,
932+ crypto_secretbox_open: crypto_secretbox_open,
933+ crypto_scalarmult: crypto_scalarmult,
934+ crypto_scalarmult_base: crypto_scalarmult_base,
935+ crypto_box_beforenm: crypto_box_beforenm,
936+ crypto_box_afternm: crypto_box_afternm,
937+ crypto_box: crypto_box,
938+ crypto_box_open: crypto_box_open,
939+ crypto_box_keypair: crypto_box_keypair,
940+ crypto_hash: crypto_hash,
941+ crypto_sign: crypto_sign,
942+ crypto_sign_keypair: crypto_sign_keypair,
943+ crypto_sign_open: crypto_sign_open,
944+
945+ crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
946+ crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
947+ crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
948+ crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
949+ crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
950+ crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
951+ crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
952+ crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
953+ crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
954+ crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
955+ crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
956+ crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
957+ crypto_sign_BYTES: crypto_sign_BYTES,
958+ crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
959+ crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
960+ crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
961+ crypto_hash_BYTES: crypto_hash_BYTES,
962+
963+ gf: gf,
964+ D: D,
965+ L: L,
966+ pack25519: pack25519,
967+ unpack25519: unpack25519,
968+ M: M,
969+ A: A,
970+ S: S,
971+ Z: Z,
972+ pow2523: pow2523,
973+ add: add,
974+ set25519: set25519,
975+ modL: modL,
976+ scalarmult: scalarmult,
977+ scalarbase: scalarbase,
978+ };
979+
980+ /* High-level API */
981+
982+ function checkLengths(k, n) {
983+ if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
984+ if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
985+ }
986+
987+ function checkBoxLengths(pk, sk) {
988+ if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
989+ if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
990+ }
991+
992+ function checkArrayTypes() {
993+ for (var i = 0; i < arguments.length; i++) {
994+ if (!(arguments[i] instanceof Uint8Array))
995+ throw new TypeError('unexpected type, use Uint8Array');
996+ }
997+ }
998+
999+ function cleanup(arr) {
1000+ for (var i = 0; i < arr.length; i++) arr[i] = 0;
1001+ }
1002+
1003+ nacl.randomBytes = function(n) {
1004+ var b = new Uint8Array(n);
1005+ randombytes(b, n);
1006+ return b;
1007+ };
1008+
1009+ nacl.secretbox = function(msg, nonce, key) {
1010+ checkArrayTypes(msg, nonce, key);
1011+ checkLengths(key, nonce);
1012+ var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
1013+ var c = new Uint8Array(m.length);
1014+ for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
1015+ crypto_secretbox(c, m, m.length, nonce, key);
1016+ return c.subarray(crypto_secretbox_BOXZEROBYTES);
1017+ };
1018+
1019+ nacl.secretbox.open = function(box, nonce, key) {
1020+ checkArrayTypes(box, nonce, key);
1021+ checkLengths(key, nonce);
1022+ var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
1023+ var m = new Uint8Array(c.length);
1024+ for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
1025+ if (c.length < 32) return null;
1026+ if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
1027+ return m.subarray(crypto_secretbox_ZEROBYTES);
1028+ };
1029+
1030+ nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
1031+ nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
1032+ nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
1033+
1034+ nacl.scalarMult = function(n, p) {
1035+ checkArrayTypes(n, p);
1036+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
1037+ if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
1038+ var q = new Uint8Array(crypto_scalarmult_BYTES);
1039+ crypto_scalarmult(q, n, p);
1040+ return q;
1041+ };
1042+
1043+ nacl.scalarMult.base = function(n) {
1044+ checkArrayTypes(n);
1045+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
1046+ var q = new Uint8Array(crypto_scalarmult_BYTES);
1047+ crypto_scalarmult_base(q, n);
1048+ return q;
1049+ };
1050+
1051+ nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
1052+ nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
1053+
1054+ nacl.box = function(msg, nonce, publicKey, secretKey) {
1055+ var k = nacl.box.before(publicKey, secretKey);
1056+ return nacl.secretbox(msg, nonce, k);
1057+ };
1058+
1059+ nacl.box.before = function(publicKey, secretKey) {
1060+ checkArrayTypes(publicKey, secretKey);
1061+ checkBoxLengths(publicKey, secretKey);
1062+ var k = new Uint8Array(crypto_box_BEFORENMBYTES);
1063+ crypto_box_beforenm(k, publicKey, secretKey);
1064+ return k;
1065+ };
1066+
1067+ nacl.box.after = nacl.secretbox;
1068+
1069+ nacl.box.open = function(msg, nonce, publicKey, secretKey) {
1070+ var k = nacl.box.before(publicKey, secretKey);
1071+ return nacl.secretbox.open(msg, nonce, k);
1072+ };
1073+
1074+ nacl.box.open.after = nacl.secretbox.open;
1075+
1076+ nacl.box.keyPair = function() {
1077+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
1078+ var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
1079+ crypto_box_keypair(pk, sk);
1080+ return {publicKey: pk, secretKey: sk};
1081+ };
1082+
1083+ nacl.box.keyPair.fromSecretKey = function(secretKey) {
1084+ checkArrayTypes(secretKey);
1085+ if (secretKey.length !== crypto_box_SECRETKEYBYTES)
1086+ throw new Error('bad secret key size');
1087+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
1088+ crypto_scalarmult_base(pk, secretKey);
1089+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
1090+ };
1091+
1092+ nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
1093+ nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
1094+ nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
1095+ nacl.box.nonceLength = crypto_box_NONCEBYTES;
1096+ nacl.box.overheadLength = nacl.secretbox.overheadLength;
1097+
1098+ nacl.sign = function(msg, secretKey) {
1099+ checkArrayTypes(msg, secretKey);
1100+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
1101+ throw new Error('bad secret key size');
1102+ var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
1103+ crypto_sign(signedMsg, msg, msg.length, secretKey);
1104+ return signedMsg;
1105+ };
1106+
1107+ nacl.innerSign = function(msg, secretKey, publicKey) {
1108+ checkArrayTypes(msg, secretKey);
1109+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
1110+ throw new Error('bad secret key size');
1111+ const _msg = Buffer.from(msg,'hex');
1112+ var signedMsg = new Uint8Array(crypto_sign_BYTES);
1113+ crypto_inner_sign(signedMsg, _msg, _msg.length, secretKey, publicKey);
1114+ return signedMsg;
1115+ };
1116+
1117+ nacl.sign.open = function(signedMsg, publicKey) {
1118+ checkArrayTypes(signedMsg, publicKey);
1119+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
1120+ throw new Error('bad public key size');
1121+ var tmp = new Uint8Array(signedMsg.length);
1122+ var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
1123+ if (mlen < 0) return null;
1124+ var m = new Uint8Array(mlen);
1125+ for (var i = 0; i < m.length; i++) m[i] = tmp[i];
1126+ return m;
1127+ };
1128+
1129+ nacl.sign.detached = function(msg, secretKey) {
1130+ var signedMsg = nacl.sign(msg, secretKey);
1131+ var sig = new Uint8Array(crypto_sign_BYTES);
1132+ for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
1133+ return sig;
1134+ };
1135+
1136+ nacl.sign.detached.verify = function(msg, sig, publicKey) {
1137+ checkArrayTypes(msg, sig, publicKey);
1138+ if (sig.length !== crypto_sign_BYTES)
1139+ throw new Error('bad signature size');
1140+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
1141+ throw new Error('bad public key size');
1142+ var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
1143+ var m = new Uint8Array(crypto_sign_BYTES + msg.length);
1144+ var i;
1145+ for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
1146+ for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
1147+ return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
1148+ };
1149+
1150+ nacl.sign.keyPair = function() {
1151+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
1152+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
1153+ crypto_sign_keypair(pk, sk);
1154+ return {publicKey: pk, secretKey: sk};
1155+ };
1156+
1157+ nacl.sign.keyPair.fromSecretKey = function(secretKey) {
1158+ checkArrayTypes(secretKey);
1159+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
1160+ throw new Error('bad secret key size');
1161+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
1162+ for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
1163+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
1164+ };
1165+
1166+ nacl.sign.keyPair.fromSeed = function(seed) {
1167+ checkArrayTypes(seed);
1168+ if (seed.length !== crypto_sign_SEEDBYTES)
1169+ throw new Error('bad seed size');
1170+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
1171+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
1172+ for (var i = 0; i < 32; i++) sk[i] = seed[i];
1173+ crypto_sign_keypair(pk, sk, true);
1174+ return {publicKey: pk, secretKey: sk};
1175+ };
1176+
1177+ nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
1178+ nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
1179+ nacl.sign.seedLength = crypto_sign_SEEDBYTES;
1180+ nacl.sign.signatureLength = crypto_sign_BYTES;
1181+
1182+ nacl.hash = function(msg) {
1183+ checkArrayTypes(msg);
1184+ var h = new Uint8Array(crypto_hash_BYTES);
1185+ crypto_hash(h, msg, msg.length);
1186+ return h;
1187+ };
1188+
1189+ nacl.hash.hashLength = crypto_hash_BYTES;
1190+
1191+ nacl.verify = function(x, y) {
1192+ checkArrayTypes(x, y);
1193+ // Zero length arguments are considered not equal.
1194+ if (x.length === 0 || y.length === 0) return false;
1195+ if (x.length !== y.length) return false;
1196+ return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
1197+ };
1198+
1199+ nacl.setPRNG = function(fn) {
1200+ randombytes = fn;
1201+ };
1202+
1203+ (function() {
1204+ // Initialize PRNG if environment provides CSPRNG.
1205+ // If not, methods calling randombytes will throw.
1206+ var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
1207+ if (crypto && crypto.getRandomValues) {
1208+ // Browsers.
1209+ var QUOTA = 65536;
1210+ nacl.setPRNG(function(x, n) {
1211+ var i, v = new Uint8Array(n);
1212+ for (i = 0; i < n; i += QUOTA) {
1213+ crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
1214+ }
1215+ for (i = 0; i < n; i++) x[i] = v[i];
1216+ cleanup(v);
1217+ });
1218+ } else if (typeof require !== 'undefined') {
1219+ // Node.js.
1220+ crypto = require('crypto');
1221+ if (crypto && crypto.randomBytes) {
1222+ nacl.setPRNG(function(x, n) {
1223+ var i, v = crypto.randomBytes(n);
1224+ for (i = 0; i < n; i++) x[i] = v[i];
1225+ cleanup(v);
1226+ });
1227+ }
1228+ }
1229+ })();
1230+
1231+})(typeof module !== 'undefined' && module.exports ? module.exports : (self.nacl = self.nacl || {}));
\ No newline at end of file
--- /dev/null
+++ b/src/utils/transaction/signMessage.js
@@ -0,0 +1,17 @@
1+import {SignData} from './signTransaction';
2+
3+function signMessage(message, password, keyJSON) {
4+ if (!(message) || !(password) || !(keyJSON) ){
5+ throw('Input args are empty', 'BTM3100');
6+ }
7+
8+ let signData = SignData(keyJSON, null, Buffer.from(message, 'utf8'), password);
9+
10+ let ret = {};
11+ ret.signature = (new Buffer(signData)).toString('hex')
12+ return ret;
13+}
14+
15+export {
16+ signMessage
17+};
\ No newline at end of file
--- /dev/null
+++ b/src/utils/transaction/signTransaction.js
@@ -0,0 +1,48 @@
1+import { decryptKey} from '../key/keystore';
2+import {XPrv} from '../key/chainkd';
3+
4+
5+function signTransaction(transaction, password, keyJSON) {
6+ if (!(transaction) || !(password) || !(keyJSON) ){
7+ throw('Input args are empty', 'BTM3100');
8+ }
9+ let tx = transaction;
10+ let signRet = [];
11+
12+ for(let k = 0; k<tx.signingInstructions.length; k++){
13+ const v = tx.signingInstructions[k];
14+ let path = [];
15+ if(v.derivationPath){
16+ for(let i = 0; i< v.derivationPath.length; i++ ){
17+ path[i] = Buffer.from(v.derivationPath[i],"hex");
18+ }
19+ }
20+ for(let d of v.signData ){
21+
22+ const h = Buffer.from(d, 'hex');
23+ const signData = SignData(keyJSON, path, h, password);
24+ if(signRet[k] == undefined) {
25+ signRet[k] = [];
26+ }
27+ signRet[k] = signRet[k].concat( (new Buffer(signData)).toString('hex'));
28+ }
29+ }
30+ let ret ={};
31+ ret.raw_transaction = tx.rawTransaction;
32+ ret.signatures = signRet;
33+ return ret;
34+}
35+
36+function SignData(keyJSON, path, data, password){
37+ const key = decryptKey(keyJSON, password);
38+ let _xprv = new XPrv(key.xPrv);
39+ if (path && path.length > 0) {
40+ _xprv = _xprv.Derive(path);
41+ }
42+ return _xprv.Sign(data);
43+}
44+
45+export {
46+ signTransaction,
47+ SignData
48+};
--- /dev/null
+++ b/src/utils/utils.js
@@ -0,0 +1,19 @@
1+export const camelize = (object) => {
2+ for (let key in object) {
3+ let value = object[key];
4+ let newKey = key;
5+
6+ if (/_/.test(key)) {
7+ newKey = key.replace(/([_][a-z])/g, v => v[1].toUpperCase());
8+ delete object[key];
9+ }
10+
11+ if (typeof value == 'object') {
12+ value = camelize(value);
13+ }
14+
15+ object[newKey] = value;
16+ }
17+
18+ return object;
19+};
\ No newline at end of file
--- a/src/wasm/go.js
+++ b/src/wasm/go.js
@@ -16,37 +16,37 @@ export function LoadWasm() {
1616 // Map web browser API and Node.js API to a single common API (preferring web standards over Node.js API).
1717 let outputBuf = '';
1818 global.fs = {
19- constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
20- writeSync(fd, buf) {
21- outputBuf += decoder.decode(buf);
22- const nl = outputBuf.lastIndexOf('\n');
23- if (nl != -1) {
24- console.log(outputBuf.substr(0, nl));
25- outputBuf = outputBuf.substr(nl + 1);
26- }
27- return buf.length;
28- },
29- write(fd, buf, offset, length, position, callback) {
30- if (offset !== 0 || length !== buf.length || position !== null) {
31- throw new Error('not implemented');
32- }
33- const n = this.writeSync(fd, buf);
34- callback(null, n);
35- },
36- open(path, flags, mode, callback) {
37- const err = new Error('not implemented');
38- err.code = 'ENOSYS';
39- callback(err);
40- },
41- read(fd, buffer, offset, length, position, callback) {
42- const err = new Error('not implemented');
43- err.code = 'ENOSYS';
44- callback(err);
45- },
46- fsync(fd, callback) {
47- callback(null);
48- },
49- };
19+ constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1 }, // unused
20+ writeSync(fd, buf) {
21+ outputBuf += decoder.decode(buf);
22+ const nl = outputBuf.lastIndexOf('\n');
23+ if (nl != -1) {
24+ console.log(outputBuf.substr(0, nl));
25+ outputBuf = outputBuf.substr(nl + 1);
26+ }
27+ return buf.length;
28+ },
29+ write(fd, buf, offset, length, position, callback) {
30+ if (offset !== 0 || length !== buf.length || position !== null) {
31+ throw new Error('not implemented');
32+ }
33+ const n = this.writeSync(fd, buf);
34+ callback(null, n);
35+ },
36+ open(path, flags, mode, callback) {
37+ const err = new Error('not implemented');
38+ err.code = 'ENOSYS';
39+ callback(err);
40+ },
41+ read(fd, buffer, offset, length, position, callback) {
42+ const err = new Error('not implemented');
43+ err.code = 'ENOSYS';
44+ callback(err);
45+ },
46+ fsync(fd, callback) {
47+ callback(null);
48+ },
49+ };
5050
5151 const encoder = new TextEncoder('utf-8');
5252 const decoder = new TextDecoder('utf-8');
@@ -219,7 +219,15 @@ export function LoadWasm() {
219219 const id = this._nextCallbackTimeoutID;
220220 this._nextCallbackTimeoutID++;
221221 this._scheduledTimeouts.set(id, setTimeout(
222- () => { this._resume(); },
222+ () => {
223+ this._resume();
224+ while (this._scheduledTimeouts.has(id)) {
225+ // for some reason Go failed to register the timeout event, log and try again
226+ // (temporary workaround for https://github.com/golang/go/issues/28975)
227+ console.warn('scheduleTimeoutEvent: missed timeout event');
228+ this._resume();
229+ }
230+ },
223231 getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early
224232 ));
225233 mem().setInt32(sp + 16, id, true);
@@ -333,6 +341,34 @@ export function LoadWasm() {
333341 mem().setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16));
334342 },
335343
344+ // func copyBytesToGo(dst []byte, src ref) (int, bool)
345+ 'syscall/js.copyBytesToGo': (sp) => {
346+ const dst = loadSlice(sp + 8);
347+ const src = loadValue(sp + 32);
348+ if (!(src instanceof Uint8Array)) {
349+ mem().setUint8(sp + 48, 0);
350+ return;
351+ }
352+ const toCopy = src.subarray(0, dst.length);
353+ dst.set(toCopy);
354+ setInt64(sp + 40, toCopy.length);
355+ mem().setUint8(sp + 48, 1);
356+ },
357+
358+ // func copyBytesToJS(dst ref, src []byte) (int, bool)
359+ 'syscall/js.copyBytesToJS': (sp) => {
360+ const dst = loadValue(sp + 8);
361+ const src = loadSlice(sp + 16);
362+ if (!(dst instanceof Uint8Array)) {
363+ mem().setUint8(sp + 48, 0);
364+ return;
365+ }
366+ const toCopy = src.subarray(0, dst.length);
367+ dst.set(toCopy);
368+ setInt64(sp + 40, toCopy.length);
369+ mem().setUint8(sp + 48, 1);
370+ },
371+
336372 'debug': (value) => {
337373 console.log(value);
338374 },
@@ -349,7 +385,6 @@ export function LoadWasm() {
349385 true,
350386 false,
351387 global,
352- this._inst.exports.mem,
353388 this,
354389 ];
355390 this._refs = new Map();
@@ -361,9 +396,13 @@ export function LoadWasm() {
361396 let offset = 4096;
362397
363398 const strPtr = (str) => {
364- let ptr = offset;
365- new Uint8Array(mem.buffer, offset, str.length + 1).set(encoder.encode(str + '\0'));
366- offset += str.length + (8 - (str.length % 8));
399+ const ptr = offset;
400+ const bytes = encoder.encode(str + '\0');
401+ new Uint8Array(mem.buffer, offset, bytes.length).set(bytes);
402+ offset += bytes.length;
403+ if (offset % 8 !== 0) {
404+ offset += 8 - (offset % 8);
405+ }
367406 return ptr;
368407 };
369408
Show on old repository browser