@aura-stack/jose 0.2.0 → 0.4.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/dist/assert.js +2 -2
- package/dist/chunk-FCUM7BTG.js +67 -0
- package/dist/{chunk-ZHFHDRQH.js → chunk-MWFJ4CA5.js} +1 -1
- package/dist/{chunk-BMXFAB6Q.js → chunk-NGBYHSRN.js} +5 -1
- package/dist/chunk-OG4QRUXH.js +47 -0
- package/dist/{chunk-VPFE27PW.js → chunk-Q2LAK6W2.js} +9 -7
- package/dist/chunk-RQFUZSWH.js +19 -0
- package/dist/{chunk-ZHDED44B.js → chunk-WXGX6PJ5.js} +9 -7
- package/dist/crypto.cjs +46 -0
- package/dist/crypto.d.ts +19 -0
- package/dist/crypto.js +12 -0
- package/dist/deriveKey.cjs +74 -17
- package/dist/deriveKey.d.ts +2 -2
- package/dist/deriveKey.js +5 -4
- package/dist/encrypt.cjs +46 -19
- package/dist/encrypt.d.ts +2 -2
- package/dist/encrypt.js +5 -4
- package/dist/errors.cjs +7 -2
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +5 -3
- package/dist/index.cjs +102 -38
- package/dist/index.d.ts +2 -153
- package/dist/index.js +32 -15
- package/dist/secret.cjs +45 -6
- package/dist/secret.d.ts +2 -17
- package/dist/secret.js +8 -3
- package/dist/sign.cjs +46 -19
- package/dist/sign.d.ts +185 -2
- package/dist/sign.js +5 -4
- package/package.json +7 -1
- package/dist/chunk-GXM4P5MQ.js +0 -31
- package/dist/chunk-K5BQTFSO.js +0 -27
package/dist/sign.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/sign.ts
|
|
@@ -35,7 +25,6 @@ __export(sign_exports, {
|
|
|
35
25
|
verifyJWS: () => verifyJWS
|
|
36
26
|
});
|
|
37
27
|
module.exports = __toCommonJS(sign_exports);
|
|
38
|
-
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
39
28
|
var import_jose = require("jose");
|
|
40
29
|
|
|
41
30
|
// src/errors.ts
|
|
@@ -76,16 +65,54 @@ var isInvalidPayload = (payload) => {
|
|
|
76
65
|
return isFalsy(payload) || !isObject(payload) || typeof payload === "object" && payload !== null && !Array.isArray(payload) && Object.keys(payload).length === 0;
|
|
77
66
|
};
|
|
78
67
|
|
|
68
|
+
// src/crypto.ts
|
|
69
|
+
var encoder = new TextEncoder();
|
|
70
|
+
var decoder = new TextDecoder();
|
|
71
|
+
var getRandomBytes = (size) => {
|
|
72
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(size));
|
|
73
|
+
};
|
|
74
|
+
|
|
79
75
|
// src/secret.ts
|
|
80
|
-
var
|
|
81
|
-
|
|
76
|
+
var MIN_SECRET_ENTROPY_BITS = 4.5;
|
|
77
|
+
var getEntropy = (secret) => {
|
|
78
|
+
const charFreq = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const char of secret) {
|
|
80
|
+
if (!charFreq.has(char)) {
|
|
81
|
+
charFreq.set(char, 0);
|
|
82
|
+
}
|
|
83
|
+
charFreq.set(char, charFreq.get(char) + 1);
|
|
84
|
+
}
|
|
85
|
+
let entropy = 0;
|
|
86
|
+
const length = secret.length;
|
|
87
|
+
for (const freq of charFreq.values()) {
|
|
88
|
+
const p = freq / length;
|
|
89
|
+
entropy -= p * Math.log2(p);
|
|
90
|
+
}
|
|
91
|
+
return entropy;
|
|
92
|
+
};
|
|
93
|
+
var createSecret = (secret, length = 32) => {
|
|
94
|
+
if (!Boolean(secret)) throw new InvalidSecretError("Secret is required");
|
|
82
95
|
if (typeof secret === "string") {
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
const encoded = encoder.encode(secret);
|
|
97
|
+
const byteLength = encoded.byteLength;
|
|
98
|
+
if (byteLength < length) {
|
|
99
|
+
throw new InvalidSecretError(`Secret string must be at least ${length} bytes long`);
|
|
100
|
+
}
|
|
101
|
+
const entropy = getEntropy(secret);
|
|
102
|
+
if (entropy < MIN_SECRET_ENTROPY_BITS) {
|
|
103
|
+
throw new InvalidSecretError(
|
|
104
|
+
`Secret string must have an entropy of at least ${MIN_SECRET_ENTROPY_BITS} bits per character`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return encoded;
|
|
108
|
+
}
|
|
109
|
+
if (secret instanceof CryptoKey || secret instanceof Uint8Array) {
|
|
110
|
+
if (secret instanceof Uint8Array && secret.byteLength < length) {
|
|
111
|
+
throw new InvalidSecretError(`Secret must be at least ${length} bytes long`);
|
|
85
112
|
}
|
|
86
|
-
return
|
|
113
|
+
return secret;
|
|
87
114
|
}
|
|
88
|
-
|
|
115
|
+
throw new InvalidSecretError("Secret must be a string, Uint8Array, or CryptoKey");
|
|
89
116
|
};
|
|
90
117
|
|
|
91
118
|
// src/sign.ts
|
|
@@ -95,8 +122,8 @@ var signJWS = async (payload, secret) => {
|
|
|
95
122
|
throw new InvalidPayloadError("The payload must be a non-empty object");
|
|
96
123
|
}
|
|
97
124
|
const secretKey = createSecret(secret);
|
|
98
|
-
const jti =
|
|
99
|
-
return new import_jose.SignJWT(payload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuedAt().setNotBefore(payload.nbf ?? "0s").setExpirationTime(payload.exp ?? "15d").setJti(jti).sign(secretKey);
|
|
125
|
+
const jti = import_jose.base64url.encode(getRandomBytes(32));
|
|
126
|
+
return await new import_jose.SignJWT(payload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuedAt().setNotBefore(payload.nbf ?? "0s").setExpirationTime(payload.exp ?? "15d").setJti(jti).sign(secretKey);
|
|
100
127
|
} catch (error) {
|
|
101
128
|
if (isAuraJoseError(error)) {
|
|
102
129
|
throw error;
|
package/dist/sign.d.ts
CHANGED
|
@@ -1,3 +1,186 @@
|
|
|
1
|
+
import { JWTPayload, JWTVerifyOptions, JWTDecryptOptions } from 'jose';
|
|
1
2
|
export { JWTVerifyOptions } from 'jose';
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
import './crypto.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sign a standard JWT token with the following claims:
|
|
7
|
+
* - alg: algorithm used to sign the JWT
|
|
8
|
+
* - typ: type of the token
|
|
9
|
+
* - iat: time at which the JWT was issued
|
|
10
|
+
* - nbf: not before time of the JWT
|
|
11
|
+
* - exp: expiration time of the JWT
|
|
12
|
+
* - jti: unique identifier to avoid collisions
|
|
13
|
+
*
|
|
14
|
+
* @param payload - Payload data information to sign the JWT
|
|
15
|
+
* @param secret - Secret key to sign the JWT (CryptoKey, KeyObject, string or Uint8Array)
|
|
16
|
+
* @returns Signed JWT string
|
|
17
|
+
*/
|
|
18
|
+
declare const signJWS: <Payload extends JWTPayload>(payload: TypedJWTPayload<Partial<Payload>>, secret: SecretInput) => Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Verify the integrity of a JWT token and return the payload if valid, rejecting
|
|
21
|
+
* tokens that use the "none" algorithm to prevent unsecured tokens.
|
|
22
|
+
*
|
|
23
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7519#section-6 Unsecured JWTs
|
|
24
|
+
* @param token - JWT string to verify
|
|
25
|
+
* @param secret - CryptoKey or KeyObject used to verify the JWT
|
|
26
|
+
* @param options - Additional JWT verification options
|
|
27
|
+
* @returns verify and return the payload of the JWT
|
|
28
|
+
*/
|
|
29
|
+
declare const verifyJWS: <Payload extends JWTPayload>(token: string, secret: SecretInput, options?: JWTVerifyOptions) => Promise<TypedJWTPayload<Payload>>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a JWS (JSON Web Signature) signer and verifier. It implements the `signJWS`
|
|
32
|
+
* and `verifyJWS` functions of the module.
|
|
33
|
+
*
|
|
34
|
+
* @param secret - Secret key used for signing and verifying the JWS
|
|
35
|
+
* @returns signJWS and verifyJWS functions
|
|
36
|
+
*/
|
|
37
|
+
declare const createJWS: <Payload extends JWTPayload>(secret: SecretInput) => {
|
|
38
|
+
signJWS: <SignPayload extends JWTPayload = Payload>(payload: TypedJWTPayload<Partial<SignPayload>>) => Promise<string>;
|
|
39
|
+
verifyJWS: <VerifyPayload extends JWTPayload = Payload>(payload: string, options?: JWTVerifyOptions) => Promise<TypedJWTPayload<VerifyPayload>>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
interface EncryptedPayload {
|
|
43
|
+
payload: string;
|
|
44
|
+
}
|
|
45
|
+
interface EncryptOptions {
|
|
46
|
+
nbf?: string | number | Date;
|
|
47
|
+
exp?: string | number | Date;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Encrypt a standard JWT token with the following claims:
|
|
51
|
+
* - alg: algorithm used to encrypt the JWT
|
|
52
|
+
* - enc: encryption method used
|
|
53
|
+
* - typ: type of the token
|
|
54
|
+
* - cty: content type of the token
|
|
55
|
+
*
|
|
56
|
+
* @param payload - Payload data information to encrypt the JWT
|
|
57
|
+
* @param secret - Secret key to encrypt the JWT (CryptoKey, KeyObject, string or Uint8Array)
|
|
58
|
+
* @returns Encrypted JWT string
|
|
59
|
+
*/
|
|
60
|
+
declare const encryptJWE: (payload: string, secret: SecretInput, options?: EncryptOptions) => Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Decrypt a JWE token and return the payload if valid.
|
|
63
|
+
*
|
|
64
|
+
* @param token - Encrypted JWT string to decrypt
|
|
65
|
+
* @param secret - Secret key to decrypt the JWT (CryptoKey, KeyObject, string or Uint8Array)
|
|
66
|
+
* @returns Decrypted JWT payload string
|
|
67
|
+
*/
|
|
68
|
+
declare const decryptJWE: (token: string, secret: SecretInput, options?: JWTDecryptOptions) => Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a `JWE (JSON Web Encryption)` encrypter and decrypter. It implements the `encryptJWE`
|
|
71
|
+
* and `decryptJWE` functions of the module.
|
|
72
|
+
*
|
|
73
|
+
* @param secret - Secret key used for encrypting and decrypting the JWE
|
|
74
|
+
* @returns encryptJWE and decryptJWE functions
|
|
75
|
+
*/
|
|
76
|
+
declare const createJWE: (secret: SecretInput) => {
|
|
77
|
+
encryptJWE: (payload: string, options?: EncryptOptions) => Promise<string>;
|
|
78
|
+
decryptJWE: (payload: string, options?: JWTDecryptOptions) => Promise<string>;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare const MIN_SECRET_ENTROPY_BITS = 4.5;
|
|
82
|
+
declare const getEntropy: (secret: string) => number;
|
|
83
|
+
/**
|
|
84
|
+
* Create a secret in Uint8Array format
|
|
85
|
+
* Uses the standard TextEncoder API for cross-runtime compatibility
|
|
86
|
+
*
|
|
87
|
+
* @param secret - The secret as a string or Uint8Array
|
|
88
|
+
* @returns The secret in Uint8Array format
|
|
89
|
+
*/
|
|
90
|
+
declare const createSecret: (secret: SecretInput, length?: number) => Uint8Array<ArrayBufferLike> | CryptoKey;
|
|
91
|
+
declare const getSecrets: (secret: SecretInput | DerivedKeyInput) => {
|
|
92
|
+
jwsSecret: SecretInput;
|
|
93
|
+
jweSecret: SecretInput;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @module @aura-stack/jose
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Secret input can be:
|
|
102
|
+
* - CryptoKey: W3C standard key object (works across all runtimes)
|
|
103
|
+
* - Uint8Array: Raw bytes
|
|
104
|
+
* - string: String that will be encoded to UTF-8
|
|
105
|
+
*/
|
|
106
|
+
type SecretInput = Uint8Array | string | CryptoKey;
|
|
107
|
+
type DerivedKeyInput = {
|
|
108
|
+
jws: SecretInput;
|
|
109
|
+
jwe: SecretInput;
|
|
110
|
+
};
|
|
111
|
+
type DecodedJWTPayloadOptions = {
|
|
112
|
+
jws: JWTVerifyOptions;
|
|
113
|
+
jwt: JWTDecryptOptions;
|
|
114
|
+
};
|
|
115
|
+
type Prettify<T> = {
|
|
116
|
+
[K in keyof T]: T[K];
|
|
117
|
+
} & {};
|
|
118
|
+
type TypedJWTPayload<Payload extends JWTPayload> = JWTPayload & Payload;
|
|
119
|
+
/**
|
|
120
|
+
* Encode a JWT signed and encrypted token. The token first signed using JWS
|
|
121
|
+
* and then encrypted using JWE to ensure both integrity and confidentiality.
|
|
122
|
+
* It implements the `signJWS` and `encryptJWE` functions of the module.
|
|
123
|
+
*
|
|
124
|
+
* Based on the RFC 7519 standard
|
|
125
|
+
* - Official RFC: https://datatracker.ietf.org/doc/html/rfc7519
|
|
126
|
+
* - Nested JWTs should be signed and then encrypted: https://datatracker.ietf.org/doc/html/rfc7519#section-5.2
|
|
127
|
+
* - Ensuring the integrity and confidentiality of the claims: https://datatracker.ietf.org/doc/html/rfc7519#section-11.2
|
|
128
|
+
*
|
|
129
|
+
* @param token - Payload data to encode in the JWT
|
|
130
|
+
* @param secret - Secret key used for both signing and encrypting the JWT
|
|
131
|
+
* @returns Promise resolving to the signed and encrypted JWT string
|
|
132
|
+
*/
|
|
133
|
+
declare const encodeJWT: <Payload extends JWTPayload>(token: TypedJWTPayload<Partial<Payload>>, secret: SecretInput | DerivedKeyInput) => Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Decode a JWT signed and encrypted token. The token is first decrypted using JWE
|
|
136
|
+
* and then verified using JWS to ensure both confidentiality and integrity. It
|
|
137
|
+
* implements the `decryptJWE` and `verifyJWS` functions of the module.
|
|
138
|
+
*
|
|
139
|
+
* Based on the RFC 7519 standard
|
|
140
|
+
* - Official RFC: https://datatracker.ietf.org/doc/html/rfc7519
|
|
141
|
+
* - Validating a JWT: https://datatracker.ietf.org/doc/html/rfc7519#section-7.2
|
|
142
|
+
* @param token
|
|
143
|
+
* @param secret
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
declare const decodeJWT: <Payload extends JWTPayload>(token: string, secret: SecretInput | DerivedKeyInput, options?: DecodedJWTPayloadOptions) => Promise<TypedJWTPayload<Payload>>;
|
|
147
|
+
/**
|
|
148
|
+
* Create a JWT handler with encode and decode methods to `signJWS/encryptJWE` and `verifyJWS/decryptJWE`
|
|
149
|
+
* JWT tokens. The JWTs are signed and verified using JWS and encrypted and decrypted using JWE. It
|
|
150
|
+
* implements the `signJWS`, `verifyJWS`, `encryptJWE` and `decryptJWE` functions of the module.
|
|
151
|
+
*
|
|
152
|
+
* @param secret - Secret key used for signing, verifying, encrypting and decrypting the JWT
|
|
153
|
+
* @returns JWT handler object with `signJWS/encryptJWE` and `verifyJWS/decryptJWE` methods
|
|
154
|
+
*/
|
|
155
|
+
declare const createJWT: <Payload extends JWTPayload>(secret: SecretInput | DerivedKeyInput) => {
|
|
156
|
+
encodeJWT: <EncodePayload extends JWTPayload = Payload>(payload: TypedJWTPayload<Partial<EncodePayload>>) => Promise<string>;
|
|
157
|
+
decodeJWT: <DecodePayload extends JWTPayload = Payload>(token: string, options?: DecodedJWTPayloadOptions) => Promise<TypedJWTPayload<DecodePayload>>;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Generate a derived key using HKDF (HMAC-based Extract-and-Expand Key Derivation Function)
|
|
162
|
+
* Uses the Web Crypto API for cross-runtime compatibility (Node.js, Deno, Bun, Browsers)
|
|
163
|
+
*
|
|
164
|
+
* @param secret Value used as the input keying material
|
|
165
|
+
* @param salt Cryptographic salt
|
|
166
|
+
* @param info Context and application specific information
|
|
167
|
+
* @param length Size of the derived key in bytes (default is 32 bytes)
|
|
168
|
+
* @returns Derived key as Uint8Array
|
|
169
|
+
*/
|
|
170
|
+
declare const deriveKey: (secret: Uint8Array, salt: string | Uint8Array, info: string | Uint8Array, length?: number) => Promise<Uint8Array>;
|
|
171
|
+
/**
|
|
172
|
+
* Create a derived key from a given secret.
|
|
173
|
+
* This is an async function that works across all modern JavaScript runtimes.
|
|
174
|
+
*
|
|
175
|
+
* > [!NOTE]
|
|
176
|
+
* > If the secret is a CryptoKey, this function cannot derive keys from it.
|
|
177
|
+
*
|
|
178
|
+
* @param secret - The secret as a string or Uint8Array
|
|
179
|
+
* @param salt - Optional cryptographic salt (defaults to "Aura Jose secret salt")
|
|
180
|
+
* @param info - Optional context information (defaults to "Aura Jose secret derivation")
|
|
181
|
+
* @param length - Size of the derived key in bytes (default is 32 bytes)
|
|
182
|
+
* @returns Promise resolving to the derived key as a Uint8Array
|
|
183
|
+
*/
|
|
184
|
+
declare const createDeriveKey: (secret: SecretInput, salt?: string | Uint8Array, info?: string | Uint8Array, length?: number) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
185
|
+
|
|
186
|
+
export { type DecodedJWTPayloadOptions as D, type EncryptOptions as E, MIN_SECRET_ENTROPY_BITS as M, type Prettify as P, type SecretInput as S, type TypedJWTPayload as T, type EncryptedPayload as a, createSecret as b, createJWE as c, createJWS, decryptJWE as d, encryptJWE as e, getSecrets as f, getEntropy as g, type DerivedKeyInput as h, createDeriveKey as i, createJWT as j, decodeJWT as k, deriveKey as l, encodeJWT as m, signJWS, verifyJWS };
|
package/dist/sign.js
CHANGED
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
createJWS,
|
|
3
3
|
signJWS,
|
|
4
4
|
verifyJWS
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-WXGX6PJ5.js";
|
|
6
|
+
import "./chunk-FCUM7BTG.js";
|
|
7
|
+
import "./chunk-MWFJ4CA5.js";
|
|
8
|
+
import "./chunk-RQFUZSWH.js";
|
|
9
|
+
import "./chunk-NGBYHSRN.js";
|
|
9
10
|
export {
|
|
10
11
|
createJWS,
|
|
11
12
|
signJWS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aura-stack/jose",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "JOSE utilities for @aura-stack/auth",
|
|
@@ -40,6 +40,11 @@
|
|
|
40
40
|
"types": "./dist/deriveKey.d.ts",
|
|
41
41
|
"require": "./dist/deriveKey.cjs",
|
|
42
42
|
"import": "./dist/deriveKey.js"
|
|
43
|
+
},
|
|
44
|
+
"./crypto": {
|
|
45
|
+
"types": "./dist/crypto.d.ts",
|
|
46
|
+
"require": "./dist/crypto.cjs",
|
|
47
|
+
"import": "./dist/crypto.js"
|
|
43
48
|
}
|
|
44
49
|
},
|
|
45
50
|
"keywords": [
|
|
@@ -57,6 +62,7 @@
|
|
|
57
62
|
"jose": "^6.1.2"
|
|
58
63
|
},
|
|
59
64
|
"devDependencies": {
|
|
65
|
+
"typescript": "^5.9.2",
|
|
60
66
|
"@aura-stack/tsconfig": "0.0.0",
|
|
61
67
|
"@aura-stack/tsup-config": "0.0.0"
|
|
62
68
|
},
|
package/dist/chunk-GXM4P5MQ.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isObject
|
|
3
|
-
} from "./chunk-ZHFHDRQH.js";
|
|
4
|
-
import {
|
|
5
|
-
InvalidSecretError
|
|
6
|
-
} from "./chunk-BMXFAB6Q.js";
|
|
7
|
-
|
|
8
|
-
// src/secret.ts
|
|
9
|
-
var createSecret = (secret) => {
|
|
10
|
-
if (secret === void 0) throw new InvalidSecretError("Secret is required");
|
|
11
|
-
if (typeof secret === "string") {
|
|
12
|
-
if (new TextEncoder().encode(secret).byteLength < 32) {
|
|
13
|
-
throw new InvalidSecretError("Secret string must be at least 32 characters long");
|
|
14
|
-
}
|
|
15
|
-
return new Uint8Array(Buffer.from(secret, "utf-8"));
|
|
16
|
-
}
|
|
17
|
-
return secret;
|
|
18
|
-
};
|
|
19
|
-
var getSecrets = (secret) => {
|
|
20
|
-
const jwsSecret = isObject(secret) && "jws" in secret ? secret.jws : secret;
|
|
21
|
-
const jweSecret = isObject(secret) && "jwe" in secret ? secret.jwe : secret;
|
|
22
|
-
return {
|
|
23
|
-
jwsSecret,
|
|
24
|
-
jweSecret
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
createSecret,
|
|
30
|
-
getSecrets
|
|
31
|
-
};
|
package/dist/chunk-K5BQTFSO.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createSecret
|
|
3
|
-
} from "./chunk-GXM4P5MQ.js";
|
|
4
|
-
|
|
5
|
-
// src/deriveKey.ts
|
|
6
|
-
import { hkdfSync } from "crypto";
|
|
7
|
-
var deriveKey = (secret, salt, info, length = 32) => {
|
|
8
|
-
try {
|
|
9
|
-
const key = hkdfSync("SHA256", secret, salt, info, length);
|
|
10
|
-
const derivedKey = Buffer.from(key);
|
|
11
|
-
return {
|
|
12
|
-
key,
|
|
13
|
-
derivedKey
|
|
14
|
-
};
|
|
15
|
-
} catch (error) {
|
|
16
|
-
throw new Error("Failed to create a derived key (HKDF)", { cause: error });
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var createDeriveKey = (secret, salt, info, length = 32) => {
|
|
20
|
-
const secretKey = createSecret(secret);
|
|
21
|
-
return deriveKey(secretKey, salt ?? "Aura Jose secret salt", info ?? "Aura Jose secret derivation", length);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
deriveKey,
|
|
26
|
-
createDeriveKey
|
|
27
|
-
};
|