@mysten/sui 2.16.1 → 2.16.3
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 +22 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/client/core-resolver.mjs +21 -12
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- 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/transactions/Transaction.d.mts +6 -6
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/bcs.d.mts.map +1 -1
- package/docs/bcs.md +134 -0
- package/docs/clients/core.md +622 -0
- package/docs/clients/graphql.md +101 -0
- package/docs/clients/grpc.md +210 -0
- package/docs/clients/index.md +95 -0
- package/docs/clients/json-rpc.md +239 -0
- package/docs/cryptography/keypairs.md +267 -0
- package/docs/cryptography/multisig.md +194 -0
- package/docs/cryptography/passkey.md +112 -0
- package/docs/cryptography/webcrypto-signer.md +81 -0
- package/docs/executors.md +150 -0
- package/docs/faucet.md +26 -0
- package/docs/hello-sui.md +115 -0
- package/docs/index.md +53 -0
- package/docs/install.md +61 -0
- package/docs/llm-docs.md +32 -0
- package/docs/llms-index.md +44 -0
- package/docs/migrations/0.38.md +58 -0
- package/docs/migrations/sui-1.0.md +455 -0
- package/docs/migrations/sui-2.0/agent-prompt.md +42 -0
- package/docs/migrations/sui-2.0/dapp-kit.md +350 -0
- package/docs/migrations/sui-2.0/deepbook-v3.md +33 -0
- package/docs/migrations/sui-2.0/index.md +158 -0
- package/docs/migrations/sui-2.0/json-rpc-migration.md +408 -0
- package/docs/migrations/sui-2.0/kiosk.md +120 -0
- package/docs/migrations/sui-2.0/sdk-maintainers.md +90 -0
- package/docs/migrations/sui-2.0/seal.md +14 -0
- package/docs/migrations/sui-2.0/sui.md +341 -0
- package/docs/migrations/sui-2.0/suins.md +44 -0
- package/docs/migrations/sui-2.0/wallet-builders.md +66 -0
- package/docs/migrations/sui-2.0/walrus.md +41 -0
- package/docs/migrations/sui-2.0/zksend.md +95 -0
- package/docs/plugins.md +258 -0
- package/docs/sdk-building.md +344 -0
- package/docs/transaction-building/basics.md +299 -0
- package/docs/transaction-building/gas.md +61 -0
- package/docs/transaction-building/intents.md +62 -0
- package/docs/transaction-building/offline.md +73 -0
- package/docs/transaction-building/sponsored-transactions.md +22 -0
- package/docs/utils/derived_objects.md +80 -0
- package/docs/utils/index.md +59 -0
- package/docs/zklogin.md +83 -0
- package/package.json +3 -3
- package/src/client/core-resolver.ts +48 -13
- package/src/version.ts +1 -1
package/docs/zklogin.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# ZkLogin
|
|
2
|
+
|
|
3
|
+
> Zero-knowledge authentication with OAuth providers on Sui.
|
|
4
|
+
|
|
5
|
+
Utilities for working with zkLogin. Currently contains functionality to create and parse zkLogin
|
|
6
|
+
signatures and compute zkLogin addresses.
|
|
7
|
+
|
|
8
|
+
To parse a serialized zkLogin signature
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
|
|
12
|
+
const parsedSignature = await parseZkLoginSignature('BQNNMTY4NjAxMzAyO....');
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Use `getZkLoginSignature` to serialize a zkLogin signature.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
|
|
19
|
+
const serializedSignature = await getZkLoginSignature({ inputs, maxEpoch, userSignature });
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
To compute the address for a given address seed and iss you can use `computeZkLoginAddressFromSeed`
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
|
|
26
|
+
const address = computeZkLoginAddressFromSeed(0n, 'https://accounts.google.com');
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To compute an address from jwt:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
|
|
33
|
+
const address = jwtToAddress(jwtAsString, salt);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To compute an address from a parsed jwt:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
|
|
40
|
+
const address = computeZkLoginAddress({
|
|
41
|
+
claimName,
|
|
42
|
+
claimValue,
|
|
43
|
+
iss,
|
|
44
|
+
aud,
|
|
45
|
+
userSalt: BigInt(salt),
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
To use zkLogin inside a multisig, see the [Multisig Guide](../sui/cryptography/multisig) for more
|
|
50
|
+
details.
|
|
51
|
+
|
|
52
|
+
## Legacy addresses
|
|
53
|
+
|
|
54
|
+
When zklogin was first introduced, there was an inconsistency in how the address seed was computed.
|
|
55
|
+
For backwards compatibility reasons there are 2 valid addresses for a given set of inputs. Methods
|
|
56
|
+
that produce zklogin addresses all accept a `legacyAddress` boolean flag, either as their last
|
|
57
|
+
parameter, or in their options argument.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
|
|
61
|
+
computeZkLoginAddress,
|
|
62
|
+
computeZkLoginAddressFromSeed,
|
|
63
|
+
jwtToAddress,
|
|
64
|
+
toZkLoginPublicIdentifier,
|
|
65
|
+
genAddressSeed,
|
|
66
|
+
} from '@mysten/sui/zklogin';
|
|
67
|
+
|
|
68
|
+
const address = jwtToAddress(jwtAsString, salt, true);
|
|
69
|
+
const address = computeZkLoginAddressFromSeed(0n, 'https://accounts.google.com', true);
|
|
70
|
+
const address = computeZkLoginAddress({
|
|
71
|
+
claimName,
|
|
72
|
+
claimValue,
|
|
73
|
+
iss,
|
|
74
|
+
aud,
|
|
75
|
+
userSalt: BigInt(salt),
|
|
76
|
+
legacyAddress: true,
|
|
77
|
+
});
|
|
78
|
+
const address = toZkLoginPublicIdentifier(
|
|
79
|
+
genAddressSeed(userSalt, claimName, claimValue, aud),
|
|
80
|
+
iss,
|
|
81
|
+
{ legacyAddress: true },
|
|
82
|
+
).toSuiAddress();
|
|
83
|
+
```
|
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.16.
|
|
6
|
+
"version": "2.16.3",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
@@ -168,8 +168,8 @@
|
|
|
168
168
|
"graphql": "^16.12.0",
|
|
169
169
|
"poseidon-lite": "0.2.1",
|
|
170
170
|
"valibot": "^1.2.0",
|
|
171
|
-
"@mysten/bcs": "^2.0.
|
|
172
|
-
"@mysten/utils": "^0.3.
|
|
171
|
+
"@mysten/bcs": "^2.0.5",
|
|
172
|
+
"@mysten/utils": "^0.3.3"
|
|
173
173
|
},
|
|
174
174
|
"scripts": {
|
|
175
175
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
@@ -84,7 +84,18 @@ export async function coreClientResolveTransactionPlugin(
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
// `setGasBudget` simulates with `payment: []` whenever it has to compute a
|
|
88
|
+
// budget (i.e. one wasn't preset). The validator's replay-protection check
|
|
89
|
+
// then requires either a `ValidDuring` expiration or at least one
|
|
90
|
+
// "address-owned" input — an `ImmOrOwnedMoveObject` whose owner is
|
|
91
|
+
// `AddressOwner`, which we can't tell from `Immutable` without owner info we
|
|
92
|
+
// don't track. Provide a simulate-only `ValidDuring` whenever we'll actually
|
|
93
|
+
// simulate and one isn't user-set.
|
|
94
|
+
const needsSimulateExpiration =
|
|
95
|
+
!options.onlyTransactionKind && !transactionData.expiration && !transactionData.gasData.budget;
|
|
96
|
+
const needsSystemState =
|
|
97
|
+
needsGasPrice || (needsPayment && usesGasCoin) || needsSimulateExpiration;
|
|
98
|
+
const needsChainId = (needsPayment && usesGasCoin) || needsSimulateExpiration;
|
|
88
99
|
const [, systemStateResult, balanceResult, coinsResult, chainIdResult] = await Promise.all([
|
|
89
100
|
normalizeInputs(transactionData, client),
|
|
90
101
|
needsSystemState ? client.core.getCurrentSystemState() : null,
|
|
@@ -92,19 +103,25 @@ export async function coreClientResolveTransactionPlugin(
|
|
|
92
103
|
needsPayment && gasPayer
|
|
93
104
|
? client.core.listCoins({ owner: gasPayer, coinType: SUI_TYPE_ARG })
|
|
94
105
|
: null,
|
|
95
|
-
|
|
106
|
+
needsChainId ? client.core.getChainIdentifier() : null,
|
|
96
107
|
]);
|
|
97
108
|
|
|
98
109
|
await resolveObjectReferences(transactionData, client);
|
|
99
110
|
|
|
100
111
|
if (!options.onlyTransactionKind) {
|
|
101
112
|
const systemState = systemStateResult?.systemState ?? null;
|
|
113
|
+
const chainIdentifier = chainIdResult?.chainIdentifier ?? null;
|
|
102
114
|
|
|
103
115
|
if (systemState && !transactionData.gasData.price) {
|
|
104
116
|
transactionData.gasData.price = systemState.referenceGasPrice;
|
|
105
117
|
}
|
|
106
118
|
|
|
107
|
-
|
|
119
|
+
const simulateExpiration =
|
|
120
|
+
needsSimulateExpiration && systemState && chainIdentifier
|
|
121
|
+
? buildValidDuringExpiration(systemState, chainIdentifier)
|
|
122
|
+
: undefined;
|
|
123
|
+
|
|
124
|
+
await setGasBudget(transactionData, client, simulateExpiration);
|
|
108
125
|
|
|
109
126
|
if (needsPayment) {
|
|
110
127
|
if (!balanceResult || !coinsResult) {
|
|
@@ -119,25 +136,24 @@ export async function coreClientResolveTransactionPlugin(
|
|
|
119
136
|
usesGasCoin,
|
|
120
137
|
withdrawals,
|
|
121
138
|
gasPayer: gasPayer!,
|
|
122
|
-
chainIdentifier
|
|
139
|
+
chainIdentifier,
|
|
123
140
|
epoch: systemState?.epoch ?? null,
|
|
124
141
|
});
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
if (!transactionData.expiration && transactionData.gasData.payment?.length === 0) {
|
|
128
|
-
await setExpiration(
|
|
129
|
-
transactionData,
|
|
130
|
-
client,
|
|
131
|
-
systemState,
|
|
132
|
-
chainIdResult?.chainIdentifier ?? null,
|
|
133
|
-
);
|
|
145
|
+
await setExpiration(transactionData, client, systemState, chainIdentifier);
|
|
134
146
|
}
|
|
135
147
|
}
|
|
136
148
|
|
|
137
149
|
return await next();
|
|
138
150
|
}
|
|
139
151
|
|
|
140
|
-
async function setGasBudget(
|
|
152
|
+
async function setGasBudget(
|
|
153
|
+
transactionData: TransactionDataBuilder,
|
|
154
|
+
client: ClientWithCoreApi,
|
|
155
|
+
simulateExpiration?: ValidDuringExpiration,
|
|
156
|
+
) {
|
|
141
157
|
if (transactionData.gasData.budget) {
|
|
142
158
|
return;
|
|
143
159
|
}
|
|
@@ -149,6 +165,7 @@ async function setGasBudget(transactionData: TransactionDataBuilder, client: Cli
|
|
|
149
165
|
budget: String(MAX_GAS),
|
|
150
166
|
payment: [],
|
|
151
167
|
},
|
|
168
|
+
...(simulateExpiration && { expiration: simulateExpiration }),
|
|
152
169
|
},
|
|
153
170
|
}),
|
|
154
171
|
include: { effects: true },
|
|
@@ -243,9 +260,27 @@ async function setExpiration(
|
|
|
243
260
|
existingChainIdentifier ?? client.core.getChainIdentifier().then((r) => r.chainIdentifier),
|
|
244
261
|
systemState ?? client.core.getCurrentSystemState().then((r) => r.systemState),
|
|
245
262
|
]);
|
|
246
|
-
|
|
263
|
+
transactionData.expiration = buildValidDuringExpiration(resolvedSystemState, chainIdentifier);
|
|
264
|
+
}
|
|
247
265
|
|
|
248
|
-
|
|
266
|
+
type ValidDuringExpiration = {
|
|
267
|
+
$kind: 'ValidDuring';
|
|
268
|
+
ValidDuring: {
|
|
269
|
+
minEpoch: string;
|
|
270
|
+
maxEpoch: string;
|
|
271
|
+
minTimestamp: null;
|
|
272
|
+
maxTimestamp: null;
|
|
273
|
+
chain: string;
|
|
274
|
+
nonce: number;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
function buildValidDuringExpiration(
|
|
279
|
+
systemState: SystemStateData,
|
|
280
|
+
chainIdentifier: string,
|
|
281
|
+
): ValidDuringExpiration {
|
|
282
|
+
const currentEpoch = BigInt(systemState.epoch);
|
|
283
|
+
return {
|
|
249
284
|
$kind: 'ValidDuring',
|
|
250
285
|
ValidDuring: {
|
|
251
286
|
minEpoch: String(currentEpoch),
|
package/src/version.ts
CHANGED