veritaszk-sdk 0.1.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/README.md +77 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/index.ts +212 -0
- package/tsconfig.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# veritaszk-sdk
|
|
2
|
+
|
|
3
|
+
Zero-knowledge solvency verification for Aleo.
|
|
4
|
+
Verify any organization's proof of solvency in 3 lines of code —
|
|
5
|
+
without seeing their financial data.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
```bash
|
|
9
|
+
npm install veritaszk-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
```typescript
|
|
14
|
+
import { VeritasZK } from "veritaszk-sdk"
|
|
15
|
+
|
|
16
|
+
const client = new VeritasZK({ network: "testnet" })
|
|
17
|
+
|
|
18
|
+
// Verify an organization's solvency
|
|
19
|
+
const result = await client.verifySolvency("aleo1abc...")
|
|
20
|
+
console.log(result.isSolvent) // true
|
|
21
|
+
console.log(result.timestamp) // proof timestamp
|
|
22
|
+
console.log(result.verificationCount) // times verified
|
|
23
|
+
// Note: no amounts, no asset types, no financial data returned
|
|
24
|
+
|
|
25
|
+
// Get organization info
|
|
26
|
+
const org = await client.getOrgInfo("aleo1abc...")
|
|
27
|
+
console.log(org?.isActive) // true
|
|
28
|
+
|
|
29
|
+
// One-line convenience function
|
|
30
|
+
import { verifySolvency } from "veritaszk-sdk"
|
|
31
|
+
const { isSolvent } = await verifySolvency("aleo1abc...")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## What the SDK does NOT return
|
|
35
|
+
|
|
36
|
+
By design, `veritaszk-sdk` never returns:
|
|
37
|
+
- Asset amounts or liability amounts
|
|
38
|
+
- Asset types or compositions
|
|
39
|
+
- Wallet addresses beyond the one queried
|
|
40
|
+
- Any data that could reveal financial strategy
|
|
41
|
+
|
|
42
|
+
This is guaranteed by the underlying Leo smart contract —
|
|
43
|
+
the data does not exist in any queryable public state.
|
|
44
|
+
|
|
45
|
+
## API Reference
|
|
46
|
+
|
|
47
|
+
### `new VeritasZK(config?)`
|
|
48
|
+
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
|--------|------|---------|-------------|
|
|
51
|
+
| network | `"testnet"` \| `"mainnet"` | `"testnet"` | Aleo network |
|
|
52
|
+
| rpcUrl | `string` | Aleo testnet RPC | Custom RPC endpoint |
|
|
53
|
+
| programId | `string` | `"veritaszk.aleo"` | Contract program ID |
|
|
54
|
+
|
|
55
|
+
### `client.verifySolvency(address)` → `Promise<SolvencyResult>`
|
|
56
|
+
|
|
57
|
+
| Field | Type | Description |
|
|
58
|
+
|-------|------|-------------|
|
|
59
|
+
| isSolvent | boolean | Whether a valid proof exists |
|
|
60
|
+
| timestamp | number | When the proof was generated |
|
|
61
|
+
| proofNonce | string | BHP256 commitment — not reversible |
|
|
62
|
+
| assetCount | number | Number of asset categories declared |
|
|
63
|
+
| liabilityCount | number | Number of liability categories declared |
|
|
64
|
+
| verificationCount | number | Times this proof has been verified |
|
|
65
|
+
| lastChecked | Date | When this query was made |
|
|
66
|
+
|
|
67
|
+
### `client.getOrgInfo(address)` → `Promise<OrgInfo | null>`
|
|
68
|
+
|
|
69
|
+
### `client.getVerificationCount(address)` → `Promise<number>`
|
|
70
|
+
|
|
71
|
+
## Links
|
|
72
|
+
|
|
73
|
+
- [Live Demo](https://veritaszk.vercel.app)
|
|
74
|
+
- [GitHub](https://github.com/Vinaystwt/veritaszk)
|
|
75
|
+
- [Aleo Explorer](https://explorer.aleo.org)
|
|
76
|
+
|
|
77
|
+
Built on [Aleo](https://aleo.org) — privacy by default.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export interface SolvencyResult {
|
|
2
|
+
address: string;
|
|
3
|
+
isSolvent: boolean;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
proofNonce: string;
|
|
6
|
+
assetCount: number;
|
|
7
|
+
liabilityCount: number;
|
|
8
|
+
verificationCount: number;
|
|
9
|
+
lastChecked: Date;
|
|
10
|
+
}
|
|
11
|
+
export interface OrgInfo {
|
|
12
|
+
address: string;
|
|
13
|
+
nameHash: string;
|
|
14
|
+
registeredAt: number;
|
|
15
|
+
isActive: boolean;
|
|
16
|
+
}
|
|
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;
|
|
65
|
+
}
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgCD,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,GAAE,eAAoB;IAOxC;;;;;;;;;;;OAWG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA+B9D;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAY1D;;;;;;OAMG;IACG,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU5D;;;;;;;OAOG;YACW,YAAY;CAiC3B;AAMD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,cAAc,CAAC,CAGzB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VeritasZK = void 0;
|
|
7
|
+
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)$/, "");
|
|
11
|
+
}
|
|
12
|
+
function isSolvencyProofRaw(v) {
|
|
13
|
+
return typeof v === "object" && v !== null && "is_solvent" in v;
|
|
14
|
+
}
|
|
15
|
+
function isOrgInfoRaw(v) {
|
|
16
|
+
return typeof v === "object" && v !== null && "name_hash" in v;
|
|
17
|
+
}
|
|
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, "");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
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);
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","s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AU,cAAc,CAClC,OAAe,EACf,MAAwB;IAExB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
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.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"aleo",
|
|
13
|
+
"zero-knowledge",
|
|
14
|
+
"zk",
|
|
15
|
+
"solvency",
|
|
16
|
+
"proof-of-reserves",
|
|
17
|
+
"privacy",
|
|
18
|
+
"leo"
|
|
19
|
+
],
|
|
20
|
+
"author": "VeritasZK",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/Vinaystwt/veritaszk"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://veritaszk.vercel.app",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"node-fetch": "^3.3.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|