Page MenuHomePhabricator

D6130.id20538.diff
No OneTemporary

D6130.id20538.diff

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
@@ -47,6 +47,11 @@
return `Device IdPubKey: ${publicKey} ${siweStatement}`;
}
+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,
@@ -54,4 +59,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);
+ });
});

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 11, 5:21 AM (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2857565
Default Alt Text
D6130.id20538.diff (1 KB)

Event Timeline