Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign offline #209

Merged
merged 52 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8b54398
start (draft)
May 30, 2023
e583830
start (draft)
May 30, 2023
2eadc03
Merge branch 'sign-offline' of https://github.com/near/near-cli-rs in…
May 31, 2023
5378180
draft
May 31, 2023
47a4e83
fixed GlobalContext
May 31, 2023
3df29dc
draft
May 31, 2023
97bea23
added offline mode for tokens commands
May 31, 2023
006a47b
added offline mode for sign_with...
May 31, 2023
4fc49ba
added offline mode for sign_with..keychain (draft)
May 31, 2023
7369c2b
added offline mode for network... (draft)
May 31, 2023
4a5aac1
added offline mode for sign-with-keychain
Jun 1, 2023
c979e2a
fixed
Jun 1, 2023
dab0ac0
added SignLater
Jun 1, 2023
b078139
draft (Account)
Jun 2, 2023
57d3476
fixed
Jun 2, 2023
bff5d00
added offline mode for creating account
Jun 2, 2023
789d0c3
clippy
Jun 2, 2023
3c81e66
refactored
Jun 2, 2023
13ad4cd
fmt
Jun 2, 2023
90745f7
added offline mode for DeleteAccount
Jun 2, 2023
5c4869e
Merge branch 'master' into sign-offline
FroVolod Jun 2, 2023
7245c50
fixed
Jun 2, 2023
44daac9
added offline mode for AddKey
Jun 2, 2023
88b8b0e
added offline mode for DeleteKey
Jun 2, 2023
90dc245
added offline mode for ManageStorageDeposit
Jun 2, 2023
89f7f8e
updated interactive_clap
Jun 2, 2023
402f505
updated interactive_clap
Jun 2, 2023
14bd8c2
refactored GlobalContext
Jun 4, 2023
aee2e7f
types::BlockHeight instead of primitive u64
Jun 4, 2023
f2cfc80
wrap_err instead unwrap
Jun 4, 2023
4e117f5
refactored SignKeychain
Jun 4, 2023
02bc5bb
Merge branch 'master' into sign-offline
FroVolod Jun 4, 2023
96146ee
updated Config
Jun 4, 2023
21e9ea2
updated Contract
Jun 4, 2023
5af7623
fixed
Jun 4, 2023
230b07a
updated Transaction
Jun 4, 2023
ac759fa
added Debug for contexts
Jun 4, 2023
a3b955b
fixed
Jun 4, 2023
41ed380
Update src/main.rs
FroVolod Jun 4, 2023
c7905b8
Update src/commands/account/storage_management/mod.rs
FroVolod Jun 4, 2023
f0fc968
Update src/commands/account/delete_account/mod.rs
FroVolod Jun 4, 2023
0ba8da3
Update src/commands/account/delete_account/mod.rs
FroVolod Jun 4, 2023
98f4cc7
fixed
Jun 4, 2023
1f34de6
fixed
Jun 4, 2023
75a7681
draft
Jun 5, 2023
17057ec
fixed input_beneficiary_account_id()
Jun 5, 2023
d5f50cd
refactored input_beneficiary_id()
Jun 5, 2023
7fe07cc
fixed
Jun 5, 2023
1ac949a
added offline mode for SignMacosKeychain
Jun 5, 2023
31741f0
updated GUID
Jun 5, 2023
e0ab114
fixed
Jun 5, 2023
659f18d
fixed
Jun 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ near-primitives = "0.16.1"
near-jsonrpc-client = "0.5.1"
near-jsonrpc-primitives = "0.16.1"

interactive-clap = "0.2.2"
interactive-clap-derive = "0.2.2"
interactive-clap = "0.2.4"
interactive-clap-derive = "0.2.4"

