Blockin
  • Blockin Overview
  • How Does It Work?
  • Developer Docs
    • Core Concepts
    • Getting Started
      • 🖊️User Signatures
      • 🖥️Sign In with BitBadges
      • 🆔Verification
      • 📤ChainDrivers
        • Setting Chain Drivers
        • Chain Driver Interface
        • Implementing a New Chain Driver
        • List of Implemented Chain Drivers
          • EthDriver
          • SolDriver
          • CosmosDriver
          • BtcDriver
          • AlgoDriver
    • Library Documentation
Powered by GitBook
On this page
  • Installation and Initialization
  • Signatures
  • BitBadges
  • Scheme
  • Ownership Times
  • Snapshots
  1. Developer Docs
  2. Getting Started
  3. ChainDrivers
  4. List of Implemented Chain Drivers

CosmosDriver

This page describes documentation specific to the Cosmos ChainDriver named as CosmosDriver created by the Blockin team.

Installation and Initialization

First, npm install blockin-cosmos-driver

Then, import via import CosmosDriver from 'blockin-cosmos-driver';

To initialize a new instance, run:

const CosmosDriver = new CosmosDriver(CHAIN_ID);

Signatures

See here for an example of implementing signatures in a compatible format using Keplr.

const signChallenge = async (message: string) => {
    let sig = await window.keplr?.signArbitrary("bitbadges_1-2", cosmosAddress, message);

    if (!sig) sig = { signature: '', pub_key: { type: '', value: '' } };

    const signatureBuffer = Buffer.from(sig.signature, 'base64');
    const uint8Signature = new Uint8Array(signatureBuffer); // Convert the buffer to an Uint8Array
    const pubKeyValueBuffer = Buffer.from(sig.pub_key.value, 'base64'); // Decode the base64 encoded value
    const pubKeyUint8Array = new Uint8Array(pubKeyValueBuffer); // Convert the buffer to an Uint8Array

    const isRecovered = verifyADR36Amino('cosmos', cosmosAddress, message, pubKeyUint8Array, uint8Signature, 'secp256k1');
    if (!isRecovered) {
      throw new Error('Signature verification failed');
    }

    return {
      message: message,
      signature: sig.signature,
      publicKey: sig.pub_key.value,
    }
  }

BitBadges

This driver is compatible with BitBadges and querying badge ownership.

Note to use the BitBadges API and query badges, you must set a valid environment variable for process.env.BITBADGES_API_KEY.

Scheme

For BitBadges, we use the collection ID the collectionId.

BitBadges assetIds must be in the form of [{ start: 1, end: 10 }, ....]

ownershipTimes (if blank, we query current time) can either be a valid JS Date string or in UNIX milliseconds via [{ start: 1, end: 1000000 }]

{
  collectionId: 1,
  assetIds: [{ start: 1, end: 1 }],
  mustOwnAmounts: [{ start: 0, end: 0 }],
  chain: 'BitBadges',
}

Ownership Times

To actually query if they owned at the current time, you must query the blockchain state at that time or provide a snapshot of it at that time. This is not supported currently.

Snapshots

PreviousSolDriverNextBtcDriver

Last updated 1 year ago

For BitBadges, we support checking ownership time via their time-based balances feature. Note this is an ownership rights feature, it queries if the user has ownership rights for time XYZ currently, not that they had rights at time XYZ for time XYZ. See .

You can provide snapshots for BitBadges badges via the verifyChallenge options. Snapshot maps are expected to be in the form of . See .

📤
here
OffChainBalancesMap<NumberType>
https://bafybeiejae7ylsndxcpxfrfctdlzh2my7ts5hk6fxhxverib7vei3wjn4a.ipfs.dweb.link/