Skip to content

TypeScript: @dnsid-ai/key-gcp

Optional Node.js Google Cloud KMS provider that opens existing software EC_SIGN_ED25519 key versions or explicitly creates a pending first version through create() under an existing compatible CryptoKey. Install this package separately from the base SDK; its Google dependency is not required by base SDK consumers.

import { KeyManagementServiceClient } from '@google-cloud/kms';
import { GcpCloudKmsKeyProvider } from '@dnsid-ai/key-gcp';
const keyProvider = await GcpCloudKmsKeyProvider.load(new KeyManagementServiceClient(), {
activeKeyVersion: 'projects/p/locations/l/keyRings/r/cryptoKeys/k/cryptoKeyVersions/1',
algorithm: 'EC_SIGN_ED25519',
});

Use ambient Google credentials with cloudkms.cryptoKeyVersions.viewPublicKey and cloudkms.cryptoKeyVersions.useToSign permissions. Both initial create() and rotation through generateKey() also require cloudkms.cryptoKeyVersions.create and cloudkms.cryptoKeyVersions.get for version creation and readiness metadata reads. Initial create() additionally requires cloudkms.cryptoKeys.get to validate the existing parent. Grant the version metadata-read permission before either operation: a readiness read can fail after the remote version has already been created. The reference must name a numeric immutable version, not a parent or alias. The provider exports only the public Ed25519 JWK, with an RFC 7638 thumbprint as kid. It sends raw data (never a digest) and verifies request/response CRC32C integrity and returned version bindings. Google transport and permission errors propagate; there is no local signing fallback, key import, or generation during opening.

For first-key creation, explicitly call GcpCloudKmsKeyProvider.create with an existing ASYMMETRIC_SIGN CryptoKey parent whose version template is EC_SIGN_ED25519 / SOFTWARE; no prior version is required. See the KMS-first setup guide for pending-key activation, reference handoff, publication boundaries, and failure recovery. Subsequent startup must reopen the saved immutable version with load, never recreate it; normal configuration remains open-only.

Configuration selects this optional package with provider: "google-kms", the immutable version as keyRef, and optional settings.algorithm: "EdDSA" (the only supported deployment algorithm). SDK composition translates EdDSA to the Cloud KMS EC_SIGN_ED25519 algorithm; direct GcpCloudKmsConfig.algorithm remains EC_SIGN_ED25519, as in the example above. Only the selected package is imported; injected providers bypass selection.

const keySource = {
provider: 'google-kms',
keyRef: 'projects/p/locations/l/keyRings/r/cryptoKeys/k/cryptoKeyVersions/1',
settings: { algorithm: 'EdDSA' },
};

An explicit generateKey() or generateKey('EdDSA') creates a pending software Ed25519 version under the same CryptoKey. Other requested algorithms are rejected before creation. validateKeyGeneration('EdDSA') checks algorithm support without creating a version. Like first-key creation, generation waits for the exact created version to become enabled, polling pending generation at most 20 times, 250ms apart. Transport call deadlines remain caller-owned. Post-create failures retain the known version reference and cause; service/integrity failures are not caller-argument errors. There is no automatic recreation or deletion on failure. Generation does not change deployment configuration or the active signer. Pending keys support jwk and signKey; activate drains in-flight signatures and blocks new signing while promoting the pending key. listKeyIds contains only the active ID, or is empty after local supersession. supersede and its purge alias change local eligibility only; no cloud version is disabled or destroyed. Historical public keys remain available through jwk.

Lifecycle state is in memory. Applications own durable recovery and publication orchestration. For recovery, pass the application’s saved immutable A reference as activeKeyVersion and saved B reference as optional pendingKeyVersion to load. Both versions and public bindings are validated; duplicate versions or public-key identities are rejected. B is inserted directly as pending: jwk and rotation signKey are available, while signingKey, sign, and listKeyIds continue to select only A. Existing activate performs the local transition. This input is saved application state, not key discovery or permission to activate; managed recovery still validates the saved rotation’s exact bindings. Ordinary A-only loading is unchanged and does not discover pending state. Retained-key configuration loading is rejected. Lifecycle behavior implements the provisional shared #56 clarification, not a claim of contract acceptance.

