Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #384 from symbol/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
yilmazbahadir authored Jan 5, 2022
2 parents 5a6fbc1 + 7b10bb9 commit 65f5eaf
Show file tree
Hide file tree
Showing 115 changed files with 36,540 additions and 26,784 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
dist: bionic
language: node_js
node_js:
- "12"
- 12
- lts/*
cache:
directories:
- "node_modules"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [1.0.1] - 31-Dec-2021

### Changed

- `symbol-sdk` upgraded to v1.0.3
- Other project dependencies updates
## [1.0.0] - 13-Mar-2021

### Changed
Expand Down Expand Up @@ -433,6 +439,7 @@ Before installing ``symbol-cli@0.16.0``, backup and delete the file ``~ \.nem2r

- Initial code release.

[1.0.1]: https://github.com/nemtech/symbol-cli/compare/v1.0.0...v1.0.1
[0.21.1]: https://github.com/nemtech/symbol-cli/compare/v0.20.1...v0.21.1
[0.20.1]: https://github.com/nemtech/symbol-cli/compare/v0.19.2...v0.20.1
[0.19.2]: https://github.com/nemtech/symbol-cli/compare/v0.18.3...v0.19.2
Expand Down
11,544 changes: 10,365 additions & 1,179 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 24 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"pretest": "npm run build",
"test": "mocha --ui bdd --recursive ./build/test",
"build": "rm -rf build/ && tsc",
"watch": "tsc -w",
"build:win": "del build && tsc",
"dev": "nodemon --config \"./nodemon-config.json\"/",
"test:cov": "nyc --reporter=lcov --reporter=text-summary npm t",
Expand All @@ -32,52 +33,56 @@
},
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.21.1",
"@ledgerhq/hw-transport-node-hid": "^5.51.1",
"axios": "^0.21.4",
"bip32": "^1.0.2",
"chalk": "^2.3.0",
"cli-table3": "^0.5.1",
"clime": "^0.5.9",
"ora": "^3.4.0",
"path": "^0.12.7",
"prompts": "^2.4.0",
"rxjs": "^6.6.3",
"symbol-hd-wallets": "0.14.1-alpha-202103052158",
"symbol-sdk": "0.23.4-alpha-202103071752",
"symbol-uri-scheme": "0.6.0",
"prompts": "^2.4.2",
"rxjs": "^6.6.7",
"symbol-hd-wallets": "0.14.2",
"symbol-ledger-typescript": "0.0.1-alpha-202106081510",
"symbol-sdk": "^1.0.3",
"symbol-uri-scheme": "0.6.1",
"update-notifier": "^4.1.0",
"utf8": "^3.0.0"
},
"devDependencies": {
"@types/bip32": "^1.0.2",
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^9.6.61",
"@types/chai": "^4.3.0",
"@types/ledgerhq__hw-transport": "^4.21.3",
"@types/ledgerhq__hw-transport-node-hid": "^4.22.2",
"@types/mocha": "^9.0.0",
"@types/node": "^17.0.5",
"@types/ora": "^3.2.0",
"@types/prompts": "^2.0.3",
"@types/prompts": "^2.0.14",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^7.5.2",
"@types/sinon": "^10.0.6",
"@types/update-notifier": "^4.1.0",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.18.0",
"chai": "^4.1.2",
"coveralls": "^3.0.14",
"chai": "^4.3.4",
"coveralls": "^3.1.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-prefer-arrow": "^1.1.7",
"eslint-plugin-prettier": "^3.3.1",
"import-sort-style-module": "^6.0.0",
"mocha": "^8.2.1",
"nodemon": "^2.0.7",
"mocha": "^9.1.3",
"nodemon": "^2.0.15",
"nyc": "^15.0.0",
"prettier": "^2.2.1",
"prettier": "^2.5.1",
"prettier-plugin-import-sort": "0.0.4",
"prettier-plugin-organize-imports": "^1.1.1",
"proxyquire": "^2.1.3",
"sinon": "^9.2.3",
"sinon": "^12.0.1",
"ts-mockito": "^2.2.8",
"ts-node": "^5.0.1",
"typescript": "^3.8.3"
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
},
"nyc": {
"exclude": [
Expand Down
28 changes: 17 additions & 11 deletions src/commands/account/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
* limitations under the License.
*
*/
import { command, metadata, option } from 'clime';
import { command, ExpectedError, metadata, option } from 'clime';
import { MnemonicPassPhrase } from 'symbol-hd-wallets';
import { Account } from 'symbol-sdk';
import { AccountCredentialsTable, CreateProfileCommand } from '../../interfaces/create.profile.command';
import { CreateProfileOptions } from '../../interfaces/create.profile.options';
import { ImportType } from '../../models/importType.enum';
import { Profile } from '../../models/profile.model';
import { ProfileCreationBase } from '../../models/profileCreation.types';
import { HdProfileCreation, PrivateKeyProfileCreation, ProfileCreationBase } from '../../models/profileCreation.types';
import { DefaultResolver } from '../../resolvers/default.resolver';
import { EpochAdjustmentResolver } from '../../resolvers/epochAdjustment.resolver';
import { GenerationHashResolver } from '../../resolvers/generationHash.resolver';
Expand Down Expand Up @@ -59,12 +58,15 @@ export default class extends CreateProfileCommand {
const networkType = await new NetworkResolver().resolve(options);
const save = await new SaveResolver().resolve(options);
const importType = await new ImportTypeResolver().resolve(options);
if (importType == ImportType.Ledger) {
throw new ExpectedError('Ledger cannot be generated, use the profile import or profile create command!');
}

if (!save) {
if (importType === ImportType.PrivateKey) {
const account = Account.generateNewAccount(networkType);
console.log(AccountCredentialsTable.createFromAccount(account).toString());
} else {
} else if (importType === ImportType.Mnemonic) {
const pathNumber = await new PathNumberResolver().resolve(options);
const mnemonic = MnemonicPassPhrase.createRandom().plain;
const privateKey = DerivationService.getPrivateKeyFromMnemonic(mnemonic, pathNumber, networkType);
Expand All @@ -75,6 +77,8 @@ export default class extends CreateProfileCommand {
pathNumber,
).toString(),
);
} else {
throw new Error('Ledger cannot be generated, use the profile import or profile create command!');
}
return;
}
Expand All @@ -97,21 +101,23 @@ export default class extends CreateProfileCommand {
name,
networkCurrency,
networkType,
password,
url: options.url,
};

