Skip to content

Commit

Permalink
Merge pull request #1404 from Phala-Network/pink-vrf
Browse files Browse the repository at this point in the history
pink: Add vrf
  • Loading branch information
kvinwang authored Oct 12, 2023
2 parents a7f8efe + 2e839d1 commit 959e2d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/pink/pink-extension/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ pub fn upgrade_runtime(version: (u32, u32)) {
emit_event::<PinkEnvironment, _>(PinkEvent::UpgradeRuntimeTo { version });
}

/// Generate a slice of verifiable random bytes.
///
/// When called in a contract with the same salt, the same random bytes will be generated.
/// Different contracts with the same salt will generate different random bytes.
///
/// # Availability
/// any contract | query | transaction
pub fn vrf(salt: &[u8]) -> Vec<u8> {
let mut key_salt = b"vrf:".to_vec();
key_salt.extend_from_slice(salt);
ext().derive_sr25519_key(key_salt.into())
}

/// Pink defined environment. This environment is used to access the phat contract extended runtime features.
///
/// # Example
Expand Down

0 comments on commit 959e2d9

Please sign in to comment.