-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.ts
77 lines (67 loc) · 1.74 KB
/
handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { APIGatewayProxyHandler } from 'aws-lambda'
import LockService from './src/lock-service'
import Signer from './src/signer'
import { TezosKmsClient } from '@tacoinfra/tezos-kms'
/** Constants */
// TODO(keefertaylor): Inject these with environment variables
// DynamoDb
const DYNAMO_DB_TABLE_NAME = ""
const DYNAMO_DB_AWS_REGION = ""
const DYNAMO_DB_AWS_ENDPOINT = ""
// KMS
const KMS_AWS_REGION = ""
const KMS_KEY_ID = ""
// Initialize services
const lockService = new LockService(DYNAMO_DB_AWS_REGION, DYNAMO_DB_AWS_ENDPOINT, DYNAMO_DB_TABLE_NAME)
const kmsSigner = new TezosKmsClient(KMS_KEY_ID, KMS_AWS_REGION)
const signer = new Signer(kmsSigner, lockService)
export const sign: APIGatewayProxyHandler = async (
event,
_context,
) => {
try {
if (event === null || event.body === null) {
throw new Error("API params required.")
}
const operation = JSON.parse(event.body)
console.log("Parsed operation as " + operation)
const signature = await signer.sign(operation)
const response = {
signature
}
return {
statusCode: 200,
body: JSON.stringify(response)
}
} catch (e) {
console.log("Handler caught error: " + e.message)
return {
statusCode: 500,
body: e.message
}
}
}
// TODO(keefertaylor): Properly implement.
export const getKey: APIGatewayProxyHandler = async (
event,
_context,
) => {
const key = await kmsSigner.getPublicKey()
return {
statusCode: 200,
body: JSON.stringify({
public_key: key
})
}
}
// TODO(keefertaylor): Properly implement.
export const dumpKeys: APIGatewayProxyHandler = async (
event,
_context,
) => {
const key = await kmsSigner.getPublicKey()
return {
statusCode: 200,
body: JSON.stringify({})
}
}