Full lesson
CityLightAI
What it does
From the project README:
Choose a video up to 30 seconds / 100 MB and draw two approach regions before analysis. Video stays on your device. Model download is about 36 MB; speed depends on your device. Browser results have their own evidence hashes and must be published separately from the reference receipts. A browser wallet with test SOL is required only for new Devnet publication. Controller tests cover the TypeScript port against the saved Python run.
- Original
- amirmurat/CityLightAI
- SuperStack fork
- Blockchains/CityLightAI @
7d44fe5 - Stars
- 0
- Last push (original)
- 2026-10-27
- Languages
- TypeScript, Python, JavaScript, Rust, PowerShell, HTML
- Detected stack
- Anchorweb3.js
- Categories
- Other
- Licence
- MIT
Architecture
24 source files. By extension: .ts ×12, .py ×10, .tsx ×1, .rs ×1.
| Top-level directory | Source files |
|---|---|
src | 8 |
backend | 7 |
tests | 6 |
(root) | 1 |
programs | 1 |
scripts | 1 |
On-chain programs: programs/citylight_audit
Dapp: devnet deploy pending
⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/citylightai/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
programs/citylight_audit/src/lib.rs L25–48 @ 7d44fe5 · MIT · original let registry_key = r.key(); let commitment = hashv(&[registry_key.as_ref(), &sequence.to_le_bytes(), &evidence_hash, &previous]).to_bytes(); let receipt = &mut ctx.accounts.receipt; receipt.registry = registry_key; receipt.publisher = ctx.accounts.publisher.key(); receipt.sequence = sequence; receipt.evidence_hash = evidence_hash; receipt.previous = previous; receipt.commitment = commitment; receipt.slot = Clock::get()?.slot; r.next_sequence = sequence.checked_add(1).ok_or(AuditError::Overflow)?; r.last_commitment = commitment; Ok(()) }} #[derive(Accounts)]#[instruction(run_id: [u8;16])]pub struct RegisterRun<'info> { #[account(mut)] pub authority: Signer<'info>, #[account(init, payer=authority, space=8+32+32+16+32+32+8+32, seeds=[b"run", authority.key().as_ref(), run_id.as_ref()], bump)] pub registry: Account<'info, RunRegistry>,- Line 34
receipt.slot = Clock::get()?.slot;: Reads on-chain time from the Clock sysvar. - Line 35
r.next_sequence = sequence.checked_add(1).ok_or(AuditError::Overflow)?;: Uses checked arithmetic so overflow fails instead of wrapping. - Line 45
pub authority: Signer<'info>,: Requires this account to have signed the transaction. - Line 46
#[account(init, payer=authority, space=8+32+32+16+32+32+8+32,: Creates and pays for a new account. Space and payer must be specified. - Line 47
seeds=[b"run", authority.key().as_ref(), run_id.as_ref()], bump)]: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 47
seeds=[b"run", authority.key().as_ref(), run_id.as_ref()], bump)]: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
scripts/chain.ts L25–48 @ 7d44fe5 · MIT · originalconst receiptAddress=(id:PublicKey,registry:PublicKey,sequence:number)=>PublicKey.findProgramAddressSync([Buffer.from('receipt'),registry.toBuffer(),u64(sequence)],id)[0];async function readAccount(address:PublicKey,disc:string,id:PublicKey){ const account=await connection.getAccountInfo(address,'finalized');if(!account)throw Error(`Account not found: ${address}`); if(!account.owner.equals(id)||!account.data.subarray(0,8).equals(discriminator('account',disc)))throw Error('Invalid account owner/discriminator'); return account.data;}async function send(id:PublicKey,data:Buffer,keys:any[],payer:Keypair){ const tx=new Transaction().add(new TransactionInstruction({programId:id,data,keys})); return sendAndConfirmTransaction(connection,tx,[payer],{commitment:'finalized',preflightCommitment:'confirmed',maxRetries:5});}export async function verifyBundle(bundle:any,hash:string){return sha(canonical(bundle)).toString('hex')===hash;}async function verify(){ const local=JSON.parse(readFileSync(`${runs}/latest.json`,'utf8')); const chain=JSON.parse(readFileSync(`${runs}/chain.json`,'utf8')); if(chain.run_id!==local.metadata.run_id)throw Error('Displayed run does not match published run'); const id=program();if(chain.program_id!==id.toBase58())throw Error('Unexpected program ID'); const registry=new PublicKey(chain.registry);const authority=new PublicKey(chain.authority); const config=JSON.parse(readFileSync(programFile,'utf8')); if(authority.toBase58()!==config.operator_authority)throw Error('Untrusted operator authority'); if(!registry.equals(registryAddress(id,authority,local.metadata.run_id)))throw Error('Registry PDA mismatch'); const state=await readAccount(registry,'RunRegistry',id); if(state.length!==192)throw Error('Registry length mismatch'); if(!new PublicKey(state.subarray(8,40)).equals(authority))throw Error('Authority mismatch'); const publisher=new PublicKey(state.subarray(40,72));- Line 25
const receiptAddress=(id:PublicKey,registry:PublicKey,sequence:number)=>PublicKey.findProg: Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 33
return sendAndConfirmTransaction(connection,tx,[payer],{commitment:'finalized',preflightCo: Submits the signed transaction to the cluster.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
. | npm run dev | vite --host 127.0.0.1 |
. | npm run build | tsc --noEmit && vite build |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | anchor run test | pnpm test:chain |
. | cargo build | Rust workspace build |
. | cargo test | Rust tests |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)