@kontor/kontor-sdk 1.0.0-alpha.27 → 1.0.0-alpha.28
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/dist/cjs/sdk/actions/kontor/public/build-compose-query.js +9 -12
- package/dist/cjs/sdk/actions/kontor/public/build-compose-query.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/build-instruction-query.js +13 -33
- package/dist/cjs/sdk/actions/kontor/public/build-instruction-query.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/call-compose.js +6 -4
- package/dist/cjs/sdk/actions/kontor/public/call-compose.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/call-view.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/inspect.js +1 -2
- package/dist/cjs/sdk/actions/kontor/public/inspect.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/proc-contract.js +5 -5
- package/dist/cjs/sdk/actions/kontor/public/proc-contract.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/view-contract.js +2 -1
- package/dist/cjs/sdk/actions/kontor/public/view-contract.js.map +1 -1
- package/dist/cjs/sdk/chains/definitions/signet.js +0 -1
- package/dist/cjs/sdk/chains/definitions/signet.js.map +1 -1
- package/dist/cjs/sdk/clients/decorators/kontor/public.js.map +1 -1
- package/dist/cjs/sdk/errors/chain.js +44 -0
- package/dist/cjs/sdk/errors/chain.js.map +1 -0
- package/dist/cjs/sdk/utils/chain/assert-current-chain.js +11 -0
- package/dist/cjs/sdk/utils/chain/assert-current-chain.js.map +1 -0
- package/dist/cjs/sdk/utils/kontor/build-compose-query.js +19 -0
- package/dist/cjs/sdk/utils/kontor/build-compose-query.js.map +1 -0
- package/dist/cjs/sdk/utils/kontor/build-instruction-query.js +36 -0
- package/dist/cjs/sdk/utils/kontor/build-instruction-query.js.map +1 -0
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/sdk/actions/kontor/public/build-compose-query.js +9 -13
- package/dist/esm/sdk/actions/kontor/public/build-compose-query.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/build-instruction-query.js +13 -36
- package/dist/esm/sdk/actions/kontor/public/build-instruction-query.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/call-compose.js +6 -4
- package/dist/esm/sdk/actions/kontor/public/call-compose.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/call-view.js +1 -0
- package/dist/esm/sdk/actions/kontor/public/call-view.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/inspect.js +9 -4
- package/dist/esm/sdk/actions/kontor/public/inspect.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/proc-contract.js +5 -6
- package/dist/esm/sdk/actions/kontor/public/proc-contract.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/view-contract.js +3 -5
- package/dist/esm/sdk/actions/kontor/public/view-contract.js.map +1 -1
- package/dist/esm/sdk/chains/definitions/signet.js +0 -1
- package/dist/esm/sdk/chains/definitions/signet.js.map +1 -1
- package/dist/esm/sdk/clients/decorators/kontor/public.js.map +1 -1
- package/dist/esm/sdk/errors/chain.js +37 -0
- package/dist/esm/sdk/errors/chain.js.map +1 -0
- package/dist/esm/sdk/utils/chain/assert-current-chain.js +8 -0
- package/dist/esm/sdk/utils/chain/assert-current-chain.js.map +1 -0
- package/dist/esm/sdk/utils/kontor/build-compose-query.js +16 -0
- package/dist/esm/sdk/utils/kontor/build-compose-query.js.map +1 -0
- package/dist/esm/sdk/utils/kontor/build-instruction-query.js +36 -0
- package/dist/esm/sdk/utils/kontor/build-instruction-query.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts +5 -3
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/build-instruction-query.d.ts +6 -6
- package/dist/types/sdk/actions/kontor/public/build-instruction-query.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/call-compose.d.ts +1 -1
- package/dist/types/sdk/actions/kontor/public/call-compose.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/call-view.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/call-view.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/inspect.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/inspect.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/proc-contract.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/proc-contract.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/view-contract.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/view-contract.d.ts.map +1 -1
- package/dist/types/sdk/chains/definitions/signet.d.ts +0 -1
- package/dist/types/sdk/chains/definitions/signet.d.ts.map +1 -1
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts +6 -6
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts.map +1 -1
- package/dist/types/sdk/errors/chain.d.ts +32 -0
- package/dist/types/sdk/errors/chain.d.ts.map +1 -0
- package/dist/types/sdk/types/chain.d.ts +0 -2
- package/dist/types/sdk/types/chain.d.ts.map +1 -1
- package/dist/types/sdk/utils/chain/assert-current-chain.d.ts +10 -0
- package/dist/types/sdk/utils/chain/assert-current-chain.d.ts.map +1 -0
- package/dist/types/sdk/utils/kontor/build-compose-query.d.ts +13 -0
- package/dist/types/sdk/utils/kontor/build-compose-query.d.ts.map +1 -0
- package/dist/types/sdk/utils/kontor/build-instruction-query.d.ts +22 -0
- package/dist/types/sdk/utils/kontor/build-instruction-query.d.ts.map +1 -0
- package/dist/types/wit/type-utils.d.ts.map +1 -1
- package/dist/types/wit/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sdk/actions/kontor/public/build-compose-query.ts +23 -22
- package/src/sdk/actions/kontor/public/build-instruction-query.ts +27 -53
- package/src/sdk/actions/kontor/public/call-compose.ts +8 -4
- package/src/sdk/actions/kontor/public/call-view.ts +5 -4
- package/src/sdk/actions/kontor/public/inspect.ts +20 -9
- package/src/sdk/actions/kontor/public/proc-contract.test.ts +1 -2
- package/src/sdk/actions/kontor/public/proc-contract.ts +21 -55
- package/src/sdk/actions/kontor/public/{view-contract.test-d.ts → view-contract.test.ts} +2 -2
- package/src/sdk/actions/kontor/public/view-contract.ts +10 -9
- package/src/sdk/chains/definitions/signet.ts +0 -1
- package/src/sdk/clients/base/create-rpc-client.test.ts +0 -1
- package/src/sdk/clients/create-public-client.test.ts +0 -1
- package/src/sdk/clients/decorators/kontor/public.ts +21 -12
- package/src/sdk/clients/kontor/create-public-client.test.ts +0 -7
- package/src/sdk/errors/chain.ts +64 -0
- package/src/sdk/test/e2e.test.ts +21 -0
- package/src/sdk/types/chain.ts +0 -2
- package/src/sdk/utils/chain/assert-current-chain.ts +28 -0
- package/src/sdk/utils/kontor/build-compose-query.ts +33 -0
- package/src/sdk/utils/kontor/build-instruction-query.ts +75 -0
- package/src/wit/type-utils.ts +0 -2
- package/src/wit/utils.ts +3 -6
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChainMismatchError,
|
|
3
|
+
type ChainMismatchErrorType,
|
|
4
|
+
ChainNotFoundError,
|
|
5
|
+
type ChainNotFoundErrorType,
|
|
6
|
+
} from "../../errors/chain.js";
|
|
7
|
+
|
|
8
|
+
import type { ErrorType } from "../../errors/utils.js";
|
|
9
|
+
import type { Chain } from "../../types/chain.js";
|
|
10
|
+
|
|
11
|
+
export type AssertCurrentChainParameters = {
|
|
12
|
+
chain?: Chain | undefined;
|
|
13
|
+
currentChain: Chain;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type AssertCurrentChainErrorType =
|
|
17
|
+
| ChainNotFoundErrorType
|
|
18
|
+
| ChainMismatchErrorType
|
|
19
|
+
| ErrorType;
|
|
20
|
+
|
|
21
|
+
export function assertCurrentChain({
|
|
22
|
+
chain,
|
|
23
|
+
currentChain,
|
|
24
|
+
}: AssertCurrentChainParameters): void {
|
|
25
|
+
if (!chain) throw new ChainNotFoundError();
|
|
26
|
+
if (currentChain.name !== chain.name)
|
|
27
|
+
throw new ChainMismatchError({ chain, currentChain });
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Address, UtxoId, XOnlyPubKey } from "../../types/misc.js";
|
|
2
|
+
import type { ComposeQuery } from "@kontor/kontor-ts";
|
|
3
|
+
import type { Inst } from "../../../sdk/types/kontor.js";
|
|
4
|
+
import { buildInstructionQuery } from "./build-instruction-query.js";
|
|
5
|
+
|
|
6
|
+
export type BuildComposeQueryParameters = {
|
|
7
|
+
instruction: Inst;
|
|
8
|
+
address: Address;
|
|
9
|
+
xOnlyPubKey: XOnlyPubKey; // TODO: maybe this should be wrapped in a single object
|
|
10
|
+
utxos: UtxoId[];
|
|
11
|
+
satsPerVByte: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type BuildComposeQueryReturnType = ComposeQuery;
|
|
15
|
+
|
|
16
|
+
export function buildComposeQuery(
|
|
17
|
+
params: BuildComposeQueryParameters,
|
|
18
|
+
): BuildComposeQueryReturnType {
|
|
19
|
+
const { instruction: inst, utxos, address, xOnlyPubKey } = params;
|
|
20
|
+
|
|
21
|
+
const instruction = buildInstructionQuery({
|
|
22
|
+
instruction: inst,
|
|
23
|
+
utxos,
|
|
24
|
+
xOnlyPubKey,
|
|
25
|
+
address,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
instructions: [instruction],
|
|
30
|
+
sat_per_vbyte: params.satsPerVByte,
|
|
31
|
+
envelope: null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Inst, InstructionQuery } from "../../types/kontor.js";
|
|
2
|
+
import type { Address, UtxoId, XOnlyPubKey } from "../../types/misc.js";
|
|
3
|
+
|
|
4
|
+
export type BuildInstructionQueryReturnType = InstructionQuery;
|
|
5
|
+
|
|
6
|
+
export type BuildInstructionQueryParameters = {
|
|
7
|
+
address: Address;
|
|
8
|
+
xOnlyPubKey: XOnlyPubKey; // TODO: maybe this should be wrapped in a single object
|
|
9
|
+
utxos: UtxoId[];
|
|
10
|
+
/**
|
|
11
|
+
* The concrete instruction to send (Publish | Call | Issuance).
|
|
12
|
+
* Example:
|
|
13
|
+
* { Call: { gas_limit: 100000, contract: "addr", expr: "balance(...)" } }
|
|
14
|
+
* { Publish: { gas_limit: 100000, name: "token", bytes: [0,1,2,...] } }
|
|
15
|
+
* "Issuance"
|
|
16
|
+
*/
|
|
17
|
+
instruction: Inst;
|
|
18
|
+
/**
|
|
19
|
+
* Optional chained instruction if you want to send two instructions atomically.
|
|
20
|
+
*/
|
|
21
|
+
chainedInstruction?: Inst | null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// ------------------ helpers ------------------
|
|
25
|
+
|
|
26
|
+
function normalizeXOnly(pub: string): string {
|
|
27
|
+
if (!/^[0-9a-fA-F]{64}$/.test(pub)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"x_only_public_key must be 32-byte (64 hex chars) x-only pubkey",
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return pub.toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizeUtxoId(u: UtxoId): string {
|
|
36
|
+
if (typeof u === "string") return u;
|
|
37
|
+
if (!u?.txid || typeof u.vout !== "number") {
|
|
38
|
+
throw new Error("funding UTXO must be 'txid:vout' or { txid, vout }");
|
|
39
|
+
}
|
|
40
|
+
return `${u.txid}:${u.vout}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function normalizeUtxoIds(u: UtxoId | UtxoId[]): string[] {
|
|
44
|
+
return Array.isArray(u) ? u.map(normalizeUtxoId) : [normalizeUtxoId(u)];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ------------------ main builder ------------------
|
|
48
|
+
|
|
49
|
+
export function buildInstructionQuery(
|
|
50
|
+
params: BuildInstructionQueryParameters,
|
|
51
|
+
): BuildInstructionQueryReturnType {
|
|
52
|
+
const {
|
|
53
|
+
utxos,
|
|
54
|
+
instruction,
|
|
55
|
+
chainedInstruction = null,
|
|
56
|
+
address,
|
|
57
|
+
xOnlyPubKey,
|
|
58
|
+
} = params;
|
|
59
|
+
|
|
60
|
+
if (utxos.length === 0) {
|
|
61
|
+
// TODO: add custom error
|
|
62
|
+
throw new Error("at least one funding UTXO is required");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const xOnly = normalizeXOnly(xOnlyPubKey);
|
|
66
|
+
const fundingIds = normalizeUtxoIds(utxos);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
address,
|
|
70
|
+
x_only_public_key: xOnly,
|
|
71
|
+
funding_utxo_ids: fundingIds.join(","),
|
|
72
|
+
instruction,
|
|
73
|
+
chained_instruction: chainedInstruction ?? null,
|
|
74
|
+
};
|
|
75
|
+
}
|
package/src/wit/type-utils.ts
CHANGED
|
@@ -40,8 +40,6 @@ export type OneOf<
|
|
|
40
40
|
: never;
|
|
41
41
|
type KeyofUnion<type> = type extends type ? keyof type : never;
|
|
42
42
|
|
|
43
|
-
// from viem: https://github.com/wevm/viem/blob/320895cf0e6c654b419d8d61a59c4e7b46674368/src/types/utils.ts#L58
|
|
44
|
-
|
|
45
43
|
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
46
44
|
|
|
47
45
|
export type IsNarrowable<T, U> =
|
package/src/wit/utils.ts
CHANGED
|
@@ -264,8 +264,7 @@ type _TypedDataParametersToWitParameters<
|
|
|
264
264
|
name: string;
|
|
265
265
|
type: unknown;
|
|
266
266
|
}
|
|
267
|
-
?
|
|
268
|
-
typedDataParameter["type"] extends keyof typedData & string
|
|
267
|
+
? typedDataParameter["type"] extends keyof typedData & string
|
|
269
268
|
? {
|
|
270
269
|
name: typedDataParameter["name"];
|
|
271
270
|
type: "tuple";
|
|
@@ -277,8 +276,7 @@ type _TypedDataParametersToWitParameters<
|
|
|
277
276
|
keyReferences & { [_ in typedDataParameter["type"]]: true }
|
|
278
277
|
>;
|
|
279
278
|
}
|
|
280
|
-
:
|
|
281
|
-
typedDataParameter["type"] extends `${infer type extends
|
|
279
|
+
: typedDataParameter["type"] extends `${infer type extends
|
|
282
280
|
keyof typedData & string}[${infer tail}]`
|
|
283
281
|
? {
|
|
284
282
|
name: typedDataParameter["name"];
|
|
@@ -291,7 +289,6 @@ type _TypedDataParametersToWitParameters<
|
|
|
291
289
|
keyReferences & { [_ in type]: true }
|
|
292
290
|
>;
|
|
293
291
|
}
|
|
294
|
-
:
|
|
295
|
-
typedDataParameter
|
|
292
|
+
: typedDataParameter
|
|
296
293
|
: never;
|
|
297
294
|
};
|