Skip to content

Commit

Permalink
VDR endorsement flow simplification (#31)
Browse files Browse the repository at this point in the history
* Simplified transaction endorsement flow from VDR library perspective. 
* Polished documentation of Rust functions
  • Loading branch information
Toktar authored Mar 1, 2024
2 parents d1f3e41 + 5963551 commit 18a4ff9
Show file tree
Hide file tree
Showing 77 changed files with 3,052 additions and 3,452 deletions.
2 changes: 1 addition & 1 deletion docs/design/legacy-identifiers-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ So that legacy DID can be associated with a new `did:ethr` and we can only use `
bytes32 sigS,
string calldata identifier,
bytes32 ed25519Key,
bytes calldata ed25518Signature
bytes calldata ed25519Signature
)
// check signatures
didMapping[identifier] = identity;
Expand Down
4 changes: 2 additions & 2 deletions docs/migration/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ Issuer need to run migration tool manually (on the machine containing Indy Walle
* `contracts` - specifications for contracts deployed on the network
* `signer` - transactions signer
2. DID ownership moving to Besu Ledger:
1. Issuer create Ed25518 key (with seed) in the Besu wallet
1. Issuer create Ed25519 key (with seed) in the Besu wallet
2. Issuer create a new Secp256k1 keypair in Besu wallet
3. Issuer publish Secp256k1 key to Indy ledger using ATTRIB transaction: `{ "besu": { "key": secp256k1_key } }`
* Now Besu Secp256k1 key is associated with the Issuer DID which is published on the Indy Ledger.
* ATTRIB transaction is signed with Ed25518 key. No signature request for `secp256k1_key`.
* ATTRIB transaction is signed with Ed25519 key. No signature request for `secp256k1_key`.
3. Issuer build DID Document which will include:
* DID - fully qualified form should be used: `did:besu:network:<did_value>` of DID which was published as NYM transaction to Indy Ledger
* Two Verification Methods must be included:
Expand Down
6 changes: 3 additions & 3 deletions network/config/besu/genesis.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion network/config/nodes/validator5/key
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x172c22cdceb87c56ef30c9b4cd34b20c3c63c19cc6bd7b7d12c2dfd2179b3f86
0x40b6b9dc85d45b8bd1d8edc548ace4e5fd6c705bbf28a509f12791777b6b8843
8 changes: 4 additions & 4 deletions smart_contracts/contracts/migration/LegacyMappingRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract LegacyMappingRegistry is LegacyMappingRegistryInterface, ControlledUpgr
string calldata legacyIdentifier,
string calldata newDid,
bytes32 ed25519Key,
bytes calldata ed25518Signature
bytes calldata ed25519Signature
) public virtual {
bytes32 hash = keccak256(
abi.encodePacked(
Expand All @@ -90,7 +90,7 @@ contract LegacyMappingRegistry is LegacyMappingRegistryInterface, ControlledUpgr
legacyIdentifier,
newDid,
ed25519Key,
ed25518Signature
ed25519Signature
)
);
_createDidMapping(
Expand All @@ -99,7 +99,7 @@ contract LegacyMappingRegistry is LegacyMappingRegistryInterface, ControlledUpgr
legacyIdentifier,
newDid,
ed25519Key,
ed25518Signature
ed25519Signature
);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ contract LegacyMappingRegistry is LegacyMappingRegistryInterface, ControlledUpgr
string calldata legacyIdentifier,
string calldata newDid,
bytes32 ed25519Key,
bytes calldata ed25518Signature
bytes calldata ed25519Signature
) internal _identityOwner(identity, actor) _senderIsTrusteeOrEndorserOrSteward {
// Checks the uniqueness of the DID mapping
if (!isEmpty(didMapping[legacyIdentifier].toSlice())) revert DidMappingAlreadyExist(legacyIdentifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('LegacyMappingRegistry', function () {
).to.be.revertedWithCustomError(legacyMappingRegistry.baseInstance, MigrationErrors.DidMappingAlreadyExist)
})

it('Should fail if DID mapping is being created with not matching ed25518 key', async function () {
it('Should fail if DID mapping is being created with not matching ed25519 key', async function () {
const ed25519Key = Uint8Array.from([
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 25, 180, 23, 224, 175, 15, 188, 235, 170, 233, 240, 145, 111, 204, 153,
108, 117, 188, 145,
Expand Down
31 changes: 16 additions & 15 deletions vdr/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
Address, BlockDetails, QuorumConfig,
};

/// Client object for interaction with the network
pub struct LedgerClient {
chain_id: u64,
client: Box<dyn Client>,
Expand All @@ -31,14 +32,14 @@ impl LedgerClient {
/// Create client interacting with ledger
///
/// # Params
/// - `chain_id` - chain id of network (chain ID is part of the transaction signing process to protect against transaction replay attack)
/// - `rpc_node` - string - RPC node endpoint
/// - `network` - string - Name of the network
/// - `contract_configs` - [ContractSpec] specifications for contracts deployed on the network
/// - `quorum_config` - Option<[QuorumConfig]> quorum configuration. Can be None if quorum check is not needed
/// - `chain_id`: [u64] - chain id of network (chain ID is part of the transaction signing process to protect against transaction replay attack)
/// - `rpc_node`: [String] - RPC node endpoint
/// - `network`: [String] - Name of the network
/// - `contract_configs`: [ContractSpec] - specifications for contracts deployed on the network
/// - `quorum_config`: Option<[QuorumConfig]> - quorum configuration. Can be None if quorum check is not needed
///
/// # Returns
/// client to use for building and sending transactions
/// client: [LedgerClient] - client to use for building and sending transactions
#[logfn(Info)]
#[logfn_inputs(Debug)]
pub fn new(
Expand Down Expand Up @@ -70,7 +71,7 @@ impl LedgerClient {
/// Ping Ledger.
///
/// # Returns
/// ping status
/// status: [PingStatus] - ping status
#[logfn(Info)]
#[logfn_inputs(Debug)]
pub async fn ping(&self) -> VdrResult<PingStatus> {
Expand All @@ -84,10 +85,10 @@ impl LedgerClient {
/// Depending on the transaction type Write/Read ethereum methods will be used
///
/// #Params
/// `transaction` - transaction to submit
/// `transaction`: [Transaction] - transaction to submit
///
/// #Returns
/// transaction execution result:
/// response: [Vec] - transaction execution result:
/// depending on the type it will be either result bytes or block hash
#[logfn(Info)]
#[logfn_inputs(Debug)]
Expand All @@ -111,10 +112,10 @@ impl LedgerClient {
/// Submit prepared events query to the ledger
///
/// #Params
/// `query` - events query to submit
/// `query`: [EventQuery] - events query to submit
///
/// #Returns
/// log events received from the ledger
/// events: [Vec] - list of log events received from the ledger
#[logfn(Info)]
#[logfn_inputs(Debug)]
pub async fn query_events(&self, query: &EventQuery) -> VdrResult<Vec<EventLog>> {
Expand All @@ -126,10 +127,10 @@ impl LedgerClient {
/// Get receipt for the given block hash
///
/// # Params
/// `transaction` - transaction to submit
/// `transaction`: [Transaction] - transaction to submit
///
/// # Returns
/// receipt for the given block
/// receipt: [String] - receipt for the given block
#[logfn(Info)]
#[logfn_inputs(Debug)]
pub async fn get_receipt(&self, hash: &[u8]) -> VdrResult<String> {
Expand All @@ -139,10 +140,10 @@ impl LedgerClient {
/// Get a number of transactions sent by the given account address
///
/// # Params
/// `address` - target account address
/// `address`: [Address] - target account address
///
/// # Returns
/// number of sent transaction
/// count: [u64] - number of transaction sent by the given account
#[logfn(Info)]
#[logfn_inputs(Debug)]
pub(crate) async fn get_transaction_count(&self, address: &Address) -> VdrResult<u64> {
Expand Down
6 changes: 1 addition & 5 deletions vdr/src/client/implementation/web3/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ impl Web3Client {
#[logfn(Info)]
#[logfn_inputs(Debug)]
pub fn new(node_address: &str) -> VdrResult<Web3Client> {
trace!("Web3Client::new >>> node_address: {}", node_address);

let transport = Http::new(node_address).map_err(|_| VdrError::ClientNodeUnreachable)?;
let web3 = Web3::new(transport);
let web3_client = Web3Client { client: web3 };

trace!("Web3Client::new <<<");
Ok(web3_client)
}

pub fn eth(&self) -> Eth<Http> {
pub(crate) fn eth(&self) -> Eth<Http> {
self.client.eth()
}
}
Expand Down
11 changes: 3 additions & 8 deletions vdr/src/client/implementation/web3/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use std::fmt::{Debug, Formatter};

use ethabi::Event;
use log::{trace, warn};
use log::warn;
use log_derive::{logfn, logfn_inputs};
use std::str::FromStr;

Expand All @@ -30,17 +30,13 @@ pub struct Web3Contract {
}

impl Web3Contract {
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub fn new(
web3_client: &Web3Client,
address: &str,
contract_spec: &ContractSpec,
) -> VdrResult<Web3Contract> {
trace!(
"Web3Contract::new >>> address: {:?}, address: {:?}",
address,
contract_spec
);

let abi = serde_json::to_vec(&contract_spec.abi).map_err(|err| {
let vdr_error = VdrError::CommonInvalidData(format!(
"Unable to parse contract ABI from specification. Err: {:?}",
Expand All @@ -64,7 +60,6 @@ impl Web3Contract {
let contract =
Web3ContractImpl::from_json(web3_client.eth(), parsed_address, abi.as_slice())?;

trace!("Web3Contract::new <<< contract: {:?}", contract);
Ok(Web3Contract {
contract,
address: Address::from(address),
Expand Down
16 changes: 10 additions & 6 deletions vdr/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait Client: Sync + Send + Debug {
/// Retrieve count of transaction for the given account
///
/// # Params
/// - `address` address of an account to get number of written transactions
/// - `address` [Address] address of an account to get number of written transactions
///
/// # Returns
/// number of transactions
Expand All @@ -32,8 +32,7 @@ pub trait Client: Sync + Send + Debug {
/// Submit transaction to the ledger
///
/// # Params
/// - `transaction` transaction to submit
/// - `transaction` prepared transaction to submit
/// - `transaction` [Transaction] transaction to submit
///
/// # Returns
/// hash of a block in which transaction included
Expand All @@ -42,7 +41,7 @@ pub trait Client: Sync + Send + Debug {
/// Submit read transaction to the ledger
///
/// # Params
/// - `transaction` prepared transaction to submit
/// - `transaction` [Transaction] prepared transaction to submit
///
/// # Returns
/// result data of transaction execution
Expand All @@ -51,8 +50,7 @@ pub trait Client: Sync + Send + Debug {
/// Send a prepared query for retrieving log events on the ledger
///
/// #Params
/// param: client: Ledger - client (Ethereum client - for example web3::Http)
/// param: query: EventQuery - query to send
/// - `query` [EventQuery] query to send
///
/// #Returns
/// logs - list of received events
Expand Down Expand Up @@ -92,12 +90,18 @@ pub trait Contract: Sync + Send + Debug {

/// Get the contract function
///
/// # Params
/// - `name` name of a contract method
///
/// # Returns
/// Contract function
fn function(&self, name: &str) -> VdrResult<&Function>;

/// Get the contract event
///
/// # Params
/// - `name` name of a contract event
///
/// # Returns
/// Contract event
fn event(&self, name: &str) -> VdrResult<&Event>;
Expand Down
Loading

0 comments on commit 18a4ff9

Please sign in to comment.