Skip to content

TypeScript: @dnsid-ai/key-aws

AWS KMS-backed DNSid KeyProvider.

Private keys stay in AWS KMS. This package fetches public keys, exposes them as DNSid JWKs, signs through KMS, and manages active/pending/retained key state.

Terminal window
npm install @dnsid-ai/key-aws @dnsid-ai/protocol @aws-sdk/client-kms
import { KMSClient } from '@aws-sdk/client-kms';
import { AwsKmsKeyProvider, AwsSdkKmsFacade } from '@dnsid-ai/key-aws';
const state = {
activeKeyId: 'alias/dnsid-current',
retainedKeyIds: [],
pendingKeyIds: [],
};
const provider = await AwsKmsKeyProvider.load(
new AwsSdkKmsFacade(new KMSClient({ region: 'us-east-1' })),
{
state,
algorithm: 'ECDSA_SHA_256',
keySpec: 'ECC_NIST_P256',
},
);
const signature = await provider.sign(new TextEncoder().encode('payload'));
const jwk = await provider.signingKey();

Persist provider.stateSnapshot() after generateKey(), activate(), or supersede(). The package mutates the supplied state object, but persistence is the caller’s job.

DNSid/JWS algAWS signing algorithmAWS key spec
ES256ECDSA_SHA_256ECC_NIST_P256
EdDSAED25519_SHA_512ECC_NIST_EDWARDS25519

Loaded keys must have:

  • KeyUsage: SIGN_VERIFY
  • matching KeySpec
  • SigningAlgorithms containing the configured algorithm

Aliases, alias ARNs, key IDs, and key ARNs are accepted. They are resolved to canonical KMS key IDs on load.

Minimum runtime permissions:

  • kms:GetPublicKey
  • kms:Sign

Rotation permissions, if used:

  • kms:CreateKey for generateKey()
  • kms:ScheduleKeyDeletion for supersede() when scheduleKeyDeletionOnPurge is enabled
const nextKid = await provider.generateKey();
await provider.activate(nextKid);
await provider.supersede('old-key-id');
await saveState(provider.stateSnapshot());

Pending keys are not published by listKeyIds() or jwk(). Activating a pending key moves the previous active key to retained.

AWS KMS RAW signing is limited to 4096 bytes. For ECDSA_SHA_256, larger payloads are SHA-256 hashed locally and signed with KMS DIGEST mode. ED25519_SHA_512 remains RAW-only.

From the repo root:

Terminal window
DNSID_AWS_KMS_LOCALSTACK=1 npm run test:aws-kms:localstack

AWS KMS-backed key provider for DNSid.

@dnsid-ai/key-aws implements the KeyProvider contract from @dnsid-ai/protocol on top of AWS KMS: private key material never leaves KMS, while AwsKmsKeyProvider exposes public keys as DNSid JWKs, signs through KMS, and manages the active/pending/retained key lifecycle. Callers persist stateSnapshot() after lifecycle changes. AwsSdkKmsFacade adapts AWS SDK v3’s KMSClient to the narrow AwsKmsFacade interface this package depends on.

Defined in: index.ts:173

AWS KMS-backed DNSid KeyProvider.

AWS KMS owns private key material and signing. This provider owns DNSid’s active/pending/retained lifecycle state and exposes public keys as JWKs.

activate(kid): Promise<void>;

Defined in: index.ts:279

Promotes a pending key to active. The previously active key transitions to retained.

string

Promise<void>

KeyProvider.activate

generateKey(): Promise<string>;

Defined in: index.ts:263

Generates a new key pair in the pending state. Returns the new key’s kid.

Promise<string>

KeyProvider.generateKey

jwk(kid): Promise<DnsIdJWK>;

Defined in: index.ts:213

Returns the JWK representation of a key by ID (active, pending, or retained). Raises if not found.

string

Promise<DnsIdJWK>

KeyProvider.jwk

listKeyIds(): Promise<string[]>;

Defined in: index.ts:220

Returns the IDs of all active and retained keys (pending keys excluded). The active key ID MUST appear first; retained keys follow in any order.

Promise<string[]>

KeyProvider.listKeyIds

purge(kid): Promise<void>;

Defined in: index.ts:310

string

Promise<void>

Use supersede().

KeyProvider.purge

sign(payload): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: index.ts:232

Signs the given payload with the current active signing key. Returns raw signature bytes.

Uint8Array

Promise<Uint8Array<ArrayBufferLike>>

KeyProvider.sign

signingKey(): Promise<DnsIdJWK>;

Defined in: index.ts:209

Returns the JWK representation of the current active public signing key. The returned kid MUST NOT contain ’#’.

Promise<DnsIdJWK>

KeyProvider.signingKey

signKey(kid, payload): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: index.ts:236

Signs with a specified active or pending key.

string

Uint8Array

Promise<Uint8Array<ArrayBufferLike>>

KeyProvider.signKey

stateSnapshot(): AwsKmsKeyState;

Defined in: index.ts:224

AwsKmsKeyState

supersede(kid): Promise<void>;

Defined in: index.ts:288

Supersedes and removes a retained key from this provider’s published key set.

string

Promise<void>

KeyProvider.supersede

static load(client, config): Promise<AwsKmsKeyProvider>;

Defined in: index.ts:197

AwsKmsFacade

AwsKmsConfig

Promise<AwsKmsKeyProvider>


Defined in: index.ts:107

Adapter from AWS SDK v3’s KMSClient to the narrow facade used by AwsKmsKeyProvider.

new AwsSdkKmsFacade(client): AwsSdkKmsFacade;

Defined in: index.ts:108

AwsSdkKmsClient

AwsSdkKmsFacade

