@upstash/qstash 0.3.0 → 0.3.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 (47) hide show
  1. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/_util/asserts.js +0 -0
  2. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/fnv32.js +0 -0
  3. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/fnv64.js +0 -0
  4. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/index.js +0 -0
  5. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/util.js +0 -0
  6. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_wasm/lib/deno_std_wasm_crypto.generated.mjs +0 -0
  7. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_wasm/mod.js +0 -0
  8. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/keystack.js +1 -2
  9. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/mod.js +152 -2
  10. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/timing_safe_equal.js +0 -0
  11. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/util.js +0 -0
  12. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/base64.js +17 -0
  13. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/base64url.js +16 -0
  14. package/esm/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/hex.js +16 -0
  15. package/esm/pkg/receiver.js +1 -1
  16. package/package.json +1 -1
  17. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/_util/asserts.js +0 -0
  18. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/fnv32.js +0 -0
  19. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/fnv64.js +0 -0
  20. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/index.js +0 -0
  21. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/util.js +0 -0
  22. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_wasm/lib/deno_std_wasm_crypto.generated.mjs +0 -0
  23. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_wasm/mod.js +0 -0
  24. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/keystack.js +1 -2
  25. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/mod.js +152 -2
  26. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/timing_safe_equal.js +0 -0
  27. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/util.js +0 -0
  28. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/base64.js +17 -0
  29. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/base64url.js +16 -0
  30. package/script/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/hex.js +16 -0
  31. package/script/pkg/receiver.js +1 -1
  32. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/_util/asserts.d.ts +0 -0
  33. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/fnv32.d.ts +0 -0
  34. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/fnv64.d.ts +0 -0
  35. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/index.d.ts +0 -0
  36. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_fnv/util.d.ts +0 -0
  37. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_wasm/lib/deno_std_wasm_crypto.generated.d.mts +0 -0
  38. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/_wasm/mod.d.ts +0 -0
  39. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/keystack.d.ts +1 -2
  40. package/types/deps/deno.land/std@0.167.0/crypto/mod.d.ts +206 -0
  41. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/timing_safe_equal.d.ts +0 -0
  42. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/crypto/util.d.ts +0 -0
  43. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/base64.d.ts +0 -0
  44. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/base64url.d.ts +0 -0
  45. package/types/deps/deno.land/{std@0.164.0 → std@0.167.0}/encoding/hex.d.ts +0 -0
  46. package/types/pkg/receiver.d.ts +1 -1
  47. package/types/deps/deno.land/std@0.164.0/crypto/mod.d.ts +0 -56
