Page MenuHomePhabricator

D6125.id.diff
No OneTemporary

D6125.id.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
@@ -13,6 +13,11 @@
return ethereumAddressRegex.test(candidate);
}
+const primaryIdentityPublicKeyRegex: RegExp = /^[a-zA-Z0-9+/]{43}$/;
+function isValidPrimaryIdentityPublicKey(candidate: string): boolean {
+ return primaryIdentityPublicKeyRegex.test(candidate);
+}
+
const siweStatement: string =
'By continuing, I accept the Comm Terms of Service: https://comm.app/terms';
@@ -36,5 +41,6 @@
siweStatement,
isValidSIWENonce,
isValidEthereumAddress,
+ isValidPrimaryIdentityPublicKey,
isValidSIWEMessage,
};
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
@@ -1,6 +1,10 @@
// @flow
-import { isValidEthereumAddress, isValidSIWENonce } from './siwe-utils.js';
+import {
+ isValidEthereumAddress,
+ isValidPrimaryIdentityPublicKey,
+ isValidSIWENonce,
+} from './siwe-utils.js';
describe('SIWE Nonce utils', () => {
it('isValidSIWENonce should match valid nonces', () => {
@@ -153,4 +157,22 @@
const invalidAddress = 'e523fc253bcdea8373e030ee66e00c6864776d70';
expect(isValidEthereumAddress(invalidAddress)).toBe(false);
});
+
+ it(`isValidPrimaryIdentityPublicKey should succeed for valid ed25519 keys`, () => {
+ const validPublicKey = 'rPFzRtV7E6v1b60zjTvghqb2xgnggmn6j4UaYccJYdo';
+ expect(isValidPrimaryIdentityPublicKey(validPublicKey)).toBe(true);
+
+ const anotherValidPublicKey = '98+/eB2MUVvYCpkESOS1zuWnWttsYWDKeDXl8T3o8LY';
+ expect(isValidPrimaryIdentityPublicKey(anotherValidPublicKey)).toBe(true);
+ });
+
+ it(`isValidPrimaryIdentityPublicKey should fail for keys < 43 chars`, () => {
+ const shortPublicKey = 'rPFzRtV7E6v1b60zjTvghqb2xgnggmn6j4JYdo';
+ expect(isValidPrimaryIdentityPublicKey(shortPublicKey)).toBe(false);
+ });
+
+ it(`isValidPrimaryIdentityPublicKey should fail for keys > 43 chars`, () => {
+ const longPublicKey = '98+/eB2MUVvYCpkESOSWttsYWDKeDXl8TAAAAAAAAAA3o8LY';
+ expect(isValidPrimaryIdentityPublicKey(longPublicKey)).toBe(false);
+ });
});

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 12:51 AM (4 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2603028
Default Alt Text
D6125.id.diff (2 KB)

Event Timeline