-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
826ad35
commit bfa246b
Showing
10 changed files
with
305 additions
and
163 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { keccak256 } from 'ethers'; | ||
import { byteEncoder, hexToBytes, isEthereumIdentity } from '../../utils'; | ||
import { CircuitId } from '../../circuits'; | ||
import { Hex } from '@iden3/js-crypto'; | ||
import { DID } from '@iden3/js-iden3-core'; | ||
import { IProofService } from '../../proof'; | ||
import { ZeroKnowledgeProofResponse } from '../types'; | ||
|
||
/** | ||
* Retrieves the AuthV2 request ID. | ||
* | ||
* @returns The AuthV2 request ID. | ||
*/ | ||
export function getAuthV2RequestId(): number { | ||
const circuitHash = keccak256(byteEncoder.encode(CircuitId.AuthV2)); | ||
const dataView = new DataView(Hex.decodeString(circuitHash.replace('0x', '')).buffer); | ||
const id = dataView.getUint32(0); | ||
return id; | ||
} | ||
|
||
|
||
/** | ||
* Prepares the zero-knowledge proof response for the AuthV2 circuit. | ||
* @param address - The address associated with the request. | ||
* @param senderDid - The sender's decentralized identifier (DID). | ||
* @param proofService - The proof service used to generate the proof. | ||
* @returns A promise that resolves to an array of ZeroKnowledgeProofResponse objects. | ||
*/ | ||
export async function prepareAuthV2ZeroKnowledgeResponse( | ||
address: string, | ||
senderDid: DID, | ||
proofService: IProofService | ||
): Promise<ZeroKnowledgeProofResponse[]> { | ||
const circuitId = CircuitId.AuthV2; | ||
const id = getAuthV2RequestId(); | ||
|
||
if (isEthereumIdentity(senderDid)) { | ||
return [ | ||
{ | ||
circuitId, | ||
id, | ||
pub_signals: [], | ||
proof: { | ||
pi_a: [], | ||
pi_b: [], | ||
pi_c: [], | ||
protocol: 'groth16' | ||
} | ||
} | ||
]; | ||
} | ||
const hash = Uint8Array.from([...hexToBytes(address), ...new Uint8Array(12)]).reverse(); | ||
const authInputs = await proofService.generateAuthV2Inputs(hash, senderDid, CircuitId.AuthV2); | ||
|
||
const prover = proofService.getProver(); | ||
|
||
const { proof, pub_signals } = await prover.generate(authInputs, CircuitId.AuthV2); | ||
|
||
return [ | ||
{ | ||
circuitId, | ||
id, | ||
pub_signals, | ||
proof | ||
} | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './envelope'; | ||
export * from './message'; | ||
export * from './did'; | ||
export * from './contract-request.utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.