Skip to content

Commit

Permalink
add signer id
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 16, 2023
1 parent 0af5ec6 commit b61032e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion vls-mqtt/app/src/signerUtils.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +26,7 @@ export interface Args {
allowlist: string[];
timestamp: number; // unix ts in seconds
lss_nonce: Uint8Array;
signer_id: Uint8Array;
}

export enum Topics {
Expand Down Expand Up @@ -87,6 +95,7 @@ function makeArgs(): Args {
allowlist: get(allowlist),
timestamp: now(),
lss_nonce: fromHexString(get(lss_nonce)),
signer_id: fromHexString(get(signer_id)),
};
}

Expand Down
11 changes: 11 additions & 0 deletions vls-mqtt/app/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("entropy", genEntropy());

export const seed = derived([loaded, entropy], ([$loaded, $entropy]) => {
Expand All @@ -75,6 +84,8 @@ export const seed = derived([loaded, entropy], ([$loaded, $entropy]) => {

export const lss_nonce = writable<string>(gen32Nonce());

export const signer_id = writable<string>(gen16Id());

export const keys = derived([loaded, seed], ([$loaded, $seed]) => {
if (!$loaded) return null;
if (!$seed) return null;
Expand Down

0 comments on commit b61032e

Please sign in to comment.