@mtkruto/node 0.171.0 → 0.180.1
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/esm/0_deps.d.ts +1 -0
- package/esm/0_deps.d.ts.map +1 -1
- package/esm/0_deps.js +1 -0
- package/esm/client/0_params.d.ts +54 -8
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/1_client_generic.d.ts +72 -1
- package/esm/client/1_client_generic.d.ts.map +1 -1
- package/esm/client/2_file_manager.d.ts +9 -1
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +93 -37
- package/esm/client/3_secret_chat_manager.d.ts +11 -2
- package/esm/client/3_secret_chat_manager.d.ts.map +1 -1
- package/esm/client/3_secret_chat_manager.js +322 -11
- package/esm/client/4_context.d.ts +24 -6
- package/esm/client/4_context.d.ts.map +1 -1
- package/esm/client/4_context.js +53 -0
- package/esm/client/6_client.d.ts +72 -1
- package/esm/client/6_client.d.ts.map +1 -1
- package/esm/client/6_client.js +89 -0
- package/esm/client/6_client_dispatcher.d.ts +72 -1
- package/esm/client/6_client_dispatcher.d.ts.map +1 -1
- package/esm/client/6_client_dispatcher.js +89 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.js +2 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts +2 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts +69 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.js +237 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.js +2277 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts +13 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.js +46 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts +76 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.js +132 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts +149 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.js +270 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts +22 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.js +23 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +40 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +61 -0
- package/esm/tl/0_utilities.d.ts.map +1 -1
- package/esm/tl/0_utilities.js +44 -2
- package/esm/tl/1_tl_writer.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +6 -1
- package/esm/types/1_sticker.d.ts +7 -9
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/1_sticker.js +1 -6
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -0
- package/script/0_deps.d.ts.map +1 -1
- package/script/0_deps.js +7 -5
- package/script/client/0_params.d.ts +54 -8
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/1_client_generic.d.ts +72 -1
- package/script/client/1_client_generic.d.ts.map +1 -1
- package/script/client/2_file_manager.d.ts +9 -1
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +90 -34
- package/script/client/3_secret_chat_manager.d.ts +11 -2
- package/script/client/3_secret_chat_manager.d.ts.map +1 -1
- package/script/client/3_secret_chat_manager.js +319 -8
- package/script/client/4_context.d.ts +24 -6
- package/script/client/4_context.d.ts.map +1 -1
- package/script/client/4_context.js +53 -0
- package/script/client/6_client.d.ts +72 -1
- package/script/client/6_client.d.ts.map +1 -1
- package/script/client/6_client.js +89 -0
- package/script/client/6_client_dispatcher.d.ts +72 -1
- package/script/client/6_client_dispatcher.d.ts.map +1 -1
- package/script/client/6_client_dispatcher.js +89 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_types.js +3 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts +2 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts +69 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.js +255 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.js +2315 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts +13 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.js +51 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts +76 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.js +169 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts +149 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/crypto.js +306 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts +22 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/mod.js +39 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +40 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +64 -0
- package/script/tl/0_utilities.d.ts.map +1 -1
- package/script/tl/0_utilities.js +43 -1
- package/script/tl/1_tl_writer.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +6 -1
- package/script/types/1_sticker.d.ts +7 -9
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/1_sticker.js +1 -6
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { digest, DigestContext } from "./lib/deno_std_wasm_crypto.js";
|
|
2
|
+
/**
|
|
3
|
+
* All cryptographic hash/digest algorithms supported by std/crypto.
|
|
4
|
+
*
|
|
5
|
+
* For algorithms that are supported by WebCrypto, the name here will match the
|
|
6
|
+
* one used by WebCrypto. Otherwise we prefer the formatting used in the
|
|
7
|
+
* algorithm's official specification. All names are uppercase to facilitate
|
|
8
|
+
* case-insensitive comparisons required by the WebCrypto spec.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DIGEST_ALGORITHM_NAMES: readonly ["BLAKE2B", "BLAKE2B-128", "BLAKE2B-160", "BLAKE2B-224", "BLAKE2B-256", "BLAKE2B-384", "BLAKE2S", "BLAKE3", "KECCAK-224", "KECCAK-256", "KECCAK-384", "KECCAK-512", "SHA-384", "SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512", "SHAKE128", "SHAKE256", "TIGER", "RIPEMD-160", "SHA-224", "SHA-256", "SHA-512", "MD4", "MD5", "SHA-1", "FNV32", "FNV32A", "FNV64", "FNV64A"];
|
|
11
|
+
/** An algorithm name supported by std/crypto. */
|
|
12
|
+
export type DigestAlgorithmName = typeof DIGEST_ALGORITHM_NAMES[number];
|
|
13
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEtE;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sXAmCzB,CAAC;AAEX,iDAAiD;AACjD,MAAM,MAAM,mBAAmB,GAAG,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIGEST_ALGORITHM_NAMES = exports.DigestContext = exports.digest = void 0;
|
|
4
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
5
|
+
var deno_std_wasm_crypto_js_1 = require("./lib/deno_std_wasm_crypto.js");
|
|
6
|
+
Object.defineProperty(exports, "digest", { enumerable: true, get: function () { return deno_std_wasm_crypto_js_1.digest; } });
|
|
7
|
+
Object.defineProperty(exports, "DigestContext", { enumerable: true, get: function () { return deno_std_wasm_crypto_js_1.DigestContext; } });
|
|
8
|
+
/**
|
|
9
|
+
* All cryptographic hash/digest algorithms supported by std/crypto.
|
|
10
|
+
*
|
|
11
|
+
* For algorithms that are supported by WebCrypto, the name here will match the
|
|
12
|
+
* one used by WebCrypto. Otherwise we prefer the formatting used in the
|
|
13
|
+
* algorithm's official specification. All names are uppercase to facilitate
|
|
14
|
+
* case-insensitive comparisons required by the WebCrypto spec.
|
|
15
|
+
*/
|
|
16
|
+
exports.DIGEST_ALGORITHM_NAMES = [
|
|
17
|
+
"BLAKE2B",
|
|
18
|
+
"BLAKE2B-128",
|
|
19
|
+
"BLAKE2B-160",
|
|
20
|
+
"BLAKE2B-224",
|
|
21
|
+
"BLAKE2B-256",
|
|
22
|
+
"BLAKE2B-384",
|
|
23
|
+
"BLAKE2S",
|
|
24
|
+
"BLAKE3",
|
|
25
|
+
"KECCAK-224",
|
|
26
|
+
"KECCAK-256",
|
|
27
|
+
"KECCAK-384",
|
|
28
|
+
"KECCAK-512",
|
|
29
|
+
"SHA-384",
|
|
30
|
+
"SHA3-224",
|
|
31
|
+
"SHA3-256",
|
|
32
|
+
"SHA3-384",
|
|
33
|
+
"SHA3-512",
|
|
34
|
+
"SHAKE128",
|
|
35
|
+
"SHAKE256",
|
|
36
|
+
"TIGER",
|
|
37
|
+
// insecure (length-extendable):
|
|
38
|
+
"RIPEMD-160",
|
|
39
|
+
"SHA-224",
|
|
40
|
+
"SHA-256",
|
|
41
|
+
"SHA-512",
|
|
42
|
+
// insecure (length-extendable and collidable):
|
|
43
|
+
"MD4",
|
|
44
|
+
"MD5",
|
|
45
|
+
"SHA-1",
|
|
46
|
+
// insecure (non-cryptographic)
|
|
47
|
+
"FNV32",
|
|
48
|
+
"FNV32A",
|
|
49
|
+
"FNV64",
|
|
50
|
+
"FNV64A",
|
|
51
|
+
];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
2
|
+
import type { Uint8Array_ } from "./_types.js";
|
|
3
|
+
export type { Uint8Array_ };
|
|
4
|
+
/** Options for {@linkcode encryptAesGcm} and {@linkcode decryptAesGcm}. */
|
|
5
|
+
export interface AesGcmOptions {
|
|
6
|
+
/** Additional authenticated data. Authenticated but not encrypted. */
|
|
7
|
+
additionalData?: dntShim.BufferSource;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Encrypts plaintext using AES-GCM with a random 96-bit nonce.
|
|
11
|
+
*
|
|
12
|
+
* Returns `nonce (12 bytes) || ciphertext || tag (16 bytes)`.
|
|
13
|
+
*
|
|
14
|
+
* @example Usage
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { encryptAesGcm } from "@std/crypto/aes-gcm";
|
|
17
|
+
* import { assertNotEquals } from "@std/assert";
|
|
18
|
+
*
|
|
19
|
+
* const key = await crypto.subtle.generateKey(
|
|
20
|
+
* { name: "AES-GCM", length: 256 },
|
|
21
|
+
* false,
|
|
22
|
+
* ["encrypt", "decrypt"],
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* const encrypted = await encryptAesGcm(
|
|
26
|
+
* key,
|
|
27
|
+
* new TextEncoder().encode("hello world"),
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* assertNotEquals(encrypted.length, 0);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param key The AES-GCM `CryptoKey` to encrypt with.
|
|
34
|
+
* @param plaintext The data to encrypt.
|
|
35
|
+
* @param options Optional additional authenticated data.
|
|
36
|
+
* @returns The concatenated nonce, ciphertext, and authentication tag.
|
|
37
|
+
*
|
|
38
|
+
* @remarks With random nonces, do not encrypt more than ~2^32 messages
|
|
39
|
+
* under the same key. Beyond this limit, nonce collision probability
|
|
40
|
+
* becomes non-negligible.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://csrc.nist.gov/pubs/sp/800/38/d/final | NIST SP 800-38D} Section 8.3
|
|
43
|
+
*/
|
|
44
|
+
export declare function encryptAesGcm(key: dntShim.CryptoKey, plaintext: dntShim.BufferSource, options?: AesGcmOptions): Promise<Uint8Array_>;
|
|
45
|
+
/**
|
|
46
|
+
* Decrypts data produced by {@linkcode encryptAesGcm}.
|
|
47
|
+
*
|
|
48
|
+
* Expects input in the format `nonce (12 bytes) || ciphertext || tag (16 bytes)`.
|
|
49
|
+
*
|
|
50
|
+
* @example Usage
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { decryptAesGcm, encryptAesGcm } from "@std/crypto/aes-gcm";
|
|
53
|
+
* import { assertEquals } from "@std/assert";
|
|
54
|
+
*
|
|
55
|
+
* const key = await crypto.subtle.generateKey(
|
|
56
|
+
* { name: "AES-GCM", length: 256 },
|
|
57
|
+
* false,
|
|
58
|
+
* ["encrypt", "decrypt"],
|
|
59
|
+
* );
|
|
60
|
+
*
|
|
61
|
+
* const plaintext = new TextEncoder().encode("hello world");
|
|
62
|
+
* const encrypted = await encryptAesGcm(key, plaintext);
|
|
63
|
+
*
|
|
64
|
+
* assertEquals(await decryptAesGcm(key, encrypted), plaintext);
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param key The AES-GCM `CryptoKey` to decrypt with.
|
|
68
|
+
* @param data The wire-format output from {@linkcode encryptAesGcm}: nonce (12 B) || ciphertext || tag (16 B).
|
|
69
|
+
* @param options Optional additional authenticated data (must match what was used during encryption).
|
|
70
|
+
* @returns The decrypted plaintext.
|
|
71
|
+
* @throws {RangeError} If `data` is shorter than 28 bytes (12 nonce + 16 tag).
|
|
72
|
+
* @throws {DOMException} If authentication fails (wrong key, tampered data, or
|
|
73
|
+
* mismatched additional data).
|
|
74
|
+
*/
|
|
75
|
+
export declare function decryptAesGcm(key: dntShim.CryptoKey, data: dntShim.BufferSource, options?: AesGcmOptions): Promise<Uint8Array_>;
|
|
76
|
+
//# sourceMappingURL=aes_gcm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes_gcm.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,8BAA8B,CAAC;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAiC5B,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,cAAc,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,CAAC,SAAS,EACtB,SAAS,EAAE,OAAO,CAAC,YAAY,EAC/B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,WAAW,CAAC,CAqBtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,OAAO,CAAC,SAAS,EACtB,IAAI,EAAE,OAAO,CAAC,YAAY,EAC1B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,WAAW,CAAC,CA0BtB"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.encryptAesGcm = encryptAesGcm;
|
|
37
|
+
exports.decryptAesGcm = decryptAesGcm;
|
|
38
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
39
|
+
// This module is browser compatible.
|
|
40
|
+
const dntShim = __importStar(require("../../../../../_dnt.shims.js"));
|
|
41
|
+
/**
|
|
42
|
+
* High-level AES-GCM authenticated encryption with automatic nonce generation.
|
|
43
|
+
*
|
|
44
|
+
* With random nonces, do not encrypt more than ~2^32 messages under the same
|
|
45
|
+
* key. Beyond this limit, nonce collision probability becomes non-negligible.
|
|
46
|
+
*
|
|
47
|
+
* @example Usage
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { encryptAesGcm, decryptAesGcm } from "@std/crypto/aes-gcm";
|
|
50
|
+
* import { assertEquals } from "@std/assert";
|
|
51
|
+
*
|
|
52
|
+
* const key = await crypto.subtle.generateKey(
|
|
53
|
+
* { name: "AES-GCM", length: 256 },
|
|
54
|
+
* false,
|
|
55
|
+
* ["encrypt", "decrypt"],
|
|
56
|
+
* );
|
|
57
|
+
*
|
|
58
|
+
* const plaintext = new TextEncoder().encode("hello world");
|
|
59
|
+
* const encrypted = await encryptAesGcm(key, plaintext);
|
|
60
|
+
* const decrypted = await decryptAesGcm(key, encrypted);
|
|
61
|
+
*
|
|
62
|
+
* assertEquals(decrypted, plaintext);
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @module
|
|
66
|
+
*/
|
|
67
|
+
const NONCE_LENGTH = 12;
|
|
68
|
+
const TAG_LENGTH = 16;
|
|
69
|
+
const OVERHEAD = NONCE_LENGTH + TAG_LENGTH;
|
|
70
|
+
/**
|
|
71
|
+
* Encrypts plaintext using AES-GCM with a random 96-bit nonce.
|
|
72
|
+
*
|
|
73
|
+
* Returns `nonce (12 bytes) || ciphertext || tag (16 bytes)`.
|
|
74
|
+
*
|
|
75
|
+
* @example Usage
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { encryptAesGcm } from "@std/crypto/aes-gcm";
|
|
78
|
+
* import { assertNotEquals } from "@std/assert";
|
|
79
|
+
*
|
|
80
|
+
* const key = await crypto.subtle.generateKey(
|
|
81
|
+
* { name: "AES-GCM", length: 256 },
|
|
82
|
+
* false,
|
|
83
|
+
* ["encrypt", "decrypt"],
|
|
84
|
+
* );
|
|
85
|
+
*
|
|
86
|
+
* const encrypted = await encryptAesGcm(
|
|
87
|
+
* key,
|
|
88
|
+
* new TextEncoder().encode("hello world"),
|
|
89
|
+
* );
|
|
90
|
+
*
|
|
91
|
+
* assertNotEquals(encrypted.length, 0);
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @param key The AES-GCM `CryptoKey` to encrypt with.
|
|
95
|
+
* @param plaintext The data to encrypt.
|
|
96
|
+
* @param options Optional additional authenticated data.
|
|
97
|
+
* @returns The concatenated nonce, ciphertext, and authentication tag.
|
|
98
|
+
*
|
|
99
|
+
* @remarks With random nonces, do not encrypt more than ~2^32 messages
|
|
100
|
+
* under the same key. Beyond this limit, nonce collision probability
|
|
101
|
+
* becomes non-negligible.
|
|
102
|
+
*
|
|
103
|
+
* @see {@link https://csrc.nist.gov/pubs/sp/800/38/d/final | NIST SP 800-38D} Section 8.3
|
|
104
|
+
*/
|
|
105
|
+
async function encryptAesGcm(key, plaintext, options) {
|
|
106
|
+
const nonce = dntShim.crypto.getRandomValues(new Uint8Array(NONCE_LENGTH));
|
|
107
|
+
const params = {
|
|
108
|
+
name: "AES-GCM",
|
|
109
|
+
iv: nonce,
|
|
110
|
+
tagLength: TAG_LENGTH * 8,
|
|
111
|
+
};
|
|
112
|
+
if (options?.additionalData !== undefined) {
|
|
113
|
+
params.additionalData = options.additionalData;
|
|
114
|
+
}
|
|
115
|
+
const ciphertextAndTag = new Uint8Array(await dntShim.crypto.subtle.encrypt(params, key, plaintext));
|
|
116
|
+
const result = new Uint8Array(NONCE_LENGTH + ciphertextAndTag.byteLength);
|
|
117
|
+
result.set(nonce);
|
|
118
|
+
result.set(ciphertextAndTag, NONCE_LENGTH);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Decrypts data produced by {@linkcode encryptAesGcm}.
|
|
123
|
+
*
|
|
124
|
+
* Expects input in the format `nonce (12 bytes) || ciphertext || tag (16 bytes)`.
|
|
125
|
+
*
|
|
126
|
+
* @example Usage
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { decryptAesGcm, encryptAesGcm } from "@std/crypto/aes-gcm";
|
|
129
|
+
* import { assertEquals } from "@std/assert";
|
|
130
|
+
*
|
|
131
|
+
* const key = await crypto.subtle.generateKey(
|
|
132
|
+
* { name: "AES-GCM", length: 256 },
|
|
133
|
+
* false,
|
|
134
|
+
* ["encrypt", "decrypt"],
|
|
135
|
+
* );
|
|
136
|
+
*
|
|
137
|
+
* const plaintext = new TextEncoder().encode("hello world");
|
|
138
|
+
* const encrypted = await encryptAesGcm(key, plaintext);
|
|
139
|
+
*
|
|
140
|
+
* assertEquals(await decryptAesGcm(key, encrypted), plaintext);
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param key The AES-GCM `CryptoKey` to decrypt with.
|
|
144
|
+
* @param data The wire-format output from {@linkcode encryptAesGcm}: nonce (12 B) || ciphertext || tag (16 B).
|
|
145
|
+
* @param options Optional additional authenticated data (must match what was used during encryption).
|
|
146
|
+
* @returns The decrypted plaintext.
|
|
147
|
+
* @throws {RangeError} If `data` is shorter than 28 bytes (12 nonce + 16 tag).
|
|
148
|
+
* @throws {DOMException} If authentication fails (wrong key, tampered data, or
|
|
149
|
+
* mismatched additional data).
|
|
150
|
+
*/
|
|
151
|
+
async function decryptAesGcm(key, data, options) {
|
|
152
|
+
const bytes = ArrayBuffer.isView(data)
|
|
153
|
+
? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
|
|
154
|
+
: new Uint8Array(data);
|
|
155
|
+
if (bytes.byteLength < OVERHEAD) {
|
|
156
|
+
throw new RangeError(`Data is too short: expected at least ${OVERHEAD} bytes, got ${bytes.byteLength}`);
|
|
157
|
+
}
|
|
158
|
+
const nonce = bytes.subarray(0, NONCE_LENGTH);
|
|
159
|
+
const ciphertextAndTag = bytes.subarray(NONCE_LENGTH);
|
|
160
|
+
const params = {
|
|
161
|
+
name: "AES-GCM",
|
|
162
|
+
iv: nonce,
|
|
163
|
+
tagLength: TAG_LENGTH * 8,
|
|
164
|
+
};
|
|
165
|
+
if (options?.additionalData !== undefined) {
|
|
166
|
+
params.additionalData = options.additionalData;
|
|
167
|
+
}
|
|
168
|
+
return new Uint8Array(await dntShim.crypto.subtle.decrypt(params, key, ciphertextAndTag));
|
|
169
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extensions to the
|
|
3
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API | Web Crypto API}
|
|
4
|
+
* supporting additional encryption APIs, but also delegating to the built-in
|
|
5
|
+
* APIs when possible.
|
|
6
|
+
*
|
|
7
|
+
* Provides additional digest algorithms that are not part of the WebCrypto
|
|
8
|
+
* standard as well as a `subtle.digest` and `subtle.digestSync` methods.
|
|
9
|
+
*
|
|
10
|
+
* The {@linkcode KeyStack} export implements the {@linkcode KeyRing} interface
|
|
11
|
+
* for managing rotatable keys for signing data to prevent tampering, like with
|
|
12
|
+
* HTTP cookies.
|
|
13
|
+
*
|
|
14
|
+
* ## Supported algorithms
|
|
15
|
+
*
|
|
16
|
+
* Here is a list of supported algorithms. If the algorithm name in WebCrypto
|
|
17
|
+
* and Wasm/Rust is the same, this library prefers to use the implementation
|
|
18
|
+
* provided by WebCrypto.
|
|
19
|
+
*
|
|
20
|
+
* Length-adjustable algorithms support the
|
|
21
|
+
* {@linkcode DigestAlgorithmObject.length} option.
|
|
22
|
+
*
|
|
23
|
+
* WebCrypto:
|
|
24
|
+
* - `SHA-384`
|
|
25
|
+
* - `SHA-256` (length-extendable)
|
|
26
|
+
* - `SHA-512` (length-extendable)
|
|
27
|
+
*
|
|
28
|
+
* Wasm/Rust:
|
|
29
|
+
* - `BLAKE2B`
|
|
30
|
+
* - `BLAKE2B-128`
|
|
31
|
+
* - `BLAKE2B-160`
|
|
32
|
+
* - `BLAKE2B-224`
|
|
33
|
+
* - `BLAKE2B-256`
|
|
34
|
+
* - `BLAKE2B-384`
|
|
35
|
+
* - `BLAKE2S`
|
|
36
|
+
* - `BLAKE3` (length-adjustable)
|
|
37
|
+
* - `KECCAK-224`
|
|
38
|
+
* - `KECCAK-256`
|
|
39
|
+
* - `KECCAK-384`
|
|
40
|
+
* - `KECCAK-512`
|
|
41
|
+
* - `SHA-384`
|
|
42
|
+
* - `SHA3-224`
|
|
43
|
+
* - `SHA3-256`
|
|
44
|
+
* - `SHA3-384`
|
|
45
|
+
* - `SHA3-512`
|
|
46
|
+
* - `SHAKE128` (length-adjustable)
|
|
47
|
+
* - `SHAKE256` (length-adjustable)
|
|
48
|
+
* - `TIGER`
|
|
49
|
+
* - `RIPEMD-160` (length-extendable)
|
|
50
|
+
* - `SHA-224` (length-extendable)
|
|
51
|
+
* - `SHA-256` (length-extendable)
|
|
52
|
+
* - `SHA-512` (length-extendable)
|
|
53
|
+
* - `MD4` (length-extendable and collidable)
|
|
54
|
+
* - `MD5` (length-extendable and collidable)
|
|
55
|
+
* - `SHA-1` (length-extendable and collidable)
|
|
56
|
+
* - `FNV32` (non-cryptographic)
|
|
57
|
+
* - `FNV32A` (non-cryptographic)
|
|
58
|
+
* - `FNV64` (non-cryptographic)
|
|
59
|
+
* - `FNV64A` (non-cryptographic)
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { crypto } from "@std/crypto";
|
|
64
|
+
*
|
|
65
|
+
* // This will delegate to the runtime's WebCrypto implementation.
|
|
66
|
+
* console.log(
|
|
67
|
+
* new Uint8Array(
|
|
68
|
+
* await crypto.subtle.digest(
|
|
69
|
+
* "SHA-384",
|
|
70
|
+
* new TextEncoder().encode("hello world"),
|
|
71
|
+
* ),
|
|
72
|
+
* ),
|
|
73
|
+
* );
|
|
74
|
+
*
|
|
75
|
+
* // This will use a bundled Wasm/Rust implementation.
|
|
76
|
+
* console.log(
|
|
77
|
+
* new Uint8Array(
|
|
78
|
+
* await crypto.subtle.digest(
|
|
79
|
+
* "BLAKE3",
|
|
80
|
+
* new TextEncoder().encode("hello world"),
|
|
81
|
+
* ),
|
|
82
|
+
* ),
|
|
83
|
+
* );
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example Convert hash to a string
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* import {
|
|
90
|
+
* crypto,
|
|
91
|
+
* } from "@std/crypto";
|
|
92
|
+
* import { encodeHex } from "@std/encoding/hex"
|
|
93
|
+
* import { encodeBase64 } from "@std/encoding/base64"
|
|
94
|
+
*
|
|
95
|
+
* const hash = await crypto.subtle.digest(
|
|
96
|
+
* "SHA-384",
|
|
97
|
+
* new TextEncoder().encode("You hear that Mr. Anderson?"),
|
|
98
|
+
* );
|
|
99
|
+
*
|
|
100
|
+
* // Hex encoding
|
|
101
|
+
* console.log(encodeHex(hash));
|
|
102
|
+
*
|
|
103
|
+
* // Or with base64 encoding
|
|
104
|
+
* console.log(encodeBase64(hash));
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @module
|
|
108
|
+
*/
|
|
109
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
110
|
+
import { DIGEST_ALGORITHM_NAMES, type DigestAlgorithmName } from "./_wasm/mod.js";
|
|
111
|
+
export { DIGEST_ALGORITHM_NAMES, type DigestAlgorithmName };
|
|
112
|
+
/** Extensions to the web standard `SubtleCrypto` interface. */
|
|
113
|
+
export interface StdSubtleCrypto extends dntShim.SubtleCrypto {
|
|
114
|
+
/**
|
|
115
|
+
* Returns a new `Promise` object that will digest `data` using the specified
|
|
116
|
+
* `AlgorithmIdentifier`.
|
|
117
|
+
*/
|
|
118
|
+
digest(algorithm: DigestAlgorithm, data: dntShim.BufferSource | AsyncIterable<dntShim.BufferSource> | Iterable<dntShim.BufferSource>): Promise<ArrayBuffer>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns a ArrayBuffer with the result of digesting `data` using the
|
|
121
|
+
* specified `AlgorithmIdentifier`.
|
|
122
|
+
*/
|
|
123
|
+
digestSync(algorithm: DigestAlgorithm, data: dntShim.BufferSource | Iterable<dntShim.BufferSource>): ArrayBuffer;
|
|
124
|
+
}
|
|
125
|
+
/** Extensions to the Web {@linkcode Crypto} interface. */
|
|
126
|
+
export interface StdCrypto extends dntShim.Crypto {
|
|
127
|
+
/** Extension to the {@linkcode crypto.SubtleCrypto} interface. */
|
|
128
|
+
readonly subtle: StdSubtleCrypto;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A wrapper for WebCrypto which adds support for additional non-standard
|
|
132
|
+
* algorithms, but delegates to the runtime WebCrypto implementation whenever
|
|
133
|
+
* possible.
|
|
134
|
+
*/
|
|
135
|
+
declare const stdCrypto: StdCrypto;
|
|
136
|
+
/** Extended digest algorithm objects. */
|
|
137
|
+
export type DigestAlgorithmObject = {
|
|
138
|
+
name: DigestAlgorithmName;
|
|
139
|
+
length?: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Extended digest algorithms accepted by {@linkcode stdCrypto.subtle.digest}.
|
|
143
|
+
*
|
|
144
|
+
* The `length` option will be ignored for
|
|
145
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#algorithm | Web Standard algorithms}.
|
|
146
|
+
*/
|
|
147
|
+
export type DigestAlgorithm = DigestAlgorithmName | DigestAlgorithmObject;
|
|
148
|
+
export { stdCrypto as crypto };
|
|
149
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/crypto/1.1.0/crypto.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2GG;AACH,OAAO,KAAK,OAAO,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAEL,sBAAsB,EACtB,KAAK,mBAAmB,EAEzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,CAAC;AA6C5D,+DAA+D;AAC/D,MAAM,WAAW,eAAgB,SAAQ,OAAO,CAAC,YAAY;IAC3D;;;OAGG;IACH,MAAM,CACJ,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,OAAO,CAAC,YAAY,GAAG,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,GAChG,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;OAGG;IACH,UAAU,CACR,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,GAC1D,WAAW,CAAC;CAChB;AAED,0DAA0D;AAC1D,MAAM,WAAW,SAAU,SAAQ,OAAO,CAAC,MAAM;IAC/C,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CAClC;AAED;;;;GAIG;AACH,QAAA,MAAM,SAAS,EAAE,SA6Ff,CAAC;AAyBH,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAuB1E,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,CAAC"}
|