From 25c5d6c3ed6b1112086fd6395cd9982ad8b7002d Mon Sep 17 00:00:00 2001 From: Sergey Ukustov Date: Wed, 2 Aug 2023 15:45:53 +0300 Subject: [PATCH] chore(blockchain-utils-validation): Make TS strict --- .../blockchain-utils-linking/src/filecoin.ts | 14 +------------ .../src/blockchains/ethereum.ts | 2 +- .../blockchain-utils-validation/tsconfig.json | 10 ++++++++- .../@smontero__eosio-signing-tools/index.d.ts | 12 +++++++++++ .../index.d.ts | 21 +++++++++++++++++++ 5 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 types/@smontero__eosio-signing-tools/index.d.ts create mode 100644 types/@zondax__filecoin-signing-tools/index.d.ts diff --git a/packages/blockchain-utils-linking/src/filecoin.ts b/packages/blockchain-utils-linking/src/filecoin.ts index 7c0310e00c..fc84908722 100644 --- a/packages/blockchain-utils-linking/src/filecoin.ts +++ b/packages/blockchain-utils-linking/src/filecoin.ts @@ -2,19 +2,7 @@ import { AuthProvider } from './auth-provider.js' import { AccountId } from 'caip' import { asOldCaipString, getConsentMessage, LinkProof } from './util.js' import * as uint8arrays from 'uint8arrays' - -type MessageParams = { - From: string - To: string - Value: '0' - Method: 0 - GasPrice: '1' - GasLimit: 1000 - Nonce: 0 - Params: string - GasFeeCap: string - GasPremium: string -} +import type { MessageParams } from '@zondax/filecoin-signing-tools' export class FilecoinAuthProvider implements AuthProvider { readonly isAuthProvider = true diff --git a/packages/blockchain-utils-validation/src/blockchains/ethereum.ts b/packages/blockchain-utils-validation/src/blockchains/ethereum.ts index f32fabcfa2..24c40f0030 100644 --- a/packages/blockchain-utils-validation/src/blockchains/ethereum.ts +++ b/packages/blockchain-utils-validation/src/blockchains/ethereum.ts @@ -60,7 +60,7 @@ async function validateErc1271Link(proof: LinkProof): Promise const provider = getEthersProvider(account.chainId.reference) const contract = new Contract(account.address, ERC1271_ABI, provider) const message = utf8toHex(proof.message) - const returnValue = await contract.isValidSignature(message, proof.signature) + const returnValue = await contract['isValidSignature'](message, proof.signature) return returnValue === MAGIC_ERC1271_VALUE ? proof : null } diff --git a/packages/blockchain-utils-validation/tsconfig.json b/packages/blockchain-utils-validation/tsconfig.json index 99b66b38e1..374e82f0f8 100644 --- a/packages/blockchain-utils-validation/tsconfig.json +++ b/packages/blockchain-utils-validation/tsconfig.json @@ -2,7 +2,15 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "lib", - "rootDir": "src" + "rootDir": "src", + "strict": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true }, "include": [ "./src/**/*" diff --git a/types/@smontero__eosio-signing-tools/index.d.ts b/types/@smontero__eosio-signing-tools/index.d.ts new file mode 100644 index 0000000000..8a514e5db4 --- /dev/null +++ b/types/@smontero__eosio-signing-tools/index.d.ts @@ -0,0 +1,12 @@ +declare module '@smontero/eosio-signing-tools' { + type VerifySignatureArgs = { + chainId: string + account: string + signature: string + data: string + } + + export class SigningTools { + static verifySignature(args: VerifySignatureArgs): Promise + } +} diff --git a/types/@zondax__filecoin-signing-tools/index.d.ts b/types/@zondax__filecoin-signing-tools/index.d.ts new file mode 100644 index 0000000000..78b4687d7c --- /dev/null +++ b/types/@zondax__filecoin-signing-tools/index.d.ts @@ -0,0 +1,21 @@ +/// +declare module '@zondax/filecoin-signing-tools' { + export type MessageParams = { + From: string + To: string + Value: string + Method: 0 + GasPrice: string + GasLimit: 1000 + Nonce: 0 + Params: string + GasFeeCap: string + GasPremium: string + } + + export function transactionSerialize(message: MessageParams): string + export function verifySignature( + signature: string | Buffer, + message: MessageParams | string + ): boolean +}