Overview
zkLogin is a Sui primitive that allows users to transact on Sui using the OAuth login flows they’re familiar with, eliminating the friction of handling cryptographic keys or remembering mnemonics. zkLogin can be thought of as a two-factor authentication scheme, since sending a transaction requires both a credential from a recent OAuth login and a salt managed by someone other than the OAuth provider (in this case, Shinami). To learn more, see the Sui Foundation’s zkLogin doc.. You’ll find API endpoints and key usage notes below. If you ever need help you can reach out to us.Use Cases
Core use cases include app-managed NFTs or closed-loop tokens. For a breakdown of the wallets we offer and wallet use-cases, see our high-level guide.Authentication, Rate Limits, and Error Handling
Authentication You authenticate via an access key passed in a header (‘X-Api-Key: ACCESS_KEY’) or in the request url, e.g.https://api.us1.shinami.com/sui/zkprover/v1/ACCESS_KEY
. We recommend using a request header and not putting access keys in your request URLs for reduced visibility (in logs, etc). These steps are done automatically by our TypeScript SDK. Region URLs - us1
above - only work with API keys created in the same region. So, to use this API, you’ll make Wallet Services API keys in our US East - us1
region.
For more information, including how to set up an access key with Wallet Services rights, see our Authentication and API Keys guide.
Call this API from your backendShinami Wallet Services do not support CORS requests, so if you call these APIs from your frontend you’ll get a CORS error. This is for security reasons: exposed wallet information could lead to malicious actors signing transactions on behalf of your users.
-32010
. We recommend implementing retries with a backoff to handle any rate limits errors that arise. You can also adjust the rate limits of your keys to better balance your QPS allotment across your keys.
We also have a limit of two zk proofs per address per minute. When you hit this limit, we return a JSON-RPC code -32012
.
zkLogin Addresses
A zkLogin wallet address is derived fromiss, aud, sub, salt
in the OpenID connect response, where:
iss
: The OpenID provider.aud
: The unique identifier assigned to your application by the OpenID provider.sub
: The OpenID provider’s locally unique and never reassigned identifier for the user.salt
: A consistent, ideally unique, value used to unlink the OpenID identifier with the on-chain address.
Tutorial + SDKs
The endpoints below show sample requests using our TypeScript SDK (in addition to cURL). We also have a Next.js zkLogin SDK, which aims to provide full-stack support for building user authentication and Sui transaction execution into your Next.js application, using zkLogin primitives. We built a Next.js starter template to quickly get you off the ground using this SDK. Even if you are starting with an existing Next.js application, it’s recommended to check out that example as a reference end-to-end implementation. Our Next.js tutorial has guidance on running our zkLogin app starter template.zkLogin wallet service methods
shinami_zkw_getOrCreateZkLoginWallet
Retrieves a zkLogin wallet along with its associated salt, creating a new wallet if necessary. This method provides the option to create and use multiple zkLogin wallets per (user, OAuth provider) pair by using the optionalsubWallet
parameter. Note that your users will already have a different zkLogin wallet for each OAuth provider they use, whose jwt
you pass to this method (see zkLogin Addresses for more details).
On the free tier you have a limit of wallet creations per month as shown on the “Sui Wallet Services” tab of the billing page in your dashboard (where you can also see how to upgrade if needed). If you hit this limit, you will get a JSON-RPC code -32012
and should not retry. All other wallet operations will still work for the month, like signing with wallets you’ve already created.
Request Parameters
Name | Type | Description |
---|---|---|
jwt | String | A valid JWT signed by one of the supported OpenID providers. The JWT nonce must be prepared according to the zkLogin requirements . |
keyClaimName | String | Optional. The claim name in the JWT that identifies a particular user. Defaults to “sub”. Currently, Mysten’s zkLogin implementation only supports the “sub” field of the OpenID spec. This parameter allows for forward compatibility as the implementation expands to support other values. |
subWallet | Integer | Optional. The sub-wallet id, which enables the same OpenID user to have more than one wallet address tied to your app. Defaults to 0 |
{{name}}
with the actual value for that name
Name | Type | Description |
---|---|---|
userId | Object | The OAuth user information used to create the wallet. |
subWallet | Integer | The subWallet number. |
salt | cURL: Base64 encoded String SDK: BigInt | The salt associated with this zkLogin wallet. |
address | Hex encoded String | The Sui zkLogin address of this wallet. |
zkProver service methods
shinami_zkp_createZkLoginProof
Generate a zkLogin proof prior to signing and executing a transaction. The example below uses the Shinami Clients SDK. Notes:- Devnet has a different zkey than Testnet and Mainnet. Shinami’s zk prover currently only works with Testnet and Mainnet.
- We have a limit of two zk proofs per address per minute. When you hit this limit, we return a JSON-RPC code
-32012
.
Name | Type | Description |
---|---|---|
jwt | string | A valid JWT signed by one of the supported OpenID providers. The JWT nonce must be prepared according to the zkLogin requirements. |
maxEpoch | cURL: string SDK: number | The max epoch used to prepare the JWT nonce. This governs the expiration of the zkLogin proof. Once it expires, you will have to ask the user to sign in again. One epoch is roughly one day. See the expiration of recent epochs in a Sui explorer like Suivision or Suiscan (note that Mainnet and Testnet are not on the same epoch). |
extendedEphemeralPublicKey | cURL: BigInt representation or Base64 encoded SDK: PublicKey | The extended ephemeral public key used to prepare the JWT nonce (see example of how to generate it here). The corresponding private key must be used to sign any transactions to be executed with this proof. |
jwtRandomness | cURL: string: BigInt representation or Base64 encoded SDK: bigint | The random bytes used to prepare the JWT nonce (see example here). |
salt | cURL: string: BigInt representation or Base64 encoded SDK: bigint | The zkLogin wallet salt. Together with the provided JWT, this determines the zkLogin wallet’s on-chain address. This method works with salts managed by Shinami, buy you, by another third party, or by the user. Note, though, that if the salt changes, the user’s address changes. |
keyClaimName | string | Optional. The claim name in the JWT that identifies a particular user. Defaults to “sub”. Currently, Mysten’s zkLogin implementation only supports the sub field of the OpenID spec. This parameter allows for forward compatibility as the implementation expands to support other values. |
{{name}}
with the actual value for that name
Type | Description |
---|---|
JSON object | The zkLogin proof for the given JWT. |
Appendix
Common issues
JSON RPC -32002 on transaction execution (Invalid user signature)
Example errorsub
value, and I was retrieving it as undefined
from session storage when generating my address seed. Once I printed out my key variable values (sub, aud, salt, maxEpoch, ephemeral Keypair public key or address) at the time of fetching the JWT and compared them to the what I fetched from session storage right before generating my address seed and zkLogin signature, I was able to catch and fix the issue. Then my transaction when through without an error.