@mysten/sui 1.24.0 → 1.25.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 +6 -0
- package/dist/cjs/transactions/Arguments.d.ts +2 -2
- package/dist/cjs/transactions/Transaction.d.ts +4 -4
- package/dist/cjs/transactions/TransactionData.d.ts +2 -2
- package/dist/cjs/transactions/data/v1.d.ts +4 -4
- package/dist/cjs/transactions/data/v2.d.ts +4 -4
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +84 -43
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/cjs/transactions/plugins/utils.d.ts +10 -6
- package/dist/cjs/transactions/plugins/utils.js +64 -37
- package/dist/cjs/transactions/plugins/utils.js.map +2 -2
- package/dist/cjs/utils/sui-types.d.ts +1 -2
- package/dist/cjs/utils/sui-types.js +3 -1
- package/dist/cjs/utils/sui-types.js.map +2 -2
- 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/esm/transactions/Arguments.d.ts +2 -2
- package/dist/esm/transactions/Transaction.d.ts +4 -4
- package/dist/esm/transactions/TransactionData.d.ts +2 -2
- package/dist/esm/transactions/data/v1.d.ts +4 -4
- package/dist/esm/transactions/data/v2.d.ts +4 -4
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +91 -44
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/esm/transactions/plugins/utils.d.ts +10 -6
- package/dist/esm/transactions/plugins/utils.js +64 -37
- package/dist/esm/transactions/plugins/utils.js.map +2 -2
- package/dist/esm/utils/sui-types.d.ts +1 -2
- package/dist/esm/utils/sui-types.js +3 -1
- package/dist/esm/utils/sui-types.js.map +2 -2
- 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/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transactions/plugins/NamedPackagesPlugin.ts +118 -62
- package/src/transactions/plugins/utils.ts +115 -47
- package/src/utils/sui-types.ts +6 -2
- package/src/version.ts +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isValidNamedPackage, isValidNamedType } from "../../utils/move-registry.js";
|
|
2
|
+
import { normalizeStructTag, parseStructTag } from "../../utils/sui-types.js";
|
|
2
3
|
const NAME_SEPARATOR = "/";
|
|
3
|
-
|
|
4
|
+
function findNamesInTransaction(builder) {
|
|
4
5
|
const packages = /* @__PURE__ */ new Set();
|
|
5
6
|
const types = /* @__PURE__ */ new Set();
|
|
6
7
|
for (const command of builder.commands) {
|
|
@@ -14,7 +15,7 @@ const findTransactionBlockNames = (builder) => {
|
|
|
14
15
|
const tx = command.MoveCall;
|
|
15
16
|
if (!tx) continue;
|
|
16
17
|
const pkg = tx.package.split("::")[0];
|
|
17
|
-
if (pkg
|
|
18
|
+
if (hasMvrName(pkg)) {
|
|
18
19
|
if (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);
|
|
19
20
|
packages.add(pkg);
|
|
20
21
|
}
|
|
@@ -26,21 +27,46 @@ const findTransactionBlockNames = (builder) => {
|
|
|
26
27
|
packages: [...packages],
|
|
27
28
|
types: [...types]
|
|
28
29
|
};
|
|
29
|
-
}
|
|
30
|
-
function
|
|
31
|
-
const
|
|
30
|
+
}
|
|
31
|
+
function getFirstLevelNamedTypes(types) {
|
|
32
|
+
const results = /* @__PURE__ */ new Set();
|
|
32
33
|
for (const type of types) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
findMvrNames(type).forEach((name) => results.add(name));
|
|
35
|
+
}
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
function findMvrNames(type) {
|
|
39
|
+
const types = /* @__PURE__ */ new Set();
|
|
40
|
+
if (typeof type === "string" && !hasMvrName(type)) return types;
|
|
41
|
+
let tag = isStructTag(type) ? type : parseStructTag(type);
|
|
42
|
+
if (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);
|
|
43
|
+
for (const param of tag.typeParams) {
|
|
44
|
+
findMvrNames(param).forEach((name) => types.add(name));
|
|
37
45
|
}
|
|
38
|
-
return
|
|
46
|
+
return types;
|
|
47
|
+
}
|
|
48
|
+
function populateNamedTypesFromCache(types, typeCache) {
|
|
49
|
+
const composedTypes = {};
|
|
50
|
+
types.forEach((type) => {
|
|
51
|
+
const normalized = normalizeStructTag(findAndReplaceCachedTypes(type, typeCache));
|
|
52
|
+
composedTypes[type] = normalized;
|
|
53
|
+
});
|
|
54
|
+
return composedTypes;
|
|
55
|
+
}
|
|
56
|
+
function findAndReplaceCachedTypes(tag, typeCache) {
|
|
57
|
+
const type = isStructTag(tag) ? tag : parseStructTag(tag);
|
|
58
|
+
let typeTag = `${type.address}::${type.module}::${type.name}`;
|
|
59
|
+
const cacheHit = typeCache[typeTag];
|
|
60
|
+
return {
|
|
61
|
+
...type,
|
|
62
|
+
address: cacheHit ? cacheHit.split("::")[0] : type.address,
|
|
63
|
+
typeParams: type.typeParams.map((param) => findAndReplaceCachedTypes(param, typeCache))
|
|
64
|
+
};
|
|
39
65
|
}
|
|
40
|
-
|
|
66
|
+
function replaceNames(builder, cache) {
|
|
41
67
|
for (const command of builder.commands) {
|
|
42
68
|
if (command.MakeMoveVec?.type) {
|
|
43
|
-
if (!command.MakeMoveVec.type
|
|
69
|
+
if (!hasMvrName(command.MakeMoveVec.type)) continue;
|
|
44
70
|
if (!cache.types[command.MakeMoveVec.type])
|
|
45
71
|
throw new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);
|
|
46
72
|
command.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];
|
|
@@ -49,49 +75,50 @@ const replaceNames = (builder, cache) => {
|
|
|
49
75
|
if (!tx) continue;
|
|
50
76
|
const nameParts = tx.package.split("::");
|
|
51
77
|
const name = nameParts[0];
|
|
52
|
-
if (name
|
|
78
|
+
if (hasMvrName(name) && !cache.packages[name])
|
|
53
79
|
throw new Error(`No address found for package: ${name}`);
|
|
54
|
-
if (name
|
|
80
|
+
if (hasMvrName(name)) {
|
|
55
81
|
nameParts[0] = cache.packages[name];
|
|
56
82
|
tx.package = nameParts.join("::");
|
|
57
83
|
}
|
|
58
84
|
const types = tx.typeArguments;
|
|
59
85
|
if (!types) continue;
|
|
60
86
|
for (let i = 0; i < types.length; i++) {
|
|
61
|
-
if (!types[i]
|
|
87
|
+
if (!hasMvrName(types[i])) continue;
|
|
62
88
|
if (!cache.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);
|
|
63
89
|
types[i] = cache.types[types[i]];
|
|
64
90
|
}
|
|
65
91
|
tx.typeArguments = types;
|
|
66
92
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const results = [];
|
|
70
|
-
const uniqueNames = deduplicate(names.packages);
|
|
71
|
-
const uniqueTypes = deduplicate(names.types);
|
|
72
|
-
for (const [idx, name] of uniqueNames.entries()) {
|
|
73
|
-
results.push({ id: idx, type: "package", name });
|
|
74
|
-
}
|
|
75
|
-
for (const [idx, type] of uniqueTypes.entries()) {
|
|
76
|
-
results.push({
|
|
77
|
-
id: idx + uniqueNames.length,
|
|
78
|
-
type: "moveType",
|
|
79
|
-
name: type
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
return batch(results, batchSize);
|
|
83
|
-
};
|
|
84
|
-
const deduplicate = (arr) => [...new Set(arr)];
|
|
85
|
-
const batch = (arr, size) => {
|
|
93
|
+
}
|
|
94
|
+
function batch(arr, size) {
|
|
86
95
|
const batches = [];
|
|
87
96
|
for (let i = 0; i < arr.length; i += size) {
|
|
88
97
|
batches.push(arr.slice(i, i + size));
|
|
89
98
|
}
|
|
90
99
|
return batches;
|
|
91
|
-
}
|
|
100
|
+
}
|
|
101
|
+
function getNamesFromTypeList(types) {
|
|
102
|
+
const names = /* @__PURE__ */ new Set();
|
|
103
|
+
for (const type of types) {
|
|
104
|
+
if (hasMvrName(type)) {
|
|
105
|
+
if (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);
|
|
106
|
+
names.add(type);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return names;
|
|
110
|
+
}
|
|
111
|
+
function hasMvrName(nameOrType) {
|
|
112
|
+
return nameOrType.includes(NAME_SEPARATOR) || nameOrType.includes("@") || nameOrType.includes(".sui");
|
|
113
|
+
}
|
|
114
|
+
function isStructTag(type) {
|
|
115
|
+
return typeof type === "object" && "address" in type && "module" in type && "name" in type && "typeParams" in type;
|
|
116
|
+
}
|
|
92
117
|
export {
|
|
93
|
-
|
|
94
|
-
|
|
118
|
+
batch,
|
|
119
|
+
findNamesInTransaction,
|
|
120
|
+
getFirstLevelNamedTypes,
|
|
121
|
+
populateNamedTypesFromCache,
|
|
95
122
|
replaceNames
|
|
96
123
|
};
|
|
97
124
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/plugins/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\n\nexport type NamedPackagesPluginCache = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\nconst NAME_SEPARATOR = '/';\n\nexport type NameResolutionRequest = {\n\tid: number;\n\ttype: 'package' | 'moveType';\n\tname: string;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport
|
|
5
|
-
"mappings": "AAGA,SAAS,qBAAqB,wBAAwB;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';\nimport { normalizeStructTag, parseStructTag } from '../../utils/sui-types.js';\nimport type { StructTag } from '../../utils/sui-types.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\n\nexport type NamedPackagesPluginCache = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\nconst NAME_SEPARATOR = '/';\n\nexport type NameResolutionRequest = {\n\tid: number;\n\ttype: 'package' | 'moveType';\n\tname: string;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport function findNamesInTransaction(builder: TransactionDataBuilder): {\n\tpackages: string[];\n\ttypes: string[];\n} {\n\tconst packages: Set<string> = new Set();\n\tconst types: Set<string> = new Set();\n\n\tfor (const command of builder.commands) {\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tgetNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {\n\t\t\t\ttypes.add(type);\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (!('MoveCall' in command)) continue;\n\t\tconst tx = command.MoveCall;\n\n\t\tif (!tx) continue;\n\n\t\tconst pkg = tx.package.split('::')[0];\n\t\tif (hasMvrName(pkg)) {\n\t\t\tif (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);\n\t\t\tpackages.add(pkg);\n\t\t}\n\n\t\tgetNamesFromTypeList(tx.typeArguments ?? []).forEach((type) => {\n\t\t\ttypes.add(type);\n\t\t});\n\t}\n\n\treturn {\n\t\tpackages: [...packages],\n\t\ttypes: [...types],\n\t};\n}\n\n/**\n * Extracts all first-level types from a list of types.\n * E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,\n * the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.\n */\nexport function getFirstLevelNamedTypes(types: string[]) {\n\tconst results: Set<string> = new Set();\n\n\tfor (const type of types) {\n\t\tfindMvrNames(type).forEach((name) => results.add(name));\n\t}\n\n\treturn results;\n}\n\n/**\n * Extracts all named types from a given type.\n */\nfunction findMvrNames(type: string | StructTag) {\n\tconst types: Set<string> = new Set();\n\n\tif (typeof type === 'string' && !hasMvrName(type)) return types;\n\n\tlet tag = isStructTag(type) ? type : parseStructTag(type);\n\n\tif (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);\n\n\tfor (const param of tag.typeParams) {\n\t\tfindMvrNames(param).forEach((name) => types.add(name));\n\t}\n\n\treturn types;\n}\n\n// /**\n// * Allows partial replacements of known types with their resolved equivalents.\n// * E.g. `@mvr/demo::a::A<@mvr/demo::b::B>` can be resolved, if we already have\n// * the address for `@mvr/demo::b::B` and the address for `@mvr/demo::a::A`,\n// * without the need to have the full type in the cache.\n// *\n// * Returns the fully composed resolved types (if any) in a `named-type -> normalized-type` map.\n// */\nexport function populateNamedTypesFromCache(types: string[], typeCache: Record<string, string>) {\n\tconst composedTypes: Record<string, string> = {};\n\n\ttypes.forEach((type) => {\n\t\tconst normalized = normalizeStructTag(findAndReplaceCachedTypes(type, typeCache));\n\t\tcomposedTypes[type] = normalized;\n\t});\n\n\treturn composedTypes;\n}\n\n/**\n * Traverses a type, and replaces any found names with their resolved equivalents,\n * based on the supplied type cache.\n */\nfunction findAndReplaceCachedTypes(\n\ttag: string | StructTag,\n\ttypeCache: Record<string, string>,\n): StructTag {\n\tconst type = isStructTag(tag) ? tag : parseStructTag(tag);\n\n\tlet typeTag = `${type.address}::${type.module}::${type.name}`;\n\tconst cacheHit = typeCache[typeTag];\n\n\treturn {\n\t\t...type,\n\t\taddress: cacheHit ? cacheHit.split('::')[0] : type.address,\n\t\ttypeParams: type.typeParams.map((param) => findAndReplaceCachedTypes(param, typeCache)),\n\t};\n}\n\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport function replaceNames(builder: TransactionDataBuilder, cache: NamedPackagesPluginCache) {\n\tfor (const command of builder.commands) {\n\t\t// Replacements for `MakeMoveVec` commands (that can include types)\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tif (!hasMvrName(command.MakeMoveVec.type)) continue;\n\t\t\tif (!cache.types[command.MakeMoveVec.type])\n\t\t\t\tthrow new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);\n\t\t\tcommand.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];\n\t\t}\n\t\t// Replacements for `MoveCall` commands (that can include packages & types)\n\t\tconst tx = command.MoveCall;\n\t\tif (!tx) continue;\n\n\t\tconst nameParts = tx.package.split('::');\n\t\tconst name = nameParts[0];\n\n\t\tif (hasMvrName(name) && !cache.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\t// Replace package name with address.\n\t\tif (hasMvrName(name)) {\n\t\t\tnameParts[0] = cache.packages[name];\n\t\t\ttx.package = nameParts.join('::');\n\t\t}\n\n\t\tconst types = tx.typeArguments;\n\t\tif (!types) continue;\n\n\t\tfor (let i = 0; i < types.length; i++) {\n\t\t\tif (!hasMvrName(types[i])) continue;\n\n\t\t\tif (!cache.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);\n\t\t\ttypes[i] = cache.types[types[i]];\n\t\t}\n\n\t\ttx.typeArguments = types;\n\t}\n}\n\nexport function batch<T>(arr: T[], size: number): T[][] {\n\tconst batches = [];\n\tfor (let i = 0; i < arr.length; i += size) {\n\t\tbatches.push(arr.slice(i, i + size));\n\t}\n\treturn batches;\n}\n\n/**\n * Returns a list of unique types that include a name\n * from the given list. This list is retrieved from the Transaction Data.\n */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (hasMvrName(type)) {\n\t\t\tif (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);\n\t\t\tnames.add(type);\n\t\t}\n\t}\n\treturn names;\n}\n\nfunction hasMvrName(nameOrType: string) {\n\treturn (\n\t\tnameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')\n\t);\n}\n\nfunction isStructTag(type: string | StructTag): type is StructTag {\n\treturn (\n\t\ttypeof type === 'object' &&\n\t\t'address' in type &&\n\t\t'module' in type &&\n\t\t'name' in type &&\n\t\t'typeParams' in type\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,qBAAqB,wBAAwB;AACtD,SAAS,oBAAoB,sBAAsB;AASnD,MAAM,iBAAiB;AAYhB,SAAS,uBAAuB,SAGrC;AACD,QAAM,WAAwB,oBAAI,IAAI;AACtC,QAAM,QAAqB,oBAAI,IAAI;AAEnC,aAAW,WAAW,QAAQ,UAAU;AACvC,QAAI,QAAQ,aAAa,MAAM;AAC9B,2BAAqB,CAAC,QAAQ,YAAY,IAAI,CAAC,EAAE,QAAQ,CAAC,SAAS;AAClE,cAAM,IAAI,IAAI;AAAA,MACf,CAAC;AACD;AAAA,IACD;AACA,QAAI,EAAE,cAAc,SAAU;AAC9B,UAAM,KAAK,QAAQ;AAEnB,QAAI,CAAC,GAAI;AAET,UAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;AACpC,QAAI,WAAW,GAAG,GAAG;AACpB,UAAI,CAAC,oBAAoB,GAAG,EAAG,OAAM,IAAI,MAAM,yBAAyB,GAAG,EAAE;AAC7E,eAAS,IAAI,GAAG;AAAA,IACjB;AAEA,yBAAqB,GAAG,iBAAiB,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS;AAC9D,YAAM,IAAI,IAAI;AAAA,IACf,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN,UAAU,CAAC,GAAG,QAAQ;AAAA,IACtB,OAAO,CAAC,GAAG,KAAK;AAAA,EACjB;AACD;AAOO,SAAS,wBAAwB,OAAiB;AACxD,QAAM,UAAuB,oBAAI,IAAI;AAErC,aAAW,QAAQ,OAAO;AACzB,iBAAa,IAAI,EAAE,QAAQ,CAAC,S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E;AAC/E,YAAM,IAAI,IAAI;AAAA,IACf;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,WAAW,YAAoB;AACvC,SACC,WAAW,SAAS,cAAc,KAAK,WAAW,SAAS,GAAG,KAAK,WAAW,SAAS,MAAM;AAE/F;AAEA,SAAS,YAAY,MAA6C;AACjE,SACC,OAAO,SAAS,YAChB,aAAa,QACb,YAAY,QACZ,UAAU,QACV,gBAAgB;AAElB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ export declare function isValidTransactionDigest(value: string): value is string
|
|
|
3
3
|
export declare const SUI_ADDRESS_LENGTH = 32;
|
|
4
4
|
export declare function isValidSuiAddress(value: string): value is string;
|
|
5
5
|
export declare function isValidSuiObjectId(value: string): boolean;
|
|
6
|
-
type StructTag = {
|
|
6
|
+
export type StructTag = {
|
|
7
7
|
address: string;
|
|
8
8
|
module: string;
|
|
9
9
|
name: string;
|
|
@@ -24,4 +24,3 @@ export declare function normalizeStructTag(type: string | StructTag): string;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function normalizeSuiAddress(value: string, forceAdd0x?: boolean): string;
|
|
26
26
|
export declare function normalizeSuiObjectId(value: string, forceAdd0x?: boolean): string;
|
|
27
|
-
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fromBase58, splitGenericParameters } from "@mysten/bcs";
|
|
2
|
+
import { isValidNamedPackage } from "./move-registry.js";
|
|
2
3
|
const TX_DIGEST_LENGTH = 32;
|
|
3
4
|
function isValidTransactionDigest(value) {
|
|
4
5
|
try {
|
|
@@ -21,13 +22,14 @@ function parseTypeTag(type) {
|
|
|
21
22
|
}
|
|
22
23
|
function parseStructTag(type) {
|
|
23
24
|
const [address, module] = type.split("::");
|
|
25
|
+
const isMvrPackage = isValidNamedPackage(address);
|
|
24
26
|
const rest = type.slice(address.length + module.length + 4);
|
|
25
27
|
const name = rest.includes("<") ? rest.slice(0, rest.indexOf("<")) : rest;
|
|
26
28
|
const typeParams = rest.includes("<") ? splitGenericParameters(rest.slice(rest.indexOf("<") + 1, rest.lastIndexOf(">"))).map(
|
|
27
29
|
(typeParam) => parseTypeTag(typeParam.trim())
|
|
28
30
|
) : [];
|
|
29
31
|
return {
|
|
30
|
-
address: normalizeSuiAddress(address),
|
|
32
|
+
address: isMvrPackage ? address : normalizeSuiAddress(address),
|
|
31
33
|
module,
|
|
32
34
|
name,
|
|
33
35
|
typeParams
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/sui-types.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@mysten/bcs';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch (e) {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/MystenLabs/sui/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/sui-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const SUI_ADDRESS_LENGTH = 32;\nexport function isValidSuiAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === SUI_ADDRESS_LENGTH;\n}\n\nexport function isValidSuiObjectId(value: string): boolean {\n\treturn isValidSuiAddress(value);\n}\n\
|
|
5
|
-
"mappings": "AAGA,SAAS,YAAY,8BAA8B;AAEnD,MAAM,mBAAmB;AAGlB,SAAS,yBAAyB,OAAgC;AACxE,MAAI;AACH,UAAM,SAAS,WAAW,KAAK;AAC/B,WAAO,OAAO,WAAW;AAAA,EAC1B,SAAS,GAAG;AACX,WAAO;AAAA,EACR;AACD;AAQO,MAAM,qBAAqB;AAC3B,SAAS,kBAAkB,OAAgC;AACjE,SAAO,MAAM,KAAK,KAAK,iBAAiB,KAAK,MAAM;AACpD;AAEO,SAAS,mBAAmB,OAAwB;AAC1D,SAAO,kBAAkB,KAAK;AAC/B;AASA,SAAS,aAAa,MAAkC;AACvD,MAAI,CAAC,KAAK,SAAS,IAAI,EAAG,QAAO;AAEjC,SAAO,eAAe,IAAI;AAC3B;AAEO,SAAS,eAAe,MAAyB;AACvD,QAAM,CAAC,SAAS,MAAM,IAAI,KAAK,MAAM,IAAI;AAEzC,QAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,OAAO,SAAS,CAAC;AAC1D,QAAM,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,KAAK,QAAQ,GAAG,CAAC,IAAI;AACrE,QAAM,aAAa,KAAK,SAAS,GAAG,IACjC,uBAAuB,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,GAAG,KAAK,YAAY,GAAG,CAAC,CAAC,EAAE;AAAA,IACjF,CAAC,cAAc,aAAa,UAAU,KAAK,CAAC;AAAA,EAC7C,IACC,CAAC;AAEJ,SAAO;AAAA,IACN,SAAS,oBAAoB,OAAO;AAAA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@mysten/bcs';\n\nimport { isValidNamedPackage } from './move-registry.js';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch (e) {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/MystenLabs/sui/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/sui-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const SUI_ADDRESS_LENGTH = 32;\nexport function isValidSuiAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === SUI_ADDRESS_LENGTH;\n}\n\nexport function isValidSuiObjectId(value: string): boolean {\n\treturn isValidSuiAddress(value);\n}\n\nexport type StructTag = {\n\taddress: string;\n\tmodule: string;\n\tname: string;\n\ttypeParams: (string | StructTag)[];\n};\n\nfunction parseTypeTag(type: string): string | StructTag {\n\tif (!type.includes('::')) return type;\n\n\treturn parseStructTag(type);\n}\n\nexport function parseStructTag(type: string): StructTag {\n\tconst [address, module] = type.split('::');\n\n\tconst isMvrPackage = isValidNamedPackage(address);\n\n\tconst rest = type.slice(address.length + module.length + 4);\n\tconst name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;\n\tconst typeParams = rest.includes('<')\n\t\t? splitGenericParameters(rest.slice(rest.indexOf('<') + 1, rest.lastIndexOf('>'))).map(\n\t\t\t\t(typeParam) => parseTypeTag(typeParam.trim()),\n\t\t\t)\n\t\t: [];\n\n\treturn {\n\t\taddress: isMvrPackage ? address : normalizeSuiAddress(address),\n\t\tmodule,\n\t\tname,\n\t\ttypeParams,\n\t};\n}\n\nexport function normalizeStructTag(type: string | StructTag): string {\n\tconst { address, module, name, typeParams } =\n\t\ttypeof type === 'string' ? parseStructTag(type) : type;\n\n\tconst formattedTypeParams =\n\t\ttypeParams?.length > 0\n\t\t\t? `<${typeParams\n\t\t\t\t\t.map((typeParam) =>\n\t\t\t\t\t\ttypeof typeParam === 'string' ? typeParam : normalizeStructTag(typeParam),\n\t\t\t\t\t)\n\t\t\t\t\t.join(',')}>`\n\t\t\t: '';\n\n\treturn `${address}::${module}::${name}${formattedTypeParams}`;\n}\n\n/**\n * Perform the following operations:\n * 1. Make the address lower case\n * 2. Prepend `0x` if the string does not start with `0x`.\n * 3. Add more zeros if the length of the address(excluding `0x`) is less than `SUI_ADDRESS_LENGTH`\n *\n * WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior\n * is to treat the first `0x` not as part of the address. The default behavior can be overridden by\n * setting `forceAdd0x` to true\n *\n */\nexport function normalizeSuiAddress(value: string, forceAdd0x: boolean = false): string {\n\tlet address = value.toLowerCase();\n\tif (!forceAdd0x && address.startsWith('0x')) {\n\t\taddress = address.slice(2);\n\t}\n\treturn `0x${address.padStart(SUI_ADDRESS_LENGTH * 2, '0')}`;\n}\n\nexport function normalizeSuiObjectId(value: string, forceAdd0x: boolean = false): string {\n\treturn normalizeSuiAddress(value, forceAdd0x);\n}\n\nfunction isHex(value: string): boolean {\n\treturn /^(0x|0X)?[a-fA-F0-9]+$/.test(value) && value.length % 2 === 0;\n}\n\nfunction getHexByteLength(value: string): number {\n\treturn /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,YAAY,8BAA8B;AAEnD,SAAS,2BAA2B;AAEpC,MAAM,mBAAmB;AAGlB,SAAS,yBAAyB,OAAgC;AACxE,MAAI;AACH,UAAM,SAAS,WAAW,KAAK;AAC/B,WAAO,OAAO,WAAW;AAAA,EAC1B,SAAS,GAAG;AACX,WAAO;AAAA,EACR;AACD;AAQO,MAAM,qBAAqB;AAC3B,SAAS,kBAAkB,OAAgC;AACjE,SAAO,MAAM,KAAK,KAAK,iBAAiB,KAAK,MAAM;AACpD;AAEO,SAAS,mBAAmB,OAAwB;AAC1D,SAAO,kBAAkB,KAAK;AAC/B;AASA,SAAS,aAAa,MAAkC;AACvD,MAAI,CAAC,KAAK,SAAS,IAAI,EAAG,QAAO;AAEjC,SAAO,eAAe,IAAI;AAC3B;AAEO,SAAS,eAAe,MAAyB;AACvD,QAAM,CAAC,SAAS,MAAM,IAAI,KAAK,MAAM,IAAI;AA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AAS,iBAAiB,OAAuB;AAChD,SAAO,WAAW,KAAK,KAAK,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS;AACzE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "1.
|
|
2
|
-
export declare const TARGETED_RPC_VERSION = "1.
|
|
1
|
+
export declare const PACKAGE_VERSION = "1.25.0";
|
|
2
|
+
export declare const TARGETED_RPC_VERSION = "1.46.0";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.25.0';\nexport const TARGETED_RPC_VERSION = '1.46.0';\n"],
|
|
5
5
|
"mappings": "AAKO,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|