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

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.
Files changed (113) hide show
  1. package/dist/src/kwit/error.js +59 -0
  2. package/dist/src/kwit/error.js.map +1 -0
  3. package/dist/src/kwit/kwit-parser/core/errors/kwit-parameter.js +29 -0
  4. package/dist/src/kwit/kwit-parser/core/errors/kwit-parameter.js.map +1 -0
  5. package/dist/src/kwit/kwit-parser/core/errors/signature.js +42 -0
  6. package/dist/src/kwit/kwit-parser/core/errors/signature.js.map +1 -0
  7. package/dist/src/kwit/kwit-parser/core/errors/splitParameters.js +18 -0
  8. package/dist/src/kwit/kwit-parser/core/errors/splitParameters.js.map +1 -0
  9. package/dist/src/kwit/kwit-parser/core/records.js +73 -0
  10. package/dist/src/kwit/kwit-parser/core/records.js.map +1 -0
  11. package/dist/src/kwit/kwit-parser/core/records.test.js +53 -0
  12. package/dist/src/kwit/kwit-parser/core/records.test.js.map +1 -0
  13. package/dist/src/kwit/kwit-parser/core/signatures.js +33 -0
  14. package/dist/src/kwit/kwit-parser/core/signatures.js.map +1 -0
  15. package/dist/src/kwit/kwit-parser/core/signatures.test.js +54 -0
  16. package/dist/src/kwit/kwit-parser/core/signatures.test.js.map +1 -0
  17. package/dist/src/kwit/kwit-parser/core/types/records.js +2 -0
  18. package/dist/src/kwit/kwit-parser/core/types/records.js.map +1 -0
  19. package/dist/src/kwit/kwit-parser/core/types/records.test-d.js +19 -0
  20. package/dist/src/kwit/kwit-parser/core/types/records.test-d.js.map +1 -0
  21. package/dist/src/kwit/kwit-parser/core/types/signatures.js +3 -0
  22. package/dist/src/kwit/kwit-parser/core/types/signatures.js.map +1 -0
  23. package/dist/src/kwit/kwit-parser/core/types/signatures.test-d.js +18 -0
  24. package/dist/src/kwit/kwit-parser/core/types/signatures.test-d.js.map +1 -0
  25. package/dist/src/kwit/kwit-parser/core/types/utils.js +2 -0
  26. package/dist/src/kwit/kwit-parser/core/types/utils.js.map +1 -0
  27. package/dist/src/kwit/kwit-parser/core/types/utils.test-d.js +159 -0
  28. package/dist/src/kwit/kwit-parser/core/types/utils.test-d.js.map +1 -0
  29. package/dist/src/kwit/kwit-parser/core/utils.js +212 -0
  30. package/dist/src/kwit/kwit-parser/core/utils.js.map +1 -0
  31. package/dist/src/kwit/kwit-parser/core/utils.test.js +302 -0
  32. package/dist/src/kwit/kwit-parser/core/utils.test.js.map +1 -0
  33. package/dist/src/kwit/kwit-parser/parse-kwit-parameter.js +26 -0
  34. package/dist/src/kwit/kwit-parser/parse-kwit-parameter.js.map +1 -0
  35. package/dist/src/kwit/kwit-parser/parse-kwit-parameter.test.js +83 -0
  36. package/dist/src/kwit/kwit-parser/parse-kwit-parameter.test.js.map +1 -0
  37. package/dist/src/kwit/kwit-parser/parse-kwit.js +16 -0
  38. package/dist/src/kwit/kwit-parser/parse-kwit.js.map +1 -0
  39. package/dist/src/kwit/kwit-parser/parse-kwit.test.js +78 -0
  40. package/dist/src/kwit/kwit-parser/parse-kwit.test.js.map +1 -0
  41. package/dist/src/kwit/kwit.js +2 -0
  42. package/dist/src/kwit/kwit.js.map +1 -0
  43. package/dist/src/kwit/kwit.test.js +9 -0
  44. package/dist/src/kwit/kwit.test.js.map +1 -0
  45. package/dist/src/kwit/narrow.js +14 -0
  46. package/dist/src/kwit/narrow.js.map +1 -0
  47. package/dist/src/kwit/regex.js +6 -0
  48. package/dist/src/kwit/regex.js.map +1 -0
  49. package/dist/src/kwit/register.js +2 -0
  50. package/dist/src/kwit/register.js.map +1 -0
  51. package/dist/src/kwit/type-utils.js +2 -0
  52. package/dist/src/kwit/type-utils.js.map +1 -0
  53. package/dist/src/kwit/utils.js +2 -0
  54. package/dist/src/kwit/utils.js.map +1 -0
  55. package/dist/src/kwit/utils.test-d.js +17 -0
  56. package/dist/src/kwit/utils.test-d.js.map +1 -0
  57. package/dist/src/kwit/version.js +2 -0
  58. package/dist/src/kwit/version.js.map +1 -0
  59. package/dist/src/sdk/actions/kontor/wallet/sign-reveal.js +0 -3
  60. package/dist/src/sdk/actions/kontor/wallet/sign-reveal.js.map +1 -1
  61. package/dist/src/sdk/actions/public/test-mempool-accept.js +8 -32
  62. package/dist/src/sdk/actions/public/test-mempool-accept.js.map +1 -1
  63. package/dist/src/sdk/clients/decorators/public.js +2 -0
  64. package/dist/src/sdk/clients/decorators/public.js.map +1 -1
  65. package/dist/src/sdk/errors/kwit.js +19 -0
  66. package/dist/src/sdk/errors/kwit.js.map +1 -0
  67. package/dist/src/sdk/test/e2e.test.js +27 -6
  68. package/dist/src/sdk/test/e2e.test.js.map +1 -1
  69. package/dist/src/sdk/utils/kwit/codecs/decimal.js +165 -0
  70. package/dist/src/sdk/utils/kwit/codecs/decimal.js.map +1 -0
  71. package/dist/src/sdk/utils/kwit/codecs/enum.js +104 -0
  72. package/dist/src/sdk/utils/kwit/codecs/enum.js.map +1 -0
  73. package/dist/src/sdk/utils/kwit/codecs/integer.js +167 -0
  74. package/dist/src/sdk/utils/kwit/codecs/integer.js.map +1 -0
  75. package/dist/src/sdk/utils/kwit/codecs/list.js +117 -0
  76. package/dist/src/sdk/utils/kwit/codecs/list.js.map +1 -0
  77. package/dist/src/sdk/utils/kwit/codecs/option.js +91 -0
  78. package/dist/src/sdk/utils/kwit/codecs/option.js.map +1 -0
  79. package/dist/src/sdk/utils/kwit/codecs/string.js +27 -0
  80. package/dist/src/sdk/utils/kwit/codecs/string.js.map +1 -0
  81. package/dist/src/sdk/utils/kwit/codecs/types.js +45 -0
  82. package/dist/src/sdk/utils/kwit/codecs/types.js.map +1 -0
  83. package/dist/src/sdk/utils/kwit/codecs/unit.js +22 -0
  84. package/dist/src/sdk/utils/kwit/codecs/unit.js.map +1 -0
  85. package/dist/src/sdk/utils/kwit/decode-function-result.js +36 -0
  86. package/dist/src/sdk/utils/kwit/decode-function-result.js.map +1 -0
  87. package/dist/src/sdk/utils/kwit/decode-kwit-parameter.js +286 -0
  88. package/dist/src/sdk/utils/kwit/decode-kwit-parameter.js.map +1 -0
  89. package/dist/src/sdk/utils/kwit/decode-kwit-parameter.test.js +75 -0
  90. package/dist/src/sdk/utils/kwit/decode-kwit-parameter.test.js.map +1 -0
  91. package/dist/src/sdk/utils/kwit/encode-function-data.js +17 -0
  92. package/dist/src/sdk/utils/kwit/encode-function-data.js.map +1 -0
  93. package/dist/src/sdk/utils/kwit/encode-function-data.test-d.js +21 -0
  94. package/dist/src/sdk/utils/kwit/encode-function-data.test-d.js.map +1 -0
  95. package/dist/src/sdk/utils/kwit/encode-function-data.test.js +91 -0
  96. package/dist/src/sdk/utils/kwit/encode-function-data.test.js.map +1 -0
  97. package/dist/src/sdk/utils/kwit/encode-kwit-parameters.js +250 -0
  98. package/dist/src/sdk/utils/kwit/encode-kwit-parameters.js.map +1 -0
  99. package/dist/src/sdk/utils/kwit/encode-kwit-parameters.test.js +62 -0
  100. package/dist/src/sdk/utils/kwit/encode-kwit-parameters.test.js.map +1 -0
  101. package/dist/src/sdk/utils/kwit/get-kwit-item.js +186 -0
  102. package/dist/src/sdk/utils/kwit/get-kwit-item.js.map +1 -0
  103. package/dist/src/sdk/utils/kwit/get-kwit-item.test.js +119 -0
  104. package/dist/src/sdk/utils/kwit/get-kwit-item.test.js.map +1 -0
  105. package/dist/src/sdk/utils/kwit/prepare-encode-function-data.js +24 -0
  106. package/dist/src/sdk/utils/kwit/prepare-encode-function-data.js.map +1 -0
  107. package/dist/tsconfig.tsbuildinfo +1 -1
  108. package/package.json +6 -2
  109. package/src/sdk/actions/kontor/wallet/sign-reveal.ts +0 -4
  110. package/src/sdk/actions/public/test-mempool-accept.ts +34 -31
  111. package/src/sdk/clients/decorators/public.ts +11 -0
  112. package/src/sdk/test/e2e.test.ts +31 -6
  113. package/src/sdk/types/btc-rpc.ts +12 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontor/kontor-sdk",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.4",
