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

@moosty/lisk-htlc

v0.1.2

Published

Hashed Time Lock Contract transaction for Lisk SDK based blockchain applications

Downloads

31

Readme

Lisk Hash Time Locked Contract transaction

Build Status Coverage Status Dependencies Status DeepScan grade Lisk SDK Status License: GPL v3

Simpely add this transaction to your Lisk SDK based blockchain application. It allows for atomic swap between other blockchains that allow atomic swap by using Hash Time Locked Contracts.

This is by no means meant to support the production phase yet.

How does it work

Send an amount of token, from your wallet on a blockchain application made with the Lisk SDK, to a hash time locked contract using this custom transaction HTLC-transaction. After successfully completing the HTLC-Transaction the amount will be locked inside the contract wallet. To redeem the locked amount, the recipient can unlock the HTLC by sending the HTLC-transaction to the contract wallet with the secret included. If the secret is valid and the transaction is not timed out, the locked funds in the contract wallet will be send to the recipient wallet. If the contract is expired, the initial creator of the contract can send a refund HTLC-transaction to the contract wallet and will receive the funds minus the initial fees back.

Installation

npm install --save @moosty/lisk-htlc

or

yarn add @moosty/lisk-htlc

Usage

Register the transaction to your blockchain application.

import { HTLCTransaction } from '@moosty/lisk-htlc';

App.registerTransaction(HTLCTransaction);

Configure the transaction fee and register the HTLC-transaction to your blockchain application.

import { UnConfigureHTLCTransaction } from '@moosty/lisk-htlc';

const HTLCTransaction = UnConfigureHTLCTransaction({ fee: '500000000' });
App.registerTransaction(HTLCTransaction);

The HTLC transaction is a combination of three sub-transactions.

  1. Lock contract transaction
  2. Redeem contract transaction
  3. Refund contract transaction

Examples

Lock contract transaction

import { HTLCTransaction } from '@moosty/lisk-htlc';
const LockContractTransaction = new HTLCTransaction({
  "passphrase": string, // string passphrase from senderId
  "type": 199,
  "timestamp": number,
  "asset": {
     "time": number,
     "recipientPublicKey": "", // string recipient publicKey
     "type": "", // string [ OP_HASH160 | OP_HASH256 ]
     "data": "", // string preimage hash
     "secretLength": number, // number length preimage
     "amount": "", // string amount to be locked
  },
  "networkIdentifier": "" // string network Identifier
});

// broadcast LockContractTransaction.toJSON() to blockchain application nodes

Redeem contract transaction

import { HTLCTransaction } from '@moosty/lisk-htlc';
const RedeemContractTransaction = new HTLCTransaction({
  "passphrase": string, // string passphrase from recipientId
  "type": 199,
  "timestamp": number,
  "asset": {
     "contractId": "", // string contractId
     "secret": "", // string preimage
  },
  "networkIdentifier": "" // string network Identifier
});

// broadcast RedeemContractTransaction.toJSON() to blockchain application nodes

Refund contract transaction

import { HTLCTransaction } from '@moosty/lisk-htlc';
const RefundContractTransaction = new HTLCTransaction({
  "passphrase": string, // string passphrase from senderId
  "type": 199,
  "timestamp": number,
  "asset": {
     "contractId": "", // string contractId
     "data": "", // string preimage
  },
  "networkIdentifier": "" // string network Identifier
});

// broadcast RefundContractTransaction.toJSON() to blockchain application nodes

Todos

- [X] Configurable fee amount
- [ ] Better determanistic time lock
- [ ] Documentation
- [ ] Live chain tests

Use case

The HTLC-transaction functions as a interoperability option to transfer tokens between different blockchain applications. The transaction can facilitate Atomic Swaps between different blockchain tokens. To help better adoption of this transaction we are building a decentralized exchange to help connect users from different blockchain applications. Atomic Swap between your Lisk SDK based blockchain application and Bitcoin, Ethereum or any other Lisk SDK based blockchain with the lisk-htlc transaction is coming soon with Mercator.network.

License

Copyright © 2019 - 2020 Moosty Team

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.