Permalink
Browse files

Initial commit.

  • Loading branch information...
karmacoma committed Jan 11, 2016
0 parents commit 0ace4cc1cbfaa551aae08e2b36adbbcfe9d69a1d
@@ -0,0 +1,4 @@
.DS_Store
.idea
node_modules
npm-debug.log
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Lisk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,78 @@
# Lisk JS

A client-side transactions library for [Lisk](https://lisk.io/). Allows transactions to be sent from within the browser, using a simple API.

## Installation

```
npm install lisk-js
```

## Tests

```
npm test
```

Tests written using mocha + schedule.js.

## Usage

Each function call has **secondSecret** parameter, this parameter is optional.

### Create transaction

Send 1000 LISK to 1859190791819301C

```js
var lisk = require('lisk-js');
var transaction = lisk.transaction.createTransaction("1859190791819301C", 1000, "secret", "secondSecret");
```

### Create second signature transaction

```js
var lisk = require('lisk-js');
var transaction = lisk.transaction.createTransaction("secret", "secondSecret");
```

### Create delegate transaction

```js
var lisk = require('lisk-js');
var transaction = lisk.transaction.createDelegate("secret", "username", "secondSecret");
```

### Create vote transaction


```js
var lisk = require('lisk-js');
var transaction = createVote("secret", ["+58199578191950019299181920120128129"], "secondSecret");
```

### Peers Communication

All transactions are sent to `/api/peer/transactions` using the `POST` method.

Example:

```js
Method: POST
Content-Type: application/json
{
"transaction" : {
...
}
}
```

## Authors

- Boris Povod <boris@crypti.me>
- Olivier Beddows <olivier@lisk.io>

## License

MIT
@@ -0,0 +1,9 @@
module.exports = {
transaction : require("./lib/transactions/transaction.js"),
signature : require("./lib/transactions/signature.js"),
delegate : require("./lib/transactions/delegate.js"),
vote : require("./lib/transactions/vote.js"),
crypto : require("./lib/transactions/crypto.js"),
username: require('./lib/transactions/username.js'),
contact: require('./lib/transactions/contact.js')
}
@@ -0,0 +1,64 @@
function getEpochTime(time) {
if (time === undefined) {
time = (new Date()).getTime();
}
var d = beginEpochTime();
var t = d.getTime();
return Math.floor((time - t) / 1000);
}

function beginEpochTime() {
var d = new Date(Date.UTC(2015, 3, 9, 0, 0, 0, 0));

return d;
}

var interval = 10,
delegates = 11;

function getTime(time) {
return getEpochTime(time);
}

function getRealTime(epochTime) {
if (epochTime === undefined) {
epochTime = getTime()
}
var d = beginEpochTime();
var t = Math.floor(d.getTime() / 1000) * 1000;
return t + epochTime * 1000;
}

function getSlotNumber(epochTime) {
if (epochTime === undefined) {
epochTime = getTime()
}

return Math.floor(epochTime / interval);
}


function getSlotTime(slot) {
return slot * interval;
}

function getNextSlot() {
var slot = getSlotNumber();

return slot + 1;
}

function getLastSlot(nextSlot) {
return nextSlot + delegates;
}

module.exports = {
interval: interval,
delegates: delegates,
getTime: getTime,
getRealTime: getRealTime,
getSlotNumber: getSlotNumber,
getSlotTime: getSlotTime,
getNextSlot: getNextSlot,
getLastSlot: getLastSlot
}
@@ -0,0 +1,34 @@
var crypto = require('./crypto.js'),
slots = require('../time/slots.js');

function createContact(secret, address, secondSecret) {
var keys = crypto.getKeys(secret);

var transaction = {
type: 5,
amount: 0,
fee: 1 * Math.pow(10, 8),
recipientId: null,
senderPublicKey: keys.publicKey,
timestamp: slots.getTime(),
asset: {
contact: {
address: address
}
}
};

crypto.sign(transaction, keys);

if (secondSecret) {
var secondKeys = crypto.getKeys(secondSecret);
crypto.secondSign(transaction, secondKeys);
}

transaction.id = crypto.getId(transaction);
return transaction;
}

module.exports = {
createContact : createContact
}
Oops, something went wrong.

0 comments on commit 0ace4cc

Please sign in to comment.