4
4
  "author": "Unspendable Labs <dev@unspendablelabs.com>",
5
5
  "description": "The official SDK to the Kontor Bitcoin metaprotocol",
6
6
  "repository": {
@@ -65,5 +65,9 @@
65
65
  "micro-packed": "^0.8.0",
66
66
  "sats-connect": "^4.2.1",
67
67
  "zod": "^4.1.12"
68
- }
68
+ },
69
+ "workspaces": [
70
+ ".",
71
+ "demo"
72
+ ]
69
73
  }
@@ -120,15 +120,11 @@ export async function signReveal<
120
120
  signedTx.updateInput(i, {
121
121
  finalScriptWitness: [
122
122
  input.tapScriptSig![0]![1],
123
- // @ts-ignore
124
123
  hex.decode(p.commit_tap_leaf_script.script),
125
- // @ts-ignore
126
124
  hex.decode(p.commit_tap_leaf_script.controlBlock),
127
125
  ],
128
126
  });
129
127
  }
130
128
 
131
- signedTx.finalize();
132
-
133
129
  return signedTx;
134
130
  }
@@ -1,34 +1,37 @@
1
- // import type { Chain } from "../../types/chain.js";
2
- //
3
- // import type { RpcTransport } from "../../clients/transports/create-rpc-transport.js";
4
- // import type { PublicClient } from "../../clients/create-public-client.js";
5
- // import type { Account } from "../../accounts/types.js";
6
- //
7
- // export type TestMempoolAcceptOptions = {
8
- // /** Max feerate in BTC/kvB. If omitted, Core uses default relay feerate. */
9
- // maxfeerate?: string | number;
10
- // };
11
- //
12
- // export interface TestMempoolAcceptParams {
13
- // rawtx: string | string[];
14
- // options: TestMempoolAcceptOptions;
15
- // }
16
- // export type TestMempoolAcceptReturnType = any;
17
- //
18
- // export async function testMempoolAccept<
19
- // chain extends Chain | undefined,
20
- // account extends Account | undefined = Account | undefined,
21
- // >(
22
- // client: PublicClient<RpcTransport, chain, account>,
23
- // { rawtx, options = {} }: TestMempoolAcceptParams,
24
- // ): Promise<TestMempoolAcceptReturnType> {
25
- // const txs = Array.isArray(rawtx) ? rawtx : [rawtx];
26
- //
27
- // return client.request({
28
- // method: "testmempoolaccept",
29
- // params: [txs],
30
- // });
31
- // }
1
+ import type { Chain } from "../../types/chain.js";
2
+
3
+ import type { RpcTransport } from "../../clients/transports/create-rpc-transport.js";
4
+ import type { PublicClient } from "../../clients/create-public-client.js";
5
+ import type { Account } from "../../accounts/types.js";
6
+
7
+ export type TestMempoolAcceptOptions = {
8
+ /** Max feerate in BTC/kvB. If omitted, Core uses default relay feerate. */
9
+ maxfeerate?: string | number;
10
+ };
11
+
12
+ export interface TestMempoolAcceptParams {
13
+ rawtx: string | string[];
14
+ options: TestMempoolAcceptOptions;
15
+ }
16
+
17
+ export type TestMempoolAcceptReturnType = any;
18
+
19
+ export async function testMempoolAccept<
20
+ chain extends Chain | undefined,
21
+ account extends Account | undefined = Account | undefined,
22
+ >(
23
+ client: PublicClient<RpcTransport, chain, account>,
24
+ { rawtx, options = {} }: TestMempoolAcceptParams,
25
+ ): Promise<TestMempoolAcceptReturnType> {
26
+ const txs = Array.isArray(rawtx) ? rawtx : [rawtx];
27
+
28
+ const params = options.maxfeerate !== undefined ? [txs, options] : [txs];
29
+
30
+ return client.request({
31
+ method: "testmempoolaccept",
32
+ params: params as any,
33
+ });
34
+ }
32
35
 
