Skip to main content

taproot_assets_core/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5use taproot_assets_types::asset::SerializedKey;
6use thiserror::Error;
7
8/// Errors returned by TaprootOps implementations.
9#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
10pub enum OpsError {
11    /// Raw group key bytes are invalid.
12    #[error("invalid group key reveal raw key")]
13    InvalidRawGroupKey,
14    /// Internal key bytes are invalid.
15    #[error("invalid group key reveal internal key")]
16    InvalidInternalKey,
17    /// Asset ID tweak is out of range.
18    #[error("asset id tweak out of range")]
19    AssetIdTweakOutOfRange,
20    /// Failed to apply the group key tweak.
21    #[error("invalid group key tweak")]
22    InvalidGroupKeyTweak,
23    /// Taproot output key derivation failed.
24    #[error("invalid taproot output key")]
25    InvalidTaprootOutputKey,
26}
27
28/// Trait that supplies cryptographic operations needed by verifier core.
29pub trait TaprootOps {
30    /// Backend-specific public key representation.
31    type PubKey;
32
33    /// Parses a raw group key into the backend representation.
34    fn parse_group_key(&self, key: &SerializedKey) -> Result<Self::PubKey, OpsError>;
35
36    /// Parses an internal key into the backend representation.
37    fn parse_internal_key(&self, key: &SerializedKey) -> Result<Self::PubKey, OpsError>;
38
39    /// Adds a scalar tweak to a public key.
40    fn add_tweak(&self, pubkey: &Self::PubKey, tweak: [u8; 32]) -> Result<Self::PubKey, OpsError>;
41
42    /// Computes the Taproot output key for an internal key and optional tapscript root.
43    fn taproot_output_key(
44        &self,
45        internal_key: &Self::PubKey,
46        tapscript_root: Option<[u8; 32]>,
47    ) -> Result<SerializedKey, OpsError>;
48}
49
50/// Verification routines for Taproot Assets proofs.
51pub mod verify;