@sudoplatform/sudo-user 16.0.2 → 17.0.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/cjs/core/auth-store.js +6 -6
- package/cjs/core/auth-store.js.map +1 -1
- package/cjs/core/key-manager.js +3 -4
- package/cjs/core/key-manager.js.map +1 -1
- package/cjs/user/auth-provider.js +8 -9
- package/cjs/user/auth-provider.js.map +1 -1
- package/cjs/user/auth.js +2 -3
- package/cjs/user/auth.js.map +1 -1
- package/cjs/user/user-client.js +4 -5
- package/cjs/user/user-client.js.map +1 -1
- package/cjs/utils/jwt.js +230 -0
- package/cjs/utils/jwt.js.map +1 -0
- package/cjs/utils/sign-options-builder.js +1 -2
- package/cjs/utils/sign-options-builder.js.map +1 -1
- package/docs/classes/AlreadyRegisteredError.html +2 -2
- package/docs/classes/DefaultSudoUserClient.html +32 -32
- package/docs/classes/IdentityServiceConfigNotFoundError.html +2 -2
- package/docs/classes/LocalAuthenticationProvider.html +4 -4
- package/docs/classes/TESTAuthenticationProvider.html +4 -4
- package/docs/classes/internal.AmplifyClient.html +5 -5
- package/docs/enums/GraphQLClientAuthMode.html +2 -2
- package/docs/functions/internal.getIdentityServiceConfig.html +1 -1
- package/docs/interfaces/AuthenticationProvider.html +3 -3
- package/docs/interfaces/AuthenticationTokens.html +2 -2
- package/docs/interfaces/GraphQLClient.html +4 -4
- package/docs/interfaces/GraphQLClientOptions.html +7 -7
- package/docs/interfaces/SudoUserClient.html +27 -27
- package/docs/interfaces/internal.SudoUserOptions.html +2 -2
- package/docs/types/IAMCredentials.html +2 -2
- package/docs/types/TokenProvider.html +1 -1
- package/docs/types/internal.Config.html +1 -1
- package/docs/types/internal.FederatedSignInConfig.html +1 -1
- package/docs/types/internal.IdentityServiceConfig.html +1 -1
- package/docs/variables/internal.Config.html +1 -1
- package/docs/variables/internal.FederatedSignInConfigCodec.html +1 -1
- package/docs/variables/internal.IdentityServiceConfigCodec.html +1 -1
- package/lib/core/auth-store.js +6 -6
- package/lib/core/auth-store.js.map +1 -1
- package/lib/core/key-manager.js +3 -4
- package/lib/core/key-manager.js.map +1 -1
- package/lib/user/auth-provider.js +8 -8
- package/lib/user/auth-provider.js.map +1 -1
- package/lib/user/auth.js +2 -2
- package/lib/user/auth.js.map +1 -1
- package/lib/user/user-client.js +4 -4
- package/lib/user/user-client.js.map +1 -1
- package/lib/utils/jwt.js +226 -0
- package/lib/utils/jwt.js.map +1 -0
- package/lib/utils/sign-options-builder.js +1 -2
- package/lib/utils/sign-options-builder.js.map +1 -1
- package/package.json +19 -10
- package/types/utils/jwt.d.ts +21 -0
- package/types/utils/sign-options-builder.d.ts +2 -2
package/lib/utils/jwt.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Anonyome Labs, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { SignJWT, jwtVerify, importPKCS8, importSPKI } from 'jose';
|
|
7
|
+
/**
|
|
8
|
+
* Check if running in Node.js environment (where Buffer is available)
|
|
9
|
+
* @returns true if in Node.js, false if in browser
|
|
10
|
+
*/
|
|
11
|
+
function isNodeEnvironment() {
|
|
12
|
+
return typeof Buffer !== 'undefined';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Base64 decode that works in both Node.js and browser
|
|
16
|
+
*/
|
|
17
|
+
function base64Decode(base64) {
|
|
18
|
+
if (isNodeEnvironment()) {
|
|
19
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const binaryString = atob(base64);
|
|
23
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
24
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
25
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
26
|
+
}
|
|
27
|
+
return bytes;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Base64 encode that works in both Node.js and browser
|
|
32
|
+
*/
|
|
33
|
+
function base64Encode(bytes) {
|
|
34
|
+
if (isNodeEnvironment()) {
|
|
35
|
+
return Buffer.from(bytes).toString('base64');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
let binary = '';
|
|
39
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
40
|
+
binary += String.fromCharCode(bytes[i]);
|
|
41
|
+
}
|
|
42
|
+
return btoa(binary);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert PKCS#1 RSA PRIVATE KEY to PKCS#8 format
|
|
47
|
+
* This wraps the PKCS#1 key with the PKCS#8 structure
|
|
48
|
+
* @internal Exported for testing purposes
|
|
49
|
+
*/
|
|
50
|
+
export function convertPKCS1ToPKCS8(pkcs1Pem) {
|
|
51
|
+
// Extract the base64 content from PKCS#1 PEM
|
|
52
|
+
const base64 = pkcs1Pem
|
|
53
|
+
.replace('-----BEGIN RSA PRIVATE KEY-----', '')
|
|
54
|
+
.replace('-----END RSA PRIVATE KEY-----', '')
|
|
55
|
+
.replace(/\s/g, '');
|
|
56
|
+
// Decode base64 to get the DER bytes
|
|
57
|
+
const derBytes = base64Decode(base64);
|
|
58
|
+
// PKCS#8 structure for RSA:
|
|
59
|
+
// SEQUENCE {
|
|
60
|
+
// version INTEGER (0)
|
|
61
|
+
// algorithm SEQUENCE {
|
|
62
|
+
// algorithm OBJECT IDENTIFIER (rsaEncryption: 1.2.840.113549.1.1.1)
|
|
63
|
+
// parameters NULL
|
|
64
|
+
// }
|
|
65
|
+
// privateKey OCTET STRING (contains the PKCS#1 DER)
|
|
66
|
+
// }
|
|
67
|
+
// RSA algorithm identifier (1.2.840.113549.1.1.1) with NULL parameters
|
|
68
|
+
const algorithmIdentifier = new Uint8Array([
|
|
69
|
+
0x30,
|
|
70
|
+
0x0d, // SEQUENCE length 13
|
|
71
|
+
0x06,
|
|
72
|
+
0x09, // OID length 9
|
|
73
|
+
0x2a,
|
|
74
|
+
0x86,
|
|
75
|
+
0x48,
|
|
76
|
+
0x86,
|
|
77
|
+
0xf7,
|
|
78
|
+
0x0d,
|
|
79
|
+
0x01,
|
|
80
|
+
0x01,
|
|
81
|
+
0x01, // rsaEncryption OID
|
|
82
|
+
0x05,
|
|
83
|
+
0x00, // NULL
|
|
84
|
+
]);
|
|
85
|
+
// Version (INTEGER 0)
|
|
86
|
+
const version = new Uint8Array([0x02, 0x01, 0x00]);
|
|
87
|
+
// Wrap PKCS#1 in OCTET STRING
|
|
88
|
+
const pkcs1Length = derBytes.length;
|
|
89
|
+
let lengthBytes;
|
|
90
|
+
if (pkcs1Length < 128) {
|
|
91
|
+
lengthBytes = new Uint8Array([pkcs1Length]);
|
|
92
|
+
}
|
|
93
|
+
else if (pkcs1Length < 256) {
|
|
94
|
+
lengthBytes = new Uint8Array([0x81, pkcs1Length]);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
lengthBytes = new Uint8Array([
|
|
98
|
+
0x82,
|
|
99
|
+
(pkcs1Length >> 8) & 0xff,
|
|
100
|
+
pkcs1Length & 0xff,
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
const octetStringHeader = new Uint8Array([0x04]);
|
|
104
|
+
const octetString = new Uint8Array(octetStringHeader.length + lengthBytes.length + derBytes.length);
|
|
105
|
+
octetString.set(octetStringHeader, 0);
|
|
106
|
+
octetString.set(lengthBytes, octetStringHeader.length);
|
|
107
|
+
octetString.set(derBytes, octetStringHeader.length + lengthBytes.length);
|
|
108
|
+
// Build the PKCS#8 structure
|
|
109
|
+
const pkcs8Content = new Uint8Array(version.length + algorithmIdentifier.length + octetString.length);
|
|
110
|
+
pkcs8Content.set(version, 0);
|
|
111
|
+
pkcs8Content.set(algorithmIdentifier, version.length);
|
|
112
|
+
pkcs8Content.set(octetString, version.length + algorithmIdentifier.length);
|
|
113
|
+
// Wrap in outer SEQUENCE
|
|
114
|
+
const totalLength = pkcs8Content.length;
|
|
115
|
+
let sequenceLengthBytes;
|
|
116
|
+
if (totalLength < 128) {
|
|
117
|
+
sequenceLengthBytes = new Uint8Array([totalLength]);
|
|
118
|
+
}
|
|
119
|
+
else if (totalLength < 256) {
|
|
120
|
+
sequenceLengthBytes = new Uint8Array([0x81, totalLength]);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
sequenceLengthBytes = new Uint8Array([
|
|
124
|
+
0x82,
|
|
125
|
+
(totalLength >> 8) & 0xff,
|
|
126
|
+
totalLength & 0xff,
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
const sequenceHeader = new Uint8Array([0x30]);
|
|
130
|
+
const pkcs8Der = new Uint8Array(sequenceHeader.length + sequenceLengthBytes.length + pkcs8Content.length);
|
|
131
|
+
pkcs8Der.set(sequenceHeader, 0);
|
|
132
|
+
pkcs8Der.set(sequenceLengthBytes, sequenceHeader.length);
|
|
133
|
+
pkcs8Der.set(pkcs8Content, sequenceHeader.length + sequenceLengthBytes.length);
|
|
134
|
+
// Convert to PEM format
|
|
135
|
+
const pkcs8Base64 = base64Encode(pkcs8Der);
|
|
136
|
+
const pkcs8Pem = '-----BEGIN PRIVATE KEY-----\n' +
|
|
137
|
+
pkcs8Base64.match(/.{1,64}/g)?.join('\n') +
|
|
138
|
+
'\n-----END PRIVATE KEY-----';
|
|
139
|
+
return pkcs8Pem;
|
|
140
|
+
}
|
|
141
|
+
export const jwt = {
|
|
142
|
+
/**
|
|
143
|
+
* Decode a JWT token without verification
|
|
144
|
+
* @param token JWT token string
|
|
145
|
+
* @returns Decoded token parts or null if invalid
|
|
146
|
+
*/
|
|
147
|
+
decode(token) {
|
|
148
|
+
try {
|
|
149
|
+
const parts = token.split('.');
|
|
150
|
+
if (parts.length < 3)
|
|
151
|
+
return null;
|
|
152
|
+
const [header, payload, signature] = parts;
|
|
153
|
+
// Decode base64url - works in both Node.js and browser
|
|
154
|
+
const decodeBase64Url = (str) => {
|
|
155
|
+
const base64 = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
156
|
+
// Pad if necessary
|
|
157
|
+
const padded = base64 + '==='.slice((base64.length + 3) % 4);
|
|
158
|
+
if (isNodeEnvironment()) {
|
|
159
|
+
return Buffer.from(padded, 'base64').toString('utf-8');
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return decodeURIComponent(atob(padded)
|
|
163
|
+
.split('')
|
|
164
|
+
.map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
165
|
+
.join(''));
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return {
|
|
169
|
+
header: JSON.parse(decodeBase64Url(header)),
|
|
170
|
+
payload: decodeBase64Url(payload),
|
|
171
|
+
signature,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* Sign a JWT token
|
|
180
|
+
* @param options Sign options including header, payload, and private key
|
|
181
|
+
* @returns Signed JWT token
|
|
182
|
+
*/
|
|
183
|
+
async sign(options) {
|
|
184
|
+
const { header, payload, privateKey } = options;
|
|
185
|
+
const algorithm = header.alg || 'RS256';
|
|
186
|
+
let keyToUse = privateKey;
|
|
187
|
+
if (privateKey.includes('BEGIN RSA PRIVATE KEY')) {
|
|
188
|
+
keyToUse = convertPKCS1ToPKCS8(privateKey);
|
|
189
|
+
}
|
|
190
|
+
// Import the private key (now guaranteed to be PKCS#8)
|
|
191
|
+
const key = await importPKCS8(keyToUse, algorithm);
|
|
192
|
+
const jwt = new SignJWT(payload).setProtectedHeader({
|
|
193
|
+
...header,
|
|
194
|
+
alg: algorithm,
|
|
195
|
+
});
|
|
196
|
+
return await jwt.sign(key);
|
|
197
|
+
},
|
|
198
|
+
/**
|
|
199
|
+
* Verify a JWT token
|
|
200
|
+
* @param token JWT token to verify
|
|
201
|
+
* @param algorithm Algorithm to use (e.g., 'RS256')
|
|
202
|
+
* @param publicKey Public key in PEM format
|
|
203
|
+
* @returns true if valid, false if invalid, null on error
|
|
204
|
+
*/
|
|
205
|
+
async verify(token, algorithm, publicKey) {
|
|
206
|
+
try {
|
|
207
|
+
// Import the public key
|
|
208
|
+
const key = await importSPKI(publicKey, algorithm);
|
|
209
|
+
// Verify the token
|
|
210
|
+
await jwtVerify(token, key, {
|
|
211
|
+
algorithms: [algorithm],
|
|
212
|
+
});
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
// If verification fails, return false (not null)
|
|
217
|
+
// Only return null for unexpected errors
|
|
218
|
+
if (error instanceof Error) {
|
|
219
|
+
// JWTVerifyError means the token is invalid but parsing worked
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=jwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../src/utils/jwt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAoBlE;;;GAGG;AACH,SAAS,iBAAiB;IACxB,OAAO,OAAO,MAAM,KAAK,WAAW,CAAA;AACtC,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,iBAAiB,EAAE,EAAE,CAAC;QACxB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;IACtD,CAAC;SAAM,CAAC;QACN,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QACjC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QACjD,KAAK,IAAI,CAAC,GAAG,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AwB;YACxB,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;YAElD,mBAAmB;YACnB,MAAM,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE;gBAC1B,UAAU,EAAE,CAAC,SAAS,CAAC;aACxB,CAAC,CAAA;YAEF,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,iDAAiD;YACjD,yCAAyC;YACzC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,+DAA+D;gBAC/D,OAAO,KAAK,CAAA;YACd,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright ©
|
|
2
|
+
* Copyright © 2026 Anonyome Labs, Inc. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
@@ -18,7 +18,6 @@ export function getSignOptions({ aud, sub, iss, keyId, privateKey, attributes, }
|
|
|
18
18
|
nbf: now,
|
|
19
19
|
},
|
|
20
20
|
privateKey,
|
|
21
|
-
encoding: 'utf8',
|
|
22
21
|
};
|
|
23
22
|
if (attributes) {
|
|
24
23
|
for (const [key, value] of Object.entries(attributes)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-options-builder.js","sourceRoot":"","sources":["../../src/utils/sign-options-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AAEzB,MAAM,UAAU,cAAc,CAAC,EAC7B,GAAG,EACH,GAAG,EACH,GAAG,EACH,KAAK,EACL,UAAU,EACV,UAAU,GAQX;IACC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACzC,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"sign-options-builder.js","sourceRoot":"","sources":["../../src/utils/sign-options-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AAEzB,MAAM,UAAU,cAAc,CAAC,EAC7B,GAAG,EACH,GAAG,EACH,GAAG,EACH,KAAK,EACL,UAAU,EACV,UAAU,GAQX;IACC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACzC,MAAM,WAAW,GAAgB;QAC/B,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE;QACpC,OAAO,EAAE;YACP,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG,EAAE,EAAE,EAAE;YACT,GAAG,EAAE,GAAG,GAAG,EAAE;YACb,GAAG,EAAE,GAAG;YACR,GAAG,EAAE,GAAG;SACT;QACD,UAAU;KACX,CAAA;IAED,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACtD,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QAClC,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudoplatform/sudo-user",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"author": "Anonyome Labs, Inc.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
"lint:eslint": "eslint \"{bin,test,src}/**/*.{ts,tsx}\"",
|
|
14
14
|
"lint:prettier": "prettier -l \"{bin,test,src}/**/*.{js,json,jsx,ts,tsx}\"",
|
|
15
15
|
"codegen": "graphql-codegen -c codegen.yml",
|
|
16
|
+
"audit-with-suppressions": "true",
|
|
16
17
|
"verify": "true",
|
|
17
18
|
"unit-test": "yarn jest test/unit --verbose --coverage",
|
|
18
19
|
"integration-test": "/bin/bash -c 'jest test/integration'",
|
|
19
|
-
"
|
|
20
|
+
"browser-test": "yarn jest --config jest.config.browser.json --verbose --coverage",
|
|
21
|
+
"smoketest": "yarn unit-test && yarn integration-test && yarn browser-test",
|
|
20
22
|
"test": "yarn unit-test",
|
|
21
23
|
"build": "yarn codegen && yarn verify && yarn build:transpile && yarn build:docs",
|
|
22
24
|
"build:report-dependencies": "true",
|
|
@@ -57,7 +59,7 @@
|
|
|
57
59
|
"fp-ts": "^2.16.11",
|
|
58
60
|
"graphql": "^16.12.0",
|
|
59
61
|
"io-ts": "^2.2.22",
|
|
60
|
-
"
|
|
62
|
+
"jose": "^6.1.3",
|
|
61
63
|
"lodash": "^4.17.21",
|
|
62
64
|
"monocle-ts": "^2.3.13",
|
|
63
65
|
"newtype-ts": "^0.3.5",
|
|
@@ -67,7 +69,9 @@
|
|
|
67
69
|
},
|
|
68
70
|
"resolutions": {
|
|
69
71
|
"tmp": "^0.2.3",
|
|
70
|
-
"graphql": "^16.12.0"
|
|
72
|
+
"graphql": "^16.12.0",
|
|
73
|
+
"@smithy/config-resolver": "^4.4.6",
|
|
74
|
+
"fast-xml-parser": "^5.3.5"
|
|
71
75
|
},
|
|
72
76
|
"devDependencies": {
|
|
73
77
|
"@graphql-codegen/add": "^6.0.0",
|
|
@@ -80,7 +84,6 @@
|
|
|
80
84
|
"@types/amazon-cognito-auth-js": "^1.3.4",
|
|
81
85
|
"@types/firefox-webext-browser": "^143.0.0",
|
|
82
86
|
"@types/jest": "^29.5.14",
|
|
83
|
-
"@types/jws": "^3.2.11",
|
|
84
87
|
"@types/lodash": "^4.17.21",
|
|
85
88
|
"@types/node": "^22.19.1",
|
|
86
89
|
"@typescript-eslint/eslint-plugin": "^8.46.3",
|
|
@@ -94,6 +97,7 @@
|
|
|
94
97
|
"husky": "^9.1.7",
|
|
95
98
|
"isomorphic-fetch": "^3.0.0",
|
|
96
99
|
"jest": "^29.7.0",
|
|
100
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
97
101
|
"jest-environment-node": "^29.7.0",
|
|
98
102
|
"prettier": "^3.6.2",
|
|
99
103
|
"subscriptions-transport-ws": "^0.11.0",
|
|
@@ -110,12 +114,17 @@
|
|
|
110
114
|
"engines": {
|
|
111
115
|
"node": ">=22"
|
|
112
116
|
},
|
|
113
|
-
"packageManager": "yarn@4.
|
|
117
|
+
"packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8",
|
|
114
118
|
"auditSuppressions": {
|
|
115
|
-
"
|
|
116
|
-
"until":
|
|
117
|
-
"untilISO": "2026-
|
|
118
|
-
"reason": "
|
|
119
|
+
"1113296": {
|
|
120
|
+
"until": 1772584573,
|
|
121
|
+
"untilISO": "2026-03-04T00:36:13Z",
|
|
122
|
+
"reason": "minimatch - transitive dependency, we dont use the vulnerable functionality and waiting for patch"
|
|
123
|
+
},
|
|
124
|
+
"1113371": {
|
|
125
|
+
"until": 1772584573,
|
|
126
|
+
"untilISO": "2026-03-04T00:36:13Z",
|
|
127
|
+
"reason": "minimatch - transitive dependency, we dont use the vulnerable functionality and waiting for patch"
|
|
119
128
|
}
|
|
120
129
|
}
|
|
121
130
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SignOptions {
|
|
2
|
+
header: Record<string, any>;
|
|
3
|
+
payload: Record<string, any>;
|
|
4
|
+
privateKey: string;
|
|
5
|
+
}
|
|
6
|
+
export interface JWT {
|
|
7
|
+
decode(token: string): {
|
|
8
|
+
header: any;
|
|
9
|
+
payload: string;
|
|
10
|
+
signature: string;
|
|
11
|
+
} | null;
|
|
12
|
+
sign(options: SignOptions): Promise<string>;
|
|
13
|
+
verify(token: string, algorithm: string, publicKey: string): Promise<boolean | null>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert PKCS#1 RSA PRIVATE KEY to PKCS#8 format
|
|
17
|
+
* This wraps the PKCS#1 key with the PKCS#8 structure
|
|
18
|
+
* @internal Exported for testing purposes
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertPKCS1ToPKCS8(pkcs1Pem: string): string;
|
|
21
|
+
export declare const jwt: JWT;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SignOptions } from './jwt';
|
|
2
2
|
export declare function getSignOptions({ aud, sub, iss, keyId, privateKey, attributes, }: {
|
|
3
3
|
aud: string;
|
|
4
4
|
sub: string;
|
|
@@ -6,4 +6,4 @@ export declare function getSignOptions({ aud, sub, iss, keyId, privateKey, attri
|
|
|
6
6
|
keyId: string;
|
|
7
7
|
privateKey: string;
|
|
8
8
|
attributes?: Record<string, any>;
|
|
9
|
-
}):
|
|
9
|
+
}): SignOptions;
|