Skip to content

Commit

Permalink
Update hcSeedBundle and packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mrruby committed May 23, 2024
1 parent 2b9972d commit f402fb4
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 219 deletions.
24 changes: 12 additions & 12 deletions holo-key-manager-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.5.4",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@sveltejs/kit": "^2.5.9",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@types/file-saver": "^2.0.7",
"archiver": "^7.0.1",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"prettier-plugin-svelte": "^3.2.2",
"prettier-plugin-tailwindcss": "^0.5.11",
"svelte-check": "^3.6.8",
"svelte-file-dropzone": "^2.0.4",
"prettier-plugin-svelte": "^3.2.3",
"prettier-plugin-tailwindcss": "^0.5.14",
"svelte-check": "^3.7.1",
"svelte-file-dropzone": "^2.0.7",
"tslib": "^2.6.2",
"vite": "^5.2.4"
"vite": "^5.2.11"
},
"type": "module",
"dependencies": {
"@tanstack/svelte-query": "^5.28.6",
"clsx": "^2.1.0",
"@tanstack/svelte-query": "^5.37.1",
"clsx": "^2.1.1",
"file-saver": "^2.0.5",
"hcSeedBundle": "github:mrruby/hcSeedBundle#v0.0.7",
"@holochain/hc-seed-bundle": "0.1.0",
"jszip": "^3.10.1",
"svelte": "^4.2.12",
"tailwindcss": "^3.4.1",
"svelte": "^4.2.17",
"tailwindcss": "^3.4.3",
"tiny-glob": "^0.2.9"
}
}
3 changes: 1 addition & 2 deletions holo-key-manager-extension/scripts/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as hcSeedBundle from '@holochain/hc-seed-bundle';
import { AUTHENTICATED_APPS_LIST, SESSION } from '@shared/const';
import { base64ToUint8Array, uint8ArrayToBase64 } from '@shared/helpers';
import { getDeviceKey, storageService } from '@shared/services';
Expand All @@ -6,8 +7,6 @@ import {
type SignMessage,
SuccessMessageSignedSchema
} from '@shared/types';
// @ts-expect-error no types for hcSeedBundle
import * as hcSeedBundle from 'hcSeedBundle';

export const signMessageLogic = async ({ message, happId, session }: SignMessage) => {
const encryptedDeviceKey = await getDeviceKey();
Expand Down
9 changes: 7 additions & 2 deletions holo-key-manager-extension/src/lib/helpers/encryption.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PBKDF2_ITERATIONS } from '$shared/const';
import type { HashSalt } from '$shared/types';

const hexStringToArrayBuffer = (hexString: string) => {
Expand Down Expand Up @@ -32,7 +33,7 @@ const deriveBits = async (password: string, salt: Uint8Array, iterations: number

export const hashPassword = async (password: string): Promise<HashSalt> => {
const salt = crypto.getRandomValues(new Uint8Array(16));
const derivedBits = await deriveBits(password, salt, 100000);
const derivedBits = await deriveBits(password, salt, PBKDF2_ITERATIONS);
return {
hash: arrayBufferToHexString(derivedBits),
salt: arrayBufferToHexString(salt)
Expand All @@ -44,6 +45,10 @@ export const verifyPassword = async (
storedHashSalt: HashSalt
): Promise<boolean> => {
const saltBuffer = hexStringToArrayBuffer(storedHashSalt.salt);
const derivedBits = await deriveBits(inputPassword, new Uint8Array(saltBuffer), 100000);
const derivedBits = await deriveBits(
inputPassword,
new Uint8Array(saltBuffer),
PBKDF2_ITERATIONS
);
return arrayBufferToHexString(derivedBits) === storedHashSalt.hash;
};
17 changes: 4 additions & 13 deletions holo-key-manager-extension/src/lib/services/manage-keys.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// eslint-disable-next-line
// @ts-nocheck
import * as hcSeedBundle from 'hcSeedBundle';
import * as hcSeedBundle from '@holochain/hc-seed-bundle';

import { base64ToUint8Array, uint8ArrayToBase64 } from '$shared/helpers';
import type { GeneratedKeys } from '$types';

const lock = (root: never, password: string) =>
const lock = (root: hcSeedBundle.UnlockedSeedBundle, password: string) =>
root.lock([
new hcSeedBundle.SeedCipherPwHash(
hcSeedBundle.parseSecret(new TextEncoder().encode(password)),
Expand All @@ -14,18 +12,14 @@ const lock = (root: never, password: string) =>
]);

const deriveAndLock = (
master: never,
master: hcSeedBundle.UnlockedSeedBundle,
derivationPath: number,
bundleType: string,
passphrase: string
) => {
const root = master.derive(derivationPath, {
bundle_type: bundleType
});
root.setAppData({
device_number: derivationPath,
generate_by: 'keymanager-v1.0'
});

const encodedBytes = lock(root, passphrase);
root.zero();
Expand All @@ -42,9 +36,6 @@ export async function generateKeys(
const master = hcSeedBundle.UnlockedSeedBundle.newRandom({
bundle_type: 'master'
});
master.setAppData({
generate_by: 'keymanager-v1.0'
});

const encodedMasterBytes: Uint8Array = lock(master, passphrase);
const encodedRevocationBytes = deriveAndLock(master, 0, 'revocationRoot', passphrase);
Expand All @@ -66,7 +57,7 @@ export async function generateKeys(
};
}

export const lockKey = async (key: unknown, password: string) => {
export const lockKey = async (key: hcSeedBundle.UnlockedSeedBundle, password: string) => {
await hcSeedBundle.seedBundleReady;

const pw = new TextEncoder().encode(password);
Expand Down
2 changes: 1 addition & 1 deletion holo-key-manager-extension/static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Holo key manager",
"description": "A browser extension to manage holo keys",
"version": "0.0.55",
"version": "0.0.56",
"manifest_version": 3,
"action": {
"default_title": "Holo key manager",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/chrome": "^0.0.268",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"concurrently": "^8.2.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-svelte": "^2.39.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"lint-staged": "^15.2.4",
"prettier": "^3.2.5",
"rollup": "^4.17.2",
"rollup": "^4.18.0",
"rollup-plugin-tsc-alias": "^1.1.2",
"rollup-plugin-typescript2": "^0.36.0",
"typescript": "^5.4.5"
Expand Down
Loading

0 comments on commit f402fb4

Please sign in to comment.