@carecard/auth-util 3.1.11 → 3.1.13

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/index.d.ts CHANGED
@@ -143,26 +143,20 @@ export const pwdUtilAuth: {
143
143
  * @param password - The plain-text password to hash.
144
144
  * @param secret - A pepper/secret key to combine with the password.
145
145
  * @param algorithm - The hashing algorithm to use (e.g., 'sha256').
146
- * @returns A string containing the formatted hash with metadata ($1$alg$hash$salt$).
146
+ * @returns A string containing the formatted hash with metadata ($1$alg$hash$salt$) or null if an error occurs.
147
147
  */
148
- createPasswordHashWithRandomSalt: (password: string, secret: string, algorithm: string) => string;
148
+ createPasswordHashWithRandomSalt: (password: string, secret: string, algorithm: string) => string | null;
149
149
  /**
150
150
  * Generates a password hash using the same algorithm and salt from a previously saved hash.
151
151
  * Useful for verifying a password against a stored hash.
152
152
  * @param password - The plain-text password to verify.
153
153
  * @param savedPasswordHash - The full stored hash string (including salt and metadata).
154
154
  * @param secret - The pepper/secret key used for hashing.
155
- * @returns A hash string that should match the saved hash if the password is correct.
155
+ * @returns A hash string that should match the saved hash if the password is correct, or null if an error occurs.
156
156
  */
157
- createPasswordHashBasedOnSavedAlgorithmSalt: (password: string, savedPasswordHash: string, secret: string) => string;
157
+ createPasswordHashBasedOnSavedAlgorithmSalt: (password: string, savedPasswordHash: string, secret: string) => string | null;
158
158
  };
159
159
 
160
- /**
161
- * Generates a public/private key pair for JWT signing.
162
- * @param algorithm - The algorithm to use ('ed25519' or 'rsa'). Defaults to 'ed25519'.
163
- * @returns A KeyPair object containing PEM formatted keys.
164
- */
165
- export const createKeys: (algorithm?: 'ed25519' | 'rsa' | string) => KeyPair;
166
160
 
167
161
  /**
168
162
  * Utility functions for string manipulation, base64 encoding, and parsing auth-related strings.
@@ -232,12 +226,54 @@ export const stringUtilAuth: {
232
226
  };
233
227
 
234
228
 
235
- export function jwtCreateSignedFromObject(headerObject: JwtHeader, payloadObject: JwtPayload, privateKey: string): string | null;
229
+ /**
230
+ * Generates a public/private key pair for JWT signing.
231
+ * @param algorithm - The algorithm to use ('ed25519' or 'rsa'). Defaults to 'ed25519'.
232
+ * @returns A KeyPair object containing PEM formatted keys.
233
+ */
234
+ export function generateKeyPair(algorithm?: 'ed25519' | 'rsa' | string): KeyPair;
236
235
 
237
- export function jwtVerifySignature(jwt: string, publicKey: string): boolean;
236
+ /**
237
+ * Creates a signed JWT from header and payload objects.
238
+ * Automatically normalizes header (sets alg/typ) and payload (sets iat/exp/etc. in seconds).
239
+ * @param headerObject - Header data for the JWT.
240
+ * @param payloadObject - Payload data for the JWT.
241
+ * @param privateKey - PEM formatted private key to sign the token.
242
+ * @returns Signed JWT string or null if an error occurs.
243
+ */
244
+ export function jwtCreateSignedToken(headerObject: JwtHeader, payloadObject: JwtPayload, privateKey: string): string | null;
238
245
 
239
- export function jwtGetHeaderPayloadFromJwt(jwt: string): JwtParts | null;
246
+ /**
247
+ * Verifies the signature of a JWT using a public key.
248
+ * @param jwt - The JWT string to verify.
249
+ * @param publicKey - PEM formatted public key.
250
+ * @returns True if the signature is valid, false otherwise.
251
+ */
252
+ export function jwtVerifySignedToken(jwt: string, publicKey: string): boolean;
253
+
254
+ /**
255
+ * Decodes a JWT and returns its header and payload as objects.
256
+ * Note: This does NOT verify the signature.
257
+ * @param jwt - The JWT string to parse.
258
+ * @returns An object containing the header and payload, or null if parsing fails.
259
+ */
260
+ export function jwtGetHeaderPayload(jwt: string): JwtParts | null;
240
261
 
