@mysten/sui 2.20.0 → 2.20.1

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 (32) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/bcs/index.d.mts +20 -20
  3. package/dist/cryptography/signature.d.mts +6 -6
  4. package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
  5. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  6. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  7. package/dist/grpc/proto/sui/rpc/v2/name_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/subscription_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 +3 -3
  12. package/dist/transactions/intents/CoinWithBalance.d.mts.map +1 -1
  13. package/dist/transactions/intents/CoinWithBalance.mjs +7 -3
  14. package/dist/transactions/intents/CoinWithBalance.mjs.map +1 -1
  15. package/dist/version.mjs +1 -1
  16. package/dist/version.mjs.map +1 -1
  17. package/docs/cryptography/index.md +225 -0
  18. package/docs/cryptography/keypairs.md +36 -143
  19. package/docs/cryptography/signers/aws-kms.md +110 -0
  20. package/docs/cryptography/signers/gcp-kms.md +91 -0
  21. package/docs/cryptography/signers/index.md +78 -0
  22. package/docs/cryptography/signers/ledger.md +76 -0
  23. package/docs/cryptography/{multisig.md → signers/multisig.md} +2 -2
  24. package/docs/cryptography/{passkey.md → signers/passkey.md} +1 -1
  25. package/docs/cryptography/{webcrypto-signer.md → signers/webcrypto.md} +6 -6
  26. package/docs/index.md +4 -5
  27. package/docs/llms-index.md +9 -4
  28. package/docs/migrations/sui-2.0/index.md +14 -1
  29. package/docs/zklogin.md +2 -2
  30. package/package.json +1 -1
  31. package/src/transactions/intents/CoinWithBalance.ts +21 -6
  32. package/src/version.ts +1 -1
