Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetTag compatible with wasm target #202

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ secp256k1-zkp = { version = "0.9.2", features = ["rand", "rand-std", "global-con
baid58 = "~0.4.4"
mime = "~0.3.17"
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
chrono = "0.4.31"

[features]
default = []
Expand Down
8 changes: 5 additions & 3 deletions src/contract/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ use core::ops::Deref;
use core::str::FromStr;
use std::io;
use std::io::Write;
use std::time::SystemTime;

use amplify::confinement::U8;
use amplify::hex::ToHex;
// We do not import particular modules to keep aware with namespace prefixes
// that we do not use the standard secp256k1zkp library
use amplify::{hex, Array, Bytes32, Wrapper};
use bp::secp256k1::rand::thread_rng;
use chrono::Local;
use commit_verify::{
CommitEncode, CommitVerify, CommitmentProtocol, Conceal, DigestExt, Sha256, UntaggedProtocol,
};
Expand Down Expand Up @@ -76,11 +76,13 @@ pub struct AssetTag(
impl AssetTag {
pub fn new_random(contract_domain: impl AsRef<str>, assignment_type: AssignmentType) -> Self {
let rand = thread_rng().next_u64();
let timestamp = SystemTime::now().elapsed().expect("system time error");
let timestamp = Local::now()
.timestamp_nanos_opt()
.expect("local time error");
let mut hasher = Sha256::default();
hasher.input_with_len::<U8>(contract_domain.as_ref().as_bytes());
hasher.input_raw(&assignment_type.to_le_bytes());
hasher.input_raw(&timestamp.as_nanos().to_le_bytes());
hasher.input_raw(&timestamp.to_le_bytes());
hasher.input_raw(&rand.to_le_bytes());
AssetTag::from(hasher.finish())
}
Expand Down
Loading