### Install Primus zkTLS SDK using npm Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/install Installs the Primus zkTLS SDK and its dependencies into your project using npm. This is the first step in integrating the SDK. ```bash npm install --save @primuslabs/zktls-js-sdk ``` -------------------------------- ### Install Primus Network SDK with npm Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-developers/install Installs the Primus Network SDK and its dependencies using npm. This is the standard way to add the SDK to a Node.js project. ```bash npm install --save @primuslabs/network-js-sdk ``` -------------------------------- ### Initialize and Use Primus zkTLS SDK in JavaScript Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/test Demonstrates initializing the Primus zkTLS SDK, setting parameters like appId and appSecret, and generating, signing, and verifying an attestation request. This example is intended for frontend testing. ```javascript import { PrimusZKTLS } from "@primuslabs/zktls-js-sdk" // Initialize parameters, the init function is recommended to be called when the page is initialized. const primusZKTLS = new PrimusZKTLS(); const appId = "YOUR_APPID"; const appSecret= "YOUR_SECRET"; // Just for testing, appSecret cannot be written in the front-end code const initAttestaionResult = await primusZKTLS.init(appId, appSecret); // Set the device parameter to detect the user’s device type when your application supports both PC and mobile. Currently, only Android devices are supported. iOS is coming soon. // let platformDevice = "pc"; // if (navigator.userAgent.toLocaleLowerCase().includes("android")) { // platformDevice = "android"; // } else if (navigator.userAgent.toLocaleLowerCase().includes("iphone")) { // platformDevice = "ios"; // } // const initAttestaionResult = await primusZKTLS.init(appId, appSecret, {platform: platformDevice}); console.log("primusProof initAttestaionResult=", initAttestaionResult); export async function primusProof() { // Set TemplateID and user address. const attTemplateID = "YOUR_TEMPLATEID"; const userAddress = "YOUR_USER_ADDRESS"; // Generate attestation request. const request = primusZKTLS.generateRequestParams(attTemplateID, userAddress); // Set zkTLS mode, default is proxy mode. (This is optional) const workMode = "proxytls"; request.setAttMode({ algorithmType: workMode, }); // Set attestation conditions. (These are optional) // 1. Hashed result. // const attConditions = [ // [ // { // field:'YOUR_CUSTOM_DATA_FIELD', // op:'SHA256', // }, // ], // ]; // 2. Conditions result. // const attConditions = [ // [ // { // field: "YOUR_CUSTOM_DATA_FIELD", // op: ">", // value: "YOUR_CUSTOM_TARGET_DATA_VALUE", // }, // ], // ]; // request.setAttConditions(attConditions); // Transfer request object to string. const requestStr = request.toJsonString(); // Sign request. const signedRequestStr = await primusZKTLS.sign(requestStr); // Start attestation process. const attestation = await primusZKTLS.startAttestation(signedRequestStr); console.log("attestation=", attestation); // Verify siganture. const verifyResult = await primusZKTLS.verifyAttestation(attestation) console.log("verifyResult=", verifyResult); if (verifyResult === true) { // Business logic checks, such as attestation content and timestamp checks // do your own business logic. } else { // If failed, define your own logic. } } ``` -------------------------------- ### Install zktls-contracts for Hardhat (npm) Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/solidity/quickstart Installs the Primus zktls-contracts library for a Hardhat project using npm. This is the first step in setting up your smart contract project. ```bash npm install @primuslabs/zktls-contracts ``` -------------------------------- ### Complete PrimusLabs Network JS SDK Example Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-developers/example This example demonstrates the full workflow of the PrimusLabs Network JS SDK, from initialization with a provider and chain ID to submitting a task, performing an attestation, and verifying the final result. It includes error handling and optional withdrawal functionality. This code requires the `@primuslabs/network-js-sdk` package. ```javascript import { PrimusNetwork } from "@primuslabs/network-js-sdk"; async function main() { const provider = window.ethereum; const primusNetwork = new PrimusNetwork(); console.log(primusNetwork.supportedChainIds); // [84532, 8453] try { // 1. Initialize await primusNetwork.init(provider, 84532); // The Base chain changes 84532 to 8453 console.log("SDK initialized"); // 2. Submit task, set TemplateID and user address. const submitTaskParams = { templateId: "YOUR_TEMPLATEID", address: "YOUR_USER_ADDRESS", }; const submitTaskResult = await primusNetwork.submitTask(submitTaskParams); console.log("Task submitted:", submitTaskResult); // 3. Perform attestation const attestParams = { ...submitTaskParams, ...submitTaskResult, // extendedParams: JSON.stringify({ attUrlOptimization: true }), //Optional,optimization the url of attestation. }; const attestResult = await primusNetwork.attest(attestParams); console.log('Attestation completed:', attestResult); // 4. Verify & poll task result const verifyAndPollTaskResultParams = { taskId: attestResult[0].taskId, reportTxHash: attestResult[0].reportTxHash, } const taskResult = await primusNetwork.verifyAndPollTaskResult(verifyAndPollTaskResultParams); console.log("Final result:", taskResult); // Optional withdrawal // const settledTaskIds = await primusNetwork.withdrawBalance(); // console.log('Withdrawn:', settledTaskIds ); } catch (error) { console.error("Main flow error:", error); } } main(); ``` -------------------------------- ### Install Primus Network SDK with yarn Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-developers/install Installs the Primus Network SDK and its dependencies using yarn. This command is an alternative for projects using yarn as their package manager. ```bash yarn add --save @primuslabs/network-js-sdk ``` -------------------------------- ### Install Primus Core SDK using npm Source: https://docs.primuslabs.xyz/data-verification/core-sdk/install Installs the Primus Core SDK using npm. This command adds the SDK as a dependency to your project, ensuring it's available for use in your JavaScript or TypeScript applications. ```bash npm install --save @primuslabs/zktls-core-sdk ``` -------------------------------- ### Install Primus zkTLS SDK using yarn Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/install Installs the Primus zkTLS SDK and its dependencies into your project using yarn. This is an alternative to npm for package management. ```bash yarn add --save @primuslabs/zktls-js-sdk ``` -------------------------------- ### Install Primus Core SDK using yarn Source: https://docs.primuslabs.xyz/data-verification/core-sdk/install Installs the Primus Core SDK using yarn. This command adds the SDK as a dependency to your project, suitable for projects managed with the yarn package manager. ```bash yarn add --save @primuslabs/zktls-core-sdk ``` -------------------------------- ### Install zktls-contracts for Foundry (forge) Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/solidity/quickstart Installs the Primus zktls-contracts library for a Foundry project using the forge command. This is the first step in setting up your smart contract project. ```bash forge install primus-labs/zktls-contracts ``` -------------------------------- ### Import Primus Network Core SDK in JavaScript/TypeScript Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-backend/install Imports the PrimusNetwork class from the installed SDK into your JavaScript or TypeScript project. This allows you to start using the SDK's functionalities. ```javascript const { PrimusNetwork } = require("@primuslabs/network-core-sdk"); ``` -------------------------------- ### Clone and Prepare Primus Network Startup Repository Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-nodes/attestor-node-guides This snippet demonstrates how to clone the Primus Network startup repository from GitHub, navigate into the directory, and make the run script executable. This is a prerequisite for setting up the node. ```shell git clone https://github.com/primus-labs/primus-network-startup.git cd primus-network-startup chmod +x ./run.sh ``` -------------------------------- ### Primus Core SDK Data Verification (JavaScript) Source: https://docs.primuslabs.xyz/data-verification/core-sdk/simpleexample Performs a data verification process using Primus's Core SDK. It initializes the SDK, sets up request and response parameters, generates and starts the attestation process, and verifies the result. Ensure PRIMUS_APP_ID and PRIMUS_APP_SECRET are obtained from the Primus Developer Hub. ```javascript const { PrimusCoreTLS } = require("@primuslabs/zktls-core-sdk"); async function primusProofTest() { // Initialize parameters, the init function is recommended to be called when the program is initialized. const appId = "PRIMUS_APP_ID"; const appSecret= "PRIMUS_APP_SECRET"; const zkTLS = new PrimusCoreTLS(); const initResult = await zkTLS.init(appId, appSecret); console.log("primusProof initResult=", initResult); // Set request and responseResolves. const request ={ url: "YOUR_CUSTOM_URL", // Request endpoint. method: "REQUEST_METHOD", // Request method. header: {}, // Request headers. body: "" // Request body. }; // The responseResolves is the response structure of the url. // For example the response of the url is: {"data":[{ ..."instFamily": "","instType":"SPOT",...}]}. const responseResolves = [ { keyName: 'CUSTOM_KEY_NAME', // According to the response keyname, such as: instType. parsePath: 'CUSTOM_PARSE_PATH', // According to the response parsePath, such as: $.data[0].instType. } ]; // Generate attestation request. const generateRequest = zkTLS.generateRequestParams(request, responseResolves); // Set zkTLS mode, default is proxy mode. (This is optional) generateRequest.setAttMode({ algorithmType: "proxytls" }); // Start attestation process. const attestation = await zkTLS.startAttestation(generateRequest); console.log("attestation=", attestation); const verifyResult = zkTLS.verifyAttestation(attestation); console.log("verifyResult=", verifyResult); if (verifyResult === true) { // Business logic checks, such as attestation content and timestamp checks // do your own business logic. } else { // If failed, define your own logic. } } ``` -------------------------------- ### Import Primus zkTLS SDK in JavaScript/TypeScript Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/install Imports the PrimusZKTLS class from the installed SDK into your JavaScript or TypeScript files, making its functionalities available for use. ```javascript import { PrimusZKTLS } from "@primuslabs/zktls-js-sdk"; ``` -------------------------------- ### Attestation Structure Example Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/production This JSON structure represents a successful data verification attestation. It includes details about the recipient, the original request, verification parameters, actual data, conditions, timestamp, and attestor information. This structure is the standard output after a verification process is completed. ```json { "recipient": "YOUR_USER_ADDRESS", "request": { "url": "REQUEST_URL", "header": "REQUEST_HEADER", "method": "REQUEST_METHOD", "body": "REQUEST_BODY" }, "reponseResolve": [ { "keyName": "VERIFY_DATA_ITEMS", "parseType": "", "parsePath": "DARA_ITEM_PATH" } ], "data": "{ACTUAL_DATA}", "attConditions": "[RESPONSE_CONDITIONS]", "timestamp": TIMESTAMP_OF_VERIFICATION_EXECUTION, "additionParams": "", "attestors": [ { "attestorAddr": "ATTESTOR_ADDRESS", "url": "https://primuslabs.org" } ], "signatures": [ "SIGNATURE_OF_THIS_VERIFICATION" ] } ``` -------------------------------- ### Deploy AttestorTest Smart Contract (Solidity) Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/solidity/quickstart Deploys the AttestorTest smart contract to an EVM-compatible network. This contract utilizes the IPrimusZKTLS interface to verify attestations. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; // if you are using foundry, you can use the following conf: // you can edit import information like this in your local project remappings.txt: // @primuslabs/zktls-contracts=lib/zktls-contracts/ import { IPrimusZKTLS, Attestation } from "@primuslabs/zktls-contracts/src/IPrimusZKTLS.sol"; contract AttestorTest { address public primusAddress; constructor(address _primusAddress) { // Replace with the network you are deploying on primusAddress = _primusAddress; } function verifySignature(Attestation calldata attestation) public view returns(bool) { IPrimusZKTLS(primusAddress).verifyAttestation(attestation); // Business logic checks, such as attestation content and timestamp checks // do your own business logic return true; } } ``` -------------------------------- ### Deploy AttestorTest Smart Contract (Cairo/Starknet) Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/solidity/quickstart Deploys the AttestorTest smart contract to Starknet. This contract is written in Cairo and implements the IPrimusZKTLS interface for attestation verification. ```cairo use primus_zktls::IPrimusZKTLS::Attestation; #[starknet::interface] pub trait IAttestorTest { fn verifySignature(self: @TState, attestation: Attestation) -> bool; } #[starknet::contract] mod AttestorTest { use primus_zktls::IPrimusZKTLS::{ Attestation, IPrimusZKTLSDispatcher, IPrimusZKTLSDispatcherTrait, }; use starknet::ContractAddress; use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; #[storage] struct Storage { address: ContractAddress } #[constructor] fn constructor(ref self: ContractState, _primusAddress: ContractAddress) { // Replace with the network you are deploying on self.address.write(_primusAddress); } #[abi(embed_v0)] impl IAttestorTest of super::IAttestorTest { fn verifySignature(self: @ContractState, attestation: Attestation) -> bool { IPrimusZKTLSDispatcher { contract_address: self.address.read() } .verifyAttestation(attestation); // Business logic checks, such as attestation content and timestamp checks // do your own business logic return true; } } } ``` -------------------------------- ### Set zkTLS Mode (JavaScript) Source: https://docs.primuslabs.xyz/data-verification/core-sdk/simpleexample Sets the zkTLS mode for the Primus SDK. The default mode is 'proxytls'. This function is typically called before initiating the attestation process. ```javascript // Set zkTLS mode, default is proxy mode. primusZKTLS.setAttMode({ algorithmType: "proxytls", }); ``` -------------------------------- ### Initialize Primus Network SDK Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-developers/example Initializes the SDK to connect to specified blockchain networks. Requires a Web3 provider instance and a valid chain ID. Supported provider types include ethers.providers.JsonRpcProvider, ethers.providers.Web3Provider, and ethers.providers.JsonRpcSigner. ```javascript const provider = new ethers.providers.Web3Provider(window.ethereum); const chainId = 1; // Example: Ethereum Mainnet await primus.init(provider, chainId); ``` -------------------------------- ### Generate Attestation Request Parameters - JavaScript Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/production Generates the necessary parameters for an attestation request using the zkTLS SDK. This function is a prerequisite for further configuration of the request object. It requires the template ID and user's address as input. ```javascript const request = primusZKTLS.generateRequestParams(attTemplateID, userAddress); ``` -------------------------------- ### Frontend: Initialize and Generate Attestation Request with zkTLS SDK Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/production This snippet demonstrates how to initialize the PrimusZKTLS SDK on the frontend, set up application and attestation parameters, and generate a request for attestation. It includes optional configurations for device detection, custom parameters, and attestation conditions. The output is a JSON string representing the attestation request. ```javascript import { PrimusZKTLS } from "@primuslabs/zktls-js-sdk"; // Initialize parameters, the init function is recommended to be called when the page is initialized. const primusZKTLS = new PrimusZKTLS(); const appId = "YOUR_APPID"; const initAttestaionResult = await primusZKTLS.init(appId); // Set the device parameter to detect the user’s device type when your application supports both PC and mobile. Currently, only Android devices are supported. iOS is coming soon. // let platformDevice = "pc"; // if (navigator.userAgent.toLocaleLowerCase().includes("android")) { // platformDevice = "android"; // } else if (navigator.userAgent.toLocaleLowerCase().includes("iphone")) { // platformDevice = "ios"; // } // const initAttestaionResult = await primusZKTLS.init(appId, "", {platform: platformDevice}); console.log("primusProof initAttestaionResult=", initAttestaionResult); export async function primusProof() { // Set TemplateID and user address. const attTemplateID = "YOUR_TEMPLATEID"; const userAddress = "YOUR_USER_ADDRESS"; // Generate attestation request. const request = primusZKTLS.generateRequestParams(attTemplateID, userAddress); // Set additionParams. (This is optional) const additionParams = JSON.stringify({ YOUR_CUSTOM_KEY: "YOUR_CUSTOM_VALUE", }); request.setAdditionParams(additionParams); // Set zkTLS mode, default is proxy mode. (This is optional) const workMode = "proxytls"; request.setAttMode({ algorithmType: workMode, }); // Set attestation conditions. (These are optional) // 1. Hashed result. // const attConditions = [ // [ // { // field:'YOUR_CUSTOM_DATA_FIELD', // op:'SHA256', // }, // ], // ]; // 2. Conditions result. //const attConditions = [ // [ // { // field: "YOUR_CUSTOM_DATA_FIELD", // op: ">", // value: "YOUR_CUSTOM_TARGET_DATA_VALUE", // }, // ], //]; // request.setAttConditions(attConditions); // Transfer request object to string. const requestStr = request.toJsonString(); // Get signed resopnse from backend. const response = await fetch(`http://YOUR_URL:PORT?YOUR_CUSTOM_PARAMETER`); const responseJson = await response.json(); const signedRequestStr = responseJson.signResult; // Start attestation process. const attestation = await primusZKTLS.startAttestation(signedRequestStr); console.log("attestation=", attestation); // Verify siganture const verifyResult = await primusZKTLS.verifyAttestation(attestation); console.log("verifyResult=", verifyResult); if (verifyResult === true) { // Business logic checks, such as attestation content and timestamp checks // do your own business logic. } else { // If failed, define your own logic. } } ``` -------------------------------- ### Backend: Set up Express Server for Signing Attestation Requests Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/production This snippet shows a basic backend implementation using Express.js to handle signing requests from the frontend. It initializes the PrimusZKTLS SDK with application credentials and uses it to sign the provided attestation parameters. The signed result is then sent back to the client. ```javascript const express = require("express"); const cors = require("cors"); const { PrimusZKTLS } = require("@primuslabs/zktls-js-sdk"); const app = express(); const port = YOUR_PORT; // Just for test, developers can modify it. app.use(cors()); // Listen to the client's signature request and sign the attestation request. app.get("/primus/sign", async (req, res) => { const appId = "YOUR_APPID"; const appSecret = "YOUR_SECRET"; // Create a PrimusZKTLS object. const primusZKTLS = new PrimusZKTLS(); // Set appId and appSecret through the initialization function. await primusZKTLS.init(appId, appSecret); // Sign the attestation request. console.log("signParams=", req.query.signParams); const signResult = await primusZKTLS.sign(req.query.signParams); console.log("signResult=", signResult); // Return signed result. res.json({ signResult }); }); app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); }); ``` -------------------------------- ### Initialize SDK with Device Detection - JavaScript Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/production Initializes the zkTLS SDK and detects the user's device type, which is crucial if the application supports both PC and mobile platforms. Currently, it supports 'pc', 'android', and 'ios' (iOS support is pending). This ensures proper functionality across different devices. ```javascript let platformDevice = "pc"; if (navigator.userAgent.toLocaleLowerCase().includes("android")) { platformDevice = "android"; } else if (navigator.userAgent.toLocaleLowerCase().includes("iphone")) { platformDevice = "ios"; } const initAttestaionResult = await primusZKTLS.init(appId, "", {platform: platformDevice}); ``` -------------------------------- ### Primus Network SDK Implementation (JavaScript) Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-backend/simpleexample This JavaScript code snippet demonstrates how to use the Primus Network SDK to initialize a wallet, submit a task, attest to data, and verify the task result. It requires ethers.js and the Primus Network library. The input includes private keys, addresses, chain IDs, RPC URLs, request configurations, and response resolution paths. The output logs the results of each step, including task submission, attestation, and final task verification. ```javascript const PRIVATEKEY = "YOUER_PRIVATEKEY"; const address = "0xYOUER_ADDRESS"; const chainId = 84532; // Base Sepolia (or 8453 for Base mainnet) const baseSepoliaRpcUrl = "https://sepolia.base.org"; // (or 'https://mainnet.base.org' for Base mainnet) // The request and response can be customized as needed. const requests = [ { url: "https://www.okx.com/api/v5/public/instruments?instType=SPOT&instId=BTC-USD", method: "GET", header: {}, body: "", }, ]; const responseResolves = [ [ { keyName: "instType", parseType: "json", parsePath: "$.data[0].instType", // op: "SHA256", // optional, default is 'REVEAL_STRING' }, ], ]; const provider = new ethers.providers.JsonRpcProvider(baseSepoliaRpcUrl); const wallet = new ethers.Wallet(PRIVATEKEY, provider); try { const primusNetwork = new PrimusNetwork(); // Initialize the network with wallet const initResult = await primusNetwork.init(wallet, chainId); // Submit task const submitTaskParams = { address, }; let submitTaskResult = await primusNetwork.submitTask(submitTaskParams); console.log("Submit task result:", submitTaskResult); // Compose params for attest const attestParams = { ...submitTaskParams, ...submitTaskResult, requests, responseResolves, // attMode: { // algorithmType: "proxytls", // optional, default is 'proxytls' // }, // getAllJsonResponse: "true", // optional, default is 'false' }; let attestResult = await primusNetwork.attest(attestParams); console.log("Attest result:", attestResult); // Verify and poll task result const verifyParams = { taskId: attestResult[0].taskId, reportTxHash: attestResult[0].reportTxHash, }; const taskResult = await primusNetwork.verifyAndPollTaskResult(verifyParams); console.log("Task result:", taskResult); // const allResponse= await primusNetwork.getAllResponse(attestResult[0].taskId) // console.log('allResponse:', allResponse) } catch (error) { console.error("Unexpected error:", error); throw error; } ``` -------------------------------- ### On-chain Interaction with Primus Contracts (JavaScript/Ethers.js) Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/solidity/quickstart Interacts with deployed Primus contracts on-chain using the zkTLS SDK and ethers.js. This example demonstrates starting an attestation, verifying the result, and calling the `verifySignature` function on the deployed contract. ```javascript .... .... //start attestation process const attestation = await primusZKTLS.startAttestation(signedRequestStr); console.log("attestation=", attestation); if (verifyResult === true) { // Business logic checks, such as attestation content and timestamp checks // Do your own business logic // Interacting with Smart Contracts // Set contract address and ABI const contractData = {"YOUR_CONTRACT_ABI_JSON_DATA"}; const abi = contractData.abi; const contractAddress = "YOUR_CONTRACT_ADDRESS_YOU_DEPLOYED"; // Use ethers.js connect to the smart contract const provider = new ethers.providers.JsonRpcProvider("YOUR_RPC_URL"); const contract = new ethers.Contract(contractAddress, abi, provider); try { // Call verifyAttestation func const tx = await contract.verifySignature(attestation); console.log("Transaction:", tx); } catch (error) { console.error("Error in verifyAttestation:", error); } } else { //not the primus sign, error business logic } ``` -------------------------------- ### Import Primus Core SDK in JavaScript/TypeScript Source: https://docs.primuslabs.xyz/data-verification/core-sdk/install Imports the PrimusCoreTLS class from the Primus Core SDK. This is the initial step to utilize the SDK's functionalities within your project's code. ```javascript const { PrimusCoreTLS } = require("@primuslabs/zktls-core-sdk"); ``` -------------------------------- ### Node Metadata JSON Structure Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-nodes/attestor-node-guides This example defines the structure for the node metadata JSON document. This document should contain fields such as name, description, website, X username, and logo, and it must be publicly accessible. ```json { "name": "Your node name", "description": "Introduce your node", "website": "Your website URL", "x": "https://x.com/", "logo": "" } ``` -------------------------------- ### Submit Attestation and HTTP Responses to zkVM with Primus SDK Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-backend/simpleexample Facilitates the submission of both attestation data and associated HTTP response payloads to the zkVM for further computation. By setting `getAllJsonResponse` to 'true', the SDK retrieves raw HTTP responses alongside the hashed attestation, enabling comprehensive analysis within the zkVM. ```javascript const responseResolves = [ [ { ...otherParams, op: "SHA256", // optional, default is 'REVEAL_STRING' }, ], ]; const attestParams = { ...submitTaskParams, ...submitTaskResult, requests, responseResolves, getAllJsonResponse: "true", // optional, default is 'false', Must be set to true to allow getAllJsonResponse to return the HTTP response. }; let attestResult = await primusNetwork.attest(attestParams); const allJsonResponse = await primusNetwork.getAllJsonResponse( attestResult[0].taskId ); ``` -------------------------------- ### Set Attestation Conditions with Hashed Result Logic Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/test This example shows how to configure the PrimusLabs SDK to use a hashed result for verification logic. It involves setting attestation conditions where a specific field is processed using the SHA256 hashing algorithm. This is useful for verifying data integrity when the exact plaintext value is not required on-chain. ```javascript // Set Attestation conditions request.setAttConditions([ [ { field: 'YOUR_CUSTOM_DATA_FIELD', op: 'SHA256', }, ], ]); ``` -------------------------------- ### Interact with Smart Contracts using zkTLS SDK and starknet.js Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/solidity/quickstart This JavaScript code snippet demonstrates how to initiate an attestation using the zkTLS SDK, verify the attestation result, and then interact with a deployed Cairo smart contract using starknet.js. It includes setting up the contract connection, handling signatures, and calling the `verifySignature` function on the contract. Ensure you have your Starknet account, RPC URL, and contract address configured. ```javascript //start attestation process const attestation = await primusZKTLS.startAttestation(signedRequestStr); console.log("attestation=", attestation); if (verifyResult === true) { // Business logic checks, such as attestation content and timestamp checks // Do your own business logic // Interacting with Smart Contracts // Set contract address and ABI // Use starknet.js connect to the cairo contract const account = YOUR_ACCOUNT_OBJECT; const rpcUrl = "YOUR_RPC_NODE_URL"; const contractAddress = "YOUR_CONTRACT_ADDRESS_YOU_DEPLOYED"; const provider = new RpcProvider({ nodeUrl: rpcUrl }); const compiledContract = await provider.getClassAt(contractAddress); const abi = compiledContract.abi; const contract = new Contract(abi, contractAddress, provider); contract.connect(account); try { // Call verifyAttestation func // hexStringToByteArray is to convert hex string signature to byte array attestation.signatures[0] = hexStringToByteArray(attestation.signatures[0]); const tx = await contract.verifySignature(attestation); console.log("Transaction:", tx); } catch (error) { console.error("Error in verifyAttestation:", error); } } else { //not the primus sign, error business logic } ``` -------------------------------- ### Set zkTLS Mode with Primus SDK Source: https://docs.primuslabs.xyz/primus-network/build-with-primus/for-backend/simpleexample Configures the zkTLS mode for network attestations. This parameter allows selection between 'proxytls' and 'mpctls' algorithms, with 'proxytls' being the default if not explicitly set. It's a key step before initiating an attestation process. ```javascript let attestParams = { // ... other parameters attMode: { algorithmType: "proxytls", // optional, default is 'proxytls' }, }; primusNetwork.attest(attestParams); ``` -------------------------------- ### Configure zkTLS Mode in JavaScript Source: https://docs.primuslabs.xyz/data-verification/zk-tls-sdk/test Shows how to set the zkTLS working mode to 'proxytls' using the PrimusZKTLS SDK. This is an optional step as 'proxy' mode is the default. ```javascript // Set zkTLS mode, default is proxy mode. primusZKTLS.setAttMode({ algorithmType: "proxytls", }); ```