hyli-noir 0.0.2 → 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 +157 -20
- package/dist/check_secret.d.ts +21 -0
- package/dist/hyli-noir.cjs.js.map +1 -1
- package/dist/hyli-noir.es.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,35 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hyli-noir
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
-
|
|
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
|
-
##
|
|
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
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
bun install
|
|
146
|
+
bun run build
|
|
24
147
|
```
|
|
25
148
|
|
|
26
|
-
|
|
149
|
+
### Publishing
|
|
150
|
+
|
|
27
151
|
```bash
|
|
28
|
-
|
|
29
|
-
bun run dev
|
|
152
|
+
bun run pub
|
|
30
153
|
```
|
|
31
154
|
|
|
32
|
-
##
|
|
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
|
-
|
|
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
|
package/dist/check_secret.d.ts
CHANGED
|
@@ -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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hyli-noir.cjs.js","sources":["../node_modules/@noir-lang/noir_js/lib/base64_decode.mjs","../node_modules/@noir-lang/noir_js/lib/witness_generation.mjs","../node_modules/@noir-lang/noir_js/lib/program.mjs","../src/check_secret.ts"],"sourcesContent":["// Since this is a simple function, we can use feature detection to\n// see if we are in the nodeJs environment or the browser environment.\nexport function base64Decode(input) {\n if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(input, 'base64');\n }\n else if (typeof atob === 'function') {\n // Browser environment\n return Uint8Array.from(atob(input), (c) => c.charCodeAt(0));\n }\n else {\n throw new Error('No implementation found for base64 decoding.');\n }\n}\n","import { abiDecodeError, abiEncode } from '@noir-lang/noirc_abi';\nimport { base64Decode } from \"./base64_decode.mjs\";\nimport { executeProgram } from '@noir-lang/acvm_js';\nconst defaultForeignCallHandler = async (name, args) => {\n if (name == 'print') {\n // By default we do not print anything for `print` foreign calls due to a need for formatting,\n // however we provide an empty response in order to not halt execution.\n //\n // If a user needs to print values then they should provide a custom foreign call handler.\n return [];\n }\n throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);\n};\nfunction parseErrorPayload(abi, originalError) {\n const payload = originalError.rawAssertionPayload;\n if (!payload)\n return originalError;\n const enrichedError = originalError;\n try {\n // Decode the payload\n const decodedPayload = abiDecodeError(abi, payload);\n if (typeof decodedPayload === 'string') {\n // If it's a string, just add it to the error message\n enrichedError.message = `Circuit execution failed: ${decodedPayload}`;\n }\n else {\n // If not, attach the payload to the original error\n enrichedError.decodedAssertionPayload = decodedPayload;\n }\n }\n catch (_errorDecoding) {\n // Ignore errors decoding the payload\n }\n return enrichedError;\n}\n// Generates the witnesses needed to feed into the chosen proving system\nexport async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {\n // Throws on ABI encoding error\n const witnessMap = abiEncode(compiledProgram.abi, inputs);\n // Execute the circuit to generate the rest of the witnesses and serialize\n // them into a Uint8Array.\n try {\n const solvedWitness = await executeProgram(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);\n return solvedWitness;\n }\n catch (err) {\n // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.\n if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {\n throw parseErrorPayload(compiledProgram.abi, err);\n }\n throw new Error(`Circuit execution failed: ${err}`);\n }\n}\n","import { generateWitness } from \"./witness_generation.mjs\";\nimport initAbi, { abiDecode } from '@noir-lang/noirc_abi';\nimport initACVM, { compressWitnessStack } from '@noir-lang/acvm_js';\nexport class Noir {\n circuit;\n constructor(circuit) {\n this.circuit = circuit;\n }\n /** @ignore */\n async init() {\n // If these are available, then we are in the\n // web environment. For the node environment, this\n // is a no-op.\n if (typeof initAbi === 'function') {\n await Promise.all([initAbi(), initACVM()]);\n }\n }\n /**\n * @description\n * Allows to execute a circuit to get its witness and return value.\n *\n * @example\n * ```typescript\n * async execute(inputs)\n * ```\n */\n async execute(inputs, foreignCallHandler) {\n await this.init();\n const witness_stack = await generateWitness(this.circuit, inputs, foreignCallHandler);\n const main_witness = witness_stack[0].witness;\n const { return_value: returnValue } = abiDecode(this.circuit.abi, main_witness);\n return { witness: compressWitnessStack(witness_stack), returnValue };\n }\n}\n","import { Noir } from \"@noir-lang/noir_js\";\nimport { reconstructHonkProof, UltraHonkBackend } from \"@aztec/bb.js\";\nimport { CompiledCircuit, InputMap } from \"@noir-lang/types\";\nimport { Blob, ProofTransaction, NodeApiHttpClient } from \"hyli\";\n\nexport const hash_password = async (password: string): Promise<Uint8Array> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n return hashed_password_bytes;\n};\n\nexport const identity_hash = async (identity: string, password: string): Promise<string> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const computed_hash = await sha256(extended_id);\n const computed_hash_hex = Buffer.from(computed_hash).toString(\"hex\");\n return computed_hash_hex;\n};\n\n/**\n * Builds a blob transaction containing a secret derived from an identity and password.\n * The secret is constructed by:\n * 1. Hashing the password in order to have a fixed-size secret\n * 2. Concatenating the padded identity (to 64 chars) with ':' and the hashed password\n * 3. Hashing this combined value\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @returns A Promise resolving to a BlobTransaction containing the hashed secret\n */\nexport const build_blob = async (identity: string, password: string): Promise<Blob> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const secretBlob: Blob = {\n contract_name: \"check_secret\",\n data: Array.from(stored_hash),\n };\n\n return secretBlob;\n};\n\nimport defaultCircuit from \"../check-secret/target/check_secret.json\";\n\n/**\n * Builds a proof transaction by generating a zero-knowledge proof for checking a secret.\n * The proof demonstrates knowledge of a password that, when combined with an identity and hashed,\n * matches a stored hash value. The process involves:\n * 1. Hashing the password and combining it with the identity\n * 2. Generating a witness and proof using the UltraHonk backend\n * 3. Reconstructing and formatting the proof for the transaction\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @param tx_hash - The blob transaction hash string\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise resolving to a ProofTransaction containing the generated proof\n */\nexport const build_proof_transaction = async (\n identity: string,\n password: string,\n tx_hash: string,\n blob_index: number,\n tx_blob_count: number,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<ProofTransaction> => {\n const noir = new Noir(circuit);\n const backend = new UltraHonkBackend(circuit.bytecode);\n const vk = await backend.getVerificationKey();\n\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const { witness } = await noir.execute(\n generateProverData(identity, hashed_password_bytes, stored_hash, tx_hash, blob_index, tx_blob_count),\n );\n\n const proof = await backend.generateProof(witness);\n const reconstructedProof = reconstructHonkProof(flattenFieldsAsArray(proof.publicInputs), proof.proof);\n\n return {\n contract_name: \"check_secret\",\n program_id: Array.from(vk),\n verifier: \"noir\",\n proof: Array.from(reconstructedProof),\n };\n};\n\n/**\n * Registers the Noir contract with the node if it is not already registered.\n * The contract is identified by its name \"check_secret\".\n * If the contract is not found, it registers the contract using the provided circuit.\n *\n * @param node - The NodeApiHttpClient instance to interact with the NodeApiHttpClient\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise that resolves when the contract is registered\n */\nexport const register_contract = async (\n node: NodeApiHttpClient,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<void> => {\n await node.getContract(\"check_secret\").catch(async () => {\n const backend = new UltraHonkBackend(circuit.bytecode);\n\n const vk = await backend.getVerificationKey();\n\n await node.registerContract({\n verifier: \"noir\",\n program_id: Array.from(vk),\n state_commitment: [0, 0, 0, 0],\n contract_name: \"check_secret\",\n });\n });\n};\n\n// ---- Utility functions ----\n\nexport const assert = (condition: boolean, message: string): void => {\n if (!condition) {\n throw new Error(message);\n }\n};\n\nexport const sha256 = async (data: Uint8Array): Promise<Uint8Array> => {\n const hashBuffer = await crypto.subtle.digest(\"SHA-256\", data);\n return new Uint8Array(hashBuffer);\n};\n\nexport const stringToBytes = (input: string): Uint8Array => {\n return new TextEncoder().encode(input);\n};\n\nexport const encodeToHex = (data: Uint8Array): string => {\n return Array.from(data)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n};\n\nexport function flattenFieldsAsArray(fields: string[]): Uint8Array {\n const flattenedPublicInputs = fields.map(hexToUint8Array);\n return flattenUint8Arrays(flattenedPublicInputs);\n}\n\nfunction flattenUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((acc, val) => acc + val.length, 0);\n const result = new Uint8Array(totalLength);\n\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n\n return result;\n}\n\nfunction hexToUint8Array(hex: string): Uint8Array {\n const sanitisedHex = BigInt(hex).toString(16).padStart(64, \"0\");\n\n const len = sanitisedHex.length / 2;\n const u8 = new Uint8Array(len);\n\n let i = 0;\n let j = 0;\n while (i < len) {\n u8[i] = parseInt(sanitisedHex.slice(j, j + 2), 16);\n i += 1;\n j += 2;\n }\n\n return u8;\n}\n\n/**\n * Generates the prover data required for the Noir circuit.\n *\n * @param id - The user's identity string\n * @param pwd - The hashed password as a Uint8Array\n * @param stored_hash - The stored hash as a Uint8Array\n * @param tx - The transaction hash string\n * @returns An object containing the prover data\n */\nconst generateProverData = (\n id: string,\n pwd: Uint8Array,\n stored_hash: Uint8Array,\n tx: string,\n blob_index: number,\n tx_blob_count: number,\n): InputMap => {\n const version = 1;\n const initial_state = [0, 0, 0, 0];\n const initial_state_len = initial_state.length;\n const next_state = [0, 0, 0, 0];\n const next_state_len = next_state.length;\n const identity_len = id.length;\n const identity = id.padEnd(256, \"0\");\n const tx_hash = tx.padEnd(64, \"0\");\n const tx_hash_len = tx_hash.length;\n const index = blob_index;\n const blob_number = 1;\n const blob_contract_name_len = \"check_secret\".length;\n const blob_contract_name = \"check_secret\".padEnd(256, \"0\");\n const blob_capacity = 32;\n const blob_len = 32;\n const blob: number[] = Array.from(stored_hash);\n const success = 1;\n const password: number[] = Array.from(pwd);\n assert(password.length == 32, \"Password length is not 32 bytes\");\n assert(blob.length == blob_len, \"Blob length is not 32 bytes\");\n\n return {\n version,\n initial_state,\n initial_state_len,\n next_state,\n next_state_len,\n identity,\n identity_len,\n tx_hash,\n tx_hash_len,\n index,\n blob_number,\n blob_index,\n blob_contract_name_len,\n blob_contract_name,\n blob_capacity,\n blob_len,\n blob,\n tx_blob_count,\n success,\n password,\n };\n};\n"],"names":["base64Decode","input","c","defaultForeignCallHandler","name","args","parseErrorPayload","abi","originalError","payload","enrichedError","decodedPayload","abiDecodeError","generateWitness","compiledProgram","inputs","foreignCallHandler","witnessMap","abiEncode","executeProgram","err","Noir","circuit","__publicField","initAbi","initACVM","witness_stack","main_witness","returnValue","abiDecode","compressWitnessStack","hash_password","password","sha256","stringToBytes","identity_hash","identity","hashed_password_bytes","id_prefix","extended_id","computed_hash","build_blob","stored_hash","build_proof_transaction","tx_hash","blob_index","tx_blob_count","defaultCircuit","noir","backend","UltraHonkBackend","vk","witness","generateProverData","proof","reconstructedProof","reconstructHonkProof","flattenFieldsAsArray","register_contract","node","assert","condition","message","data","hashBuffer","encodeToHex","byte","fields","flattenedPublicInputs","hexToUint8Array","flattenUint8Arrays","arrays","totalLength","acc","val","result","offset","arr","hex","sanitisedHex","len","u8","i","j","id","pwd","tx","initial_state","initial_state_len","next_state","next_state_len","identity_len","tx_hash_len","index","blob_number","blob_contract_name_len","blob_contract_name","blob_capacity","blob_len","blob","success"],"mappings":"sVAEO,SAASA,EAAaC,EAAO,CAChC,GAAI,OAAO,OAAW,IAElB,OAAO,OAAO,KAAKA,EAAO,QAAQ,EAEjC,GAAI,OAAO,MAAS,WAErB,OAAO,WAAW,KAAK,KAAKA,CAAK,EAAIC,GAAMA,EAAE,WAAW,CAAC,CAAC,EAG1D,MAAM,IAAI,MAAM,8CAA8C,CAEtE,CCXA,MAAMC,EAA4B,MAAOC,EAAMC,IAAS,CACpD,GAAID,GAAQ,QAKR,MAAO,CAAE,EAEb,MAAM,MAAM,uCAAuCA,CAAI,IAAIC,EAAK,KAAK,IAAI,CAAC,GAAG,CACjF,EACA,SAASC,EAAkBC,EAAKC,EAAe,CAC3C,MAAMC,EAAUD,EAAc,oBAC9B,GAAI,CAACC,EACD,OAAOD,EACX,MAAME,EAAgBF,EACtB,GAAI,CAEA,MAAMG,EAAiBC,EAAAA,eAAeL,EAAKE,CAAO,EAC9C,OAAOE,GAAmB,SAE1BD,EAAc,QAAU,6BAA6BC,CAAc,GAInED,EAAc,wBAA0BC,CAEpD,MAC2B,CAE3B,CACI,OAAOD,CACX,CAEO,eAAeG,EAAgBC,EAAiBC,EAAQC,EAAqBb,EAA2B,CAE3G,MAAMc,EAAaC,EAAS,UAACJ,EAAgB,IAAKC,CAAM,EAGxD,GAAI,CAEA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CAAC,EAAG,EAAG,EAAG,CAAC,EAC3BC,EAAoBD,EAAc,OAClCE,EAAa,CAAC,EAAG,EAAG,EAAG,CAAC,EACxBC,EAAiBD,EAAW,OAC5BE,EAAeP,EAAG,OAClBhD,EAAWgD,EAAG,OAAO,IAAK,GAAG,EAC7BxC,EAAU0C,EAAG,OAAO,GAAI,GAAG,EAC3BM,EAAchD,EAAQ,OACtBiD,EAAQhD,EACRiD,EAAc,EACdC,EAAyB,GACzBC,EAAqB,eAAe,OAAO,IAAK,GAAG,EACnDC,EAAgB,GAChBC,EAAW,GACXC,EAAiB,MAAM,KAAKzD,CAAW,EACvC0D,EAAU,EACVpE,EAAqB,MAAM,KAAKqD,CAAG,EAClC,OAAAzB,EAAA5B,EAAS,QAAU,GAAI,iCAAiC,EACxD4B,EAAAuC,EAAK,QAAUD,EAAU,6BAA6B,EAEtD,CACL,UACA,cAAAX,EACA,kBAAAC,EACA,WAAAC,EACA,eAAAC,EACA,SAAAtD,EACA,aAAAuD,EACA,QAAA/C,EACA,YAAAgD,EACA,MAAAC,EACA,YAAAC,EACA,WAAAjD,EACA,uBAAAkD,EACA,mBAAAC,EACA,cAAAC,EACA,SAAAC,EACA,KAAAC,EACA,cAAArD,EACA,QAAAsD,EACA,SAAApE,CACF,CACF","x_google_ignoreList":[0,1,2]}
|
|
1
|
+
{"version":3,"file":"hyli-noir.cjs.js","sources":["../node_modules/@noir-lang/noir_js/lib/base64_decode.mjs","../node_modules/@noir-lang/noir_js/lib/witness_generation.mjs","../node_modules/@noir-lang/noir_js/lib/program.mjs","../src/check_secret.ts"],"sourcesContent":["// Since this is a simple function, we can use feature detection to\n// see if we are in the nodeJs environment or the browser environment.\nexport function base64Decode(input) {\n if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(input, 'base64');\n }\n else if (typeof atob === 'function') {\n // Browser environment\n return Uint8Array.from(atob(input), (c) => c.charCodeAt(0));\n }\n else {\n throw new Error('No implementation found for base64 decoding.');\n }\n}\n","import { abiDecodeError, abiEncode } from '@noir-lang/noirc_abi';\nimport { base64Decode } from \"./base64_decode.mjs\";\nimport { executeProgram } from '@noir-lang/acvm_js';\nconst defaultForeignCallHandler = async (name, args) => {\n if (name == 'print') {\n // By default we do not print anything for `print` foreign calls due to a need for formatting,\n // however we provide an empty response in order to not halt execution.\n //\n // If a user needs to print values then they should provide a custom foreign call handler.\n return [];\n }\n throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);\n};\nfunction parseErrorPayload(abi, originalError) {\n const payload = originalError.rawAssertionPayload;\n if (!payload)\n return originalError;\n const enrichedError = originalError;\n try {\n // Decode the payload\n const decodedPayload = abiDecodeError(abi, payload);\n if (typeof decodedPayload === 'string') {\n // If it's a string, just add it to the error message\n enrichedError.message = `Circuit execution failed: ${decodedPayload}`;\n }\n else {\n // If not, attach the payload to the original error\n enrichedError.decodedAssertionPayload = decodedPayload;\n }\n }\n catch (_errorDecoding) {\n // Ignore errors decoding the payload\n }\n return enrichedError;\n}\n// Generates the witnesses needed to feed into the chosen proving system\nexport async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {\n // Throws on ABI encoding error\n const witnessMap = abiEncode(compiledProgram.abi, inputs);\n // Execute the circuit to generate the rest of the witnesses and serialize\n // them into a Uint8Array.\n try {\n const solvedWitness = await executeProgram(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);\n return solvedWitness;\n }\n catch (err) {\n // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.\n if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {\n throw parseErrorPayload(compiledProgram.abi, err);\n }\n throw new Error(`Circuit execution failed: ${err}`);\n }\n}\n","import { generateWitness } from \"./witness_generation.mjs\";\nimport initAbi, { abiDecode } from '@noir-lang/noirc_abi';\nimport initACVM, { compressWitnessStack } from '@noir-lang/acvm_js';\nexport class Noir {\n circuit;\n constructor(circuit) {\n this.circuit = circuit;\n }\n /** @ignore */\n async init() {\n // If these are available, then we are in the\n // web environment. For the node environment, this\n // is a no-op.\n if (typeof initAbi === 'function') {\n await Promise.all([initAbi(), initACVM()]);\n }\n }\n /**\n * @description\n * Allows to execute a circuit to get its witness and return value.\n *\n * @example\n * ```typescript\n * async execute(inputs)\n * ```\n */\n async execute(inputs, foreignCallHandler) {\n await this.init();\n const witness_stack = await generateWitness(this.circuit, inputs, foreignCallHandler);\n const main_witness = witness_stack[0].witness;\n const { return_value: returnValue } = abiDecode(this.circuit.abi, main_witness);\n return { witness: compressWitnessStack(witness_stack), returnValue };\n }\n}\n","import { Noir } from \"@noir-lang/noir_js\";\nimport { reconstructHonkProof, UltraHonkBackend } from \"@aztec/bb.js\";\nimport { CompiledCircuit, InputMap } from \"@noir-lang/types\";\nimport { Blob, ProofTransaction, NodeApiHttpClient } from \"hyli\";\n\n/**\n * Hashes a password using SHA-256.\n * The password is converted to a Uint8Array and hashed using SHA-256.\n * The resulting hash is returned as a Uint8Array.\n *\n * @param password - The password string to hash\n * @returns A Promise resolving to the Uint8Array of the computed hash\n */\nexport const hash_password = async (password: string): Promise<Uint8Array> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n return hashed_password_bytes;\n};\n\n/**\n * Hashes an identity and password together using SHA-256.\n * The identity is concatenated with ':' and the hashed password.\n * The resulting combined value is hashed again using SHA-256.\n * The resulting hash is returned as a hexadecimal string that can be \n * stored publicly.\n * \n * This function is mainly used to check the given password against a stored hash.\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @returns A Promise resolving to the hexadecimal string of the computed hash\n */\nexport const identity_hash = async (identity: string, password: string): Promise<string> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const computed_hash = await sha256(extended_id);\n const computed_hash_hex = Buffer.from(computed_hash).toString(\"hex\");\n return computed_hash_hex;\n};\n\n/**\n * Builds a blob transaction containing a secret derived from an identity and password.\n * The secret is constructed by:\n * 1. Hashing the password in order to have a fixed-size secret\n * 2. Concatenating the padded identity (to 64 chars) with ':' and the hashed password\n * 3. Hashing this combined value\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @returns A Promise resolving to a BlobTransaction containing the hashed secret\n */\nexport const build_blob = async (identity: string, password: string): Promise<Blob> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const secretBlob: Blob = {\n contract_name: \"check_secret\",\n data: Array.from(stored_hash),\n };\n\n return secretBlob;\n};\n\nimport defaultCircuit from \"../check-secret/target/check_secret.json\";\n\n/**\n * Builds a proof transaction by generating a zero-knowledge proof for checking a secret.\n * The proof demonstrates knowledge of a password that, when combined with an identity and hashed,\n * matches a stored hash value. The process involves:\n * 1. Hashing the password and combining it with the identity\n * 2. Generating a witness and proof using the UltraHonk backend\n * 3. Reconstructing and formatting the proof for the transaction\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @param tx_hash - The blob transaction hash string\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise resolving to a ProofTransaction containing the generated proof\n */\nexport const build_proof_transaction = async (\n identity: string,\n password: string,\n tx_hash: string,\n blob_index: number,\n tx_blob_count: number,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<ProofTransaction> => {\n const noir = new Noir(circuit);\n const backend = new UltraHonkBackend(circuit.bytecode);\n const vk = await backend.getVerificationKey();\n\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const { witness } = await noir.execute(\n generateProverData(identity, hashed_password_bytes, stored_hash, tx_hash, blob_index, tx_blob_count),\n );\n\n const proof = await backend.generateProof(witness);\n const reconstructedProof = reconstructHonkProof(flattenFieldsAsArray(proof.publicInputs), proof.proof);\n\n return {\n contract_name: \"check_secret\",\n program_id: Array.from(vk),\n verifier: \"noir\",\n proof: Array.from(reconstructedProof),\n };\n};\n\n/**\n * Registers the Noir contract with the node if it is not already registered.\n * The contract is identified by its name \"check_secret\".\n * If the contract is not found, it registers the contract using the provided circuit.\n *\n * @param node - The NodeApiHttpClient instance to interact with the NodeApiHttpClient\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise that resolves when the contract is registered\n */\nexport const register_contract = async (\n node: NodeApiHttpClient,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<void> => {\n await node.getContract(\"check_secret\").catch(async () => {\n const backend = new UltraHonkBackend(circuit.bytecode);\n\n const vk = await backend.getVerificationKey();\n\n await node.registerContract({\n verifier: \"noir\",\n program_id: Array.from(vk),\n state_commitment: [0, 0, 0, 0],\n contract_name: \"check_secret\",\n });\n });\n};\n\n// ---- Utility functions ----\n\nexport const assert = (condition: boolean, message: string): void => {\n if (!condition) {\n throw new Error(message);\n }\n};\n\nexport const sha256 = async (data: Uint8Array): Promise<Uint8Array> => {\n const hashBuffer = await crypto.subtle.digest(\"SHA-256\", data);\n return new Uint8Array(hashBuffer);\n};\n\nexport const stringToBytes = (input: string): Uint8Array => {\n return new TextEncoder().encode(input);\n};\n\nexport const encodeToHex = (data: Uint8Array): string => {\n return Array.from(data)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n};\n\nexport function flattenFieldsAsArray(fields: string[]): Uint8Array {\n const flattenedPublicInputs = fields.map(hexToUint8Array);\n return flattenUint8Arrays(flattenedPublicInputs);\n}\n\nfunction flattenUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((acc, val) => acc + val.length, 0);\n const result = new Uint8Array(totalLength);\n\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n\n return result;\n}\n\nfunction hexToUint8Array(hex: string): Uint8Array {\n const sanitisedHex = BigInt(hex).toString(16).padStart(64, \"0\");\n\n const len = sanitisedHex.length / 2;\n const u8 = new Uint8Array(len);\n\n let i = 0;\n let j = 0;\n while (i < len) {\n u8[i] = parseInt(sanitisedHex.slice(j, j + 2), 16);\n i += 1;\n j += 2;\n }\n\n return u8;\n}\n\n/**\n * Generates the prover data required for the Noir circuit.\n *\n * @param id - The user's identity string\n * @param pwd - The hashed password as a Uint8Array\n * @param stored_hash - The stored hash as a Uint8Array\n * @param tx - The transaction hash string\n * @returns An object containing the prover data\n */\nconst generateProverData = (\n id: string,\n pwd: Uint8Array,\n stored_hash: Uint8Array,\n tx: string,\n blob_index: number,\n tx_blob_count: number,\n): InputMap => {\n const version = 1;\n const initial_state = [0, 0, 0, 0];\n const initial_state_len = initial_state.length;\n const next_state = [0, 0, 0, 0];\n const next_state_len = next_state.length;\n const identity_len = id.length;\n const identity = id.padEnd(256, \"0\");\n const tx_hash = tx.padEnd(64, \"0\");\n const tx_hash_len = tx_hash.length;\n const index = blob_index;\n const blob_number = 1;\n const blob_contract_name_len = \"check_secret\".length;\n const blob_contract_name = \"check_secret\".padEnd(256, \"0\");\n const blob_capacity = 32;\n const blob_len = 32;\n const blob: number[] = Array.from(stored_hash);\n const success = 1;\n const password: number[] = Array.from(pwd);\n assert(password.length == 32, \"Password length is not 32 bytes\");\n assert(blob.length == blob_len, \"Blob length is not 32 bytes\");\n\n return {\n version,\n initial_state,\n initial_state_len,\n next_state,\n next_state_len,\n identity,\n identity_len,\n tx_hash,\n tx_hash_len,\n index,\n blob_number,\n blob_index,\n blob_contract_name_len,\n blob_contract_name,\n blob_capacity,\n blob_len,\n blob,\n tx_blob_count,\n success,\n password,\n };\n};\n"],"names":["base64Decode","input","c","defaultForeignCallHandler","name","args","parseErrorPayload","abi","originalError","payload","enrichedError","decodedPayload","abiDecodeError","generateWitness","compiledProgram","inputs","foreignCallHandler","witnessMap","abiEncode","executeProgram","err","Noir","circuit","__publicField","initAbi","initACVM","witness_stack","main_witness","returnValue","abiDecode","compressWitnessStack","hash_password","password","sha256","stringToBytes","identity_hash","identity","hashed_password_bytes","id_prefix","extended_id","computed_hash","build_blob","stored_hash","build_proof_transaction","tx_hash","blob_index","tx_blob_count","defaultCircuit","noir","backend","UltraHonkBackend","vk","witness","generateProverData","proof","reconstructedProof","reconstructHonkProof","flattenFieldsAsArray","register_contract","node","assert","condition","message","data","hashBuffer","encodeToHex","byte","fields","flattenedPublicInputs","hexToUint8Array","flattenUint8Arrays","arrays","totalLength","acc","val","result","offset","arr","hex","sanitisedHex","len","u8","i","j","id","pwd","tx","initial_state","initial_state_len","next_state","next_state_len","identity_len","tx_hash_len","index","blob_number","blob_contract_name_len","blob_contract_name","blob_capacity","blob_len","blob","success"],"mappings":"sVAEO,SAASA,EAAaC,EAAO,CAChC,GAAI,OAAO,OAAW,IAElB,OAAO,OAAO,KAAKA,EAAO,QAAQ,EAEjC,GAAI,OAAO,MAAS,WAErB,OAAO,WAAW,KAAK,KAAKA,CAAK,EAAIC,GAAMA,EAAE,WAAW,CAAC,CAAC,EAG1D,MAAM,IAAI,MAAM,8CAA8C,CAEtE,CCXA,MAAMC,EAA4B,MAAOC,EAAMC,IAAS,CACpD,GAAID,GAAQ,QAKR,MAAO,CAAE,EAEb,MAAM,MAAM,uCAAuCA,CAAI,IAAIC,EAAK,KAAK,IAAI,CAAC,GAAG,CACjF,EACA,SAASC,EAAkBC,EAAKC,EAAe,CAC3C,MAAMC,EAAUD,EAAc,oBAC9B,GAAI,CAACC,EACD,OAAOD,EACX,MAAME,EAAgBF,EACtB,GAAI,CAEA,MAAMG,EAAiBC,EAAAA,eAAeL,EAAKE,CAAO,EAC9C,OAAOE,GAAmB,SAE1BD,EAAc,QAAU,6BAA6BC,CAAc,GAInED,EAAc,wBAA0BC,CAEpD,MAC2B,CAE3B,CACI,OAAOD,CACX,CAEO,eAAeG,EAAg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,EAGA,OAAAF,CACT,CAWA,MAAM5B,GAAqB,CACzB+B,EACAC,EACA3C,EACA4C,EACAzC,EACAC,IACa,CAEb,MAAMyC,EAAgB,CAAC,EAAG,EAAG,EAAG,CAAC,EAC3BC,EAAoBD,EAAc,OAClCE,EAAa,CAAC,EAAG,EAAG,EAAG,CAAC,EACxBC,EAAiBD,EAAW,OAC5BE,EAAeP,EAAG,OAClBhD,EAAWgD,EAAG,OAAO,IAAK,GAAG,EAC7BxC,EAAU0C,EAAG,OAAO,GAAI,GAAG,EAC3BM,EAAchD,EAAQ,OACtBiD,EAAQhD,EACRiD,EAAc,EACdC,EAAyB,GACzBC,EAAqB,eAAe,OAAO,IAAK,GAAG,EACnDC,EAAgB,GAChBC,EAAW,GACXC,EAAiB,MAAM,KAAKzD,CAAW,EACvC0D,EAAU,EACVpE,EAAqB,MAAM,KAAKqD,CAAG,EAClC,OAAAzB,EAAA5B,EAAS,QAAU,GAAI,iCAAiC,EACxD4B,EAAAuC,EAAK,QAAUD,EAAU,6BAA6B,EAEtD,CACL,UACA,cAAAX,EACA,kBAAAC,EACA,WAAAC,EACA,eAAAC,EACA,SAAAtD,EACA,aAAAuD,EACA,QAAA/C,EACA,YAAAgD,EACA,MAAAC,EACA,YAAAC,EACA,WAAAjD,EACA,uBAAAkD,EACA,mBAAAC,EACA,cAAAC,EACA,SAAAC,EACA,KAAAC,EACA,cAAArD,EACA,QAAAsD,EACA,SAAApE,CACF,CACF","x_google_ignoreList":[0,1,2]}
|
package/dist/hyli-noir.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hyli-noir.es.js","sources":["../node_modules/@noir-lang/noir_js/lib/base64_decode.mjs","../node_modules/@noir-lang/noir_js/lib/witness_generation.mjs","../node_modules/@noir-lang/noir_js/lib/program.mjs","../src/check_secret.ts"],"sourcesContent":["// Since this is a simple function, we can use feature detection to\n// see if we are in the nodeJs environment or the browser environment.\nexport function base64Decode(input) {\n if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(input, 'base64');\n }\n else if (typeof atob === 'function') {\n // Browser environment\n return Uint8Array.from(atob(input), (c) => c.charCodeAt(0));\n }\n else {\n throw new Error('No implementation found for base64 decoding.');\n }\n}\n","import { abiDecodeError, abiEncode } from '@noir-lang/noirc_abi';\nimport { base64Decode } from \"./base64_decode.mjs\";\nimport { executeProgram } from '@noir-lang/acvm_js';\nconst defaultForeignCallHandler = async (name, args) => {\n if (name == 'print') {\n // By default we do not print anything for `print` foreign calls due to a need for formatting,\n // however we provide an empty response in order to not halt execution.\n //\n // If a user needs to print values then they should provide a custom foreign call handler.\n return [];\n }\n throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);\n};\nfunction parseErrorPayload(abi, originalError) {\n const payload = originalError.rawAssertionPayload;\n if (!payload)\n return originalError;\n const enrichedError = originalError;\n try {\n // Decode the payload\n const decodedPayload = abiDecodeError(abi, payload);\n if (typeof decodedPayload === 'string') {\n // If it's a string, just add it to the error message\n enrichedError.message = `Circuit execution failed: ${decodedPayload}`;\n }\n else {\n // If not, attach the payload to the original error\n enrichedError.decodedAssertionPayload = decodedPayload;\n }\n }\n catch (_errorDecoding) {\n // Ignore errors decoding the payload\n }\n return enrichedError;\n}\n// Generates the witnesses needed to feed into the chosen proving system\nexport async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {\n // Throws on ABI encoding error\n const witnessMap = abiEncode(compiledProgram.abi, inputs);\n // Execute the circuit to generate the rest of the witnesses and serialize\n // them into a Uint8Array.\n try {\n const solvedWitness = await executeProgram(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);\n return solvedWitness;\n }\n catch (err) {\n // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.\n if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {\n throw parseErrorPayload(compiledProgram.abi, err);\n }\n throw new Error(`Circuit execution failed: ${err}`);\n }\n}\n","import { generateWitness } from \"./witness_generation.mjs\";\nimport initAbi, { abiDecode } from '@noir-lang/noirc_abi';\nimport initACVM, { compressWitnessStack } from '@noir-lang/acvm_js';\nexport class Noir {\n circuit;\n constructor(circuit) {\n this.circuit = circuit;\n }\n /** @ignore */\n async init() {\n // If these are available, then we are in the\n // web environment. For the node environment, this\n // is a no-op.\n if (typeof initAbi === 'function') {\n await Promise.all([initAbi(), initACVM()]);\n }\n }\n /**\n * @description\n * Allows to execute a circuit to get its witness and return value.\n *\n * @example\n * ```typescript\n * async execute(inputs)\n * ```\n */\n async execute(inputs, foreignCallHandler) {\n await this.init();\n const witness_stack = await generateWitness(this.circuit, inputs, foreignCallHandler);\n const main_witness = witness_stack[0].witness;\n const { return_value: returnValue } = abiDecode(this.circuit.abi, main_witness);\n return { witness: compressWitnessStack(witness_stack), returnValue };\n }\n}\n","import { Noir } from \"@noir-lang/noir_js\";\nimport { reconstructHonkProof, UltraHonkBackend } from \"@aztec/bb.js\";\nimport { CompiledCircuit, InputMap } from \"@noir-lang/types\";\nimport { Blob, ProofTransaction, NodeApiHttpClient } from \"hyli\";\n\nexport const hash_password = async (password: string): Promise<Uint8Array> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n return hashed_password_bytes;\n};\n\nexport const identity_hash = async (identity: string, password: string): Promise<string> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const computed_hash = await sha256(extended_id);\n const computed_hash_hex = Buffer.from(computed_hash).toString(\"hex\");\n return computed_hash_hex;\n};\n\n/**\n * Builds a blob transaction containing a secret derived from an identity and password.\n * The secret is constructed by:\n * 1. Hashing the password in order to have a fixed-size secret\n * 2. Concatenating the padded identity (to 64 chars) with ':' and the hashed password\n * 3. Hashing this combined value\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @returns A Promise resolving to a BlobTransaction containing the hashed secret\n */\nexport const build_blob = async (identity: string, password: string): Promise<Blob> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const secretBlob: Blob = {\n contract_name: \"check_secret\",\n data: Array.from(stored_hash),\n };\n\n return secretBlob;\n};\n\nimport defaultCircuit from \"../check-secret/target/check_secret.json\";\n\n/**\n * Builds a proof transaction by generating a zero-knowledge proof for checking a secret.\n * The proof demonstrates knowledge of a password that, when combined with an identity and hashed,\n * matches a stored hash value. The process involves:\n * 1. Hashing the password and combining it with the identity\n * 2. Generating a witness and proof using the UltraHonk backend\n * 3. Reconstructing and formatting the proof for the transaction\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @param tx_hash - The blob transaction hash string\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise resolving to a ProofTransaction containing the generated proof\n */\nexport const build_proof_transaction = async (\n identity: string,\n password: string,\n tx_hash: string,\n blob_index: number,\n tx_blob_count: number,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<ProofTransaction> => {\n const noir = new Noir(circuit);\n const backend = new UltraHonkBackend(circuit.bytecode);\n const vk = await backend.getVerificationKey();\n\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const { witness } = await noir.execute(\n generateProverData(identity, hashed_password_bytes, stored_hash, tx_hash, blob_index, tx_blob_count),\n );\n\n const proof = await backend.generateProof(witness);\n const reconstructedProof = reconstructHonkProof(flattenFieldsAsArray(proof.publicInputs), proof.proof);\n\n return {\n contract_name: \"check_secret\",\n program_id: Array.from(vk),\n verifier: \"noir\",\n proof: Array.from(reconstructedProof),\n };\n};\n\n/**\n * Registers the Noir contract with the node if it is not already registered.\n * The contract is identified by its name \"check_secret\".\n * If the contract is not found, it registers the contract using the provided circuit.\n *\n * @param node - The NodeApiHttpClient instance to interact with the NodeApiHttpClient\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise that resolves when the contract is registered\n */\nexport const register_contract = async (\n node: NodeApiHttpClient,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<void> => {\n await node.getContract(\"check_secret\").catch(async () => {\n const backend = new UltraHonkBackend(circuit.bytecode);\n\n const vk = await backend.getVerificationKey();\n\n await node.registerContract({\n verifier: \"noir\",\n program_id: Array.from(vk),\n state_commitment: [0, 0, 0, 0],\n contract_name: \"check_secret\",\n });\n });\n};\n\n// ---- Utility functions ----\n\nexport const assert = (condition: boolean, message: string): void => {\n if (!condition) {\n throw new Error(message);\n }\n};\n\nexport const sha256 = async (data: Uint8Array): Promise<Uint8Array> => {\n const hashBuffer = await crypto.subtle.digest(\"SHA-256\", data);\n return new Uint8Array(hashBuffer);\n};\n\nexport const stringToBytes = (input: string): Uint8Array => {\n return new TextEncoder().encode(input);\n};\n\nexport const encodeToHex = (data: Uint8Array): string => {\n return Array.from(data)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n};\n\nexport function flattenFieldsAsArray(fields: string[]): Uint8Array {\n const flattenedPublicInputs = fields.map(hexToUint8Array);\n return flattenUint8Arrays(flattenedPublicInputs);\n}\n\nfunction flattenUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((acc, val) => acc + val.length, 0);\n const result = new Uint8Array(totalLength);\n\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n\n return result;\n}\n\nfunction hexToUint8Array(hex: string): Uint8Array {\n const sanitisedHex = BigInt(hex).toString(16).padStart(64, \"0\");\n\n const len = sanitisedHex.length / 2;\n const u8 = new Uint8Array(len);\n\n let i = 0;\n let j = 0;\n while (i < len) {\n u8[i] = parseInt(sanitisedHex.slice(j, j + 2), 16);\n i += 1;\n j += 2;\n }\n\n return u8;\n}\n\n/**\n * Generates the prover data required for the Noir circuit.\n *\n * @param id - The user's identity string\n * @param pwd - The hashed password as a Uint8Array\n * @param stored_hash - The stored hash as a Uint8Array\n * @param tx - The transaction hash string\n * @returns An object containing the prover data\n */\nconst generateProverData = (\n id: string,\n pwd: Uint8Array,\n stored_hash: Uint8Array,\n tx: string,\n blob_index: number,\n tx_blob_count: number,\n): InputMap => {\n const version = 1;\n const initial_state = [0, 0, 0, 0];\n const initial_state_len = initial_state.length;\n const next_state = [0, 0, 0, 0];\n const next_state_len = next_state.length;\n const identity_len = id.length;\n const identity = id.padEnd(256, \"0\");\n const tx_hash = tx.padEnd(64, \"0\");\n const tx_hash_len = tx_hash.length;\n const index = blob_index;\n const blob_number = 1;\n const blob_contract_name_len = \"check_secret\".length;\n const blob_contract_name = \"check_secret\".padEnd(256, \"0\");\n const blob_capacity = 32;\n const blob_len = 32;\n const blob: number[] = Array.from(stored_hash);\n const success = 1;\n const password: number[] = Array.from(pwd);\n assert(password.length == 32, \"Password length is not 32 bytes\");\n assert(blob.length == blob_len, \"Blob length is not 32 bytes\");\n\n return {\n version,\n initial_state,\n initial_state_len,\n next_state,\n next_state_len,\n identity,\n identity_len,\n tx_hash,\n tx_hash_len,\n index,\n blob_number,\n blob_index,\n blob_contract_name_len,\n blob_contract_name,\n blob_capacity,\n blob_len,\n blob,\n tx_blob_count,\n success,\n password,\n };\n};\n"],"names":["base64Decode","input","c","defaultForeignCallHandler","name","args","parseErrorPayload","abi","originalError","payload","enrichedError","decodedPayload","abiDecodeError","generateWitness","compiledProgram","inputs","foreignCallHandler","witnessMap","abiEncode","executeProgram","err","Noir","circuit","__publicField","initAbi","initACVM","witness_stack","main_witness","returnValue","abiDecode","compressWitnessStack","hash_password","password","sha256","stringToBytes","identity_hash","identity","hashed_password_bytes","id_prefix","extended_id","computed_hash","build_blob","stored_hash","build_proof_transaction","tx_hash","blob_index","tx_blob_count","defaultCircuit","noir","backend","UltraHonkBackend","vk","witness","generateProverData","proof","reconstructedProof","reconstructHonkProof","flattenFieldsAsArray","register_contract","node","assert","condition","message","data","hashBuffer","encodeToHex","byte","fields","flattenedPublicInputs","hexToUint8Array","flattenUint8Arrays","arrays","totalLength","acc","val","result","offset","arr","hex","sanitisedHex","len","u8","i","j","id","pwd","tx","initial_state","initial_state_len","next_state","next_state_len","identity_len","tx_hash_len","index","blob_number","blob_contract_name_len","blob_contract_name","blob_capacity","blob_len","blob","success"],"mappings":";;;;;;AAEO,SAASA,EAAaC,GAAO;AAChC,MAAI,OAAO,SAAW;AAElB,WAAO,OAAO,KAAKA,GAAO,QAAQ;AAEjC,MAAI,OAAO,QAAS;AAErB,WAAO,WAAW,KAAK,KAAKA,CAAK,GAAG,CAACC,MAAMA,EAAE,WAAW,CAAC,CAAC;AAG1D,QAAM,IAAI,MAAM,8CAA8C;AAEtE;ACXA,MAAMC,IAA4B,OAAOC,GAAMC,MAAS;AACpD,MAAID,KAAQ;AAKR,WAAO,CAAE;AAEb,QAAM,MAAM,uCAAuCA,CAAI,IAAIC,EAAK,KAAK,IAAI,CAAC,GAAG;AACjF;AACA,SAASC,EAAkBC,GAAKC,GAAe;AAC3C,QAAMC,IAAUD,EAAc;AAC9B,MAAI,CAACC;AACD,WAAOD;AACX,QAAME,IAAgBF;AACtB,MAAI;AAEA,UAAMG,IAAiBC,EAAeL,GAAKE,CAAO;AAClD,IAAI,OAAOE,KAAmB,WAE1BD,EAAc,UAAU,6BAA6BC,CAAc,KAInED,EAAc,0BAA0BC;AAAA,EAEpD,QAC2B;AAAA,EAE3B;AACI,SAAOD;AACX;AAEO,eAAeG,EAAgBC,GAAiBC,GAAQC,IAAqBb,GAA2B;AAE3G,QAAMc,IAAaC,EAAUJ,EAAgB,KAAKC,CAAM;AAGxD,MAAI;AAEA,WADsB,MAAMI,EAAenB,EAAac,EAAgB,QAAQ,GAAGG,GAAYD,CAAkB;AAAA,EAEzH,SACWI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AC5CD,KAAA,GACAC,KAAA;AAGA,SAAAF;AACT;AAWA,MAAM5B,KAAqB,CACzB+B,GACAC,GACA3C,GACA4C,GACAzC,GACAC,MACa;AAEb,QAAMyC,IAAgB,CAAC,GAAG,GAAG,GAAG,CAAC,GAC3BC,IAAoBD,EAAc,QAClCE,IAAa,CAAC,GAAG,GAAG,GAAG,CAAC,GACxBC,IAAiBD,EAAW,QAC5BE,IAAeP,EAAG,QAClBhD,IAAWgD,EAAG,OAAO,KAAK,GAAG,GAC7BxC,IAAU0C,EAAG,OAAO,IAAI,GAAG,GAC3BM,IAAchD,EAAQ,QACtBiD,IAAQhD,GACRiD,IAAc,GACdC,IAAyB,IACzBC,IAAqB,eAAe,OAAO,KAAK,GAAG,GACnDC,IAAgB,IAChBC,IAAW,IACXC,IAAiB,MAAM,KAAKzD,CAAW,GACvC0D,IAAU,GACVpE,IAAqB,MAAM,KAAKqD,CAAG;AAClC,SAAAzB,EAAA5B,EAAS,UAAU,IAAI,iCAAiC,GACxD4B,EAAAuC,EAAK,UAAUD,GAAU,6BAA6B,GAEtD;AAAA,IACL;AAAA,IACA,eAAAX;AAAA,IACA,mBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,UAAAtD;AAAA,IACA,cAAAuD;AAAA,IACA,SAAA/C;AAAA,IACA,aAAAgD;AAAA,IACA,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,YAAAjD;AAAA,IACA,wBAAAkD;AAAA,IACA,oBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,MAAAC;AAAA,IACA,eAAArD;AAAA,IACA,SAAAsD;AAAA,IACA,UAAApE;AAAA,EACF;AACF;;;;;;;;;;;;;","x_google_ignoreList":[0,1,2]}
|
|
1
|
+
{"version":3,"file":"hyli-noir.es.js","sources":["../node_modules/@noir-lang/noir_js/lib/base64_decode.mjs","../node_modules/@noir-lang/noir_js/lib/witness_generation.mjs","../node_modules/@noir-lang/noir_js/lib/program.mjs","../src/check_secret.ts"],"sourcesContent":["// Since this is a simple function, we can use feature detection to\n// see if we are in the nodeJs environment or the browser environment.\nexport function base64Decode(input) {\n if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(input, 'base64');\n }\n else if (typeof atob === 'function') {\n // Browser environment\n return Uint8Array.from(atob(input), (c) => c.charCodeAt(0));\n }\n else {\n throw new Error('No implementation found for base64 decoding.');\n }\n}\n","import { abiDecodeError, abiEncode } from '@noir-lang/noirc_abi';\nimport { base64Decode } from \"./base64_decode.mjs\";\nimport { executeProgram } from '@noir-lang/acvm_js';\nconst defaultForeignCallHandler = async (name, args) => {\n if (name == 'print') {\n // By default we do not print anything for `print` foreign calls due to a need for formatting,\n // however we provide an empty response in order to not halt execution.\n //\n // If a user needs to print values then they should provide a custom foreign call handler.\n return [];\n }\n throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);\n};\nfunction parseErrorPayload(abi, originalError) {\n const payload = originalError.rawAssertionPayload;\n if (!payload)\n return originalError;\n const enrichedError = originalError;\n try {\n // Decode the payload\n const decodedPayload = abiDecodeError(abi, payload);\n if (typeof decodedPayload === 'string') {\n // If it's a string, just add it to the error message\n enrichedError.message = `Circuit execution failed: ${decodedPayload}`;\n }\n else {\n // If not, attach the payload to the original error\n enrichedError.decodedAssertionPayload = decodedPayload;\n }\n }\n catch (_errorDecoding) {\n // Ignore errors decoding the payload\n }\n return enrichedError;\n}\n// Generates the witnesses needed to feed into the chosen proving system\nexport async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {\n // Throws on ABI encoding error\n const witnessMap = abiEncode(compiledProgram.abi, inputs);\n // Execute the circuit to generate the rest of the witnesses and serialize\n // them into a Uint8Array.\n try {\n const solvedWitness = await executeProgram(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler);\n return solvedWitness;\n }\n catch (err) {\n // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.\n if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {\n throw parseErrorPayload(compiledProgram.abi, err);\n }\n throw new Error(`Circuit execution failed: ${err}`);\n }\n}\n","import { generateWitness } from \"./witness_generation.mjs\";\nimport initAbi, { abiDecode } from '@noir-lang/noirc_abi';\nimport initACVM, { compressWitnessStack } from '@noir-lang/acvm_js';\nexport class Noir {\n circuit;\n constructor(circuit) {\n this.circuit = circuit;\n }\n /** @ignore */\n async init() {\n // If these are available, then we are in the\n // web environment. For the node environment, this\n // is a no-op.\n if (typeof initAbi === 'function') {\n await Promise.all([initAbi(), initACVM()]);\n }\n }\n /**\n * @description\n * Allows to execute a circuit to get its witness and return value.\n *\n * @example\n * ```typescript\n * async execute(inputs)\n * ```\n */\n async execute(inputs, foreignCallHandler) {\n await this.init();\n const witness_stack = await generateWitness(this.circuit, inputs, foreignCallHandler);\n const main_witness = witness_stack[0].witness;\n const { return_value: returnValue } = abiDecode(this.circuit.abi, main_witness);\n return { witness: compressWitnessStack(witness_stack), returnValue };\n }\n}\n","import { Noir } from \"@noir-lang/noir_js\";\nimport { reconstructHonkProof, UltraHonkBackend } from \"@aztec/bb.js\";\nimport { CompiledCircuit, InputMap } from \"@noir-lang/types\";\nimport { Blob, ProofTransaction, NodeApiHttpClient } from \"hyli\";\n\n/**\n * Hashes a password using SHA-256.\n * The password is converted to a Uint8Array and hashed using SHA-256.\n * The resulting hash is returned as a Uint8Array.\n *\n * @param password - The password string to hash\n * @returns A Promise resolving to the Uint8Array of the computed hash\n */\nexport const hash_password = async (password: string): Promise<Uint8Array> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n return hashed_password_bytes;\n};\n\n/**\n * Hashes an identity and password together using SHA-256.\n * The identity is concatenated with ':' and the hashed password.\n * The resulting combined value is hashed again using SHA-256.\n * The resulting hash is returned as a hexadecimal string that can be \n * stored publicly.\n * \n * This function is mainly used to check the given password against a stored hash.\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @returns A Promise resolving to the hexadecimal string of the computed hash\n */\nexport const identity_hash = async (identity: string, password: string): Promise<string> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const computed_hash = await sha256(extended_id);\n const computed_hash_hex = Buffer.from(computed_hash).toString(\"hex\");\n return computed_hash_hex;\n};\n\n/**\n * Builds a blob transaction containing a secret derived from an identity and password.\n * The secret is constructed by:\n * 1. Hashing the password in order to have a fixed-size secret\n * 2. Concatenating the padded identity (to 64 chars) with ':' and the hashed password\n * 3. Hashing this combined value\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @returns A Promise resolving to a BlobTransaction containing the hashed secret\n */\nexport const build_blob = async (identity: string, password: string): Promise<Blob> => {\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const secretBlob: Blob = {\n contract_name: \"check_secret\",\n data: Array.from(stored_hash),\n };\n\n return secretBlob;\n};\n\nimport defaultCircuit from \"../check-secret/target/check_secret.json\";\n\n/**\n * Builds a proof transaction by generating a zero-knowledge proof for checking a secret.\n * The proof demonstrates knowledge of a password that, when combined with an identity and hashed,\n * matches a stored hash value. The process involves:\n * 1. Hashing the password and combining it with the identity\n * 2. Generating a witness and proof using the UltraHonk backend\n * 3. Reconstructing and formatting the proof for the transaction\n *\n * @param identity - The user's identity string\n * @param password - The user's password string\n * @param tx_hash - The blob transaction hash string\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise resolving to a ProofTransaction containing the generated proof\n */\nexport const build_proof_transaction = async (\n identity: string,\n password: string,\n tx_hash: string,\n blob_index: number,\n tx_blob_count: number,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<ProofTransaction> => {\n const noir = new Noir(circuit);\n const backend = new UltraHonkBackend(circuit.bytecode);\n const vk = await backend.getVerificationKey();\n\n const hashed_password_bytes = await sha256(stringToBytes(password));\n let encoder = new TextEncoder();\n let id_prefix = encoder.encode(`${identity}:`);\n let extended_id = new Uint8Array([...id_prefix, ...hashed_password_bytes]);\n const stored_hash = await sha256(extended_id);\n\n const { witness } = await noir.execute(\n generateProverData(identity, hashed_password_bytes, stored_hash, tx_hash, blob_index, tx_blob_count),\n );\n\n const proof = await backend.generateProof(witness);\n const reconstructedProof = reconstructHonkProof(flattenFieldsAsArray(proof.publicInputs), proof.proof);\n\n return {\n contract_name: \"check_secret\",\n program_id: Array.from(vk),\n verifier: \"noir\",\n proof: Array.from(reconstructedProof),\n };\n};\n\n/**\n * Registers the Noir contract with the node if it is not already registered.\n * The contract is identified by its name \"check_secret\".\n * If the contract is not found, it registers the contract using the provided circuit.\n *\n * @param node - The NodeApiHttpClient instance to interact with the NodeApiHttpClient\n * @param circuit - The compiled Noir circuit (defaults to the check_secret circuit)\n * @returns A Promise that resolves when the contract is registered\n */\nexport const register_contract = async (\n node: NodeApiHttpClient,\n circuit: CompiledCircuit = defaultCircuit as CompiledCircuit,\n): Promise<void> => {\n await node.getContract(\"check_secret\").catch(async () => {\n const backend = new UltraHonkBackend(circuit.bytecode);\n\n const vk = await backend.getVerificationKey();\n\n await node.registerContract({\n verifier: \"noir\",\n program_id: Array.from(vk),\n state_commitment: [0, 0, 0, 0],\n contract_name: \"check_secret\",\n });\n });\n};\n\n// ---- Utility functions ----\n\nexport const assert = (condition: boolean, message: string): void => {\n if (!condition) {\n throw new Error(message);\n }\n};\n\nexport const sha256 = async (data: Uint8Array): Promise<Uint8Array> => {\n const hashBuffer = await crypto.subtle.digest(\"SHA-256\", data);\n return new Uint8Array(hashBuffer);\n};\n\nexport const stringToBytes = (input: string): Uint8Array => {\n return new TextEncoder().encode(input);\n};\n\nexport const encodeToHex = (data: Uint8Array): string => {\n return Array.from(data)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n};\n\nexport function flattenFieldsAsArray(fields: string[]): Uint8Array {\n const flattenedPublicInputs = fields.map(hexToUint8Array);\n return flattenUint8Arrays(flattenedPublicInputs);\n}\n\nfunction flattenUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((acc, val) => acc + val.length, 0);\n const result = new Uint8Array(totalLength);\n\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n\n return result;\n}\n\nfunction hexToUint8Array(hex: string): Uint8Array {\n const sanitisedHex = BigInt(hex).toString(16).padStart(64, \"0\");\n\n const len = sanitisedHex.length / 2;\n const u8 = new Uint8Array(len);\n\n let i = 0;\n let j = 0;\n while (i < len) {\n u8[i] = parseInt(sanitisedHex.slice(j, j + 2), 16);\n i += 1;\n j += 2;\n }\n\n return u8;\n}\n\n/**\n * Generates the prover data required for the Noir circuit.\n *\n * @param id - The user's identity string\n * @param pwd - The hashed password as a Uint8Array\n * @param stored_hash - The stored hash as a Uint8Array\n * @param tx - The transaction hash string\n * @returns An object containing the prover data\n */\nconst generateProverData = (\n id: string,\n pwd: Uint8Array,\n stored_hash: Uint8Array,\n tx: string,\n blob_index: number,\n tx_blob_count: number,\n): InputMap => {\n const version = 1;\n const initial_state = [0, 0, 0, 0];\n const initial_state_len = initial_state.length;\n const next_state = [0, 0, 0, 0];\n const next_state_len = next_state.length;\n const identity_len = id.length;\n const identity = id.padEnd(256, \"0\");\n const tx_hash = tx.padEnd(64, \"0\");\n const tx_hash_len = tx_hash.length;\n const index = blob_index;\n const blob_number = 1;\n const blob_contract_name_len = \"check_secret\".length;\n const blob_contract_name = \"check_secret\".padEnd(256, \"0\");\n const blob_capacity = 32;\n const blob_len = 32;\n const blob: number[] = Array.from(stored_hash);\n const success = 1;\n const password: number[] = Array.from(pwd);\n assert(password.length == 32, \"Password length is not 32 bytes\");\n assert(blob.length == blob_len, \"Blob length is not 32 bytes\");\n\n return {\n version,\n initial_state,\n initial_state_len,\n next_state,\n next_state_len,\n identity,\n identity_len,\n tx_hash,\n tx_hash_len,\n index,\n blob_number,\n blob_index,\n blob_contract_name_len,\n blob_contract_name,\n blob_capacity,\n blob_len,\n blob,\n tx_blob_count,\n success,\n password,\n };\n};\n"],"names":["base64Decode","input","c","defaultForeignCallHandler","name","args","parseErrorPayload","abi","originalError","payload","enrichedError","decodedPayload","abiDecodeError","generateWitness","compiledProgram","inputs","foreignCallHandler","witnessMap","abiEncode","executeProgram","err","Noir","circuit","__publicField","initAbi","initACVM","witness_stack","main_witness","returnValue","abiDecode","compressWitnessStack","hash_password","password","sha256","stringToBytes","identity_hash","identity","hashed_password_bytes","id_prefix","extended_id","computed_hash","build_blob","stored_hash","build_proof_transaction","tx_hash","blob_index","tx_blob_count","defaultCircuit","noir","backend","UltraHonkBackend","vk","witness","generateProverData","proof","reconstructedProof","reconstructHonkProof","flattenFieldsAsArray","register_contract","node","assert","condition","message","data","hashBuffer","encodeToHex","byte","fields","flattenedPublicInputs","hexToUint8Array","flattenUint8Arrays","arrays","totalLength","acc","val","result","offset","arr","hex","sanitisedHex","len","u8","i","j","id","pwd","tx","initial_state","initial_state_len","next_state","next_state_len","identity_len","tx_hash_len","index","blob_number","blob_contract_name_len","blob_contract_name","blob_capacity","blob_len","blob","success"],"mappings":";;;;;;AAEO,SAASA,EAAaC,GAAO;AAChC,MAAI,OAAO,SAAW;AAElB,WAAO,OAAO,KAAKA,GAAO,QAAQ;AAEjC,MAAI,OAAO,QAAS;AAErB,WAAO,WAAW,KAAK,KAAKA,CAAK,GAAG,CAACC,MAAMA,EAAE,WAAW,CAAC,CAAC;AAG1D,QAAM,IAAI,MAAM,8CAA8C;AAEtE;ACXA,MAAMC,IAA4B,OAAOC,GAAMC,MAAS;AACpD,MAAID,KAAQ;AAKR,WAAO,CAAE;AAEb,QAAM,MAAM,uCAAuCA,CAAI,IAAIC,EAAK,KAAK,IAAI,CAAC,GAAG;AACjF;AACA,SAASC,EAAkBC,GAAKC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AAC;AAAA,IACA,UAAAtD;AAAA,IACA,cAAAuD;AAAA,IACA,SAAA/C;AAAA,IACA,aAAAgD;AAAA,IACA,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,YAAAjD;AAAA,IACA,wBAAAkD;AAAA,IACA,oBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,MAAAC;AAAA,IACA,eAAArD;AAAA,IACA,SAAAsD;AAAA,IACA,UAAApE;AAAA,EACF;AACF;;;;;;;;;;;;;","x_google_ignoreList":[0,1,2]}
|
package/package.json
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
"url": "https://github.com/hyli-org/hyli-noir.git"
|
|
7
7
|
},
|
|
8
8
|
"bugs": {
|
|
9
|
-
"url": "https://github.com/hyli-org/
|
|
9
|
+
"url": "https://github.com/hyli-org/hyli-noir/issues"
|
|
10
10
|
},
|
|
11
11
|
"author": "Hyli",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"version": "0.0
|
|
13
|
+
"version": "0.1.0",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "dist/hyli-noir.cjs.js",
|
|
16
16
|
"module": "dist/hyli-noir.es.js",
|