Skip to content

Commit

Permalink
chore: added release-plz workflow to main and added fmt and clippy ch…
Browse files Browse the repository at this point in the history
…eck (#10)

* added workflow file
* fixed clippy
  • Loading branch information
akorchyn authored Jun 10, 2024
1 parent 986613c commit 1a86d58
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 37 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release-plz

permissions:
pull-requests: write
contents: write

on:
push:
branches:
- main

jobs:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_PLZ_GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
env:
# https://marcoieni.github.io/release-plz/github-action.html#triggering-further-workflow-runs
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
7 changes: 4 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: apt-get update
run: sudo apt-get update
- name: Install libudev
run: sudo apt-get -y install libudev-dev libsystemd-dev
- name: fmt
run: cargo fmt --all -- --check
- name: clippy
run: cargo clippy -- -D clippy::all
- name: Check
run: cargo check --verbose --examples
# this compiles doc examples
Expand Down
6 changes: 3 additions & 3 deletions examples/common/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn tx_template(
.parse::<CryptoHash>()
.unwrap();

let signer_account_str = hex::encode(&ledger_pub_key.to_bytes());
let signer_account_str = hex::encode(ledger_pub_key.to_bytes());
let receiver_account_str = "dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c";

near_primitives::transaction::Transaction {
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn batch_of_all_types_of_actions(
let mut bytes = vec![];
bytes.push(123u8);

bytes.extend((0..255).into_iter().collect::<Vec<_>>());
bytes.extend((0..255).collect::<Vec<_>>());

let f_call = FunctionCallAction {
method_name: "saturating_add_signed".to_string(),
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn display_and_verify_signature(
) {
let signature = display_signature(signature_bytes);
assert!(public_key
.verify(&CryptoHash::hash_bytes(&msg).as_ref(), &signature)
.verify(CryptoHash::hash_bytes(&msg).as_ref(), &signature)
.is_ok());
log::info!("---");
}
Expand Down
1 change: 0 additions & 1 deletion examples/get_version.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use env_logger;
use near_ledger::{get_version, NEARLedgerError};

fn main() -> Result<(), NEARLedgerError> {
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_nep_413_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn display_and_verify_signature(
log::info!("{:<20} : {}", "signature (hex)", signature);
log::info!("{:<20} : {}", "signature (base58)", signature_near);

assert!(public_key.verify(&hash.as_ref(), &signature).is_ok());
assert!(public_key.verify(hash.as_ref(), &signature).is_ok());
log::info!("---");
}

Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/add_key_fullaccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_ledger::NEARLedgerError;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);
let sk = SecretKey::from_seed(
near_crypto::KeyType::SECP256K1,
&format!("{:?}", ledger_pub_key),
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/add_key_functioncall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_ledger::NEARLedgerError;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);
let sk = SecretKey::from_seed(
near_crypto::KeyType::SECP256K1,
&format!("{:?}", ledger_pub_key),
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/batch_all_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use near_ledger::NEARLedgerError;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);
tx.actions = common::batch_of_all_types_of_actions(ledger_pub_key);
tx
}
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/delete_key_ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_ledger::NEARLedgerError;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);
let sk = SecretKey::from_seed(
near_crypto::KeyType::ED25519,
&format!("{:?}", ledger_pub_key),
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/delete_key_secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_ledger::NEARLedgerError;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);
let sk = SecretKey::from_seed(
near_crypto::KeyType::SECP256K1,
&format!("{:?}", ledger_pub_key),
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/functioncall_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_primitives::transaction::FunctionCallAction;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);

let args = hex::decode("204f6e206f6c646572207465726d696e616c732c2074686520756e64657273636f726520636f646520697320646973706c617965642061732061206c6566740a202020202020206172726f772c2063616c6c6564206261636b6172726f772c2074686520636172657420697320646973706c6179656420617320616e2075702d6172726f770a20202020202020616e642074686520766572746963616c2062617220686173206120686f6c6520696e20746865206d6964646c652e0a0a2020202020202055707065726361736520616e64206c6f77657263617365206368617261637465727320646966666572206279206a757374206f6e652062697420616e64207468650a20202020202020415343494920636861726163746572203220646966666572732066726f6d2074686520646f75626c652071756f7465206279206a757374206f6e65206269742c0a20202020202020746f6f2e202054686174206d616465206974206d7563682065617369657220746f20656e636f64652063686172616374657273206d656368616e6963616c6c790a202020202020206f7220776974682061206e6f6e2d6d6963726f636f6e74726f6c6c65722d626173656420656c656374726f6e6963206b6579626f61726420616e6420746861740a2020202020202070616972696e672077617320666f756e64206f6e206f6c642074656c6574797065732e0a").unwrap();

Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/functioncall_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_primitives::transaction::FunctionCallAction;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);

let args = r#"{"previous_vesting_schedule_with_salt":{"vesting_schedule":{"start_timestamp":"1577919600000000000","cliff_timestamp":"1609455600000000000","end_timestamp":"1704150000000000000"},"salt":"7bc709c22801118b743fae3866edb4dea1630a97ab9cd67e993428b94a0f397a"}, "vesting_schedule_with_salt":{"vesting_schedule":{"start_timestamp":"1577919600000000000","cliff_timestamp":"1609455600000000000","end_timestamp":"1704150000000000000"},"salt":"7bc709c22801118b743fae3866edb4dea1630a97ab9cd67e993428b94a0f397a"}}"#;

Expand Down
4 changes: 2 additions & 2 deletions examples/sign_transaction/functioncall_str_parse_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use near_primitives::transaction::FunctionCallAction;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);

let mut bytes = vec![];
bytes.push(123u8);

bytes.extend((0..255).into_iter().collect::<Vec<_>>());
bytes.extend((0..255).collect::<Vec<_>>());

let f_call = FunctionCallAction {
method_name: "saturating_add_signed".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_transaction/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_ledger::NEARLedgerError;
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key.clone());
let mut tx = common::tx_template(ledger_pub_key);
let sk = SecretKey::from_seed(
near_crypto::KeyType::SECP256K1,
&format!("{:?}", ledger_pub_key),
Expand Down
36 changes: 17 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const INS_GET_VERSION: u8 = 6; // Instruction code to get app version from the L
const INS_SIGN_TRANSACTION: u8 = 2; // Instruction code to sign a transaction on the Ledger
const INS_SIGN_NEP413_MESSAGE: u8 = 7; // Instruction code to sign a nep-413 message with Ledger
const INS_SIGN_NEP366_DELEGATE_ACTION: u8 = 8; // Instruction code to sign a nep-413 message with Ledger
const NETWORK_ID: u8 = 'W' as u8; // Instruction parameter 2
const NETWORK_ID: u8 = b'W'; // Instruction parameter 2
const RETURN_CODE_OK: u16 = 36864; // APDUAnswer.retcode which means success from Ledger
const CHUNK_SIZE: usize = 250; // Chunk size to be sent to Ledger

Expand Down Expand Up @@ -51,11 +51,10 @@ pub enum NEARLedgerError {
/// Converts BIP32Path into bytes (`Vec<u8>`)
fn hd_path_to_bytes(hd_path: &slip10::BIP32Path) -> Vec<u8> {
(0..hd_path.depth())
.map(|index| {
.flat_map(|index| {
let value = *hd_path.index(index).unwrap();
value.to_be_bytes()
})
.flatten()
.collect::<Vec<u8>>()
}

Expand All @@ -68,7 +67,7 @@ fn log_command(index: usize, is_last_chunk: bool, command: &APDUCommand<Vec<u8>>
} else {
format!(" ({})", index)
},
hex::encode(&command.serialize())
hex::encode(command.serialize())
);
}

Expand All @@ -79,7 +78,6 @@ fn log_command(index: usize, is_last_chunk: bool, command: &APDUCommand<Vec<u8>>
/// * A `Result` whose `Ok` value is an `NEARLedgerAppVersion` (just a `Vec<u8>` for now, where first value is a major version, second is a minor and the last is the path)
/// and whose `Err` value is a `NEARLedgerError` containing an error which occurred.
pub fn get_version() -> Result<NEARLedgerAppVersion, NEARLedgerError> {
//! Something
// instantiate the connection to Ledger
// will return an error if Ledger is not connected
let transport = get_transport()?;
Expand All @@ -91,7 +89,7 @@ pub fn get_version() -> Result<NEARLedgerAppVersion, NEARLedgerError> {
data: vec![],
};

log::info!("APDU in: {}", hex::encode(&command.serialize()));
log::info!("APDU in: {}", hex::encode(command.serialize()));

match transport.exchange(&command) {
Ok(response) => {
Expand All @@ -109,11 +107,11 @@ pub fn get_version() -> Result<NEARLedgerAppVersion, NEARLedgerError> {
let retcode = response.retcode();

let error_string = format!("Ledger APDU retcode: 0x{:X}", retcode);
return Err(NEARLedgerError::APDUExchangeError(error_string));
Err(NEARLedgerError::APDUExchangeError(error_string))
}
}
Err(err) => return Err(NEARLedgerError::LedgerHIDError(err)),
};
Err(err) => Err(NEARLedgerError::LedgerHIDError(err)),
}
}

/// Gets PublicKey from the Ledger on the given `hd_path`
Expand Down Expand Up @@ -184,7 +182,7 @@ pub fn get_public_key_with_display_flag(
p2: NETWORK_ID,
data: hd_path_bytes,
};
log::info!("APDU in: {}", hex::encode(&command.serialize()));
log::info!("APDU in: {}", hex::encode(command.serialize()));

match transport.exchange(&command) {
Ok(response) => {
Expand All @@ -197,16 +195,16 @@ pub fn get_public_key_with_display_flag(
// but doesn't mean our request succeeded
// we need to check it based on `response.retcode`
if response.retcode() == RETURN_CODE_OK {
return Ok(ed25519_dalek::PublicKey::from_bytes(&response.data()).unwrap());
return Ok(ed25519_dalek::PublicKey::from_bytes(response.data()).unwrap());
} else {
let retcode = response.retcode();

let error_string = format!("Ledger APDU retcode: 0x{:X}", retcode);
return Err(NEARLedgerError::APDUExchangeError(error_string));
Err(NEARLedgerError::APDUExchangeError(error_string))
}
}
Err(err) => return Err(NEARLedgerError::LedgerHIDError(err)),
};
Err(err) => Err(NEARLedgerError::LedgerHIDError(err)),
}
}

pub fn get_wallet_id(
Expand All @@ -226,7 +224,7 @@ pub fn get_wallet_id(
p2: NETWORK_ID,
data: hd_path_bytes,
};
log::info!("APDU in: {}", hex::encode(&command.serialize()));
log::info!("APDU in: {}", hex::encode(command.serialize()));

match transport.exchange(&command) {
Ok(response) => {
Expand All @@ -239,16 +237,16 @@ pub fn get_wallet_id(
// but doesn't mean our request succeeded
// we need to check it based on `response.retcode`
if response.retcode() == RETURN_CODE_OK {
return Ok(ed25519_dalek::PublicKey::from_bytes(&response.data()).unwrap());
return Ok(ed25519_dalek::PublicKey::from_bytes(response.data()).unwrap());
} else {
let retcode = response.retcode();

let error_string = format!("Ledger APDU retcode: 0x{:X}", retcode);
return Err(NEARLedgerError::APDUExchangeError(error_string));
Err(NEARLedgerError::APDUExchangeError(error_string))
}
}
Err(err) => return Err(NEARLedgerError::LedgerHIDError(err)),
};
Err(err) => Err(NEARLedgerError::LedgerHIDError(err)),
}
}

fn get_transport() -> Result<TransportNativeHID, NEARLedgerError> {
Expand Down

0 comments on commit 1a86d58

Please sign in to comment.