> For the complete documentation index, see [llms.txt](https://docs.lighter.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lighter.xyz/developers/reference/wasm-signer.md).

# WASM signer functions

Every function exported by the lighter-go WASM signer, with its arguments in order.

Source: [`wasm/main.go`](https://github.com/elliottech/lighter-go/blob/main/wasm/main.go) in `elliottech/lighter-go`. Build instructions: [Quickstart: TypeScript + WASM](https://docs.lighter.xyz/developers/reference/pages/Qyh6D00o5aG85EZzIhv7#id-1.-build-the-signer).

## Conventions

* All functions are **synchronous globals** on `globalThis`.
* Arguments are **positional**. Every argument is required; pass `0` for unused ones. `undefined` returns an error.
* Return value is an object. Check `error` first:

```typescript
type SignResult = {
  error?: string;
  txType: number;         // pass as tx_type to sendTx
  txInfo: string;         // JSON string; pass as tx_info to sendTx
  txHash: string;
  messageToSign?: string; // always present for ChangePubKey, Transfer, ApproveIntegrator (see below)
};
```

* `messageToSign` is returned for **every** `ChangePubKey`, `Transfer` and `ApproveIntegrator`, but the server only requires the L1 signature in some cases (table below). When it's required, sign it with the owner's Ethereum wallet (`personal_sign`), then `txInfo = JSON.stringify({ ...JSON.parse(txInfo), L1Sig: signature })`. When it isn't, send `txInfo` as is and **don't prompt the wallet**.
* The last two arguments of every `Sign*` function are always `apiKeyIndex, accountIndex`, and they select a client previously created with `CreateClient`.
* `skipNonce`: `0` = strict `nonce = previous + 1`; `1` = allow any higher nonce. See [Core concepts](/developers/getting-started/core-concepts.md#nonce).

### When an L1 signature is required

"Same owner" means both accounts belong to the same master account, i.e. the same master account and its sub-accounts.

| Transaction                             | L1 signature required                                                                                                                                                                          | Not required                                                             |
| --------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `ChangePubKey`                          | Always                                                                                                                                                                                         | –                                                                        |
| `Transfer`                              | Sender and receiver have **different** owners. This includes [fast withdrawals](/developers/integration-guides/deposits-transfers-and-withdrawals.md), which are a transfer to the LP account. | Transfers between the same owner's accounts (e.g. master to sub-account) |
| `ApproveIntegrator`                     | Integrator has a **different** owner **and** at least one max fee is > 0                                                                                                                       | Zero-fee approvals and revokes; approving an account with the same owner |
| Everything else (orders, `Withdraw`, …) | Never; `messageToSign` isn't returned                                                                                                                                                          | –                                                                        |

```typescript
function needsL1Sig(kind: "changePubKey" | "transfer" | "approveIntegrator",
                    sameOwner: boolean, anyFeeAboveZero = false) {
  if (kind === "changePubKey") return true;
  if (kind === "transfer") return !sameOwner;
  return !sameOwner && anyFeeAboveZero;
}
```

## Client & keys

| Function           | Arguments                                                                 | Returns                         |
| ------------------ | ------------------------------------------------------------------------- | ------------------------------- |
| `GenerateAPIKey`   | –                                                                         | `{ privateKey, publicKey }`     |
| `CreateClient`     | `url, privateKey, chainId, apiKeyIndex, accountIndex`: pass `""` as `url` | `{}` or `{ error }`             |
| `CheckClient`      | `apiKeyIndex, accountIndex`: **don't use from WASM**, see below           | `{}` if key registered on-chain |
| `CreateAuthToken`  | `deadline (unix s, 0 = ~7h), apiKeyIndex, accountIndex`                   | `{ authToken }`                 |
| `SignChangePubKey` | `pubKeyHex, skipNonce, nonce, apiKeyIndex, accountIndex`                  | tx + `messageToSign`            |

You can create several clients (one per `apiKeyIndex`/`accountIndex` pair) in the same WASM instance.

{% hint style="warning" %}
**Do all HTTP from JavaScript**

The WASM build uses Go's HTTP client, which can't open network connections from WebAssembly (Node or browser). `CheckClient`, and any `Sign*` call with `nonce = -1` (which asks the signer to fetch the nonce itself), fail with `dial tcp: lookup …`. Always pass an explicit nonce from `GET /api/v1/nextNonce`. To verify a key, either:

* compare the `public_key` from `GET /api/v1/apikeys?account_index=…&api_key_index=…` with your public key (the API omits the `0x`), or
* sign an auth token with `CreateAuthToken` and call `GET /api/v1/accountLimits?account_index=…` with it in the `Authorization` header: `code: 200` means the key is registered.

See the [TypeScript quickstart](/developers/getting-started/quickstart-typescript.md) for a full example.
{% endhint %}

## Orders

| Function                  | Arguments                                                                                                                                                                                                                                                                           |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SignCreateOrder`         | `marketIndex, clientOrderIndex, baseAmount, price, isAsk, orderType, timeInForce, reduceOnly, triggerPrice, orderExpiry, integratorAccountIndex, integratorTakerFee, integratorMakerFee, selfTradeBehaviorMode, selfTradeEqualityMode, skipNonce, nonce, apiKeyIndex, accountIndex` |
| `SignModifyOrder`         | `marketIndex, index, baseAmount, price, triggerPrice, integratorAccountIndex, integratorTakerFee, integratorMakerFee, selfTradeBehaviorMode, selfTradeEqualityMode, skipNonce, nonce, orderVersion, apiKeyIndex, accountIndex`                                                      |
| `SignCancelOrder`         | `marketIndex, orderIndex, skipNonce, nonce, apiKeyIndex, accountIndex`                                                                                                                                                                                                              |
| `SignCancelAllOrders`     | `timeInForce, time, cancelAllMarketIndex, skipNonce, nonce, apiKeyIndex, accountIndex`                                                                                                                                                                                              |
| `SignCreateGroupedOrders` | `groupingType, orders[], integratorAccountIndex, integratorTakerFee, integratorMakerFee, selfTradeBehaviorMode, selfTradeEqualityMode, skipNonce, nonce, apiKeyIndex, accountIndex`                                                                                                 |

Enum values (order type, time in force, self-trade modes) are listed in [Data Structures, Constants and Errors](/developers/reference/data-structures-constants-and-errors.md) and [Signing Transactions](/developers/integration-guides/signing-transactions.md).

### SignCreateGroupedOrders

`orders` is an array of objects:

```typescript
{ MarketIndex, ClientOrderIndex, BaseAmount, Price, IsAsk, Type,
  TimeInForce, ReduceOnly, TriggerPrice, OrderExpiry }
```

`groupingType`: `1` one-triggers-the-other (OTO) · `2` one-cancels-the-other (OCO) · `3` OTOCO.

### SignCancelAllOrders

* `timeInForce`: `0` immediate · `1` scheduled (at `time`, ms) · `2` abort a scheduled cancel
* `cancelAllMarketIndex`: a market ID, or `255` for all markets. Per-market cancel must be immediate.

## Leverage & margin

| Function             | Arguments                                                                                                                                          |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SignUpdateLeverage` | `marketIndex, fraction, marginMode, skipNonce, nonce, apiKeyIndex, accountIndex` – `fraction = 10000 / leverage`; `marginMode` 0 cross, 1 isolated |
| `SignUpdateMargin`   | `marketIndex, usdcAmount, direction, skipNonce, nonce, apiKeyIndex, accountIndex` – `direction` 1 add, 0 remove                                    |

## Funds

| Function       | Arguments                                                                                                                    |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `SignWithdraw` | `assetIndex, routeType, amount, skipNonce, nonce, apiKeyIndex, accountIndex`                                                 |
| `SignTransfer` | `toAccountIndex, assetIndex, fromRouteType, toRouteType, amount, usdcFee, memo, skipNonce, nonce, apiKeyIndex, accountIndex` |

`routeType`: `0` perps, `1` spot. `memo`: 32-byte hex string.

## Accounts, pools & staking

| Function                       | Arguments                                                                                                 |
| ------------------------------ | --------------------------------------------------------------------------------------------------------- |
| `SignCreateSubAccount`         | `skipNonce, nonce, apiKeyIndex, accountIndex`                                                             |
| `SignCreatePublicPool`         | `operatorFee, initialTotalShares, minOperatorShareRate, skipNonce, nonce, apiKeyIndex, accountIndex`      |
| `SignUpdatePublicPool`         | `publicPoolIndex, status, operatorFee, minOperatorShareRate, skipNonce, nonce, apiKeyIndex, accountIndex` |
| `SignMintShares`               | `publicPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex`                               |
| `SignBurnShares`               | `publicPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex`                               |
| `SignStakeAssets`              | `stakingPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex`                              |
| `SignUnstakeAssets`            | `stakingPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex`                              |
| `SignUpdateAccountConfig`      | `accountTradingMode, skipNonce, nonce, apiKeyIndex, accountIndex`                                         |
| `SignUpdateAccountAssetConfig` | `assetIndex, assetMarginMode, skipNonce, nonce, apiKeyIndex, accountIndex`                                |

## Integrators

| Function                | Arguments                                                                                                                                            |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SignApproveIntegrator` | `integratorIndex, maxPerpsTakerFee, maxPerpsMakerFee, maxSpotTakerFee, maxSpotMakerFee, approvalExpiry, skipNonce, nonce, apiKeyIndex, accountIndex` |

See [Partner Attribution](/developers/integration-guides/partner-attribution.md).

## Other languages

The same signer ships as a C shared library (`.so` / `.dylib` / `.dll`) for Python, Rust, Java and C++, plus a React Native build. See the [lighter-go releases](https://github.com/elliottech/lighter-go/releases).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lighter.xyz/developers/reference/wasm-signer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