Google software Ed25519 in a multi-region or global location

Section titled “Google software Ed25519 in a multi-region or global location”

Google documents SOFTWARE keys in Cloud KMS locations and software EC_SIGN_ED25519. This is a vendor-documented setup pattern, not live-service verification or a universal availability promise. Check current location/algorithm support, CLI support, permissions and organization policies before provisioning. These providers target SOFTWARE Ed25519, not HSM or EXTERNAL custody.

Prefer an approved existing version. If provisioning is authorized, an external operator can create a ring/key as follows. These shell variables are CLI inputs, not new SDK environment settings:

Terminal window
set -eu
project=my-project
location=us # Or global, as a separate approved location choice.
ring=agents
key=agent
gcloud kms keyrings create "$ring" --project="$project" --location="$location"
gcloud kms keys create "$key" --project="$project" --location="$location" \
--keyring="$ring" --purpose=asymmetric-signing \
--default-algorithm=ec-sign-ed25519 --protection-level=software
gcloud kms keys versions list --project="$project" --location="$location" \
--keyring="$ring" --key="$key"

Select the actual enabled numeric version from the returned inventory; do not assume version 1 or use a mutable selector. Confirm its algorithm/protection and public key before deployment. Set finite RPC/readiness budgets, stop on failure, and reconcile any created resources rather than blindly creating again. Runtime clients need cloudkms.cryptoKeyVersions.viewPublicKey and cloudkms.cryptoKeyVersions.useToSign; creation/IAM administration stays with the separately authorized operator. Credentials use ambient Application Default Credentials, never deployment secrets.

Both independently configured clients use the identical full version name within the selected location. For example, replace this illustrative version with the actual resource in a deployment JSON fragment:

{"keySource":{"provider":"google-kms","keyRef":"projects/my-project/locations/us/keyRings/agents/cryptoKeys/agent/cryptoKeyVersions/7","settings":{"algorithm":"EdDSA"}}}

For a separate global deployment, use the actual resource containing locations/global in both clients, for example:

{"keySource":{"provider":"google-kms","keyRef":"projects/my-project/locations/global/keyRings/agents/cryptoKeys/agent/cryptoKeyVersions/7","settings":{"algorithm":"EdDSA"}}}

Do not rewrite an existing us resource to global, or to a constituent regional name: those designate different resources, not replicas of the original version. A global service endpoint does not make a regional key global. Deployment settings support only algorithm: "EdDSA"; location and project come from keyRef, not extra settings.

A multi-region (including the special global location) is one location resource/version, not independently named regional replicas. Google manages material across datacenters in that location; callers cannot select a subset. Location is immutable. global is not a geographic residency guarantee, and metadata operations requiring consensus can have higher latency. Choose topology and residency before creation; do not promise region-pinned custody or automatic SDK failover from this pattern.

Opening uses the existing version only: no automatic generation, replication, import, discovery or local-signer fallback. Explicit generation creates another version, not a regional replica, and does not authorize changing the established signer or publication. Preserve existing identity binding and application-owned rotation/recovery orchestration.

Google public JWK kid values are RFC 7638 thumbprints, not cloud resource names. To verify same-key use, independently compare canonical public crv, kty, x thumbprints and require OKP / Ed25519 / EdDSA, equal x and no private d. Sign the same raw payload independently, locally verify both signatures with the common/other client’s public key, and reopen the exact version to repeat. Do not compare different us and global keys as if they were replicas. Signing sends raw data, not a digest, and retains the provider’s version/integrity checks.

Plan version destruction with the resource owner: scheduling destruction is not immediate deletion. Key rings and CryptoKey containers cannot simply be deleted after the test; account for retained containers or an approved project lifecycle. Local provider supersession does not destroy cloud material. Prefer pre-existing approved fixtures when retained containers are unacceptable.

Google Cloud KMS Ed25519 signing with explicit native version creation. Private keys never leave KMS.

Defined in: index.ts:41

Opens existing software Ed25519 versions, or explicitly creates pending versions.

activate(kid): Promise<void>;

Defined in: index.ts:205

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

