From 6bd176095c787ce20d893c70a877fc9675afed12 Mon Sep 17 00:00:00 2001 From: yu Date: Mon, 15 Jan 2024 14:07:19 +0800 Subject: [PATCH] feat: update script expression for taproot --- libs/ur-registry/src/crypto_output.rs | 26 +++++++++++++++++++++++ libs/ur-registry/src/script_expression.rs | 16 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libs/ur-registry/src/crypto_output.rs b/libs/ur-registry/src/crypto_output.rs index 056265a..b38ca1b 100644 --- a/libs/ur-registry/src/crypto_output.rs +++ b/libs/ur-registry/src/crypto_output.rs @@ -195,6 +195,21 @@ mod tests { "d90190d90196a201020282d90132a1035821022f01e5e15cca351daff3843fb70f3c2f0a1bdd05e5af888a67784ef3e10a2a01d90132a103582103acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe", hex::encode(crypto.to_bytes().unwrap()).to_lowercase() ); + + let script_expressions = vec![ + ScriptExpression::Taproot, + ]; + let bytes = + Vec::from_hex("03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556") + .unwrap(); + + let ec_keys = CryptoECKey::new(None, None, bytes); + let crypto = CryptoOutput::new(script_expressions, Some(ec_keys), None, None); + + assert_eq!( + "d90199d90132a103582103fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556", + hex::encode(crypto.to_bytes().unwrap()).to_lowercase() + ); } #[test] @@ -209,5 +224,16 @@ mod tests { crypto.get_script_expressions() ); assert_eq!(2, crypto.get_multi_key().unwrap().get_threshold()); + + let bytes = Vec::from_hex( + "d90199d90132a103582103fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556", + ) + .unwrap(); + let crypto = CryptoOutput::from_cbor(bytes).unwrap(); + + assert_eq!( + vec![ScriptExpression::Taproot], + crypto.get_script_expressions() + ); } } diff --git a/libs/ur-registry/src/script_expression.rs b/libs/ur-registry/src/script_expression.rs index 172d7ba..eb36e8c 100644 --- a/libs/ur-registry/src/script_expression.rs +++ b/libs/ur-registry/src/script_expression.rs @@ -57,6 +57,14 @@ const RAW_SCRIPT: ScriptExpressionValue = ScriptExpressionValue { tag_value: 408, expression: "raw", }; +const TAPROOT: ScriptExpressionValue = ScriptExpressionValue { + tag_value: 409, + expression: "tr", +}; +const COSIGNER: ScriptExpressionValue = ScriptExpressionValue { + tag_value: 410, + expression: "cosigner", +}; #[derive(Clone, Debug, PartialEq)] pub enum ScriptExpression { @@ -70,6 +78,8 @@ pub enum ScriptExpression { SortedMultiSig, Address, RawScript, + Taproot, + Cosigner, Undefine(u64), } @@ -86,6 +96,8 @@ impl ScriptExpression { 407 => ScriptExpression::SortedMultiSig, 307 => ScriptExpression::Address, 408 => ScriptExpression::RawScript, + 409 => ScriptExpression::Taproot, + 410 => ScriptExpression::Cosigner, _ => ScriptExpression::Undefine(tag_value), } } @@ -102,6 +114,8 @@ impl ScriptExpression { ScriptExpression::SortedMultiSig => SORTED_MULTI_SIG.get_tag_value(), ScriptExpression::Address => ADDRESS.get_tag_value(), ScriptExpression::RawScript => RAW_SCRIPT.get_tag_value(), + ScriptExpression::Taproot => TAPROOT.get_tag_value(), + ScriptExpression::Cosigner => COSIGNER.get_tag_value(), ScriptExpression::Undefine(tag_value) => *tag_value as u32, } } @@ -118,6 +132,8 @@ impl ScriptExpression { ScriptExpression::SortedMultiSig => SORTED_MULTI_SIG.get_expression(), ScriptExpression::Address => ADDRESS.get_expression(), ScriptExpression::RawScript => RAW_SCRIPT.get_expression(), + ScriptExpression::Taproot => TAPROOT.get_expression(), + ScriptExpression::Cosigner => COSIGNER.get_expression(), ScriptExpression::Undefine(tag_value) => { format!("tag value is {}, undefine expression", tag_value) }