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

P2TR support #7

Merged
merged 3 commits into from
Dec 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/bb/deskriptor/v1alpha/deskriptor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ enum ScriptType {

// Witness pay-to-pubkey-hash nested in P2SH. Corresponds to BIP 49
SCRIPT_TYPE_WPKH_NESTED = 3;

// Pay-to-taproot. Corresponds to BIP341.
SCRIPT_TYPE_P2TR = 4;
}

// This is included in the details section of an error returned from derivation.
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/no/bb/deskriptor/service/Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ data class Script(private val script: ScriptType) {
// operators, and replace this `when` block with something that returns
// a list of operators. For another day.
ScriptType.SCRIPT_TYPE_WPKH_NESTED -> "sh(wpkh"
ScriptType.SCRIPT_TYPE_P2TR -> "tr"
ScriptType.SCRIPT_TYPE_UNSPECIFIED -> throw newStatus(Code.INVALID_ARGUMENT, "unspecified")
ScriptType.UNRECOGNIZED -> throw newStatus(Code.INVALID_ARGUMENT, "unrecognized script type: $script")
}
Expand Down
66 changes: 66 additions & 0 deletions src/test/kotlin/no/bb/deskriptor/service/ServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,72 @@ class ServiceTest : FunSpec({
) { it.assert() }
}

// https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki
context("bip86 test vectors") {
withData(
DeriveInput(
SCRIPT_TYPE_P2TR,
0,
"xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ",
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
),
DeriveInput(
SCRIPT_TYPE_P2TR,
1,
"xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ",
"bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh",
),
) { it.assert() }
}

// stand sail fiction affair arch deer grow sight keen thing faculty virus
context("torkels sparrow wallet") {
withData(
DeriveInput(
SCRIPT_TYPE_P2TR,
0,
"xpub6DDqmwVaNoavxHc8Agj4XuEVCC3RvuXHcQVcmVv59KivcBEoJG6brcQ49NCRtf25vA3YNPqeJwEa4TFCw1y5RGzULb72D3TQGV67xpEdH4j",
"bc1pcz7de4f64c4jm537f436cr7sq7wgfpfhdy4nf9avf9x9nac8fa5qwccp0z",
),
DeriveInput(
SCRIPT_TYPE_P2TR,
1,
"xpub6DDqmwVaNoavxHc8Agj4XuEVCC3RvuXHcQVcmVv59KivcBEoJG6brcQ49NCRtf25vA3YNPqeJwEa4TFCw1y5RGzULb72D3TQGV67xpEdH4j",
"bc1pzstq526x3xujh88jnmpvaq2tq8yk6dl2cu6a87qvzyslumxckwxq3yl7nf",
),
DeriveInput(
SCRIPT_TYPE_P2TR,
2,
"xpub6DDqmwVaNoavxHc8Agj4XuEVCC3RvuXHcQVcmVv59KivcBEoJG6brcQ49NCRtf25vA3YNPqeJwEa4TFCw1y5RGzULb72D3TQGV67xpEdH4j",
"bc1ph2r5c6c25520gqxsemvpt0pnue28jp2tlza2kdvmmtkqva30hs4qjp9nhj",
),
) { it.assert() }
}

context("bos sparrow wallet") {
withData(
DeriveInput(
SCRIPT_TYPE_P2TR,
0,
"xpub6CPJGRoLhx72USPrYaGsiDZq6rBu6gzJruACdcyoRjffLGmecgW9rcojBmzQgw5Qsd8PN4KfSbiycVzDicvUW5m6RG9gVd41SjAVPcjWdq9",
"bc1pzzr5kkz5rtxw733tst7yxex8kgy2hanq0jchtt0xvp7cajqz9dkqj4pxev",
),
DeriveInput(
SCRIPT_TYPE_P2TR,
1,
"xpub6CPJGRoLhx72USPrYaGsiDZq6rBu6gzJruACdcyoRjffLGmecgW9rcojBmzQgw5Qsd8PN4KfSbiycVzDicvUW5m6RG9gVd41SjAVPcjWdq9",
"bc1psxyyfk9e4lykx7ghq4g44hunn75rmh3zvuxc5mud2tuae63yk3gqq2msra",
),
DeriveInput(
SCRIPT_TYPE_P2TR,
2,
"xpub6CPJGRoLhx72USPrYaGsiDZq6rBu6gzJruACdcyoRjffLGmecgW9rcojBmzQgw5Qsd8PN4KfSbiycVzDicvUW5m6RG9gVd41SjAVPcjWdq9",
"bc1pfmkr97h8dy50srk4p5c9c3fxg8m2uum4mrrfears2c7pt2ljx2xqu4ddwk",
),
) { it.assert() }
}


// generated with https://iancoleman.io/bip39/
context("iancoleman data") {

Expand Down