Explicit operator generation only; defaults to EdDSA and rejects other algorithms before creation. Pending generation polls the exact created version at most 20 times, 250ms apart, using the caller’s transport timeouts, just as initial creation does. Returns a locally pending key without changing the active signer. Failures after creation retain the version reference and cause, without retrying or deleting it. Service/integrity failures are not caller-argument errors. Never called by configuration opening.

string

Promise<string>

KeyProvider.generateKey

jwk(kid): Promise<DnsIdJWK>;

Defined in: index.ts:121

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

Returns only the current active key ID, or an empty list when no key is active. Pending and superseded keys are excluded from this live key list, even when their public JWKs remain available through jwk for historical verification.

Promise<string[]>

KeyProvider.listKeyIds

purge(kid): Promise<void>;

Defined in: index.ts:232

Alias for local supersession; never disables or destroys a cloud version.

string

Promise<void>

KeyProvider.purge

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

Defined in: index.ts:132

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

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

Signs with a specified active or pending key.

string

Uint8Array

Promise<Uint8Array<ArrayBufferLike>>

KeyProvider.signKey

supersede(kid): Promise<void>;

Defined in: index.ts:224

Removes local signing eligibility from an active, pending, or already superseded key. Superseding the active key leaves no active signer and an empty live key list; superseding another key does not clear its successor. The public JWK remains available through jwk for historical verification. Never disables, destroys, or otherwise mutates the remote CryptoKeyVersion.

string

Promise<void>

KeyProvider.supersede

validateKeyGeneration(algorithm): Promise<void>;

Defined in: index.ts:158

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: GcpCloudKmsKeyProvider;
}>;

Defined in: index.ts:68

Creates one version under an existing ASYMMETRIC_SIGN CryptoKey with a SOFTWARE EC_SIGN_ED25519 template, without opening any prior version. Returns a locally pending provider and immutable reference; activate(kid) explicitly before initial manager injection. Never provisions the parent, writes files, deletes keys, or closes the caller-owned client. Pending generation polls the same version at most 20 times, 250ms apart. Each transport call uses the caller’s client timeout configuration. Failed/indeterminate creation may leave an operator-owned remote version; do not blindly retry. Normal load/configuration remains open-only.

GcpCloudKmsClient

string

string

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

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

Defined in: index.ts:95

Opens the selected active version and, optionally, an application-saved pending version for recovery. Both bindings are validated; the pending key supports JWK lookup and rotation proof signing but is not the active signer or live inventory. No discovery, generation, or activation occurs. Applications own durable references and recovery checks; activate performs the local transition.

GcpCloudKmsClient | undefined

GcpCloudKmsConfig

Promise<GcpCloudKmsKeyProvider>

Defined in: index.ts:20

Structural seam implemented by the official KeyManagementServiceClient.

asymmetricSign(request): Promise<readonly unknown[]>;

Defined in: index.ts:27

Uint8Array

{ value: number; }

number

string

Promise<readonly unknown[]>

optional createCryptoKeyVersion(request): Promise<readonly unknown[]>;

Defined in: index.ts:25

{ state: "ENABLED"; }

"ENABLED"

string

Promise<readonly unknown[]>

optional getCryptoKey(request): Promise<readonly unknown[]>;

Defined in: index.ts:22

Required only for initial creation; reads the existing signing parent/template.

string

Promise<readonly unknown[]>

optional getCryptoKeyVersion(request): Promise<readonly unknown[]>;

Defined in: index.ts:24

Required when a newly created version is still PENDING_GENERATION.

string

Promise<readonly unknown[]>

getPublicKey(request): Promise<readonly unknown[]>;

Defined in: index.ts:26

string

Promise<readonly unknown[]>


Defined in: index.ts:8

activeKeyVersion: string;

Defined in: index.ts:10

Fully qualified immutable CryptoKeyVersion resource name.

algorithm: string;

Defined in: index.ts:16

Must be EC_SIGN_ED25519.

optional pendingKeyVersion?: string;

Defined in: index.ts:12

Application-saved immutable pending version; never discovered or activated by load.

optional retainedKeyVersions?: string[];

Defined in: index.ts:14

Retained-key loading is not supported by this runtime slice.