77 lines
3.4 KiB
Diff
77 lines
3.4 KiB
Diff
diff --git a/node_modules/web3-eth-accounts/lib/index.js b/node_modules/web3-eth-accounts/lib/index.js
|
|
index a176dd9..4c05e61 100644
|
|
--- a/node_modules/web3-eth-accounts/lib/index.js
|
|
+++ b/node_modules/web3-eth-accounts/lib/index.js
|
|
@@ -23,7 +23,7 @@
|
|
var core = require('web3-core');
|
|
var Method = require('web3-core-method');
|
|
var Account = require('eth-lib/lib/account');
|
|
-var cryp = (typeof global === 'undefined') ? require('crypto-browserify') : require('crypto');
|
|
+var cryp = require('crypto-browserify');
|
|
var scrypt = require('scrypt-js');
|
|
var uuid = require('uuid');
|
|
var utils = require('web3-utils');
|
|
@@ -38,6 +38,18 @@ var isNot = function (value) {
|
|
var isExist = function (value) {
|
|
return (typeof value !== 'undefined') && value !== null;
|
|
};
|
|
+
|
|
+var base64ToUint8Buffer = function(base64) {
|
|
+ var binary_string = window.atob(base64);
|
|
+ var len = binary_string.length;
|
|
+ var bytes = new Uint8Array(len);
|
|
+ for (var i = 0; i < len; i++) {
|
|
+ bytes[i] = binary_string.charCodeAt(i);
|
|
+ }
|
|
+ return bytes;
|
|
+}
|
|
+
|
|
+
|
|
var Accounts = function Accounts() {
|
|
var _this = this;
|
|
// sets _requestmanager
|
|
@@ -420,7 +432,15 @@ Accounts.prototype.decrypt = function (v3Keystore, password, nonStrict) {
|
|
if (json.crypto.kdf === 'scrypt') {
|
|
kdfparams = json.crypto.kdfparams;
|
|
// FIXME: support progress reporting callback
|
|
- derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ var start = Date.now();
|
|
+ if (window.jsb && window.jsb.jcCryptoScrypt) {
|
|
+ let tmpKey = jsb.jcCryptoScrypt(password, kdfparams.salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ derivedKey = base64ToUint8Buffer(tmpKey);
|
|
+ } else {
|
|
+ derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ }
|
|
+ console.log('decrypt key: ' + derivedKey);
|
|
+ console.log('scrypt generate key cost time: ' + (Date.now() - start)/1000);
|
|
}
|
|
else if (json.crypto.kdf === 'pbkdf2') {
|
|
kdfparams = json.crypto.kdfparams;
|
|
@@ -463,7 +483,15 @@ Accounts.prototype.encrypt = function (privateKey, password, options) {
|
|
kdfparams.n = options.n || 8192; // 2048 4096 8192 16384
|
|
kdfparams.r = options.r || 8;
|
|
kdfparams.p = options.p || 1;
|
|
- derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ var start = Date.now();
|
|
+
|
|
+ if (window.jsb && window.jsb.jcCryptoScrypt) {
|
|
+ let tmpKey = jsb.jcCryptoScrypt(password, kdfparams.salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ derivedKey = base64ToUint8Buffer(tmpKey);
|
|
+ } else {
|
|
+ derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ }
|
|
+ console.log('scrypt generate key cost time: ' + (Date.now() - start)/1000);
|
|
}
|
|
else {
|
|
throw new Error('Unsupported kdf');
|
|
@@ -621,6 +649,9 @@ if (!storageAvailable('localStorage')) {
|
|
*/
|
|
function storageAvailable(type) {
|
|
var storage;
|
|
+ if (typeof cc !== undefined) {
|
|
+ return true
|
|
+ }
|
|
try {
|
|
storage = self[type];
|
|
var x = '__storage_test__';
|