|
| 1 | +# Hyperliquid signing modes |
| 2 | + |
| 3 | +This document records the signing-mode decisions for this app. Do not change |
| 4 | +an action from L1 to user-signed, or the reverse, without checking the SDK source |
| 5 | +and repeating the relevant recovery/API probe. |
| 6 | + |
| 7 | +## Two signing modes |
| 8 | + |
| 9 | +Hyperliquid has two distinct signing families: |
| 10 | + |
| 11 | +- **User-signed EIP-712**: actions such as `approveAgent`, `usdSend`, |
| 12 | + `spotSend`, `withdraw`, `usdClassTransfer`, `approveBuilderFee`, |
| 13 | + `tokenDelegate`, `convertToMultiSigUser`, and `sendAsset`. These use the |
| 14 | + `HyperliquidSignTransaction` domain and an action-specific |
| 15 | + `HyperliquidTransaction:*` primary type. |
| 16 | +- **L1 actions**: actions such as `order`, `cancel`, `vaultTransfer`, |
| 17 | + `createVault`, `vaultModify`, `vaultDistribute`, `subAccountTransfer`, |
| 18 | + `subAccountSpotTransfer`, and `createSubAccount`. These are hashed with the |
| 19 | + Hyperliquid action hash and signed as `Exchange` / `Agent` typed data. |
| 20 | + |
| 21 | +`L1` here means Hyperliquid's exchange action signing scheme, not an Ethereum |
| 22 | +L1 RPC transaction. Do not add a fake chain 1337 network to a browser wallet. |
| 23 | + |
| 24 | +## Vault and sub-account operations |
| 25 | + |
| 26 | +Keep these actions in the L1 signing family: |
| 27 | + |
| 28 | +- `vaultTransfer`: deposit USDC into a vault or withdraw USDC from a vault. |
| 29 | +- `vaultModify`: change vault settings. |
| 30 | +- `vaultDistribute`: distribute vault funds back to depositors. |
| 31 | +- `subAccountTransfer`: move USDC to or from a sub-account. |
| 32 | +- `subAccountSpotTransfer`: move spot tokens to or from a sub-account. |
| 33 | +- `createSubAccount`: create a new named sub-account. |
| 34 | + |
| 35 | +These actions are operational Hyperliquid exchange actions. They are not the |
| 36 | +same user-signed family as `usdSend`, `spotSend`, `withdraw`, or |
| 37 | +`approveAgent`. Browser-wallet success against a locally invented |
| 38 | +`HyperliquidTransaction:*` schema is not evidence that Hyperliquid will accept |
| 39 | +the submit. |
| 40 | + |
| 41 | +## createVault decision |
| 42 | + |
| 43 | +`createVault` is an L1 action. |
| 44 | + |
| 45 | +References: |
| 46 | + |
| 47 | +- nktkas TypeScript SDK `createVault.ts` marks `createVault` as |
| 48 | + `Signing: L1 Action` and calls `executeL1Action`. |
| 49 | + https://github.com/nktkas/hyperliquid/blob/main/src/api/exchange/_methods/createVault.ts |
| 50 | +- The same SDK marks `approveAgent` as `Signing: User-Signed EIP-712` and calls |
| 51 | + `executeUserSignedAction`. |
| 52 | + https://github.com/nktkas/hyperliquid/blob/main/src/api/exchange/_methods/approveAgent.ts |
| 53 | +- The same SDK marks `vaultTransfer` as `Signing: L1 Action`. |
| 54 | + https://github.com/nktkas/hyperliquid/blob/main/src/api/exchange/_methods/vaultTransfer.ts |
| 55 | +- Hyperliquid documents API wallets/agents as keys approved to sign on behalf |
| 56 | + of the master account. |
| 57 | + https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets |
| 58 | + |
| 59 | +## createVault test history |
| 60 | + |
| 61 | +The user-signed `createVault` experiment was wrong: |
| 62 | + |
| 63 | +- Browser wallets signed the local user-signed payload successfully. |
| 64 | +- Local recovery matched the listed signers. |
| 65 | +- Hyperliquid rejected the final multisig submit with |
| 66 | + `Invalid multi-sig inner signer`. |
| 67 | +- Recovering those signatures against the SDK L1 digest returned different |
| 68 | + addresses. They were valid signatures over the wrong digest. |
| 69 | + |
| 70 | +The SDK-correct direct multisig L1 browser path was also tested: |
| 71 | + |
| 72 | +- The exact SDK inner payload was captured: |
| 73 | + `domain.name = Exchange`, `domain.chainId = 1337`, |
| 74 | + `primaryType = Agent`. |
| 75 | +- Rabby rejected it before showing a useful signing path with: |
| 76 | + `chainId should be same as current chainId | -32602`. |
| 77 | +- Do not retry fake chain switching or ask users to add chain 1337. |
| 78 | + |
| 79 | +The base single-EOA L1 createVault path was validated: |
| 80 | + |
| 81 | +- A disposable underfunded EOA signed SDK-correct L1 `createVault`. |
| 82 | +- Hyperliquid returned `Insufficient balance to create vault`. |
| 83 | +- Mutating the action after signing, or mutating the signature, returned |
| 84 | + recovered-signer errors instead of the balance error. This proves the |
| 85 | + insufficient-balance response happens after valid signer recovery. |
| 86 | + |
| 87 | +The agent-wallet path was partially validated: |
| 88 | + |
| 89 | +- A throwaway unapproved agent key signed SDK-correct single-agent L1 |
| 90 | + `createVault`. |
| 91 | +- Hyperliquid returned `User or API Wallet ... does not exist`, proving the |
| 92 | + server recovered the signer and reached API-wallet authorisation. |
| 93 | +- The viable next path for browser multisigs that cannot sign `Exchange` / |
| 94 | + `Agent` directly is: |
| 95 | + 1. Approve a generated agent wallet through multisig `approveAgent`. |
| 96 | + 2. Verify the agent with a no-cost L1 action such as `noop`. |
| 97 | + 3. Submit `createVault` signed by that approved agent. |
| 98 | + |
| 99 | +The agent wallet is a separate revocable API key. It is not a multisig signer |
| 100 | +private key, and it should be stored and rotated like any other trading agent |
| 101 | +key. |
| 102 | + |
| 103 | +## Action classification checklist |
| 104 | + |
| 105 | +Before adding a new action: |
| 106 | + |
| 107 | +1. Check the nktkas SDK method source for `Signing: L1 Action` or |
| 108 | + `Signing: User-Signed EIP-712`. |
| 109 | +2. Check whether the SDK method calls `executeL1Action` or |
| 110 | + `executeUserSignedAction`. |
| 111 | +3. If it is L1, ensure the action object is canonical and does not include |
| 112 | + user-signed fields such as `signatureChainId` or `hyperliquidChain`. |
| 113 | +4. If it is user-signed, ensure the action includes the SDK's user-signed |
| 114 | + fields and the correct action-specific EIP-712 primary type. |
| 115 | +5. For multisig submit, keep the outer `SendMultiSig` signature path unchanged: |
| 116 | + trim inner signature `r`/`s`, use the same nonce as the inner action, and |
| 117 | + commit to the same `outerSigner` in every inner signature. |
0 commit comments