veritaszk-sdk 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,74 +1,33 @@
1
- export interface SolvencyResult {
2
- address: string;
1
+ export declare const PROGRAMS: {
2
+ readonly REGISTRY: "veritaszk_registry.aleo";
3
+ readonly CORE: "veritaszk_core.aleo";
4
+ readonly AUDIT: "veritaszk_audit.aleo";
5
+ };
6
+ export interface SolvencyStatus {
7
+ orgCommitment: string;
3
8
  isSolvent: boolean;
4
- timestamp: number;
5
- proofNonce: string;
6
- assetCount: number;
7
- liabilityCount: number;
9
+ timestamp: number | null;
10
+ expiryBlock: number | null;
8
11
  verificationCount: number;
9
- lastChecked: Date;
12
+ thresholdLevel: number;
13
+ hasMultiWallet: boolean;
14
+ isExpired: boolean;
15
+ lastProofBlock: number | null;
10
16
  }
11
- export interface OrgInfo {
12
- address: string;
13
- nameHash: string;
14
- registeredAt: number;
15
- isActive: boolean;
17
+ export interface AuditEvent {
18
+ orgCommitment: string;
19
+ eventCount: number;
20
+ lastProofBlock: number | null;
21
+ isExpired: boolean;
16
22
  }
17
- export interface VeritasZKConfig {
18
- network?: "testnet" | "mainnet";
19
- rpcUrl?: string;
20
- programId?: string;
21
- }
22
- export declare class VeritasZK {
23
- private rpcUrl;
24
- private programId;
25
- private network;
26
- constructor(config?: VeritasZKConfig);
27
- /**
28
- * Verify whether an organization holds a valid solvency proof.
29
- * Returns proof status without revealing any financial data.
30
- *
31
- * @param address - The Aleo address of the organization to verify
32
- * @returns SolvencyResult containing proof status and metadata
33
- *
34
- * @example
35
- * const client = new VeritasZK({ network: "testnet" })
36
- * const result = await client.verifySolvency("aleo1abc...")
37
- * console.log(result.isSolvent) // true or false — no amounts revealed
38
- */
39
- verifySolvency(address: string): Promise<SolvencyResult>;
40
- /**
41
- * Retrieve public metadata for a registered organization.
42
- * Name hash only — raw organization name is never stored on-chain.
43
- *
44
- * @param address - The Aleo address of the organization
45
- * @returns OrgInfo containing registration metadata, or null if not registered
46
- */
47
- getOrgInfo(address: string): Promise<OrgInfo | null>;
48
- /**
49
- * Get the total number of times an organization's proof
50
- * has been publicly verified.
51
- *
52
- * @param address - The Aleo address of the organization
53
- * @returns verification count as a number
54
- */
55
- getVerificationCount(address: string): Promise<number>;
56
- /**
57
- * Query any mapping from the veritaszk.aleo program.
58
- * Hits: GET {rpcUrl}/program/{programId}/mapping/{mappingName}/{key}
59
- *
60
- * @param mappingName - The mapping to query
61
- * @param key - The key to look up
62
- * @returns Parsed mapping value or null if not found
63
- */
64
- private queryMapping;
23
+ export interface BatchVerifyResult {
24
+ orgCommitment: string;
25
+ isSolvent: boolean;
26
+ error?: string;
65
27
  }
66
- /**
67
- * One-line convenience function for solvency verification.
68
- *
69
- * @example
70
- * import { verifySolvency } from "veritaszk-sdk"
71
- * const { isSolvent } = await verifySolvency("aleo1abc...")
72
- */
73
- export declare function verifySolvency(address: string, config?: VeritasZKConfig): Promise<SolvencyResult>;
74
- //# sourceMappingURL=index.d.ts.map
28
+ export declare function verifySolvency(orgCommitment: string): Promise<SolvencyStatus>;
29
+ export declare function batchVerify(orgCommitments: string[]): Promise<BatchVerifyResult[]>;
30
+ export declare function getAuditTrail(orgCommitment: string): Promise<AuditEvent>;
31
+ export declare function isRegistered(orgCommitment: string): Promise<boolean>;
32
+ export declare function getVerificationCount(orgCommitment: string): Promise<number>;
33
+ export declare function isProofExpired(orgCommitment: string): Promise<boolean>;
package/dist/index.js CHANGED
@@ -1,153 +1,105 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VeritasZK = void 0;
3
+ exports.PROGRAMS = void 0;
7
4
  exports.verifySolvency = verifySolvency;
8
- const node_fetch_1 = __importDefault(require("node-fetch"));
9
- function stripSuffix(val) {
10
- return String(val ?? "").replace(/u(8|16|32|64|128)$/, "");
5
+ exports.batchVerify = batchVerify;
6
+ exports.getAuditTrail = getAuditTrail;
7
+ exports.isRegistered = isRegistered;
8
+ exports.getVerificationCount = getVerificationCount;
9
+ exports.isProofExpired = isProofExpired;
10
+ const EXPLORER = 'https://api.explorer.provable.com/v1/testnet';
11
+ exports.PROGRAMS = {
12
+ REGISTRY: 'veritaszk_registry.aleo',
13
+ CORE: 'veritaszk_core.aleo',
14
+ AUDIT: 'veritaszk_audit.aleo',
15
+ };
16
+ async function queryMapping(program, mapping, key) {
17
+ const url = `${EXPLORER}/program/${program}/mapping/${mapping}/${key}`;
18
+ const res = await fetch(url);
19
+ if (!res.ok)
20
+ return null;
21
+ const text = await res.text();
22
+ try {
23
+ return JSON.parse(text);
24
+ }
25
+ catch {
26
+ return text;
27
+ }
11
28
  }
12
- function isSolvencyProofRaw(v) {
13
- return typeof v === "object" && v !== null && "is_solvent" in v;
29
+ function parseU32(val) {
30
+ if (val === null || val === undefined)
31
+ return null;
32
+ return Number(String(val).replace('u32', '').trim());
14
33
  }
15
- function isOrgInfoRaw(v) {
16
- return typeof v === "object" && v !== null && "name_hash" in v;
34
+ function parseU8(val) {
35
+ if (val === null || val === undefined)
36
+ return 0;
37
+ return Number(String(val).replace('u8', '').trim());
17
38
  }
18
- // ─────────────────────────────────────────────────────────────────────────────
19
- // VeritasZK main SDK class
20
- // ─────────────────────────────────────────────────────────────────────────────
21
- class VeritasZK {
22
- constructor(config = {}) {
23
- this.network = config.network ?? "testnet";
24
- this.rpcUrl =
25
- config.rpcUrl ?? "https://api.explorer.provable.com/v1/testnet";
26
- this.programId = config.programId ?? "veritaszk.aleo";
27
- }
28
- /**
29
- * Verify whether an organization holds a valid solvency proof.
30
- * Returns proof status without revealing any financial data.
31
- *
32
- * @param address - The Aleo address of the organization to verify
33
- * @returns SolvencyResult containing proof status and metadata
34
- *
35
- * @example
36
- * const client = new VeritasZK({ network: "testnet" })
37
- * const result = await client.verifySolvency("aleo1abc...")
38
- * console.log(result.isSolvent) // true or false — no amounts revealed
39
- */
40
- async verifySolvency(address) {
41
- const [raw, count] = await Promise.all([
42
- this.queryMapping("solvency_proofs", address),
43
- this.getVerificationCount(address),
44
- ]);
45
- if (!isSolvencyProofRaw(raw)) {
46
- return {
47
- address,
48
- isSolvent: false,
49
- timestamp: 0,
50
- proofNonce: "",
51
- assetCount: 0,
52
- liabilityCount: 0,
53
- verificationCount: count,
54
- lastChecked: new Date(),
55
- };
56
- }
57
- return {
58
- address,
59
- isSolvent: raw.is_solvent === true,
60
- timestamp: Number(stripSuffix(raw.timestamp)),
61
- proofNonce: String(raw.proof_nonce ?? ""),
62
- assetCount: Number(stripSuffix(raw.asset_count)),
63
- liabilityCount: Number(stripSuffix(raw.liability_count)),
64
- verificationCount: count,
65
- lastChecked: new Date(),
66
- };
67
- }
68
- /**
69
- * Retrieve public metadata for a registered organization.
70
- * Name hash only — raw organization name is never stored on-chain.
71
- *
72
- * @param address - The Aleo address of the organization
73
- * @returns OrgInfo containing registration metadata, or null if not registered
74
- */
75
- async getOrgInfo(address) {
76
- const raw = await this.queryMapping("org_metadata", address);
77
- if (!isOrgInfoRaw(raw))
78
- return null;
79
- return {
80
- address,
81
- nameHash: String(raw.name_hash ?? ""),
82
- registeredAt: Number(stripSuffix(raw.registered_at)),
83
- isActive: raw.is_active === true,
84
- };
85
- }
86
- /**
87
- * Get the total number of times an organization's proof
88
- * has been publicly verified.
89
- *
90
- * @param address - The Aleo address of the organization
91
- * @returns verification count as a number
92
- */
93
- async getVerificationCount(address) {
94
- try {
95
- const raw = await this.queryMapping("verification_count", address);
96
- if (raw === null || raw === undefined)
97
- return 0;
98
- return Number(stripSuffix(raw));
99
- }
100
- catch {
101
- return 0;
102
- }
103
- }
104
- /**
105
- * Query any mapping from the veritaszk.aleo program.
106
- * Hits: GET {rpcUrl}/program/{programId}/mapping/{mappingName}/{key}
107
- *
108
- * @param mappingName - The mapping to query
109
- * @param key - The key to look up
110
- * @returns Parsed mapping value or null if not found
111
- */
112
- async queryMapping(mappingName, key) {
113
- const url = `${this.rpcUrl}/program/${this.programId}/mapping/${mappingName}/${key}`;
114
- let res;
115
- try {
116
- res = await (0, node_fetch_1.default)(url);
117
- }
118
- catch (err) {
119
- throw new Error(`VeritasZK network error: Unable to reach ${this.rpcUrl}. ` +
120
- `Check your network connection or rpcUrl config. (${String(err)})`);
121
- }
122
- if (res.status === 404)
123
- return null;
124
- if (!res.ok) {
125
- throw new Error(`VeritasZK RPC error: ${res.status} ${res.statusText} for ${url}`);
126
- }
127
- const text = await res.text();
128
- if (!text || text === "null")
129
- return null;
130
- try {
131
- return JSON.parse(text);
132
- }
133
- catch {
134
- return text.replace(/^"|"$/g, "");
39
+ async function verifySolvency(orgCommitment) {
40
+ const [solvent, timestamp, expiry, count, threshold, multiWallet] = await Promise.all([
41
+ queryMapping(exports.PROGRAMS.CORE, 'solvency_proofs', orgCommitment),
42
+ queryMapping(exports.PROGRAMS.CORE, 'proof_timestamps', orgCommitment),
43
+ queryMapping(exports.PROGRAMS.CORE, 'proof_expiry', orgCommitment),
44
+ queryMapping(exports.PROGRAMS.CORE, 'verification_counts', orgCommitment),
45
+ queryMapping(exports.PROGRAMS.CORE, 'threshold_proofs', orgCommitment),
46
+ queryMapping(exports.PROGRAMS.CORE, 'multi_wallet_commitments', orgCommitment),
47
+ ]);
48
+ const expiryBlock = parseU32(expiry);
49
+ const ts = parseU32(timestamp);
50
+ return {
51
+ orgCommitment,
52
+ isSolvent: solvent === true || solvent === 'true',
53
+ timestamp: ts,
54
+ expiryBlock,
55
+ verificationCount: parseU32(count) ?? 0,
56
+ thresholdLevel: parseU8(threshold),
57
+ hasMultiWallet: multiWallet !== null,
58
+ isExpired: expiryBlock !== null && expiryBlock > 0 &&
59
+ (parseU32(timestamp) ?? 0) > expiryBlock,
60
+ lastProofBlock: ts,
61
+ };
62
+ }
63
+ async function batchVerify(orgCommitments) {
64
+ const results = await Promise.allSettled(orgCommitments.map(c => verifySolvency(c)));
65
+ return results.map((r, i) => {
66
+ if (r.status === 'fulfilled') {
67
+ return { orgCommitment: orgCommitments[i],
68
+ isSolvent: r.value.isSolvent };
135
69
  }
136
- }
70
+ return { orgCommitment: orgCommitments[i], isSolvent: false,
71
+ error: r.reason?.message ?? 'Query failed' };
72
+ });
73
+ }
74
+ async function getAuditTrail(orgCommitment) {
75
+ const [count, lastBlock, expired] = await Promise.all([
76
+ queryMapping(exports.PROGRAMS.AUDIT, 'event_count', orgCommitment),
77
+ queryMapping(exports.PROGRAMS.AUDIT, 'last_proof_block', orgCommitment),
78
+ queryMapping(exports.PROGRAMS.AUDIT, 'expired_proofs', orgCommitment),
79
+ ]);
80
+ return {
81
+ orgCommitment,
82
+ eventCount: parseU32(count) ?? 0,
83
+ lastProofBlock: parseU32(lastBlock),
84
+ isExpired: expired === true || expired === 'true',
85
+ };
86
+ }
87
+ async function isRegistered(orgCommitment) {
88
+ const result = await queryMapping(exports.PROGRAMS.REGISTRY, 'org_registry', orgCommitment);
89
+ return result === true || result === 'true';
90
+ }
91
+ async function getVerificationCount(orgCommitment) {
92
+ const result = await queryMapping(exports.PROGRAMS.CORE, 'verification_counts', orgCommitment);
93
+ return parseU32(result) ?? 0;
137
94
  }
138
- exports.VeritasZK = VeritasZK;
139
- // ─────────────────────────────────────────────────────────────────────────────
140
- // Convenience export — verify in one line
141
- // ─────────────────────────────────────────────────────────────────────────────
142
- /**
143
- * One-line convenience function for solvency verification.
144
- *
145
- * @example
146
- * import { verifySolvency } from "veritaszk-sdk"
147
- * const { isSolvent } = await verifySolvency("aleo1abc...")
148
- */
149
- async function verifySolvency(address, config) {
150
- const client = new VeritasZK(config);
151
- return client.verifySolvency(address);
95
+ async function isProofExpired(orgCommitment) {
96
+ const [expiry, timestamp] = await Promise.all([
97
+ queryMapping(exports.PROGRAMS.CORE, 'proof_expiry', orgCommitment),
98
+ queryMapping(exports.PROGRAMS.CORE, 'proof_timestamps', orgCommitment),
99
+ ]);
100
+ const expiryBlock = parseU32(expiry);
101
+ const ts = parseU32(timestamp);
102
+ if (!expiryBlock || !ts)
103
+ return false;
104
+ return expiryBlock > 0 && ts > expiryBlock;
152
105
  }
153
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ import type { SolvencyStatus, AuditEvent } from './index';
2
+ export declare function useSolvencyStatus(orgCommitment: string): {
3
+ status: SolvencyStatus | null;
4
+ loading: boolean;
5
+ error: string | null;
6
+ refetch: () => Promise<void>;
7
+ };
8
+ export declare function useAuditTrail(orgCommitment: string): {
9
+ events: AuditEvent | null;
10
+ loading: boolean;
11
+ error: string | null;
12
+ };
package/dist/react.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSolvencyStatus = useSolvencyStatus;
4
+ exports.useAuditTrail = useAuditTrail;
5
+ const react_1 = require("react");
6
+ const index_1 = require("./index");
7
+ function useSolvencyStatus(orgCommitment) {
8
+ const [status, setStatus] = (0, react_1.useState)(null);
9
+ const [loading, setLoading] = (0, react_1.useState)(true);
10
+ const [error, setError] = (0, react_1.useState)(null);
11
+ const refetch = (0, react_1.useCallback)(async () => {
12
+ if (!orgCommitment)
13
+ return;
14
+ setLoading(true);
15
+ try {
16
+ const result = await (0, index_1.verifySolvency)(orgCommitment);
17
+ setStatus(result);
18
+ setError(null);
19
+ }
20
+ catch (e) {
21
+ setError(e.message);
22
+ }
23
+ finally {
24
+ setLoading(false);
25
+ }
26
+ }, [orgCommitment]);
27
+ (0, react_1.useEffect)(() => {
28
+ refetch();
29
+ const interval = setInterval(refetch, 30000);
30
+ return () => clearInterval(interval);
31
+ }, [refetch]);
32
+ return { status, loading, error, refetch };
33
+ }
34
+ function useAuditTrail(orgCommitment) {
35
+ const [events, setEvents] = (0, react_1.useState)(null);
36
+ const [loading, setLoading] = (0, react_1.useState)(true);
37
+ const [error, setError] = (0, react_1.useState)(null);
38
+ (0, react_1.useEffect)(() => {
39
+ if (!orgCommitment)
40
+ return;
41
+ (0, index_1.getAuditTrail)(orgCommitment)
42
+ .then(setEvents)
43
+ .catch((e) => setError(e.message))
44
+ .finally(() => setLoading(false));
45
+ }, [orgCommitment]);
46
+ return { events, loading, error };
47
+ }
@@ -0,0 +1,16 @@
1
+ export interface WebhookConfig {
2
+ url: string;
3
+ secret?: string;
4
+ events: Array<'proof.generated' | 'proof.expired' | 'proof.revoked'>;
5
+ orgCommitment: string;
6
+ pollIntervalMs?: number;
7
+ }
8
+ export declare class VeritasZKWebhook {
9
+ private config;
10
+ private interval;
11
+ private lastSolvent;
12
+ constructor(config: WebhookConfig);
13
+ start(): void;
14
+ stop(): void;
15
+ private post;
16
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VeritasZKWebhook = void 0;
4
+ const index_1 = require("./index");
5
+ class VeritasZKWebhook {
6
+ constructor(config) {
7
+ this.interval = null;
8
+ this.lastSolvent = null;
9
+ this.config = config;
10
+ }
11
+ start() {
12
+ const ms = this.config.pollIntervalMs ?? 60000;
13
+ this.interval = setInterval(async () => {
14
+ try {
15
+ const status = await (0, index_1.verifySolvency)(this.config.orgCommitment);
16
+ const changed = this.lastSolvent !== null &&
17
+ this.lastSolvent !== status.isSolvent;
18
+ if (changed || this.lastSolvent === null) {
19
+ const eventType = status.isSolvent
20
+ ? 'proof.generated' : 'proof.revoked';
21
+ if (this.config.events.includes(eventType)) {
22
+ await this.post({ event: eventType,
23
+ orgCommitment: this.config.orgCommitment,
24
+ isSolvent: status.isSolvent,
25
+ timestamp: new Date().toISOString() });
26
+ }
27
+ }
28
+ if (status.isExpired &&
29
+ this.config.events.includes('proof.expired')) {
30
+ await this.post({ event: 'proof.expired',
31
+ orgCommitment: this.config.orgCommitment,
32
+ isSolvent: false,
33
+ timestamp: new Date().toISOString() });
34
+ }
35
+ this.lastSolvent = status.isSolvent;
36
+ }
37
+ catch (e) {
38
+ console.error('VeritasZKWebhook error:', e);
39
+ }
40
+ }, ms);
41
+ }
42
+ stop() {
43
+ if (this.interval) {
44
+ clearInterval(this.interval);
45
+ this.interval = null;
46
+ }
47
+ }
48
+ async post(payload) {
49
+ await fetch(this.config.url, {
50
+ method: 'POST',
51
+ headers: { 'Content-Type': 'application/json' },
52
+ body: JSON.stringify(payload),
53
+ });
54
+ }
55
+ }
56
+ exports.VeritasZKWebhook = VeritasZKWebhook;
package/package.json CHANGED
@@ -1,33 +1,32 @@
1
1
  {
2
2
  "name": "veritaszk-sdk",
3
- "version": "0.1.0",
4
- "description": "Zero-knowledge solvency verification SDK for Aleo. Verify any organization's proof of solvency without seeing their financial data.",
3
+ "version": "0.2.0",
4
+ "description": "SDK for VeritasZK zero-knowledge solvency proofs on Aleo",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/",
9
+ "README.md"
10
+ ],
7
11
  "scripts": {
8
12
  "build": "tsc",
13
+ "test": "jest",
9
14
  "prepublishOnly": "npm run build"
10
15
  },
11
16
  "keywords": [
12
17
  "aleo",
13
18
  "zero-knowledge",
14
- "zk",
15
19
  "solvency",
16
- "proof-of-reserves",
17
- "privacy",
18
- "leo"
20
+ "zk",
21
+ "privacy"
19
22
  ],
20
- "author": "VeritasZK",
21
23
  "license": "MIT",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/Vinaystwt/veritaszk"
25
- },
26
- "homepage": "https://veritaszk.vercel.app",
27
24
  "devDependencies": {
28
- "typescript": "^5.0.0"
29
- },
30
- "dependencies": {
31
- "node-fetch": "^3.3.0"
25
+ "@types/jest": "^29.0.0",
26
+ "@types/node": "^20.0.0",
27
+ "@types/react": "^19.2.14",
28
+ "jest": "^29.0.0",
29
+ "ts-jest": "^29.0.0",
30
+ "typescript": "^5.4.0"
32
31
  }
33
- }
32
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,WA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AwB;IAExB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC"}
package/src/index.ts DELETED
@@ -1,212 +0,0 @@
1
- import fetch from "node-fetch";
2
-
3
- // ─────────────────────────────────────────────────────────────────────────────
4
- // Types
5
- // ─────────────────────────────────────────────────────────────────────────────
6
-
7
- export interface SolvencyResult {
8
- address: string;
9
- isSolvent: boolean;
10
- timestamp: number;
11
- proofNonce: string;
12
- assetCount: number;
13
- liabilityCount: number;
14
- verificationCount: number;
15
- lastChecked: Date;
16
- }
17
-
18
- export interface OrgInfo {
19
- address: string;
20
- nameHash: string;
21
- registeredAt: number;
22
- isActive: boolean;
23
- }
24
-
25
- export interface VeritasZKConfig {
26
- network?: "testnet" | "mainnet";
27
- rpcUrl?: string;
28
- programId?: string;
29
- }
30
-
31
- interface SolvencyProofRaw {
32
- is_solvent: boolean;
33
- timestamp: string | number;
34
- proof_nonce: string;
35
- asset_count: string | number;
36
- liability_count: string | number;
37
- }
38
-
39
- interface OrgInfoRaw {
40
- name_hash: string;
41
- registered_at: string | number;
42
- is_active: boolean;
43
- }
44
-
45
- function stripSuffix(val: unknown): string {
46
- return String(val ?? "").replace(/u(8|16|32|64|128)$/, "");
47
- }
48
-
49
- function isSolvencyProofRaw(v: unknown): v is SolvencyProofRaw {
50
- return typeof v === "object" && v !== null && "is_solvent" in v;
51
- }
52
-
53
- function isOrgInfoRaw(v: unknown): v is OrgInfoRaw {
54
- return typeof v === "object" && v !== null && "name_hash" in v;
55
- }
56
-
57
- // ─────────────────────────────────────────────────────────────────────────────
58
- // VeritasZK — main SDK class
59
- // ─────────────────────────────────────────────────────────────────────────────
60
-
61
- export class VeritasZK {
62
- private rpcUrl: string;
63
- private programId: string;
64
- private network: string;
65
-
66
- constructor(config: VeritasZKConfig = {}) {
67
- this.network = config.network ?? "testnet";
68
- this.rpcUrl =
69
- config.rpcUrl ?? "https://api.explorer.provable.com/v1/testnet";
70
- this.programId = config.programId ?? "veritaszk.aleo";
71
- }
72
-
73
- /**
74
- * Verify whether an organization holds a valid solvency proof.
75
- * Returns proof status without revealing any financial data.
76
- *
77
- * @param address - The Aleo address of the organization to verify
78
- * @returns SolvencyResult containing proof status and metadata
79
- *
80
- * @example
81
- * const client = new VeritasZK({ network: "testnet" })
82
- * const result = await client.verifySolvency("aleo1abc...")
83
- * console.log(result.isSolvent) // true or false — no amounts revealed
84
- */
85
- async verifySolvency(address: string): Promise<SolvencyResult> {
86
- const [raw, count] = await Promise.all([
87
- this.queryMapping("solvency_proofs", address),
88
- this.getVerificationCount(address),
89
- ]);
90
-
91
- if (!isSolvencyProofRaw(raw)) {
92
- return {
93
- address,
94
- isSolvent: false,
95
- timestamp: 0,
96
- proofNonce: "",
97
- assetCount: 0,
98
- liabilityCount: 0,
99
- verificationCount: count,
100
- lastChecked: new Date(),
101
- };
102
- }
103
-
104
- return {
105
- address,
106
- isSolvent: raw.is_solvent === true,
107
- timestamp: Number(stripSuffix(raw.timestamp)),
108
- proofNonce: String(raw.proof_nonce ?? ""),
109
- assetCount: Number(stripSuffix(raw.asset_count)),
110
- liabilityCount: Number(stripSuffix(raw.liability_count)),
111
- verificationCount: count,
112
- lastChecked: new Date(),
113
- };
114
- }
115
-
116
- /**
117
- * Retrieve public metadata for a registered organization.
118
- * Name hash only — raw organization name is never stored on-chain.
119
- *
120
- * @param address - The Aleo address of the organization
121
- * @returns OrgInfo containing registration metadata, or null if not registered
122
- */
123
- async getOrgInfo(address: string): Promise<OrgInfo | null> {
124
- const raw = await this.queryMapping("org_metadata", address);
125
- if (!isOrgInfoRaw(raw)) return null;
126
-
127
- return {
128
- address,
129
- nameHash: String(raw.name_hash ?? ""),
130
- registeredAt: Number(stripSuffix(raw.registered_at)),
131
- isActive: raw.is_active === true,
132
- };
133
- }
134
-
135
- /**
136
- * Get the total number of times an organization's proof
137
- * has been publicly verified.
138
- *
139
- * @param address - The Aleo address of the organization
140
- * @returns verification count as a number
141
- */
142
- async getVerificationCount(address: string): Promise<number> {
143
- try {
144
- const raw = await this.queryMapping("verification_count", address);
145
- if (raw === null || raw === undefined) return 0;
146
- return Number(stripSuffix(raw));
147
- } catch {
148
- return 0;
149
- }
150
- }
151
-
152
- /**
153
- * Query any mapping from the veritaszk.aleo program.
154
- * Hits: GET {rpcUrl}/program/{programId}/mapping/{mappingName}/{key}
155
- *
156
- * @param mappingName - The mapping to query
157
- * @param key - The key to look up
158
- * @returns Parsed mapping value or null if not found
159
- */
160
- private async queryMapping(
161
- mappingName: string,
162
- key: string
163
- ): Promise<unknown> {
164
- const url = `${this.rpcUrl}/program/${this.programId}/mapping/${mappingName}/${key}`;
165
-
166
- let res;
167
- try {
168
- res = await fetch(url);
169
- } catch (err) {
170
- throw new Error(
171
- `VeritasZK network error: Unable to reach ${this.rpcUrl}. ` +
172
- `Check your network connection or rpcUrl config. (${String(err)})`
173
- );
174
- }
175
-
176
- if (res.status === 404) return null;
177
-
178
- if (!res.ok) {
179
- throw new Error(
180
- `VeritasZK RPC error: ${res.status} ${res.statusText} for ${url}`
181
- );
182
- }
183
-
184
- const text = await res.text();
185
- if (!text || text === "null") return null;
186
-
187
- try {
188
- return JSON.parse(text);
189
- } catch {
190
- return text.replace(/^"|"$/g, "");
191
- }
192
- }
193
- }
194
-
195
- // ─────────────────────────────────────────────────────────────────────────────
196
- // Convenience export — verify in one line
197
- // ─────────────────────────────────────────────────────────────────────────────
198
-
199
- /**
200
- * One-line convenience function for solvency verification.
201
- *
202
- * @example
203
- * import { verifySolvency } from "veritaszk-sdk"
204
- * const { isSolvent } = await verifySolvency("aleo1abc...")
205
- */
206
- export async function verifySolvency(
207
- address: string,
208
- config?: VeritasZKConfig
209
- ): Promise<SolvencyResult> {
210
- const client = new VeritasZK(config);
211
- return client.verifySolvency(address);
212
- }
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": [
6
- "ES2020"
7
- ],
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true,
11
- "outDir": "./dist",
12
- "rootDir": "./src",
13
- "strict": true,
14
- "esModuleInterop": true,
15
- "skipLibCheck": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "resolveJsonModule": true
18
- },
19
- "include": [
20
- "src/**/*"
21
- ],
22
- "exclude": [
23
- "node_modules",
24
- "dist"
25
- ]
26
- }