diff --git a/cache.js b/cache.js deleted file mode 100644 index eeb9433..0000000 --- a/cache.js +++ /dev/null @@ -1,81 +0,0 @@ -const MAX_CACHE_SIZE = 100; - -const transformArrayBufferIntoStr = (str) => { - if ( - !str || - str.length === 0 || - (!isArrayBuffer(str) && typeof str !== "string") - ) { - return; - } - - let newStr = str; - - // Trim leading `0x` if present - if (newStr.slice(0, 2) === "0x") { - newStr = newStr.slice(2); - } else if (isArrayBuffer(newStr)) { - newStr = Buffer.from(newStr).toString("hex"); - } - - return newStr; -}; - -const generateDefKey = (data, to) => { - if (!data || !to) { - return; - } - - const dataStr = transformArrayBufferIntoStr(data); - const toStr = transformArrayBufferIntoStr(to); - - if (!dataStr || !toStr) { - return; - } - - return `${toStr}${dataStr.slice(0, 8)}`; -}; - -const getCachedDef = (tx, cache) => { - return cache.get(generateDefKey(tx.data, tx.to)); -}; - -const saveDefToCache = (tx, cache, def) => { - if (!tx.data || tx.data.length === 0) { - return; - } - - const key = generateDefKey(tx.data, tx.to); - if (!key) { - return; - } - - if (cache.size >= MAX_CACHE_SIZE) { - cache.delete(cache.keys().next().value); - } - cache.set(key, def); -}; - -const serializeCache = (cache) => { - return JSON.stringify([...cache]); -}; - -const deserializeCache = (cache) => { - return new Map(JSON.parse(cache)); -}; - -const isArrayBuffer = (value) => { - return ( - value && - value.buffer instanceof ArrayBuffer && - value.byteLength !== undefined - ); -}; - -module.exports = { - generateDefKey, - getCachedDef, - saveDefToCache, - serializeCache, - deserializeCache, -}; diff --git a/index.js b/index.js index 4cd3261..806efc9 100644 --- a/index.js +++ b/index.js @@ -5,12 +5,6 @@ const SDK = require('gridplus-sdk'); const EthTx = require('@ethereumjs/tx'); const { addHexPrefix } = require("@ethereumjs/util"); const rlp = require('rlp'); -const { - serializeCache, - deserializeCache, - getCachedDef, - saveDefToCache, -} = require("./cache"); const keyringType = 'Lattice Hardware'; const HARDENED_OFFSET = 0x80000000; const PER_PAGE = 5; @@ -22,7 +16,6 @@ const CONNECT_TIMEOUT = 20000; class LatticeKeyring extends EventEmitter { constructor (opts={}) { super() - this.requestCache = new Map(); this.type = keyringType; this._resetDefaults(); this.deserialize(opts); @@ -52,8 +45,6 @@ class LatticeKeyring extends EventEmitter { this.network = opts.network; if (opts.page) this.page = opts.page; - if (opts.requestCache) - this.requestCache = deserializeCache(opts.requestCache) return; } @@ -73,7 +64,6 @@ class LatticeKeyring extends EventEmitter { network: this.network, page: this.page, hdPath: this.hdPath, - requestCache: serializeCache(this.requestCache), }; } @@ -187,18 +177,9 @@ class LatticeKeyring extends EventEmitter { encodingType: SDK.Constants.SIGNING.ENCODINGS.EVM, signerPath, }; - let def; - const cachedDef = getCachedDef(tx, this.requestCache) - - if (cachedDef) { - def = cachedDef - } else { - const supportsDecoderRecursion = fwVersion.major > 0 || fwVersion.minor >=16; - // Check if we can decode the calldata - const { def: fetchedDef } = await SDK.Utils.fetchCalldataDecoder(tx.data, tx.to, chainId, supportsDecoderRecursion); - saveDefToCache(tx, this.requestCache, fetchedDef); - def = fetchedDef - } + const supportsDecoderRecursion = fwVersion.major > 0 || fwVersion.minor >=16; + // Check if we can decode the calldata + const { def } = await SDK.Utils.fetchCalldataDecoder(tx.data, tx.to, chainId, supportsDecoderRecursion); if (def) { data.decoder = def; } @@ -448,7 +429,6 @@ class LatticeKeyring extends EventEmitter { this.unlockedAccount = 0; this.network = null; this.hdPath = STANDARD_HD_PATH; - this.requestCache = new Map() } async _openConnectorTab(url) { @@ -731,7 +711,6 @@ class LatticeKeyring extends EventEmitter { } return activeWallet.uid.toString('hex'); } - } // ----- diff --git a/package-lock.json b/package-lock.json index 485c0e0..b669f3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "eth-lattice-keyring", - "version": "0.12.2", + "version": "0.12.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "eth-lattice-keyring", - "version": "0.12.2", + "version": "0.12.3", "license": "MIT", "dependencies": { "@ethereumjs/tx": "3.3.0", "@ethereumjs/util": "^8.0.0", "@noble/secp256k1": "^1.7.0", "bn.js": "^5.2.0", - "gridplus-sdk": "^2.2.7", + "gridplus-sdk": "^2.2.9", "rlp": "^3.0.0" } }, @@ -190,14 +190,6 @@ "version": "3.1.2", "license": "MIT" }, - "node_modules/asap": { - "version": "2.0.6", - "license": "MIT" - }, - "node_modules/asynckit": { - "version": "0.4.0", - "license": "MIT" - }, "node_modules/base-x": { "version": "3.0.9", "license": "MIT", @@ -320,17 +312,6 @@ "version": "1.0.3", "license": "MIT" }, - "node_modules/call-bind": { - "version": "1.0.2", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/cipher-base": { "version": "1.0.4", "license": "MIT", @@ -339,28 +320,10 @@ "safe-buffer": "^5.0.1" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "2.20.3", "license": "MIT" }, - "node_modules/component-emitter": { - "version": "1.3.0", - "license": "MIT" - }, - "node_modules/cookiejar": { - "version": "2.1.3", - "license": "MIT" - }, "node_modules/crc-32": { "version": "1.2.2", "license": "Apache-2.0", @@ -394,40 +357,10 @@ "sha.js": "^2.4.8" } }, - "node_modules/debug": { - "version": "4.3.4", - "license": "MIT", - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/delimit-stream": { "version": "0.1.0", "license": "BSD-2-Clause" }, - "node_modules/dezalgo": { - "version": "1.0.3", - "license": "ISC", - "dependencies": { - "asap": "^2.0.0", - "wrappy": "1" - } - }, "node_modules/elliptic": { "version": "6.5.4", "license": "MIT", @@ -542,65 +475,10 @@ "safe-buffer": "^5.1.1" } }, - "node_modules/fast-safe-stringify": { - "version": "2.1.1", - "license": "MIT" - }, - "node_modules/form-data": { - "version": "4.0.0", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/formidable": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "dezalgo": "1.0.3", - "hexoid": "1.0.0", - "once": "1.4.0", - "qs": "6.9.3" - }, - "funding": { - "url": "https://ko-fi.com/tunnckoCore/commissions" - } - }, - "node_modules/formidable/node_modules/qs": { - "version": "6.9.3", - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/function-bind": { - "version": "1.1.1", - "license": "MIT" - }, - "node_modules/get-intrinsic": { - "version": "1.1.2", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/gridplus-sdk": { - "version": "2.2.7", - "resolved": "https://registry.npmjs.org/gridplus-sdk/-/gridplus-sdk-2.2.7.tgz", - "integrity": "sha512-acpMxOkqubJRGcCRrYm1DA40utwIATjpWj/Wyismw16nAF3wGeQ79zUo5KwddtA+OYcwmqfPQMaAQ58qE0VpYg==", + "version": "2.2.9", + "resolved": "https://registry.npmjs.org/gridplus-sdk/-/gridplus-sdk-2.2.9.tgz", + "integrity": "sha512-U39YxeLisEJmw9KCtKCQB6C8UTVRKTonhDxwcDpN8T23VZuxk2SOzdmvq/HS01l5N+p1QEKKzQF6OCFQ7nVcYA==", "hasInstallScript": true, "dependencies": { "@ethereumjs/common": "2.4.0", @@ -618,28 +496,7 @@ "hash.js": "^1.1.7", "js-sha3": "^0.8.0", "rlp": "^3.0.0", - "secp256k1": "4.0.2", - "superagent": "^7.1.3" - } - }, - "node_modules/has": { - "version": "1.0.3", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/has-symbols": { - "version": "1.0.3", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "secp256k1": "4.0.2" } }, "node_modules/hash-base": { @@ -662,13 +519,6 @@ "minimalistic-assert": "^1.0.1" } }, - "node_modules/hexoid": { - "version": "1.0.0", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/hmac-drbg": { "version": "1.0.1", "license": "MIT", @@ -731,16 +581,6 @@ "node": ">=10.0.0" } }, - "node_modules/lru-cache": { - "version": "6.0.0", - "license": "ISC", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/md5.js": { "version": "1.3.5", "license": "MIT", @@ -750,40 +590,6 @@ "safe-buffer": "^5.1.2" } }, - "node_modules/methods": { - "version": "1.1.2", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime": { - "version": "2.6.0", - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/minimalistic-assert": { "version": "1.0.1", "license": "ISC" @@ -792,10 +598,6 @@ "version": "1.0.1", "license": "MIT" }, - "node_modules/ms": { - "version": "2.1.2", - "license": "MIT" - }, "node_modules/node-addon-api": { "version": "2.0.2", "license": "MIT" @@ -809,20 +611,6 @@ "node-gyp-build-test": "build-test.js" } }, - "node_modules/object-inspect": { - "version": "1.12.2", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/once": { - "version": "1.4.0", - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, "node_modules/pbkdf2": { "version": "3.1.2", "license": "MIT", @@ -837,19 +625,6 @@ "node": ">=0.12" } }, - "node_modules/qs": { - "version": "6.11.0", - "license": "BSD-3-Clause", - "dependencies": { - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/randombytes": { "version": "2.1.0", "license": "MIT", @@ -919,19 +694,6 @@ "node": ">=10.0.0" } }, - "node_modules/semver": { - "version": "7.3.7", - "license": "ISC", - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/setimmediate": { "version": "1.0.5", "license": "MIT" @@ -947,18 +709,6 @@ "sha.js": "bin.js" } }, - "node_modules/side-channel": { - "version": "1.0.4", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/string_decoder": { "version": "1.3.0", "license": "MIT", @@ -966,37 +716,9 @@ "safe-buffer": "~5.2.0" } }, - "node_modules/superagent": { - "version": "7.1.6", - "license": "MIT", - "dependencies": { - "component-emitter": "^1.3.0", - "cookiejar": "^2.1.3", - "debug": "^4.3.4", - "fast-safe-stringify": "^2.1.1", - "form-data": "^4.0.0", - "formidable": "^2.0.1", - "methods": "^1.1.2", - "mime": "2.6.0", - "qs": "^6.10.3", - "readable-stream": "^3.6.0", - "semver": "^7.3.7" - }, - "engines": { - "node": ">=6.4.0 <13 || >=14" - } - }, "node_modules/util-deprecate": { "version": "1.0.2", "license": "MIT" - }, - "node_modules/wrappy": { - "version": "1.0.2", - "license": "ISC" - }, - "node_modules/yallist": { - "version": "4.0.0", - "license": "ISC" } }, "dependencies": { @@ -1120,12 +842,6 @@ "aes-js": { "version": "3.1.2" }, - "asap": { - "version": "2.0.6" - }, - "asynckit": { - "version": "0.4.0" - }, "base-x": { "version": "3.0.9", "requires": { @@ -1200,13 +916,6 @@ "buffer-xor": { "version": "1.0.3" }, - "call-bind": { - "version": "1.0.2", - "requires": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" - } - }, "cipher-base": { "version": "1.0.4", "requires": { @@ -1214,21 +923,9 @@ "safe-buffer": "^5.0.1" } }, - "combined-stream": { - "version": "1.0.8", - "requires": { - "delayed-stream": "~1.0.0" - } - }, "commander": { "version": "2.20.3" }, - "component-emitter": { - "version": "1.3.0" - }, - "cookiejar": { - "version": "2.1.3" - }, "crc-32": { "version": "1.2.2" }, @@ -1253,25 +950,9 @@ "sha.js": "^2.4.8" } }, - "debug": { - "version": "4.3.4", - "requires": { - "ms": "2.1.2" - } - }, - "delayed-stream": { - "version": "1.0.0" - }, "delimit-stream": { "version": "0.1.0" }, - "dezalgo": { - "version": "1.0.3", - "requires": { - "asap": "^2.0.0", - "wrappy": "1" - } - }, "elliptic": { "version": "6.5.4", "requires": { @@ -1361,46 +1042,10 @@ "safe-buffer": "^5.1.1" } }, - "fast-safe-stringify": { - "version": "2.1.1" - }, - "form-data": { - "version": "4.0.0", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, - "formidable": { - "version": "2.0.1", - "requires": { - "dezalgo": "1.0.3", - "hexoid": "1.0.0", - "once": "1.4.0", - "qs": "6.9.3" - }, - "dependencies": { - "qs": { - "version": "6.9.3" - } - } - }, - "function-bind": { - "version": "1.1.1" - }, - "get-intrinsic": { - "version": "1.1.2", - "requires": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.3" - } - }, "gridplus-sdk": { - "version": "2.2.7", - "resolved": "https://registry.npmjs.org/gridplus-sdk/-/gridplus-sdk-2.2.7.tgz", - "integrity": "sha512-acpMxOkqubJRGcCRrYm1DA40utwIATjpWj/Wyismw16nAF3wGeQ79zUo5KwddtA+OYcwmqfPQMaAQ58qE0VpYg==", + "version": "2.2.9", + "resolved": "https://registry.npmjs.org/gridplus-sdk/-/gridplus-sdk-2.2.9.tgz", + "integrity": "sha512-U39YxeLisEJmw9KCtKCQB6C8UTVRKTonhDxwcDpN8T23VZuxk2SOzdmvq/HS01l5N+p1QEKKzQF6OCFQ7nVcYA==", "requires": { "@ethereumjs/common": "2.4.0", "@ethereumjs/tx": "3.3.0", @@ -1417,19 +1062,9 @@ "hash.js": "^1.1.7", "js-sha3": "^0.8.0", "rlp": "^3.0.0", - "secp256k1": "4.0.2", - "superagent": "^7.1.3" - } - }, - "has": { - "version": "1.0.3", - "requires": { - "function-bind": "^1.1.1" + "secp256k1": "4.0.2" } }, - "has-symbols": { - "version": "1.0.3" - }, "hash-base": { "version": "3.1.0", "requires": { @@ -1445,9 +1080,6 @@ "minimalistic-assert": "^1.0.1" } }, - "hexoid": { - "version": "1.0.0" - }, "hmac-drbg": { "version": "1.0.1", "requires": { @@ -1482,12 +1114,6 @@ "readable-stream": "^3.6.0" } }, - "lru-cache": { - "version": "6.0.0", - "requires": { - "yallist": "^4.0.0" - } - }, "md5.js": { "version": "1.3.5", "requires": { @@ -1496,45 +1122,18 @@ "safe-buffer": "^5.1.2" } }, - "methods": { - "version": "1.1.2" - }, - "mime": { - "version": "2.6.0" - }, - "mime-db": { - "version": "1.52.0" - }, - "mime-types": { - "version": "2.1.35", - "requires": { - "mime-db": "1.52.0" - } - }, "minimalistic-assert": { "version": "1.0.1" }, "minimalistic-crypto-utils": { "version": "1.0.1" }, - "ms": { - "version": "2.1.2" - }, "node-addon-api": { "version": "2.0.2" }, "node-gyp-build": { "version": "4.5.0" }, - "object-inspect": { - "version": "1.12.2" - }, - "once": { - "version": "1.4.0", - "requires": { - "wrappy": "1" - } - }, "pbkdf2": { "version": "3.1.2", "requires": { @@ -1545,12 +1144,6 @@ "sha.js": "^2.4.8" } }, - "qs": { - "version": "6.11.0", - "requires": { - "side-channel": "^1.0.4" - } - }, "randombytes": { "version": "2.1.0", "requires": { @@ -1589,12 +1182,6 @@ "node-gyp-build": "^4.2.0" } }, - "semver": { - "version": "7.3.7", - "requires": { - "lru-cache": "^6.0.0" - } - }, "setimmediate": { "version": "1.0.5" }, @@ -1605,44 +1192,14 @@ "safe-buffer": "^5.0.1" } }, - "side-channel": { - "version": "1.0.4", - "requires": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" - } - }, "string_decoder": { "version": "1.3.0", "requires": { "safe-buffer": "~5.2.0" } }, - "superagent": { - "version": "7.1.6", - "requires": { - "component-emitter": "^1.3.0", - "cookiejar": "^2.1.3", - "debug": "^4.3.4", - "fast-safe-stringify": "^2.1.1", - "form-data": "^4.0.0", - "formidable": "^2.0.1", - "methods": "^1.1.2", - "mime": "2.6.0", - "qs": "^6.10.3", - "readable-stream": "^3.6.0", - "semver": "^7.3.7" - } - }, "util-deprecate": { "version": "1.0.2" - }, - "wrappy": { - "version": "1.0.2" - }, - "yallist": { - "version": "4.0.0" } } } diff --git a/package.json b/package.json index 8317050..e49b45b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eth-lattice-keyring", - "version": "0.12.2", + "version": "0.12.3", "description": "Keyring for connecting to the Lattice1 hardware wallet", "main": "index.js", "scripts": { @@ -21,7 +21,7 @@ "bn.js": "^5.2.0", "@ethereumjs/util": "^8.0.0", "@noble/secp256k1": "^1.7.0", - "gridplus-sdk": "^2.2.7", + "gridplus-sdk": "^2.2.9", "rlp": "^3.0.0" } }