Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update secret manager #123

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/secretManager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
export interface SecretManager {
getSeedPhrase(): Promise<string>
}
// for types - see original
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
export const getSecretManager = () => {
const client = new SecretsManagerClient({
region: 'ap-southeast-1',
})

export const getSecretManager = (): SecretManager => {
return {
getSeedPhrase: async () => {
const seed = process.env.SEED
if (!seed)
throw Error(
'Failed to find SEED environment variable. Add your seed phrase to the SEED environment variable or implement a secret manager instance',
getSeedPhrase: async (): Promise<string> => {
const mnemonic = process.env.WALLET_MNEMONIC
if (mnemonic) {
return mnemonic
} else {
const secretName = process.env.WALLET_MNEMONIC_SECRET_NAME
console.log('Fetching mnemonic')
const response = await client.send(
new GetSecretValueCommand({
SecretId: secretName,
VersionStage: 'AWSCURRENT', // VersionStage defaults to AWSCURRENT if unspecified
}),
)

return seed
const secret = JSON.parse(response.SecretString!)
console.log('Successfully retrieved mnemonic')
return Object.values(secret)[0] as string
}
},
}
}
}
Loading