@hawcx/oauth-client 4.0.1 → 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/LICENSE +22 -0
- package/README.md +134 -16
- 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/hawcx.d.ts +0 -8
- package/dist/delegation/hawcx.d.ts.map +1 -1
- package/dist/delegation/hawcx.js +0 -17
- package/dist/delegation/hawcx.js.map +1 -1
- package/dist/delegation/index.d.ts +1 -1
- package/dist/delegation/index.d.ts.map +1 -1
- package/dist/delegation/index.js.map +1 -1
- package/dist/errors.d.ts +51 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -6
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +188 -21
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +390 -43
- package/dist/oauth.js.map +1 -1
- package/dist/stepup/client.d.ts.map +1 -1
- package/dist/stepup/client.js +5 -11
- package/dist/stepup/client.js.map +1 -1
- package/dist/stepup/types.d.ts +2 -3
- package/dist/stepup/types.d.ts.map +1 -1
- package/package.json +11 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Hawcx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ Simple, production-ready OAuth client SDK for Hawcx authentication.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
+
- **OIDC Discovery** - `HawcxOAuth.fromIssuer(...)` resolves endpoints from `/.well-known/openid-configuration` and enforces signature + `iss` + `aud` + `exp` + `nbf` on verify
|
|
7
8
|
- **Simple JWT Verification** - Uses `jose` library for automatic JWKS caching and signature handling
|
|
8
9
|
- **PKCE Support** - Native PKCE (RFC 7636) support for enhanced OAuth security
|
|
9
10
|
- **Delegation API** - Server-to-server user management (MFA, devices)
|
|
@@ -17,19 +18,89 @@ Simple, production-ready OAuth client SDK for Hawcx authentication.
|
|
|
17
18
|
npm install @hawcx/oauth-client
|
|
18
19
|
```
|
|
19
20
|
|
|
20
|
-
## Quick Start
|
|
21
|
+
## Quick Start (OIDC discovery, recommended)
|
|
22
|
+
|
|
23
|
+
`HawcxOAuth.fromIssuer(...)` does the discovery fetch once at startup and
|
|
24
|
+
gives you a client whose `exchangeCode` + `verifyToken` enforce all the
|
|
25
|
+
standard OIDC claim checks. Construct once and reuse.
|
|
21
26
|
|
|
22
27
|
```typescript
|
|
23
28
|
import { HawcxOAuth } from '@hawcx/oauth-client';
|
|
24
29
|
|
|
25
|
-
const oauth =
|
|
30
|
+
const oauth = await HawcxOAuth.fromIssuer({
|
|
31
|
+
issuer: 'https://api.hawcx.com', // → discovery + expected `iss`
|
|
32
|
+
configId: process.env.HAWCX_CONFIG_ID!, // → X-Config-Id header
|
|
33
|
+
clientId: process.env.HAWCX_CLIENT_ID!, // → expected `aud` on id_tokens
|
|
34
|
+
});
|
|
26
35
|
|
|
27
|
-
// Exchange authorization code for tokens
|
|
28
36
|
const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
|
|
29
37
|
console.log(claims.sub); // user ID
|
|
30
38
|
console.log(claims.email); // user email
|
|
31
39
|
```
|
|
32
40
|
|
|
41
|
+
> **`configId` vs `clientId` — they are different values.**
|
|
42
|
+
> Hawcx separates the tenant routing key from the audience claim:
|
|
43
|
+
>
|
|
44
|
+
> - **`configId`** — the per-tenant config identifier. Sent as the
|
|
45
|
+
> `X-Config-Id` header on the token-exchange POST so the OAuth server
|
|
46
|
+
> can look up the tenant.
|
|
47
|
+
> - **`clientId`** — the value the tenant has configured (in the Hawcx
|
|
48
|
+
> admin console) as the `aud` claim on issued id_tokens. The verifier
|
|
49
|
+
> matches the token's `aud` against this exact string.
|
|
50
|
+
>
|
|
51
|
+
> Passing the same value for both fails verification with
|
|
52
|
+
> `Unexpected JWT audience` unless your tenant happens to use identical
|
|
53
|
+
> strings.
|
|
54
|
+
|
|
55
|
+
## Quick Start (legacy)
|
|
56
|
+
|
|
57
|
+
The legacy single-arg constructor still works for backward compatibility
|
|
58
|
+
with 4.x callers. It verifies the JWT signature only — `iss` and `aud`
|
|
59
|
+
are not checked. Prefer `fromIssuer` for new code.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { HawcxOAuth } from '@hawcx/oauth-client';
|
|
63
|
+
|
|
64
|
+
const oauth = new HawcxOAuth({ configId: 'your-config-id' });
|
|
65
|
+
|
|
66
|
+
const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Confidential clients (`private_key_jwt`)
|
|
72
|
+
|
|
73
|
+
If your project is registered in the Hawcx admin console with **Client
|
|
74
|
+
authentication = Signing key (`private_key_jwt`)**, attach an Ed25519 signer.
|
|
75
|
+
The SDK then signs an RFC 7523 `client_assertion` on every token exchange
|
|
76
|
+
(PKCE is still sent). Public clients omit this and keep using PKCE only.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { HawcxOAuth, ClientAssertionSigner } from '@hawcx/oauth-client';
|
|
80
|
+
|
|
81
|
+
const privateJwk = JSON.parse(process.env.HAWCX_PRIVATE_JWK!); // OKP/Ed25519, with kid
|
|
82
|
+
|
|
83
|
+
const oauth = (
|
|
84
|
+
await HawcxOAuth.fromIssuer({
|
|
85
|
+
issuer: 'https://dev-demo-api.hawcx.com',
|
|
86
|
+
configId: process.env.HAWCX_CONFIG_ID!,
|
|
87
|
+
clientId: process.env.HAWCX_CLIENT_ID!,
|
|
88
|
+
})
|
|
89
|
+
).withClientAssertion(ClientAssertionSigner.ed25519FromJwk(privateJwk));
|
|
90
|
+
|
|
91
|
+
const { idToken, claims } = await oauth.exchangeCode(code, codeVerifier);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The private key must be Ed25519 (`kty: 'OKP', crv: 'Ed25519'`, with a `kid`);
|
|
95
|
+
its public JWK is what you register in the admin console. The assertion's `aud`
|
|
96
|
+
is the discovered `token_endpoint`, and EdDSA is the only accepted algorithm.
|
|
97
|
+
`clientId` must be the confidential client's id — it becomes the assertion
|
|
98
|
+
`iss`/`sub` and the id_token `aud`.
|
|
99
|
+
|
|
100
|
+
> If you bound a `nonce` at `/authorize`, pass it as the 4th argument to
|
|
101
|
+
> `exchangeCode(code, verifier, redirectUri?, expectedNonce)` — verification
|
|
102
|
+
> refuses a nonce-bearing token when none is supplied (OIDC Core §3.1.3.7).
|
|
103
|
+
|
|
33
104
|
---
|
|
34
105
|
|
|
35
106
|
## Modules
|
|
@@ -46,21 +117,45 @@ console.log(claims.email); // user email
|
|
|
46
117
|
|
|
47
118
|
Core module for OAuth 2.1 + PKCE authentication.
|
|
48
119
|
|
|
49
|
-
###
|
|
120
|
+
### Construction
|
|
121
|
+
|
|
122
|
+
#### Discovery mode (recommended)
|
|
50
123
|
|
|
51
124
|
```typescript
|
|
52
125
|
import { HawcxOAuth } from '@hawcx/oauth-client';
|
|
53
126
|
|
|
127
|
+
const oauth = await HawcxOAuth.fromIssuer({
|
|
128
|
+
issuer: 'https://api.hawcx.com', // Required: discovery + expected `iss`
|
|
129
|
+
configId: 'your-config-id', // Required: X-Config-Id header
|
|
130
|
+
clientId: 'your-client-id', // Required: expected `aud` on id_tokens
|
|
131
|
+
timeout: 10000, // Optional: per-request timeout in ms
|
|
132
|
+
discoveryTimeout: 5000, // Optional: discovery fetch timeout in ms
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
oauth.discoveryMetadata; // resolved OIDC discovery doc, for diagnostics
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Throws `DiscoveryError` if the discovery document is unreachable, returns
|
|
139
|
+
non-2xx, isn't valid JSON, or is missing any of `token_endpoint`,
|
|
140
|
+
`jwks_uri`, `id_token_signing_alg_values_supported`.
|
|
141
|
+
|
|
142
|
+
#### Legacy mode
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
54
145
|
const oauth = new HawcxOAuth({
|
|
55
|
-
configId: 'your-config-id', // Required
|
|
56
|
-
baseUrl: 'https://api.hawcx.com', // Optional:
|
|
57
|
-
timeout: 10000, // Optional
|
|
146
|
+
configId: 'your-config-id', // Required
|
|
147
|
+
baseUrl: 'https://api.hawcx.com', // Optional: defaults to api.hawcx.com
|
|
148
|
+
timeout: 10000, // Optional
|
|
58
149
|
});
|
|
59
150
|
```
|
|
60
151
|
|
|
152
|
+
Hits the fixed endpoints `<baseUrl>/oauth2/token` and `<baseUrl>/keys`
|
|
153
|
+
directly. **Signature-only verification** — `iss` and `aud` are not
|
|
154
|
+
checked. Kept for backward compatibility with 4.x callers.
|
|
155
|
+
|
|
61
156
|
### Methods
|
|
62
157
|
|
|
63
|
-
#### `exchangeCode(code, codeVerifier): Promise<ExchangeResult>`
|
|
158
|
+
#### `exchangeCode(code, codeVerifier, redirectUri?): Promise<ExchangeResult>`
|
|
64
159
|
|
|
65
160
|
Exchange an authorization code for tokens.
|
|
66
161
|
|
|
@@ -69,6 +164,13 @@ const { idToken, claims } = await oauth.exchangeCode(
|
|
|
69
164
|
'authorization-code',
|
|
70
165
|
'pkce-code-verifier'
|
|
71
166
|
);
|
|
167
|
+
|
|
168
|
+
// With redirect_uri (RFC 6749 §4.1.3) when your auth request registered one:
|
|
169
|
+
const { idToken, claims } = await oauth.exchangeCode(
|
|
170
|
+
'authorization-code',
|
|
171
|
+
'pkce-code-verifier',
|
|
172
|
+
'https://app.example.com/auth/callback'
|
|
173
|
+
);
|
|
72
174
|
```
|
|
73
175
|
|
|
74
176
|
**Returns:**
|
|
@@ -79,12 +181,16 @@ interface ExchangeResult {
|
|
|
79
181
|
}
|
|
80
182
|
```
|
|
81
183
|
|
|
82
|
-
#### `verifyToken(token): Promise<JwtClaims>`
|
|
184
|
+
#### `verifyToken(token, options?): Promise<JwtClaims>`
|
|
83
185
|
|
|
84
|
-
Verify an existing JWT token.
|
|
186
|
+
Verify an existing JWT token. In discovery mode, enforces signature + `iss` +
|
|
187
|
+
`aud` + `exp` + `nbf`. In legacy mode, only the signature is checked.
|
|
85
188
|
|
|
86
189
|
```typescript
|
|
87
190
|
const claims = await oauth.verifyToken(idToken);
|
|
191
|
+
|
|
192
|
+
// With expected nonce (useful for flows that bind a nonce to the auth request):
|
|
193
|
+
const claims = await oauth.verifyToken(idToken, { nonce: 'expected-nonce' });
|
|
88
194
|
```
|
|
89
195
|
|
|
90
196
|
**Returns:**
|
|
@@ -99,34 +205,46 @@ interface JwtClaims {
|
|
|
99
205
|
name?: string; // User name
|
|
100
206
|
amr?: string[]; // Authentication methods
|
|
101
207
|
mfa_method?: string; // MFA method used
|
|
208
|
+
nonce?: string; // Nonce (if bound)
|
|
102
209
|
}
|
|
103
210
|
```
|
|
104
211
|
|
|
105
|
-
#### `
|
|
212
|
+
#### `refreshJwks(): void`
|
|
106
213
|
|
|
107
|
-
|
|
214
|
+
Reset the JWKS cache so the next verification refetches keys (useful for testing
|
|
215
|
+
or key rotation).
|
|
108
216
|
|
|
109
217
|
```typescript
|
|
110
|
-
oauth.
|
|
218
|
+
oauth.refreshJwks();
|
|
111
219
|
```
|
|
112
220
|
|
|
221
|
+
> **Deprecated:** `clearCache()` is a deprecated passthrough that calls
|
|
222
|
+
> `refreshJwks()` (and emits a one-time `console.warn`). It still works but will be
|
|
223
|
+
> removed in 6.0.0 — prefer `refreshJwks()`.
|
|
224
|
+
|
|
113
225
|
### Errors
|
|
114
226
|
|
|
115
227
|
```typescript
|
|
116
228
|
import {
|
|
117
229
|
HawcxOAuthError, // Base error class
|
|
230
|
+
DiscoveryError, // OIDC discovery resolution failed (fromIssuer only)
|
|
118
231
|
TokenExchangeError, // Code exchange failed
|
|
119
232
|
TokenVerificationError // JWT verification failed
|
|
120
233
|
} from '@hawcx/oauth-client';
|
|
121
234
|
|
|
122
235
|
try {
|
|
236
|
+
const oauth = await HawcxOAuth.fromIssuer({ issuer, configId, clientId });
|
|
123
237
|
await oauth.exchangeCode(code, verifier);
|
|
124
238
|
} catch (error) {
|
|
239
|
+
if (error instanceof DiscoveryError) {
|
|
240
|
+
console.log(error.cause); // original network / parse error
|
|
241
|
+
}
|
|
125
242
|
if (error instanceof TokenExchangeError) {
|
|
126
243
|
console.log(error.statusCode); // HTTP status code
|
|
127
244
|
}
|
|
128
245
|
if (error instanceof TokenVerificationError) {
|
|
129
|
-
|
|
246
|
+
// "Token expired", "Invalid signature", "Unexpected JWT audience: ...", etc.
|
|
247
|
+
console.log(error.message);
|
|
130
248
|
}
|
|
131
249
|
}
|
|
132
250
|
```
|
|
@@ -551,7 +669,7 @@ The SDK automatically caches JWKS (JSON Web Key Set) for JWT verification:
|
|
|
551
669
|
- Keys are fetched lazily on first `verifyToken()` call
|
|
552
670
|
- Cached in memory for the lifetime of the `HawcxOAuth` instance
|
|
553
671
|
- Auto-refreshes if a key ID isn't found (handles key rotation)
|
|
554
|
-
- Call `
|
|
672
|
+
- Call `refreshJwks()` to force a refresh (`clearCache()` is a deprecated alias — see above)
|
|
555
673
|
|
|
556
674
|
```typescript
|
|
557
675
|
// Keys fetched once, cached thereafter
|
|
@@ -560,7 +678,7 @@ const claims2 = await oauth.verifyToken(token2); // Uses cache
|
|
|
560
678
|
const claims3 = await oauth.verifyToken(token3); // Uses cache
|
|
561
679
|
|
|
562
680
|
// Force refresh if needed
|
|
563
|
-
oauth.
|
|
681
|
+
oauth.refreshJwks();
|
|
564
682
|
const claims4 = await oauth.verifyToken(token4); // Fetches JWKS again
|
|
565
683
|
```
|
|
566
684
|
|
|
@@ -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,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAI,CAAC;gBACH,GAAG,GAA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|
|
43
43
|
otp: string;
|
|
44
44
|
}
|
|
45
|
-
export interface UpdatePhoneOptions {
|
|
46
|
-
/** User identifier (userid or email) */
|
|
47
|
-
userId: string;
|
|
48
|
-
/** New phone number in E.164 format (e.g. "+14155551234"). Pass null to clear. */
|
|
49
|
-
newPhoneNumber: string | null;
|
|
50
|
-
}
|
|
51
45
|
export interface DeviceOperationOptions {
|
|
52
46
|
/** User identifier (typically email address) */
|
|
53
47
|
userId: string;
|
|
@@ -83,8 +77,6 @@ export declare class DelegationClient {
|
|
|
83
77
|
};
|
|
84
78
|
readonly users: {
|
|
85
79
|
getCredentials: (userId: string) => Promise<JsonObject>;
|
|
86
|
-
getPhone: (userId: string) => Promise<JsonObject>;
|
|
87
|
-
updatePhone: (options: UpdatePhoneOptions) => Promise<JsonObject>;
|
|
88
80
|
};
|
|
89
81
|
readonly devices: {
|
|
90
82
|
list: (userId: string) => Promise<JsonObject>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hawcx.d.ts","sourceRoot":"","sources":["../../src/delegation/hawcx.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAuD,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAGvG,oBAAY,SAAS;IACnB,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,MAAM,WAAW,2BAA2B;IAC1C,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gCAAiC,SAAQ,2BAA2B;IACnF,0CAA0C;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tE,OAAO,CAAC,gBAAgB;IAQlB,OAAO,CAAC,IAAI,SAAS,UAAU,EAAE,IAAI,SAAS,UAAU,EAC5D,OAAO,EAAE,wBAAwB,CAAC,IAAI,CAAC,GACtC,OAAO,CAAC,IAAI,CAAC;IAKhB,SAAgB,GAAG;4BACS,kBAAkB,KAAG,OAAO,CAAC,UAAU,CAAC;0BAmC1C,gBAAgB,KAAG,OAAO,CAAC,UAAU,CAAC;MAkB9D;IAEF,SAAgB,KAAK;iCACY,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC;MAO3D;IAEF,SAAgB,OAAO;uBACA,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC;0BAOzB,sBAAsB,KAAG,OAAO,CAAC,UAAU,CAAC;4BAO1C,sBAAsB,KAAG,OAAO,CAAC,UAAU,CAAC;0BAO9C,sBAAsB,KAAG,OAAO,CAAC,UAAU,CAAC;MAOpE;CACH"}
|
package/dist/delegation/hawcx.js
CHANGED
|
@@ -65,23 +65,6 @@ class DelegationClient {
|
|
|
65
65
|
payload,
|
|
66
66
|
});
|
|
67
67
|
},
|
|
68
|
-
getPhone: async (userId) => {
|
|
69
|
-
const payload = { userid: userId };
|
|
70
|
-
return await this.request({
|
|
71
|
-
endpoint: '/hc_auth/v5/management/users/phone',
|
|
72
|
-
payload,
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
updatePhone: async (options) => {
|
|
76
|
-
const payload = {
|
|
77
|
-
userid: options.userId,
|
|
78
|
-
new_phone_number: options.newPhoneNumber,
|
|
79
|
-
};
|
|
80
|
-
return await this.request({
|
|
81
|
-
endpoint: '/hc_auth/v5/management/users/phone',
|
|
82
|
-
payload,
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
68
|
};
|
|
86
69
|
this.devices = {
|
|
87
70
|
list: async (userId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hawcx.js","sourceRoot":"","sources":["../../src/delegation/hawcx.ts"],"names":[],"mappings":";AAAA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BaseOptions, DelegationClientSecretKeyOptions, DelegationClientKeyOptions, MfaInitiateOptions, MfaVerifyOptions,
|
|
5
|
+
export type { DelegationClientBaseOptions, DelegationClientSecretKeyOptions, DelegationClientKeyOptions, MfaInitiateOptions, MfaVerifyOptions, DeviceOperationOptions, DelegationRequestOptions, } from './hawcx';
|
|
6
6
|
export { parseHawcxSecretKey, generateCredentialBlob, } from './credentials';
|
|
7
7
|
export type { ParsedCredentials, HawcxCredentialBlob, } from './credentials';
|
|
8
8
|
export { DelegationError, DelegationCryptoError, DelegationRequestError, DelegationResponseError, } from './exceptions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/delegation/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,2BAA2B,EAC3B,gCAAgC,EAChC,0BAA0B,EAC1B,kBAAkB,EAClB,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/delegation/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,2BAA2B,EAC3B,gCAAgC,EAChC,0BAA0B,EAC1B,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/delegation/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAGiB;AAFf,yGAAA,gBAAgB,OAAA;AAChB,kGAAA,SAAS,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/delegation/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAGiB;AAFf,yGAAA,gBAAgB,OAAA;AAChB,kGAAA,SAAS,OAAA;AAYX,6CAGuB;AAFrB,kHAAA,mBAAmB,OAAA;AACnB,qHAAA,sBAAsB,OAAA;AAOxB,2CAKsB;AAJpB,6GAAA,eAAe,OAAA;AACf,mHAAA,qBAAqB,OAAA;AACrB,oHAAA,sBAAsB,OAAA;AACtB,qHAAA,uBAAuB,OAAA"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,14 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hawcx OAuth Errors
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Optional structured fields shared across the Hawcx OAuth error hierarchy.
|
|
6
|
+
* `error` is a stable machine-readable code callers can dispatch on (e.g.
|
|
7
|
+
* `'state_mismatch'`, `'state_missing'`, or an IdP-supplied OAuth error such as
|
|
8
|
+
* `'access_denied'`); `errorDescription` is the human-readable detail when one
|
|
9
|
+
* is available. Both are optional and never affect `.message`.
|
|
10
|
+
*/
|
|
11
|
+
export interface HawcxOAuthErrorFields {
|
|
12
|
+
/** Machine-readable error code (e.g. `'state_mismatch'`, `'access_denied'`). */
|
|
13
|
+
error?: string;
|
|
14
|
+
/** Human-readable error description, when one is available. */
|
|
15
|
+
errorDescription?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Canonical root for every Hawcx SDK error, aligned with the Java/Python SDKs
|
|
19
|
+
* (`HawcxError`). Catch this to handle any SDK-originated failure.
|
|
20
|
+
*/
|
|
21
|
+
export declare class HawcxError extends Error {
|
|
5
22
|
constructor(message: string);
|
|
6
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Historical base, retained for back-compat. Now a subclass of {@link HawcxError};
|
|
26
|
+
* every SDK error is catchable via either. New code can catch `HawcxError`.
|
|
27
|
+
*
|
|
28
|
+
* Carries optional structured {@link HawcxOAuthErrorFields} (`error` /
|
|
29
|
+
* `errorDescription`) so callers can dispatch on a stable code without parsing
|
|
30
|
+
* `.message`. These are populated at the relevant raise sites and never alter
|
|
31
|
+
* the thrown message string.
|
|
32
|
+
*/
|
|
33
|
+
export declare class HawcxOAuthError extends HawcxError {
|
|
34
|
+
/** Machine-readable error code, when set at the raise site. */
|
|
35
|
+
readonly error?: string;
|
|
36
|
+
/** Human-readable error description, when available. */
|
|
37
|
+
readonly errorDescription?: string;
|
|
38
|
+
constructor(message: string, fields?: HawcxOAuthErrorFields);
|
|
39
|
+
}
|
|
7
40
|
export declare class TokenExchangeError extends HawcxOAuthError {
|
|
8
41
|
readonly statusCode?: number;
|
|
9
|
-
constructor(message: string, statusCode?: number);
|
|
42
|
+
constructor(message: string, statusCode?: number, fields?: HawcxOAuthErrorFields);
|
|
10
43
|
}
|
|
11
44
|
export declare class TokenVerificationError extends HawcxOAuthError {
|
|
12
|
-
constructor(message: string);
|
|
45
|
+
constructor(message: string, fields?: HawcxOAuthErrorFields);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Thrown when OIDC discovery (`HawcxOAuth.fromIssuer`) cannot resolve a usable
|
|
49
|
+
* provider configuration — DNS / TLS / network failure, non-2xx response from
|
|
50
|
+
* `/.well-known/openid-configuration`, malformed JSON, or a discovery document
|
|
51
|
+
* missing required fields (`token_endpoint`, `jwks_uri`,
|
|
52
|
+
* `id_token_signing_alg_values_supported`).
|
|
53
|
+
*
|
|
54
|
+
* The original failure (when present) is attached as `cause`, so the full
|
|
55
|
+
* diagnostic stack survives.
|
|
56
|
+
*/
|
|
57
|
+
export declare class DiscoveryError extends HawcxOAuthError {
|
|
58
|
+
constructor(message: string, options?: {
|
|
59
|
+
cause?: unknown;
|
|
60
|
+
} & HawcxOAuthErrorFields);
|
|
13
61
|
}
|
|
14
62
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;CAM5D;AAED,qBAAa,kBAAmB,SAAQ,eAAe;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;CAKjF;AAED,qBAAa,sBAAuB,SAAQ,eAAe;gBAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;CAI5D;AAED;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,eAAe;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,qBAAqB;CAOnF"}
|