@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.
Files changed (107) hide show
  1. package/esm/0_deps.d.ts +1 -0
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +1 -0
  4. package/esm/client/0_params.d.ts +54 -8
  5. package/esm/client/0_params.d.ts.map +1 -1
  6. package/esm/client/1_client_generic.d.ts +72 -1
  7. package/esm/client/1_client_generic.d.ts.map +1 -1
  8. package/esm/client/2_file_manager.d.ts +9 -1
  9. package/esm/client/2_file_manager.d.ts.map +1 -1
  10. package/esm/client/2_file_manager.js +93 -37
  11. package/esm/client/3_secret_chat_manager.d.ts +11 -2
  12. package/esm/client/3_secret_chat_manager.d.ts.map +1 -1
  13. package/esm/client/3_secret_chat_manager.js +322 -11
  14. package/esm/client/4_context.d.ts +24 -6
  15. package/esm/client/4_context.d.ts.map +1 -1
  16. package/esm/client/4_context.js +53 -0
  17. package/esm/client/6_client.d.ts +72 -1
  18. package/esm/client/6_client.d.ts.map +1 -1
  19. package/esm/client/6_client.js +89 -0
  20. package/esm/client/6_client_dispatcher.d.ts +72 -1
  21. package/esm/client/6_client_dispatcher.d.ts.map +1 -1
  22. package/esm/client/6_client_dispatcher.js +89 -0
  23. package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts +9 -0
  24. package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts.map +1 -0
  25. package/esm/deps/jsr.io/@std/crypto/1.1.0/_types.js +2 -0
  26. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts +2 -0
  27. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts.map +1 -0
  28. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts +69 -0
  29. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.js +237 -0
  31. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.js +2277 -0
  32. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts +13 -0
  33. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts.map +1 -0
  34. package/esm/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.js +46 -0
  35. package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts +76 -0
  36. package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts.map +1 -0
  37. package/esm/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.js +132 -0
  38. package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts +149 -0
  39. package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts.map +1 -0
  40. package/esm/deps/jsr.io/@std/crypto/1.1.0/crypto.js +270 -0
  41. package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts +22 -0
  42. package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts.map +1 -0
  43. package/esm/deps/jsr.io/@std/crypto/1.1.0/mod.js +23 -0
  44. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +40 -0
  45. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts.map +1 -0
  46. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +61 -0
  47. package/esm/tl/0_utilities.d.ts.map +1 -1
  48. package/esm/tl/0_utilities.js +44 -2
  49. package/esm/tl/1_tl_writer.d.ts.map +1 -1
  50. package/esm/tl/1_tl_writer.js +6 -1
  51. package/esm/types/1_sticker.d.ts +7 -9
  52. package/esm/types/1_sticker.d.ts.map +1 -1
  53. package/esm/types/1_sticker.js +1 -6
  54. package/package.json +1 -1
  55. package/script/0_deps.d.ts +1 -0
  56. package/script/0_deps.d.ts.map +1 -1
  57. package/script/0_deps.js +7 -5
  58. package/script/client/0_params.d.ts +54 -8
  59. package/script/client/0_params.d.ts.map +1 -1
  60. package/script/client/1_client_generic.d.ts +72 -1
  61. package/script/client/1_client_generic.d.ts.map +1 -1
  62. package/script/client/2_file_manager.d.ts +9 -1
  63. package/script/client/2_file_manager.d.ts.map +1 -1
  64. package/script/client/2_file_manager.js +90 -34
  65. package/script/client/3_secret_chat_manager.d.ts +11 -2
  66. package/script/client/3_secret_chat_manager.d.ts.map +1 -1
  67. package/script/client/3_secret_chat_manager.js +319 -8
  68. package/script/client/4_context.d.ts +24 -6
  69. package/script/client/4_context.d.ts.map +1 -1
  70. package/script/client/4_context.js +53 -0
  71. package/script/client/6_client.d.ts +72 -1
  72. package/script/client/6_client.d.ts.map +1 -1
  73. package/script/client/6_client.js +89 -0
  74. package/script/client/6_client_dispatcher.d.ts +72 -1
  75. package/script/client/6_client_dispatcher.d.ts.map +1 -1
  76. package/script/client/6_client_dispatcher.js +89 -0
  77. package/script/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts +9 -0
  78. package/script/deps/jsr.io/@std/crypto/1.1.0/_types.d.ts.map +1 -0
  79. package/script/deps/jsr.io/@std/crypto/1.1.0/_types.js +3 -0
  80. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts +2 -0
  81. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.d.ts.map +1 -0
  82. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts +69 -0
  83. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.d.ts.map +1 -0
  84. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.internal.js +255 -0
  85. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/lib/deno_std_wasm_crypto.js +2315 -0
  86. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts +13 -0
  87. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.d.ts.map +1 -0
  88. package/script/deps/jsr.io/@std/crypto/1.1.0/_wasm/mod.js +51 -0
  89. package/script/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts +76 -0
  90. package/script/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.d.ts.map +1 -0
  91. package/script/deps/jsr.io/@std/crypto/1.1.0/aes_gcm.js +169 -0
  92. package/script/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts +149 -0
  93. package/script/deps/jsr.io/@std/crypto/1.1.0/crypto.d.ts.map +1 -0
  94. package/script/deps/jsr.io/@std/crypto/1.1.0/crypto.js +306 -0
  95. package/script/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts +22 -0
  96. package/script/deps/jsr.io/@std/crypto/1.1.0/mod.d.ts.map +1 -0
  97. package/script/deps/jsr.io/@std/crypto/1.1.0/mod.js +39 -0
  98. package/script/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +40 -0
  99. package/script/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts.map +1 -0
  100. package/script/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +64 -0
  101. package/script/tl/0_utilities.d.ts.map +1 -1
  102. package/script/tl/0_utilities.js +43 -1
  103. package/script/tl/1_tl_writer.d.ts.map +1 -1
  104. package/script/tl/1_tl_writer.js +6 -1
  105. package/script/types/1_sticker.d.ts +7 -9
  106. package/script/types/1_sticker.d.ts.map +1 -1
  107. 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,46 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ export { digest, DigestContext } from "./lib/deno_std_wasm_crypto.js";
