-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add authenticate message to account actor
- Loading branch information
Showing
4 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2019-2022 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use fvm_ipld_encoding::tuple::*; | ||
use fvm_ipld_encoding::{serde_bytes, Cbor}; | ||
|
||
#[derive(Debug, Serialize_tuple, Deserialize_tuple)] | ||
pub struct AuthenticateMessageParams { | ||
#[serde(with = "serde_bytes")] | ||
pub signature: Vec<u8>, | ||
#[serde(with = "serde_bytes")] | ||
pub message: Vec<u8>, | ||
} | ||
|
||
impl Cbor for AuthenticateMessageParams {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use fil_actor_account::types::AuthenticateMessageParams; | ||
use fil_actor_account::Method::AuthenticateMessage; | ||
use fvm_ipld_blockstore::MemoryBlockstore; | ||
use fvm_ipld_encoding::RawBytes; | ||
use fvm_shared::bigint::Zero; | ||
use fvm_shared::econ::TokenAmount; | ||
use fvm_shared::error::ExitCode; | ||
use test_vm::util::{apply_code, apply_ok, create_accounts, generate_deal_proposal}; | ||
use test_vm::{TEST_VM_INVALID, VM}; | ||
|
||
// Using a deal proposal as a serialized message, we confirm that: | ||
// - calls to authenticate_message with valid signatures succeed | ||
// - calls to authenticate_message with invalid signatures fail | ||
#[test] | ||
fn account_authenticate_message() { | ||
let store = MemoryBlockstore::new(); | ||
let v = VM::new_with_singletons(&store); | ||
let addr = create_accounts(&v, 1, TokenAmount::from(10_000e18 as i128))[0]; | ||
|
||
let proposal = | ||
generate_deal_proposal(addr, addr, TokenAmount::zero(), TokenAmount::zero(), 0, 0); | ||
let proposal_ser = | ||
RawBytes::serialize(proposal).expect("failed to marshal deal proposal").to_vec(); | ||
|
||
// With a good sig, message succeeds | ||
let authenticate_message_params = AuthenticateMessageParams { | ||
signature: proposal_ser.clone(), | ||
message: proposal_ser.clone(), | ||
}; | ||
apply_ok( | ||
&v, | ||
addr, | ||
addr, | ||
TokenAmount::zero(), | ||
AuthenticateMessage as u64, | ||
authenticate_message_params, | ||
); | ||
|
||
// Bad, bad sig! message fails | ||
let authenticate_message_params = AuthenticateMessageParams { | ||
signature: TEST_VM_INVALID.as_bytes().to_vec(), | ||
message: proposal_ser, | ||
}; | ||
apply_code( | ||
&v, | ||
addr, | ||
addr, | ||
TokenAmount::zero(), | ||
AuthenticateMessage as u64, | ||
authenticate_message_params, | ||
ExitCode::USR_ILLEGAL_ARGUMENT, | ||
); | ||
} |