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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bnb-passport-attestation

v0.1.48

Published

BAS SDK - A toolkit for blockchain interaction

Readme

BAS SDK

A comprehensive toolkit for blockchain interaction, providing React hooks and utilities for seamless integration with blockchain networks.

Features

  • 🔗 Wallet Connection & Management
  • 🔄 Network Switching (Mainnet/Testnet)
  • 📝 Smart Contract Interaction
  • 🛡️ Comprehensive Error Handling
  • 📦 TypeScript Support
  • ⚛️ React Hooks
  • 🔍 Transaction Status Tracking

Installation

# Using npm
npm install bnb-passport-attestation

# Using yarn
yarn add bnb-passport-attestation

# Using pnpm
pnpm add bnb-passport-attestation

Quick Start

Supported type values: kyc_binance, kyc_bithumb, kyc_upbit, kyc_coinbase, kyc_okx, kyc_bybit.

import { usePassportAttention } from 'bnb-passport-attestation';

function YourComponent() {
  const {
    connect,
    handleMint,
    isLoading,
    account,
    currentNetwork,
    isCorrectNetwork,
    isConnected,
    txHash,
    isConfirmed
  } = usePassportAttention({
    inviteCode: 123,  // Invite code
    env: 'mainnet'    // 'mainnet' or 'testnet'
  });

  // Handle wallet connection
  const handleConnect = async () => {
    try {
      await connect();
    } catch (error) {
      console.error('Connection failed:', error);
    }
  };

  // Handle minting
  const handleMintPassport = async () => {
    try {
      const receipt = await handleMint('kyc_binance');
      console.log('Mint successful:', receipt);
    } catch (error) {
      console.error('Mint failed:', error);
    }
  };

  return (
    <div>
      {!isConnected ? (
        <button onClick={handleConnect}>Connect Wallet</button>
      ) : !isCorrectNetwork ? (
        <div>
          <p>Please switch to {env} network</p>
          <button onClick={handleConnect}>Switch Network</button>
        </div>
      ) : (
        <button 
          onClick={handleMintPassport}
          disabled={isLoading}
        >
          {isLoading ? 'Processing...' : 'Mint Passport'}
        </button>
      )}
      
      {txHash && (
        <p>Transaction Hash: {txHash}</p>
      )}
      
      {isConfirmed && (
        <p>Transaction confirmed!</p>
      )}
    </div>
  );
}

API Documentation

usePassportAttention Hook

A React hook for handling wallet connection, network switching, and passport minting operations. The hook automatically uses the currently connected wallet address for all operations.

Parameters

interface UsePassportAttentionProps {
  inviteCode: number;   // Invite code
  env?: 'mainnet' | 'testnet';  // Environment type (default: 'testnet')
}

Return Value

interface UsePassportAttentionReturn {
  // Connection state
  isConnected: boolean;        // Whether wallet is connected
  account: string | null;      // Connected account address
  currentNetwork: string;      // Current network ('mainnet', 'testnet', or 'unknown')
  isCorrectNetwork: boolean;   // Whether connected to the correct network
  
  // Loading states
  loaded: boolean;             // Whether iframe is loaded
  isLoading: boolean;          // Whether any operation is in progress
  
  // Transaction states
  txHash: string | null;       // Current transaction hash
  isConfirmed: boolean;        // Whether transaction is confirmed
  
  // Methods
  connect: () => Promise<string>;  // Connect wallet and switch network
  handleMint: (type: string) => Promise<any>;  // Handle minting process
}

Methods

connect()

Connects the wallet and switches to the specified network. Returns the connected account address.

const connect = async () => {
  try {
    const account = await connect();
    console.log('Connected account:', account);
  } catch (error) {
    console.error('Connection failed:', error);
  }
};
handleMint(type: string)

Handles the minting process for the specified type using the currently connected wallet address. Supported type values: kyc_binance, kyc_bithumb, kyc_upbit, kyc_coinbase, kyc_okx, kyc_bybit.

const handleMintPassport = async () => {
  try {
    const receipt = await handleMint('kyc_okx');
    console.log('Mint successful:', receipt);
  } catch (error) {
    console.error('Mint failed:', error);
  }
};

Error Handling

