@hawcx/oauth-client 0.1.0 → 4.0.1
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 +475 -204
- 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 +67 -224
- package/dist/delegation/hawcx.d.ts.map +1 -1
- package/dist/delegation/hawcx.js +116 -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 +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +29 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -27
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +98 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +150 -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 +84 -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 +36 -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 +16 -17
- package/LICENSE +0 -22
- package/dist/client.d.ts +0 -134
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -301
- 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,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,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",
|
|
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;;;;;;;;;;;;;;;;GA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OAAO,CAAC,aAAa,CAAC,CAAC;IACpD,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAElD,MAAM,IAAI,GAAwB;QAChC,CAAC,EAAE,gBAAgB;QACnB,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC;QAChD,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC;QAC9C,QAAQ,EAAE,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,WAAW,CAAC;QACrD,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC;QACnD,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC;IAEF,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,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;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU;CAanD;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAmB;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAoB;gBAE1B,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAoB5C;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU;CAiBnD;AAED;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAgC;gBAEnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAmB3C;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;CAwClF;AAID;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,aAAa,CAAmB;gBAE5B,UAAU,EAAE,MAAM;IAoB9B;;OAEG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA0ClD;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,EAAE,CAAmB;gBAEjB,OAAO,EAAE,MAAM;IAkB3B;;OAEG;IACG,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAqDrD"}
|
|
@@ -59,6 +59,28 @@ function b64e(buffer) {
|
|
|
59
59
|
function b64d(str) {
|
|
60
60
|
return Buffer.from(str, 'base64url');
|
|
61
61
|
}
|
|
62
|
+
async function hkdf(digest, key, salt, info, length) {
|
|
63
|
+
return await new Promise((resolve, reject) => {
|
|
64
|
+
crypto.hkdf(digest, key, salt, info, length, (err, derivedKey) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
reject(err);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
resolve(Buffer.from(derivedKey));
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async function generateX25519KeyPair() {
|
|
74
|
+
return await new Promise((resolve, reject) => {
|
|
75
|
+
crypto.generateKeyPair('x25519', undefined, (err, publicKey, privateKey) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
reject(err);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
resolve({ publicKey, privateKey });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
62
84
|
/**
|
|
63
85
|
* Ed25519 signer for delegation requests
|
|
64
86
|
*/
|
|
@@ -80,7 +102,7 @@ class Ed25519Signer {
|
|
|
80
102
|
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
81
103
|
throw error;
|
|
82
104
|
}
|
|
83
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
105
|
+
throw new exceptions_1.DelegationCryptoError('Failed to load Ed25519 private key', { cause: error });
|
|
84
106
|
}
|
|
85
107
|
}
|
|
86
108
|
/**
|
|
@@ -97,7 +119,7 @@ class Ed25519Signer {
|
|
|
97
119
|
};
|
|
98
120
|
}
|
|
99
121
|
catch (error) {
|
|
100
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
122
|
+
throw new exceptions_1.DelegationCryptoError('Ed25519 signing failed', { cause: error });
|
|
101
123
|
}
|
|
102
124
|
}
|
|
103
125
|
}
|
|
@@ -123,7 +145,7 @@ class RsaPssSigner {
|
|
|
123
145
|
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
124
146
|
throw error;
|
|
125
147
|
}
|
|
126
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
148
|
+
throw new exceptions_1.DelegationCryptoError('Failed to load RSA private key', { cause: error });
|
|
127
149
|
}
|
|
128
150
|
}
|
|
129
151
|
/**
|
|
@@ -135,7 +157,7 @@ class RsaPssSigner {
|
|
|
135
157
|
const signature = crypto.sign('sha256', data, {
|
|
136
158
|
key: this.sk,
|
|
137
159
|
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
138
|
-
saltLength: crypto.constants.
|
|
160
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
139
161
|
});
|
|
140
162
|
return {
|
|
141
163
|
alg: this.alg,
|
|
@@ -144,7 +166,7 @@ class RsaPssSigner {
|
|
|
144
166
|
};
|
|
145
167
|
}
|
|
146
168
|
catch (error) {
|
|
147
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
169
|
+
throw new exceptions_1.DelegationCryptoError('RSA-PSS signing failed', { cause: error });
|
|
148
170
|
}
|
|
149
171
|
}
|
|
150
172
|
}
|
|
@@ -168,7 +190,7 @@ class Verifier {
|
|
|
168
190
|
}
|
|
169
191
|
}
|
|
170
192
|
catch (error) {
|
|
171
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
193
|
+
throw new exceptions_1.DelegationCryptoError('Failed to load one or more public keys', { cause: error });
|
|
172
194
|
}
|
|
173
195
|
}
|
|
174
196
|
/**
|
|
@@ -197,7 +219,7 @@ class Verifier {
|
|
|
197
219
|
isValid = crypto.verify('sha256', dataToVerify, {
|
|
198
220
|
key: pub,
|
|
199
221
|
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
200
|
-
saltLength: crypto.constants.
|
|
222
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST,
|
|
201
223
|
}, sig);
|
|
202
224
|
}
|
|
203
225
|
else {
|
|
@@ -211,7 +233,7 @@ class Verifier {
|
|
|
211
233
|
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
212
234
|
throw error;
|
|
213
235
|
}
|
|
214
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
236
|
+
throw new exceptions_1.DelegationCryptoError('Signature verification failed', { cause: error });
|
|
215
237
|
}
|
|
216
238
|
}
|
|
217
239
|
}
|
|
@@ -230,42 +252,29 @@ class EciesX25519Encryptor {
|
|
|
230
252
|
if (key.asymmetricKeyType !== 'x25519') {
|
|
231
253
|
throw new exceptions_1.DelegationCryptoError('peer_pub_pem must be an X25519 public key');
|
|
232
254
|
}
|
|
233
|
-
|
|
234
|
-
this.peerPublicKey = key.export({ type: 'spki', format: 'der' }).slice(-32);
|
|
255
|
+
this.peerPublicKey = key;
|
|
235
256
|
}
|
|
236
257
|
catch (error) {
|
|
237
258
|
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
238
259
|
throw error;
|
|
239
260
|
}
|
|
240
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
261
|
+
throw new exceptions_1.DelegationCryptoError('Failed to load ECIES peer public key', { cause: error });
|
|
241
262
|
}
|
|
242
263
|
}
|
|
243
264
|
/**
|
|
244
265
|
* Encrypt plaintext using ECIES
|
|
245
266
|
*/
|
|
246
|
-
encrypt(plaintext) {
|
|
267
|
+
async encrypt(plaintext) {
|
|
247
268
|
try {
|
|
248
269
|
// Generate ephemeral X25519 keypair
|
|
249
|
-
const
|
|
250
|
-
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
|
|
251
|
-
publicKeyEncoding: { type: 'spki', format: 'pem' },
|
|
252
|
-
});
|
|
253
|
-
const ephPrivKey = crypto.createPrivateKey(ephPrivateKey.privateKey);
|
|
254
|
-
const ephPubKey = crypto.createPublicKey(ephPrivateKey.publicKey);
|
|
270
|
+
const { publicKey: ephPubKey, privateKey: ephPrivKey } = await generateX25519KeyPair();
|
|
255
271
|
// Perform ECDH
|
|
256
272
|
const shared = crypto.diffieHellman({
|
|
257
273
|
privateKey: ephPrivKey,
|
|
258
|
-
publicKey:
|
|
259
|
-
key: Buffer.concat([
|
|
260
|
-
Buffer.from([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x03, 0x21, 0x00]),
|
|
261
|
-
this.peerPublicKey,
|
|
262
|
-
]),
|
|
263
|
-
format: 'der',
|
|
264
|
-
type: 'spki',
|
|
265
|
-
}),
|
|
274
|
+
publicKey: this.peerPublicKey,
|
|
266
275
|
});
|
|
267
276
|
// Derive AES key using HKDF
|
|
268
|
-
const key =
|
|
277
|
+
const key = await hkdf('sha256', shared, Buffer.alloc(0), Buffer.from('idp-sp-ecies-v1'), 32);
|
|
269
278
|
// Encrypt with AES-GCM
|
|
270
279
|
const nonce = crypto.randomBytes(12);
|
|
271
280
|
const cipher = crypto.createCipheriv('aes-256-gcm', Buffer.from(key), nonce);
|
|
@@ -283,7 +292,7 @@ class EciesX25519Encryptor {
|
|
|
283
292
|
return Buffer.from(JSON.stringify(envelope));
|
|
284
293
|
}
|
|
285
294
|
catch (error) {
|
|
286
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
295
|
+
throw new exceptions_1.DelegationCryptoError('ECIES encryption failed', { cause: error });
|
|
287
296
|
}
|
|
288
297
|
}
|
|
289
298
|
}
|
|
@@ -306,13 +315,13 @@ class EciesX25519Decryptor {
|
|
|
306
315
|
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
307
316
|
throw error;
|
|
308
317
|
}
|
|
309
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
318
|
+
throw new exceptions_1.DelegationCryptoError('Failed to load ECIES private key', { cause: error });
|
|
310
319
|
}
|
|
311
320
|
}
|
|
312
321
|
/**
|
|
313
322
|
* Decrypt ECIES envelope
|
|
314
323
|
*/
|
|
315
|
-
decrypt(envelopeJson) {
|
|
324
|
+
async decrypt(envelopeJson) {
|
|
316
325
|
try {
|
|
317
326
|
const envelope = JSON.parse(envelopeJson.toString('utf-8'));
|
|
318
327
|
if (envelope.enc !== 'x25519-aesgcm') {
|
|
@@ -340,7 +349,7 @@ class EciesX25519Decryptor {
|
|
|
340
349
|
publicKey: epk,
|
|
341
350
|
});
|
|
342
351
|
// Derive AES key using HKDF
|
|
343
|
-
const key =
|
|
352
|
+
const key = await hkdf('sha256', shared, Buffer.alloc(0), Buffer.from('idp-sp-ecies-v1'), 32);
|
|
344
353
|
// Decrypt with AES-GCM
|
|
345
354
|
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(key), nonce);
|
|
346
355
|
decipher.setAuthTag(tag);
|
|
@@ -348,7 +357,7 @@ class EciesX25519Decryptor {
|
|
|
348
357
|
return plaintext;
|
|
349
358
|
}
|
|
350
359
|
catch (error) {
|
|
351
|
-
throw new exceptions_1.DelegationCryptoError(
|
|
360
|
+
throw new exceptions_1.DelegationCryptoError('ECIES decryption failed', { cause: error });
|
|
352
361
|
}
|
|
353
362
|
}
|
|
354
363
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/delegation/crypto.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUH,oBAEC;AAVD,+CAAiC;AACjC,6C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;YACf,MAAM,IAAI,kCAAqB,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;CACF;AA7ED,oDA6EC"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Custom exceptions for the Delegation module
|
|
3
3
|
*/
|
|
4
|
-
import { HawcxOAuthError } from '../
|
|
4
|
+
import { HawcxOAuthError } from '../errors';
|
|
5
5
|
/**
|
|
6
6
|
* Base exception for delegation errors
|
|
7
7
|
*/
|
|
8
|
+
export interface DelegationErrorOptions {
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
}
|
|
8
11
|
export declare class DelegationError extends HawcxOAuthError {
|
|
9
|
-
|
|
12
|
+
readonly cause?: unknown;
|
|
13
|
+
constructor(message: string, options?: DelegationErrorOptions);
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* Raised for cryptographic errors (signing, encryption, etc.)
|
|
13
17
|
*/
|
|
14
18
|
export declare class DelegationCryptoError extends DelegationError {
|
|
15
|
-
constructor(message: string);
|
|
19
|
+
constructor(message: string, options?: DelegationErrorOptions);
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* Raised for errors sending requests to the IDP
|
|
@@ -20,13 +24,16 @@ export declare class DelegationCryptoError extends DelegationError {
|
|
|
20
24
|
export declare class DelegationRequestError extends DelegationError {
|
|
21
25
|
statusCode?: number;
|
|
22
26
|
responseBody?: string;
|
|
23
|
-
constructor(message: string,
|
|
27
|
+
constructor(message: string, options?: DelegationErrorOptions & {
|
|
28
|
+
statusCode?: number;
|
|
29
|
+
responseBody?: string;
|
|
30
|
+
});
|
|
24
31
|
toString(): string;
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* Raised for errors in the IDP's response
|
|
28
35
|
*/
|
|
29
36
|
export declare class DelegationResponseError extends DelegationError {
|
|
30
|
-
constructor(message: string);
|
|
37
|
+
constructor(message: string, options?: DelegationErrorOptions);
|
|
31
38
|
}
|
|
32
39
|
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/delegation/exceptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/delegation/exceptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qBAAa,eAAgB,SAAQ,eAAe;IAClD,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;CAMlE;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,eAAe;gBAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;CAKlE;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,eAAe;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAGpB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,sBAAsB,GAAG;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO;IASvF,QAAQ,IAAI,MAAM;CAOnB;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B;CAKlE"}
|