@kontor/kontor-sdk 1.0.0-alpha.19 → 1.0.0-alpha.20

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 (111) hide show
  1. package/dist/src/exports/index.test.js +27 -0
  2. package/dist/src/exports/index.test.js.map +1 -0
  3. package/dist/src/sdk/accounts/private-key-to-account.js +42 -0
  4. package/dist/src/sdk/accounts/private-key-to-account.js.map +1 -0
  5. package/dist/src/sdk/actions/get-contract.js +50 -0
  6. package/dist/src/sdk/actions/get-contract.js.map +1 -0
  7. package/dist/src/sdk/actions/get-contract.test-d.js +43 -0
  8. package/dist/src/sdk/actions/get-contract.test-d.js.map +1 -0
  9. package/dist/src/sdk/actions/kontor/public/call-view.js +21 -0
  10. package/dist/src/sdk/actions/kontor/public/call-view.js.map +1 -0
  11. package/dist/src/sdk/actions/kontor/public/inspect.js +20 -0
  12. package/dist/src/sdk/actions/kontor/public/inspect.js.map +1 -0
  13. package/dist/src/sdk/actions/kontor/public/proc-contract.test.js +47 -0
  14. package/dist/src/sdk/actions/kontor/public/proc-contract.test.js.map +1 -0
  15. package/dist/src/sdk/actions/kontor/public/view-contract.js +47 -0
  16. package/dist/src/sdk/actions/kontor/public/view-contract.js.map +1 -0
  17. package/dist/src/sdk/actions/kontor/public/view-contract.test-d.js +29 -0
  18. package/dist/src/sdk/actions/kontor/public/view-contract.test-d.js.map +1 -0
  19. package/dist/src/sdk/actions/kontor/wallet/sign-reveal.js +59 -0
  20. package/dist/src/sdk/actions/kontor/wallet/sign-reveal.js.map +1 -0
  21. package/dist/src/sdk/actions/wallet/get-addresses.js +20 -0
  22. package/dist/src/sdk/actions/wallet/get-addresses.js.map +1 -0
  23. package/dist/src/sdk/actions/wallet/sign-psbt.js +28 -0
  24. package/dist/src/sdk/actions/wallet/sign-psbt.js.map +1 -0
  25. package/dist/src/sdk/clients/base/create-http-client.js +41 -0
  26. package/dist/src/sdk/clients/base/create-http-client.js.map +1 -0
  27. package/dist/src/sdk/clients/base/create-rpc-client.js +41 -0
  28. package/dist/src/sdk/clients/base/create-rpc-client.js.map +1 -0
  29. package/dist/src/sdk/clients/base/create-rpc-client.test.js +151 -0
  30. package/dist/src/sdk/clients/base/create-rpc-client.test.js.map +1 -0
  31. package/dist/src/sdk/clients/create-public-client.js +13 -0
  32. package/dist/src/sdk/clients/create-public-client.js.map +1 -0
  33. package/dist/src/sdk/clients/create-public-client.test.js +121 -0
  34. package/dist/src/sdk/clients/create-public-client.test.js.map +1 -0
  35. package/dist/src/sdk/clients/create-wallet-client.js +14 -0
  36. package/dist/src/sdk/clients/create-wallet-client.js.map +1 -0
  37. package/dist/src/sdk/clients/kontor/create-public-client.js +14 -0
  38. package/dist/src/sdk/clients/kontor/create-public-client.js.map +1 -0
  39. package/dist/src/sdk/clients/kontor/create-public-client.test.js +45 -0
  40. package/dist/src/sdk/clients/kontor/create-public-client.test.js.map +1 -0
  41. package/dist/src/sdk/clients/transports/create-rpc-transport.js +36 -0
  42. package/dist/src/sdk/clients/transports/create-rpc-transport.js.map +1 -0
  43. package/dist/src/sdk/contracts/wits.js +26 -0
  44. package/dist/src/sdk/contracts/wits.js.map +1 -0
  45. package/dist/src/sdk/types/chain.js +2 -0
  46. package/dist/src/sdk/types/chain.js.map +1 -0
  47. package/dist/src/sdk/types/contract.js +2 -0
  48. package/dist/src/sdk/types/contract.js.map +1 -0
  49. package/dist/src/sdk/types/contract.test-d.js +34 -0
  50. package/dist/src/sdk/types/contract.test-d.js.map +1 -0
  51. package/dist/src/sdk/types/http-schema.js +73 -0
  52. package/dist/src/sdk/types/http-schema.js.map +1 -0
  53. package/dist/src/sdk/types/rpc-schema.js +2 -0
  54. package/dist/src/sdk/types/rpc-schema.js.map +1 -0
  55. package/dist/src/sdk/utils/chain/defineChain.js +9 -0
  56. package/dist/src/sdk/utils/chain/defineChain.js.map +1 -0
  57. package/dist/src/sdk/utils/wit/codecs/u64.js +63 -0
  58. package/dist/src/sdk/utils/wit/codecs/u64.js.map +1 -0
  59. package/dist/src/sdk/utils/wit/decode-wit-parameter.js +289 -0
  60. package/dist/src/sdk/utils/wit/decode-wit-parameter.js.map +1 -0
  61. package/dist/src/sdk/utils/wit/encode-function-data.test-d.js +24 -0
  62. package/dist/src/sdk/utils/wit/encode-function-data.test-d.js.map +1 -0
  63. package/dist/src/sdk/utils/wit/encode-function-data.test.js +91 -0
  64. package/dist/src/sdk/utils/wit/encode-function-data.test.js.map +1 -0
  65. package/dist/src/sdk/utils/wit/encode-wit-parameters.js +261 -0
  66. package/dist/src/sdk/utils/wit/encode-wit-parameters.js.map +1 -0
  67. package/dist/src/sdk/utils/wit/get-wit-item.test.js +167 -0
  68. package/dist/src/sdk/utils/wit/get-wit-item.test.js.map +1 -0
  69. package/dist/src/wit/wit-parser/core/records.test.js +63 -0
  70. package/dist/src/wit/wit-parser/core/records.test.js.map +1 -0
  71. package/dist/src/wit/wit-parser/core/types/records.test-d.js +19 -0
  72. package/dist/src/wit/wit-parser/core/types/records.test-d.js.map +1 -0
  73. package/dist/src/wit/wit-parser/core/types/utils.js +2 -0
  74. package/dist/src/wit/wit-parser/core/types/utils.js.map +1 -0
  75. package/dist/src/wit/wit-parser/core/types/utils.test-d.js +159 -0
  76. package/dist/src/wit/wit-parser/core/types/utils.test-d.js.map +1 -0
  77. package/dist/src/wit/wit-parser/core/utils.js +213 -0
  78. package/dist/src/wit/wit-parser/core/utils.js.map +1 -0
  79. package/dist/src/wit/wit-parser/core/utils.test.js +316 -0
  80. package/dist/src/wit/wit-parser/core/utils.test.js.map +1 -0
  81. package/dist/src/wit/wit-parser/parse-wit-parameter.test.js +93 -0
  82. package/dist/src/wit/wit-parser/parse-wit-parameter.test.js.map +1 -0
  83. package/dist/src/wit/wit-parser/parse-wit.test.js +80 -0
  84. package/dist/src/wit/wit-parser/parse-wit.test.js.map +1 -0
  85. package/dist/tsconfig.tsbuildinfo +1 -0
  86. package/package.json +1 -1
  87. package/src/exports/index.test.ts +18 -1
  88. package/src/sdk/actions/kontor/public/call-view.ts +6 -14
  89. package/src/sdk/actions/kontor/public/proc-contract.test.ts +1 -1
  90. package/src/sdk/actions/kontor/public/view-contract.test-d.ts +2 -17
  91. package/src/sdk/actions/kontor/public/view-contract.ts +8 -3
  92. package/src/sdk/actions/kontor/wallet/sign-reveal.ts +3 -35
  93. package/src/sdk/clients/base/create-rpc-client.test.ts +10 -4
  94. package/src/sdk/clients/create-public-client.test.ts +11 -3
  95. package/src/sdk/clients/kontor/create-public-client.test.ts +4 -3
  96. package/src/sdk/contracts/wits.ts +1 -1
  97. package/src/sdk/types/contract.test-d.ts +29 -24
  98. package/src/sdk/utils/wit/codecs/u64.ts +73 -0
  99. package/src/sdk/utils/wit/decode-wit-parameter.ts +5 -0
  100. package/src/sdk/utils/wit/encode-function-data.test-d.ts +15 -11
  101. package/src/sdk/utils/wit/encode-function-data.test.ts +1 -1
  102. package/src/sdk/utils/wit/encode-wit-parameters.ts +16 -1
  103. package/src/sdk/utils/wit/get-wit-item.test.ts +58 -9
  104. package/src/wit/wit-parser/core/records.test.ts +24 -14
  105. package/src/wit/wit-parser/core/types/records.test-d.ts +141 -28
  106. package/src/wit/wit-parser/core/types/utils.test-d.ts +23 -2
  107. package/src/wit/wit-parser/core/types/utils.ts +8 -41
  108. package/src/wit/wit-parser/core/utils.test.ts +14 -0
  109. package/src/wit/wit-parser/core/utils.ts +1 -0
  110. package/src/wit/wit-parser/parse-wit-parameter.test.ts +30 -3
  111. package/src/wit/wit-parser/parse-wit.test.ts +93 -102
