@kontor/kontor-sdk 1.0.0-alpha.4 → 1.0.0-alpha.6

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.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "author": "Unspendable Labs <dev@unspendablelabs.com>",
5
5
  "description": "The official SDK to the Kontor Bitcoin metaprotocol",
6
6
  "repository": {
@@ -7,7 +7,11 @@ import type { GetAccountParameter } from "../../../types/account.js";
7
7
  import type { Chain, GetChainParameter } from "../../../types/chain.js";
8
8
  import { getAction } from "../../../utils/get-action.js";
9
9
  import { signPsbt } from "../../wallet/sign-psbt.js";
10
- import { p2tr, taprootListToTree, Transaction } from "@scure/btc-signer";
10
+ import {
11
+ TaprootControlBlock,
12
+ Transaction,
13
+ utils as u,
14
+ } from "@scure/btc-signer";
11
15
  import { hex } from "@scure/base";
12
16
  import type { ParticipantScripts } from "@kontor/kontor-ts";
13
17
 
@@ -51,30 +55,21 @@ export async function signReveal<
51
55
  for (let i = 0; i < params.parcipantScripts.length; i++) {
52
56
  const { commit_tap_leaf_script } = params.parcipantScripts[i]!;
53
57
 
54
- const tree = taprootListToTree([
55
- {
56
- // TODO: fix this type error
57
- // @ts-ignore
58
- script: hex.decode(commit_tap_leaf_script.script),
59
- leafVersion: commit_tap_leaf_script.leafVersion,
60
- },
61
- ]);
62
-
63
- const payment = p2tr(
64
- // @ts-ignore
65
- undefined,
66
- tree,
67
- // TODO: must assert chain or default to mainnet
68
- chain!.networkConfig,
69
- true,
58
+ const scriptBytes = hex.decode(commit_tap_leaf_script.script);
59
+ const controlBlockBytes = hex.decode(commit_tap_leaf_script.controlBlock);
60
+ // const leafVersion = commit_tap_leaf_script.leafVersion;
61
+
62
+ const scriptWithVersion = u.concatBytes(
63
+ scriptBytes,
64
+ // new Uint8Array([leafVersion]),
70
65
  );
71
66
 
67
+ const controlBlockStruct = TaprootControlBlock.decode(controlBlockBytes);
68
+
72
69
  tx.updateInput(
73
70
  i,
74
71
  {
75
- tapLeafScript: payment.tapLeafScript!,
76
- tapInternalKey: payment.tapInternalKey,
77
- tapMerkleRoot: payment.tapMerkleRoot,
72
+ tapLeafScript: [[controlBlockStruct, scriptWithVersion]],
78
73
  },
79
74
  true,
80
75
  );
@@ -33,9 +33,164 @@ export const nativeTokenRaw = [
33
33
 
34
34
  export const wit = parseWit(nativeTokenRaw);
35
35
 
36
+ // test("e2e kontor wallet client", async () => {
37
+ // const account = mnemonicToAccount(process.env.TEST_MNEMONIC!);
38
+ //
39
+ // const kontorPublicClient = createKontorPublicClient({
40
+ // transport: http("https://signet-staging.kontor.network:35000/api"),
41
+ // account,
42
+ // chain: signet,
43
+ // });
44
+ //
45
+ // const kontorWalletClient = createKontorWalletClient({
46
+ // account,
47
+ // // TODO: transport is not used for local account.
48
+ // transport: custom({
49
+ // request: async (_args: any) => null,
50
+ // }),
51
+ // });
52
+ //
53
+ // const res = await kontorPublicClient.procContract({
54
+ // wit: wit,
55
+ // // TODO: add optional account override
56
+ //
57
+ // functionName: "mint", // functin name is only valid if it's got a proc-context
58
+ // contractAddress: "token_0_0",
59
+ // args: [[7n, 18]],
60
+ // satsPerVByte: 1,
61
+ // utxos: [
62
+ // "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
63
+ // ],
64
+ // gas: 10n,
65
+ // });
66
+ //
67
+ // const commit: Transaction = await kontorWalletClient.signCommit({
68
+ // account: account,
69
+ // chain: signet,
70
+ // psbt: res.result.commit_psbt_hex,
71
+ // });
72
+ //
73
+ // const reveal: Transaction = await kontorWalletClient.signReveal({
74
+ // account: account,
75
+ // chain: signet,
76
+ // psbt: res.result.reveal_psbt_hex,
77
+ // parcipantScripts: res.result.per_participant,
78
+ // });
79
+ //
80
+ // const commitExtracted = commit.extract();
81
+ // const revealExtracted = reveal.extract();
82
+ //
83
+ // // const m = await btcPublicClient.testMempoolAccept({
84
+ // // rawtx: [hex.encode(commitExtracted), hex.encode(revealExtracted)],
85
+ // // options: {},
86
+ // // });
87
+ // //
88
+ //
89
+ // const r = await fetch("https://signet.kontor.network:38332", {
90
+ // method: "POST",
91
+ // headers: {
92
+ // "Content-Type": "application/json",
93
+ // Authorization: `Basic ${Buffer.from("rpc:rpc").toString("base64")}`,
94
+ // },
95
+ // body: JSON.stringify({
96
+ // method: "testmempoolaccept",
97
+ // params: [[hex.encode(commitExtracted), hex.encode(revealExtracted)]],
98
+ // }),
99
+ // });
100
+ // console.log({
101
+ // r,
102
+ // reveal: [hex.encode(commitExtracted), hex.encode(revealExtracted)],
103
+ // });
104
+ //
105
+ // const j = await r.json();
106
+ //
107
+ // console.log(j);
108
+ // //
109
+ // // const op = await kontorPublicClient.inspect({
110
+ // // hex: hex.encode(revealExtracted),
111
+ // // });
112
+ //
113
+ // // console.log(JSON.stringify(op.result[0]!.op));
114
+ // //
115
+ // });
116
+
36
117
  test("e2e kontor wallet client", async () => {
37
118
  const account = mnemonicToAccount(process.env.TEST_MNEMONIC!);
38
119
 
120
+ const res = {
121
+ result: {
122
+ commit_transaction: {
123
+ version: 2,
124
+ lock_time: 0,
125
+ input: [
126
+ {
127
+ previous_output:
128
+ "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
129
+ script_sig: "",
130
+ sequence: 4294967295,
131
+ witness: [],
132
+ },
133
+ ],
134
+ output: [
135
+ {
136
+ value: 570,
137
+ script_pubkey:
138
+ "51207fe892a65813b770346d37f8fbbdf5c1e6bee0bc34b0c625e8f4ca5ff3ad144f",
139
+ },
140
+ {
141
+ value: 8502,
142
+ script_pubkey:
143
+ "5120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f",
144
+ },
145
+ ],
146
+ },
147
+ commit_transaction_hex:
148
+ "0200000001332a0e2d0c369ebb984ce8addb4387bd6702f59b255ceada1c0fcff4ed401c640100000000ffffffff023a020000000000002251207fe892a65813b770346d37f8fbbdf5c1e6bee0bc34b0c625e8f4ca5ff3ad144f3621000000000000225120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f00000000",
149
+ commit_psbt_hex:
150
+ "70736274ff0100890200000001332a0e2d0c369ebb984ce8addb4387bd6702f59b255ceada1c0fcff4ed401c640100000000ffffffff023a020000000000002251207fe892a65813b770346d37f8fbbdf5c1e6bee0bc34b0c625e8f4ca5ff3ad144f3621000000000000225120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f000000000001012b8e24000000000000225120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f0117202c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f000000",
151
+ reveal_transaction: {
152
+ version: 2,
153
+ lock_time: 0,
154
+ input: [
155
+ {
156
+ previous_output:
157
+ "4b195fabb3bd5360de2e2db6821df9d8909f0dbd5f1ba50ae1ca71a841080c3d:0",
158
+ script_sig: "",
159
+ sequence: 4294967295,
160
+ witness: [],
161
+ },
162
+ ],
163
+ output: [
164
+ {
165
+ value: 330,
166
+ script_pubkey:
167
+ "5120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f",
168
+ },
169
+ ],
170
+ },
171
+ reveal_transaction_hex:
172
+ "02000000013d0c0841a871cae10aa51b5fbd0d9f90d8f91d82b62d2ede6053bdb3ab5f194b0000000000ffffffff014a01000000000000225120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f00000000",
173
+ reveal_psbt_hex:
174
+ "70736274ff01005e02000000013d0c0841a871cae10aa51b5fbd0d9f90d8f91d82b62d2ede6053bdb3ab5f194b0000000000ffffffff014a01000000000000225120929c39410fb437b4ff387ec898cbc098365d91965073004fc43e013d410d417f000000000001012b3a020000000000002251207fe892a65813b770346d37f8fbbdf5c1e6bee0bc34b0c625e8f4ca5ff3ad144f0117202c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f0000",
175
+ per_participant: [
176
+ {
177
+ address:
178
+ "tb1pj2wrjsg0ksmmflec0myf3j7qnqm9myvk2pesqn7y8cqn6sgdg9ls9u6tar",
179
+ x_only_public_key:
180
+ "2c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f",
181
+ commit_tap_leaf_script: {
182
+ leafVersion: 192,
183
+ script:
184
+ "202c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51fac0063036b6f6e00010268",
185
+ controlBlock:
186
+ "c12c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f",
187
+ },
188
+ chained_tap_leaf_script: null,
189
+ },
190
+ ],
191
+ },
192
+ };
193
+
39
194
  const kontorPublicClient = createKontorPublicClient({
40
195
  transport: http("https://signet-staging.kontor.network:35000/api"),
41
196
  account,
@@ -50,19 +205,19 @@ test("e2e kontor wallet client", async () => {
50
205
  }),
51
206
  });
52
207
 
53
- const res = await kontorPublicClient.procContract({
54
- wit: wit,
55
- // TODO: add optional account override
56
-
57
- functionName: "mint", // functin name is only valid if it's got a proc-context
58
- contractAddress: "token_0_0",
59
- args: [[7n, 18]],
60
- satsPerVByte: 1,
61
- utxos: [
62
- "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
63
- ],
64
- gas: 10n,
65
- });
208
+ // const res = await kontorPublicClient.procContract({
209
+ // wit: wit,
210
+ // // TODO: add optional account override
211
+ //
212
+ // functionName: "mint", // functin name is only valid if it's got a proc-context
213
+ // contractAddress: "token_0_0",
214
+ // args: [[7n, 18]],
215
+ // satsPerVByte: 1,
216
+ // utxos: [
217
+ // "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
218
+ // ],
219
+ // gas: 10n,
220
+ // });
66
221
 
67
222
  const commit: Transaction = await kontorWalletClient.signCommit({
68
223
  account: account,
@@ -84,7 +239,6 @@ test("e2e kontor wallet client", async () => {
84
239
  // rawtx: [hex.encode(commitExtracted), hex.encode(revealExtracted)],
85
240
  // options: {},
86
241
  // });
87
- //
88
242
 
89
243
  const r = await fetch("https://signet.kontor.network:38332", {
90
244
  method: "POST",
@@ -97,16 +251,15 @@ test("e2e kontor wallet client", async () => {
97
251
  params: [[hex.encode(commitExtracted), hex.encode(revealExtracted)]],
98
252
  }),
99
253
  });
100
- console.log({ r, reveal: hex.encode(revealExtracted) });
101
254
 
102
- const j = await r.json();
255
+ const mempoolAccept = await r.json();
103
256
 
104
- console.log(j);
257
+ console.log({ mempoolAccept: mempoolAccept.result });
105
258
  //
106
- // const op = await kontorPublicClient.inspect({
107
- // hex: hex.encode(revealExtracted),
108
- // });
259
+ const op = await kontorPublicClient.inspect({
260
+ hex: hex.encode(revealExtracted),
261
+ });
109
262
 
110
- // console.log(JSON.stringify(op.result[0]!.op));
263
+ console.log(JSON.stringify(op.result[0]!.op));
111
264
  //
112
265
  });