1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 |
/**
* Extensions to the
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API | Web Crypto}
* supporting additional encryption APIs, but also delegating to the built-in
* APIs when possible.
*
* ```ts no-assert
* import { crypto } from "@std/crypto/crypto";
*
* const message = "Hello, Deno!";
* const encoder = new TextEncoder();
* const data = encoder.encode(message);
*
* await crypto.subtle.digest("BLAKE3", data);
* ```
*
* @module
*/
import { DIGEST_ALGORITHM_NAMES as _variable_DIGEST_ALGORITHM_NAMES } from "jsr:@std/[email protected]"
/**
* All cryptographic hash/digest algorithms supported by std/crypto.
*
* For algorithms that are supported by WebCrypto, the name here will match the
* one used by WebCrypto. Otherwise we prefer the formatting used in the
* algorithm's official specification. All names are uppercase to facilitate
* case-insensitive comparisons required by the WebCrypto spec.
*/
const DIGEST_ALGORITHM_NAMES = _variable_DIGEST_ALGORITHM_NAMES as typeof _variable_DIGEST_ALGORITHM_NAMES
export { DIGEST_ALGORITHM_NAMES }
import type { DigestAlgorithmName as _typeAlias_DigestAlgorithmName } from "jsr:@std/[email protected]"
/**
* An algorithm name supported by std/crypto.
*/
type DigestAlgorithmName = _typeAlias_DigestAlgorithmName
export type { DigestAlgorithmName }
import type { StdSubtleCrypto as _interface_StdSubtleCrypto } from "jsr:@std/[email protected]"
/**
* Extensions to the web standard `SubtleCrypto` interface.
*/
interface StdSubtleCrypto extends _interface_StdSubtleCrypto {}
export type { StdSubtleCrypto }
import type { StdCrypto as _interface_StdCrypto } from "jsr:@std/[email protected]"
/**
* Extensions to the Web {@linkcode Crypto} interface.
*/
interface StdCrypto extends _interface_StdCrypto {}
export type { StdCrypto }
import type { DigestAlgorithmObject as _typeAlias_DigestAlgorithmObject } from "jsr:@std/[email protected]"
/**
* Extended digest algorithm objects.
*/
type DigestAlgorithmObject = _typeAlias_DigestAlgorithmObject
export type { DigestAlgorithmObject }
import type { DigestAlgorithm as _typeAlias_DigestAlgorithm } from "jsr:@std/[email protected]"
/**
* Extended digest algorithms accepted by {@linkcode stdCrypto.subtle.digest}.
*
* The `length` option will be ignored for
* {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#algorithm | Web Standard algorithms}.
*/
type DigestAlgorithm = _typeAlias_DigestAlgorithm
export type { DigestAlgorithm }
import { crypto as _variable_crypto } from "jsr:@std/[email protected]"
/**
* An wrapper for WebCrypto adding support for additional non-standard
* algorithms, but delegating to the runtime WebCrypto implementation whenever
* possible.
*/
const crypto = _variable_crypto as typeof _variable_crypto
export { crypto }
import { timingSafeEqual as _function_timingSafeEqual } from "jsr:@std/[email protected]"
/**
* When checking the values of cryptographic hashes are equal, default
* comparisons can be susceptible to timing based attacks, where attacker is
* able to find out information about the host system by repeatedly checking
* response times to equality comparisons of values.
*
* It is likely some form of timing safe equality will make its way to the
* WebCrypto standard (see:
* {@link https://github.com/w3c/webcrypto/issues/270 | w3c/webcrypto#270}), but until
* that time, `timingSafeEqual()` is provided:
*
* @example Usage
* ```ts
* import { timingSafeEqual } from "@std/crypto/timing-safe-equal";
* import { assert } from "@std/assert";
*
* const a = await crypto.subtle.digest(
* "SHA-384",
* new TextEncoder().encode("hello world"),
* );
* const b = await crypto.subtle.digest(
* "SHA-384",
* new TextEncoder().encode("hello world"),
* );
*
* assert(timingSafeEqual(a, b));
* ```
*
* @param a The first value to compare.
* @param b The second value to compare.
* @return `true` if the values are equal, otherwise `false`.
*/
const timingSafeEqual = _function_timingSafeEqual as typeof _function_timingSafeEqual
export { timingSafeEqual }
|