@agenticprimitives/key-custody 0.1.0-alpha.2 → 1.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -5
- package/bin/ap-provision-gcp.mjs +91 -0
- package/dist/account.js +1 -1
- package/dist/account.js.map +1 -1
- package/dist/derive-subject.js +4 -4
- package/dist/derive-subject.js.map +1 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +3 -2
- package/dist/factories.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/dist/kms/gcp-transport.d.ts +36 -0
- package/dist/kms/gcp-transport.d.ts.map +1 -0
- package/dist/kms/gcp-transport.js +114 -0
- package/dist/kms/gcp-transport.js.map +1 -0
- package/dist/kms/key-map.d.ts +13 -0
- package/dist/kms/key-map.d.ts.map +1 -0
- package/dist/kms/key-map.js +65 -0
- package/dist/kms/key-map.js.map +1 -0
- package/dist/kms/kms-core.d.ts +4 -0
- package/dist/kms/kms-core.d.ts.map +1 -0
- package/dist/kms/kms-core.js +14 -0
- package/dist/kms/kms-core.js.map +1 -0
- package/dist/kms/provision-gcp.d.ts +56 -0
- package/dist/kms/provision-gcp.d.ts.map +1 -0
- package/dist/kms/provision-gcp.js +107 -0
- package/dist/kms/provision-gcp.js.map +1 -0
- package/dist/kms/secp256k1-core.d.ts +46 -0
- package/dist/kms/secp256k1-core.d.ts.map +1 -0
- package/dist/kms/secp256k1-core.js +209 -0
- package/dist/kms/secp256k1-core.js.map +1 -0
- package/dist/providers/aws.d.ts +3 -0
- package/dist/providers/aws.d.ts.map +1 -1
- package/dist/providers/aws.js +17 -7
- package/dist/providers/aws.js.map +1 -1
- package/dist/providers/gcp.d.ts +5 -34
- package/dist/providers/gcp.d.ts.map +1 -1
- package/dist/providers/gcp.js +36 -329
- package/dist/providers/gcp.js.map +1 -1
- package/dist/providers/local.d.ts +3 -3
- package/dist/providers/local.d.ts.map +1 -1
- package/dist/providers/local.js +16 -6
- package/dist/providers/local.js.map +1 -1
- package/dist/relayer-account.d.ts +44 -0
- package/dist/relayer-account.d.ts.map +1 -0
- package/dist/relayer-account.js +146 -0
- package/dist/relayer-account.js.map +1 -0
- package/dist/spend-capped-account.d.ts +71 -0
- package/dist/spend-capped-account.d.ts.map +1 -0
- package/dist/spend-capped-account.js +181 -0
- package/dist/spend-capped-account.js.map +1 -0
- package/package.json +50 -19
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Hex } from './secp256k1-core.js';
|
|
2
|
+
export interface ProvisionPlan {
|
|
3
|
+
project: string;
|
|
4
|
+
location: string;
|
|
5
|
+
keyRing: string;
|
|
6
|
+
/** Opaque signing-identity labels → one HSM secp256k1 key each. NO vertical names here. */
|
|
7
|
+
identities: string[];
|
|
8
|
+
/** Service-account email to grant `roles/cloudkms.signer`, scoped per key. */
|
|
9
|
+
runtimeServiceAccount: string;
|
|
10
|
+
/** secp256k1 in GCP requires HSM; SOFTWARE is rejected by GCP for this curve. Default HSM. */
|
|
11
|
+
protectionLevel?: 'HSM' | 'SOFTWARE';
|
|
12
|
+
}
|
|
13
|
+
export type StepKind = 'create-keyring' | 'create-key' | 'grant-iam';
|
|
14
|
+
export interface GcloudStep {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: StepKind;
|
|
17
|
+
description: string;
|
|
18
|
+
/** argv for `gcloud` (no shell string — avoids injection). */
|
|
19
|
+
argv: string[];
|
|
20
|
+
/** Present for create-key / grant-iam steps. */
|
|
21
|
+
identity?: string;
|
|
22
|
+
/** The key resource this step targets (create-key / grant-iam). */
|
|
23
|
+
cryptoKeyName?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface StepExecutor {
|
|
26
|
+
/** Run a planned step. Return `{ alreadyExists: true }` to mark an idempotent skip
|
|
27
|
+
* (the resource already existed); throw for any real failure. */
|
|
28
|
+
run(step: GcloudStep): Promise<{
|
|
29
|
+
stdout: string;
|
|
30
|
+
alreadyExists?: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
/** Fetch a key version's SPKI PEM (for address verification) — via gcloud or REST. */
|
|
33
|
+
getPublicKeyPem(cryptoKeyVersionName: string): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
export interface ProvisionResult {
|
|
36
|
+
/** identity → full `…/cryptoKeyVersions/1` resource name. */
|
|
37
|
+
keyMap: Record<string, string>;
|
|
38
|
+
/** identity → derived EVM address (verify against expectations BEFORE wiring env). */
|
|
39
|
+
addresses: Record<string, Hex>;
|
|
40
|
+
granted: Array<{
|
|
41
|
+
key: string;
|
|
42
|
+
member: string;
|
|
43
|
+
role: 'roles/cloudkms.signer';
|
|
44
|
+
}>;
|
|
45
|
+
/** Step ids that were skipped because the resource already existed (idempotent re-run). */
|
|
46
|
+
alreadyExisted: string[];
|
|
47
|
+
}
|
|
48
|
+
/** First key version GCP creates for an asymmetric-signing key. */
|
|
49
|
+
export declare function keyVersionName(plan: ProvisionPlan, identity: string): string;
|
|
50
|
+
/** Emit the ordered gcloud steps for a provisioning plan. Pure — no execution. */
|
|
51
|
+
export declare function planGcpProvision(plan: ProvisionPlan): GcloudStep[];
|
|
52
|
+
/** Execute a provisioning plan through an injected executor. Idempotent: steps whose
|
|
53
|
+
* resource already exists are skipped and reported. After create+grant, fetches each
|
|
54
|
+
* key's public key and derives its EVM address so the operator can verify before wiring. */
|
|
55
|
+
export declare function executeGcpProvision(plan: ProvisionPlan, exec: StepExecutor): Promise<ProvisionResult>;
|
|
56
|
+
//# sourceMappingURL=provision-gcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-gcp.d.ts","sourceRoot":"","sources":["../../src/kms/provision-gcp.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,KAAK,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ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wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,EAAE,CA2DlE;AAED;;6FAE6F;AAC7F,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAuB3G"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// GCP Cloud KMS provisioning helper (spec 276 KCS-D3). Ports smart-agent's
|
|
2
|
+
// G-PR-6 operator runbook into a reusable, peer-dependency-free primitive.
|
|
3
|
+
//
|
|
4
|
+
// PURE PLANNING + INJECTED EXECUTION: `planGcpProvision` emits the gcloud steps;
|
|
5
|
+
// `executeGcpProvision` runs them through a caller-supplied `StepExecutor` (a
|
|
6
|
+
// gcloud runner, a REST runner, or a test fake). The package never shells out
|
|
7
|
+
// itself — that keeps it Workers-safe and unit-testable. The CLI (`bin/ap-provision-gcp.mjs`)
|
|
8
|
+
// supplies a Node child_process executor.
|
|
9
|
+
//
|
|
10
|
+
// No vertical identity names are baked in — `identities` are opaque labels the
|
|
11
|
+
// caller supplies (ADR-0021). Per-key (not per-keyring) IAM enforces master-key
|
|
12
|
+
// separation (key-custody CLAUDE.md invariant).
|
|
13
|
+
import { addressFromSpkiPem } from './secp256k1-core.js';
|
|
14
|
+
function keyResourceName(plan, identity) {
|
|
15
|
+
return `projects/${plan.project}/locations/${plan.location}/keyRings/${plan.keyRing}/cryptoKeys/${identity}`;
|
|
16
|
+
}
|
|
17
|
+
/** First key version GCP creates for an asymmetric-signing key. */
|
|
18
|
+
export function keyVersionName(plan, identity) {
|
|
19
|
+
return `${keyResourceName(plan, identity)}/cryptoKeyVersions/1`;
|
|
20
|
+
}
|
|
21
|
+
/** Emit the ordered gcloud steps for a provisioning plan. Pure — no execution. */
|
|
22
|
+
export function planGcpProvision(plan) {
|
|
23
|
+
if (!plan.project || !plan.location || !plan.keyRing) {
|
|
24
|
+
throw new Error('planGcpProvision: project, location, and keyRing are required');
|
|
25
|
+
}
|
|
26
|
+
if (!plan.runtimeServiceAccount.includes('@')) {
|
|
27
|
+
throw new Error('planGcpProvision: runtimeServiceAccount must be a service-account email');
|
|
28
|
+
}
|
|
29
|
+
if (plan.identities.length === 0)
|
|
30
|
+
throw new Error('planGcpProvision: at least one identity is required');
|
|
31
|
+
const dupes = plan.identities.filter((id, i) => plan.identities.indexOf(id) !== i);
|
|
32
|
+
if (dupes.length)
|
|
33
|
+
throw new Error(`planGcpProvision: duplicate identities: ${[...new Set(dupes)].join(', ')}`);
|
|
34
|
+
const protection = (plan.protectionLevel ?? 'HSM').toLowerCase();
|
|
35
|
+
const steps = [
|
|
36
|
+
{
|
|
37
|
+
id: 'keyring',
|
|
38
|
+
kind: 'create-keyring',
|
|
39
|
+
description: `Create key ring ${plan.keyRing} in ${plan.location}`,
|
|
40
|
+
argv: ['kms', 'keyrings', 'create', plan.keyRing, '--location', plan.location, '--project', plan.project],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
for (const identity of plan.identities) {
|
|
44
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(identity)) {
|
|
45
|
+
throw new Error(`planGcpProvision: identity "${identity}" must match [a-zA-Z0-9_-]+ (a GCP key id)`);
|
|
46
|
+
}
|
|
47
|
+
const cryptoKeyName = keyResourceName(plan, identity);
|
|
48
|
+
steps.push({
|
|
49
|
+
id: `key:${identity}`,
|
|
50
|
+
kind: 'create-key',
|
|
51
|
+
identity,
|
|
52
|
+
cryptoKeyName,
|
|
53
|
+
description: `Create HSM secp256k1 signing key ${identity}`,
|
|
54
|
+
argv: [
|
|
55
|
+
'kms', 'keys', 'create', identity,
|
|
56
|
+
'--keyring', plan.keyRing,
|
|
57
|
+
'--location', plan.location,
|
|
58
|
+
'--project', plan.project,
|
|
59
|
+
'--purpose', 'asymmetric-signing',
|
|
60
|
+
'--default-algorithm', 'ec-sign-secp256k1-sha256',
|
|
61
|
+
'--protection-level', protection,
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
steps.push({
|
|
65
|
+
id: `iam:${identity}`,
|
|
66
|
+
kind: 'grant-iam',
|
|
67
|
+
identity,
|
|
68
|
+
cryptoKeyName,
|
|
69
|
+
description: `Grant roles/cloudkms.signer on ${identity} to ${plan.runtimeServiceAccount}`,
|
|
70
|
+
argv: [
|
|
71
|
+
'kms', 'keys', 'add-iam-policy-binding', identity,
|
|
72
|
+
'--keyring', plan.keyRing,
|
|
73
|
+
'--location', plan.location,
|
|
74
|
+
'--project', plan.project,
|
|
75
|
+
'--member', `serviceAccount:${plan.runtimeServiceAccount}`,
|
|
76
|
+
'--role', 'roles/cloudkms.signer',
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return steps;
|
|
81
|
+
}
|
|
82
|
+
/** Execute a provisioning plan through an injected executor. Idempotent: steps whose
|
|
83
|
+
* resource already exists are skipped and reported. After create+grant, fetches each
|
|
84
|
+
* key's public key and derives its EVM address so the operator can verify before wiring. */
|
|
85
|
+
export async function executeGcpProvision(plan, exec) {
|
|
86
|
+
const steps = planGcpProvision(plan);
|
|
87
|
+
const alreadyExisted = [];
|
|
88
|
+
const granted = [];
|
|
89
|
+
for (const step of steps) {
|
|
90
|
+
const r = await exec.run(step);
|
|
91
|
+
if (r.alreadyExists)
|
|
92
|
+
alreadyExisted.push(step.id);
|
|
93
|
+
if (step.kind === 'grant-iam' && step.cryptoKeyName) {
|
|
94
|
+
granted.push({ key: step.cryptoKeyName, member: `serviceAccount:${plan.runtimeServiceAccount}`, role: 'roles/cloudkms.signer' });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const keyMap = {};
|
|
98
|
+
const addresses = {};
|
|
99
|
+
for (const identity of plan.identities) {
|
|
100
|
+
const versionName = keyVersionName(plan, identity);
|
|
101
|
+
keyMap[identity] = versionName;
|
|
102
|
+
const pem = await exec.getPublicKeyPem(versionName);
|
|
103
|
+
addresses[identity] = addressFromSpkiPem(pem);
|
|
104
|
+
}
|
|
105
|
+
return { keyMap, addresses, granted, alreadyExisted };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=provision-gcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-gcp.js","sourceRoot":"","sources":["../../src/kms/provision-gcp.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,EAAE;AACF,iFAAiF;AACjF,8EAA8E;AAC9E,8EAA8E;AAC9E,8FAA8F;AAC9F,0CAA0C;AAC1C,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,gDAAgD;AAEhD,OAAO,EAAE,kBAAkB,EAAY,MAAM,qBAAqB,CAAC;AA8CnE,SAAS,eAAe,CAAC,IAAmB,EAAE,QAAgB;IAC5D,OAAO,YAAY,IAAI,CAAC,OAAO,cAAc,IAAI,CAAC,QAAQ,aAAa,IAAI,CAAC,OAAO,eAAe,QAAQ,EAAE,CAAC;AAC/G,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,IAAmB,EAAE,QAAgB;IAClE,OAAO,GAAG,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,CAAC;AAClE,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,IAAI,CA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CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACpD,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,kBAAkB,IAAI,CAAC,qBAAqB,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC,CAAC;QACnI,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAwB,EAAE,CAAC;IAC1C,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnD,MAAM,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC;QAC/B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACpD,SAAS,CAAC,QAAQ,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** A 0x-prefixed lowercase hex string (structurally compatible with viem's `Hex`/`Address`). */
|
|
2
|
+
export type Hex = `0x${string}`;
|
|
3
|
+
/** Bytes → `0x`-prefixed lowercase hex. Byte-for-byte compatible with viem's `bytesToHex`. */
|
|
4
|
+
export declare function bytesToHex(bytes: Uint8Array): Hex;
|
|
5
|
+
export declare function base64UrlEncode(bytes: Uint8Array): string;
|
|
6
|
+
export declare function base64Decode(s: string): Uint8Array;
|
|
7
|
+
export declare function base64Encode(bytes: Uint8Array): string;
|
|
8
|
+
export declare function pemToDer(pem: string): Uint8Array;
|
|
9
|
+
export declare function bigIntTo32Bytes(n: bigint): Uint8Array;
|
|
10
|
+
/** Parse a DER-encoded ECDSA signature → `(r, s)`. Range-validates `0 < r,s < n`
|
|
11
|
+
* (audit F-7): a degenerate KMS response (r/s = 0 or ≥ n) is never valid — fail closed. */
|
|
12
|
+
export declare function parseDerEcdsa(der: Uint8Array): {
|
|
13
|
+
r: bigint;
|
|
14
|
+
s: bigint;
|
|
15
|
+
};
|
|
16
|
+
/** spec-276 alias for {@link parseDerEcdsa}. */
|
|
17
|
+
export declare const parseDerEcdsaSignature: typeof parseDerEcdsa;
|
|
18
|
+
/** Normalize `s` to its low-s form (EIP-2): malleability-canonical signatures only. */
|
|
19
|
+
export declare function normalizeLowS(s: bigint): bigint;
|
|
20
|
+
/** spec-276 alias for {@link normalizeLowS}. */
|
|
21
|
+
export declare const toLowS: typeof normalizeLowS;
|
|
22
|
+
/** Extract the trailing 65-byte uncompressed secp256k1 point (`0x04||X||Y`) from an SPKI DER blob. */
|
|
23
|
+
export declare function parseSpkiUncompressedSecp256k1PubKey(spkiDer: Uint8Array): Uint8Array;
|
|
24
|
+
/** `0x04||X||Y` (65 bytes) → EVM address (`keccak256(X||Y)[-20:]`). */
|
|
25
|
+
export declare function publicKeyToAddress(pubKey65: Uint8Array): Hex;
|
|
26
|
+
/** Convenience: SPKI PEM (the Cloud KMS `publicKey` response) → EVM address. */
|
|
27
|
+
export declare function addressFromSpkiPem(pem: string): Hex;
|
|
28
|
+
/** Cloud KMS does not return the recovery bit; recover it by trying v∈{27,28}
|
|
29
|
+
* against the known uncompressed public key. Throws (redacted error) if neither matches. */
|
|
30
|
+
export declare function findRecoveryByte(r: bigint, s: bigint, digest: Uint8Array, knownPubKey65: Uint8Array): number;
|
|
31
|
+
/** spec-276 ordering of {@link findRecoveryByte}: `(digest, r, s, knownPubKey65)`. */
|
|
32
|
+
export declare function recoverV(digest: Uint8Array, r: bigint, s: bigint, knownPubKey65: Uint8Array): 27 | 28;
|
|
33
|
+
/** Assemble an Ethereum 65-byte `(r,s,v)` signature as 0x hex. */
|
|
34
|
+
export declare function assembleEthSignature(r: bigint, s: bigint, v: number): Hex;
|
|
35
|
+
/** Turn a raw KMS asymmetric-sign (DER output) into an Ethereum `(r,s,v)` signature.
|
|
36
|
+
* Transport is INJECTED (`asymmetricSign`) so this stays peer-dependency-free and
|
|
37
|
+
* testable: the caller supplies however it reaches Cloud KMS. Returns 0x-hex 65 bytes. */
|
|
38
|
+
export declare function signDigestWithKms(opts: {
|
|
39
|
+
/** The 32-byte keccak digest to sign. */
|
|
40
|
+
digest: Uint8Array;
|
|
41
|
+
/** The signing key's SPKI PEM (the Cloud KMS `publicKey` response `.pem`). Cached by the caller. */
|
|
42
|
+
publicKeyPem: string;
|
|
43
|
+
/** Calls Cloud KMS `:asymmetricSign` for the digest; returns the DER-encoded signature bytes. */
|
|
44
|
+
asymmetricSign: (digest: Uint8Array) => Promise<Uint8Array>;
|
|
45
|
+
}): Promise<Hex>;
|
|
46
|
+
//# sourceMappingURL=secp256k1-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secp256k1-core.d.ts","sourceRoot":"","sources":["../../src/kms/secp256k1-core.ts"],"names":[],"mappings":"AAwBA,gGAAgG;AAChG,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAIhC,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAIjD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIzD;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAKlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAItD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAMhD;AAUD,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAQrD;AAID;4FAC4F;AAC5F,wBAAgB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OAAO,CAAC,GAAG,CAAC,CAUf"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// secp256k1 KMS signing core — the CONSUMER-SAFE, peer-dependency-free surface (spec 276 KCS-D1).
|
|
2
|
+
//
|
|
3
|
+
// This module contains the raw cryptography for turning a Cloud-KMS-style
|
|
4
|
+
// secp256k1 asymmetric signature into an Ethereum-compatible 65-byte
|
|
5
|
+
// `(r,s,v)` signature, plus SPKI public-key → address derivation. It is the
|
|
6
|
+
// extract that lets an external consumer import the primitive instead of
|
|
7
|
+
// inlining a copy (the demo-validator `kms-signer.ts` problem).
|
|
8
|
+
//
|
|
9
|
+
// HARD CONSTRAINT (enforced by test/unit/kms-core-import-graph.test.ts):
|
|
10
|
+
// This file and everything it imports MUST depend ONLY on `@noble/curves`,
|
|
11
|
+
// `@noble/hashes`, and Web/Node built-ins. NO `viem`, NO `@agenticprimitives/*`.
|
|
12
|
+
// That is the entire point — a standalone external app can import
|
|
13
|
+
// `@agenticprimitives/key-custody/kms-core` with no viem / audit / connect-auth peer install.
|
|
14
|
+
//
|
|
15
|
+
// The audited, viem-typed `GcpKmsSigner` (providers/gcp.ts) is a thin wrapper
|
|
16
|
+
// over this core — one implementation, two surfaces (no second KMS path).
|
|
17
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
18
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
19
|
+
// ── secp256k1 constants ──────────────────────────────────────────────
|
|
20
|
+
const SECP256K1_N = secp256k1.Point.Fn.ORDER;
|
|
21
|
+
const SECP256K1_HALF_N = SECP256K1_N >> 1n;
|
|
22
|
+
// ── hex / base64 / PEM helpers (viem-free) ───────────────────────────
|
|
23
|
+
/** Bytes → `0x`-prefixed lowercase hex. Byte-for-byte compatible with viem's `bytesToHex`. */
|
|
24
|
+
export function bytesToHex(bytes) {
|
|
25
|
+
let h = '';
|
|
26
|
+
for (let i = 0; i < bytes.length; i++)
|
|
27
|
+
h += bytes[i].toString(16).padStart(2, '0');
|
|
28
|
+
return `0x${h}`;
|
|
29
|
+
}
|
|
30
|
+
export function base64UrlEncode(bytes) {
|
|
31
|
+
let str = '';
|
|
32
|
+
for (let i = 0; i < bytes.length; i++)
|
|
33
|
+
str += String.fromCharCode(bytes[i]);
|
|
34
|
+
return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
35
|
+
}
|
|
36
|
+
export function base64Decode(s) {
|
|
37
|
+
const binary = atob(s);
|
|
38
|
+
const out = new Uint8Array(binary.length);
|
|
39
|
+
for (let i = 0; i < binary.length; i++)
|
|
40
|
+
out[i] = binary.charCodeAt(i);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
export function base64Encode(bytes) {
|
|
44
|
+
let str = '';
|
|
45
|
+
for (let i = 0; i < bytes.length; i++)
|
|
46
|
+
str += String.fromCharCode(bytes[i]);
|
|
47
|
+
return btoa(str);
|
|
48
|
+
}
|
|
49
|
+
export function pemToDer(pem) {
|
|
50
|
+
const lines = pem
|
|
51
|
+
.split('\n')
|
|
52
|
+
.filter((l) => !l.startsWith('-----') && l.trim().length > 0)
|
|
53
|
+
.join('');
|
|
54
|
+
return base64Decode(lines);
|
|
55
|
+
}
|
|
56
|
+
// ── bigint <-> bytes ─────────────────────────────────────────────────
|
|
57
|
+
function bytesToBigInt(bytes) {
|
|
58
|
+
let n = 0n;
|
|
59
|
+
for (const b of bytes)
|
|
60
|
+
n = (n << 8n) | BigInt(b);
|
|
61
|
+
return n;
|
|
62
|
+
}
|
|
63
|
+
export function bigIntTo32Bytes(n) {
|
|
64
|
+
const out = new Uint8Array(32);
|
|
65
|
+
let v = n;
|
|
66
|
+
for (let i = 31; i >= 0; i--) {
|
|
67
|
+
out[i] = Number(v & 0xffn);
|
|
68
|
+
v >>= 8n;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
// ── DER ECDSA signature parsing ──────────────────────────────────────
|
|
73
|
+
/** Parse a DER-encoded ECDSA signature → `(r, s)`. Range-validates `0 < r,s < n`
|
|
74
|
+
* (audit F-7): a degenerate KMS response (r/s = 0 or ≥ n) is never valid — fail closed. */
|
|
75
|
+
export function parseDerEcdsa(der) {
|
|
76
|
+
const at = (idx) => {
|
|
77
|
+
const b = der[idx];
|
|
78
|
+
if (b === undefined)
|
|
79
|
+
throw new Error(`DER: unexpected end of buffer at offset ${idx}`);
|
|
80
|
+
return b;
|
|
81
|
+
};
|
|
82
|
+
let i = 0;
|
|
83
|
+
if (at(i++) !== 0x30)
|
|
84
|
+
throw new Error('DER: expected SEQUENCE tag (0x30)');
|
|
85
|
+
// Skip length. Handle short and long form.
|
|
86
|
+
const lenByte = at(i++);
|
|
87
|
+
if (lenByte & 0x80) {
|
|
88
|
+
const lenBytes = lenByte & 0x7f;
|
|
89
|
+
i += lenBytes;
|
|
90
|
+
}
|
|
91
|
+
if (at(i++) !== 0x02)
|
|
92
|
+
throw new Error('DER: expected INTEGER tag for r');
|
|
93
|
+
const rLen = at(i++);
|
|
94
|
+
const rBytes = der.slice(i, i + rLen);
|
|
95
|
+
i += rLen;
|
|
96
|
+
if (at(i++) !== 0x02)
|
|
97
|
+
throw new Error('DER: expected INTEGER tag for s');
|
|
98
|
+
const sLen = at(i++);
|
|
99
|
+
const sBytes = der.slice(i, i + sLen);
|
|
100
|
+
const r = bytesToBigInt(rBytes);
|
|
101
|
+
const s = bytesToBigInt(sBytes);
|
|
102
|
+
if (r <= 0n || r >= SECP256K1_N || s <= 0n || s >= SECP256K1_N) {
|
|
103
|
+
throw new Error('DER: r/s out of range (require 0 < r,s < n)');
|
|
104
|
+
}
|
|
105
|
+
return { r, s };
|
|
106
|
+
}
|
|
107
|
+
/** spec-276 alias for {@link parseDerEcdsa}. */
|
|
108
|
+
export const parseDerEcdsaSignature = parseDerEcdsa;
|
|
109
|
+
/** Normalize `s` to its low-s form (EIP-2): malleability-canonical signatures only. */
|
|
110
|
+
export function normalizeLowS(s) {
|
|
111
|
+
return s > SECP256K1_HALF_N ? SECP256K1_N - s : s;
|
|
112
|
+
}
|
|
113
|
+
/** spec-276 alias for {@link normalizeLowS}. */
|
|
114
|
+
export const toLowS = normalizeLowS;
|
|
115
|
+
// ── SPKI public-key parsing + address derivation ─────────────────────
|
|
116
|
+
/** Extract the trailing 65-byte uncompressed secp256k1 point (`0x04||X||Y`) from an SPKI DER blob. */
|
|
117
|
+
export function parseSpkiUncompressedSecp256k1PubKey(spkiDer) {
|
|
118
|
+
if (spkiDer.length < 66) {
|
|
119
|
+
throw new Error(`SPKI too short to contain uncompressed secp256k1 pubkey: ${spkiDer.length} bytes`);
|
|
120
|
+
}
|
|
121
|
+
const tail = spkiDer.slice(spkiDer.length - 65);
|
|
122
|
+
const marker = tail[0];
|
|
123
|
+
if (marker !== 0x04) {
|
|
124
|
+
throw new Error(`SPKI does not end with uncompressed point marker (0x04). Wrong key algorithm? ` +
|
|
125
|
+
`Found 0x${(marker ?? 0).toString(16).padStart(2, '0')} at position ${spkiDer.length - 65}.`);
|
|
126
|
+
}
|
|
127
|
+
return tail;
|
|
128
|
+
}
|
|
129
|
+
/** `0x04||X||Y` (65 bytes) → EVM address (`keccak256(X||Y)[-20:]`). */
|
|
130
|
+
export function publicKeyToAddress(pubKey65) {
|
|
131
|
+
const raw = pubKey65.slice(1);
|
|
132
|
+
const hash = keccak_256(raw);
|
|
133
|
+
return bytesToHex(hash.slice(12));
|
|
134
|
+
}
|
|
135
|
+
/** Convenience: SPKI PEM (the Cloud KMS `publicKey` response) → EVM address. */
|
|
136
|
+
export function addressFromSpkiPem(pem) {
|
|
137
|
+
return publicKeyToAddress(parseSpkiUncompressedSecp256k1PubKey(pemToDer(pem)));
|
|
138
|
+
}
|
|
139
|
+
// ── recovery-byte search ─────────────────────────────────────────────
|
|
140
|
+
function bytesEqual(a, b) {
|
|
141
|
+
if (a.length !== b.length)
|
|
142
|
+
return false;
|
|
143
|
+
for (let i = 0; i < a.length; i++)
|
|
144
|
+
if (a[i] !== b[i])
|
|
145
|
+
return false;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/** Cloud KMS does not return the recovery bit; recover it by trying v∈{27,28}
|
|
149
|
+
* against the known uncompressed public key. Throws (redacted error) if neither matches. */
|
|
150
|
+
export function findRecoveryByte(r, s, digest, knownPubKey65) {
|
|
151
|
+
const rBytes = bigIntTo32Bytes(r);
|
|
152
|
+
const sBytes = bigIntTo32Bytes(s);
|
|
153
|
+
const compact = new Uint8Array(64);
|
|
154
|
+
compact.set(rBytes, 0);
|
|
155
|
+
compact.set(sBytes, 32);
|
|
156
|
+
const attempts = [];
|
|
157
|
+
for (let recovery = 0; recovery < 2; recovery++) {
|
|
158
|
+
try {
|
|
159
|
+
const sig = secp256k1.Signature.fromBytes(compact).addRecoveryBit(recovery);
|
|
160
|
+
const recovered = sig.recoverPublicKey(digest).toBytes(false);
|
|
161
|
+
attempts.push(`v=${recovery + 27} recovered=${bytesToHex(recovered)}`);
|
|
162
|
+
if (bytesEqual(recovered, knownPubKey65))
|
|
163
|
+
return recovery + 27;
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
attempts.push(`v=${recovery + 27} threw ${e instanceof Error ? e.message : String(e)}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Redact operational fingerprints (digest/pubkey are chain-correlatable / long-lived
|
|
170
|
+
// identity) to keccak-prefix-8 — still actionable, no raw values leaked (PKG-KEY-CUSTODY-004).
|
|
171
|
+
const tag = (label, b) => `${label}=${bytesToHex(keccak_256(b)).slice(0, 8)}`;
|
|
172
|
+
// eslint-disable-next-line no-console
|
|
173
|
+
console.error('[gcp-kms findRecoveryByte] mismatch:', {
|
|
174
|
+
digestTag: tag('k', digest),
|
|
175
|
+
rTag: tag('k', rBytes),
|
|
176
|
+
sTag: tag('k', sBytes),
|
|
177
|
+
knownPubKeyTag: tag('k', knownPubKey65),
|
|
178
|
+
attempts,
|
|
179
|
+
});
|
|
180
|
+
throw new Error('Recovery byte search failed: neither v=27 nor v=28 recovers the known public key. ' + attempts.join(' | '));
|
|
181
|
+
}
|
|
182
|
+
/** spec-276 ordering of {@link findRecoveryByte}: `(digest, r, s, knownPubKey65)`. */
|
|
183
|
+
export function recoverV(digest, r, s, knownPubKey65) {
|
|
184
|
+
return findRecoveryByte(r, s, digest, knownPubKey65);
|
|
185
|
+
}
|
|
186
|
+
/** Assemble an Ethereum 65-byte `(r,s,v)` signature as 0x hex. */
|
|
187
|
+
export function assembleEthSignature(r, s, v) {
|
|
188
|
+
const sig65 = new Uint8Array(65);
|
|
189
|
+
sig65.set(bigIntTo32Bytes(r), 0);
|
|
190
|
+
sig65.set(bigIntTo32Bytes(s), 32);
|
|
191
|
+
sig65[64] = v;
|
|
192
|
+
return bytesToHex(sig65);
|
|
193
|
+
}
|
|
194
|
+
// ── high-level: digest → eth signature, transport injected ───────────
|
|
195
|
+
/** Turn a raw KMS asymmetric-sign (DER output) into an Ethereum `(r,s,v)` signature.
|
|
196
|
+
* Transport is INJECTED (`asymmetricSign`) so this stays peer-dependency-free and
|
|
197
|
+
* testable: the caller supplies however it reaches Cloud KMS. Returns 0x-hex 65 bytes. */
|
|
198
|
+
export async function signDigestWithKms(opts) {
|
|
199
|
+
if (opts.digest.length !== 32) {
|
|
200
|
+
throw new Error(`signDigestWithKms expects a 32-byte digest; got ${opts.digest.length}.`);
|
|
201
|
+
}
|
|
202
|
+
const pub65 = parseSpkiUncompressedSecp256k1PubKey(pemToDer(opts.publicKeyPem));
|
|
203
|
+
const der = await opts.asymmetricSign(opts.digest);
|
|
204
|
+
const { r, s: rawS } = parseDerEcdsa(der);
|
|
205
|
+
const s = normalizeLowS(rawS);
|
|
206
|
+
const v = recoverV(opts.digest, r, s, pub65);
|
|
207
|
+
return assembleEthSignature(r, s, v);
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=secp256k1-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secp256k1-core.js","sourceRoot":"","sources":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,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,mDAAmD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5F,CAAC;IACD,MAAM,KAAK,GAAG,oCAAoC,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,OAAO,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/providers/aws.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { A2AKeyProvider, KmsAccountBackend } from '../types';
|
|
2
2
|
import type { Address } from '@agenticprimitives/types';
|
|
3
|
+
export declare const AWS_KMS_NOT_IMPLEMENTED: string;
|
|
3
4
|
export declare class AwsKmsProvider implements A2AKeyProvider {
|
|
4
5
|
readonly keyVersion = "aws-kms:not-implemented";
|
|
6
|
+
constructor();
|
|
5
7
|
generateSessionDataKey(): Promise<never>;
|
|
6
8
|
decryptSessionDataKey(): Promise<never>;
|
|
7
9
|
}
|
|
8
10
|
export declare class AwsKmsSigner implements KmsAccountBackend {
|
|
9
11
|
readonly provider: "aws-kms";
|
|
12
|
+
constructor();
|
|
10
13
|
signA2AAction(): Promise<never>;
|
|
11
14
|
getSignerAddress(): Promise<Address>;
|
|
12
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../src/providers/aws.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../src/providers/aws.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,eAAO,MAAM,uBAAuB,QAEyE,CAAC;AAE9G,qBAAa,cAAe,YAAW,cAAc;IACnD,QAAQ,CAAC,UAAU,6BAA6B;;IAG1C,sBAAsB,IAAI,OAAO,CAAC,KAAK,CAAC;IACxC,qBAAqB,IAAI,OAAO,CAAC,KAAK,CAAC;CAC9C;AAED,qBAAa,YAAa,YAAW,iBAAiB;IACpD,QAAQ,CAAC,QAAQ,EAAG,SAAS,CAAU;;IAGjC,aAAa,IAAI,OAAO,CAAC,KAAK,CAAC;IAC/B,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;CAC3C"}
|
package/dist/providers/aws.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
// AwsKmsProvider / AwsKmsSigner —
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// AwsKmsProvider / AwsKmsSigner — AWS KMS backend (NOT YET IMPLEMENTED).
|
|
2
|
+
//
|
|
3
|
+
// AUDIT N-2: these must FAIL FAST. Previously the classes constructed cleanly and threw only on the
|
|
4
|
+
// first signing/encryption call — a deferred-failure footgun: an operator who selects `aws-kms` for a
|
|
5
|
+
// real deployment boots fine and explodes on the first hot-path op. Per the package's "fail-closed at
|
|
6
|
+
// boot" invariant (CLAUDE.md security invariants), construction now throws. Only `gcp-kms` is
|
|
7
|
+
// production-ready (spec 214 §5 is single-chain GCP-KMS); `aws-kms` is reserved, not wired.
|
|
8
|
+
export const AWS_KMS_NOT_IMPLEMENTED = '[key-custody] aws-kms backend is not implemented. Use backend "gcp-kms" for real deploys ' +
|
|
9
|
+
'(the only production-ready KMS, spec 214 §5) or "local-aes" for dev. `aws-kms` is reserved but not wired.';
|
|
4
10
|
export class AwsKmsProvider {
|
|
5
11
|
keyVersion = 'aws-kms:not-implemented';
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
// Fail fast at construction (N-2) rather than on the first generate/decrypt call.
|
|
13
|
+
constructor() { throw new Error(AWS_KMS_NOT_IMPLEMENTED); }
|
|
14
|
+
async generateSessionDataKey() { throw new Error(AWS_KMS_NOT_IMPLEMENTED); }
|
|
15
|
+
async decryptSessionDataKey() { throw new Error(AWS_KMS_NOT_IMPLEMENTED); }
|
|
8
16
|
}
|
|
9
17
|
export class AwsKmsSigner {
|
|
10
18
|
provider = 'aws-kms';
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
// Fail fast at construction (N-2) rather than on the first sign/getSignerAddress call.
|
|
20
|
+
constructor() { throw new Error(AWS_KMS_NOT_IMPLEMENTED); }
|
|
21
|
+
async signA2AAction() { throw new Error(AWS_KMS_NOT_IMPLEMENTED); }
|
|
22
|
+
async getSignerAddress() { throw new Error(AWS_KMS_NOT_IMPLEMENTED); }
|
|
13
23
|
}
|
|
14
24
|
//# sourceMappingURL=aws.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.js","sourceRoot":"","sources":["../../src/providers/aws.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"aws.js","sourceRoot":"","sources":["../../src/providers/aws.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,oGAAoG;AACpG,sGAAsG;AACtG,sGAAsG;AACtG,8FAA8F;AAC9F,4FAA4F;AAK5F,MAAM,CAAC,MAAM,uBAAuB,GAClC,2FAA2F;IAC3F,2GAA2G,CAAC;AAE9G,MAAM,OAAO,cAAc;IAChB,UAAU,GAAG,yBAAyB,CAAC;IAChD,kFAAkF;IAClF,gBAAgB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC3D,KAAK,CAAC,sBAAsB,KAAqB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC5F,KAAK,CAAC,qBAAqB,KAAqB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;CAC5F;AAED,MAAM,OAAO,YAAY;IACd,QAAQ,GAAG,SAAkB,CAAC;IACvC,uFAAuF;IACvF,gBAAgB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC3D,KAAK,CAAC,aAAa,KAAqB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IACnF,KAAK,CAAC,gBAAgB,KAAuB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;CACzF"}
|
package/dist/providers/gcp.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
2
|
import { type AuditSink } from '@agenticprimitives/audit';
|
|
3
3
|
import type { A2AKeyProvider, KmsAccountBackend } from '../types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** PEM-encoded PKCS#8 RSA private key. */
|
|
7
|
-
private_key: string;
|
|
8
|
-
project_id?: string;
|
|
9
|
-
}
|
|
10
|
-
interface CachedToken {
|
|
11
|
-
accessToken: string;
|
|
12
|
-
/** Unix seconds at which the token must be refreshed (already minus buffer). */
|
|
13
|
-
expiresAt: number;
|
|
14
|
-
}
|
|
4
|
+
export { base64UrlEncode, pemToDer, parseDerEcdsa, normalizeLowS, bigIntTo32Bytes, parseSpkiUncompressedSecp256k1PubKey, publicKeyToAddress, findRecoveryByte, } from '../kms/secp256k1-core.js';
|
|
5
|
+
export { signJwt, fetchAccessToken } from '../kms/gcp-transport.js';
|
|
15
6
|
export interface GcpKmsSignerOpts {
|
|
16
7
|
/**
|
|
17
8
|
* Full Cloud KMS resource name of the key version to sign with, e.g.
|
|
@@ -22,31 +13,16 @@ export interface GcpKmsSignerOpts {
|
|
|
22
13
|
/** Raw JSON string of the service-account key file. */
|
|
23
14
|
serviceAccountJson: string;
|
|
24
15
|
}
|
|
25
|
-
export declare function base64UrlEncode(bytes: Uint8Array): string;
|
|
26
|
-
export declare function pemToDer(pem: string): Uint8Array;
|
|
27
|
-
export declare function signJwt(serviceAccount: ServiceAccount, scope: string): Promise<string>;
|
|
28
|
-
export declare function fetchAccessToken(serviceAccount: ServiceAccount): Promise<CachedToken>;
|
|
29
|
-
export declare function parseSpkiUncompressedSecp256k1PubKey(spkiDer: Uint8Array): Uint8Array;
|
|
30
|
-
export declare function publicKeyToAddress(pubKey65: Uint8Array): Address;
|
|
31
|
-
export declare function parseDerEcdsa(der: Uint8Array): {
|
|
32
|
-
r: bigint;
|
|
33
|
-
s: bigint;
|
|
34
|
-
};
|
|
35
|
-
export declare function bigIntTo32Bytes(n: bigint): Uint8Array;
|
|
36
|
-
export declare function normalizeLowS(s: bigint): bigint;
|
|
37
|
-
export declare function findRecoveryByte(r: bigint, s: bigint, digest: Uint8Array, knownPubKey65: Uint8Array): number;
|
|
38
16
|
export declare class GcpKmsSigner implements KmsAccountBackend {
|
|
39
17
|
readonly provider: "gcp-kms";
|
|
40
18
|
private readonly keyName;
|
|
41
|
-
private readonly
|
|
19
|
+
private readonly transport;
|
|
42
20
|
private readonly auditSink?;
|
|
43
|
-
private cachedToken?;
|
|
44
21
|
private cachedPubKey65?;
|
|
45
22
|
private cachedAddress?;
|
|
46
23
|
constructor(opts?: Partial<GcpKmsSignerOpts> & {
|
|
47
24
|
auditSink?: AuditSink;
|
|
48
25
|
});
|
|
49
|
-
private getAccessToken;
|
|
50
26
|
private getPublicKeyBytes;
|
|
51
27
|
getSignerAddress(): Promise<Address>;
|
|
52
28
|
signA2AAction(input: {
|
|
@@ -73,11 +49,7 @@ export interface GcpKmsProviderOpts {
|
|
|
73
49
|
serviceAccountJson: string;
|
|
74
50
|
}
|
|
75
51
|
export declare class GcpKmsProvider implements A2AKeyProvider {
|
|
76
|
-
/**
|
|
77
|
-
* H7-F.4: this default is now ONLY used when the GCP encrypt response
|
|
78
|
-
* doesn't carry a `name` field (test fixtures + offline mocks). Real
|
|
79
|
-
* runs derive `keyVersion` from the response per call.
|
|
80
|
-
*/
|
|
52
|
+
/** Only used when the GCP encrypt response doesn't carry a `name` (test fixtures). */
|
|
81
53
|
readonly keyVersion = "gcp-kms:unknown";
|
|
82
54
|
private readonly keyName;
|
|
83
55
|
private readonly serviceAccount;
|
|
@@ -99,5 +71,4 @@ export declare class GcpKmsProvider implements A2AKeyProvider {
|
|
|
99
71
|
keyVersion: string;
|
|
100
72
|
}): Promise<Uint8Array>;
|
|
101
73
|
}
|
|
102
|
-
export {};
|
|
103
74
|
//# sourceMappingURL=gcp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcp.d.ts","sourceRoot":"","sources":["../../src/providers/gcp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gcp.d.ts","sourceRoot":"","sources":["../../src/providers/gcp.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AA0BlE,OAAO,EACL,eAAe,EACf,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,oCAAoC,EACpC,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAMD,qBAAa,YA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