The hook provides comprehensive error handling for various scenarios:

  • Wallet not installed
  • Network switching failures
  • Transaction rejections
  • Contract interaction errors

Example error handling:

try {
  await connect();
} catch (error: any) {
  if (error.code === 4001) {
    console.error('User rejected the connection');
  } else if (error.code === 4902) {
    console.error('Network not found');
  } else {
    console.error('Connection error:', error);
  }
}

Hooks

useAttestationQueries

A React hook for querying attestation data with wallet connection and network switching capabilities.

Features

  • Wallet connection management
  • Network switching
  • Attestation data querying
  • Account and network change event handling

Usage

import { useAttestationQueries } from 'bnb-passport-attestation';

function MyComponent() {
  const {
    getUserAttestedSchemas,
    getUserLastAttestationRecord,
    isLoading,
    account,
    connect,
    isConnected,
    currentNetwork,
    isCorrectNetwork
  } = useAttestationQueries({
    env: 'testnet' // or 'mainnet'
  });

  // Query user's attested schemas
  const handleQuerySchemas = async () => {
    try {
      const schemas = await getUserAttestedSchemas(account!);
      console.log('User attested schemas:', schemas);
    } catch (error) {
      console.error('Query failed:', error);
    }
  };

  // Query user's last attestation record
  const handleQueryLastRecord = async () => {
    try {
      const [record, exists] = await getUserLastAttestationRecord(account!, 'schemaId');
      if (exists) {
        console.log('Last attestation record:', record);
      } else {
        console.log('No attestation record found');
      }
    } catch (error) {
      console.error('Query failed:', error);
    }
  };

  return (
    <div>
      {!isConnected ? (
        <button onClick={connect}>Connect Wallet</button>
      ) : (
        <div>
          <p>Current Account: {account}</p>
          <p>Current Network: {currentNetwork}</p>
          <button onClick={handleQuerySchemas}>Query Attested Schemas</button>
          <button onClick={handleQueryLastRecord}>Query Last Record</button>
        </div>
      )}
    </div>
  );
}

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | env | 'mainnet' | 'testnet' | 'testnet' | Network environment |

Return Value

| Property | Type | Description | |----------|------|-------------| | getUserAttestedSchemas | (user: string) => Promise<string[]> | Get all attested schemas for a user | | getUserAttestedSchemasInGivenSchemaSet | (user: string, schemas: string[]) => Promise<string[]> | Get user's attested schemas within a given schema set | | getUserLastAttestationRecord | (user: string, schemaId: string) => Promise<[AttestationRecord, boolean]> | Get user's last attestation record | | userFinishedAllAttestation | (user: string, schemas: string[]) => Promise | Check if user has completed all attestations | | userFinishedAllAttestationsAfter | (user: string, schemas: string[], timestamp: number) => Promise | Check if user has completed all attestations after a timestamp | | userFinishedOneOfAttestation | (user: string, schemas: string[]) => Promise | Check if user has completed at least one attestation | | userFinishedOneOfAttestationAfter | (user: string, schemas: string[], timestamp: number) => Promise | Check if user has completed at least one attestation after a timestamp | | switchNetwork | (network: EnvType) => Promise | Switch network | | currentNetwork | string | Current network | | isCorrectNetwork | boolean | Whether connected to the correct network | | isLoading | boolean | Loading state | | error | Error | null | Error information | | account | string | null | Currently connected account address | | isConnected | boolean | Whether wallet is connected | | connect | () => Promise | Connect wallet |

AttestationRecord Type

| Property | Type | Description | |----------|------|-------------| | attestation_id | string | Attestation ID | | proof_hash | string | Proof hash | | timestamp | number | Timestamp | | _type | number | Attestation type |

Development

Prerequisites

  • Node.js >= 14
  • npm or yarn

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
  3. Start development server:
    npm run dev

Available Scripts

  • npm run build - Build the project
  • npm run dev - Start development server
  • npm run test - Run tests
  • npm run lint - Run linter
  • npm run format - Format code

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

  • Documentation: [Link to documentation]
  • Community Support: [Link to community]
  • Issue Tracking: [Link to issues]

License

This project is licensed under the MIT License - see the LICENSE file for details.