Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "refactor: using only viem for EIP712" (#1547)" #1615

Closed
wants to merge 1 commit into from
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
197 changes: 116 additions & 81 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import localRules from "eslint-plugin-local-rules";
import sonarjs from "eslint-plugin-sonarjs";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import localRules from 'eslint-plugin-local-rules';
import sonarjs from 'eslint-plugin-sonarjs';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand All @@ -16,85 +16,120 @@ const compat = new FlatCompat({
allConfig: js.configs.all
});

export default [{
ignores: ["**/node_modules/", "**/dist/", "**/coverage/", "**/coverageUnit/", "**/jest.config.*", "**/eslint.config.mjs", "**/jest.browser-setup.js"],
}, ...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended",
"standard-with-typescript",
"prettier",
"plugin:sonarjs/recommended-legacy",
"plugin:security/recommended-legacy",
), {
files: ["**/src/**/*.ts", "**/tests/**/*.ts"],
plugins: {
"@typescript-eslint": typescriptEslint,
"local-rules": localRules,
sonarjs,
export default [
{
ignores: [
'**/node_modules/',
'**/dist/',
'**/coverage/',
'**/coverageUnit/',
'**/jest.config.*',
'**/eslint.config.mjs',
'**/jest.browser-setup.js',
'**/coverageIntegration/**', // Add this line
'**/lcov-report/**', // Add this line
'**/*.js', // Add this to ignore all JS files if needed
]
},

languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended',
'standard-with-typescript',
'prettier',
'plugin:sonarjs/recommended-legacy',
'plugin:security/recommended-legacy'
),
{
files: ['**/src/**/*.ts', '**/tests/**/*.ts'],
plugins: {
'@typescript-eslint': typescriptEslint,
'local-rules': localRules,
sonarjs
},

parser: tsParser,
ecmaVersion: "latest",
sourceType: "script",
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs
},

parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'script',

parserOptions: {
project: "./tsconfig.json",
parserOptions: {
project: './tsconfig.json'
}
},
},

rules: {
"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
}],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_'
}
],

"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/non-nullable-type-assertion-style": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-throw-literal": "off",
"@typescript-eslint/lines-between-class-members": "off",
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/lines-between-class-members': 'off',

"prettier/prettier": ["error", {
singleQuote: true,
trailingComma: "none",
tabWidth: 4,
}],
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'none',
tabWidth: 4
}
],

"no-warning-comments": "warn",
"no-multi-str": "off",
"local-rules/disallow-buffer-from-alloc": "error",
"local-rules/disallow-instanceof-uint8array": "error",
"sonarjs/different-types-comparison": "off",
"sonarjs/no-ignored-exceptions": "off",
"sonarjs/no-nested-functions": "off",
"sonarjs/function-return-type": "off",
"sonarjs/no-nested-conditional": "off",
"sonarjs/cognitive-complexity": "off",
"sonarjs/new-cap": "off",
"security/detect-object-injection": "off",
"security/detect-unsafe-regex": "off",
"security/detect-non-literal-fs-filename": "off",
"sonarjs/sonar-no-unused-vars": "off",
"sonarjs/sonar-no-fallthrough": "off",
"import/no-extraneous-dependencies": ["error", {"devDependencies": false, "optionalDependencies": false, "peerDependencies": false}]
}
}, {
files: ["**/tests/**/*.ts"],
rules: {
"import/no-extraneous-dependencies": "off",
'no-warning-comments': 'warn',
'no-multi-str': 'off',
'local-rules/disallow-buffer-from-alloc': 'error',
'local-rules/disallow-instanceof-uint8array': 'error',
'sonarjs/different-types-comparison': 'off',
'sonarjs/no-ignored-exceptions': 'off',
'sonarjs/no-nested-functions': 'off',
'sonarjs/function-return-type': 'off',
'sonarjs/no-nested-conditional': 'off',
'sonarjs/cognitive-complexity': 'off',
'sonarjs/new-cap': 'off',
'security/detect-object-injection': 'off',
'security/detect-unsafe-regex': 'off',
'security/detect-non-literal-fs-filename': 'off',
'sonarjs/sonar-no-unused-vars': 'off',
'sonarjs/sonar-no-fallthrough': 'off',
'sonarjs/no-empty-function': [
'error',
{
allow: ['arrowFunctions', 'functions', 'methods']
}
],
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: false,
optionalDependencies: false,
peerDependencies: false
}
]
}
},
{
files: ['**/tests/**/*.ts'],
rules: {
'import/no-extraneous-dependencies': 'off'
}
}
}];
];
3 changes: 1 addition & 2 deletions packages/aws-kms-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@vechain/sdk-errors": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5",
"asn1js": "^3.0.5",
"ethers": "6.13.4",
"viem": "^2.21.54"
"viem": "^2.21.45"
}
}
18 changes: 10 additions & 8 deletions packages/aws-kms-adapter/src/KMSVeChainSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
} from '@vechain/sdk-network';
import { BitString, ObjectIdentifier, Sequence, verifySchema } from 'asn1js';
import {
hashTypedData,
recoverPublicKey,
toHex,
type TypedDataDomain,
TypedDataEncoder,
type TypedDataField
} from 'ethers';
import { recoverPublicKey, toHex } from 'viem';
type TypedDataParameter
} from 'viem';
import { KMSVeChainProvider } from './KMSVeChainProvider';

