@mysten/sui 2.15.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bcs/bcs.d.mts +6 -6
  3. package/dist/bcs/index.d.mts +20 -20
  4. package/dist/client/mvr.d.mts.map +1 -1
  5. package/dist/client/mvr.mjs +3 -0
  6. package/dist/client/mvr.mjs.map +1 -1
  7. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  8. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  9. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  10. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  11. package/dist/transactions/Transaction.d.mts +9 -9
  12. package/dist/transactions/data/internal.d.mts +109 -109
  13. package/dist/transactions/data/internal.d.mts.map +1 -1
  14. package/dist/transactions/data/v1.d.mts +220 -220
  15. package/dist/transactions/data/v1.d.mts.map +1 -1
  16. package/dist/transactions/data/v2.d.mts +16 -16
  17. package/dist/transactions/data/v2.d.mts.map +1 -1
  18. package/dist/utils/format.d.mts +5 -1
  19. package/dist/utils/format.d.mts.map +1 -1
  20. package/dist/utils/format.mjs +19 -1
  21. package/dist/utils/format.mjs.map +1 -1
  22. package/dist/utils/index.d.mts +2 -2
  23. package/dist/utils/index.mjs +2 -2
  24. package/dist/version.mjs +2 -2
  25. package/dist/version.mjs.map +1 -1
  26. package/dist/zklogin/bcs.d.mts +14 -14
  27. package/dist/zklogin/bcs.d.mts.map +1 -1
  28. package/docs/llms-index.md +5 -5
  29. package/docs/utils/index.md +7 -0
  30. package/package.json +1 -1
  31. package/src/client/mvr.ts +12 -0
  32. package/src/utils/format.ts +36 -0
  33. package/src/utils/index.ts +1 -1
  34. package/src/version.ts +2 -2
@@ -1,3 +1,5 @@
1
+ import { SUI_DECIMALS } from "./constants.mjs";
2
+
1
3
  //#region src/utils/format.ts
2
4
  const ELLIPSIS = "…";
