hyli-noir 0.0.1 → 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 CHANGED
@@ -1,35 +1,172 @@
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
+ ```
18
+
19
+ ### Peer Dependencies
20
+
21
+ This library requires the following peer dependencies:
22
+
23
+ ```bash
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
25
+ ```
26
+
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.
12
77
 
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.
78
+ **Parameters:**
79
+ - `identity` - The user's identity string
80
+ - `password` - The user's password string
17
81
 
18
- ## Setup and Running
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
19
144
 
20
- 1. Install dependencies:
21
145
  ```bash
22
- # In the frontend directory
23
- bun install
146
+ bun run build
24
147
  ```
25
148
 
26
- 2. Run the frontend development server:
149
+ ### Publishing
150
+
27
151
  ```bash
28
- # In the frontend directory
29
- bun run dev
152
+ bun run pub
30
153
  ```
31
154
 
32
- ## Security
155
+ ## License
156
+
157
+ MIT
158
+
159
+ ## Contributing
160
+
161
+ Contributions are welcome! Please feel free to submit a Pull Request.
162
+
163
+ ## Support
164
+
165
+ For issues and questions:
166
+ - GitHub Issues: [https://github.com/hyli-org/hyli-noir/issues](https://github.com/hyli-org/hyli-noir/issues)
167
+ - Repository: [https://github.com/hyli-org/hyli-noir](https://github.com/hyli-org/hyli-noir)
33
168
 
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.
169
+ ## Related Projects
35
170
 
171
+ - [Hyli](https://github.com/hyli-org/hyli) - The main Hyli ecosystem
172
+ - [Noir](https://noir-lang.org/) - Zero-knowledge proof language
@@ -1,5 +1,28 @@
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
+ */
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
+ */
25
+ export declare const identity_hash: (identity: string, password: string) => Promise<string>;
3
26
  /**
4
27
  * Builds a blob transaction containing a secret derived from an identity and password.
5
28
  * The secret is constructed by: