UNPKG

@kadena/kadena-cli

Version:

Kadena CLI tool to interact with the Kadena blockchain (manage keys, transactions, etc.)

87 lines 3.11 kB
import { log } from '../../../utils/logger.js'; import { relativeToCwd } from '../../../utils/path.util.js'; import { TABLE_DEFAULT, createTable } from '../../../utils/table.js'; export async function printPlainKeys(plainKeys) { const hasLegacy = plainKeys.some((key) => key.legacy); const table = createTable({ head: hasLegacy ? ['Filename', 'Public Key', 'Legacy'] : ['Filename', 'Public Key'], }); if (plainKeys.length === 0) { log.warning('There are no key files in your working directory.'); log.warning('You can add one using:\n'); log.warning(' kadena key generate'); return; } for (const key of plainKeys) { const row = [key.alias, key.publicKey]; if (hasLegacy) row.push(key.legacy ? 'Yes' : 'No'); table.push(row); } log.info(`Listing keys in the working directory:`); if (table.length > 0) { log.output(table.toString(), plainKeys); } else { log.info('No valid keys found'); } } export async function printWalletKeys(wallet) { var _a, _b; if (!wallet) return; const table = createTable({ ...TABLE_DEFAULT, head: ['Alias', 'Index', 'Public key'], }); if (wallet.keys.length === 0) { log.info(`\nWallet: ${wallet.alias}${wallet.legacy ? ' (legacy)' : ''}`); return log.info('No keys'); } for (const key of wallet.keys) { table.push([ (_a = key.alias) !== null && _a !== void 0 ? _a : `N/A`, key.index.toString(), (_b = key.publicKey) !== null && _b !== void 0 ? _b : 'N/A', ]); } if (table.length > 0) { log.info(`\nWallet: ${wallet.alias}${wallet.legacy ? ' (legacy)' : ''}`); log.info(table.toString()); } else { log.info(`\nWallet: ${wallet.alias}${wallet.legacy ? ' (legacy)' : ''}`); log.info('No valid keys found'); } } /** * Prints the filenames of stored plain keys. * @param {IKeyPair[]} keyPairs - Array of plain key pairs */ export function printStoredPlainKeys(keyPairs) { if (keyPairs.length === 0) return; log.info(log.color.green('The Key Pair is stored in your working directory with the filename(s):')); log.info(keyPairs.map((key) => relativeToCwd(key.filepath)).join('\n')); } /** * Displays generated plain key pairs in a formatted manner. * @param {IPlainKey[]} keys - Array of plain key pairs. * @param {boolean} [legacy] - Optional flag to indicate if the keys are legacy keys. */ export function displayGeneratedPlainKeys(keys) { if (keys.length === 0) { log.info('Did not generate any keys.'); return; } const hasLegacy = keys.some((key) => key.legacy); log.info(log.color.green(hasLegacy ? 'Generated Legacy Plain Key Pair(s):' : 'Generated Plain Key Pair(s):')); log.info(log.color.green('Public key')); log.output(keys.map((key) => key.publicKey).join('\n'), keys.length === 1 ? keys[0] : keys); log.info(''); } //# sourceMappingURL=keysDisplay.js.map