Skip to content

Commit

Permalink
feat: add netlify function to fetch attestor group public key
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Feb 18, 2025
1 parent 1d527ef commit 5b79051
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
42 changes: 42 additions & 0 deletions netlify/functions/fetch-extended-attestor-group-public-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Handler, HandlerEvent } from '@netlify/functions';
import { getAttestorExtendedGroupPublicKey } from 'dlc-btc-lib/attestor-request-functions';

const handler: Handler = async (event: HandlerEvent) => {
try {
if (!event.queryStringParameters) {
return {
statusCode: 400,
body: JSON.stringify({
message: 'No Parameters were provided',
}),
};
}

if (!event.queryStringParameters.coordinatorURL) {
return {
statusCode: 400,
body: JSON.stringify({
message: 'No Coordinator URL was provided',
}),
};
}

const coordinatorURL = event.queryStringParameters.coordinatorURL;

const attestorGroupPublicKey = await getAttestorExtendedGroupPublicKey(coordinatorURL);

return {
statusCode: 200,
body: attestorGroupPublicKey,
};
} catch (error: any) {
return {
statusCode: 500,
body: JSON.stringify({
message: `Failed to get Extended Attestor Group Public Key: ${error.message}`,
}),
};
}
};

export { handler };
16 changes: 16 additions & 0 deletions src/app/functions/netlify-fetch.functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function getExtendedAttestorGroupPublicKey(coordinatorURL: string): Promise<string> {
try {
const netlifyFunctionEndpoint = `/.netlify/functions/fetch-extended-attestor-group-public-key?coordinatorURL=${coordinatorURL}`;

const response = await fetch(netlifyFunctionEndpoint);

if (!response.ok) {
const errorMessage = await response.text();
throw new Error(`HTTP Error: ${errorMessage}`);
}

return await response.text();
} catch (error: any) {
throw new Error(`Failed to get Attestor Group Public Key: ${error.message}`);
}
}
4 changes: 2 additions & 2 deletions src/app/hooks/use-extended-attestor-group-public-key.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useContext } from 'react';

import { getExtendedAttestorGroupPublicKey } from '@functions/netlify-fetch.functions';
import { EthereumNetworkConfigurationContext } from '@providers/ethereum-network-configuration.provider';
import { NetworkConfigurationContext } from '@providers/network-configuration.provider';
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import { getAttestorExtendedGroupPublicKey } from 'dlc-btc-lib/attestor-request-functions';
import { getAttestorGroupPublicKey } from 'dlc-btc-lib/ethereum-functions';

import { NetworkType } from '@shared/constants/network.constants';
Expand All @@ -22,7 +22,7 @@ export function useExtendedAttestorGroupPublicKey(): UseQueryResult<string, Erro
};

const fetchXRPLExtendedAttestorGroupPublicKey = async (): Promise<string> => {
return await getAttestorExtendedGroupPublicKey(coordinatorURL);
return await getExtendedAttestorGroupPublicKey(coordinatorURL);
};

const fetchExtendedAttestorGroupPublicKey = async (): Promise<string> => {
Expand Down

0 comments on commit 5b79051

Please sign in to comment.