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

Commit

Permalink
Merge branch 'release/6.1.0' of https://github.com/LiskHQ/lisk-sdk in…
Browse files Browse the repository at this point in the history
…to development
  • Loading branch information
shuse2 committed Nov 1, 2023
2 parents 2d04e23 + 773ba74 commit b43550e
Show file tree
Hide file tree
Showing 344 changed files with 10,533 additions and 4,974 deletions.
683 changes: 683 additions & 0 deletions commander/oclif.manifest.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions commander/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-commander",
"version": "6.0.0-beta.7",
"version": "6.1.0-beta.1",
"description": "A command line interface for Lisk",
"author": "Lisk Foundation <admin@lisk.com>, lightcurve GmbH <admin@lightcurve.io>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -101,16 +101,16 @@
"/docs"
],
"dependencies": {
"@liskhq/lisk-api-client": "^6.0.0-beta.6",
"@liskhq/lisk-chain": "^0.4.0-beta.6",
"@liskhq/lisk-client": "^6.0.0-beta.6",
"@liskhq/lisk-codec": "^0.3.0-beta.5",
"@liskhq/lisk-cryptography": "^4.0.0-beta.4",
"@liskhq/lisk-api-client": "^6.1.0-beta.1",
"@liskhq/lisk-chain": "^0.6.0-beta.0",
"@liskhq/lisk-client": "^6.1.0-beta.1",
"@liskhq/lisk-codec": "^0.5.0-beta.0",
"@liskhq/lisk-cryptography": "^4.1.0-beta.1",
"@liskhq/lisk-db": "0.3.7",
"@liskhq/lisk-passphrase": "^4.0.0-beta.2",
"@liskhq/lisk-transactions": "^6.0.0-beta.5",
"@liskhq/lisk-utils": "^0.3.0-beta.3",
"@liskhq/lisk-validator": "^0.7.0-beta.5",
"@liskhq/lisk-passphrase": "^4.1.0-beta.0",
"@liskhq/lisk-transactions": "^6.1.0-beta.1",
"@liskhq/lisk-utils": "^0.4.0-beta.0",
"@liskhq/lisk-validator": "^0.9.0-beta.0",
"@oclif/core": "1.20.4",
"@oclif/plugin-autocomplete": "1.3.6",
"@oclif/plugin-help": "5.1.19",
Expand All @@ -121,7 +121,7 @@
"cli-table3": "0.6.0",
"fs-extra": "11.1.0",
"inquirer": "8.2.5",
"lisk-framework": "^0.10.0-beta.7",
"lisk-framework": "^0.12.0-beta.0",
"listr": "0.14.3",
"progress": "2.0.3",
"semver": "7.5.2",
Expand Down
14 changes: 7 additions & 7 deletions commander/src/bootstrapping/commands/generator/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ export abstract class ExportCommand extends BaseIPCClientCommand {
static description = 'Export to <FILE>.';

static examples = [
'generator:export --output /mypath/genInfo.json',
'generator:export --output /mypath/genInfo.json --data-path ./data ',
'generator:export',
'generator:export --output /mypath/generator_info.json',
'generator:export --output /mypath/generator_info.json --data-path ./data ',
];

static flags = {
Expand All @@ -80,6 +81,7 @@ export abstract class ExportCommand extends BaseIPCClientCommand {

async run(): Promise<void> {
const { flags } = await this.parse(ExportCommand);

if (!this._client) {
this.error('APIClient is not initialized.');
}
Expand Down Expand Up @@ -117,10 +119,8 @@ export abstract class ExportCommand extends BaseIPCClientCommand {
generatorInfo: returnedGeneratorInfo,
};

if (flags.output) {
fs.writeJSONSync(flags.output, output, { spaces: ' ', mode: OWNER_READ_WRITE });
} else {
this.log(JSON.stringify(output, undefined, ' '));
}
const filePath = flags.output ? flags.output : path.join(process.cwd(), 'generator_info.json');
fs.writeJSONSync(filePath, output, { spaces: ' ', mode: OWNER_READ_WRITE });
this.log(`Generator info is exported to ${filePath}`);
}
}
55 changes: 52 additions & 3 deletions commander/src/bootstrapping/commands/genesis-block/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { Application, PartialApplicationConfig } from 'lisk-framework';
import { objects } from '@liskhq/lisk-utils';
import { Command, Flags as flagParser } from '@oclif/core';
import * as fs from 'fs-extra';
import { join, resolve } from 'path';
import { isAbsolute, join, resolve } from 'path';
import { validator } from '@liskhq/lisk-validator';
import { codec } from '@liskhq/lisk-codec';
import { homedir } from 'os';
import { GenesisAssetsInput, genesisAssetsSchema } from '../../../utils/genesis_creation';
import { flagsWithParser } from '../../../utils/flags';
import { getNetworkConfigFilesPath } from '../../../utils/path';
Expand All @@ -31,6 +32,7 @@ export abstract class BaseGenesisBlockCommand extends Command {
static examples = [
'genesis-block:create --output mydir',
'genesis-block:create --output mydir --assets-file ./assets.json',
'genesis-block:create --output mydir --assets-file ./assets.json --height 2 --timestamp 1592924699 --previous-block-id 085d7c9b7bddc8052be9eefe185f407682a495f1b4498677df1480026b74f2e9',
];

static flags = {
Expand All @@ -46,11 +48,39 @@ export abstract class BaseGenesisBlockCommand extends Command {
description: 'Path to file which contains genesis block asset in JSON format',
required: true,
}),
'export-json': flagParser.boolean({
description: 'Export genesis block as JSON format along with blob',
default: false,
}),
height: flagParser.integer({
char: 'h',
description: 'Genesis block height',
required: false,
}),
timestamp: flagParser.integer({
char: 't',
description: 'Timestamp',
required: false,
}),
'previous-block-id': flagParser.string({
char: 'p',
description: 'Previous block id',
required: false,
}),
};

async run(): Promise<void> {
const {
flags: { output, config: configFilePath, network, 'assets-file': assetsFile },
flags: {
output,
config: configFilePath,
network,
'assets-file': assetsFile,
height,
timestamp,
'previous-block-id': previousBlockIDString,
'export-json': exportJSON,
},
} = await this.parse(BaseGenesisBlockCommand);
// validate folder name to not include camelcase or whitespace
const regexWhitespace = /\s/g;
Expand All @@ -71,7 +101,12 @@ export abstract class BaseGenesisBlockCommand extends Command {
config = objects.mergeDeep(config, customConfig);
}
// determine proper path
const configPath = join(process.cwd(), output);
let configPath = output;
if (output.includes('~')) {
configPath = configPath.replace('~', homedir());
} else if (!isAbsolute(output)) {
configPath = join(process.cwd(), output);
}
const app = this.getApplication(config);
// If assetsFile exist, create from assetsFile and default config/accounts are not needed
const assetsJSON = (await fs.readJSON(resolve(assetsFile))) as GenesisAssetsInput;
Expand All @@ -84,11 +119,25 @@ export abstract class BaseGenesisBlockCommand extends Command {
schema: a.schema,
})),
chainID: Buffer.from(app.config.genesis.chainID, 'hex'),
height,
timestamp,
previousBlockID: previousBlockIDString
? Buffer.from(previousBlockIDString, 'hex')
: undefined,
});
fs.mkdirSync(configPath, { recursive: true });
fs.writeFileSync(resolve(configPath, 'genesis_block.blob'), genesisBlock.getBytes(), {
mode: OWNER_READ_WRITE,
});
if (exportJSON) {
fs.writeFileSync(
resolve(configPath, 'genesis_block.json'),
JSON.stringify(genesisBlock.toJSON(), undefined, ' '),
{
mode: OWNER_READ_WRITE,
},
);
}
this.log(`Genesis block files saved at: ${configPath}`);
}

