• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 15853103462

24 Jun 2025 02:21PM UTC coverage: 71.683% (-0.7%) from 72.398%
15853103462

push

github

web-flow
feat: offline signing (#7122)

Description
---

Adds the following features.

### CLI `--skip-recovery` option.

Cold wallets need to run in environments without Internet connection.
Console wallet created from seed words will require full initial
recovery to proceed with other functionality.
This switch allows to skip the recovery step.

### "prepare-one-sided-transaction-for-signing" CLI command

```sh
minotari_console_wallet prepare-one-sided-transaction-for-signing --output-file <unsigned_tx_file> <amount> <recipient_address>
```

Supposed to be run on _hot side_. This will create an unsigned
transaction request, which needs to be signed on cold side.

### "sign-one-sided-transaction" CLI command

```sh
minotari_console_wallet sign-one-sided-transaction --input-file <unsigned_tx_file> --output-file <signed_tx_file>
```

Supposed to be run on _cold side_. Signs the transaction using **private
spend key**.

### "broadcast-signed-one-sided-transaction" CLI command

```sh
minotari_console_wallet broadcast-signed-one-sided-transaction --input-file <signed_tx_file>
```

Supposed to be run on _hot side_. Broadcasts the signed transaction to
Tari network (mempool)

### GRPC methods to be run on _hot side_

* PrepareOneSidedTransactionForSigning
* BroadcastSignedOneSidedTransaction

Motivation and Context
---

Exchanges are requesting a way to have offline signing.
Basically, they want two wallets:
- a hot wallet, which uses view key and public spend key
- cold wallet with private spend key, not connected to internet

The signing process would look like follows.
1. Hot wallet is requested to create an unsigned transaction (from
recipient address and amount). There will be an option to use CLI to
create a file, which contains unsigned transaction
2. Unisigned transaction will be airgap transferred to cold wallet,
where it is signed via CLI. The output will be another file containing a
signed transaction
3. Signed transaction file is transferred to hot walle... (continued)

0 of 851 new or added lines in 9 files covered. (0.0%)

301 existing lines in 23 files now uncovered.

82846 of 115572 relevant lines covered (71.68%)

239176.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.62
/base_layer/core/src/proof_of_work/proof_of_work_algorithm.rs
1
// Copyright 2020. The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
use std::{
23
    convert::TryFrom,
24
    fmt::{Display, Formatter},
25
    str::FromStr,
26
};
27

28
use borsh::{BorshDeserialize, BorshSerialize};
29
use serde::{Deserialize, Serialize};
30

31
/// Indicates the algorithm used to mine a block
32
#[repr(u8)]
33
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Hash, Eq, BorshSerialize, BorshDeserialize)]
10,503✔
34
#[borsh(use_discriminant = true)]
35
pub enum PowAlgorithm {
36
    RandomXM = 0,
37
    Sha3x = 1,
38
    RandomXT = 2,
39
}
40

41
impl PowAlgorithm {
42
    /// Returns true if the PoW algorithm is merged mined monero RandomX
UNCOV
43
    pub fn is_merged_mined_randomx(&self) -> bool {
×
44
        matches!(self, Self::RandomXM)
×
45
    }
×
46

47
    /// Returns true if the PoW algorithm is solo tari RandomX
UNCOV
48
    pub fn is_tari_randomx(&self) -> bool {
×
49
        matches!(self, Self::RandomXT)
×
50
    }
×
51

52
    /// Returns true if the PoW algorithm is Sha3
UNCOV
53
    pub fn is_sha3(&self) -> bool {
×
54
        matches!(self, Self::Sha3x)
×
55
    }
×
56

57
    /// A convenience functions that returns the PoW algorithm as a u64
UNCOV
58
    pub fn as_u64(&self) -> u64 {
×
59
        *self as u64
×
60
    }
×
61
}
62

63
impl TryFrom<u64> for PowAlgorithm {
64
    type Error = String;
65

66
    fn try_from(v: u64) -> Result<Self, Self::Error> {
71✔
67
        match v {
71✔
UNCOV
68
            0 => Ok(PowAlgorithm::RandomXM),
×
69
            1 => Ok(PowAlgorithm::Sha3x),
71✔
UNCOV
70
            2 => Ok(PowAlgorithm::RandomXT),
×
UNCOV
71
            _ => Err("Invalid PoWAlgorithm".into()),
×
72
        }
73
    }
71✔
74
}
75

