@upstash/qstash 0.1.6 → 0.1.8
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 +9 -14
- package/esm/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/fnv32.js +0 -0
- package/esm/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/fnv64.js +0 -0
- package/esm/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/index.js +0 -0
- package/esm/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/util.js +0 -0
- package/esm/deps/deno.land/std@0.161.0/crypto/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +3253 -0
- package/esm/deps/deno.land/{std@0.149.0 → std@0.161.0/crypto}/_wasm_crypto/mod.js +0 -0
- package/esm/deps/deno.land/std@0.161.0/crypto/keystack.js +150 -0
- package/esm/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/mod.js +26 -8
- package/esm/deps/deno.land/std@0.161.0/crypto/timing_safe_equal.js +24 -0
- package/esm/deps/deno.land/std@0.161.0/crypto/util.js +27 -0
- package/esm/deps/deno.land/std@0.161.0/encoding/base64.js +122 -0
- package/esm/deps/deno.land/std@0.161.0/encoding/base64url.js +49 -0
- package/esm/deps/deno.land/std@0.161.0/encoding/hex.js +60 -0
- package/esm/deps/deno.land/std@0.161.0/fmt/colors.js +442 -0
- package/esm/deps/deno.land/std@0.161.0/testing/_diff.js +308 -0
- package/esm/deps/deno.land/std@0.161.0/testing/_format.js +23 -0
- package/esm/deps/deno.land/std@0.161.0/testing/asserts.js +615 -0
- package/esm/pkg/client/client.js +1 -1
- package/package.json +2 -2
- package/script/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/fnv32.js +0 -0
- package/script/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/fnv64.js +0 -0
- package/script/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/index.js +0 -0
- package/script/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/util.js +0 -0
- package/script/deps/deno.land/std@0.161.0/crypto/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +3261 -0
- package/script/deps/deno.land/{std@0.149.0 → std@0.161.0/crypto}/_wasm_crypto/mod.js +0 -0
- package/script/deps/deno.land/std@0.161.0/crypto/keystack.js +177 -0
- package/script/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/mod.js +30 -10
- package/script/deps/deno.land/std@0.161.0/crypto/timing_safe_equal.js +28 -0
- package/script/deps/deno.land/std@0.161.0/crypto/util.js +54 -0
- package/script/deps/deno.land/std@0.161.0/encoding/base64.js +127 -0
- package/script/deps/deno.land/std@0.161.0/encoding/base64url.js +77 -0
- package/script/deps/deno.land/std@0.161.0/encoding/hex.js +65 -0
- package/script/deps/deno.land/std@0.161.0/fmt/colors.js +516 -0
- package/script/deps/deno.land/std@0.161.0/testing/_diff.js +314 -0
- package/script/deps/deno.land/std@0.161.0/testing/_format.js +50 -0
- package/script/deps/deno.land/std@0.161.0/testing/asserts.js +641 -0
- package/script/pkg/client/client.js +1 -1
- package/types/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/fnv32.d.ts +0 -0
- package/types/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/fnv64.d.ts +0 -0
- package/types/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/index.d.ts +0 -0
- package/types/deps/deno.land/{std@0.149.0 → std@0.161.0}/crypto/_fnv/util.d.ts +0 -0
- package/types/deps/deno.land/{std@0.149.0 → std@0.161.0/crypto}/_wasm_crypto/lib/deno_std_wasm_crypto.generated.d.mts +0 -0
- package/types/deps/deno.land/{std@0.149.0 → std@0.161.0/crypto}/_wasm_crypto/mod.d.ts +0 -0
- package/types/deps/deno.land/std@0.161.0/crypto/keystack.d.ts +47 -0
- package/types/deps/deno.land/std@0.161.0/crypto/mod.d.ts +56 -0
- package/types/deps/deno.land/std@0.161.0/crypto/timing_safe_equal.d.ts +3 -0
- package/types/deps/deno.land/std@0.161.0/crypto/util.d.ts +16 -0
- package/types/deps/deno.land/std@0.161.0/encoding/base64.d.ts +11 -0
- package/types/deps/deno.land/std@0.161.0/encoding/base64url.d.ts +10 -0
- package/types/deps/deno.land/std@0.161.0/encoding/hex.d.ts +7 -0
- package/types/deps/deno.land/std@0.161.0/fmt/colors.d.ts +270 -0
- package/types/deps/deno.land/std@0.161.0/testing/_diff.d.ts +26 -0
- package/types/deps/deno.land/std@0.161.0/testing/_format.d.ts +1 -0
- package/types/deps/deno.land/std@0.161.0/testing/asserts.d.ts +160 -0
- package/types/pkg/client/messages.d.ts +1 -1
- package/types/pkg/receiver.d.ts +1 -1
- package/esm/deps/deno.land/std@0.149.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +0 -3159
- package/script/deps/deno.land/std@0.149.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs +0 -3167
- package/types/deps/deno.land/std@0.149.0/crypto/mod.d.ts +0 -53
|
File without changes
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
28
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
29
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
30
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
31
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
32
|
+
};
|
|
33
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
34
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
35
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
36
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
37
|
+
};
|
|
38
|
+
var _KeyStack_instances, _KeyStack_cryptoKeys, _KeyStack_keys, _KeyStack_toCryptoKey;
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.KeyStack = void 0;
|
|
41
|
+
/**
|
|
42
|
+
* Provides the {@linkcode KeyStack} class which implements the
|
|
43
|
+
* {@linkcode KeyRing} interface for managing rotatable keys.
|
|
44
|
+
*
|
|
45
|
+
* @module
|
|
46
|
+
*/
|
|
47
|
+
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
48
|
+
const timing_safe_equal_js_1 = require("./timing_safe_equal.js");
|
|
49
|
+
const base64url = __importStar(require("../encoding/base64url.js"));
|
|
50
|
+
const encoder = new TextEncoder();
|
|
51
|
+
function importKey(key) {
|
|
52
|
+
if (typeof key === "string") {
|
|
53
|
+
key = encoder.encode(key);
|
|
54
|
+
}
|
|
55
|
+
else if (Array.isArray(key)) {
|
|
56
|
+
key = new Uint8Array(key);
|
|
57
|
+
}
|
|
58
|
+
return dntShim.crypto.subtle.importKey("raw", key, {
|
|
59
|
+
name: "HMAC",
|
|
60
|
+
hash: { name: "SHA-256" },
|
|
61
|
+
}, true, ["sign", "verify"]);
|
|
62
|
+
}
|
|
63
|
+
function sign(data, key) {
|
|
64
|
+
if (typeof data === "string") {
|
|
65
|
+
data = encoder.encode(data);
|
|
66
|
+
}
|
|
67
|
+
else if (Array.isArray(data)) {
|
|
68
|
+
data = Uint8Array.from(data);
|
|
69
|
+
}
|
|
70
|
+
return dntShim.crypto.subtle.sign("HMAC", key, data);
|
|
71
|
+
}
|
|
72
|
+
/** Compare two strings, Uint8Arrays, ArrayBuffers, or arrays of numbers in a
|
|
73
|
+
* way that avoids timing based attacks on the comparisons on the values.
|
|
74
|
+
*
|
|
75
|
+
* The function will return `true` if the values match, or `false`, if they
|
|
76
|
+
* do not match.
|
|
77
|
+
*
|
|
78
|
+
* This was inspired by https://github.com/suryagh/tsscmp which provides a
|
|
79
|
+
* timing safe string comparison to avoid timing attacks as described in
|
|
80
|
+
* https://codahale.com/a-lesson-in-timing-attacks/.
|
|
81
|
+
*/
|
|
82
|
+
async function compare(a, b) {
|
|
83
|
+
const key = new Uint8Array(32);
|
|
84
|
+
dntShim.dntGlobalThis.crypto.getRandomValues(key);
|
|
85
|
+
const cryptoKey = await importKey(key);
|
|
86
|
+
const ah = await sign(a, cryptoKey);
|
|
87
|
+
const bh = await sign(b, cryptoKey);
|
|
88
|
+
return (0, timing_safe_equal_js_1.timingSafeEqual)(ah, bh);
|
|
89
|
+
}
|
|
90
|
+
/** A cryptographic key chain which allows signing of data to prevent tampering,
|
|
91
|
+
* but also allows for easy key rotation without needing to re-sign the data.
|
|
92
|
+
*
|
|
93
|
+
* Data is signed as SHA256 HMAC.
|
|
94
|
+
*
|
|
95
|
+
* This was inspired by [keygrip](https://github.com/crypto-utils/keygrip/).
|
|
96
|
+
*
|
|
97
|
+
* ### Example
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { KeyStack } from "https://deno.land/std@$STD_VERSION/crypto/keystack.ts";
|
|
101
|
+
*
|
|
102
|
+
* const keyStack = new KeyStack(["hello", "world"]);
|
|
103
|
+
* const digest = await keyStack.sign("some data");
|
|
104
|
+
*
|
|
105
|
+
* const rotatedStack = new KeyStack(["deno", "says", "hello", "world"]);
|
|
106
|
+
* await rotatedStack.verify("some data", digest); // true
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
class KeyStack {
|
|
110
|
+
/** A class which accepts an array of keys that are used to sign and verify
|
|
111
|
+
* data and allows easy key rotation without invalidation of previously signed
|
|
112
|
+
* data.
|
|
113
|
+
*
|
|
114
|
+
* @param keys An iterable of keys, of which the index 0 will be used to sign
|
|
115
|
+
* data, but verification can happen against any key.
|
|
116
|
+
*/
|
|
117
|
+
constructor(keys) {
|
|
118
|
+
_KeyStack_instances.add(this);
|
|
119
|
+
_KeyStack_cryptoKeys.set(this, new Map());
|
|
120
|
+
_KeyStack_keys.set(this, void 0);
|
|
121
|
+
const values = Array.isArray(keys) ? keys : [...keys];
|
|
122
|
+
if (!(values.length)) {
|
|
123
|
+
throw new TypeError("keys must contain at least one value");
|
|
124
|
+
}
|
|
125
|
+
__classPrivateFieldSet(this, _KeyStack_keys, values, "f");
|
|
126
|
+
}
|
|
127
|
+
get length() {
|
|
128
|
+
return __classPrivateFieldGet(this, _KeyStack_keys, "f").length;
|
|
129
|
+
}
|
|
130
|
+
/** Take `data` and return a SHA256 HMAC digest that uses the current 0 index
|
|
131
|
+
* of the `keys` passed to the constructor. This digest is in the form of a
|
|
132
|
+
* URL safe base64 encoded string. */
|
|
133
|
+
async sign(data) {
|
|
134
|
+
const key = await __classPrivateFieldGet(this, _KeyStack_instances, "m", _KeyStack_toCryptoKey).call(this, __classPrivateFieldGet(this, _KeyStack_keys, "f")[0]);
|
|
135
|
+
return base64url.encode(await sign(data, key));
|
|
136
|
+
}
|
|
137
|
+
/** Given `data` and a `digest`, verify that one of the `keys` provided the
|
|
138
|
+
* constructor was used to generate the `digest`. Returns `true` if one of
|
|
139
|
+
* the keys was used, otherwise `false`. */
|
|
140
|
+
async verify(data, digest) {
|
|
141
|
+
return (await this.indexOf(data, digest)) > -1;
|
|
142
|
+
}
|
|
143
|
+
/** Given `data` and a `digest`, return the current index of the key in the
|
|
144
|
+
* `keys` passed the constructor that was used to generate the digest. If no
|
|
145
|
+
* key can be found, the method returns `-1`. */
|
|
146
|
+
async indexOf(data, digest) {
|
|
147
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _KeyStack_keys, "f").length; i++) {
|
|
148
|
+
const cryptoKey = await __classPrivateFieldGet(this, _KeyStack_instances, "m", _KeyStack_toCryptoKey).call(this, __classPrivateFieldGet(this, _KeyStack_keys, "f")[i]);
|
|
149
|
+
if (await compare(digest, base64url.encode(await sign(data, cryptoKey)))) {
|
|
150
|
+
return i;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return -1;
|
|
154
|
+
}
|
|
155
|
+
[(_KeyStack_cryptoKeys = new WeakMap(), _KeyStack_keys = new WeakMap(), _KeyStack_instances = new WeakSet(), _KeyStack_toCryptoKey = async function _KeyStack_toCryptoKey(key) {
|
|
156
|
+
if (!__classPrivateFieldGet(this, _KeyStack_cryptoKeys, "f").has(key)) {
|
|
157
|
+
__classPrivateFieldGet(this, _KeyStack_cryptoKeys, "f").set(key, await importKey(key));
|
|
158
|
+
}
|
|
159
|
+
return __classPrivateFieldGet(this, _KeyStack_cryptoKeys, "f").get(key);
|
|
160
|
+
}, Symbol.for("Deno.customInspect"))](inspect) {
|
|
161
|
+
const { length } = this;
|
|
162
|
+
return `${this.constructor.name} ${inspect({ length })}`;
|
|
163
|
+
}
|
|
164
|
+
[Symbol.for("nodejs.util.inspect.custom")](depth,
|
|
165
|
+
// deno-lint-ignore no-explicit-any
|
|
166
|
+
options, inspect) {
|
|
167
|
+
if (depth < 0) {
|
|
168
|
+
return options.stylize(`[${this.constructor.name}]`, "special");
|
|
169
|
+
}
|
|
170
|
+
const newOptions = Object.assign({}, options, {
|
|
171
|
+
depth: options.depth === null ? null : options.depth - 1,
|
|
172
|
+
});
|
|
173
|
+
const { length } = this;
|
|
174
|
+
return `${options.stylize(this.constructor.name, "special")} ${inspect({ length }, newOptions)}`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.KeyStack = KeyStack;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
2
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
4
|
if (k2 === undefined) k2 = k;
|
|
4
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -23,15 +24,36 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
24
|
return result;
|
|
24
25
|
};
|
|
25
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.crypto = void 0;
|
|
27
|
-
|
|
27
|
+
exports.crypto = exports.toHashString = exports.KeyStack = void 0;
|
|
28
|
+
/**
|
|
29
|
+
* Extensions to the
|
|
30
|
+
* [Web Crypto](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
|
|
31
|
+
* supporting additional encryption APIs.
|
|
32
|
+
*
|
|
33
|
+
* Provides additional digest algorithms that are not part of the WebCrypto
|
|
34
|
+
* standard as well as a `subtle.digest` and `subtle.digestSync` methods. It
|
|
35
|
+
* also provide a `subtle.timingSafeEqual()` method to compare array buffers
|
|
36
|
+
* or data views in a way that isn't prone to timing based attacks.
|
|
37
|
+
*
|
|
38
|
+
* The "polyfill" delegates to `WebCrypto` where possible.
|
|
39
|
+
*
|
|
40
|
+
* The {@linkcode KeyStack} export implements the {@linkcode KeyRing} interface
|
|
41
|
+
* for managing rotatable keys for signing data to prevent tampering, like with
|
|
42
|
+
* HTTP cookies.
|
|
43
|
+
*
|
|
44
|
+
* @module
|
|
45
|
+
*/
|
|
28
46
|
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
29
|
-
const mod_js_1 = require("
|
|
47
|
+
const mod_js_1 = require("./_wasm_crypto/mod.js");
|
|
48
|
+
const timing_safe_equal_js_1 = require("./timing_safe_equal.js");
|
|
30
49
|
const index_js_1 = require("./_fnv/index.js");
|
|
50
|
+
var keystack_js_1 = require("./keystack.js");
|
|
51
|
+
Object.defineProperty(exports, "KeyStack", { enumerable: true, get: function () { return keystack_js_1.KeyStack; } });
|
|
52
|
+
var util_js_1 = require("./util.js");
|
|
53
|
+
Object.defineProperty(exports, "toHashString", { enumerable: true, get: function () { return util_js_1.toHashString; } });
|
|
31
54
|
/**
|
|
32
55
|
* A copy of the global WebCrypto interface, with methods bound so they're
|
|
33
56
|
* safe to re-export.
|
|
34
|
-
* @module
|
|
35
57
|
*/
|
|
36
58
|
const webCrypto = ((crypto) => ({
|
|
37
59
|
getRandomValues: crypto.getRandomValues?.bind(crypto),
|
|
@@ -74,8 +96,8 @@ const stdCrypto = ((x) => x)({
|
|
|
74
96
|
subtle: {
|
|
75
97
|
...webCrypto.subtle,
|
|
76
98
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
99
|
+
* Polyfills stream support until the Web Crypto API does so:
|
|
100
|
+
* @see {@link https://github.com/wintercg/proposal-webcrypto-streams}
|
|
79
101
|
*/
|
|
80
102
|
async digest(algorithm, data) {
|
|
81
103
|
const { name, length } = normalizeAlgorithm(algorithm);
|
|
@@ -127,10 +149,6 @@ const stdCrypto = ((x) => x)({
|
|
|
127
149
|
throw new TypeError(`unsupported digest algorithm: ${algorithm}`);
|
|
128
150
|
}
|
|
129
151
|
},
|
|
130
|
-
/**
|
|
131
|
-
* Returns a ArrayBuffer with the result of digesting `data` using the
|
|
132
|
-
* specified `AlgorithmIdentifier`.
|
|
133
|
-
*/
|
|
134
152
|
digestSync(algorithm, data) {
|
|
135
153
|
algorithm = normalizeAlgorithm(algorithm);
|
|
136
154
|
const bytes = bufferSourceBytes(data);
|
|
@@ -157,6 +175,8 @@ const stdCrypto = ((x) => x)({
|
|
|
157
175
|
throw new TypeError("data must be a BufferSource or Iterable<BufferSource>");
|
|
158
176
|
}
|
|
159
177
|
},
|
|
178
|
+
// TODO(@kitsonk): rework when https://github.com/w3c/webcrypto/issues/270 resolved
|
|
179
|
+
timingSafeEqual: timing_safe_equal_js_1.timingSafeEqual,
|
|
160
180
|
},
|
|
161
181
|
});
|
|
162
182
|
exports.crypto = stdCrypto;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.timingSafeEqual = void 0;
|
|
5
|
+
const asserts_js_1 = require("../testing/asserts.js");
|
|
6
|
+
/** Compare to array buffers or data views in a way that timing based attacks
|
|
7
|
+
* cannot gain information about the platform. */
|
|
8
|
+
function timingSafeEqual(a, b) {
|
|
9
|
+
if (a.byteLength !== b.byteLength) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (!(a instanceof DataView)) {
|
|
13
|
+
a = new DataView(ArrayBuffer.isView(a) ? a.buffer : a);
|
|
14
|
+
}
|
|
15
|
+
if (!(b instanceof DataView)) {
|
|
16
|
+
b = new DataView(ArrayBuffer.isView(b) ? b.buffer : b);
|
|
17
|
+
}
|
|
18
|
+
(0, asserts_js_1.assert)(a instanceof DataView);
|
|
19
|
+
(0, asserts_js_1.assert)(b instanceof DataView);
|
|
20
|
+
const length = a.byteLength;
|
|
21
|
+
let out = 0;
|
|
22
|
+
let i = -1;
|
|
23
|
+
while (++i < length) {
|
|
24
|
+
out |= a.getUint8(i) ^ b.getUint8(i);
|
|
25
|
+
}
|
|
26
|
+
return out === 0;
|
|
27
|
+
}
|
|
28
|
+
exports.timingSafeEqual = timingSafeEqual;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.toHashString = void 0;
|
|
27
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
28
|
+
const hex = __importStar(require("../encoding/hex.js"));
|
|
29
|
+
const base64 = __importStar(require("../encoding/base64.js"));
|
|
30
|
+
const decoder = new TextDecoder();
|
|
31
|
+
/**
|
|
32
|
+
* Converts a hash to a string with a given encoding.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { crypto, toHashString } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts";
|
|
36
|
+
*
|
|
37
|
+
* const hash = await crypto.subtle.digest("SHA-384", new TextEncoder().encode("You hear that Mr. Anderson?"));
|
|
38
|
+
*
|
|
39
|
+
* // Hex encoding by default
|
|
40
|
+
* console.log(toHashString(hash));
|
|
41
|
+
*
|
|
42
|
+
* // Or with base64 encoding
|
|
43
|
+
* console.log(toHashString(hash, "base64"));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function toHashString(hash, encoding = "hex") {
|
|
47
|
+
switch (encoding) {
|
|
48
|
+
case "hex":
|
|
49
|
+
return decoder.decode(hex.encode(new Uint8Array(hash)));
|
|
50
|
+
case "base64":
|
|
51
|
+
return base64.encode(hash);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.toHashString = toHashString;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.decode = exports.encode = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* {@linkcode encode} and {@linkcode decode} for
|
|
7
|
+
* [base64](https://en.wikipedia.org/wiki/Base64) encoding.
|
|
8
|
+
*
|
|
9
|
+
* This module is browser compatible.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
const base64abc = [
|
|
14
|
+
"A",
|
|
15
|
+
"B",
|
|
16
|
+
"C",
|
|
17
|
+
"D",
|
|
18
|
+
"E",
|
|
19
|
+
"F",
|
|
20
|
+
"G",
|
|
21
|
+
"H",
|
|
22
|
+
"I",
|
|
23
|
+
"J",
|
|
24
|
+
"K",
|
|
25
|
+
"L",
|
|
26
|
+
"M",
|
|
27
|
+
"N",
|
|
28
|
+
"O",
|
|
29
|
+
"P",
|
|
30
|
+
"Q",
|
|
31
|
+
"R",
|
|
32
|
+
"S",
|
|
33
|
+
"T",
|
|
34
|
+
"U",
|
|
35
|
+
"V",
|
|
36
|
+
"W",
|
|
37
|
+
"X",
|
|
38
|
+
"Y",
|
|
39
|
+
"Z",
|
|
40
|
+
"a",
|
|
41
|
+
"b",
|
|
42
|
+
"c",
|
|
43
|
+
"d",
|
|
44
|
+
"e",
|
|
45
|
+
"f",
|
|
46
|
+
"g",
|
|
47
|
+
"h",
|
|
48
|
+
"i",
|
|
49
|
+
"j",
|
|
50
|
+
"k",
|
|
51
|
+
"l",
|
|
52
|
+
"m",
|
|
53
|
+
"n",
|
|
54
|
+
"o",
|
|
55
|
+
"p",
|
|
56
|
+
"q",
|
|
57
|
+
"r",
|
|
58
|
+
"s",
|
|
59
|
+
"t",
|
|
60
|
+
"u",
|
|
61
|
+
"v",
|
|
62
|
+
"w",
|
|
63
|
+
"x",
|
|
64
|
+
"y",
|
|
65
|
+
"z",
|
|
66
|
+
"0",
|
|
67
|
+
"1",
|
|
68
|
+
"2",
|
|
69
|
+
"3",
|
|
70
|
+
"4",
|
|
71
|
+
"5",
|
|
72
|
+
"6",
|
|
73
|
+
"7",
|
|
74
|
+
"8",
|
|
75
|
+
"9",
|
|
76
|
+
"+",
|
|
77
|
+
"/",
|
|
78
|
+
];
|
|
79
|
+
/**
|
|
80
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
81
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
82
|
+
* @param data
|
|
83
|
+
*/
|
|
84
|
+
function encode(data) {
|
|
85
|
+
const uint8 = typeof data === "string"
|
|
86
|
+
? new TextEncoder().encode(data)
|
|
87
|
+
: data instanceof Uint8Array
|
|
88
|
+
? data
|
|
89
|
+
: new Uint8Array(data);
|
|
90
|
+
let result = "", i;
|
|
91
|
+
const l = uint8.length;
|
|
92
|
+
for (i = 2; i < l; i += 3) {
|
|
93
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
94
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
95
|
+
result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
96
|
+
result += base64abc[uint8[i] & 0x3f];
|
|
97
|
+
}
|
|
98
|
+
if (i === l + 1) {
|
|
99
|
+
// 1 octet yet to write
|
|
100
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
101
|
+
result += base64abc[(uint8[i - 2] & 0x03) << 4];
|
|
102
|
+
result += "==";
|
|
103
|
+
}
|
|
104
|
+
if (i === l) {
|
|
105
|
+
// 2 octets yet to write
|
|
106
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
107
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
108
|
+
result += base64abc[(uint8[i - 1] & 0x0f) << 2];
|
|
109
|
+
result += "=";
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
exports.encode = encode;
|
|
114
|
+
/**
|
|
115
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
116
|
+
* @param b64
|
|
117
|
+
*/
|
|
118
|
+
function decode(b64) {
|
|
119
|
+
const binString = atob(b64);
|
|
120
|
+
const size = binString.length;
|
|
121
|
+
const bytes = new Uint8Array(size);
|
|
122
|
+
for (let i = 0; i < size; i++) {
|
|
123
|
+
bytes[i] = binString.charCodeAt(i);
|
|
124
|
+
}
|
|
125
|
+
return bytes;
|
|
126
|
+
}
|
|
127
|
+
exports.decode = decode;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.decode = exports.encode = void 0;
|
|
28
|
+
/**
|
|
29
|
+
* {@linkcode encode} and {@linkcode decode} for
|
|
30
|
+
* [base64 URL safe](https://en.wikipedia.org/wiki/Base64#URL_applications) encoding.
|
|
31
|
+
*
|
|
32
|
+
* This module is browser compatible.
|
|
33
|
+
*
|
|
34
|
+
* @module
|
|
35
|
+
*/
|
|
36
|
+
const base64 = __importStar(require("./base64.js"));
|
|
37
|
+
/*
|
|
38
|
+
* Some variants allow or require omitting the padding '=' signs:
|
|
39
|
+
* https://en.wikipedia.org/wiki/Base64#The_URL_applications
|
|
40
|
+
* @param base64url
|
|
41
|
+
*/
|
|
42
|
+
function addPaddingToBase64url(base64url) {
|
|
43
|
+
if (base64url.length % 4 === 2)
|
|
44
|
+
return base64url + "==";
|
|
45
|
+
if (base64url.length % 4 === 3)
|
|
46
|
+
return base64url + "=";
|
|
47
|
+
if (base64url.length % 4 === 1) {
|
|
48
|
+
throw new TypeError("Illegal base64url string!");
|
|
49
|
+
}
|
|
50
|
+
return base64url;
|
|
51
|
+
}
|
|
52
|
+
function convertBase64urlToBase64(b64url) {
|
|
53
|
+
if (!/^[-_A-Z0-9]*?={0,2}$/i.test(b64url)) {
|
|
54
|
+
// Contains characters not part of base64url spec.
|
|
55
|
+
throw new TypeError("Failed to decode base64url: invalid character");
|
|
56
|
+
}
|
|
57
|
+
return addPaddingToBase64url(b64url).replace(/\-/g, "+").replace(/_/g, "/");
|
|
58
|
+
}
|
|
59
|
+
function convertBase64ToBase64url(b64) {
|
|
60
|
+
return b64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Encodes a given ArrayBuffer or string into a base64url representation
|
|
64
|
+
* @param data
|
|
65
|
+
*/
|
|
66
|
+
function encode(data) {
|
|
67
|
+
return convertBase64ToBase64url(base64.encode(data));
|
|
68
|
+
}
|
|
69
|
+
exports.encode = encode;
|
|
70
|
+
/**
|
|
71
|
+
* Converts given base64url encoded data back to original
|
|
72
|
+
* @param b64url
|
|
73
|
+
*/
|
|
74
|
+
function decode(b64url) {
|
|
75
|
+
return base64.decode(convertBase64urlToBase64(b64url));
|
|
76
|
+
}
|
|
77
|
+
exports.decode = decode;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2009 The Go Authors. All rights reserved.
|
|
3
|
+
// https://github.com/golang/go/blob/master/LICENSE
|
|
4
|
+
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decode = exports.encode = void 0;
|
|
7
|
+
/** Port of the Go
|
|
8
|
+
* [encoding/hex](https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go)
|
|
9
|
+
* library.
|
|
10
|
+
*
|
|
11
|
+
* This module is browser compatible.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
const hexTable = new TextEncoder().encode("0123456789abcdef");
|
|
16
|
+
function errInvalidByte(byte) {
|
|
17
|
+
return new TypeError(`Invalid byte '${String.fromCharCode(byte)}'`);
|
|
18
|
+
}
|
|
19
|
+
function errLength() {
|
|
20
|
+
return new RangeError("Odd length hex string");
|
|
21
|
+
}
|
|
22
|
+
/** Converts a hex character into its value. */
|
|
23
|
+
function fromHexChar(byte) {
|
|
24
|
+
// '0' <= byte && byte <= '9'
|
|
25
|
+
if (48 <= byte && byte <= 57)
|
|
26
|
+
return byte - 48;
|
|
27
|
+
// 'a' <= byte && byte <= 'f'
|
|
28
|
+
if (97 <= byte && byte <= 102)
|
|
29
|
+
return byte - 97 + 10;
|
|
30
|
+
// 'A' <= byte && byte <= 'F'
|
|
31
|
+
if (65 <= byte && byte <= 70)
|
|
32
|
+
return byte - 65 + 10;
|
|
33
|
+
throw errInvalidByte(byte);
|
|
34
|
+
}
|
|
35
|
+
/** Encodes `src` into `src.length * 2` bytes. */
|
|
36
|
+
function encode(src) {
|
|
37
|
+
const dst = new Uint8Array(src.length * 2);
|
|
38
|
+
for (let i = 0; i < dst.length; i++) {
|
|
39
|
+
const v = src[i];
|
|
40
|
+
dst[i * 2] = hexTable[v >> 4];
|
|
41
|
+
dst[i * 2 + 1] = hexTable[v & 0x0f];
|
|
42
|
+
}
|
|
43
|
+
return dst;
|
|
44
|
+
}
|
|
45
|
+
exports.encode = encode;
|
|
46
|
+
/**
|
|
47
|
+
* Decodes `src` into `src.length / 2` bytes.
|
|
48
|
+
* If the input is malformed, an error will be thrown.
|
|
49
|
+
*/
|
|
50
|
+
function decode(src) {
|
|
51
|
+
const dst = new Uint8Array(src.length / 2);
|
|
52
|
+
for (let i = 0; i < dst.length; i++) {
|
|
53
|
+
const a = fromHexChar(src[i * 2]);
|
|
54
|
+
const b = fromHexChar(src[i * 2 + 1]);
|
|
55
|
+
dst[i] = (a << 4) | b;
|
|
56
|
+
}
|
|
57
|
+
if (src.length % 2 == 1) {
|
|
58
|
+
// Check for invalid char before reporting bad length,
|
|
59
|
+
// since the invalid char (if present) is an earlier problem.
|
|
60
|
+
fromHexChar(src[dst.length * 2]);
|
|
61
|
+
throw errLength();
|
|
62
|
+
}
|
|
63
|
+
return dst;
|
|
64
|
+
}
|
|
65
|
+
exports.decode = decode;
|