@@ -0,0 +1,78 @@
1
+ # Signers
2
+
3
+ > Signer implementations beyond keypairs — cloud KMS, Ledger, Web Crypto, passkeys, and multisig
4
+
5
+ In addition to the in-process [keypairs](/sui/cryptography/keypairs) built into `@mysten/sui`, the
6
+ SDK ecosystem ships more implementations of the [`Signer`](/sui/cryptography) interface. Some keep
7
+ the private key outside your application — in a cloud key-management service (KMS), on a hardware
8
+ wallet, or as a non-extractable browser key — while others, like
9
+ [multisig](/sui/cryptography/signers/multisig), combine several signers together. Because each one
10
+ extends the same `Signer` base class, it works anywhere a keypair does.
11
+
12
+ ## External signers
13
+
14
+ These signers hold the key material outside your process. Each is published as its **own package**,
15
+ so you install only the one you need:
16
+
17
+ | Signer | Package | Scheme | Key lives in |
18
+ | ----------------- | -------------------------- | ---------------------- | --------------------------------------------------------------- |
19
+ | `AwsKmsSigner` | `@mysten/aws-kms-signer` | Secp256k1 or Secp256r1 | [AWS KMS](/sui/cryptography/signers/aws-kms) |
20
+ | `GcpKmsSigner` | `@mysten/gcp-kms-signer` | Secp256k1 or Secp256r1 | [GCP KMS](/sui/cryptography/signers/gcp-kms) |
21
+ | `LedgerSigner` | `@mysten/ledger-signer` | Ed25519 | [Ledger hardware wallet](/sui/cryptography/signers/ledger) |
22
+ | `WebCryptoSigner` | `@mysten/webcrypto-signer` | Secp256r1 | [Browser Web Crypto store](/sui/cryptography/signers/webcrypto) |
23
+
24
+ For the AWS and GCP signers, the curve of the underlying KMS key determines the signature scheme
25
+ (`ECC_NIST_P256` → `Secp256r1`, `ECC_SECG_P256K1` → `Secp256k1`).
26
+
27
+ > Each signer above is its own npm package — import directly from `@mysten/aws-kms-signer`,
28
+ > `@mysten/ledger-signer`, and so on, and depend only on the ones you use. The `@mysten/signers`
29
+ > package is a convenience umbrella that re-exports all four under subpaths (`@mysten/signers/aws`,
30
+ > `@mysten/signers/gcp`, `@mysten/signers/ledger`, `@mysten/signers/webcrypto`) if you would rather
31
+ > depend on a single package. The individual pages below use the standalone packages.
32
+
33
+ ## Other Signer implementations
34
+
35
+ Two more `Signer` implementations live in `@mysten/sui` itself rather than in a standalone package:
36
+
37
+ - **[Passkey](/sui/cryptography/signers/passkey)**: sign with a WebAuthn passkey (biometric or
38
+ platform authenticator) through `PasskeyKeypair`.
39
+ - **[Multi-signature](/sui/cryptography/signers/multisig)**: combine signatures from several public
40
+ keys under a configurable threshold with `MultiSigPublicKey`. Its `getSigner` method returns a
41
+ `MultiSigSigner` you can use anywhere a keypair works. The underlying keys can be keypairs, KMS
42
+ signers, passkeys, or zkLogin identifiers.
43
+
44
+ ## Shared interface
45
+
46
+ Because every signer extends `Signer`, the signing API is identical regardless of where the key is
47
+ held; only the way you construct the signer differs:
48
+
49
+ ```typescript
50
+ // Derive the address
51
+ const address = signer.getPublicKey().toSuiAddress();
52
+
53
+ // Sign a personal message
54
+ const message = new TextEncoder().encode('hello world');
55
+ const { signature } = await signer.signPersonalMessage(message);
56
+
57
+ // Sign and execute a transaction (resolves to a discriminated union)
58
+ const result = await client.signAndExecuteTransaction({ transaction, signer });
59
+ if (result.FailedTransaction) {
60
+ throw new Error('Transaction failed to execute');
61
+ }
62
+ console.log(result.Transaction.digest);
63
+ ```
64
+
65
+ See [Cryptography](/sui/cryptography) for the full signing and verification API that all signers
66
+ share.
67
+
68
+ ## Construction
69
+
70
+ Each external signer exposes a static factory rather than a public constructor, because preparing
71
+ the signer requires an async round-trip to fetch the public key from the KMS or device:
72
+
73
+ - `AwsKmsSigner.fromKeyId(keyId, options)`. See [AWS KMS Signer](/sui/cryptography/signers/aws-kms).
74
+ - `GcpKmsSigner.fromOptions(options)`. See [GCP KMS Signer](/sui/cryptography/signers/gcp-kms).
75
+ - `LedgerSigner.fromDerivationPath(path, ledgerClient, suiClient)`. See
76
+ [Ledger Signer](/sui/cryptography/signers/ledger).
77
+ - `WebCryptoSigner.generate()` and `WebCryptoSigner.import(exported)`. See
78
+ [Web Crypto Signer](/sui/cryptography/signers/webcrypto).
@@ -0,0 +1,76 @@
1
+ # Ledger Signer
2
+
3
+ > Sign Sui transactions with a Ledger hardware wallet
4
+
5
+ The `LedgerSigner` signs Sui transactions and personal messages with a
6
+ [Ledger](https://www.ledger.com/) hardware wallet. The private key never leaves the device; you
7
+ confirm each signature on the Ledger. The Ledger signer uses the `Ed25519` scheme.
8
+
9
+ ## Installation
10
+
11
+ ```sh npm2yarn
12
+ npm i @mysten/ledger-signer @mysten/ledgerjs-hw-app-sui
13
+ ```
14
+
15
+ You also need a
16
+ [Ledger transport](https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs) for your
17
+ environment, for example `@ledgerhq/hw-transport-node-hid` in Node.js or
18
+ `@ledgerhq/hw-transport-webhid` in the browser.
19
+
20
+ ## Creating a signer
21
+
22
+ Open a transport, wrap it in a `SuiLedgerClient`, then construct the signer with
23
+ `LedgerSigner.fromDerivationPath`. This is async: it fetches the public key from the device so the
24
+ signer can derive the Sui address.
25
+
26
+ ```typescript
27
+
28
+ const transport = await Transport.open(undefined);
29
+ const ledgerClient = new SuiLedgerClient(transport);
30
+ const suiClient = new SuiGrpcClient({
31
+ network: 'testnet',
32
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
33
+ });
34
+
35
+ const signer = await LedgerSigner.fromDerivationPath(
36
+ "m/44'/784'/0'/0'/0'",
37
+ ledgerClient,
38
+ suiClient,
39
+ );
40
+ ```
41
+
42
+ ### Parameters
43
+
44
+ `fromDerivationPath(derivationPath, ledgerClient, suiClient)`
45
+
46
+ | Parameter | Type | Description |
47
+ | ---------------- | ------------------- | ----------------------------------------------------- |
48
+ | `derivationPath` | `string` | BIP-32 derivation path (Sui uses coin type `784`) |
49
+ | `ledgerClient` | `SuiLedgerClient` | A `SuiLedgerClient` wrapping an open Ledger transport |
50
+ | `suiClient` | `ClientWithCoreApi` | A Sui client used to resolve transaction data |
51
+
52
+ ## Usage
53
+
54
+ Derive the address, then sign a transaction or personal message. The user confirms each signature on
55
+ the device.
56
+
57
+ ```typescript
58
+
59
+ // Derive the Sui address
60
+ const address = signer.toSuiAddress();
61
+
62
+ // Build and sign a transaction
63
+ const transaction = new Transaction();
64
+ const transactionBytes = await transaction.build({ client: suiClient });
65
+ const { signature } = await signer.signTransaction(transactionBytes);
66
+
67
+ // Or sign a personal message
68
+ const message = new TextEncoder().encode('Hello, Ledger Signer!');
69
+ await signer.signPersonalMessage(message);
70
+ ```
71
+
72
+ > **Warning:** The Ledger signer supports only `signTransaction` and `signPersonalMessage`. It does not support
73
+ > the generic `sign` and `signWithIntent` methods, which throw an error because the device only
74
+ > signs recognized transaction and message payloads.
75
+
76
+ See [Cryptography](/sui/cryptography) for the signing and verification API shared by all signers.
@@ -6,8 +6,8 @@ The Sui TypeScript SDK provides a `MultiSigPublicKey` class to support
6
6
  [Multi-Signature](https://docs.sui.io/concepts/cryptography/transaction-auth/multisig) (MultiSig)
7
7
  transaction and personal message signing.
8
8
 
9
- This class implements the same interface as the `PublicKey` classes that [Keypairs](./keypairs) uses
10
- and you call the same methods to verify signatures for `PersonalMessages` and `Transactions`.
9
+ This class implements the same interface as the `PublicKey` classes that [Keypairs](../keypairs)
10
+ uses and you call the same methods to verify signatures for `PersonalMessages` and `Transactions`.
11
11
 
12
12
  ## Creating a MultiSigPublicKey
13
13
 
@@ -90,7 +90,7 @@ work.
90
90
 
91
91
  The usage for a passkey keypair is the same as any other keypair. You can derive the public key,
92
92
  derive the address, sign personal messages, sign transactions, and verify signatures. See the
93
- [Key pairs](./keypairs) documentation for more details.
93
+ [Key pairs](../keypairs) documentation for more details.
94
94
 
95
95
  ```typescript
96
96
  const publicKey = keypair.getPublicKey();
@@ -1,13 +1,13 @@
1
1
  # Web Crypto Signer
2
2
 
3
- > Sign transactions using the Web Crypto API for secure browser-based key management.
3
+ > Sign transactions using the Web Crypto API for secure browser-based key management
4
4
 
5
5
  For cases where you need to create keypairs directly within client apps, you can use the Web Crypto
6
6
  Signer. This signer leverages the
7
7
  [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) to provide a
8
- secure and efficient way to generate and manage cryptographic keys in the browser. The generated
9
- keys are `Secp256r1` keys which can be persisted between sessions, and are not extractable by
10
- client-side code (including extensions).
8
+ secure and efficient way to generate and manage cryptographic keys in the browser. It generates
9
+ `Secp256r1` keys that you can persist between sessions, and that client-side code (including
10
+ extensions) cannot extract.
11
11
 
12
12
  Common use cases for the Web Crypto Signer include:
13
13
 
@@ -68,8 +68,8 @@ const keypair = await WebCryptoSigner.import(exported);
68
68
  ## Usage
69
69
 
70
70
  The usage for a Web Crypto signer is the same as any other keypair. You can derive the public key,
71
- derive the address, sign personal messages, sign transactions, and verify signatures. See the
72
- [Key pairs](./keypairs) documentation for more details.
71
+ derive the address, sign personal messages, sign transactions, and verify signatures. See
72
+ [Cryptography](/sui/cryptography) for more details.
73
73
 
74
74
  ```typescript
75
75
  const publicKey = keypair.getPublicKey();
package/docs/index.md CHANGED
@@ -34,11 +34,10 @@ what you need to keep your code light and compact.
34
34
  with transactions.
35
35
  - [`@mysten/sui/keypairs/*`](/sui/cryptography/keypairs): Modular exports for specific KeyPair
36
36
  implementations.
37
- - [`@mysten/sui/verify`](/sui/cryptography/keypairs#verifying-signatures-without-a-key-pair):
38
- Methods for verifying transactions and messages.
39
- - [`@mysten/sui/cryptography`](/sui/cryptography/keypairs): Shared types and classes for
40
- cryptography.
41
- - [`@mysten/sui/multisig`](/sui/cryptography/multisig): Utilities for working with multisig
37
+ - [`@mysten/sui/verify`](/sui/cryptography#verifying-signatures): Methods for verifying transactions
38
+ and messages.
39
+ - [`@mysten/sui/cryptography`](/sui/cryptography): Shared types and classes for cryptography.
40
+ - [`@mysten/sui/multisig`](/sui/cryptography/signers/multisig): Utilities for working with multisig
42
41
  signatures.
43
42
  - [`@mysten/sui/utils`](/sui/utils): Utilities for formatting and parsing various Sui types.
44
43
  - [`@mysten/sui/faucet`](#faucet): Methods for requesting SUI from a faucet.
@@ -13,10 +13,15 @@
13
13
  - [Coins and Balances](./transactions/coins-and-balances.md): Work with coin objects and address balances in transactions
14
14
  - [Commands and Inputs Reference](./transactions/reference.md): Complete reference for transaction commands and input types
15
15
  - [Building Offline](./transactions/offline.md): Build transactions without a network connection
16
- - [Key pairs](./cryptography/keypairs.md): Create and manage Ed25519, Secp256k1, and Secp256r1 keypairs for Sui transaction signing.
17
- - [Multi-Signature Transactions](./cryptography/multisig.md): Create multi-signature transactions with multiple signers on Sui.
18
- - [Passkey](./cryptography/passkey.md): Use WebAuthn passkeys for Sui transaction signing.
19
- - [Web Crypto Signer](./cryptography/webcrypto-signer.md): Sign transactions using the Web Crypto API for secure browser-based key management.
16
+ - [Cryptography](./cryptography.md): Sign and verify Sui transactions and messages with keypairs and external signers
17
+ - [Key pairs](./cryptography/keypairs.md): Create Ed25519, Secp256k1, and Secp256r1 keypairs and derive them from mnemonics and secret keys
18
+ - [Signers](./cryptography/signers.md): Signer implementations beyond keypairs cloud KMS, Ledger, Web Crypto, passkeys, and multisig
19
+ - [AWS KMS Signer](./cryptography/signers/aws-kms.md): Sign Sui transactions with a key stored in AWS Key Management Service
20
+ - [GCP KMS Signer](./cryptography/signers/gcp-kms.md): Sign Sui transactions with a key stored in Google Cloud Key Management Service
21
+ - [Ledger Signer](./cryptography/signers/ledger.md): Sign Sui transactions with a Ledger hardware wallet
22
+ - [Web Crypto Signer](./cryptography/signers/webcrypto.md): Sign transactions using the Web Crypto API for secure browser-based key management
23
+ - [Passkey](./cryptography/signers/passkey.md): Use WebAuthn passkeys for Sui transaction signing.
24
+ - [Multi-Signature Transactions](./cryptography/signers/multisig.md): Create multi-signature transactions with multiple signers on Sui.
20
25
  - [The `@mysten/sui/utils` package](./utils.md): Utility functions for addresses, coins, and common operations in the Sui TypeScript SDK.
21
26
  - [Derived Objects](./utils/derived_objects.md): Compute derived object IDs from parent objects for deterministic offline derivation.
22
27
  - [BCS](./bcs.md): Binary Canonical Serialization for encoding Sui Move types.
@@ -155,4 +155,17 @@ For wallet builders and SDK maintainers building on the Sui ecosystem:
155
155
  - **[Wallet builders](/sui/migrations/sui-2.0/wallet-builders):** Guide for wallet implementations
156
156
  adapting to `reportTransactionEffects` removal and new core API response format
157
157
  - **[SDK maintainers](/sui/migrations/sui-2.0/sdk-maintainers):** Guide for SDK authors migrating to
158
- `ClientWithCoreApi` and the new transport-agnostic architecture
158
+ `ClientWithCoreApi` and the new transport-agnostic architecture
159
+
160
+ ## Non-existent objects
161
+
162
+ When migrating from the v1 SDK to the v2 SDK, review any code paths that read objects or dynamic
163
+ fields that may not exist.
164
+
165
+ In v1, methods such as `core.getObject` and `getDynamicField` return `null` when the requested
166
+ object or field does not exist. In v2, the same operations throw an exception instead. Applications
167
+ that previously relied on `null` checks should be updated to handle exceptions appropriately, either
168
+ through try/catch blocks or by validating object existence before attempting to read it.
169
+
170
+ This behavioral change may require updates to error handling logic to avoid unexpected runtime
171
+ failures after migration.
package/docs/zklogin.md CHANGED
@@ -46,8 +46,8 @@ const address = computeZkLoginAddress({
46
46
  });
47
47
  ```
48
48
 
49
- To use zkLogin inside a multisig, see the [Multisig Guide](../sui/cryptography/multisig) for more
50
- details.
49
+ To use zkLogin inside a multisig, see the [Multisig Guide](../sui/cryptography/signers/multisig) for
50
+ more details.
51
51
 
52
52
  ## Legacy addresses
53
53
 
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.20.0",
6
+ "version": "2.20.1",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [
@@ -2,7 +2,19 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { InferInput } from 'valibot';
5
- import { bigint, object, optional, parse, picklist, string } from 'valibot';
5
+ import {
6
+ bigint,
7
+ integer,
8
+ number,
9
+ object,
10
+ optional,
11
+ parse,
12
+ picklist,
13
+ pipe,
14
+ string,
15
+ transform,
16
+ union,
17
+ } from 'valibot';
6
18
 
7
19
  import { bcs } from '../../bcs/index.js';
8
20
  import { normalizeStructTag } from '../../utils/sui-types.js';
@@ -87,9 +99,15 @@ export function createBalance({
87
99
  };
88
100
  }
89
101
 
102
+ // `balance` is a bigint in memory, but serializing a transaction to JSON converts it to a
103
+ // string. When that JSON is deserialized with `Transaction.from`, the value stays a string
104
+ // (the intent `data` is opaque to the transaction schema), so coerce it back to a bigint here.
90
105
  const CoinWithBalanceData = object({
91
106
  type: string(),
92
- balance: bigint(),
107
+ balance: pipe(
108
+ union([bigint(), string(), pipe(number(), integer())]),
109
+ transform((value) => BigInt(value)),
110
+ ),
93
111
  outputKind: optional(picklist(['coin', 'balance'])),
94
112
  });
95
113
 
@@ -208,10 +226,7 @@ export async function resolveCoinBalance(
208
226
  continue;
209
227
  }
210
228
 
211
- const { type, balance } = transaction.$Intent.data as {
212
- type: string;
213
- balance: bigint;
214
- };
229
+ const { type, balance } = parse(CoinWithBalanceData, transaction.$Intent.data);
215
230
  const coinType = type === 'gas' ? SUI_TYPE : type;
216
231
  const totalRequired = totalByType.get(type)!;
217
232
  const addressBalance = addressBalanceByType.get(type) ?? 0n;
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  // This file is generated by genversion.mjs. Do not edit it directly.
5
5
 
6
- export const PACKAGE_VERSION = '2.20.0';
6
+ export const PACKAGE_VERSION = '2.20.1';