WASM signer functions
Every function exported by the lighter-go WASM signer, with its arguments in order.
Source: wasm/main.go in elliottech/lighter-go. Build instructions: Quickstart: TypeScript + WASM.
Conventions
- All functions are synchronous globals on
globalThis. - Arguments are positional. Every argument is required; pass
0for unused ones.undefinedreturns an error. - Return value is an object. Check
errorfirst:
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)
};messageToSignis returned for everyChangePubKey,TransferandApproveIntegrator, 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), thentxInfo = JSON.stringify({ ...JSON.parse(txInfo), L1Sig: signature }). When it isn't, sendtxInfoas is and don't prompt the wallet.- The last two arguments of every
Sign*function are alwaysapiKeyIndex, accountIndex, and they select a client previously created withCreateClient. skipNonce:0= strictnonce = previous + 1;1= allow any higher nonce. See Core concepts.
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, 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 | – |
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.
Do all HTTP from JavaScriptThe WASM build uses Go's HTTP client, which can't open network connections from WebAssembly (Node or browser).
CheckClient, and anySign*call withnonce = -1(which asks the signer to fetch the nonce itself), fail withdial tcp: lookup …. Always pass an explicit nonce fromGET /api/v1/nextNonce. To verify a key, either:
- compare the
public_keyfromGET /api/v1/apikeys?account_index=…&api_key_index=…with your public key (the API omits the0x), or- sign an auth token with
CreateAuthTokenand callGET /api/v1/accountLimits?account_index=…with it in theAuthorizationheader:code: 200means the key is registered.See the TypeScript quickstart for a full example.
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 and Signing Transactions.
SignCreateGroupedOrders
orders is an array of objects:
{ 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:0immediate ·1scheduled (attime, ms) ·2abort a scheduled cancelcancelAllMarketIndex: a market ID, or255for 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.
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.
Updated 2 days ago
