GithubHelp home page GithubHelp logo

sunjunwei11 / dotbit.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotbithq/dotbit.js

0.0 1.0 0.0 309 KB

The ultimate JavaScript SDK for .bit

Home Page: https://did.id

License: MIT License

JavaScript 5.15% TypeScript 94.40% HTML 0.45%

dotbit.js's Introduction

dotbit: .bit JavaScript SDK

NPM npm

A complete .bit SDK and utilities in JavaScript (and TypeScript).

This is the new version of .bit (Previously DAS) JavaScript SDK. If you are looking for the source code of npm package das-sdk(Deprecated), please check out the branch das-sdk.

Features

  • Query .bit account info, including owner, manager, status, and more.
  • Query .bit account records, including addresses, profiles, dwebs and custom data.
  • Enable .bit SubDID for a specific account.
  • Mint a SubDID of a .bit main account.
  • Query all the SubDIDs of a .bit main account.
  • Manage the ownership of a .bit account(SubDID included).
  • Manage the records of a .bit account(SubDID included).
  • Register a .bit account with CKB. (Coming soon)

Installation

npm install dotbit --save

QuickStart

Query users' addresses

// import { createInstance } from 'dotbit' // For ES Module
const { createInstance } = require('dotbit')
const dotbit = createInstance()

// Get all `eth` addresses of a .bit account
dotbit.addrs('imac.bit', '60').then(console.log)  // Result is the same as below, using coin_type
dotbit.addrs('imac.bit', 'eth').then(console.log)

Developers are encouraged to use coin_type instead of plain symbol like 'eth' as coin_type is a more standard way to identify a chain/coin, and there will only be coin_type on chain in the future. What is coin_type

Query other different records:

// Get `twitter` account of a .bit account
dotbit.profiles('imac.bit', 'twitter').then(console.log)

// Get all `dwebs` of a .bit account
dotbit.dwebs('imac.bit').then(console.log)

// Get all .bit account records, please only use it when necessary.
dotbit.records('imac.bit').then(console.log)

Query .bit Alias(Reverse Record)

⚠️Notice: Only when .bit alias is set at https://app.did.id/alias by user, reverse record is valid.

const account = await dotbit.reverse({
  key: '0x1D643FAc9a463c9d544506006a6348c234dA485f',
  coin_type: '60', // See FAQ below to get the defination of coin_type
})
console.log(account.account) // jeffx.bit

Query the accounts that an owner address is holding

const accounts = await dotbit.accountsOfOwner({
    key: '0x1d643fac9a463c9d544506006a6348c234da485f',
    coin_type: '60', // See FAQ below to get the defination of coin_type
})

console.log(accounts[0].account) // thefirst💯registeredbydevteamtoensuredassuccessfullylaunched10.bit

Mint a SubDID in testnet:

Currently, SubDID is fully available in testnet, and need whitelist on mainnet. If you would like to distribute SubDIDs on mainnet, please email [email protected] with a brief description of your project.

// import { createInstance, ProviderSigner, BitNetwork } from 'dotbit' // For ES Module
const { createInstance, ProviderSigner, BitNetwork } = require('dotbit')

const signer = new ProviderSigner(window.ethereum)
const dotbit = createInstance({
  network: BitNetwork.testnet,
  signer
})

const bitAccount = dotbit.account('imac.bit')

bitAccount.mintSubAccount({
  account: '001.imac.bit',
  keyInfo: {
    key: '0x...',
    coin_type: '60', // See FAQ below to get the defination of coin_type
  },
  registerYears: 1,
}).then(console.log)

For more complete usages, please check out the examples: For browser, For Node.js.

Plugins

.bit has partnerships with the greatest teams & projects in the ecosystems.

dotbit.js provided a simple yet powerful plugin system, with which we can add more powerful features to this library.

Usage

Basically, you can install and use a plugin like the codes below.

import { PluginXXX } from 'dotbit-plugin-xxx'
import { createInstance } from 'dotbit'

const dotbit = createInstance()
dotbit.installPlugin(new PluginXXX())
dotbit.methodAddedByXXX()

For detailed usage, please follow the instructions in the specific plugin's README.

List of plugins

Write your own plugin

Write a plugin for .bit is easy!

If you want to write a plugin for your or other projects, please follow the same structure of plugin template.

FAQ

What is coin_type?

coin_type is the Coin Types defined in slip44 to distinguish different Coins/Chains.

For example, 60 is the coin_type of ETH, 0 is the coin_type of BTC, 714 is the coin_type of BNB, etc.

Which coin_type does .bit support?

.bit use coin_type in multiple ways, here are 2 mainly usages:

  • .bit use coin_type to identify each chain/coin in .bit records. In this situation, .bit support all coin_type defined in slip44.
  • .bit use coin_type to identify different types of owner/manager key info. You can use ETH address(coin_type: 60) as your .bit owner and TRON address(coin_type: 195) as your manager. For all coin_type that .bit supported in key_info, please check const.ts

Get help

Please join our Discord channel, or raise an issue: Issues

Contribute

This SDK is still under heavily development. Any contribution including PR is welcome.

Please raise an issue if you find any bugs or have any suggestions.

License

MIT License (including all dependencies).

dotbit.js's People

Contributors

zgayjjf avatar web3max avatar vecpeng avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.