Skip to content

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 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 signature and an inputs object. The server rebuilds the message from inputs (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" }.
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.

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)

FieldSolidity type
projectIdstring
timestampuint256
projectNamestring
projectDescriptionstring
projectWebsitestring
projectLogostring
projectTaglinestring
projectAccentColorstring
projectAccentColorVariantstring
projectBannerstring
projectDisclaimerShortstring
projectDisclaimerLongstring
projectSocialLinksstring
projectTagsstring
startTimeuint256
inflectionTimeuint256
endTimeuint256
disabledbool
decayRateSingleStepuint256
decaySingleStepDelaySecondsuint256
volumeBonusRateuint256
usdToPointBaseRateuint256
volumeBonusCutoffuint256
flatBonusCutoffuint256
flatBonusRateuint256
referralRateuint256
countEarlySacrificesbool
useInflectionStepOnebool
priceValidFromTimestampstring
incrementModestring
registryAddressstring

Used by: POST /projects

addressGeneration (primary type AddressGeneration)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
timestampuint256

Used by: POST /address

login (primary type Validate)

FieldSolidity type
purposestring
projectIdstring
timestampuint256
termsOfUsestring

Used by: POST /address/all

referralSubmission (primary type ReferralSubmission)

FieldSolidity type
projectIdstring
referrerAddressstring
actionstring
timestampuint256

Used by: POST /referral, POST /referral/disconnect

report (primary type Report)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
blockHashstring
tokenAddressstring
transactionHashstring
logIndexuint32
logTypestring
timestampuint256
messagestring

Used by: POST /reports

adminRead (primary type AdminRead)

FieldSolidity type
purposestring
projectIdstring
timestampuint256

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)

FieldSolidity type
configstring
timestampuint256

Used by: POST /admin/campaign/import

networkManagement (primary type NetworkManagement)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
actionstring
timestampuint256
rootAddressstring
networkNamestring
lowestBlockuint256
lowerRangeuint256
upperRangeuint256
rpcUrlsstring

Used by: POST /admin/network

projectUpdate (primary type ProjectUpdate)

FieldSolidity type
projectIdstring
timestampuint256
projectNamestring
projectWebsitestring
projectDescriptionstring
projectLogostring
projectTaglinestring
projectAccentColorstring
projectAccentColorVariantstring
projectBannerstring
projectDisclaimerShortstring
projectDisclaimerLongstring
projectSocialLinksstring
projectTagsstring
startTimeuint256
inflectionTimeuint256
endTimeuint256
decaySingleStepDelaySecondsuint256
volumeBonusCutoffuint256
flatBonusCutoffuint256
decayRateSingleStepuint256
usdToPointBaseRateuint256
flatBonusRateuint256
referralRateuint256
countEarlySacrificesbool
useInflectionStepOnebool

Used by: POST /admin/project/update

tokenManagement (primary type TokenManagement)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
actionstring
timestampuint256
tokenAddressstring
sourcestring
marketstring
searchablestring

Used by: POST /admin/token

adminManagement (primary type AdminManagement)

FieldSolidity type
projectIdstring
addressstring
actionstring
timestampuint256

Used by: POST /admin/admin

sacrificeMutation (primary type SacrificeMutation)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
blockHashstring
transactionHashstring
tokenAddressstring
logIndexuint32
logTypestring
actionstring
timestampuint256
amountstring
pointsDestinationAddressstring
userAddressListIndexstring
sourcestring
marketstring
sacrificeTimestampstring
blockNumberstring
blockStatusstring
tokenSymbolstring
tokenNamestring
tokenDecimalsstring
pricestring
reasonstring

Used by: POST /admin/sacrifice-mutation/upsert

reportToggle (primary type ReportToggle)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
blockHashstring
tokenAddressstring
transactionHashstring
logIndexuint32
logTypestring
signerAddressstring
ignoredbool
timestampuint256

Used by: POST /admin/report/toggle-ignored

addressPoolUpload (primary type AddressPoolUpload)

FieldSolidity type
projectIdstring
networkTypestring
chainIduint256
rangeStartuint256
countuint256
merkleRootbytes32
timestampuint256

Used by: POST /admin/address-pool/begin

instanceLogin (primary type InstanceLogin)

FieldSolidity type
purposestring
timestampuint256

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

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.ts
/**
* 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,
},
})
import { privateKeyToAccount } from 'viem/accounts'
import { buildLoginRequestBody, nowAsTimestamp, signLogin } from './signing-examples'
const account = privateKeyToAccount('0x...') // or a wallet client
const 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())
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 reads
const 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) } }),
})

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.

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.

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.