57 lines
2.7 KiB
Diff
57 lines
2.7 KiB
Diff
diff --git a/node_modules/web3-eth-accounts/lib/index.js b/node_modules/web3-eth-accounts/lib/index.js
|
|
index a176dd9..de56ed8 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');
|
|
@@ -420,7 +420,14 @@ 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) {
|
|
+ derivedKey = jsb.jcCryptoScrypt(password, kdfparams.salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ } else {
|
|
+ derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ }
|
|
+ console.log('scrypt encrypt cost time: ' + (Date.now() - start)/1000);
|
|
}
|
|
else if (json.crypto.kdf === 'pbkdf2') {
|
|
kdfparams = json.crypto.kdfparams;
|
|
@@ -463,7 +470,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) {
|
|
+ derivedKey = jsb.jcCryptoScrypt(password, kdfparams.salt, kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ } else {
|
|
+ derivedKey = scrypt.syncScrypt(Buffer.from(password), Buffer.from(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
|
|
+ }
|
|
+
|
|
+ console.log('scrypt encrypt cost time: ' + (Date.now() - start)/1000);
|
|
}
|
|
else {
|
|
throw new Error('Unsupported kdf');
|
|
@@ -621,6 +636,9 @@ if (!storageAvailable('localStorage')) {
|
|
*/
|
|
function storageAvailable(type) {
|
|
var storage;
|
|
+ if (typeof cc !== undefined) {
|
|
+ return true
|
|
+ }
|
|
try {
|
|
storage = self[type];
|
|
var x = '__storage_test__';
|