@hawcx/oauth-client 0.2.0 → 5.1.0
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 +587 -204
- package/dist/client-assertion.d.ts +45 -0
- package/dist/client-assertion.d.ts.map +1 -0
- package/dist/client-assertion.js +141 -0
- package/dist/client-assertion.js.map +1 -0
- package/dist/delegation/credentials.d.ts +92 -0
- package/dist/delegation/credentials.d.ts.map +1 -0
- package/dist/delegation/credentials.js +215 -0
- package/dist/delegation/credentials.js.map +1 -0
- package/dist/delegation/crypto.d.ts +2 -2
- package/dist/delegation/crypto.d.ts.map +1 -1
- package/dist/delegation/crypto.js +41 -32
- package/dist/delegation/crypto.js.map +1 -1
- package/dist/delegation/exceptions.d.ts +12 -5
- package/dist/delegation/exceptions.d.ts.map +1 -1
- package/dist/delegation/exceptions.js +12 -14
- package/dist/delegation/exceptions.js.map +1 -1
- package/dist/delegation/factory.d.ts +20 -0
- package/dist/delegation/factory.d.ts.map +1 -0
- package/dist/delegation/factory.js +49 -0
- package/dist/delegation/factory.js.map +1 -0
- package/dist/delegation/hawcx.d.ts +59 -224
- package/dist/delegation/hawcx.d.ts.map +1 -1
- package/dist/delegation/hawcx.js +99 -299
- package/dist/delegation/hawcx.js.map +1 -1
- package/dist/delegation/index.d.ts +4 -9
- package/dist/delegation/index.d.ts.map +1 -1
- package/dist/delegation/index.js +5 -17
- package/dist/delegation/index.js.map +1 -1
- package/dist/delegation/transport.d.ts +40 -0
- package/dist/delegation/transport.d.ts.map +1 -0
- package/dist/delegation/transport.js +120 -0
- package/dist/delegation/transport.js.map +1 -0
- package/dist/errors.d.ts +62 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +73 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -27
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +265 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +497 -0
- package/dist/oauth.js.map +1 -0
- package/dist/stepup/client.d.ts +26 -0
- package/dist/stepup/client.d.ts.map +1 -0
- package/dist/stepup/client.js +78 -0
- package/dist/stepup/client.js.map +1 -0
- package/dist/stepup/index.d.ts +3 -0
- package/dist/stepup/index.d.ts.map +1 -0
- package/dist/stepup/index.js +19 -0
- package/dist/stepup/index.js.map +1 -0
- package/dist/stepup/types.d.ts +35 -0
- package/dist/stepup/types.d.ts.map +1 -0
- package/dist/stepup/types.js +3 -0
- package/dist/stepup/types.js.map +1 -0
- package/package.json +13 -16
- package/dist/client.d.ts +0 -134
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -300
- package/dist/client.js.map +0 -1
- package/dist/delegation/client.d.ts +0 -116
- package/dist/delegation/client.d.ts.map +0 -1
- package/dist/delegation/client.js +0 -227
- package/dist/delegation/client.js.map +0 -1
- package/dist/exceptions.d.ts +0 -52
- package/dist/exceptions.d.ts.map +0 -1
- package/dist/exceptions.js +0 -81
- package/dist/exceptions.js.map +0 -1
- package/dist/utils.d.ts +0 -61
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -263
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { KeyObject } from 'node:crypto';
|
|
2
|
+
import { type JWK } from 'jose';
|
|
3
|
+
/** RFC 7523 §2.2 assertion type for the `private_key_jwt` method. */
|
|
4
|
+
export declare const CLIENT_ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
|
|
5
|
+
export declare class ClientAssertionSigner {
|
|
6
|
+
private readonly importKeyFn;
|
|
7
|
+
private readonly kid;
|
|
8
|
+
private readonly lifetimeSeconds;
|
|
9
|
+
/** Lazily-imported signing key, memoised across sign() calls. */
|
|
10
|
+
private keyPromise?;
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Build a signer from an Ed25519 *private* JWK (RFC 8037):
|
|
14
|
+
* `{ kty: 'OKP', crv: 'Ed25519', d, x, kid }`. The `kid` is read from the
|
|
15
|
+
* JWK. This is the canonical Hawcx key format (what the admin console
|
|
16
|
+
* generates/downloads). Accepts either a JWK object or its JSON string.
|
|
17
|
+
*/
|
|
18
|
+
static ed25519FromJwk(privateJwk: JWK | string): ClientAssertionSigner;
|
|
19
|
+
/**
|
|
20
|
+
* Build a signer from a PKCS#8 PEM-encoded Ed25519 private key plus its `kid`.
|
|
21
|
+
* The key type is validated (must be Ed25519) on first use.
|
|
22
|
+
*/
|
|
23
|
+
static ed25519FromPem(pkcs8Pem: string, kid: string): ClientAssertionSigner;
|
|
24
|
+
/**
|
|
25
|
+
* Build a signer from an already-loaded Ed25519 private `KeyObject`
|
|
26
|
+
* (e.g. from `crypto.createPrivateKey(...)`) plus its `kid`.
|
|
27
|
+
*/
|
|
28
|
+
static ed25519(privateKey: KeyObject, kid: string): ClientAssertionSigner;
|
|
29
|
+
/**
|
|
30
|
+
* Return a copy of this signer using `seconds` as the assertion lifetime
|
|
31
|
+
* (iat→exp). Clamped to [1, 120] (the OP maximum). Defaults to 60; most
|
|
32
|
+
* callers never need this.
|
|
33
|
+
*/
|
|
34
|
+
withLifetimeSeconds(seconds: number): ClientAssertionSigner;
|
|
35
|
+
private importKey;
|
|
36
|
+
/**
|
|
37
|
+
* Build and Ed25519-sign the `client_assertion` JWT for one token exchange.
|
|
38
|
+
*
|
|
39
|
+
* @param clientId - becomes `iss` and `sub` (RFC 7523 §3)
|
|
40
|
+
* @param audience - the OP's token endpoint, exactly as advertised in
|
|
41
|
+
* discovery (the OP pins `aud` to that string)
|
|
42
|
+
*/
|
|
43
|
+
sign(clientId: string, audience: string): Promise<string>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=client-assertion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-assertion.d.ts","sourceRoot":"","sources":["../src/client-assertion.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAmC,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAKjE,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,2DACwB,CAAC;AAK3D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IACzD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,iEAAiE;IACjE,OAAO,CAAC,UAAU,CAAC,CAAuB;IAE1C,OAAO;IAUP;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,GAAG,MAAM,GAAG,qBAAqB;IA0BtE;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB;IAkB3E;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,qBAAqB;IAazE;;;;OAIG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB;IAK3D,OAAO,CAAC,SAAS;IAYjB;;;;;;OAMG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYhE"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientAssertionSigner = exports.CLIENT_ASSERTION_TYPE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* RFC 7523 / OIDC Core §9 `client_assertion` signer for the
|
|
6
|
+
* `private_key_jwt` token-endpoint authentication method.
|
|
7
|
+
*
|
|
8
|
+
* EdDSA over Ed25519 is the only algorithm the Hawcx OP accepts at the token
|
|
9
|
+
* endpoint, so it is the only one supported here. Obtain an instance via
|
|
10
|
+
* {@link ClientAssertionSigner.ed25519FromJwk} (or `ed25519FromPem` /
|
|
11
|
+
* `ed25519`) and attach it with `HawcxOAuth.withClientAssertion(signer)`.
|
|
12
|
+
*
|
|
13
|
+
* @beta This `private_key_jwt` surface is experimental and may change before
|
|
14
|
+
* it is marked stable.
|
|
15
|
+
*/
|
|
16
|
+
const node_crypto_1 = require("node:crypto");
|
|
17
|
+
const jose_1 = require("jose");
|
|
18
|
+
/** RFC 7523 §2.2 assertion type for the `private_key_jwt` method. */
|
|
19
|
+
exports.CLIENT_ASSERTION_TYPE = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
|
|
20
|
+
const DEFAULT_LIFETIME_SECONDS = 60;
|
|
21
|
+
const MAX_LIFETIME_SECONDS = 120; // OP cap (ASSERTION_MAX_TTL_SECONDS)
|
|
22
|
+
class ClientAssertionSigner {
|
|
23
|
+
constructor(importKeyFn, kid, lifetimeSeconds) {
|
|
24
|
+
this.importKeyFn = importKeyFn;
|
|
25
|
+
this.kid = kid;
|
|
26
|
+
this.lifetimeSeconds = lifetimeSeconds;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build a signer from an Ed25519 *private* JWK (RFC 8037):
|
|
30
|
+
* `{ kty: 'OKP', crv: 'Ed25519', d, x, kid }`. The `kid` is read from the
|
|
31
|
+
* JWK. This is the canonical Hawcx key format (what the admin console
|
|
32
|
+
* generates/downloads). Accepts either a JWK object or its JSON string.
|
|
33
|
+
*/
|
|
34
|
+
static ed25519FromJwk(privateJwk) {
|
|
35
|
+
let jwk;
|
|
36
|
+
if (typeof privateJwk === 'string') {
|
|
37
|
+
try {
|
|
38
|
+
jwk = JSON.parse(privateJwk);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
throw new Error(`private JWK is not valid JSON: ${String(err)}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
jwk = privateJwk;
|
|
46
|
+
}
|
|
47
|
+
if (jwk.kty !== 'OKP' || jwk.crv !== 'Ed25519') {
|
|
48
|
+
throw new Error(`client assertion key must be an Ed25519 OKP JWK (got kty=${String(jwk.kty)}, crv=${String(jwk.crv)})`);
|
|
49
|
+
}
|
|
50
|
+
if (typeof jwk.d !== 'string' || jwk.d.length === 0) {
|
|
51
|
+
throw new Error("client assertion JWK has no 'd' (not a private key)");
|
|
52
|
+
}
|
|
53
|
+
if (typeof jwk.kid !== 'string' || jwk.kid.length === 0) {
|
|
54
|
+
throw new Error("client assertion JWK is missing 'kid'");
|
|
55
|
+
}
|
|
56
|
+
const kid = jwk.kid;
|
|
57
|
+
return new ClientAssertionSigner(() => (0, jose_1.importJWK)(jwk, 'EdDSA'), kid, DEFAULT_LIFETIME_SECONDS);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a signer from a PKCS#8 PEM-encoded Ed25519 private key plus its `kid`.
|
|
61
|
+
* The key type is validated (must be Ed25519) on first use.
|
|
62
|
+
*/
|
|
63
|
+
static ed25519FromPem(pkcs8Pem, kid) {
|
|
64
|
+
if (!kid)
|
|
65
|
+
throw new Error('kid is required');
|
|
66
|
+
return new ClientAssertionSigner(async () => {
|
|
67
|
+
let key;
|
|
68
|
+
try {
|
|
69
|
+
key = await (0, jose_1.importPKCS8)(pkcs8Pem, 'EdDSA');
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
throw new Error(`not a valid PKCS#8 PEM private key: ${String(err)}`);
|
|
73
|
+
}
|
|
74
|
+
assertEd25519(key);
|
|
75
|
+
return key;
|
|
76
|
+
}, kid, DEFAULT_LIFETIME_SECONDS);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build a signer from an already-loaded Ed25519 private `KeyObject`
|
|
80
|
+
* (e.g. from `crypto.createPrivateKey(...)`) plus its `kid`.
|
|
81
|
+
*/
|
|
82
|
+
static ed25519(privateKey, kid) {
|
|
83
|
+
if (!kid)
|
|
84
|
+
throw new Error('kid is required');
|
|
85
|
+
if (privateKey.asymmetricKeyType !== 'ed25519') {
|
|
86
|
+
throw new Error(`private key must be Ed25519 (got ${String(privateKey.asymmetricKeyType)})`);
|
|
87
|
+
}
|
|
88
|
+
// Round-trip through a JWK so the key flows through jose's own importJWK
|
|
89
|
+
// rather than an unchecked cast into jose's KeyLike union.
|
|
90
|
+
const jwk = privateKey.export({ format: 'jwk' });
|
|
91
|
+
return new ClientAssertionSigner(() => (0, jose_1.importJWK)(jwk, 'EdDSA'), kid, DEFAULT_LIFETIME_SECONDS);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Return a copy of this signer using `seconds` as the assertion lifetime
|
|
95
|
+
* (iat→exp). Clamped to [1, 120] (the OP maximum). Defaults to 60; most
|
|
96
|
+
* callers never need this.
|
|
97
|
+
*/
|
|
98
|
+
withLifetimeSeconds(seconds) {
|
|
99
|
+
const clamped = Math.max(1, Math.min(MAX_LIFETIME_SECONDS, Math.floor(seconds)));
|
|
100
|
+
return new ClientAssertionSigner(this.importKeyFn, this.kid, clamped);
|
|
101
|
+
}
|
|
102
|
+
importKey() {
|
|
103
|
+
if (!this.keyPromise) {
|
|
104
|
+
// Don't memoise a rejection — a transient/structural import failure must
|
|
105
|
+
// not permanently poison the signer. Reset so the next sign() retries.
|
|
106
|
+
this.keyPromise = this.importKeyFn().catch((err) => {
|
|
107
|
+
this.keyPromise = undefined;
|
|
108
|
+
throw err;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return this.keyPromise;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build and Ed25519-sign the `client_assertion` JWT for one token exchange.
|
|
115
|
+
*
|
|
116
|
+
* @param clientId - becomes `iss` and `sub` (RFC 7523 §3)
|
|
117
|
+
* @param audience - the OP's token endpoint, exactly as advertised in
|
|
118
|
+
* discovery (the OP pins `aud` to that string)
|
|
119
|
+
*/
|
|
120
|
+
async sign(clientId, audience) {
|
|
121
|
+
const key = await this.importKey();
|
|
122
|
+
return new jose_1.SignJWT({})
|
|
123
|
+
.setProtectedHeader({ alg: 'EdDSA', typ: 'JWT', kid: this.kid })
|
|
124
|
+
.setIssuer(clientId)
|
|
125
|
+
.setSubject(clientId)
|
|
126
|
+
.setAudience(audience)
|
|
127
|
+
.setIssuedAt()
|
|
128
|
+
.setExpirationTime(`${this.lifetimeSeconds}s`)
|
|
129
|
+
.setJti((0, node_crypto_1.randomUUID)())
|
|
130
|
+
.sign(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.ClientAssertionSigner = ClientAssertionSigner;
|
|
134
|
+
function assertEd25519(key) {
|
|
135
|
+
// Node's importPKCS8 yields a KeyObject; reject non-Ed25519 with a clean message.
|
|
136
|
+
const type = key.asymmetricKeyType;
|
|
137
|
+
if (type !== undefined && type !== 'ed25519') {
|
|
138
|
+
throw new Error(`PEM key is not Ed25519 (got ${String(type)})`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=client-assertion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-assertion.js","sourceRoot":"","sources":["../src/client-assertion.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,6CAAyC;AAEzC,+BAAiE;AAKjE,qEAAqE;AACxD,QAAA,qBAAqB,GAChC,wDAAwD,CAAC;AAE3D,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,qCAAqC;AAEvE,MAAa,qBAAqB;IAOhC,YACE,WAAuC,EACvC,GAAW,EACX,eAAuB;QAEvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,UAAwB;QAC5C,IAAI,GAAQ,CAAC;QACb,I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|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential blob parsing for HAWCX_SECRET_KEY
|
|
3
|
+
*
|
|
4
|
+
* Format: hwx_sk_v1_<base64url(JSON)>
|
|
5
|
+
*
|
|
6
|
+
* JSON payload:
|
|
7
|
+
* {
|
|
8
|
+
* "v": 1,
|
|
9
|
+
* "alg": "ed25519+x25519",
|
|
10
|
+
* "kid": "cust_abc123",
|
|
11
|
+
* "ed_priv": "<32-byte-base64url>",
|
|
12
|
+
* "x_priv": "<32-byte-base64url>",
|
|
13
|
+
* "h_ed_pub": "<32-byte-base64url>",
|
|
14
|
+
* "h_x_pub": "<32-byte-base64url>",
|
|
15
|
+
* "hkid": "hwx_2025_01"
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Raw credential blob structure (as stored in the base64url JSON)
|
|
20
|
+
*/
|
|
21
|
+
export interface HawcxCredentialBlob {
|
|
22
|
+
/** Version number (must be 1) */
|
|
23
|
+
v: number;
|
|
24
|
+
/** Algorithm identifier (must be "ed25519+x25519") */
|
|
25
|
+
alg: string;
|
|
26
|
+
/** Customer key ID */
|
|
27
|
+
kid: string;
|
|
28
|
+
/** Customer Ed25519 private key (32 bytes, base64url) */
|
|
29
|
+
ed_priv: string;
|
|
30
|
+
/** Customer X25519 private key (32 bytes, base64url) */
|
|
31
|
+
x_priv: string;
|
|
32
|
+
/** Hawcx Ed25519 public key (32 bytes, base64url) */
|
|
33
|
+
h_ed_pub: string;
|
|
34
|
+
/** Hawcx X25519 public key (32 bytes, base64url) */
|
|
35
|
+
h_x_pub: string;
|
|
36
|
+
/** Hawcx key ID (for key rotation) */
|
|
37
|
+
hkid: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parsed credentials ready for use with crypto classes
|
|
41
|
+
*/
|
|
42
|
+
export interface ParsedCredentials {
|
|
43
|
+
/** Customer key ID */
|
|
44
|
+
kid: string;
|
|
45
|
+
/** Hawcx key ID */
|
|
46
|
+
hkid: string;
|
|
47
|
+
/** Customer Ed25519 private key (PEM format) */
|
|
48
|
+
signingKeyPem: string;
|
|
49
|
+
/** Hawcx Ed25519 public key (PEM format) */
|
|
50
|
+
verifyKeyPem: string;
|
|
51
|
+
/** Hawcx X25519 public key (PEM format) - for encrypting requests */
|
|
52
|
+
encryptKeyPem: string;
|
|
53
|
+
/** Customer X25519 private key (PEM format) - for decrypting responses */
|
|
54
|
+
decryptKeyPem: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse a HAWCX_SECRET_KEY credential string into usable key material.
|
|
58
|
+
*
|
|
59
|
+
* @param secretKey - The full credential string (hwx_sk_v1_<base64url>)
|
|
60
|
+
* @returns Parsed credentials with PEM-formatted keys
|
|
61
|
+
* @throws DelegationCryptoError if parsing fails
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const creds = parseHawcxSecretKey(process.env.HAWCX_SECRET_KEY!);
|
|
66
|
+
* const signer = new Ed25519Signer(creds.signingKeyPem, creds.kid);
|
|
67
|
+
* const encryptor = new EciesX25519Encryptor(creds.encryptKeyPem);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function parseHawcxSecretKey(secretKey: string): ParsedCredentials;
|
|
71
|
+
/**
|
|
72
|
+
* Generate a credential blob (for dashboard/admin tooling).
|
|
73
|
+
* This is typically called server-side when provisioning a new customer.
|
|
74
|
+
*
|
|
75
|
+
* @param options - Key generation options
|
|
76
|
+
* @returns The full credential string (hwx_sk_v1_<base64url>)
|
|
77
|
+
*/
|
|
78
|
+
export declare function generateCredentialBlob(options: {
|
|
79
|
+
/** Customer key ID */
|
|
80
|
+
kid: string;
|
|
81
|
+
/** Hawcx key ID */
|
|
82
|
+
hkid: string;
|
|
83
|
+
/** Customer Ed25519 private key (raw 32 bytes) */
|
|
84
|
+
edPrivate: Buffer;
|
|
85
|
+
/** Customer X25519 private key (raw 32 bytes) */
|
|
86
|
+
xPrivate: Buffer;
|
|
87
|
+
/** Hawcx Ed25519 public key (raw 32 bytes) */
|
|
88
|
+
hawcxEdPublic: Buffer;
|
|
89
|
+
/** Hawcx X25519 public key (raw 32 bytes) */
|
|
90
|
+
hawcxXPublic: Buffer;
|
|
91
|
+
}): string;
|
|
92
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/delegation/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAkDH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iCAAiC;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC;IACZ,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,aAAa,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,aAAa,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,aAAa,EAAE,MAAM,CAAC;CACvB;AA8DD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CA2ExE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,MAAM,CA6BT"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Credential blob parsing for HAWCX_SECRET_KEY
|
|
4
|
+
*
|
|
5
|
+
* Format: hwx_sk_v1_<base64url(JSON)>
|
|
6
|
+
*
|
|
7
|
+
* JSON payload:
|
|
8
|
+
* {
|
|
9
|
+
* "v": 1,
|
|
10
|
+
* "alg": "ed25519+x25519",
|
|
11
|
+
* "kid": "cust_abc123",
|
|
12
|
+
* "ed_priv": "<32-byte-base64url>",
|
|
13
|
+
* "x_priv": "<32-byte-base64url>",
|
|
14
|
+
* "h_ed_pub": "<32-byte-base64url>",
|
|
15
|
+
* "h_x_pub": "<32-byte-base64url>",
|
|
16
|
+
* "hkid": "hwx_2025_01"
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.parseHawcxSecretKey = parseHawcxSecretKey;
|
|
21
|
+
exports.generateCredentialBlob = generateCredentialBlob;
|
|
22
|
+
const exceptions_1 = require("./exceptions");
|
|
23
|
+
// -------- Constants --------
|
|
24
|
+
const CREDENTIAL_PREFIX = 'hwx_sk_v1_';
|
|
25
|
+
const EXPECTED_VERSION = 1;
|
|
26
|
+
const EXPECTED_ALG = 'ed25519+x25519';
|
|
27
|
+
const RAW_KEY_LENGTH = 32;
|
|
28
|
+
// DER headers for key wrapping
|
|
29
|
+
// Ed25519 private key PKCS8 header (14 bytes) + 2 bytes length prefix for the key
|
|
30
|
+
const ED25519_PKCS8_HEADER = Buffer.from([
|
|
31
|
+
0x30, 0x2e, // SEQUENCE, 46 bytes
|
|
32
|
+
0x02, 0x01, 0x00, // INTEGER 0 (version)
|
|
33
|
+
0x30, 0x05, // SEQUENCE, 5 bytes (algorithm identifier)
|
|
34
|
+
0x06, 0x03, 0x2b, 0x65, 0x70, // OID 1.3.101.112 (Ed25519)
|
|
35
|
+
0x04, 0x22, // OCTET STRING, 34 bytes
|
|
36
|
+
0x04, 0x20, // OCTET STRING, 32 bytes (the actual key)
|
|
37
|
+
]);
|
|
38
|
+
// Ed25519 public key SPKI header (12 bytes)
|
|
39
|
+
const ED25519_SPKI_HEADER = Buffer.from([
|
|
40
|
+
0x30, 0x2a, // SEQUENCE, 42 bytes
|
|
41
|
+
0x30, 0x05, // SEQUENCE, 5 bytes (algorithm identifier)
|
|
42
|
+
0x06, 0x03, 0x2b, 0x65, 0x70, // OID 1.3.101.112 (Ed25519)
|
|
43
|
+
0x03, 0x21, 0x00, // BIT STRING, 33 bytes (with 0 unused bits)
|
|
44
|
+
]);
|
|
45
|
+
// X25519 private key PKCS8 header
|
|
46
|
+
const X25519_PKCS8_HEADER = Buffer.from([
|
|
47
|
+
0x30, 0x2e, // SEQUENCE, 46 bytes
|
|
48
|
+
0x02, 0x01, 0x00, // INTEGER 0 (version)
|
|
49
|
+
0x30, 0x05, // SEQUENCE, 5 bytes (algorithm identifier)
|
|
50
|
+
0x06, 0x03, 0x2b, 0x65, 0x6e, // OID 1.3.101.110 (X25519)
|
|
51
|
+
0x04, 0x22, // OCTET STRING, 34 bytes
|
|
52
|
+
0x04, 0x20, // OCTET STRING, 32 bytes (the actual key)
|
|
53
|
+
]);
|
|
54
|
+
// X25519 public key SPKI header
|
|
55
|
+
const X25519_SPKI_HEADER = Buffer.from([
|
|
56
|
+
0x30, 0x2a, // SEQUENCE, 42 bytes
|
|
57
|
+
0x30, 0x05, // SEQUENCE, 5 bytes (algorithm identifier)
|
|
58
|
+
0x06, 0x03, 0x2b, 0x65, 0x6e, // OID 1.3.101.110 (X25519)
|
|
59
|
+
0x03, 0x21, 0x00, // BIT STRING, 33 bytes (with 0 unused bits)
|
|
60
|
+
]);
|
|
61
|
+
// -------- Key Conversion Helpers --------
|
|
62
|
+
/**
|
|
63
|
+
* Convert raw 32-byte Ed25519 private key to PEM format
|
|
64
|
+
*/
|
|
65
|
+
function ed25519PrivateToPem(rawKey) {
|
|
66
|
+
if (rawKey.length !== RAW_KEY_LENGTH) {
|
|
67
|
+
throw new exceptions_1.DelegationCryptoError(`Ed25519 private key must be ${RAW_KEY_LENGTH} bytes, got ${rawKey.length}`);
|
|
68
|
+
}
|
|
69
|
+
const der = Buffer.concat([ED25519_PKCS8_HEADER, rawKey]);
|
|
70
|
+
const b64 = der.toString('base64');
|
|
71
|
+
return `-----BEGIN PRIVATE KEY-----\n${b64.match(/.{1,64}/g)?.join('\n')}\n-----END PRIVATE KEY-----`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Convert raw 32-byte Ed25519 public key to PEM format
|
|
75
|
+
*/
|
|
76
|
+
function ed25519PublicToPem(rawKey) {
|
|
77
|
+
if (rawKey.length !== RAW_KEY_LENGTH) {
|
|
78
|
+
throw new exceptions_1.DelegationCryptoError(`Ed25519 public key must be ${RAW_KEY_LENGTH} bytes, got ${rawKey.length}`);
|
|
79
|
+
}
|
|
80
|
+
const der = Buffer.concat([ED25519_SPKI_HEADER, rawKey]);
|
|
81
|
+
const b64 = der.toString('base64');
|
|
82
|
+
return `-----BEGIN PUBLIC KEY-----\n${b64.match(/.{1,64}/g)?.join('\n')}\n-----END PUBLIC KEY-----`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Convert raw 32-byte X25519 private key to PEM format
|
|
86
|
+
*/
|
|
87
|
+
function x25519PrivateToPem(rawKey) {
|
|
88
|
+
if (rawKey.length !== RAW_KEY_LENGTH) {
|
|
89
|
+
throw new exceptions_1.DelegationCryptoError(`X25519 private key must be ${RAW_KEY_LENGTH} bytes, got ${rawKey.length}`);
|
|
90
|
+
}
|
|
91
|
+
const der = Buffer.concat([X25519_PKCS8_HEADER, rawKey]);
|
|
92
|
+
const b64 = der.toString('base64');
|
|
93
|
+
return `-----BEGIN PRIVATE KEY-----\n${b64.match(/.{1,64}/g)?.join('\n')}\n-----END PRIVATE KEY-----`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert raw 32-byte X25519 public key to PEM format
|
|
97
|
+
*/
|
|
98
|
+
function x25519PublicToPem(rawKey) {
|
|
99
|
+
if (rawKey.length !== RAW_KEY_LENGTH) {
|
|
100
|
+
throw new exceptions_1.DelegationCryptoError(`X25519 public key must be ${RAW_KEY_LENGTH} bytes, got ${rawKey.length}`);
|
|
101
|
+
}
|
|
102
|
+
const der = Buffer.concat([X25519_SPKI_HEADER, rawKey]);
|
|
103
|
+
const b64 = der.toString('base64');
|
|
104
|
+
return `-----BEGIN PUBLIC KEY-----\n${b64.match(/.{1,64}/g)?.join('\n')}\n-----END PUBLIC KEY-----`;
|
|
105
|
+
}
|
|
106
|
+
// -------- Main Parser --------
|
|
107
|
+
/**
|
|
108
|
+
* Parse a HAWCX_SECRET_KEY credential string into usable key material.
|
|
109
|
+
*
|
|
110
|
+
* @param secretKey - The full credential string (hwx_sk_v1_<base64url>)
|
|
111
|
+
* @returns Parsed credentials with PEM-formatted keys
|
|
112
|
+
* @throws DelegationCryptoError if parsing fails
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const creds = parseHawcxSecretKey(process.env.HAWCX_SECRET_KEY!);
|
|
117
|
+
* const signer = new Ed25519Signer(creds.signingKeyPem, creds.kid);
|
|
118
|
+
* const encryptor = new EciesX25519Encryptor(creds.encryptKeyPem);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
function parseHawcxSecretKey(secretKey) {
|
|
122
|
+
// Validate prefix
|
|
123
|
+
if (!secretKey.startsWith(CREDENTIAL_PREFIX)) {
|
|
124
|
+
throw new exceptions_1.DelegationCryptoError(`Invalid credential format: must start with '${CREDENTIAL_PREFIX}'`);
|
|
125
|
+
}
|
|
126
|
+
// Extract and decode payload
|
|
127
|
+
const payloadB64 = secretKey.slice(CREDENTIAL_PREFIX.length);
|
|
128
|
+
let blob;
|
|
129
|
+
try {
|
|
130
|
+
const payloadJson = Buffer.from(payloadB64, 'base64url').toString('utf-8');
|
|
131
|
+
blob = JSON.parse(payloadJson);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
throw new exceptions_1.DelegationCryptoError('Invalid credential format: failed to decode payload', {
|
|
135
|
+
cause: error,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Validate version
|
|
139
|
+
if (blob.v !== EXPECTED_VERSION) {
|
|
140
|
+
throw new exceptions_1.DelegationCryptoError(`Unsupported credential version: ${blob.v} (expected ${EXPECTED_VERSION})`);
|
|
141
|
+
}
|
|
142
|
+
// Validate algorithm
|
|
143
|
+
if (blob.alg !== EXPECTED_ALG) {
|
|
144
|
+
throw new exceptions_1.DelegationCryptoError(`Unsupported credential algorithm: ${blob.alg} (expected ${EXPECTED_ALG})`);
|
|
145
|
+
}
|
|
146
|
+
// Validate required fields
|
|
147
|
+
const requiredFields = [
|
|
148
|
+
'kid',
|
|
149
|
+
'ed_priv',
|
|
150
|
+
'x_priv',
|
|
151
|
+
'h_ed_pub',
|
|
152
|
+
'h_x_pub',
|
|
153
|
+
'hkid',
|
|
154
|
+
];
|
|
155
|
+
for (const field of requiredFields) {
|
|
156
|
+
if (!blob[field]) {
|
|
157
|
+
throw new exceptions_1.DelegationCryptoError(`Missing required field: ${field}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Decode and validate key lengths
|
|
161
|
+
let edPrivRaw;
|
|
162
|
+
let xPrivRaw;
|
|
163
|
+
let hEdPubRaw;
|
|
164
|
+
let hXPubRaw;
|
|
165
|
+
try {
|
|
166
|
+
edPrivRaw = Buffer.from(blob.ed_priv, 'base64url');
|
|
167
|
+
xPrivRaw = Buffer.from(blob.x_priv, 'base64url');
|
|
168
|
+
hEdPubRaw = Buffer.from(blob.h_ed_pub, 'base64url');
|
|
169
|
+
hXPubRaw = Buffer.from(blob.h_x_pub, 'base64url');
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
throw new exceptions_1.DelegationCryptoError('Invalid base64url in credential keys', { cause: error });
|
|
173
|
+
}
|
|
174
|
+
// Convert to PEM format
|
|
175
|
+
return {
|
|
176
|
+
kid: blob.kid,
|
|
177
|
+
hkid: blob.hkid,
|
|
178
|
+
signingKeyPem: ed25519PrivateToPem(edPrivRaw),
|
|
179
|
+
verifyKeyPem: ed25519PublicToPem(hEdPubRaw),
|
|
180
|
+
encryptKeyPem: x25519PublicToPem(hXPubRaw),
|
|
181
|
+
decryptKeyPem: x25519PrivateToPem(xPrivRaw),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Generate a credential blob (for dashboard/admin tooling).
|
|
186
|
+
* This is typically called server-side when provisioning a new customer.
|
|
187
|
+
*
|
|
188
|
+
* @param options - Key generation options
|
|
189
|
+
* @returns The full credential string (hwx_sk_v1_<base64url>)
|
|
190
|
+
*/
|
|
191
|
+
function generateCredentialBlob(options) {
|
|
192
|
+
const validateLen = (label, value) => {
|
|
193
|
+
if (value.length !== RAW_KEY_LENGTH) {
|
|
194
|
+
throw new exceptions_1.DelegationCryptoError(`${label} must be ${RAW_KEY_LENGTH} bytes, got ${value.length}`);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
validateLen('edPrivate', options.edPrivate);
|
|
198
|
+
validateLen('xPrivate', options.xPrivate);
|
|
199
|
+
validateLen('hawcxEdPublic', options.hawcxEdPublic);
|
|
200
|
+
validateLen('hawcxXPublic', options.hawcxXPublic);
|
|
201
|
+
const blob = {
|
|
202
|
+
v: EXPECTED_VERSION,
|
|
203
|
+
alg: EXPECTED_ALG,
|
|
204
|
+
kid: options.kid,
|
|
205
|
+
ed_priv: options.edPrivate.toString('base64url'),
|
|
206
|
+
x_priv: options.xPrivate.toString('base64url'),
|
|
207
|
+
h_ed_pub: options.hawcxEdPublic.toString('base64url'),
|
|
208
|
+
h_x_pub: options.hawcxXPublic.toString('base64url'),
|
|
209
|
+
hkid: options.hkid,
|
|
210
|
+
};
|
|
211
|
+
const payloadJson = JSON.stringify(blob);
|
|
212
|
+
const payloadB64 = Buffer.from(payloadJson).toString('base64url');
|
|
213
|
+
return `${CREDENTIAL_PREFIX}${payloadB64}`;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/delegation/credentials.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AAoKH,kDA2EC;AASD,wDA0CC;AAhSD,6CAAqD;AAErD,8BAA8B;AAE9B,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,+BAA+B;AAC/B,kFAAkF;AAClF,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC;IACvC,IAAI,EAAE,IAAI,EAAE,qBAAqB;IACjC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,sBAAsB;IACxC,IAAI,EAAE,IAAI,EAAE,2CAA2C;IACvD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,4BAA4B;IAC1D,IAAI,EAAE,IAAI,EAAE,yBAAyB;IACrC,IAAI,EAAE,IAAI,EAAE,0CAA0C;CACvD,CAAC,CAAC;AAEH,4CAA4C;AAC5C,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAA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CAAC,WAAW,CAAC,CAAC;IAElE,OAAO,GAAG,iBAAiB,GAAG,UAAU,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -56,7 +56,7 @@ export declare class EciesX25519Encryptor {
|
|
|
56
56
|
/**
|
|
57
57
|
* Encrypt plaintext using ECIES
|
|
58
58
|
*/
|
|
59
|
-
encrypt(plaintext: Buffer): Buffer
|
|
59
|
+
encrypt(plaintext: Buffer): Promise<Buffer>;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* ECIES decryptor using X25519 + AES-GCM
|
|
@@ -67,6 +67,6 @@ export declare class EciesX25519Decryptor {
|
|
|
67
67
|
/**
|
|
68
68
|
* Decrypt ECIES envelope
|
|
69
69
|
*/
|
|
70
|
-
decrypt(envelopeJson: Buffer): Buffer
|
|
70
|
+
decrypt(envelopeJson: Buffer): Promise<Buffer>;
|
|
71
71
|
}
|
|
72
72
|
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/delegation/crypto.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,wBAAgB,IAAI,IAAI,MAAM,CAE7B;
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/delegation/crypto.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,wBAAgB,IAAI,IAAI,MAAM,CAE7B;AAuDD,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,EAAE,CAAmB;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAa;gBAEnB,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAoB5C;;OA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