@opaquecash/psr-core 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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Base class for PSR errors surfaced to applications.
3
+ */
4
+ export declare class PsrError extends Error {
5
+ /** Machine-readable tag for logging and UI. */
6
+ readonly code: string;
7
+ constructor(code: string, message: string);
8
+ }
9
+ /** Groth16 or witness pipeline failed. */
10
+ export declare class ProofError extends PsrError {
11
+ constructor(message: string);
12
+ }
13
+ /** Merkle root is missing or past verifier TTL. */
14
+ export declare class RootExpiredError extends PsrError {
15
+ constructor(message?: string);
16
+ }
17
+ /** On-chain nullifier already consumed. */
18
+ export declare class NullifierUsedError extends PsrError {
19
+ constructor(message?: string);
20
+ }
21
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,0CAA0C;AAC1C,qBAAa,UAAW,SAAQ,QAAQ;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,mDAAmD;AACnD,qBAAa,gBAAiB,SAAQ,QAAQ;gBAChC,OAAO,SAA+C;CAInE;AAED,2CAA2C;AAC3C,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,OAAO,SAAqD;CAIzE"}
package/dist/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Base class for PSR errors surfaced to applications.
3
+ */
4
+ export class PsrError extends Error {
5
+ /** Machine-readable tag for logging and UI. */
6
+ code;
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.name = "PsrError";
10
+ this.code = code;
11
+ }
12
+ }
13
+ /** Groth16 or witness pipeline failed. */
14
+ export class ProofError extends PsrError {
15
+ constructor(message) {
16
+ super("PROOF_ERROR", message);
17
+ this.name = "ProofError";
18
+ }
19
+ }
20
+ /** Merkle root is missing or past verifier TTL. */
21
+ export class RootExpiredError extends PsrError {
22
+ constructor(message = "Merkle root expired or unknown on verifier") {
23
+ super("ROOT_EXPIRED", message);
24
+ this.name = "RootExpiredError";
25
+ }
26
+ }
27
+ /** On-chain nullifier already consumed. */
28
+ export class NullifierUsedError extends PsrError {
29
+ constructor(message = "Nullifier already used for this reputation proof") {
30
+ super("NULLIFIER_USED", message);
31
+ this.name = "NullifierUsedError";
32
+ }
33
+ }
34
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,+CAA+C;IACtC,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,0CAA0C;AAC1C,MAAM,OAAO,UAAW,SAAQ,QAAQ;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,mDAAmD;AACnD,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAC5C,YAAY,OAAO,GAAG,4CAA4C;QAChE,KAAK,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,2CAA2C;AAC3C,MAAM,OAAO,kBAAmB,SAAQ,QAAQ;IAC9C,YAAY,OAAO,GAAG,kDAAkD;QACtE,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@opaquecash/psr-core` — Programmable Stealth Reputation types and deterministic scoping.
3
+ *
4
+ * Safe to import in Node, edge workers, and browsers (no snarkjs / WASM required).
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export { PSR_CIRCUIT_VERSION } from "./scope.js";
9
+ export { buildActionScope, externalNullifierFromScope } from "./scope.js";
10
+ export type { Attestation, DiscoveredTrait, MerkleRootMeta, ProofData, } from "./types.js";
11
+ export { PsrError, ProofError, RootExpiredError, NullifierUsedError, } from "./errors.js";
12
+ export { attestationsToDiscoveredTraits } from "./traits.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE1E,YAAY,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@opaquecash/psr-core` — Programmable Stealth Reputation types and deterministic scoping.
3
+ *
4
+ * Safe to import in Node, edge workers, and browsers (no snarkjs / WASM required).
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export { PSR_CIRCUIT_VERSION } from "./scope.js";
9
+ export { buildActionScope, externalNullifierFromScope } from "./scope.js";
10
+ export { PsrError, ProofError, RootExpiredError, NullifierUsedError, } from "./errors.js";
11
+ export { attestationsToDiscoveredTraits } from "./traits.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAS1E,OAAO,EACL,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Semantic version string for Circom / artifact compatibility (bump when circuits change).
3
+ */
4
+ export declare const PSR_CIRCUIT_VERSION: "0.1.0";
5
+ /**
6
+ * Build a deterministic action scope string from chain + module + action id.
7
+ *
8
+ * Use stable `actionId` values (proposal id, campaign id, …). **Do not** use timestamps alone in production.
9
+ *
10
+ * @param params - Scope components.
11
+ * @returns Canonical `chainId:module:actionId` string.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const scope = buildActionScope({
16
+ * chainId: 11155111,
17
+ * module: "governance",
18
+ * actionId: "proposal-42",
19
+ * });
20
+ * ```
21
+ */
22
+ export declare function buildActionScope(params: {
23
+ chainId: number;
24
+ module: string;
25
+ actionId: string | bigint | number;
26
+ }): string;
27
+ /**
28
+ * Map a scope string to a `uint256` external nullifier using Keccak-256 (left-padded to 32 bytes).
29
+ *
30
+ * Must stay consistent with how your circuit expects the external nullifier input.
31
+ *
32
+ * @param scope - Output of {@link buildActionScope}.
33
+ */
34
+ export declare function externalNullifierFromScope(scope: string): bigint;
35
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,mBAAmB,SAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CACpC,GAAG,MAAM,CAMT;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhE"}
package/dist/scope.js ADDED
@@ -0,0 +1,40 @@
1
+ import { keccak256, stringToBytes } from "viem";
2
+ /**
3
+ * Semantic version string for Circom / artifact compatibility (bump when circuits change).
4
+ */
5
+ export const PSR_CIRCUIT_VERSION = "0.1.0";
6
+ /**
7
+ * Build a deterministic action scope string from chain + module + action id.
8
+ *
9
+ * Use stable `actionId` values (proposal id, campaign id, …). **Do not** use timestamps alone in production.
10
+ *
11
+ * @param params - Scope components.
12
+ * @returns Canonical `chainId:module:actionId` string.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const scope = buildActionScope({
17
+ * chainId: 11155111,
18
+ * module: "governance",
19
+ * actionId: "proposal-42",
20
+ * });
21
+ * ```
22
+ */
23
+ export function buildActionScope(params) {
24
+ const id = typeof params.actionId === "bigint"
25
+ ? params.actionId.toString()
26
+ : String(params.actionId);
27
+ return `${params.chainId}:${params.module}:${id}`;
28
+ }
29
+ /**
30
+ * Map a scope string to a `uint256` external nullifier using Keccak-256 (left-padded to 32 bytes).
31
+ *
32
+ * Must stay consistent with how your circuit expects the external nullifier input.
33
+ *
34
+ * @param scope - Output of {@link buildActionScope}.
35
+ */
36
+ export function externalNullifierFromScope(scope) {
37
+ const hash = keccak256(stringToBytes(scope));
38
+ return BigInt(hash);
39
+ }
40
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAgB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAIhC;IACC,MAAM,EAAE,GACN,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ;QACjC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE;QAC5B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;AACpD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAa;IACtD,MAAM,IAAI,GAAG,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Attestation, DiscoveredTrait } from "./types.js";
2
+ /**
3
+ * Convert raw WASM/JSON {@link Attestation} rows into {@link DiscoveredTrait}.
4
+ *
5
+ * @param rows - Parsed JSON array from `scan_attestations_wasm`.
6
+ * @param nowMs - Optional clock override (defaults to `Date.now()`).
7
+ */
8
+ export declare function attestationsToDiscoveredTraits(rows: Attestation[], nowMs?: number): DiscoveredTrait[];
9
+ //# sourceMappingURL=traits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traits.d.ts","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,WAAW,EAAE,EACnB,KAAK,GAAE,MAAmB,GACzB,eAAe,EAAE,CASnB"}
package/dist/traits.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Convert raw WASM/JSON {@link Attestation} rows into {@link DiscoveredTrait}.
3
+ *
4
+ * @param rows - Parsed JSON array from `scan_attestations_wasm`.
5
+ * @param nowMs - Optional clock override (defaults to `Date.now()`).
6
+ */
7
+ export function attestationsToDiscoveredTraits(rows, nowMs = Date.now()) {
8
+ return rows.map((a) => ({
9
+ attestationId: a.attestation_id,
10
+ stealthAddress: a.stealth_address,
11
+ txHash: a.tx_hash,
12
+ blockNumber: a.block_number,
13
+ discoveredAt: nowMs,
14
+ ephemeralPubkey: a.ephemeral_pubkey,
15
+ }));
16
+ }
17
+ //# sourceMappingURL=traits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traits.js","sourceRoot":"","sources":["../src/traits.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,IAAmB,EACnB,QAAgB,IAAI,CAAC,GAAG,EAAE;IAE1B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtB,aAAa,EAAE,CAAC,CAAC,cAAc;QAC/B,cAAc,EAAE,CAAC,CAAC,eAAe;QACjC,MAAM,EAAE,CAAC,CAAC,OAAO;QACjB,WAAW,EAAE,CAAC,CAAC,YAAY;QAC3B,YAAY,EAAE,KAAK;QACnB,eAAe,EAAE,CAAC,CAAC,gBAAgB;KACpC,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { Hex } from "viem";
2
+ /**
3
+ * Issuer attestation embedded in announcement metadata and discovered by the WASM scanner.
4
+ */
5
+ export interface Attestation {
6
+ /** Stealth address the trait is bound to (hex). */
7
+ readonly stealth_address: string;
8
+ /** Numeric attestation / trait id from issuer policy. */
9
+ readonly attestation_id: number;
10
+ /** Source transaction hash. */
11
+ readonly tx_hash: string;
12
+ /** Block number containing the announcement. */
13
+ readonly block_number: number;
14
+ /** Compressed ephemeral secp256k1 pubkey bytes. */
15
+ readonly ephemeral_pubkey: number[];
16
+ }
17
+ /**
18
+ * Trait discovered for the connected recipient (app-level view over {@link Attestation}).
19
+ */
20
+ export interface DiscoveredTrait {
21
+ /** Numeric attestation id (matches circuit public input). */
22
+ attestationId: number;
23
+ /** One-time stealth address. */
24
+ stealthAddress: string;
25
+ /** Announcement transaction hash. */
26
+ txHash: string;
27
+ blockNumber: number;
28
+ /** Unix ms when the trait was discovered client-side. */
29
+ discoveredAt: number;
30
+ /** Ephemeral pubkey from the announcement (compressed bytes). */
31
+ ephemeralPubkey?: number[];
32
+ }
33
+ /**
34
+ * Metadata about an on-chain Merkle root (for indexers or `OpaqueReputationVerifier` history).
35
+ */
36
+ export interface MerkleRootMeta {
37
+ /** 32-byte root as hex. */
38
+ root: Hex;
39
+ /** Block or timestamp context from your indexer / contract. */
40
+ blockNumber?: bigint;
41
+ submittedAt?: bigint;
42
+ /** Whether the verifier considers the root valid right now. */
43
+ valid?: boolean;
44
+ }
45
+ /**
46
+ * Groth16 proof bundle compatible with {@link submitVerifyReputation} in `@opaquecash/psr-chain`.
47
+ */
48
+ export interface ProofData {
49
+ proof: {
50
+ pi_a: string[];
51
+ pi_b: string[][];
52
+ pi_c: string[];
53
+ };
54
+ publicSignals: string[];
55
+ nullifier: string;
56
+ attestationId: number;
57
+ }
58
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,yDAAyD;IACzD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,+BAA+B;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2BAA2B;IAC3B,IAAI,EAAE,GAAG,CAAC;IACV,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;QACjB,IAAI,EAAE,MAAM,EAAE,CAAC;KAChB,CAAC;IACF,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@opaquecash/psr-core",
3
+ "version": "0.1.0",
4
+ "description": "Programmable Stealth Reputation types, scoping, and error taxonomy",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "clean": "rm -rf dist"
20
+ },
21
+ "dependencies": {
22
+ "viem": "^2.21.0"
23
+ },
24
+ "sideEffects": false
25
+ }