let profile: Profile;

if (importType === ImportType.PrivateKey) {
const { privateKey } = Account.generateNewAccount(networkType);
profile = this.createProfile({ ...baseArguments, privateKey });
} else {
const args: PrivateKeyProfileCreation = { ...baseArguments, password, privateKey };
const profile = this.createProfile(args);
console.log(profile.getTable(password).toString());
} else if (importType === ImportType.Mnemonic) {
const mnemonic = MnemonicPassPhrase.createRandom().plain;
profile = this.createProfile({ ...baseArguments, mnemonic, pathNumber: 1 });
const args: HdProfileCreation = { ...baseArguments, password, mnemonic, pathNumber: 1 };
const profile = this.createProfile(args);
console.log(profile.getTable(password).toString());
} else {
throw new Error('Ledger cannot be generated, use the profile import or profile create command!');
}

console.log(AccountCredentialsTable.createFromProfile(profile, password).toString());
console.log(FormatterService.success('Stored ' + name + ' profile'));
}
}
2 changes: 1 addition & 1 deletion src/commands/converter/privateKeyToPublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CommandOptions extends ProfileOptions {

@option({
flag: 'n',
description: 'Network Type. (MAIN_NET, TEST_NET, PRIVATE, PRIVATE_TEST, MIJIN, MIJIN_TEST)',
description: 'Network Type. (MAIN_NET, TEST_NET)',
})
network: string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/converter/publicKeyToAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CommandOptions extends ProfileOptions {

@option({
flag: 'n',
description: 'Network Type. (MAIN_NET, TEST_NET, PRIVATE, PRIVATE_TEST, MIJIN, MIJIN_TEST)',
description: 'Network Type. (MAIN_NET, TEST_NET)',
})
network: string;
}
Expand Down
48 changes: 33 additions & 15 deletions src/commands/profile/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@
import { command, metadata } from 'clime';
import { MnemonicPassPhrase } from 'symbol-hd-wallets';
import { Account } from 'symbol-sdk';
import { AccountCredentialsTable, CreateProfileCommand } from '../../interfaces/create.profile.command';
import { CreateProfileCommand } from '../../interfaces/create.profile.command';
import { CreateProfileOptions } from '../../interfaces/create.profile.options';
import { ImportType } from '../../models/importType.enum';
import { Profile } from '../../models/profile.model';
import { ProfileCreationBase } from '../../models/profileCreation.types';
import {
HdProfileCreation,
LedgerProfileCreation,
PrivateKeyProfileCreation,
ProfileCreationBase,
} from '../../models/profileCreation.types';
import { DefaultResolver } from '../../resolvers/default.resolver';
import { EpochAdjustmentResolver } from '../../resolvers/epochAdjustment.resolver';
import { GenerationHashResolver } from '../../resolvers/generationHash.resolver';
import { ImportTypeResolver } from '../../resolvers/importType.resolver';
import { LedgerResolver } from '../../resolvers/ledger.resolver';
import { NetworkResolver } from '../../resolvers/network.resolver';
import { NetworkCurrencyResolver } from '../../resolvers/networkCurrency.resolver';
import { PasswordResolver } from '../../resolvers/password.resolver';
import { ProfileNameResolver } from '../../resolvers/profile.resolver';
import { URLResolver } from '../../resolvers/url.resolver';
import { FormatterService } from '../../services/formatter.service';

export class CommandOptions extends CreateProfileOptions {}

@command({
Expand All @@ -49,7 +53,6 @@ export default class extends CreateProfileCommand {
const networkType = await new NetworkResolver().resolve(options);
options.url = await new URLResolver().resolve(options);
const name = await new ProfileNameResolver().resolve(options);
const password = await new PasswordResolver().resolve(options);
const isDefault = await new DefaultResolver().resolve(options);

this.spinner.start();
Expand All @@ -60,28 +63,43 @@ export default class extends CreateProfileCommand {

const importType = await new ImportTypeResolver().resolve(options);

const url = options.url;
const baseArguments: ProfileCreationBase = {
generationHash,
epochAdjustment,
isDefault,
name,
networkCurrency,
networkType,
password,
url: options.url,
url,
};

let profile: Profile;

if (importType === ImportType.PrivateKey) {
const { privateKey } = Account.generateNewAccount(networkType);
profile = this.createProfile({ ...baseArguments, privateKey });
} else {
const password = await new PasswordResolver().resolve(options);
const privateKey = Account.generateNewAccount(networkType).privateKey;
const args: PrivateKeyProfileCreation = { ...baseArguments, password, privateKey };
const profile = this.createProfile(args);
console.log(profile.getTable(password).toString());
} else if (importType === ImportType.Mnemonic) {
const password = await new PasswordResolver().resolve(options);
const mnemonic = MnemonicPassPhrase.createRandom().plain;
profile = this.createProfile({ ...baseArguments, mnemonic, pathNumber: 1 });
const args: HdProfileCreation = {
...baseArguments,
password,
mnemonic,
pathNumber: 1,
};
const profile = this.createProfile(args);
console.log(profile.getTable(password).toString());
} else if (importType === ImportType.Ledger) {
const ledgerArguments = await new LedgerResolver(networkType, false, this.spinner).resolve(options);
const args: LedgerProfileCreation = { ...baseArguments, ...ledgerArguments };
const profile = this.createProfile(args);
console.log(profile.getTable(undefined).toString());
} else {
throw new Error(`Invalid import type ${importType}`);
}

console.log(AccountCredentialsTable.createFromProfile(profile, password).toString());
console.log(FormatterService.success('Stored ' + name + ' profile'));
console.log(FormatterService.success(`Stored ${name} profile`));
}
}
15 changes: 1 addition & 14 deletions src/commands/profile/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/

import { command, metadata } from 'clime';
import { Crypto } from 'symbol-sdk';
import { AccountCredentialsTable } from '../../interfaces/create.profile.command';
import { ProfileCommand } from '../../interfaces/profile.command';
import { ProfileOptions } from '../../interfaces/profile.options';
import { HdProfile } from '../../models/hdProfile.model';
import { PasswordResolver } from '../../resolvers/password.resolver';

@command({
Expand All @@ -34,18 +31,8 @@ export default class extends ProfileCommand {

@metadata
async execute(options: ProfileOptions) {
let mnemonic;
let pathNumber;

const profile = this.getProfile(options);
const password = await new PasswordResolver().resolve(options);
const account = profile.decrypt(password);

if (profile instanceof HdProfile) {
mnemonic = Crypto.decrypt(profile.encryptedPassphrase, password.value);
pathNumber = profile.pathNumber;
}

console.log(AccountCredentialsTable.createFromAccount(account, mnemonic, pathNumber).toString());
console.log(profile.getTable(password).toString());
}
}
Loading

0 comments on commit 65f5eaf

Please sign in to comment.