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();

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

First-key create() is different: persist the returned immutable keyRef and public-key binding in application-owned durable storage before activation. Its pending-only snapshot has no active key ID and cannot be reopened with load({ state }). If restarting with only the handed-off reference, deliberately select it with load({ activeKeyId: savedKeyRef, ... }); prior local activation is not required, and the reopened key is locally active. Do not discard saved provider or managed-rotation state to use this reference-only path. Local signing eligibility does not establish publication or protocol identity status.

For first-key creation, explicitly call AwsKmsKeyProvider.create; no existing key is required. See the KMS-first setup guide for pending-key activation, canonical ARN handoff, publication boundaries, and failure recovery. Subsequent startup must reopen the saved key with load, never recreate it; normal configuration remains open-only.

The Node SDK lazily selects this optional package for keySource.provider: "aws-kms". Use an existing keyRef and non-secret settings with optional region and algorithm (EdDSA, the default, or ES256). Authentication uses ambient AWS credentials; raw secrets are rejected. createAwsKmsKeyProvider(keyRef, settings) provides the same factory for explicit composition.

Configuration-driven cloud generation is not supported: use an existing stable reference because KMS creation lacks atomic named create-or-recover. The SDK configuration constructor checks the resolved key against verified publication before returning a signing manager. Changing an alias to another key requires authorized rotation and updated publication. The standalone factory only opens the key; its caller owns identity binding checks.

AWS documents asymmetric multi-Region keys and Ed25519 signing. This is a vendor-documented setup pattern, not live-service verification or a promise that every account/region supports the combination. Check current service availability, CLI support and organization policies before provisioning; stop on an unsupported combination rather than substituting another algorithm.

Provision outside application startup, using a separately authorized operator. For example, in one account and AWS partition (shell variables below are operator inputs/output, not SDK environment settings):

Terminal window
set -eu
primary_region=us-east-1
replica_region=us-west-2
primary_arn=$(aws kms create-key --region "$primary_region" \
--multi-region --key-spec ECC_NIST_EDWARDS25519 --key-usage SIGN_VERIFY \
--query KeyMetadata.Arn --output text)
replica_arn=$(aws kms replicate-key --region "$primary_region" \
--key-id "$primary_arn" --replica-region "$replica_region" \
--query ReplicaKeyMetadata.Arn --output text)
aws kms describe-key --region "$primary_region" --key-id "$primary_arn"
aws kms describe-key --region "$replica_region" --key-id "$replica_arn"

Save the exact returned ARNs. Confirm MultiRegionConfiguration links the two keys, KeySpec is ECC_NIST_EDWARDS25519, KeyUsage is SIGN_VERIFY, and both keys are enabled before use. Set a finite readiness deadline and RPC timeouts; if a key is still creating, recheck within that budget, not in an endless loop. Do not blindly repeat creation after a lost response. Runtime principals need kms:GetPublicKey and kms:Sign on each regional key; replication/provisioning permissions belong to the operator, not ordinary startup.

For standalone cryptographic use, open two independent providers with different immutable regional key ARNs and matching regions, explicitly selecting EdDSA. The JSON below shows each regional key source, not a complete shared-identity deployment. Replace the illustrative account/key IDs with the returned ARNs:

{"keySource":{"provider":"aws-kms","keyRef":"arn:aws:kms:us-east-1:123456789012:key/mrk-0123456789abcdef0123456789abcdef","settings":{"region":"us-east-1","algorithm":"EdDSA"}}}
{"keySource":{"provider":"aws-kms","keyRef":"arn:aws:kms:us-west-2:123456789012:key/mrk-0123456789abcdef0123456789abcdef","settings":{"region":"us-west-2","algorithm":"EdDSA"}}}

Use ambient AWS credentials. Do not send the primary ARN to the replica region and rely on redirection. Related MRKs share key material and a key ID, not one global ARN: policies, grants, aliases and enabled state are regional. An mrk- prefix alone proves neither relationship nor public-key equality.

Opening configuration never generates or replicates keys and has no automatic regional failover or local-signer fallback. Explicit provider creation/rotation is not automatic MRK replication or fleet coordination. Preserve existing publication/signing-key binding checks; changing configuration does not authorize replacing an established signer.

EdDSA uses ED25519_SHA_512 with RAW data, at most 4096 bytes. Oversized payloads fail. Do not hash them and substitute Ed25519ph/DIGEST: that is not the same signature scheme. See AWS Sign limits.

Go and TypeScript AWS providers retain canonical native KMS identifiers as JWK kid values. The two regional ARNs above therefore produce different kids even when their public key material and RFC 7638 thumbprints are identical. Python AWS instead uses public-key thumbprint kids while retaining native references separately; do not assume the same identity-binding behavior across SDKs.