3
5
  function formatAddress(address) {
@@ -8,7 +10,23 @@ function formatAddress(address) {
8
10
  function formatDigest(digest) {
9
11
  return `${digest.slice(0, 10)}${ELLIPSIS}`;
10
12
  }
13
+ const AMOUNT_REGEX = /^-?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)$/;
14
+ /** Parse a decimal string into its smallest-unit bigint representation. No floating point. */
15
+ function parseToUnits(amount, decimals) {
16
+ if (decimals < 0 || !Number.isInteger(decimals)) throw new Error(`Invalid decimals: ${decimals}`);
17
+ if (!AMOUNT_REGEX.test(amount)) throw new Error(`Invalid amount: "${amount}"`);
18
+ const negative = amount.startsWith("-");
19
+ const [whole, fraction = ""] = (negative ? amount.slice(1) : amount).split(".");
20
+ if (fraction.length > decimals) throw new Error(`Too many decimal places: "${amount}" has ${fraction.length} but max is ${decimals}`);
21
+ const paddedFraction = fraction.padEnd(decimals, "0") || "0";
22
+ const result = BigInt(whole || "0") * 10n ** BigInt(decimals) + BigInt(paddedFraction);
23
+ return negative ? -result : result;
24
+ }
25
+ /** Parse a SUI decimal string into MIST. */
26
+ function parseToMist(amount) {
27
+ return parseToUnits(amount, SUI_DECIMALS);
28
+ }
11
29
 
12
30
  //#endregion
13
- export { formatAddress, formatDigest };
31
+ export { formatAddress, formatDigest, parseToMist, parseToUnits };
14
32
  //# sourceMappingURL=format.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.mjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nconst ELLIPSIS = '\\u{2026}';\n\nexport function formatAddress(address: string) {\n\tif (address.length <= 6) {\n\t\treturn address;\n\t}\n\n\tconst offset = address.startsWith('0x') ? 2 : 0;\n\n\treturn `0x${address.slice(offset, offset + 4)}${ELLIPSIS}${address.slice(-4)}`;\n}\n\nexport function formatDigest(digest: string) {\n\t// Use 10 first characters\n\treturn `${digest.slice(0, 10)}${ELLIPSIS}`;\n}\n"],"mappings":";AAGA,MAAM,WAAW;AAEjB,SAAgB,cAAc,SAAiB;AAC9C,KAAI,QAAQ,UAAU,EACrB,QAAO;CAGR,MAAM,SAAS,QAAQ,WAAW,KAAK,GAAG,IAAI;AAE9C,QAAO,KAAK,QAAQ,MAAM,QAAQ,SAAS,EAAE,GAAG,WAAW,QAAQ,MAAM,GAAG;;AAG7E,SAAgB,aAAa,QAAgB;AAE5C,QAAO,GAAG,OAAO,MAAM,GAAG,GAAG,GAAG"}
1
+ {"version":3,"file":"format.mjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { SUI_DECIMALS } from './constants.js';\n\nconst ELLIPSIS = '\\u{2026}';\n\nexport function formatAddress(address: string) {\n\tif (address.length <= 6) {\n\t\treturn address;\n\t}\n\n\tconst offset = address.startsWith('0x') ? 2 : 0;\n\n\treturn `0x${address.slice(offset, offset + 4)}${ELLIPSIS}${address.slice(-4)}`;\n}\n\nexport function formatDigest(digest: string) {\n\t// Use 10 first characters\n\treturn `${digest.slice(0, 10)}${ELLIPSIS}`;\n}\n\nconst AMOUNT_REGEX = /^-?(?:[0-9]+(?:\\.[0-9]+)?|\\.[0-9]+)$/;\n\n/** Parse a decimal string into its smallest-unit bigint representation. No floating point. */\nexport function parseToUnits(amount: string, decimals: number): bigint {\n\tif (decimals < 0 || !Number.isInteger(decimals)) {\n\t\tthrow new Error(`Invalid decimals: ${decimals}`);\n\t}\n\n\tif (!AMOUNT_REGEX.test(amount)) {\n\t\tthrow new Error(`Invalid amount: \"${amount}\"`);\n\t}\n\n\tconst negative = amount.startsWith('-');\n\tconst stripped = negative ? amount.slice(1) : amount;\n\n\tconst [whole, fraction = ''] = stripped.split('.');\n\n\tif (fraction.length > decimals) {\n\t\tthrow new Error(\n\t\t\t`Too many decimal places: \"${amount}\" has ${fraction.length} but max is ${decimals}`,\n\t\t);\n\t}\n\n\tconst paddedFraction = fraction.padEnd(decimals, '0') || '0';\n\tconst result = BigInt(whole || '0') * 10n ** BigInt(decimals) + BigInt(paddedFraction);\n\n\treturn negative ? -result : result;\n}\n\n/** Parse a SUI decimal string into MIST. */\nexport function parseToMist(amount: string): bigint {\n\treturn parseToUnits(amount, SUI_DECIMALS);\n}\n"],"mappings":";;;AAKA,MAAM,WAAW;AAEjB,SAAgB,cAAc,SAAiB;AAC9C,KAAI,QAAQ,UAAU,EACrB,QAAO;CAGR,MAAM,SAAS,QAAQ,WAAW,KAAK,GAAG,IAAI;AAE9C,QAAO,KAAK,QAAQ,MAAM,QAAQ,SAAS,EAAE,GAAG,WAAW,QAAQ,MAAM,GAAG;;AAG7E,SAAgB,aAAa,QAAgB;AAE5C,QAAO,GAAG,OAAO,MAAM,GAAG,GAAG,GAAG;;AAGjC,MAAM,eAAe;;AAGrB,SAAgB,aAAa,QAAgB,UAA0B;AACtE,KAAI,WAAW,KAAK,CAAC,OAAO,UAAU,SAAS,CAC9C,OAAM,IAAI,MAAM,qBAAqB,WAAW;AAGjD,KAAI,CAAC,aAAa,KAAK,OAAO,CAC7B,OAAM,IAAI,MAAM,oBAAoB,OAAO,GAAG;CAG/C,MAAM,WAAW,OAAO,WAAW,IAAI;CAGvC,MAAM,CAAC,OAAO,WAAW,OAFR,WAAW,OAAO,MAAM,EAAE,GAAG,QAEN,MAAM,IAAI;AAElD,KAAI,SAAS,SAAS,SACrB,OAAM,IAAI,MACT,6BAA6B,OAAO,QAAQ,SAAS,OAAO,cAAc,WAC1E;CAGF,MAAM,iBAAiB,SAAS,OAAO,UAAU,IAAI,IAAI;CACzD,MAAM,SAAS,OAAO,SAAS,IAAI,GAAG,OAAO,OAAO,SAAS,GAAG,OAAO,eAAe;AAEtF,QAAO,WAAW,CAAC,SAAS;;;AAI7B,SAAgB,YAAY,QAAwB;AACnD,QAAO,aAAa,QAAQ,aAAa"}
@@ -1,10 +1,10 @@
1
1
  import { normalizeTypeTag } from "../bcs/type-tag-serializer.mjs";
