Authentication and signing
Altar has no API keys and no session tokens. A route that needs to know who you are asks for a typed-data signature (EIP-712) made by your wallet. The server recovers your address from the signature and checks it. Every signed message carries a timestamp, so a signature expires.
The rules
Section titled “The rules”- The timestamp is in milliseconds since the Unix epoch. It must be at most 60 minutes old and at most 5 minutes in the future. Older signatures fail with HTTP 401.
- The domain is fixed. All messages use the same domain, shown below. The chain identifier in it is only part of the signature domain. It does not depend on the chains a campaign tracks, and you do not need to switch your wallet network.
- Each message is bound to what it authorizes. A login signature is bound to one campaign. An admin-read signature is bound to one campaign and one purpose. Each admin change signs its own typed data. A signature of one kind is not accepted for another.
- The request body repeats the data. You send the
signatureand aninputsobject. The server rebuilds the message frominputs(and from stored campaign data where needed) and checks the signature against it. - Large integers in a body use the form
{ "__type__": "bigint", "value": "123" }.
The kinds of signature
Section titled “The kinds of signature”| Kind | Use |
|---|---|
login |
Proves you own a points address in one campaign. The message includes the campaign identifier and the campaign short terms text, so the login of one campaign is no good in another. Used to read your private data and to list your addresses. |
adminRead |
One signature per campaign that opens every admin read route of that campaign. Reads and writes use different typed data, so a leaked login never works on an admin route. |
instanceLogin |
The same idea for instance admins. It binds no campaign. |
addressGeneration |
Asks for your deposit address on one network. |
referralSubmission |
Referrals. The message names the action (submit or disconnect), so a signature for one cannot be replayed for the other. |
report |
A report about a deposit. |
| Admin changes | projectCreation, campaignImport, projectUpdate, networkManagement, tokenManagement, adminManagement, sacrificeMutation, reportToggle, addressPoolUpload. Each signs exactly what it changes. |
One more signature, RegisterVoucher, belongs to the onchain registry and uses the registry contract as its domain. See Onchain ID registry.
Every message
Section titled “Every message”This section is generated when the docs are built. It is read from the OpenAPI document, which is generated from the signers in @provex/eip712-utils. If the code changes a message, this section changes with it.
All messages use this domain:
{
"name": "ProveX",
"version": "1",
"chainId": 1,
"verifyingContract": "0x0000000000000000000000000000000000000000"
}projectCreation (primary type ProjectCreation)
| Field | Solidity type |
|---|---|
projectId | string |
timestamp | uint256 |
projectName | string |
projectDescription | string |
projectWebsite | string |
projectLogo | string |
projectTagline | string |
projectAccentColor | string |
projectAccentColorVariant | string |
projectBanner | string |
projectDisclaimerShort | string |
projectDisclaimerLong | string |
projectSocialLinks | string |
projectTags | string |
startTime | uint256 |
inflectionTime | uint256 |
endTime | uint256 |
disabled | bool |
decayRateSingleStep | uint256 |
decaySingleStepDelaySeconds | uint256 |
volumeBonusRate | uint256 |
usdToPointBaseRate | uint256 |
volumeBonusCutoff | uint256 |
flatBonusCutoff | uint256 |
flatBonusRate | uint256 |
referralRate | uint256 |
countEarlySacrifices | bool |
useInflectionStepOne | bool |
priceValidFromTimestamp | string |
incrementMode | string |
registryAddress | string |
Used by: POST /projects
addressGeneration (primary type AddressGeneration)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
timestamp | uint256 |
Used by: POST /address
login (primary type Validate)
| Field | Solidity type |
|---|---|
purpose | string |
projectId | string |
timestamp | uint256 |
termsOfUse | string |
Used by: POST /address/all
referralSubmission (primary type ReferralSubmission)
| Field | Solidity type |
|---|---|
projectId | string |
referrerAddress | string |
action | string |
timestamp | uint256 |
Used by: POST /referral, POST /referral/disconnect
report (primary type Report)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
blockHash | string |
tokenAddress | string |
transactionHash | string |
logIndex | uint32 |
logType | string |
timestamp | uint256 |
message | string |
Used by: POST /reports
adminRead (primary type AdminRead)
| Field | Solidity type |
|---|---|
purpose | string |
projectId | string |
timestamp | uint256 |
Used by: POST /admin/projects, POST /admin/project, POST /admin/campaign/export, POST /admin/latest-block, POST /admin/referrals, POST /admin/sacrifice-mutations, POST /admin/price-overrides, POST /admin/sacrifice-details, POST /admin/reports
campaignImport (primary type CampaignImport)
| Field | Solidity type |
|---|---|
config | string |
timestamp | uint256 |
Used by: POST /admin/campaign/import
networkManagement (primary type NetworkManagement)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
action | string |
timestamp | uint256 |
rootAddress | string |
networkName | string |
lowestBlock | uint256 |
lowerRange | uint256 |
upperRange | uint256 |
rpcUrls | string |
Used by: POST /admin/network
projectUpdate (primary type ProjectUpdate)
| Field | Solidity type |
|---|---|
projectId | string |
timestamp | uint256 |
projectName | string |
projectWebsite | string |
projectDescription | string |
projectLogo | string |
projectTagline | string |
projectAccentColor | string |
projectAccentColorVariant | string |
projectBanner | string |
projectDisclaimerShort | string |
projectDisclaimerLong | string |
projectSocialLinks | string |
projectTags | string |
startTime | uint256 |
inflectionTime | uint256 |
endTime | uint256 |
decaySingleStepDelaySeconds | uint256 |
volumeBonusCutoff | uint256 |
flatBonusCutoff | uint256 |
decayRateSingleStep | uint256 |
usdToPointBaseRate | uint256 |
flatBonusRate | uint256 |
referralRate | uint256 |
countEarlySacrifices | bool |
useInflectionStepOne | bool |
Used by: POST /admin/project/update
tokenManagement (primary type TokenManagement)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
action | string |
timestamp | uint256 |
tokenAddress | string |
source | string |
market | string |
searchable | string |
Used by: POST /admin/token
adminManagement (primary type AdminManagement)
| Field | Solidity type |
|---|---|
projectId | string |
address | string |
action | string |
timestamp | uint256 |
Used by: POST /admin/admin
sacrificeMutation (primary type SacrificeMutation)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
blockHash | string |
transactionHash | string |
tokenAddress | string |
logIndex | uint32 |
logType | string |
action | string |
timestamp | uint256 |
amount | string |
pointsDestinationAddress | string |
userAddressListIndex | string |
source | string |
market | string |
sacrificeTimestamp | string |
blockNumber | string |
blockStatus | string |
tokenSymbol | string |
tokenName | string |
tokenDecimals | string |
price | string |
reason | string |
Used by: POST /admin/sacrifice-mutation/upsert
reportToggle (primary type ReportToggle)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
blockHash | string |
tokenAddress | string |
transactionHash | string |
logIndex | uint32 |
logType | string |
signerAddress | string |
ignored | bool |
timestamp | uint256 |
Used by: POST /admin/report/toggle-ignored
addressPoolUpload (primary type AddressPoolUpload)
| Field | Solidity type |
|---|---|
projectId | string |
networkType | string |
chainId | uint256 |
rangeStart | uint256 |
count | uint256 |
merkleRoot | bytes32 |
timestamp | uint256 |
Used by: POST /admin/address-pool/begin
instanceLogin (primary type InstanceLogin)
| Field | Solidity type |
|---|---|
purpose | string |
timestamp | uint256 |
Used by: POST /admin/instance/whoami, POST /admin/instance/labels, POST /admin/instance/labels/add, POST /admin/instance/labels/remove, POST /admin/instance/activity, POST /admin/instance/campaigns, POST /admin/instance/identities, POST /admin/instance/cycle-status, GET /admin/instance/activity/stream
Examples with viem
Section titled “Examples with viem”The code below is the real file src/lib/signing-examples.ts of the docs package. Its tests run each example and check the result with the server-side signer objects. You only need viem. In a browser, replace account with the wallet client of the user.
/** * Signing examples shown on the "Authentication and signing" page. * * This file is the source of the code samples on that page (the page imports it as raw text), * and `signing-examples.test.ts` runs it. The tests check that each message recovers to the * signer with the real server-side signer objects, so a sample that drifts from the server * fails the build of the docs tests instead of misleading a reader. * * Only `viem` is needed to sign. Replace `account` with a wallet client in a browser. */import type { Account, Hex } from 'viem'
/** The domain every Altar typed-data message uses. */export const ALTAR_DOMAIN = { name: 'ProveX', version: '1', chainId: 1, verifyingContract: '0x0000000000000000000000000000000000000000',} as const
/** Send large integers to the API in this object form. */export const toApiBigint = (value: bigint) => ({ __type__: 'bigint', value: value.toString() })
/** Timestamps are milliseconds since the Unix epoch. Signatures expire 60 minutes after this time. */export const nowAsTimestamp = (): bigint => BigInt(Date.now())
/** The value the login message carries in its `purpose` field. */export const LOGIN_PURPOSE = 'sacrifice_address_login'
/** The value the admin-read message carries in its `purpose` field. */export const ADMIN_READ_PURPOSE = 'altar_admin_read'
/** * Sign in to one campaign. The login message is bound to the campaign: it includes the * campaign identifier and the campaign short terms text (`projectDisclaimerShort`, empty * when the campaign has none). The server rebuilds the same message to check it. */export const signLogin = async (options: { account: Account projectId: string termsOfUse: string timestamp: bigint}): Promise<Hex> => options.account.signTypedData!({ domain: ALTAR_DOMAIN, types: { Validate: [ { name: 'purpose', type: 'string' }, { name: 'projectId', type: 'string' }, { name: 'timestamp', type: 'uint256' }, { name: 'termsOfUse', type: 'string' }, ], }, primaryType: 'Validate', message: { purpose: LOGIN_PURPOSE, projectId: options.projectId, timestamp: options.timestamp, termsOfUse: options.termsOfUse, }, })
/** Request body for `POST /address/all` and other login-signed routes that take `projectId`. */export const buildLoginRequestBody = (options: { signature: Hex; projectId: string; timestamp: bigint }) => ({ signature: options.signature, projectId: options.projectId, inputs: { timestamp: toApiBigint(options.timestamp) },})
/** * One admin-read signature opens every admin READ route of one campaign. Reads and writes * use different typed data, so a login signature never works on an admin route. */export const signAdminRead = async (options: { account: Account projectId: string timestamp: bigint}): Promise<Hex> => options.account.signTypedData!({ domain: ALTAR_DOMAIN, types: { AdminRead: [ { name: 'purpose', type: 'string' }, { name: 'projectId', type: 'string' }, { name: 'timestamp', type: 'uint256' }, ], }, primaryType: 'AdminRead', message: { purpose: ADMIN_READ_PURPOSE, projectId: options.projectId, timestamp: options.timestamp, }, })
/** What a referral signature authorizes. The action is signed, so it cannot be swapped. */export type ReferralAction = 'submit' | 'disconnect'
/** * Sign a referral. `submit` links you to a referrer. `disconnect` ends the link. * A signature made for one action fails on the other route. */export const signReferral = async (options: { account: Account projectId: string referrerAddress: string action: ReferralAction timestamp: bigint}): Promise<Hex> => options.account.signTypedData!({ domain: ALTAR_DOMAIN, types: { ReferralSubmission: [ { name: 'projectId', type: 'string' }, { name: 'referrerAddress', type: 'string' }, { name: 'action', type: 'string' }, { name: 'timestamp', type: 'uint256' }, ], }, primaryType: 'ReferralSubmission', message: { projectId: options.projectId, // The server lowercases the referrer address before it checks the signature. // Sign the lowercase form, or the signature will not verify. referrerAddress: options.referrerAddress.toLowerCase(), action: options.action, timestamp: options.timestamp, }, })
/** Request body for `POST /referral` and `POST /referral/disconnect`. */export const buildReferralRequestBody = (options: { signature: Hex projectId: string referrerAddress: string timestamp: bigint}) => ({ signature: options.signature, inputs: { projectId: options.projectId, referrerAddress: options.referrerAddress, timestamp: toApiBigint(options.timestamp), },})
/** Sign the request for your deposit address on one network (`POST /address`). */export const signAddressRequest = async (options: { account: Account projectId: string networkType: string chainId: bigint timestamp: bigint}): Promise<Hex> => options.account.signTypedData!({ domain: ALTAR_DOMAIN, types: { AddressGeneration: [ { name: 'projectId', type: 'string' }, { name: 'networkType', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'timestamp', type: 'uint256' }, ], }, primaryType: 'AddressGeneration', message: { projectId: options.projectId, networkType: options.networkType, chainId: options.chainId, timestamp: options.timestamp, }, })Read your own addresses
Section titled “Read your own addresses”import { privateKeyToAccount } from 'viem/accounts'import { buildLoginRequestBody, nowAsTimestamp, signLogin } from './signing-examples'
const account = privateKeyToAccount('0x...') // or a wallet clientconst projectId = 'provex'const timestamp = nowAsTimestamp()
// termsOfUse is the campaign's projectDisclaimerShort from GET /projects ("" when it has none).const signature = await signLogin({ account, projectId, termsOfUse: '...', timestamp })
const response = await fetch('https://altar.fund/api/v1/address/all', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(buildLoginRequestBody({ signature, projectId, timestamp })),})console.log(await response.json())Read as a campaign admin
Section titled “Read as a campaign admin”import { signAdminRead } from './signing-examples'import { toApiBigint, nowAsTimestamp } from './signing-examples'
const timestamp = nowAsTimestamp()const signature = await signAdminRead({ account, projectId: 'provex', timestamp })
// POST /admin/project, /admin/referrals, /admin/price-overrides, and the other admin readsconst response = await fetch('https://altar.fund/api/v1/admin/project', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ signature, projectId: 'provex', inputs: { timestamp: toApiBigint(timestamp) } }),})Submit or end a referral
Section titled “Submit or end a referral”Sign the referrer address in lowercase. The server lowercases it before it checks the signature.
import { buildReferralRequestBody, signReferral } from './signing-examples'
const signature = await signReferral({ account, projectId: 'provex', referrerAddress, action: 'submit', timestamp })await fetch('https://altar.fund/api/v1/referral', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(buildReferralRequestBody({ signature, projectId: 'provex', referrerAddress, timestamp })),})// To end it: sign with action: 'disconnect' and POST to /referral/disconnect.Referrals are recorded, but Altar does not award referral points at present. See How points are calculated.
Other messages
Section titled “Other messages”For every other kind, copy the types from the section above and pass them to signTypedData the same way. The signed routes reference shows the body of each route.
Errors you may see
Section titled “Errors you may see”| Status | Meaning |
|---|---|
| 400 | The body is malformed, or the signature or timestamp has the wrong format. |
| 401 | The timestamp is too old, or the signature does not verify. A message built from the wrong campaign, kind, or terms text fails here. |
| 403 | The signature is valid, but the signer holds no admin role. |