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

xian-js

v0.1.7

Published

javascript tools for interacting with the Xian blockchain.

Downloads

16

Readme

xian-js

Tools for interacting with the Xian blockchain

Installation

npm install xian-js

Wallet Functions

Create a Xian Keypair

import Xian from "xian-js"

// Create a new wallet
const new_wallet = Xian.Wallet.new_wallet()

console.log(new_wallet)

>>  {
        vk: "ea2cee33f9478d767d67afe345592ef36446ee04f8d588fa76942e6569a53298",
        sk: "69a8db3fb7196debc2711fad1fa1935918d09f5d8900d84c3288ea5237611c03"
    }

Create a new BIP39 / BIP 32 compatible wallet

  • BIP39 = 24 word mnemonic
  • BIP32 = derivation path
let new_wallet_bip39 = Xian.Wallet.new_wallet_bip39()

console.log(new_wallet_bip39)
>> {
       sk: 'a6b72cb3d1160c26f9f39a8f1d4a3c7c0da2ac59d193b66ac5f919ec77f28915',
       vk: '53d016586ce35c5f6ea581cadf4693dd2850621dfad6a2261e8dd311c83e11d5',
       derivationIndex: 0,
       seed: '3626c59ee5bce833a8bf5024645eb10415b39c6f9fd0ff0fb1b00b8ca9fd6ff4b8a0ed7077296cdaff1b955f03318f244dfd3fead404d93f11a3f301c0e3e1c6',
       mnemonic: 'evidence rifle behave normal duty mean junk chicken salute relief raw chunk region ocean guard swarm taste toy loop ozone spell crumble apart echo'
   }

Create a wallet from sk (private key)

const sk = 'a6b72cb3d1160c26f9f39a8f1d4a3c7c0da2ac59d193b66ac5f919ec77f28915'

const wallet = Xian.Wallet.create_wallet({sk})

console.log(wallet)

>> {
       sk: 'a6b72cb3d1160c26f9f39a8f1d4a3c7c0da2ac59d193b66ac5f919ec77f28915',
       vk: '53d016586ce35c5f6ea581cadf4693dd2850621dfad6a2261e8dd311c83e11d5',
       derivationIndex: 0,
       seed: null,
       mnemonic: null
   }

Restore a BIP39 / BIP 32 compatible wallet

  • BIP39 = 24 word mnemonic
  • BIP32 = derivation path
const seed = '3626c59ee5bce833a8bf5024645eb10415b39c6f9fd0ff0fb1b00b8ca9fd6ff4b8a0ed7077296cdaff1b955f03318f244dfd3fead404d93f11a3f301c0e3e1c6'
const derivationIndex = 0;
let wallet = Xian.Wallet.new_wallet_bip39(seed, derivationIndex)

console.log(wallet)
>> {
       sk: 'a6b72cb3d1160c26f9f39a8f1d4a3c7c0da2ac59d193b66ac5f919ec77f28915',
       vk: '53d016586ce35c5f6ea581cadf4693dd2850621dfad6a2261e8dd311c83e11d5',
       derivationIndex: 0,
       seed: null,
       mnemonic: null
   }

Get a public key (vk) from a private key (sk)

Takes the sk as an argument and returns the vk

let sk = "69a8db3fb7196debc2711fad1fa1935918d09f5d8900d84c3288ea5237611c03"
let vk = wallet.get_vk(sk)

console.log(vk)
>> 'ea2cee33f9478d767d67afe345592ef36446ee04f8d588fa76942e6569a53298'

Sign a message

Signs a string payload

const stringBuffer = Buffer.from('message')
let messageBytes = new Uint8Array(stringBuffer);
let sk = "69a8db3fb7196debc2711fad1fa1935918d09f5d8900d84c3288ea5237611c03"

let signedMessage = wallet.sign(sk, messageBytes)

console.log(signedMessage)
>> '982c204fe88e620f3319558aa6b11f9d8be75b99b3199f434f5edf2834a9c52059ba4ea3d623ac1d550170e532e919c364aad1333f757f8f22e0355cb1dd8c09'

Verify signature

verify a payload

let validSignature = wallet.verify(vk, messageBytes, signedMessage)

console.log(validSignature)
>> true

Create a Xian Transaction

Public Testnet masternode host is https://testnet.xian.org

Use Xian.TransactionBuilder(network_info, tx_info) to create a new Xian transaction.

Create network_info object

create an object that describes the masternode/network that you are going to send the transcation to.


let network_info: I_NetworkSettings = {
    chain_id: "xian-testnet-2",
    type: "testnet", // or "mainnet"
    masternode_hosts: ["https://testnet.xian.org"]
};
// Sender and Receiver public keys
let senderVk = "ea2cee33f9478d767d67afe345592ef36446ee04f8d588fa76942e6569a53298"
let receiverVk = "bb0fab41b9118f0afdabf3721fa9a6caae3c93845ed409d3118841065ad1a197"

// Kwargs are the arugments you will send the contract method.  
// For example the "currency" contract's "transfer" method needs two arguments to create a transfter; the person reciving the XIAN and the amount to transfer.  So we create a kwargs object like so.
let kwargs = {
        to: receiverVk,
        amount: 1000
}

let txInfo: I_TxInfo = {
    senderVk,
    contractName: "currency",
    methodName: "transfer",
    kwargs,
    stampLimit: 50000, // Max stamps to be used. Could use less, won't use more.
}

Create transaction

let tx = new Xian.TransactionBuilder(networkInfo, txInfo)

Send transaction

let senderSk = "69a8db3fb7196debc2711fad1fa1935918d09f5d8900d84c3288ea5237611c03"

const res = await tx.send(senderSk)