2
2
  import { SUI_ADDRESS_LENGTH, isValidStructTag, isValidSuiAddress, isValidSuiObjectId, isValidTransactionDigest, normalizeStructTag, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag } from "./sui-types.mjs";
3
- import { formatAddress, formatDigest } from "./format.mjs";
3
+ import { formatAddress, formatDigest, parseToMist, parseToUnits } 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_COIN_REGISTRY_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";
6
6
  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_COIN_REGISTRY_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 };
10
+ export { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_ADDRESS_LENGTH, SUI_CLOCK_OBJECT_ID, SUI_COIN_REGISTRY_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, parseToMist, parseToUnits, toBase58, toBase64, toHex };
@@ -4,8 +4,8 @@ import { SUI_ADDRESS_LENGTH, isValidStructTag, isValidSuiAddress, isValidSuiObje
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_COIN_REGISTRY_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
- import { formatAddress, formatDigest } from "./format.mjs";
7
+ import { formatAddress, formatDigest, parseToMist, parseToUnits } 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_COIN_REGISTRY_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 };
11
+ export { MIST_PER_SUI, MOVE_STDLIB_ADDRESS, SUI_ADDRESS_LENGTH, SUI_CLOCK_OBJECT_ID, SUI_COIN_REGISTRY_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, parseToMist, parseToUnits, toBase58, toBase64, toHex };
package/dist/version.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
- const PACKAGE_VERSION = "2.15.0";
3
- const TARGETED_RPC_VERSION = "1.70.0";
2
+ const PACKAGE_VERSION = "2.16.0";
3
+ const TARGETED_RPC_VERSION = "1.71.0";
4
4
 
5
5
  //#endregion
6
6
  export { PACKAGE_VERSION, TARGETED_RPC_VERSION };
@@ -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.15.0';\nexport const TARGETED_RPC_VERSION = '1.70.0';\n"],"mappings":";AAKA,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB"}
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.16.0';\nexport const TARGETED_RPC_VERSION = '1.71.0';\n"],"mappings":";AAKA,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB"}
@@ -1,31 +1,31 @@
1
- import * as _mysten_bcs810 from "@mysten/bcs";
1
+ import * as _mysten_bcs1118 from "@mysten/bcs";
2
2
  import { InferBcsInput } from "@mysten/bcs";
3
3
 
4
4
  //#region src/zklogin/bcs.d.ts
