ZK Social Protocol
Search
⌃K

zkitter-js

Javascript implementation of a standalone zkitter node
​zkitter-js is an npm module and a CLI tool designed to make building on Zkitter easier.

To initialize Zkitter and sync with the network:

import {Zkitter} from "zkitter-js";
const zkitter = await Zkitter.initialize({
arbitrumHttpProvider: 'https://...',
});
​
// Sync with arbitrum registrar
await zkitter.syncUsers();
​
// Sync with zk groups on zkitter
await zkitter.syncGroup();
​
// Get all historical messages (30 days) from Waku store
await zkitter.queryAll();
​
// Subscribe to all future messages from everyone
await zkitter.subscribe();

To implement custom database instead of using default LevelDB:

import { Zkitter, GenericDBAdapterInterface, Post, Proof } from 'zkitter-js';
import postgres from 'postgres';
​
const sql = postgres({ /* options */ });
​
class PostgresDB implements GenericDBAdapterInterface {
async insertPost(post: Post, proof: Proof) {
const existing = await sql`
select * from posts
where hash = ${post.hash()}
`
if (!existing) {
await sql`
insert into posts (...)
values (...)
`
}
}
}
​
const zkitter = await Zkitter.initialize({
db: new PostgresDB(),
arbitrumHttpProvider: 'https://...',
});
interface GenericDBAdapterInterface {
getUserCount: () => Promise<number>;
getLastArbitrumBlockScanned: () => Promise<number>;
updateLastArbitrumBlockScanned: (block: number) => Promise<number>;
updateUser: (user: User) => Promise<User>;
getUsers: (limit?: number, offset?: number|string) => Promise<User[]>;
getUser: (address: string) => Promise<User|null>;
getUserMeta: (address: string) => Promise<UserMeta>;
getProof: (hash: string) => Promise<Proof | null>;
insertGroupMember: (groupId: string, member: GroupMember) => Promise<GroupMember|null>;
getGroupMembers: (groupId: string, limit?: number, offset?: number|string) => Promise<string[]>
findGroupHash: (hash: string) => Promise<string | null>;
insertPost: (post: Post, proof: Proof) => Promise<Post>;
insertModeration: (moderation: Moderation, proof: Proof) => Promise<Moderation|null>;
insertConnection: (connection: Connection, proof: Proof) => Promise<Connection|null>;
insertProfile: (profile: Profile, proof: Proof) => Promise<Profile|null>;
getMessagesByUser: (address: string, limit?: number, offset?: number|string) => Promise<Message[]>;
getPostMeta: (postHash: string) => Promise<PostMeta>;
getPost: (hash: string) => Promise<Post|null>;
getPosts: (limit?: number, offset?: number|string) => Promise<Post[]>;
getUserPosts: (address: string, limit?: number, offset?: number|string) => Promise<Post[]>;
getReplies: (hash: string, limit?: number, offset?: number|string) => Promise<Post[]>;
getReposts: (hash: string, limit?: number, offset?: number|string) => Promise<string[]>;
getModerations: (hash: string, limit?: number, offset?: number|string) => Promise<Moderation[]>;
getConnections: (address: string, limit?: number, offset?: number|string) => Promise<Connection[]>;
}

CLI Usage:

You must first initialize zkitter cli with an HTTP provider for Arbitrum mainnet
zkitter init --arbitrumHttpProvider="https://..."
To fetch all users from Arbitrum:
zkitter sync -a
To sync with one group or all groups:
zkitter sync -g semaphore_taz_members
zkitter sync --groups
To list all groups or users:
zkitter list -u
zkitter list -g
To publish a post: (instruction to generate private key is not available yet!)
zkitter write -c "Hello, World!" -u "0x12345..." -s "base64-encoded-private-key"
To view a user profile:
zkitter whois 0xd44a82dD160217d46D754a03C8f841edF06EBE3c
To view timeline:
zkitter timeline --limit=3
To run zkitter node:
zkitter up
# type "help" view command options
​