Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Approval

EIP-712 typed data utilities for purchase approval signatures.

import { Approval } from '@sceneinfrastructure/sdk'

Functions

getTypedData

Returns complete EIP-712 typed data for signing a purchase approval.

import { Approval, SaleKey, gatekeeperAddress } from '@sceneinfrastructure/sdk'
import { Hex } from 'ox'
 
const chainId = 8453 // Base
 
const saleKey = {
  token: '0x1234567890123456789012345678901234567890', // Your deployed contract
  vendorFeeBps: 0,
  referralFeeBps: 0,
  salesTaxBps: 0,
  vendor: '0x2345678901234567890123456789012345678901',
  nonce: 1n,
  currency: '0x1111111111111111111111111111111111111111',
  fundsRecipient: '0x3456789012345678901234567890123456789012',
  tokenId: 1n,
} as const
 
const typedData = Approval.getTypedData({
  chainId: BigInt(chainId),
  gatekeeper: gatekeeperAddress[chainId],
  message: {
    recipient: '0x4567890123456789012345678901234567890123',
    referrer: '0x0000000000000000000000000000000000000000',
    quantity: 1,
    deadline: Approval.getDeadline(),
    salt: Hex.random(32),
    saleKeyId: SaleKey.generateId(saleKey),
  },
})
 
// Sign with viem
// const signature = await walletClient.signTypedData(typedData)

Each approval signature is single-use. Gatekeeper rejects replays using the (recipient, referrer, quantity, deadline, salt, saleKeyId) hash, so generate a fresh salt for every approval and keep deadlines short.

Parameters

ParameterTypeDescription
chainIdbigintChain ID for domain separator
gatekeeperAddressGatekeeper contract address
messageApprovalMessageMessage to sign

Returns

{
  domain: {
    name: 'Gatekeeper'
    version: '1'
    chainId: bigint
    verifyingContract: Address
  }
  types: typeof purchaseApprovalTypes
  primaryType: 'PurchaseApproval'
  message: ApprovalMessage
}

getDeadline

Calculates a Unix timestamp deadline for approval signatures.

import { Approval } from '@sceneinfrastructure/sdk'
 
// Default: 15 minutes from now
const deadline = Approval.getDeadline()
 
// Custom: 30 minutes from now
const thirtyMin = Approval.getDeadline(new Date(), 30)
 
// From specific date
const future = Approval.getDeadline(new Date('2024-12-31'), 60)

Parameters

ParameterTypeDefaultDescription
dateDatenew Date()Base date
minutesnumber15Minutes until expiration

Returns

bigint - Unix timestamp


Constants

types

EIP-712 type definitions for PurchaseApproval signatures.

import { Approval } from '@sceneinfrastructure/sdk'
 
console.log(Approval.types)
// {
//   EIP712Domain: [...],
//   PurchaseApproval: [
//     { name: 'recipient', type: 'address' },
//     { name: 'referrer', type: 'address' },
//     { name: 'quantity', type: 'uint16' },
//     { name: 'deadline', type: 'uint256' },
//     { name: 'salt', type: 'bytes32' },
//     { name: 'saleKeyId', type: 'bytes32' },
//   ]
// }

domain

Base EIP-712 domain (name and version only).

import { Approval, gatekeeperAddress } from '@sceneinfrastructure/sdk'
 
const chainId = 8453 // Base
 
console.log(Approval.domain)
// { name: 'Gatekeeper', version: '1' }
 
// Complete domain for signing:
const fullDomain = {
  ...Approval.domain,
  chainId: BigInt(chainId),
  verifyingContract: gatekeeperAddress[chainId],
}

primaryType

The primary type identifier.

import { Approval } from '@sceneinfrastructure/sdk'
 
console.log(Approval.primaryType)
// 'PurchaseApproval'

Types

ApprovalMessage

The message payload for purchase approval signatures.

import type { Approval } from '@sceneinfrastructure/sdk'
 
const message: Approval.ApprovalMessage = {
  recipient: '0x1234567890123456789012345678901234567890',     // Ticket recipient
  referrer: '0x0000000000000000000000000000000000000000',      // Referrer address (or zero)
  quantity: 1,                                                   // Number of tickets
  deadline: 1700000000n,                                         // Expiration timestamp
  salt: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',          // Random bytes32
  saleKeyId: '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890ab',   // Sale key hash
}
FieldTypeDescription
recipientAddressAddress receiving tickets
referrerAddressReferrer address (or zero)
quantitynumberNumber of tickets
deadlinebigintUnix timestamp expiration
saltHexRandom bytes32 nonce
saleKeyIdHexHash of SaleKey struct

Schema

messageSchema

Zod schema for validating approval messages.

import { Approval } from '@sceneinfrastructure/sdk'
 
const result = Approval.messageSchema.safeParse({
  recipient: '0x...',
  referrer: '0x0000000000000000000000000000000000000000',
  quantity: 1,
  deadline: 1700000000n,
  salt: '0x...',
  saleKeyId: '0x...',
})
 
if (result.success) {
  console.log('Valid:', result.data)
}