Skip to content

Commit c4af8fe

Browse files
committed
feat(hearbeat): Move submitter validation logic to it's own file
1 parent 3c804d2 commit c4af8fe

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

frontend/functions/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as functions from 'firebase-functions';
33
import * as blake2 from 'blake2';
44
import bs58check from 'bs58check';
55
import Client from 'mina-signer';
6+
import { submitterAllowed } from './submitterValidator';
67

78
interface SignatureJson {
89
field: string;
@@ -19,10 +20,6 @@ const minaClient = new Client({ network: 'testnet' });
1920

2021
admin.initializeApp();
2122

22-
// base58 encoded public keys that are allowed to submit data
23-
const allowedPublicKeys: Set<string> = new Set([
24-
]);
25-
2623
function validateSignature(
2724
data: string,
2825
signature: SignatureJson,
@@ -71,7 +68,7 @@ export const handleValidationAndStore = functions
7168
console.log('Received data:', data);
7269
const { publicKey, data: inputData, signature } = data;
7370

74-
if (!allowedPublicKeys.has(publicKey)) {
71+
if (!submitterAllowed(publicKey)) {
7572
throw new functions.https.HttpsError(
7673
'permission-denied',
7774
'Public key not authorized'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// base58 encoded public keys that are allowed to submit data
2+
const allowedPublicKeys: Set<string> = new Set([
3+
]);
4+
5+
export function submitterAllowed(publicKeyBase58: string): boolean {
6+
if (allowedPublicKeys.size === 0) {
7+
return true;
8+
}
9+
return allowedPublicKeys.has(publicKeyBase58);
10+
}

0 commit comments

Comments
 (0)