3
+ /**
4
+ * All cryptographic hash/digest algorithms supported by std/crypto.
5
+ *
6
+ * For algorithms that are supported by WebCrypto, the name here will match the
7
+ * one used by WebCrypto. Otherwise we prefer the formatting used in the
8
+ * algorithm's official specification. All names are uppercase to facilitate
9
+ * case-insensitive comparisons required by the WebCrypto spec.
10
+ */
11
+ export const DIGEST_ALGORITHM_NAMES = [
12
+ "BLAKE2B",
13
+ "BLAKE2B-128",
14
+ "BLAKE2B-160",
15
+ "BLAKE2B-224",
16
+ "BLAKE2B-256",
17
+ "BLAKE2B-384",
18
+ "BLAKE2S",
19
+ "BLAKE3",
20
+ "KECCAK-224",
21
+ "KECCAK-256",
22
+ "KECCAK-384",
23
+ "KECCAK-512",
24
+ "SHA-384",
25
+ "SHA3-224",
26
+ "SHA3-256",
27
+ "SHA3-384",
28
+ "SHA3-512",
29
+ "SHAKE128",
30
+ "SHAKE256",
31
+ "TIGER",
32
+ // insecure (length-extendable):
33
+ "RIPEMD-160",
34
+ "SHA-224",
35
+ "SHA-256",
36
+ "SHA-512",
37
+ // insecure (length-extendable and collidable):
38
+ "MD4",
39
+ "MD5",
40
+ "SHA-1",
41
+ // insecure (non-cryptographic)
42
+ "FNV32",
43
+ "FNV32A",
44
+ "FNV64",
45
+ "FNV64A",
46
+ ];
@@ -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,132 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ import * as dntShim from "../../../../../_dnt.shims.js";
4
+ /**
5
+ * High-level AES-GCM authenticated encryption with automatic nonce generation.
6
+ *
7
+ * With random nonces, do not encrypt more than ~2^32 messages under the same
8
+ * key. Beyond this limit, nonce collision probability becomes non-negligible.
9
+ *
10
+ * @example Usage
11
+ * ```ts
12
+ * import { encryptAesGcm, decryptAesGcm } from "@std/crypto/aes-gcm";
13
+ * import { assertEquals } from "@std/assert";
14
+ *
15
+ * const key = await crypto.subtle.generateKey(
16
+ * { name: "AES-GCM", length: 256 },
17
+ * false,
18
+ * ["encrypt", "decrypt"],
19
+ * );
20
+ *
21
+ * const plaintext = new TextEncoder().encode("hello world");
22
+ * const encrypted = await encryptAesGcm(key, plaintext);
23
+ * const decrypted = await decryptAesGcm(key, encrypted);
24
+ *
25
+ * assertEquals(decrypted, plaintext);
26
+ * ```
27
+ *
28
+ * @module
29
+ */
30
+ const NONCE_LENGTH = 12;
31
+ const TAG_LENGTH = 16;
32
+ const OVERHEAD = NONCE_LENGTH + TAG_LENGTH;
33
+ /**
34
+ * Encrypts plaintext using AES-GCM with a random 96-bit nonce.
35
+ *
36
+ * Returns `nonce (12 bytes) || ciphertext || tag (16 bytes)`.
37
+ *
38
+ * @example Usage
39
+ * ```ts
40
+ * import { encryptAesGcm } from "@std/crypto/aes-gcm";
41
+ * import { assertNotEquals } from "@std/assert";
42
+ *
43
+ * const key = await crypto.subtle.generateKey(
44
+ * { name: "AES-GCM", length: 256 },
45
+ * false,
46
+ * ["encrypt", "decrypt"],
47
+ * );
48
+ *
49
+ * const encrypted = await encryptAesGcm(
50
+ * key,
51
+ * new TextEncoder().encode("hello world"),
52
+ * );
53
+ *
54
+ * assertNotEquals(encrypted.length, 0);
55
+ * ```
56
+ *
57
+ * @param key The AES-GCM `CryptoKey` to encrypt with.
58
+ * @param plaintext The data to encrypt.
59
+ * @param options Optional additional authenticated data.
60
+ * @returns The concatenated nonce, ciphertext, and authentication tag.
61
+ *
62
+ * @remarks With random nonces, do not encrypt more than ~2^32 messages
63
+ * under the same key. Beyond this limit, nonce collision probability
64
+ * becomes non-negligible.
65
+ *
66
+ * @see {@link https://csrc.nist.gov/pubs/sp/800/38/d/final | NIST SP 800-38D} Section 8.3
67
+ */
68
+ export async function encryptAesGcm(key, plaintext, options) {
69
+ const nonce = dntShim.crypto.getRandomValues(new Uint8Array(NONCE_LENGTH));
70
+ const params = {
71
+ name: "AES-GCM",
72
+ iv: nonce,
73
+ tagLength: TAG_LENGTH * 8,
74
+ };
75
+ if (options?.additionalData !== undefined) {
76
+ params.additionalData = options.additionalData;
77
+ }
78
+ const ciphertextAndTag = new Uint8Array(await dntShim.crypto.subtle.encrypt(params, key, plaintext));
79
+ const result = new Uint8Array(NONCE_LENGTH + ciphertextAndTag.byteLength);
80
+ result.set(nonce);
81
+ result.set(ciphertextAndTag, NONCE_LENGTH);
82
+ return result;
83
+ }
84
+ /**
85
+ * Decrypts data produced by {@linkcode encryptAesGcm}.
86
+ *
87
+ * Expects input in the format `nonce (12 bytes) || ciphertext || tag (16 bytes)`.
88
+ *
89
+ * @example Usage
90
+ * ```ts
91
+ * import { decryptAesGcm, encryptAesGcm } from "@std/crypto/aes-gcm";
92
+ * import { assertEquals } from "@std/assert";
93
+ *
94
+ * const key = await crypto.subtle.generateKey(
95
+ * { name: "AES-GCM", length: 256 },
96
+ * false,
97
+ * ["encrypt", "decrypt"],
98
+ * );
99
+ *
100
+ * const plaintext = new TextEncoder().encode("hello world");
101
+ * const encrypted = await encryptAesGcm(key, plaintext);
102
+ *
103
+ * assertEquals(await decryptAesGcm(key, encrypted), plaintext);
104
+ * ```
105
+ *
106
+ * @param key The AES-GCM `CryptoKey` to decrypt with.
107
+ * @param data The wire-format output from {@linkcode encryptAesGcm}: nonce (12 B) || ciphertext || tag (16 B).
108
+ * @param options Optional additional authenticated data (must match what was used during encryption).
109
+ * @returns The decrypted plaintext.
110
+ * @throws {RangeError} If `data` is shorter than 28 bytes (12 nonce + 16 tag).
111
+ * @throws {DOMException} If authentication fails (wrong key, tampered data, or
112
+ * mismatched additional data).
113
+ */
114
+ export async function decryptAesGcm(key, data, options) {
115
+ const bytes = ArrayBuffer.isView(data)
116
+ ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
117
+ : new Uint8Array(data);
118
+ if (bytes.byteLength < OVERHEAD) {
119
+ throw new RangeError(`Data is too short: expected at least ${OVERHEAD} bytes, got ${bytes.byteLength}`);
120
+ }
121
+ const nonce = bytes.subarray(0, NONCE_LENGTH);
122
+ const ciphertextAndTag = bytes.subarray(NONCE_LENGTH);
123
+ const params = {
124
+ name: "AES-GCM",
125
+ iv: nonce,
126
+ tagLength: TAG_LENGTH * 8,
127
+ };
128
+ if (options?.additionalData !== undefined) {
129
+ params.additionalData = options.additionalData;
130
+ }
131
+ return new Uint8Array(await dntShim.crypto.subtle.decrypt(params, key, ciphertextAndTag));
132
+ }
@@ -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"}