WASM signer functions
Every user-facing 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.
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
–
Client & keys
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.
Orders
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:
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
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
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
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
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.
Last updated
Was this helpful?