241
- export function passwordCreateHashWithRandomSalt(password: string, secret: string, algorithm: string): string;
262
+ /**
263
+ * Generates a password hash using a random salt and specified algorithm.
264
+ * @param password - The plain-text password to hash.
265
+ * @param secret - A pepper/secret key to combine with the password.
266
+ * @param algorithm - The hashing algorithm to use (e.g., 'sha256').
267
+ * @returns A string containing the formatted hash with metadata ($1$alg$hash$salt$) or null if an error occurs.
268
+ */
269
+ export function passwordCreateHashWithRandomSalt(password: string, secret: string, algorithm: string): string | null;
242
270
 
243
- export function passwordCreateHashBasedOnSavedAlgorithmSalt(password: string, savedPasswordHash: string, secret: string): string;
271
+ /**
272
+ * Generates a password hash using the same algorithm and salt from a previously saved hash.
273
+ * Useful for verifying a password against a stored hash.
274
+ * @param password - The plain-text password to verify.
275
+ * @param savedPasswordHash - The full stored hash string (including salt and metadata).
276
+ * @param secret - The pepper/secret key used for hashing.
277
+ * @returns A hash string that should match the saved hash if the password is correct, or null if an error occurs.
278
+ */
279
+ export function passwordCreateHashFromSavedHash(password: string, savedPasswordHash: string, secret: string): string | null;
package/index.js CHANGED
@@ -4,16 +4,16 @@ const keyGen = require('./lib/keyGen');
4
4
 
5
5
  module.exports = {
6
6
  // New
7
- createKeys: keyGen.generateKeyPair,
8
- jwtCreateSignedFromObject: jwtUtilAuth.createSignedJwtFromObject,
9
- jwtVerifySignature: jwtUtilAuth.verifyJwtSignature,
10
- jwtGetHeaderPayloadFromJwt: jwtUtilAuth.getHeaderPayloadFromJwt,
7
+ generateKeyPair: keyGen.generateKeyPair,
8
+ jwtCreateSignedToken: jwtUtilAuth.createSignedJwtFromObject,
9
+ jwtVerifySignedToken: jwtUtilAuth.verifyJwtSignature,
10
+ jwtGetHeaderPayload: jwtUtilAuth.getHeaderPayloadFromJwt,
11
11
  passwordCreateHashWithRandomSalt: pwdUtilAuth.createPasswordHashWithRandomSalt,
12
- passwordCreateHashBasedOnSavedAlgorithmSalt: pwdUtilAuth.createPasswordHashBasedOnSavedAlgorithmSalt,
12
+ passwordCreateHashFromSavedHash: pwdUtilAuth.createPasswordHashBasedOnSavedAlgorithmSalt,
13
13
 
14
14
  // Deprecated
15
15
  /**
16
- * @deprecated Use native Buffer methods or other modern alternatives.
16
+ * @deprecated use direct import of the new functions.
17
17
  */
18
18
  jwtUtilAuth: {
19
19
  createSignedJwtFromObject: jwtUtilAuth.createSignedJwtFromObject,
@@ -21,7 +21,7 @@ module.exports = {
21
21
  getHeaderPayloadFromJwt: jwtUtilAuth.getHeaderPayloadFromJwt
22
22
  },
23
23
  /**
24
- * @deprecated Use native Buffer methods or other modern alternatives.
24
+ * @deprecated use direct import of the new functions.
25
25
  */
26
26
  pwdUtilAuth: {
27
27
  createPasswordHashWithRandomSalt: pwdUtilAuth.createPasswordHashWithRandomSalt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/auth-util",
3
- "version": "3.1.11",
3
+ "version": "3.1.13",
4
4
  "repository": "https://github.com/CareCard-ca/pkg-auth-util.git",
5
5
  "description": "Auth utility functions",
6
6
  "main": "index.js",
package/readme.md CHANGED
@@ -61,13 +61,13 @@ const isCorrect = (pwdUtilAuth.createPasswordHashBasedOnSavedAlgorithmSalt(passw
61
61
  ### Key Generation
62
62
 
63
63
  ```javascript
64
- const { createKeys } = require('@carecard/auth-util');
64
+ const { generateKeyPair } = require('@carecard/auth-util');
65
65
 
66
66
  // Generate Ed25519 keys (default)
67
- const { publicKey, privateKey } = createKeys();
67
+ const { publicKey, privateKey } = generateKeyPair();
68
68
 
69
69
  // Generate RSA keys
70
- const rsaKeys = createKeys('rsa');
70
+ const rsaKeys = generateKeyPair('rsa');
71
71
  ```
72
72
 
73
73
  ### String Utilities (`stringUtilAuth`)