33
36
  // export async function testMempoolAccept(
34
37
  // rawtx: string | string[],
@@ -8,6 +8,13 @@ import {
8
8
  type SendRawTransactionReturnType,
9
9
  sendRawTransaction,
10
10
  } from "../../actions/public/send-raw-transaction.js";
11
+
12
+ import {
13
+ type TestMempoolAcceptParams,
14
+ type TestMempoolAcceptReturnType,
15
+ testMempoolAccept,
16
+ } from "../../actions/public/test-mempool-accept.js";
17
+
11
18
  import type { PublicClient as PublicClient } from "../create-public-client.js";
12
19
 
13
20
  export type PublicActions<
@@ -20,6 +27,9 @@ export type PublicActions<
20
27
  sendRawTransaction: (
21
28
  parameters: SendRawTransactionParams,
22
29
  ) => Promise<SendRawTransactionReturnType>;
30
+ testMempoolAccept: (
31
+ parameters: TestMempoolAcceptParams,
32
+ ) => Promise<TestMempoolAcceptReturnType>;
23
33
  };
24
34
 
25
35
  export function publicActions<
@@ -31,5 +41,6 @@ export function publicActions<
31
41
  ): PublicActions<chain, account> {
32
42
  return {
33
43
  sendRawTransaction: (args) => sendRawTransaction(client, args),
44
+ testMempoolAccept: (args) => testMempoolAccept(client, args),
34
45
  };
35
46
  }
