@kontor/kontor-sdk 1.0.0-alpha.28 → 1.0.0-alpha.29
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/exports/index.js.map +1 -1
- package/dist/cjs/sdk/accounts/hd-key-to-account.js +1 -0
- package/dist/cjs/sdk/accounts/hd-key-to-account.js.map +1 -1
- package/dist/cjs/sdk/accounts/mnemonic-to-account.js +2 -4
- package/dist/cjs/sdk/accounts/mnemonic-to-account.js.map +1 -1
- package/dist/cjs/sdk/accounts/private-key-to-account.js +3 -8
- package/dist/cjs/sdk/accounts/private-key-to-account.js.map +1 -1
- package/dist/cjs/sdk/accounts/to-local-account.js.map +1 -1
- package/dist/cjs/sdk/actions/get-contract.js +36 -16
- package/dist/cjs/sdk/actions/get-contract.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/build-compose-query.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/codecs/bool.js +29 -0
- package/dist/cjs/sdk/utils/wit/codecs/bool.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/s64.js +57 -0
- package/dist/cjs/sdk/utils/wit/codecs/s64.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +134 -131
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js +74 -26
- package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/{splitParameters.js → split-parameters.js} +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/split-parameters.js.map +1 -0
- package/dist/cjs/wit/wit-parser/core/utils.js +3 -3
- package/dist/cjs/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/esm/exports/index.js +1 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/sdk/accounts/hd-key-to-account.js +2 -5
- package/dist/esm/sdk/accounts/hd-key-to-account.js.map +1 -1
- package/dist/esm/sdk/accounts/mnemonic-to-account.js +2 -10
- package/dist/esm/sdk/accounts/mnemonic-to-account.js.map +1 -1
- package/dist/esm/sdk/accounts/private-key-to-account.js +3 -15
- package/dist/esm/sdk/accounts/private-key-to-account.js.map +1 -1
- package/dist/esm/sdk/accounts/to-local-account.js +0 -5
- package/dist/esm/sdk/accounts/to-local-account.js.map +1 -1
- package/dist/esm/sdk/actions/get-contract.js +37 -35
- package/dist/esm/sdk/actions/get-contract.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/build-compose-query.js.map +1 -1
- package/dist/esm/sdk/utils/wit/codecs/bool.js +26 -0
- package/dist/esm/sdk/utils/wit/codecs/bool.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/s64.js +65 -0
- package/dist/esm/sdk/utils/wit/codecs/s64.js.map +1 -0
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +155 -147
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/esm/sdk/utils/wit/encode-wit-parameters.js +74 -72
- package/dist/esm/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/wit/wit-parser/core/errors/{splitParameters.js → split-parameters.js} +1 -1
- package/dist/esm/wit/wit-parser/core/errors/split-parameters.js.map +1 -0
- package/dist/esm/wit/wit-parser/core/utils.js +1 -1
- package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/types/exports/index.d.ts +1 -1
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/sdk/accounts/hd-key-to-account.d.ts +0 -5
- package/dist/types/sdk/accounts/hd-key-to-account.d.ts.map +1 -1
- package/dist/types/sdk/accounts/mnemonic-to-account.d.ts +1 -6
- package/dist/types/sdk/accounts/mnemonic-to-account.d.ts.map +1 -1
- package/dist/types/sdk/accounts/private-key-to-account.d.ts +5 -3
- package/dist/types/sdk/accounts/private-key-to-account.d.ts.map +1 -1
- package/dist/types/sdk/accounts/to-local-account.d.ts +0 -5
- package/dist/types/sdk/accounts/to-local-account.d.ts.map +1 -1
- package/dist/types/sdk/actions/get-contract.d.ts +28 -5
- package/dist/types/sdk/actions/get-contract.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts +0 -2
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts.map +1 -1
- package/dist/types/sdk/types/contract.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/codecs/bool.d.ts +3 -0
- package/dist/types/sdk/utils/wit/codecs/bool.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/s64.d.ts +23 -0
- package/dist/types/sdk/utils/wit/codecs/s64.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts +12 -3
- package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/errors/{splitParameters.d.ts → split-parameters.d.ts} +1 -1
- package/dist/types/wit/wit-parser/core/errors/split-parameters.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/exports/index.ts +1 -1
- package/src/sdk/accounts/hd-key-to-account.ts +2 -5
- package/src/sdk/accounts/mnemonic-to-account.test.ts +7 -81
- package/src/sdk/accounts/mnemonic-to-account.ts +2 -11
- package/src/sdk/accounts/private-key-to-account.ts +10 -16
- package/src/sdk/accounts/to-local-account.ts +0 -5
- package/src/sdk/actions/get-contract.test-d.ts +10 -9
- package/src/sdk/actions/get-contract.test.ts +49 -0
- package/src/sdk/actions/get-contract.ts +312 -91
- package/src/sdk/actions/kontor/public/build-compose-query.ts +0 -3
- package/src/sdk/test/e2e.test.ts +4 -1
- package/src/sdk/types/contract.ts +3 -14
- package/src/sdk/utils/wit/codecs/bool.ts +29 -0
- package/src/sdk/utils/wit/codecs/s64.ts +76 -0
- package/src/sdk/utils/wit/decode-wit-parameter.ts +167 -164
- package/src/sdk/utils/wit/encode-wit-parameters.ts +78 -75
- package/src/wit/wit-parser/core/utils.ts +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/splitParameters.js.map +0 -1
- package/dist/esm/wit/wit-parser/core/errors/splitParameters.js.map +0 -1
- package/dist/types/wit/wit-parser/core/errors/splitParameters.d.ts.map +0 -1
- /package/src/wit/wit-parser/core/errors/{splitParameters.ts → split-parameters.ts} +0 -0
|
@@ -36,7 +36,9 @@ import { signPsbt } from "./utils/sign-psbt.js";
|
|
|
36
36
|
// signTypedData,
|
|
37
37
|
// } from './utils/signTypedData.js'
|
|
38
38
|
//
|
|
39
|
-
export type PrivateKeyToAccountOptions = {
|
|
39
|
+
export type PrivateKeyToAccountOptions = {
|
|
40
|
+
networkConfig?: BtcNetwork;
|
|
41
|
+
};
|
|
40
42
|
//
|
|
41
43
|
export type PrivateKeyToAccountErrorType =
|
|
42
44
|
| PublicKeyToP2TRPaymentErrorType
|
|
@@ -48,29 +50,21 @@ export type PrivateKeyToAccountErrorType =
|
|
|
48
50
|
// | SignTransactionErrorType
|
|
49
51
|
// | SignTypedDataErrorType
|
|
50
52
|
| ErrorType;
|
|
51
|
-
//
|
|
52
|
-
// /**
|
|
53
|
-
// * @description Creates an Account from a private key.
|
|
54
|
-
// *
|
|
55
|
-
// * @returns A Private Key Account.
|
|
56
|
-
// */
|
|
57
53
|
|
|
58
|
-
const signet: BtcNetwork = {
|
|
59
|
-
bech32: "tb",
|
|
60
|
-
pubKeyHash: 0x6f, // 111 in decimal
|
|
61
|
-
scriptHash: 0xc4, // 196 in decimal
|
|
62
|
-
wif: 0xef, // 239 in decimal
|
|
63
|
-
};
|
|
64
54
|
export function privateKeyToAccount(
|
|
65
55
|
privateKey: Hex,
|
|
66
|
-
|
|
56
|
+
options: PrivateKeyToAccountOptions = {},
|
|
67
57
|
): PrivateKeyAccount {
|
|
58
|
+
console.log({ options });
|
|
59
|
+
|
|
68
60
|
const publicKey = toHex(
|
|
69
61
|
secp256k1.getPublicKey(hex.decode(privateKey.slice(2)), true),
|
|
70
62
|
);
|
|
71
63
|
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
const address = publicKeyToP2TRPayment(
|
|
65
|
+
publicKey.slice(2),
|
|
66
|
+
options.networkConfig,
|
|
67
|
+
);
|
|
74
68
|
|
|
75
69
|
const account = toLocalAccount({
|
|
76
70
|
address: address.address,
|
|
@@ -31,11 +31,6 @@ export type ToLocalAccountErrorType =
|
|
|
31
31
|
| IsAddressErrorType
|
|
32
32
|
| ErrorType;
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* @description Creates an Account from a custom signing implementation.
|
|
36
|
-
*
|
|
37
|
-
* @returns A Local Account.
|
|
38
|
-
*/
|
|
39
34
|
export function toLocalAccount<accountSource extends AccountSource>(
|
|
40
35
|
source: accountSource,
|
|
41
36
|
): GetAccountReturnType<accountSource> {
|
|
@@ -32,14 +32,15 @@ test("KebabToCamel basic mapping", () => {
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test("GetContractReturnType", () => {
|
|
35
|
-
expectTypeOf<GetContractReturnType<typeof wit>>().toEqualTypeOf<{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
35
|
+
// expectTypeOf<GetContractReturnType<typeof wit>>().toEqualTypeOf<{
|
|
36
|
+
// view: {
|
|
37
|
+
// cachedValues: never;
|
|
38
|
+
// fibAsView: never;
|
|
39
|
+
// readWithRecordArg: never;
|
|
40
|
+
// readTools: never;
|
|
41
|
+
// };
|
|
42
|
+
// proc: {}
|
|
43
|
+
// }>;
|
|
43
44
|
});
|
|
44
45
|
test("GetContractReturnType view keys are camelCased", () => {
|
|
45
46
|
type ViewKeys = keyof GetContractReturnType<typeof wit>["view"];
|
|
@@ -63,7 +64,7 @@ test("getContract", async () => {
|
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
test("GetViewFunction for cached-values (no inputs)", () => {
|
|
66
|
-
type Fn = GetViewFunction<true, typeof wit, "cached-values">;
|
|
67
|
+
type Fn = GetViewFunction<true, undefined, typeof wit, "cached-values">;
|
|
67
68
|
|
|
68
69
|
// return type: Promise<ViewContractReturnType<...>>
|
|
69
70
|
// kay
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { test } from "vitest";
|
|
2
|
+
import { nativeToken as nativeToken_ } from "../contracts/wits.js";
|
|
3
|
+
import { createPublicClient as createKontorPublicClient } from "../clients/kontor/create-public-client.js";
|
|
4
|
+
|
|
5
|
+
const nativeToken = nativeToken_.wit;
|
|
6
|
+
|
|
7
|
+
import { mnemonicToAccount } from "../accounts/mnemonic-to-account.js";
|
|
8
|
+
import { signet } from "../chains/definitions/signet.js";
|
|
9
|
+
import { http } from "../clients/transports/http.js";
|
|
10
|
+
import { getContract } from "./get-contract.js";
|
|
11
|
+
|
|
12
|
+
test("e2e getContract", async () => {
|
|
13
|
+
const account = mnemonicToAccount(process.env.TEST_MNEMONIC!, {
|
|
14
|
+
coinType: 1,
|
|
15
|
+
networkConfig: signet.networkConfig,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// if chain is omittet here
|
|
19
|
+
const kontorPublicClient = createKontorPublicClient({
|
|
20
|
+
transport: http("https://signet-staging.kontor.network:35000/api"),
|
|
21
|
+
chain: signet,
|
|
22
|
+
account,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const contract = getContract({
|
|
26
|
+
wit: nativeToken,
|
|
27
|
+
contractAddress: "token_0_0",
|
|
28
|
+
client: kontorPublicClient,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// then options.chain should be required on the view calls
|
|
32
|
+
const balances = await contract.view.balances();
|
|
33
|
+
|
|
34
|
+
const balance = await contract.view.balance([
|
|
35
|
+
"2c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f",
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
const composeOutputs = await contract.proc.burn([[1n, 18]], {
|
|
39
|
+
utxos: [
|
|
40
|
+
"641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
|
|
41
|
+
],
|
|
42
|
+
gas: 1000n,
|
|
43
|
+
satsPerVByte: 1,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.log({ balances });
|
|
47
|
+
console.log({ balance });
|
|
48
|
+
console.log({ composeOutputs });
|
|
49
|
+
});
|
|
@@ -15,12 +15,23 @@ import type {
|
|
|
15
15
|
ContractFunctionName,
|
|
16
16
|
} from "../types/contract.js";
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
import { getKontorAction } from "../utils/get-action.js";
|
|
19
19
|
import {
|
|
20
|
+
viewContract,
|
|
20
21
|
// viewContract,
|
|
21
22
|
type ViewContractParameters,
|
|
22
23
|
type ViewContractReturnType,
|
|
23
24
|
} from "./kontor/public/view-contract.js";
|
|
25
|
+
import type { HttpTransport } from "../clients/transports/create-http-transport.js";
|
|
26
|
+
import type { Chain } from "../types/chain.js";
|
|
27
|
+
import type { Account } from "../accounts/types.js";
|
|
28
|
+
import type { KontorPublicClient } from "../clients/kontor/create-public-client.js";
|
|
29
|
+
import type { ResolvedRegister } from "../../wit/register.js";
|
|
30
|
+
import {
|
|
31
|
+
procContract,
|
|
32
|
+
type ProcContractParameters,
|
|
33
|
+
type ProcContractReturnType,
|
|
34
|
+
} from "./kontor/public/proc-contract.js";
|
|
24
35
|
|
|
25
36
|
// TODO: move to utils
|
|
26
37
|
function camelToKebab(str: string): string {
|
|
@@ -32,45 +43,29 @@ export type KebabToCamel<S extends string> =
|
|
|
32
43
|
? `${Head}${Capitalize<KebabToCamel<Tail>>}`
|
|
33
44
|
: S;
|
|
34
45
|
|
|
35
|
-
export type GetContractParameters<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
_args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
54
|
-
_options = Prettify<
|
|
55
|
-
UnionOmit<
|
|
56
|
-
ViewContractParameters<wit, functionName, args>,
|
|
57
|
-
"contractAddress" | "args" | "functionName"
|
|
58
|
-
>
|
|
59
|
-
>,
|
|
60
|
-
> = narrowable extends true
|
|
61
|
-
? (
|
|
62
|
-
...parameters: _args extends readonly []
|
|
63
|
-
? [options?: _options]
|
|
64
|
-
: [args: _args, options?: _options]
|
|
65
|
-
) => Promise<ViewContractReturnType<wit, functionName, args>>
|
|
66
|
-
: (
|
|
67
|
-
...parameters:
|
|
68
|
-
| [options?: _options]
|
|
69
|
-
| [args: readonly unknown[], options?: _options]
|
|
70
|
-
) => Promise<ViewContractReturnType>;
|
|
46
|
+
export type GetContractParameters<
|
|
47
|
+
transport extends HttpTransport = HttpTransport,
|
|
48
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
49
|
+
account extends Account | undefined = Account | undefined,
|
|
50
|
+
wit extends Wit | readonly unknown[] = Wit,
|
|
51
|
+
client extends KontorPublicClient<
|
|
52
|
+
transport,
|
|
53
|
+
chain,
|
|
54
|
+
account
|
|
55
|
+
> = KontorPublicClient<transport, chain, account>,
|
|
56
|
+
contractAddress extends
|
|
57
|
+
ResolvedRegister["contractAddress"] = ResolvedRegister["contractAddress"],
|
|
58
|
+
> = {
|
|
59
|
+
wit: wit;
|
|
60
|
+
contractAddress: contractAddress;
|
|
61
|
+
client: client;
|
|
62
|
+
};
|
|
71
63
|
|
|
72
64
|
export type GetContractReturnType<
|
|
73
65
|
wit extends Wit | readonly unknown[] = Wit,
|
|
66
|
+
client extends KontorPublicClient = KontorPublicClient,
|
|
67
|
+
contractAddress extends
|
|
68
|
+
ResolvedRegister["contractAddress"] = ResolvedRegister["contractAddress"],
|
|
74
69
|
_viewFunctionNames extends string = wit extends Wit
|
|
75
70
|
? Wit extends wit
|
|
76
71
|
? string
|
|
@@ -85,74 +80,300 @@ export type GetContractReturnType<
|
|
|
85
80
|
> = {
|
|
86
81
|
view: {
|
|
87
82
|
// K is the *original* wit function name ("cached-values")
|
|
88
|
-
[
|
|
83
|
+
[functionName in _viewFunctionNames as KebabToCamel<functionName>]: GetViewFunction<
|
|
89
84
|
_narrowable,
|
|
85
|
+
client["chain"],
|
|
90
86
|
wit,
|
|
91
87
|
// and we pass K directly into GetViewFunction
|
|
92
|
-
|
|
88
|
+
functionName extends ContractFunctionName<wit, "view">
|
|
89
|
+
? functionName
|
|
90
|
+
: never
|
|
93
91
|
>;
|
|
94
92
|
};
|
|
93
|
+
proc: {
|
|
94
|
+
// K is the *original* wit function name ("cached-values")
|
|
95
|
+
[functionName in _procFunctionNames as KebabToCamel<functionName>]: GetProcFunction<
|
|
96
|
+
_narrowable,
|
|
97
|
+
client["chain"],
|
|
98
|
+
client["account"],
|
|
99
|
+
wit,
|
|
100
|
+
// and we pass K directly into GetProcFunction
|
|
101
|
+
functionName extends ContractFunctionName<wit, "proc">
|
|
102
|
+
? functionName
|
|
103
|
+
: never
|
|
104
|
+
>;
|
|
105
|
+
};
|
|
106
|
+
contractAddress: contractAddress;
|
|
107
|
+
wit: wit;
|
|
95
108
|
};
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
wit
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
type ViewOptions<
|
|
111
|
+
wit extends Wit | readonly unknown[],
|
|
112
|
+
functionName extends ContractFunctionName<wit, "view">,
|
|
113
|
+
args extends ContractFunctionArgs<wit, "view", functionName>,
|
|
114
|
+
chain extends Chain | undefined,
|
|
115
|
+
chainOverride extends Chain | undefined,
|
|
116
|
+
> = Prettify<
|
|
117
|
+
UnionOmit<
|
|
118
|
+
ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
119
|
+
"wit" | "contractAddress" | "args" | "functionName"
|
|
120
|
+
>
|
|
121
|
+
>;
|
|
101
122
|
|
|
123
|
+
type OptTuple<chain extends Chain | undefined, O> = chain extends Chain
|
|
124
|
+
? [options?: O]
|
|
125
|
+
: [options: O];
|
|
126
|
+
|
|
127
|
+
export type GetViewFunction<
|
|
128
|
+
narrowable extends boolean,
|
|
129
|
+
chain extends Chain | undefined,
|
|
130
|
+
wit extends Wit | readonly unknown[],
|
|
131
|
+
functionName extends ContractFunctionName<wit, "view">,
|
|
132
|
+
args extends ContractFunctionArgs<
|
|
133
|
+
wit,
|
|
134
|
+
"view",
|
|
135
|
+
functionName
|
|
136
|
+
> = ContractFunctionArgs<wit, "view", functionName>,
|
|
137
|
+
witFunction extends WitFunction = wit extends Wit
|
|
138
|
+
? ExtractWitFunction<wit, functionName>
|
|
139
|
+
: WitFunction,
|
|
140
|
+
_args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
141
|
+
> = narrowable extends true
|
|
142
|
+
? <chainOverride extends Chain | undefined = undefined>(
|
|
143
|
+
...parameters: _args extends readonly []
|
|
144
|
+
? OptTuple<
|
|
145
|
+
chain,
|
|
146
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
147
|
+
>
|
|
148
|
+
: [
|
|
149
|
+
args: _args,
|
|
150
|
+
...options: OptTuple<
|
|
151
|
+
chain,
|
|
152
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
153
|
+
>,
|
|
154
|
+
]
|
|
155
|
+
) => Promise<ViewContractReturnType<wit, functionName, args>>
|
|
156
|
+
: <chainOverride extends Chain | undefined = undefined>(
|
|
157
|
+
...parameters:
|
|
158
|
+
| OptTuple<
|
|
159
|
+
chain,
|
|
160
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
161
|
+
>
|
|
162
|
+
| [
|
|
163
|
+
args: readonly unknown[],
|
|
164
|
+
...options: OptTuple<
|
|
165
|
+
chain,
|
|
166
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
167
|
+
>,
|
|
168
|
+
]
|
|
169
|
+
) => Promise<ViewContractReturnType>;
|
|
170
|
+
|
|
171
|
+
// export type GetViewFunction<
|
|
172
|
+
// narrowable extends boolean,
|
|
173
|
+
// chain extends Chain | undefined,
|
|
174
|
+
// wit extends Wit | readonly unknown[],
|
|
175
|
+
// functionName extends ContractFunctionName<wit, "view">,
|
|
176
|
+
// args extends ContractFunctionArgs<
|
|
177
|
+
// wit,
|
|
178
|
+
// "view",
|
|
179
|
+
// functionName
|
|
180
|
+
// > = ContractFunctionArgs<wit, "view", functionName>,
|
|
181
|
+
// witFunction extends WitFunction = wit extends Wit
|
|
182
|
+
// ? ExtractWitFunction<wit, functionName>
|
|
183
|
+
// : WitFunction,
|
|
184
|
+
// //
|
|
185
|
+
// _args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
186
|
+
// > = narrowable extends true
|
|
187
|
+
// ? <
|
|
188
|
+
// chainOverride extends Chain | undefined,
|
|
189
|
+
// options extends Prettify<
|
|
190
|
+
// UnionOmit<
|
|
191
|
+
// ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
192
|
+
// "wit" | "contractAddress" | "args" | "functionName"
|
|
193
|
+
// >
|
|
194
|
+
// >,
|
|
195
|
+
// >(
|
|
196
|
+
// ...parameters: _args extends readonly []
|
|
197
|
+
// ? chain extends Chain
|
|
198
|
+
// ? [options?: options]
|
|
199
|
+
// : [options: options]
|
|
200
|
+
// : [args: _args, options?: options]
|
|
201
|
+
// ) => Promise<ViewContractReturnType<wit, functionName, args>>
|
|
202
|
+
// : <
|
|
203
|
+
// chainOverride extends Chain | undefined,
|
|
204
|
+
// options extends Prettify<
|
|
205
|
+
// UnionOmit<
|
|
206
|
+
// ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
207
|
+
// "wit" | "contractAddress" | "args" | "functionName"
|
|
208
|
+
// >
|
|
209
|
+
// >,
|
|
210
|
+
// Rest extends unknown[] = [options: options],
|
|
211
|
+
// >(
|
|
212
|
+
// ...parameters: chain extends Chain
|
|
213
|
+
// ? [options?: options] | [args: readonly unknown[], ...parameters: Rest]
|
|
214
|
+
// : [options: options] | [args: readonly unknown[], ...parameters: Rest]
|
|
215
|
+
// ) => Promise<ViewContractReturnType>;
|
|
216
|
+
|
|
217
|
+
export type GetProcFunction<
|
|
218
|
+
narrowable extends boolean,
|
|
219
|
+
chain extends Chain | undefined,
|
|
220
|
+
account extends Account | undefined,
|
|
221
|
+
wit extends Wit | readonly unknown[],
|
|
222
|
+
functionName extends ContractFunctionName<wit, "proc">,
|
|
223
|
+
args extends ContractFunctionArgs<
|
|
224
|
+
wit,
|
|
225
|
+
"proc",
|
|
226
|
+
functionName
|
|
227
|
+
> = ContractFunctionArgs<wit, "proc", functionName>,
|
|
228
|
+
witFunction extends WitFunction = wit extends Wit
|
|
229
|
+
? ExtractWitFunction<wit, functionName>
|
|
230
|
+
: WitFunction,
|
|
231
|
+
//
|
|
232
|
+
_args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
233
|
+
> = narrowable extends true
|
|
234
|
+
? <
|
|
235
|
+
chainOverride extends Chain | undefined,
|
|
236
|
+
options extends Prettify<
|
|
237
|
+
UnionOmit<
|
|
238
|
+
ProcContractParameters<
|
|
239
|
+
wit,
|
|
240
|
+
functionName,
|
|
241
|
+
args,
|
|
242
|
+
chain,
|
|
243
|
+
account,
|
|
244
|
+
chainOverride
|
|
245
|
+
>,
|
|
246
|
+
"wit" | "contractAddress" | "args" | "functionName"
|
|
247
|
+
>
|
|
248
|
+
>,
|
|
249
|
+
>(
|
|
250
|
+
...parameters: _args extends readonly []
|
|
251
|
+
? [options: options]
|
|
252
|
+
: [args: _args, options: options]
|
|
253
|
+
) => Promise<ProcContractReturnType>
|
|
254
|
+
: <
|
|
255
|
+
chainOverride extends Chain | undefined,
|
|
256
|
+
options extends Prettify<
|
|
257
|
+
UnionOmit<
|
|
258
|
+
ProcContractParameters<
|
|
259
|
+
wit,
|
|
260
|
+
functionName,
|
|
261
|
+
args,
|
|
262
|
+
chain,
|
|
263
|
+
account,
|
|
264
|
+
chainOverride
|
|
265
|
+
>,
|
|
266
|
+
"contractAddress" | "args" | "functionName"
|
|
267
|
+
>
|
|
268
|
+
>,
|
|
269
|
+
Rest extends unknown[] = [options: options],
|
|
270
|
+
>(
|
|
271
|
+
...parameters:
|
|
272
|
+
| [options: options]
|
|
273
|
+
| [args: readonly unknown[], ...parameters: Rest]
|
|
274
|
+
) => Promise<ProcContractReturnType>;
|
|
275
|
+
|
|
276
|
+
export function getContract<
|
|
277
|
+
transport extends HttpTransport,
|
|
278
|
+
contractAddress extends ResolvedRegister["contractAddress"],
|
|
279
|
+
const wit extends Wit | readonly unknown[],
|
|
280
|
+
const client extends KontorPublicClient<transport, chain, account>,
|
|
281
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
282
|
+
account extends Account | undefined = Account | undefined,
|
|
283
|
+
>({
|
|
284
|
+
wit,
|
|
285
|
+
contractAddress,
|
|
286
|
+
client: client_,
|
|
287
|
+
}: GetContractParameters<
|
|
288
|
+
transport,
|
|
289
|
+
chain,
|
|
290
|
+
account,
|
|
291
|
+
wit,
|
|
292
|
+
client,
|
|
293
|
+
contractAddress
|
|
294
|
+
>): GetContractReturnType<wit, client, contractAddress> {
|
|
102
295
|
const contract: {
|
|
103
|
-
[_ in "wit" | "view"]?: unknown;
|
|
296
|
+
[_ in "wit" | "contractAddress" | "view" | "proc"]?: unknown;
|
|
104
297
|
} = {};
|
|
105
298
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
299
|
+
console.log("we are defining a proxy");
|
|
300
|
+
|
|
301
|
+
contract.view = new Proxy(
|
|
302
|
+
{},
|
|
303
|
+
{
|
|
304
|
+
get(_, functionName: string) {
|
|
305
|
+
const witFunctionName = camelToKebab(functionName);
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
...parameters: [
|
|
309
|
+
args?: readonly unknown[] | undefined,
|
|
310
|
+
options?: UnionOmit<
|
|
311
|
+
ViewContractParameters,
|
|
312
|
+
"wit" | "contractAddress" | "functionName" | "args"
|
|
313
|
+
>,
|
|
314
|
+
]
|
|
315
|
+
) => {
|
|
316
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
317
|
+
|
|
318
|
+
return getKontorAction(
|
|
319
|
+
client_,
|
|
320
|
+
viewContract,
|
|
321
|
+
"viewContract",
|
|
322
|
+
)({
|
|
323
|
+
wit,
|
|
324
|
+
functionName: witFunctionName,
|
|
325
|
+
contractAddress,
|
|
326
|
+
// address,
|
|
327
|
+
args,
|
|
328
|
+
...options,
|
|
329
|
+
} as ViewContractParameters);
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
contract.proc = new Proxy(
|
|
336
|
+
{},
|
|
337
|
+
{
|
|
338
|
+
get(_, functionName: string) {
|
|
339
|
+
const witFunctionName = camelToKebab(functionName);
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
...parameters: [
|
|
343
|
+
args?: readonly unknown[] | undefined,
|
|
344
|
+
options?: UnionOmit<
|
|
345
|
+
ProcContractParameters,
|
|
346
|
+
"wit" | "contractAddress" | "functionName" | "args"
|
|
347
|
+
>,
|
|
348
|
+
]
|
|
349
|
+
) => {
|
|
350
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
351
|
+
|
|
352
|
+
return getKontorAction(
|
|
353
|
+
client_,
|
|
354
|
+
procContract,
|
|
355
|
+
"procContract",
|
|
356
|
+
)({
|
|
357
|
+
wit,
|
|
358
|
+
functionName: witFunctionName,
|
|
359
|
+
contractAddress,
|
|
360
|
+
args,
|
|
361
|
+
|
|
362
|
+
...options,
|
|
363
|
+
} as any);
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
);
|
|
152
368
|
|
|
153
369
|
contract.wit = wit;
|
|
370
|
+
contract.contractAddress = contractAddress;
|
|
154
371
|
|
|
155
|
-
return contract as unknown as GetContractReturnType<
|
|
372
|
+
return contract as unknown as GetContractReturnType<
|
|
373
|
+
wit,
|
|
374
|
+
client,
|
|
375
|
+
contractAddress
|
|
376
|
+
>;
|
|
156
377
|
}
|
|
157
378
|
|
|
158
379
|
export function getFunctionParameters(
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// import type { ResolvedRegister } from "../../../../wit/register.js";
|
|
2
1
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
3
2
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
4
3
|
import type { Chain } from "../../../types/chain.js";
|
|
@@ -19,8 +18,6 @@ export type BuildComposeQueryParameters<
|
|
|
19
18
|
| undefined,
|
|
20
19
|
> = {
|
|
21
20
|
instruction: Inst;
|
|
22
|
-
address?: Address;
|
|
23
|
-
xOnlyPubKey?: XOnlyPubKey; // TODO: maybe this should be wrapped in a single object
|
|
24
21
|
utxos: UtxoId[];
|
|
25
22
|
satsPerVByte: number;
|
|
26
23
|
} & GetAccountParameter<account, accountOverride, true, true>;
|
package/src/sdk/test/e2e.test.ts
CHANGED
|
@@ -116,7 +116,10 @@ export const wit = parseWit(nativeTokenRaw);
|
|
|
116
116
|
// });
|
|
117
117
|
|
|
118
118
|
test("e2e kontor wallet client", async () => {
|
|
119
|
-
const account = mnemonicToAccount(process.env.TEST_MNEMONIC
|
|
119
|
+
const account = mnemonicToAccount(process.env.TEST_MNEMONIC!, {
|
|
120
|
+
coinType: 1,
|
|
121
|
+
networkConfig: signet.networkConfig,
|
|
122
|
+
});
|
|
120
123
|
|
|
121
124
|
const kontorPublicClient = createKontorPublicClient({
|
|
122
125
|
transport: http("https://signet-staging.kontor.network:35000/api"),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
// Address,
|
|
3
2
|
Wit,
|
|
4
3
|
WitFunction,
|
|
5
4
|
WitParameter,
|
|
@@ -26,10 +25,6 @@ export type ContractFunctionName<
|
|
|
26
25
|
: functionName
|
|
27
26
|
: string;
|
|
28
27
|
|
|
29
|
-
// AbiParametersToPrimitiveTypes,
|
|
30
|
-
// AbiParameterToPrimitiveType,
|
|
31
|
-
// ExtractAbiFunction,
|
|
32
|
-
|
|
33
28
|
export type ContractFunctionArgs<
|
|
34
29
|
wit extends Wit | readonly unknown[] = Wit,
|
|
35
30
|
mutability extends WitStateMutability = WitStateMutability,
|
|
@@ -107,12 +102,8 @@ export type ContractFunctionParameters<
|
|
|
107
102
|
mutability,
|
|
108
103
|
functionName
|
|
109
104
|
> = ContractFunctionArgs<wit, mutability, functionName>,
|
|
110
|
-
// deployless extends boolean = false,
|
|
111
|
-
///
|
|
112
105
|
allFunctionNames = ContractFunctionName<wit, mutability>,
|
|
113
106
|
allArgs = ContractFunctionArgs<wit, mutability, functionName>,
|
|
114
|
-
// when `args` is inferred to `readonly []` ("inputs": []) or `never` (`abi` declared as `Abi` or not inferrable), allow `args` to be optional.
|
|
115
|
-
// important that both branches return same structural type
|
|
116
107
|
> = {
|
|
117
108
|
wit: wit;
|
|
118
109
|
functionName:
|
|
@@ -224,23 +215,21 @@ export type ExtractWitItemForArgs<
|
|
|
224
215
|
ExtractWitItem<wit, name> extends infer witItem extends WitItem & {
|
|
225
216
|
inputs: readonly WitParameter[];
|
|
226
217
|
}
|
|
227
|
-
? IsUnion<witItem> extends true
|
|
218
|
+
? IsUnion<witItem> extends true
|
|
228
219
|
? UnionToTuple<witItem> extends infer witItems extends
|
|
229
220
|
readonly (WitItem & {
|
|
230
221
|
inputs: readonly WitParameter[];
|
|
231
222
|
})[]
|
|
232
223
|
? {
|
|
233
224
|
[k in keyof witItems]: (
|
|
234
|
-
readonly [] extends args
|
|
235
|
-
? readonly [] // fallback to `readonly []` if `args` has no value (e.g. `args` property not provided)
|
|
236
|
-
: args
|
|
225
|
+
readonly [] extends args ? readonly [] : args
|
|
237
226
|
) extends WitParametersToPrimitiveTypes<
|
|
238
227
|
witItems[k]["inputs"],
|
|
239
228
|
"inputs"
|
|
240
229
|
>
|
|
241
230
|
? witItems[k]
|
|
242
231
|
: never;
|
|
243
|
-
}[number]
|
|
232
|
+
}[number]
|
|
244
233
|
: never
|
|
245
234
|
: witItem
|
|
246
235
|
: never;
|