hyli-noir 0.0.2 → 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/README.md CHANGED
@@ -1,35 +1,187 @@
1
- # Check Secret Noir
1
+ # Hyli-noir
2
2
 
3
- This is a demonstration project that shows how to implement a secret checking system using Noir (a Domain Specific Language for SNARK proving systems) with a web frontend.
3
+ A TypeScript/JavaScript library providing Noir-based zero-knowledge proof functionality for the Hyli ecosystem. This library enables secure secret verification through cryptographic proofs without revealing sensitive information.
4
4
 
5
- ## Project Structure
5
+ ## Features
6
6
 
7
- - `/contract` - Contains the Noir smart contract code
8
- - `src/main.nr` - The main Noir contract implementing the secret checking logic
9
- - `/frontend` - Web interface implementation
7
+ - 🔐 **Zero-Knowledge Secret Verification**: Generate proofs that demonstrate knowledge of a password without revealing it
8
+ - 🛡️ **Identity-Based Authentication**: Combine user identity with password hashing for secure authentication
9
+ - 📦 **Blob Transaction Support**: Create and manage blob transactions containing encrypted secrets
10
+ - ⚡ **Noir Circuit Integration**: Built on Noir's zero-knowledge proof system with UltraHonk backend
11
+ - 🔧 **TypeScript Support**: Full TypeScript definitions and type safety
10
12
 
11
- ## Features
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install hyli-noir
17
+ ```
12
18
 
13
- - Zero-knowledge proof based secret verification
14
- - Web interface for submitting identity and password
15
- - Real-time proof verification display
16
- - Secure password handling through zero-knowledge proofs, settling on Hyle network.
19
+ ### Peer Dependencies
17
20
 
18
- ## Setup and Running
21
+ This library requires the following peer dependencies:
19
22
 
20
- 1. Install dependencies:
21
23
  ```bash
22
- # In the frontend directory
23
- bun install
24
+ npm install @aztec/bb.js@0.82.2 @noir-lang/noir_js@1.0.0-beta.2 @noir-lang/noir_wasm@1.0.0-beta.2
24
25
  ```
25
26
 
26
- 2. Run the frontend development server:
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { check_secret } from 'hyli-noir';
31
+
32
+ // Hash a password
33
+ const hashedPassword = await check_secret.hash_password('my-secret-password');
34
+
35
+ // Generate identity hash
36
+ const identityHash = await check_secret.identity_hash('user@example.com', 'my-secret-password');
37
+
38
+ // Build a blob transaction
39
+ const blob = await check_secret.build_blob('user@example.com', 'my-secret-password');
40
+
41
+ // Generate a proof transaction
42
+ const proofTx = await check_secret.build_proof_transaction(
43
+ 'user@example.com',
44
+ 'my-secret-password',
45
+ '0x1234567890abcdef...', // transaction hash
46
+ 0, // blob index
47
+ 1 // total blob count
48
+ );
49
+ ```
50
+
51
+ ## API Reference
52
+
53
+ ### Core Functions
54
+
55
+ #### `hash_password(password: string): Promise<Uint8Array>`
56
+
57
+ Hashes a password using SHA-256.
58
+
59
+ **Parameters:**
60
+ - `password` - The password string to hash
61
+
62
+ **Returns:** Promise resolving to a 32-byte Uint8Array containing the SHA-256 hash
63
+
64
+ #### `identity_hash(identity: string, password: string): Promise<string>`
65
+
66
+ Creates a combined hash of identity and password for authentication.
67
+
68
+ **Parameters:**
69
+ - `identity` - The user's identity string
70
+ - `password` - The user's password string
71
+
72
+ **Returns:** Promise resolving to a hex-encoded string of the combined hash
73
+
74
+ #### `build_blob(identity: string, password: string): Promise<Blob>`
75
+
76
+ Creates a blob transaction containing a secret derived from identity and password.
77
+
78
+ **Parameters:**
79
+ - `identity` - The user's identity string
80
+ - `password` - The user's password string
81
+
82
+ **Returns:** Promise resolving to a Blob object containing the encrypted secret
83
+
84
+ #### `build_proof_transaction(identity, password, tx_hash, blob_index, tx_blob_count, circuit?): Promise<ProofTransaction>`
85
+
86
+ Generates a zero-knowledge proof transaction demonstrating knowledge of the password.
87
+
88
+ **Parameters:**
89
+ - `identity` - The user's identity string
90
+ - `password` - The user's password string
91
+ - `tx_hash` - The blob transaction hash string
92
+ - `blob_index` - The index of the blob in the transaction
93
+ - `tx_blob_count` - Total number of blobs in the transaction
94
+ - `circuit` - Optional compiled Noir circuit (defaults to check_secret circuit)
95
+
96
+ **Returns:** Promise resolving to a ProofTransaction containing the generated proof
97
+
98
+ #### `register_contract(node, circuit?): Promise<void>`
99
+
100
+ Registers the Noir contract with the node if not already registered.
101
+
102
+ **Parameters:**
103
+ - `node` - The NodeApiHttpClient instance
104
+ - `circuit` - Optional compiled Noir circuit (defaults to check_secret circuit)
105
+
106
+ ### Utility Functions
107
+
108
+ #### `assert(condition: boolean, message: string): void`
109
+
110
+ Throws an error if the condition is false.
111
+
112
+ #### `sha256(data: Uint8Array): Promise<Uint8Array>`
113
+
114
+ Computes SHA-256 hash of the input data.
115
+
116
+ #### `stringToBytes(input: string): Uint8Array`
117
+
118
+ Converts a string to Uint8Array using UTF-8 encoding.
119
+
120
+ #### `encodeToHex(data: Uint8Array): string`
121
+
122
+ Converts Uint8Array to hex string representation.
123
+
124
+ ## How It Works
125
+
126
+ The library implements a zero-knowledge proof system for secret verification:
127
+
128
+ 1. **Password Hashing**: The user's password is hashed using SHA-256 to create a fixed-size secret
129
+ 2. **Identity Combination**: The identity is concatenated with the hashed password using a colon separator
130
+ 3. **Final Hash**: The combined value is hashed again to create the stored secret
131
+ 4. **Proof Generation**: A zero-knowledge proof is generated that demonstrates knowledge of the password without revealing it
132
+ 5. **Verification**: The proof can be verified against the stored hash without exposing the original password
133
+
134
+ ## Security Considerations
135
+
136
+ - Passwords are never stored in plain text
137
+ - The zero-knowledge proof system ensures password privacy
138
+ - All cryptographic operations use industry-standard algorithms (SHA-256)
139
+ - The system is designed to prevent replay attacks and unauthorized access
140
+
141
+ ## Development
142
+
143
+ ### Building Noir contract
144
+
145
+ In `./check-jwt/` folder if `./Prover.toml` is present and well constructed
146
+
27
147
  ```bash
28
- # In the frontend directory
29
- bun run dev
148
+ nargo execute
30
149
  ```
150
+ It builds and executes the circuit.
151
+
152
+ In `./check-secret/`, to build without executing do
153
+
154
+ ```bash
155
+ nargo build
156
+ ```
157
+
158
+ ### Building library
159
+
160
+ ```bash
161
+ bun run build
162
+ ```
163
+
164
+ ### Publishing
165
+
166
+ ```bash
167
+ bun run pub
168
+ ```
169
+
170
+ ## License
171
+
172
+ MIT
173
+
174
+ ## Contributing
175
+
176
+ Contributions are welcome! Please feel free to submit a Pull Request.
177
+
178
+ ## Support
31
179
 
32
- ## Security
180
+ For issues and questions:
181
+ - GitHub Issues: [https://github.com/hyli-org/hyli-noir/issues](https://github.com/hyli-org/hyli-noir/issues)
182
+ - Repository: [https://github.com/hyli-org/hyli-noir](https://github.com/hyli-org/hyli-noir)
33
183
 
34
- This example demonstrates zero-knowledge proof concepts for password verification. The password is never directly exposed in the verification process, enhancing security through cryptographic proofs.
184
+ ## Related Projects
35
185
 
186
+ - [Hyli](https://github.com/hyli-org/hyli) - The main Hyli ecosystem
187
+ - [Noir](https://noir-lang.org/) - Zero-knowledge proof language
@@ -0,0 +1,70 @@
1
+ import { Fr } from "@aztec/bb.js";
2
+ import { CompiledCircuit } from "@noir-lang/noir_js";
3
+ import { Blob } from "hyli";
4
+ export declare const contract_name = "check_jwt";
5
+ /**
6
+ * Generates a cryptographic proof for a transaction using a JWT circuit.
7
+ *
8
+ * @param {Object} params - Parameters required for proof generation.
9
+ * @param {string} params.identity - The user's identity string.
10
+ * @param {number[]} params.stored_hash - The precomputed/stored hash.
11
+ * @param {string} params.tx - The transaction identifier or hash.
12
+ * @param {number} params.blob_index - The index of the blob within the transaction.
13
+ * @param {number} params.tx_blob_count - The total number of blobs in the transaction.
14
+ * @param {string} params.idToken - The signed JWT token.
15
+ * @param {JsonWebKey} params.jwtPubkey - The JWT public key in JWK format.
16
+ * @param {CompiledCircuit} params.circuit - The compiled circuit to execute (defaults to check-jwt).
17
+ *
18
+ * @returns {Promise<{ contract_name: string; program_id: number[]; verifier: string; proof: number[] }>}
19
+ * An object containing verifier details and the generated proof.
20
+ */
21
+ export declare const build_proof_transaction: ({ identity, stored_hash, tx, blob_index, tx_blob_count, idToken, jwtPubkey, circuit, }: {
22
+ identity: string;
23
+ stored_hash: number[];
24
+ tx: string;
25
+ blob_index: number;
26
+ tx_blob_count: number;
27
+ idToken: string;
28
+ jwtPubkey: JsonWebKey;
29
+ circuit: CompiledCircuit;
30
+ }) => Promise<{
31
+ contract_name: string;
32
+ program_id: number[];
33
+ verifier: string;
34
+ proof: number[];
35
+ }>;
36
+ /**
37
+ * Extracts and computes the modulus (n) from a JWK public key.
38
+ *
39
+ * @param {JsonWebKey} jwk - The public key in JWK format.
40
+ * @returns {Promise<bigint>} The modulus of the public key as a BigInt.
41
+ */
42
+ export declare function jwk_pubkey_mod(jwk: JsonWebKey): Promise<bigint>;
43
+ /**
44
+ * Extracts specific claims from a JWT.
45
+ *
46
+ * @param {string} jwt - A JWT string in the format header.payload.signature.
47
+ * @returns {{ email: string; nonce: string; kid: string }}
48
+ * An object containing the email, nonce, and key ID (kid).
49
+ */
50
+ export declare const extract_jwt_claims: (jwt: string) => {
51
+ email: string;
52
+ nonce: string;
53
+ kid: string;
54
+ };
55
+ /**
56
+ * Builds a blob representing a JWT, used for proof generation in the circuit.
57
+ *
58
+ * @param {Uint8Array} mail_hash - The hashed email value.
59
+ * @param {string} nonce - The nonce value from the JWT.
60
+ * @param {string} pubkey - The public key (base64url encoded).
61
+ * @returns {Blob} A structured Blob object containing the JWT data.
62
+ */
63
+ export declare const build_blob: (mail_hash: Uint8Array, nonce: string, pubkey: string) => Blob;
64
+ /**
65
+ * Computes the Poseidon2 hash of a string.
66
+ *
67
+ * @param {string} string - The input string to be hashed.
68
+ * @returns {Promise<Fr>} The Poseidon2 hash result.
69
+ */
70
+ export declare const poseidon_hash: (string: string) => Promise<Fr>;
@@ -1,6 +1,27 @@
1
1
  import { CompiledCircuit } from "@noir-lang/types";
2
2
  import { Blob, ProofTransaction, NodeApiHttpClient } from "hyli";
3
+ /**
4
+ * Hashes a password using SHA-256.
5
+ * The password is converted to a Uint8Array and hashed using SHA-256.
6
+ * The resulting hash is returned as a Uint8Array.
7
+ *
8
+ * @param password - The password string to hash
9
+ * @returns A Promise resolving to the Uint8Array of the computed hash
10
+ */
3
11
  export declare const hash_password: (password: string) => Promise<Uint8Array>;
12
+ /**
13
+ * Hashes an identity and password together using SHA-256.
14
+ * The identity is concatenated with ':' and the hashed password.
15
+ * The resulting combined value is hashed again using SHA-256.
16
+ * The resulting hash is returned as a hexadecimal string that can be
17
+ * stored publicly.
18
+ *
19
+ * This function is mainly used to check the given password against a stored hash.
20
+ *
21
+ * @param identity - The user's identity string
22
+ * @param password - The user's password string
23
+ * @returns A Promise resolving to the hexadecimal string of the computed hash
24
+ */
4
25
  export declare const identity_hash: (identity: string, password: string) => Promise<string>;
5
26
  /**
6
27
  * Builds a blob transaction containing a secret derived from an identity and password.
@@ -39,8 +60,3 @@ export declare const build_proof_transaction: (identity: string, password: strin
39
60
  * @returns A Promise that resolves when the contract is registered
40
61
  */
41
62
  export declare const register_contract: (node: NodeApiHttpClient, circuit?: CompiledCircuit) => Promise<void>;
42
- export declare const assert: (condition: boolean, message: string) => void;
43
- export declare const sha256: (data: Uint8Array) => Promise<Uint8Array>;
44
- export declare const stringToBytes: (input: string) => Uint8Array;
45
- export declare const encodeToHex: (data: Uint8Array) => string;
46
- export declare function flattenFieldsAsArray(fields: string[]): Uint8Array;
@@ -0,0 +1,7 @@
1
+ export declare const assert: (condition: boolean, message: string) => void;
2
+ export declare const sha256: (data: Uint8Array) => Promise<Uint8Array>;
3
+ export declare const stringToBytes: (input: string) => Uint8Array;
4
+ export declare const encodeToHex: (data: Uint8Array) => string;
5
+ export declare function flattenFieldsAsArray(fields: string[]): Uint8Array;
6
+ export declare function bytesToBigInt(bytes: Uint8Array): bigint;
7
+ export declare function b64urlToU8(s: string): Uint8Array;