@@ -5,6 +5,7 @@ import { createPublicClient as createKontorPublicClient } from "../clients/konto
5
5
  import { http } from "../clients/transports/http.js";
6
6
  import { mnemonicToAccount } from "../accounts/mnemonic-to-account.js";
7
7
  import { createWalletClient as createKontorWalletClient } from "../clients/kontor/create-wallet-client.js";
8
+
8
9
  import { custom } from "../clients/transports/custom.js";
9
10
  import { Transaction } from "@scure/btc-signer";
10
11
  import { hex } from "@scure/base";
@@ -38,6 +39,7 @@ test("e2e kontor wallet client", async () => {
38
39
  const kontorPublicClient = createKontorPublicClient({
39
40
  transport: http("https://signet-staging.kontor.network:35000/api"),
40
41
  account,
42
+ chain: signet,
41
43
  });
42
44
 
43
45
  const kontorWalletClient = createKontorWalletClient({
@@ -57,13 +59,12 @@ test("e2e kontor wallet client", async () => {
57
59
  args: [[7n, 18]],
58
60
  satsPerVByte: 1,
59
61
  utxos: [
60
- "57f1f46857ab12e20f32ecaac780b4096b0951458e15ab08e2ce0992f0521323:0",
62
+ "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
61
63
  ],
62
64
  gas: 10n,
63
65
  });
64
66
 
65
- // @ts-ignore
66
- const commit_: Transaction = await kontorWalletClient.signCommit({
67
+ const commit: Transaction = await kontorWalletClient.signCommit({
67
68
  account: account,
68
69
  chain: signet,
69
70
  psbt: res.result.commit_psbt_hex,
@@ -76,12 +77,36 @@ test("e2e kontor wallet client", async () => {
76
77
  parcipantScripts: res.result.per_participant,
77
78
  });
78
79
 
80
+ const commitExtracted = commit.extract();
79
81
  const revealExtracted = reveal.extract();
80
82
 
81
- const op = await kontorPublicClient.inspect({
82
- hex: hex.encode(revealExtracted),
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
+ }),
83
99
  });
100
+ console.log({ r, reveal: hex.encode(revealExtracted) });
101
+
102
+ const j = await r.json();
103
+
104
+ console.log(j);
105
+ //
106
+ // const op = await kontorPublicClient.inspect({
107
+ // hex: hex.encode(revealExtracted),
108
+ // });
84
109
 
85
- console.log(JSON.stringify(op.result[0]!.op));
110
+ // console.log(JSON.stringify(op.result[0]!.op));
86
111
  //
87
112
  });
@@ -1,10 +1,5 @@
1
1
  import type { Prettify } from "../../wit/type-utils.js";
2
2
 
3
- // import type {
4
- // TestMempoolAcceptParams,
5
- // TestMempoolAcceptReturnType,
6
- // } from "../actions/public/test-mempool-accept.js";
7
-
8
3
  import type { RpcRequestFn, RpcSchema, RpcSchemaEntry } from "./rpc-schema.js";
9
4
 
10
5
  export type SendRawTransactionParams = [
@@ -16,18 +11,24 @@ export interface SendRawTransactionReturnType {
16
11
  txid: string;
17
12
  }
18
13
 
14
+ export type TestMempoolAcceptParams = [
15
+ txs: string[],
16
+ opts?: { maxFeeRate: number | string },
17
+ ];
18
+
19
+ export type TestMempoolAcceptReturnType = any;
20
+
19
21
  export type BtcRpcSchema = readonly [
20
22
  RpcSchemaEntry<
21
23
  "sendrawtransaction",
22
24
  SendRawTransactionParams,
23
25
  SendRawTransactionReturnType
24
26
  >,
25
- // RpcSchemaEntry<
26
- // "testmempoolaccept",
27
- // // todo add options
28
- // [TestMempoolAcceptParams["rawtx"]],
29
- // string[][]
30
- // >,
27
+ RpcSchemaEntry<
28
+ "testmempoolaccept",
29
+ TestMempoolAcceptParams,
30
+ TestMempoolAcceptReturnType
31
+ >,
31
32
  ];
32
33
 
33
34
  export type BtcNodeRequestFn<