0.1.13 • Published 8 months ago

@hinkal/client v0.1.13

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Hinkal Client SDK

Hinkal is a middleware and a suite of smart contracts on EVM-compatible chains that leverage ZK-proofs and stealth addresses to facilitate compliant and private transactions across major dApps. Users can securely store assets and interact with popular platforms such as Uniswap, Pendle, Lido, Curve, and more, all while maintaining privacy and compliance.

The Hinkal SDK client package enables users to perform arbitrary smart contract interactions privately, ensuring both security and anonymity.

Installation

Install the Hinkal SDK client using npm or yarn:

Using npm:

npm install @hinkal/client

Using yarn:

yarn add @hinkal/client

Getting Started

1. Import and Initialize Hinkal

Begin by importing the Hinkal class from the @hinkal/client package and creating an instance of it.

import { Hinkal } from '@hinkal/client';
import { ethers } from 'ethers';

// Initialize ethers provider and signer
const provider = new ethers.providers.JsonRpcProvider('https://your-eth-node-url');
const signer = provider.getSigner();

// Create an instance of Hinkal
const hinkal = new Hinkal<ethers.Signer>();

2. Initialize the Provider Adapter

Instantiate the EthersProviderAdapter with your signer and chain ID, then initialize it within the Hinkal instance.

import { EthersProviderAdapter } from '@hinkal/client';

// Replace with your desired chain ID
const chainId = 1; // Ethereum Mainnet
const providerAdapter = new EthersProviderAdapter(signer, chainId);
await hinkal.initProviderAdapter(signer, providerAdapter);

3. Initialize User Keys and Reset Merkle Trees

Generate the user's shielded address and synchronize the Merkle trees with the smart contracts.

// Initialize user keys (generates a shielded address)
await hinkal.initUserKeys();

// Reset Merkle trees to synchronize state
await hinkal.resetMerkle();

4. Fetch Shielded Balances

Retrieve the user's shielded balances across supported tokens.

const balances = await hinkal.getBalances();
console.log('Shielded Balances:', balances);

5. Perform Deposits

Deposit tokens into the user's shielded account. Specify the ERC20 token addresses and the respective amounts to deposit.

const erc20Addresses = ['0xTokenAddress1', '0xTokenAddress2'];
const amountChanges = [BigInt(1000), BigInt(2000)];
const depositTx = await hinkal.deposit(erc20Addresses, amountChanges);
console.log('Deposit Transaction:', depositTx);

6. Execute Smart Contract Interactions

After updating the user's balance, perform any smart contract interaction privately.

const recipientAddress = '0xRecipientAddress';
const isRelayerOff = false;
const onlyGasEstimate = false;
const ops = ['0xOperation1', '0xOperation2'];
const onChainCreation = [false, true];

const transaction = await hinkal.actionPrivateWallet(
  erc20Addresses,
  amountChanges,
  onChainCreation,
  ops,
  undefined,
  onlyGasEstimate,
);
console.log('Smart Contract Interaction Transaction:', transaction);

Access Tokens

Before interacting with Hinkal smart contracts, users must mint an access token after passing compliance checks.

Check for Existing Access Token

Verify if the user already possesses an access token.

const hasAccessToken = await hinkal.checkAccessToken();
console.log('Has Access Token:', hasAccessToken);

Minting an Access Token

If the user does not have an access token, they must pass compliance checks using a supported provider and then mint the token.

import { mintAccessToken } from '@hinkal/client';

// Assume user has passed compliance checks and obtained signatureData
const signatureData = await hinkal.getAPI().getAccessTokenSignature(chainId, ethereumAddress, accessKey);

// Mint the access token
const mintTx = await mintAccessToken(hinkal, signatureData);
console.log('Mint Access Token Transaction:', mintTx);

Example: Integrating with Ethers.js

Below is a comprehensive example demonstrating how to integrate the Hinkal SDK with a simple Node.js application using Ethers.js.

import { Hinkal, EthersProviderAdapter, mintAccessToken } from '@hinkal/client';
import { ethers } from 'ethers';

// Setup ethers provider and signer
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);

// Initialize Hinkal
const hinkal = new Hinkal<ethers.Signer>();

// Initialize Provider Adapter
const chainId = 1; // Ethereum Mainnet
const providerAdapter = new EthersProviderAdapter(wallet, chainId);
await hinkal.initProviderAdapter(wallet, providerAdapter);

// Initialize User Keys
await hinkal.initUserKeys();

// Reset Merkle Trees
await hinkal.resetMerkle();

// Check for Access Token
const hasToken = await hinkal.checkAccessToken();
if (!hasToken) {
  // Perform compliance checks with a provider
  // This step depends on the integration with your compliance provider
  const signatureData = await hinkal
    .getAPI()
    .getAccessTokenSignature(chainId, await wallet.getAddress(), 'USER_ACCESS_KEY');

  // Mint Access Token
  const mintTx = await mintAccessToken(hinkal, signatureData);
  console.log('Access Token Minted:', mintTx);
}

// Fetch Balances
const balances = await hinkal.getBalances();
console.log('User Balances:', balances);

// Perform a Deposit
const erc20Addresses = ['0xTokenAddress1', '0xTokenAddress2'];
const amountChanges = [BigInt(1000), BigInt(2000)];
const depositTx = await hinkal.deposit(erc20Addresses, amountChanges);
console.log('Deposit Transaction:', depositTx);

// Perform a Private Wallet Action
const recipientAddress = '0xRecipientAddress';
const isRelayerOff = false;
const onlyGasEstimate = false;
const ops = ['0xOperation1', '0xOperation2'];
const onChainCreation = [false, true];
const actionTx = await hinkal.actionPrivateWallet(
  erc20Addresses,
  amountChanges,
  onChainCreation,
  ops,
  undefined,
  onlyGasEstimate,
);
console.log('Action Transaction:', actionTx);
0.1.10

8 months ago

0.1.11

8 months ago

0.1.12

8 months ago

0.1.13

8 months ago

0.1.9

8 months ago

0.1.8

8 months ago

0.1.7

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago