@mysten/sui 1.24.0 → 1.26.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 (98) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/client/client.d.ts +12 -2
  3. package/dist/cjs/client/client.js +16 -4
  4. package/dist/cjs/client/client.js.map +2 -2
  5. package/dist/cjs/experimental/client.d.ts +8 -0
  6. package/dist/cjs/experimental/client.js +43 -0
  7. package/dist/cjs/experimental/client.js.map +7 -0
  8. package/dist/cjs/experimental/core.d.ts +14 -0
  9. package/dist/cjs/experimental/core.js +31 -0
  10. package/dist/cjs/experimental/core.js.map +7 -0
  11. package/dist/cjs/experimental/errors.d.ts +8 -0
  12. package/dist/cjs/experimental/errors.js +54 -0
  13. package/dist/cjs/experimental/errors.js.map +7 -0
  14. package/dist/cjs/experimental/transports/jsonRPC.d.ts +62 -0
  15. package/dist/cjs/experimental/transports/jsonRPC.js +255 -0
  16. package/dist/cjs/experimental/transports/jsonRPC.js.map +7 -0
  17. package/dist/cjs/experimental/types.d.ts +211 -0
  18. package/dist/cjs/experimental/types.js +17 -0
  19. package/dist/cjs/experimental/types.js.map +7 -0
  20. package/dist/cjs/transactions/Arguments.d.ts +2 -2
  21. package/dist/cjs/transactions/Transaction.d.ts +4 -4
  22. package/dist/cjs/transactions/TransactionData.d.ts +2 -2
  23. package/dist/cjs/transactions/data/v1.d.ts +4 -4
  24. package/dist/cjs/transactions/data/v2.d.ts +4 -4
  25. package/dist/cjs/transactions/executor/parallel.d.ts +1 -1
  26. package/dist/cjs/transactions/executor/parallel.js +4 -4
  27. package/dist/cjs/transactions/executor/parallel.js.map +2 -2
  28. package/dist/cjs/transactions/executor/serial.d.ts +1 -1
  29. package/dist/cjs/transactions/executor/serial.js +2 -2
  30. package/dist/cjs/transactions/executor/serial.js.map +2 -2
  31. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
  32. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +84 -43
  33. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
  34. package/dist/cjs/transactions/plugins/utils.d.ts +10 -6
  35. package/dist/cjs/transactions/plugins/utils.js +64 -37
  36. package/dist/cjs/transactions/plugins/utils.js.map +2 -2
  37. package/dist/cjs/utils/sui-types.d.ts +1 -2
  38. package/dist/cjs/utils/sui-types.js +3 -1
  39. package/dist/cjs/utils/sui-types.js.map +2 -2
  40. package/dist/cjs/version.d.ts +2 -2
  41. package/dist/cjs/version.js +2 -2
  42. package/dist/cjs/version.js.map +1 -1
  43. package/dist/esm/client/client.d.ts +12 -2
  44. package/dist/esm/client/client.js +16 -4
  45. package/dist/esm/client/client.js.map +2 -2
  46. package/dist/esm/experimental/client.d.ts +8 -0
  47. package/dist/esm/experimental/client.js +23 -0
  48. package/dist/esm/experimental/client.js.map +7 -0
  49. package/dist/esm/experimental/core.d.ts +14 -0
  50. package/dist/esm/experimental/core.js +11 -0
  51. package/dist/esm/experimental/core.js.map +7 -0
  52. package/dist/esm/experimental/errors.d.ts +8 -0
  53. package/dist/esm/experimental/errors.js +34 -0
  54. package/dist/esm/experimental/errors.js.map +7 -0
  55. package/dist/esm/experimental/transports/jsonRPC.d.ts +62 -0
  56. package/dist/esm/experimental/transports/jsonRPC.js +235 -0
  57. package/dist/esm/experimental/transports/jsonRPC.js.map +7 -0
  58. package/dist/esm/experimental/types.d.ts +211 -0
  59. package/dist/esm/experimental/types.js +1 -0
  60. package/dist/esm/experimental/types.js.map +7 -0
  61. package/dist/esm/transactions/Arguments.d.ts +2 -2
  62. package/dist/esm/transactions/Transaction.d.ts +4 -4
  63. package/dist/esm/transactions/TransactionData.d.ts +2 -2
  64. package/dist/esm/transactions/data/v1.d.ts +4 -4
  65. package/dist/esm/transactions/data/v2.d.ts +4 -4
  66. package/dist/esm/transactions/executor/parallel.d.ts +1 -1
  67. package/dist/esm/transactions/executor/parallel.js +4 -4
  68. package/dist/esm/transactions/executor/parallel.js.map +2 -2
  69. package/dist/esm/transactions/executor/serial.d.ts +1 -1
  70. package/dist/esm/transactions/executor/serial.js +2 -2
  71. package/dist/esm/transactions/executor/serial.js.map +2 -2
  72. package/dist/esm/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
  73. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +91 -44
  74. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
  75. package/dist/esm/transactions/plugins/utils.d.ts +10 -6
  76. package/dist/esm/transactions/plugins/utils.js +64 -37
  77. package/dist/esm/transactions/plugins/utils.js.map +2 -2
  78. package/dist/esm/utils/sui-types.d.ts +1 -2
  79. package/dist/esm/utils/sui-types.js +3 -1
  80. package/dist/esm/utils/sui-types.js.map +2 -2
  81. package/dist/esm/version.d.ts +2 -2
  82. package/dist/esm/version.js +2 -2
  83. package/dist/esm/version.js.map +1 -1
  84. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -1
  87. package/src/client/client.ts +21 -2
  88. package/src/experimental/client.ts +61 -0
  89. package/src/experimental/core.ts +46 -0
  90. package/src/experimental/errors.ts +37 -0
  91. package/src/experimental/transports/jsonRPC.ts +263 -0
  92. package/src/experimental/types.ts +293 -0
  93. package/src/transactions/executor/parallel.ts +8 -3
  94. package/src/transactions/executor/serial.ts +2 -1
  95. package/src/transactions/plugins/NamedPackagesPlugin.ts +118 -62
  96. package/src/transactions/plugins/utils.ts +115 -47
  97. package/src/utils/sui-types.ts +6 -2
  98. package/src/version.ts +2 -2
@@ -2,6 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';
5
+ import { normalizeStructTag, parseStructTag } from '../../utils/sui-types.js';
6
+ import type { StructTag } from '../../utils/sui-types.js';
5
7
  import type { TransactionDataBuilder } from '../TransactionData.js';
6
8
 
7
9
  export type NamedPackagesPluginCache = {
@@ -21,9 +23,10 @@ export type NameResolutionRequest = {
21
23
  * Looks up all `.move` names in a transaction block.
22
24
  * Returns a list of all the names found.
23
25
  */
24
- export const findTransactionBlockNames = (
25
- builder: TransactionDataBuilder,
26
- ): { packages: string[]; types: string[] } => {
26
+ export function findNamesInTransaction(builder: TransactionDataBuilder): {
27
+ packages: string[];
28
+ types: string[];
29
+ } {
27
30
  const packages: Set<string> = new Set();
28
31
  const types: Set<string> = new Set();
29
32
 
@@ -40,7 +43,7 @@ export const findTransactionBlockNames = (
40
43
  if (!tx) continue;
41
44
 
42
45
  const pkg = tx.package.split('::')[0];
43
- if (pkg.includes(NAME_SEPARATOR)) {
46
+ if (hasMvrName(pkg)) {
44
47
  if (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);
45
48
  packages.add(pkg);
46
49
  }
@@ -54,32 +57,90 @@ export const findTransactionBlockNames = (
54
57
  packages: [...packages],
55
58
  types: [...types],
56
59
  };
57
- };
60
+ }
58
61
 
59
62
  /**
60
- * Returns a list of unique types that include a name
61
- * from the given list.
62
- * */
63
- function getNamesFromTypeList(types: string[]) {
64
- const names = new Set<string>();
63
+ * Extracts all first-level types from a list of types.
64
+ * E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,
65
+ * the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.
66
+ */
67
+ export function getFirstLevelNamedTypes(types: string[]) {
68
+ const results: Set<string> = new Set();
69
+
65
70
  for (const type of types) {
66
- if (type.includes(NAME_SEPARATOR)) {
67
- if (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);
68
- names.add(type);
69
- }
71
+ findMvrNames(type).forEach((name) => results.add(name));
72
+ }
73
+
74
+ return results;
75
+ }
76
+
77
+ /**
78
+ * Extracts all named types from a given type.
79
+ */
80
+ function findMvrNames(type: string | StructTag) {
81
+ const types: Set<string> = new Set();
82
+
83
+ if (typeof type === 'string' && !hasMvrName(type)) return types;
84
+
85
+ let tag = isStructTag(type) ? type : parseStructTag(type);
86
+
87
+ if (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);
88
+
89
+ for (const param of tag.typeParams) {
90
+ findMvrNames(param).forEach((name) => types.add(name));
70
91
  }
71
- return [...names];
92
+
93
+ return types;
94
+ }
95
+
96
+ // /**
97
+ // * Allows partial replacements of known types with their resolved equivalents.
98
+ // * E.g. `@mvr/demo::a::A<@mvr/demo::b::B>` can be resolved, if we already have
99
+ // * the address for `@mvr/demo::b::B` and the address for `@mvr/demo::a::A`,
100
+ // * without the need to have the full type in the cache.
101
+ // *
102
+ // * Returns the fully composed resolved types (if any) in a `named-type -> normalized-type` map.
103
+ // */
104
+ export function populateNamedTypesFromCache(types: string[], typeCache: Record<string, string>) {
105
+ const composedTypes: Record<string, string> = {};
106
+
107
+ types.forEach((type) => {
108
+ const normalized = normalizeStructTag(findAndReplaceCachedTypes(type, typeCache));
109
+ composedTypes[type] = normalized;
110
+ });
111
+
112
+ return composedTypes;
113
+ }
114
+
115
+ /**
116
+ * Traverses a type, and replaces any found names with their resolved equivalents,
117
+ * based on the supplied type cache.
118
+ */
119
+ function findAndReplaceCachedTypes(
120
+ tag: string | StructTag,
121
+ typeCache: Record<string, string>,
122
+ ): StructTag {
123
+ const type = isStructTag(tag) ? tag : parseStructTag(tag);
124
+
125
+ let typeTag = `${type.address}::${type.module}::${type.name}`;
126
+ const cacheHit = typeCache[typeTag];
127
+
128
+ return {
129
+ ...type,
130
+ address: cacheHit ? cacheHit.split('::')[0] : type.address,
131
+ typeParams: type.typeParams.map((param) => findAndReplaceCachedTypes(param, typeCache)),
132
+ };
72
133
  }
73
134
 
74
135
  /**
75
136
  * Replace all names & types in a transaction block
76
137
  * with their resolved names/types.
77
138
  */
78
- export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackagesPluginCache) => {
139
+ export function replaceNames(builder: TransactionDataBuilder, cache: NamedPackagesPluginCache) {
79
140
  for (const command of builder.commands) {
80
141
  // Replacements for `MakeMoveVec` commands (that can include types)
81
142
  if (command.MakeMoveVec?.type) {
82
- if (!command.MakeMoveVec.type.includes(NAME_SEPARATOR)) continue;
143
+ if (!hasMvrName(command.MakeMoveVec.type)) continue;
83
144
  if (!cache.types[command.MakeMoveVec.type])
84
145
  throw new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);
85
146
  command.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];
@@ -91,11 +152,11 @@ export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackag
91
152
  const nameParts = tx.package.split('::');
92
153
  const name = nameParts[0];
93
154
 
94
- if (name.includes(NAME_SEPARATOR) && !cache.packages[name])
155
+ if (hasMvrName(name) && !cache.packages[name])
95
156
  throw new Error(`No address found for package: ${name}`);
96
157
 
97
158
  // Replace package name with address.
98
- if (name.includes(NAME_SEPARATOR)) {
159
+ if (hasMvrName(name)) {
99
160
  nameParts[0] = cache.packages[name];
100
161
  tx.package = nameParts.join('::');
101
162
  }
@@ -104,7 +165,7 @@ export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackag
104
165
  if (!types) continue;
105
166
 
106
167
  for (let i = 0; i < types.length; i++) {
107
- if (!types[i].includes(NAME_SEPARATOR)) continue;
168
+ if (!hasMvrName(types[i])) continue;
108
169
 
109
170
  if (!cache.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);
110
171
  types[i] = cache.types[types[i]];
@@ -112,36 +173,43 @@ export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackag
112
173
 
113
174
  tx.typeArguments = types;
114
175
  }
115
- };
116
-
117
- export const listToRequests = (
118
- names: { packages: string[]; types: string[] },
119
- batchSize: number,
120
- ): NameResolutionRequest[][] => {
121
- const results: NameResolutionRequest[] = [];
122
- const uniqueNames = deduplicate(names.packages);
123
- const uniqueTypes = deduplicate(names.types);
124
-
125
- for (const [idx, name] of uniqueNames.entries()) {
126
- results.push({ id: idx, type: 'package', name } as NameResolutionRequest);
127
- }
128
- for (const [idx, type] of uniqueTypes.entries()) {
129
- results.push({
130
- id: idx + uniqueNames.length,
131
- type: 'moveType',
132
- name: type,
133
- } as NameResolutionRequest);
134
- }
135
-
136
- return batch(results, batchSize);
137
- };
138
-
139
- const deduplicate = <T>(arr: T[]): T[] => [...new Set(arr)];
176
+ }
140
177
 
141
- const batch = <T>(arr: T[], size: number): T[][] => {
178
+ export function batch<T>(arr: T[], size: number): T[][] {
142
179
  const batches = [];
143
180
  for (let i = 0; i < arr.length; i += size) {
144
181
  batches.push(arr.slice(i, i + size));
145
182
  }
146
183
  return batches;
147
- };
184
+ }
185
+
186
+ /**
187
+ * Returns a list of unique types that include a name
188
+ * from the given list. This list is retrieved from the Transaction Data.
189
+ */
190
+ function getNamesFromTypeList(types: string[]) {
191
+ const names = new Set<string>();
192
+ for (const type of types) {
193
+ if (hasMvrName(type)) {
194
+ if (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);
195
+ names.add(type);
196
+ }
197
+ }
198
+ return names;
199
+ }
200
+
201
+ function hasMvrName(nameOrType: string) {
202
+ return (
203
+ nameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')
204
+ );
205
+ }
206
+
207
+ function isStructTag(type: string | StructTag): type is StructTag {
208
+ return (
209
+ typeof type === 'object' &&
210
+ 'address' in type &&
211
+ 'module' in type &&
212
+ 'name' in type &&
213
+ 'typeParams' in type
214
+ );
215
+ }
@@ -3,6 +3,8 @@
3
3
 
4
4
  import { fromBase58, splitGenericParameters } from '@mysten/bcs';
5
5
 
6
+ import { isValidNamedPackage } from './move-registry.js';
7
+
6
8
  const TX_DIGEST_LENGTH = 32;
7
9
 
8
10
  /** Returns whether the tx digest is valid based on the serialization format */
@@ -30,7 +32,7 @@ export function isValidSuiObjectId(value: string): boolean {
30
32
  return isValidSuiAddress(value);
31
33
  }
32
34
 
33
- type StructTag = {
35
+ export type StructTag = {
34
36
  address: string;
35
37
  module: string;
36
38
  name: string;
@@ -46,6 +48,8 @@ function parseTypeTag(type: string): string | StructTag {
46
48
  export function parseStructTag(type: string): StructTag {
47
49
  const [address, module] = type.split('::');
48
50
 
51
+ const isMvrPackage = isValidNamedPackage(address);
52
+
49
53
  const rest = type.slice(address.length + module.length + 4);
50
54
  const name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;
51
55
  const typeParams = rest.includes('<')
@@ -55,7 +59,7 @@ export function parseStructTag(type: string): StructTag {
55
59
  : [];
56
60
 
57
61
  return {
58
- address: normalizeSuiAddress(address),
62
+ address: isMvrPackage ? address : normalizeSuiAddress(address),
59
63
  module,
60
64
  name,
61
65
  typeParams,
package/src/version.ts CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  // This file is generated by genversion.mjs. Do not edit it directly.
5
5
 
6
- export const PACKAGE_VERSION = '1.24.0';
7
- export const TARGETED_RPC_VERSION = '1.45.0';
6
+ export const PACKAGE_VERSION = '1.26.0';
7
+ export const TARGETED_RPC_VERSION = '1.47.0';