From b61032ed4a20f846d93384a95425572d3cb1c791 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 16 Oct 2023 15:35:48 -0700 Subject: [PATCH] add signer id --- vls-mqtt/app/src/signerUtils.ts | 11 ++++++++++- vls-mqtt/app/src/store.ts | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/vls-mqtt/app/src/signerUtils.ts b/vls-mqtt/app/src/signerUtils.ts index 9a6f68d..b89fdc5 100644 --- a/vls-mqtt/app/src/signerUtils.ts +++ b/vls-mqtt/app/src/signerUtils.ts @@ -1,6 +1,13 @@ import * as localforage from "localforage"; import * as msgpack from "@msgpack/msgpack"; -import { type Policy, seed, lss_nonce, policy, allowlist } from "./store"; +import { + type Policy, + seed, + lss_nonce, + signer_id, + policy, + allowlist, +} from "./store"; import { get } from "svelte/store"; // store state mutations in IndexedDB @@ -19,6 +26,7 @@ export interface Args { allowlist: string[]; timestamp: number; // unix ts in seconds lss_nonce: Uint8Array; + signer_id: Uint8Array; } export enum Topics { @@ -87,6 +95,7 @@ function makeArgs(): Args { allowlist: get(allowlist), timestamp: now(), lss_nonce: fromHexString(get(lss_nonce)), + signer_id: fromHexString(get(signer_id)), }; } diff --git a/vls-mqtt/app/src/store.ts b/vls-mqtt/app/src/store.ts index 3a83843..b6de76a 100644 --- a/vls-mqtt/app/src/store.ts +++ b/vls-mqtt/app/src/store.ts @@ -62,6 +62,15 @@ export const gen32Nonce = (): string => { ).join(""); }; +export const gen16Id = (): string => { + return Array.from( + window.crypto.getRandomValues(new Uint8Array(16)), + (byte) => { + return ("0" + (byte & 0xff).toString(16)).slice(-2); + } + ).join(""); +}; + export const entropy = localStorageStore("entropy", genEntropy()); export const seed = derived([loaded, entropy], ([$loaded, $entropy]) => { @@ -75,6 +84,8 @@ export const seed = derived([loaded, entropy], ([$loaded, $entropy]) => { export const lss_nonce = writable(gen32Nonce()); +export const signer_id = writable(gen16Id()); + export const keys = derived([loaded, seed], ([$loaded, $seed]) => { if (!$loaded) return null; if (!$seed) return null;