From 398abbccef9aa190a0ccc4c82721c0accf5f9b40 Mon Sep 17 00:00:00 2001 From: Nayyir Jutha Date: Wed, 13 Nov 2024 16:16:17 -0600 Subject: [PATCH] [NayNay] Complete Import - on import, only the address and basic account info is added to the users config - this adds the existing verifying keys to the account info --- src/account/interaction.ts | 21 +++++++++++++++------ src/account/main.ts | 5 +++++ src/account/utils.ts | 13 +++++++++++++ src/faucet/main.ts | 5 +++-- src/tui.ts | 2 +- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/account/interaction.ts b/src/account/interaction.ts index 9cbff0c..660188e 100644 --- a/src/account/interaction.ts +++ b/src/account/interaction.ts @@ -2,9 +2,9 @@ import inquirer from "inquirer"; import Entropy from "@entropyxyz/sdk"; import { EntropyAccount } from './main' -import { selectAndPersistNewAccount, addVerifyingKeyToAccountAndSelect } from "./utils"; +import { selectAndPersistNewAccount, addVerifyingKeyToAccountAndSelect, completeImport } from "./utils"; import { findAccountByAddressOrName, print } from "../common/utils" -import { EntropyConfig } from "../config/types"; +import { EntropyAccountConfig, EntropyConfig } from "../config/types"; import * as config from "../config"; import { @@ -17,7 +17,7 @@ import { ERROR_RED } from "src/common/constants"; /* * @returns partialConfigUpdate | "exit" | undefined */ -export async function entropyAccount (endpoint: string, storedConfig: EntropyConfig) { +export async function entropyAccount (storedConfig: EntropyConfig, endpoint?: string) { const { accounts } = storedConfig const { interactionChoice } = await inquirer.prompt(accountManageQuestions) @@ -32,9 +32,13 @@ export async function entropyAccount (endpoint: string, storedConfig: EntropyCon seed = seed.split('#debug')[0] } - const newAccount = seed - ? await EntropyAccount.import({ seed, name, path }) - : await EntropyAccount.create({ name, path }) + let newAccount: EntropyAccountConfig + if (seed) { + const partiallyImportedAccount = await EntropyAccount.import({ seed, name, path }) + newAccount = await completeImport(partiallyImportedAccount, endpoint) + } else { + newAccount = await EntropyAccount.create({ name, path }) + } await selectAndPersistNewAccount(newAccount) return @@ -87,6 +91,11 @@ export async function entropyRegister (entropy: Entropy, endpoint: string, store try { const verifyingKey = await accountService.register() await addVerifyingKeyToAccountAndSelect(verifyingKey, account.address) + const fullAccount = await entropy.keyring.getAccount() + const newverifyingkeys = await accountService.getVerifyingKeys(fullAccount.registration.address) + + console.log({ regkeys: fullAccount.registration.verifyingKeys, devkeys: fullAccount.deviceKey.verifyingKeys, adminkeys: fullAccount.admin.verifyingKeys }); + console.log({ newverifyingkeys }) print("Your address", account.address, "has been successfully registered.") } catch (error) { diff --git a/src/account/main.ts b/src/account/main.ts index abff37c..2d65c1e 100644 --- a/src/account/main.ts +++ b/src/account/main.ts @@ -53,6 +53,11 @@ export class EntropyAccount extends EntropyBase { })) } + async getVerifyingKeys (address: string) { + return this.entropy.substrate.query.registry.modifiableKeys(address) + .then(result => result.toJSON()) + } + async register (params?: AccountRegisterParams): Promise { let programModAddress: string let programData: any diff --git a/src/account/utils.ts b/src/account/utils.ts index a59da64..bb66abf 100644 --- a/src/account/utils.ts +++ b/src/account/utils.ts @@ -2,6 +2,8 @@ import { ACCOUNTS_CONTENT } from './constants'; import { EntropyAccountConfig } from "../config/types"; import * as config from "../config"; import { generateAccountChoices, findAccountByAddressOrName } from '../common/utils'; +import { EntropyAccount } from './main'; +import { initializeEntropy } from 'src/common/initializeEntropy'; export async function selectAndPersistNewAccount (newAccount: EntropyAccountConfig) { const storedConfig = await config.get() @@ -93,3 +95,14 @@ export const accountManageQuestions = [ choices: ACCOUNTS_CONTENT.interactionChoice.choices } ] + +export async function completeImport (newAccount: EntropyAccountConfig, endpoint: string) { + const entropy = await initializeEntropy({ keyMaterial: newAccount.data, endpoint }) + const accountService = new EntropyAccount(entropy, endpoint) + + const verifyingKeys = await accountService.getVerifyingKeys(newAccount.address) + newAccount.data.admin.verifyingKeys = verifyingKeys as string[] + newAccount.data.registration.verifyingKeys = verifyingKeys as string[] + + return newAccount +} \ No newline at end of file diff --git a/src/faucet/main.ts b/src/faucet/main.ts index 84346b5..1358f1f 100644 --- a/src/faucet/main.ts +++ b/src/faucet/main.ts @@ -7,6 +7,7 @@ import { EntropyProgram } from "src/program/main"; import FaucetSigner from "./helpers/signer"; import { SendMoneyParams } from "./types"; import { formatDispatchError } from "src/common/utils"; +import { EntropyAccount } from "src/account/main"; const FLOW_CONTEXT = 'ENTROPY-FAUCET' @@ -43,8 +44,8 @@ export class EntropyFaucet extends EntropyBase { } async getAllFaucetVerifyingKeys (programModKey = FAUCET_PROGRAM_MOD_KEY) { - return this.entropy.substrate.query.registry.modifiableKeys(programModKey) - .then(res => res.toJSON()) + const accountService = new EntropyAccount(this.entropy, this.endpoint) + return accountService.getVerifyingKeys(programModKey) } // To handle overloading the individual faucet, multiple faucet accounts have been generated, and here is diff --git a/src/tui.ts b/src/tui.ts index 6c49418..9660c8b 100644 --- a/src/tui.ts +++ b/src/tui.ts @@ -134,7 +134,7 @@ async function main (entropy: Entropy, choices: string[], options: EntropyTuiOpt switch (answers.choice) { case 'Manage Accounts': { - const response = await entropyAccount(options.endpoint, storedConfig) + const response = await entropyAccount(storedConfig, options.endpoint) if (response === 'exit') { returnToMain = true } break }