npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hinkal/client

v0.1.13

Published

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 pla

Downloads

658

Readme

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);