@mysten/sui 1.9.0 → 1.10.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/plugins/NamedPackagesPlugin.d.ts +3 -3
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +1 -1
- package/dist/cjs/transactions/plugins/utils.js +26 -7
- package/dist/cjs/transactions/plugins/utils.js.map +2 -2
- package/dist/cjs/utils/move-registry.js +12 -3
- package/dist/cjs/utils/move-registry.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/plugins/NamedPackagesPlugin.d.ts +3 -3
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +1 -1
- package/dist/esm/transactions/plugins/utils.js +26 -7
- package/dist/esm/transactions/plugins/utils.js.map +2 -2
- package/dist/esm/utils/move-registry.js +12 -3
- package/dist/esm/utils/move-registry.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 +2 -2
- package/src/transactions/plugins/NamedPackagesPlugin.ts +3 -3
- package/src/transactions/plugins/utils.ts +33 -7
- package/src/utils/move-registry.ts +24 -5
- package/src/version.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -22,10 +22,10 @@ export type NamedPackagesPluginOptions = {
|
|
|
22
22
|
* Expected format example:
|
|
23
23
|
* {
|
|
24
24
|
* packages: {
|
|
25
|
-
* '
|
|
25
|
+
* '@framework/std': '0x1234',
|
|
26
26
|
* },
|
|
27
27
|
* types: {
|
|
28
|
-
* '
|
|
28
|
+
* '@framework/std::string::String': '0x1234::string::String',
|
|
29
29
|
* },
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
@@ -36,7 +36,7 @@ export type NamedPackagesPluginOptions = {
|
|
|
36
36
|
* @experimental This plugin is in experimental phase and there might be breaking changes in the future
|
|
37
37
|
*
|
|
38
38
|
* Adds named resolution so that you can use .move names in your transactions.
|
|
39
|
-
* e.g.
|
|
39
|
+
* e.g. `@org/app::type::Type` will be resolved to `0x1234::type::Type`.
|
|
40
40
|
* This plugin will resolve all names & types in the transaction block.
|
|
41
41
|
*
|
|
42
42
|
* To install this plugin globally in your app, use:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/plugins/NamedPackagesPlugin.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiGraphQLClient } from '../../graphql/client.js';\nimport type { BuildTransactionOptions } from '../json-rpc-resolver.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { NamedPackagesPluginCache, NameResolutionRequest } from './utils.js';\nimport { findTransactionBlockNames, listToRequests, replaceNames } from './utils.js';\n\nexport type NamedPackagesPluginOptions = {\n\t/**\n\t * The SuiGraphQLClient to use for resolving names.\n\t * The endpoint should be the GraphQL endpoint of the network you are targeting.\n\t * For non-mainnet networks, if the plugin doesn't work as expected, you need to validate that the\n\t * RPC provider has support for the `packageByName` and `typeByName` queries (using external resolver).\n\t */\n\tsuiGraphQLClient: SuiGraphQLClient;\n\t/**\n\t * The number of names to resolve in each batch request.\n\t * Needs to be calculated based on the GraphQL query limits.\n\t */\n\tpageSize?: number;\n\t/**\n\t * Local overrides for the resolution plugin. Pass this to pre-populate\n\t * the cache with known packages / types (especially useful for local or CI testing).\n\t *\n\t * \tExpected format example:\n\t * {\n\t * \t\tpackages: {\n\t * \t\t\t'
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiGraphQLClient } from '../../graphql/client.js';\nimport type { BuildTransactionOptions } from '../json-rpc-resolver.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { NamedPackagesPluginCache, NameResolutionRequest } from './utils.js';\nimport { findTransactionBlockNames, listToRequests, replaceNames } from './utils.js';\n\nexport type NamedPackagesPluginOptions = {\n\t/**\n\t * The SuiGraphQLClient to use for resolving names.\n\t * The endpoint should be the GraphQL endpoint of the network you are targeting.\n\t * For non-mainnet networks, if the plugin doesn't work as expected, you need to validate that the\n\t * RPC provider has support for the `packageByName` and `typeByName` queries (using external resolver).\n\t */\n\tsuiGraphQLClient: SuiGraphQLClient;\n\t/**\n\t * The number of names to resolve in each batch request.\n\t * Needs to be calculated based on the GraphQL query limits.\n\t */\n\tpageSize?: number;\n\t/**\n\t * Local overrides for the resolution plugin. Pass this to pre-populate\n\t * the cache with known packages / types (especially useful for local or CI testing).\n\t *\n\t * \tExpected format example:\n\t * {\n\t * \t\tpackages: {\n\t * \t\t\t'@framework/std': '0x1234',\n\t * \t\t},\n\t * \t\ttypes: {\n\t * \t\t\t'@framework/std::string::String': '0x1234::string::String',\n\t * \t\t},\n\t * \t}\n\t *\n\t */\n\toverrides?: NamedPackagesPluginCache;\n};\n\n/**\n * @experimental This plugin is in experimental phase and there might be breaking changes in the future\n *\n * Adds named resolution so that you can use .move names in your transactions.\n * e.g. `@org/app::type::Type` will be resolved to `0x1234::type::Type`.\n * This plugin will resolve all names & types in the transaction block.\n *\n * To install this plugin globally in your app, use:\n * ```\n * Transaction.registerGlobalSerializationPlugin(\"namedPackagesPlugin\", namedPackagesPlugin({ suiGraphQLClient }));\n * ```\n *\n * You can also define `overrides` to pre-populate name resolutions locally (removes the GraphQL request).\n */\nexport const namedPackagesPlugin = ({\n\tsuiGraphQLClient,\n\tpageSize = 10,\n\toverrides = { packages: {}, types: {} },\n}: NamedPackagesPluginOptions) => {\n\tconst cache = {\n\t\tpackages: { ...overrides.packages },\n\t\ttypes: { ...overrides.types },\n\t};\n\n\treturn async (\n\t\ttransactionData: TransactionDataBuilder,\n\t\t_buildOptions: BuildTransactionOptions,\n\t\tnext: () => Promise<void>,\n\t) => {\n\t\tconst names = findTransactionBlockNames(transactionData);\n\t\tconst batches = listToRequests(\n\t\t\t{\n\t\t\t\tpackages: names.packages.filter((x) => !cache.packages[x]),\n\t\t\t\ttypes: names.types.filter((x) => !cache.types[x]),\n\t\t\t},\n\t\t\tpageSize,\n\t\t);\n\n\t\t// now we need to bulk resolve all the names + types, and replace them in the transaction data.\n\t\t(await Promise.all(batches.map((batch) => query(suiGraphQLClient, batch)))).forEach((res) => {\n\t\t\tObject.assign(cache.types, res.types);\n\t\t\tObject.assign(cache.packages, res.packages);\n\t\t});\n\n\t\treplaceNames(transactionData, cache);\n\n\t\tawait next();\n\t};\n\n\tasync function query(client: SuiGraphQLClient, requests: NameResolutionRequest[]) {\n\t\tconst results: NamedPackagesPluginCache = { packages: {}, types: {} };\n\t\t// avoid making a request if there are no names to resolve.\n\t\tif (requests.length === 0) return results;\n\n\t\t// Create multiple queries for each name / type we need to resolve\n\t\t// TODO: Replace with bulk APIs when available.\n\t\tconst gqlQuery = `{\n ${requests.map((req) => {\n\t\t\t\t\tconst request = req.type === 'package' ? 'packageByName' : 'typeByName';\n\t\t\t\t\tconst fields = req.type === 'package' ? 'address' : 'repr';\n\n\t\t\t\t\treturn `${gqlQueryKey(req.id)}: ${request}(name:\"${req.name}\") {\n ${fields}\n }`;\n\t\t\t\t})}\n }`;\n\n\t\tconst result = await client.query({\n\t\t\tquery: gqlQuery,\n\t\t\tvariables: undefined,\n\t\t});\n\n\t\tif (result.errors) throw new Error(JSON.stringify({ query: gqlQuery, errors: result.errors }));\n\n\t\t// Parse the results and create a map of `<name|type> -> <address|repr>`\n\t\tfor (const req of requests) {\n\t\t\tconst key = gqlQueryKey(req.id);\n\t\t\tif (!result.data || !result.data[key]) throw new Error(`No result found for: ${req.name}`);\n\t\t\tconst data = result.data[key] as { address?: string; repr?: string };\n\n\t\t\tif (req.type === 'package') results.packages[req.name] = data.address!;\n\t\t\tif (req.type === 'moveType') results.types[req.name] = data.repr!;\n\t\t}\n\n\t\treturn results;\n\t}\n};\n\nconst gqlQueryKey = (idx: number) => `key_${idx}`;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAAwE;AA+CjE,MAAM,sBAAsB,CAAC;AAAA,EACnC;AAAA,EACA,WAAW;AAAA,EACX,YAAY,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,EAAE;AACvC,MAAkC;AACjC,QAAM,QAAQ;AAAA,IACb,UAAU,EAAE,GAAG,UAAU,SAAS;AAAA,IAClC,OAAO,EAAE,GAAG,UAAU,MAAM;AAAA,EAC7B;AAEA,SAAO,OACN,iBACA,eACA,SACI;AACJ,UAAM,YAAQ,wCAA0B,eAAe;AACvD,UAAM,cAAU;AAAA,MACf;AAAA,QACC,UAAU,MAAM,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,SAAS,CAAC,CAAC;AAAA,QACzD,OAAO,MAAM,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC;AAAA,MACjD;AAAA,MACA;AAAA,IACD;AAGA,KAAC,MAAM,QAAQ,IAAI,QAAQ,IAAI,CAAC,UAAU,MAAM,kBAAkB,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ;AAC5F,aAAO,OAAO,MAAM,OAAO,IAAI,KAAK;AACpC,aAAO,OAAO,MAAM,UAAU,IAAI,QAAQ;AAAA,IAC3C,CAAC;AAED,mCAAa,iBAAiB,KAAK;AAEnC,UAAM,KAAK;AAAA,EACZ;AAEA,iBAAe,MAAM,QAA0B,UAAmC;AACjF,UAAM,UAAoC,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,EAAE;AAEpE,QAAI,SAAS,WAAW,EAAG,QAAO;AAIlC,UAAM,WAAW;AAAA,UACT,SAAS,IAAI,CAAC,QAAQ;AAC3B,YAAM,UAAU,IAAI,SAAS,YAAY,kBAAkB;AAC3D,YAAM,SAAS,IAAI,SAAS,YAAY,YAAY;AAEpD,aAAO,GAAG,YAAY,IAAI,EAAE,CAAC,KAAK,OAAO,UAAU,IAAI,IAAI;AAAA,sBAC1C,MAAM;AAAA;AAAA,IAExB,CAAC,CAAC;AAAA;AAGJ,UAAM,SAAS,MAAM,OAAO,MAAM;AAAA,MACjC,OAAO;AAAA,MACP,WAAW;AAAA,IACZ,CAAC;AAED,QAAI,OAAO,OAAQ,OAAM,IAAI,MAAM,KAAK,UAAU,EAAE,OAAO,UAAU,QAAQ,OAAO,OAAO,CAAC,CAAC;AAG7F,eAAW,OAAO,UAAU;AAC3B,YAAM,MAAM,YAAY,IAAI,EAAE;AAC9B,UAAI,CAAC,OAAO,QAAQ,CAAC,OAAO,KAAK,GAAG,EAAG,OAAM,IAAI,MAAM,wBAAwB,IAAI,IAAI,EAAE;AACzF,YAAM,OAAO,OAAO,KAAK,GAAG;AAE5B,UAAI,IAAI,SAAS,UAAW,SAAQ,SAAS,IAAI,IAAI,IAAI,KAAK;AAC9D,UAAI,IAAI,SAAS,WAAY,SAAQ,MAAM,IAAI,IAAI,IAAI,KAAK;AAAA,IAC7D;AAEA,WAAO;AAAA,EACR;AACD;AAEA,MAAM,cAAc,CAAC,QAAgB,OAAO,GAAG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,11 +24,17 @@ __export(utils_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(utils_exports);
|
|
26
26
|
var import_move_registry = require("../../utils/move-registry.js");
|
|
27
|
-
const NAME_SEPARATOR = "
|
|
27
|
+
const NAME_SEPARATOR = "/";
|
|
28
28
|
const findTransactionBlockNames = (builder) => {
|
|
29
29
|
const packages = /* @__PURE__ */ new Set();
|
|
30
30
|
const types = /* @__PURE__ */ new Set();
|
|
31
31
|
for (const command of builder.commands) {
|
|
32
|
+
if (command.MakeMoveVec?.type) {
|
|
33
|
+
getNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {
|
|
34
|
+
types.add(type);
|
|
35
|
+
});
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
32
38
|
if (!("MoveCall" in command)) continue;
|
|
33
39
|
const tx = command.MoveCall;
|
|
34
40
|
if (!tx) continue;
|
|
@@ -37,20 +43,33 @@ const findTransactionBlockNames = (builder) => {
|
|
|
37
43
|
if (!(0, import_move_registry.isValidNamedPackage)(pkg)) throw new Error(`Invalid package name: ${pkg}`);
|
|
38
44
|
packages.add(pkg);
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
types.add(type);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
+
getNamesFromTypeList(tx.typeArguments ?? []).forEach((type) => {
|
|
47
|
+
types.add(type);
|
|
48
|
+
});
|
|
46
49
|
}
|
|
47
50
|
return {
|
|
48
51
|
packages: [...packages],
|
|
49
52
|
types: [...types]
|
|
50
53
|
};
|
|
51
54
|
};
|
|
55
|
+
function getNamesFromTypeList(types) {
|
|
56
|
+
const names = /* @__PURE__ */ new Set();
|
|
57
|
+
for (const type of types) {
|
|
58
|
+
if (type.includes(NAME_SEPARATOR)) {
|
|
59
|
+
if (!(0, import_move_registry.isValidNamedType)(type)) throw new Error(`Invalid type with names: ${type}`);
|
|
60
|
+
names.add(type);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return [...names];
|
|
64
|
+
}
|
|
52
65
|
const replaceNames = (builder, cache) => {
|
|
53
66
|
for (const command of builder.commands) {
|
|
67
|
+
if (command.MakeMoveVec?.type) {
|
|
68
|
+
if (!command.MakeMoveVec.type.includes(NAME_SEPARATOR)) continue;
|
|
69
|
+
if (!cache.types[command.MakeMoveVec.type])
|
|
70
|
+
throw new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);
|
|
71
|
+
command.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];
|
|
72
|
+
}
|
|
54
73
|
const tx = command.MoveCall;
|
|
55
74
|
if (!tx) continue;
|
|
56
75
|
const nameParts = tx.package.split("::");
|
|
@@ -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 = '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAsD;AAQtD,MAAM,iBAAiB;AAYhB,MAAM,4BAA4B,CACxC,YAC6C;AAC7C,QAAM,WAAwB,oBAAI,IAAI;AACtC,QAAM,QAAqB,oBAAI,IAAI;AAEnC,aAAW,WAAW,QAAQ,UAAU;AACvC,QAAI,EAAE,cAAc,SAAU;AAC9B,UAAM,KAAK,QAAQ;AAEnB,QAAI,CAAC,GAAI;AAET,UAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;AACpC,QAAI,IAAI,SAAS,cAAc,GAAG;AACjC,UAAI,KAAC,0CAAoB,GAAG,EAAG,OAAM,IAAI,MAAM,yBAAyB,GAAG,EAAE;AAC7E,eAAS,IAAI,GAAG;AAAA,IACjB;AAEA,
|
|
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 const findTransactionBlockNames = (\n\tbuilder: TransactionDataBuilder,\n): { packages: string[]; types: string[] } => {\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 (pkg.includes(NAME_SEPARATOR)) {\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 * Returns a list of unique types that include a name\n * from the given list.\n * */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (type.includes(NAME_SEPARATOR)) {\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\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport const 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 (!command.MakeMoveVec.type.includes(NAME_SEPARATOR)) 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 (name.includes(NAME_SEPARATOR) && !cache.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\tnameParts[0] = cache.packages[name];\n\t\ttx.package = nameParts.join('::');\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 (!types[i].includes(NAME_SEPARATOR)) 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 const listToRequests = (\n\tnames: { packages: string[]; types: string[] },\n\tbatchSize: number,\n): NameResolutionRequest[][] => {\n\tconst results: NameResolutionRequest[] = [];\n\tconst uniqueNames = deduplicate(names.packages);\n\tconst uniqueTypes = deduplicate(names.types);\n\n\tfor (const [idx, name] of uniqueNames.entries()) {\n\t\tresults.push({ id: idx, type: 'package', name } as NameResolutionRequest);\n\t}\n\tfor (const [idx, type] of uniqueTypes.entries()) {\n\t\tresults.push({\n\t\t\tid: idx + uniqueNames.length,\n\t\t\ttype: 'moveType',\n\t\t\tname: type,\n\t\t} as NameResolutionRequest);\n\t}\n\n\treturn batch(results, batchSize);\n};\n\nconst deduplicate = <T>(arr: T[]): T[] => [...new Set(arr)];\n\nconst 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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;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AK,IAAI,KAAK,YAAY,QAAQ,GAAG;AAChD,YAAQ,KAAK;AAAA,MACZ,IAAI,MAAM,YAAY;AAAA,MACtB,MAAM;AAAA,MACN,MAAM;AAAA,IACP,CAA0B;AAAA,EAC3B;AAEA,SAAO,MAAM,SAAS,SAAS;AAChC;AAEA,MAAM,cAAc,CAAI,QAAkB,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC;AAE1D,MAAM,QAAQ,CAAI,KAAU,SAAwB;AACnD,QAAM,UAAU,CAAC;AACjB,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,MAAM;AAC1C,YAAQ,KAAK,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC;AAAA,EACpC;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,14 +22,23 @@ __export(move_registry_exports, {
|
|
|
22
22
|
isValidNamedType: () => isValidNamedType
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(move_registry_exports);
|
|
25
|
-
|
|
25
|
+
var import_suins = require("./suins.js");
|
|
26
|
+
const NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)$/;
|
|
27
|
+
const VERSION_REGEX = /^\d+$/;
|
|
28
|
+
const MAX_APP_SIZE = 64;
|
|
29
|
+
const NAME_SEPARATOR = "/";
|
|
26
30
|
const isValidNamedPackage = (name) => {
|
|
27
|
-
|
|
31
|
+
const parts = name.split(NAME_SEPARATOR);
|
|
32
|
+
if (parts.length < 2 || parts.length > 3) return false;
|
|
33
|
+
const [org, app, version] = parts;
|
|
34
|
+
if (version !== void 0 && !VERSION_REGEX.test(version)) return false;
|
|
35
|
+
if (!(0, import_suins.isValidSuiNSName)(org)) return false;
|
|
36
|
+
return NAME_PATTERN.test(app) && app.length < MAX_APP_SIZE;
|
|
28
37
|
};
|
|
29
38
|
const isValidNamedType = (type) => {
|
|
30
39
|
const splitType = type.split(/::|<|>|,/);
|
|
31
40
|
for (const t of splitType) {
|
|
32
|
-
if (t.includes(
|
|
41
|
+
if (t.includes(NAME_SEPARATOR) && !isValidNamedPackage(t)) return false;
|
|
33
42
|
}
|
|
34
43
|
return true;
|
|
35
44
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/move-registry.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/** The pattern to find an optionally versioned name */\nconst NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidSuiNSName } from './suins.js';\n\n/** The pattern to find an optionally versioned name */\nconst NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)$/;\n/** The pattern for a valid version number */\nconst VERSION_REGEX = /^\\d+$/;\n/** The maximum size for an app */\nconst MAX_APP_SIZE = 64;\n/** The separator for the name */\nconst NAME_SEPARATOR = '/';\n\nexport const isValidNamedPackage = (name: string): boolean => {\n\tconst parts = name.split(NAME_SEPARATOR);\n\t// The name has to have 2 parts (without-version), or 3 parts (with version).\n\tif (parts.length < 2 || parts.length > 3) return false;\n\n\tconst [org, app, version] = parts; // split by {org} {app} {optional version}\n\n\t// If the version exists, it must be a number.\n\tif (version !== undefined && !VERSION_REGEX.test(version)) return false;\n\t// Check if the org is a valid SuiNS name.\n\tif (!isValidSuiNSName(org)) return false;\n\n\t// Check if the app is a valid name.\n\treturn NAME_PATTERN.test(app) && app.length < MAX_APP_SIZE;\n};\n\n/**\n * Checks if a type contains valid named packages.\n * This DOES NOT check if the type is a valid Move type.\n */\nexport const isValidNamedType = (type: string): boolean => {\n\t// split our type by all possible type delimeters.\n\tconst splitType = type.split(/::|<|>|,/);\n\tfor (const t of splitType) {\n\t\tif (t.includes(NAME_SEPARATOR) && !isValidNamedPackage(t)) return false;\n\t}\n\t// TODO: Add `isValidStructTag` check once it's introduced.\n\treturn true;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAiC;AAGjC,MAAM,eAAe;AAErB,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AAErB,MAAM,iBAAiB;AAEhB,MAAM,sBAAsB,CAAC,SAA0B;AAC7D,QAAM,QAAQ,KAAK,MAAM,cAAc;AAEvC,MAAI,MAAM,SAAS,KAAK,MAAM,SAAS,EAAG,QAAO;AAEjD,QAAM,CAAC,KAAK,KAAK,OAAO,IAAI;AAG5B,MAAI,YAAY,UAAa,CAAC,cAAc,KAAK,OAAO,EAAG,QAAO;AAElE,MAAI,KAAC,+BAAiB,GAAG,EAAG,QAAO;AAGnC,SAAO,aAAa,KAAK,GAAG,KAAK,IAAI,SAAS;AAC/C;AAMO,MAAM,mBAAmB,CAAC,SAA0B;AAE1D,QAAM,YAAY,KAAK,MAAM,UAAU;AACvC,aAAW,KAAK,WAAW;AAC1B,QAAI,EAAE,SAAS,cAAc,KAAK,CAAC,oBAAoB,CAAC,EAAG,QAAO;AAAA,EACnE;AAEA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/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.10.0";
|
|
2
|
+
export declare const TARGETED_RPC_VERSION = "1.35.0";
|
package/dist/cjs/version.js
CHANGED
|
@@ -22,6 +22,6 @@ __export(version_exports, {
|
|
|
22
22
|
TARGETED_RPC_VERSION: () => TARGETED_RPC_VERSION
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const PACKAGE_VERSION = "1.
|
|
26
|
-
const TARGETED_RPC_VERSION = "1.
|
|
25
|
+
const PACKAGE_VERSION = "1.10.0";
|
|
26
|
+
const TARGETED_RPC_VERSION = "1.35.0";
|
|
27
27
|
//# sourceMappingURL=version.js.map
|
package/dist/cjs/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.10.0';\nexport const TARGETED_RPC_VERSION = '1.35.0';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,10 +22,10 @@ export type NamedPackagesPluginOptions = {
|
|
|
22
22
|
* Expected format example:
|
|
23
23
|
* {
|
|
24
24
|
* packages: {
|
|
25
|
-
* '
|
|
25
|
+
* '@framework/std': '0x1234',
|
|
26
26
|
* },
|
|
27
27
|
* types: {
|
|
28
|
-
* '
|
|
28
|
+
* '@framework/std::string::String': '0x1234::string::String',
|
|
29
29
|
* },
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
@@ -36,7 +36,7 @@ export type NamedPackagesPluginOptions = {
|
|
|
36
36
|
* @experimental This plugin is in experimental phase and there might be breaking changes in the future
|
|
37
37
|
*
|
|
38
38
|
* Adds named resolution so that you can use .move names in your transactions.
|
|
39
|
-
* e.g.
|
|
39
|
+
* e.g. `@org/app::type::Type` will be resolved to `0x1234::type::Type`.
|
|
40
40
|
* This plugin will resolve all names & types in the transaction block.
|
|
41
41
|
*
|
|
42
42
|
* To install this plugin globally in your app, use:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/plugins/NamedPackagesPlugin.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiGraphQLClient } from '../../graphql/client.js';\nimport type { BuildTransactionOptions } from '../json-rpc-resolver.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { NamedPackagesPluginCache, NameResolutionRequest } from './utils.js';\nimport { findTransactionBlockNames, listToRequests, replaceNames } from './utils.js';\n\nexport type NamedPackagesPluginOptions = {\n\t/**\n\t * The SuiGraphQLClient to use for resolving names.\n\t * The endpoint should be the GraphQL endpoint of the network you are targeting.\n\t * For non-mainnet networks, if the plugin doesn't work as expected, you need to validate that the\n\t * RPC provider has support for the `packageByName` and `typeByName` queries (using external resolver).\n\t */\n\tsuiGraphQLClient: SuiGraphQLClient;\n\t/**\n\t * The number of names to resolve in each batch request.\n\t * Needs to be calculated based on the GraphQL query limits.\n\t */\n\tpageSize?: number;\n\t/**\n\t * Local overrides for the resolution plugin. Pass this to pre-populate\n\t * the cache with known packages / types (especially useful for local or CI testing).\n\t *\n\t * \tExpected format example:\n\t * {\n\t * \t\tpackages: {\n\t * \t\t\t'
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiGraphQLClient } from '../../graphql/client.js';\nimport type { BuildTransactionOptions } from '../json-rpc-resolver.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { NamedPackagesPluginCache, NameResolutionRequest } from './utils.js';\nimport { findTransactionBlockNames, listToRequests, replaceNames } from './utils.js';\n\nexport type NamedPackagesPluginOptions = {\n\t/**\n\t * The SuiGraphQLClient to use for resolving names.\n\t * The endpoint should be the GraphQL endpoint of the network you are targeting.\n\t * For non-mainnet networks, if the plugin doesn't work as expected, you need to validate that the\n\t * RPC provider has support for the `packageByName` and `typeByName` queries (using external resolver).\n\t */\n\tsuiGraphQLClient: SuiGraphQLClient;\n\t/**\n\t * The number of names to resolve in each batch request.\n\t * Needs to be calculated based on the GraphQL query limits.\n\t */\n\tpageSize?: number;\n\t/**\n\t * Local overrides for the resolution plugin. Pass this to pre-populate\n\t * the cache with known packages / types (especially useful for local or CI testing).\n\t *\n\t * \tExpected format example:\n\t * {\n\t * \t\tpackages: {\n\t * \t\t\t'@framework/std': '0x1234',\n\t * \t\t},\n\t * \t\ttypes: {\n\t * \t\t\t'@framework/std::string::String': '0x1234::string::String',\n\t * \t\t},\n\t * \t}\n\t *\n\t */\n\toverrides?: NamedPackagesPluginCache;\n};\n\n/**\n * @experimental This plugin is in experimental phase and there might be breaking changes in the future\n *\n * Adds named resolution so that you can use .move names in your transactions.\n * e.g. `@org/app::type::Type` will be resolved to `0x1234::type::Type`.\n * This plugin will resolve all names & types in the transaction block.\n *\n * To install this plugin globally in your app, use:\n * ```\n * Transaction.registerGlobalSerializationPlugin(\"namedPackagesPlugin\", namedPackagesPlugin({ suiGraphQLClient }));\n * ```\n *\n * You can also define `overrides` to pre-populate name resolutions locally (removes the GraphQL request).\n */\nexport const namedPackagesPlugin = ({\n\tsuiGraphQLClient,\n\tpageSize = 10,\n\toverrides = { packages: {}, types: {} },\n}: NamedPackagesPluginOptions) => {\n\tconst cache = {\n\t\tpackages: { ...overrides.packages },\n\t\ttypes: { ...overrides.types },\n\t};\n\n\treturn async (\n\t\ttransactionData: TransactionDataBuilder,\n\t\t_buildOptions: BuildTransactionOptions,\n\t\tnext: () => Promise<void>,\n\t) => {\n\t\tconst names = findTransactionBlockNames(transactionData);\n\t\tconst batches = listToRequests(\n\t\t\t{\n\t\t\t\tpackages: names.packages.filter((x) => !cache.packages[x]),\n\t\t\t\ttypes: names.types.filter((x) => !cache.types[x]),\n\t\t\t},\n\t\t\tpageSize,\n\t\t);\n\n\t\t// now we need to bulk resolve all the names + types, and replace them in the transaction data.\n\t\t(await Promise.all(batches.map((batch) => query(suiGraphQLClient, batch)))).forEach((res) => {\n\t\t\tObject.assign(cache.types, res.types);\n\t\t\tObject.assign(cache.packages, res.packages);\n\t\t});\n\n\t\treplaceNames(transactionData, cache);\n\n\t\tawait next();\n\t};\n\n\tasync function query(client: SuiGraphQLClient, requests: NameResolutionRequest[]) {\n\t\tconst results: NamedPackagesPluginCache = { packages: {}, types: {} };\n\t\t// avoid making a request if there are no names to resolve.\n\t\tif (requests.length === 0) return results;\n\n\t\t// Create multiple queries for each name / type we need to resolve\n\t\t// TODO: Replace with bulk APIs when available.\n\t\tconst gqlQuery = `{\n ${requests.map((req) => {\n\t\t\t\t\tconst request = req.type === 'package' ? 'packageByName' : 'typeByName';\n\t\t\t\t\tconst fields = req.type === 'package' ? 'address' : 'repr';\n\n\t\t\t\t\treturn `${gqlQueryKey(req.id)}: ${request}(name:\"${req.name}\") {\n ${fields}\n }`;\n\t\t\t\t})}\n }`;\n\n\t\tconst result = await client.query({\n\t\t\tquery: gqlQuery,\n\t\t\tvariables: undefined,\n\t\t});\n\n\t\tif (result.errors) throw new Error(JSON.stringify({ query: gqlQuery, errors: result.errors }));\n\n\t\t// Parse the results and create a map of `<name|type> -> <address|repr>`\n\t\tfor (const req of requests) {\n\t\t\tconst key = gqlQueryKey(req.id);\n\t\t\tif (!result.data || !result.data[key]) throw new Error(`No result found for: ${req.name}`);\n\t\t\tconst data = result.data[key] as { address?: string; repr?: string };\n\n\t\t\tif (req.type === 'package') results.packages[req.name] = data.address!;\n\t\t\tif (req.type === 'moveType') results.types[req.name] = data.repr!;\n\t\t}\n\n\t\treturn results;\n\t}\n};\n\nconst gqlQueryKey = (idx: number) => `key_${idx}`;\n"],
|
|
5
5
|
"m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,IAExB,CAAC,CAAC;AAAA;AAGJ,UAAM,SAAS,MAAM,OAAO,MAAM;AAAA,MACjC,OAAO;AAAA,MACP,WAAW;AAAA,IACZ,CAAC;AAED,QAAI,OAAO,OAAQ,OAAM,IAAI,MAAM,KAAK,UAAU,EAAE,OAAO,UAAU,QAAQ,OAAO,OAAO,CAAC,CAAC;AAG7F,eAAW,OAAO,UAAU;AAC3B,YAAM,MAAM,YAAY,IAAI,EAAE;AAC9B,UAAI,CAAC,OAAO,QAAQ,CAAC,OAAO,KAAK,GAAG,EAAG,OAAM,IAAI,MAAM,wBAAwB,IAAI,IAAI,EAAE;AACzF,YAAM,OAAO,OAAO,KAAK,GAAG;AAE5B,UAAI,IAAI,SAAS,UAAW,SAAQ,SAAS,IAAI,IAAI,IAAI,KAAK;AAC9D,UAAI,IAAI,SAAS,WAAY,SAAQ,MAAM,IAAI,IAAI,IAAI,KAAK;AAAA,IAC7D;AAEA,WAAO;AAAA,EACR;AACD;AAEA,MAAM,cAAc,CAAC,QAAgB,OAAO,GAAG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { isValidNamedPackage, isValidNamedType } from "../../utils/move-registry.js";
|
|
2
|
-
const NAME_SEPARATOR = "
|
|
2
|
+
const NAME_SEPARATOR = "/";
|
|
3
3
|
const findTransactionBlockNames = (builder) => {
|
|
4
4
|
const packages = /* @__PURE__ */ new Set();
|
|
5
5
|
const types = /* @__PURE__ */ new Set();
|
|
6
6
|
for (const command of builder.commands) {
|
|
7
|
+
if (command.MakeMoveVec?.type) {
|
|
8
|
+
getNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {
|
|
9
|
+
types.add(type);
|
|
10
|
+
});
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
7
13
|
if (!("MoveCall" in command)) continue;
|
|
8
14
|
const tx = command.MoveCall;
|
|
9
15
|
if (!tx) continue;
|
|
@@ -12,20 +18,33 @@ const findTransactionBlockNames = (builder) => {
|
|
|
12
18
|
if (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);
|
|
13
19
|
packages.add(pkg);
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
types.add(type);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
+
getNamesFromTypeList(tx.typeArguments ?? []).forEach((type) => {
|
|
22
|
+
types.add(type);
|
|
23
|
+
});
|
|
21
24
|
}
|
|
22
25
|
return {
|
|
23
26
|
packages: [...packages],
|
|
24
27
|
types: [...types]
|
|
25
28
|
};
|
|
26
29
|
};
|
|
30
|
+
function getNamesFromTypeList(types) {
|
|
31
|
+
const names = /* @__PURE__ */ new Set();
|
|
32
|
+
for (const type of types) {
|
|
33
|
+
if (type.includes(NAME_SEPARATOR)) {
|
|
34
|
+
if (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);
|
|
35
|
+
names.add(type);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...names];
|
|
39
|
+
}
|
|
27
40
|
const replaceNames = (builder, cache) => {
|
|
28
41
|
for (const command of builder.commands) {
|
|
42
|
+
if (command.MakeMoveVec?.type) {
|
|
43
|
+
if (!command.MakeMoveVec.type.includes(NAME_SEPARATOR)) continue;
|
|
44
|
+
if (!cache.types[command.MakeMoveVec.type])
|
|
45
|
+
throw new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);
|
|
46
|
+
command.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];
|
|
47
|
+
}
|
|
29
48
|
const tx = command.MoveCall;
|
|
30
49
|
if (!tx) continue;
|
|
31
50
|
const nameParts = tx.package.split("::");
|
|
@@ -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 = '
|
|
5
|
-
"mappings": "AAGA,SAAS,qBAAqB,wBAAwB;AAQtD,MAAM,iBAAiB;AAYhB,MAAM,4BAA4B,CACxC,YAC6C;AAC7C,QAAM,WAAwB,oBAAI,IAAI;AACtC,QAAM,QAAqB,oBAAI,IAAI;AAEnC,aAAW,WAAW,QAAQ,UAAU;AACvC,QAAI,EAAE,cAAc,SAAU;AAC9B,UAAM,KAAK,QAAQ;AAEnB,QAAI,CAAC,GAAI;AAET,UAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,EAAE,CAAC;AACpC,QAAI,IAAI,SAAS,cAAc,GAAG;AACjC,UAAI,CAAC,oBAAoB,GAAG,EAAG,OAAM,IAAI,MAAM,yBAAyB,GAAG,EAAE;AAC7E,eAAS,IAAI,GAAG;AAAA,IACjB;AAEA,
|
|
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 const findTransactionBlockNames = (\n\tbuilder: TransactionDataBuilder,\n): { packages: string[]; types: string[] } => {\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 (pkg.includes(NAME_SEPARATOR)) {\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 * Returns a list of unique types that include a name\n * from the given list.\n * */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (type.includes(NAME_SEPARATOR)) {\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\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport const 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 (!command.MakeMoveVec.type.includes(NAME_SEPARATOR)) 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 (name.includes(NAME_SEPARATOR) && !cache.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\tnameParts[0] = cache.packages[name];\n\t\ttx.package = nameParts.join('::');\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 (!types[i].includes(NAME_SEPARATOR)) 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 const listToRequests = (\n\tnames: { packages: string[]; types: string[] },\n\tbatchSize: number,\n): NameResolutionRequest[][] => {\n\tconst results: NameResolutionRequest[] = [];\n\tconst uniqueNames = deduplicate(names.packages);\n\tconst uniqueTypes = deduplicate(names.types);\n\n\tfor (const [idx, name] of uniqueNames.entries()) {\n\t\tresults.push({ id: idx, type: 'package', name } as NameResolutionRequest);\n\t}\n\tfor (const [idx, type] of uniqueTypes.entries()) {\n\t\tresults.push({\n\t\t\tid: idx + uniqueNames.length,\n\t\t\ttype: 'moveType',\n\t\t\tname: type,\n\t\t} as NameResolutionRequest);\n\t}\n\n\treturn batch(results, batchSize);\n};\n\nconst deduplicate = <T>(arr: T[]): T[] => [...new Set(arr)];\n\nconst 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"],
|
|
5
|
+
"mappings": "AAGA,SAAS,qBAAqB,wBAAwB;AAQtD,MAAM,iBAAiB;AAYhB,MAAM,4BAA4B,CACxC,YAC6C;AAC7C,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,MAC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AQ,KAAK,MAAM;AAC1C,YAAQ,KAAK,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC;AAAA,EACpC;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { isValidSuiNSName } from "./suins.js";
|
|
2
|
+
const NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)$/;
|
|
3
|
+
const VERSION_REGEX = /^\d+$/;
|
|
4
|
+
const MAX_APP_SIZE = 64;
|
|
5
|
+
const NAME_SEPARATOR = "/";
|
|
2
6
|
const isValidNamedPackage = (name) => {
|
|
3
|
-
|
|
7
|
+
const parts = name.split(NAME_SEPARATOR);
|
|
8
|
+
if (parts.length < 2 || parts.length > 3) return false;
|
|
9
|
+
const [org, app, version] = parts;
|
|
10
|
+
if (version !== void 0 && !VERSION_REGEX.test(version)) return false;
|
|
11
|
+
if (!isValidSuiNSName(org)) return false;
|
|
12
|
+
return NAME_PATTERN.test(app) && app.length < MAX_APP_SIZE;
|
|
4
13
|
};
|
|
5
14
|
const isValidNamedType = (type) => {
|
|
6
15
|
const splitType = type.split(/::|<|>|,/);
|
|
7
16
|
for (const t of splitType) {
|
|
8
|
-
if (t.includes(
|
|
17
|
+
if (t.includes(NAME_SEPARATOR) && !isValidNamedPackage(t)) return false;
|
|
9
18
|
}
|
|
10
19
|
return true;
|
|
11
20
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/move-registry.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/** The pattern to find an optionally versioned name */\nconst NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidSuiNSName } from './suins.js';\n\n/** The pattern to find an optionally versioned name */\nconst NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)$/;\n/** The pattern for a valid version number */\nconst VERSION_REGEX = /^\\d+$/;\n/** The maximum size for an app */\nconst MAX_APP_SIZE = 64;\n/** The separator for the name */\nconst NAME_SEPARATOR = '/';\n\nexport const isValidNamedPackage = (name: string): boolean => {\n\tconst parts = name.split(NAME_SEPARATOR);\n\t// The name has to have 2 parts (without-version), or 3 parts (with version).\n\tif (parts.length < 2 || parts.length > 3) return false;\n\n\tconst [org, app, version] = parts; // split by {org} {app} {optional version}\n\n\t// If the version exists, it must be a number.\n\tif (version !== undefined && !VERSION_REGEX.test(version)) return false;\n\t// Check if the org is a valid SuiNS name.\n\tif (!isValidSuiNSName(org)) return false;\n\n\t// Check if the app is a valid name.\n\treturn NAME_PATTERN.test(app) && app.length < MAX_APP_SIZE;\n};\n\n/**\n * Checks if a type contains valid named packages.\n * This DOES NOT check if the type is a valid Move type.\n */\nexport const isValidNamedType = (type: string): boolean => {\n\t// split our type by all possible type delimeters.\n\tconst splitType = type.split(/::|<|>|,/);\n\tfor (const t of splitType) {\n\t\tif (t.includes(NAME_SEPARATOR) && !isValidNamedPackage(t)) return false;\n\t}\n\t// TODO: Add `isValidStructTag` check once it's introduced.\n\treturn true;\n};\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,wBAAwB;AAGjC,MAAM,eAAe;AAErB,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AAErB,MAAM,iBAAiB;AAEhB,MAAM,sBAAsB,CAAC,SAA0B;AAC7D,QAAM,QAAQ,KAAK,MAAM,cAAc;AAEvC,MAAI,MAAM,SAAS,KAAK,MAAM,SAAS,EAAG,QAAO;AAEjD,QAAM,CAAC,KAAK,KAAK,OAAO,IAAI;AAG5B,MAAI,YAAY,UAAa,CAAC,cAAc,KAAK,OAAO,EAAG,QAAO;AAElE,MAAI,CAAC,iBAAiB,GAAG,EAAG,QAAO;AAGnC,SAAO,aAAa,KAAK,GAAG,KAAK,IAAI,SAAS;AAC/C;AAMO,MAAM,mBAAmB,CAAC,SAA0B;AAE1D,QAAM,YAAY,KAAK,MAAM,UAAU;AACvC,aAAW,KAAK,WAAW;AAC1B,QAAI,EAAE,SAAS,cAAc,KAAK,CAAC,oBAAoB,CAAC,EAAG,QAAO;AAAA,EACnE;AAEA,SAAO;AACR;",
|
|
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.10.0";
|
|
2
|
+
export declare const TARGETED_RPC_VERSION = "1.35.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.10.0';\nexport const TARGETED_RPC_VERSION = '1.35.0';\n"],
|
|
5
5
|
"mappings": "AAKO,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|