"use client";import Header from "@/components/header";import Padder from "@/components/padder";import EncryptedInput from "@/components/encrypted-input";import Balance from "@/components/balance";const Page = () => { return ( <Padder> <Header /> <div className="max-w-md mx-auto"> <EncryptedInput /> <Balance /> </div> </Padder> );};export default Page;
utils/constants.ts
Contains program IDs, PDA derivation, and helper functions:
import { PublicKey } from "@solana/web3.js";// Your deployed program ID (from IDL)export const PROGRAM_ID = new PublicKey(idl.address);// Inco Lightning program on devnetexport const INCO_LIGHTNING_PROGRAM_ID = new PublicKey( "5sjEbPiqgZrYwR31ahR6Uk9wf5awoX61YGg7jExQSwaj");// Account discriminators for filteringexport const INCO_MINT_DISCRIMINATOR = [254, 129, 245, 169, 202, 143, 198, 4];export const INCO_ACCOUNT_DISCRIMINATOR = [18, 233, 131, 18, 230, 173, 249, 89];
Key Helper Functions
getAllowancePda
Derives the allowance PDA for a handle and wallet:
export const getAllowancePda = ( handle: bigint, allowedAddress: PublicKey): [PublicKey, number] => { // Convert handle to little-endian bytes const handleBuffer = Buffer.alloc(16); let h = handle; for (let i = 0; i < 16; i++) { handleBuffer[i] = Number(h & BigInt(0xff)); h = h >> BigInt(8); } return PublicKey.findProgramAddressSync( [handleBuffer, allowedAddress.toBuffer()], INCO_LIGHTNING_PROGRAM_ID );};
extractHandle
Extracts the encrypted handle from account data:
export const extractHandle = (data: Buffer): bigint => { // Handle is stored as u128 at offset 72-88 (little-endian) const bytes = data.slice(72, 88); let result = BigInt(0); for (let i = 15; i >= 0; i--) { result = result * BigInt(256) + BigInt(bytes[i]); } return result;};
The offset 72-88 is specific to the Inco Token program’s IncoAccount structure. Adjust the offset based on your program’s account layout.