@@ -9,27 +9,29 @@ test("parse records", () => {
9
9
  ]),
10
10
  ).toEqual({
11
11
  "contract-address": [
12
- { name: "name", type: "string" },
13
- { name: "height", type: "s64" },
14
- { name: "tx-index", type: "s64" },
12
+ { name: "name", type: "string", internalType: "string" },
13
+ { name: "height", type: "s64", internalType: "s64" },
14
+ { name: "tx-index", type: "s64", internalType: "s64" },
15
15
  ],
16
16
  "token-pair": [
17
17
  {
18
18
  type: "tuple",
19
19
  name: "a",
20
+ internalType: "contract-address",
20
21
  components: [
21
- { name: "name", type: "string" },
22
- { name: "height", type: "s64" },
23
- { name: "tx-index", type: "s64" },
22
+ { name: "name", type: "string", internalType: "string" },
23
+ { name: "height", type: "s64", internalType: "s64" },
24
+ { name: "tx-index", type: "s64", internalType: "s64" },
24
25
  ],
25
26
  },
26
27
  {
27
28
  type: "tuple",
28
29
  name: "b",
30
+ internalType: "contract-address",
29
31
  components: [
30
- { name: "name", type: "string" },
31
- { name: "height", type: "s64" },
32
- { name: "tx-index", type: "s64" },
32
+ { name: "name", type: "string", internalType: "string" },
33
+ { name: "height", type: "s64", internalType: "s64" },
34
+ { name: "tx-index", type: "s64", internalType: "s64" },
33
35
  ],
34
36
  },
35
37
  ],
@@ -38,7 +40,9 @@ test("parse records", () => {
38
40
 
39
41
  test("generic", () => {
40
42
  expect(parseRecords(["record generic { values: list<string> }"])).toEqual({
41
- generic: [{ name: "values", type: "list<string>" }],
43
+ generic: [
44
+ { name: "values", type: "list<string>", internalType: "list<string>" },
45
+ ],
42
46
  });
43
47
  });
44
48
 
@@ -50,10 +54,16 @@ test("generic", () => {
50
54
  ]),
51
55
  ).toEqual({
52
56
  "contract-address": [
53
- { type: "string", name: "name" },
54
- { type: "s64", name: "height" },
55
- { type: "s64", name: "tx-index" },
57
+ { name: "name", type: "string", internalType: "string" },
58
+ { name: "height", type: "s64", internalType: "s64" },
59
+ { name: "tx-index", type: "s64", internalType: "s64" },
60
+ ],
61
+ generic: [
62
+ {
63
+ name: "values",
64
+ type: "list<contract-address>",
65
+ internalType: "list<contract-address>",
66
+ },
56
67
  ],
57
- generic: [{ name: "values", type: "list<contract-address>" }],
58
68
  });
59
69
  });
@@ -1,5 +1,6 @@
1
1
  import { expectTypeOf, test } from "vitest";
2
2
 
3
+ // TODO: audit discrepancies in this whole file
3
4
  import type {
4
5
  ParseRecords,
5
6
  ParseRecord,
@@ -25,28 +26,65 @@ test("ParseRecords", () => {
25
26
  >
26
27
  >().toEqualTypeOf<{
27
28
  "contract-address": readonly [
28
- { readonly name: "name"; readonly type: "string" },
29
- { readonly name: "height"; readonly type: "s64" },
30
- { readonly name: "tx-index"; readonly type: "s64" },
29
+ {
30
+ readonly name: "name";
31
+ readonly type: "string";
32
+ readonly internalType: "string";
33
+ },
34
+ {
35
+ readonly name: "height";
36
+ readonly type: "s64";
37
+ readonly internalType: "s64";
38
+ },
39
+ {
40
+ readonly name: "tx-index";
41
+ readonly type: "s64";
42
+ readonly internalType: "s64";
43
+ },
31
44
  ];
32
45
 
33
46
  "token-pair": readonly [
34
47
  {
35
48
  readonly type: "tuple";
36
49
  readonly name: "a";
50
+ // TODO: should include internalType
37
51
  readonly components: readonly [
38
- { readonly name: "name"; readonly type: "string" },
39
- { readonly name: "height"; readonly type: "s64" },
40
- { readonly name: "tx-index"; readonly type: "s64" },
52
+ {
53
+ readonly name: "name";
54
+ readonly type: "string";
55
+ readonly internalType: "string";
56
+ },
57
+ {
58
+ readonly name: "height";
59
+ readonly type: "s64";
60
+ readonly internalType: "s64";
61
+ },
62
+ {
63
+ readonly name: "tx-index";
64
+ readonly type: "s64";
65
+ readonly internalType: "s64";
66
+ },
41
67
  ];
42
68
  },
43
69
  {
44
70
  readonly type: "tuple";
45
71
  readonly name: "b";
46
72
  readonly components: readonly [
47
- { readonly name: "name"; readonly type: "string" },
48
- { readonly name: "height"; readonly type: "s64" },
49
- { readonly name: "tx-index"; readonly type: "s64" },
73
+ {
74
+ readonly name: "name";
75
+ readonly type: "string";
76
+ readonly internalType: "string";
77
+ },
78
+ {
79
+ readonly name: "height";
80
+ readonly type: "s64";
81
+ readonly internalType: "s64";
82
+ },
83
+ {
84
+ readonly name: "tx-index";
85
+ readonly type: "s64";
86
+ readonly internalType: "s64";
87
+ },
50
88
  ];
51
89
  },
52
90
  ];
@@ -60,9 +98,21 @@ test("ParseRecords", () => {
60
98
  >
61
99
  >().toEqualTypeOf<{
62
100
  "contract-address": readonly [
63
- { readonly name: "name"; readonly type: "string" },
64
- { readonly name: "height"; readonly type: "s64" },
65
- { readonly name: "tx-index"; readonly type: "s64" },
101
+ {
102
+ readonly name: "name";
103
+ readonly type: "string";
104
+ readonly internalType: "string";
105
+ },
106
+ {
107
+ readonly name: "height";
108
+ readonly type: "s64";
109
+ readonly internalType: "s64";
110
+ },
111
+ {
112
+ readonly name: "tx-index";
113
+ readonly type: "s64";
114
+ readonly internalType: "s64";
115
+ },
66
116
  ];
67
117
 
68
118
  "token-pair": readonly [
@@ -95,9 +145,21 @@ test("ParseRecord", () => {
95
145
  >().toEqualTypeOf<{
96
146
  readonly name: "contract-address";
97
147
  readonly components: [
98
- { readonly name: "name"; readonly type: "string" },
99
- { readonly name: "height"; readonly type: "s64" },
100
- { readonly name: "tx-index"; readonly type: "s64" },
148
+ {
149
+ readonly name: "name";
150
+ readonly type: "string";
151
+ readonly internalType: "string";
152
+ },
153
+ {
154
+ readonly name: "height";
155
+ readonly type: "s64";
156
+ readonly internalType: "s64";
157
+ },
158
+ {
159
+ readonly name: "tx-index";
160
+ readonly type: "s64";
161
+ readonly internalType: "s64";
162
+ },
101
163
  ];
102
164
  }>();
103
165
 
@@ -106,8 +168,16 @@ test("ParseRecord", () => {
106
168
  >().toEqualTypeOf<{
107
169
  readonly name: "token-pair";
108
170
  readonly components: [
109
- { readonly name: "a"; readonly type: "contract-address" },
110
- { readonly name: "b"; readonly type: "contract-address" },
171
+ {
172
+ readonly name: "a";
173
+ readonly type: "contract-address";
174
+ readonly internalType: "contract-address";
175
+ },
176
+ {
177
+ readonly name: "b";
178
+ readonly type: "contract-address";
179
+ readonly internalType: "contract-address";
180
+ },
111
181
  ];
112
182
  }>();
113
183
 
@@ -122,19 +192,40 @@ test("ParseRecord", () => {
122
192
  {
123
193
  readonly type: "tuple";
124
194
  readonly name: "a";
195
+ readonly internalType: "contract-address";
125
196
  readonly components: readonly [
126
- { readonly name: "name"; readonly type: "string" },
127
- { readonly name: "height"; readonly type: "s64" },
128
- { readonly name: "tx-index"; readonly type: "s64" },
197
+ {
198
+ // TODO: why aren't we getting internalType here
199
+ readonly name: "name";
200
+ readonly type: "string";
201
+ },
202
+ {
203
+ readonly name: "height";
204
+ readonly type: "s64";
205
+ },
206
+ {
207
+ readonly name: "tx-index";
208
+ readonly type: "s64";
209
+ },
129
210
  ];
130
211
  },
131
212
  {
132
213
  readonly type: "tuple";
133
214
  readonly name: "b";
215
+ readonly internalType: "contract-address";
134
216
  readonly components: readonly [
135
- { readonly name: "name"; readonly type: "string" },
136
- { readonly name: "height"; readonly type: "s64" },
137
- { readonly name: "tx-index"; readonly type: "s64" },
217
+ {
218
+ readonly name: "name";
219
+ readonly type: "string";
220
+ },
221
+ {
222
+ readonly name: "height";
223
+ readonly type: "s64";
224
+ },
225
+ {
226
+ readonly name: "tx-index";
227
+ readonly type: "s64";
228
+ },
138
229
  ];
139
230
  },
140
231
  ];
@@ -146,9 +237,21 @@ test("ParseRecordProperties", () => {
146
237
  ParseRecordProperties<"name: string, height: s64, tx-index: s64">
147
238
  >().toEqualTypeOf<
148
239
  [
149
- { readonly name: "name"; readonly type: "string" },
150
- { readonly name: "height"; readonly type: "s64" },
151
- { readonly name: "tx-index"; readonly type: "s64" },
240
+ {
241
+ readonly name: "name";
242
+ readonly type: "string";
243
+ readonly internalType: "string";
244
+ },
245
+ {
246
+ readonly name: "height";
247
+ readonly type: "s64";
248
+ readonly internalType: "s64";
249
+ },
250
+ {
251
+ readonly name: "tx-index";
252
+ readonly type: "s64";
253
+ readonly internalType: "s64";
254
+ },
152
255
  ]
153
256
  >();
154
257
 
@@ -156,8 +259,16 @@ test("ParseRecordProperties", () => {
156
259
  ParseRecordProperties<"a: contract-address, b: contract-address">
157
260
  >().toEqualTypeOf<
158
261
  [
159
- { readonly name: "a"; readonly type: "contract-address" },
160
- { readonly name: "b"; readonly type: "contract-address" },
262
+ {
263
+ readonly name: "a";
264
+ readonly type: "contract-address";
265
+ readonly internalType: "contract-address";
266
+ },
267
+ {
268
+ readonly name: "b";
269
+ readonly type: "contract-address";
270
+ readonly internalType: "contract-address";
271
+ },
161
272
  ]
162
273
  >();
163
274
 
@@ -168,6 +279,7 @@ test("ParseRecordProperties", () => {
168
279
  {
169
280
  readonly type: "tuple";
170
281
  readonly name: "a";
282
+ readonly internalType: "contract-address";
171
283
  readonly components: readonly [
172
284
  { readonly name: "name"; readonly type: "string" },
173
285
  { readonly name: "height"; readonly type: "s64" },
@@ -177,6 +289,7 @@ test("ParseRecordProperties", () => {
177
289
  {
178
290
  readonly type: "tuple";
179
291
  readonly name: "b";
292
+ readonly internalType: "contract-address";
180
293
  readonly components: readonly [
181
294
  { readonly name: "name"; readonly type: "string" },
182
295
  { readonly name: "height"; readonly type: "s64" },
@@ -46,30 +46,36 @@ test("ParseWitParameter", () => {
46
46
  assertType<ParseWitParameter<"ctx: borrow<proc-context>">>({
47
47
  name: "ctx",
48
48
  type: "borrow<proc-context>",
49
+ internalType: "borrow<proc-context>",
49
50
  });
50
51
 
51
52
  assertType<ParseWitParameter<"arith-address: contract-address">>({
52
53
  name: "arith-address",
53
54
  type: "contract-address",
55
+ internalType: "contract-address",
54
56
  });
55
57
 
56
58
  assertType<ParseWitParameter<"n: u64">>({
57
59
  name: "n",
58
60
  type: "u64",
61
+ internalType: "u64",
59
62
  });
60
63
 
61
64
  assertType<ParseWitParameter<"u64">>({
62
65
  type: "u64",
66
+ internalType: "u64",
63
67
  });
64
68
 
65
69
  assertType<ParseWitParameter<"x: string">>({
66
70
  name: "x",
67
71
  type: "string",
72
+ internalType: "string",
68
73
  });
69
74
 
70
75
  assertType<ParseWitParameter<"y: string">>({
71
76
  name: "y",
72
77
  type: "string",
78
+ internalType: "string",
73
79
  });
74
80
 
75
81
  assertType<ParseWitParameter<"option-string: option<string>">>({
@@ -91,15 +97,18 @@ test("ParseWitParameter", () => {
91
97
 
92
98
  assertType<ParseWitParameter<"contract-address">>({
93
99
  type: "contract-address",
100
+ internalType: "contract-address",
94
101
  });
95
102
  assertType<ParseWitParameter<"ctx: borrow<view-context>">>({
96
103
  name: "ctx",
97
104
  type: "borrow<view-context>",
105
+ internalType: "borrow<view-context>",
98
106
  });
99
107
 
100
108
  assertType<ParseWitParameter<"arith-address: contract-address">>({
101
109
  name: "arith-address",
102
110
  type: "contract-address",
111
+ internalType: "contract-address",
103
112
  });
104
113
  });
105
114
 
@@ -149,12 +158,17 @@ test("Parse Signature", () => {
149
158
  name: "fib",
150
159
  context: "proc",
151
160
  inputs: [
152
- { name: "arith-address", type: "contract-address" },
161
+ {
162
+ name: "arith-address",
163
+ type: "contract-address",
164
+ internalType: "contract-address",
165
+ },
153
166
  { name: "n", type: "list<u64>" },
154
167
  ],
155
168
  outputs: [
156
169
  {
157
170
  type: "u64",
171
+ internalType: "u64",
158
172
  },
159
173
  ],
160
174
  });
@@ -165,12 +179,17 @@ test("Parse Signature", () => {
165
179
  name: "fib",
166
180
  context: "proc",
167
181
  inputs: [
168
- { name: "arith-address", type: "contract-address" },
182
+ {
183
+ name: "arith-address",
184
+ type: "contract-address",
185
+ internalType: "contract-address",
186
+ },
169
187
  { name: "n", type: "list<u64>" },
170
188
  ],
171
189
  outputs: [
172
190
  {
173
191
  type: "contract-address",
192
+ internalType: "contract-address",
174
193
  },
175
194
  ],
176
195
  });
@@ -184,12 +203,14 @@ test("Parse Signature", () => {
184
203
  {
185
204
  name: "arith-address",
186
205
  type: "contract-address",
206
+ internalType: "contract-address",
187
207
  },
188
208
  { name: "n", type: "list<u64>" },
189
209
  ],
190
210
  outputs: [
191
211
  {
192
212
  type: "contract-address",
213
+ internalType: "contract-address",
193
214
  },
194
215
  ],
195
216
  });
@@ -26,9 +26,13 @@ type GetComponents<T> = T extends { components: infer C }
26
26
  type AsTupleFromRecord<T extends string, Opts extends ParseOptions> =
27
27
  HasRecords<Opts> extends true
28
28
  ? T extends keyof RecordsOf<Opts>
29
- ? Readonlyify<{ type: "tuple"; components: RecordsOf<Opts>[T] }>
30
- : Readonlyify<{ type: T }>
31
- : Readonlyify<{ type: T }>;
29
+ ? Readonlyify<{
30
+ type: "tuple";
31
+ components: RecordsOf<Opts>[T];
32
+ internalType: T;
33
+ }>
34
+ : Readonlyify<{ type: T; internalType: T }>
35
+ : Readonlyify<{ type: T; internalType: T }>;
32
36
 
33
37
  type SplitResultInner<S extends string> = S extends `${infer L}, ${infer R}`
34
38
  ? [Trim<L>, Trim<R>]
@@ -40,44 +44,6 @@ type MaybeResultComponents<
40
44
  _Err extends { type: string },
41
45
  > = Ok extends { components: infer _C } ? GetComponents<Ok> : {};
42
46
 
43
- // type MaybeResultComponents<
44
- // L extends { type: string },
45
- // R extends { type: string },
46
- // > = L extends { components: infer _LC }
47
- // ? R extends { components: infer _RC }
48
- // ? {
49
- // readonly components: [
50
- // {
51
- // readonly name: "left";
52
- // readonly type: L["type"];
53
- // } & GetComponents<L>,
54
- // {
55
- // readonly name: "right";
56
- // readonly type: R["type"];
57
- // } & GetComponents<R>,
58
- // ];
59
- // }
60
- // : {
61
- // readonly components: [
62
- // {
63
- // readonly name: "left";
64
- // readonly type: L["type"];
65
- // } & GetComponents<L>,
66
- // { readonly name: "right"; readonly type: R["type"] },
67
- // ];
68
- // }
69
- // : R extends { components: infer _RC }
70
- // ? {
71
- // readonly components: [
72
- // { readonly name: "left"; readonly type: L["type"] },
73
- // {
74
- // readonly name: "right";
75
- // readonly type: R["type"];
76
- // } & GetComponents<R>,
77
- // ];
78
- // }
79
- // : {}; // neither side has components → omit components entirely
80
-
81
47
  type MapGenericType<T extends string, Opts extends ParseOptions> =
82
48
  // list<...>
83
49
  T extends `list<${infer U}>`
@@ -103,6 +69,7 @@ type MapGenericType<T extends string, Opts extends ParseOptions> =
103
69
  ? Readonlyify<
104
70
  {
105
71
  type: `result<${LMapped["type"]}, ${RMapped["type"]}>`;
72
+ internalType: T;
106
73
  } & MaybeResultComponents<LMapped, RMapped>
107
74
  >
108
75
  : never
@@ -28,16 +28,19 @@ describe("parseFunctionSignature", () => {
28
28
  {
29
29
  name: "arith-address",
30
30
  type: "contract-address",
31
+ internalType: "contract-address",
31
32
  },
32
33
  {
33
34
  name: "n",
34
35
  type: "u64",
36
+ internalType: "u64",
35
37
  },
36
38
  ],
37
39
  name: "fib",
38
40
  outputs: [
39
41
  {
40
42
  type: "u64",
43
+ internalType: "u64",
41
44
  },
42
45
  ],
43
46
  type: "function",
@@ -53,6 +56,7 @@ describe("parseFunctionSignature", () => {
53
56
  outputs: [
54
57
  {
55
58
  type: "list<u64>",
59
+ internalType: "list<u64>",
56
60
  },
57
61
  ],
58
62
  type: "function",
@@ -70,6 +74,7 @@ describe("parseWitParameter", () => {
70
74
  expected: {
71
75
  name: "ctx",
72
76
  type: "borrow<proc-context>",
77
+ internalType: "borrow<proc-context>",
73
78
  },
74
79
  },
75
80
  {
@@ -77,6 +82,7 @@ describe("parseWitParameter", () => {
77
82
  expected: {
78
83
  name: "arith-address",
79
84
  type: "tuple",
85
+ internalType: "contract-address",
80
86
  components: [
81
87
  { name: "name", type: "string" },
82
88
  { name: "height", type: "s64" },
@@ -89,6 +95,7 @@ describe("parseWitParameter", () => {
89
95
  expected: {
90
96
  name: "n",
91
97
  type: "u64",
98
+ internalType: "u64",
92
99
  },
93
100
  },
94
101
  {
@@ -96,6 +103,7 @@ describe("parseWitParameter", () => {
96
103
  expected: {
97
104
  name: "y",
98
105
  type: "string",
106
+ internalType: "string",
99
107
  },
100
108
  },
101
109
  {
@@ -103,6 +111,7 @@ describe("parseWitParameter", () => {
103
111
  expected: {
104
112
  name: "list-of-strings",
105
113
  type: "list<string>",
114
+ internalType: "list<string>",
106
115
  },
107
116
  },
108
117
  {
@@ -110,6 +119,7 @@ describe("parseWitParameter", () => {
110
119
  expected: {
111
120
  name: "arith-addresses",
112
121
  type: "list<tuple>",
122
+ internalType: "list<contract-address>",
113
123
  components: [
114
124
  { name: "name", type: "string" },
115
125
  { name: "height", type: "s64" },
@@ -121,6 +131,7 @@ describe("parseWitParameter", () => {
121
131
  parameter: "list<contract-address>",
122
132
  expected: {
123
133
  type: "list<tuple>",
134
+ internalType: "list<contract-address>",
124
135
  components: [
125
136
  { name: "name", type: "string" },
126
137
  { name: "height", type: "s64" },
@@ -132,6 +143,7 @@ describe("parseWitParameter", () => {
132
143
  parameter: "option<contract-address>",
133
144
  expected: {
134
145
  type: "option<tuple>",
146
+ internalType: "option<contract-address>",
135
147
  components: [
136
148
  { name: "name", type: "string" },
137
149
  { name: "height", type: "s64" },
@@ -143,6 +155,7 @@ describe("parseWitParameter", () => {
143
155
  parameter: "result<contract-address, error>",
144
156
  expected: {
145
157
  type: "result<tuple, error>",
158
+ internalType: "result<contract-address, error>",
146
159
  components: [
147
160
  { name: "name", type: "string" },
148
161
  { name: "height", type: "s64" },
@@ -154,6 +167,7 @@ describe("parseWitParameter", () => {
154
167
  parameter: "result<list<contract-address>, error>",
155
168
  expected: {
156
169
  type: "result<list<tuple>, error>",
170
+ internalType: "result<list<contract-address>, error>",
157
171
  components: [
158
172
  { name: "name", type: "string" },
159
173
  { name: "height", type: "s64" },
@@ -152,6 +152,7 @@ export function parseWitParameter(param: string, options?: ParseOptions) {
152
152
 
153
153
  const witParameter: WitParameter = {
154
154
  type: `${type}${match.array ?? ""}`,
155
+ internalType: match.type,
155
156
  ...(name as { name: string }),
156
157
  ...components,
157
158
  };