|
| 1 | +# How to add Hardware Wallet support |
| 2 | + |
| 3 | +With `v0.7.0`, `tapd` uses four different forms of scripts/tweaks for anchoring |
| 4 | +commitment roots into Bitcoin transactions that can be relevant for hardware |
| 5 | +signing devices: |
| 6 | + - The "Taproot Asset Root Commitment": The pseudo-leaf that's placed in the |
| 7 | + Taproot merkle tree to commit to asset mints and transfers. |
| 8 | + - Relevant when signing any asset mint or transfer transaction. The Taproot |
| 9 | + internal key used for the mint or transfer output(s) would be a key that |
| 10 | + belongs to the signing device. And the Taproot Asset Root Commitment pseudo |
| 11 | + leaf would be the single leaf in the tree (unless there are more |
| 12 | + user-defined script leaves added, as would be the case for Lightning |
| 13 | + Channel outputs) |
| 14 | + - The V0 group key scheme that tweaks the group internal key twice. |
| 15 | + - Deprecated, should not be used when targeting Hardware Wallet support. The |
| 16 | + commitment is a simple double tweak to arrive at the final ("tweaked") |
| 17 | + group key: |
| 18 | + ```go |
| 19 | + // internalKey = rawKey + singleTweak * G |
| 20 | + // tweakedGroupKey = TapTweak(internalKey, tapscriptRoot) |
| 21 | + ``` |
| 22 | + Where `singleTweak` is the asset ID of the group anchor and the |
| 23 | + `tapscriptRoot` is either an empty byte slice or the root of a custom |
| 24 | + script tapscript tree. |
| 25 | + - The `OP_RETURN` commitment scheme for signing minting events with the group |
| 26 | + key. |
| 27 | + - Currently only relevant as an option to choose from when defining a group |
| 28 | + key V1. Relevant for signing new tranches of assets only: A single |
| 29 | + `OP_RETURN` leaf would be present in the group key's tapscript tree that |
| 30 | + commits to the group anchor's asset ID. |
| 31 | + - The Pedersen commitment scheme for signing minting events with the group key |
| 32 | + and for generating unique script keys in V2 TAP address sends. |
| 33 | + - Relevant as an option to choose from when defining a group |
| 34 | + key V1. Relevant for signing new tranches of assets: A single |
| 35 | + `<pedersen_key> OP_CHECKSIG` leaf would be present in the group key's |
| 36 | + tapscript tree that commits to the group anchor's asset ID through a |
| 37 | + Pedersen commitment key. |
| 38 | + - This is also relevant for outputs created for sends to V2 TAP addresses. |
| 39 | + The receiver script keys are constructed with a Pedersen commitment, so |
| 40 | + if the internal key of the script key is held in a signing device, then |
| 41 | + authorizing the spend of such an output would require the signing device |
| 42 | + to be able to deal with such a leaf being present. |
| 43 | + |
| 44 | +## On-chain Taproot Asset Root Commitment Structure |
| 45 | + |
| 46 | +The Taproot Asset commitment is what is placed in a tap leaf of a transaction |
| 47 | +output's tapscript tree. The exact structure of the leaf script depends on the |
| 48 | +commitment version. |
| 49 | +
|
| 50 | +### V0 and V1 Commitments |
| 51 | +
|
| 52 | +For `TapCommitmentV0` and `TapCommitmentV1`, the tap leaf script is constructed |
| 53 | +as follows: |
| 54 | +
|
| 55 | +`version (1 byte) || TaprootAssetsMarker (32 bytes) || root_hash (32 bytes) || |
| 56 | +root_sum (8 bytes)` |
| 57 | +
|
| 58 | +Where: |
| 59 | +- `version`: The `TapCommitmentVersion`, which is `0` for V0 and `1` for V1. |
| 60 | +- `TaprootAssetsMarker`: A static marker to identify the leaf as a Taproot Asset |
| 61 | + commitment. It is the `sha256` hash of the string `taproot-assets`. |
| 62 | +- `root_hash`: The MS-SMT root of the `TapCommitment`, which commits to all the |
| 63 | + asset commitments within it. |
| 64 | +- `root_sum`: The sum of all asset amounts under that `TapCommitment` root. |
| 65 | +
|
| 66 | +### V2 Commitments |
| 67 | +
|
| 68 | +For `TapCommitmentV2`, the tap leaf script is constructed as follows: |
| 69 | +
|
| 70 | +`tag (32 bytes) || version (1 byte) || root_hash (32 bytes) || |
| 71 | +root_sum (8 bytes)` |
| 72 | +
|
| 73 | +Where: |
| 74 | +- `tag`: A tagged hash to uniquely identify this as a V2+ Taproot Asset |
| 75 | + commitment. It is the `sha256` hash of the string `taproot-assets:194243`. |
| 76 | +- `version`: The `TapCommitmentVersion`, which is `2` for V2. |
| 77 | +- `root_hash`: The MS-SMT root of the `TapCommitment`, which commits to all the |
| 78 | + asset commitments within it. |
| 79 | +- `root_sum`: The sum of all asset amounts under that `TapCommitment` root. |
| 80 | +
|
| 81 | +## Group Key Commitment Schemes |
| 82 | +
|
| 83 | +To commit to a group key, two main schemes are used to create non-spendable |
| 84 | +tapscript leaves. These leaves are used to commit to the genesis asset ID within |
| 85 | +the group key's tapscript tree and therefore a signing device signing a new |
| 86 | +asset tranche needs to be able to deal with such a leaf being present in the |
| 87 | +tapscript tree. |
| 88 | + |
| 89 | +### OP_RETURN Commitment |
| 90 | + |
| 91 | +This scheme creates a non-spendable script by using the `OP_RETURN` opcode. |
| 92 | +The script is constructed as follows: |
| 93 | + |
| 94 | +`OP_RETURN || <data>` |
| 95 | + |
| 96 | +Where: |
| 97 | +- `data`: The data to be committed to, which is typically the genesis asset ID. |
| 98 | + |
| 99 | +This creates a script that will terminate execution early, making it provably |
| 100 | +unspendable. |
| 101 | + |
| 102 | +### Pedersen Commitment |
| 103 | + |
| 104 | +This scheme uses a normal `OP_CHECKSIG` operator with a public key that cannot |
| 105 | +be signed for. This special public key is generated using a Pedersen |
| 106 | +commitment. The script is constructed as follows: |
| 107 | + |
| 108 | +`<tweaked_nums_key> OP_CHECKSIG` |
| 109 | + |
| 110 | +Where: |
| 111 | +- `tweaked_nums_key`: A public key derived from a Pedersen commitment. The |
| 112 | + message for the commitment is the asset ID (or 32 zero bytes if no data is |
| 113 | + provided). To achieve hardware wallet support, this key is turned into an |
| 114 | + extended key (xpub), and a child key at path `0/0` is used as the actual |
| 115 | + public key that goes into the `OP_CHECKSIG` script. |
| 116 | + |
0 commit comments