Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3753320
D6131.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D6131.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
@@ -52,6 +52,22 @@
return siweStatementWithPublicKeyRegex.test(candidate);
}
+const publicKeyFromSIWEStatementRegex: RegExp = /[a-zA-Z0-9+/]{43}/;
+function getPublicKeyFromSIWEStatement(statement: string): string {
+ invariant(
+ isValidSIWEStatementWithPublicKey(statement),
+ 'candidate must be well formed SIWE statement with public key',
+ );
+ const publicKeyMatchArray = statement.match(publicKeyFromSIWEStatementRegex);
+ invariant(
+ publicKeyMatchArray !== null &&
+ publicKeyMatchArray !== undefined &&
+ publicKeyMatchArray.length === 1,
+ 'publicKeyMatchArray should have one and only one element',
+ );
+ return publicKeyMatchArray[0];
+}
+
export {
siweStatement,
isValidSIWENonce,
@@ -60,4 +76,5 @@
isValidSIWEMessage,
getSIWEStatementForPublicKey,
isValidSIWEStatementWithPublicKey,
+ getPublicKeyFromSIWEStatement,
};
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,7 @@
// @flow
import {
+ getPublicKeyFromSIWEStatement,
getSIWEStatementForPublicKey,
isValidEthereumAddress,
isValidPrimaryIdentityPublicKey,
@@ -201,4 +202,14 @@
),
).toBe(true);
});
+
+ it(`getPublicKeyFromSIWEStatement should pull public key out of valid SIWE statement`, () => {
+ const validSIWEMessageStatement =
+ `Device IdPubKey: rPFzRtV7E6v1b60zjTvghqb2xgnggmn6j4UaYccJYdo ` +
+ `By continuing, I accept the Comm Terms of Service: https://comm.app/terms`;
+
+ expect(getPublicKeyFromSIWEStatement(validSIWEMessageStatement)).toBe(
+ 'rPFzRtV7E6v1b60zjTvghqb2xgnggmn6j4UaYccJYdo',
+ );
+ });
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 11, 1:46 AM (19 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2858222
Default Alt Text
D6131.diff (1 KB)
Attached To
Mode
D6131: [lib] Introduce `getPublicKeyFromSIWEStatement(...)`
Attached
Detach File
Event Timeline
Log In to Comment