@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.
Files changed (200) hide show
  1. package/CHANGELOG.md +212 -84
  2. package/README.md +2 -46
  3. package/dist/cjs/bcs/bcs.d.ts +2 -2
  4. package/dist/cjs/bcs/bcs.js.map +2 -2
  5. package/dist/cjs/bcs/index.d.ts +20 -20
  6. package/dist/cjs/bcs/type-tag-serializer.js.map +1 -1
  7. package/dist/cjs/client/client.d.ts +5 -2
  8. package/dist/cjs/client/client.js +5 -0
  9. package/dist/cjs/client/client.js.map +2 -2
  10. package/dist/cjs/client/http-transport.js +14 -28
  11. package/dist/cjs/client/http-transport.js.map +1 -1
  12. package/dist/cjs/client/network.js.map +1 -1
  13. package/dist/cjs/client/rpc-websocket-client.d.ts +1 -8
  14. package/dist/cjs/client/rpc-websocket-client.js +14 -31
  15. package/dist/cjs/client/rpc-websocket-client.js.map +1 -1
  16. package/dist/cjs/cryptography/publickey.js +1 -2
  17. package/dist/cjs/cryptography/publickey.js.map +1 -1
  18. package/dist/cjs/faucet/faucet.js.map +1 -1
  19. package/dist/cjs/graphql/client.js +11 -22
  20. package/dist/cjs/graphql/client.js.map +2 -2
  21. package/dist/cjs/graphql/schemas/2024.1/index.d.ts +681 -681
  22. package/dist/cjs/graphql/schemas/2024.4/index.d.ts +682 -682
  23. package/dist/cjs/keypairs/ed25519/keypair.js.map +1 -1
  24. package/dist/cjs/keypairs/ed25519/publickey.js.map +1 -1
  25. package/dist/cjs/keypairs/secp256k1/publickey.js.map +1 -1
  26. package/dist/cjs/keypairs/secp256r1/publickey.js.map +1 -1
  27. package/dist/cjs/multisig/publickey.js.map +1 -1
  28. package/dist/cjs/multisig/signer.js +9 -20
  29. package/dist/cjs/multisig/signer.js.map +1 -1
  30. package/dist/cjs/transactions/Arguments.d.ts +988 -0
  31. package/dist/cjs/transactions/Arguments.js +32 -0
  32. package/dist/cjs/transactions/Arguments.js.map +7 -0
  33. package/dist/cjs/transactions/Commands.d.ts +19 -72
  34. package/dist/cjs/transactions/Commands.js.map +1 -1
  35. package/dist/cjs/transactions/ObjectCache.d.ts +1 -4
  36. package/dist/cjs/transactions/ObjectCache.js +8 -19
  37. package/dist/cjs/transactions/ObjectCache.js.map +1 -1
  38. package/dist/cjs/transactions/Transaction.d.ts +48 -50
  39. package/dist/cjs/transactions/Transaction.js +25 -51
  40. package/dist/cjs/transactions/Transaction.js.map +2 -2
  41. package/dist/cjs/transactions/TransactionData.d.ts +2 -2
  42. package/dist/cjs/transactions/TransactionData.js.map +2 -2
  43. package/dist/cjs/transactions/data/internal.d.ts +447 -2128
  44. package/dist/cjs/transactions/data/internal.js +32 -29
  45. package/dist/cjs/transactions/data/internal.js.map +2 -2
  46. package/dist/cjs/transactions/data/v1.d.ts +288 -1818
  47. package/dist/cjs/transactions/data/v1.js +80 -80
  48. package/dist/cjs/transactions/data/v1.js.map +2 -2
  49. package/dist/cjs/transactions/data/v2.d.ts +24 -192
  50. package/dist/cjs/transactions/data/v2.js +3 -3
  51. package/dist/cjs/transactions/data/v2.js.map +2 -2
  52. package/dist/cjs/transactions/executor/caching.d.ts +1 -0
  53. package/dist/cjs/transactions/executor/caching.js +23 -22
  54. package/dist/cjs/transactions/executor/caching.js.map +2 -2
  55. package/dist/cjs/transactions/executor/parallel.d.ts +1 -0
  56. package/dist/cjs/transactions/executor/parallel.js +45 -61
  57. package/dist/cjs/transactions/executor/parallel.js.map +2 -2
  58. package/dist/cjs/transactions/executor/queue.js +6 -13
  59. package/dist/cjs/transactions/executor/queue.js.map +1 -1
  60. package/dist/cjs/transactions/executor/serial.d.ts +2 -1
  61. package/dist/cjs/transactions/executor/serial.js +14 -40
  62. package/dist/cjs/transactions/executor/serial.js.map +2 -2
  63. package/dist/cjs/transactions/hash.js.map +1 -1
  64. package/dist/cjs/transactions/index.d.ts +1 -0
  65. package/dist/cjs/transactions/index.js +2 -2
  66. package/dist/cjs/transactions/index.js.map +2 -2
  67. package/dist/cjs/transactions/intents/CoinWithBalance.js.map +2 -2
  68. package/dist/cjs/transactions/json-rpc-resolver.js +1 -2
  69. package/dist/cjs/transactions/json-rpc-resolver.js.map +2 -2
  70. package/dist/cjs/transactions/pure.d.ts +25 -182
  71. package/dist/cjs/transactions/pure.js +58 -12
  72. package/dist/cjs/transactions/pure.js.map +3 -3
  73. package/dist/cjs/transactions/serializer.js.map +1 -1
  74. package/dist/cjs/utils/constants.js.map +1 -1
  75. package/dist/cjs/utils/format.js.map +1 -1
  76. package/dist/cjs/utils/sui-types.js +1 -2
  77. package/dist/cjs/utils/sui-types.js.map +2 -2
  78. package/dist/cjs/utils/suins.js +2 -2
  79. package/dist/cjs/utils/suins.js.map +2 -2
  80. package/dist/cjs/verify/verify.js.map +1 -1
  81. package/dist/cjs/version.d.ts +2 -2
  82. package/dist/cjs/version.js +2 -2
  83. package/dist/cjs/version.js.map +1 -1
  84. package/dist/cjs/zklogin/index.d.ts +1 -1
  85. package/dist/cjs/zklogin/index.js +1 -0
  86. package/dist/cjs/zklogin/index.js.map +2 -2
  87. package/dist/cjs/zklogin/jwt-utils.js.map +1 -1
  88. package/dist/cjs/zklogin/publickey.js +11 -22
  89. package/dist/cjs/zklogin/publickey.js.map +1 -1
  90. package/dist/esm/bcs/bcs.d.ts +2 -2
  91. package/dist/esm/bcs/bcs.js.map +2 -2
  92. package/dist/esm/bcs/index.d.ts +20 -20
  93. package/dist/esm/bcs/type-tag-serializer.js.map +1 -1
  94. package/dist/esm/client/client.d.ts +5 -2
  95. package/dist/esm/client/client.js +5 -0
  96. package/dist/esm/client/client.js.map +2 -2
  97. package/dist/esm/client/http-transport.js +13 -27
  98. package/dist/esm/client/http-transport.js.map +1 -1
  99. package/dist/esm/client/network.js.map +1 -1
  100. package/dist/esm/client/rpc-websocket-client.d.ts +1 -8
  101. package/dist/esm/client/rpc-websocket-client.js +13 -30
  102. package/dist/esm/client/rpc-websocket-client.js.map +1 -1
  103. package/dist/esm/cryptography/publickey.js +1 -2
  104. package/dist/esm/cryptography/publickey.js.map +1 -1
  105. package/dist/esm/faucet/faucet.js.map +1 -1
  106. package/dist/esm/graphql/client.js +10 -21
  107. package/dist/esm/graphql/client.js.map +2 -2
  108. package/dist/esm/graphql/schemas/2024.1/index.d.ts +681 -681
  109. package/dist/esm/graphql/schemas/2024.4/index.d.ts +682 -682
  110. package/dist/esm/keypairs/ed25519/keypair.js.map +1 -1
  111. package/dist/esm/keypairs/ed25519/publickey.js.map +1 -1
  112. package/dist/esm/keypairs/secp256k1/publickey.js.map +1 -1
  113. package/dist/esm/keypairs/secp256r1/publickey.js.map +1 -1
  114. package/dist/esm/multisig/publickey.js.map +1 -1
  115. package/dist/esm/multisig/signer.js +8 -19
  116. package/dist/esm/multisig/signer.js.map +1 -1
  117. package/dist/esm/transactions/Arguments.d.ts +988 -0
  118. package/dist/esm/transactions/Arguments.js +12 -0
  119. package/dist/esm/transactions/Arguments.js.map +7 -0
  120. package/dist/esm/transactions/Commands.d.ts +19 -72
  121. package/dist/esm/transactions/Commands.js.map +1 -1
  122. package/dist/esm/transactions/ObjectCache.d.ts +1 -4
  123. package/dist/esm/transactions/ObjectCache.js +7 -18
  124. package/dist/esm/transactions/ObjectCache.js.map +1 -1
  125. package/dist/esm/transactions/Transaction.d.ts +48 -50
  126. package/dist/esm/transactions/Transaction.js +24 -50
  127. package/dist/esm/transactions/Transaction.js.map +2 -2
  128. package/dist/esm/transactions/TransactionData.d.ts +2 -2
  129. package/dist/esm/transactions/TransactionData.js.map +2 -2
  130. package/dist/esm/transactions/data/internal.d.ts +447 -2128
  131. package/dist/esm/transactions/data/internal.js +35 -31
  132. package/dist/esm/transactions/data/internal.js.map +2 -2
  133. package/dist/esm/transactions/data/v1.d.ts +288 -1818
  134. package/dist/esm/transactions/data/v1.js +83 -82
  135. package/dist/esm/transactions/data/v1.js.map +2 -2
  136. package/dist/esm/transactions/data/v2.d.ts +24 -192
  137. package/dist/esm/transactions/data/v2.js +4 -3
  138. package/dist/esm/transactions/data/v2.js.map +2 -2
  139. package/dist/esm/transactions/executor/caching.d.ts +1 -0
  140. package/dist/esm/transactions/executor/caching.js +22 -21
  141. package/dist/esm/transactions/executor/caching.js.map +2 -2
  142. package/dist/esm/transactions/executor/parallel.d.ts +1 -0
  143. package/dist/esm/transactions/executor/parallel.js +44 -60
  144. package/dist/esm/transactions/executor/parallel.js.map +2 -2
  145. package/dist/esm/transactions/executor/queue.js +5 -12
  146. package/dist/esm/transactions/executor/queue.js.map +1 -1
  147. package/dist/esm/transactions/executor/serial.d.ts +2 -1
  148. package/dist/esm/transactions/executor/serial.js +13 -39
  149. package/dist/esm/transactions/executor/serial.js.map +2 -2
  150. package/dist/esm/transactions/hash.js.map +1 -1
  151. package/dist/esm/transactions/index.d.ts +1 -0
  152. package/dist/esm/transactions/index.js +2 -2
  153. package/dist/esm/transactions/index.js.map +2 -2
  154. package/dist/esm/transactions/intents/CoinWithBalance.js.map +2 -2
  155. package/dist/esm/transactions/json-rpc-resolver.js +1 -2
  156. package/dist/esm/transactions/json-rpc-resolver.js.map +2 -2
  157. package/dist/esm/transactions/pure.d.ts +25 -182
  158. package/dist/esm/transactions/pure.js +48 -2
  159. package/dist/esm/transactions/pure.js.map +2 -2
  160. package/dist/esm/transactions/serializer.js.map +1 -1
  161. package/dist/esm/utils/constants.js.map +1 -1
  162. package/dist/esm/utils/format.js.map +1 -1
  163. package/dist/esm/utils/sui-types.js +1 -2
  164. package/dist/esm/utils/sui-types.js.map +2 -2
  165. package/dist/esm/utils/suins.js +2 -2
  166. package/dist/esm/utils/suins.js.map +2 -2
  167. package/dist/esm/verify/verify.js.map +1 -1
  168. package/dist/esm/version.d.ts +2 -2
  169. package/dist/esm/version.js +2 -2
  170. package/dist/esm/version.js.map +1 -1
  171. package/dist/esm/zklogin/index.d.ts +1 -1
  172. package/dist/esm/zklogin/index.js +2 -1
  173. package/dist/esm/zklogin/index.js.map +2 -2
  174. package/dist/esm/zklogin/jwt-utils.js.map +1 -1
  175. package/dist/esm/zklogin/publickey.js +10 -21
  176. package/dist/esm/zklogin/publickey.js.map +1 -1
  177. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  178. package/dist/tsconfig.tsbuildinfo +1 -1
  179. package/package.json +26 -26
  180. package/src/bcs/bcs.ts +2 -2
  181. package/src/client/client.ts +7 -4
  182. package/src/graphql/client.ts +1 -1
  183. package/src/transactions/Arguments.ts +23 -0
  184. package/src/transactions/Commands.ts +12 -12
  185. package/src/transactions/Transaction.ts +14 -13
  186. package/src/transactions/TransactionData.ts +4 -2
  187. package/src/transactions/data/internal.ts +52 -47
  188. package/src/transactions/data/v1.ts +102 -100
  189. package/src/transactions/data/v2.ts +9 -8
  190. package/src/transactions/executor/caching.ts +14 -2
  191. package/src/transactions/executor/parallel.ts +16 -2
  192. package/src/transactions/executor/serial.ts +3 -10
  193. package/src/transactions/index.ts +2 -0
  194. package/src/transactions/intents/CoinWithBalance.ts +2 -2
  195. package/src/transactions/json-rpc-resolver.ts +1 -1
  196. package/src/transactions/pure.ts +106 -4
  197. package/src/utils/sui-types.ts +1 -1
  198. package/src/utils/suins.ts +2 -2
  199. package/src/version.ts +2 -2
  200. 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.2.0",
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.7.1",
102
- "@graphql-codegen/add": "^5.0.2",
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.4",
105
- "@graphql-codegen/typescript": "4.0.4",
106
- "@graphql-codegen/typescript-operations": "^4.1.2",
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.4.2",
109
- "@types/tmp": "^0.2.3",
110
- "@types/ws": "^8.5.9",
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": "^1.2.2",
114
- "tmp": "^0.2.1",
115
- "ts-retry-promise": "^0.7.0",
116
- "typescript": "^5.3.3",
117
- "vite": "^4.4.4",
118
- "vitest": "^1.6.0",
119
- "wait-on": "^7.0.1",
120
- "ws": "^8.14.2",
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.1.0",
126
- "@noble/hashes": "^1.3.1",
127
- "@scure/bip32": "^1.3.1",
128
- "@scure/bip39": "^1.2.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.7.0",
132
- "graphql": "^16.8.1",
131
+ "gql.tada": "^1.8.2",
132
+ "graphql": "^16.9.0",
133
133
  "tweetnacl": "^1.0.3",
134
- "valibot": "^0.25.0",
135
- "@mysten/bcs": "1.0.2"
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-test-validator --bin sui --profile dev && cross-env RUST_LOG=warn,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui-test-validator -- --with-indexer --pg-port 5435 --pg-db-name sui_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125",
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
@@ -164,10 +164,10 @@ export const Command = bcs.enum('Command', {
164
164
  val === null
165
165
  ? {
166
166
  None: true,
167
- }
167
+ }
168
168
  : {
169
169
  Some: val,
170
- },
170
+ },
171
171
  output: (val) => val.Some ?? null,
172
172
  }),
173
173
  elements: bcs.vector(Argument),
@@ -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 */
@@ -26,7 +26,7 @@ export type GraphQLQueryOptions<
26
26
  ? { variables?: Variables }
27
27
  : {
28
28
  variables: Variables;
29
- });
29
+ });
30
30
 
31
31
  export type GraphQLQueryResult<Result = Record<string, unknown>> = {
32
32
  data?: Result;
@@ -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 { Input } from 'valibot';
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
- | Input<typeof Argument>
15
- | ((tx: Transaction) => Input<typeof Argument>);
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: Input<typeof Argument>[],
66
- address: Input<typeof Argument>,
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: Input<typeof Argument>,
78
- amounts: Input<typeof Argument>[],
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: Input<typeof Argument>,
90
- sources: Input<typeof Argument>[],
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: Input<typeof Argument>;
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: Input<typeof Argument>[];
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, Input<typeof Argument> | Input<typeof Argument>[]>;
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 { Input } from 'valibot';
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<Input<typeof Argument>, { Input: unknown; type?: 'pure' }>
31
- | ((tx: Transaction) => Exclude<Input<typeof Argument>, { Input: unknown; type?: 'pure' }>);
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?: Input<typeof TransactionExpiration> | null) {
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
- ? Inputs.Pure(value)
228
- : { $kind: 'UnresolvedPure', UnresolvedPure: { value } },
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) => TransactionResult)): TransactionResult {
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
- return createTransactionResult(index - 1);
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 { Input } from 'valibot';
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: Input<typeof SerializedTransactionDataV2> | Input<typeof SerializedTransactionDataV1>,
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 { BaseSchema, Input, Output } from 'valibot';
5
+ import type { GenericSchema, InferInput, InferOutput } from 'valibot';
6
6
  import {
7
7
  array,
8
8
  boolean,
9
- custom,
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, BaseSchema<any>>> = BaseSchema<
31
+ type EnumSchema<T extends Record<string, GenericSchema<any>>> = GenericSchema<
31
32
  EnumInputShape<
32
33
  Merge<{
33
- [K in keyof T]: Input<T[K]>;
34
+ [K in keyof T]: InferInput<T[K]>;
34
35
  }>
35
36
  >,
36
37
  EnumOutputShape<
37
38
  Merge<{
38
- [K in keyof T]: Output<T[K]>;
39
+ [K in keyof T]: InferOutput<T[K]>;
39
40
  }>
40
41
  >
41
42
  >;
42
43
 
43
- export function safeEnum<T extends Record<string, BaseSchema<any>>>(options: T): EnumSchema<T> {
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 transform(union(unionOptions), (value) => ({
47
- ...value,
48
- $kind: Object.keys(value)[0] as keyof typeof value,
49
- })) as EnumSchema<T>;
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 = transform(string(), (value) => normalizeSuiAddress(value), [
53
- custom(isValidSuiAddress),
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 = union(
58
- [string(), number([integer()])],
59
- [
60
- custom((val) => {
61
- try {
62
- BigInt(val);
63
- return BigInt(val) >= 0 && BigInt(val) <= 18446744073709551615n;
64
- } catch {
65
- return false;
66
- }
67
- }, 'Invalid u64'),
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 = Output<typeof 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 = transform(
85
+ export const Argument = pipe(
81
86
  union([
82
87
  object({ GasCoin: literal(true) }),
83
- object({ Input: number([integer()]), type: optional(literal('pure')) }),
84
- object({ Input: number([integer()]), type: optional(literal('object')) }),
85
- object({ Result: number([integer()]) }),
86
- object({ NestedResult: tuple([number([integer()]), number([integer()])]) }),
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 BaseSchema<
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 = Output<typeof 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 = Output<typeof 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 = Output<typeof 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: BaseSchema<OpenMoveTypeSignatureBody> = union([
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: recursive(() => OpenMoveTypeSignatureBody) }),
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(recursive(() => OpenMoveTypeSignatureBody)),
169
+ typeParameters: array(lazy(() => OpenMoveTypeSignatureBody)),
165
170
  }),
166
171
  }),
167
- object({ typeParameter: number([integer()]) }),
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 = Output<typeof 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 = Output<typeof 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 = Output<typeof 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 = Output<typeof 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 = Output<typeof TransactionData>;
326
+ export type TransactionData = InferOutput<typeof TransactionData>;