@mysten/sui 1.2.0 → 1.3.0
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/CHANGELOG.md +212 -84
- package/README.md +2 -46
- package/dist/cjs/bcs/bcs.d.ts +2 -2
- package/dist/cjs/bcs/bcs.js.map +2 -2
- package/dist/cjs/bcs/index.d.ts +20 -20
- package/dist/cjs/bcs/type-tag-serializer.js.map +1 -1
- package/dist/cjs/client/client.d.ts +5 -2
- package/dist/cjs/client/client.js +5 -0
- package/dist/cjs/client/client.js.map +2 -2
- package/dist/cjs/client/http-transport.js +14 -28
- package/dist/cjs/client/http-transport.js.map +1 -1
- package/dist/cjs/client/network.js.map +1 -1
- package/dist/cjs/client/rpc-websocket-client.d.ts +1 -8
- package/dist/cjs/client/rpc-websocket-client.js +14 -31
- package/dist/cjs/client/rpc-websocket-client.js.map +1 -1
- package/dist/cjs/cryptography/publickey.js +1 -2
- package/dist/cjs/cryptography/publickey.js.map +1 -1
- package/dist/cjs/faucet/faucet.js.map +1 -1
- package/dist/cjs/graphql/client.js +11 -22
- package/dist/cjs/graphql/client.js.map +2 -2
- package/dist/cjs/graphql/schemas/2024.1/index.d.ts +681 -681
- package/dist/cjs/graphql/schemas/2024.4/index.d.ts +682 -682
- package/dist/cjs/keypairs/ed25519/keypair.js.map +1 -1
- package/dist/cjs/keypairs/ed25519/publickey.js.map +1 -1
- package/dist/cjs/keypairs/secp256k1/publickey.js.map +1 -1
- package/dist/cjs/keypairs/secp256r1/publickey.js.map +1 -1
- package/dist/cjs/multisig/publickey.js.map +1 -1
- package/dist/cjs/multisig/signer.js +9 -20
- package/dist/cjs/multisig/signer.js.map +1 -1
- package/dist/cjs/transactions/Arguments.d.ts +988 -0
- package/dist/cjs/transactions/Arguments.js +32 -0
- package/dist/cjs/transactions/Arguments.js.map +7 -0
- package/dist/cjs/transactions/Commands.d.ts +19 -72
- package/dist/cjs/transactions/Commands.js.map +1 -1
- package/dist/cjs/transactions/ObjectCache.d.ts +1 -4
- package/dist/cjs/transactions/ObjectCache.js +8 -19
- package/dist/cjs/transactions/ObjectCache.js.map +1 -1
- package/dist/cjs/transactions/Transaction.d.ts +48 -50
- package/dist/cjs/transactions/Transaction.js +25 -51
- package/dist/cjs/transactions/Transaction.js.map +2 -2
- package/dist/cjs/transactions/TransactionData.d.ts +2 -2
- package/dist/cjs/transactions/TransactionData.js.map +2 -2
- package/dist/cjs/transactions/data/internal.d.ts +447 -2128
- package/dist/cjs/transactions/data/internal.js +32 -29
- package/dist/cjs/transactions/data/internal.js.map +2 -2
- package/dist/cjs/transactions/data/v1.d.ts +288 -1818
- package/dist/cjs/transactions/data/v1.js +80 -80
- package/dist/cjs/transactions/data/v1.js.map +2 -2
- package/dist/cjs/transactions/data/v2.d.ts +24 -192
- package/dist/cjs/transactions/data/v2.js +3 -3
- package/dist/cjs/transactions/data/v2.js.map +2 -2
- package/dist/cjs/transactions/executor/caching.d.ts +1 -0
- package/dist/cjs/transactions/executor/caching.js +23 -22
- package/dist/cjs/transactions/executor/caching.js.map +2 -2
- package/dist/cjs/transactions/executor/parallel.d.ts +1 -0
- package/dist/cjs/transactions/executor/parallel.js +45 -61
- package/dist/cjs/transactions/executor/parallel.js.map +2 -2
- package/dist/cjs/transactions/executor/queue.js +6 -13
- package/dist/cjs/transactions/executor/queue.js.map +1 -1
- package/dist/cjs/transactions/executor/serial.d.ts +2 -1
- package/dist/cjs/transactions/executor/serial.js +14 -40
- package/dist/cjs/transactions/executor/serial.js.map +2 -2
- package/dist/cjs/transactions/hash.js.map +1 -1
- package/dist/cjs/transactions/index.d.ts +1 -0
- package/dist/cjs/transactions/index.js +2 -2
- package/dist/cjs/transactions/index.js.map +2 -2
- package/dist/cjs/transactions/intents/CoinWithBalance.js.map +2 -2
- package/dist/cjs/transactions/json-rpc-resolver.js +1 -2
- package/dist/cjs/transactions/json-rpc-resolver.js.map +2 -2
- package/dist/cjs/transactions/pure.d.ts +25 -182
- package/dist/cjs/transactions/pure.js +58 -12
- package/dist/cjs/transactions/pure.js.map +3 -3
- package/dist/cjs/transactions/serializer.js.map +1 -1
- package/dist/cjs/utils/constants.js.map +1 -1
- package/dist/cjs/utils/format.js.map +1 -1
- package/dist/cjs/utils/sui-types.js +1 -2
- package/dist/cjs/utils/sui-types.js.map +2 -2
- package/dist/cjs/utils/suins.js +2 -2
- package/dist/cjs/utils/suins.js.map +2 -2
- package/dist/cjs/verify/verify.js.map +1 -1
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/zklogin/index.d.ts +1 -1
- package/dist/cjs/zklogin/index.js +1 -0
- package/dist/cjs/zklogin/index.js.map +2 -2
- package/dist/cjs/zklogin/jwt-utils.js.map +1 -1
- package/dist/cjs/zklogin/publickey.js +11 -22
- package/dist/cjs/zklogin/publickey.js.map +1 -1
- package/dist/esm/bcs/bcs.d.ts +2 -2
- package/dist/esm/bcs/bcs.js.map +2 -2
- package/dist/esm/bcs/index.d.ts +20 -20
- package/dist/esm/bcs/type-tag-serializer.js.map +1 -1
- package/dist/esm/client/client.d.ts +5 -2
- package/dist/esm/client/client.js +5 -0
- package/dist/esm/client/client.js.map +2 -2
- package/dist/esm/client/http-transport.js +13 -27
- package/dist/esm/client/http-transport.js.map +1 -1
- package/dist/esm/client/network.js.map +1 -1
- package/dist/esm/client/rpc-websocket-client.d.ts +1 -8
- package/dist/esm/client/rpc-websocket-client.js +13 -30
- package/dist/esm/client/rpc-websocket-client.js.map +1 -1
- package/dist/esm/cryptography/publickey.js +1 -2
- package/dist/esm/cryptography/publickey.js.map +1 -1
- package/dist/esm/faucet/faucet.js.map +1 -1
- package/dist/esm/graphql/client.js +10 -21
- package/dist/esm/graphql/client.js.map +2 -2
- package/dist/esm/graphql/schemas/2024.1/index.d.ts +681 -681
- package/dist/esm/graphql/schemas/2024.4/index.d.ts +682 -682
- package/dist/esm/keypairs/ed25519/keypair.js.map +1 -1
- package/dist/esm/keypairs/ed25519/publickey.js.map +1 -1
- package/dist/esm/keypairs/secp256k1/publickey.js.map +1 -1
- package/dist/esm/keypairs/secp256r1/publickey.js.map +1 -1
- package/dist/esm/multisig/publickey.js.map +1 -1
- package/dist/esm/multisig/signer.js +8 -19
- package/dist/esm/multisig/signer.js.map +1 -1
- package/dist/esm/transactions/Arguments.d.ts +988 -0
- package/dist/esm/transactions/Arguments.js +12 -0
- package/dist/esm/transactions/Arguments.js.map +7 -0
- package/dist/esm/transactions/Commands.d.ts +19 -72
- package/dist/esm/transactions/Commands.js.map +1 -1
- package/dist/esm/transactions/ObjectCache.d.ts +1 -4
- package/dist/esm/transactions/ObjectCache.js +7 -18
- package/dist/esm/transactions/ObjectCache.js.map +1 -1
- package/dist/esm/transactions/Transaction.d.ts +48 -50
- package/dist/esm/transactions/Transaction.js +24 -50
- package/dist/esm/transactions/Transaction.js.map +2 -2
- package/dist/esm/transactions/TransactionData.d.ts +2 -2
- package/dist/esm/transactions/TransactionData.js.map +2 -2
- package/dist/esm/transactions/data/internal.d.ts +447 -2128
- package/dist/esm/transactions/data/internal.js +35 -31
- package/dist/esm/transactions/data/internal.js.map +2 -2
- package/dist/esm/transactions/data/v1.d.ts +288 -1818
- package/dist/esm/transactions/data/v1.js +83 -82
- package/dist/esm/transactions/data/v1.js.map +2 -2
- package/dist/esm/transactions/data/v2.d.ts +24 -192
- package/dist/esm/transactions/data/v2.js +4 -3
- package/dist/esm/transactions/data/v2.js.map +2 -2
- package/dist/esm/transactions/executor/caching.d.ts +1 -0
- package/dist/esm/transactions/executor/caching.js +22 -21
- package/dist/esm/transactions/executor/caching.js.map +2 -2
- package/dist/esm/transactions/executor/parallel.d.ts +1 -0
- package/dist/esm/transactions/executor/parallel.js +44 -60
- package/dist/esm/transactions/executor/parallel.js.map +2 -2
- package/dist/esm/transactions/executor/queue.js +5 -12
- package/dist/esm/transactions/executor/queue.js.map +1 -1
- package/dist/esm/transactions/executor/serial.d.ts +2 -1
- package/dist/esm/transactions/executor/serial.js +13 -39
- package/dist/esm/transactions/executor/serial.js.map +2 -2
- package/dist/esm/transactions/hash.js.map +1 -1
- package/dist/esm/transactions/index.d.ts +1 -0
- package/dist/esm/transactions/index.js +2 -2
- package/dist/esm/transactions/index.js.map +2 -2
- package/dist/esm/transactions/intents/CoinWithBalance.js.map +2 -2
- package/dist/esm/transactions/json-rpc-resolver.js +1 -2
- package/dist/esm/transactions/json-rpc-resolver.js.map +2 -2
- package/dist/esm/transactions/pure.d.ts +25 -182
- package/dist/esm/transactions/pure.js +48 -2
- package/dist/esm/transactions/pure.js.map +2 -2
- package/dist/esm/transactions/serializer.js.map +1 -1
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/sui-types.js +1 -2
- package/dist/esm/utils/sui-types.js.map +2 -2
- package/dist/esm/utils/suins.js +2 -2
- package/dist/esm/utils/suins.js.map +2 -2
- package/dist/esm/verify/verify.js.map +1 -1
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/zklogin/index.d.ts +1 -1
- package/dist/esm/zklogin/index.js +2 -1
- package/dist/esm/zklogin/index.js.map +2 -2
- package/dist/esm/zklogin/jwt-utils.js.map +1 -1
- package/dist/esm/zklogin/publickey.js +10 -21
- package/dist/esm/zklogin/publickey.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -26
- package/src/bcs/bcs.ts +2 -2
- package/src/client/client.ts +7 -4
- package/src/graphql/client.ts +1 -1
- package/src/transactions/Arguments.ts +23 -0
- package/src/transactions/Commands.ts +12 -12
- package/src/transactions/Transaction.ts +14 -13
- package/src/transactions/TransactionData.ts +4 -2
- package/src/transactions/data/internal.ts +52 -47
- package/src/transactions/data/v1.ts +102 -100
- package/src/transactions/data/v2.ts +9 -8
- package/src/transactions/executor/caching.ts +14 -2
- package/src/transactions/executor/parallel.ts +16 -2
- package/src/transactions/executor/serial.ts +3 -10
- package/src/transactions/index.ts +2 -0
- package/src/transactions/intents/CoinWithBalance.ts +2 -2
- package/src/transactions/json-rpc-resolver.ts +1 -1
- package/src/transactions/pure.ts +106 -4
- package/src/utils/sui-types.ts +1 -1
- package/src/utils/suins.ts +2 -2
- package/src/version.ts +2 -2
- package/src/zklogin/index.ts +1 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "Sui TypeScript API(Work in Progress)",
|
|
5
5
|
"homepage": "https://sdk.mystenlabs.com",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.0",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
@@ -98,41 +98,41 @@
|
|
|
98
98
|
"access": "public"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@0no-co/graphqlsp": "^1.
|
|
102
|
-
"@graphql-codegen/add": "^5.0.
|
|
101
|
+
"@0no-co/graphqlsp": "^1.12.11",
|
|
102
|
+
"@graphql-codegen/add": "^5.0.3",
|
|
103
103
|
"@graphql-codegen/cli": "^5.0.2",
|
|
104
|
-
"@graphql-codegen/typed-document-node": "^5.0.
|
|
105
|
-
"@graphql-codegen/typescript": "4.0.
|
|
106
|
-
"@graphql-codegen/typescript-operations": "^4.
|
|
104
|
+
"@graphql-codegen/typed-document-node": "^5.0.9",
|
|
105
|
+
"@graphql-codegen/typescript": "4.0.9",
|
|
106
|
+
"@graphql-codegen/typescript-operations": "^4.2.3",
|
|
107
107
|
"@iarna/toml": "^2.2.5",
|
|
108
|
-
"@types/node": "^20.
|
|
109
|
-
"@types/tmp": "^0.2.
|
|
110
|
-
"@types/ws": "^8.5.
|
|
108
|
+
"@types/node": "^20.14.10",
|
|
109
|
+
"@types/tmp": "^0.2.6",
|
|
110
|
+
"@types/ws": "^8.5.10",
|
|
111
111
|
"cross-env": "^7.0.3",
|
|
112
112
|
"graphql-config": "^5.0.3",
|
|
113
|
-
"msw": "^
|
|
114
|
-
"tmp": "^0.2.
|
|
115
|
-
"ts-retry-promise": "^0.
|
|
116
|
-
"typescript": "^5.
|
|
117
|
-
"vite": "^
|
|
118
|
-
"vitest": "^
|
|
119
|
-
"wait-on": "^7.0
|
|
120
|
-
"ws": "^8.
|
|
113
|
+
"msw": "^2.3.1",
|
|
114
|
+
"tmp": "^0.2.3",
|
|
115
|
+
"ts-retry-promise": "^0.8.1",
|
|
116
|
+
"typescript": "^5.5.3",
|
|
117
|
+
"vite": "^5.3.3",
|
|
118
|
+
"vitest": "^2.0.1",
|
|
119
|
+
"wait-on": "^7.2.0",
|
|
120
|
+
"ws": "^8.18.0",
|
|
121
121
|
"@mysten/build-scripts": "^0.0.0"
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
124
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
125
|
-
"@noble/curves": "^1.
|
|
126
|
-
"@noble/hashes": "^1.
|
|
127
|
-
"@scure/bip32": "^1.
|
|
128
|
-
"@scure/bip39": "^1.
|
|
125
|
+
"@noble/curves": "^1.4.2",
|
|
126
|
+
"@noble/hashes": "^1.4.0",
|
|
127
|
+
"@scure/bip32": "^1.4.0",
|
|
128
|
+
"@scure/bip39": "^1.3.0",
|
|
129
129
|
"@suchipi/femver": "^1.0.0",
|
|
130
130
|
"bech32": "^2.0.0",
|
|
131
|
-
"gql.tada": "^1.
|
|
132
|
-
"graphql": "^16.
|
|
131
|
+
"gql.tada": "^1.8.2",
|
|
132
|
+
"graphql": "^16.9.0",
|
|
133
133
|
"tweetnacl": "^1.0.3",
|
|
134
|
-
"valibot": "^0.
|
|
135
|
-
"@mysten/bcs": "1.0.
|
|
134
|
+
"valibot": "^0.36.0",
|
|
135
|
+
"@mysten/bcs": "1.0.3"
|
|
136
136
|
},
|
|
137
137
|
"scripts": {
|
|
138
138
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"test:unit": "vitest run unit __tests__",
|
|
146
146
|
"test:e2e": "wait-on http://127.0.0.1:9123 -l --timeout 180000 && vitest run e2e",
|
|
147
147
|
"test:e2e:nowait": "vitest run e2e",
|
|
148
|
-
"prepare:e2e": "docker-compose down && docker-compose up -d && cargo build --bin sui
|
|
148
|
+
"prepare:e2e": "docker-compose down && docker-compose up -d && cargo build --bin sui --features indexer --profile dev && cross-env RUST_LOG=warn,sui=error,anemo_tower=warn,consensus=off ../../target/debug/sui start --with-faucet --force-regenesis --with-indexer --pg-port 5435 --pg-db-name sui_indexer_v2 --with-graphql",
|
|
149
149
|
"size": "size-limit",
|
|
150
150
|
"analyze": "size-limit --why",
|
|
151
151
|
"prettier:check": "prettier -c --ignore-unknown .",
|
package/src/bcs/bcs.ts
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -118,13 +118,11 @@ type NetworkOrTransport =
|
|
|
118
118
|
url?: never;
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
const SUI_CLIENT_BRAND = Symbol.for('@mysten/SuiClient');
|
|
121
|
+
const SUI_CLIENT_BRAND = Symbol.for('@mysten/SuiClient') as never;
|
|
122
122
|
|
|
123
123
|
export function isSuiClient(client: unknown): client is SuiClient {
|
|
124
124
|
return (
|
|
125
|
-
typeof client === 'object' &&
|
|
126
|
-
client !== null &&
|
|
127
|
-
(client as { [SUI_CLIENT_BRAND]: unknown })[SUI_CLIENT_BRAND] === true
|
|
125
|
+
typeof client === 'object' && client !== null && (client as any)[SUI_CLIENT_BRAND] === true
|
|
128
126
|
);
|
|
129
127
|
}
|
|
130
128
|
|
|
@@ -525,6 +523,8 @@ export class SuiClient {
|
|
|
525
523
|
|
|
526
524
|
/**
|
|
527
525
|
* Subscribe to get notifications whenever an event matching the filter occurs
|
|
526
|
+
*
|
|
527
|
+
* @deprecated
|
|
528
528
|
*/
|
|
529
529
|
async subscribeEvent(
|
|
530
530
|
input: SubscribeEventParams & {
|
|
@@ -540,6 +540,9 @@ export class SuiClient {
|
|
|
540
540
|
});
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
+
/**
|
|
544
|
+
* @deprecated
|
|
545
|
+
*/
|
|
543
546
|
async subscribeTransaction(
|
|
544
547
|
input: SubscribeTransactionParams & {
|
|
545
548
|
/** function to run when we receive a notification of a new event matching the filter */
|
package/src/graphql/client.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Inputs } from './Inputs.js';
|
|
5
|
+
import { createPure } from './pure.js';
|
|
6
|
+
import type { Transaction, TransactionObjectInput } from './Transaction.js';
|
|
7
|
+
|
|
8
|
+
export const Arguments = {
|
|
9
|
+
pure: createPure((value) => (tx: Transaction) => tx.pure(value)),
|
|
10
|
+
object: (value: TransactionObjectInput) => (tx: Transaction) => tx.object(value),
|
|
11
|
+
sharedObjectRef:
|
|
12
|
+
(...args: Parameters<(typeof Inputs)['SharedObjectRef']>) =>
|
|
13
|
+
(tx: Transaction) =>
|
|
14
|
+
tx.sharedObjectRef(...args),
|
|
15
|
+
objectRef:
|
|
16
|
+
(...args: Parameters<(typeof Inputs)['ObjectRef']>) =>
|
|
17
|
+
(tx: Transaction) =>
|
|
18
|
+
tx.objectRef(...args),
|
|
19
|
+
receivingRef:
|
|
20
|
+
(...args: Parameters<(typeof Inputs)['ReceivingRef']>) =>
|
|
21
|
+
(tx: Transaction) =>
|
|
22
|
+
tx.receivingRef(...args),
|
|
23
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { toB64 } from '@mysten/bcs';
|
|
5
|
-
import type {
|
|
5
|
+
import type { InferInput } from 'valibot';
|
|
6
6
|
import { parse } from 'valibot';
|
|
7
7
|
|
|
8
8
|
import { normalizeSuiObjectId } from '../utils/sui-types.js';
|
|
@@ -11,8 +11,8 @@ import type { CallArg, Command } from './data/internal.js';
|
|
|
11
11
|
import type { Transaction } from './Transaction.js';
|
|
12
12
|
|
|
13
13
|
export type TransactionArgument =
|
|
14
|
-
|
|
|
15
|
-
| ((tx: Transaction) =>
|
|
14
|
+
| InferInput<typeof Argument>
|
|
15
|
+
| ((tx: Transaction) => InferInput<typeof Argument>);
|
|
16
16
|
export type TransactionInput = CallArg;
|
|
17
17
|
|
|
18
18
|
// Keep in sync with constants in
|
|
@@ -62,8 +62,8 @@ export const Commands = {
|
|
|
62
62
|
},
|
|
63
63
|
|
|
64
64
|
TransferObjects(
|
|
65
|
-
objects:
|
|
66
|
-
address:
|
|
65
|
+
objects: InferInput<typeof Argument>[],
|
|
66
|
+
address: InferInput<typeof Argument>,
|
|
67
67
|
): TransactionShape<'TransferObjects'> {
|
|
68
68
|
return {
|
|
69
69
|
$kind: 'TransferObjects',
|
|
@@ -74,8 +74,8 @@ export const Commands = {
|
|
|
74
74
|
};
|
|
75
75
|
},
|
|
76
76
|
SplitCoins(
|
|
77
|
-
coin:
|
|
78
|
-
amounts:
|
|
77
|
+
coin: InferInput<typeof Argument>,
|
|
78
|
+
amounts: InferInput<typeof Argument>[],
|
|
79
79
|
): TransactionShape<'SplitCoins'> {
|
|
80
80
|
return {
|
|
81
81
|
$kind: 'SplitCoins',
|
|
@@ -86,8 +86,8 @@ export const Commands = {
|
|
|
86
86
|
};
|
|
87
87
|
},
|
|
88
88
|
MergeCoins(
|
|
89
|
-
destination:
|
|
90
|
-
sources:
|
|
89
|
+
destination: InferInput<typeof Argument>,
|
|
90
|
+
sources: InferInput<typeof Argument>[],
|
|
91
91
|
): TransactionShape<'MergeCoins'> {
|
|
92
92
|
return {
|
|
93
93
|
$kind: 'MergeCoins',
|
|
@@ -123,7 +123,7 @@ export const Commands = {
|
|
|
123
123
|
modules: number[][] | string[];
|
|
124
124
|
dependencies: string[];
|
|
125
125
|
package: string;
|
|
126
|
-
ticket:
|
|
126
|
+
ticket: InferInput<typeof Argument>;
|
|
127
127
|
}): TransactionShape<'Upgrade'> {
|
|
128
128
|
return {
|
|
129
129
|
$kind: 'Upgrade',
|
|
@@ -142,7 +142,7 @@ export const Commands = {
|
|
|
142
142
|
elements,
|
|
143
143
|
}: {
|
|
144
144
|
type?: string;
|
|
145
|
-
elements:
|
|
145
|
+
elements: InferInput<typeof Argument>[];
|
|
146
146
|
}): TransactionShape<'MakeMoveVec'> {
|
|
147
147
|
return {
|
|
148
148
|
$kind: 'MakeMoveVec',
|
|
@@ -158,7 +158,7 @@ export const Commands = {
|
|
|
158
158
|
data = {},
|
|
159
159
|
}: {
|
|
160
160
|
name: string;
|
|
161
|
-
inputs?: Record<string,
|
|
161
|
+
inputs?: Record<string, InferInput<typeof Argument> | InferInput<typeof Argument>[]>;
|
|
162
162
|
data?: Record<string, unknown>;
|
|
163
163
|
}): TransactionShape<'$Intent'> {
|
|
164
164
|
return {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SerializedBcs } from '@mysten/bcs';
|
|
5
5
|
import { fromB64, isSerializedBcs } from '@mysten/bcs';
|
|
6
|
-
import type {
|
|
6
|
+
import type { InferInput } from 'valibot';
|
|
7
7
|
import { is, parse } from 'valibot';
|
|
8
8
|
|
|
9
9
|
import type { SuiClient } from '../client/index.js';
|
|
@@ -27,8 +27,8 @@ import { TransactionDataBuilder } from './TransactionData.js';
|
|
|
27
27
|
import { getIdFromCallArg } from './utils.js';
|
|
28
28
|
|
|
29
29
|
export type TransactionObjectArgument =
|
|
30
|
-
| Exclude<
|
|
31
|
-
| ((tx: Transaction) => Exclude<
|
|
30
|
+
| Exclude<InferInput<typeof Argument>, { Input: unknown; type?: 'pure' }>
|
|
31
|
+
| ((tx: Transaction) => Exclude<InferInput<typeof Argument>, { Input: unknown; type?: 'pure' }>);
|
|
32
32
|
|
|
33
33
|
export type TransactionResult = Extract<Argument, { Result: unknown }> &
|
|
34
34
|
Extract<Argument, { NestedResult: unknown }>[];
|
|
@@ -86,7 +86,7 @@ function createTransactionResult(index: number) {
|
|
|
86
86
|
}) as TransactionResult;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const TRANSACTION_BRAND = Symbol.for('@mysten/transaction');
|
|
89
|
+
const TRANSACTION_BRAND = Symbol.for('@mysten/transaction') as never;
|
|
90
90
|
|
|
91
91
|
interface SignOptions extends BuildTransactionOptions {
|
|
92
92
|
signer: Signer;
|
|
@@ -170,7 +170,7 @@ export class Transaction {
|
|
|
170
170
|
this.#data.sender = sender;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
setExpiration(expiration?:
|
|
173
|
+
setExpiration(expiration?: InferInput<typeof TransactionExpiration> | null) {
|
|
174
174
|
this.#data.expiration = expiration ? parse(TransactionExpiration, expiration) : null;
|
|
175
175
|
}
|
|
176
176
|
setGasPrice(price: number | bigint) {
|
|
@@ -205,10 +205,10 @@ export class Transaction {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
// Temporary workaround for the wallet interface accidentally serializing transactions via postMessage
|
|
208
|
-
get pure(): ReturnType<typeof createPure
|
|
208
|
+
get pure(): ReturnType<typeof createPure<Argument>> {
|
|
209
209
|
Object.defineProperty(this, 'pure', {
|
|
210
210
|
enumerable: false,
|
|
211
|
-
value: createPure((value): Argument => {
|
|
211
|
+
value: createPure<Argument>((value): Argument => {
|
|
212
212
|
if (isSerializedBcs(value)) {
|
|
213
213
|
return this.#data.addInput('pure', {
|
|
214
214
|
$kind: 'Pure',
|
|
@@ -224,8 +224,8 @@ export class Transaction {
|
|
|
224
224
|
is(NormalizedCallArg, value)
|
|
225
225
|
? parse(NormalizedCallArg, value)
|
|
226
226
|
: value instanceof Uint8Array
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
? Inputs.Pure(value)
|
|
228
|
+
: { $kind: 'UnresolvedPure', UnresolvedPure: { value } },
|
|
229
229
|
);
|
|
230
230
|
}),
|
|
231
231
|
});
|
|
@@ -272,9 +272,9 @@ export class Transaction {
|
|
|
272
272
|
? {
|
|
273
273
|
$kind: 'UnresolvedObject',
|
|
274
274
|
UnresolvedObject: { objectId: normalizeSuiAddress(value) },
|
|
275
|
-
|
|
275
|
+
}
|
|
276
276
|
: value,
|
|
277
|
-
|
|
277
|
+
);
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
/**
|
|
@@ -302,13 +302,14 @@ export class Transaction {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
/** Add a transaction to the transaction */
|
|
305
|
-
add(command: Command | ((tx: Transaction) =>
|
|
305
|
+
add<T = TransactionResult>(command: Command | ((tx: Transaction) => T)): T {
|
|
306
306
|
if (typeof command === 'function') {
|
|
307
307
|
return command(this);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
const index = this.#data.commands.push(command);
|
|
311
|
-
|
|
311
|
+
|
|
312
|
+
return createTransactionResult(index - 1) as T;
|
|
312
313
|
}
|
|
313
314
|
|
|
314
315
|
#normalizeTransactionArgument(arg: TransactionArgument | SerializedBcs<any>) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { toB58 } from '@mysten/bcs';
|
|
5
|
-
import type {
|
|
5
|
+
import type { InferInput } from 'valibot';
|
|
6
6
|
import { parse } from 'valibot';
|
|
7
7
|
|
|
8
8
|
import { bcs } from '../bcs/index.js';
|
|
@@ -68,7 +68,9 @@ export class TransactionDataBuilder implements TransactionData {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
static restore(
|
|
71
|
-
data:
|
|
71
|
+
data:
|
|
72
|
+
| InferInput<typeof SerializedTransactionDataV2>
|
|
73
|
+
| InferInput<typeof SerializedTransactionDataV1>,
|
|
72
74
|
) {
|
|
73
75
|
if (data.version === 2) {
|
|
74
76
|
return new TransactionDataBuilder(parse(TransactionData, data));
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EnumInputShape, EnumOutputShape } from '@mysten/bcs';
|
|
5
|
-
import type {
|
|
5
|
+
import type { GenericSchema, InferInput, InferOutput } from 'valibot';
|
|
6
6
|
import {
|
|
7
7
|
array,
|
|
8
8
|
boolean,
|
|
9
|
-
|
|
9
|
+
check,
|
|
10
10
|
integer,
|
|
11
|
+
lazy,
|
|
11
12
|
literal,
|
|
12
13
|
nullable,
|
|
13
14
|
nullish,
|
|
14
15
|
number,
|
|
15
16
|
object,
|
|
16
17
|
optional,
|
|
18
|
+
pipe,
|
|
17
19
|
record,
|
|
18
|
-
recursive,
|
|
19
20
|
string,
|
|
20
21
|
transform,
|
|
21
22
|
tuple,
|
|
@@ -27,45 +28,49 @@ import { isValidSuiAddress, normalizeSuiAddress } from '../../utils/sui-types.js
|
|
|
27
28
|
|
|
28
29
|
type Merge<T> = T extends object ? { [K in keyof T]: T[K] } : never;
|
|
29
30
|
|
|
30
|
-
type EnumSchema<T extends Record<string,
|
|
31
|
+
type EnumSchema<T extends Record<string, GenericSchema<any>>> = GenericSchema<
|
|
31
32
|
EnumInputShape<
|
|
32
33
|
Merge<{
|
|
33
|
-
[K in keyof T]:
|
|
34
|
+
[K in keyof T]: InferInput<T[K]>;
|
|
34
35
|
}>
|
|
35
36
|
>,
|
|
36
37
|
EnumOutputShape<
|
|
37
38
|
Merge<{
|
|
38
|
-
[K in keyof T]:
|
|
39
|
+
[K in keyof T]: InferOutput<T[K]>;
|
|
39
40
|
}>
|
|
40
41
|
>
|
|
41
42
|
>;
|
|
42
43
|
|
|
43
|
-
export function safeEnum<T extends Record<string,
|
|
44
|
+
export function safeEnum<T extends Record<string, GenericSchema<any>>>(options: T): EnumSchema<T> {
|
|
44
45
|
const unionOptions = Object.entries(options).map(([key, value]) => object({ [key]: value }));
|
|
45
46
|
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return pipe(
|
|
48
|
+
union(unionOptions),
|
|
49
|
+
transform((value) => ({
|
|
50
|
+
...value,
|
|
51
|
+
$kind: Object.keys(value)[0] as keyof typeof value,
|
|
52
|
+
})),
|
|
53
|
+
) as EnumSchema<T>;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
export const SuiAddress =
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
export const SuiAddress = pipe(
|
|
57
|
+
string(),
|
|
58
|
+
transform((value) => normalizeSuiAddress(value)),
|
|
59
|
+
check(isValidSuiAddress),
|
|
60
|
+
);
|
|
55
61
|
export const ObjectID = SuiAddress;
|
|
56
62
|
export const BCSBytes = string();
|
|
57
|
-
export const JsonU64 =
|
|
58
|
-
[string(), number(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
],
|
|
63
|
+
export const JsonU64 = pipe(
|
|
64
|
+
union([string(), pipe(number(), integer())]),
|
|
65
|
+
|
|
66
|
+
check((val) => {
|
|
67
|
+
try {
|
|
68
|
+
BigInt(val);
|
|
69
|
+
return BigInt(val) >= 0 && BigInt(val) <= 18446744073709551615n;
|
|
70
|
+
} catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}, 'Invalid u64'),
|
|
69
74
|
);
|
|
70
75
|
// https://github.com/MystenLabs/sui/blob/df41d5fa8127634ff4285671a01ead00e519f806/crates/sui-types/src/base_types.rs#L138
|
|
71
76
|
// Implemented as a tuple in rust
|
|
@@ -74,23 +79,23 @@ export const ObjectRef = object({
|
|
|
74
79
|
version: JsonU64,
|
|
75
80
|
digest: string(),
|
|
76
81
|
});
|
|
77
|
-
export type ObjectRef =
|
|
82
|
+
export type ObjectRef = InferOutput<typeof ObjectRef>;
|
|
78
83
|
|
|
79
84
|
// https://github.com/MystenLabs/sui/blob/df41d5fa8127634ff4285671a01ead00e519f806/crates/sui-types/src/transaction.rs#L690-L702
|
|
80
|
-
export const Argument =
|
|
85
|
+
export const Argument = pipe(
|
|
81
86
|
union([
|
|
82
87
|
object({ GasCoin: literal(true) }),
|
|
83
|
-
object({ Input: number(
|
|
84
|
-
object({ Input: number(
|
|
85
|
-
object({ Result: number(
|
|
86
|
-
object({ NestedResult: tuple([number(
|
|
88
|
+
object({ Input: pipe(number(), integer()), type: optional(literal('pure')) }),
|
|
89
|
+
object({ Input: pipe(number(), integer()), type: optional(literal('object')) }),
|
|
90
|
+
object({ Result: pipe(number(), integer()) }),
|
|
91
|
+
object({ NestedResult: tuple([pipe(number(), integer()), pipe(number(), integer())]) }),
|
|
87
92
|
]),
|
|
88
|
-
(value) => ({
|
|
93
|
+
transform((value) => ({
|
|
89
94
|
...value,
|
|
90
95
|
$kind: Object.keys(value)[0] as keyof typeof value,
|
|
91
|
-
}),
|
|
96
|
+
})),
|
|
92
97
|
// Defined manually to add `type?: 'pure' | 'object'` to Input
|
|
93
|
-
) as
|
|
98
|
+
) as GenericSchema<
|
|
94
99
|
// Input
|
|
95
100
|
| { GasCoin: true }
|
|
96
101
|
| { Input: number; type?: 'pure' | 'object' }
|
|
@@ -104,7 +109,7 @@ export const Argument = transform(
|
|
|
104
109
|
| { $kind: 'NestedResult'; NestedResult: [number, number] }
|
|
105
110
|
>;
|
|
106
111
|
|
|
107
|
-
export type Argument =
|
|
112
|
+
export type Argument = InferOutput<typeof Argument>;
|
|
108
113
|
|
|
109
114
|
// https://github.com/MystenLabs/sui/blob/df41d5fa8127634ff4285671a01ead00e519f806/crates/sui-types/src/transaction.rs#L1387-L1392
|
|
110
115
|
export const GasData = object({
|
|
@@ -113,7 +118,7 @@ export const GasData = object({
|
|
|
113
118
|
owner: nullable(SuiAddress),
|
|
114
119
|
payment: nullable(array(ObjectRef)),
|
|
115
120
|
});
|
|
116
|
-
export type GasData =
|
|
121
|
+
export type GasData = InferOutput<typeof GasData>;
|
|
117
122
|
|
|
118
123
|
// https://github.com/MystenLabs/sui/blob/df41d5fa8127634ff4285671a01ead00e519f806/external-crates/move/crates/move-core-types/src/language_storage.rs#L140-L147
|
|
119
124
|
export const StructTag = object({
|
|
@@ -123,7 +128,7 @@ export const StructTag = object({
|
|
|
123
128
|
// type_params in rust, should be updated to use camelCase
|
|
124
129
|
typeParams: array(string()),
|
|
125
130
|
});
|
|
126
|
-
export type StructTag =
|
|
131
|
+
export type StructTag = InferOutput<typeof StructTag>;
|
|
127
132
|
|
|
128
133
|
// https://github.com/MystenLabs/sui/blob/cea8742e810142a8145fd83c4c142d61e561004a/crates/sui-graphql-rpc/schema/current_progress_schema.graphql#L1614-L1627
|
|
129
134
|
export type OpenMoveTypeSignatureBody =
|
|
@@ -146,7 +151,7 @@ export type OpenMoveTypeSignatureBody =
|
|
|
146
151
|
}
|
|
147
152
|
| { typeParameter: number };
|
|
148
153
|
|
|
149
|
-
export const OpenMoveTypeSignatureBody:
|
|
154
|
+
export const OpenMoveTypeSignatureBody: GenericSchema<OpenMoveTypeSignatureBody> = union([
|
|
150
155
|
literal('address'),
|
|
151
156
|
literal('bool'),
|
|
152
157
|
literal('u8'),
|
|
@@ -155,16 +160,16 @@ export const OpenMoveTypeSignatureBody: BaseSchema<OpenMoveTypeSignatureBody> =
|
|
|
155
160
|
literal('u64'),
|
|
156
161
|
literal('u128'),
|
|
157
162
|
literal('u256'),
|
|
158
|
-
object({ vector:
|
|
163
|
+
object({ vector: lazy(() => OpenMoveTypeSignatureBody) }),
|
|
159
164
|
object({
|
|
160
165
|
datatype: object({
|
|
161
166
|
package: string(),
|
|
162
167
|
module: string(),
|
|
163
168
|
type: string(),
|
|
164
|
-
typeParameters: array(
|
|
169
|
+
typeParameters: array(lazy(() => OpenMoveTypeSignatureBody)),
|
|
165
170
|
}),
|
|
166
171
|
}),
|
|
167
|
-
object({ typeParameter: number(
|
|
172
|
+
object({ typeParameter: pipe(number(), integer()) }),
|
|
168
173
|
]);
|
|
169
174
|
|
|
170
175
|
// https://github.com/MystenLabs/sui/blob/cea8742e810142a8145fd83c4c142d61e561004a/crates/sui-graphql-rpc/schema/current_progress_schema.graphql#L1609-L1612
|
|
@@ -172,7 +177,7 @@ export const OpenMoveTypeSignature = object({
|
|
|
172
177
|
ref: nullable(union([literal('&'), literal('&mut')])),
|
|
173
178
|
body: OpenMoveTypeSignatureBody,
|
|
174
179
|
});
|
|
175
|
-
export type OpenMoveTypeSignature =
|
|
180
|
+
export type OpenMoveTypeSignature = InferOutput<typeof OpenMoveTypeSignature>;
|
|
176
181
|
|
|
177
182
|
// https://github.com/MystenLabs/sui/blob/df41d5fa8127634ff4285671a01ead00e519f806/crates/sui-types/src/transaction.rs#L707-L718
|
|
178
183
|
const ProgrammableMoveCall = object({
|
|
@@ -184,7 +189,7 @@ const ProgrammableMoveCall = object({
|
|
|
184
189
|
arguments: array(Argument),
|
|
185
190
|
_argumentTypes: optional(nullable(array(OpenMoveTypeSignature))),
|
|
186
191
|
});
|
|
187
|
-
export type ProgrammableMoveCall =
|
|
192
|
+
export type ProgrammableMoveCall = InferOutput<typeof ProgrammableMoveCall>;
|
|
188
193
|
|
|
189
194
|
export const $Intent = object({
|
|
190
195
|
name: string(),
|
|
@@ -294,7 +299,7 @@ const CallArg = safeEnum({
|
|
|
294
299
|
initialSharedVersion: optional(nullable(JsonU64)),
|
|
295
300
|
}),
|
|
296
301
|
});
|
|
297
|
-
export type CallArg =
|
|
302
|
+
export type CallArg = InferOutput<typeof CallArg>;
|
|
298
303
|
|
|
299
304
|
export const NormalizedCallArg = safeEnum({
|
|
300
305
|
Object: ObjectArg,
|
|
@@ -308,7 +313,7 @@ export const TransactionExpiration = safeEnum({
|
|
|
308
313
|
Epoch: JsonU64,
|
|
309
314
|
});
|
|
310
315
|
|
|
311
|
-
export type TransactionExpiration =
|
|
316
|
+
export type TransactionExpiration = InferOutput<typeof TransactionExpiration>;
|
|
312
317
|
|
|
313
318
|
export const TransactionData = object({
|
|
314
319
|
version: literal(2),
|
|
@@ -318,4 +323,4 @@ export const TransactionData = object({
|
|
|
318
323
|
inputs: array(CallArg),
|
|
319
324
|
commands: array(Command),
|
|
320
325
|
});
|
|
321
|
-
export type TransactionData =
|
|
326
|
+
export type TransactionData = InferOutput<typeof TransactionData>;
|