[target.'cfg(target_os = "macos")'.dependencies]
security-framework = "2.7.0"
Expand Down
16 changes: 15 additions & 1 deletion docs/GUIDE.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ overview of its capabilities. This guide assumes that _near CLI_ is
[installed](README.md#installation)
and that readers have passing familiarity with using command line tools. This
also assumes a Unix-like system, although most commands are probably easily
translatable to any command line shell environment.
translatable to any command line shell environment.

With _near CLI_ you can create, sign and send transactions in _online_ mode, which is enabled by default.
In _offline_ mode, you can create and sign a transaction. The base64 encoding transaction can be sent later (even from another computer). To enter the _offline_ mode, you need to set the ```--offline``` flag in the command:
```txt
near --offline tokens \
fro_volod.testnet \
send-near volodymyr.testnet 0.1NEAR \
network-config testnet \
sign-later
```

Before proceeding to the description of specific commands, it is necessary to consider two points common to these commands:

Expand Down Expand Up @@ -49,6 +59,10 @@ Before proceeding to the description of specific commands, it is necessary to co

When choosing this signature option, _near CLI_ will ask the user to enter the mnemonic phrase associated with the account.

- _sign-later - Prepare unsigned transaction (we'll use base64 encoding to simplify copy-pasting)_

This option involves signing the created transaction later.

2. Actions with a signed transaction

_near CLI_ support for meta transactions as specified in [NEP-366](https://near.github.io/nearcore/architecture/how/meta-tx.html#meta-transactions). To create it, you just need to specify a _network_ that supports meta transactions. You can find out about such support in [config](#show-connections---Show-a-list-of-network-connections). The *meta_transaction_relayer_url* field is responsible for the ability to support meta transactions. For example:
Expand Down
17 changes: 15 additions & 2 deletions docs/GUIDE.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
Это руководство предназначено для того, чтобы дать подробное описание утилиты _near CLI_ и
обзор её возможностей. Предполагается, что утилита _near CLI_
[установлена](README.ru.md#installation)
и пользователи знакомы с использованием инструментов командной строки. Также предполагается Unix-подобная система, хотя большинство команд, вероятно, легко
переводимы в любую среду оболочки командной строки.
и пользователи знакомы с использованием инструментов командной строки. Также предполагается Unix-подобная система, хотя большинство команд, вероятно, легко переводимы в любую среду оболочки командной строки.

Спомощью _near CLI_ можно создать, подписать и отправить транзакцию в режиме _online_, который включен по умолчанию.
В режиме _offline_ можно создать и подписать транзакцию. Транзакция, кодированная в base64 может быть отправлена позже (даже с другого компьютера). Для входа в режим _offline_ необходимо в команде установить флаг ```--offline```:
```txt
near --offline tokens \
fro_volod.testnet \
send-near volodymyr.testnet 0.1NEAR \
network-config testnet \
sign-later
```

Прежде, чем перейти к описанию конкретных команд, необходимо рассмотреть два общих для этих команд пункта:

Expand Down Expand Up @@ -47,6 +56,10 @@

При выборе этого варианта подписи _near CLI_ попросит пользователя ввести мнемоническую фразу, связанную с аккаунтом.

- _sign-later - Prepare unsigned transaction (we'll use base64 encoding to simplify copy-pasting)_

Этот вариант предполагает подписание созданной транзакции позже.

2. Действия с подписанной транзакцией

_near CLI_ поддерживает мета-транзакции, описанные в спецификации [NEP-366](https://near.github.io/nearcore/architecture/how/meta-tx.html#meta-transactions). Для её создания достаточно указать _network_, поддерживающую мета-транзакции. Узнать о такой поддержке можно в [конфигурационном файле](#show-connections---Show-a-list-of-network-connections). За возможность поддержки мета-транзакции отвечает поле *meta_transaction_relayer_url*. Например:
Expand Down
14 changes: 7 additions & 7 deletions src/commands/account/add_key/access_key_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use inquire::{CustomType, Select, Text};

#[derive(Debug, Clone)]
pub struct AccessTypeContext {
pub config: crate::config::Config,
pub global_context: crate::GlobalContext,
pub signer_account_id: near_primitives::types::AccountId,
pub permission: near_primitives::account::AccessKeyPermission,
}
Expand All @@ -19,7 +19,7 @@ pub struct FullAccessType {

#[derive(Debug, Clone)]
pub struct FullAccessTypeContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
}
Expand All @@ -30,7 +30,7 @@ impl FullAccessTypeContext {
_scope: &<FullAccessType as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.owner_account_id.into(),
permission: near_primitives::account::AccessKeyPermission::FullAccess,
})
Expand All @@ -40,7 +40,7 @@ impl FullAccessTypeContext {
impl From<FullAccessTypeContext> for AccessTypeContext {
fn from(item: FullAccessTypeContext) -> Self {
Self {
config: item.config,
global_context: item.global_context,
signer_account_id: item.signer_account_id,
permission: item.permission,
}
Expand All @@ -67,7 +67,7 @@ pub struct FunctionCallType {

#[derive(Debug, Clone)]
pub struct FunctionCallTypeContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
allowance: Option<crate::common::NearBalance>,
receiver_account_id: crate::types::account_id::AccountId,
Expand All @@ -80,7 +80,7 @@ impl FunctionCallTypeContext {
scope: &<FunctionCallType as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.owner_account_id.into(),
allowance: scope.allowance.clone(),
receiver_account_id: scope.receiver_account_id.clone(),
Expand All @@ -92,7 +92,7 @@ impl FunctionCallTypeContext {
impl From<FunctionCallTypeContext> for AccessTypeContext {
fn from(item: FunctionCallTypeContext) -> Self {
Self {
config: item.config,
global_context: item.global_context,
signer_account_id: item.signer_account_id,
permission: near_primitives::account::AccessKeyPermission::FunctionCall(
near_primitives::account::FunctionCallPermission {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/account/add_key/autogenerate_new_keypair/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct GenerateKeypair {

#[derive(Debug, Clone)]
pub struct GenerateKeypairContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
key_pair_properties: crate::common::KeyPairProperties,
Expand All @@ -32,7 +32,7 @@ impl GenerateKeypairContext {
crate::common::generate_keypair()?;
let public_key = near_crypto::PublicKey::from_str(&key_pair_properties.public_key_str)?;
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.signer_account_id,
permission: previous_context.permission,
key_pair_properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct PrintKeypairToTerminal {

#[derive(Debug, Clone)]
pub struct PrintKeypairToTerminalContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
key_pair_properties: crate::common::KeyPairProperties,
Expand All @@ -22,7 +22,7 @@ impl PrintKeypairToTerminalContext {
_scope: &<PrintKeypairToTerminal as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.signer_account_id,
permission: previous_context.permission,
key_pair_properties: previous_context.key_pair_properties,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl From<PrintKeypairToTerminalContext> for crate::commands::ActionContext {
})
});
Self {
config: item.config,
global_context: item.global_context,
on_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct SaveKeypairToKeychain {

#[derive(Debug, Clone)]
pub struct SaveKeypairToKeychainContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
key_pair_properties: crate::common::KeyPairProperties,
Expand All @@ -24,7 +24,7 @@ impl SaveKeypairToKeychainContext {
_scope: &<SaveKeypairToKeychain as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.signer_account_id,
permission: previous_context.permission,
key_pair_properties: previous_context.key_pair_properties,
Expand All @@ -35,7 +35,7 @@ impl SaveKeypairToKeychainContext {

impl From<SaveKeypairToKeychainContext> for crate::commands::ActionContext {
fn from(item: SaveKeypairToKeychainContext) -> Self {
let credentials_home_dir = item.config.credentials_home_dir.clone();
let credentials_home_dir = item.global_context.config.credentials_home_dir.clone();

let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
std::sync::Arc::new(move |_network_config| {
Expand Down Expand Up @@ -76,7 +76,7 @@ impl From<SaveKeypairToKeychainContext> for crate::commands::ActionContext {
);

Self {
config: item.config,
global_context: item.global_context,
on_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl From<SaveKeypairToMacosKeychainContext> for crate::commands::ActionContext
},
);
Self {
config: item.0.config,
global_context: item.0.global_context,
on_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/account/add_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct AddKeyCommand {

#[derive(Debug, Clone)]
pub struct AddKeyCommandContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
owner_account_id: crate::types::account_id::AccountId,
}

Expand All @@ -29,7 +29,7 @@ impl AddKeyCommandContext {
scope: &<AddKeyCommand as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
config: previous_context.0,
global_context: previous_context,
owner_account_id: scope.owner_account_id.clone(),
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/account/add_key/use_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct AddLedgerKeyAction {

#[derive(Debug, Clone)]
pub struct AddLedgerKeyActionContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
public_key: crate::types::public_key::PublicKey,
Expand Down Expand Up @@ -38,7 +38,7 @@ impl AddLedgerKeyActionContext {
));

Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.signer_account_id,
permission: previous_context.permission,
public_key: public_key.into(),
Expand All @@ -65,7 +65,7 @@ impl From<AddLedgerKeyActionContext> for crate::commands::ActionContext {
})
});
Self {
config: item.config,
global_context: item.global_context,
on_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct AddAccessWithSeedPhraseAction {

#[derive(Debug, Clone)]
pub struct AddAccessWithSeedPhraseActionContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
public_key: near_crypto::PublicKey,
Expand All @@ -30,7 +30,7 @@ impl AddAccessWithSeedPhraseActionContext {
&scope.master_seed_phrase,
)?;
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.signer_account_id,
permission: previous_context.permission,
public_key,
Expand All @@ -57,7 +57,7 @@ impl From<AddAccessWithSeedPhraseActionContext> for crate::commands::ActionConte
})
});
Self {
config: item.config,
global_context: item.global_context,
on_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
Expand Down
6 changes: 3 additions & 3 deletions src/commands/account/add_key/use_public_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct AddAccessKeyAction {

#[derive(Debug, Clone)]
pub struct AddAccessKeyActionContext {
config: crate::config::Config,
global_context: crate::GlobalContext,
signer_account_id: near_primitives::types::AccountId,
permission: near_primitives::account::AccessKeyPermission,
public_key: crate::types::public_key::PublicKey,
Expand All @@ -23,7 +23,7 @@ impl AddAccessKeyActionContext {
scope: &<AddAccessKeyAction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
Ok(Self {
config: previous_context.config,
global_context: previous_context.global_context,
signer_account_id: previous_context.signer_account_id,
permission: previous_context.permission,
public_key: scope.public_key.clone(),
Expand All @@ -50,7 +50,7 @@ impl From<AddAccessKeyActionContext> for crate::commands::ActionContext {
})
});
Self {
config: item.config,
global_context: item.global_context,
on_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SaveWithUseAutoGenerationContext {
}
});
Ok(Self(super::SaveImplicitAccountContext {
config: previous_context.0,
config: previous_context.config,
on_after_getting_folder_path_callback,
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl SaveWithLedgerContext {
}
});
Ok(Self(super::SaveImplicitAccountContext {
config: previous_context.0,
config: previous_context.config,
on_after_getting_folder_path_callback,
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl SaveWithSeedPhraseContext {
}
});
Ok(Self(super::SaveImplicitAccountContext {
config: previous_context.0,
config: previous_context.config,
on_after_getting_folder_path_callback,
}))
}
Expand Down
Loading