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

feat: update script expression for taproot #80

Merged
merged 1 commit into from
Jan 15, 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
26 changes: 26 additions & 0 deletions libs/ur-registry/src/crypto_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()
);
}
}
16 changes: 16 additions & 0 deletions libs/ur-registry/src/script_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -70,6 +78,8 @@ pub enum ScriptExpression {
SortedMultiSig,
Address,
RawScript,
Taproot,
Cosigner,
Undefine(u64),
}

Expand All @@ -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),
}
}
Expand All @@ -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,
}
}
Expand All @@ -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)
}
Expand Down
Loading