Skip to content

Commit

Permalink
Merge pull request #335 from GridPlus/dev
Browse files Browse the repository at this point in the history
v1.1.4
  • Loading branch information
alex-miller-0 authored Mar 22, 2022
2 parents fd3b675 + b69d2bd commit 4589295
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
43 changes: 27 additions & 16 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
// -----
Expand Down Expand Up @@ -409,6 +416,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 &&
Expand All @@ -424,7 +434,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 = {
Expand Down Expand Up @@ -1105,7 +1116,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.
Expand Down
6 changes: 5 additions & 1 deletion src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4589295

Please sign in to comment.