From 0c05505c461ef281c525e23ef3f1aefd0661fbd2 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 20 Aug 2023 19:46:12 -0600 Subject: [PATCH] allow use of custom derivation path, and add way to increment derivation for existing --- project.task.yaml | 1 + src/db/index.ts | 4 +- src/libs/crypto/index.ts | 8 +- src/router/index.ts | 8 ++ src/views/ImportAccountView.vue | 35 +++++- src/views/ImportDerivedAccountView.vue | 163 +++++++++++++++++++++++++ src/views/SeedBackupView.vue | 10 ++ src/views/StartView.vue | 28 ++++- 8 files changed, 244 insertions(+), 13 deletions(-) create mode 100644 src/views/ImportDerivedAccountView.vue diff --git a/project.task.yaml b/project.task.yaml index e8799f377..763accab7 100644 --- a/project.task.yaml +++ b/project.task.yaml @@ -37,6 +37,7 @@ tasks: - .2 fix rate limit verbiage (with the new one-per-day allowance) assignee:trent - .2 move 'switch identity' to the advanced section - .1 remove the logic to exclude beforeId in list of plans after server has commit 26b25af605e715600d4f12b6416ed9fd7142d164 +- .2 in SeedBackupView, don't load the mnemonic and keep it in memory; only load it when they click "show" - Discuss whether the remaining tasks are worthwhile before MVP release. diff --git a/src/db/index.ts b/src/db/index.ts index 8091e5c84..d39ea5ec6 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -28,12 +28,12 @@ type NonsensitiveTables = { * https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any */ export type SensitiveDexie = BaseDexie & T; -export const accountsDB = new BaseDexie("KickStartAccounts") as SensitiveDexie; +export const accountsDB = new BaseDexie("TimeSafariAccounts") as SensitiveDexie; const SensitiveSchemas = Object.assign({}, AccountsSchema); export type NonsensitiveDexie = BaseDexie & T; -export const db = new BaseDexie("KickStart") as NonsensitiveDexie; +export const db = new BaseDexie("TimeSafari") as NonsensitiveDexie; const NonsensitiveSchemas = Object.assign({}, ContactsSchema, SettingsSchema); /** diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index fb75e2018..b3600b467 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -7,6 +7,8 @@ import { HDNode } from "@ethersproject/hdnode"; import * as didJwt from "did-jwt"; import * as u8a from "uint8arrays"; +export const DEFAULT_ROOT_DERIVATION_PATH = "m/76798669'/0'/0'/0'"; + /** * * @@ -47,17 +49,17 @@ export const newIdentifier = ( */ export const deriveAddress = ( mnemonic: string, + derivationPath: string = DEFAULT_ROOT_DERIVATION_PATH, ): [string, string, string, string] => { - const UPORT_ROOT_DERIVATION_PATH = "m/7696500'/0'/0'/0'"; mnemonic = mnemonic.trim().toLowerCase(); const hdnode: HDNode = HDNode.fromMnemonic(mnemonic); - const rootNode: HDNode = hdnode.derivePath(UPORT_ROOT_DERIVATION_PATH); + const rootNode: HDNode = hdnode.derivePath(derivationPath); const privateHex = rootNode.privateKey.substring(2); // original starts with '0x' const publicHex = rootNode.publicKey.substring(2); // original starts with '0x' const address = rootNode.address; - return [address, privateHex, publicHex, UPORT_ROOT_DERIVATION_PATH]; + return [address, privateHex, publicHex, derivationPath]; }; /** diff --git a/src/router/index.ts b/src/router/index.ts index c524c1b75..7ce59c4e8 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -91,6 +91,14 @@ const routes: Array = [ /* webpackChunkName: "import-account" */ "../views/ImportAccountView.vue" ), }, + { + path: "/import-derive", + name: "import-derive", + component: () => + import( + /* webpackChunkName: "import-derive" */ "../views/ImportDerivedAccountView.vue" + ), + }, { path: "/new-edit-account", name: "new-edit-account", diff --git a/src/views/ImportAccountView.vue b/src/views/ImportAccountView.vue index ae3f0ac5b..52e933024 100644 --- a/src/views/ImportAccountView.vue +++ b/src/views/ImportAccountView.vue @@ -24,6 +24,24 @@ v-model="mnemonic" /> {{ mnemonic }} +

+ Advanced +

+
+ Enter a custom derivation path + + For previous uPort or Endorser users, + + click here to use that value. + +