@mysten/sui 2.3.1 → 2.4.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 +16 -0
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +2 -2
- package/dist/utils/move-registry.d.mts +1 -2
- package/dist/utils/move-registry.d.mts.map +1 -1
- package/dist/utils/move-registry.mjs +3 -3
- package/dist/utils/move-registry.mjs.map +1 -1
- package/dist/utils/sui-types.d.mts +2 -1
- package/dist/utils/sui-types.d.mts.map +1 -1
- package/dist/utils/sui-types.mjs +39 -1
- package/dist/utils/sui-types.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +37 -20
- package/src/utils/index.ts +1 -0
- package/src/utils/move-registry.ts +3 -4
- package/src/utils/sui-types.ts +57 -0
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mysten/sui.js
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5270eaf: Add `isValidStructTag` validation utility. `isValidNamedType` now also validates the full
|
|
8
|
+
struct tag structure (completing the TODO that previously returned `true` unconditionally).
|
|
9
|
+
|
|
10
|
+
## 2.3.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 99d1e00: Add default export condition
|
|
15
|
+
- Updated dependencies [99d1e00]
|
|
16
|
+
- @mysten/utils@0.3.1
|
|
17
|
+
- @mysten/bcs@2.0.2
|
|
18
|
+
|
|
3
19
|
## 2.3.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetDatatypeRequest, GetDatatypeResponse, GetFunctionRequest, GetFunctionResponse, GetPackageRequest, GetPackageResponse, ListPackageVersionsRequest, ListPackageVersionsResponse } from "./move_package_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime2 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc2 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/move_package_service.client.d.ts
|
|
@@ -32,9 +32,9 @@ interface IMovePackageServiceClient {
|
|
|
32
32
|
declare class MovePackageServiceClient implements IMovePackageServiceClient, ServiceInfo {
|
|
33
33
|
private readonly _transport;
|
|
34
34
|
typeName: string;
|
|
35
|
-
methods:
|
|
35
|
+
methods: _protobuf_ts_runtime_rpc2.MethodInfo<any, any>[];
|
|
36
36
|
options: {
|
|
37
|
-
[extensionName: string]:
|
|
37
|
+
[extensionName: string]: _protobuf_ts_runtime2.JsonValue;
|
|
38
38
|
};
|
|
39
39
|
constructor(_transport: RpcTransport);
|
|
40
40
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LookupNameRequest, LookupNameResponse, ReverseLookupNameRequest, ReverseLookupNameResponse } from "./name_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime3 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc3 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/name_service.client.d.ts
|
|
@@ -24,9 +24,9 @@ interface INameServiceClient {
|
|
|
24
24
|
declare class NameServiceClient implements INameServiceClient, ServiceInfo {
|
|
25
25
|
private readonly _transport;
|
|
26
26
|
typeName: string;
|
|
27
|
-
methods:
|
|
27
|
+
methods: _protobuf_ts_runtime_rpc3.MethodInfo<any, any>[];
|
|
28
28
|
options: {
|
|
29
|
-
[extensionName: string]:
|
|
29
|
+
[extensionName: string]: _protobuf_ts_runtime3.JsonValue;
|
|
30
30
|
};
|
|
31
31
|
constructor(_transport: RpcTransport);
|
|
32
32
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VerifySignatureRequest, VerifySignatureResponse } from "./signature_verification_service.mjs";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
2
|
+
import * as _protobuf_ts_runtime1 from "@protobuf-ts/runtime";
|
|
3
|
+
import * as _protobuf_ts_runtime_rpc1 from "@protobuf-ts/runtime-rpc";
|
|
4
4
|
import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
|
|
5
5
|
|
|
6
6
|
//#region src/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.ts
|
|
@@ -22,9 +22,9 @@ interface ISignatureVerificationServiceClient {
|
|
|
22
22
|
declare class SignatureVerificationServiceClient implements ISignatureVerificationServiceClient, ServiceInfo {
|
|
23
23
|
private readonly _transport;
|
|
24
24
|
typeName: string;
|
|
25
|
-
methods:
|
|
25
|
+
methods: _protobuf_ts_runtime_rpc1.MethodInfo<any, any>[];
|
|
26
26
|
options: {
|
|
27
|
-
[extensionName: string]:
|
|
27
|
+
[extensionName: string]: _protobuf_ts_runtime1.JsonValue;
|
|
28
28
|
};
|
|
29
29
|
constructor(_transport: RpcTransport);
|
|
30
30
|
/**
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeTypeTag } from "../bcs/type-tag-serializer.mjs";
|
|
2
|
-
import { SUI_ADDRESS_LENGTH, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag } from "./sui-types.mjs";
|
|
2
|
+
import { SUI_ADDRESS_LENGTH, isValidStructTag, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag } from "./sui-types.mjs";
|
|
3
3
|
import { formatAddress, formatDigest } from "./format.mjs";
|
|
4
4
|
import { isValidSuiNSName, normalizeSuiNSName } from "./suins.mjs";
|
|
5
5
|
import { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_CLOCK_OBJECT_ID, SUI_DECIMALS, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_MODULE_NAME, SUI_SYSTEM_STATE_OBJECT_ID, SUI_TYPE_ARG } from "./constants.mjs";
|
|
@@ -7,4 +7,4 @@ import { isValidNamedPackage, isValidNamedType } from "./move-registry.mjs";
|
|
|
7
7
|
import { deriveDynamicFieldID } from "./dynamic-fields.mjs";
|
|
8
8
|
import { deriveObjectID } from "./derived-objects.mjs";
|
|
9
9
|
import { fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from "@mysten/bcs";
|
|
10
|
-
export { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_ADDRESS_LENGTH, SUI_CLOCK_OBJECT_ID, SUI_DECIMALS, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_MODULE_NAME, SUI_SYSTEM_STATE_OBJECT_ID, SUI_TYPE_ARG, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidNamedPackage, isValidNamedType, isValidSuiAddress, isValidSuiNSName, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiNSName, normalizeSuiObjectId, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
|
|
10
|
+
export { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_ADDRESS_LENGTH, SUI_CLOCK_OBJECT_ID, SUI_DECIMALS, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_MODULE_NAME, SUI_SYSTEM_STATE_OBJECT_ID, SUI_TYPE_ARG, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidNamedPackage, isValidNamedType, isValidStructTag, isValidSuiAddress, isValidSuiNSName, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiNSName, normalizeSuiObjectId, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isValidSuiNSName, normalizeSuiNSName } from "./suins.mjs";
|
|
2
2
|
import { isValidNamedPackage, isValidNamedType } from "./move-registry.mjs";
|
|
3
|
-
import { SUI_ADDRESS_LENGTH, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag } from "./sui-types.mjs";
|
|
3
|
+
import { SUI_ADDRESS_LENGTH, isValidStructTag, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag } from "./sui-types.mjs";
|
|
4
4
|
import { normalizeTypeTag } from "../bcs/type-tag-serializer.mjs";
|
|
5
5
|
import { deriveDynamicFieldID } from "./dynamic-fields.mjs";
|
|
6
6
|
import { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_CLOCK_OBJECT_ID, SUI_DECIMALS, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_MODULE_NAME, SUI_SYSTEM_STATE_OBJECT_ID, SUI_TYPE_ARG } from "./constants.mjs";
|
|
@@ -8,4 +8,4 @@ import { formatAddress, formatDigest } from "./format.mjs";
|
|
|
8
8
|
import { deriveObjectID } from "./derived-objects.mjs";
|
|
9
9
|
import { fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from "@mysten/bcs";
|
|
10
10
|
|
|
11
|
-
export { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_ADDRESS_LENGTH, SUI_CLOCK_OBJECT_ID, SUI_DECIMALS, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_MODULE_NAME, SUI_SYSTEM_STATE_OBJECT_ID, SUI_TYPE_ARG, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidNamedPackage, isValidNamedType, isValidSuiAddress, isValidSuiNSName, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiNSName, normalizeSuiObjectId, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
|
|
11
|
+
export { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_ADDRESS_LENGTH, SUI_CLOCK_OBJECT_ID, SUI_DECIMALS, SUI_DENY_LIST_OBJECT_ID, SUI_FRAMEWORK_ADDRESS, SUI_RANDOM_OBJECT_ID, SUI_SYSTEM_ADDRESS, SUI_SYSTEM_MODULE_NAME, SUI_SYSTEM_STATE_OBJECT_ID, SUI_TYPE_ARG, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidNamedPackage, isValidNamedType, isValidStructTag, isValidSuiAddress, isValidSuiNSName, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiNSName, normalizeSuiObjectId, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//#region src/utils/move-registry.d.ts
|
|
2
2
|
declare const isValidNamedPackage: (name: string) => boolean;
|
|
3
3
|
/**
|
|
4
|
-
* Checks if a type contains valid named packages.
|
|
5
|
-
* This DOES NOT check if the type is a valid Move type.
|
|
4
|
+
* Checks if a type contains valid named packages and is a valid Move struct tag.
|
|
6
5
|
*/
|
|
7
6
|
declare const isValidNamedType: (type: string) => boolean;
|
|
8
7
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"move-registry.d.mts","names":[],"sources":["../../src/utils/move-registry.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"move-registry.d.mts","names":[],"sources":["../../src/utils/move-registry.ts"],"sourcesContent":[],"mappings":";cAea;AAAb;AAmBA;;cAAa"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isValidSuiNSName } from "./suins.mjs";
|
|
2
|
+
import { isValidStructTag } from "./sui-types.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/utils/move-registry.ts
|
|
4
5
|
/** The pattern to find an optionally versioned name */
|
|
@@ -18,13 +19,12 @@ const isValidNamedPackage = (name) => {
|
|
|
18
19
|
return NAME_PATTERN.test(app) && app.length < MAX_APP_SIZE;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
|
-
* Checks if a type contains valid named packages.
|
|
22
|
-
* This DOES NOT check if the type is a valid Move type.
|
|
22
|
+
* Checks if a type contains valid named packages and is a valid Move struct tag.
|
|
23
23
|
*/
|
|
24
24
|
const isValidNamedType = (type) => {
|
|
25
25
|
const splitType = type.split(/::|<|>|,/);
|
|
26
26
|
for (const t of splitType) if (t.includes(NAME_SEPARATOR) && !isValidNamedPackage(t)) return false;
|
|
27
|
-
return
|
|
27
|
+
return isValidStructTag(type);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"move-registry.mjs","names":[],"sources":["../../src/utils/move-registry.ts"],"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
|
|
1
|
+
{"version":3,"file":"move-registry.mjs","names":[],"sources":["../../src/utils/move-registry.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidSuiNSName } from './suins.js';\nimport { isValidStructTag } from './sui-types.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 and is a valid Move struct tag.\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\treturn isValidStructTag(type);\n};\n"],"mappings":";;;;;AAOA,MAAM,eAAe;;AAErB,MAAM,gBAAgB;;AAEtB,MAAM,eAAe;;AAErB,MAAM,iBAAiB;AAEvB,MAAa,uBAAuB,SAA0B;CAC7D,MAAM,QAAQ,KAAK,MAAM,eAAe;AAExC,KAAI,MAAM,SAAS,KAAK,MAAM,SAAS,EAAG,QAAO;CAEjD,MAAM,CAAC,KAAK,KAAK,WAAW;AAG5B,KAAI,YAAY,UAAa,CAAC,cAAc,KAAK,QAAQ,CAAE,QAAO;AAElE,KAAI,CAAC,iBAAiB,IAAI,CAAE,QAAO;AAGnC,QAAO,aAAa,KAAK,IAAI,IAAI,IAAI,SAAS;;;;;AAM/C,MAAa,oBAAoB,SAA0B;CAE1D,MAAM,YAAY,KAAK,MAAM,WAAW;AACxC,MAAK,MAAM,KAAK,UACf,KAAI,EAAE,SAAS,eAAe,IAAI,CAAC,oBAAoB,EAAE,CAAE,QAAO;AAEnE,QAAO,iBAAiB,KAAK"}
|
|
@@ -4,6 +4,7 @@ declare function isValidTransactionDigest(value: string): value is string;
|
|
|
4
4
|
declare const SUI_ADDRESS_LENGTH = 32;
|
|
5
5
|
declare function isValidSuiAddress(value: string): value is string;
|
|
6
6
|
declare function isValidSuiObjectId(value: string): boolean;
|
|
7
|
+
declare function isValidStructTag(type: string): boolean;
|
|
7
8
|
type StructTag = {
|
|
8
9
|
address: string;
|
|
9
10
|
module: string;
|
|
@@ -26,5 +27,5 @@ declare function normalizeStructTag(type: string | StructTag): string;
|
|
|
26
27
|
declare function normalizeSuiAddress(value: string, forceAdd0x?: boolean): string;
|
|
27
28
|
declare function normalizeSuiObjectId(value: string, forceAdd0x?: boolean): string;
|
|
28
29
|
//#endregion
|
|
29
|
-
export { SUI_ADDRESS_LENGTH, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag };
|
|
30
|
+
export { SUI_ADDRESS_LENGTH, isValidStructTag, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag };
|
|
30
31
|
//# sourceMappingURL=sui-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sui-types.d.mts","names":[],"sources":["../../src/utils/sui-types.ts"],"sourcesContent":[],"mappings":";;AAUgB,iBAAA,wBAAA,CAAwB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAe3B,cAAA,kBAAA,GAAkB,EAAA;AACf,iBAAA,iBAAA,CAAiB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAIjB,iBAAA,kBAAA,CAAkB,KAAA,EAAA,MAAA,CAAA,EAAA,OAAA;
|
|
1
|
+
{"version":3,"file":"sui-types.d.mts","names":[],"sources":["../../src/utils/sui-types.ts"],"sourcesContent":[],"mappings":";;AAUgB,iBAAA,wBAAA,CAAwB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAe3B,cAAA,kBAAA,GAAkB,EAAA;AACf,iBAAA,iBAAA,CAAiB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAIjB,iBAAA,kBAAA,CAAkB,KAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AA6DtB,iBATI,gBAAA,CAagB,IAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AAShB,KAbJ,SAAA,GAakB;EA0Bd,OAAA,EAAA,MAAA;EA2BA,MAAA,EAAA,MAAA;EAQA,IAAA,EAAA,MAAA;wBAtEO;;iBASP,cAAA,gBAA8B;iBA0B9B,kBAAA,gBAAkC;;;;;;;;;;;;iBA2BlC,mBAAA;iBAQA,oBAAA"}
|
package/dist/utils/sui-types.mjs
CHANGED
|
@@ -18,6 +18,44 @@ function isValidSuiAddress(value) {
|
|
|
18
18
|
function isValidSuiObjectId(value) {
|
|
19
19
|
return isValidSuiAddress(value);
|
|
20
20
|
}
|
|
21
|
+
const MOVE_IDENTIFIER_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
22
|
+
function isValidMoveIdentifier(name) {
|
|
23
|
+
return MOVE_IDENTIFIER_REGEX.test(name);
|
|
24
|
+
}
|
|
25
|
+
const PRIMITIVE_TYPE_TAGS = [
|
|
26
|
+
"bool",
|
|
27
|
+
"u8",
|
|
28
|
+
"u16",
|
|
29
|
+
"u32",
|
|
30
|
+
"u64",
|
|
31
|
+
"u128",
|
|
32
|
+
"u256",
|
|
33
|
+
"address",
|
|
34
|
+
"signer"
|
|
35
|
+
];
|
|
36
|
+
const VECTOR_TYPE_REGEX = /^vector<(.+)>$/;
|
|
37
|
+
function isValidTypeTag(type) {
|
|
38
|
+
if (PRIMITIVE_TYPE_TAGS.includes(type)) return true;
|
|
39
|
+
const vectorMatch = type.match(VECTOR_TYPE_REGEX);
|
|
40
|
+
if (vectorMatch) return isValidTypeTag(vectorMatch[1]);
|
|
41
|
+
if (type.includes("::")) return isValidStructTag(type);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
function isValidParsedStructTag(tag) {
|
|
45
|
+
if (!isValidSuiAddress(tag.address) && !isValidNamedPackage(tag.address)) return false;
|
|
46
|
+
if (!isValidMoveIdentifier(tag.module) || !isValidMoveIdentifier(tag.name)) return false;
|
|
47
|
+
return tag.typeParams.every((param) => {
|
|
48
|
+
if (typeof param === "string") return isValidTypeTag(param);
|
|
49
|
+
return isValidParsedStructTag(param);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function isValidStructTag(type) {
|
|
53
|
+
try {
|
|
54
|
+
return isValidParsedStructTag(parseStructTag(type));
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
21
59
|
function parseTypeTag(type) {
|
|
22
60
|
if (!type.includes("::")) return type;
|
|
23
61
|
return parseStructTag(type);
|
|
@@ -68,5 +106,5 @@ function getHexByteLength(value) {
|
|
|
68
106
|
}
|
|
69
107
|
|
|
70
108
|
//#endregion
|
|
71
|
-
export { SUI_ADDRESS_LENGTH, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag };
|
|
109
|
+
export { SUI_ADDRESS_LENGTH, isValidStructTag, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag };
|
|
72
110
|
//# sourceMappingURL=sui-types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sui-types.mjs","names":[],"sources":["../../src/utils/sui-types.ts"],"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 {\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 parts = type.split('::');\n\n\tif (parts.length < 3) {\n\t\tthrow new Error(`Invalid struct tag: ${type}`);\n\t}\n\n\tconst [address, module] = parts;\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"],"mappings":";;;;AAOA,MAAM,mBAAmB;;AAGzB,SAAgB,yBAAyB,OAAgC;AACxE,KAAI;AAEH,SADe,WAAW,MAAM,CAClB,WAAW;SAClB;AACP,SAAO;;;AAUT,MAAa,qBAAqB;AAClC,SAAgB,kBAAkB,OAAgC;AACjE,QAAO,MAAM,MAAM,IAAI,iBAAiB,MAAM,KAAK;;AAGpD,SAAgB,mBAAmB,OAAwB;AAC1D,QAAO,kBAAkB,MAAM;;
|
|
1
|
+
{"version":3,"file":"sui-types.mjs","names":[],"sources":["../../src/utils/sui-types.ts"],"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 {\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\nconst MOVE_IDENTIFIER_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;\n\nexport function isValidMoveIdentifier(name: string): boolean {\n\treturn MOVE_IDENTIFIER_REGEX.test(name);\n}\n\nconst PRIMITIVE_TYPE_TAGS = [\n\t'bool',\n\t'u8',\n\t'u16',\n\t'u32',\n\t'u64',\n\t'u128',\n\t'u256',\n\t'address',\n\t'signer',\n];\n\nconst VECTOR_TYPE_REGEX = /^vector<(.+)>$/;\n\nfunction isValidTypeTag(type: string): boolean {\n\tif (PRIMITIVE_TYPE_TAGS.includes(type)) return true;\n\n\tconst vectorMatch = type.match(VECTOR_TYPE_REGEX);\n\tif (vectorMatch) return isValidTypeTag(vectorMatch[1]);\n\n\tif (type.includes('::')) return isValidStructTag(type);\n\n\treturn false;\n}\n\nfunction isValidParsedStructTag(tag: StructTag): boolean {\n\tif (!isValidSuiAddress(tag.address) && !isValidNamedPackage(tag.address)) {\n\t\treturn false;\n\t}\n\n\tif (!isValidMoveIdentifier(tag.module) || !isValidMoveIdentifier(tag.name)) {\n\t\treturn false;\n\t}\n\n\treturn tag.typeParams.every((param) => {\n\t\tif (typeof param === 'string') {\n\t\t\treturn isValidTypeTag(param);\n\t\t}\n\t\treturn isValidParsedStructTag(param);\n\t});\n}\n\nexport function isValidStructTag(type: string): boolean {\n\ttry {\n\t\tconst tag = parseStructTag(type);\n\t\treturn isValidParsedStructTag(tag);\n\t} catch {\n\t\treturn false;\n\t}\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 parts = type.split('::');\n\n\tif (parts.length < 3) {\n\t\tthrow new Error(`Invalid struct tag: ${type}`);\n\t}\n\n\tconst [address, module] = parts;\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"],"mappings":"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"}
|
package/dist/version.mjs
CHANGED
package/dist/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"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 = '2.
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"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 = '2.4.0';\nexport const TARGETED_RPC_VERSION = '1.66.0';\n"],"mappings":";AAKA,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "Sui TypeScript API",
|
|
5
5
|
"homepage": "https://sdk.mystenlabs.com",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.4.0",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
@@ -35,71 +35,88 @@
|
|
|
35
35
|
"exports": {
|
|
36
36
|
"./bcs": {
|
|
37
37
|
"types": "./dist/bcs/index.d.mts",
|
|
38
|
-
"import": "./dist/bcs/index.mjs"
|
|
38
|
+
"import": "./dist/bcs/index.mjs",
|
|
39
|
+
"default": "./dist/bcs/index.mjs"
|
|
39
40
|
},
|
|
40
41
|
"./client": {
|
|
41
42
|
"types": "./dist/client/index.d.mts",
|
|
42
|
-
"import": "./dist/client/index.mjs"
|
|
43
|
+
"import": "./dist/client/index.mjs",
|
|
44
|
+
"default": "./dist/client/index.mjs"
|
|
43
45
|
},
|
|
44
46
|
"./cryptography": {
|
|
45
47
|
"types": "./dist/cryptography/index.d.mts",
|
|
46
|
-
"import": "./dist/cryptography/index.mjs"
|
|
48
|
+
"import": "./dist/cryptography/index.mjs",
|
|
49
|
+
"default": "./dist/cryptography/index.mjs"
|
|
47
50
|
},
|
|
48
51
|
"./faucet": {
|
|
49
52
|
"types": "./dist/faucet/index.d.mts",
|
|
50
|
-
"import": "./dist/faucet/index.mjs"
|
|
53
|
+
"import": "./dist/faucet/index.mjs",
|
|
54
|
+
"default": "./dist/faucet/index.mjs"
|
|
51
55
|
},
|
|
52
56
|
"./graphql": {
|
|
53
57
|
"types": "./dist/graphql/index.d.mts",
|
|
54
|
-
"import": "./dist/graphql/index.mjs"
|
|
58
|
+
"import": "./dist/graphql/index.mjs",
|
|
59
|
+
"default": "./dist/graphql/index.mjs"
|
|
55
60
|
},
|
|
56
61
|
"./grpc": {
|
|
57
62
|
"types": "./dist/grpc/index.d.mts",
|
|
58
|
-
"import": "./dist/grpc/index.mjs"
|
|
63
|
+
"import": "./dist/grpc/index.mjs",
|
|
64
|
+
"default": "./dist/grpc/index.mjs"
|
|
59
65
|
},
|
|
60
66
|
"./jsonRpc": {
|
|
61
67
|
"types": "./dist/jsonRpc/index.d.mts",
|
|
62
|
-
"import": "./dist/jsonRpc/index.mjs"
|
|
68
|
+
"import": "./dist/jsonRpc/index.mjs",
|
|
69
|
+
"default": "./dist/jsonRpc/index.mjs"
|
|
63
70
|
},
|
|
64
71
|
"./keypairs/ed25519": {
|
|
65
72
|
"types": "./dist/keypairs/ed25519/index.d.mts",
|
|
66
|
-
"import": "./dist/keypairs/ed25519/index.mjs"
|
|
73
|
+
"import": "./dist/keypairs/ed25519/index.mjs",
|
|
74
|
+
"default": "./dist/keypairs/ed25519/index.mjs"
|
|
67
75
|
},
|
|
68
76
|
"./keypairs/secp256k1": {
|
|
69
77
|
"types": "./dist/keypairs/secp256k1/index.d.mts",
|
|
70
|
-
"import": "./dist/keypairs/secp256k1/index.mjs"
|
|
78
|
+
"import": "./dist/keypairs/secp256k1/index.mjs",
|
|
79
|
+
"default": "./dist/keypairs/secp256k1/index.mjs"
|
|
71
80
|
},
|
|
72
81
|
"./keypairs/secp256r1": {
|
|
73
82
|
"types": "./dist/keypairs/secp256r1/index.d.mts",
|
|
74
|
-
"import": "./dist/keypairs/secp256r1/index.mjs"
|
|
83
|
+
"import": "./dist/keypairs/secp256r1/index.mjs",
|
|
84
|
+
"default": "./dist/keypairs/secp256r1/index.mjs"
|
|
75
85
|
},
|
|
76
86
|
"./keypairs/passkey": {
|
|
77
87
|
"types": "./dist/keypairs/passkey/index.d.mts",
|
|
78
|
-
"import": "./dist/keypairs/passkey/index.mjs"
|
|
88
|
+
"import": "./dist/keypairs/passkey/index.mjs",
|
|
89
|
+
"default": "./dist/keypairs/passkey/index.mjs"
|
|
79
90
|
},
|
|
80
91
|
"./multisig": {
|
|
81
92
|
"types": "./dist/multisig/index.d.mts",
|
|
82
|
-
"import": "./dist/multisig/index.mjs"
|
|
93
|
+
"import": "./dist/multisig/index.mjs",
|
|
94
|
+
"default": "./dist/multisig/index.mjs"
|
|
83
95
|
},
|
|
84
96
|
"./transactions": {
|
|
85
97
|
"types": "./dist/transactions/index.d.mts",
|
|
86
|
-
"import": "./dist/transactions/index.mjs"
|
|
98
|
+
"import": "./dist/transactions/index.mjs",
|
|
99
|
+
"default": "./dist/transactions/index.mjs"
|
|
87
100
|
},
|
|
88
101
|
"./utils": {
|
|
89
102
|
"types": "./dist/utils/index.d.mts",
|
|
90
|
-
"import": "./dist/utils/index.mjs"
|
|
103
|
+
"import": "./dist/utils/index.mjs",
|
|
104
|
+
"default": "./dist/utils/index.mjs"
|
|
91
105
|
},
|
|
92
106
|
"./verify": {
|
|
93
107
|
"types": "./dist/verify/index.d.mts",
|
|
94
|
-
"import": "./dist/verify/index.mjs"
|
|
108
|
+
"import": "./dist/verify/index.mjs",
|
|
109
|
+
"default": "./dist/verify/index.mjs"
|
|
95
110
|
},
|
|
96
111
|
"./zklogin": {
|
|
97
112
|
"types": "./dist/zklogin/index.d.mts",
|
|
98
|
-
"import": "./dist/zklogin/index.mjs"
|
|
113
|
+
"import": "./dist/zklogin/index.mjs",
|
|
114
|
+
"default": "./dist/zklogin/index.mjs"
|
|
99
115
|
},
|
|
100
116
|
"./graphql/schema": {
|
|
101
117
|
"types": "./dist/graphql/schema/index.d.mts",
|
|
102
|
-
"import": "./dist/graphql/schema/index.mjs"
|
|
118
|
+
"import": "./dist/graphql/schema/index.mjs",
|
|
119
|
+
"default": "./dist/graphql/schema/index.mjs"
|
|
103
120
|
}
|
|
104
121
|
},
|
|
105
122
|
"repository": {
|
|
@@ -151,8 +168,8 @@
|
|
|
151
168
|
"graphql": "^16.12.0",
|
|
152
169
|
"poseidon-lite": "0.2.1",
|
|
153
170
|
"valibot": "^1.2.0",
|
|
154
|
-
"@mysten/bcs": "^2.0.
|
|
155
|
-
"@mysten/utils": "^0.3.
|
|
171
|
+
"@mysten/bcs": "^2.0.2",
|
|
172
|
+
"@mysten/utils": "^0.3.1"
|
|
156
173
|
},
|
|
157
174
|
"scripts": {
|
|
158
175
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
package/src/utils/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { isValidSuiNSName } from './suins.js';
|
|
5
|
+
import { isValidStructTag } from './sui-types.js';
|
|
5
6
|
|
|
6
7
|
/** The pattern to find an optionally versioned name */
|
|
7
8
|
const NAME_PATTERN = /^([a-z0-9]+(?:-[a-z0-9]+)*)$/;
|
|
@@ -29,8 +30,7 @@ export const isValidNamedPackage = (name: string): boolean => {
|
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* Checks if a type contains valid named packages.
|
|
33
|
-
* This DOES NOT check if the type is a valid Move type.
|
|
33
|
+
* Checks if a type contains valid named packages and is a valid Move struct tag.
|
|
34
34
|
*/
|
|
35
35
|
export const isValidNamedType = (type: string): boolean => {
|
|
36
36
|
// split our type by all possible type delimeters.
|
|
@@ -38,6 +38,5 @@ export const isValidNamedType = (type: string): boolean => {
|
|
|
38
38
|
for (const t of splitType) {
|
|
39
39
|
if (t.includes(NAME_SEPARATOR) && !isValidNamedPackage(t)) return false;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
return true;
|
|
41
|
+
return isValidStructTag(type);
|
|
43
42
|
};
|
package/src/utils/sui-types.ts
CHANGED
|
@@ -32,6 +32,63 @@ export function isValidSuiObjectId(value: string): boolean {
|
|
|
32
32
|
return isValidSuiAddress(value);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const MOVE_IDENTIFIER_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;
|
|
36
|
+
|
|
37
|
+
export function isValidMoveIdentifier(name: string): boolean {
|
|
38
|
+
return MOVE_IDENTIFIER_REGEX.test(name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const PRIMITIVE_TYPE_TAGS = [
|
|
42
|
+
'bool',
|
|
43
|
+
'u8',
|
|
44
|
+
'u16',
|
|
45
|
+
'u32',
|
|
46
|
+
'u64',
|
|
47
|
+
'u128',
|
|
48
|
+
'u256',
|
|
49
|
+
'address',
|
|
50
|
+
'signer',
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const VECTOR_TYPE_REGEX = /^vector<(.+)>$/;
|
|
54
|
+
|
|
55
|
+
function isValidTypeTag(type: string): boolean {
|
|
56
|
+
if (PRIMITIVE_TYPE_TAGS.includes(type)) return true;
|
|
57
|
+
|
|
58
|
+
const vectorMatch = type.match(VECTOR_TYPE_REGEX);
|
|
59
|
+
if (vectorMatch) return isValidTypeTag(vectorMatch[1]);
|
|
60
|
+
|
|
61
|
+
if (type.includes('::')) return isValidStructTag(type);
|
|
62
|
+
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isValidParsedStructTag(tag: StructTag): boolean {
|
|
67
|
+
if (!isValidSuiAddress(tag.address) && !isValidNamedPackage(tag.address)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!isValidMoveIdentifier(tag.module) || !isValidMoveIdentifier(tag.name)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return tag.typeParams.every((param) => {
|
|
76
|
+
if (typeof param === 'string') {
|
|
77
|
+
return isValidTypeTag(param);
|
|
78
|
+
}
|
|
79
|
+
return isValidParsedStructTag(param);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isValidStructTag(type: string): boolean {
|
|
84
|
+
try {
|
|
85
|
+
const tag = parseStructTag(type);
|
|
86
|
+
return isValidParsedStructTag(tag);
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
35
92
|
export type StructTag = {
|
|
36
93
|
address: string;
|
|
37
94
|
module: string;
|
package/src/version.ts
CHANGED