Expand Down
126 changes: 97 additions & 29 deletions commander/src/bootstrapping/commands/keys/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { codec } from '@liskhq/lisk-codec';
import { bls, address as addressUtil, ed, encrypt } from '@liskhq/lisk-cryptography';
import { bls, address as addressUtil, ed, encrypt, legacy } from '@liskhq/lisk-cryptography';
import { Command, Flags as flagParser } from '@oclif/core';
import * as fs from 'fs-extra';
import * as path from 'path';
Expand Down Expand Up @@ -60,6 +60,9 @@ export class CreateCommand extends Command {
description: 'Chain id',
default: 0,
}),
'add-legacy': flagParser.boolean({
description: 'Add legacy key derivation path to the result',
}),
};

async run(): Promise<void> {
Expand All @@ -72,6 +75,7 @@ export class CreateCommand extends Command {
count,
offset,
chainid,
'add-legacy': addLegacy,
},
} = await this.parse(CreateCommand);

Expand All @@ -86,7 +90,37 @@ export class CreateCommand extends Command {
}

const keys = [];
for (let i = 0; i < count; i += 1) {
let i = 0;
if (addLegacy) {
const legacyKeyPath = 'legacy';
const { privateKey: accountPrivateKey, publicKey: accountPublicKey } =
legacy.getPrivateAndPublicKeyFromPassphrase(passphrase);
const address = addressUtil.getAddressFromPublicKey(accountPublicKey);
const generatorPrivateKey = accountPrivateKey;
const generatorPublicKey = ed.getPublicKeyFromPrivateKey(generatorPrivateKey);
const blsKeyPath = `m/12381/134/${chainid}/99999`;
const blsPrivateKey = await bls.getPrivateKeyFromPhraseAndPath(passphrase, blsKeyPath);
const blsPublicKey = bls.getPublicKeyFromPrivateKey(blsPrivateKey);
const result = await this._createEncryptedObject(
{
address,
keyPath: legacyKeyPath,
accountPrivateKey,
accountPublicKey,
generatorKeyPath: legacyKeyPath,
generatorPrivateKey,
generatorPublicKey,
blsKeyPath,
blsPrivateKey,
blsPublicKey,
password,
},
noEncrypt,
);
keys.push(result);
i += 1;
}
for (; i < count; i += 1) {
const accountKeyPath = `m/44'/134'/${offset + i}'`;
const generatorKeyPath = `m/25519'/134'/${chainid}'/${offset + i}'`;
const blsKeyPath = `m/12381/134/${chainid}/${offset + i}`;
Expand All @@ -102,37 +136,23 @@ export class CreateCommand extends Command {
const blsPrivateKey = await bls.getPrivateKeyFromPhraseAndPath(passphrase, blsKeyPath);
const blsPublicKey = bls.getPublicKeyFromPrivateKey(blsPrivateKey);

let encryptedMessageObject = {};
if (!noEncrypt) {
const plainGeneratorKeyData = {
generatorKey: generatorPublicKey,
const result = await this._createEncryptedObject(
{
address,
keyPath: accountKeyPath,
accountPrivateKey,
accountPublicKey,
generatorKeyPath,
generatorPrivateKey,
blsKey: blsPublicKey,
generatorPublicKey,
blsKeyPath,
blsPrivateKey,
};
const encodedGeneratorKeys = codec.encode(plainGeneratorKeysSchema, plainGeneratorKeyData);
encryptedMessageObject = await encrypt.encryptMessageWithPassword(
encodedGeneratorKeys,
blsPublicKey,
password,
);
}

keys.push({
address: addressUtil.getLisk32AddressFromAddress(address),
keyPath: accountKeyPath,
publicKey: accountPublicKey.toString('hex'),
privateKey: accountPrivateKey.toString('hex'),
plain: {
generatorKeyPath,
generatorKey: generatorPublicKey.toString('hex'),
generatorPrivateKey: generatorPrivateKey.toString('hex'),
blsKeyPath,
blsKey: blsPublicKey.toString('hex'),
blsProofOfPossession: bls.popProve(blsPrivateKey).toString('hex'),
blsPrivateKey: blsPrivateKey.toString('hex'),
},
encrypted: encryptedMessageObject,
});
noEncrypt,
);
keys.push(result);
}

if (output) {
Expand All @@ -141,4 +161,52 @@ export class CreateCommand extends Command {
this.log(JSON.stringify({ keys }, undefined, ' '));
}
}
private async _createEncryptedObject(
input: {
address: Buffer;
keyPath: string;
accountPublicKey: Buffer;
accountPrivateKey: Buffer;
generatorKeyPath: string;
generatorPublicKey: Buffer;
generatorPrivateKey: Buffer;
blsKeyPath: string;
blsPublicKey: Buffer;
blsPrivateKey: Buffer;
password: string;
},
noEncrypt: boolean,
) {
let encryptedMessageObject = {};
if (!noEncrypt) {
const plainGeneratorKeyData = {
generatorKey: input.generatorPublicKey,
generatorPrivateKey: input.generatorPrivateKey,
blsKey: input.blsPublicKey,
blsPrivateKey: input.blsPrivateKey,
};
const encodedGeneratorKeys = codec.encode(plainGeneratorKeysSchema, plainGeneratorKeyData);
encryptedMessageObject = await encrypt.encryptMessageWithPassword(
encodedGeneratorKeys,
input.password,
);
}

return {
address: addressUtil.getLisk32AddressFromAddress(input.address),
keyPath: input.keyPath,
publicKey: input.accountPublicKey.toString('hex'),
privateKey: input.accountPrivateKey.toString('hex'),
plain: {
generatorKeyPath: input.generatorKeyPath,
generatorKey: input.generatorPublicKey.toString('hex'),
generatorPrivateKey: input.generatorPrivateKey.toString('hex'),
blsKeyPath: input.blsKeyPath,
blsKey: input.blsPublicKey.toString('hex'),
blsProofOfPossession: bls.popProve(input.blsPrivateKey).toString('hex'),
blsPrivateKey: input.blsPrivateKey.toString('hex'),
},
encrypted: encryptedMessageObject,
};
}
}
8 changes: 4 additions & 4 deletions commander/src/bootstrapping/commands/transaction/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ export abstract class CreateCommand extends Command {
];

static examples = [
'transaction:create token transfer 100000000 --params=\'{"amount":100000000,"recipientAddress":"lskycz7hvr8yfu74bcwxy2n4mopfmjancgdvxq8xz","data":"send token"}\'',
'transaction:create token transfer 100000000 --params=\'{"amount":100000000,"recipientAddress":"lskycz7hvr8yfu74bcwxy2n4mopfmjancgdvxq8xz","data":"send token"}\' --json',
'transaction:create token transfer 100000000 --offline --network mainnet --chain-id 10000000 --nonce 1 --params=\'{"amount":100000000,"recipientAddress":"lskycz7hvr8yfu74bcwxy2n4mopfmjancgdvxq8xz","data":"send token"}\'',
'transaction:create token transfer 100000000 --params=\'{"amount":100000000,"tokenID":"0400000000000000","recipientAddress":"lskycz7hvr8yfu74bcwxy2n4mopfmjancgdvxq8xz","data":"send token"}\'',
'transaction:create token transfer 100000000 --params=\'{"amount":100000000,"tokenID":"0400000000000000","recipientAddress":"lskycz7hvr8yfu74bcwxy2n4mopfmjancgdvxq8xz","data":"send token"}\' --json',
'transaction:create token transfer 100000000 --offline --network mainnet --chain-id 10000000 --nonce 1 --params=\'{"amount":100000000,"tokenID":"0400000000000000","recipientAddress":"lskycz7hvr8yfu74bcwxy2n4mopfmjancgdvxq8xz","data":"send token"}\'',
'transaction:create token transfer 100000000 --file=/txn_params.json',
'transaction:create token transfer 100000000 --file=/txn_params.json --json',
];
Expand Down Expand Up @@ -355,7 +355,7 @@ export abstract class CreateCommand extends Command {
}

if (flags.send) {
await SendCommand.run([encodedTransaction]);
await SendCommand.run([encodedTransaction, `--data-path=${this._dataPath}`], this.config);
}
}

Expand Down
Loading

0 comments on commit b43550e

Please sign in to comment.