Skip to content

Commit

Permalink
OG-770: Update to TypeScript 4 and update dependencies (opengsn#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat authored Apr 5, 2022
1 parent a01db9a commit 6b0c718
Show file tree
Hide file tree
Showing 40 changed files with 1,421 additions and 1,613 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
],
"nohoist": [
"**eslint**",
"**eth-sig-util**",
"**ts-node**"
]
},
Expand Down Expand Up @@ -80,7 +79,6 @@
"@typechain/truffle-v5": "^6.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.2.12",
"@types/eth-sig-util": "^2.1.0",
"@types/mocha": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
Expand All @@ -92,7 +90,7 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
"eth-sig-util": "2.5.2",
"eth-sig-util": "^3.0.1",
"ethereumjs-abi": "^0.6.8",
"ganache-cli": "^6.12.2",
"lerna": "^3.22.1",
Expand All @@ -102,7 +100,7 @@
"truffle": "5.1.26",
"ts-node": "8.6.2",
"typechain": "^6.0.5",
"typescript": "3.8.3",
"typescript": "^4.6.3",
"verdaccio": "^4.12.0",
"web3": "1.6.1",
"web3-core": "1.6.1",
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/CommandsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class CommandsLogic {
let isReady = false
try {
isReady = await this.isRelayReady(relayUrl)
} catch (e) {
} catch (e: any) {
console.log(e.message)
}
if (isReady) {
Expand Down Expand Up @@ -361,7 +361,7 @@ export class CommandsLogic {
try {
await relayHub.verifyRelayManagerStaked(relayAddress)
console.log('Relayer already authorized')
} catch (e) {
} catch (e: any) {
console.log('verifyRelayManagerStaked reverted with:', e.message)
console.log('Authorizing relayer for hub')
const authorizeTx = await stakeManager
Expand All @@ -375,7 +375,7 @@ export class CommandsLogic {
success: true,
transactions
}
} catch (error) {
} catch (error: any) {
return {
success: false,
transactions,
Expand Down Expand Up @@ -440,6 +440,7 @@ export class CommandsLogic {
console.log('Calling in view mode')
await this.contractInteractor.web3.eth.call({ ...web3TxData })
const txData = { ...web3TxData, gasLimit: web3TxData.gas }
// @ts-ignore
delete txData.gas
txToSign = new Transaction(txData, this.contractInteractor.getRawTxOptions())
} else {
Expand Down Expand Up @@ -479,7 +480,7 @@ export class CommandsLogic {
success: true,
transactions
}
} catch (e) {
} catch (e: any) {
return {
success: false,
transactions,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/GsnTestEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class GsnTestEnvironmentClass {
private async _resolveAvailablePort (): Promise<number> {
const server = net.createServer()
await new Promise(resolve => {
// @ts-ignore
server.listen(0, resolve)
})
const address = server.address()
Expand Down
3 changes: 1 addition & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
"@ethereumjs/tx": "^3.2.0",
"@opengsn/contracts": "^2.2.4",
"@types/bn.js": "^5.1.0",
"@types/eth-sig-util": "^2.1.0",
"@types/semver": "^7.3.4",
"@types/web3": "1.2.2",
"axios": "^0.21.1",
"bn.js": "^5.2.0",
"chalk": "^4.1.0",
"eth-sig-util": "2.5.2",
"eth-sig-util": "^3.0.1",
"ethereumjs-util": "^7.1.0",
"ethval": "^2.1.1",
"ow": "^0.17.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/ContractInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ export class ContractInteractor {
}))
relayEventParts.push(pastEvents)
break
} catch (e) {
} catch (e: any) {
/* eslint-disable */
this.logger.error(`error in getPastEvents.
fromBlock: ${fromBlock.toString()}
Expand All @@ -690,7 +690,7 @@ export class ContractInteractor {
}
}
break
} catch (e) {
} catch (e: any) {
// dynamically adjust query size fo some RPC providers
if (e.toString().match(/query returned more than/) != null) {
this.logger.warn(
Expand Down
36 changes: 27 additions & 9 deletions packages/common/src/EIP712/TypedRequestData.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import { Address } from '../types/Aliases'
import { RelayRequest } from './RelayRequest'
import { EIP712Domain, EIP712TypedData, EIP712TypeProperty, EIP712Types, TypedDataUtils } from 'eth-sig-util'

import { bufferToHex, PrefixedHexString } from 'ethereumjs-util'
import { TypedDataUtils, TypedMessage } from 'eth-sig-util'

export const EIP712DomainType: EIP712TypeProperty[] = [
export interface MessageTypeProperty {
name: string
type: string
}

export interface MessageTypes {
EIP712Domain: MessageTypeProperty[]

[additionalProperties: string]: MessageTypeProperty[]
}

export interface EIP712Domain {
name?: string
version?: string
chainId?: number
verifyingContract?: string
}

export const EIP712DomainType: MessageTypeProperty[] = [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' }
]

export const EIP712DomainTypeWithoutVersion: EIP712TypeProperty[] = [
export const EIP712DomainTypeWithoutVersion: MessageTypeProperty[] = [
{ name: 'name', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' }
Expand Down Expand Up @@ -44,10 +62,10 @@ const RelayRequestType = [
{ name: 'relayData', type: 'RelayData' }
]

interface Types extends EIP712Types {
EIP712Domain: EIP712TypeProperty[]
RelayRequest: EIP712TypeProperty[]
RelayData: EIP712TypeProperty[]
interface Types extends MessageTypes {
EIP712Domain: MessageTypeProperty[]
RelayRequest: MessageTypeProperty[]
RelayData: MessageTypeProperty[]
}

// use these values in registerDomainSeparator
Expand All @@ -57,7 +75,7 @@ export const GsnDomainSeparatorType = {
version: '2'
}

export function getDomainSeparator (verifier: Address, chainId: number): EIP712Domain {
export function getDomainSeparator (verifier: Address, chainId: number): Record<string, unknown> {
return {
name: GsnDomainSeparatorType.name,
version: GsnDomainSeparatorType.version,
Expand All @@ -70,7 +88,7 @@ export function getDomainSeparatorHash (verifier: Address, chainId: number): Pre
return bufferToHex(TypedDataUtils.hashStruct('EIP712Domain', getDomainSeparator(verifier, chainId), { EIP712Domain: EIP712DomainType }))
}

export class TypedRequestData implements EIP712TypedData {
export class TypedRequestData implements TypedMessage<Types> {
readonly types: Types
readonly domain: EIP712Domain
readonly primaryType: string
Expand Down
9 changes: 5 additions & 4 deletions packages/common/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import { Address } from './types/Aliases'

import chalk from 'chalk'
import { encode, List } from 'rlp'
import { EIP712TypedData } from 'eth-sig-util'
import { RelayRequest } from './EIP712/RelayRequest'
import { MessageTypes } from './EIP712/TypedRequestData'
import { TypedMessage } from 'eth-sig-util'

export function removeHexPrefix (hex: string): string {
if (hex == null || typeof hex.replace !== 'function') {
Expand Down Expand Up @@ -95,14 +96,14 @@ export async function getDefaultMethodSuffix (web3: Web3): Promise<string> {
return '_v4'
}

export async function getEip712Signature (
export async function getEip712Signature<T extends MessageTypes> (
web3: Web3,
typedRequestData: EIP712TypedData,
typedRequestData: TypedMessage<T>,
methodSuffix: string | null = null,
jsonStringifyRequest = false
): Promise<PrefixedHexString> {
const senderAddress = typedRequestData.message.from
let dataToSign: EIP712TypedData | string
let dataToSign: TypedMessage<T> | string
if (jsonStringifyRequest) {
dataToSign = JSON.stringify(typedRequestData)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/statistics/StatisticsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class StatisticsManager {
try {
const pingResponse = await this.httpClient.getPingResponse(url)
relayPing = { pingResponse }
} catch (error) {
} catch (error: any) {
relayPing = { error }
}
return relayPing
Expand Down
3 changes: 1 addition & 2 deletions packages/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
"@nomiclabs/hardhat-truffle5": "^2.0.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@types/chai-as-promised": "^7.1.3",
"@types/eth-sig-util": "^2.1.0",
"@types/sinon": "^9.0.10",
"@types/sinon-chai": "^3.2.5",
"abi-decoder": "^2.3.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eth-sig-util": "2.5.2",
"eth-sig-util": "^3.0.1",
"ethereumjs-util": "^7.1.0",
"hardhat": "^2.6.8",
"sinon": "^9.2.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/dev/test/Flows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ options.forEach(params => {
try {
const gas = await sr.contract.methods.emitMessage('hello').estimateGas()
res = await sr.emitMessage('hello', { from: from, gas })
} catch (e) {
} catch (e: any) {
console.log('error is ', e.message)
throw e
}
Expand All @@ -165,7 +165,7 @@ options.forEach(params => {
await fixTxDetails(txDetails, relayProvider)
const res = await sr.emitMessage('hello, from gasless', txDetails)
console.log('res after gasless emit:', res.logs[0].args.message)
} catch (e) {
} catch (e: any) {
ex = e
}

Expand Down Expand Up @@ -211,7 +211,7 @@ options.forEach(params => {
const txDetails: any = { from, gas }
await fixTxDetails(txDetails, relayProvider)
res = await sr.emitMessageNoParams(txDetails)
} catch (e) {
} catch (e: any) {
console.log('error is ', e.message)
throw e
}
Expand Down Expand Up @@ -267,7 +267,7 @@ options.forEach(params => {
}
await fixTxDetails(txDetails, relayProvider)
await sr.emitMessage('xxx', txDetails)
} catch (e) {
} catch (e: any) {
console.log('error1: ', e)
throw e
} finally {
Expand Down Expand Up @@ -307,7 +307,7 @@ options.forEach(params => {
await fixTxDetails(txDetails, relayProvider)
await sr.emitMessage('xxx', txDetails)
}, 'unexpected approvalData: \'\' instead of')
} catch (e) {
} catch (e: any) {
console.log('error3: ', e)
throw e
} finally {
Expand Down Expand Up @@ -338,7 +338,7 @@ options.forEach(params => {
let ex: Error | undefined
try {
await asyncFunc()
} catch (e) {
} catch (e: any) {
ex = e
}
assert.ok(ex != null, `Expected to throw ${msg} but threw nothing`)
Expand Down
1 change: 1 addition & 0 deletions packages/dev/test/GasPriceFetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ context('GasPriceFetcher', function () {
res.send(mockOracleResponse)
})
await new Promise((resolve) => {
// @ts-ignore
server = mockServer.listen(0, resolve)
})
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Expand Down
1 change: 1 addition & 0 deletions packages/dev/test/KeyManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function cleanFolder (): void {
fs.unlinkSync(keyStoreFilePath)
}
if (fs.existsSync(workdir)) {
// @ts-ignore
fs.rmSync(workdir, {
recursive: true,
force: true
Expand Down
Loading

0 comments on commit 6b0c718

Please sign in to comment.