@mysten/sui 2.34.0 → 2.36.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 +21 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/bcs.mjs +4 -2
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/index.d.mts +12 -3
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +1 -1
- package/dist/client/types.d.mts +18 -1
- package/dist/client/types.d.mts.map +1 -1
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +10 -1
- package/dist/client/utils.mjs.map +1 -1
- package/dist/cryptography/publickey.mjs +1 -0
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature-scheme.d.mts +4 -1
- package/dist/cryptography/signature-scheme.d.mts.map +1 -1
- package/dist/cryptography/signature-scheme.mjs +6 -3
- package/dist/cryptography/signature-scheme.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/cryptography/signature.mjs +2 -1
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/graphql/client.d.mts +4 -3
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +7 -4
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/queries.mjs +7 -0
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/grpc/client.d.mts +4 -3
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +8 -4
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +7 -4
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/keypairs/mldsa65/index.d.mts +3 -0
- package/dist/keypairs/mldsa65/index.mjs +4 -0
- package/dist/keypairs/mldsa65/keypair.d.mts +67 -0
- package/dist/keypairs/mldsa65/keypair.d.mts.map +1 -0
- package/dist/keypairs/mldsa65/keypair.mjs +91 -0
- package/dist/keypairs/mldsa65/keypair.mjs.map +1 -0
- package/dist/keypairs/mldsa65/publickey.d.mts +37 -0
- package/dist/keypairs/mldsa65/publickey.d.mts.map +1 -0
- package/dist/keypairs/mldsa65/publickey.mjs +64 -0
- package/dist/keypairs/mldsa65/publickey.mjs.map +1 -0
- package/dist/multisig/publickey.d.mts +4 -0
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +7 -6
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +10 -8
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +4 -2
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/utils/constants.d.mts +6 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +6 -1
- package/dist/utils/constants.mjs.map +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +2 -2
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/verify/verify.mjs +4 -0
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/address-seed.d.mts +6 -0
- package/dist/zklogin/address-seed.d.mts.map +1 -0
- package/dist/zklogin/address-seed.mjs +51 -0
- package/dist/zklogin/address-seed.mjs.map +1 -0
- package/dist/zklogin/address.d.mts.map +1 -1
- package/dist/zklogin/address.mjs +2 -1
- package/dist/zklogin/address.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/index.d.mts +2 -1
- package/dist/zklogin/index.mjs +3 -2
- package/dist/zklogin/nonce.mjs +1 -1
- package/dist/zklogin/utils.d.mts +1 -3
- package/dist/zklogin/utils.d.mts.map +1 -1
- package/dist/zklogin/utils.mjs +1 -46
- package/dist/zklogin/utils.mjs.map +1 -1
- package/docs/clients/executing.md +7 -1
- package/docs/cryptography/index.md +7 -6
- package/docs/cryptography/keypairs.md +13 -1
- package/docs/llms-index.md +1 -1
- package/package.json +7 -1
- package/src/bcs/bcs.ts +4 -0
- package/src/client/types.ts +18 -1
- package/src/client/utils.ts +10 -0
- package/src/cryptography/publickey.ts +1 -0
- package/src/cryptography/signature-scheme.ts +4 -1
- package/src/cryptography/signature.ts +1 -0
- package/src/graphql/client.ts +4 -3
- package/src/graphql/core.ts +9 -3
- package/src/graphql/generated/queries.ts +8 -1
- package/src/graphql/queries/transactions.graphql +7 -0
- package/src/grpc/client.ts +4 -3
- package/src/grpc/core.ts +11 -4
- package/src/jsonRpc/core.ts +5 -0
- package/src/keypairs/mldsa65/index.ts +5 -0
- package/src/keypairs/mldsa65/keypair.ts +128 -0
- package/src/keypairs/mldsa65/publickey.ts +95 -0
- package/src/multisig/publickey.ts +13 -9
- package/src/transactions/Transaction.ts +4 -2
- package/src/utils/constants.ts +6 -0
- package/src/utils/index.ts +1 -0
- package/src/verify/verify.ts +4 -0
- package/src/version.ts +1 -1
- package/src/zklogin/address-seed.ts +86 -0
- package/src/zklogin/address.ts +2 -6
- package/src/zklogin/index.ts +1 -2
- package/src/zklogin/utils.ts +0 -83
package/dist/zklogin/nonce.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { poseidonHash } from "./poseidon.mjs";
|
|
2
1
|
import { toPaddedBigEndianBytes } from "./utils.mjs";
|
|
2
|
+
import { poseidonHash } from "./poseidon.mjs";
|
|
3
3
|
import { toHex } from "@mysten/bcs";
|
|
4
4
|
import { randomBytes } from "@noble/hashes/utils.js";
|
|
5
5
|
import { base64urlnopad } from "@scure/base";
|
package/dist/zklogin/utils.d.mts
CHANGED
|
@@ -4,8 +4,6 @@ import { PublicKey } from "../cryptography/publickey.mjs";
|
|
|
4
4
|
declare function toPaddedBigEndianBytes(num: bigint, width: number): Uint8Array;
|
|
5
5
|
declare function toBigEndianBytes(num: bigint, width: number): Uint8Array;
|
|
6
6
|
declare function getExtendedEphemeralPublicKey(publicKey: PublicKey): string;
|
|
7
|
-
declare function hashASCIIStrToField(str: string, maxSize: number): bigint;
|
|
8
|
-
declare function genAddressSeed(salt: string | bigint, name: string, value: string, aud: string, max_name_length?: number, max_value_length?: number, max_aud_length?: number): bigint;
|
|
9
7
|
//#endregion
|
|
10
|
-
export {
|
|
8
|
+
export { getExtendedEphemeralPublicKey, toBigEndianBytes, toPaddedBigEndianBytes };
|
|
11
9
|
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/zklogin/utils.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/zklogin/utils.ts"],"mappings":";;;iBAkBgB,sBAAA,CAAuB,GAAA,UAAa,KAAA,WAAgB,UAAA;AAAA,iBAMpD,gBAAA,CAAiB,GAAA,UAAa,KAAA,WAAgB,UAAA;AAAA,iBAY9C,6BAAA,CAA8B,SAAA,EAAW,SAAA"}
|
package/dist/zklogin/utils.mjs
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { poseidonHash } from "./poseidon.mjs";
|
|
2
1
|
import { hexToBytes } from "@noble/hashes/utils.js";
|
|
3
2
|
|
|
4
3
|
//#region src/zklogin/utils.ts
|
|
5
|
-
const MAX_KEY_CLAIM_NAME_LENGTH = 32;
|
|
6
|
-
const MAX_KEY_CLAIM_VALUE_LENGTH = 115;
|
|
7
|
-
const MAX_AUD_VALUE_LENGTH = 145;
|
|
8
|
-
const PACK_WIDTH = 248;
|
|
9
4
|
function findFirstNonZeroIndex(bytes) {
|
|
10
5
|
for (let i = 0; i < bytes.length; i++) if (bytes[i] !== 0) return i;
|
|
11
6
|
return -1;
|
|
@@ -22,51 +17,11 @@ function toBigEndianBytes(num, width) {
|
|
|
22
17
|
function getExtendedEphemeralPublicKey(publicKey) {
|
|
23
18
|
return publicKey.toSuiPublicKey();
|
|
24
19
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Splits an array into chunks of size chunk_size. If the array is not evenly
|
|
27
|
-
* divisible by chunk_size, the first chunk will be smaller than chunk_size.
|
|
28
|
-
*
|
|
29
|
-
* E.g., arrayChunk([1, 2, 3, 4, 5], 2) => [[1], [2, 3], [4, 5]]
|
|
30
|
-
*
|
|
31
|
-
* Note: Can be made more efficient by avoiding the reverse() calls.
|
|
32
|
-
*/
|
|
33
|
-
function chunkArray(array, chunk_size) {
|
|
34
|
-
const chunks = Array(Math.ceil(array.length / chunk_size));
|
|
35
|
-
const revArray = array.reverse();
|
|
36
|
-
for (let i = 0; i < chunks.length; i++) chunks[i] = revArray.slice(i * chunk_size, (i + 1) * chunk_size).reverse();
|
|
37
|
-
return chunks.reverse();
|
|
38
|
-
}
|
|
39
|
-
function bytesBEToBigInt(bytes) {
|
|
40
|
-
const hex = bytes.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
41
|
-
if (hex.length === 0) return BigInt(0);
|
|
42
|
-
return BigInt("0x" + hex);
|
|
43
|
-
}
|
|
44
|
-
function hashASCIIStrToField(str, maxSize) {
|
|
45
|
-
if (str.length > maxSize) throw new Error(`String ${str} is longer than ${maxSize} chars`);
|
|
46
|
-
return poseidonHash(chunkArray(str.padEnd(maxSize, String.fromCharCode(0)).split("").map((c) => c.charCodeAt(0)), PACK_WIDTH / 8).map((chunk) => bytesBEToBigInt(chunk)));
|
|
47
|
-
}
|
|
48
|
-
function assertNoJsonEscape(value, label) {
|
|
49
|
-
for (let i = 0; i < value.length; i++) {
|
|
50
|
-
const c = value.charCodeAt(i);
|
|
51
|
-
if (c < 32 || c === 34 || c === 92) throw new Error(`zkLogin ${label} contains a JSON-escaped character (code ${c}); the circuit hashes raw JWT bytes, so claim values with escapes are not supported`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function genAddressSeed(salt, name, value, aud, max_name_length = MAX_KEY_CLAIM_NAME_LENGTH, max_value_length = MAX_KEY_CLAIM_VALUE_LENGTH, max_aud_length = MAX_AUD_VALUE_LENGTH) {
|
|
55
|
-
assertNoJsonEscape(name, "key claim name");
|
|
56
|
-
assertNoJsonEscape(value, "key claim value");
|
|
57
|
-
assertNoJsonEscape(aud, "aud");
|
|
58
|
-
return poseidonHash([
|
|
59
|
-
hashASCIIStrToField(name, max_name_length),
|
|
60
|
-
hashASCIIStrToField(value, max_value_length),
|
|
61
|
-
hashASCIIStrToField(aud, max_aud_length),
|
|
62
|
-
poseidonHash([BigInt(salt)])
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
20
|
function normalizeZkLoginIssuer(iss) {
|
|
66
21
|
if (iss === "accounts.google.com") return "https://accounts.google.com";
|
|
67
22
|
return iss;
|
|
68
23
|
}
|
|
69
24
|
|
|
70
25
|
//#endregion
|
|
71
|
-
export {
|
|
26
|
+
export { getExtendedEphemeralPublicKey, normalizeZkLoginIssuer, toBigEndianBytes, toPaddedBigEndianBytes };
|
|
72
27
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/zklogin/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { hexToBytes } from '@noble/hashes/utils.js';\n\nimport type { PublicKey } from '../cryptography/publickey.js';\
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/zklogin/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { hexToBytes } from '@noble/hashes/utils.js';\n\nimport type { PublicKey } from '../cryptography/publickey.js';\n\nfunction findFirstNonZeroIndex(bytes: Uint8Array) {\n\tfor (let i = 0; i < bytes.length; i++) {\n\t\tif (bytes[i] !== 0) {\n\t\t\treturn i;\n\t\t}\n\t}\n\n\treturn -1;\n}\n\n// Derive bytearray from num where the bytearray is padded to the left with 0s to the specified width.\nexport function toPaddedBigEndianBytes(num: bigint, width: number): Uint8Array {\n\tconst hex = num.toString(16);\n\treturn hexToBytes(hex.padStart(width * 2, '0').slice(-width * 2));\n}\n\n// Derive bytearray from num where the bytearray is not padded with 0.\nexport function toBigEndianBytes(num: bigint, width: number): Uint8Array {\n\tconst bytes = toPaddedBigEndianBytes(num, width);\n\n\tconst firstNonZeroIndex = findFirstNonZeroIndex(bytes);\n\n\tif (firstNonZeroIndex === -1) {\n\t\treturn new Uint8Array([0]);\n\t}\n\n\treturn bytes.slice(firstNonZeroIndex);\n}\n\nexport function getExtendedEphemeralPublicKey(publicKey: PublicKey) {\n\treturn publicKey.toSuiPublicKey();\n}\n\nexport function normalizeZkLoginIssuer(iss: string) {\n\tif (iss === 'accounts.google.com') {\n\t\treturn 'https://accounts.google.com';\n\t}\n\treturn iss;\n}\n"],"mappings":";;;AAOA,SAAS,sBAAsB,OAAmB;AACjD,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IACjC,KAAI,MAAM,OAAO,EAChB,QAAO;AAIT,QAAO;;AAIR,SAAgB,uBAAuB,KAAa,OAA2B;AAE9E,QAAO,WADK,IAAI,SAAS,GAAG,CACN,SAAS,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;;AAIlE,SAAgB,iBAAiB,KAAa,OAA2B;CACxE,MAAM,QAAQ,uBAAuB,KAAK,MAAM;CAEhD,MAAM,oBAAoB,sBAAsB,MAAM;AAEtD,KAAI,sBAAsB,GACzB,QAAO,IAAI,WAAW,CAAC,EAAE,CAAC;AAG3B,QAAO,MAAM,MAAM,kBAAkB;;AAGtC,SAAgB,8BAA8B,WAAsB;AACnE,QAAO,UAAU,gBAAgB;;AAGlC,SAAgB,uBAAuB,KAAa;AACnD,KAAI,QAAQ,sBACX,QAAO;AAER,QAAO"}
|
|
@@ -110,4 +110,10 @@ Two further options change how the node runs the simulation:
|
|
|
110
110
|
| Option | Effect |
|
|
111
111
|
| ---------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
112
112
|
| `checksEnabled` | Set `false` to skip transaction validation, so non-public and non-entry functions can be inspected. Defaults to `true` |
|
|
113
|
-
| `doGasSelection` | Overrides whether the
|
|
113
|
+
| `doGasSelection` | gRPC and GraphQL only. Overrides whether the node selects real gas. Defaults to `true` only when gas payment is `[]` |
|
|
114
|
+
|
|
115
|
+
A transaction with no gas payment is simulated with a mocked gas coin, which also funds anything
|
|
116
|
+
drawn from `tx.gas`, so the result validates the transaction and estimates gas but is not a preview
|
|
117
|
+
of what the sender would spend. To simulate with the sender's real gas, set gas coins on the
|
|
118
|
+
transaction, or on gRPC and GraphQL set an empty gas payment and let the node select gas. The
|
|
119
|
+
result's `gasPaymentMocked` field reports which case ran.
|
|
@@ -11,13 +11,14 @@ implementation in detail.
|
|
|
11
11
|
## Signing schemes
|
|
12
12
|
|
|
13
13
|
A signer always produces a signature under a signature scheme, which determines the curve and
|
|
14
|
-
signature format. Sui supports
|
|
14
|
+
signature format. Sui supports four schemes, each with a corresponding `Keypair` class:
|
|
15
15
|
|
|
16
16
|
| Scheme | Class | Import |
|
|
17
17
|
| --------------- | ------------------ | -------------------------------- |
|
|
18
18
|
| Ed25519 | `Ed25519Keypair` | `@mysten/sui/keypairs/ed25519` |
|
|
19
19
|
| ECDSA Secp256k1 | `Secp256k1Keypair` | `@mysten/sui/keypairs/secp256k1` |
|
|
20
20
|
| ECDSA Secp256r1 | `Secp256r1Keypair` | `@mysten/sui/keypairs/secp256r1` |
|
|
21
|
+
| ML-DSA-65 | `MLDSA65Keypair` | `@mysten/sui/keypairs/mldsa65` |
|
|
21
22
|
|
|
22
23
|
For background on the schemes themselves, see the
|
|
23
24
|
[Signatures](https://docs.sui.io/concepts/cryptography/transaction-auth/signatures) concept topic. A
|
|
@@ -31,11 +32,11 @@ so the rest of your code doesn't need to know where the key lives.
|
|
|
31
32
|
|
|
32
33
|
Implementations provide three primitives:
|
|
33
34
|
|
|
34
|
-
| Method | Description
|
|
35
|
-
| ---------------- |
|
|
36
|
-
| `getPublicKey()` | Returns the `PublicKey` for deriving the address and verifying
|
|
37
|
-
| `getKeyScheme()` | Returns the signature scheme (`ED25519`, `Secp256k1`, `Secp256r1`) |
|
|
38
|
-
| `sign(bytes)` | Signs raw bytes and returns the signature
|
|
35
|
+
| Method | Description |
|
|
36
|
+
| ---------------- | ----------------------------------------------------------------------------- |
|
|
37
|
+
| `getPublicKey()` | Returns the `PublicKey` for deriving the address and verifying |
|
|
38
|
+
| `getKeyScheme()` | Returns the signature scheme (`ED25519`, `Secp256k1`, `Secp256r1`, `MLDSA65`) |
|
|
39
|
+
| `sign(bytes)` | Signs raw bytes and returns the signature |
|
|
39
40
|
|
|
40
41
|
On top of those, `Signer` provides the methods you typically call:
|
|
41
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Key pairs
|
|
2
2
|
|
|
3
|
-
> >- Create Ed25519, Secp256k1, and
|
|
3
|
+
> >- Create Ed25519, Secp256k1, Secp256r1, and ML-DSA-65 keypairs and derive them from mnemonics and secret keys
|
|
4
4
|
|
|
5
5
|
A `Keypair` holds a Sui private key in process and signs with it. It is the easiest
|
|
6
6
|
[`Signer`](/sui/cryptography) to use. It is ideal for scripts, backends, and tests where you manage
|
|
@@ -15,6 +15,7 @@ Each signing scheme has a corresponding `Keypair` class:
|
|
|
15
15
|
| Ed25519 | `Ed25519Keypair` | `@mysten/sui/keypairs/ed25519` |
|
|
16
16
|
| ECDSA Secp256k1 | `Secp256k1Keypair` | `@mysten/sui/keypairs/secp256k1` |
|
|
17
17
|
| ECDSA Secp256r1 | `Secp256r1Keypair` | `@mysten/sui/keypairs/secp256r1` |
|
|
18
|
+
| ML-DSA-65 | `MLDSA65Keypair` | `@mysten/sui/keypairs/mldsa65` |
|
|
18
19
|
|
|
19
20
|
To use, import the key pair class your project uses from the `@mysten/sui/keypairs` folder. For
|
|
20
21
|
example, to use the Ed25519 scheme, import the `Ed25519Keypair` class from
|
|
@@ -24,6 +25,17 @@ example, to use the Ed25519 scheme, import the `Ed25519Keypair` class from
|
|
|
24
25
|
|
|
25
26
|
```
|
|
26
27
|
|
|
28
|
+
ML-DSA-65 is the post-quantum scheme from FIPS 204. Its secret key is a 32-byte seed, so it imports
|
|
29
|
+
and exports like the other schemes, but its public keys (1952 bytes) and signatures (3309 bytes) are
|
|
30
|
+
much larger, and every signature is randomized. Deriving an ML-DSA-65 keypair from a mnemonic is not
|
|
31
|
+
supported yet, and the scheme is only accepted by networks where it has been enabled.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
|
|
35
|
+
const keypair = MLDSA65Keypair.generate();
|
|
36
|
+
const restored = MLDSA65Keypair.fromSecretKey(keypair.getSecretKey());
|
|
37
|
+
```
|
|
38
|
+
|
|
27
39
|
## Creating a key pair
|
|
28
40
|
|
|
29
41
|
To create a random key pair (which identifies a Sui address), instantiate a new `Keypair` class. To
|
package/docs/llms-index.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
- [Commands and Inputs Reference](./transactions/reference.md): Complete reference for transaction commands and input types
|
|
17
17
|
- [Building Offline](./transactions/offline.md): Build transactions without a network connection
|
|
18
18
|
- [Cryptography](./cryptography.md): >- Sign and verify Sui transactions and messages with keypairs and external signers
|
|
19
|
-
- [Key pairs](./cryptography/keypairs.md): >- Create Ed25519, Secp256k1, and
|
|
19
|
+
- [Key pairs](./cryptography/keypairs.md): >- Create Ed25519, Secp256k1, Secp256r1, and ML-DSA-65 keypairs and derive them from mnemonics and secret keys
|
|
20
20
|
- [Signers](./cryptography/signers.md): >- Signer implementations beyond keypairs — cloud KMS, Ledger, Web Crypto, passkeys, and multisig
|
|
21
21
|
- [AWS KMS Signer](./cryptography/signers/aws-kms.md): Sign Sui transactions with a key stored in AWS Key Management Service
|
|
22
22
|
- [GCP KMS Signer](./cryptography/signers/gcp-kms.md): Sign Sui transactions with a key stored in Google Cloud Key Management Service
|
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.36.0",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
@@ -89,6 +89,11 @@
|
|
|
89
89
|
"import": "./dist/keypairs/passkey/index.mjs",
|
|
90
90
|
"default": "./dist/keypairs/passkey/index.mjs"
|
|
91
91
|
},
|
|
92
|
+
"./keypairs/mldsa65": {
|
|
93
|
+
"types": "./dist/keypairs/mldsa65/index.d.mts",
|
|
94
|
+
"import": "./dist/keypairs/mldsa65/index.mjs",
|
|
95
|
+
"default": "./dist/keypairs/mldsa65/index.mjs"
|
|
96
|
+
},
|
|
92
97
|
"./multisig": {
|
|
93
98
|
"types": "./dist/multisig/index.d.mts",
|
|
94
99
|
"import": "./dist/multisig/index.mjs",
|
|
@@ -158,6 +163,7 @@
|
|
|
158
163
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
159
164
|
"@noble/curves": "^2.3.0",
|
|
160
165
|
"@noble/hashes": "^2.3.0",
|
|
166
|
+
"@noble/post-quantum": "^0.7.1",
|
|
161
167
|
"@protobuf-ts/grpcweb-transport": "^2.11.1",
|
|
162
168
|
"@protobuf-ts/runtime": "^2.11.1",
|
|
163
169
|
"@protobuf-ts/runtime-rpc": "^2.11.1",
|
package/src/bcs/bcs.ts
CHANGED
|
@@ -341,14 +341,18 @@ export const CompressedSignature = bcs.enum('CompressedSignature', {
|
|
|
341
341
|
Secp256r1: bcs.bytes(64),
|
|
342
342
|
ZkLogin: bcs.byteVector(),
|
|
343
343
|
Passkey: bcs.byteVector(),
|
|
344
|
+
MLDSA65: bcs.bytes(3309),
|
|
344
345
|
});
|
|
345
346
|
|
|
347
|
+
// Variant order must match Sui's `PublicKey` enum, which validators hash to
|
|
348
|
+
// derive a multisig address.
|
|
346
349
|
export const PublicKey = bcs.enum('PublicKey', {
|
|
347
350
|
ED25519: bcs.bytes(32),
|
|
348
351
|
Secp256k1: bcs.bytes(33),
|
|
349
352
|
Secp256r1: bcs.bytes(33),
|
|
350
353
|
ZkLogin: bcs.byteVector(),
|
|
351
354
|
Passkey: bcs.bytes(33),
|
|
355
|
+
MLDSA65: bcs.bytes(1952),
|
|
352
356
|
});
|
|
353
357
|
|
|
354
358
|
export const MultiSigPkMap = bcs.struct('MultiSigPkMap', {
|
package/src/client/types.ts
CHANGED
|
@@ -363,12 +363,28 @@ export namespace SuiClientTypes {
|
|
|
363
363
|
Transaction: Transaction<Include>;
|
|
364
364
|
FailedTransaction?: never;
|
|
365
365
|
commandResults: Include extends { commandResults: true } ? CommandResult[] : undefined;
|
|
366
|
+
/**
|
|
367
|
+
* `true` when the transaction had no gas payment, so the node simulated it with a mocked gas
|
|
368
|
+
* coin instead of the sender's funds. Gas costs and transaction logic are still exercised,
|
|
369
|
+
* but anything drawn from the gas coin (`tx.gas`, including SUI from `tx.coin()`) was funded
|
|
370
|
+
* by the mocked coin rather than the sender. `false` when gas was paid with real coins or
|
|
371
|
+
* from the sender's address balance.
|
|
372
|
+
*/
|
|
373
|
+
gasPaymentMocked: boolean;
|
|
366
374
|
}
|
|
367
375
|
| {
|
|
368
376
|
$kind: 'FailedTransaction';
|
|
369
377
|
Transaction?: never;
|
|
370
378
|
FailedTransaction: Transaction<Include>;
|
|
371
379
|
commandResults: Include extends { commandResults: true } ? CommandResult[] : undefined;
|
|
380
|
+
/**
|
|
381
|
+
* `true` when the transaction had no gas payment, so the node simulated it with a mocked gas
|
|
382
|
+
* coin instead of the sender's funds. Gas costs and transaction logic are still exercised,
|
|
383
|
+
* but anything drawn from the gas coin (`tx.gas`, including SUI from `tx.coin()`) was funded
|
|
384
|
+
* by the mocked coin rather than the sender. `false` when gas was paid with real coins or
|
|
385
|
+
* from the sender's address balance.
|
|
386
|
+
*/
|
|
387
|
+
gasPaymentMocked: boolean;
|
|
372
388
|
};
|
|
373
389
|
|
|
374
390
|
export interface TransactionInclude {
|
|
@@ -468,7 +484,8 @@ export namespace SuiClientTypes {
|
|
|
468
484
|
/**
|
|
469
485
|
* When set to `false`, disables transaction validation checks during simulation.
|
|
470
486
|
* This allows inspecting non-public/non-entry Move functions and other transactions
|
|
471
|
-
* that would normally fail validation.
|
|
487
|
+
* that would normally fail validation. Disabling checks also disables gas selection, so a
|
|
488
|
+
* transaction with an empty gas payment is simulated with a mocked gas coin.
|
|
472
489
|
*
|
|
473
490
|
* Defaults to `true` (checks enabled).
|
|
474
491
|
*/
|
package/src/client/utils.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { toBase64 } from '@mysten/utils';
|
|
|
6
6
|
import { bcs } from '../bcs/index.js';
|
|
7
7
|
import { ExecutionStatus } from '../bcs/effects.js';
|
|
8
8
|
import { TransactionDataBuilder } from '../transactions/TransactionData.js';
|
|
9
|
+
import { MOCKED_GAS_OBJECT_ID } from '../utils/constants.js';
|
|
10
|
+
import { normalizeSuiAddress } from '../utils/sui-types.js';
|
|
9
11
|
import type { SuiClientTypes } from './types.js';
|
|
10
12
|
|
|
11
13
|
const ordinalRules = new Intl.PluralRules('en-US', { type: 'ordinal' });
|
|
@@ -414,6 +416,14 @@ export function transactionBytesHaveEmptyGasPayment(bytes: Uint8Array): boolean
|
|
|
414
416
|
}
|
|
415
417
|
}
|
|
416
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Checks whether a gas object ID is the mocked gas coin the node substitutes when a transaction
|
|
421
|
+
* is simulated without a gas payment.
|
|
422
|
+
*/
|
|
423
|
+
export function isMockedGasObjectId(objectId: string | null | undefined): boolean {
|
|
424
|
+
return objectId != null && normalizeSuiAddress(objectId) === MOCKED_GAS_OBJECT_ID;
|
|
425
|
+
}
|
|
426
|
+
|
|
417
427
|
/**
|
|
418
428
|
* Extracts just the status from transaction effects BCS without fully parsing.
|
|
419
429
|
* This is optimized for cases where we only need the status (success/failure)
|
|
@@ -150,6 +150,7 @@ export function parseSerializedKeypairSignature(serializedSignature: string) {
|
|
|
150
150
|
case 'ED25519':
|
|
151
151
|
case 'Secp256k1':
|
|
152
152
|
case 'Secp256r1':
|
|
153
|
+
case 'MLDSA65':
|
|
153
154
|
const size =
|
|
154
155
|
SIGNATURE_SCHEME_TO_SIZE[signatureScheme as keyof typeof SIGNATURE_SCHEME_TO_SIZE];
|
|
155
156
|
const signature = bytes.slice(1, bytes.length - size);
|
|
@@ -8,6 +8,7 @@ export const SIGNATURE_SCHEME_TO_FLAG = {
|
|
|
8
8
|
MultiSig: 0x03,
|
|
9
9
|
ZkLogin: 0x05,
|
|
10
10
|
Passkey: 0x06,
|
|
11
|
+
MLDSA65: 0x07,
|
|
11
12
|
} as const;
|
|
12
13
|
|
|
13
14
|
export const SIGNATURE_SCHEME_TO_SIZE = {
|
|
@@ -15,6 +16,7 @@ export const SIGNATURE_SCHEME_TO_SIZE = {
|
|
|
15
16
|
Secp256k1: 33,
|
|
16
17
|
Secp256r1: 33,
|
|
17
18
|
Passkey: 33,
|
|
19
|
+
MLDSA65: 1952,
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const SIGNATURE_FLAG_TO_SCHEME = {
|
|
@@ -24,9 +26,10 @@ export const SIGNATURE_FLAG_TO_SCHEME = {
|
|
|
24
26
|
0x03: 'MultiSig',
|
|
25
27
|
0x05: 'ZkLogin',
|
|
26
28
|
0x06: 'Passkey',
|
|
29
|
+
0x07: 'MLDSA65',
|
|
27
30
|
} as const;
|
|
28
31
|
|
|
29
32
|
export type SignatureScheme =
|
|
30
|
-
'ED25519' | 'Secp256k1' | 'Secp256r1' | 'MultiSig' | 'ZkLogin' | 'Passkey';
|
|
33
|
+
'ED25519' | 'Secp256k1' | 'Secp256r1' | 'MultiSig' | 'ZkLogin' | 'Passkey' | 'MLDSA65';
|
|
31
34
|
|
|
32
35
|
export type SignatureFlag = keyof typeof SIGNATURE_FLAG_TO_SCHEME;
|
|
@@ -69,6 +69,7 @@ export function parseSerializedSignature(serializedSignature: string) {
|
|
|
69
69
|
case 'ED25519':
|
|
70
70
|
case 'Secp256k1':
|
|
71
71
|
case 'Secp256r1':
|
|
72
|
+
case 'MLDSA65':
|
|
72
73
|
return parseSerializedKeypairSignature(serializedSignature);
|
|
73
74
|
default:
|
|
74
75
|
throw new Error('Unsupported signature scheme');
|
package/src/graphql/client.ts
CHANGED
|
@@ -78,9 +78,10 @@ export interface GraphQLSimulateTransactionOptions<
|
|
|
78
78
|
* Overrides whether the server selects gas payment during simulation.
|
|
79
79
|
*
|
|
80
80
|
* When not set, gas selection is enabled only when the transaction's gas payment is explicitly
|
|
81
|
-
* set to an empty list (`[]`)
|
|
82
|
-
* Transactions with gas coins set are simulated as-is, and transactions without a
|
|
83
|
-
* are simulated with a mocked gas coin
|
|
81
|
+
* set to an empty list (`[]`); the server then pays gas from the sender's address balance or
|
|
82
|
+
* coin objects. Transactions with gas coins set are simulated as-is, and transactions without a
|
|
83
|
+
* gas payment are simulated with a mocked gas coin (reported as `gasPaymentMocked` on the
|
|
84
|
+
* result).
|
|
84
85
|
*/
|
|
85
86
|
doGasSelection?: boolean;
|
|
86
87
|
}
|
package/src/graphql/core.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { chunk, fromBase64, toBase64 } from '@mysten/utils';
|
|
|
43
43
|
import { normalizeStructTag, normalizeSuiAddress } from '../utils/sui-types.js';
|
|
44
44
|
import {
|
|
45
45
|
formatMoveAbortMessage,
|
|
46
|
+
isMockedGasObjectId,
|
|
46
47
|
parseTransactionEffectsBcs,
|
|
47
48
|
transactionBytesHaveEmptyGasPayment,
|
|
48
49
|
} from '../client/utils.js';
|
|
@@ -422,9 +423,9 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
422
423
|
await options.transaction.prepareForSerialization({ client: this });
|
|
423
424
|
}
|
|
424
425
|
|
|
425
|
-
// A gas payment explicitly set to an empty list means
|
|
426
|
-
//
|
|
427
|
-
//
|
|
426
|
+
// A gas payment explicitly set to an empty list means the server should select real gas
|
|
427
|
+
// (from the sender's address balance or coin objects) rather than simulating with a
|
|
428
|
+
// mocked gas coin.
|
|
428
429
|
const doGasSelection =
|
|
429
430
|
options.doGasSelection ??
|
|
430
431
|
(options.transaction instanceof Uint8Array
|
|
@@ -459,6 +460,9 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
459
460
|
);
|
|
460
461
|
|
|
461
462
|
const transactionResult = parseTransaction(result.effects?.transaction!, options.include);
|
|
463
|
+
const gasPaymentMocked = isMockedGasObjectId(
|
|
464
|
+
result.effects?.transaction?.effects?.gasEffects?.gasObject?.address,
|
|
465
|
+
);
|
|
462
466
|
|
|
463
467
|
const commandResults =
|
|
464
468
|
options.include?.commandResults && result.outputs
|
|
@@ -478,6 +482,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
478
482
|
Transaction: transactionResult.Transaction,
|
|
479
483
|
commandResults:
|
|
480
484
|
commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
|
|
485
|
+
gasPaymentMocked,
|
|
481
486
|
};
|
|
482
487
|
} else {
|
|
483
488
|
return {
|
|
@@ -485,6 +490,7 @@ export class GraphQLCoreClient extends CoreClient {
|
|
|
485
490
|
FailedTransaction: transactionResult.FailedTransaction,
|
|
486
491
|
commandResults:
|
|
487
492
|
commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
|
|
493
|
+
gasPaymentMocked,
|
|
488
494
|
};
|
|
489
495
|
}
|
|
490
496
|
}
|
|
@@ -380,7 +380,7 @@ export type SimulateTransactionQueryVariables = Exact<{
|
|
|
380
380
|
}>;
|
|
381
381
|
|
|
382
382
|
|
|
383
|
-
export type SimulateTransactionQuery = { simulateTransaction: { effects: { transaction: { digest: string, transactionJson?: unknown, transactionBcs?: string | null,
|
|
383
|
+
export type SimulateTransactionQuery = { simulateTransaction: { effects: { transaction: { digest: string, transactionJson?: unknown, transactionBcs?: string | null, effects: { status: ExecutionStatus | null, timestamp: string | null, effectsBcs?: string | null, effectsJson?: unknown, balanceChangesJson?: unknown, gasEffects: { gasObject: { address: string } | null } | null, checkpoint: { sequenceNumber: number } | null, executionError: { message: string, abortCode: string | null, identifier: string | null, constant: string | null, sourceLineNumber: number | null, instructionOffset: number | null, module: { name: string, package: { address: string } | null } | null, function: { name: string } | null } | null, epoch: { epochId: number } | null, objectChanges?: { nodes: Array<{ address: string, outputState: { asMoveObject: { contents: { type: { repr: string } | null } | null } | null } | null }> } | null, events?: { pageInfo: { hasNextPage: boolean }, nodes: Array<{ transactionModule: { name: string, package: { address: string } | null } | null, sender: { address: string } | null, contents: { bcs: string | null, json: unknown, type: { repr: string } | null } | null }> } | null } | null, signatures: Array<{ signatureBytes: string | null }> } | null } | null, outputs?: Array<{ returnValues: Array<{ value: { bcs: string | null } | null }> | null, mutatedReferences: Array<{ value: { bcs: string | null } | null }> | null }> | null } };
|
|
384
384
|
|
|
385
385
|
export type ExecuteTransactionMutationVariables = Exact<{
|
|
386
386
|
transactionDataBcs: string;
|
|
@@ -1047,6 +1047,13 @@ export const SimulateTransactionDocument = new TypedDocumentString(`
|
|
|
1047
1047
|
effects {
|
|
1048
1048
|
transaction {
|
|
1049
1049
|
...TRANSACTION_FIELDS
|
|
1050
|
+
effects {
|
|
1051
|
+
gasEffects {
|
|
1052
|
+
gasObject {
|
|
1053
|
+
address
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1050
1057
|
}
|
|
1051
1058
|
}
|
|
1052
1059
|
outputs @include(if: $includeCommandResults) {
|
package/src/grpc/client.ts
CHANGED
|
@@ -130,9 +130,10 @@ export interface GrpcSimulateTransactionOptions<
|
|
|
130
130
|
* Overrides whether the server selects gas payment during simulation.
|
|
131
131
|
*
|
|
132
132
|
* When not set, gas selection is enabled only when the transaction's gas payment is explicitly
|
|
133
|
-
* set to an empty list (`[]`)
|
|
134
|
-
* Transactions with gas coins set are simulated as-is, and transactions without a
|
|
135
|
-
* are simulated with a mocked gas coin
|
|
133
|
+
* set to an empty list (`[]`); the server then pays gas from the sender's address balance or
|
|
134
|
+
* coin objects. Transactions with gas coins set are simulated as-is, and transactions without a
|
|
135
|
+
* gas payment are simulated with a mocked gas coin (reported as `gasPaymentMocked` on the
|
|
136
|
+
* result).
|
|
136
137
|
*/
|
|
137
138
|
doGasSelection?: boolean;
|
|
138
139
|
}
|
package/src/grpc/core.ts
CHANGED
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
grpcTransactionToTransactionData,
|
|
51
51
|
} from '../client/transaction-resolver.js';
|
|
52
52
|
import { setAddressBalanceTransactionExpirationFromSimulatedEpoch } from '../client/address-balance-transaction-expiration.js';
|
|
53
|
-
import { transactionBytesHaveEmptyGasPayment } from '../client/utils.js';
|
|
53
|
+
import { isMockedGasObjectId, transactionBytesHaveEmptyGasPayment } from '../client/utils.js';
|
|
54
54
|
import { Value } from './proto/google/protobuf/struct.js';
|
|
55
55
|
import { ExecutedTransaction } from './proto/sui/rpc/v2/executed_transaction.js';
|
|
56
56
|
import {
|
|
@@ -457,14 +457,18 @@ export class GrpcCoreClient extends CoreClient {
|
|
|
457
457
|
if (options.include?.commandResults) {
|
|
458
458
|
paths.push('command_outputs');
|
|
459
459
|
}
|
|
460
|
+
if (!options.include?.effects) {
|
|
461
|
+
// The gas object ID is always needed to report whether a mocked gas coin was used
|
|
462
|
+
paths.push('transaction.effects.gas_object.object_id');
|
|
463
|
+
}
|
|
460
464
|
|
|
461
465
|
if (!(options.transaction instanceof Uint8Array)) {
|
|
462
466
|
await options.transaction.prepareForSerialization({ client: this });
|
|
463
467
|
}
|
|
464
468
|
|
|
465
|
-
// A gas payment explicitly set to an empty list means
|
|
466
|
-
//
|
|
467
|
-
//
|
|
469
|
+
// A gas payment explicitly set to an empty list means the server should select real gas
|
|
470
|
+
// (from the sender's address balance or coin objects) rather than simulating with a
|
|
471
|
+
// mocked gas coin.
|
|
468
472
|
const doGasSelection =
|
|
469
473
|
options.doGasSelection ??
|
|
470
474
|
(options.transaction instanceof Uint8Array
|
|
@@ -1621,6 +1625,7 @@ export function parseGrpcSimulateTransactionResponse<
|
|
|
1621
1625
|
): SuiClientTypes.SimulateTransactionResult<Include> {
|
|
1622
1626
|
const include = options?.include;
|
|
1623
1627
|
const transactionResult = parseGrpcTransactionResponse(response.transaction!, { include });
|
|
1628
|
+
const gasPaymentMocked = isMockedGasObjectId(response.transaction?.effects?.gasObject?.objectId);
|
|
1624
1629
|
|
|
1625
1630
|
const commandResults =
|
|
1626
1631
|
include?.commandResults && response.commandOutputs
|
|
@@ -1640,6 +1645,7 @@ export function parseGrpcSimulateTransactionResponse<
|
|
|
1640
1645
|
Transaction: transactionResult.Transaction,
|
|
1641
1646
|
commandResults:
|
|
1642
1647
|
commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
|
|
1648
|
+
gasPaymentMocked,
|
|
1643
1649
|
};
|
|
1644
1650
|
}
|
|
1645
1651
|
|
|
@@ -1648,6 +1654,7 @@ export function parseGrpcSimulateTransactionResponse<
|
|
|
1648
1654
|
FailedTransaction: transactionResult.FailedTransaction,
|
|
1649
1655
|
commandResults:
|
|
1650
1656
|
commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
|
|
1657
|
+
gasPaymentMocked,
|
|
1651
1658
|
};
|
|
1652
1659
|
}
|
|
1653
1660
|
|
package/src/jsonRpc/core.ts
CHANGED
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
parseTransactionBcs,
|
|
44
44
|
parseTransactionEffectsBcs,
|
|
45
45
|
} from '../client/index.js';
|
|
46
|
+
import { isMockedGasObjectId } from '../client/utils.js';
|
|
46
47
|
import type { SuiJsonRpcClient } from './client.js';
|
|
47
48
|
import { JsonRpcError } from './errors.js';
|
|
48
49
|
|
|
@@ -576,18 +577,22 @@ export class JSONRpcCoreClient extends CoreClient {
|
|
|
576
577
|
}));
|
|
577
578
|
}
|
|
578
579
|
|
|
580
|
+
const gasPaymentMocked = isMockedGasObjectId(effects.gasObject?.objectId);
|
|
581
|
+
|
|
579
582
|
return effects.status.success
|
|
580
583
|
? {
|
|
581
584
|
$kind: 'Transaction',
|
|
582
585
|
Transaction: transactionData,
|
|
583
586
|
commandResults:
|
|
584
587
|
commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
|
|
588
|
+
gasPaymentMocked,
|
|
585
589
|
}
|
|
586
590
|
: {
|
|
587
591
|
$kind: 'FailedTransaction',
|
|
588
592
|
FailedTransaction: transactionData,
|
|
589
593
|
commandResults:
|
|
590
594
|
commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
|
|
595
|
+
gasPaymentMocked,
|
|
591
596
|
};
|
|
592
597
|
}
|
|
593
598
|
/**
|