Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Bitcoin Minimalist

Sanket Kanjalkar sanket1729

💭
Bitcoin Minimalist
View GitHub Profile
@sanket1729
sanket1729 / psbt_sign.txt
Last active Aug 18, 2022
psbt test cases
View psbt_sign.txt
#unsigned_psbt,signed_psbt,(pk;sk,)*
70736274ff01005202000000014f1081b4b3f3527113058a48b6fd84d968f212c1c0d334d637f77d294b3289f80100000000010000000148d5f50500000000160014b6e35acec5146ef531a6372137cd45f104f8f8f8da0e995f0001011f00e1f50500000000160014773dfa9e21789bf357c19b7db8a4c7df97d930c6220603ab1ac1872a38a2f196bed5a6047f0da2c8130fe8de49fc4d5dfb201f7611d8e204773dfa9e0000,70736274ff01005202000000014f1081b4b3f3527113058a48b6fd84d968f212c1c0d334d637f77d294b3289f80100000000010000000148d5f50500000000160014b6e35acec5146ef531a6372137cd45f104f8f8f8da0e995f0001011f00e1f50500000000160014773dfa9e21789bf357c19b7db8a4c7df97d930c6220203ab1ac1872a38a2f196bed5a6047f0da2c8130fe8de49fc4d5dfb201f7611d8e24830450221009f58243e91c0272fe8f617bba3d05d4d3f3112ad30bfcb83053a353f38b1cc8102202bbbb144a78090840132ffabb3fc6aa193c1346e29d9444a156e799d605fcd6901220603ab1ac1872a38a2f196bed5a6047f0da2c8130fe8de49fc4d5dfb201f7611d8e204773dfa9e0000,03ab1ac1872a38a2f196bed5a6047f0da2c8130fe8de49fc4d5dfb201f7611d8e2;cMeb8vatuSpDLwokavVgGWFc2gF8xKDRfA
@sanket1729
sanket1729 / seattle-bitcoin.md
Last active Jun 17, 2022
Socratic Reading list
View seattle-bitcoin.md
@sanket1729
sanket1729 / create_spend_info.rs
Last active Mar 26, 2022
Creating Spend Info from Tree sturcture
View create_spend_info.rs
// Some user struct for trees
enum Tree {
Node(Tree,Tree),
Leaf(Miniscript),
}
impl Tree {
fn update_builder(&self, builder: TaprootBuilder, depth: usize) -> TaprootBuilder {
match self {
@sanket1729
sanket1729 / psbt-musig2.md
Last active Jun 15, 2022
Psbt musig2 signing
View psbt-musig2.md

Musig2 signing in Psbt

New fields required:

  • PSBT_IN_MUSIG_PARTICIPANT_PUBLIC_KEYS: (<x_only_pk(agg_pk_to_sign)><x_only_pk(agg_pk)>) -> <[x_only_pk]*>: For example, (a, b) -> [c] where b = Musig2_KeyAgg([c]) and a is a tweaked(BIP32 tweak or x-only tweak or both) key derived from b where the tweaking information is present in PSBT_IN_TAP_BIP32_DERIVATION in case of BIP32 tweak. In case, a is the output key, an additional BIP341 tweak is applied. The tweak information is provided in PSBT_IN_TAP_INTERNAL_KEY or PSBT_IN_TAP_MERKLE_ROOT. The full xpub for the aggregated agg_pk can be provided in PBST_GLOBAL_XPUB field

  • PSBT_IN_TAP_MUSIG2_PUB_NONCE: (<x_only_pk(participant_key), x_only_pk(agg_pk_to_sign), leaf_hash>) -> <pub_nonce> (serialized pub_nonce including R1 and R2).

  • PSBT_IN_TAP_PARTIAL_SIGNATURE: (<x_only_pk(participant_key), x_only_pk(agg_pk_to_sign), leaf_hash>) -> <partial_sig> (serialized partial_sig)

Aggregating pubkeys and tweaking:

@sanket1729
sanket1729 / output_desc.md
Created Feb 15, 2022
Classification of output descriptors
View output_desc.md

Output Descriptors

Descriptor Trait/Typeclass:

Table of API on along the rows, and columns showing the descriptor type. Each box represents

  • y = always succeeds
  • n = always fails
  • yn = may succeed

All descriptors sh/wsh/shwsh/tr/bare support miniscript descriptors

View temp.rs
let ms = match desc {
Descriptor::Sh(ref sh) => {
match sh.as_inner(){
ShInner::Wsh(wsh ) => {
match wsh.as_inner() {
WshInner::Ms(ref ms) => ms
}
}
}
}
View thakns_rustc.rs
error[E0308]: mismatched types
--> src/test_random_miniscripts.rs:32:44
|
32 | let ms: Result<_, ()> = ms.translate_pk(
| ^^^^^^^^^^^^ one type is more general than the other
|
= note: expected type `FnOnce<(&std::string::String,)>`
found type `FnOnce<(&std::string::String,)>`
View temp.rs
// Miniscript
// Written in 2018 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
View temp.rs
fn witness_script<ToPkCtx: Copy>(&self, to_pk_ctx: ToPkCtx) -> BtcScript
where
Pk: ToPublicKey<ToPkCtx>,
{
let tweak = self.desc.witness_script(to_pk_ctx).into_bytes();
let mut builder = script::Builder::new()
.push_opcode(opcodes::all::OP_DEPTH)
.push_int(self.fed_k as i64 + 1)
.push_opcode(opcodes::all::OP_EQUAL)
View test.py
def normalize(sign, v, modulus):
"""Compute sign*v mod modulus, where v in (-2*modulus,modulus); output in [0,modulus)."""
ans = (sign*v) % modulus
v += modulus & (v >> 256) # I think this line is wrong when v has 257th bit set and 256 unset
c = (sign - 1) >> 1
v = (v ^ c) - c
v += modulus & (v >> 256)
assert ans == (v % modulus), print(ans, v)
return v