From 67eb3173217726873ea053f3bb872ea83a66afcb Mon Sep 17 00:00:00 2001 From: gagdiez Date: Tue, 19 Mar 2024 13:13:13 +0100 Subject: [PATCH 1/5] fix: added message for Ledger users --- utils/connect.js | 2 ++ utils/ledger.js | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/connect.js b/utils/connect.js index 16d8da28..552d0e27 100644 --- a/utils/connect.js +++ b/utils/connect.js @@ -1,10 +1,12 @@ const { connect: nearConnect } = require('near-api-js'); const { getConfig } = require('../config'); const { getPublicKeyForPath, signForPath } = require('./ledger'); +const chalk = require('chalk'); module.exports = async function connect({ keyStore, ...options }) { // If using Ledger, override the signer so that it uses the Ledger device if (options.signWithLedger) { + console.log(chalk`\nUsing Ledger with path {blue ${options.ledgerPath}}, change path with {blue --ledgerPath}\n`); options.signer = { getPublicKey: () => getPublicKeyForPath(options.ledgerPath), signMessage: (m) => signForPath(m, options.ledgerPath) diff --git a/utils/ledger.js b/utils/ledger.js index caccb13d..ba9ec453 100644 --- a/utils/ledger.js +++ b/utils/ledger.js @@ -18,10 +18,12 @@ async function getPublicKeyForPath(hdKeyPath) { // cache keys to avoid confirming on Ledger multiple times if (cachedPublicKeys[hdKeyPath]) return cachedPublicKeys[hdKeyPath]; + console.log('Trying to connect with Ledger...'); + transport = await TransportNodeHid.create(); client = await createClient(transport); - console.log('Getting Public Key from Ledger...'); + console.log('Getting public key from Ledger...'); try { const rawPublicKey = await client.getPublicKey(hdKeyPath); From f2033613ce99b3583cba455911c91eed55a2166b Mon Sep 17 00:00:00 2001 From: gagdiez Date: Tue, 19 Mar 2024 13:29:17 +0100 Subject: [PATCH 2/5] chore: update changelog & readme --- CHANGELOG.md | 6 ++++++ README.md | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 381ffce6..ab396e7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ ## [unreleased] - ... +## `4.0.12` [03-19-2024] +- New: Added back Ledger support, please notice that the `--useLedger` does not set the path anymore, use `--ledgerPath` for this. +- New: Added back all `validator` commands. +- New: Added `add-credentials` command to add credentials to the `near-cli` config file. +- Fixes: Multitude of small fixes, see each release note for more details. + ## `4.0.0` [01-23-2024] - Reorganized code to simplify its maintenance. - New: Fixed `create-account` can now create `TLA`, `sub-accounts` and `.testnet/.near` accounts. diff --git a/README.md b/README.md index 68b9797c..fd853e03 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,26 @@ # NEAR CLI (command line interface) -[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/near/near-cli) - NEAR CLI is a Node.js application that relies on [`near-api-js`](https://github.com/near/near-api-js) to connect to and interact with the NEAR blockchain. Create accounts, access keys, sign & send transactions with this versatile command line interface tool. **Note:** Node.js version 16+ is required to run NEAR CLI. +## 🚨 v4.0.0 Notes +This release is a major reorganization of the codebase to simplify its maintenance. It also includes a few new features and a multitude of small fixes. + +The most notable changes are: +- **Ledger users**, please notice that the `--useLedger` does not set the path anymore, use `--ledgerPath` for this + - Please check the commands that support Ledger for more details +- Users can now import credentials using the `add-credentials` command +- The `generate-key` command now has a `--saveImplicit` option to save the key as an implicit account +- Users can create `testnet` pre-funded accounts using the `--useFaucet` option +- Accounts cannot create `TLA` with less than 32 characters anymore (this is a NEAR protocol change) +- Removed unnecessary options from commands, e.g. `view` now does not take an `--accountId` or `--masterAccount` +- If a command does not work, please first check the commands help to see if the options have changed + - For example, run `near create-account` to see how options might have changed + ## Release notes -**Release notes and unreleased changes can be found in the [CHANGELOG](CHANGELOG.md)** +Release notes and unreleased changes can be found in the [CHANGELOG](CHANGELOG.md) ## Overview @@ -37,7 +49,6 @@ _Click on a command for more information and examples._ | **TRANSACTIONS** | | | [`near tx-status`](#near-tx-status) | queries a transaction's status by `txHash` | - --- ## Setup @@ -111,6 +122,9 @@ export NEAR_NETWORK=mainnet near send-near ... --networkId mainnet ``` +> [!WARNING] +> In previous versions, `near-cli` used `NEAR_ENV` to set the network. This can still be used, but `NEAR_NETWORK` has priority over `NEAR_ENV` if both are set. + --- ### Custom RPC server selection @@ -123,7 +137,7 @@ Clear them in case you want to get back to the default RPC server. Example: ```bash -export NEAR_TESTNET_RPC= +export NEAR_TESTNET_RPC=https://rpc.testnet.near.org ``` --- From 96d09783ee1f6c3deb14b0239277722b0f2f5a6b Mon Sep 17 00:00:00 2001 From: gagdiez Date: Tue, 19 Mar 2024 13:30:14 +0100 Subject: [PATCH 3/5] Release 4.0.12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f65d07af..3e1abd8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "near-cli", - "version": "4.0.11", + "version": "4.0.12", "description": "Simple CLI for interacting with NEAR Protocol", "engines": { "node": ">= 16" From d7dd7d4492447cf869cea24798a35e5ba95c29c5 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Wed, 20 Mar 2024 13:03:21 +0100 Subject: [PATCH 4/5] fix: warning when passing path on ledger flag --- bin/near-cli.js | 3 ++- middleware/retro-ledger.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 middleware/retro-ledger.js diff --git a/bin/near-cli.js b/bin/near-cli.js index c757c20c..9f5d469a 100644 --- a/bin/near-cli.js +++ b/bin/near-cli.js @@ -5,8 +5,9 @@ yargs // eslint-disable-line .strict() .scriptName('near') .middleware(require('../utils/check-version')) - .middleware(require('../middleware/print-options')) .middleware(require('../middleware/key-store')) + .middleware(require('../middleware/retro-ledger')) + .middleware(require('../middleware/print-options')) .command(require('../commands/credentials/add')) .command(require('../commands/keys/add')) .command(require('../commands/contract/call')) diff --git a/middleware/retro-ledger.js b/middleware/retro-ledger.js new file mode 100644 index 00000000..66acd6e9 --- /dev/null +++ b/middleware/retro-ledger.js @@ -0,0 +1,16 @@ +// In v3.5.0 the argument `useLedgerKey` was a string, in v4.0.0 this was change to a boolean +// Sadly, yargs assumes that --useLedgerKey='anything' is FALSE +// Here we detect if an argument is `useLedgerKey=` and guide the user to the correct format + +module.exports = async function ledgerOptions() { + let path = ''; + + process.argv.forEach(arg => { + path = arg.includes('--useLedgerKey=') ? arg.split('=')[1] : path; + }); + + if (path != '') { + console.log(`\nPlease use --useLedgerKey --ledgerPath="${path}" instead of --useLedgerKey="${path}"\n`); + process.exit(0); + } +}; \ No newline at end of file From e730777b7eaaef7897a8ddae5f0a0375c050fff7 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Wed, 20 Mar 2024 13:13:02 +0100 Subject: [PATCH 5/5] Release 4.0.13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e1abd8a..a7ec2d8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "near-cli", - "version": "4.0.12", + "version": "4.0.13", "description": "Simple CLI for interacting with NEAR Protocol", "engines": { "node": ">= 16"