From d7ef07c2e2730dba2708ce5894578469d753879f Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 14 Jan 2024 21:00:59 -0700 Subject: [PATCH] automatically create an identity on the first page (and other UI tweaks) --- project.task.yaml | 2 +- src/libs/util.ts | 33 ++++++++- src/views/AccountViewView.vue | 120 +++++++++++++++++-------------- src/views/ContactsView.vue | 2 +- src/views/HelpView.vue | 12 ++++ src/views/HomeView.vue | 53 ++++++++------ src/views/ImportAccountView.vue | 35 +++++++-- src/views/NewEditProjectView.vue | 7 +- src/views/NewIdentifierView.vue | 27 +------ 9 files changed, 177 insertions(+), 114 deletions(-) diff --git a/project.task.yaml b/project.task.yaml index 048b820..a2d25ad 100644 --- a/project.task.yaml +++ b/project.task.yaml @@ -2,7 +2,7 @@ tasks: - create an identifier automatically, with a message that they can import a different one -- choose an agent - make a contact chooser +- choose an agent via a contact chooser (not just copy-paste a DID) - make set-name request yellow - make the "give" on contact screen work like other give (allowing donation vs current blank) - make give action executable right from an offer diff --git a/src/libs/util.ts b/src/libs/util.ts index 2b4b037..52e48e7 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -3,8 +3,9 @@ import axios, { AxiosResponse } from "axios"; import { DEFAULT_PUSH_SERVER } from "@/constants/app"; -import { db } from "@/db/index"; +import { accountsDB, db } from "@/db/index"; import { MASTER_SETTINGS_KEY } from "@/db/tables/settings"; +import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto"; // eslint-disable-next-line @typescript-eslint/no-var-requires const Buffer = require("buffer/").Buffer; @@ -18,6 +19,36 @@ export const isGlobalUri = (uri: string) => { export const ONBOARD_MESSAGE = "1) Check that they have entered their name on the profile page in their device. 2) Add them to your Contacts by scanning with the QR icon that is by the input box. 3) Click the person icon to register them. 4) Have them go to their Contact page and scan your QR to add you to their list."; +/** + * Generates a new identity, saves it to the database, and sets it as the active identity. + * @return {Promise} with the DID of the new identity + */ +export const generateSaveAndActivateIdentity = async (): Promise => { + const mnemonic = generateSeed(); + // address is 0x... ETH address, without "did:eth:" + const [address, privateHex, publicHex, derivationPath] = + deriveAddress(mnemonic); + + const newId = newIdentifier(address, publicHex, privateHex, derivationPath); + const identity = JSON.stringify(newId); + + await accountsDB.open(); + await accountsDB.accounts.add({ + dateCreated: new Date().toISOString(), + derivationPath: derivationPath, + did: newId.did, + identity: identity, + mnemonic: mnemonic, + publicKeyHex: newId.keys[0].publicKeyHex, + }); + + await db.settings.update(MASTER_SETTINGS_KEY, { + activeDid: newId.did, + }); + + return newId.did; +}; + export const sendTestThroughPushServer = async ( subscription: PushSubscription, skipFilter: boolean, diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 7dbd703..9ebb1d6 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -4,6 +4,16 @@
+ +
+

+ +

+
+

Your Identity @@ -51,24 +61,6 @@ - - -
-

- Note: Before you can publicly announce a new project or time - commitment, a friend needs to register you. -

- - Share Your Info - -
-

@@ -80,9 +72,9 @@ - (Set Your Name) + Set Your Name @@ -101,6 +93,24 @@

+ + +
+

+ Note: Before you can publicly announce a new project or time + commitment, a friend needs to register you. +

+ + Share Your Info + +
+
-

Data Export

- - - Backup Identifier Seed - - - - - If no download happened yet, click again here to download now. - - -
-

Rate Limits

- +
Usage Limits
Checking… @@ -200,6 +180,40 @@

+ +
+ +
+
Data Export
+ + Backup Identifier Seed + + + + + If no download happened yet, click again here to download now. +
diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 7443845..c86b537 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -604,7 +604,7 @@ export default class ContactsView extends Vue { group: "alert", type: "info", title: "New User?", - text: "If they are a new user, be sure to register them.", + text: "If they are a new user, be sure to register to onboard them.", }, -1, ); diff --git a/src/views/HelpView.vue b/src/views/HelpView.vue index 623fe78..f9f5229 100644 --- a/src/views/HelpView.vue +++ b/src/views/HelpView.vue @@ -69,6 +69,18 @@ make it an opportunity to get to know their projects, and show your own.

+

+ I had an identifier, but I reinstalled and I got a new one automatically. + How do I restore my old one? +

+

+ Go to the page + import your identifier. + If you don't want the old one, click "Advanced" and check the box to erase it. + (The erase option only shows if you have exactly one identifier. + For more in-depth surgery, you'll have to erase data from the browser or reinstall.) +

+

How do I add someone else?