-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
1 deletion.
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,57 @@ | ||
use crate::{wallets::Wallets}; | ||
use rand::rngs::OsRng; | ||
use orchard::{ | ||
builder::Builder, | ||
bundle::{Authorized, Flags}, | ||
circuit::{ProvingKey, VerifyingKey}, | ||
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendAuthorizingKey, SpendingKey}, | ||
note::ExtractedNoteCommitment, | ||
note_encryption::OrchardDomain, | ||
tree::{MerkleHashOrchard, MerklePath}, | ||
value::NoteValue, | ||
Bundle, | ||
}; | ||
|
||
|
||
pub fn deposit(address: String, value: u64) -> Bundle<Authorized, i64> { | ||
let wallets = Wallets::new(); | ||
let wallet = wallets.get_wallet(&address).unwrap(); | ||
|
||
let mut rng = OsRng; | ||
let pk = ProvingKey::build(); | ||
|
||
let sk = wallet.sk(); | ||
let fvk = FullViewingKey::from(&sk); | ||
let recipient = fvk.address_at(0u32, Scope::External); | ||
|
||
// Create a shielding bundle. | ||
let shielding_bundle: Bundle<_, i64> = { | ||
// Use the empty tree. | ||
let anchor = MerkleHashOrchard::empty_root(32.into()).into(); | ||
|
||
let mut builder = Builder::new(Flags::from_parts(false, true), anchor); | ||
assert_eq!( | ||
builder.add_recipient(None, recipient, NoteValue::from_raw(5000), None), | ||
Ok(()) | ||
); | ||
let unauthorized = builder.build(&mut rng).unwrap(); | ||
let sighash = unauthorized.commitment().into(); | ||
let proven = unauthorized.create_proof(&pk, &mut rng).unwrap(); | ||
proven.apply_signatures(rng, sighash, &[]).unwrap() | ||
}; | ||
shielding_bundle | ||
} | ||
|
||
pub fn verify_bundle(bundle: &Bundle<Authorized, i64>) { | ||
let vk = VerifyingKey::build(); | ||
assert!(matches!(bundle.verify_proof(&vk), Ok(()))); | ||
let sighash: [u8; 32] = bundle.commitment().into(); | ||
let bvk = bundle.binding_validating_key(); | ||
for action in bundle.actions() { | ||
assert_eq!(action.rk().verify(&sighash, action.authorization()), Ok(())); | ||
} | ||
assert_eq!( | ||
bvk.verify(&sighash, bundle.authorization().binding_signature()), | ||
Ok(()) | ||
); | ||
} |
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,3 @@ | ||
pub fn transfer(address: String, value: u64) -> Bundle<Authorized, i64> { | ||
|
||
} |
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