@@ -68,8 +68,7 @@ async function compare(a, b) {
68
68
  *
69
69
  * This was inspired by [keygrip](https://github.com/crypto-utils/keygrip/).
70
70
  *
71
- * ### Example
72
- *
71
+ * @example
73
72
  * ```ts
74
73
  * import { KeyStack } from "https://deno.land/std@$STD_VERSION/crypto/keystack.ts";
75
74
  *
@@ -2,11 +2,12 @@
2
2
  /**
3
3
  * Extensions to the
4
4
  * [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
5
- * supporting additional encryption APIs.
5
+ * supporting additional encryption APIs, but also delegating to the built-in
6
+ * APIs when possible.
6
7
  *
7
8
  * Provides additional digest algorithms that are not part of the WebCrypto
8
9
  * standard as well as a `subtle.digest` and `subtle.digestSync` methods. It
9
- * also provide a `subtle.timingSafeEqual()` method to compare array buffers
10
+ * also provides a `subtle.timingSafeEqual()` method to compare array buffers
10
11
  * or data views in a way that isn't prone to timing based attacks.
11
12
  *
12
13
  * The "polyfill" delegates to `WebCrypto` where possible.
@@ -15,6 +16,155 @@
15
16
  * for managing rotatable keys for signing data to prevent tampering, like with
16
17
  * HTTP cookies.
17
18
  *
19
+ * ## Supported algorithms
20
+ *
21
+ * Here is a list of supported algorithms. If the algorithm name in WebCrypto
22
+ * and Wasm/Rust is the same, this library prefers to use algorithms that are
23
+ * supported by WebCrypto.
24
+ *
25
+ * WebCrypto
26
+ *
27
+ * ```ts
28
+ * // https://deno.land/std/crypto/mod.ts
29
+ * const webCryptoDigestAlgorithms = [
30
+ * "SHA-384",
31
+ * "SHA-256",
32
+ * "SHA-512",
33
+ * // insecure (length-extendable and collidable):
34
+ * "SHA-1",
35
+ * ] as const;
36
+ * ```
37
+ *
38
+ * Wasm/Rust
39
+ *
40
+ * ```ts
41
+ * // https://deno.land/std/_wasm_crypto/mod.ts
42
+ * export const digestAlgorithms = [
43
+ * "BLAKE2B-256",
44
+ * "BLAKE2B-384",
45
+ * "BLAKE2B",
46
+ * "BLAKE2S",
47
+ * "BLAKE3",
48
+ * "KECCAK-224",
49
+ * "KECCAK-256",
50
+ * "KECCAK-384",
51
+ * "KECCAK-512",
52
+ * "SHA-384",
53
+ * "SHA3-224",
54
+ * "SHA3-256",
55
+ * "SHA3-384",
56
+ * "SHA3-512",
57
+ * "SHAKE128",
58
+ * "SHAKE256",
59
+ * "TIGER",
60
+ * // insecure (length-extendable):
61
+ * "RIPEMD-160",
62
+ * "SHA-224",
63
+ * "SHA-256",
64
+ * "SHA-512",
65
+ * // insecure (collidable and length-extendable):
66
+ * "MD5",
67
+ * "SHA-1",
68
+ * ] as const;
69
+ * ```
70
+ *
71
+ * ## Timing safe comparison
72
+ *
73
+ * When checking the values of cryptographic hashes are equal, default
74
+ * comparisons can be susceptible to timing based attacks, where attacker is
75
+ * able to find out information about the host system by repeatedly checking
76
+ * response times to equality comparisons of values.
77
+ *
78
+ * It is likely some form of timing safe equality will make its way to the
79
+ * WebCrypto standard (see:
80
+ * [w3c/webcrypto#270](https://github.com/w3c/webcrypto/issues/270)), but until
81
+ * that time, `timingSafeEqual()` is provided:
82
+ *
83
+ * ```ts
84
+ * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
85
+ * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
86
+ *
87
+ * const a = await crypto.subtle.digest(
88
+ * "SHA-384",
89
+ * new TextEncoder().encode("hello world"),
90
+ * );
91
+ * const b = await crypto.subtle.digest(
92
+ * "SHA-384",
93
+ * new TextEncoder().encode("hello world"),
94
+ * );
95
+ * const c = await crypto.subtle.digest(
96
+ * "SHA-384",
97
+ * new TextEncoder().encode("hello deno"),
98
+ * );
99
+ *
100
+ * assert(crypto.subtle.timingSafeEqual(a, b));
101
+ * assert(!crypto.subtle.timingSafeEqual(a, c));
102
+ * ```
103
+ *
104
+ * In addition to the method being part of the `crypto.subtle` interface, it is
105
+ * also loadable directly:
106
+ *
107
+ * ```ts
108
+ * import { timingSafeEqual } from "https://deno.land/std@$STD_VERSION/crypto/timing_safe_equal.ts";
109
+ * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
110
+ *
111
+ * const a = await crypto.subtle.digest(
112
+ * "SHA-384",
113
+ * new TextEncoder().encode("hello world"),
114
+ * );
115
+ * const b = await crypto.subtle.digest(
116
+ * "SHA-384",
117
+ * new TextEncoder().encode("hello world"),
118
+ * );
119
+ *
120
+ * assert(timingSafeEqual(a, b));
121
+ * ```
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
126
+ *
127
+ * // This will delegate to the runtime's WebCrypto implementation.
128
+ * console.log(
129
+ * new Uint8Array(
130
+ * await crypto.subtle.digest(
131
+ * "SHA-384",
132
+ * new TextEncoder().encode("hello world"),
133
+ * ),
134
+ * ),
135
+ * );
136
+ *
137
+ * // This will use a bundled Wasm/Rust implementation.
138
+ * console.log(
139
+ * new Uint8Array(
140
+ * await crypto.subtle.digest(
141
+ * "BLAKE3",
142
+ * new TextEncoder().encode("hello world"),
143
+ * ),
144
+ * ),
145
+ * );
146
+ * ```
147
+ *
148
+ * @example Convert hash to a string
149
+ *
150
+ * ```ts
151
+ * import {
152
+ * crypto,
153
+ * toHashString,
154
+ * } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
155
+ *
156
+ * const hash = await crypto.subtle.digest(
157
+ * "SHA-384",
158
+ * new TextEncoder().encode("You hear that Mr. Anderson?"),
159
+ * );
160
+ *
161
+ * // Hex encoding by default
162
+ * console.log(toHashString(hash));
163
+ *
164
+ * // Or with base64 encoding
165
+ * console.log(toHashString(hash, "base64"));
166
+ * ```
167
+ *
18
168
  * @module
19
169
  */
20
170
  import * as dntShim from "../../../../_dnt.shims.js";
@@ -5,6 +5,23 @@
5
5
  *
6
6
  * This module is browser compatible.
7
7
  *
8
+ * @example
9
+ * ```ts
10
+ * import {
11
+ * decode,
12
+ * encode,
13
+ * } from "https://deno.land/std@$STD_VERSION/encoding/base64.ts";
14
+ *
15
+ * const b64Repr = "Zm9vYg==";
16
+ *
17
+ * const binaryData = decode(b64Repr);
18
+ * console.log(binaryData);
19
+ * // => Uint8Array [ 102, 111, 111, 98 ]
20
+ *
21
+ * console.log(encode(binaryData));
22
+ * // => Zm9vYg==
23
+ * ```
24
+ *
8
25
  * @module
9
26
  */
10
27
  const base64abc = [
@@ -5,6 +5,22 @@
5
5
  *
6
6
  * This module is browser compatible.
7
7
  *
8
+ * @example
9
+ * ```ts
10
+ * import {
11
+ * decode,
12
+ * encode,
13
+ * } from "https://deno.land/std@$STD_VERSION/encoding/base64url.ts";
14
+ *
15
+ * const binary = new TextEncoder().encode("foobar");
16
+ * const encoded = encode(binary);
17
+ * console.log(encoded);
18
+ * // => "Zm9vYmFy"
19
+ *
20
+ * console.log(decode(encoded));
21
+ * // => Uint8Array(6) [ 102, 111, 111, 98, 97, 114 ]
22
+ * ```
23
+ *
8
24
  * @module
9
25
  */
10
26
  import * as base64 from "./base64.js";
@@ -7,6 +7,22 @@
7
7
  *
8
8
  * This module is browser compatible.
9
9
  *
10
+ * @example
11
+ * ```ts
12
+ * import {
13
+ * decode,
14
+ * encode,
15
+ * } from "https://deno.land/std@$STD_VERSION/encoding/hex.ts";
16
+ *
17
+ * const binary = new TextEncoder().encode("abc");
18
+ * const encoded = encode(binary);
19
+ * console.log(encoded);
20
+ * // => Uint8Array(6) [ 54, 49, 54, 50, 54, 51 ]
21
+ *
22
+ * console.log(decode(encoded));
23
+ * // => Uint8Array(3) [ 97, 98, 99 ]
24
+ * ```
25
+ *
10
26
  * @module
11
27
  */
12
28
  const hexTable = new TextEncoder().encode("0123456789abcdef");
@@ -74,7 +74,7 @@ export class Receiver {
74
74
  console.log({ now, exp: p.exp });
75
75
  throw new SignatureError("token has expired");
76
76
  }
77
- if (now - (req.clockTolerance ?? 0) < p.nbf) {
77
+ if (now + (req.clockTolerance ?? 0) < p.nbf) {
78
78
  throw new SignatureError("token is not yet valid");
79
79
  }
80
80
  const bodyHash = await this.subtleCrypto.digest("SHA-256", typeof req.body === "string"
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/entrypoints/nodejs.js",
4
4
  "types": "./types/entrypoints/nodejs.d.ts",
5
5
  "name": "@upstash/qstash",
6
- "version": "v0.3.0",
6
+ "version": "v0.3.1",
7
7
  "description": "Official Deno/Typescript client for QStash",
8
8
  "repository": {
9
9
  "type": "git",
@@ -94,8 +94,7 @@ async function compare(a, b) {
94
94
  *
95
95
  * This was inspired by [keygrip](https://github.com/crypto-utils/keygrip/).
96
96
  *
97
- * ### Example
98
- *
97
+ * @example
99
98
  * ```ts
100
99
  * import { KeyStack } from "https://deno.land/std@$STD_VERSION/crypto/keystack.ts";
101
100
  *
@@ -28,11 +28,12 @@ exports.crypto = exports.toHashString = exports.KeyStack = void 0;
28
28
  /**
29
29
  * Extensions to the
30
30
  * [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
31
- * supporting additional encryption APIs.
31
+ * supporting additional encryption APIs, but also delegating to the built-in
32
+ * APIs when possible.
32
33
  *
33
34
  * Provides additional digest algorithms that are not part of the WebCrypto
34
35
  * standard as well as a `subtle.digest` and `subtle.digestSync` methods. It
35
- * also provide a `subtle.timingSafeEqual()` method to compare array buffers
36
+ * also provides a `subtle.timingSafeEqual()` method to compare array buffers
36
37
  * or data views in a way that isn't prone to timing based attacks.
37
38
  *
38
39
  * The "polyfill" delegates to `WebCrypto` where possible.
@@ -41,6 +42,155 @@ exports.crypto = exports.toHashString = exports.KeyStack = void 0;
41
42
  * for managing rotatable keys for signing data to prevent tampering, like with
42
43
  * HTTP cookies.
43
44
  *
45
+ * ## Supported algorithms
46
+ *
47
+ * Here is a list of supported algorithms. If the algorithm name in WebCrypto
48
+ * and Wasm/Rust is the same, this library prefers to use algorithms that are
49
+ * supported by WebCrypto.
50
+ *
51
+ * WebCrypto
52
+ *
53
+ * ```ts
54
+ * // https://deno.land/std/crypto/mod.ts
55
+ * const webCryptoDigestAlgorithms = [
56
+ * "SHA-384",
57
+ * "SHA-256",
58
+ * "SHA-512",
59
+ * // insecure (length-extendable and collidable):
60
+ * "SHA-1",
61
+ * ] as const;
62
+ * ```
63
+ *
64
+ * Wasm/Rust
65
+ *
66
+ * ```ts
67
+ * // https://deno.land/std/_wasm_crypto/mod.ts
68
+ * export const digestAlgorithms = [
69
+ * "BLAKE2B-256",
70
+ * "BLAKE2B-384",
71
+ * "BLAKE2B",
72
+ * "BLAKE2S",
73
+ * "BLAKE3",
74
+ * "KECCAK-224",
75
+ * "KECCAK-256",
76
+ * "KECCAK-384",
77
+ * "KECCAK-512",
78
+ * "SHA-384",
79
+ * "SHA3-224",
80
+ * "SHA3-256",
81
+ * "SHA3-384",
82
+ * "SHA3-512",
83
+ * "SHAKE128",
84
+ * "SHAKE256",
85
+ * "TIGER",
86
+ * // insecure (length-extendable):
87
+ * "RIPEMD-160",
88
+ * "SHA-224",
89
+ * "SHA-256",
90
+ * "SHA-512",
91
+ * // insecure (collidable and length-extendable):
92
+ * "MD5",
93
+ * "SHA-1",
94
+ * ] as const;
95
+ * ```
96
+ *
97
+ * ## Timing safe comparison
98
+ *
99
+ * When checking the values of cryptographic hashes are equal, default
100
+ * comparisons can be susceptible to timing based attacks, where attacker is
101
+ * able to find out information about the host system by repeatedly checking
102
+ * response times to equality comparisons of values.
103
+ *
104
+ * It is likely some form of timing safe equality will make its way to the
105
+ * WebCrypto standard (see:
106
+ * [w3c/webcrypto#270](https://github.com/w3c/webcrypto/issues/270)), but until
107
+ * that time, `timingSafeEqual()` is provided:
108
+ *
109
+ * ```ts
110
+ * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
111
+ * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
112
+ *
113
+ * const a = await crypto.subtle.digest(
114
+ * "SHA-384",
115
+ * new TextEncoder().encode("hello world"),
116
+ * );
117
+ * const b = await crypto.subtle.digest(
118
+ * "SHA-384",
119
+ * new TextEncoder().encode("hello world"),
120
+ * );
121
+ * const c = await crypto.subtle.digest(
122
+ * "SHA-384",
123
+ * new TextEncoder().encode("hello deno"),
124
+ * );
125
+ *
126
+ * assert(crypto.subtle.timingSafeEqual(a, b));
127
+ * assert(!crypto.subtle.timingSafeEqual(a, c));
128
+ * ```
129
+ *
130
+ * In addition to the method being part of the `crypto.subtle` interface, it is
131
+ * also loadable directly:
132
+ *
133
+ * ```ts
134
+ * import { timingSafeEqual } from "https://deno.land/std@$STD_VERSION/crypto/timing_safe_equal.ts";
135
+ * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
136
+ *
137
+ * const a = await crypto.subtle.digest(
138
+ * "SHA-384",
139
+ * new TextEncoder().encode("hello world"),
140
+ * );
141
+ * const b = await crypto.subtle.digest(
142
+ * "SHA-384",
143
+ * new TextEncoder().encode("hello world"),
144
+ * );
145
+ *
146
+ * assert(timingSafeEqual(a, b));
147
+ * ```
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
152
+ *
153
+ * // This will delegate to the runtime's WebCrypto implementation.
154
+ * console.log(
155
+ * new Uint8Array(
156
+ * await crypto.subtle.digest(
157
+ * "SHA-384",
158
+ * new TextEncoder().encode("hello world"),
159
+ * ),
160
+ * ),
161
+ * );
162
+ *
163
+ * // This will use a bundled Wasm/Rust implementation.
164
+ * console.log(
165
+ * new Uint8Array(
166
+ * await crypto.subtle.digest(
167
+ * "BLAKE3",
168
+ * new TextEncoder().encode("hello world"),
169
+ * ),
170
+ * ),
171
+ * );
172
+ * ```
173
+ *
174
+ * @example Convert hash to a string
175
+ *
176
+ * ```ts
177
+ * import {
178
+ * crypto,
179
+ * toHashString,
180
+ * } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
181
+ *
182
+ * const hash = await crypto.subtle.digest(
183
+ * "SHA-384",
184
+ * new TextEncoder().encode("You hear that Mr. Anderson?"),
185
+ * );
186
+ *
187
+ * // Hex encoding by default
188
+ * console.log(toHashString(hash));
189
+ *
190
+ * // Or with base64 encoding
191
+ * console.log(toHashString(hash, "base64"));
192
+ * ```
193
+ *
44
194
  * @module
45
195
  */
46
196
  const dntShim = __importStar(require("../../../../_dnt.shims.js"));
@@ -8,6 +8,23 @@ exports.decode = exports.encode = void 0;
8
8
  *
9
9
  * This module is browser compatible.
10
10
  *
11
+ * @example
12
+ * ```ts
13
+ * import {
14
+ * decode,
15
+ * encode,
16
+ * } from "https://deno.land/std@$STD_VERSION/encoding/base64.ts";
17
+ *
18
+ * const b64Repr = "Zm9vYg==";
19
+ *
20
+ * const binaryData = decode(b64Repr);
21
+ * console.log(binaryData);
22
+ * // => Uint8Array [ 102, 111, 111, 98 ]
23
+ *
24
+ * console.log(encode(binaryData));
25
+ * // => Zm9vYg==
26
+ * ```
27
+ *
11
28
  * @module
12
29
  */
13
30
  const base64abc = [
@@ -31,6 +31,22 @@ exports.decode = exports.encode = void 0;
31
31
  *
32
32
  * This module is browser compatible.
33
33
  *
34
+ * @example
35
+ * ```ts
36
+ * import {
37
+ * decode,
38
+ * encode,
39
+ * } from "https://deno.land/std@$STD_VERSION/encoding/base64url.ts";
40
+ *
41
+ * const binary = new TextEncoder().encode("foobar");
42
+ * const encoded = encode(binary);
43
+ * console.log(encoded);
44
+ * // => "Zm9vYmFy"
45
+ *
46
+ * console.log(decode(encoded));
47
+ * // => Uint8Array(6) [ 102, 111, 111, 98, 97, 114 ]
48
+ * ```
49
+ *
34
50
  * @module
35
51
  */
36
52
  const base64 = __importStar(require("./base64.js"));
@@ -10,6 +10,22 @@ exports.decode = exports.encode = void 0;
10
10
  *
11
11
  * This module is browser compatible.
12
12
  *
13
+ * @example
14
+ * ```ts
15
+ * import {
16
+ * decode,
17
+ * encode,
18
+ * } from "https://deno.land/std@$STD_VERSION/encoding/hex.ts";
19
+ *
20
+ * const binary = new TextEncoder().encode("abc");
21
+ * const encoded = encode(binary);
22
+ * console.log(encoded);
23
+ * // => Uint8Array(6) [ 54, 49, 54, 50, 54, 51 ]
24
+ *
25
+ * console.log(decode(encoded));
26
+ * // => Uint8Array(3) [ 97, 98, 99 ]
27
+ * ```
28
+ *
13
29
  * @module
14
30
  */
15
31
  const hexTable = new TextEncoder().encode("0123456789abcdef");
@@ -78,7 +78,7 @@ class Receiver {
78
78
  console.log({ now, exp: p.exp });
79
79
  throw new SignatureError("token has expired");
80
80
  }
81
- if (now - (req.clockTolerance ?? 0) < p.nbf) {
81
+ if (now + (req.clockTolerance ?? 0) < p.nbf) {
82
82
  throw new SignatureError("token is not yet valid");
83
83
  }
84
84
  const bodyHash = await this.subtleCrypto.digest("SHA-256", typeof req.body === "string"
@@ -9,8 +9,7 @@ export declare type Key = string | number[] | ArrayBuffer | Uint8Array;
9
9
  *
10
10
  * This was inspired by [keygrip](https://github.com/crypto-utils/keygrip/).
11
11
  *
12
- * ### Example
13
- *
12
+ * @example
14
13
  * ```ts
15
14
  * import { KeyStack } from "https://deno.land/std@$STD_VERSION/crypto/keystack.ts";
16
15
  *
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Extensions to the
3
+ * [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/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. It
9
+ * also provides a `subtle.timingSafeEqual()` method to compare array buffers
10
+ * or data views in a way that isn't prone to timing based attacks.
11
+ *
12
+ * The "polyfill" delegates to `WebCrypto` where possible.
13
+ *
14
+ * The {@linkcode KeyStack} export implements the {@linkcode KeyRing} interface
15
+ * for managing rotatable keys for signing data to prevent tampering, like with
16
+ * HTTP cookies.
17
+ *
18
+ * ## Supported algorithms
19
+ *
20
+ * Here is a list of supported algorithms. If the algorithm name in WebCrypto
21
+ * and Wasm/Rust is the same, this library prefers to use algorithms that are
22
+ * supported by WebCrypto.
23
+ *
24
+ * WebCrypto
25
+ *
26
+ * ```ts
27
+ * // https://deno.land/std/crypto/mod.ts
28
+ * const webCryptoDigestAlgorithms = [
29
+ * "SHA-384",
30
+ * "SHA-256",
31
+ * "SHA-512",
32
+ * // insecure (length-extendable and collidable):
33
+ * "SHA-1",
34
+ * ] as const;
35
+ * ```
36
+ *
37
+ * Wasm/Rust
38
+ *
39
+ * ```ts
40
+ * // https://deno.land/std/_wasm_crypto/mod.ts
41
+ * export const digestAlgorithms = [
42
+ * "BLAKE2B-256",
43
+ * "BLAKE2B-384",
44
+ * "BLAKE2B",
45
+ * "BLAKE2S",
46
+ * "BLAKE3",
47
+ * "KECCAK-224",
48
+ * "KECCAK-256",
49
+ * "KECCAK-384",
50
+ * "KECCAK-512",
51
+ * "SHA-384",
52
+ * "SHA3-224",
53
+ * "SHA3-256",
54
+ * "SHA3-384",
55
+ * "SHA3-512",
56
+ * "SHAKE128",
57
+ * "SHAKE256",
58
+ * "TIGER",
59
+ * // insecure (length-extendable):
60
+ * "RIPEMD-160",
61
+ * "SHA-224",
62
+ * "SHA-256",
63
+ * "SHA-512",
64
+ * // insecure (collidable and length-extendable):
65
+ * "MD5",
66
+ * "SHA-1",
67
+ * ] as const;
68
+ * ```
69
+ *
70
+ * ## Timing safe comparison
71
+ *
72
+ * When checking the values of cryptographic hashes are equal, default
73
+ * comparisons can be susceptible to timing based attacks, where attacker is
74
+ * able to find out information about the host system by repeatedly checking
75
+ * response times to equality comparisons of values.
76
+ *
77
+ * It is likely some form of timing safe equality will make its way to the
78
+ * WebCrypto standard (see:
79
+ * [w3c/webcrypto#270](https://github.com/w3c/webcrypto/issues/270)), but until
80
+ * that time, `timingSafeEqual()` is provided:
81
+ *
82
+ * ```ts
83
+ * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
84
+ * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
85
+ *
86
+ * const a = await crypto.subtle.digest(
87
+ * "SHA-384",
88
+ * new TextEncoder().encode("hello world"),
89
+ * );
90
+ * const b = await crypto.subtle.digest(
91
+ * "SHA-384",
92
+ * new TextEncoder().encode("hello world"),
93
+ * );
94
+ * const c = await crypto.subtle.digest(
95
+ * "SHA-384",
96
+ * new TextEncoder().encode("hello deno"),
97
+ * );
98
+ *
99
+ * assert(crypto.subtle.timingSafeEqual(a, b));
100
+ * assert(!crypto.subtle.timingSafeEqual(a, c));
101
+ * ```
102
+ *
103
+ * In addition to the method being part of the `crypto.subtle` interface, it is
104
+ * also loadable directly:
105
+ *
106
+ * ```ts
107
+ * import { timingSafeEqual } from "https://deno.land/std@$STD_VERSION/crypto/timing_safe_equal.ts";
108
+ * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
109
+ *
110
+ * const a = await crypto.subtle.digest(
111
+ * "SHA-384",
112
+ * new TextEncoder().encode("hello world"),
113
+ * );
114
+ * const b = await crypto.subtle.digest(
115
+ * "SHA-384",
116
+ * new TextEncoder().encode("hello world"),
117
+ * );
118
+ *
119
+ * assert(timingSafeEqual(a, b));
120
+ * ```
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
125
+ *
126
+ * // This will delegate to the runtime's WebCrypto implementation.
127
+ * console.log(
128
+ * new Uint8Array(
129
+ * await crypto.subtle.digest(
130
+ * "SHA-384",
131
+ * new TextEncoder().encode("hello world"),
132
+ * ),
133
+ * ),
134
+ * );
135
+ *
136
+ * // This will use a bundled Wasm/Rust implementation.
137
+ * console.log(
138
+ * new Uint8Array(
139
+ * await crypto.subtle.digest(
140
+ * "BLAKE3",
141
+ * new TextEncoder().encode("hello world"),
142
+ * ),
143
+ * ),
144
+ * );
145
+ * ```
146
+ *
147
+ * @example Convert hash to a string
148
+ *
149
+ * ```ts
150
+ * import {
151
+ * crypto,
152
+ * toHashString,
153
+ * } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
154
+ *
155
+ * const hash = await crypto.subtle.digest(
156
+ * "SHA-384",
157
+ * new TextEncoder().encode("You hear that Mr. Anderson?"),
158
+ * );
159
+ *
160
+ * // Hex encoding by default
161
+ * console.log(toHashString(hash));
162
+ *
163
+ * // Or with base64 encoding
164
+ * console.log(toHashString(hash, "base64"));
165
+ * ```
166
+ *
167
+ * @module
168
+ */
169
+ import * as dntShim from "../../../../_dnt.shims.js";
170
+ import { DigestAlgorithm as WasmDigestAlgorithm } from "./_wasm/mod.js";
171
+ export { type Data, type Key, KeyStack } from "./keystack.js";
172
+ export { toHashString } from "./util.js";
173
+ /** Extensions to the web standard `SubtleCrypto` interface. */
174
+ export interface StdSubtleCrypto extends dntShim.SubtleCrypto {
175
+ /**
176
+ * Returns a new `Promise` object that will digest `data` using the specified
177
+ * `AlgorithmIdentifier`.
178
+ */
179
+ digest(algorithm: DigestAlgorithm, data: dntShim.BufferSource | AsyncIterable<dntShim.BufferSource> | Iterable<dntShim.BufferSource>): Promise<ArrayBuffer>;
180
+ /**
181
+ * Returns a ArrayBuffer with the result of digesting `data` using the
182
+ * specified `AlgorithmIdentifier`.
183
+ */
184
+ digestSync(algorithm: DigestAlgorithm, data: dntShim.BufferSource | Iterable<dntShim.BufferSource>): ArrayBuffer;
185
+ /** Compare to array buffers or data views in a way that timing based attacks
186
+ * cannot gain information about the platform. */
187
+ timingSafeEqual(a: ArrayBufferLike | DataView, b: ArrayBufferLike | DataView): boolean;
188
+ }
189
+ /** Extensions to the Web {@linkcode Crypto} interface. */
190
+ export interface StdCrypto extends dntShim.Crypto {
191
+ readonly subtle: StdSubtleCrypto;
192
+ }
193
+ /**
194
+ * An wrapper for WebCrypto adding support for additional non-standard
195
+ * algorithms, but delegating to the runtime WebCrypto implementation whenever
196
+ * possible.
197
+ */
198
+ declare const stdCrypto: StdCrypto;
199
+ export declare type FNVAlgorithms = "FNV32" | "FNV32A" | "FNV64" | "FNV64A";
200
+ export declare type DigestAlgorithmName = WasmDigestAlgorithm | FNVAlgorithms;
201
+ export declare type DigestAlgorithmObject = {
202
+ name: DigestAlgorithmName;
203
+ length?: number;
204
+ };
205
+ export declare type DigestAlgorithm = DigestAlgorithmName | DigestAlgorithmObject;
206
+ export { stdCrypto as crypto };
@@ -1,4 +1,4 @@
1
- import { crypto } from "../deps/deno.land/std@0.164.0/crypto/mod.js";
1
+ import { crypto } from "../deps/deno.land/std@0.167.0/crypto/mod.js";
2
2
  export declare type SubtleCrypto = typeof crypto.subtle;
3
3
  /**
4
4
  * Necessary to verify the signature of a request.
@@ -1,56 +0,0 @@
1
- /**
2
- * Extensions to the
3
- * [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
4
- * supporting additional encryption APIs.
5
- *
6
- * Provides additional digest algorithms that are not part of the WebCrypto
7
- * standard as well as a `subtle.digest` and `subtle.digestSync` methods. It
8
- * also provide a `subtle.timingSafeEqual()` method to compare array buffers
9
- * or data views in a way that isn't prone to timing based attacks.
10
- *
11
- * The "polyfill" delegates to `WebCrypto` where possible.
12
- *
13
- * The {@linkcode KeyStack} export implements the {@linkcode KeyRing} interface
14
- * for managing rotatable keys for signing data to prevent tampering, like with
15
- * HTTP cookies.
16
- *
17
- * @module
18
- */
19
- import * as dntShim from "../../../../_dnt.shims.js";
20
- import { DigestAlgorithm as WasmDigestAlgorithm } from "./_wasm/mod.js";
21
- export { type Data, type Key, KeyStack } from "./keystack.js";
22
- export { toHashString } from "./util.js";
23
- /** Extensions to the web standard `SubtleCrypto` interface. */
24
- export interface StdSubtleCrypto extends dntShim.SubtleCrypto {
25
- /**
26
- * Returns a new `Promise` object that will digest `data` using the specified
27
- * `AlgorithmIdentifier`.
28
- */
29
- digest(algorithm: DigestAlgorithm, data: dntShim.BufferSource | AsyncIterable<dntShim.BufferSource> | Iterable<dntShim.BufferSource>): Promise<ArrayBuffer>;
30
- /**
31
- * Returns a ArrayBuffer with the result of digesting `data` using the
32
- * specified `AlgorithmIdentifier`.
33
- */
34
- digestSync(algorithm: DigestAlgorithm, data: dntShim.BufferSource | Iterable<dntShim.BufferSource>): ArrayBuffer;
35
- /** Compare to array buffers or data views in a way that timing based attacks
36
- * cannot gain information about the platform. */
37
- timingSafeEqual(a: ArrayBufferLike | DataView, b: ArrayBufferLike | DataView): boolean;
38
- }
39
- /** Extensions to the Web {@linkcode Crypto} interface. */
40
- export interface StdCrypto extends dntShim.Crypto {
41
- readonly subtle: StdSubtleCrypto;
42
- }
43
- /**
44
- * An wrapper for WebCrypto adding support for additional non-standard
45
- * algorithms, but delegating to the runtime WebCrypto implementation whenever
46
- * possible.
47
- */
48
- declare const stdCrypto: StdCrypto;
49
- export declare type FNVAlgorithms = "FNV32" | "FNV32A" | "FNV64" | "FNV64A";
50
- export declare type DigestAlgorithmName = WasmDigestAlgorithm | FNVAlgorithms;
51
- export declare type DigestAlgorithmObject = {
52
- name: DigestAlgorithmName;
53
- length?: number;
54
- };
55
- export declare type DigestAlgorithm = DigestAlgorithmName | DigestAlgorithmObject;
56
- export { stdCrypto as crypto };