diff --git a/src/encryption.ts b/src/encryption.ts index d825f914..6a0ed138 100644 --- a/src/encryption.ts +++ b/src/encryption.ts @@ -195,8 +195,13 @@ export function decrypt({ } return output; } catch (err) { - if (err && typeof err.message === 'string' && err.message.length) { - throw new Error(`Decryption failed: ${err.message as string}`); + const error = err as { message?: unknown } | null | undefined; + if ( + error && + typeof error.message === 'string' && + error.message.length + ) { + throw new Error(`Decryption failed: ${error.message}`); } throw new Error(`Decryption failed.`); } diff --git a/src/sign-typed-data.test.ts b/src/sign-typed-data.test.ts index a09feff5..f0b7f72b 100644 --- a/src/sign-typed-data.test.ts +++ b/src/sign-typed-data.test.ts @@ -242,7 +242,7 @@ const MAX_SAFE_INTEGER_PLUS_ONE_CHAR_AS_HEX = `0x${Number.MAX_SAFE_INTEGER.toStr even or odd number of characters */ -const encodeDataExamples = { +const encodeDataExamples: Record = { // dynamic types supported by EIP-712: bytes: [ 10, @@ -313,7 +313,10 @@ const encodeDataExamples = { // `function` type omitted because it is not supported by `ethereumjs-abi`. }; -const encodeDataErrorExamples = { +const encodeDataErrorExamples: Record< + string, + { input: unknown; errorMessage: string }[] +> = { address: [ { input: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB0', @@ -4304,7 +4307,7 @@ describe('TypedDataUtils.eip712Hash', function () { }); // Comments starting with "V1:" highlight differences relative to V3 and 4. -const signTypedDataV1Examples = { +const signTypedDataV1Examples: Record = { // dynamic types supported by EIP-712: bytes: [10, '10', '0x10', Buffer.from('10', 'utf8')], string: [ @@ -4357,7 +4360,10 @@ const signTypedDataV1Examples = { // `function` type omitted because it is not supported by `ethereumjs-abi`. }; -const signTypedDataV1ErrorExamples = { +const signTypedDataV1ErrorExamples: Record< + string, + { input: unknown; errorMessage: string }[] +> = { string: [ { // V1: Does not accept numbers as strings (arguably correctly). diff --git a/src/sign-typed-data.ts b/src/sign-typed-data.ts index 2350103d..c3b20b74 100644 --- a/src/sign-typed-data.ts +++ b/src/sign-typed-data.ts @@ -358,8 +358,8 @@ function encodeField( ); } const parsedType = type.slice(0, type.lastIndexOf('[')); - const typeValuePairs = value.map((item: any) => - encodeField(types, name, parsedType, item, version), + const typeValuePairs: ReturnType[] = value.map( + (item: any) => encodeField(types, name, parsedType, item, version), ); return [ 'bytes32', @@ -527,9 +527,12 @@ function sanitizeData( data: TypedMessage, ): TypedMessage { const sanitizedData: Partial> = {}; + const copyProperty = >(key: K) => { + sanitizedData[key] = data[key]; + }; for (const key in TYPED_MESSAGE_SCHEMA.properties) { - if (data[key]) { - sanitizedData[key] = data[key]; + if (data[key as keyof TypedMessage]) { + copyProperty(key as keyof TypedMessage); } } diff --git a/src/utils.ts b/src/utils.ts index 940b835c..fa1f5afb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -51,7 +51,7 @@ export function padWithZeroes(hexString: string, targetLength: number): string { * @param value - The value being checked. * @returns Whether the value is nullish. */ -export function isNullish(value) { +export function isNullish(value: unknown) { return value === null || value === undefined; } diff --git a/tsconfig.json b/tsconfig.json index acedad29..a205c7b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "outDir": "dist", "rootDir": "src", "sourceMap": true, - "strictNullChecks": true, + "strict": true, "target": "ES2017", "typeRoots": ["./node_modules/@types"] },