class KMSVeChainSigner extends VeChainAbstractSigner {
Expand Down Expand Up @@ -388,20 +389,21 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
*/
public async signTypedData(
domain: TypedDataDomain,
types: Record<string, TypedDataField[]>,
value: Record<string, unknown>
types: Record<string, TypedDataParameter[]>,
primaryType: string,
message: Record<string, unknown>
): Promise<string> {
try {
const payload = Hex.of(
TypedDataEncoder.hash(domain, types, value)
hashTypedData({ domain, types, primaryType, message })
).bytes;

return await this.signPayload(payload);
} catch (error) {
throw new SignerMethodError(
'KMSVeChainSigner.signTypedData',
'The typed data could not be signed.',
{ domain, types, value },
{ domain, types, primaryType, message },
error
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ describe('KMSVeChainSigner - Thor Solo', () => {
const signature = await signer.signTypedData(
typedData.domain,
typedData.types,
typedData.primaryType,
typedData.data
);
expect(signature).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type ThorClient,
type TransactionRequestInput
} from '@vechain/sdk-network';
import { type TypedDataDomain, type TypedDataField } from 'ethers';
import { type TypedDataDomain, type TypedDataParameter } from 'viem';
import { KMSVeChainProvider, KMSVeChainSigner } from '../src';
import { EIP712_CONTRACT, EIP712_FROM, EIP712_TO } from './fixture';
jest.mock('asn1js', () => ({
Expand Down Expand Up @@ -136,6 +136,7 @@ describe('KMSVeChainSigner', () => {
}
]
},
'Mail',
{
from: {
name: 'Cow',
Expand All @@ -159,7 +160,8 @@ describe('KMSVeChainSigner', () => {
await expect(
signer.signTypedData(
{} as unknown as TypedDataDomain,
{} as unknown as Record<string, TypedDataField[]>,
{} as unknown as Record<string, TypedDataParameter[]>,
'primaryType',
{} as unknown as Record<string, unknown>
)
).rejects.toThrow(SignerMethodError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
JSONRPCInvalidParams,
stringifyData
} from '@vechain/sdk-errors';
import type { TypedDataDomain, TypedDataField } from 'ethers';
import type { TypedDataDomain, TypedDataParameter } from 'viem';
import type { VeChainSigner } from '../../../../../signer/signers';
import type { ThorClient } from '../../../../../thor-client';
import type { VeChainProvider } from '../../../../providers/vechain-provider';
Expand Down Expand Up @@ -61,7 +61,7 @@ const ethSignTypedDataV4 = async (
{
primaryType: string;
domain: TypedDataDomain;
types: Record<string, TypedDataField[]>;
types: Record<string, TypedDataParameter[]>;
message: Record<string, unknown>;
}
];
Expand All @@ -74,6 +74,7 @@ const ethSignTypedDataV4 = async (
return await signer.signTypedData(
typedData.domain,
typedData.types,
typedData.primaryType,
typedData.message
);
} catch (error) {
Expand Down
8 changes: 5 additions & 3 deletions packages/network/src/signer/signers/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type HardhatVeChainProvider,
type VeChainProvider
} from '../../provider';
import { type TypedDataDomain, type TypedDataParameter } from 'viem';

/**
* Available types for the VeChainProvider's
Expand Down Expand Up @@ -368,9 +369,10 @@ interface VeChainSigner {
* Signs the [[link-eip-712]] typed data.
*/
signTypedData: (
domain: vechain_sdk_core_ethers.TypedDataDomain,
types: Record<string, vechain_sdk_core_ethers.TypedDataField[]>,
value: Record<string, unknown>,
domain: TypedDataDomain,
types: Record<string, TypedDataParameter[]>,
primaryType: string,
message: Record<string, unknown>,
options?: SignTypedDataOptions
) => Promise<string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type TransactionClause
} from '@vechain/sdk-core';
import { InvalidDataType, JSONRPCInvalidParams } from '@vechain/sdk-errors';
import { type TypedDataDomain, type TypedDataField } from 'ethers';
import { type TypedDataDomain, type TypedDataParameter } from 'viem';
import { RPC_METHODS } from '../../../provider/utils/const/rpc-mapper/rpc-methods';
import { type TransactionSimulationResult } from '../../../thor-client';
import { vnsUtils } from '../../../utils';
Expand Down Expand Up @@ -336,15 +336,17 @@ abstract class VeChainAbstractSigner implements VeChainSigner {
* Signs the [[link-eip-712]] typed data.
*
* @param {TypedDataDomain} domain - The domain parameters used for signing.
* @param {Record<string, TypedDataField[]>} types - The types used for signing.
* @param {Record<string, unknown>} value - The message data to be signed.
* @param {Record<string, TypedDataParameter[]>} types - The types used for signing.
* @param {string} primaryType - The primary type used for signing.
* @param {Record<string, unknown>} message - The message data to be signed.
*
* @return {Promise<string>} - A promise that resolves with the signature string.
*/
abstract signTypedData(
domain: TypedDataDomain,
types: Record<string, TypedDataField[]>,
value: Record<string, unknown>,
types: Record<string, TypedDataParameter[]>,
primaryType: string,
message: Record<string, unknown>,
options?: SignTypedDataOptions
): Promise<string>;

Expand Down
Loading
Loading