76
impl FromStr for PowAlgorithm {
77
    type Err = anyhow::Error;
78

79
    fn from_str(s: &str) -> Result<Self, Self::Err> {
21✔
80
        let s_trimmed = s.replace("\"", "").replace("\'", "").replace(" ", "").to_uppercase();
21✔
81
        match s_trimmed.as_str() {
21✔
82
            "RANDOMXM" | "RANDOM_XM" | "MONERO_RANDOM_X" | "RANDOMX" | "RANDOM_X" | "RANDOMXMONERO" => {
21✔
83
                Ok(Self::RandomXM)
7✔
84
            },
85
            "SHA" | "SHA3" | "SHA3X" => Ok(Self::Sha3x),
14✔
86
            "RANDOMXT" | "RANDOM_XT" | "TARI_RANDOM_X" | "RANDOMXTARI" => Ok(Self::RandomXT),
4✔
87
            _ => Err(anyhow::Error::msg(format!("Unknown pow algorithm type: {}", s))),
×
88
        }
89
    }
21✔
90
}
91

92
impl Display for PowAlgorithm {
93
    fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
1✔
94
        let algo = match self {
1✔
UNCOV
95
            PowAlgorithm::RandomXM => "RandomXMonero",
×
96
            PowAlgorithm::Sha3x => "Sha3",
1✔
UNCOV
97
            PowAlgorithm::RandomXT => "RandomXTari",
×
98
        };
99
        fmt.write_str(algo)
1✔
100
    }
1✔
101
}
102

103
#[cfg(test)]
104
mod tests {
105
    use serde_json;
106

107
    use super::*;
108

109
    #[test]
110
    fn test_pow_algorithm_from_str_variants() {
1✔
111
        // Test valid variants for RandomXM
1✔
112
        let randomxm_variants = vec![
1✔
113
            "RandomXM",
1✔
114
            "RandomX",
1✔
115
            "randomx",
1✔
116
            "random_x",
1✔
117
            "randomxm",
1✔
118
            "RANDOM_XM",
1✔
119
            "monero_random_x",
1✔
120
        ];
1✔
121
        for variant in randomxm_variants {
8✔
122
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse RandomXM variant");
7✔
123
            assert_eq!(algo, PowAlgorithm::RandomXM);
7✔
124
        }
125

126
        // Test valid variants for Sha3x
127
        let sha3x_variants = vec![
1✔
128
            "Sha3x",
1✔
129
            "\"Sha3x\"",
1✔
130
            "\'Sha3x\'",
1✔
131
            "Sha 3 x",
1✔
132
            "sha",
1✔
133
            "sha3",
1✔
134
            "SHA3",
1✔
135
            "sha3X",
1✔
136
            "Sha3X",
1✔
137
            "SHA3X",
1✔
138
        ];
1✔
139
        for variant in sha3x_variants {
11✔
140
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse Sha3x variant");
10✔
141
            assert_eq!(algo, PowAlgorithm::Sha3x);
10✔
142
        }
143

144
        // Test valid variants for RandomXT
145
        let randomxt_variants = vec!["RandomXT", "randomxt", "tari_random_x", "RANDOM_XT"];
1✔
146
        for variant in randomxt_variants {
5✔
147
            let algo = PowAlgorithm::from_str(variant).expect("Failed to parse RandomXT variant");
4✔
148
            assert_eq!(algo, PowAlgorithm::RandomXT);
4✔
149
        }
150
    }
1✔
151

152
    #[test]
153
    fn test_pow_algorithm_serialization() {
1✔
154
        for algo in [PowAlgorithm::Sha3x, PowAlgorithm::RandomXM, PowAlgorithm::RandomXT] {
3✔
155
            let serialized = serde_json::to_string(&algo).expect("Failed to serialize PowAlgorithm");
3✔
156
            let deserialized: PowAlgorithm =
3✔
157
                serde_json::from_str(&serialized).expect("Failed to deserialize PowAlgorithm");
3✔
158
            assert_eq!(deserialized, algo);
3✔
159
        }
160
    }
1✔
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc