@mysten/sui 1.29.1 → 1.30.1

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 (133) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/cryptography/keypair.d.ts +9 -0
  3. package/dist/cjs/cryptography/keypair.js +13 -0
  4. package/dist/cjs/cryptography/keypair.js.map +2 -2
  5. package/dist/cjs/experimental/core.d.ts +6 -1
  6. package/dist/cjs/experimental/core.js.map +2 -2
  7. package/dist/cjs/experimental/index.d.ts +3 -1
  8. package/dist/cjs/experimental/index.js +4 -1
  9. package/dist/cjs/experimental/index.js.map +2 -2
  10. package/dist/cjs/experimental/transports/graphql.d.ts +1 -0
  11. package/dist/cjs/experimental/transports/graphql.js +7 -5
  12. package/dist/cjs/experimental/transports/graphql.js.map +2 -2
  13. package/dist/cjs/experimental/transports/json-rpc-resolver.d.ts +4 -0
  14. package/dist/cjs/{transactions → experimental/transports}/json-rpc-resolver.js +25 -66
  15. package/dist/cjs/experimental/transports/json-rpc-resolver.js.map +7 -0
  16. package/dist/cjs/experimental/transports/jsonRPC.d.ts +5 -1
  17. package/dist/cjs/experimental/transports/jsonRPC.js +68 -50
  18. package/dist/cjs/experimental/transports/jsonRPC.js.map +2 -2
  19. package/dist/cjs/experimental/transports/utils.d.ts +2 -5
  20. package/dist/cjs/experimental/transports/utils.js +15 -16
  21. package/dist/cjs/experimental/transports/utils.js.map +2 -2
  22. package/dist/cjs/experimental/types.d.ts +7 -3
  23. package/dist/cjs/experimental/types.js.map +1 -1
  24. package/dist/cjs/graphql/generated/queries.d.ts +16 -0
  25. package/dist/cjs/graphql/generated/queries.js +12 -0
  26. package/dist/cjs/graphql/generated/queries.js.map +2 -2
  27. package/dist/cjs/transactions/ObjectCache.d.ts +1 -1
  28. package/dist/cjs/transactions/ObjectCache.js.map +1 -1
  29. package/dist/cjs/transactions/Transaction.d.ts +1 -1
  30. package/dist/cjs/transactions/Transaction.js +2 -2
  31. package/dist/cjs/transactions/Transaction.js.map +2 -2
  32. package/dist/cjs/transactions/executor/caching.d.ts +1 -1
  33. package/dist/cjs/transactions/executor/caching.js.map +1 -1
  34. package/dist/cjs/transactions/index.d.ts +1 -1
  35. package/dist/cjs/transactions/index.js.map +1 -1
  36. package/dist/cjs/transactions/intents/CoinWithBalance.d.ts +3 -0
  37. package/dist/cjs/transactions/intents/CoinWithBalance.js +11 -3
  38. package/dist/cjs/transactions/intents/CoinWithBalance.js.map +2 -2
  39. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.d.ts +1 -1
  40. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +1 -1
  41. package/dist/cjs/transactions/{json-rpc-resolver.d.ts → resolve.d.ts} +5 -4
  42. package/dist/cjs/transactions/resolve.js +97 -0
  43. package/dist/cjs/transactions/resolve.js.map +7 -0
  44. package/dist/cjs/verify/verify.d.ts +2 -0
  45. package/dist/cjs/verify/verify.js +17 -6
  46. package/dist/cjs/verify/verify.js.map +2 -2
  47. package/dist/cjs/version.d.ts +2 -2
  48. package/dist/cjs/version.js +2 -2
  49. package/dist/cjs/version.js.map +1 -1
  50. package/dist/cjs/zklogin/index.d.ts +1 -1
  51. package/dist/cjs/zklogin/index.js.map +2 -2
  52. package/dist/cjs/zklogin/publickey.d.ts +5 -0
  53. package/dist/cjs/zklogin/publickey.js +33 -0
  54. package/dist/cjs/zklogin/publickey.js.map +2 -2
  55. package/dist/esm/cryptography/keypair.d.ts +9 -0
  56. package/dist/esm/cryptography/keypair.js +13 -0
  57. package/dist/esm/cryptography/keypair.js.map +2 -2
  58. package/dist/esm/experimental/core.d.ts +6 -1
  59. package/dist/esm/experimental/core.js.map +2 -2
  60. package/dist/esm/experimental/index.d.ts +3 -1
  61. package/dist/esm/experimental/index.js +4 -1
  62. package/dist/esm/experimental/index.js.map +2 -2
  63. package/dist/esm/experimental/transports/graphql.d.ts +1 -0
  64. package/dist/esm/experimental/transports/graphql.js +8 -6
  65. package/dist/esm/experimental/transports/graphql.js.map +2 -2
  66. package/dist/esm/experimental/transports/json-rpc-resolver.d.ts +4 -0
  67. package/dist/esm/{transactions → experimental/transports}/json-rpc-resolver.js +29 -66
  68. package/dist/esm/experimental/transports/json-rpc-resolver.js.map +7 -0
  69. package/dist/esm/experimental/transports/jsonRPC.d.ts +5 -1
  70. package/dist/esm/experimental/transports/jsonRPC.js +69 -51
  71. package/dist/esm/experimental/transports/jsonRPC.js.map +2 -2
  72. package/dist/esm/experimental/transports/utils.d.ts +2 -5
  73. package/dist/esm/experimental/transports/utils.js +15 -16
  74. package/dist/esm/experimental/transports/utils.js.map +2 -2
  75. package/dist/esm/experimental/types.d.ts +7 -3
  76. package/dist/esm/graphql/generated/queries.d.ts +16 -0
  77. package/dist/esm/graphql/generated/queries.js +12 -0
  78. package/dist/esm/graphql/generated/queries.js.map +2 -2
  79. package/dist/esm/transactions/ObjectCache.d.ts +1 -1
  80. package/dist/esm/transactions/ObjectCache.js.map +1 -1
  81. package/dist/esm/transactions/Transaction.d.ts +1 -1
  82. package/dist/esm/transactions/Transaction.js +2 -2
  83. package/dist/esm/transactions/Transaction.js.map +2 -2
  84. package/dist/esm/transactions/executor/caching.d.ts +1 -1
  85. package/dist/esm/transactions/executor/caching.js.map +1 -1
  86. package/dist/esm/transactions/index.d.ts +1 -1
  87. package/dist/esm/transactions/index.js.map +1 -1
  88. package/dist/esm/transactions/intents/CoinWithBalance.d.ts +3 -0
  89. package/dist/esm/transactions/intents/CoinWithBalance.js +11 -3
  90. package/dist/esm/transactions/intents/CoinWithBalance.js.map +2 -2
  91. package/dist/esm/transactions/plugins/NamedPackagesPlugin.d.ts +1 -1
  92. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +1 -1
  93. package/dist/esm/transactions/{json-rpc-resolver.d.ts → resolve.d.ts} +5 -4
  94. package/dist/esm/transactions/resolve.js +77 -0
  95. package/dist/esm/transactions/resolve.js.map +7 -0
  96. package/dist/esm/verify/verify.d.ts +2 -0
  97. package/dist/esm/verify/verify.js +17 -6
  98. package/dist/esm/verify/verify.js.map +2 -2
  99. package/dist/esm/version.d.ts +2 -2
  100. package/dist/esm/version.js +2 -2
  101. package/dist/esm/version.js.map +1 -1
  102. package/dist/esm/zklogin/index.d.ts +1 -1
  103. package/dist/esm/zklogin/index.js +4 -1
  104. package/dist/esm/zklogin/index.js.map +2 -2
  105. package/dist/esm/zklogin/publickey.d.ts +5 -0
  106. package/dist/esm/zklogin/publickey.js +33 -0
  107. package/dist/esm/zklogin/publickey.js.map +2 -2
  108. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  109. package/dist/tsconfig.tsbuildinfo +1 -1
  110. package/package.json +1 -1
  111. package/src/cryptography/keypair.ts +25 -0
  112. package/src/experimental/core.ts +8 -1
  113. package/src/experimental/index.ts +3 -0
  114. package/src/experimental/transports/graphql.ts +9 -6
  115. package/src/{transactions → experimental/transports}/json-rpc-resolver.ts +37 -115
  116. package/src/experimental/transports/jsonRPC.ts +73 -49
  117. package/src/experimental/transports/utils.ts +15 -20
  118. package/src/experimental/types.ts +10 -6
  119. package/src/graphql/generated/queries.ts +16 -4
  120. package/src/graphql/queries/transactions.graphql +3 -0
  121. package/src/transactions/ObjectCache.ts +1 -1
  122. package/src/transactions/Transaction.ts +3 -3
  123. package/src/transactions/executor/caching.ts +1 -1
  124. package/src/transactions/index.ts +1 -1
  125. package/src/transactions/intents/CoinWithBalance.ts +12 -3
  126. package/src/transactions/plugins/NamedPackagesPlugin.ts +1 -1
  127. package/src/transactions/resolve.ts +120 -0
  128. package/src/verify/verify.ts +21 -8
  129. package/src/version.ts +2 -2
  130. package/src/zklogin/index.ts +5 -1
  131. package/src/zklogin/publickey.ts +41 -0
  132. package/dist/cjs/transactions/json-rpc-resolver.js.map +0 -7
  133. package/dist/esm/transactions/json-rpc-resolver.js.map +0 -7
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.29.1",
6
+ "version": "1.30.1",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [
@@ -11,12 +11,16 @@ import type { PublicKey } from './publickey.js';
11
11
  import { SIGNATURE_FLAG_TO_SCHEME, SIGNATURE_SCHEME_TO_FLAG } from './signature-scheme.js';
12
12
  import type { SignatureScheme } from './signature-scheme.js';
13
13
  import { toSerializedSignature } from './signature.js';
14
+ import type { Transaction } from '../transactions/Transaction.js';
15
+ import type { ClientWithCoreApi, Experimental_SuiClientTypes } from '../experimental/index.js';
14
16
 
15
17
  export const PRIVATE_KEY_SIZE = 32;
16
18
  export const LEGACY_PRIVATE_KEY_SIZE = 64;
17
19
  export const SUI_PRIVATE_KEY_PREFIX = 'suiprivkey';
18
20
 
19
21
  export type ParsedKeypair = {
22
+ scheme: SignatureScheme;
23
+ /** @deprecated use `scheme` instead */
20
24
  schema: SignatureScheme;
21
25
  secretKey: Uint8Array;
22
26
  };
@@ -26,6 +30,11 @@ export interface SignatureWithBytes {
26
30
  signature: string;
27
31
  }
28
32
 
33
+ export interface SignAndExecuteOptions {
34
+ transaction: Transaction;
35
+ client: ClientWithCoreApi;
36
+ }
37
+
29
38
  /**
30
39
  * TODO: Document
31
40
  */
@@ -71,6 +80,20 @@ export abstract class Signer {
71
80
  };
72
81
  }
73
82
 
83
+ async signAndExecuteTransaction({
84
+ transaction,
85
+ client,
86
+ }: SignAndExecuteOptions): Promise<Experimental_SuiClientTypes.TransactionResponse> {
87
+ const bytes = await transaction.build({ client });
88
+ const { signature } = await this.signTransaction(bytes);
89
+ const response = await client.core.executeTransaction({
90
+ transaction: bytes,
91
+ signatures: [signature],
92
+ });
93
+
94
+ return response.transaction;
95
+ }
96
+
74
97
  toSuiAddress(): string {
75
98
  return this.getPublicKey().toSuiAddress();
76
99
  }
@@ -107,7 +130,9 @@ export function decodeSuiPrivateKey(value: string): ParsedKeypair {
107
130
  const secretKey = extendedSecretKey.slice(1);
108
131
  const signatureScheme =
109
132
  SIGNATURE_FLAG_TO_SCHEME[extendedSecretKey[0] as keyof typeof SIGNATURE_FLAG_TO_SCHEME];
133
+
110
134
  return {
135
+ scheme: signatureScheme,
111
136
  schema: signatureScheme,
112
137
  secretKey: secretKey,
113
138
  };
@@ -2,10 +2,15 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { TypeTagSerializer } from '../bcs/type-tag-serializer.js';
5
+ import type { TransactionPlugin } from '../transactions/index.js';
5
6
  import { deriveDynamicFieldID } from '../utils/dynamic-fields.js';
6
7
  import { normalizeStructTag, parseStructTag, SUI_ADDRESS_LENGTH } from '../utils/sui-types.js';
7
8
  import { Experimental_BaseClient } from './client.js';
8
- import type { Experimental_SuiClientTypes } from './types.js';
9
+ import type { ClientWithExtensions, Experimental_SuiClientTypes } from './types.js';
10
+
11
+ export type ClientWithCoreApi = ClientWithExtensions<{
12
+ core: Experimental_CoreClient;
13
+ }>;
9
14
 
10
15
  export abstract class Experimental_CoreClient
11
16
  extends Experimental_BaseClient
@@ -66,6 +71,8 @@ export abstract class Experimental_CoreClient
66
71
  options: Experimental_SuiClientTypes.GetDynamicFieldsOptions,
67
72
  ): Promise<Experimental_SuiClientTypes.GetDynamicFieldsResponse>;
68
73
 
74
+ abstract resolveTransactionPlugin(): TransactionPlugin;
75
+
69
76
  async getDynamicField(
70
77
  options: Experimental_SuiClientTypes.GetDynamicFieldOptions,
71
78
  ): Promise<Experimental_SuiClientTypes.GetDynamicFieldResponse> {
@@ -2,12 +2,14 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Experimental_BaseClient } from './client.js';
5
+ import type { ClientWithCoreApi } from './core.js';
5
6
  import { Experimental_CoreClient } from './core.js';
6
7
  import type {
7
8
  ClientWithExtensions,
8
9
  Experimental_SuiClientTypes,
9
10
  SuiClientRegistration,
10
11
  } from './types.js';
12
+ export { parseTransactionBcs, parseTransactionEffectsBcs } from './transports/utils.js';
11
13
 
12
14
  export {
13
15
  Experimental_BaseClient,
@@ -15,6 +17,7 @@ export {
15
17
  type ClientWithExtensions,
16
18
  type Experimental_SuiClientTypes,
17
19
  type SuiClientRegistration,
20
+ type ClientWithCoreApi,
18
21
  };
19
22
 
20
23
  export { ClientCache, type ClientCacheOptions } from './cache.js';
@@ -27,7 +27,7 @@ import { ObjectError } from '../errors.js';
27
27
  import { fromBase64, toBase64 } from '@mysten/utils';
28
28
  import { normalizeStructTag, normalizeSuiAddress } from '../../utils/sui-types.js';
29
29
  import { deriveDynamicFieldID } from '../../utils/dynamic-fields.js';
30
- import { parseTransactionEffects } from './utils.js';
30
+ import { parseTransactionBcs, parseTransactionEffectsBcs } from './utils.js';
31
31
 
32
32
  export class GraphQLTransport extends Experimental_CoreClient {
33
33
  #graphqlClient: SuiGraphQLClient;
@@ -339,6 +339,10 @@ export class GraphQLTransport extends Experimental_CoreClient {
339
339
  errors: result.errors,
340
340
  };
341
341
  }
342
+
343
+ resolveTransactionPlugin(): never {
344
+ throw new Error('GraphQL client does not support transaction resolution yet');
345
+ }
342
346
  }
343
347
  export type GraphQLResponseErrors = Array<{
344
348
  message: string;
@@ -411,11 +415,10 @@ function parseTransaction(
411
415
 
412
416
  return {
413
417
  digest: transaction.digest!,
414
- effects: parseTransactionEffects({
415
- effects: new Uint8Array(transaction.effects?.bcs!),
416
- objectTypes,
417
- }),
418
- bcs: transaction.bcs!,
418
+ effects: parseTransactionEffectsBcs(new Uint8Array(transaction.effects?.bcs!)),
419
+ epoch: transaction.effects?.epoch?.epochId ?? null,
420
+ objectTypes: Promise.resolve(objectTypes),
421
+ transaction: parseTransactionBcs(transaction.bcs!),
419
422
  signatures: transaction.signatures!,
420
423
  };
421
424
  }
@@ -3,16 +3,19 @@
3
3
 
4
4
  import { parse } from 'valibot';
5
5
 
6
- import type { BcsType } from '../bcs/index.js';
7
- import { bcs } from '../bcs/index.js';
8
- import type { SuiClient } from '../client/client.js';
9
- import { normalizeSuiAddress, normalizeSuiObjectId, SUI_TYPE_ARG } from '../utils/index.js';
10
- import { ObjectRef } from './data/internal.js';
11
- import type { Argument, CallArg, Command, OpenMoveTypeSignature } from './data/internal.js';
12
- import { Inputs } from './Inputs.js';
13
- import { getPureBcsSchema, isTxContext, normalizedTypeToMoveTypeSignature } from './serializer.js';
14
- import type { TransactionDataBuilder } from './TransactionData.js';
6
+ import { normalizeSuiAddress, normalizeSuiObjectId, SUI_TYPE_ARG } from '../../utils/index.js';
7
+ import { ObjectRef } from '../../transactions/data/internal.js';
8
+ import type { CallArg, Command, OpenMoveTypeSignature } from '../../transactions/data/internal.js';
9
+ import { Inputs } from '../../transactions/Inputs.js';
10
+ import {
11
+ getPureBcsSchema,
12
+ isTxContext,
13
+ normalizedTypeToMoveTypeSignature,
14
+ } from '../../transactions/serializer.js';
15
+ import type { TransactionDataBuilder } from '../../transactions/TransactionData.js';
15
16
  import { chunk } from '@mysten/utils';
17
+ import type { SuiClient } from '../../client/index.js';
18
+ import type { BuildTransactionOptions } from '../../transactions/index.js';
16
19
 
17
20
  // The maximum objects that can be fetched at once using multiGetObjects.
18
21
  const MAX_OBJECTS_PER_FETCH = 50;
@@ -21,56 +24,37 @@ const MAX_OBJECTS_PER_FETCH = 50;
21
24
  const GAS_SAFE_OVERHEAD = 1000n;
22
25
  const MAX_GAS = 50_000_000_000;
23
26
 
24
- export interface BuildTransactionOptions {
25
- client?: SuiClient;
26
- onlyTransactionKind?: boolean;
27
- }
27
+ export function resolveTransactionPlugin(client: SuiClient) {
28
+ return async function resolveTransactionData(
29
+ transactionData: TransactionDataBuilder,
30
+ options: BuildTransactionOptions,
31
+ next: () => Promise<void>,
32
+ ) {
33
+ await normalizeInputs(transactionData, client);
34
+ await resolveObjectReferences(transactionData, client);
35
+
36
+ if (!options.onlyTransactionKind) {
37
+ await setGasPrice(transactionData, client);
38
+ await setGasBudget(transactionData, client);
39
+ await setGasPayment(transactionData, client);
40
+ }
28
41
 
29
- export interface SerializeTransactionOptions extends BuildTransactionOptions {
30
- supportedIntents?: string[];
42
+ return await next();
43
+ };
31
44
  }
32
45
 
33
- export type TransactionPlugin = (
34
- transactionData: TransactionDataBuilder,
35
- options: BuildTransactionOptions,
36
- next: () => Promise<void>,
37
- ) => Promise<void>;
38
-
39
- export async function resolveTransactionData(
40
- transactionData: TransactionDataBuilder,
41
- options: BuildTransactionOptions,
42
- next: () => Promise<void>,
43
- ) {
44
- await normalizeInputs(transactionData, options);
45
- await resolveObjectReferences(transactionData, options);
46
-
47
- if (!options.onlyTransactionKind) {
48
- await setGasPrice(transactionData, options);
49
- await setGasBudget(transactionData, options);
50
- await setGasPayment(transactionData, options);
51
- }
52
- await validate(transactionData);
53
- return await next();
54
- }
55
-
56
- async function setGasPrice(
57
- transactionData: TransactionDataBuilder,
58
- options: BuildTransactionOptions,
59
- ) {
46
+ async function setGasPrice(transactionData: TransactionDataBuilder, client: SuiClient) {
60
47
  if (!transactionData.gasConfig.price) {
61
- transactionData.gasConfig.price = String(await getClient(options).getReferenceGasPrice());
48
+ transactionData.gasConfig.price = String(await client.getReferenceGasPrice());
62
49
  }
63
50
  }
64
51
 
65
- async function setGasBudget(
66
- transactionData: TransactionDataBuilder,
67
- options: BuildTransactionOptions,
68
- ) {
52
+ async function setGasBudget(transactionData: TransactionDataBuilder, client: SuiClient) {
69
53
  if (transactionData.gasConfig.budget) {
70
54
  return;
71
55
  }
72
56
 
73
- const dryRunResult = await getClient(options).dryRunTransactionBlock({
57
+ const dryRunResult = await client.dryRunTransactionBlock({
74
58
  transactionBlock: transactionData.build({
75
59
  overrides: {
76
60
  gasData: {
@@ -104,12 +88,9 @@ async function setGasBudget(
104
88
  }
105
89
 
106
90
  // The current default is just picking _all_ coins we can which may not be ideal.
107
- async function setGasPayment(
108
- transactionData: TransactionDataBuilder,
109
- options: BuildTransactionOptions,
110
- ) {
91
+ async function setGasPayment(transactionData: TransactionDataBuilder, client: SuiClient) {
111
92
  if (!transactionData.gasConfig.payment) {
112
- const coins = await getClient(options).getCoins({
93
+ const coins = await client.getCoins({
113
94
  owner: transactionData.gasConfig.owner || transactionData.sender!,
114
95
  coinType: SUI_TYPE_ARG,
115
96
  });
@@ -141,10 +122,7 @@ async function setGasPayment(
141
122
  }
142
123
  }
143
124
 
144
- async function resolveObjectReferences(
145
- transactionData: TransactionDataBuilder,
146
- options: BuildTransactionOptions,
147
- ) {
125
+ async function resolveObjectReferences(transactionData: TransactionDataBuilder, client: SuiClient) {
148
126
  // Keep track of the object references that will need to be resolved at the end of the transaction.
149
127
  // We keep the input by-reference to avoid needing to re-resolve it:
150
128
  const objectsToResolve = transactionData.inputs.filter((input) => {
@@ -164,7 +142,7 @@ async function resolveObjectReferences(
164
142
  const resolved = (
165
143
  await Promise.all(
166
144
  objectChunks.map((chunk) =>
167
- getClient(options).multiGetObjects({
145
+ client.multiGetObjects({
168
146
  ids: chunk,
169
147
  options: { showOwner: true },
170
148
  }),
@@ -246,10 +224,7 @@ async function resolveObjectReferences(
246
224
  }
247
225
  }
248
226
 
249
- async function normalizeInputs(
250
- transactionData: TransactionDataBuilder,
251
- options: BuildTransactionOptions,
252
- ) {
227
+ async function normalizeInputs(transactionData: TransactionDataBuilder, client: SuiClient) {
253
228
  const { inputs, commands } = transactionData;
254
229
  const moveCallsToResolve: Extract<Command, { MoveCall: unknown }>['MoveCall'][] = [];
255
230
  const moveFunctionsToResolve = new Set<string>();
@@ -282,24 +257,10 @@ async function normalizeInputs(
282
257
  moveCallsToResolve.push(command.MoveCall);
283
258
  }
284
259
  }
285
-
286
- // Special handling for values that where previously encoded using the wellKnownEncoding pattern.
287
- // This should only happen when transaction data was hydrated from an old version of the SDK
288
- switch (command.$kind) {
289
- case 'SplitCoins':
290
- command.SplitCoins.amounts.forEach((amount) => {
291
- normalizeRawArgument(amount, bcs.U64, transactionData);
292
- });
293
- break;
294
- case 'TransferObjects':
295
- normalizeRawArgument(command.TransferObjects.address, bcs.Address, transactionData);
296
- break;
297
- }
298
260
  });
299
261
 
300
262
  const moveFunctionParameters = new Map<string, OpenMoveTypeSignature[]>();
301
263
  if (moveFunctionsToResolve.size > 0) {
302
- const client = getClient(options);
303
264
  await Promise.all(
304
265
  [...moveFunctionsToResolve].map(async (functionName) => {
305
266
  const [packageId, moduleId, functionId] = functionName.split('::');
@@ -400,35 +361,6 @@ async function normalizeInputs(
400
361
  });
401
362
  }
402
363
 
403
- function validate(transactionData: TransactionDataBuilder) {
404
- transactionData.inputs.forEach((input, index) => {
405
- if (input.$kind !== 'Object' && input.$kind !== 'Pure') {
406
- throw new Error(
407
- `Input at index ${index} has not been resolved. Expected a Pure or Object input, but found ${JSON.stringify(
408
- input,
409
- )}`,
410
- );
411
- }
412
- });
413
- }
414
-
415
- function normalizeRawArgument(
416
- arg: Argument,
417
- schema: BcsType<any>,
418
- transactionData: TransactionDataBuilder,
419
- ) {
420
- if (arg.$kind !== 'Input') {
421
- return;
422
- }
423
- const input = transactionData.inputs[arg.Input];
424
-
425
- if (input.$kind !== 'UnresolvedPure') {
426
- return;
427
- }
428
-
429
- transactionData.inputs[arg.Input] = Inputs.Pure(schema.serialize(input.UnresolvedPure.value));
430
- }
431
-
432
364
  function isUsedAsMutable(transactionData: TransactionDataBuilder, index: number) {
433
365
  let usedAsMutable = false;
434
366
 
@@ -470,13 +402,3 @@ function isReceivingType(type: OpenMoveTypeSignature): boolean {
470
402
  type.body.datatype.type === 'Receiving'
471
403
  );
472
404
  }
473
-
474
- export function getClient(options: BuildTransactionOptions): SuiClient {
475
- if (!options.client) {
476
- throw new Error(
477
- `No sui client passed to Transaction#build, but transaction data was not sufficient to build offline.`,
478
- );
479
- }
480
-
481
- return options.client;
482
- }
@@ -14,11 +14,12 @@ import type {
14
14
  } from '../../client/index.js';
15
15
  import { batch } from '../../transactions/plugins/utils.js';
16
16
  import { Transaction } from '../../transactions/Transaction.js';
17
- import { normalizeStructTag } from '../../utils/sui-types.js';
18
17
  import { Experimental_CoreClient } from '../core.js';
19
18
  import { ObjectError } from '../errors.js';
20
19
  import type { Experimental_SuiClientTypes } from '../types.js';
21
- import { parseTransactionEffects } from './utils.js';
20
+ import { parseTransactionBcs, parseTransactionEffectsBcs } from './utils.js';
21
+ import { resolveTransactionPlugin } from './json-rpc-resolver.js';
22
+ import { TransactionDataBuilder } from '../../transactions/TransactionData.js';
22
23
 
23
24
  export class JSONRpcTransport extends Experimental_CoreClient {
24
25
  #jsonRpcClient: SuiClient;
@@ -185,15 +186,19 @@ export class JSONRpcTransport extends Experimental_CoreClient {
185
186
  signal: options.signal,
186
187
  });
187
188
 
189
+ const { effects, objectTypes } = parseTransactionEffectsJson({
190
+ effects: result.effects,
191
+ objectChanges: result.objectChanges,
192
+ });
193
+
188
194
  return {
189
195
  transaction: {
190
196
  digest: await tx.getDigest(),
191
- effects: parseTransactionEffectsJson({
192
- effects: result.effects,
193
- objectChanges: result.objectChanges,
194
- }),
197
+ epoch: null,
198
+ effects,
199
+ objectTypes: Promise.resolve(objectTypes),
195
200
  signatures: [],
196
- bcs: options.transaction,
201
+ transaction: parseTransactionBcs(options.transaction),
197
202
  },
198
203
  };
199
204
  }
@@ -242,6 +247,10 @@ export class JSONRpcTransport extends Experimental_CoreClient {
242
247
  errors: result.errors,
243
248
  };
244
249
  }
250
+
251
+ resolveTransactionPlugin() {
252
+ return resolveTransactionPlugin(this.#jsonRpcClient);
253
+ }
245
254
  }
246
255
 
247
256
  function parseObject(object: SuiObjectData): Experimental_SuiClientTypes.ObjectResponse {
@@ -315,13 +324,26 @@ function parseTransaction(
315
324
  }
316
325
  });
317
326
 
327
+ const bytes = bcs.TransactionData.serialize(parsedTx.intentMessage.value).toBytes();
328
+
329
+ const data = TransactionDataBuilder.restore({
330
+ version: 2,
331
+ sender: parsedTx.intentMessage.value.V1.sender,
332
+ expiration: parsedTx.intentMessage.value.V1.expiration,
333
+ gasData: parsedTx.intentMessage.value.V1.gasData,
334
+ inputs: parsedTx.intentMessage.value.V1.kind.ProgrammableTransaction!.inputs,
335
+ commands: parsedTx.intentMessage.value.V1.kind.ProgrammableTransaction!.commands,
336
+ });
337
+
318
338
  return {
319
339
  digest: transaction.digest,
320
- effects: parseTransactionEffects({
321
- effects: new Uint8Array(transaction.rawEffects!),
322
- objectTypes,
323
- }),
324
- bcs: bcs.TransactionData.serialize(parsedTx.intentMessage.value).toBytes(),
340
+ epoch: transaction.effects?.executedEpoch ?? null,
341
+ effects: parseTransactionEffectsBcs(new Uint8Array(transaction.rawEffects!)),
342
+ objectTypes: Promise.resolve(objectTypes),
343
+ transaction: {
344
+ ...data,
345
+ bcs: bytes,
346
+ },
325
347
  signatures: parsedTx.txSignatures,
326
348
  };
327
349
  }
@@ -329,16 +351,18 @@ function parseTransaction(
329
351
  function parseTransactionEffectsJson({
330
352
  bytes,
331
353
  effects,
332
- epoch,
333
354
  objectChanges,
334
355
  }: {
335
356
  bytes?: Uint8Array;
336
357
  effects: TransactionEffects;
337
- epoch?: string | null;
338
358
  objectChanges: SuiObjectChange[] | null;
339
- }): Experimental_SuiClientTypes.TransactionEffects {
359
+ }): {
360
+ effects: Experimental_SuiClientTypes.TransactionEffects;
361
+ objectTypes: Record<string, string>;
362
+ } {
340
363
  const changedObjects: Experimental_SuiClientTypes.ChangedObject[] = [];
341
364
  const unchangedSharedObjects: Experimental_SuiClientTypes.UnchangedSharedObject[] = [];
365
+ const objectTypes: Record<string, string> = {};
342
366
 
343
367
  objectChanges?.forEach((change) => {
344
368
  switch (change.type) {
@@ -354,7 +378,6 @@ function parseTransactionEffectsJson({
354
378
  outputDigest: change.digest,
355
379
  outputOwner: null,
356
380
  idOperation: 'Created',
357
- objectType: null,
358
381
  });
359
382
  break;
360
383
  case 'transferred':
@@ -372,8 +395,8 @@ function parseTransactionEffectsJson({
372
395
  outputDigest: change.digest,
373
396
  outputOwner: parseOwner(change.recipient),
374
397
  idOperation: 'None',
375
- objectType: change.objectType,
376
398
  });
399
+ objectTypes[change.objectId] = change.objectType;
377
400
  break;
378
401
  case 'mutated':
379
402
  changedObjects.push({
@@ -387,8 +410,8 @@ function parseTransactionEffectsJson({
387
410
  outputDigest: change.digest,
388
411
  outputOwner: parseOwner(change.owner),
389
412
  idOperation: 'None',
390
- objectType: change.objectType,
391
413
  });
414
+ objectTypes[change.objectId] = change.objectType;
392
415
  break;
393
416
  case 'deleted':
394
417
  changedObjects.push({
@@ -402,8 +425,8 @@ function parseTransactionEffectsJson({
402
425
  outputDigest: null,
403
426
  outputOwner: null,
404
427
  idOperation: 'Deleted',
405
- objectType: change.objectType,
406
428
  });
429
+ objectTypes[change.objectId] = change.objectType;
407
430
  break;
408
431
  case 'wrapped':
409
432
  changedObjects.push({
@@ -424,8 +447,8 @@ function parseTransactionEffectsJson({
424
447
  ObjectOwner: change.sender,
425
448
  },
426
449
  idOperation: 'None',
427
- objectType: change.objectType,
428
450
  });
451
+ objectTypes[change.objectId] = change.objectType;
429
452
  break;
430
453
  case 'created':
431
454
  changedObjects.push({
@@ -439,42 +462,43 @@ function parseTransactionEffectsJson({
439
462
  outputDigest: change.digest,
440
463
  outputOwner: parseOwner(change.owner),
441
464
  idOperation: 'Created',
442
- objectType: change.objectType,
443
465
  });
466
+ objectTypes[change.objectId] = change.objectType;
444
467
  break;
445
468
  }
446
469
  });
447
470
 
448
471
  return {
449
- bcs: bytes ?? null,
450
- digest: effects.transactionDigest,
451
- version: 2,
452
- status:
453
- effects.status.status === 'success'
454
- ? { success: true, error: null }
455
- : { success: false, error: effects.status.error! },
456
- epoch: epoch ?? null,
457
- gasUsed: effects.gasUsed,
458
- transactionDigest: effects.transactionDigest,
459
- gasObject: {
460
- id: effects.gasObject?.reference.objectId,
461
- inputState: 'Exists',
462
- inputVersion: null,
463
- inputDigest: null,
464
- inputOwner: null,
465
- outputState: 'ObjectWrite',
466
- outputVersion: effects.gasObject.reference.version,
467
- outputDigest: effects.gasObject.reference.digest,
468
- outputOwner: parseOwner(effects.gasObject.owner),
469
- idOperation: 'None',
470
- objectType: normalizeStructTag('0x2::coin::Coin<0x2::sui::SUI>'),
472
+ objectTypes,
473
+ effects: {
474
+ bcs: bytes ?? null,
475
+ digest: effects.transactionDigest,
476
+ version: 2,
477
+ status:
478
+ effects.status.status === 'success'
479
+ ? { success: true, error: null }
480
+ : { success: false, error: effects.status.error! },
481
+ gasUsed: effects.gasUsed,
482
+ transactionDigest: effects.transactionDigest,
483
+ gasObject: {
484
+ id: effects.gasObject?.reference.objectId,
485
+ inputState: 'Exists',
486
+ inputVersion: null,
487
+ inputDigest: null,
488
+ inputOwner: null,
489
+ outputState: 'ObjectWrite',
490
+ outputVersion: effects.gasObject.reference.version,
491
+ outputDigest: effects.gasObject.reference.digest,
492
+ outputOwner: parseOwner(effects.gasObject.owner),
493
+ idOperation: 'None',
494
+ },
495
+ eventsDigest: effects.eventsDigest ?? null,
496
+ dependencies: effects.dependencies ?? [],
497
+ lamportVersion: effects.gasObject.reference.version,
498
+ changedObjects,
499
+ unchangedSharedObjects,
500
+ auxiliaryDataDigest: null,
471
501
  },
472
- eventsDigest: effects.eventsDigest ?? null,
473
- dependencies: effects.dependencies ?? [],
474
- lamportVersion: effects.gasObject.reference.version,
475
- changedObjects,
476
- unchangedSharedObjects,
477
- auxiliaryDataDigest: null,
478
502
  };
479
503
  }
480
504