Dev ManualCreate an API key

Create an API key

Use a key for server-side calls on behalf of a controller. The owner signs the exact JSON body sent to POST /api/keys. This ethers v6 example requests only catalog:read. Check the scope for your endpoint

import { sha256, toUtf8Bytes } from 'ethers'
 
export async function createCatalogKey(signer) {
  const address = (await signer.getAddress()).toLowerCase()
  const body = JSON.stringify({ name: 'Wallet catalog', scopes: ['catalog:read'] })
  const ts = Date.now().toString()
  const digest = sha256(toUtf8Bytes(body)).slice(2)
  const signature = await signer.signMessage(`AEX action · api-key-create · ${address} · ${ts} · ${digest}`)
  const response = await fetch('https://aex.human.tech/api/keys', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-owner-action': 'api-key-create',
      'x-owner-address': address,
      'x-owner-ts': ts,
      'x-owner-signature': signature,
    },
    body,
  })
  if (!response.ok) throw new Error(`Key creation returned HTTP ${response.status}`)
  return (await response.json()).key
}

Store the returned key in your backend’s secret store. AEX shows it once. Send Authorization: Bearer <key> on requests that need its scope.