@hawcx/oauth-client 0.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/LICENSE +22 -0
- package/README.md +304 -0
- package/dist/client.d.ts +134 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +301 -0
- package/dist/client.js.map +1 -0
- package/dist/delegation/client.d.ts +116 -0
- package/dist/delegation/client.d.ts.map +1 -0
- package/dist/delegation/client.js +227 -0
- package/dist/delegation/client.js.map +1 -0
- package/dist/delegation/crypto.d.ts +72 -0
- package/dist/delegation/crypto.d.ts.map +1 -0
- package/dist/delegation/crypto.js +356 -0
- package/dist/delegation/crypto.js.map +1 -0
- package/dist/delegation/exceptions.d.ts +32 -0
- package/dist/delegation/exceptions.d.ts.map +1 -0
- package/dist/delegation/exceptions.js +61 -0
- package/dist/delegation/exceptions.js.map +1 -0
- package/dist/delegation/hawcx.d.ts +254 -0
- package/dist/delegation/hawcx.d.ts.map +1 -0
- package/dist/delegation/hawcx.js +326 -0
- package/dist/delegation/hawcx.js.map +1 -0
- package/dist/delegation/index.d.ts +14 -0
- package/dist/delegation/index.d.ts.map +1 -0
- package/dist/delegation/index.js +30 -0
- package/dist/delegation/index.js.map +1 -0
- package/dist/exceptions.d.ts +52 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +81 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +61 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +263 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic utilities for delegation (ECIES, Ed25519, RSA-PSS)
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get current Unix timestamp in seconds
|
|
6
|
+
*/
|
|
7
|
+
export declare function nowS(): number;
|
|
8
|
+
export interface SignResult {
|
|
9
|
+
alg: string;
|
|
10
|
+
signatureB64: string;
|
|
11
|
+
kid?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Ed25519 signer for delegation requests
|
|
15
|
+
*/
|
|
16
|
+
export declare class Ed25519Signer {
|
|
17
|
+
private sk;
|
|
18
|
+
kid?: string;
|
|
19
|
+
alg: string;
|
|
20
|
+
constructor(privatePem: string, kid?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Sign detached signature over body and timestamp
|
|
23
|
+
*/
|
|
24
|
+
signDetached(body: Buffer, ts: number): SignResult;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* RSA-PSS signer for delegation requests
|
|
28
|
+
*/
|
|
29
|
+
export declare class RsaPssSigner {
|
|
30
|
+
private sk;
|
|
31
|
+
kid?: string;
|
|
32
|
+
alg: string;
|
|
33
|
+
constructor(privatePem: string, kid?: string);
|
|
34
|
+
/**
|
|
35
|
+
* Sign detached signature over body and timestamp
|
|
36
|
+
*/
|
|
37
|
+
signDetached(body: Buffer, ts: number): SignResult;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Verifier for checking signatures from the IDP
|
|
41
|
+
*/
|
|
42
|
+
export declare class Verifier {
|
|
43
|
+
private pubKeys;
|
|
44
|
+
constructor(pubkeys: Record<string, string>);
|
|
45
|
+
/**
|
|
46
|
+
* Verify signature from IDP
|
|
47
|
+
*/
|
|
48
|
+
verify(body: Buffer, ts: number, sigB64: string, alg: string, kid?: string): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* ECIES encryptor using X25519 + AES-GCM
|
|
52
|
+
*/
|
|
53
|
+
export declare class EciesX25519Encryptor {
|
|
54
|
+
private peerPublicKey;
|
|
55
|
+
constructor(peerPubPem: string);
|
|
56
|
+
/**
|
|
57
|
+
* Encrypt plaintext using ECIES
|
|
58
|
+
*/
|
|
59
|
+
encrypt(plaintext: Buffer): Buffer;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* ECIES decryptor using X25519 + AES-GCM
|
|
63
|
+
*/
|
|
64
|
+
export declare class EciesX25519Decryptor {
|
|
65
|
+
private sk;
|
|
66
|
+
constructor(privPem: string);
|
|
67
|
+
/**
|
|
68
|
+
* Decrypt ECIES envelope
|
|
69
|
+
*/
|
|
70
|
+
decrypt(envelopeJson: Buffer): Buffer;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +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;AAkBD,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,CAAS;gBAElB,UAAU,EAAE,MAAM;IAqB9B;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAiDnC;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,EAAE,CAAmB;gBAEjB,OAAO,EAAE,MAAM;IAkB3B;;OAEG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CA+CtC"}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cryptographic utilities for delegation (ECIES, Ed25519, RSA-PSS)
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.EciesX25519Decryptor = exports.EciesX25519Encryptor = exports.Verifier = exports.RsaPssSigner = exports.Ed25519Signer = void 0;
|
|
40
|
+
exports.nowS = nowS;
|
|
41
|
+
const crypto = __importStar(require("crypto"));
|
|
42
|
+
const exceptions_1 = require("./exceptions");
|
|
43
|
+
// -------- Helpers --------
|
|
44
|
+
/**
|
|
45
|
+
* Get current Unix timestamp in seconds
|
|
46
|
+
*/
|
|
47
|
+
function nowS() {
|
|
48
|
+
return Math.floor(Date.now() / 1000);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Base64url encode (no padding)
|
|
52
|
+
*/
|
|
53
|
+
function b64e(buffer) {
|
|
54
|
+
return buffer.toString('base64url');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Base64url decode
|
|
58
|
+
*/
|
|
59
|
+
function b64d(str) {
|
|
60
|
+
return Buffer.from(str, 'base64url');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Ed25519 signer for delegation requests
|
|
64
|
+
*/
|
|
65
|
+
class Ed25519Signer {
|
|
66
|
+
constructor(privatePem, kid) {
|
|
67
|
+
this.alg = 'ed25519';
|
|
68
|
+
this.kid = kid;
|
|
69
|
+
try {
|
|
70
|
+
this.sk = crypto.createPrivateKey({
|
|
71
|
+
key: privatePem,
|
|
72
|
+
format: 'pem',
|
|
73
|
+
});
|
|
74
|
+
// Verify it's Ed25519
|
|
75
|
+
if (this.sk.asymmetricKeyType !== 'ed25519') {
|
|
76
|
+
throw new exceptions_1.DelegationCryptoError('Provided PEM is not an Ed25519 private key');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
throw new exceptions_1.DelegationCryptoError(`Failed to load Ed25519 private key: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sign detached signature over body and timestamp
|
|
88
|
+
*/
|
|
89
|
+
signDetached(body, ts) {
|
|
90
|
+
try {
|
|
91
|
+
const data = Buffer.concat([body, Buffer.from('.'), Buffer.from(String(ts))]);
|
|
92
|
+
const signature = crypto.sign(null, data, this.sk);
|
|
93
|
+
return {
|
|
94
|
+
alg: this.alg,
|
|
95
|
+
signatureB64: b64e(signature),
|
|
96
|
+
kid: this.kid,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
throw new exceptions_1.DelegationCryptoError(`Ed25519 signing failed: ${error}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Ed25519Signer = Ed25519Signer;
|
|
105
|
+
/**
|
|
106
|
+
* RSA-PSS signer for delegation requests
|
|
107
|
+
*/
|
|
108
|
+
class RsaPssSigner {
|
|
109
|
+
constructor(privatePem, kid) {
|
|
110
|
+
this.alg = 'rsa-pss-sha256';
|
|
111
|
+
this.kid = kid;
|
|
112
|
+
try {
|
|
113
|
+
this.sk = crypto.createPrivateKey({
|
|
114
|
+
key: privatePem,
|
|
115
|
+
format: 'pem',
|
|
116
|
+
});
|
|
117
|
+
// Verify it's RSA
|
|
118
|
+
if (this.sk.asymmetricKeyType !== 'rsa') {
|
|
119
|
+
throw new exceptions_1.DelegationCryptoError('Provided PEM is not an RSA private key');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
throw new exceptions_1.DelegationCryptoError(`Failed to load RSA private key: ${error}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Sign detached signature over body and timestamp
|
|
131
|
+
*/
|
|
132
|
+
signDetached(body, ts) {
|
|
133
|
+
try {
|
|
134
|
+
const data = Buffer.concat([body, Buffer.from('.'), Buffer.from(String(ts))]);
|
|
135
|
+
const signature = crypto.sign('sha256', data, {
|
|
136
|
+
key: this.sk,
|
|
137
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
138
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
alg: this.alg,
|
|
142
|
+
signatureB64: b64e(signature),
|
|
143
|
+
kid: this.kid,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new exceptions_1.DelegationCryptoError(`RSA-PSS signing failed: ${error}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.RsaPssSigner = RsaPssSigner;
|
|
152
|
+
/**
|
|
153
|
+
* Verifier for checking signatures from the IDP
|
|
154
|
+
*/
|
|
155
|
+
class Verifier {
|
|
156
|
+
constructor(pubkeys) {
|
|
157
|
+
if (!pubkeys || Object.keys(pubkeys).length === 0) {
|
|
158
|
+
throw new exceptions_1.DelegationCryptoError('At least one public key is required for verification.');
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
this.pubKeys = new Map();
|
|
162
|
+
for (const [kid, pem] of Object.entries(pubkeys)) {
|
|
163
|
+
const key = crypto.createPublicKey({
|
|
164
|
+
key: pem,
|
|
165
|
+
format: 'pem',
|
|
166
|
+
});
|
|
167
|
+
this.pubKeys.set(kid, key);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
throw new exceptions_1.DelegationCryptoError(`Failed to load one or more public keys: ${error}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Verify signature from IDP
|
|
176
|
+
*/
|
|
177
|
+
verify(body, ts, sigB64, alg, kid) {
|
|
178
|
+
try {
|
|
179
|
+
const sig = b64d(sigB64);
|
|
180
|
+
let pub;
|
|
181
|
+
if (kid && this.pubKeys.has(kid)) {
|
|
182
|
+
pub = this.pubKeys.get(kid);
|
|
183
|
+
}
|
|
184
|
+
else if (this.pubKeys.size === 1 && !kid) {
|
|
185
|
+
pub = Array.from(this.pubKeys.values())[0];
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new exceptions_1.DelegationCryptoError('Unknown or ambiguous key ID for verification');
|
|
189
|
+
}
|
|
190
|
+
const dataToVerify = Buffer.concat([body, Buffer.from('.'), Buffer.from(String(ts))]);
|
|
191
|
+
let isValid = false;
|
|
192
|
+
const keyType = pub.asymmetricKeyType;
|
|
193
|
+
if (alg === 'ed25519' && keyType === 'ed25519') {
|
|
194
|
+
isValid = crypto.verify(null, dataToVerify, pub, sig);
|
|
195
|
+
}
|
|
196
|
+
else if (alg === 'rsa-pss-sha256' && keyType === 'rsa') {
|
|
197
|
+
isValid = crypto.verify('sha256', dataToVerify, {
|
|
198
|
+
key: pub,
|
|
199
|
+
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
|
200
|
+
saltLength: crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN,
|
|
201
|
+
}, sig);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw new exceptions_1.DelegationCryptoError(`Unsupported algorithm '${alg}' or mismatched key type.`);
|
|
205
|
+
}
|
|
206
|
+
if (!isValid) {
|
|
207
|
+
throw new exceptions_1.DelegationCryptoError('Signature verification failed');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
throw new exceptions_1.DelegationCryptoError(`Signature verification failed: ${error}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.Verifier = Verifier;
|
|
219
|
+
// -------- ECIES (X25519 + AES-GCM) --------
|
|
220
|
+
/**
|
|
221
|
+
* ECIES encryptor using X25519 + AES-GCM
|
|
222
|
+
*/
|
|
223
|
+
class EciesX25519Encryptor {
|
|
224
|
+
constructor(peerPubPem) {
|
|
225
|
+
try {
|
|
226
|
+
const key = crypto.createPublicKey({
|
|
227
|
+
key: peerPubPem,
|
|
228
|
+
format: 'pem',
|
|
229
|
+
});
|
|
230
|
+
if (key.asymmetricKeyType !== 'x25519') {
|
|
231
|
+
throw new exceptions_1.DelegationCryptoError('peer_pub_pem must be an X25519 public key');
|
|
232
|
+
}
|
|
233
|
+
// Export raw X25519 public key (32 bytes)
|
|
234
|
+
this.peerPublicKey = key.export({ type: 'spki', format: 'der' }).slice(-32);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
throw new exceptions_1.DelegationCryptoError(`Failed to load ECIES peer public key: ${error}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Encrypt plaintext using ECIES
|
|
245
|
+
*/
|
|
246
|
+
encrypt(plaintext) {
|
|
247
|
+
try {
|
|
248
|
+
// Generate ephemeral X25519 keypair
|
|
249
|
+
const ephPrivateKey = crypto.generateKeyPairSync('x25519', {
|
|
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);
|
|
255
|
+
// Perform ECDH
|
|
256
|
+
const shared = crypto.diffieHellman({
|
|
257
|
+
privateKey: ephPrivKey,
|
|
258
|
+
publicKey: crypto.createPublicKey({
|
|
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
|
+
}),
|
|
266
|
+
});
|
|
267
|
+
// Derive AES key using HKDF
|
|
268
|
+
const key = crypto.hkdfSync('sha256', shared, Buffer.alloc(0), Buffer.from('idp-sp-ecies-v1'), 32);
|
|
269
|
+
// Encrypt with AES-GCM
|
|
270
|
+
const nonce = crypto.randomBytes(12);
|
|
271
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', Buffer.from(key), nonce);
|
|
272
|
+
const ct = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
273
|
+
const tag = cipher.getAuthTag();
|
|
274
|
+
// Get ephemeral public key raw bytes
|
|
275
|
+
const ephPubKeyRaw = ephPubKey.export({ type: 'spki', format: 'der' }).slice(-32);
|
|
276
|
+
// Build envelope
|
|
277
|
+
const envelope = {
|
|
278
|
+
enc: 'x25519-aesgcm',
|
|
279
|
+
epk: b64e(ephPubKeyRaw),
|
|
280
|
+
iv: b64e(nonce),
|
|
281
|
+
ct: b64e(Buffer.concat([ct, tag])),
|
|
282
|
+
};
|
|
283
|
+
return Buffer.from(JSON.stringify(envelope));
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
throw new exceptions_1.DelegationCryptoError(`ECIES encryption failed: ${error}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.EciesX25519Encryptor = EciesX25519Encryptor;
|
|
291
|
+
/**
|
|
292
|
+
* ECIES decryptor using X25519 + AES-GCM
|
|
293
|
+
*/
|
|
294
|
+
class EciesX25519Decryptor {
|
|
295
|
+
constructor(privPem) {
|
|
296
|
+
try {
|
|
297
|
+
this.sk = crypto.createPrivateKey({
|
|
298
|
+
key: privPem,
|
|
299
|
+
format: 'pem',
|
|
300
|
+
});
|
|
301
|
+
if (this.sk.asymmetricKeyType !== 'x25519') {
|
|
302
|
+
throw new exceptions_1.DelegationCryptoError('priv_pem must be an X25519 private key');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
if (error instanceof exceptions_1.DelegationCryptoError) {
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
throw new exceptions_1.DelegationCryptoError(`Failed to load ECIES private key: ${error}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Decrypt ECIES envelope
|
|
314
|
+
*/
|
|
315
|
+
decrypt(envelopeJson) {
|
|
316
|
+
try {
|
|
317
|
+
const envelope = JSON.parse(envelopeJson.toString('utf-8'));
|
|
318
|
+
if (envelope.enc !== 'x25519-aesgcm') {
|
|
319
|
+
throw new exceptions_1.DelegationCryptoError('Unsupported envelope encryption algorithm');
|
|
320
|
+
}
|
|
321
|
+
const epkBytes = b64d(envelope.epk);
|
|
322
|
+
const nonce = b64d(envelope.iv);
|
|
323
|
+
const ctWithTag = b64d(envelope.ct);
|
|
324
|
+
// Split ciphertext and auth tag (last 16 bytes)
|
|
325
|
+
const ct = ctWithTag.slice(0, -16);
|
|
326
|
+
const tag = ctWithTag.slice(-16);
|
|
327
|
+
// Reconstruct ephemeral public key
|
|
328
|
+
const epkDer = Buffer.concat([
|
|
329
|
+
Buffer.from([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x03, 0x21, 0x00]),
|
|
330
|
+
epkBytes,
|
|
331
|
+
]);
|
|
332
|
+
const epk = crypto.createPublicKey({
|
|
333
|
+
key: epkDer,
|
|
334
|
+
format: 'der',
|
|
335
|
+
type: 'spki',
|
|
336
|
+
});
|
|
337
|
+
// Perform ECDH
|
|
338
|
+
const shared = crypto.diffieHellman({
|
|
339
|
+
privateKey: this.sk,
|
|
340
|
+
publicKey: epk,
|
|
341
|
+
});
|
|
342
|
+
// Derive AES key using HKDF
|
|
343
|
+
const key = crypto.hkdfSync('sha256', shared, Buffer.alloc(0), Buffer.from('idp-sp-ecies-v1'), 32);
|
|
344
|
+
// Decrypt with AES-GCM
|
|
345
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(key), nonce);
|
|
346
|
+
decipher.setAuthTag(tag);
|
|
347
|
+
const plaintext = Buffer.concat([decipher.update(ct), decipher.final()]);
|
|
348
|
+
return plaintext;
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
throw new exceptions_1.DelegationCryptoError(`ECIES decryption failed: ${error}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
exports.EciesX25519Decryptor = EciesX25519Decryptor;
|
|
356
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/delegation/crypto.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUH,oBAEC;AAVD,+CAAiC;AACjC,6CAAqD;AAErD,4BAA4B;AAE5B;;GAEG;AACH,SAAgB,IAAI;IAClB,OAAO,IAAI,CAAC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AQ;aACT,CAAC,CAAC;YAEH,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC;gBACjC,GAAG,EAAE,MAAM;gBACX,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,MAAM;aACb,CAAC,CAAC;YAEH,eAAe;YACf,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;gBAClC,UAAU,EAAE,IAAI,CAAC,EAAE;gBACnB,SAAS,EAAE,GAAG;aACf,CAAC,CAAC;YAEH,4BAA4B;YAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAAC,CAAC;YAEnG,uBAAuB;YACvB,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;YACjF,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACzB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAEzE,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,kCAAqB,CAAC,4BAA4B,KAAK,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CACF;AAvED,oDAuEC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom exceptions for the Delegation module
|
|
3
|
+
*/
|
|
4
|
+
import { HawcxOAuthError } from '../exceptions';
|
|
5
|
+
/**
|
|
6
|
+
* Base exception for delegation errors
|
|
7
|
+
*/
|
|
8
|
+
export declare class DelegationError extends HawcxOAuthError {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Raised for cryptographic errors (signing, encryption, etc.)
|
|
13
|
+
*/
|
|
14
|
+
export declare class DelegationCryptoError extends DelegationError {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Raised for errors sending requests to the IDP
|
|
19
|
+
*/
|
|
20
|
+
export declare class DelegationRequestError extends DelegationError {
|
|
21
|
+
statusCode?: number;
|
|
22
|
+
responseBody?: string;
|
|
23
|
+
constructor(message: string, statusCode?: number, responseBody?: string);
|
|
24
|
+
toString(): string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Raised for errors in the IDP's response
|
|
28
|
+
*/
|
|
29
|
+
export declare class DelegationResponseError extends DelegationError {
|
|
30
|
+
constructor(message: string);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/delegation/exceptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD;;GAEG;AACH,qBAAa,eAAgB,SAAQ,eAAe;gBACtC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,eAAe;gBAC5C,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,eAAe;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;IAQvE,QAAQ,IAAI,MAAM;CAOnB;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom exceptions for the Delegation module
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DelegationResponseError = exports.DelegationRequestError = exports.DelegationCryptoError = exports.DelegationError = void 0;
|
|
7
|
+
const exceptions_1 = require("../exceptions");
|
|
8
|
+
/**
|
|
9
|
+
* Base exception for delegation errors
|
|
10
|
+
*/
|
|
11
|
+
class DelegationError extends exceptions_1.HawcxOAuthError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'DelegationError';
|
|
15
|
+
Object.setPrototypeOf(this, DelegationError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.DelegationError = DelegationError;
|
|
19
|
+
/**
|
|
20
|
+
* Raised for cryptographic errors (signing, encryption, etc.)
|
|
21
|
+
*/
|
|
22
|
+
class DelegationCryptoError extends DelegationError {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'DelegationCryptoError';
|
|
26
|
+
Object.setPrototypeOf(this, DelegationCryptoError.prototype);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DelegationCryptoError = DelegationCryptoError;
|
|
30
|
+
/**
|
|
31
|
+
* Raised for errors sending requests to the IDP
|
|
32
|
+
*/
|
|
33
|
+
class DelegationRequestError extends DelegationError {
|
|
34
|
+
constructor(message, statusCode, responseBody) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'DelegationRequestError';
|
|
37
|
+
this.statusCode = statusCode;
|
|
38
|
+
this.responseBody = responseBody;
|
|
39
|
+
Object.setPrototypeOf(this, DelegationRequestError.prototype);
|
|
40
|
+
}
|
|
41
|
+
toString() {
|
|
42
|
+
let base = this.message;
|
|
43
|
+
if (this.statusCode) {
|
|
44
|
+
base = `${base} (HTTP ${this.statusCode})`;
|
|
45
|
+
}
|
|
46
|
+
return base;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DelegationRequestError = DelegationRequestError;
|
|
50
|
+
/**
|
|
51
|
+
* Raised for errors in the IDP's response
|
|
52
|
+
*/
|
|
53
|
+
class DelegationResponseError extends DelegationError {
|
|
54
|
+
constructor(message) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = 'DelegationResponseError';
|
|
57
|
+
Object.setPrototypeOf(this, DelegationResponseError.prototype);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.DelegationResponseError = DelegationResponseError;
|
|
61
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/delegation/exceptions.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,8CAAgD;AAEhD;;GAEG;AACH,MAAa,eAAgB,SAAQ,4BAAe;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AAND,0CAMC;AAED;;GAEG;AACH,MAAa,qBAAsB,SAAQ,eAAe;IACxD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC/D,CAAC;CACF;AAND,sDAMC;AAED;;GAEG;AACH,MAAa,sBAAuB,SAAQ,eAAe;IAIzD,YAAY,OAAe,EAAE,UAAmB,EAAE,YAAqB;QACrE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU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