# ENOKI HTTP API Request on React Native

**URL:** <https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097>\
**Category:** zkLogin\
**Tags:** sdk\
**Created:** [October 5, 2025, 4:53pm UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097 "2025-10-05T16:53:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![0xserkantoraman](https://avatars.discourse-cdn.com/v4/letter/0/bc79bd/32.png) [@0xserkantoraman](https://forums.sui.io/u/0xserkantoraman)\
**Post date:** [October 5, 2025, 4:53pm UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097/1 "2025-10-05T16:53:16Z")

</div>

We are developing a mobile app using Expo (React Native). Since the @mysten/enoki package throws an error in React Native, we want to use the Enoki HTTP API instead. However, I received an error during the /v1/zklogin/nonce request.

I sent the ephemeral key as Base64 using the following code:

`export function makeEphemeralPublicKey() {`  
`const kp = Ed25519Keypair.generate();`  
`const publicKey = kp.getPublicKey().toBase64();`  
`return publicKey;`  
`}`  
But I received this error:  
`{“errors”:[{“code”:“custom”,“message”:“Public key is not a valid Ed25519 or Secp256r1 public key”,“path”:[“ephemeralPublicKey”]}]}`

For reference, an example ephemeralPublicKey returned by the `makeEphemeralPublicKe` function is:  
uBkVkSG71lcWXiCJO5/+0NzPdyLu9yYubzckl42I/kA=

How can I fix this error?

---

<div class="post-metadata">

**Author:** ![nikos.petridis](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/nikos.petridis/32/31604_2.png) [@nikos.petridis](https://forums.sui.io/u/nikos.petridis)\
**Post date:** [October 6, 2025, 12:03pm UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097/2 "2025-10-06T12:03:58Z")

</div>

Can you post an example of the public key you post to the api?  
Two common catches are:

1. accidentally sending Sui’s **flag-prefixed** public key (aka “SuiPublicKey”, 33 bytes), or

2. sending something that isn’t exactly 32 bytes after base64-decoding.

---

<div class="post-metadata">

**Author:** ![0xserkantoraman](https://avatars.discourse-cdn.com/v4/letter/0/bc79bd/32.png) [@0xserkantoraman](https://forums.sui.io/u/0xserkantoraman)\
**Post date:** [October 7, 2025, 7:28am UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097/3 "2025-10-07T07:28:58Z")

</div>

Here’s an example ephemeralPublicKey I send to the API:

> zZQ6r425fk/bgxz3kTjtlOQ67cMzzZTZv0szIIlzjVc=

This key is created by generating a new Ed25519 keypair and converting the public key to Base64:  
const kp = Ed25519Keypair.generate();  
const publicKey = kp.getPublicKey().toBase64();

---

<div class="post-metadata">

**Author:** ![nikos.petridis](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/nikos.petridis/32/31604_2.png) [@nikos.petridis](https://forums.sui.io/u/nikos.petridis)\
**Post date:** [October 21, 2025, 12:29pm UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097/4 "2025-10-21T12:29:52Z")

</div>

Thanks for the sample. The issue seems to be that getPublicKey().toBase64() returns Sui’s **flag-prefixed** public key (“SuiPublicKey”), while Enoki expects the **raw** public key bytes.

Try the following and send the raw 32-byte key, base64-encoded:

```typescript
import { toB64 } from ‘@mysten/bcs’;
import { Ed25519Keypair } from ‘@mysten/sui.js/cryptography’;

const kp = Ed25519Keypair.generate();
// ❌ Sui format (flag + key): kp.getPublicKey().toBase64()
// ✅ Raw 32B:
const ephemPkB64 = toB64(kp.getPublicKey().toRawBytes());

const res = await fetch(‘https://api.enoki.mystenlabs.com/v1/zklogin/nonce’, {
  method: ‘POST’,
  headers: {
    ‘Content-Type’: ‘application/json’,
    ‘Authorization’: Bearer ${ENOKI_API_KEY}, // if required
  },
  body: JSON.stringify({
    network: ‘testnet’, // optional
    ephemeralPublicKey: ephemPkB64, // raw key in base64
  }),
});

```

To make sure you send the correct format base64-decode before sending and ensure length === 32 for Ed25519

---

<div class="post-metadata">

**Author:** ![0xserkantoraman](https://avatars.discourse-cdn.com/v4/letter/0/bc79bd/32.png) [@0xserkantoraman](https://forums.sui.io/u/0xserkantoraman)\
**Post date:** [October 22, 2025, 9:21pm UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097/5 "2025-10-22T21:21:57Z")

</div>

Thanks for the feedback.  
toRawBytes() didn’t work for me for some reason, but when I changed it as below, it worked:

```auto
const publicKey = toB64(kp.getPublicKey().toSuiBytes());

```

I’m developing a dApp on mobile. I realized that passing the nonce to googleSignin is a bit problematic compared to the web app. So I tried using the zkLogin HTTP request instead:

```auto
fetch("https://api.enoki.mystenlabs.com/v1/zklogin", {
  method: "GET",
  headers: {
    "zklogin-jwt": "string",
    "Authorization": "Bearer "
  }
})

```

This returns:

```auto
{
  "data": {
    "salt": "string",
    "address": "string",
    "publicKey": "string"
  }
}

```

The issue is that, when I want to request a zero-knowledge proof, I’m providing randomness but not requesting a salt. How should I handle creating the zero-knowledge proof in this case?

```auto
const body = JSON.stringify({
  "ephemeralPublicKey": "string",
  "maxEpoch": 0,
  "randomness": "string"
})

fetch("https://api.enoki.mystenlabs.com/v1/zklogin/zkp", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "zklogin-jwt": "string",
    "Authorization": "Bearer "
  },
  body
})

```

---

<div class="post-metadata">

**Author:** ![nikos.petridis](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/nikos.petridis/32/31604_2.png) [@nikos.petridis](https://forums.sui.io/u/nikos.petridis)\
**Post date:** [October 30, 2025, 11:15am UTC](https://forums.sui.io/t/enoki-http-api-request-on-react-native/49097/6 "2025-10-30T11:15:38Z")

</div>

Let me write the flow step by step, it might help clarify that part. So,

1. Create a nonce (Enoki server)  
• You send your raw 32-byte Ed25519 ephemeral public key (base64).  
• Enoki returns { nonce, randomness, epoch, maxEpoch }.

```auto
curl -X POST https://api.enoki.mystenlabs.com/v1/zklogin/nonce \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <YOUR_ENOKI_API_KEY>' \
  -d '{"ephemeralPublicKey":"<base64 32B>"}'

```

1. Do OAuth with your provider

- Pass the nonce from step 1 into the provider’s login.
- You receive a JWT from the provider.

1. (Optional) Get salt/address (Enoki server)

- Useful to confirm the derived Sui address before proving

```auto
curl -X GET https://api.enoki.mystenlabs.com/v1/zklogin \
  -H 'Authorization: Bearer <YOUR_ENOKI_API_KEY>' \
  -H 'zklogin-jwt: <OIDC_JWT_FROM_PROVIDER>'

```

1. Request the ZK proof (Enoki server)

- You do **not** send salt here.
- Send the **same** ephemeralPublicKey, the maxEpoch, and the exact randomness from step 1, plus the JWT in a header.

```auto
curl -X POST https://api.enoki.mystenlabs.com/v1/zklogin/zkp \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <YOUR_ENOKI_API_KEY>' \
  -H 'zklogin-jwt: <OIDC_JWT_FROM_PROVIDER>' \
  -d '{
    "ephemeralPublicKey":"<base64 32B>",
    "maxEpoch": <from step 1>,
    "randomness":"<from step 1>"
  }'

```

Let me know if something does not work
