@mysten/sui 2.7.0 → 2.9.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 +19 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/keypairs/passkey/keypair.d.mts +11 -4
- package/dist/keypairs/passkey/keypair.d.mts.map +1 -1
- package/dist/keypairs/passkey/keypair.mjs +19 -6
- package/dist/keypairs/passkey/keypair.mjs.map +1 -1
- package/dist/utils/constants.d.mts +2 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +2 -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/version.mjs +2 -2
- 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 +131 -0
- package/docs/clients/core.md +601 -0
- package/docs/clients/graphql.md +99 -0
- package/docs/clients/grpc.md +152 -0
- package/docs/clients/index.md +93 -0
- package/docs/clients/json-rpc.md +235 -0
- package/docs/cryptography/keypairs.md +258 -0
- package/docs/cryptography/multisig.md +192 -0
- package/docs/cryptography/passkey.md +111 -0
- package/docs/cryptography/webcrypto-signer.md +81 -0
- package/docs/executors.md +147 -0
- package/docs/faucet.md +26 -0
- package/docs/hello-sui.md +114 -0
- package/docs/index.md +54 -0
- package/docs/install.md +61 -0
- package/docs/llm-docs.md +32 -0
- package/docs/llms-index.md +60 -0
- package/docs/migrations/0.38.md +57 -0
- package/docs/migrations/sui-1.0.md +453 -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 +157 -0
- package/docs/migrations/sui-2.0/json-rpc-migration.md +383 -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 +42 -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 +94 -0
- package/docs/plugins.md +255 -0
- package/docs/sdk-building.md +340 -0
- package/docs/transaction-building/basics.md +297 -0
- package/docs/transaction-building/gas.md +62 -0
- package/docs/transaction-building/intents.md +61 -0
- package/docs/transaction-building/offline.md +71 -0
- package/docs/transaction-building/sponsored-transactions.md +22 -0
- package/docs/utils/derived_objects.md +59 -0
- package/docs/utils/index.md +52 -0
- package/docs/zklogin.md +78 -0
- package/package.json +4 -2
- package/src/keypairs/passkey/keypair.ts +20 -6
- package/src/utils/constants.ts +2 -0
- package/src/utils/index.ts +1 -0
- package/src/version.ts +2 -2
package/docs/zklogin.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
const parsedSignature = await parseZkLoginSignature('BQNNMTY4NjAxMzAyO....');
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Use `getZkLoginSignature` to serialize a zkLogin signature.
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
const serializedSignature = await getZkLoginSignature({ inputs, maxEpoch, userSignature });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
To compute the address for a given address seed and iss you can use `computeZkLoginAddressFromSeed`
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
const address = computeZkLoginAddressFromSeed(0n, 'https://accounts.google.com');
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To compute an address from jwt:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const address = jwtToAddress(jwtAsString, salt);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To compute an address from a parsed jwt:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const address = computeZkLoginAddress({
|
|
36
|
+
claimName,
|
|
37
|
+
claimValue,
|
|
38
|
+
iss,
|
|
39
|
+
aud,
|
|
40
|
+
userSalt: BigInt(salt),
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To use zkLogin inside a multisig, see the [Multisig Guide](../sui/cryptography/multisig) for more
|
|
45
|
+
details.
|
|
46
|
+
|
|
47
|
+
## Legacy addresses
|
|
48
|
+
|
|
49
|
+
When zklogin was first introduced, there was an inconsistency in how the address seed was computed.
|
|
50
|
+
For backwards compatibility reasons there are 2 valid addresses for a given set of inputs. Methods
|
|
51
|
+
that produce zklogin addresses all accept a `legacyAddress` boolean flag, either as their last
|
|
52
|
+
parameter, or in their options argument.
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
|
|
56
|
+
computeZkLoginAddress,
|
|
57
|
+
computeZkLoginAddressFromSeed,
|
|
58
|
+
jwtToAddress,
|
|
59
|
+
toZkLoginPublicIdentifier,
|
|
60
|
+
genAddressSeed,
|
|
61
|
+
} from '@mysten/sui/zklogin';
|
|
62
|
+
|
|
63
|
+
const address = jwtToAddress(jwtAsString, salt, true);
|
|
64
|
+
const address = computeZkLoginAddressFromSeed(0n, 'https://accounts.google.com', true);
|
|
65
|
+
const address = computeZkLoginAddress({
|
|
66
|
+
claimName,
|
|
67
|
+
claimValue,
|
|
68
|
+
iss,
|
|
69
|
+
aud,
|
|
70
|
+
userSalt: BigInt(salt),
|
|
71
|
+
legacyAddress: true,
|
|
72
|
+
});
|
|
73
|
+
const address = toZkLoginPublicIdentifier(
|
|
74
|
+
genAddressSeed(userSalt, claimName, claimValue, aud),
|
|
75
|
+
iss,
|
|
76
|
+
{ legacyAddress: true },
|
|
77
|
+
).toSuiAddress();
|
|
78
|
+
```
|
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.9.0",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"client",
|
|
16
16
|
"cryptography",
|
|
17
17
|
"dist",
|
|
18
|
+
"docs",
|
|
18
19
|
"experimental",
|
|
19
20
|
"faucet",
|
|
20
21
|
"graphql",
|
|
@@ -168,7 +169,7 @@
|
|
|
168
169
|
"graphql": "^16.12.0",
|
|
169
170
|
"poseidon-lite": "0.2.1",
|
|
170
171
|
"valibot": "^1.2.0",
|
|
171
|
-
"@mysten/bcs": "^2.0.
|
|
172
|
+
"@mysten/bcs": "^2.0.3",
|
|
172
173
|
"@mysten/utils": "^0.3.1"
|
|
173
174
|
},
|
|
174
175
|
"scripts": {
|
|
@@ -182,6 +183,7 @@
|
|
|
182
183
|
"codegen:grpc-header": "find src/grpc/proto -type f -exec sh -c 'echo \"// Copyright (c) Mysten Labs, Inc.\\n// SPDX-License-Identifier: Apache-2.0\\n\" | cat - {} > temp && mv temp {}' \\;",
|
|
183
184
|
"codegen:grpc-extensions": "find src/grpc/proto -name '*.ts' | xargs sed -i '' -E 's/from \"(\\.[^\"]+)\"/from \"\\1.js\"/g'",
|
|
184
185
|
"build": "rm -rf dist && node genversion.mjs && tsc --noEmit && tsdown",
|
|
186
|
+
"build:docs": "tsx ../docs/scripts/build-docs.ts",
|
|
185
187
|
"vitest": "vitest",
|
|
186
188
|
"test": "pnpm test:typecheck && pnpm test:unit",
|
|
187
189
|
"test:typecheck": "tsc -p ./test",
|
|
@@ -39,7 +39,7 @@ export type BrowserPasswordProviderOptions = Pick<
|
|
|
39
39
|
|
|
40
40
|
export interface PasskeyProvider {
|
|
41
41
|
create(): Promise<RegistrationCredential>;
|
|
42
|
-
get(challenge: Uint8Array): Promise<AuthenticationCredential>;
|
|
42
|
+
get(challenge: Uint8Array, credentialId?: Uint8Array): Promise<AuthenticationCredential>;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// Default browser implementation
|
|
@@ -80,12 +80,15 @@ export class BrowserPasskeyProvider implements PasskeyProvider {
|
|
|
80
80
|
})) as RegistrationCredential;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
async get(challenge: Uint8Array): Promise<AuthenticationCredential> {
|
|
83
|
+
async get(challenge: Uint8Array, credentialId?: Uint8Array): Promise<AuthenticationCredential> {
|
|
84
84
|
return (await navigator.credentials.get({
|
|
85
85
|
publicKey: {
|
|
86
86
|
challenge: challenge as BufferSource,
|
|
87
87
|
userVerification: this.#options.authenticatorSelection?.userVerification || 'required',
|
|
88
88
|
timeout: this.#options.timeout ?? 60000,
|
|
89
|
+
...(credentialId && {
|
|
90
|
+
allowCredentials: [{ type: 'public-key' as const, id: credentialId as BufferSource }],
|
|
91
|
+
}),
|
|
89
92
|
},
|
|
90
93
|
})) as AuthenticationCredential;
|
|
91
94
|
}
|
|
@@ -98,6 +101,7 @@ export class BrowserPasskeyProvider implements PasskeyProvider {
|
|
|
98
101
|
export class PasskeyKeypair extends Signer {
|
|
99
102
|
private publicKey: Uint8Array;
|
|
100
103
|
private provider: PasskeyProvider;
|
|
104
|
+
private credentialId?: Uint8Array;
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
107
|
* Get the key scheme of passkey,
|
|
@@ -120,10 +124,20 @@ export class PasskeyKeypair extends Signer {
|
|
|
120
124
|
* If there are existing passkey wallet, use `signAndRecover` to identify the correct
|
|
121
125
|
* public key and then initialize the instance. See usage in `signAndRecover`.
|
|
122
126
|
*/
|
|
123
|
-
constructor(publicKey: Uint8Array, provider: PasskeyProvider) {
|
|
127
|
+
constructor(publicKey: Uint8Array, provider: PasskeyProvider, credentialId?: Uint8Array) {
|
|
124
128
|
super();
|
|
125
129
|
this.publicKey = publicKey;
|
|
126
130
|
this.provider = provider;
|
|
131
|
+
this.credentialId = credentialId;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Return the credential ID for this passkey, if available.
|
|
136
|
+
* The credential ID is captured when creating a new passkey via `getPasskeyInstance`
|
|
137
|
+
* and can be used to constrain which credential the browser selects during signing.
|
|
138
|
+
*/
|
|
139
|
+
getCredentialId(): Uint8Array | undefined {
|
|
140
|
+
return this.credentialId;
|
|
127
141
|
}
|
|
128
142
|
|
|
129
143
|
/**
|
|
@@ -145,7 +159,7 @@ export class PasskeyKeypair extends Signer {
|
|
|
145
159
|
const pubkeyUncompressed = parseDerSPKI(new Uint8Array(derSPKI));
|
|
146
160
|
const pubkey = secp256r1.Point.fromBytes(pubkeyUncompressed);
|
|
147
161
|
const pubkeyCompressed = pubkey.toBytes(true);
|
|
148
|
-
return new PasskeyKeypair(pubkeyCompressed, provider);
|
|
162
|
+
return new PasskeyKeypair(pubkeyCompressed, provider, new Uint8Array(credential.rawId));
|
|
149
163
|
}
|
|
150
164
|
}
|
|
151
165
|
|
|
@@ -162,7 +176,7 @@ export class PasskeyKeypair extends Signer {
|
|
|
162
176
|
*/
|
|
163
177
|
async sign(data: Uint8Array) {
|
|
164
178
|
// asks the passkey to sign over challenge as the data.
|
|
165
|
-
const credential = await this.provider.get(data);
|
|
179
|
+
const credential = await this.provider.get(data, this.credentialId);
|
|
166
180
|
|
|
167
181
|
// parse authenticatorData (as bytes), clientDataJSON (decoded as string).
|
|
168
182
|
const authenticatorData = new Uint8Array(credential.response.authenticatorData);
|
|
@@ -245,7 +259,7 @@ export class PasskeyKeypair extends Signer {
|
|
|
245
259
|
* const testMessage2 = new TextEncoder().encode('Hello world 2!');
|
|
246
260
|
* const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);
|
|
247
261
|
* const commonPk = findCommonPublicKey(possiblePks, possiblePks2);
|
|
248
|
-
* const signer = new PasskeyKeypair(
|
|
262
|
+
* const signer = new PasskeyKeypair(commonPk.toRawBytes(), provider);
|
|
249
263
|
* ```
|
|
250
264
|
*
|
|
251
265
|
* @param provider - the passkey provider.
|
package/src/utils/constants.ts
CHANGED
|
@@ -18,5 +18,7 @@ export const SUI_SYSTEM_STATE_OBJECT_ID =
|
|
|
18
18
|
'0x0000000000000000000000000000000000000000000000000000000000000005';
|
|
19
19
|
export const SUI_RANDOM_OBJECT_ID =
|
|
20
20
|
'0x0000000000000000000000000000000000000000000000000000000000000008';
|
|
21
|
+
export const SUI_COIN_REGISTRY_OBJECT_ID =
|
|
22
|
+
'0x000000000000000000000000000000000000000000000000000000000000000c';
|
|
21
23
|
export const SUI_DENY_LIST_OBJECT_ID =
|
|
22
24
|
'0x0000000000000000000000000000000000000000000000000000000000000403';
|
package/src/utils/index.ts
CHANGED
package/src/version.ts
CHANGED