Identity-bound configuration limitation: constructIdentityManager checks the configuration-selected signing key against the verified publication by kid, algorithm and thumbprint, not public material alone. A publication made with region A’s ARN cannot be reused by configuration selecting region B’s ARN: construction rejects the different kid. Each identity-bound setup needs a verified publication matching its selected regional kid; these fragments do not provide two regional signers for one unchanged published identity. Any change to an established signer must follow authorized publication/key-rotation procedures, not just a regional configuration switch.

Standalone provider opens and raw signature cross-verification remain supported for the two regional references, independently of identity-manager construction. They demonstrate cryptographic key equality, not shared published-identity compatibility or automatic failover. Injecting a provider is not a documented workaround: the owning workflow still has identity-binding responsibilities, and signature kid values must match the published identity’s expectations. This setup does not normalize regional kids or solve that shared-identity limitation.

For cryptographic equality, require public JWK kty=OKP, crv=Ed25519, alg=EdDSA, equal x, and no private d. Independently compute RFC 7638 SHA-256 thumbprints over canonical JSON containing only crv, kty, x; compare those, not entire serialized JWKs or native references. Sign the same bounded raw payload through each client and independently verify both signatures with the common public key (and the other client’s public key). Reopen the exact saved references and repeat; signature-byte equality is not the acceptance criterion. Unrelated keys cannot satisfy this check; the SDK does not discover cross-region misconfiguration.

Plan cleanup before allocation. For owned disposable fixtures, schedule replica deletion before deleting the primary and verify each key’s disposition. Scheduled deletion is delayed, not completed removal; retain an owner/follow-up for outstanding resources. Never delete shared keys as test cleanup.

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

First-key creation permission:

  • kms:CreateKey for AwsKmsKeyProvider.create()
  • kms:TagResource only when tags are supplied

Rotation permissions, if used:

  • kms:CreateKey for generateKey()
  • kms:TagResource only when tags are supplied
  • kms:ScheduleKeyDeletion for supersede() when scheduleKeyDeletionOnPurge is enabled

Like first-key create(), generateKey() requires the getPublicKey response for the newly created key to include a nonempty immutable keyId matching the created reference. A bare key UUID may resolve to its matching canonical key ARN. An omitted or unrelated response ID rejects generation before adding a pending key, even though the remote key has already been created; the operator owns reconciliation and cleanup. Response keyId remains optional when opening an existing key with load().

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:201

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:349

Blocks new signing and drains in-flight signatures before promoting a pending key. The previously active key transitions to retained.

string

Promise<void>

KeyProvider.activate

generateKey(algorithm?): Promise<string>;

Defined in: index.ts:328

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

string

Promise<string>

KeyProvider.generateKey

jwk(kid): Promise<DnsIdJWK>;

Defined in: index.ts:262

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:269

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:385

string

Promise<void>

Use supersede().

KeyProvider.purge

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

Defined in: index.ts:281

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:257

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:286

Signs with a specified active or pending key.

string

Uint8Array

Promise<Uint8Array<ArrayBufferLike>>

KeyProvider.signKey

stateSnapshot(): AwsKmsKeyState;

Defined in: index.ts:273

AwsKmsKeyState

supersede(kid): Promise<void>;

Defined in: index.ts:363

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

string

Promise<void>

KeyProvider.supersede

validateKeyGeneration(algorithm): Promise<void>;

Defined in: index.ts:321

Validates generation settings and algorithm support without creating a key.

string

Promise<void>

KeyProvider.validateKeyGeneration

static create(client, config): Promise<{
keyRef: string;
kid: string;
provider: AwsKmsKeyProvider;
}>;

Defined in: index.ts:233

Explicitly creates a native KMS signing key, locally pending until activate(kid). Returns its canonical immutable reference; never writes state or imports private keys. The caller owns the client and recovery of remote keys after ambiguous failures. Normal load/configuration opening never creates keys.

AwsKmsFacade

Pick<AwsKmsConfig, | "algorithm" | "keySpec" | "description" | "tags" | "scheduleKeyDeletionOnPurge" | "deletionWindowInDays">

Promise<{ keyRef: string; kid: string; provider: AwsKmsKeyProvider; }>

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

Defined in: index.ts:245

AwsKmsFacade

AwsKmsConfig

Promise<AwsKmsKeyProvider>


Defined in: index.ts:131

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

new AwsSdkKmsFacade(client): AwsSdkKmsFacade;

Defined in: index.ts:132

AwsSdkKmsClient

AwsSdkKmsFacade

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

Defined in: index.ts:134

AwsKmsCreateSigningKeyInput

