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

zixo-wallet

v0.0.2-beta.2

Published

zixo wallet api with support payment channel

Downloads

11

Readme

zixo bsv wallet api

The official low-level zixo client for Node.js and the browser.

Features

  • One-to-one mapping with REST API and the other official clients
  • Generalized, pluggable architecture. See Extending Core Components
  • Configurable, automatic discovery of cluster nodes
  • Persistent, Keep-Alive connections
  • Load balancing (with pluggable selection strategy) across all available nodes.

Use in Node.js

npm install zixo-wallet-api

Use in the Browser

npm install zixo-wallet-api

Docs

Questions?

You can probably find help in #wallet on zixo.

Examples

Create a wallet for first use.

const zwa = require('zixo-wallet-api');
const client = new zixo.Client({
  network: 'test', //bsv network
});
client.create("[email protected]","your-user-name","your-password")
	.then(createResult=>{
		console.log(createResult);
	});

Response:

{
	"token":"xxxxxxxxxxxxxxxxxx",
	"mnemonic":"12 words for recovery your wallet"
}	

Login to wallet

client.login("your-email-or-username","your-password")
	.then(loginResult=>{
		console.log(loginResult);
	});

Response:

{
	"token":"xxxxxxxxxxxxxxxxxx"	
}	

Create a client instance with stored token

const client = new zixo.Client({
  host: 'test',
  token: 'xxxxxxxxxxxxxxxxxxxxxxxx'
});

Get deposite address

client.receiveAddress()
	.then(addressResult=>{
		console.log(addressResult);
	});

Response:

{
	"address":"18EymorX4Zqq56MF3tCaKerkQf118uymDf"
}	

Get wallet balance

client.balance()
	.then(balanceResult=>{
		console.log(balanceResult);
	});

Rsponse:

{
	"summery": {
		"confirmed": 38080,
		"unconfirmed": 0
	}
}	

Send to an address

client.send("1HDvABd9bGu2x4KTujebbDP6UX6sZPwWPy",0.01,"USD")
	.then(sendResult=>{
		console.log(sendResult);
	});

Response:

{
	"txId":"4752abb0b1e43f066e92ed1bc6c3d6dc4e1a7059b7a492eae0bc24590875be59",
	"destAddress":"1HDvABd9bGu2x4KTujebbDP6UX6sZPwWPy",
	"satoshis":10000
}	

Histories of transactions

client.history(0,2)
	.then(historyResult=>{
		console.log(historyResult);
	});

Response:

{
   "total": 14,
   "results": [
       {
			"txId": "c345cb3fbdc57930e494f1960cad6e79e09c88d106604bb3149773c7d428ce16",
			"satoshis": -2000,
			"date": "2020-05-31T13:20:45.573Z"
        },
        {
            "txId": "c90f557fce4c5bb1d5b9fef771bd30f41c190a1142e57bbee8393bcd175beba2",
            "satoshis": 3700,
            "date": "2020-05-31T12:41:34.589Z"
        }
    ]
}

Create a new channel

NOTICE that we have two type of clients in a channel

  • Customer who create a channel
  • Provider who join the channel
client.createChannel(0.01,"USD",3600)
	.then(channelResult=>{
		console.log(sendResult);
	});

Response:

{
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 10000,
    "lockSeconds": 3600
}	

Get channel

client.getChannel("932c9fb9a89c25f919722c48e2d6dc14")
	.then(channelResult=>{
		console.log(sendResult);
	});

Response:

{
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 10000,
    "lockSeconds": 3600
}	

Join the channel

const partners = [{address:"first-prtner-address", percentage:20}];
//If you don't have any partner, then you can ignore the partners
// In this case, after closing the channel, 80% send to you and 20% send to first partner
client.joinChannel("932c9fb9a89c25f919722c48e2d6dc14", partners)
	.then(joinResult=>{
		console.log(joinResult);
	});

Response:

{
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "guaranteeTxId": "20ec95f1c59f13f4b0f146b6a5fb70e69df2043aaca8a215c820e586b046a7ed",
    "satoshis": 10000,
    "lockedUntil": 1591111074000
}	

Start the payment on the channel

Make an invoice

client.makeInvoice("932c9fb9a89c25f919722c48e2d6dc14",0.005,"USD","content 1")
	.then(invoiceResult=>{
		console.log(invoiceResult);
	});

Response:

{
    "paymentId": "bd0e89bd90fa9531b952c73a7af3c960",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 2000,
    "sumSatoshis": 2000,
    "date": "2020-06-02T16:20:03.940Z"
}

Make another invoice (more than once)

client.makeInvoice("932c9fb9a89c25f919722c48e2d6dc14",0.0035,"USD","content 2")
	.then(invoiceResult=>{
		console.log(invoiceResult);
	});

Response:

{
    "paymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 1500,
    "sumSatoshis": 3500,
    "date": "2020-06-02T16:21:46.733Z"
}

Pay the invoice

client.payToChannel("932c9fb9a89c25f919722c48e2d6dc14","bd0e89bd90fa9531b952c73a7af3c960")
	.then(payResult=>{
		console.log(payResult);
	});

Response:

{
    "paymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "satoshis": 1500,
    "sumSatoshis": 3500,
    "date": "2020-06-02T16:21:46.733Z"
}

NOTICE that if customer make an invoice, it doesn`t need to call payToChannel.

Get payment

client.getPayment("932c9fb9a89c25f919722c48e2d6dc14","bd0e89bd90fa9531b952c73a7af3c960")
	.then(payResult=>{
		console.log(payResult);
	});

Response:

{
    "paymentId": "bd0e89bd90fa9531b952c73a7af3c960",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "lastChannelPaymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "satoshis": 2000,
    "sumSatoshis": 2000,
    "date": "2020-06-02T16:20:03.940Z"
}

Close channel

client.closeChannel("932c9fb9a89c25f919722c48e2d6dc14")
	.then(closeResult=>{
		console.log(closeResult);
	});

Response:

{
    "paymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "channelId": "932c9fb9a89c25f919722c48e2d6dc14",
    "lastChannelPaymentId": "9a2ae7b48eebe5d950ed468ce4f48885",
    "sumSatoshis": 3500,
    "date": "2020-06-02T16:21:46.733Z"
}

More examples and detailed information about each method are available here

License

This software is licensed under the Apache 2 license, quoted below.

Copyright (c) 2014 Elasticsearch <http://www.elasticsearch.org>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.