Attestation SDK β
Implementation Guide
Get started with secure attestation workflows
Implementation β
Ready to build with the Attestation SDK? This guide walks you through installing and using the Core SDK, setting up the Attestify Backend, and leveraging the Attestify CLI. Whether youβre integrating it into a project or running a full attestation system, hereβs how to get started with code examples and best practices. Check out the source code for each component below!
Core SDK Setup β
The Core SDK is the heart of Attestify, providing attestation and cryptographic functionality.
Installation β
Install via npm:
npm install attestation-sdk
Basic Usage β
Initialize an attestation with a custom derivation path:
import { Attestation, Attest } from 'attestation-sdk';
const config = {
ethereum: "m/44'/60'/0'/0", // Ethereum standard
cosmos: "m/44'/118'/0'/0", // Cosmos standard
custom: "m/44'/999'/0'/0" // Custom path
};
const attestation = new Attestation(
committerXpub, // Extended public key of committer
committeeXpub, // Extended public key of committee
config.ethereum, // Derivation path
"Payment of $10M", // Payload
"", "", "", // Initial signatures (empty)
Attest.INITIATED // Starting state
);
attestation.initiateAttestation();
console.log(attestation.attestationId); // Unique UUID v4
External Signing (e.g., MetaMask) β
Integrate with Web3 wallets:
async function signWithMetaMask(payload) {
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
const signature = await window.ethereum.request({
method: 'personal_sign',
params: [payload, accounts[0]]
});
return signature;
}
const signature = await signWithMetaMask(attestation.attestationPayload);
attestation.setCommitteeSignature(signature);
attestation.acknowledgeAttestation();
Source Code β
Explore the Core SDK:
GitHub - Attestify SDK
Attestify Backend Setup β
The backend extends the SDK with persistent storage and REST APIs.
Prerequisites β
- Node.js (v14+)
- npm (v6+)
- MongoDB (v4.4+)
Installation β
- Clone the repository:bash
git clone https://github.com/STarLo-rd/attestify-backend.git cd attestify-backend
- Install dependencies:bash
npm install
- Configure environment:bashEdit
cp .env.example .env
.env
:PORT=3000 MONGODB_URI=mongodb://localhost:27017/attestify JWT_SECRET=your_jwt_secret_key JWT_EXPIRY=1h
- Start the service:bash
npm run dev # Development mode npm start # Production mode
API Example β
Create an attestation via Express:
import express from 'express';
import { Attestation, Attest } from 'attestation-sdk';
const app = express();
app.use(express.json());
app.post('/create-attestation', async (req, res) => {
const { committerXpub, committeeXpub, payload } = req.body;
const attestation = new Attestation(
committerXpub,
committeeXpub,
"m/44'/60'/0'/0",
payload,
"", "", "",
Attest.INITIATED
);
attestation.initiateAttestation();
// Store in database (pseudo-code)
await db.attestations.create({
id: attestation.attestationId,
state: attestation.commitmentState,
payload: attestation.attestationPayload
});
res.json({
attestationId: attestation.attestationId,
status: 'initiated'
});
});
app.post('/acknowledge-attestation/:id', async (req, res) => {
const { signature } = req.body;
const attestation = await getAttestationFromDB(req.params.id); // Fetch from DB
attestation.setCommitteeSignature(signature);
attestation.acknowledgeAttestation();
await updateAttestationInDB(attestation); // Update DB
res.json({ status: 'acknowledged' });
});
app.listen(3000, () => console.log('Server running on port 3000'));
Verification Endpoint β
Validate signatures:
app.post('/verify-attestation', async (req, res) => {
const { payload, signature, pubKey } = req.body;
const isValid = SignatureService.verifySignature(payload, pubKey, signature);
res.json({ isValid });
});
Source Code β
Explore the Backend:
GitHub - Attestify Backend
Attestify CLI Setup β
The CLI simplifies interaction with the backend and SDK.
Prerequisites β
- Node.js (v14+)
- npm (v6+)
- Running Attestify Backend
Installation β
- Clone the repository:bash
git clone https://github.com/STarLo-rd/attestify-cli.git cd attestify-cli
- Install dependencies:bash
npm install
Usage β
- Quick Start: Run the full lifecycle:bash
npm run lifecycle
- Manual Flow:
- Register a user:bash
node index.js register \ --username alice \ --email alice@example.com \ --password password123 \ --mnemonic "kit novel carpet brief draft install mammal nation link fabric crouch boy"
- Login:bash
node index.js login --email alice@example.com --password password123
- Create a commitment:bash
node index.js create-commitment \ --committer "677169348ac63afebc3bf5ee" \ --assetName "Gold" \ --quantity 100 \ --unit "grams"
- Acknowledge it:bash
node index.js acknowledge-commitment \ --commitmentId "67716a338ac63afebc3bf5f3" \ --mnemonic "kit novel carpet brief draft install mammal nation link fabric crouch boy"
- Register a user:
Source Code β
Explore the CLI:
GitHub - Attestify CLI