diff --git a/packages/siwe-parser/lib/abnf.ts b/packages/siwe-parser/lib/abnf.ts index a7e5fcfa..34531d6e 100644 --- a/packages/siwe-parser/lib/abnf.ts +++ b/packages/siwe-parser/lib/abnf.ts @@ -175,7 +175,7 @@ export class ParsedMessage { requestId: string | null; resources: Array | null; - constructor(msg: string) { + constructor(msg: string, parserOptions = { validateEIP55Address: true }) { const parser = new apgLib.parser(); parser.ast = new apgLib.ast(); const id = apgLib.ids; @@ -359,7 +359,7 @@ export class ParsedMessage { throw new Error("Domain cannot be empty."); } - if (!isEIP55Address(this.address)) { + if (parserOptions.validateEIP55Address && !isEIP55Address(this.address)) { throw new Error("Address not conformant to EIP-55."); } } diff --git a/packages/siwe/lib/client.ts b/packages/siwe/lib/client.ts index bf3b9fac..61f86b26 100644 --- a/packages/siwe/lib/client.ts +++ b/packages/siwe/lib/client.ts @@ -10,6 +10,7 @@ import { getAddress, Provider, verifyMessage } from './ethersCompat'; import { SiweError, SiweErrorType, + SiweMessageConstructorOptions, SiweResponse, VerifyOpts, VerifyOptsKeys, @@ -61,15 +62,24 @@ export class SiweMessage { * expressed as RFC 3986 URIs separated by `\n- `. */ resources?: Array; + /** If the library should validate the address against EIP-55, defaults to true */ + validateEIP55Address = true; + /** * Creates a parsed Sign-In with Ethereum Message (EIP-4361) object from a * string or an object. If a string is used an ABNF parser is called to * validate the parameter, otherwise the fields are attributed. * @param param {string | SiweMessage} Sign message as a string or an object. */ - constructor(param: string | Partial) { + constructor(param: string | Partial, options?: SiweMessageConstructorOptions) { + if(options.validateEIP55Address !== undefined){ + this.validateEIP55Address = options.validateEIP55Address; + } + if (typeof param === 'string') { - const parsedMessage = new ParsedMessage(param); + const parsedMessage = new ParsedMessage(param, { + validateEIP55Address: this.validateEIP55Address + }); this.scheme = parsedMessage.scheme; this.domain = parsedMessage.domain; this.address = parsedMessage.address; @@ -426,7 +436,7 @@ export class SiweMessage { } /** EIP-55 `address` check. */ - if (!isEIP55Address(this.address)) { + if (this.validateEIP55Address && !isEIP55Address(this.address)) { throw new SiweError( SiweErrorType.INVALID_ADDRESS, getAddress(this.address), diff --git a/packages/siwe/lib/types.ts b/packages/siwe/lib/types.ts index df14e191..c3199cb6 100644 --- a/packages/siwe/lib/types.ts +++ b/packages/siwe/lib/types.ts @@ -121,3 +121,8 @@ export enum SiweErrorType { /** Thrown when some required field is missing. */ UNABLE_TO_PARSE = 'Unable to parse the message.', } + +export interface SiweMessageConstructorOptions { + /** If the library should validate the address against EIP-55, defaults to true */ + validateEIP55Address?: boolean +}