UNPKG

@antefinance/ante-sdk

Version:

Library for interacting with Ante smart contracts

31 lines (30 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZupassGate = void 0; const util_1 = require("@pcd/util"); const zupass_1 = require("../utils/zupass"); const viem_1 = require("viem"); const buildConfiguration = (manager, events) => { const uintEvents = events.map(util_1.uuidToBigInt); return (0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'bytes' }], [ (0, viem_1.getAddress)(manager), (0, viem_1.encodeAbiParameters)([{ type: 'uint256[]' }], [uintEvents]), ]); }; const getProof = async (events, proofInput) => { const { serializedPCDStr, watermark, externalNullifier } = proofInput; const pcd = await (0, zupass_1.pcdFromSerializedPcdString)(serializedPCDStr); const proofVerification = await (0, zupass_1.verifyZupassProof)(pcd, BigInt(watermark), externalNullifier, events); if (!proofVerification) { return Promise.reject(new Error('Proof verification failed, invalid proof input')); } const witness = (0, zupass_1.generateWitness)(pcd); if (!(await (0, zupass_1.verifyWitnessSignature)(witness))) { return Promise.reject(new Error('Proof verification failed, invalid witness signature')); } return (0, zupass_1.abiEncodeProof)(witness); }; exports.ZupassGate = { buildConfiguration, getProof, };