How umarhashmi2002/hedera-kms-signer works
Purpose and Entry Points
Hedera Key Guardian is a serverless custodial signing backend for Hedera. It exposes JWT-protected HTTP endpoints that validate transfer requests, enforce policy, sign with non-exportable AWS KMS secp256k1 keys, submit to Hedera, and emit dual audit records. The Lambda entry point and router are src/handler.ts; the deployable AWS application starts at infra/bin/app.ts and is defined by infra/lib/hedera-kms-signer-stack.ts.
Request Boundary and Dispatch
API Gateway authenticates callers with Cognito JWTs before invoking one Node.js 20 Lambda. src/handler.ts dispatches /sign-transfer, token transfer, scheduling, public-key, rotation, multisig, audit-topic, and public docs routes. Request contracts and validation form the application’s untrusted-input boundary in src/schemas.ts; the API surface is specified in docs/openapi.yaml.
Authorization, Validation, and Idempotency
Before KMS access, the handler validates UUIDs, Hedera account IDs, amounts, and route-specific payloads, then evaluates transaction policy in src/policy.ts. Policies constrain amount, recipient allowlists, transaction type, and permitted hours. Audit persistence in src/audit.ts supports request-id idempotency and conflict detection, using DynamoDB conditional writes to make duplicate/replayed requests return cached results or conflict rather than re-sign.
Hedera Transaction Construction and Signing
The core signing path is src/hedera.ts plus src/kms.ts. The service constructs and freezes a Hedera transaction, hashes frozen bytes with keccak256, and sends that 32-byte digest to AWS KMS using the secp256k1 signing key and digest mode. KMS returns a DER ECDSA signature; the application parses it into Hedera-compatible (r,s) form, attaches it, submits the signed transaction through the Hedera SDK, and returns consensus status/transaction ID. This keccak-before-KMS boundary is the critical chain-specific integration.
Transaction Variants and Key Lifecycle
Base HBAR transfer handling is extended by separate transaction orchestration modules: HTS token transfers in src/tokenTransfer.ts and scheduled transfers in src/scheduledTransfer.ts. src/publicKey.ts obtains/derives KMS public-key representations for account setup and EVM use. Key rotation in src/rotation.ts creates a replacement KMS key, updates the Hedera account using the current signer, then disables the old key. Threshold/multisig configuration is modeled in src/multisig.ts.
Audit and Hedera Consensus Logging
Successful and rejected signing decisions are persisted to DynamoDB through src/audit.ts for queryable operational audit. src/consensus.ts additionally publishes selected audit events to a Hedera Consensus Service topic, creating an external tamper-evident record. These writes are downstream side effects of request processing; transaction submission and audit/HCS outcomes need distinct failure handling.
Infrastructure and External Services
The CDK stack in infra/lib/hedera-kms-signer-stack.ts provisions/wires API Gateway, Cognito, Lambda, KMS (ECC_SECG_P256K1), DynamoDB, CloudWatch, CloudTrail, and SNS. Runtime dependencies cross AWS trust boundaries (JWT verification, KMS signing, audit storage/monitoring) and Hedera network boundaries (transaction consensus and HCS). Operational architecture and security assumptions are expanded in docs/architecture.md and docs/threat-model.md.
Main entry points: hedera-kms-signer-stack.ts Signer stack · handler.ts Signing Lambda · policy.ts Transaction policy · audit.ts Audit and idempotency
Components 19
Deployment
- CDK app
infra/bin/app.ts - Signer stack · Provisions and wires the serverless signing system.
infra/lib/hedera-kms-signer-stack.ts - OpenAPI surface
docs/openapi.yaml
Lambda runtime
- Signing Lambda
src/handler.ts - Request validation · Validates route payloads, UUIDs, account IDs, and amounts.
src/schemas.ts - Transaction policy · Enforces limits, allowlists, transaction types, and permitted hours.
src/policy.ts - Audit and idempotency · Uses conditional writes for replay detection, conflicts, and cached results.
src/audit.ts - Transaction variants · Handles HBAR, HTS token, and scheduled transfers.
src/tokenTransfer.ts - Hedera signing flow · Freezes transactions, hashes bytes with keccak256, attaches KMS signatures, and submits.
src/hedera.ts - KMS signature adapter · Signs the 32-byte digest and converts DER ECDSA to Hedera (r,s).
src/kms.ts - Key lifecycle routes · Provides public key, rotation, and multisig configuration operations.
src/rotation.ts
AWS services
- API Gateway
- Cognito
- AWS KMS key · Non-exportable custodial signing key.
- DynamoDB audit store
- CloudWatch, CloudTrail, SNS
Hedera network
- Hedera network
- HCS audit publisher · Publishes selected audit events to a tamper-evident topic.
src/consensus.ts - HCS topic
Connections 24
- CDK app → Signer stack: instantiates
- Signer stack → API Gateway: provisions
- Signer stack → Cognito: provisions
- Signer stack → Signing Lambda: deploys
- Signer stack → AWS KMS key: provisions
- Signer stack → DynamoDB audit store: provisions
- Signer stack → CloudWatch, CloudTrail, SNS: wires
- OpenAPI surface → API Gateway: specifies routes
- API Gateway → Cognito: authenticates with
- API Gateway → Signing Lambda: invokes after JWT
- Signing Lambda → Request validation: validates request
- Request validation → Transaction policy: valid input
- Transaction policy → Audit and idempotency: records decision / checks request ID
- Transaction policy → Transaction variants: approved transfer
- Transaction variants → Hedera signing flow: builds transaction
- Hedera signing flow → KMS signature adapter: keccak256 digest
- KMS signature adapter → AWS KMS key: signs digest
- Hedera signing flow → Hedera network: submits signed transaction
- Signing Lambda → Key lifecycle routes: dispatches key routes
- Key lifecycle routes → AWS KMS key: creates / reads / rotates keys
- Audit and idempotency → DynamoDB audit store: conditional audit writes
- Audit and idempotency → HCS audit publisher: selected events
- HCS audit publisher → HCS topic: publishes
- Signing Lambda → CloudWatch, CloudTrail, SNS: logs and alerts