@kontor/kontor-sdk 1.0.0-alpha.7 → 1.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontor/kontor-sdk",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
4
4
  "author": "Unspendable Labs <dev@unspendablelabs.com>",
5
5
  "description": "The official SDK to the Kontor Bitcoin metaprotocol",
6
6
  "repository": {
@@ -55,28 +55,25 @@ export async function signReveal<
55
55
  for (let i = 0; i < params.parcipantScripts.length; i++) {
56
56
  const { commit_tap_leaf_script } = params.parcipantScripts[i]!;
57
57
 
58
- // 1. Raw tapscript from compose (no version byte)
59
58
  const scriptBytes = hex.decode(commit_tap_leaf_script.script);
60
-
61
- // 2. Control block from compose (contains version + internal key + path)
62
59
  const controlBlockBytes = hex.decode(commit_tap_leaf_script.controlBlock);
63
- const controlBlock = TaprootControlBlock.decode(controlBlockBytes);
64
-
65
- // Optional sanity check:
66
- const versionFromCB = controlBlock.version & 0xfe;
67
- if (
68
- commit_tap_leaf_script.leafVersion !== undefined &&
69
- commit_tap_leaf_script.leafVersion !== versionFromCB
70
- ) {
71
- console.warn(
72
- "LeafVersion mismatch between ParticipantScripts and controlBlock",
73
- );
74
- }
75
-
76
- // 3. PSBT encoding: [controlBlock, scriptBytes]
77
- tx.updateInput(i, {
78
- tapLeafScript: [[controlBlock, scriptBytes]],
79
- });
60
+ const leafVersion = commit_tap_leaf_script.leafVersion;
61
+
62
+ // scure expects script || leafVersion as one buffer
63
+ const scriptWithVersion = u.concatBytes(
64
+ scriptBytes,
65
+ new Uint8Array([leafVersion ?? 0xc0]), // default 0xc0 if needed
66
+ );
67
+
68
+ const controlBlockStruct = TaprootControlBlock.decode(controlBlockBytes);
69
+
70
+ tx.updateInput(
71
+ i,
72
+ {
73
+ tapLeafScript: [[controlBlockStruct, scriptWithVersion]],
74
+ },
75
+ true,
76
+ );
80
77
  }
81
78
 
82
79
  const signInputs = Array.from(
@@ -112,18 +109,23 @@ export async function signReveal<
112
109
 
113
110
  // this is technically unnecessary as scure/btc-signer
114
111
  // will product this witness by default
115
- for (let i = 0; i < params.parcipantScripts.length; i++) {
116
- const input = signedTx.getInput(i);
117
- const p = params.parcipantScripts[i]!;
118
- console.log({ input, tapscriptsig: input.tapScriptSig });
119
- signedTx.updateInput(i, {
120
- finalScriptWitness: [
121
- input.tapScriptSig![0]![1],
122
- hex.decode(p.commit_tap_leaf_script.script),
123
- hex.decode(p.commit_tap_leaf_script.controlBlock),
124
- ],
125
- });
126
- }
112
+ // for (let i = 0; i < params.parcipantScripts.length; i++) {
113
+ // const input = signedTx.getInput(i);
114
+ // const p = params.parcipantScripts[i]!;
115
+ // console.log({ input, tapscriptsig: input.tapScriptSig });
116
+ //
117
+ // signedTx.updateInput(i, {
118
+ // finalScriptWitness: [
119
+ // input.tapScriptSig![0]![1],
120
+ // hex.decode(p.commit_tap_leaf_script.script),
121
+ // hex.decode(p.commit_tap_leaf_script.controlBlock),
122
+ // ],
123
+ // });
124
+ //
125
+ // delete input.tapScriptSig;
126
+ // delete input.tapKeySig;
127
+ // delete input.tapLeafScript;
128
+ // }
127
129
 
128
130
  return signedTx;
129
131
  }