Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3393820
D6125.id20474.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6125.id20474.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 4:03 PM (20 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2603028
Default Alt Text
D6125.id20474.diff (2 KB)
Attached To
Mode
D6125: [lib] Introduce `isValidPrimaryIdentityPublicKey`
Attached
Detach File
Event Timeline
Log In to Comment