> For the complete documentation index, see [llms.txt](https://docs.unix.market/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unix.market/authentication/signing-method-b-typed-data.md).

# Signing Method B — Typed Data

Method B signs an operation-specific EIP-712 struct directly. It does not compute `actionHash`, does not use an Action Tag, and does not use `target_address`.

Method B is used for Agent management and sub-account creation.

## Method B Endpoints

| Endpoint                         | Action             |
| -------------------------------- | ------------------ |
| `POST /v1/account/approve-agent` | Approve Agent Key  |
| `POST /v1/account/revoke-agent`  | Revoke Agent Key   |
| `POST /v1/account/renew-agent`   | Renew Agent Key    |
| `POST /v1/account/create-sub`    | Create sub-account |

All other write endpoints use [Signing Method A](broken://pages/3b457b2c7c07361c47d7e076750634c56318fe7f).

## Difference From Method A

| Aspect                 | Method A                                                     | Method B                  |
| ---------------------- | ------------------------------------------------------------ | ------------------------- |
| Signed struct          | `Agent(...)` wrapper                                         | Operation-specific struct |
| `actionHash`           | Required                                                     | Not used                  |
| Action Tag             | Required                                                     | Not used                  |
| `target_address`       | Supported by the `Agent` wrapper                             | Not used                  |
| EIP-712 Domain         | Same                                                         | Same                      |
| `signing_hash` formula | `keccak256(concat("\x19\x01", domainSeparator, structHash))` | Same                      |
| `tx_hash`              | `signing_hash`                                               | `signing_hash`            |

## EIP-712 Domain

```json
{
  "name": "UniX",
  "version": "1",
  "chainId": 1,
  "verifyingContract": "0x0000000000000000000000000000000000000000"
}
```

Domain type:

```
EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)
```

## Typed Data Definitions

### ApproveAgent

```
ApproveAgent(address signerAddress,address agentAddress,address authorizedAddress,uint32 validDays,string label,uint64 nonce,uint64 expiresAfter)
```

| EIP-712 field       | Type      | Source                             |
| ------------------- | --------- | ---------------------------------- |
| `signerAddress`     | `address` | HTTP `signer_address`              |
| `agentAddress`      | `address` | Request field `agent_address`      |
| `authorizedAddress` | `address` | Request field `authorized_address` |
| `validDays`         | `uint32`  | Request field `valid_days`         |
| `label`             | `string`  | Request field `label`              |
| `nonce`             | `uint64`  | HTTP `nonce`                       |
| `expiresAfter`      | `uint64`  | HTTP `expires_after`               |

### RevokeAgent

```
RevokeAgent(address signerAddress,address agentAddress,uint64 nonce,uint64 expiresAfter)
```

| EIP-712 field   | Type      | Source                        |
| --------------- | --------- | ----------------------------- |
| `signerAddress` | `address` | HTTP `signer_address`         |
| `agentAddress`  | `address` | Request field `agent_address` |
| `nonce`         | `uint64`  | HTTP `nonce`                  |
| `expiresAfter`  | `uint64`  | HTTP `expires_after`          |

### RenewAgent

```
RenewAgent(address signerAddress,address agentAddress,uint32 validDays,uint64 nonce,uint64 expiresAfter)
```

| EIP-712 field   | Type      | Source                        |
| --------------- | --------- | ----------------------------- |
| `signerAddress` | `address` | HTTP `signer_address`         |
| `agentAddress`  | `address` | Request field `agent_address` |
| `validDays`     | `uint32`  | Request field `valid_days`    |
| `nonce`         | `uint64`  | HTTP `nonce`                  |
| `expiresAfter`  | `uint64`  | HTTP `expires_after`          |

### CreateSubAccount

```
CreateSubAccount(address signerAddress,string label,uint64 nonce,uint64 expiresAfter)
```

| EIP-712 field   | Type      | Source                |
| --------------- | --------- | --------------------- |
| `signerAddress` | `address` | HTTP `signer_address` |
| `label`         | `string`  | Request field `label` |
| `nonce`         | `uint64`  | HTTP `nonce`          |
| `expiresAfter`  | `uint64`  | HTTP `expires_after`  |

## Encoding

`structHash` follows standard EIP-712 struct encoding:

```
typeHash = keccak256(encodeType)
structHash = keccak256(concat(typeHash, encoded_field_1, encoded_field_2, ...))
signing_hash = keccak256(concat("\x19\x01", domainSeparator, structHash))
```

Field order must match the type string exactly.

| Type      | Encoding                                |
| --------- | --------------------------------------- |
| `address` | 20-byte address left-padded to 32 bytes |
| `uint32`  | Value left-padded to 32 bytes           |
| `uint64`  | Value left-padded to 32 bytes           |
| `string`  | `keccak256(utf8_bytes(value))`          |

## Example — Approve Agent Key

```python
import time, requests
from eth_account import Account
from eth_account.messages import encode_typed_data

nonce = int(time.time() * 1000)
expires_after = nonce + 600_000

domain = {
    "name": "UniX",
    "version": "1",
    "chainId": 1,
    "verifyingContract": "0x0000000000000000000000000000000000000000",
}
types = {"ApproveAgent": [
    {"name": "signerAddress", "type": "address"},
    {"name": "agentAddress", "type": "address"},
    {"name": "authorizedAddress", "type": "address"},
    {"name": "validDays", "type": "uint32"},
    {"name": "label", "type": "string"},
    {"name": "nonce", "type": "uint64"},
    {"name": "expiresAfter", "type": "uint64"},
]}
message = {
    "signerAddress": "0xYOUR_ADDRESS",
    "agentAddress": "0xAGENT_ADDRESS",
    "authorizedAddress": "0xYOUR_ADDRESS",
    "validDays": 30,
    "label": "mm-bot-prod",
    "nonce": nonce,
    "expiresAfter": expires_after,
}

signed = Account.sign_message(
    encode_typed_data(domain, types, "ApproveAgent", message),
    private_key="0xYOUR_PRIVATE_KEY",
)

resp = requests.post("https://api.unixtrade.pro/v1/account/approve-agent", json={
    "agent_address": "0xAGENT_ADDRESS",
    "authorized_address": "0xYOUR_ADDRESS",
    "valid_days": 30,
    "label": "mm-bot-prod",
    "signer_address": "0xYOUR_ADDRESS",
    "nonce": nonce,
    "expires_after": expires_after,
    "signature": {"r": hex(signed.r), "s": hex(signed.s), "v": signed.v},
})
print(resp.json())
```

The node recomputes the typed struct, recovers the signer with `ecrecover`, and rejects the request unless the recovered address equals `signer_address`.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.unix.market/authentication/signing-method-b-typed-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
