Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand Down
14 changes: 10 additions & 4 deletions src/sign-typed-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown[]> = {
// dynamic types supported by EIP-712:
bytes: [
10,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -4304,7 +4307,7 @@ describe('TypedDataUtils.eip712Hash', function () {
});

// Comments starting with "V1:" highlight differences relative to V3 and 4.
const signTypedDataV1Examples = {
const signTypedDataV1Examples: Record<string, unknown[]> = {
// dynamic types supported by EIP-712:
bytes: [10, '10', '0x10', Buffer.from('10', 'utf8')],
string: [
Expand Down Expand Up @@ -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).
Expand Down
11 changes: 7 additions & 4 deletions src/sign-typed-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof encodeField>[] = value.map(
(item: any) => encodeField(types, name, parsedType, item, version),
);
return [
'bytes32',
Expand Down Expand Up @@ -527,9 +527,12 @@ function sanitizeData<T extends MessageTypes>(
data: TypedMessage<T>,
): TypedMessage<T> {
const sanitizedData: Partial<TypedMessage<T>> = {};
const copyProperty = <K extends keyof TypedMessage<T>>(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<T>]) {
copyProperty(key as keyof TypedMessage<T>);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"strictNullChecks": true,
"strict": true,
"target": "ES2017",
"typeRoots": ["./node_modules/@types"]
},
Expand Down