From cd85833f10aacec21dc515e3c08860b812dbf4b8 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 21 Mar 2022 19:59:04 -0500 Subject: [PATCH 1/4] Fixes @ethereumjs/common instantiation For custom chains we need to use this syntax. --- package-lock.json | 4 ++-- package.json | 2 +- src/ethereum.ts | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8123f4f..707633ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gridplus-sdk", - "version": "1.1.3", + "version": "1.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gridplus-sdk", - "version": "1.1.3", + "version": "1.1.4", "license": "MIT", "dependencies": { "@ethereumjs/common": "^2.6.2", diff --git a/package.json b/package.json index bf2098c0..035f63cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gridplus-sdk", - "version": "1.1.3", + "version": "1.1.4", "description": "SDK to interact with GridPlus Lattice1 device", "scripts": { "build": "tsc -p tsconfig.json", diff --git a/src/ethereum.ts b/src/ethereum.ts index 19a652bb..160151b8 100644 --- a/src/ethereum.ts +++ b/src/ethereum.ts @@ -934,7 +934,11 @@ const ethConvertLegacyToGenericReq = function(req) { if (!req.chainId || ensureHexBuffer(req.chainId).toString('hex') === '01') { common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai }); } else { - common = Common.custom({ chainId: req.chainId }); + // Not every network will support EIP1559 but we will allow it here. + common = Common.custom( + { chainId: req.chainId }, + { hardfork: Hardfork.Shanghai, eips: [1559]} + ); } // Newer transaction types if (req.type === 1) { From d8fb27df2370c39ff81a42e37f0be2ee3c8a301d Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 22 Mar 2022 10:24:20 -0500 Subject: [PATCH 2/4] Changes `startPath` -> `signerPath` for `sign` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 978d73aa..89192d6d 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ General signing allows you to request a signature on any message from a private ``` const msg = "I am the message to sign" const req = { - startPath: [ + signerPath: [ 0x80000000 + 44, 0x80000000 + 60, 0x80000000, @@ -274,7 +274,7 @@ If you do not wish to specify a decoder, you can leave this field empty and the ``` const msg = solTx.compileMessage().serialize() const req = { - startPath: [ // Derivation path of the first requested pubkey + signerPath: [ // Derivation path of the first requested pubkey 0x80000000 + 44, 0x80000000 + 60, 0x80000000, From 9a420eaf10b61aeb7f97cb5ed18529b77817b2b8 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 22 Mar 2022 17:42:34 -0500 Subject: [PATCH 3/4] Adds option to skip wrong wallet retries Also adds ClientOpts type --- src/client.ts | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/client.ts b/src/client.ts index ccced975..3c377fc5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -73,6 +73,7 @@ export class Client { private privKey: Buffer; private retryCount: number; private fwVersion: Buffer; + private skipRetryOnWrongWallet: boolean; /** Temporary secret that is generated by the Lattice device */ private ephemeralPub: KeyPair; @@ -105,20 +106,25 @@ export class Client { /** * @param params - Parameters are passed as an object. */ - constructor({ baseUrl, name, privKey, stateData, timeout, retryCount }: { - /** The base URL of the signing server. */ - baseUrl?: string; - /** The name of the client. */ - name?: string; - /** The private key of the client.*/ - privKey?: Buffer; - /** Number of times to retry a request if it fails. */ - retryCount?: number; - /** The time to wait for a response before cancelling. */ - timeout?: number; - /** User can pass in previous state data to rehydrate connected session */ - stateData?: string; - }) { + constructor({ + baseUrl, name, privKey, stateData, timeout, retryCount, skipRetryOnWrongWallet + }: { + /** The base URL of the signing server. */ + baseUrl?: string; + /** The name of the client. */ + name?: string; + /** The private key of the client.*/ + privKey?: Buffer; + /** Number of times to retry a request if it fails. */ + retryCount?: number; + /** The time to wait for a response before cancelling. */ + timeout?: number; + /** User can pass in previous state data to rehydrate connected session */ + stateData?: string; + /** If true we will not retry if we get a wrong wallet error code */ + skipRetryOnWrongWallet: boolean; + } + ) { // Default state params // ----- this.ephemeralPub = null; @@ -138,6 +144,7 @@ export class Client { external: true, }, }; + this.skipRetryOnWrongWallet = skipRetryOnWrongWallet || false; // The user may pass in state data to rehydrate a session that was previously cached // ----- @@ -1105,7 +1112,7 @@ export class Client { } this._request(payload, encReqCode, cb, retryCount - 1); }); - } else if (canRetry && wrongWallet) { + } else if (canRetry && wrongWallet && !this.skipRetryOnWrongWallet) { // Incorrect wallet being requested. Clear wallet state. this._resetActiveWallets(); // Refetch the active wallet. From fbe1ef488b882dd09a6716c03524f83c136071e4 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Tue, 22 Mar 2022 17:48:11 -0500 Subject: [PATCH 4/4] Fixes ETH v2 bridge language Closes #338 --- src/client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index ccced975..f046c017 100644 --- a/src/client.ts +++ b/src/client.ts @@ -409,6 +409,9 @@ export class Client { // In v0.15.0 Lattice firmware removed the legacy ETH signing path, so // we need to convert such requests to general signing requests using // the EVM decoder. + // NOTE: Not every request can be converted, so users should switch + // to using general signing requests for newer firmware versions. + // EIP1559 and EIP155 legacy requests will convert, but others may not. const useEVMDecoder = ( fwConstants.genericSigning && fwConstants.genericSigning.encodingTypes && @@ -424,7 +427,8 @@ export class Client { payload = ethereum.ethConvertLegacyToGenericReq(data); } catch (err) { return cb( - `Please update Lattice firmware. Request failed. ${err.message}` + 'Could not convert legacy request. Please switch to a general signing ' + + 'request. See gridplus-sdk docs for more information.' ); } data = {