5
- declare const zkLoginSignature: _mysten_bcs810.BcsStruct<{
6
- inputs: _mysten_bcs810.BcsStruct<{
7
- proofPoints: _mysten_bcs810.BcsStruct<{
8
- a: _mysten_bcs810.BcsType<string[], Iterable<string> & {
5
+ declare const zkLoginSignature: _mysten_bcs1118.BcsStruct<{
6
+ inputs: _mysten_bcs1118.BcsStruct<{
7
+ proofPoints: _mysten_bcs1118.BcsStruct<{
8
+ a: _mysten_bcs1118.BcsType<string[], Iterable<string> & {
9
9
  length: number;
10
10
  }, string>;
11
- b: _mysten_bcs810.BcsType<string[][], Iterable<Iterable<string> & {
11
+ b: _mysten_bcs1118.BcsType<string[][], Iterable<Iterable<string> & {
12
12
  length: number;
13
13
  }> & {
14
14
  length: number;
15
15
  }, string>;
16
- c: _mysten_bcs810.BcsType<string[], Iterable<string> & {
16
+ c: _mysten_bcs1118.BcsType<string[], Iterable<string> & {
17
17
  length: number;
18
18
  }, string>;
19
19
  }, string>;
20
- issBase64Details: _mysten_bcs810.BcsStruct<{
21
- value: _mysten_bcs810.BcsType<string, string, "string">;
22
- indexMod4: _mysten_bcs810.BcsType<number, number, "u8">;
20
+ issBase64Details: _mysten_bcs1118.BcsStruct<{
21
+ value: _mysten_bcs1118.BcsType<string, string, "string">;
22
+ indexMod4: _mysten_bcs1118.BcsType<number, number, "u8">;
23
23
  }, string>;
24
- headerBase64: _mysten_bcs810.BcsType<string, string, "string">;
25
- addressSeed: _mysten_bcs810.BcsType<string, string, "string">;
24
+ headerBase64: _mysten_bcs1118.BcsType<string, string, "string">;
25
+ addressSeed: _mysten_bcs1118.BcsType<string, string, "string">;
26
26
  }, string>;
27
- maxEpoch: _mysten_bcs810.BcsType<string, string | number | bigint, "u64">;
28
- userSignature: _mysten_bcs810.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
27
+ maxEpoch: _mysten_bcs1118.BcsType<string, string | number | bigint, "u64">;
28
+ userSignature: _mysten_bcs1118.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
29
29
  }, string>;
30
30
  type ZkLoginSignature = InferBcsInput<typeof zkLoginSignature>;
31
31
  type ZkLoginSignatureInputs = ZkLoginSignature['inputs'];
@@ -1 +1 @@
1
- {"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/zklogin/bcs.ts"],"mappings":";;;;cAMa,gBAAA,iBAAgB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAkBjB,gBAAA,GAAmB,aAAA,QAAqB,gBAAA;AAAA,KACxC,sBAAA,GAAyB,gBAAA"}
1
+ {"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/zklogin/bcs.ts"],"mappings":";;;;cAMa,gBAAA,kBAAgB,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAkBjB,gBAAA,GAAmB,aAAA,QAAqB,gBAAA;AAAA,KACxC,sBAAA,GAAyB,gBAAA"}
@@ -2,13 +2,13 @@
2
2
 
3
3
  > TypeScript interfaces for Sui
4
4
 
5
- - [Sui TypeScript SDK Quick Start](./index.md): TypeScript SDK for building on the Sui blockchain
5
+ - [Sui TypeScript SDK Quick Start](..md): TypeScript SDK for building on the Sui blockchain
6
6
  - [Install Sui TypeScript SDK](./install.md): Install the @mysten/sui package and configure your
7
7
  project
8
8
  - [LLM Documentation](./llm-docs.md): Give AI agents access to Sui SDK documentation in your project
9
9
  - [Hello Sui](./hello-sui.md): Build your first Sui application with the TypeScript SDK
10
10
  - [Faucet](./faucet.md): Request test SUI tokens from the faucet
11
- - [Sui Clients](./clients/index.md): Choose and configure gRPC, GraphQL, or JSON-RPC clients
11
+ - [Sui Clients](./clients.md): Choose and configure gRPC, GraphQL, or JSON-RPC clients
12
12
  - [Core API](./clients/core.md): Transport-agnostic Core API shared by all Sui clients
13
13
  - [SuiGrpcClient](./clients/grpc.md): Connect to Sui via gRPC with SuiGrpcClient
14
14
  - [SuiGraphQLClient](./clients/graphql.md): Connect to Sui via GraphQL with SuiGraphQLClient
@@ -30,8 +30,8 @@
30
30
  - [Passkey](./cryptography/passkey.md): Use WebAuthn passkeys for Sui transaction signing
31
31
  - [Web Crypto Signer](./cryptography/webcrypto-signer.md): Sign transactions using the Web Crypto
32
32
  API
33
- - [The `@mysten/sui/utils` package](./utils/index.md): Utility functions for addresses, coins, and
34
- common operations
33
+ - [The `@mysten/sui/utils` package](./utils.md): Utility functions for addresses, coins, and common
34
+ operations
35
35
  - [Derived Objects](./utils/derived_objects.md): Compute derived object IDs from parent objects
36
36
  - [BCS](./bcs.md): Binary Canonical Serialization for encoding Sui Move types
37
37
  - [ZkLogin](./zklogin.md): Zero-knowledge authentication with OAuth providers on Sui
@@ -39,7 +39,7 @@
39
39
  strategies
40
40
  - [Transaction Plugins](./plugins.md): Extend transaction building with reusable plugins
41
41
  - [Building SDKs](./sdk-building.md): Build custom SDKs on top of the Sui TypeScript SDK
42
- - [Migrate to 2.0](./migrations/sui-2.0/index.md): Migration guide for Sui TypeScript SDK 2.0
42
+ - [Migrate to 2.0](./migrations/sui-2.0.md): Migration guide for Sui TypeScript SDK 2.0
43
43
  - [Agent Migration Prompt](./migrations/sui-2.0/agent-prompt.md): AI agent prompt for automated SDK
44
44
  2.0 migration
45
45
  - [@mysten/sui](./migrations/sui-2.0/sui.md): Migrate @mysten/sui from 1.x to 2.0
@@ -31,6 +31,13 @@ You can use the following helpers to format various values:
31
31
  - `normalizeSuiNSName`
32
32
  - `normalizeSuiNSName`
33
33
 
34
+ ## Parsers
35
+
36
+ You can use the following helpers to parse decimal strings into smallest-unit bigints:
37
+
38
+ - `parseToUnits`: Parse a decimal string into a `bigint`, given a coin's `decimals`
39
+ - `parseToMist`: Parse a SUI decimal string into MIST (9 decimals)
40
+
34
41
  ## Validators
35
42
 
36
43
  You can use the following helpers to validate the format of various values (this only validates that
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.15.0",
6
+ "version": "2.16.0",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [
package/src/client/mvr.ts CHANGED
@@ -332,6 +332,10 @@ function validateOverrides(overrides?: {
332
332
  export function extractMvrTypes(type: string | StructTag, types = new Set<string>()) {
333
333
  if (typeof type === 'string' && !hasMvrName(type)) return types;
334
334
 
335
+ if (typeof type === 'string' && type.startsWith('vector<') && type.endsWith('>')) {
336
+ return extractMvrTypes(type.slice(7, -1), types);
337
+ }
338
+
335
339
  const tag = isStructTag(type) ? type : parseStructTag(type);
336
340
 
337
341
  if (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);
@@ -348,6 +352,14 @@ export function extractMvrTypes(type: string | StructTag, types = new Set<string
348
352
  * based on the supplied type cache.
349
353
  */
350
354
  function replaceMvrNames(tag: string | StructTag, typeCache: Record<string, string>): string {
355
+ if (typeof tag === 'string' && !tag.includes('::')) {
356
+ return tag;
357
+ }
358
+
359
+ if (typeof tag === 'string' && tag.startsWith('vector<') && tag.endsWith('>')) {
360
+ return `vector<${replaceMvrNames(tag.slice(7, -1), typeCache)}>`;
361
+ }
362
+
351
363
  const type = isStructTag(tag) ? tag : parseStructTag(tag);
352
364
 
353
365
  const typeTag = `${type.address}::${type.module}::${type.name}`;
@@ -1,6 +1,8 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { SUI_DECIMALS } from './constants.js';
5
+
4
6
  const ELLIPSIS = '\u{2026}';
5
7
 
6
8
  export function formatAddress(address: string) {
@@ -17,3 +19,37 @@ export function formatDigest(digest: string) {
17
19
  // Use 10 first characters
18
20
  return `${digest.slice(0, 10)}${ELLIPSIS}`;
19
21
  }
22
+
23
+ const AMOUNT_REGEX = /^-?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)$/;
24
+
25
+ /** Parse a decimal string into its smallest-unit bigint representation. No floating point. */
26
+ export function parseToUnits(amount: string, decimals: number): bigint {
27
+ if (decimals < 0 || !Number.isInteger(decimals)) {
28
+ throw new Error(`Invalid decimals: ${decimals}`);
29
+ }
30
+
31
+ if (!AMOUNT_REGEX.test(amount)) {
32
+ throw new Error(`Invalid amount: "${amount}"`);
33
+ }
34
+
35
+ const negative = amount.startsWith('-');
36
+ const stripped = negative ? amount.slice(1) : amount;
37
+
38
+ const [whole, fraction = ''] = stripped.split('.');
39
+
40
+ if (fraction.length > decimals) {
41
+ throw new Error(
42
+ `Too many decimal places: "${amount}" has ${fraction.length} but max is ${decimals}`,
43
+ );
44
+ }
45
+
46
+ const paddedFraction = fraction.padEnd(decimals, '0') || '0';
47
+ const result = BigInt(whole || '0') * 10n ** BigInt(decimals) + BigInt(paddedFraction);
48
+
49
+ return negative ? -result : result;
50
+ }
51
+
52
+ /** Parse a SUI decimal string into MIST. */
53
+ export function parseToMist(amount: string): bigint {
54
+ return parseToUnits(amount, SUI_DECIMALS);
55
+ }
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export { formatAddress, formatDigest } from './format.js';
4
+ export { formatAddress, formatDigest, parseToUnits, parseToMist } from './format.js';
5
5
  export {
6
6
  isValidStructTag,
7
7
  isValidSuiAddress,
package/src/version.ts CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  // This file is generated by genversion.mjs. Do not edit it directly.
5
5
 
6
- export const PACKAGE_VERSION = '2.15.0';
7
- export const TARGETED_RPC_VERSION = '1.70.0';
6
+ export const PACKAGE_VERSION = '2.16.0';
7
+ export const TARGETED_RPC_VERSION = '1.71.0';