Skip to content

Commit

Permalink
feat(iota)!: unordered optional IotaClientCommands::NewAddress argu…
Browse files Browse the repository at this point in the history
…ments (#4647)

* cli: unordered optional `IotaClientCommands::NewAddress` arguments

* optional key_scheme

* docs

* command doc

* Update docs/content/developer/dev-cheat-sheet.mdx

Co-authored-by: Thoralf-M <[email protected]>

---------

Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
thibault-martinez and Thoralf-M authored Jan 10, 2025
1 parent 7ad13e8 commit 5026687
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 64 deletions.
4 changes: 2 additions & 2 deletions crates/iota-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ See the programmable transactions [example](https://github.com/iotaledger/iota/b
1. [Connect to IOTA Devnet](https://docs.iota.org/developer/getting-started/connect).
1. [Make sure you have two addresses with gas](https://docs.iota.org/developer/getting-started/get-address) by using the `new-address` command to create new addresses:
```shell
iota client new-address ed25519
iota client new-address --key-scheme ed25519
```
You must specify the key scheme, one of `ed25519` or `secp256k1` or `secp256r1`.
You can specify the key scheme, one of `ed25519` or `secp256k1` or `secp256r1`.
You can skip this step if you are going to play with a friend. :)
1. [Request IOTA tokens](https://docs.iota.org/developer/getting-started/get-coins) for all addresses that will be used to join the game.

Expand Down
52 changes: 10 additions & 42 deletions crates/iota/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ pub enum IotaClientCommands {
/// not in production environments.
#[clap(hide = true)]
gas_price: Option<u64>,

#[clap(flatten)]
opts: OptsWithGas,
},
Expand Down Expand Up @@ -191,7 +190,6 @@ pub enum IotaClientCommands {
/// using --serialize-unsigned-transaction.
#[clap(long)]
tx_bytes: String,

/// A list of Base64 encoded signatures `flag || signature || pubkey`.
#[clap(long)]
signatures: Vec<String>,
Expand Down Expand Up @@ -236,18 +234,23 @@ pub enum IotaClientCommands {
#[clap(flatten)]
opts: OptsWithGas,
},
/// Generate new address and keypair with keypair scheme flag {ed25519 |
/// secp256k1 | secp256r1} with optional derivation path, default to
/// m/44'/4218'/0'/0'/0' for ed25519 or m/54'/4218'/0'/0/0 for secp256k1
/// or m/74'/4218'/0'/0/0 for secp256r1. Word length can be { word12 |
/// word15 | word18 | word21 | word24} default to word12 if not specified.
/// Generate new address and keypair with optional key scheme {ed25519 |
/// secp256k1 | secp256r1} which defaults to ed25519, optional alias which
/// defaults to a random one, optional word length { word12 | word15 |
/// word18 | word21 | word24} which defaults to word12, and optional
/// derivation path which defaults to m/44'/4218'/0'/0'/0' for ed25519,
/// m/54'/4218'/0'/0/0 for secp256k1 or m/74'/4218'/0'/0/0 for secp256r1.
#[clap(name = "new-address")]
NewAddress {
#[clap(long, default_value_t = SignatureScheme::ED25519)]
key_scheme: SignatureScheme,
/// The alias must start with a letter and can contain only letters,
/// digits, hyphens (-), or underscores (_).
#[clap(long)]
alias: Option<String>,
#[clap(long)]
word_length: Option<String>,
#[clap(long)]
derivation_path: Option<DerivationPath>,
},
/// Add new IOTA environment.
Expand All @@ -274,7 +277,6 @@ pub enum IotaClientCommands {
/// Object ID of the object to fetch
#[clap(name = "object_id")]
id: ObjectID,

/// Return the bcs serialized version of the object
#[clap(long)]
bcs: bool,
Expand All @@ -296,16 +298,13 @@ pub enum IotaClientCommands {
/// specified amounts.
#[clap(long, num_args(1..))]
input_coins: Vec<ObjectID>,

/// The recipient addresses, must be of same length as amounts.
/// Aliases of addresses are also accepted as input.
#[clap(long, num_args(1..))]
recipients: Vec<KeyIdentity>,

/// The amounts to be paid, following the order of recipients.
#[clap(long, num_args(1..))]
amounts: Vec<u64>,

#[clap(flatten)]
opts: OptsWithGas,
},
Expand All @@ -317,12 +316,10 @@ pub enum IotaClientCommands {
/// coin.
#[clap(long, num_args(1..))]
input_coins: Vec<ObjectID>,

/// The recipient address (or its alias if it's an address in the
/// keystore).
#[clap(long)]
recipient: KeyIdentity,

#[clap(flatten)]
opts: Opts,
},
Expand All @@ -335,16 +332,13 @@ pub enum IotaClientCommands {
/// coin.
#[clap(long, num_args(1..))]
input_coins: Vec<ObjectID>,

/// The recipient addresses, must be of same length as amounts.
/// Aliases of addresses are also accepted as input.
#[clap(long, num_args(1..))]
recipients: Vec<KeyIdentity>,

/// The amounts to be paid, following the order of recipients.
#[clap(long, num_args(1..))]
amounts: Vec<u64>,

#[clap(flatten)]
opts: Opts,
},
Expand All @@ -357,20 +351,16 @@ pub enum IotaClientCommands {
/// Path to directory containing a Move package
#[clap(name = "package_path", global = true, default_value = ".")]
package_path: PathBuf,

/// Package build options
#[clap(flatten)]
build_config: MoveBuildConfig,

#[clap(flatten)]
opts: OptsWithGas,

/// Publish the package without checking whether compiling dependencies
/// from source results in bytecode matching the dependencies
/// found on-chain.
#[clap(long)]
skip_dependency_verification: bool,

/// Also publish transitive dependencies that have not already been
/// published.
#[clap(long)]
Expand Down Expand Up @@ -417,11 +407,9 @@ pub enum IotaClientCommands {
/// Recipient address (or its alias if it's an address in the keystore)
#[clap(long)]
to: KeyIdentity,

/// ID of the object to transfer
#[clap(long)]
object_id: ObjectID,

#[clap(flatten)]
opts: OptsWithGas,
},
Expand All @@ -431,24 +419,19 @@ pub enum IotaClientCommands {
/// Path to directory containing a Move package
#[clap(name = "package_path", global = true, default_value = ".")]
package_path: PathBuf,

/// ID of the upgrade capability for the package being upgraded.
#[clap(long)]
upgrade_capability: ObjectID,

/// Package build options
#[clap(flatten)]
build_config: MoveBuildConfig,

#[clap(flatten)]
opts: OptsWithGas,

/// Publish the package without checking whether compiling dependencies
/// from source results in bytecode matching the dependencies
/// found on-chain.
#[clap(long)]
skip_dependency_verification: bool,

/// Also publish transitive dependencies that have not already been
/// published.
#[clap(long)]
Expand All @@ -461,19 +444,16 @@ pub enum IotaClientCommands {
/// current directory)
#[clap(name = "package", long, global = true)]
package_path: Option<PathBuf>,

/// Protocol version to use for the bytecode verifier (defaults to the
/// latest protocol version)
#[clap(name = "protocol-version", long)]
protocol_version: Option<u64>,

/// Paths to specific pre-compiled module bytecode to verify (instead of
/// an entire package). Multiple modules can be verified by
/// passing multiple --module flags. They will be treated as if
/// they were one package (subject to the overall package limit).
#[clap(name = "module", long, action = clap::ArgAction::Append, global = true)]
module_paths: Vec<PathBuf>,

/// Package build options
#[clap(flatten)]
build_config: MoveBuildConfig,
Expand All @@ -485,19 +465,15 @@ pub enum IotaClientCommands {
/// Path to directory containing a Move package
#[clap(name = "package_path", global = true, default_value = ".")]
package_path: PathBuf,

/// Package build options
#[clap(flatten)]
build_config: MoveBuildConfig,

/// Verify on-chain dependencies.
#[clap(long)]
verify_deps: bool,

/// Don't verify source (only valid if --verify-deps is enabled).
#[clap(long)]
skip_source: bool,

/// If specified, override the addresses for the package's own modules
/// with this address. Only works for unpublished modules (whose
/// addresses are currently 0x0).
Expand All @@ -513,7 +489,6 @@ pub enum IotaClientCommands {
/// The digest of the transaction to replay
#[arg(long, short)]
tx_digest: String,

/// If specified, overrides the filepath of the output profile, for
/// example -- /temp/my_profile_name.json will write output to
/// `/temp/my_profile_name_{tx_digest}_{unix_timestamp}.json` If
Expand All @@ -530,20 +505,16 @@ pub enum IotaClientCommands {
/// The digest of the transaction to replay
#[arg(long, short)]
tx_digest: String,

/// Log extra gas-related information
#[arg(long)]
gas_info: bool,

/// Log information about each programmable transaction command
#[arg(long)]
ptb_info: bool,

/// Optional version of the executor to use, if not specified defaults
/// to the one originally used for the transaction.
#[arg(long, short, allow_hyphen_values = true)]
executor_version: Option<i64>,

/// Optional protocol version to use, if not specified defaults to the
/// one originally used for the transaction.
#[arg(long, short, allow_hyphen_values = true)]
Expand All @@ -556,7 +527,6 @@ pub enum IotaClientCommands {
/// digest per line
#[arg(long, short)]
path: PathBuf,

/// If an error is encountered during a transaction, this specifies
/// whether to terminate or continue
#[arg(long, short)]
Expand All @@ -569,12 +539,10 @@ pub enum IotaClientCommands {
/// to replay
#[arg(long, short)]
start: u64,

/// The ending checkpoint sequence number of the range of checkpoints to
/// replay
#[arg(long, short)]
end: u64,

/// If an error is encountered during a transaction, this specifies
/// whether to terminate or continue
#[arg(long, short)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ To implement multisig for moderators, follow these steps:
Each moderator requires a unique key and corresponding IOTA address. To generate these keys and addresses, you can use any of the following key types: `ed25519`, `secp256k1`, or `secp256r1`. Use the following commands to create a key and address for each moderator:

```shell
iota client new-address ed25519
iota client new-address secp256k1
iota client new-address secp256r1
iota client new-address --key-scheme ed25519
iota client new-address --key-scheme secp256k1
iota client new-address --key-scheme secp256r1
```
### 2. Add Keys to IOTA Keystore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const address = keypair.getPublicKey().toIotaAddress();

```shell
iota keytool import "TEST_MNEMONIC" ed25519 "m/44'/4218'/0'/0'/0'"
iota client new-address ed25519 "m/44'/4218'/0'/0'/0'"
iota client new-address --key-scheme ed25519 --derivation-path "m/44'/4218'/0'/0'/0'"
```

</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Use the following command to generate a IOTA address and key for each supported
Use `iota client` to create IOTA addresses of different key schemes.

```shell
iota client new-address ed25519
iota client new-address secp256k1
iota client new-address secp256r1
iota client new-address --key-scheme ed25519
iota client new-address --key-scheme secp256k1
iota client new-address --key-scheme secp256r1
```

### Step 2: Add keys to IOTA keystore
Expand Down
2 changes: 1 addition & 1 deletion docs/content/developer/dev-cheat-sheet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Quick reference on best practices for IOTA Network developers.
|`cargo install --locked --git https://github.com/iotaledger/iota.git --branch <BRANCH-NAME> --features gas-profiler iota`|To get the latest version of CLI|
|`iota client active-address`|to get the current address.|
|`iota client -–help`|to list out all commands of iota client.|
|`iota client new-address <Scheme> Scheme`|to generate address , **Scheme** - (ed25519,secp256k1,secp256r1)|
|`iota client new-address --key-scheme <Scheme>`|to generate address, **Scheme** - (ed25519,secp256k1,secp256r1)|

## Move

Expand Down
2 changes: 1 addition & 1 deletion docs/content/developer/getting-started/get-address.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Please write down the recovery phrase associated with your address and keep it i
#### Generate Address

You can use the [IOTA Client CLI](../../references/cli/client.mdx) to generate any number of addresses by using
the `iota client new-address <AddressType>`, where `<AddresType>` is one of the following:
the `iota client new-address --key-scheme <KeyScheme>`, where `<KeyScheme>` is one of the following:

* `ed25519`
* `secp256k1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ You can initialize a key in three ways:

```shell
# generate randomly.
iota client new-address ed25519
iota client new-address secp256k1
iota client new-address secp256r1
iota client new-address --key-scheme ed25519
iota client new-address --key-scheme secp256k1
iota client new-address --key-scheme secp256r1

# import the 32-byte private key to keystore.
iota keytool import "0xd463e11c7915945e86ac2b72d88b8190cfad8ff7b48e7eb892c275a5cf0a3e82" ed25519
Expand Down
4 changes: 2 additions & 2 deletions docs/content/references/cli/cheatsheet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ The cheat sheet highlights common IOTA CLI commands.
<td class="w-1/3">List the addresses, their aliases, and the active address</td>
</tr>
<tr>
<td class="w-2/3">`iota client new-address ed25519`</td>
<td class="w-2/3">`iota client new-address --key-scheme ed25519`</td>
<td class="w-1/3">Create a new address with ED25519 scheme</td>
</tr>
<tr>
<td class="w-2/3">`iota client new-address ed25519 MY_ALIAS`</td>
<td class="w-2/3">`iota client new-address --key-scheme ed25519 --alias MY_ALIAS`</td>
<td class="w-1/3">Create a new address with ED25519 scheme and alias</td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions docs/content/references/cli/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Commands:
faucet Request gas coin from faucet. By default, it will use the active address and the active network
gas Obtain all gas objects owned by the address. An address' alias can be used instead of the address
merge-coin Merge two coin objects into one coin
new-address Generate new address and keypair with keypair scheme flag {ed25519 | secp256k1 | secp256r1} with optional derivation path, default to m/44'/4218'/0'/0'/0' for ed25519 or m/54'/4218'/0'/0/0
for secp256k1 or m/74'/4218'/0'/0/0 for secp256r1. Word length can be { word12 | word15 | word18 | word21 | word24} default to word12 if not specified
new-address Generate new address and keypair with optional key scheme {ed25519 | secp256k1 | secp256r1} which defaults to ed25519, optional alias which defaults to a random one, optional word length { word12 | word15 | word18 | word21 |
word24} which defaults to word12, and optional derivation path which defaults to m/44'/4218'/0'/0'/0' for ed25519, m/54'/4218'/0'/0/0 for secp256k1 or m/74'/4218'/0'/0/0 for secp256r1
new-env Add new IOTA environment
object Get object info
objects Obtain all objects owned by the address. It also accepts an address by its alias
Expand Down
2 changes: 1 addition & 1 deletion sdk/create-dapp/templates/react-e2e-counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you haven't set up an address in the iota client yet, you can use the
following command to get a new address:

```bash
iota client new-address secp256k1
iota client new-address --key-scheme secp256k1
```

This well generate a new address and recover phrase for you. You can mark a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Ed25519PublicKey } from '../../../src/keypairs/ed25519';

// Test case generated against CLI:
// cargo build --bin iota
// ../iota/target/debug/iota client new-address ed25519
// ../iota/target/debug/iota client new-address --key-scheme ed25519
// ../iota/target/debug/iota keytool list
const TEST_CASES = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { INVALID_SECP256K1_PUBLIC_KEY, VALID_SECP256K1_PUBLIC_KEY } from './secp

// Test case generated against CLI:
// cargo build --bin iota
// ../iota/target/debug/iota client new-address secp256k1
// ../iota/target/debug/iota client new-address --key-scheme secp256k1
// ../iota/target/debug/iota keytool list
const TEST_CASES = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { INVALID_SECP256R1_PUBLIC_KEY, VALID_SECP256R1_PUBLIC_KEY } from './secp

// Test case generated against CLI:
// cargo build --bin iota
// ../iota/target/debug/iota client new-address secp256r1
// ../iota/target/debug/iota client new-address --key-scheme secp256r1
// ../iota/target/debug/iota keytool list
const TEST_CASES = [
{
Expand Down

0 comments on commit 5026687

Please sign in to comment.