-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add netlify function to fetch attestor group public key
- Loading branch information
1 parent
1d527ef
commit 5b79051
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
netlify/functions/fetch-extended-attestor-group-public-key.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters