Skip to content

Commit

Permalink
[aptos-wallet] Diem -> Aptos
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Mar 11, 2022
1 parent 6addcfa commit 9faebd5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions crates/aptos-wallet/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Diem Wallet
# Aptos Wallet

Diem Wallet is a pure-rust implementation of hierarchical key derivation for SecretKey material in Diem.
Aptos Wallet is a pure-rust implementation of hierarchical key derivation for SecretKey material.

# Overview

`aptos-wallet` is a library providing hierarchical key derivation for SecretKey material in Diem. The following crate is largely inspired by [`rust-wallet`](https://github.com/rust-bitcoin/rust-wallet) with minor modifications to the key derivation function. Note that Diem makes use of the ed25519 Edwards Curve Digital Signature Algorithm (EdDSA) over the Edwards Cruve cruve25519. Therefore, BIP32-like PublicKey derivation is not possible without falling back to a traditional non-deterministic Schnorr signature algorithm. For this reason, we modified the key derivation function to a simpler alternative.
`aptos-wallet` is a library providing hierarchical key derivation for SecretKey material. The following crate is largely inspired by [`rust-wallet`](https://github.com/rust-bitcoin/rust-wallet) with minor modifications to the key derivation function. Note that it makes use of the ed25519 Edwards Curve Digital Signature Algorithm (EdDSA) over the Edwards Curve curve25519. Therefore, BIP32-like PublicKey derivation is not possible without falling back to a traditional non-deterministic Schnorr signature algorithm. For this reason, we modified the key derivation function to a simpler alternative.

The `internal_macros.rs` is taken from [`rust-bitcoin`](https://github.com/rust-bitcoin/rust-bitcoin/blob/master/src/internal_macros.rs) and `mnemonic.rs` is a slightly modified version of the file with the same name from [`rust-wallet`](https://github.com/rust-bitcoin/rust-wallet/blob/master/src/mnemonic.rs), while `error.rs`, `key_factor.rs` and `wallet_library.rs` are modified to present a minimalist wallet library for the Diem Client. Note that `mnemonic.rs` from `rust-wallet` adheres to the [`BIP39`](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) spec.
The `internal_macros.rs` is taken from [`rust-bitcoin`](https://github.com/rust-bitcoin/rust-bitcoin/blob/master/src/internal_macros.rs) and `mnemonic.rs` is a slightly modified version of the file with the same name from [`rust-wallet`](https://github.com/rust-bitcoin/rust-wallet/blob/master/src/mnemonic.rs), while `error.rs`, `key_factor.rs` and `wallet_library.rs` are modified to present a minimalist wallet library for the Aptos Client. Note that `mnemonic.rs` from `rust-wallet` adheres to the [`BIP39`](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) spec.

# Implementation Details

`key_factory.rs` implements the key derivation functions. The `KeyFactory` struct holds the Master Secret Material used to derive the Child Key(s). The constructor of a particular `KeyFactory` accepts a `[u8; 64]` `Seed` and computes both the `Master` Secret Material as well as the `ChainCode` from the HMAC-512 of the `Seed`. Finally, the `KeyFactory` allows to derive a child PrivateKey at a particular `ChildNumber` from the Master and ChainCode, as well as the `ChildNumber`'s u64 member.

`wallet_library.rs` is a thin wrapper around `KeyFactory` which enables to keep track of Diem `AccountAddresses` and the information required to restore the current wallet from a `Mnemonic` backup. The `WalletLibrary` struct includes constructors that allow to generate a new `WalletLibrary` from OS randomness or generate a `WalletLibrary` from an instance of `Mnemonic`. `WalletLibrary` also allows to generate new addresses in-order or out-of-order via the `fn new_address` and `fn new_address_at_child_number`. Finally, `WalletLibrary` is capable of signing a Diem `RawTransaction` with the PrivateKey associated to the `AccountAddress` submitted. Note that in the future, Diem will support rotating authentication keys and therefore, `WalletLibrary` will need to understand more general inputs when mapping `AuthenticationKeys` to `PrivateKeys`
`wallet_library.rs` is a thin wrapper around `KeyFactory` which enables to keep track of `AccountAddresses` and the information required to restore the current wallet from a `Mnemonic` backup. The `WalletLibrary` struct includes constructors that allow to generate a new `WalletLibrary` from OS randomness or generate a `WalletLibrary` from an instance of `Mnemonic`. `WalletLibrary` also allows to generate new addresses in-order or out-of-order via the `fn new_address` and `fn new_address_at_child_number`. Finally, `WalletLibrary` is capable of signing a `RawTransaction` with the PrivateKey associated to the `AccountAddress` submitted. Note that in the future, Aptos will support rotating authentication keys and therefore, `WalletLibrary` will need to understand more general inputs when mapping `AuthenticationKeys` to `PrivateKeys`
4 changes: 2 additions & 2 deletions crates/aptos-wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use thiserror::Error;

/// Diem Wallet Error is a convenience enum for generating arbitrary WalletErrors. Currently, only
/// Aptos Wallet Error is a convenience enum for generating arbitrary WalletErrors. Currently, only
/// the AptosWalletGeneric error is being used, but there are plans to add more specific errors as
/// the Diem Wallet matures
/// the Aptos Wallet matures
#[derive(Debug, Error)]
pub enum WalletError {
/// generic error message
Expand Down
8 changes: 4 additions & 4 deletions crates/aptos-wallet/src/key_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! The following is a minimalist version of a hierarchical key derivation library for the
//! AptosWallet.
//!
//! Note that the Diem Blockchain makes use of ed25519 Edwards Digital Signature Algorithm
//! Note that the blockchain makes use of ed25519 Edwards Digital Signature Algorithm
//! (EdDSA) and therefore, BIP32 Public Key derivation is not available without falling back to
//! a non-deterministic Schnorr signature scheme. As AptosWallet is meant to be a minimalist
//! reference implementation of a simple wallet, the following does not deviate from the
Expand Down Expand Up @@ -114,10 +114,10 @@ impl ExtendedPrivKey {
AuthenticationKey::ed25519(&self.get_public())
}

/// Diem specific sign function that is capable of signing an arbitrary
/// Sign function that is capable of signing an arbitrary
/// Serializable value.
///
/// NOTE: In Diem, we do not sign the raw bytes of a transaction, but
/// NOTE: We do not sign the raw bytes of a transaction, but
/// those raw bytes prefixed by a domain separation hash.
/// Informally signed_bytes = sha3(domain_separator) || bcs_serialization_bytes
///
Expand Down Expand Up @@ -158,7 +158,7 @@ impl KeyFactory {
///
/// Note that the function below adheres to [HKDF RFC 5869](https://tools.ietf.org/html/rfc5869).
pub fn private_child(&self, child: ChildNumber) -> Result<ExtendedPrivKey> {
// application info in the HKDF context is defined as Diem derived key$child_number.
// application info in the HKDF context is defined as a derived key$child_number.
let mut le_n = [0u8; 8];
LittleEndian::write_u64(&mut le_n, child.0);
let mut info = KeyFactory::INFO_PREFIX.to_vec();
Expand Down
4 changes: 2 additions & 2 deletions crates/aptos-wallet/src/wallet_library.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) The Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

//! The following document is a minimalist version of Diem Wallet. Note that this Wallet does
//! The following document is a minimalist version of Aptos Wallet. Note that this Wallet does
//! not promote security as the mnemonic is stored in unencrypted form. In future iterations,
//! we will be releasing more robust Wallet implementations. It is our intention to present a
//! foundation that is simple to understand and incrementally improve the AptosWallet
Expand Down Expand Up @@ -155,7 +155,7 @@ impl WalletLibrary {
Ok(ret)
}

/// Simple public function that allows to sign a Diem RawTransaction with the PrivateKey
/// Simple public function that allows to sign a Aptos RawTransaction with the PrivateKey
/// associated to a particular AccountAddress. If the PrivateKey associated to an
/// AccountAddress is not contained in the addr_map, then this function will return an Error
pub fn sign_txn(&self, txn: RawTransaction) -> Result<SignedTransaction> {
Expand Down

0 comments on commit 9faebd5

Please sign in to comment.