Promise<{ keyId: string; }>

AwsKmsFacade.createSigningKey

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

Defined in: index.ts:146

For newly created keys, including rotation through generateKey(), the response must include a nonempty immutable keyId matching the created reference. A bare key UUID may resolve to its matching canonical key ARN. Omitted or unrelated IDs reject generation after remote creation and before pending-key insertion. Response keyId remains optional when opening an existing key with load().

AwsKmsGetPublicKeyInput

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

AwsKmsFacade.getPublicKey

scheduleKeyDeletion(input): Promise<void>;

Defined in: index.ts:187

AwsKmsScheduleKeyDeletionInput

Promise<void>

AwsKmsFacade.scheduleKeyDeletion

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

Defined in: index.ts:168

AwsKmsSignInput

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

AwsKmsFacade.sign

Defined in: index.ts:56

optional activeKeyArn?: string;

Defined in: index.ts:63

Legacy alias for activeKeyId kept for existing callers.

optional activeKeyId?: string;

Defined in: index.ts:49

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:69

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

optional deletionWindowInDays?: number;

Defined in: index.ts:79

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

optional description?: string;

Defined in: index.ts:73

Optional description passed to generated KMS keys.

optional keySpec?: AwsKmsKeySpec;

Defined in: index.ts:71

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

optional pendingKeyArns?: string[];

Defined in: index.ts:67

Legacy alias for pendingKeyIds kept for existing callers.

optional pendingKeyIds?: string[];

Defined in: index.ts:53

KMS key IDs generated but not yet active.

AwsKmsKeyState.pendingKeyIds

optional retainedKeyArns?: string[];

Defined in: index.ts:65

Legacy alias for retainedKeyIds kept for existing callers.

optional retainedKeyIds?: string[];

Defined in: index.ts:51

KMS key IDs retained for verification of previous signatures.

AwsKmsKeyState.retainedKeyIds

optional scheduleKeyDeletionOnPurge?: boolean;

Defined in: index.ts:77

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

optional state?: AwsKmsKeyState;

Defined in: index.ts:61

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:75

Optional tags passed to generated KMS keys.


Defined in: index.ts:82

optional description?: string;

Defined in: index.ts:84

keySpec: AwsKmsKeySpec;

Defined in: index.ts:83

optional tags?: Record<string, string>;

Defined in: index.ts:85


Defined in: index.ts:104

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

Defined in: index.ts:105

AwsKmsCreateSigningKeyInput

Promise<{ keyId: string; }>

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

Defined in: index.ts:113

For newly created keys, including rotation through generateKey(), the response must include a nonempty immutable keyId matching the created reference. A bare key UUID may resolve to its matching canonical key ARN. Omitted or unrelated IDs reject generation after remote creation and before pending-key insertion. Response keyId remains optional when opening an existing key with load().

AwsKmsGetPublicKeyInput

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

optional scheduleKeyDeletion(input): Promise<void>;

Defined in: index.ts:125

AwsKmsScheduleKeyDeletionInput

Promise<void>

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

Defined in: index.ts:120

AwsKmsSignInput

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


Defined in: index.ts:88

keyId: string;

Defined in: index.ts:89


Defined in: index.ts:47

activeKeyId: string;

Defined in: index.ts:49

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:53

KMS key IDs generated but not yet active.

optional retainedKeyIds?: string[];

Defined in: index.ts:51

KMS key IDs retained for verification of previous signatures.


Defined in: index.ts:99

keyId: string;

Defined in: index.ts:100

pendingWindowInDays: number;

Defined in: index.ts:101


Defined in: index.ts:92

keyId: string;

Defined in: index.ts:93

message: Uint8Array;

Defined in: index.ts:94

messageType: "RAW" | "DIGEST";

Defined in: index.ts:96

signingAlgorithm: AwsKmsSigningAlgorithm;

Defined in: index.ts:95

type AwsKmsKeySpec = "ECC_NIST_P256" | "ECC_NIST_EDWARDS25519";

Defined in: index.ts:43


type AwsKmsSigningAlgorithm = "ECDSA_SHA_256" | "ED25519_SHA_512";

Defined in: index.ts:41


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

Defined in: index.ts:128

function createAwsKmsKeyProvider(keyRef, settings?): Promise<AwsKmsKeyProvider>;

Defined in: index.ts:33

Opens an existing KMS key, without generation or private-key import.

string

Record<string, unknown> = {}

Promise<AwsKmsKeyProvider>


function validateAwsKmsSettings(settings?): void;

Defined in: index.ts:25

Deployment-file settings use ambient AWS credentials; raw credentials are not accepted.

Record<string, unknown> = {}

void