Skip to content

Commit

Permalink
Merge pull request #202 from crisdut/fix/asset-tag-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky authored Jan 26, 2024
2 parents 729c652 + aeec368 commit c51af67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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

0 comments on commit c51af67

Please sign in to comment.