{
    "version": 1,
    "test_vectors": [
        {
            "id": "p2mr_misuse_v2_witness_version_with_pubkey_error",
            "objective": "Tests that P2MR fails with use of internal_pubkey",
            "given": {
                "internalPubkey": "d6889cb081036e0faefa3a35157ad71086b123b2b144b649798b494c300a961d",
                "scriptTree": null
            },
            "intermediary": {
                "merkleRoot": null,
                "tweak": "b86e7be8f39bab32a6f2c0443abbc210f0edac0e2c53d501b36b64437d9c6c70",
                "tweakedPubkey": "53a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343"
            },
            "expected": {
                "scriptPubKey": "522053a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343",
                "error": "P2MR does not support internal pubkeys"
            }
        },
        {
            "id": "p2mr_null_or_missing_script_tree_error",
            "objective": "Tests P2MR with null or missing script tree",
            "given": {
                "script_tree": ""
            },
            "intermediary": {
            },
            "expected": {
                "error": "P2MR requires a script tree with at least one leaf"
            }
        },
        {
            "id": "p2mr_single_leaf_script_tree",
            "objective": "Tests P2MR with single leaf script tree",
            "given": {
                "scriptTree": {
                    "id": 0,
                    "script": "20b617298552a72ade070667e86ca63b8f5789a9fe8731ef91202a91c9f3459007ac",
                    "asm": "b617298552a72ade070667e86ca63b8f5789a9fe8731ef91202a91c9f3459007 OP_CHECKSIG",
                    "leafVersion": 192
                }
            },
            "intermediary": {
                "leafHashes": [
                    "c525714a7f49c28aedbbba78c005931a81c234b2f6c99a73e4d06082adc8bf2b"
                ],
                "merkleRoot": "c525714a7f49c28aedbbba78c005931a81c234b2f6c99a73e4d06082adc8bf2b"
            },
            "expected": {
                "scriptPubKey": "5220c525714a7f49c28aedbbba78c005931a81c234b2f6c99a73e4d06082adc8bf2b",
                "bip350Address": "bc1zc5jhzjnlf8pg4mdmhfuvqpvnr2quyd9j7mye5uly6psg9twghu4ssr0v9k",
                "scriptPathControlBlocks": [
                    "c1"
                ]
            }
        },
        {
            "id": "p2mr_different_version_leaves",
            "objective": "Tests P2MR with two script leaves of different versions. An unknown leaf version should be accepted and the P2MR output constructed successfully.",
            "given": {
                "scriptTree": [
                    {
                        "id": 0,
                        "script": "20387671353e273264c495656e27e39ba899ea8fee3bb69fb2a680e22093447d48ac",
                        "asm": "387671353e273264c495656e27e39ba899ea8fee3bb69fb2a680e22093447d48 OP_CHECKSIG",
                        "leafVersion": 192
                    },
                    {
                        "id": 1,
                        "script": "06424950333431",
                        "asm": "424950333431",
                        "description": "just pushes the string 'BIP341' onto the stack",
                        "leafVersion": 250
                    }
                ]
            },
            "intermediary": {
                "leafHashes": [
                    "8ad69ec7cf41c2a4001fd1f738bf1e505ce2277acdcaa63fe4765192497f47a7",
                    "f224a923cd0021ab202ab139cc56802ddb92dcfc172b9212261a539df79a112a"
                ],
                "merkleRoot": "6c2dc106ab816b73f9d07e3cd1ef2c8c1256f519748e0813e4edd2405d277bef"
            },
            "expected": {
                "scriptPubKey": "52206c2dc106ab816b73f9d07e3cd1ef2c8c1256f519748e0813e4edd2405d277bef",
                "bip350Address": "bc1zdskuzp4ts94h87ws0c7drmev3sf9dagewj8qsylyahfyqhf800hsam4d6e",
                "scriptPathControlBlocks": [
                    "c1f224a923cd0021ab202ab139cc56802ddb92dcfc172b9212261a539df79a112a",
                    "fb8ad69ec7cf41c2a4001fd1f738bf1e505ce2277acdcaa63fe4765192497f47a7"
                ]
            }
        },
        {
            "id": "p2mr_simple_lightning_contract",
            "objective": "Tests P2MR with two script leaves that simulate a simple lightning network contract.  Reference: https://github.com/bitcoin-core/btcdeb/blob/master/doc/tapscript-example-with-tap.md",
            "given": {
                "scriptTree": [
                    {
                        "id": 0,
                        "script": "029000b275209997a497d964fc1a62885b05a51166a65a90df00492c8d7cf61d6accf54803beac",
                        "asm": "144 OP_CHECKSEQUENCEVERIFY OP_DROP 9997a497d964fc1a62885b05a51166a65a90df00492c8d7cf61d6accf54803be OP_CHECKSIG",
                        "description": "Alice takes the money after waiting 1 day",
                        "leafVersion": 192
                    },
                    {
                        "id": 1,
                        "script": "a8206c60f404f8167a38fc70eaf8aa17ac351023bef86bcb9d1086a19afe95bd533388204edfcf9dfe6c0b5c83d1ab3f78d1b39a46ebac6798e08e19761f5ed89ec83c10ac",
                        "asm": "OP_SHA256 6c60f404f8167a38fc70eaf8aa17ac351023bef86bcb9d1086a19afe95bd5333 OP_EQUALVERIFY 4edfcf9dfe6c0b5c83d1ab3f78d1b39a46ebac6798e08e19761f5ed89ec83c10 OP_CHECKSIG",
                        "description": "Bob takes the money whenever he wishes to by revealing the preimage_hash",
                        "leafVersion": 192
                    }
                ]
            },
            "intermediary": {
                "leafHashes": [
                    "c81451874bd9ebd4b6fd4bba1f84cdfb533c532365d22a0a702205ff658b17c9",
                    "632c8632b4f29c6291416e23135cf78ecb82e525788ea5ed6483e3c6ce943b42"
                ],
                "merkleRoot": "41646f8c1fe2a96ddad7f5471bc4fee7da98794ef8c45a4f4fc6a559d60c9f6b"
            },
            "expected": {
                "scriptPubKey": "522041646f8c1fe2a96ddad7f5471bc4fee7da98794ef8c45a4f4fc6a559d60c9f6b",
                "bip350Address": "bc1zg9jxlrqlu25kmkkh74r3h387uldfs72wlrz95n60c6j4n4svna4s4lhfhe",
                "scriptPathControlBlocks": [
                    "c1632c8632b4f29c6291416e23135cf78ecb82e525788ea5ed6483e3c6ce943b42",
                    "c1c81451874bd9ebd4b6fd4bba1f84cdfb533c532365d22a0a702205ff658b17c9"
                ]
            }
        },
        {
            "id": "p2mr_two_leaf_same_version",
            "objective": "Tests P2MR with two script leaves of same version",
            "given": {
                "scriptTree": [
                    {
                        "id": 0,
                        "script": "2044b178d64c32c4a05cc4f4d1407268f764c940d20ce97abfd44db5c3592b72fdac",
                        "asm": "44b178d64c32c4a05cc4f4d1407268f764c940d20ce97abfd44db5c3592b72fd OP_CHECKSIG",
                        "leafVersion": 192
                    },
                    {
                        "id": 1,
                        "script": "07546170726f6f74",
                        "asm": "546170726f6f74",
                        "description": "pushes the string 'Taproot' onto the stack",
                        "leafVersion": 192
                    }
                ]
            },
            "intermediary": {
                "leafHashes": [
                    "64512fecdb5afa04f98839b50e6f0cb7b1e539bf6f205f67934083cdcc3c8d89",
                    "2cb2b90daa543b544161530c925f285b06196940d6085ca9474d41dc3822c5cb"
                ],
                "merkleRoot": "ab179431c28d3b68fb798957faf5497d69c883c6fb1e1cd9f81483d87bac90cc"
            },
            "expected": {
                "scriptPubKey": "5220ab179431c28d3b68fb798957faf5497d69c883c6fb1e1cd9f81483d87bac90cc",
                "bip350Address": "bc1z4vtegvwz35ak37me39tl4a2f045u3q7xlv0pek0czjpas7avjrxqz20g2y",
                "scriptPathControlBlocks": [
                    "c12cb2b90daa543b544161530c925f285b06196940d6085ca9474d41dc3822c5cb",
                    "c164512fecdb5afa04f98839b50e6f0cb7b1e539bf6f205f67934083cdcc3c8d89"
                ]
            }
        },
        {
            "id": "p2mr_three_leaf_complex",
            "objective": "Tests P2MR with a complex three-leaf script tree structure, demonstrating nested script paths and multiple verification options",
            "given": {
                "scriptTree": [
                    {
                        "id": 0,
                        "script": "2072ea6adcf1d371dea8fba1035a09f3d24ed5a059799bae114084130ee5898e69ac",
                        "asm": "72ea6adcf1d371dea8fba1035a09f3d24ed5a059799bae114084130ee5898e69 OP_CHECKSIG",
                        "leafVersion": 192
                    },
                    [
                        {
                            "id": 1,
                            "script": "202352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8ac",
                            "asm": "2352d137f2f3ab38d1eaa976758873377fa5ebb817372c71e2c542313d4abda8 OP_CHECKSIG",
                            "leafVersion": 192
                        },
                        {
                            "id": 2,
                            "script": "207337c0dd4253cb86f2c43a2351aadd82cccb12a172cd120452b9bb8324f2186aac",
                            "asm": "7337c0dd4253cb86f2c43a2351aadd82cccb12a172cd120452b9bb8324f2186a OP_CHECKSIG",
                            "leafVersion": 192
                        }
                    ]
                ]
            },
            "intermediary": {
                "leafHashes": [
                    "2645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817",
                    "ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c",
                    "9e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf6"
                ],
                "merkleRoot": "ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2"
            },
            "expected": {
                "scriptPubKey": "5220ccbd66c6f7e8fdab47b3a486f59d28262be857f30d4773f2d5ea47f7761ce0e2",
                "bip350Address": "bc1zej7kd3hhar76k3an5jr0t8fgyc47s4lnp4rh8uk4afrlwasuur3qzgewqq",
                "scriptPathControlBlocks": [
                    "c1ffe578e9ea769027e4f5a3de40732f75a88a6353a09d767ddeb66accef85e553",
                    "c19e31407bffa15fefbf5090b149d53959ecdf3f62b1246780238c24501d5ceaf62645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817",
                    "c1ba982a91d4fc552163cb1c0da03676102d5b7a014304c01f0c77b2b8e888de1c2645a02e0aac1fe69d69755733a9b7621b694bb5b5cde2bbfc94066ed62b9817"
                ]
            }
        },
        {
            "id": "p2mr_three_leaf_alternative",
            "objective": "Tests another variant of P2MR with three leaves arranged in a different tree structure, showing alternative script path spending options",
            "given": {
                "scriptTree": [
                    {
                        "id": 0,
                        "script": "2071981521ad9fc9036687364118fb6ccd2035b96a423c59c5430e98310a11abe2ac",
                        "asm": "71981521ad9fc9036687364118fb6ccd2035b96a423c59c5430e98310a11abe2 OP_CHECKSIG",
                        "leafVersion": 192
                    },
                    [
                        {
                            "id": 1,
                            "script": "20d5094d2dbe9b76e2c245a2b89b6006888952e2faa6a149ae318d69e520617748ac",
                            "asm": "d5094d2dbe9b76e2c245a2b89b6006888952e2faa6a149ae318d69e520617748 OP_CHECKSIG",
                            "leafVersion": 192
                        },
                        {
                            "id": 2,
                            "script": "20c440b462ad48c7a77f94cd4532d8f2119dcebbd7c9764557e62726419b08ad4cac",
                            "asm": "c440b462ad48c7a77f94cd4532d8f2119dcebbd7c9764557e62726419b08ad4c OP_CHECKSIG",
                            "leafVersion": 192
                        }
                    ]
                ]
            },
            "intermediary": {
                "leafHashes": [
                    "f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d",
                    "737ed1fe30bc42b8022d717b44f0d93516617af64a64753b7a06bf16b26cd711",
                    "d7485025fceb78b9ed667db36ed8b8dc7b1f0b307ac167fa516fe4352b9f4ef7"
                ],
                "merkleRoot": "2f6b2c5397b6d68ca18e09a3f05161668ffe93a988582d55c6f07bd5b3329def"
            },
            "expected": {
                "scriptPubKey": "52202f6b2c5397b6d68ca18e09a3f05161668ffe93a988582d55c6f07bd5b3329def",
                "bip350Address": "bc1z9a4jc5uhkmtgegvwpx3lq5tpv68layaf3pvz64wx7paatvejnhhsv52lcv",
                "scriptPathControlBlocks": [
                    "c13cd369a528b326bc9d2133cbd2ac21451acb31681a410434672c8e34fe757e91",
                    "c1d7485025fceb78b9ed667db36ed8b8dc7b1f0b307ac167fa516fe4352b9f4ef7f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d",
                    "c1737ed1fe30bc42b8022d717b44f0d93516617af64a64753b7a06bf16b26cd711f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d"
                ]
            }
        },
        {
            "id": "p2mr_duplicate_leaves",
            "objective": "Ensure P2MR control blocks can be constructed correctly even when duplicate script leaves coexist in the same tree.",
            "given": {
                "scriptTree": [
                    {
                        "id": 0,
                        "script": "2071981521ad9fc9036687364118fb6ccd2035b96a423c59c5430e98310a11abe2ac",
                        "asm": "71981521ad9fc9036687364118fb6ccd2035b96a423c59c5430e98310a11abe2 OP_CHECKSIG",
                        "leafVersion": 192
                    },
                    [
                        {
                            "id": 1,
                            "script": "20d5094d2dbe9b76e2c245a2b89b6006888952e2faa6a149ae318d69e520617748ac",
                            "asm": "d5094d2dbe9b76e2c245a2b89b6006888952e2faa6a149ae318d69e520617748 OP_CHECKSIG",
                            "leafVersion": 192
                        },
                        {
                            "id": 2,
                            "script": "2071981521ad9fc9036687364118fb6ccd2035b96a423c59c5430e98310a11abe2ac",
                            "asm": "71981521ad9fc9036687364118fb6ccd2035b96a423c59c5430e98310a11abe2 OP_CHECKSIG",
                            "leafVersion": 192
                        }
                    ]
                ]
            },
            "intermediary": {
                "leafHashes": [
                    "f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d",
                    "737ed1fe30bc42b8022d717b44f0d93516617af64a64753b7a06bf16b26cd711",
                    "f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d"
                ],
                "merkleRoot": "3ab4f80153012398a7df2df273b0bd3cdb839883320ff06d62e8cc1ecb351ba7"
            },
            "expected": {
                "scriptPubKey": "52203ab4f80153012398a7df2df273b0bd3cdb839883320ff06d62e8cc1ecb351ba7",
                "bip350Address": "bc1z8260sq2nqy3e3f7l9he88v9a8ndc8xyrxg8lqmtzarxpaje4rwnsxxww7h",
                "scriptPathControlBlocks": [
                    "c13a9adbb72f00022f76909e0f4bbab37dacafadb59618a4a13a123e13cb6f3019",
                    "c1f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9df154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d",
                    "c1737ed1fe30bc42b8022d717b44f0d93516617af64a64753b7a06bf16b26cd711f154e8e8e17c31d3462d7132589ed29353c6fafdb884c5a6e04ea938834f0d9d"
                ]
            }
        }
    ]
}
