diff --git a/lib/utils/siwe-utils.js b/lib/utils/siwe-utils.js --- a/lib/utils/siwe-utils.js +++ b/lib/utils/siwe-utils.js @@ -50,6 +50,11 @@ ); } +const siweStatementWithPublicKeyRegex = /^Device IdPubKey: [a-zA-Z0-9+/]{43} By continuing, I accept the Comm Terms of Service: https:\/\/comm.app\/terms$/; +function isValidSIWEStatementWithPublicKey(candidate: string): boolean { + return siweStatementWithPublicKeyRegex.test(candidate); +} + export { siweStatement, isValidSIWENonce, @@ -57,4 +62,5 @@ isValidPrimaryIdentityPublicKey, isValidSIWEMessage, getSIWEStatementForPublicKey, + isValidSIWEStatementWithPublicKey, }; diff --git a/lib/utils/siwe-utils.test.js b/lib/utils/siwe-utils.test.js --- a/lib/utils/siwe-utils.test.js +++ b/lib/utils/siwe-utils.test.js @@ -5,6 +5,7 @@ isValidEthereumAddress, isValidPrimaryIdentityPublicKey, isValidSIWENonce, + isValidSIWEStatementWithPublicKey, } from './siwe-utils.js'; describe('SIWE Nonce utils', () => { @@ -186,4 +187,18 @@ getSIWEStatementForPublicKey(validPublicKey) === expectedString, ).toBe(true); }); + + it(`isValidSIWEStatementWithPublicKey should be true for well formed SIWE statement`, () => { + const validPublicKey = 'rPFzRtV7E6v1b60zjTvghqb2xgnggmn6j4UaYccJYdo'; + const expectedString = + `Device IdPubKey: rPFzRtV7E6v1b60zjTvghqb2xgnggmn6j4UaYccJYdo ` + + `By continuing, I accept the Comm Terms of Service: https://comm.app/terms`; + + expect(isValidSIWEStatementWithPublicKey(expectedString)).toBe(true); + expect( + isValidSIWEStatementWithPublicKey( + getSIWEStatementForPublicKey(validPublicKey), + ), + ).toBe(true); + }); });