Skip to content

Commit

Permalink
Fix Wallet Creation / Destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Jul 12, 2023
1 parent 0054c97 commit 9884530
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 43 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the "ultra-cpp" extension will be documented in this file.

## 1.3.9

- Fix issue where wallet could not be destroyed properly.
- Fix issue where wallet could not be created again after being destroyed.
- Added 'Wallet - Create Key' command

## 1.3.8

- Fix extension path issues.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The wallet service allows you to store private keys inside of VSCode's global st
- Keep the wallet unlocked to easily sign transactions, and view keys.
- Ultra: Wallet - Lock
- Lock the wallet.
- Ultra: Wallet - Create Key
- Create a key, and print it to console.

## Previews

Expand Down
79 changes: 47 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": {
"url": "https://github.com/Stuyk/ultra-cpp-extension"
},
"version": "1.3.8",
"version": "1.3.9",
"engines": {
"vscode": "^1.70.0"
},
Expand Down Expand Up @@ -85,6 +85,11 @@
"command": "ultra.lockWallet",
"title": "Wallet - Lock",
"category": "Ultra"
},
{
"command": "ultra.createKey",
"title": "Wallet - Create Key",
"category": "Ultra"
}
],
"snippets": [
Expand Down Expand Up @@ -123,9 +128,10 @@
"dependencies": {
"@types/node-fetch": "^2.6.4",
"@ultraos/contract-builder": "^1.0.4",
"@wharfkit/antelope": "^0.7.2",
"eosjs": "^22.1.0",
"eosjs-ecc": "^4.0.7",
"node-fetch": "^2.6.11",
"glob": "^8.1.0"
"glob": "^8.1.0",
"node-fetch": "^2.6.11"
}
}
}
3 changes: 2 additions & 1 deletion src/commands/addKeyToWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let disposable: vscode.Disposable;

async function register() {
disposable = vscode.commands.registerCommand(Service.command.commandNames.addKeyToWallet, async () => {
if (!Service.wallet.exists()) {
const walletExists = await Service.wallet.exists();
if (!walletExists) {
vscode.window.showErrorMessage('Wallet does not exist. Create a wallet first!');
return;
}
Expand Down
37 changes: 37 additions & 0 deletions src/commands/apiFlows/getAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as vscode from 'vscode';
import fetch from 'node-fetch';
import * as Utility from '../../utility/index';

const endpoint = '/v1/chain/get_abi';

export async function start(api: string) {
const accountName = await Utility.quickInput.create({ title: 'Account Name', value: '', placeHolder: 'ultra' });

if (!accountName) {
vscode.window.showWarningMessage(`Account name was not provided. Query cancelled.`);
return;
}

const options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: `{"account_name":"${accountName}","json":true}`,
};

const outputChannel = Utility.outputChannel.get();
outputChannel.show();
outputChannel.appendLine(endpoint);

const response = await fetch(api + endpoint, options).catch((err) => {
outputChannel.appendLine(err);
return undefined;
});

if (!response || !response.ok) {
vscode.window.showWarningMessage(`Failed to fetch data`);
return;
}

const data = await response.json();
outputChannel.appendLine(JSON.stringify(data, null, 2));
}
74 changes: 74 additions & 0 deletions src/commands/createKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as vscode from 'vscode';
import * as Utility from '../utility/index';
import * as Service from '../service/index';
import * as wharfkit from '@wharfkit/antelope';

let disposable: vscode.Disposable;

async function register() {
disposable = vscode.commands.registerCommand(Service.command.commandNames.createKey, async () => {
const keyType = await Utility.quickPick.create({
title: 'Choose Key Version',
items: [
{ label: 'K1', description: 'K1' },
{ label: 'R1', description: 'R1' },
{ label: 'WA', description: 'WA' },
],
placeholder: 'Choose a key version. K1 is considered default.',
});

if (!keyType) {
return;
}

const privateKey = wharfkit.PrivateKey.generate(keyType);
const publicKeyType = await Utility.quickPick.create({
title: 'Choose Public Key Type',
items: [
{ label: 'Standard', description: 'standard' },
{ label: 'Legacy', description: 'legacy' },
],
placeholder: 'Choose a public key version. Legacy starts with "EOS"',
});

const ready = await Utility.quickPick.create({
title: 'Keys will be printed to console, are you ready to view them?',
items: [
{ label: 'Yes', description: 'yes' },
{ label: 'No', description: 'no' },
],
placeholder: 'Read above carefully before selecting an answer.',
});

if (ready === 'no') {
vscode.window.showWarningMessage('Declined showing keys after generation.');
return;
}

const output = Utility.outputChannel.get();

if (keyType === 'K1') {
output.appendLine(`Private: ${privateKey.toWif()}`);
} else {
output.appendLine(`Private: ${privateKey.toString()}`);
}

if (publicKeyType === 'standard') {
output.appendLine(`Public: ${privateKey.toPublic().toString()}`);
} else {
output.appendLine(`Public: ${privateKey.toPublic().toLegacyString()}`);
}

output.show();
});

const context = await Utility.context.get();
context.subscriptions.push(disposable);
return () => {
if (disposable) {
disposable.dispose();
}
};
}

Service.command.register('createKey', register);
3 changes: 2 additions & 1 deletion src/commands/createWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let disposable: vscode.Disposable;

async function register() {
disposable = vscode.commands.registerCommand(Service.command.commandNames.createWallet, async () => {
if (Service.wallet.exists()) {
const walletExists = await Service.wallet.exists();
if (walletExists) {
vscode.window.showInformationMessage('Wallet already exists!');
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/destroyWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let disposable: vscode.Disposable;

async function register() {
disposable = vscode.commands.registerCommand(Service.command.commandNames.destroyWallet, async () => {
if (!Service.wallet.exists()) {
const walletExists = await Service.wallet.exists();
if (!walletExists) {
vscode.window.showInformationMessage('No wallet available.');
return;
}
Expand Down
Loading

0 comments on commit 9884530

Please sign in to comment.