createSigningKey(input): Promise<{
keyId: string;
}>;

Defined in: index.ts:110

AwsKmsCreateSigningKeyInput

Promise<{ keyId: string; }>

AwsKmsFacade.createSigningKey

getPublicKey(input): Promise<{
keyId?: string;
keySpec?: string;
keyUsage?: string;
publicKey: Uint8Array;
signingAlgorithms?: string[];
}>;

Defined in: index.ts:122

AwsKmsGetPublicKeyInput

Promise<{ keyId?: string; keySpec?: string; keyUsage?: string; publicKey: Uint8Array; signingAlgorithms?: string[]; }>

AwsKmsFacade.getPublicKey

scheduleKeyDeletion(input): Promise<void>;

Defined in: index.ts:159

AwsKmsScheduleKeyDeletionInput

Promise<void>

AwsKmsFacade.scheduleKeyDeletion

sign(input): Promise<{
keyId?: string;
signature: Uint8Array;
signingAlgorithm?: string;
}>;

Defined in: index.ts:140

AwsKmsSignInput

Promise<{ keyId?: string; signature: Uint8Array; signingAlgorithm?: string; }>

AwsKmsFacade.sign

Defined in: index.ts:39

optional activeKeyArn?: string;

Defined in: index.ts:46

Legacy alias for activeKeyId kept for existing callers.

optional activeKeyId?: string;

Defined in: index.ts:32

ARN, key ID, alias, or alias ARN of the currently active signing key. Aliases are resolved to canonical key IDs on load.

AwsKmsKeyState.activeKeyId

algorithm: AwsKmsSigningAlgorithm;

Defined in: index.ts:52

KMS signing algorithm to request. Must match the key spec.

optional deletionWindowInDays?: number;

Defined in: index.ts:62

Waiting period for ScheduleKeyDeletion. AWS allows 7-30 days. Default: 30.

optional description?: string;

Defined in: index.ts:56

Optional description passed to generated KMS keys.

optional keySpec?: AwsKmsKeySpec;

Defined in: index.ts:54

KMS key spec to use when generateKey creates a new key.

optional pendingKeyArns?: string[];

Defined in: index.ts:50

Legacy alias for pendingKeyIds kept for existing callers.

optional pendingKeyIds?: string[];

Defined in: index.ts:36

KMS key IDs generated but not yet active.

AwsKmsKeyState.pendingKeyIds

optional retainedKeyArns?: string[];

Defined in: index.ts:48

Legacy alias for retainedKeyIds kept for existing callers.

optional retainedKeyIds?: string[];

Defined in: index.ts:34

KMS key IDs retained for verification of previous signatures.

AwsKmsKeyState.retainedKeyIds

optional scheduleKeyDeletionOnPurge?: boolean;

Defined in: index.ts:60

Schedule deletion of retained KMS keys on purge. Default: false.

optional state?: AwsKmsKeyState;

Defined in: index.ts:44

Mutable state object for provider lifecycle. Prefer this over the legacy top-level active/retained/pending fields when state must persist.

optional tags?: Record<string, string>;

Defined in: index.ts:58

Optional tags passed to generated KMS keys.


Defined in: index.ts:65

optional description?: string;

Defined in: index.ts:67

keySpec: AwsKmsKeySpec;

Defined in: index.ts:66

optional tags?: Record<string, string>;

Defined in: index.ts:68


Defined in: index.ts:87

createSigningKey(input): Promise<{
keyId: string;
}>;

Defined in: index.ts:88

AwsKmsCreateSigningKeyInput

Promise<{ keyId: string; }>

getPublicKey(input): Promise<{
keyId?: string;
keySpec?: string;
keyUsage?: string;
publicKey: Uint8Array;
signingAlgorithms?: string[];
}>;

Defined in: index.ts:89

AwsKmsGetPublicKeyInput

Promise<{ keyId?: string; keySpec?: string; keyUsage?: string; publicKey: Uint8Array; signingAlgorithms?: string[]; }>

optional scheduleKeyDeletion(input): Promise<void>;

Defined in: index.ts:101

AwsKmsScheduleKeyDeletionInput

Promise<void>

sign(input): Promise<{
keyId?: string;
signature: Uint8Array;
signingAlgorithm?: string;
}>;

Defined in: index.ts:96

AwsKmsSignInput

Promise<{ keyId?: string; signature: Uint8Array; signingAlgorithm?: string; }>


Defined in: index.ts:71

keyId: string;

Defined in: index.ts:72


Defined in: index.ts:30

activeKeyId: string;

Defined in: index.ts:32

ARN, key ID, alias, or alias ARN of the currently active signing key. Aliases are resolved to canonical key IDs on load.

optional pendingKeyIds?: string[];

Defined in: index.ts:36

KMS key IDs generated but not yet active.

optional retainedKeyIds?: string[];

Defined in: index.ts:34

KMS key IDs retained for verification of previous signatures.


Defined in: index.ts:82

keyId: string;

Defined in: index.ts:83

pendingWindowInDays: number;

Defined in: index.ts:84


Defined in: index.ts:75

keyId: string;

Defined in: index.ts:76

message: Uint8Array;

Defined in: index.ts:77

messageType: "RAW" | "DIGEST";

Defined in: index.ts:79

signingAlgorithm: AwsKmsSigningAlgorithm;

Defined in: index.ts:78

type AwsKmsKeySpec = "ECC_NIST_P256" | "ECC_NIST_EDWARDS25519";

Defined in: index.ts:26


type AwsKmsSigningAlgorithm = "ECDSA_SHA_256" | "ED25519_SHA_512";

Defined in: index.ts:24


type AwsSdkKmsClient = Pick<KMSClient, "send">;

Defined in: index.ts:104