@zpcash/sdk
v0.1.0
Published
Identity and proof SDK for ZpCash with optional Starknet proof registry
Readme
ZpCash SDK
Privacy-preserving identity SDK for the hypothetical ZpCash ecosystem. The toolkit mirrors the ideas from @zkterm/zkid and augments them with a Cairo smart contract for immutable proof anchoring on Starknet.
Features
did:zpcash:xxxxidentity generation backed by Ed25519 keypairs- Password-based encryption (AES-256-GCM + PBKDF2, 200k iterations)
- Deterministic proof messages with short-lived nonces and timestamping
- Built-in utilities to hash proofs and prepare Starknet call data
- Starknet (STARK curve) wallet management for OpenZeppelin or ArgentX flows
- Cairo smart contract (
contracts/src/lib.cairo) to store proof hashes on-chain
Installation
npm install @zpcash/sdk
# or
pnpm add @zpcash/sdkInstall dependencies after cloning this workspace with
npm installbefore running TypeScript builds.
Quick Start
import {
createZpIdentity,
generateProof,
hashProof,
assembleOnChainProof,
buildStoreProofCalldata,
} from '@zpcash/sdk';
async function main() {
const password = 'ChangeMe123!';
const identity = await createZpIdentity(password);
const proof = await generateProof({
zpId: identity.zpId,
password,
encrypted: identity.encryptedPrivateKey.encrypted,
salt: identity.encryptedPrivateKey.salt,
iv: identity.encryptedPrivateKey.iv,
iterations: identity.encryptedPrivateKey.iterations,
});
const proofHash = hashProof(proof);
const payload = assembleOnChainProof(proof, identity.zpId);
const calldata = buildStoreProofCalldata(payload);
console.log('Proof ID (felt):', payload.proofId);
console.log('Proof hash (hex):', proofHash.hashHex);
console.log('Starknet calldata:', calldata);
}
main().catch(console.error);Starknet Wallet Helpers
import { createZpcashWallet, decryptZpcashPrivateKey } from '@zpcash/sdk';
const wallet = await createZpcashWallet('MyWalletPassword', 'openzeppelin');
console.log(wallet.address);
const privateKey = await decryptZpcashPrivateKey(wallet.encryptedPrivateKey, 'MyWalletPassword');The helpers rely on the starknet library internally and work with both OpenZeppelin and ArgentX class hashes.
Cairo Contract
The Starknet contract is packaged in contracts/ with Scarb metadata:
contracts/
├── README.md
├── Scarb.toml
└── src/
└── lib.cairoThe contract exposes:
store_proof(proof_id, proof_hash, zp_id)get_proof(proof_id)verify_proof_exists(proof_id)
See contracts/README.md for compilation and deployment steps.
Building
npm run buildTypeScript sources compile to dist/ with declaration files for downstream projects.
Security Notes
- Private keys are zeroed in memory immediately after encryption/decryption helpers finish.
- PBKDF2 iterations default to 200,000. Override with caution and always prefer values ≥ 100,000.
- Proof messages expire after 10 minutes by default. Adjust
ttlSecondswhen callinggenerateProofif necessary.
License
MIT
