Skip to content

Commit

Permalink
fix: ethers-providers-type-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed Apr 12, 2024
1 parent b6fbd05 commit 5439afc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/siwe/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
ParsedMessage,
parseIntegerNumber,
} from '@spruceid/siwe-parser';
// @ts-expect-error -- ethers v6 compatibility hack
import { providers } from 'ethers';
import * as uri from 'valid-url';

import { getAddress, verifyMessage } from './ethersCompat';
import { getAddress, Provider, verifyMessage } from './ethersCompat';
import {
SiweError,
SiweErrorType,
Expand Down Expand Up @@ -194,7 +192,7 @@ export class SiweMessage {
* @param signature Signature to match the address in the message.
* @param provider Ethers provider to be used for EIP-1271 validation
*/
async validate(signature: string, provider?: providers.Provider) {
async validate(signature: string, provider?: Provider) {
console.warn(
'validate() has been deprecated, please update your code to use verify(). validate() may be removed in future versions.'
);
Expand Down
5 changes: 5 additions & 0 deletions packages/siwe/lib/ethersCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ try {
ethersGetAddress = ethers.getAddress as (address: string) => string;
}

// @ts-expect-error -- v6 compatibility hack
type ProviderV5 = ethers.providers.Provider
type ProviderV6 = ethers.Provider

export type Provider = ProviderV6 extends undefined ? ProviderV5 : ProviderV6
export const verifyMessage = ethersVerifyMessage;
export const hashMessage = ethersHashMessage;
export const getAddress = ethersGetAddress;

0 comments on commit 5439afc

Please sign in to comment.