Quick Start
EVM Blockchains
This section walks you through deploying and integrating a Primus contract into your Solidity project.
Install the Contract
When setting up your smart contract project, you need to pull out the smart contract library first.
Using Hardhat:
npm install @primuslabs/zktls-contracts
Using Foundry:
forge install primus-labs/zktls-contracts
Deploy a Smart Contract
Deploy the following contract to any EVM-compatible network of your choice. For this walkthrough, we'll use Ethereum as an example.
// 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;
}
}
On-chain Interactions
The following code helps developers interact with the Test example or Production example contracts on-chain. This can be done using the zkTLS SDK after completing the smart contract development and deployment.
....
....
//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
}
Straknet Blockchains
This section walks you through deploying and integrating a Primus contract into your cairo project.
Install the Contract
When setting up your smart contract project, you need to reference the Primus contract library first. Make the following configuration in the Scarb.toml file.
[dependencies]
primus_zktls = { git = "https://github.com/primus-labs/zktls-starknet-contracts.git" }
Deploy a Smart Contract
Deploy the following contract to Starknet. For this walkthrough.
use primus_zktls::IPrimusZKTLS::Attestation;
#[starknet::interface]
pub trait IAttestorTest<TState> {
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<ContractState> {
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;
}
}
}
On-chain Interactions
The following code helps developers interact with the Test example or Production example contracts on-chain. This can be done using the zkTLS SDK after completing the smart contract development and deployment.
....
....
//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
}