fixup! feat(speech): the speech capability over Cap'n Web, behind a gate
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
This commit is contained in:
1 parent
372f6a2b96
commit
a97ba6c174
12 files changed
+245
-92
No files matched your search
+24
-13
@@ -10,18 +10,29 @@ import { createHash, timingSafeEqual } from 'node:crypto';
|
||||
const digest = (s) => createHash('sha256').update(String(s)).digest();
|
||||
|
||||
/**
|
||||
* @param {string} key unguessable, from a credential file
|
||||
* @param {object} cap what open(key) hands out
|
||||
* @template T
|
||||
*/
|
||||
export const makeGate = (key, cap) => {
|
||||
const want = digest(key);
|
||||
class Gate extends RpcTarget {
|
||||
/** @param {string} k */
|
||||
open(k) {
|
||||
// Digests are the same length whatever k is, so the comparison takes the same time.
|
||||
if (!timingSafeEqual(digest(k), want)) throw new Error('no such key');
|
||||
return cap;
|
||||
}
|
||||
export class Gate extends RpcTarget {
|
||||
#want;
|
||||
#cap;
|
||||
|
||||
/**
|
||||
* @param {string} key unguessable, from a credential file
|
||||
* @param {T} cap what open(key) hands out
|
||||
*/
|
||||
constructor(key, cap) {
|
||||
super();
|
||||
this.#want = digest(key);
|
||||
this.#cap = cap;
|
||||
}
|
||||
return new Gate();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} k
|
||||
* @returns {T}
|
||||
*/
|
||||
open(k) {
|
||||
// Digests are the same length whatever k is, so the comparison takes the same time.
|
||||
if (!timingSafeEqual(digest(k), this.#want)) throw new Error('no such key');
|
||||
return this.#cap;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user