@enbox/crypto 0.0.2 → 0.0.4
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/README.md +34 -102
- package/dist/browser.mjs +6 -10
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/algorithms/aes-ctr.js +1 -1
- package/dist/esm/algorithms/aes-gcm.js +35 -2
- package/dist/esm/algorithms/aes-gcm.js.map +1 -1
- package/dist/esm/algorithms/aes-kw.js +154 -0
- package/dist/esm/algorithms/aes-kw.js.map +1 -0
- package/dist/esm/algorithms/ecdsa.js +119 -6
- package/dist/esm/algorithms/ecdsa.js.map +1 -1
- package/dist/esm/algorithms/eddsa.js +99 -6
- package/dist/esm/algorithms/eddsa.js.map +1 -1
- package/dist/esm/algorithms/hkdf.js +53 -0
- package/dist/esm/algorithms/hkdf.js.map +1 -0
- package/dist/esm/algorithms/pbkdf2.js +55 -0
- package/dist/esm/algorithms/pbkdf2.js.map +1 -0
- package/dist/esm/algorithms/sha-2.js +2 -2
- package/dist/esm/algorithms/sha-2.js.map +1 -1
- package/dist/esm/algorithms/x25519.js +125 -0
- package/dist/esm/algorithms/x25519.js.map +1 -0
- package/dist/esm/crypto-error.js +41 -0
- package/dist/esm/crypto-error.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jose/jwk.js +52 -26
- package/dist/esm/jose/jwk.js.map +1 -1
- package/dist/esm/local-key-manager.js +9 -3
- package/dist/esm/local-key-manager.js.map +1 -1
- package/dist/esm/primitives/aes-ctr.js.map +1 -1
- package/dist/esm/primitives/aes-gcm.js.map +1 -1
- package/dist/esm/primitives/aes-kw.js +246 -0
- package/dist/esm/primitives/aes-kw.js.map +1 -0
- package/dist/esm/primitives/concat-kdf.js +1 -1
- package/dist/esm/primitives/concat-kdf.js.map +1 -1
- package/dist/esm/primitives/ecies-secp256k1.js +79 -0
- package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
- package/dist/esm/primitives/ed25519.js +3 -3
- package/dist/esm/primitives/ed25519.js.map +1 -1
- package/dist/esm/primitives/hkdf.js +79 -0
- package/dist/esm/primitives/hkdf.js.map +1 -0
- package/dist/esm/primitives/pbkdf2.js +49 -0
- package/dist/esm/primitives/pbkdf2.js.map +1 -1
- package/dist/esm/primitives/secp256k1.js +4 -4
- package/dist/esm/primitives/secp256k1.js.map +1 -1
- package/dist/esm/primitives/secp256r1.js +4 -4
- package/dist/esm/primitives/secp256r1.js.map +1 -1
- package/dist/esm/primitives/x25519.js +10 -17
- package/dist/esm/primitives/x25519.js.map +1 -1
- package/dist/esm/primitives/xchacha20-poly1305.js +48 -3
- package/dist/esm/primitives/xchacha20-poly1305.js.map +1 -1
- package/dist/esm/primitives/xchacha20.js +1 -1
- package/dist/esm/primitives/xchacha20.js.map +1 -1
- package/dist/esm/utils.js +30 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/algorithms/aes-ctr.d.ts +2 -2
- package/dist/types/algorithms/aes-ctr.d.ts.map +1 -1
- package/dist/types/algorithms/aes-gcm.d.ts +25 -5
- package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
- package/dist/types/algorithms/aes-kw.d.ts +129 -0
- package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
- package/dist/types/algorithms/ecdsa.d.ts +49 -4
- package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
- package/dist/types/algorithms/eddsa.d.ts +49 -4
- package/dist/types/algorithms/eddsa.d.ts.map +1 -1
- package/dist/types/algorithms/hkdf.d.ts +35 -0
- package/dist/types/algorithms/hkdf.d.ts.map +1 -0
- package/dist/types/algorithms/pbkdf2.d.ts +35 -0
- package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
- package/dist/types/algorithms/sha-2.d.ts +2 -2
- package/dist/types/algorithms/sha-2.d.ts.map +1 -1
- package/dist/types/algorithms/x25519.d.ts +76 -0
- package/dist/types/algorithms/x25519.d.ts.map +1 -0
- package/dist/types/crypto-error.d.ts +29 -0
- package/dist/types/crypto-error.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/jose/jwk.d.ts.map +1 -1
- package/dist/types/local-key-manager.d.ts +6 -6
- package/dist/types/local-key-manager.d.ts.map +1 -1
- package/dist/types/primitives/aes-kw.d.ts +103 -0
- package/dist/types/primitives/aes-kw.d.ts.map +1 -0
- package/dist/types/primitives/concat-kdf.d.ts +1 -1
- package/dist/types/primitives/concat-kdf.d.ts.map +1 -1
- package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
- package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
- package/dist/types/primitives/hkdf.d.ts +90 -0
- package/dist/types/primitives/hkdf.d.ts.map +1 -0
- package/dist/types/primitives/pbkdf2.d.ts +58 -0
- package/dist/types/primitives/pbkdf2.d.ts.map +1 -1
- package/dist/types/primitives/x25519.d.ts +9 -16
- package/dist/types/primitives/x25519.d.ts.map +1 -1
- package/dist/types/primitives/xchacha20-poly1305.d.ts +47 -0
- package/dist/types/primitives/xchacha20-poly1305.d.ts.map +1 -1
- package/dist/types/types/cipher.d.ts +1 -1
- package/dist/types/types/crypto-api.d.ts +54 -6
- package/dist/types/types/crypto-api.d.ts.map +1 -1
- package/dist/types/types/key-converter.d.ts +37 -15
- package/dist/types/types/key-converter.d.ts.map +1 -1
- package/dist/types/types/key-deriver.d.ts +41 -0
- package/dist/types/types/key-deriver.d.ts.map +1 -1
- package/dist/types/types/key-io.d.ts +37 -0
- package/dist/types/types/key-io.d.ts.map +1 -1
- package/dist/types/types/params-direct.d.ts +96 -1
- package/dist/types/types/params-direct.d.ts.map +1 -1
- package/dist/types/types/params-kms.d.ts +55 -0
- package/dist/types/types/params-kms.d.ts.map +1 -1
- package/dist/types/utils.d.ts +19 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +4 -4
- package/package.json +29 -45
- package/src/algorithms/aes-ctr.ts +2 -2
- package/src/algorithms/aes-gcm.ts +41 -4
- package/src/algorithms/aes-kw.ts +182 -0
- package/src/algorithms/ecdsa.ts +145 -8
- package/src/algorithms/eddsa.ts +117 -10
- package/src/algorithms/hkdf.ts +54 -0
- package/src/algorithms/pbkdf2.ts +57 -0
- package/src/algorithms/sha-2.ts +3 -3
- package/src/algorithms/x25519.ts +153 -0
- package/src/crypto-error.ts +45 -0
- package/src/index.ts +8 -0
- package/src/jose/jwk.ts +32 -32
- package/src/local-key-manager.ts +22 -16
- package/src/primitives/aes-ctr.ts +1 -1
- package/src/primitives/aes-gcm.ts +5 -5
- package/src/primitives/aes-kw.ts +269 -0
- package/src/primitives/concat-kdf.ts +4 -2
- package/src/primitives/ecies-secp256k1.ts +113 -0
- package/src/primitives/ed25519.ts +6 -6
- package/src/primitives/hkdf.ts +121 -0
- package/src/primitives/pbkdf2.ts +91 -0
- package/src/primitives/secp256k1.ts +6 -6
- package/src/primitives/secp256r1.ts +6 -6
- package/src/primitives/x25519.ts +12 -19
- package/src/primitives/xchacha20-poly1305.ts +57 -4
- package/src/primitives/xchacha20.ts +1 -1
- package/src/types/cipher.ts +1 -1
- package/src/types/crypto-api.ts +129 -11
- package/src/types/key-converter.ts +33 -7
- package/src/types/key-deriver.ts +49 -0
- package/src/types/key-io.ts +40 -0
- package/src/types/params-direct.ts +118 -1
- package/src/types/params-kms.ts +67 -0
- package/src/utils.ts +55 -2
- package/dist/browser.js +0 -64
- package/dist/browser.js.map +0 -7
- package/dist/cjs/algorithms/aes-ctr.js +0 -188
- package/dist/cjs/algorithms/aes-ctr.js.map +0 -1
- package/dist/cjs/algorithms/aes-gcm.js +0 -196
- package/dist/cjs/algorithms/aes-gcm.js.map +0 -1
- package/dist/cjs/algorithms/crypto-algorithm.js +0 -13
- package/dist/cjs/algorithms/crypto-algorithm.js.map +0 -1
- package/dist/cjs/algorithms/ecdsa.js +0 -352
- package/dist/cjs/algorithms/ecdsa.js.map +0 -1
- package/dist/cjs/algorithms/eddsa.js +0 -325
- package/dist/cjs/algorithms/eddsa.js.map +0 -1
- package/dist/cjs/algorithms/sha-2.js +0 -119
- package/dist/cjs/algorithms/sha-2.js.map +0 -1
- package/dist/cjs/index.js +0 -41
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/jose/jwe.js +0 -3
- package/dist/cjs/jose/jwe.js.map +0 -1
- package/dist/cjs/jose/jwk.js +0 -278
- package/dist/cjs/jose/jwk.js.map +0 -1
- package/dist/cjs/jose/jws.js +0 -3
- package/dist/cjs/jose/jws.js.map +0 -1
- package/dist/cjs/jose/jwt.js +0 -3
- package/dist/cjs/jose/jwt.js.map +0 -1
- package/dist/cjs/jose/utils.js +0 -60
- package/dist/cjs/jose/utils.js.map +0 -1
- package/dist/cjs/local-key-manager.js +0 -521
- package/dist/cjs/local-key-manager.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/primitives/aes-ctr.js +0 -398
- package/dist/cjs/primitives/aes-ctr.js.map +0 -1
- package/dist/cjs/primitives/aes-gcm.js +0 -425
- package/dist/cjs/primitives/aes-gcm.js.map +0 -1
- package/dist/cjs/primitives/concat-kdf.js +0 -215
- package/dist/cjs/primitives/concat-kdf.js.map +0 -1
- package/dist/cjs/primitives/ed25519.js +0 -651
- package/dist/cjs/primitives/ed25519.js.map +0 -1
- package/dist/cjs/primitives/pbkdf2.js +0 -120
- package/dist/cjs/primitives/pbkdf2.js.map +0 -1
- package/dist/cjs/primitives/secp256k1.js +0 -958
- package/dist/cjs/primitives/secp256k1.js.map +0 -1
- package/dist/cjs/primitives/secp256r1.js +0 -959
- package/dist/cjs/primitives/secp256r1.js.map +0 -1
- package/dist/cjs/primitives/sha256.js +0 -93
- package/dist/cjs/primitives/sha256.js.map +0 -1
- package/dist/cjs/primitives/x25519.js +0 -498
- package/dist/cjs/primitives/x25519.js.map +0 -1
- package/dist/cjs/primitives/xchacha20-poly1305.js +0 -340
- package/dist/cjs/primitives/xchacha20-poly1305.js.map +0 -1
- package/dist/cjs/primitives/xchacha20.js +0 -316
- package/dist/cjs/primitives/xchacha20.js.map +0 -1
- package/dist/cjs/types/cipher.js +0 -3
- package/dist/cjs/types/cipher.js.map +0 -1
- package/dist/cjs/types/crypto-api.js +0 -3
- package/dist/cjs/types/crypto-api.js.map +0 -1
- package/dist/cjs/types/hasher.js +0 -3
- package/dist/cjs/types/hasher.js.map +0 -1
- package/dist/cjs/types/identifier.js +0 -3
- package/dist/cjs/types/identifier.js.map +0 -1
- package/dist/cjs/types/key-compressor.js +0 -3
- package/dist/cjs/types/key-compressor.js.map +0 -1
- package/dist/cjs/types/key-converter.js +0 -3
- package/dist/cjs/types/key-converter.js.map +0 -1
- package/dist/cjs/types/key-deriver.js +0 -3
- package/dist/cjs/types/key-deriver.js.map +0 -1
- package/dist/cjs/types/key-generator.js +0 -3
- package/dist/cjs/types/key-generator.js.map +0 -1
- package/dist/cjs/types/key-io.js +0 -3
- package/dist/cjs/types/key-io.js.map +0 -1
- package/dist/cjs/types/key-wrapper.js +0 -3
- package/dist/cjs/types/key-wrapper.js.map +0 -1
- package/dist/cjs/types/params-direct.js +0 -3
- package/dist/cjs/types/params-direct.js.map +0 -1
- package/dist/cjs/types/params-enclosed.js +0 -3
- package/dist/cjs/types/params-enclosed.js.map +0 -1
- package/dist/cjs/types/params-kms.js +0 -3
- package/dist/cjs/types/params-kms.js.map +0 -1
- package/dist/cjs/types/signer.js +0 -3
- package/dist/cjs/types/signer.js.map +0 -1
- package/dist/cjs/utils.js +0 -173
- package/dist/cjs/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../../../src/primitives/aes-gcm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D,OAAO,EAAE,oBAAoB,EAAE,eAAe,E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AiC;YACjC,8FAA8F;YAC9F,wFAAwF;YACxF,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,WAAW,CAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAElG,wCAAwC;YACxC,MAAM,KAAkC,MAAM,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,EAAhF,EAAE,GAAG,EAAE,OAAO,OAAkE,EAA7D,UAAU,cAA7B,kBAA+B,CAAiD,CAAC;YAEvF,oDAAoD;YACpD,UAAU,CAAC,GAAG,GAAG,MAAM,oBAAoB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;YAEjE,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACI,MAAM,CAAO,iBAAiB;6DAAC,EAAE,UAAU,EAEjD;YACC,8DAA8D;YAC9D,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC9E,CAAC;YAED,4CAA4C;YAC5C,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
22
|
+
import { Convert } from '@enbox/common';
|
|
23
|
+
import { computeJwkThumbprint, isOctPrivateJwk } from '../jose/jwk.js';
|
|
24
|
+
import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
|
|
25
|
+
/**
|
|
26
|
+
* Constant defining the AES key length values in bits.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* NIST publication FIPS 197 states:
|
|
30
|
+
* > The AES algorithm is capable of using cryptographic keys of 128, 192, and 256 bits to encrypt
|
|
31
|
+
* > and decrypt data in blocks of 128 bits.
|
|
32
|
+
*
|
|
33
|
+
* This implementation does not support key lengths that are different from the three values
|
|
34
|
+
* defined by this constant.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://doi.org/10.6028/NIST.FIPS.197-upd1 | NIST FIPS 197}
|
|
37
|
+
*/
|
|
38
|
+
const AES_KEY_LENGTHS = [128, 192, 256];
|
|
39
|
+
export class AesKw {
|
|
40
|
+
/**
|
|
41
|
+
* Converts a raw private key in bytes to its corresponding JSON Web Key (JWK) format.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* This method takes a symmetric key represented as a byte array (Uint8Array) and
|
|
45
|
+
* converts it into a JWK object for use with AES (Advanced Encryption Standard)
|
|
46
|
+
* for key wrapping. The conversion process involves encoding the key into
|
|
47
|
+
* base64url format and setting the appropriate JWK parameters.
|
|
48
|
+
*
|
|
49
|
+
* The resulting JWK object includes the following properties:
|
|
50
|
+
* - `kty`: Key Type, set to 'oct' for Octet Sequence (representing a symmetric key).
|
|
51
|
+
* - `k`: The symmetric key, base64url-encoded.
|
|
52
|
+
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const privateKeyBytes = new Uint8Array([...]); // Replace with actual symmetric key bytes
|
|
57
|
+
* const privateKey = await AesKw.bytesToPrivateKey({ privateKeyBytes });
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param params - The parameters for the symmetric key conversion.
|
|
61
|
+
* @param params.privateKeyBytes - The raw symmetric key as a Uint8Array.
|
|
62
|
+
*
|
|
63
|
+
* @returns A Promise that resolves to the symmetric key in JWK format.
|
|
64
|
+
*/
|
|
65
|
+
static bytesToPrivateKey(_a) {
|
|
66
|
+
return __awaiter(this, arguments, void 0, function* ({ privateKeyBytes }) {
|
|
67
|
+
// Construct the private key in JWK format.
|
|
68
|
+
const privateKey = {
|
|
69
|
+
k: Convert.uint8Array(privateKeyBytes).toBase64Url(),
|
|
70
|
+
kty: 'oct'
|
|
71
|
+
};
|
|
72
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
73
|
+
privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey });
|
|
74
|
+
// Add algorithm identifier based on key length.
|
|
75
|
+
const lengthInBits = privateKeyBytes.length * 8;
|
|
76
|
+
privateKey.alg = { 128: 'A128KW', 192: 'A192KW', 256: 'A256KW' }[lengthInBits];
|
|
77
|
+
return privateKey;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Generates a symmetric key for AES for key wrapping in JSON Web Key (JWK) format.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* This method creates a new symmetric key of a specified length suitable for use with
|
|
85
|
+
* AES key wrapping. It uses cryptographically secure random number generation to
|
|
86
|
+
* ensure the uniqueness and security of the key. The generated key adheres to the JWK
|
|
87
|
+
* format, making it compatible with common cryptographic standards and easy to use in
|
|
88
|
+
* various cryptographic processes.
|
|
89
|
+
*
|
|
90
|
+
* The generated key includes the following components:
|
|
91
|
+
* - `kty`: Key Type, set to 'oct' for Octet Sequence.
|
|
92
|
+
* - `k`: The symmetric key component, base64url-encoded.
|
|
93
|
+
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
94
|
+
* - `alg`: Algorithm, set to 'A128KW', 'A192KW', or 'A256KW' for AES Key Wrap with the
|
|
95
|
+
* specified key length.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
|
|
100
|
+
* const privateKey = await AesKw.generateKey({ length });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @param params - The parameters for the key generation.
|
|
104
|
+
* @param params.length - The length of the key in bits. Common lengths are 128, 192, and 256 bits.
|
|
105
|
+
*
|
|
106
|
+
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
107
|
+
*/
|
|
108
|
+
static generateKey(_a) {
|
|
109
|
+
return __awaiter(this, arguments, void 0, function* ({ length }) {
|
|
110
|
+
// Validate the key length.
|
|
111
|
+
if (!AES_KEY_LENGTHS.includes(length)) {
|
|
112
|
+
throw new RangeError(`The key length is invalid: Must be ${AES_KEY_LENGTHS.join(', ')} bits`);
|
|
113
|
+
}
|
|
114
|
+
// Get the Web Crypto API interface.
|
|
115
|
+
const webCrypto = getWebcryptoSubtle();
|
|
116
|
+
// Generate a random private key.
|
|
117
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#usage_notes for
|
|
118
|
+
// an explanation for why Web Crypto generateKey() is used instead of getRandomValues().
|
|
119
|
+
const webCryptoKey = yield webCrypto.generateKey({ name: 'AES-KW', length }, true, ['wrapKey', 'unwrapKey']);
|
|
120
|
+
// Export the private key in JWK format.
|
|
121
|
+
const _b = yield webCrypto.exportKey('jwk', webCryptoKey), { ext, key_ops } = _b, privateKey = __rest(_b, ["ext", "key_ops"]);
|
|
122
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
123
|
+
privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey });
|
|
124
|
+
return privateKey;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Converts a private key from JSON Web Key (JWK) format to a raw byte array (Uint8Array).
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* This method takes a symmetric key in JWK format and extracts its raw byte representation.
|
|
132
|
+
* It decodes the 'k' parameter of the JWK value, which represents the symmetric key in base64url
|
|
133
|
+
* encoding, into a byte array.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const privateKey = { ... }; // A symmetric key in JWK format
|
|
138
|
+
* const privateKeyBytes = await AesKw.privateKeyToBytes({ privateKey });
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @param params - The parameters for the symmetric key conversion.
|
|
142
|
+
* @param params.privateKey - The symmetric key in JWK format.
|
|
143
|
+
*
|
|
144
|
+
* @returns A Promise that resolves to the symmetric key as a Uint8Array.
|
|
145
|
+
*/
|
|
146
|
+
static privateKeyToBytes(_a) {
|
|
147
|
+
return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
|
|
148
|
+
// Verify the provided JWK represents a valid oct private key.
|
|
149
|
+
if (!isOctPrivateJwk(privateKey)) {
|
|
150
|
+
throw new Error(`AesKw: The provided key is not a valid oct private key.`);
|
|
151
|
+
}
|
|
152
|
+
// Decode the provided private key to bytes.
|
|
153
|
+
const privateKeyBytes = Convert.base64Url(privateKey.k).toUint8Array();
|
|
154
|
+
return privateKeyBytes;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
static unwrapKey(_a) {
|
|
158
|
+
return __awaiter(this, arguments, void 0, function* ({ wrappedKeyBytes, wrappedKeyAlgorithm, decryptionKey }) {
|
|
159
|
+
if (!('alg' in decryptionKey && decryptionKey.alg)) {
|
|
160
|
+
throw new CryptoError(CryptoErrorCode.InvalidJwk, `The decryption key is missing the 'alg' property.`);
|
|
161
|
+
}
|
|
162
|
+
if (!['A128KW', 'A192KW', 'A256KW'].includes(decryptionKey.alg)) {
|
|
163
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'decryptionKey' algorithm is not supported: ${decryptionKey.alg}`);
|
|
164
|
+
}
|
|
165
|
+
// Get the Web Crypto API interface.
|
|
166
|
+
const webCrypto = getWebcryptoSubtle();
|
|
167
|
+
// Import the decryption key for use with the Web Crypto API.
|
|
168
|
+
const decryptionCryptoKey = yield webCrypto.importKey('jwk', // key format
|
|
169
|
+
decryptionKey, // key data
|
|
170
|
+
{ name: 'AES-KW' }, // algorithm identifier
|
|
171
|
+
true, // key is extractable
|
|
172
|
+
['unwrapKey'] // key usages
|
|
173
|
+
);
|
|
174
|
+
// Map the private key's JOSE algorithm name to the Web Crypto API algorithm identifier.
|
|
175
|
+
const webCryptoAlgorithm = {
|
|
176
|
+
A128KW: 'AES-KW', A192KW: 'AES-KW', A256KW: 'AES-KW',
|
|
177
|
+
A128GCM: 'AES-GCM', A192GCM: 'AES-GCM', A256GCM: 'AES-GCM',
|
|
178
|
+
}[wrappedKeyAlgorithm];
|
|
179
|
+
if (!webCryptoAlgorithm) {
|
|
180
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'wrappedKeyAlgorithm' is not supported: ${wrappedKeyAlgorithm}`);
|
|
181
|
+
}
|
|
182
|
+
// Unwrap the key using the Web Crypto API.
|
|
183
|
+
const unwrappedCryptoKey = yield webCrypto.unwrapKey('raw', // output format
|
|
184
|
+
wrappedKeyBytes.buffer, // key to unwrap
|
|
185
|
+
decryptionCryptoKey, // unwrapping key
|
|
186
|
+
'AES-KW', // algorithm identifier
|
|
187
|
+
{ name: webCryptoAlgorithm }, // unwrapped key algorithm identifier
|
|
188
|
+
true, // key is extractable
|
|
189
|
+
['unwrapKey'] // key usages
|
|
190
|
+
);
|
|
191
|
+
// Export the unwrapped key in JWK format.
|
|
192
|
+
const _b = yield webCrypto.exportKey('jwk', unwrappedCryptoKey), { ext, key_ops } = _b, unwrappedJsonWebKey = __rest(_b, ["ext", "key_ops"]);
|
|
193
|
+
const unwrappedKey = unwrappedJsonWebKey;
|
|
194
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
195
|
+
unwrappedKey.kid = yield computeJwkThumbprint({ jwk: unwrappedKey });
|
|
196
|
+
return unwrappedKey;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
static wrapKey(_a) {
|
|
200
|
+
return __awaiter(this, arguments, void 0, function* ({ unwrappedKey, encryptionKey }) {
|
|
201
|
+
if (!('alg' in encryptionKey && encryptionKey.alg)) {
|
|
202
|
+
throw new CryptoError(CryptoErrorCode.InvalidJwk, `The encryption key is missing the 'alg' property.`);
|
|
203
|
+
}
|
|
204
|
+
if (!['A128KW', 'A192KW', 'A256KW'].includes(encryptionKey.alg)) {
|
|
205
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'encryptionKey' algorithm is not supported: ${encryptionKey.alg}`);
|
|
206
|
+
}
|
|
207
|
+
if (!('alg' in unwrappedKey && unwrappedKey.alg)) {
|
|
208
|
+
throw new CryptoError(CryptoErrorCode.InvalidJwk, `The private key to wrap is missing the 'alg' property.`);
|
|
209
|
+
}
|
|
210
|
+
// Get the Web Crypto API interface.
|
|
211
|
+
const webCrypto = getWebcryptoSubtle();
|
|
212
|
+
// Import the encryption key for use with the Web Crypto API.
|
|
213
|
+
const encryptionCryptoKey = yield webCrypto.importKey('jwk', // key format
|
|
214
|
+
encryptionKey, // key data
|
|
215
|
+
{ name: 'AES-KW' }, // algorithm identifier
|
|
216
|
+
true, // key is extractable
|
|
217
|
+
['wrapKey'] // key usages
|
|
218
|
+
);
|
|
219
|
+
// Map the private key's JOSE algorithm name to the Web Crypto API algorithm identifier.
|
|
220
|
+
const webCryptoAlgorithm = {
|
|
221
|
+
A128KW: 'AES-KW', A192KW: 'AES-KW', A256KW: 'AES-KW',
|
|
222
|
+
A128GCM: 'AES-GCM', A192GCM: 'AES-GCM', A256GCM: 'AES-GCM',
|
|
223
|
+
}[unwrappedKey.alg];
|
|
224
|
+
if (!webCryptoAlgorithm) {
|
|
225
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'unwrappedKey' algorithm is not supported: ${unwrappedKey.alg}`);
|
|
226
|
+
}
|
|
227
|
+
// Import the private key to wrap for use with the Web Crypto API.
|
|
228
|
+
const unwrappedCryptoKey = yield webCrypto.importKey('jwk', // key format
|
|
229
|
+
unwrappedKey, // key data
|
|
230
|
+
{ name: webCryptoAlgorithm }, // algorithm identifier
|
|
231
|
+
true, // key is extractable
|
|
232
|
+
['unwrapKey'] // key usages
|
|
233
|
+
);
|
|
234
|
+
// Wrap the key using the Web Crypto API.
|
|
235
|
+
const wrappedKeyBuffer = yield webCrypto.wrapKey('raw', // output format
|
|
236
|
+
unwrappedCryptoKey, // key to wrap
|
|
237
|
+
encryptionCryptoKey, // wrapping key
|
|
238
|
+
'AES-KW' // algorithm identifier
|
|
239
|
+
);
|
|
240
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
241
|
+
const wrappedKeyBytes = new Uint8Array(wrappedKeyBuffer);
|
|
242
|
+
return wrappedKeyBytes;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=aes-kw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-kw.js","sourceRoot":"","sources":["../../../src/primitives/aes-kw.ts"],"names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B;YAC3C,IAAI,EAAE,qBAAqB;YAC3B,CAAC,SAAS,CAAC,CAAC,aAAa;aAC1B,CAAC;YAEF,wFAAwF;YACxF,MAAM,kBAAkB,GAAG;gBACzB,MAAM,EAAI,QAAQ,EAAE,MAAM,EAAI,QAAQ,EAAE,MAAM,EAAI,QAAQ;gBAC1D,OAAO,EAAG,SAAS,EAAE,OAAO,EAAG,SAAS,EAAE,OAAO,EAAG,SAAS;aAC9D,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAEpB,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACxB,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,kDAAkD,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;YACrI,CAAC;YAED,kEAAkE;YAClE,MAAM,kBAAkB,GAAG,MAAM,SAAS,CAAC,SAAS,CAClD,KAAK,EAAE,aAAa;YACpB,YAA0B,EAAE,WAAW;YACvC,EAAE,IAAI,EAAE,kBAAkB,EAAE,EAAE,uBAAuB;YACrD,IAAI,EAAE,qBAAqB;YAC3B,CAAC,WAAW,CAAC,CAAC,aAAa;aAC5B,CAAC;YAEF,yCAAyC;YACzC,MAAM,gBAAgB,GAAG,MAAM,SAAS,CAAC,OAAO,CAC9C,KAAK,EAAE,gBAAgB;YACvB,kBAAkB,EAAE,cAAc;YAClC,mBAAmB,EAAE,eAAe;YACpC,QAAQ,CAAC,uBAAuB;aACjC,CAAC;YAEF,0CAA0C;YAC1C,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;YAEzD,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
|
|
@@ -7,9 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { concatBytes } from '@noble/hashes/utils';
|
|
10
11
|
import { sha256 } from '@noble/hashes/sha256';
|
|
11
12
|
import { Convert, universalTypeOf } from '@enbox/common';
|
|
12
|
-
import { concatBytes } from '@noble/hashes/utils';
|
|
13
13
|
/**
|
|
14
14
|
* An implementation of the Concatenation Key Derivation Function (ConcatKDF)
|
|
15
15
|
* as specified in NIST.800-56A, a single-step key-derivation function (SSKDF).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat-kdf.js","sourceRoot":"","sources":["../../../src/primitives/concat-kdf.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"concat-kdf.js","sourceRoot":"","sources":["../../../src/primitives/concat-kdf.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA+CzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,OAAO,SAAS;IACpB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,MAAM,CAAO,SAAS;6DAAC,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAIlE;YACC,yEAAyE;YACzE,mEAAmE;YACnE,wEAAwE;YACxE,+DAA+D;YAC/D,MAAM,OAAO,GAAG,GAAG,CAAC;YAEpB,6DAA6D;YAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC;YACnD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,wBAAwB,CAAC,CAAC;YACzE,CAAC;YAED,oEAAoE;YACpE,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;YAClC,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAA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AAI,EAAE,cAAc,GAAG,IAAI,EAGzD;QACC,IAAI,WAAuB,CAAC;QAC5B,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QAEvC,2DAA2D;QAC3D,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;YAC7B,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;QAED,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,OAAO,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;gBACzC,CAAC,CAAC,IAAkB;gBACpB,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,YAAY,EAAE,CAAC;YAC/C,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;YACpC,WAAW,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;YAC/C,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;YAC5D,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAE9B,CAAC;aAAM,CAAC;YACN,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,MAAM,SAAS,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YACD,WAAW,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { concatBytes } from '@noble/ciphers/utils';
|
|
2
|
+
import { gcm } from '@noble/ciphers/aes';
|
|
3
|
+
import { hkdf } from '@noble/hashes/hkdf';
|
|
4
|
+
import { randomBytes } from '@noble/ciphers/webcrypto';
|
|
5
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
6
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
7
|
+
/**
|
|
8
|
+
* AEAD tag length for AES-256-GCM (16 bytes / 128 bits).
|
|
9
|
+
*/
|
|
10
|
+
const AEAD_TAG_LENGTH = 16;
|
|
11
|
+
/**
|
|
12
|
+
* Nonce length for AES-256-GCM encryption.
|
|
13
|
+
*/
|
|
14
|
+
const NONCE_LENGTH = 16;
|
|
15
|
+
/**
|
|
16
|
+
* Browser-compatible ECIES (Elliptic Curve Integrated Encryption Scheme) using secp256k1.
|
|
17
|
+
*
|
|
18
|
+
* Wire-format compatible with `eciesjs` v0.4.x configured with
|
|
19
|
+
* `isEphemeralKeyCompressed: true, isHkdfKeyCompressed: false` (the default).
|
|
20
|
+
*
|
|
21
|
+
* Protocol:
|
|
22
|
+
* 1. Generate an ephemeral secp256k1 key pair.
|
|
23
|
+
* 2. ECDH shared secret (uncompressed point).
|
|
24
|
+
* 3. HKDF-SHA-256 key derivation: `hkdf(sha256, ephemeralPubUncompressed || sharedPointUncompressed)`.
|
|
25
|
+
* 4. AES-256-GCM encryption with random 16-byte nonce.
|
|
26
|
+
*
|
|
27
|
+
* All underlying primitives (`@noble/ciphers`, `@noble/curves`, `@noble/hashes`)
|
|
28
|
+
* are pure JavaScript and work in Node, Bun, and browsers.
|
|
29
|
+
*/
|
|
30
|
+
export class EciesSecp256k1 {
|
|
31
|
+
/**
|
|
32
|
+
* Encrypt plaintext for a given secp256k1 public key.
|
|
33
|
+
* @param publicKeyBytes - Recipient's public key (compressed 33 bytes or uncompressed 65 bytes).
|
|
34
|
+
* @param plaintext - The data to encrypt.
|
|
35
|
+
*/
|
|
36
|
+
static encrypt(publicKeyBytes, plaintext) {
|
|
37
|
+
// Generate ephemeral key pair.
|
|
38
|
+
const ephemeralPrivateKey = secp256k1.utils.randomPrivateKey();
|
|
39
|
+
const ephemeralPubCompressed = secp256k1.getPublicKey(ephemeralPrivateKey, true);
|
|
40
|
+
const ephemeralPubUncompressed = secp256k1.getPublicKey(ephemeralPrivateKey, false);
|
|
41
|
+
// ECDH: shared point (uncompressed).
|
|
42
|
+
const sharedPointUncompressed = secp256k1.getSharedSecret(ephemeralPrivateKey, publicKeyBytes, false);
|
|
43
|
+
// HKDF-SHA-256: derive 32-byte symmetric key.
|
|
44
|
+
// eciesjs (isHkdfKeyCompressed=false): master = senderPubUncompressed || sharedPointUncompressed
|
|
45
|
+
const symmetricKey = hkdf(sha256, concatBytes(ephemeralPubUncompressed, sharedPointUncompressed), undefined, undefined, 32);
|
|
46
|
+
// AES-256-GCM encrypt.
|
|
47
|
+
const nonce = randomBytes(NONCE_LENGTH);
|
|
48
|
+
const ciphered = gcm(symmetricKey, nonce).encrypt(plaintext); // ciphertext || tag
|
|
49
|
+
return {
|
|
50
|
+
ephemeralPublicKey: ephemeralPubCompressed,
|
|
51
|
+
initializationVector: nonce,
|
|
52
|
+
messageAuthenticationCode: ciphered.subarray(ciphered.length - AEAD_TAG_LENGTH),
|
|
53
|
+
ciphertext: ciphered.subarray(0, ciphered.length - AEAD_TAG_LENGTH),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Decrypt ciphertext produced by {@link EciesSecp256k1.encrypt}.
|
|
58
|
+
* @param input - The encryption output plus the recipient's private key.
|
|
59
|
+
*/
|
|
60
|
+
static decrypt(input) {
|
|
61
|
+
const { privateKey, ephemeralPublicKey, initializationVector, messageAuthenticationCode, ciphertext } = input;
|
|
62
|
+
// Decompress ephemeral public key (HKDF needs uncompressed form).
|
|
63
|
+
const ephemeralPubUncompressed = secp256k1.ProjectivePoint.fromHex(ephemeralPublicKey).toRawBytes(false);
|
|
64
|
+
// ECDH: shared point (uncompressed).
|
|
65
|
+
const sharedPointUncompressed = secp256k1.getSharedSecret(privateKey, ephemeralPublicKey, false);
|
|
66
|
+
// HKDF-SHA-256: derive 32-byte symmetric key (same derivation as encrypt).
|
|
67
|
+
const symmetricKey = hkdf(sha256, concatBytes(ephemeralPubUncompressed, sharedPointUncompressed), undefined, undefined, 32);
|
|
68
|
+
// AES-256-GCM decrypt: reconstruct the wire format (ciphertext || tag).
|
|
69
|
+
const ciphered = concatBytes(ciphertext, messageAuthenticationCode);
|
|
70
|
+
return gcm(symmetricKey, Uint8Array.from(initializationVector)).decrypt(ciphered);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether the ephemeral public key is compressed (always true for this implementation).
|
|
74
|
+
*/
|
|
75
|
+
static get isEphemeralKeyCompressed() {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=ecies-secp256k1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecies-secp256k1.js","sourceRoot":"","sources":["../../../src/primitives/ecies-secp256k1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;GAEG;AACH,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;GAEG;AACH,MAAM,YAAY,GAAG,EAAE,CAAC;AAwBxB;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,cAAc;IACzB;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,cAA0B,EAAE,SAAqB;QACrE,+BAA+B;QAC/B,MAAM,mBAAmB,GAAG,SAAS,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/D,MAAM,sBAAsB,GAAG,SAAS,CAAC,YAAY,CAAC,mBAAmB,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AEjG,2EAA2E;QAC3E,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,wBAAwB,EAAE,uBAAuB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QAE5H,wEAAwE;QACxE,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,EAAE,yBAAyB,CAAC,CAAC;QACpE,OAAO,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpF,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,wBAAwB;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -19,7 +19,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { Convert } from '@enbox/common';
|
|
22
|
-
import { ed25519,
|
|
22
|
+
import { ed25519, edwardsToMontgomeryPriv, edwardsToMontgomeryPub, x25519 } from '@noble/curves/ed25519';
|
|
23
23
|
import { computeJwkThumbprint, isOkpPrivateJwk, isOkpPublicJwk } from '../jose/jwk.js';
|
|
24
24
|
/**
|
|
25
25
|
* The `Ed25519` class provides a comprehensive suite of utilities for working with the Ed25519
|
|
@@ -343,7 +343,7 @@ export class Ed25519 {
|
|
|
343
343
|
throw new Error(`Ed25519: The provided key is not an Ed25519 private JWK.`);
|
|
344
344
|
}
|
|
345
345
|
// Remove the private key property ('d') and make a shallow copy of the provided key.
|
|
346
|
-
|
|
346
|
+
const { d } = key, publicKey = __rest(key, ["d"]);
|
|
347
347
|
// If the key ID is undefined, set it to the JWK thumbprint.
|
|
348
348
|
(_b = publicKey.kid) !== null && _b !== void 0 ? _b : (publicKey.kid = yield computeJwkThumbprint({ jwk: publicKey }));
|
|
349
349
|
return publicKey;
|
|
@@ -477,7 +477,7 @@ export class Ed25519 {
|
|
|
477
477
|
// Check if points are on the Twisted Edwards curve.
|
|
478
478
|
point.assertValidity();
|
|
479
479
|
}
|
|
480
|
-
catch (
|
|
480
|
+
catch (_b) {
|
|
481
481
|
return false;
|
|
482
482
|
}
|
|
483
483
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../../src/primitives/ed25519.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../../src/primitives/ed25519.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKzG,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,OAAO,OAAO;IAClB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,MAAM,CAAO,iBAAiB;6DAAC,EAAE,eAAe,EAEtD;YACC,8CAA8C;YAC9C,MAAM,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;YAE7D,2CAA2C;YAC3C,MAAM,UAAU,GAAQ;gBACtB,GAAG,EAAG,SAAS;gBACf,CAAC,EAAK,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,WAAW,EAAE;gBACvD,GAAG,EAAG,KAAK;gBACX,CAAC,EAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE;aACvD,CAAC;YAEF,oDAAoD;YACpD,UAAU,CAAC,GAAG,GAAG,MAAM,oBAAoB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AAO,CAAC,cAAc,CAAC,CAAC;gBAE5D,oDAAoD;gBACpD,KAAK,CAAC,cAAc,EAAE,CAAC;YAEzB,CAAC;YAAC,WAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACI,MAAM,CAAO,MAAM;6DAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EACnC;YAEZ,mDAAmD;YACnD,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;YAE1E,6CAA6C;YAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;YAEhE,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
11
|
+
import { Convert } from '@enbox/common';
|
|
12
|
+
/**
|
|
13
|
+
* The `Hkdf` class provides an interface for HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
|
|
14
|
+
* as defined in RFC 5869.
|
|
15
|
+
*
|
|
16
|
+
* Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy secret
|
|
17
|
+
* value, such as a cryptographic key. It should be kept confidential and not be derived from a
|
|
18
|
+
* low-entropy value, such as a password.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const info = new Uint8Array([...]);
|
|
23
|
+
* const derivedKeyBytes = await Hkdf.deriveKeyBytes({
|
|
24
|
+
* baseKeyBytes: new Uint8Array([...]), // Input keying material
|
|
25
|
+
* hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
|
|
26
|
+
* salt: new Uint8Array([...]), // The salt value
|
|
27
|
+
* info: new Uint8Array([...]), // Optional application-specific information
|
|
28
|
+
* length: 256 // The length of the derived key in bits
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class Hkdf {
|
|
33
|
+
/**
|
|
34
|
+
* Derives a key using the HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
|
|
35
|
+
*
|
|
36
|
+
* This method generates a derived key using a hash function from input keying material given as
|
|
37
|
+
* `baseKeyBytes`. The length of the derived key can be specified. Optionally, it can also use a salt
|
|
38
|
+
* and info for the derivation process.
|
|
39
|
+
*
|
|
40
|
+
* HKDF is useful in various cryptographic applications and protocols, especially when
|
|
41
|
+
* there's a need to derive multiple keys from a single source of key material.
|
|
42
|
+
*
|
|
43
|
+
* Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy
|
|
44
|
+
* secret value, such as a cryptographic key. It should be kept confidential and not be derived
|
|
45
|
+
* from a low-entropy value, such as a password.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const info = new Uint8Array([...]);
|
|
50
|
+
* const derivedKeyBytes = await Hkdf.deriveKeyBytes({
|
|
51
|
+
* baseKeyBytes: new Uint8Array([...]), // Input keying material
|
|
52
|
+
* hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
|
|
53
|
+
* salt: new Uint8Array([...]), // The salt value
|
|
54
|
+
* info: new Uint8Array([...]), // Optional application-specific information
|
|
55
|
+
* length: 256 // The length of the derived key in bits
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param params - The parameters for key derivation.
|
|
60
|
+
* @returns A Promise that resolves to the derived key as a byte array.
|
|
61
|
+
*/
|
|
62
|
+
static deriveKeyBytes(_a) {
|
|
63
|
+
return __awaiter(this, arguments, void 0, function* ({ baseKeyBytes, length, hash, salt, info = new Uint8Array() }) {
|
|
64
|
+
// Get the Web Crypto API interface.
|
|
65
|
+
const webCrypto = getWebcryptoSubtle();
|
|
66
|
+
// Import the baseKeyBytes into the Web Crypto API to use for the key derivation operation.
|
|
67
|
+
const webCryptoKey = yield webCrypto.importKey('raw', baseKeyBytes, { name: 'HKDF' }, false, ['deriveBits']);
|
|
68
|
+
// Convert the salt and info to Uint8Array if they are provided as strings.
|
|
69
|
+
const saltBytes = typeof salt === 'string' ? Convert.string(salt).toUint8Array() : salt;
|
|
70
|
+
const infoBytes = typeof info === 'string' ? Convert.string(info).toUint8Array() : info;
|
|
71
|
+
// Derive the bytes using the Web Crypto API.
|
|
72
|
+
const derivedKeyBuffer = yield webCrypto.deriveBits({ name: 'HKDF', hash, salt: saltBytes, info: infoBytes }, webCryptoKey, length);
|
|
73
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
74
|
+
const derivedKeyBytes = new Uint8Array(derivedKeyBuffer);
|
|
75
|
+
return derivedKeyBytes;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=hkdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../../src/primitives/hkdf.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,OAAO,EAA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ments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
10
11
|
import { crypto } from '@noble/hashes/crypto';
|
|
11
12
|
/**
|
|
12
13
|
* The `Pbkdf2` class provides a secure way to derive cryptographic keys from a password
|
|
@@ -74,5 +75,53 @@ export class Pbkdf2 {
|
|
|
74
75
|
return derivedKey;
|
|
75
76
|
});
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Derives cryptographic key bytes from base key material using the PBKDF2 algorithm.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This method is similar to {@link Pbkdf2.deriveKey | `deriveKey()`} but accepts
|
|
83
|
+
* raw key bytes (`baseKeyBytes`) instead of a password. It is intended for use cases
|
|
84
|
+
* where the input key material is already available as a byte array.
|
|
85
|
+
*
|
|
86
|
+
* Notes:
|
|
87
|
+
* - The `baseKeyBytes` that will be the input key material for PBKDF2 is expected to be a
|
|
88
|
+
* low-entropy value, such as a password or passphrase. It should be kept confidential.
|
|
89
|
+
* - In 2023,
|
|
90
|
+
* {@link https://web.archive.org/web/20230123232056/https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
|
|
91
|
+
* | OWASP recommended}
|
|
92
|
+
* a minimum of 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({
|
|
97
|
+
* baseKeyBytes: new TextEncoder().encode('password'),
|
|
98
|
+
* hash: 'SHA-256',
|
|
99
|
+
* salt: new Uint8Array([...]),
|
|
100
|
+
* iterations: 600_000,
|
|
101
|
+
* length: 256
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @param params - The parameters for key derivation.
|
|
106
|
+
* @returns A Promise that resolves to the derived key as a byte array.
|
|
107
|
+
*/
|
|
108
|
+
static deriveKeyBytes(_a) {
|
|
109
|
+
return __awaiter(this, arguments, void 0, function* ({ baseKeyBytes, hash, salt, iterations, length }) {
|
|
110
|
+
// Get the Web Crypto API interface.
|
|
111
|
+
const webCrypto = getWebcryptoSubtle();
|
|
112
|
+
// Import the password as a raw key for use with the Web Crypto API.
|
|
113
|
+
const webCryptoKey = yield webCrypto.importKey('raw', // key format is raw bytes
|
|
114
|
+
baseKeyBytes, // key data to import
|
|
115
|
+
{ name: 'PBKDF2' }, // algorithm identifier
|
|
116
|
+
false, // key is not extractable
|
|
117
|
+
['deriveBits'] // key usages
|
|
118
|
+
);
|
|
119
|
+
// Derive the bytes using the Web Crypto API.
|
|
120
|
+
const derivedKeyBuffer = yield webCrypto.deriveBits({ name: 'PBKDF2', hash, salt, iterations }, webCryptoKey, length);
|
|
121
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
122
|
+
const derivedKeyBytes = new Uint8Array(derivedKeyBuffer);
|
|
123
|
+
return derivedKeyBytes;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
77
126
|
}
|
|
78
127
|
//# sourceMappingURL=pbkdf2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../../src/primitives/pbkdf2.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../../src/primitives/pbkdf2.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAuE9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,MAAM;IACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACI,MAAM,CAAO,SAAS;6DAAC,EAAE,IAAI,EAAE,QAAQ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AAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
|
|
@@ -19,9 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { Convert } from '@enbox/common';
|
|
22
|
-
import { sha256 } from '@noble/hashes/sha256';
|
|
23
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
24
22
|
import { numberToBytesBE } from '@noble/curves/abstract/utils';
|
|
23
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
24
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
25
25
|
import { computeJwkThumbprint, isEcPrivateJwk, isEcPublicJwk } from '../jose/jwk.js';
|
|
26
26
|
/**
|
|
27
27
|
* The `Secp256k1` class provides a comprehensive suite of utilities for working with
|
|
@@ -454,7 +454,7 @@ export class Secp256k1 {
|
|
|
454
454
|
throw new Error(`Secp256k1: The provided key is not a secp256k1 private JWK.`);
|
|
455
455
|
}
|
|
456
456
|
// Remove the private key property ('d') and make a shallow copy of the provided key.
|
|
457
|
-
|
|
457
|
+
const { d } = key, publicKey = __rest(key, ["d"]);
|
|
458
458
|
// If the key ID is undefined, set it to the JWK thumbprint.
|
|
459
459
|
(_b = publicKey.kid) !== null && _b !== void 0 ? _b : (publicKey.kid = yield computeJwkThumbprint({ jwk: publicKey }));
|
|
460
460
|
return publicKey;
|
|
@@ -696,7 +696,7 @@ export class Secp256k1 {
|
|
|
696
696
|
// Check if points are on the Short Weierstrass curve.
|
|
697
697
|
point.assertValidity();
|
|
698
698
|
}
|
|
699
|
-
catch (
|
|
699
|
+
catch (_b) {
|
|
700
700
|
return false;
|
|
701
701
|
}
|
|
702
702
|
return true;
|