@kontor/kontor-sdk 1.0.0-alpha.26 → 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 +9 -9
- 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 +9 -12
- 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/actions/kontor/wallet/sign-commit.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/cjs/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/cjs/wit/wit-parser/parse-wit.js.map +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 +10 -10
- 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 +10 -15
- 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/actions/kontor/wallet/sign-commit.js +1 -0
- package/dist/esm/sdk/actions/kontor/wallet/sign-commit.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/esm/wit/wit-parser/core/utils.js +0 -5
- package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/esm/wit/wit-parser/parse-wit.js.map +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 +6 -5
- 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 +6 -6
- 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/actions/kontor/wallet/sign-commit.d.ts +4 -2
- package/dist/types/sdk/actions/kontor/wallet/sign-commit.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/wallet/sign-reveal.d.ts +1 -1
- package/dist/types/sdk/actions/kontor/wallet/sign-reveal.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 +8 -8
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts.map +1 -1
- package/dist/types/sdk/clients/decorators/kontor/wallet.d.ts +1 -1
- package/dist/types/sdk/clients/decorators/kontor/wallet.d.ts.map +1 -1
- package/dist/types/sdk/clients/kontor/create-public-client.d.ts +1 -1
- package/dist/types/sdk/clients/kontor/create-public-client.d.ts.map +1 -1
- package/dist/types/sdk/clients/kontor/create-wallet-client.d.ts +1 -1
- package/dist/types/sdk/clients/kontor/create-wallet-client.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 +1 -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/dist/types/wit/wit-parser/core/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/parse-wit.d.ts +0 -15
- package/dist/types/wit/wit-parser/parse-wit.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 +32 -21
- 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 +2 -0
- package/src/sdk/actions/kontor/public/proc-contract.ts +34 -23
- 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/actions/kontor/wallet/sign-commit.ts +18 -7
- package/src/sdk/actions/kontor/wallet/sign-reveal.ts +1 -1
- 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 +25 -16
- package/src/sdk/clients/decorators/kontor/wallet.ts +2 -2
- package/src/sdk/clients/kontor/create-public-client.test.ts +0 -7
- package/src/sdk/clients/kontor/create-public-client.ts +3 -3
- package/src/sdk/clients/kontor/create-wallet-client.ts +3 -3
- package/src/sdk/errors/chain.ts +64 -0
- package/src/sdk/test/e2e.test.ts +28 -11
- package/src/sdk/types/chain.ts +5 -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
- package/src/wit/wit-parser/core/utils.ts +1 -5
- package/src/wit/wit-parser/parse-wit.ts +0 -15
|
@@ -4,16 +4,16 @@ import { parseWit } from "../../../../wit/wit-parser/parse-wit.js";
|
|
|
4
4
|
import { createPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
5
5
|
import { http } from "../../../clients/transports/http.js";
|
|
6
6
|
import { nativeToken } from "../../../contracts/wits.js";
|
|
7
|
+
import { signet } from "../../../chains/definitions/signet.js";
|
|
7
8
|
|
|
8
9
|
const wit = parseWit(nativeToken.raw);
|
|
9
10
|
|
|
10
11
|
test("e2e", async () => {
|
|
11
12
|
const client = createPublicClient({
|
|
12
13
|
transport: http("https://signet-staging.kontor.network:35000/api"),
|
|
14
|
+
chain: signet,
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
// view contract action defined on client
|
|
16
|
-
// response is correctly typed
|
|
17
17
|
const res = await client.viewContract({
|
|
18
18
|
wit: wit,
|
|
19
19
|
functionName: "balances", // functin name is only valid if it's got a view-context
|
|
@@ -2,7 +2,7 @@ import type { Wit } from "../../../../wit/wit.js";
|
|
|
2
2
|
import type { Prettify } from "../../../../wit/type-utils.js";
|
|
3
3
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
4
4
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
5
|
-
import type { Chain } from "../../../types/chain.js";
|
|
5
|
+
import type { Chain, GetChainParameter } from "../../../types/chain.js";
|
|
6
6
|
import type {
|
|
7
7
|
ContractFunctionArgs,
|
|
8
8
|
ContractFunctionName,
|
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
} from "../../../types/contract.js";
|
|
12
12
|
import { getKontorAction } from "../../../utils/get-action.js";
|
|
13
13
|
import { decodeFunctionResult } from "../../../utils/wit/decode-function-result.js";
|
|
14
|
-
// import { getAction } from "../../utils/getAction.js";
|
|
15
14
|
import {
|
|
16
15
|
encodeFunctionData,
|
|
17
16
|
type EncodeFunctionDataParameters,
|
|
@@ -29,7 +28,10 @@ export type ViewContractParameters<
|
|
|
29
28
|
"view",
|
|
30
29
|
functionName
|
|
31
30
|
> = ContractFunctionArgs<wit, "view", functionName>,
|
|
32
|
-
|
|
31
|
+
chain extends Chain | undefined = Chain,
|
|
32
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
33
|
+
> = ContractFunctionParameters<wit, "view", functionName, args> &
|
|
34
|
+
GetChainParameter<chain, chainOverride>;
|
|
33
35
|
|
|
34
36
|
export type ViewContractReturnType<
|
|
35
37
|
wit extends Wit | readonly unknown[] = Wit,
|
|
@@ -46,26 +48,24 @@ export type ViewContractReturnType<
|
|
|
46
48
|
> = Prettify<ContractFunctionReturnType<wit, "view", functionName, args>>;
|
|
47
49
|
|
|
48
50
|
export async function viewContract<
|
|
49
|
-
// chain exhttps://viem.sh/tends Chain | undefined,
|
|
50
51
|
chain extends Chain | undefined,
|
|
51
52
|
const wit extends Wit | readonly unknown[],
|
|
52
53
|
functionName extends ContractFunctionName<wit, "view">,
|
|
53
54
|
const args extends ContractFunctionArgs<wit, "view", functionName>,
|
|
54
55
|
>(
|
|
55
56
|
client: KontorPublicClient<HttpTransport, chain>,
|
|
56
|
-
parameters: ViewContractParameters<wit, functionName, args>,
|
|
57
|
+
parameters: ViewContractParameters<wit, functionName, args, chain>,
|
|
57
58
|
): Promise<ViewContractReturnType<wit, functionName, args>> {
|
|
58
59
|
const {
|
|
59
60
|
wit: wit,
|
|
60
61
|
contractAddress,
|
|
61
62
|
args,
|
|
62
63
|
functionName,
|
|
63
|
-
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
...rest
|
|
64
|
+
chain: chain_ = client.chain,
|
|
66
65
|
} = parameters as ViewContractParameters;
|
|
67
66
|
|
|
68
|
-
//
|
|
67
|
+
//TODO: assert chain ( or delegate to downstream call )
|
|
68
|
+
|
|
69
69
|
const wave = encodeFunctionData({
|
|
70
70
|
wit: wit,
|
|
71
71
|
args,
|
|
@@ -80,6 +80,7 @@ export async function viewContract<
|
|
|
80
80
|
)({
|
|
81
81
|
contractAddress: contractAddress,
|
|
82
82
|
wave: wave,
|
|
83
|
+
chain: chain_,
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
console.log(response.result.type);
|
|
@@ -8,23 +8,33 @@ 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
10
|
import { parseAccount } from "../../../accounts/utils/parse-account.js";
|
|
11
|
+
import type { XOnlyPubKey, Address } from "../../../../sdk/types/misc.js";
|
|
12
|
+
|
|
13
|
+
export type SignCommitRequest = {
|
|
14
|
+
psbt: string;
|
|
15
|
+
};
|
|
11
16
|
|
|
12
17
|
export type SignCommitParameters<
|
|
13
|
-
chain extends Chain | undefined,
|
|
14
|
-
account extends Account | undefined,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
chain extends Chain | undefined = Chain,
|
|
19
|
+
account extends Account | undefined = Account | undefined,
|
|
20
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
21
|
+
accountOverride extends Account | [Address, XOnlyPubKey] | undefined =
|
|
22
|
+
| Account
|
|
23
|
+
| [Address, XOnlyPubKey]
|
|
24
|
+
| undefined,
|
|
25
|
+
> = SignCommitRequest &
|
|
26
|
+
GetAccountParameter<account, accountOverride, false, true> &
|
|
27
|
+
GetChainParameter<chain, chainOverride>;
|
|
18
28
|
|
|
19
29
|
export type SignCommitReturnType = Transaction;
|
|
20
30
|
|
|
21
31
|
export async function signCommit<
|
|
22
|
-
// @ts-ignore
|
|
23
32
|
chain extends Chain | undefined,
|
|
24
33
|
account extends Account | undefined,
|
|
34
|
+
chainOverride extends Chain | undefined = undefined,
|
|
25
35
|
>(
|
|
26
36
|
client: KontorWalletClient<RpcTransport, chain, account>,
|
|
27
|
-
parameters: SignCommitParameters<chain, account>,
|
|
37
|
+
parameters: SignCommitParameters<chain, account, chainOverride>,
|
|
28
38
|
): Promise<SignCommitReturnType> {
|
|
29
39
|
const {
|
|
30
40
|
account: account_ = client.account,
|
|
@@ -33,6 +43,7 @@ export async function signCommit<
|
|
|
33
43
|
} = parameters;
|
|
34
44
|
|
|
35
45
|
if (!account_) throw new Error("AccountNotFoundError");
|
|
46
|
+
// TODO: throw if chain is undefined
|
|
36
47
|
|
|
37
48
|
const account = parseAccount(account_);
|
|
38
49
|
|
|
@@ -18,7 +18,7 @@ import type { ParticipantScripts } from "@kontor/kontor-ts";
|
|
|
18
18
|
export type SignRevealParameters<
|
|
19
19
|
chain extends Chain | undefined,
|
|
20
20
|
account extends Account | undefined,
|
|
21
|
-
> = GetAccountParameter<account> &
|
|
21
|
+
> = GetAccountParameter<account, account, false> &
|
|
22
22
|
// TODO: add chainoverride?
|
|
23
23
|
GetChainParameter<chain> & {
|
|
24
24
|
psbt: string;
|
|
@@ -52,42 +52,51 @@ import type { HttpTransport } from "../../transports/create-http-transport.js";
|
|
|
52
52
|
|
|
53
53
|
export type KontorPublicActions<
|
|
54
54
|
_transport extends HttpTransport = HttpTransport,
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
56
|
+
account extends Account | undefined = Account | undefined,
|
|
57
57
|
> = {
|
|
58
58
|
viewContract: <
|
|
59
59
|
const wit extends Wit | readonly unknown[],
|
|
60
60
|
functionName extends ContractFunctionName<wit, "view">,
|
|
61
61
|
const args extends ContractFunctionArgs<wit, "view", functionName>,
|
|
62
|
+
chainOverride extends Chain | undefined,
|
|
62
63
|
>(
|
|
63
|
-
args: ViewContractParameters<wit, functionName, args>,
|
|
64
|
+
args: ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
64
65
|
) => Promise<ViewContractReturnType<wit, functionName, args>>;
|
|
65
66
|
|
|
66
67
|
procContract: <
|
|
67
68
|
const wit extends Wit | readonly unknown[],
|
|
68
69
|
functionName extends ContractFunctionName<wit, "proc">,
|
|
69
70
|
const args extends ContractFunctionArgs<wit, "proc", functionName>,
|
|
71
|
+
chainOverride extends Chain | undefined,
|
|
70
72
|
>(
|
|
71
|
-
args: ProcContractParameters<
|
|
73
|
+
args: ProcContractParameters<
|
|
74
|
+
wit,
|
|
75
|
+
functionName,
|
|
76
|
+
args,
|
|
77
|
+
chain,
|
|
78
|
+
account,
|
|
79
|
+
chainOverride
|
|
80
|
+
>,
|
|
72
81
|
) => Promise<ProcContractReturnType>;
|
|
73
82
|
|
|
74
|
-
callView: <
|
|
75
|
-
args: CallViewParameters<chain>,
|
|
83
|
+
callView: <chainOverride extends Chain | undefined>(
|
|
84
|
+
args: CallViewParameters<chain, chainOverride>,
|
|
76
85
|
) => Promise<CallViewReturnType>;
|
|
77
86
|
|
|
78
|
-
buildInstructionQuery:
|
|
79
|
-
args: BuildInstructionQueryParameters<
|
|
80
|
-
) =>
|
|
87
|
+
buildInstructionQuery: (
|
|
88
|
+
args: BuildInstructionQueryParameters<account>,
|
|
89
|
+
) => BuildInstructionQueryReturnType;
|
|
81
90
|
|
|
82
|
-
buildComposeQuery:
|
|
83
|
-
args: BuildComposeQueryParameters<
|
|
84
|
-
) =>
|
|
91
|
+
buildComposeQuery: (
|
|
92
|
+
args: BuildComposeQueryParameters<account>,
|
|
93
|
+
) => BuildComposeQueryReturnType;
|
|
85
94
|
|
|
86
|
-
callCompose: <
|
|
87
|
-
args: CallComposeParameters<chain>,
|
|
95
|
+
callCompose: <chainOverride extends Chain | undefined>(
|
|
96
|
+
args: CallComposeParameters<chain, account, chainOverride>,
|
|
88
97
|
) => Promise<CallComposeReturnType>;
|
|
89
|
-
inspect: <
|
|
90
|
-
args: InspectParameters,
|
|
98
|
+
inspect: <chainOverride extends Chain | undefined>(
|
|
99
|
+
args: InspectParameters<chain, chainOverride>,
|
|
91
100
|
) => Promise<InspectReturnType>;
|
|
92
101
|
};
|
|
93
102
|
|
|
@@ -33,8 +33,8 @@ export type KontorWalletActions<
|
|
|
33
33
|
signPsbt: (
|
|
34
34
|
params: SignPsbtParameters<chain, account>,
|
|
35
35
|
) => Promise<SignPsbtReturnType>;
|
|
36
|
-
signCommit: (
|
|
37
|
-
params: SignCommitParameters<chain, account>,
|
|
36
|
+
signCommit: <chainOverride extends Chain | undefined>(
|
|
37
|
+
params: SignCommitParameters<chain, account, chainOverride>,
|
|
38
38
|
) => Promise<SignCommitReturnType>;
|
|
39
39
|
signReveal: (
|
|
40
40
|
params: SignRevealParameters<chain, account>,
|
|
@@ -43,17 +43,17 @@ export type KontorPublicClientConfig<
|
|
|
43
43
|
export type KontorPublicClient<
|
|
44
44
|
transport extends HttpTransport = HttpTransport,
|
|
45
45
|
chain extends Chain | undefined = Chain | undefined,
|
|
46
|
-
|
|
46
|
+
account extends Account | undefined = Account | undefined,
|
|
47
47
|
httpSchema extends HttpSchema | undefined = undefined,
|
|
48
48
|
> = Prettify<
|
|
49
49
|
HttpClient<
|
|
50
50
|
transport,
|
|
51
51
|
chain,
|
|
52
|
-
|
|
52
|
+
account,
|
|
53
53
|
httpSchema extends HttpSchema
|
|
54
54
|
? [...KontorSchemaPublic, ...httpSchema]
|
|
55
55
|
: KontorSchemaPublic,
|
|
56
|
-
KontorPublicActions
|
|
56
|
+
KontorPublicActions<transport, chain, account>
|
|
57
57
|
>
|
|
58
58
|
>;
|
|
59
59
|
|
|
@@ -44,17 +44,17 @@ export type KontorWalletClientConfig<
|
|
|
44
44
|
export type KontorWalletClient<
|
|
45
45
|
transport extends RpcTransport = RpcTransport,
|
|
46
46
|
chain extends Chain | undefined = Chain | undefined,
|
|
47
|
-
|
|
47
|
+
account extends Account | undefined = Account | undefined,
|
|
48
48
|
rpcSchema extends RpcSchema | undefined = undefined,
|
|
49
49
|
> = Prettify<
|
|
50
50
|
RpcClient<
|
|
51
51
|
transport,
|
|
52
52
|
chain,
|
|
53
|
-
|
|
53
|
+
account,
|
|
54
54
|
rpcSchema extends RpcSchema
|
|
55
55
|
? [...WBIP001Schema, ...rpcSchema]
|
|
56
56
|
: WBIP001Schema,
|
|
57
|
-
KontorWalletActions
|
|
57
|
+
KontorWalletActions<chain, account>
|
|
58
58
|
>
|
|
59
59
|
>;
|
|
60
60
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Chain } from "../types/chain.js";
|
|
2
|
+
|
|
3
|
+
import { BaseError } from "./base.js";
|
|
4
|
+
|
|
5
|
+
export type ChainMismatchErrorType = ChainMismatchError & {
|
|
6
|
+
name: "ChainMismatchError";
|
|
7
|
+
};
|
|
8
|
+
export class ChainMismatchError extends BaseError {
|
|
9
|
+
constructor({ chain, currentChain }: { chain: Chain; currentChain: Chain }) {
|
|
10
|
+
super(
|
|
11
|
+
`The current chain of the wallet (name: ${currentChain.name}) does not match the target chain for the transaction (name: ${chain.name}).`,
|
|
12
|
+
{
|
|
13
|
+
metaMessages: [
|
|
14
|
+
`Current Chain: ${currentChain.name}`,
|
|
15
|
+
`Expected Chain: ${chain.name}`,
|
|
16
|
+
],
|
|
17
|
+
name: "ChainMismatchError",
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ChainNotFoundErrorType = ChainNotFoundError & {
|
|
24
|
+
name: "ChainNotFoundError";
|
|
25
|
+
};
|
|
26
|
+
export class ChainNotFoundError extends BaseError {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(
|
|
29
|
+
[
|
|
30
|
+
"No chain was provided to the request.",
|
|
31
|
+
"Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient.",
|
|
32
|
+
].join("\n"),
|
|
33
|
+
{
|
|
34
|
+
name: "ChainNotFoundError",
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ClientChainNotConfiguredErrorType =
|
|
41
|
+
ClientChainNotConfiguredError & {
|
|
42
|
+
name: "ClientChainNotConfiguredError";
|
|
43
|
+
};
|
|
44
|
+
export class ClientChainNotConfiguredError extends BaseError {
|
|
45
|
+
constructor() {
|
|
46
|
+
super("No chain was provided to the Client.", {
|
|
47
|
+
name: "ClientChainNotConfiguredError",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type InvalidChainIdErrorType = InvalidChainIdError & {
|
|
53
|
+
name: "InvalidChainIdError";
|
|
54
|
+
};
|
|
55
|
+
export class InvalidChainIdError extends BaseError {
|
|
56
|
+
constructor({ chainId }: { chainId?: number | undefined }) {
|
|
57
|
+
super(
|
|
58
|
+
typeof chainId === "number"
|
|
59
|
+
? `Chain ID "${chainId}" is invalid.`
|
|
60
|
+
: "Chain ID is invalid.",
|
|
61
|
+
{ name: "InvalidChainIdError" },
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/sdk/test/e2e.test.ts
CHANGED
|
@@ -120,8 +120,16 @@ test("e2e kontor wallet client", async () => {
|
|
|
120
120
|
|
|
121
121
|
const kontorPublicClient = createKontorPublicClient({
|
|
122
122
|
transport: http("https://signet-staging.kontor.network:35000/api"),
|
|
123
|
+
chain: signet,
|
|
124
|
+
account,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const kontorWalletClient = createKontorWalletClient({
|
|
123
128
|
account,
|
|
124
129
|
chain: signet,
|
|
130
|
+
transport: custom({
|
|
131
|
+
request: async (_args: any) => null,
|
|
132
|
+
}),
|
|
125
133
|
});
|
|
126
134
|
|
|
127
135
|
const res = await kontorPublicClient.callCompose({
|
|
@@ -132,23 +140,32 @@ test("e2e kontor wallet client", async () => {
|
|
|
132
140
|
satsPerVByte: 1,
|
|
133
141
|
});
|
|
134
142
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
143
|
+
// TODO: add separate tests for these
|
|
144
|
+
// const instructionQuery_ = kontorPublicClient.buildInstructionQuery({
|
|
145
|
+
// utxos: [
|
|
146
|
+
// "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
|
|
147
|
+
// ],
|
|
148
|
+
// instruction: Instruction.issuance(),
|
|
149
|
+
// });
|
|
150
|
+
//
|
|
151
|
+
// const composeQuery_ = kontorPublicClient.buildComposeQuery({
|
|
152
|
+
// utxos: [
|
|
153
|
+
// "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
|
|
154
|
+
// ],
|
|
155
|
+
//
|
|
156
|
+
// instruction: Instruction.issuance(),
|
|
157
|
+
// satsPerVByte: 1,
|
|
158
|
+
// });
|
|
159
|
+
// const x = await kontorPublicClient.callView({
|
|
160
|
+
// contractAddress: "token_0_0",
|
|
161
|
+
// wave: "balances()",
|
|
162
|
+
// });
|
|
142
163
|
|
|
143
164
|
const commit: Transaction = await kontorWalletClient.signCommit({
|
|
144
|
-
account: account,
|
|
145
|
-
chain: signet,
|
|
146
165
|
psbt: res.result.commit_psbt_hex,
|
|
147
166
|
});
|
|
148
167
|
|
|
149
168
|
const reveal: Transaction = await kontorWalletClient.signReveal({
|
|
150
|
-
account: account,
|
|
151
|
-
chain: signet,
|
|
152
169
|
psbt: res.result.reveal_psbt_hex,
|
|
153
170
|
parcipantScripts: res.result.per_participant,
|
|
154
171
|
});
|
package/src/sdk/types/chain.ts
CHANGED
|
@@ -73,8 +73,6 @@ export type Chain<
|
|
|
73
73
|
}
|
|
74
74
|
>
|
|
75
75
|
| undefined;
|
|
76
|
-
/** ID in number form */
|
|
77
|
-
id: number;
|
|
78
76
|
/** Human-readable name */
|
|
79
77
|
name: string;
|
|
80
78
|
nativeCurrency: ChainNativeCurrency;
|
|
@@ -108,3 +106,8 @@ export type GetChainParameter<
|
|
|
108
106
|
IsUndefined<chain> extends true
|
|
109
107
|
? { chain: chainOverride | null }
|
|
110
108
|
: { chain?: chainOverride | null | undefined };
|
|
109
|
+
|
|
110
|
+
export type DeriveChain<
|
|
111
|
+
chain extends Chain | undefined,
|
|
112
|
+
chainOverride extends Chain | undefined,
|
|
113
|
+
> = chainOverride extends Chain ? chainOverride : chain;
|
|
@@ -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
|
};
|
|
@@ -16,10 +16,7 @@ export type ParseOptions = {
|
|
|
16
16
|
records?: RecordLookup;
|
|
17
17
|
type?: WitItemType | "record";
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
// export const witParameterRegex =
|
|
21
|
-
// /^(?:(?<name>[a-z][a-z0-9-]*)\s*:\s*)?(?<type>(?:borrow|list|option|result|tuple)\s*<[\s\S]+>|[a-z][a-z0-9-]*|(?:record|variant|flags|enum)\s*\{[\s\S]*\})$/;
|
|
22
|
-
//
|
|
19
|
+
|
|
23
20
|
export const witParameterRegex =
|
|
24
21
|
/^(?:(?<name>[a-z][a-z0-9-]*)\s*:\s*)?(?<type>_|(?:borrow|list|option|result|tuple)\s*<[\s\S]+>|[a-z][a-z0-9-]*|(?:record|variant|flags|enum)\s*\{[\s\S]*\})$/;
|
|
25
22
|
|
|
@@ -60,7 +57,6 @@ export function parseWitParameter(param: string, options?: ParseOptions) {
|
|
|
60
57
|
if (match.name && isWitKeyword(match.name))
|
|
61
58
|
throw new WitProtectedKeywordError({ param, name: match.name });
|
|
62
59
|
|
|
63
|
-
// TODO: smell
|
|
64
60
|
const name = match.name ? { name: match.name } : {};
|
|
65
61
|
const records = options?.records ?? {};
|
|
66
62
|
let type: string;
|