@venizia/ignis-helpers 0.4.7-2 → 0.4.7-3
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/esm/core.d.ts +3 -0
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +6 -1
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.d.ts +22 -0
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.js +10 -0
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.js.map +1 -0
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.d.ts +7 -6
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +32 -38
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts +9 -8
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +46 -41
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.engine.d.ts +32 -0
- package/dist/esm/modules/crypto/algorithms/aes.engine.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/aes.engine.js +76 -0
- package/dist/esm/modules/crypto/algorithms/aes.engine.js.map +1 -0
- package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts +10 -17
- package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js +51 -12
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts +37 -0
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js +95 -0
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js.map +1 -0
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts +6 -2
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js +18 -5
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.js +2 -3
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/index.d.ts +1 -0
- package/dist/esm/modules/crypto/algorithms/index.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/index.js +1 -0
- package/dist/esm/modules/crypto/algorithms/index.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts +8 -7
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js +22 -25
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/common/types.d.ts +3 -3
- package/dist/esm/modules/crypto/common/types.d.ts.map +1 -1
- package/dist/esm/modules/crypto/common/types.js.map +1 -1
- package/dist/esm/modules/uid/uuid/sha1.d.ts +1 -1
- package/dist/esm/modules/uid/uuid/sha1.js +1 -1
- package/dist/esm/modules/uid/uuid/sha1.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdh.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/ecdh.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,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AC,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC","sourcesContent":["import { getError } from '@/modules/error';\nimport { AbstractCryptoAlgorithm } from './abstract.algorithm';\n\nconst CURVE = { name: 'ECDH', namedCurve: 'P-256' } as const;\nconst CIPHER = 'AES-GCM' as const;\nconst KEY_BITS = 256;\nconst IV_BYTES = 12;\nconst DEFAULT_HKDF_INFO = 'ignis-ecdh-p256-aes-256-gcm-v1';\nconst SALT_BYTES = 32;\nconst TAG_BITS = 128;\nconst BASE64_CHUNK = 0x8000;\n\nexport type ECDHAlgorithmType = 'ecdh-p256';\n\nexport interface IECDHEncryptedPayload {\n iv: string;\n ct: string;\n}\n\nexport interface IECDHExtraOptions {\n additionalData?: string;\n}\n\n/**\n * ECDH P-256 key exchange with HKDF-derived AES-256-GCM session encryption. It runs in a browser or a Worker as\n * well as on the server: `crypto.subtle`, `btoa` and `atob` only, no `Buffer` and no `node:*`, so it rides\n * `@venizia/ignis-helpers/core`. Server and client both use this class and speak one wire format.\n */\nexport class ECDH extends AbstractCryptoAlgorithm<\n ECDHAlgorithmType,\n string,\n IECDHEncryptedPayload,\n CryptoKey,\n Promise<IECDHEncryptedPayload>,\n Promise<string>,\n IECDHExtraOptions\n> {\n private static readonly encoder = new TextEncoder();\n private static readonly decoder = new TextDecoder();\n private readonly hkdfInfo: Uint8Array;\n\n constructor(opts?: { algorithm: ECDHAlgorithmType; hkdfInfo?: string }) {\n super({\n scope: ECDH.name,\n identifier: 'ecdh-p256',\n });\n\n this.algorithm = 'ecdh-p256';\n this.hkdfInfo = ECDH.encoder.encode(opts?.hkdfInfo ?? DEFAULT_HKDF_INFO);\n }\n\n static withAlgorithm(opts?: { algorithm: ECDHAlgorithmType; hkdfInfo?: string }) {\n return new ECDH(opts);\n }\n\n async generateKeyPair(): Promise<{ keyPair: CryptoKeyPair; publicKeyB64: string }> {\n const keyPair = await crypto.subtle.generateKey(CURVE, false, ['deriveBits']);\n const raw = await crypto.subtle.exportKey('raw', keyPair.publicKey);\n return { keyPair, publicKeyB64: ECDH.toBase64(raw) };\n }\n\n async importPublicKey(opts: { rawKeyB64: string }): Promise<CryptoKey> {\n return crypto.subtle.importKey('raw', ECDH.fromBase64(opts.rawKeyB64), CURVE, false, []);\n }\n\n async deriveAESKey(opts: {\n privateKey: CryptoKey;\n peerPublicKey: CryptoKey;\n salt?: string;\n }): Promise<{ key: CryptoKey; salt: string }> {\n const { privateKey, peerPublicKey, salt: saltB64 } = opts;\n\n const salt = saltB64\n ? new Uint8Array(ECDH.fromBase64(saltB64))\n : crypto.getRandomValues(new Uint8Array(SALT_BYTES));\n\n const sharedBits = await crypto.subtle.deriveBits(\n { name: 'ECDH', public: peerPublicKey },\n privateKey,\n KEY_BITS,\n );\n\n const hkdfKey = await crypto.subtle.importKey('raw', sharedBits, 'HKDF', false, ['deriveKey']);\n\n const key = await crypto.subtle.deriveKey(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n salt: salt as Uint8Array<ArrayBuffer>,\n info: this.hkdfInfo as Uint8Array<ArrayBuffer>,\n },\n hkdfKey,\n { name: CIPHER, length: KEY_BITS },\n false,\n ['encrypt', 'decrypt'],\n );\n\n return { key, salt: ECDH.toBase64(salt) };\n }\n\n async encrypt(opts: {\n message: string;\n secret: CryptoKey;\n opts?: IECDHExtraOptions;\n }): Promise<IECDHEncryptedPayload> {\n const { message, secret: key, opts: extra } = opts;\n const iv = crypto.getRandomValues(new Uint8Array(IV_BYTES));\n const ct = await crypto.subtle.encrypt(\n {\n name: CIPHER,\n iv,\n tagLength: TAG_BITS,\n ...(extra?.additionalData && {\n additionalData: ECDH.encoder.encode(extra.additionalData),\n }),\n },\n key,\n ECDH.encoder.encode(message),\n );\n\n return { iv: ECDH.toBase64(iv), ct: ECDH.toBase64(ct) };\n }\n\n async decrypt(opts: {\n message: IECDHEncryptedPayload;\n secret: CryptoKey;\n opts?: IECDHExtraOptions;\n }): Promise<string> {\n const { message: payload, secret: key, opts: extra } = opts;\n const decrypted = await crypto.subtle.decrypt(\n {\n name: CIPHER,\n iv: new Uint8Array(ECDH.fromBase64(payload.iv)),\n tagLength: TAG_BITS,\n ...(extra?.additionalData && {\n additionalData: ECDH.encoder.encode(extra.additionalData),\n }),\n },\n key,\n ECDH.fromBase64(payload.ct),\n );\n\n return ECDH.decoder.decode(decrypted);\n }\n\n private static toBase64(data: ArrayBuffer | Uint8Array): string {\n const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i += BASE64_CHUNK) {\n binary += String.fromCharCode(...bytes.subarray(i, i + BASE64_CHUNK));\n }\n return btoa(binary);\n }\n\n private static fromBase64(base64: string): ArrayBuffer {\n if (!base64.length || base64.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(base64)) {\n throw getError({ message: '[ECDH.fromBase64] Invalid base64 input' });\n }\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes.buffer;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/hash.algorithm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/hash.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AAEnB,UAAU,iBAAiB;IACzB,cAAc,CAAC,EAAE,mBAAmB,CAAC;CACtC;AAED,kDAAkD;AAClD,KAAK,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;AAEtC;;;GAGG;AACH,qBAAa,IAAK,SAAQ,UAAU;IAClC,SAAS,EAAE,cAAc,CAAC;gBAEd,IAAI,EAAE;QAAE,SAAS,EAAE,cAAc,CAAA;KAAE;IAO/C,wJAAwJ;IACxJ,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAmC;IAEpE,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,cAAc;IAY9C,qBAAqB,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,cAAc,CAAA;KAAE;IAUzD;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE;QACX,OAAO,EAAE,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QAChD,IAAI,CAAC,EAAE,iBAAiB,CAAC;KAC1B,GAAG,MAAM;IAYV;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC;QAAC,IAAI,CAAC,EAAE,iBAAiB,CAAA;KAAE,GAAG,MAAM;CAY1F"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import C from 'node:crypto';
|
|
2
1
|
import { BaseHelper } from '../../base.js';
|
|
3
2
|
import { getError } from '../../error/index.js';
|
|
4
3
|
import { DEFAULT_HASH_OUTPUT_ENCODING, HashAlgorithms, } from '../common/index.js';
|
|
@@ -39,7 +38,7 @@ export class Hash extends BaseHelper {
|
|
|
39
38
|
digest(opts) {
|
|
40
39
|
const { message } = opts;
|
|
41
40
|
const { outputEncoding = DEFAULT_HASH_OUTPUT_ENCODING } = opts.opts ?? {};
|
|
42
|
-
const hash =
|
|
41
|
+
const hash = new Bun.CryptoHasher(this.algorithm);
|
|
43
42
|
for (const part of Array.isArray(message) ? message : [message]) {
|
|
44
43
|
hash.update(part);
|
|
45
44
|
}
|
|
@@ -58,7 +57,7 @@ export class Hash extends BaseHelper {
|
|
|
58
57
|
message: `[Hash][hmac] Missing secret for HMAC-${this.algorithm.toUpperCase()}`,
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
|
-
return
|
|
60
|
+
return new Bun.CryptoHasher(this.algorithm, secret).update(message).digest(outputEncoding);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
//# sourceMappingURL=hash.algorithm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/hash.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"hash.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/hash.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,4BAA4B,EAC5B,cAAc,GAGf,MAAM,WAAW,CAAC;AASnB;;;GAGG;AACH,MAAM,OAAO,IAAK,SAAQ,UAAU;IAGlC,YAAY,IAAmC;QAC7C,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,qBAAqB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAE1D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IAClC,CAAC;IAED,wJAAwJ;aAChI,cAAS,GAAG,IAAI,GAAG,EAAwB,CAAC;IAEpE,MAAM,CAAC,aAAa,CAAC,SAAyB;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,MAAM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AAK,CAAC,EAAE,CAAC;YACxB,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,wCAAwC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE;aAChF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC7F,CAAC","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport {\n DEFAULT_HASH_OUTPUT_ENCODING,\n HashAlgorithms,\n type THashAlgorithm,\n type THashOutputEncoding,\n} from '../common';\n\ninterface IHashExtraOptions {\n outputEncoding?: THashOutputEncoding;\n}\n\n/** Text is hashed as UTF-8, bytes as they are. */\ntype THashInput = string | Uint8Array;\n\n/**\n * One-way message digests and keyed HMACs. Unlike `AES`/`RSA` this has no `decrypt` - a digest\n * cannot be reversed, so `digest`/`hmac` are the only operations, not `ICryptoAlgorithm`.\n */\nexport class Hash extends BaseHelper {\n algorithm: THashAlgorithm;\n\n constructor(opts: { algorithm: THashAlgorithm }) {\n super({ scope: Hash.name, identifier: opts.algorithm });\n this.validateAlgorithmName({ algorithm: opts.algorithm });\n\n this.algorithm = opts.algorithm;\n }\n\n /** Memoized - `BaseHelper`'s constructor resolves a logger on every allocation (~50ns), and downstream token code calls `withAlgorithm` per request. */\n private static readonly instances = new Map<THashAlgorithm, Hash>();\n\n static withAlgorithm(algorithm: THashAlgorithm) {\n const cached = Hash.instances.get(algorithm);\n if (cached) {\n return cached;\n }\n\n const created = new Hash({ algorithm });\n Hash.instances.set(algorithm, created);\n\n return created;\n }\n\n validateAlgorithmName(opts: { algorithm: THashAlgorithm }) {\n const { algorithm } = opts;\n\n if (!algorithm || !HashAlgorithms.isValid(algorithm)) {\n throw getError({\n message: `[Hash][validateAlgorithmName] Invalid algorithm name | algorithm: ${algorithm}`,\n });\n }\n }\n\n /**\n * Plain digest, no secret. `message` is text (UTF-8), bytes, or several parts hashed in order as ONE message: a git\n * blob is the header text \"blob <size>\" and a NUL byte, then the bytes, so its parts are the header and the bytes. MD5/SHA1\n * are broken/weak - see {@link HashAlgorithms} - never use for security decisions.\n */\n digest(opts: {\n message: THashInput | ReadonlyArray<THashInput>;\n opts?: IHashExtraOptions;\n }): string {\n const { message } = opts;\n const { outputEncoding = DEFAULT_HASH_OUTPUT_ENCODING } = opts.opts ?? {};\n const hash = new Bun.CryptoHasher(this.algorithm);\n\n for (const part of Array.isArray(message) ? message : [message]) {\n hash.update(part);\n }\n\n return hash.digest(outputEncoding);\n }\n\n /**\n * Keyed HMAC. `message` and `secret` are text (UTF-8) or bytes: a `Buffer` or `Uint8Array` key gives the same output\n * as the text of the same bytes, so a token printed with one keeps verifying with the other. `secret` is mandatory and\n * validated non-empty so a request for an HMAC never silently degrades into an unkeyed digest.\n */\n hmac(opts: { message: THashInput; secret: THashInput; opts?: IHashExtraOptions }): string {\n const { message, secret } = opts;\n const { outputEncoding = DEFAULT_HASH_OUTPUT_ENCODING } = opts.opts ?? {};\n\n if (secret.length === 0) {\n throw getError({\n message: `[Hash][hmac] Missing secret for HMAC-${this.algorithm.toUpperCase()}`,\n });\n }\n\n return new Bun.CryptoHasher(this.algorithm, secret).update(message).digest(outputEncoding);\n }\n}\n"]}
|
|
@@ -3,5 +3,6 @@ export * from './aes.algorithm.js';
|
|
|
3
3
|
export * from './aes-legacy.algorithm.js';
|
|
4
4
|
export * from './ecdh.algorithm.js';
|
|
5
5
|
export * from './hash.algorithm.js';
|
|
6
|
+
export * from './credential.algorithm.js';
|
|
6
7
|
export * from './rsa.algorithm.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
|
|
@@ -3,5 +3,6 @@ export * from './aes.algorithm.js';
|
|
|
3
3
|
export * from './aes-legacy.algorithm.js';
|
|
4
4
|
export * from './ecdh.algorithm.js';
|
|
5
5
|
export * from './hash.algorithm.js';
|
|
6
|
+
export * from './credential.algorithm.js';
|
|
6
7
|
export * from './rsa.algorithm.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './base.algorithm';\n\nexport * from './aes.algorithm';\nexport * from './aes-legacy.algorithm';\nexport * from './ecdh.algorithm';\nexport * from './hash.algorithm';\nexport * from './rsa.algorithm';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './base.algorithm';\n\nexport * from './aes.algorithm';\nexport * from './aes-legacy.algorithm';\nexport * from './ecdh.algorithm';\nexport * from './hash.algorithm';\nexport * from './credential.algorithm';\nexport * from './rsa.algorithm';\n"]}
|
|
@@ -8,7 +8,8 @@ interface IRSAExtraOptions {
|
|
|
8
8
|
doThrow?: boolean;
|
|
9
9
|
}
|
|
10
10
|
export type RSAAlgorithmType = 'rsa';
|
|
11
|
-
|
|
11
|
+
/** `generateDERKeyPair`, `encrypt` and `decrypt` are async: they run over `crypto.subtle`. */
|
|
12
|
+
export declare class RSA extends BaseCryptoAlgorithm<RSAAlgorithmType, string, string, string, Promise<string>, Promise<string>, IRSAExtraOptions> {
|
|
12
13
|
constructor(opts: {
|
|
13
14
|
algorithm: RSAAlgorithmType;
|
|
14
15
|
});
|
|
@@ -19,20 +20,20 @@ export declare class RSA extends BaseCryptoAlgorithm<RSAAlgorithmType, string, s
|
|
|
19
20
|
*/
|
|
20
21
|
generateDERKeyPair(opts?: {
|
|
21
22
|
modulus: number;
|
|
22
|
-
}): {
|
|
23
|
-
publicKey:
|
|
24
|
-
privateKey:
|
|
25
|
-
}
|
|
23
|
+
}): Promise<{
|
|
24
|
+
publicKey: Buffer<ArrayBuffer>;
|
|
25
|
+
privateKey: Buffer<ArrayBuffer>;
|
|
26
|
+
}>;
|
|
26
27
|
encrypt(opts: {
|
|
27
28
|
message: string;
|
|
28
29
|
secret: string;
|
|
29
30
|
opts?: IRSAExtraOptions;
|
|
30
|
-
}): string
|
|
31
|
+
}): Promise<string>;
|
|
31
32
|
decrypt(opts: {
|
|
32
33
|
message: string;
|
|
33
34
|
secret: string;
|
|
34
35
|
opts?: IRSAExtraOptions;
|
|
35
|
-
}): string
|
|
36
|
+
}): Promise<string>;
|
|
36
37
|
}
|
|
37
38
|
export {};
|
|
38
39
|
//# sourceMappingURL=rsa.algorithm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/rsa.algorithm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsa.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/rsa.algorithm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,UAAU,gBAAgB;IACxB,aAAa,CAAC,EAAE;QAAE,GAAG,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,cAAc,CAAA;KAAE,CAAC;IACjE,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAWrC,8FAA8F;AAC9F,qBAAa,GAAI,SAAQ,mBAAmB,CAC1C,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,CAAC,MAAM,CAAC,EACf,OAAO,CAAC,MAAM,CAAC,EACf,gBAAgB,CACjB;gBACa,IAAI,EAAE;QAAE,SAAS,EAAE,gBAAgB,CAAA;KAAE;IAIjD,MAAM,CAAC,aAAa;IAIpB;;;OAGG;IACG,kBAAkB,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;;;;IAqB7C,OAAO,CAAC,IAAI,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,gBAAgB,CAAC;KACzB,GAAG,OAAO,CAAC,MAAM,CAAC;IA+Bb,OAAO,CAAC,IAAI,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,gBAAgB,CAAC;KACzB,GAAG,OAAO,CAAC,MAAM,CAAC;CA8BpB"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import C from 'node:crypto';
|
|
2
1
|
import { getError } from '../../error/index.js';
|
|
3
2
|
import { MINIMUM_RSA_MODULUS_BITS } from '../common/constants.js';
|
|
4
3
|
import { BaseCryptoAlgorithm } from './base.algorithm.js';
|
|
4
|
+
/**
|
|
5
|
+
* OAEP with SHA-1 for both the label hash and MGF1, and the public exponent 65537: what Node's
|
|
6
|
+
* `publicEncrypt`/`privateDecrypt` and `generateKeyPairSync('rsa')` used by default, so keys and
|
|
7
|
+
* ciphertext written by earlier releases still work. Do not change them: every ciphertext stored under
|
|
8
|
+
* them would stop decrypting.
|
|
9
|
+
*/
|
|
10
|
+
const OAEP = { name: 'RSA-OAEP', hash: 'SHA-1' };
|
|
11
|
+
const PUBLIC_EXPONENT = new Uint8Array([0x01, 0x00, 0x01]);
|
|
12
|
+
/** `generateDERKeyPair`, `encrypt` and `decrypt` are async: they run over `crypto.subtle`. */
|
|
5
13
|
export class RSA extends BaseCryptoAlgorithm {
|
|
6
14
|
constructor(opts) {
|
|
7
15
|
super({ scope: RSA.name, ...opts });
|
|
@@ -13,32 +21,25 @@ export class RSA extends BaseCryptoAlgorithm {
|
|
|
13
21
|
* Rejects a modulus below `MINIMUM_RSA_MODULUS_BITS` rather than generating it - a weak key still
|
|
14
22
|
* works, signs, and verifies, so this is the only point where the size is ever checked.
|
|
15
23
|
*/
|
|
16
|
-
generateDERKeyPair(opts) {
|
|
24
|
+
async generateDERKeyPair(opts) {
|
|
17
25
|
const modulus = opts?.modulus ?? MINIMUM_RSA_MODULUS_BITS;
|
|
18
26
|
if (modulus < MINIMUM_RSA_MODULUS_BITS) {
|
|
19
27
|
throw getError({
|
|
20
28
|
message: `[RSA][generateDERKeyPair] Modulus ${modulus} is below the ${MINIMUM_RSA_MODULUS_BITS}-bit minimum`,
|
|
21
29
|
});
|
|
22
30
|
}
|
|
23
|
-
const keys =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
publicKey: keys.publicKey.export({ type: 'spki', format: 'der' }),
|
|
28
|
-
privateKey: keys.privateKey.export({ type: 'pkcs8', format: 'der' }),
|
|
29
|
-
};
|
|
31
|
+
const keys = await crypto.subtle.generateKey({ ...OAEP, modulusLength: modulus, publicExponent: PUBLIC_EXPONENT }, true, ['encrypt', 'decrypt']);
|
|
32
|
+
const publicKey = await crypto.subtle.exportKey('spki', keys.publicKey);
|
|
33
|
+
const privateKey = await crypto.subtle.exportKey('pkcs8', keys.privateKey);
|
|
34
|
+
return { publicKey: Buffer.from(publicKey), privateKey: Buffer.from(privateKey) };
|
|
30
35
|
}
|
|
31
|
-
encrypt(opts) {
|
|
36
|
+
async encrypt(opts) {
|
|
32
37
|
const { message, secret: pubKey } = opts;
|
|
33
38
|
const { inputEncoding = { key: 'base64', message: 'utf-8' }, outputEncoding = 'base64', doThrow = true, } = opts.opts ?? {};
|
|
34
39
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type: 'spki',
|
|
39
|
-
});
|
|
40
|
-
const rs = C.publicEncrypt(k, Buffer.from(message, inputEncoding.message));
|
|
41
|
-
return rs.toString(outputEncoding);
|
|
40
|
+
const key = await crypto.subtle.importKey('spki', Buffer.from(pubKey, inputEncoding.key), OAEP, false, ['encrypt']);
|
|
41
|
+
const cipherBytes = await crypto.subtle.encrypt({ name: OAEP.name }, key, Buffer.from(message, inputEncoding.message));
|
|
42
|
+
return Buffer.from(cipherBytes).toString(outputEncoding);
|
|
42
43
|
}
|
|
43
44
|
catch (error) {
|
|
44
45
|
if (doThrow) {
|
|
@@ -47,17 +48,13 @@ export class RSA extends BaseCryptoAlgorithm {
|
|
|
47
48
|
return message;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
decrypt(opts) {
|
|
51
|
+
async decrypt(opts) {
|
|
51
52
|
const { message, secret: privKey } = opts;
|
|
52
53
|
const { inputEncoding = { key: 'base64', message: 'base64' }, outputEncoding = 'utf-8', doThrow = true, } = opts.opts ?? {};
|
|
53
54
|
try {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
type: 'pkcs8',
|
|
58
|
-
});
|
|
59
|
-
const rs = C.privateDecrypt(k, Buffer.from(message, inputEncoding.message));
|
|
60
|
-
return rs.toString(outputEncoding);
|
|
55
|
+
const key = await crypto.subtle.importKey('pkcs8', Buffer.from(privKey, inputEncoding.key), OAEP, false, ['decrypt']);
|
|
56
|
+
const plainBytes = await crypto.subtle.decrypt({ name: OAEP.name }, key, Buffer.from(message, inputEncoding.message));
|
|
57
|
+
return Buffer.from(plainBytes).toString(outputEncoding);
|
|
61
58
|
}
|
|
62
59
|
catch (error) {
|
|
63
60
|
if (doThrow) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/rsa.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rsa.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/rsa.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAUvD;;;;;GAKG;AACH,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAW,CAAC;AAC1D,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE3D,8FAA8F;AAC9F,MAAM,OAAO,GAAI,SAAQ,mBAQxB;IACC,YAAY,IAAqC;QAC/C,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,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AAC,OAAO,CAC5C,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EACnB,GAAG,EACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,CAC5C,CAAC;YACF,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { getError } from '@/modules/error';\nimport { MINIMUM_RSA_MODULUS_BITS } from '../common/constants';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\ninterface IRSAExtraOptions {\n inputEncoding?: { key: BufferEncoding; message: BufferEncoding };\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n}\n\nexport type RSAAlgorithmType = 'rsa';\n\n/**\n * OAEP with SHA-1 for both the label hash and MGF1, and the public exponent 65537: what Node's\n * `publicEncrypt`/`privateDecrypt` and `generateKeyPairSync('rsa')` used by default, so keys and\n * ciphertext written by earlier releases still work. Do not change them: every ciphertext stored under\n * them would stop decrypting.\n */\nconst OAEP = { name: 'RSA-OAEP', hash: 'SHA-1' } as const;\nconst PUBLIC_EXPONENT = new Uint8Array([0x01, 0x00, 0x01]);\n\n/** `generateDERKeyPair`, `encrypt` and `decrypt` are async: they run over `crypto.subtle`. */\nexport class RSA extends BaseCryptoAlgorithm<\n RSAAlgorithmType,\n string,\n string,\n string,\n Promise<string>,\n Promise<string>,\n IRSAExtraOptions\n> {\n constructor(opts: { algorithm: RSAAlgorithmType }) {\n super({ scope: RSA.name, ...opts });\n }\n\n static withAlgorithm() {\n return new RSA({ algorithm: 'rsa' });\n }\n\n /**\n * Rejects a modulus below `MINIMUM_RSA_MODULUS_BITS` rather than generating it - a weak key still\n * works, signs, and verifies, so this is the only point where the size is ever checked.\n */\n async generateDERKeyPair(opts?: { modulus: number }) {\n const modulus = opts?.modulus ?? MINIMUM_RSA_MODULUS_BITS;\n\n if (modulus < MINIMUM_RSA_MODULUS_BITS) {\n throw getError({\n message: `[RSA][generateDERKeyPair] Modulus ${modulus} is below the ${MINIMUM_RSA_MODULUS_BITS}-bit minimum`,\n });\n }\n\n const keys = await crypto.subtle.generateKey(\n { ...OAEP, modulusLength: modulus, publicExponent: PUBLIC_EXPONENT },\n true,\n ['encrypt', 'decrypt'],\n );\n\n const publicKey = await crypto.subtle.exportKey('spki', keys.publicKey);\n const privateKey = await crypto.subtle.exportKey('pkcs8', keys.privateKey);\n\n return { publicKey: Buffer.from(publicKey), privateKey: Buffer.from(privateKey) };\n }\n\n async encrypt(opts: {\n message: string;\n secret: string;\n opts?: IRSAExtraOptions;\n }): Promise<string> {\n const { message, secret: pubKey } = opts;\n const {\n inputEncoding = { key: 'base64', message: 'utf-8' },\n outputEncoding = 'base64',\n doThrow = true,\n } = opts.opts ?? {};\n\n try {\n const key = await crypto.subtle.importKey(\n 'spki',\n Buffer.from(pubKey, inputEncoding.key),\n OAEP,\n false,\n ['encrypt'],\n );\n const cipherBytes = await crypto.subtle.encrypt(\n { name: OAEP.name },\n key,\n Buffer.from(message, inputEncoding.message),\n );\n return Buffer.from(cipherBytes).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n async decrypt(opts: {\n message: string;\n secret: string;\n opts?: IRSAExtraOptions;\n }): Promise<string> {\n const { message, secret: privKey } = opts;\n const {\n inputEncoding = { key: 'base64', message: 'base64' },\n outputEncoding = 'utf-8',\n doThrow = true,\n } = opts.opts ?? {};\n\n try {\n const key = await crypto.subtle.importKey(\n 'pkcs8',\n Buffer.from(privKey, inputEncoding.key),\n OAEP,\n false,\n ['decrypt'],\n );\n const plainBytes = await crypto.subtle.decrypt(\n { name: OAEP.name },\n key,\n Buffer.from(message, inputEncoding.message),\n );\n return Buffer.from(plainBytes).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/** The narrow slice of a cipher that string-in/string-out payload encryption needs. Both `AES` and `LegacyAES` satisfy it, so an application holding data in the pre-PBKDF2 envelope can hand over the legacy one instead of re-encrypting. */
|
|
1
|
+
/** The narrow slice of a cipher that string-in/string-out payload encryption needs. A cipher may answer at once or with a promise (`AES` and `LegacyAES` answer with a promise); the caller awaits either. Both `AES` and `LegacyAES` satisfy it, so an application holding data in the pre-PBKDF2 envelope can hand over the legacy one instead of re-encrypting. */
|
|
2
2
|
export interface IPayloadCipher {
|
|
3
3
|
encrypt(opts: {
|
|
4
4
|
message: string;
|
|
5
5
|
secret: string;
|
|
6
|
-
}): string
|
|
6
|
+
}): string | Promise<string>;
|
|
7
7
|
decrypt(opts: {
|
|
8
8
|
message: string;
|
|
9
9
|
secret: string;
|
|
10
|
-
}): string
|
|
10
|
+
}): string | Promise<string>;
|
|
11
11
|
}
|
|
12
12
|
export interface ICryptoAlgorithm<AlgorithmNameType extends string, EncryptInputType = unknown, DecryptInputType = unknown, SecretKeyType = unknown, EncryptReturnType = unknown, DecryptReturnType = unknown, ExtraOptions = unknown> {
|
|
13
13
|
algorithm: AlgorithmNameType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/types.ts"],"names":[],"mappings":"AAAA,sWAAsW;AACtW,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7E,OAAO,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9E;AAED,MAAM,WAAW,gBAAgB,CAC/B,iBAAiB,SAAS,MAAM,EAChC,gBAAgB,GAAG,OAAO,EAC1B,gBAAgB,GAAG,OAAO,EAC1B,aAAa,GAAG,OAAO,EACvB,iBAAiB,GAAG,OAAO,EAC3B,iBAAiB,GAAG,OAAO,EAC3B,YAAY,GAAG,OAAO;IAEtB,SAAS,EAAE,iBAAiB,CAAC;IAE7B,OAAO,CAAC,IAAI,EAAE;QACZ,OAAO,EAAE,gBAAgB,CAAC;QAC1B,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,CAAC,EAAE,YAAY,CAAC;KACrB,GAAG,iBAAiB,CAAC;IACtB,OAAO,CAAC,IAAI,EAAE;QACZ,OAAO,EAAE,gBAAgB,CAAC;QAC1B,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,CAAC,EAAE,YAAY,CAAC;KACrB,GAAG,iBAAiB,CAAC;CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/types.ts"],"names":[],"mappings":"","sourcesContent":["/** The narrow slice of a cipher that string-in/string-out payload encryption needs. Both `AES` and `LegacyAES` satisfy it, so an application holding data in the pre-PBKDF2 envelope can hand over the legacy one instead of re-encrypting. */\nexport interface IPayloadCipher {\n encrypt(opts: { message: string; secret: string }): string
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/types.ts"],"names":[],"mappings":"","sourcesContent":["/** The narrow slice of a cipher that string-in/string-out payload encryption needs. A cipher may answer at once or with a promise (`AES` and `LegacyAES` answer with a promise); the caller awaits either. Both `AES` and `LegacyAES` satisfy it, so an application holding data in the pre-PBKDF2 envelope can hand over the legacy one instead of re-encrypting. */\nexport interface IPayloadCipher {\n encrypt(opts: { message: string; secret: string }): string | Promise<string>;\n decrypt(opts: { message: string; secret: string }): string | Promise<string>;\n}\n\nexport interface ICryptoAlgorithm<\n AlgorithmNameType extends string,\n EncryptInputType = unknown,\n DecryptInputType = unknown,\n SecretKeyType = unknown,\n EncryptReturnType = unknown,\n DecryptReturnType = unknown,\n ExtraOptions = unknown,\n> {\n algorithm: AlgorithmNameType;\n\n encrypt(opts: {\n message: EncryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): EncryptReturnType;\n decrypt(opts: {\n message: DecryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): DecryptReturnType;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SHA-1 over bytes, synchronous, no host API -
|
|
2
|
+
* SHA-1 over bytes, synchronous, no host API - a host module would fail the purity gate and
|
|
3
3
|
* `crypto.subtle` is async and secure-context only.
|
|
4
4
|
*
|
|
5
5
|
* Only UUID v5 uses it. SHA-1 is broken against a chosen-prefix collision: never sign, authenticate
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SHA-1 over bytes, synchronous, no host API -
|
|
2
|
+
* SHA-1 over bytes, synchronous, no host API - a host module would fail the purity gate and
|
|
3
3
|
* `crypto.subtle` is async and secure-context only.
|
|
4
4
|
*
|
|
5
5
|
* Only UUID v5 uses it. SHA-1 is broken against a chosen-prefix collision: never sign, authenticate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha1.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/sha1.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IACrB,gFAAgF;aACxD,aAAQ,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IAEvD,kFAAkF;aAC1D,YAAO,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;aAE9B,MA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AAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YAClC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YACtC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;YACrC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["/**\n * SHA-1 over bytes, synchronous, no host API -
|
|
1
|
+
{"version":3,"file":"sha1.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/sha1.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IACrB,gFAAgF;aACxD,aAAQ,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IAEvD,kFAAkF;aAC1D,YAAO,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;aAE9B,MAAC,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE7E,gDAAgD;IAChD,MAAM,CAAC,EAAE,CAAC,IAA2B;QACnC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAE5B,6FAA6F;QAC7F,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACrD,MAAM,YAAY,GAAG,UAAU,GAAG,EAAE,CAAC;QAErC,MAAM,QAAQ,GAAG,YAAY,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAA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,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACpB,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACnC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;YACrB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YAClC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;YACtC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;YACrC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["/**\n * SHA-1 over bytes, synchronous, no host API - a host module would fail the purity gate and\n * `crypto.subtle` is async and secure-context only.\n *\n * Only UUID v5 uses it. SHA-1 is broken against a chosen-prefix collision: never sign, authenticate\n * or store a password with it.\n */\nexport class Sha1Digest {\n /** Reused: `of()` never yields, so no second call can observe it mid-flight. */\n private static readonly SCHEDULE = new Uint32Array(80);\n\n /** Padding buffer sized for a namespace plus a name; a longer input allocates. */\n private static readonly SCRATCH = new Uint8Array(512);\n\n private static readonly K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];\n\n /** Digests `bytes` into 20 big-endian bytes. */\n static of(opts: { bytes: Uint8Array }): Uint8Array {\n const { bytes } = opts;\n const length = bytes.length;\n\n // Padding: a `0x80` byte, zeroes, then the bit length in the last 8 bytes of the last block.\n const blockCount = Math.floor((length + 8) / 64) + 1;\n const paddedLength = blockCount * 64;\n\n const reusable = paddedLength <= Sha1Digest.SCRATCH.length;\n const padded = reusable ? Sha1Digest.SCRATCH : new Uint8Array(paddedLength);\n\n padded.set(bytes);\n padded[length] = 0x80;\n if (reusable) {\n // The scratch still holds the previous input past this one: zero the gap, not the whole buffer.\n padded.fill(0, length + 1, paddedLength);\n }\n\n // The bit length is 3 bits wider than 32 for inputs over 512 MB: split it arithmetically.\n const bitsHigh = Math.floor(length / 0x20000000);\n const bitsLow = (length << 3) >>> 0;\n padded[paddedLength - 8] = (bitsHigh >>> 24) & 0xff;\n padded[paddedLength - 7] = (bitsHigh >>> 16) & 0xff;\n padded[paddedLength - 6] = (bitsHigh >>> 8) & 0xff;\n padded[paddedLength - 5] = bitsHigh & 0xff;\n padded[paddedLength - 4] = (bitsLow >>> 24) & 0xff;\n padded[paddedLength - 3] = (bitsLow >>> 16) & 0xff;\n padded[paddedLength - 2] = (bitsLow >>> 8) & 0xff;\n padded[paddedLength - 1] = bitsLow & 0xff;\n\n let h0 = 0x67452301;\n let h1 = 0xefcdab89;\n let h2 = 0x98badcfe;\n let h3 = 0x10325476;\n let h4 = 0xc3d2e1f0;\n\n const schedule = Sha1Digest.SCHEDULE;\n const constants = Sha1Digest.K;\n\n for (let block = 0; block < paddedLength; block += 64) {\n for (let index = 0; index < 16; index++) {\n const at = block + index * 4;\n schedule[index] =\n ((padded[at] << 24) | (padded[at + 1] << 16) | (padded[at + 2] << 8) | padded[at + 3]) >>>\n 0;\n }\n\n for (let index = 16; index < 80; index++) {\n const mixed =\n schedule[index - 3] ^ schedule[index - 8] ^ schedule[index - 14] ^ schedule[index - 16];\n schedule[index] = (mixed << 1) | (mixed >>> 31);\n }\n\n let a = h0;\n let b = h1;\n let c = h2;\n let d = h3;\n let e = h4;\n\n for (let index = 0; index < 80; index++) {\n const round = (index / 20) | 0;\n\n let mixed: number;\n if (round === 0) {\n mixed = (b & c) | (~b & d);\n } else if (round === 2) {\n mixed = (b & c) | (b & d) | (c & d);\n } else {\n mixed = b ^ c ^ d;\n }\n\n const next =\n (((a << 5) | (a >>> 27)) + mixed + e + constants[round] + schedule[index]) >>> 0;\n\n e = d;\n d = c;\n c = (b << 30) | (b >>> 2);\n b = a;\n a = next;\n }\n\n h0 = (h0 + a) >>> 0;\n h1 = (h1 + b) >>> 0;\n h2 = (h2 + c) >>> 0;\n h3 = (h3 + d) >>> 0;\n h4 = (h4 + e) >>> 0;\n }\n\n const digest = new Uint8Array(20);\n const words = [h0, h1, h2, h3, h4];\n for (let index = 0; index < 5; index++) {\n const word = words[index];\n const at = index * 4;\n digest[at] = (word >>> 24) & 0xff;\n digest[at + 1] = (word >>> 16) & 0xff;\n digest[at + 2] = (word >>> 8) & 0xff;\n digest[at + 3] = word & 0xff;\n }\n\n return digest;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-helpers",
|
|
3
|
-
"version": "0.4.7-
|
|
3
|
+
"version": "0.4.7-3",
|
|
4
4
|
"description": "Production-ready TypeScript utility library: pluggable logging (winston or pino behind one ILogger contract), Redis single/cluster/sentinel with pub/sub, BullMQ/MQTT/Kafka message queues, MinIO/Disk/Bun-S3 object storage, AES-256/RSA/ECDH cryptography, Snowflake UID generation, cron scheduling, Socket.IO/WebSocket, TCP/TLS/UDP networking, HTTP clients, secrets/Vault, worker thread pools, and environment management. Sub-path imports isolate optional peer dependencies so the root barrel never forces a peer into your bundle.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aes",
|
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
"@socket.io/redis-emitter": "^5.1.0",
|
|
189
189
|
"@types/bun": "^1.4.3",
|
|
190
190
|
"@types/luxon": "^3.7.6",
|
|
191
|
-
"@venizia/dev-configs": "0.4.7-
|
|
191
|
+
"@venizia/dev-configs": "0.4.7-3",
|
|
192
192
|
"axios": "^1.20.0",
|
|
193
193
|
"bullmq": "^6.4.0",
|
|
194
194
|
"cron": "^4.4.0",
|