diff --git a/askeladd-dvm-marketplace/src/app/components/description/index.tsx b/askeladd-dvm-marketplace/src/app/components/description/index.tsx index 18d0838..4a48029 100644 --- a/askeladd-dvm-marketplace/src/app/components/description/index.tsx +++ b/askeladd-dvm-marketplace/src/app/components/description/index.tsx @@ -4,7 +4,6 @@ export const HowItWork = () => { const [openHowItWork, setOpenHowItWork] = useState(false); - return(
setOpenHowItWork(!openHowItWork)} className="max-w-sm cursor-pointer my-5 p-1 m-1 whitespace-pre-line break-words" diff --git a/askeladd-dvm-marketplace/src/app/config-marketplace/page.tsx b/askeladd-dvm-marketplace/src/app/config-marketplace/page.tsx index 0d7a51e..e583879 100644 --- a/askeladd-dvm-marketplace/src/app/config-marketplace/page.tsx +++ b/askeladd-dvm-marketplace/src/app/config-marketplace/page.tsx @@ -10,7 +10,6 @@ import { ASKELADD_KINDS, ConfigHandle } from "@/types"; import EventCard from "../components/EventCard"; import { generateContentAndTags } from "../utils/generateAppHandler"; import { HowItWork } from "../components/description"; - export default function Home() { const [publicKey, setPublicKey] = useState(); const [appKind, setAppKind] = useState(ASKELADD_KINDS.KIND_JOB_REQUEST) @@ -28,7 +27,6 @@ export default function Home() { const [isAdmin, setIsAdmin] = useState(false); const [timestampJob, setTimestampJob] = useState(); const { fetchEvents, fetchEventsTools, setupSubscriptionNostr } = useFetchEvents() - const { sendNote, publishNote } = useSendNote() useEffect(() => { if (isNeedLoadEvents || !isInitialized) { @@ -60,7 +58,6 @@ export default function Home() { setIsNeedLoadEvents(false) } - /** Connect you */ const connectExtension = async () => { try { @@ -109,7 +106,6 @@ export default function Home() { setError(undefined); setTimestampJob(new Date().getTime()) - /** Use Nostr extension to send event */ const pool = new SimplePool(); let pubkey; if (typeof window !== "undefined" && window.nostr) { @@ -130,7 +126,6 @@ export default function Home() { content: content }) // takes an event object, adds `id`, `pubkey` and `sig` and returns it // Setup job request to fetch job id - // let eventID = await relay.publish(event as EventNostr); const eventID = await Promise.any(pool.publish(ASKELADD_RELAY, event as EventNostr)); console.log("eventID", eventID[0]) diff --git a/askeladd-dvm-marketplace/src/app/launch-program/page.tsx b/askeladd-dvm-marketplace/src/app/launch-program/page.tsx index 3077a99..2534d9d 100644 --- a/askeladd-dvm-marketplace/src/app/launch-program/page.tsx +++ b/askeladd-dvm-marketplace/src/app/launch-program/page.tsx @@ -4,14 +4,10 @@ import { useState, useEffect, useMemo } from "react"; import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { useSendNote } from "@/hooks/useSendNote"; import { useFetchEvents } from "@/hooks/useFetchEvents"; -import { APPLICATION_PUBKEY_DVM, ASKELADD_RELAY } from "@/constants/relay"; +import { ASKELADD_RELAY } from "@/constants/relay"; import { Event as EventNostr, SimplePool } from "nostr-tools"; import { ASKELADD_KINDS, ConfigHandle, ContractUploadType, IGenerateZKPRequestDVM, IProgramParams, KIND_JOB_ADD_PROGRAM } from "@/types"; -import EventCard from "../components/EventCard"; -import { generateContentAndTags } from "../utils/generateAppHandler"; import { HowItWork } from "../components/description"; -import { PROGRAM_INTERAL_REQUEST } from "@/constants/program"; - export default function LaunchProgram() { const [publicKey, setPublicKey] = useState(); const [appKind, setAppKind] = useState(ASKELADD_KINDS.KIND_JOB_REQUEST) @@ -30,7 +26,6 @@ export default function LaunchProgram() { const [timestampJob, setTimestampJob] = useState(); const { fetchEvents, fetchEventsTools, setupSubscriptionNostr } = useFetchEvents() const { sendNote, publishNote } = useSendNote() - const [logSize, setLogSize] = useState(5); const [claim, setClaim] = useState(443693538); const [inputIndex, setInputsIndex] = useState(0) const [isOpenForm, setIsOpenForm] = useState(false) @@ -178,20 +173,6 @@ export default function LaunchProgram() { }; - const mockProgram = async () => { - /** Todo better check */ - if (!isLoading && !isOpenForm && Object.entries(form).length == 0) return; - setIsLoading(true); - setJobId(undefined) - setProofStatus("pending"); - setError(undefined); - const tags = [ - ['param', 'log_size', logSize.toString()], - ['param', 'claim', claim.toString()], - ['output', 'text/json'] - ]; - - } const submitProgram = async () => { try { setIsLoading(true); @@ -199,7 +180,6 @@ export default function LaunchProgram() { setLastConfig(undefined); setError(undefined); console.log("formEncrypted", formEncrypted) - let tags: string[][] = [] const inputs: Map = new Map(); { @@ -236,20 +216,13 @@ export default function LaunchProgram() { } const content = JSON.stringify({ - // request: form as any, - // request: form, request: Object.fromEntries(inputs), program: { contract_name: programParam?.contract_name ?? "test", - // internal_contract_name: programParam?.internal_contract_name ?? "test", contract_reached: programParam?.contract_reached ?? ContractUploadType.Ipfs, inputs: Object.fromEntries(inputs), - // inputs_types: Object.fromEntries(inputs), - // inputs_encrypted: Object.fromEntries(inputs_encrypted), - // tags: tags } }) - console.log("tags", tags) console.log("content", content) setTimestampJob(new Date().getTime()) @@ -272,7 +245,6 @@ export default function LaunchProgram() { content: content }) // takes an event object, adds `id`, `pubkey` and `sig` and returns it // // Setup job request to fetch job id - // // let eventID = await relay.publish(event as EventNostr); const eventID = await Promise.any(pool.publish(ASKELADD_RELAY, event as EventNostr)); console.log("eventID", eventID[0]) @@ -307,13 +279,13 @@ export default function LaunchProgram() { } - const handleAllInputsEncrypted = () => { - Object.entries(form).map(([key, value]) => { - setFormEncrypted({ ...formEncrypted, [value as string]: true }) - } - ) + // const handleAllInputsEncrypted = () => { + // Object.entries(form).map(([key, value]) => { + // setFormEncrypted({ ...formEncrypted, [value as string]: true }) + // } + // ) - } + // } return (
@@ -327,8 +299,6 @@ export default function LaunchProgram() { > {isLoading ? "PROCESSING..." : "CONNECT"} - -

Askeladd DVM

Launch program

@@ -372,7 +342,6 @@ export default function LaunchProgram() { }}>X
-
) })} @@ -389,7 +358,6 @@ export default function LaunchProgram() {

Inputs encrypted

- {formEncrypted && Object.entries(formEncrypted).map(([key, value], i) => { return ( @@ -449,13 +417,7 @@ export default function LaunchProgram() {
{isLoading &&
} - {/* */} - {/* */} - {/* */} - +
diff --git a/askeladd-dvm-marketplace/src/app/page.tsx b/askeladd-dvm-marketplace/src/app/page.tsx index b7b5e84..f927f3b 100644 --- a/askeladd-dvm-marketplace/src/app/page.tsx +++ b/askeladd-dvm-marketplace/src/app/page.tsx @@ -1,21 +1,14 @@ "use client"; import { useState, useEffect, useMemo } from "react"; -import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; -import { useNostrContext } from "@/context/NostrContext"; -import { useSendNote } from "@/hooks/useSendNote"; -import { ContractUploadType, JobResultProver, KIND_JOB_REQUEST, KIND_JOB_RESULT, ProgramInternalContractName } from "@/types"; -import init, { verify_stark_proof, prove_and_verify, prove_and_verify_fib, verify_stark_proof_fib, stark_proof_wide_fibo, verify_stark_proof_wide_fibo } from "../pkg/stwo_wasm"; -import { useFetchEvents } from "@/hooks/useFetchEvents"; -import { ASKELADD_RELAY } from "@/constants/relay"; -import { Relay } from 'nostr-tools/relay'; -import { Event as EventNostr, SimplePool } from "nostr-tools"; +import { NDKEvent } from '@nostr-dev-kit/ndk'; +import { ContractUploadType, ProgramInternalContractName } from "@/types"; +import init, { stark_proof_wide_fibo, verify_stark_proof_wide_fibo } from "../pkg/stwo_wasm"; +import { Event as EventNostr } from "nostr-tools"; import { useDVMState } from "@/hooks/useDVMState"; -import { useSubmitJob } from "@/hooks/useSubmitJob"; export default function Home() { const [log_n_instances, setLogNInstances] = useState(0); const [log_fibonacci_size, setLogFibonacciSize] = useState(5); - const [publicKey, setPublicKey] = useState(); const [error, setError] = useState() const [jobEventResult, setJobEventResult] = useState() const [proofStatus, setProofStatus] = useState< @@ -24,9 +17,10 @@ export default function Home() { const [isLoading, setIsLoading] = useState(false); const [isInitialized, setIsInitialized] = useState(false); const [isFetchJob, setIsFetchJob] = useState(false); - const { eventIdRequest, jobId, setJobId, setIsWaitingJob, fetchJobRequest, proof, fetchEventsProof, + const { eventIdRequest, jobId, setJobId, setIsWaitingJob, fetchJobRequest, proof, fetchEventsProof, starkProof, - submitJob: submitJobModular, } = useDVMState() + submitJob: submitJobModular, + publicKey } = useDVMState() // Init wasm module to run_fibonacci_verify useEffect(() => { init() @@ -104,7 +98,7 @@ export default function Home() { } } - let res= await submitJobModular(5600, { + let res = await submitJobModular(5600, { log_n_instances, log_fibonacci_size }, @@ -116,8 +110,6 @@ export default function Home() { waitingForJobResult() timeoutWaitingForJobResult() - - } catch (e) { } finally { setIsLoading(false); @@ -131,7 +123,6 @@ export default function Home() { setIsLoading(true); /** Change Wide fibo to default */ const serialised_proof_from_nostr_event = JSON.stringify(starkProof); - if (!log_n_instances && !log_fibonacci_size && !serialised_proof_from_nostr_event) return; const prove_result = stark_proof_wide_fibo(Number(log_fibonacci_size), Number(log_n_instances)); console.log("wide fibo prove_result", prove_result); @@ -169,9 +160,8 @@ export default function Home() {

Censorship resistant global proving network

Verifiable computation for DVMs

- {/*

Prove poseidon

*/} -

Wide cci

+

Wide Fibonacci

- -
- - {/*
- - setClaim(Number(e.target.value))} - className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2" - /> -
*/} - - - {/*
- - setLogSize(Number(e.target.value))} - className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2" - /> -
- -
- - setClaim(Number(e.target.value))} - className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2" - /> -
*/} -
{isLoading &&
} - {jobId && (

Job ID: {jobId}

diff --git a/askeladd-dvm-marketplace/src/app/stwo-program/page.tsx b/askeladd-dvm-marketplace/src/app/stwo-program/page.tsx index bf99221..1a484a6 100644 --- a/askeladd-dvm-marketplace/src/app/stwo-program/page.tsx +++ b/askeladd-dvm-marketplace/src/app/stwo-program/page.tsx @@ -1,58 +1,22 @@ "use client"; -import { useState, useEffect, useMemo } from "react"; -import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; -import { useNostrContext } from "@/context/NostrContext"; -import { useSendNote } from "@/hooks/useSendNote"; -import { ContractUploadType, IGenerateZKPRequestDVM, JobResultProver, KIND_JOB_ADD_PROGRAM, KIND_JOB_REQUEST, KIND_JOB_RESULT, ProgramInternalContractName } from "@/types"; -import init, { verify_stark_proof, prove_and_verify } from "../../pkg/stwo_wasm"; -import { useFetchEvents } from "@/hooks/useFetchEvents"; -import { ASKELADD_RELAY } from "@/constants/relay"; -import { Relay } from 'nostr-tools/relay'; -import { Event as EventNostr, SimplePool } from "nostr-tools"; +import { useState, useEffect } from "react"; +import { IGenerateZKPRequestDVM } from "@/types"; import { PROGRAM_INTERAL_REQUEST } from "@/constants/program"; import ProgramCard from "../components/ProgramCard"; import InternalProgram from "../components/InternalProgram"; import { useDVMState } from "@/hooks/useDVMState"; export default function StwoProgramMarketplace() { - const [jobEventResult, setJobEventResult] = useState() - const [events, setEvents] = useState([]) const [isLoading, setIsLoading] = useState(false); - const [isInitialized, setIsInitialized] = useState(false); const [isFetchJob, setIsFetchJob] = useState(false); - const [isLoadingJobResult, setIsLoadingJobResult] = useState(false); - const [isWaitingJob, setIsWaitingJob] = useState(false); - - const [internalProgram, setInternalProgram] = useState(PROGRAM_INTERAL_REQUEST) - - const { ndk, pool } = useNostrContext() - const { fetchEvents, fetchEventsTools, setupSubscriptionNostr } = useFetchEvents() - const {fetchEventsProof, jobId} = useDVMState() - const { sendNote, publishNote } = useSendNote() - - // Init wasm module to run_fibonacci_verify - useEffect(() => { - init() - .then(() => setIsInitialized(true)) - .catch((error) => { - console.error("Failed to initialize WASM module:", error); - - }); - }, []); - + const [internalsPrograms, setInternalPrograms] = useState(PROGRAM_INTERAL_REQUEST) + const {fetchEventsProof, jobId, jobEventResult, fetchPrograms, events, eventsPrograms} = useDVMState() /** Effect to fetch the job result when a job request is sent */ const waitingForJobResult = async () => { if (jobEventResult && jobId) return; if(!jobId) return; fetchEventsProof() setIsLoading(false); - setIsWaitingJob(false) - } - const timeoutWaitingForJobResult = async () => { - console.log("waiting timeout job result") - setTimeout(() => { - waitingForJobResult() - }, 5000); } useEffect(() => { @@ -62,54 +26,26 @@ export default function StwoProgramMarketplace() { } }, [jobId, isFetchJob, jobEventResult]) - - - const fetchPrograms = async () => { - console.log("fetch events program") - // if(jobEventResult && jobId)return; - setIsFetchJob(false); - setIsLoadingJobResult(true); - const { events } = await fetchEvents({ - kind: KIND_JOB_ADD_PROGRAM, - // kinds:[KIND_JOB_ADD_PROGRAM as NDKKind] - // since: timestampJob, - // search: jobId - // search: `#${jobId}`, - }) - console.log("events job program", events); - setEvents(events) - if (!events) return; - let lastEvent = events[events?.length - 1] - if (!lastEvent) return; - - } - - - return (
-

Askeladd DVM

STWO ZK Program Marketplace

Check the STWO Prover ready to use!

- - -
{internalProgram?.map((p, i) => { +
{internalsPrograms?.map((p, i) => { return ( ) })} -
-
{events?.map((e, i) => { +
{eventsPrograms?.map((e, i) => { const p: IGenerateZKPRequestDVM = JSON.parse(e.content) return ( diff --git a/askeladd-dvm-marketplace/src/app/utils/generateAppHandler.ts b/askeladd-dvm-marketplace/src/app/utils/generateAppHandler.ts index 449b092..255ca15 100644 --- a/askeladd-dvm-marketplace/src/app/utils/generateAppHandler.ts +++ b/askeladd-dvm-marketplace/src/app/utils/generateAppHandler.ts @@ -4,9 +4,6 @@ import { ASKELADD_KINDS, ConfigHandle, KIND_JOB_REQUEST, KIND_JOB_RESULT } from const PARAMS_JOB_REQUEST_ZK = { request: { - }, - params: { - }, program: { @@ -24,15 +21,13 @@ const PARAMS_JOB_RESULT_ZK = { } } - const PARAMS_ALL_KIND = { [KIND_JOB_REQUEST]:PARAMS_JOB_REQUEST_ZK, [KIND_JOB_RESULT]:PARAMS_JOB_RESULT_ZK, } +/** TODO correct bech32 for nprofile, nevent of the application handler */ export const generateTagsByAppKind = (tags: string[][], appKind: ASKELADD_KINDS, config:ConfigHandle) => { - const randomId = Math.random().toString(36).substring(7); - if(config == ConfigHandle.SPECIFIC_KIND) { tags = [ ["d", randomId], @@ -59,6 +54,8 @@ export const generateTagsByAppKind = (tags: string[][], appKind: ASKELADD_KINDS, return tags } + +/** TODO correct bech32 for nprofile, nevent of the application handler */ export const generateContentAndTags = (configKind: ConfigHandle, appKind?: ASKELADD_KINDS, pubkey?:string): { tags?: string[][], content?: string } => { let tags: string[][] = [] let content = ""; diff --git a/askeladd-dvm-marketplace/src/hooks/useDVMState.ts b/askeladd-dvm-marketplace/src/hooks/useDVMState.ts index e6e0ed9..92f5575 100644 --- a/askeladd-dvm-marketplace/src/hooks/useDVMState.ts +++ b/askeladd-dvm-marketplace/src/hooks/useDVMState.ts @@ -1,6 +1,5 @@ import { ASKELADD_RELAY } from '@/constants/relay'; -import { useNostrContext } from '@/context/NostrContext'; -import { IGenerateZKPRequestDVM, KIND_JOB_REQUEST, KIND_JOB_RESULT } from '@/types'; +import { IGenerateZKPRequestDVM, KIND_JOB_ADD_PROGRAM, KIND_JOB_REQUEST, KIND_JOB_RESULT } from '@/types'; import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { SimplePool, NostrEvent, Relay } from 'nostr-tools'; import { useMemo, useState } from 'react'; @@ -11,19 +10,16 @@ export const useDVMState = () => { "idle" | "pending" | "received" | "verified" >("idle"); const [publicKey, setPublicKey] = useState(); - - const { ndk } = useNostrContext(); - // const pool = new SimplePool() const [pool, setPool] = useState(new SimplePool()) const [jobId, setJobId] = useState(); - const [jobIdResult, setJobIdResult] = useState(); const [isWaitingJob, setIsWaitingJob] = useState(false); const [jobEventResult, setJobEventResult] = useState() const [starkProof, setStarkProof] = useState() const [isFetchJob, setIsFetchJob] = useState(false); const [isLoadingJobResult, setIsLoadingJobResult] = useState(false); const [selectedEvent, setSelectedEvent] = useState() - + const [events, setEvents] = useState([]) + const [eventsPrograms, setEventsPrograms] = useState([]) let eventIdRequest = useMemo(() => { return jobId }, [jobId]) @@ -43,11 +39,9 @@ export const useDVMState = () => { const { events } = await fetchEventsTools({ kind: KIND_JOB_REQUEST, since: timestampJob, - // authors: pubkey ? [pubkey] : [] }); console.log("events job request", events); if (!events) return; - // const lastEvent = events[events?.length - 1] const lastEvent = events[0] if (!lastEvent?.id) return; const lastEventId = lastEvent?.id; @@ -57,7 +51,6 @@ export const useDVMState = () => { eventIdRequest = lastEventId; setIsWaitingJob(true) } - } @@ -84,7 +77,6 @@ export const useDVMState = () => { setJobId(event?.id) } poolRequest.close(); - } if (event?.kind == KIND_JOB_RESULT) { console.log("Event job request received: ", event?.id); @@ -105,8 +97,6 @@ export const useDVMState = () => { ) } - - /** TODO fetch subscribed event * fix search jobId => check if relayer support NIP-50 * Fetch Job result from the Prover @@ -272,6 +262,24 @@ export const useDVMState = () => { }; + const fetchPrograms = async () => { + console.log("fetch events program") + const { events } = await fetchEvents({ + kind: KIND_JOB_ADD_PROGRAM, + // kinds:[KIND_JOB_ADD_PROGRAM as NDKKind] + // since: timestampJob, + // search: jobId + // search: `#${jobId}`, + }) + console.log("events job program", events); + setEventsPrograms(events) + if (!events) return; + let lastEvent = events[events?.length - 1] + if (!lastEvent) return; + + } + + return { starkProof, proof, proofStatus, setProof, setProofStatus, runSubscriptionEvent, @@ -283,5 +291,9 @@ export const useDVMState = () => { isWaitingJob, setIsWaitingJob, publicKey, setPublicKey, setIsLoadingJobResult, + jobEventResult, + fetchPrograms, + eventsPrograms, + events } }; diff --git a/askeladd-dvm-marketplace/src/types/index.ts b/askeladd-dvm-marketplace/src/types/index.ts index c8c8dab..0cd638b 100644 --- a/askeladd-dvm-marketplace/src/types/index.ts +++ b/askeladd-dvm-marketplace/src/types/index.ts @@ -3,6 +3,62 @@ export const KIND_JOB_REQUEST = 5600 export const KIND_JOB_ADD_PROGRAM = 5700 // check if not used +export enum ASKELADD_KINDS { + KIND_JOB_REQUEST = 5600, + KIND_JOB_RESULT = 6600, + KIND_JOB_LAUNCH_PROGRAM = 5700, + // KIND_SUBMIT_PROGRAM +} + +export enum ASKELADD_KINDS_NAME { + KIND_JOB_REQUEST = "Job request", + KIND_JOB_RESULT = "Job result", + KIND_SUBMIT_PROGRAM = "Submit result", +} + +export interface IProgramParams { + // Add to the see user Application profile NIP-0 metadata + // Also can be used to do a 1-1 DVM and force it. + pubkey_app?: string; + // Event id related to the NIP-89 and the JOB_LAUNCH_PROGRAM 5700 or other kind we can discuss + event_id?: string; + unique_id?: string; + inputs?: Map + inputs_types?: Map + inputs_encrypted?: Map + contract_reached?: ContractUploadType, + contract_name?: string; + internal_contract_name?: ProgramInternalContractName + +} +export interface IGenerateZKPRequestDVM { + request?: any; + program?: IProgramParams; +} + +export interface IFormRecommendedApplicationHandlerEvent { + +} + +export enum ConfigHandle { + SPECIFIC_KIND, + ALL_KIND +} + +export enum ProgramInternalContractName { + FibonacciProvingRequest = "FibonacciProvingRequest", + PoseidonProvingRequest = "PoseidonProvingRequest", + WideFibonacciProvingRequest = "WideFibonacciProvingRequest", + MultiFibonacciProvingRequest = "MultiFibonacciProvingRequest", + Custom = "Custom" +} + + +export enum ContractUploadType { + InternalAskeladd = "InternalAskeladd", + Ipfs = "Ipfs", +} + export interface JobResultProver { job_id: string; response: { @@ -45,64 +101,3 @@ export interface CommitmentSchemeProof { } }; } - -export enum ASKELADD_KINDS { - KIND_JOB_REQUEST = 5600, - KIND_JOB_RESULT = 6600, - KIND_JOB_LAUNCH_PROGRAM = 5700, - // KIND_SUBMIT_PROGRAM -} - -export enum ASKELADD_KINDS_NAME { - KIND_JOB_REQUEST = "Job request", - KIND_JOB_RESULT = "Job result", - KIND_SUBMIT_PROGRAM = "Submit result", -} -// export const ASKELADD_KINDS= { -// KIND_JOB_REQUEST, -// KIND_JOB_RESULT -// } - -export interface IFormRecommendedApplicationHandlerEvent { - -} - -export enum ConfigHandle { - SPECIFIC_KIND, - ALL_KIND -} - -export enum ProgramInternalContractName { - FibonacciProvingRequest = "FibonacciProvingRequest", - PoseidonProvingRequest = "PoseidonProvingRequest", - WideFibonacciProvingRequest = "WideFibonacciProvingRequest", - MultiFibonacciProvingRequest = "MultiFibonacciProvingRequest", - Custom = "Custom" -} - - -export enum ContractUploadType { - InternalAskeladd = "InternalAskeladd", - Ipfs = "Ipfs", -} - -export interface IProgramParams { - // Add to the see user Application profile NIP-0 metadata - // Also can be used to do a 1-1 DVM and force it. - pubkey_app?: string; - // Event id related to the NIP-89 and the JOB_LAUNCH_PROGRAM 5700 or other kind we can discuss - event_id?: string; - - unique_id?: string; - inputs?: Map - inputs_types?: Map - inputs_encrypted?: Map - contract_reached?: ContractUploadType, - contract_name?: string; - internal_contract_name?: ProgramInternalContractName - -} -export interface IGenerateZKPRequestDVM { - request?: any; - program?: IProgramParams; -} \ No newline at end of file diff --git a/crates/cli/src/dvm_customer.rs b/crates/cli/src/dvm_customer.rs index 7fad08e..17e1317 100644 --- a/crates/cli/src/dvm_customer.rs +++ b/crates/cli/src/dvm_customer.rs @@ -67,7 +67,7 @@ async fn main() -> Result<(), Box> { request: req_value, program: Some(ProgramParams { pubkey_application: None, - inputs: map_inputs, + inputs: Some(map_inputs), inputs_encrypted: None, inputs_types: None, unique_id: None, @@ -146,7 +146,7 @@ pub async fn poseidon_program(customer: Customer) -> Result<(), CustomerError> { let job_request = GenerateZKPJobRequest { request: req_value, program: Some(ProgramParams { - inputs: map_inputs, + inputs: Some(map_inputs), pubkey_application: None, inputs_encrypted: None, inputs_types: None, diff --git a/crates/core/src/dvm/customer.rs b/crates/core/src/dvm/customer.rs index cd73b0b..7bc9fce 100644 --- a/crates/core/src/dvm/customer.rs +++ b/crates/core/src/dvm/customer.rs @@ -11,6 +11,7 @@ use tokio::time::timeout; use crate::config::Settings; use crate::dvm::constants::*; use crate::dvm::types::{GenerateZKPJobRequest, GenerateZKPJobResult}; +use crate::nostr_utils::extract_params_from_tags; use crate::verifier_service::VerifierService; /// Represents a customer in the Askeladd system. @@ -84,7 +85,21 @@ impl Customer { let mut params_inputs: HashMap = HashMap::new(); let mut tags = vec![]; if let Some(p) = program { - params_inputs = p.inputs; + if let Some(inputs) = p.inputs { + params_inputs = inputs; + } + else { + let successful_parses = extract_params_from_tags(&tags); + // let inputs_values:HashMap= successful_parses + // .into_iter() + // .map(|(k, v)| { + // let val:Value= serde_json::to_value(&v).unwrap(); + // // params_inputs.insert(k.clone(), val.clone()); + // return (k, val) + // }) + // .collect(); + params_inputs = successful_parses; + } } // OLD TAGS creation // let tags = vec![ diff --git a/crates/core/src/dvm/mod.rs b/crates/core/src/dvm/mod.rs index 4a705af..5639bdd 100644 --- a/crates/core/src/dvm/mod.rs +++ b/crates/core/src/dvm/mod.rs @@ -59,7 +59,7 @@ pub mod types { pub unique_id: Option, pub pubkey_application: Option, /* Use for one to one marketplace => difficult * on the archi of the DVM */ - pub inputs: HashMap, + pub inputs: Option>, pub inputs_types: Option>, pub inputs_encrypted: Option>, pub contract_reached: ContractUploadType, diff --git a/crates/core/src/dvm/service_provider.rs b/crates/core/src/dvm/service_provider.rs index e154797..90beb6a 100644 --- a/crates/core/src/dvm/service_provider.rs +++ b/crates/core/src/dvm/service_provider.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; // use std::collections::HashMap; use std::error::Error; @@ -177,6 +178,7 @@ impl ServiceProvider { async fn handle_event(&self, event: Box) -> Result<(), ServiceProviderError> { info!("Proving request received [{}]", event.id); + let tags = event.tags.clone(); let job_id = event.id.to_string(); let zkp_request = match ServiceProvider::deserialize_zkp_request_data(&event.content.to_owned()) { @@ -188,15 +190,31 @@ impl ServiceProvider { }; println!("zkp_request {:?}", zkp_request); let params_program: Option = zkp_request.program.clone(); - let params_inputs; + // let params_inputs= new HashMap() + let mut params_inputs: HashMap = HashMap::new(); // TODO Check strict if user have sent a good request if let Some(program_params) = params_program.clone() { println!("params_program {:?}", params_program); - - let successful_parses = convert_inputs_to_run_program(program_params.inputs); - // params_inputs = program_params.inputs.clone(); - params_inputs = successful_parses.clone(); - println!("params_inputs {:?}", params_inputs); + if let Some(inputs) = program_params.inputs { + let successful_parses = convert_inputs_to_run_program(inputs); + params_inputs = successful_parses.clone(); + println!("params_inputs {:?}", params_inputs); + } else { + let successful_parses = extract_params_from_tags(&tags); + successful_parses.into_iter().for_each(|(k, v)| { + let val: Value = serde_json::to_value(v).unwrap(); + params_inputs.insert(k.clone(), val.clone()); + }); + // let inputs_values:HashMap= successful_parses + // .into_iter() + // .map(|(k, v)| { + // let val:Value= serde_json::to_value(v).unwrap(); + // params_inputs.insert(k.clone(), val.clone()); + // return (k, val) + // }) + // .collect(); + // params_inputs = inputs_values; + } } else { println!("program_params {:?}", params_program); } diff --git a/crates/core/src/prover_service.rs b/crates/core/src/prover_service.rs index 0907964..d7ecb57 100644 --- a/crates/core/src/prover_service.rs +++ b/crates/core/src/prover_service.rs @@ -69,7 +69,9 @@ impl ProverService { println!("generate_proof_by_program type {:?}", request); let mut successful_parses = HashMap::new(); if let Some(program_params) = program_params.clone() { - successful_parses = convert_inputs_to_run_program(program_params.inputs); + if let Some(inputs) = program_params.inputs { + successful_parses = convert_inputs_to_run_program(inputs); + } } let serialized_request = serde_json::to_string(&successful_parses).unwrap(); // TODO