Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytyr committed Oct 17, 2017
0 parents commit 7425c3e
Show file tree
Hide file tree
Showing 12 changed files with 3,300 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Waves Node JS API
=====

A library to use [Waves](wavesplatform.com) blockchain from node.js based on [WavesDevKit](https://github.com/wavesplatform/WavesDevKit)

## Getting started
```bash
npm install waves-nodejs --save
```

## REST Methods
### Send asset transaction to a node
```javascript
var Waves = require('waves-nodejs');

Waves.api.sendAsset(
'https://stats.arker.io/',
'API KEY (optional)',
'assetId',
'seed',
'recipient address',
1 // amount
).then(function(data) {
console.log(data);
}, function(err) {
console.error(err);
});
```

## API Methods
```javascript
var Waves = require('waves-nodejs');

Waves.getPublicKey(secretPhrase);

Waves.getPrivateKey(secretPhrase);

Waves.appendUint8Arrays(array1, array2);

Waves.appendNonce(originalSeed);

Waves.keccakHash(messageBytes);

Waves.blake2bHash(messageBytes);

Waves.hashChain(noncedSecretPhraseBytes);

Waves.sign(privateKey, dataToSign);

Waves.buildAccountSeedHash(seedBytes);

Waves.buildPublicKey(seedBytes);

Waves.buildPrivateKey(seedBytes);

Waves.shortToByteArray(value);

Waves.byteArrayWithSize(byteArray);

Waves.base58StringToByteArray(base58String);

Waves.longToByteArray(value);

Waves.signatureAssetData(senderPublicKey, assetId, feeAssetId, timestamp, amount, fee, recipient, attachment);
```
## TODO

Add all REST API methods
28 changes: 28 additions & 0 deletions http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

var request = require('request');

var http = {};

http.post = function(url, headers, body) {
return new Promise(function(resolve, reject) {
var options = {
url: url,
headers: headers,
body: body
};

function callback(error, response, body) {
if (!error && (response.statusCode == 200 || response.statusCode == 201)) {
resolve(JSON.parse(body));
} else {
reject(body);
}
}

request.post(options, callback);
});

}

module.exports = http;
101 changes: 101 additions & 0 deletions lib/base58.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Taken from https://github.com/45678/Base58
// Generated by CoffeeScript 1.8.0
(function() {
var ALPHABET, ALPHABET_MAP, Base58, i;

Base58 = (typeof module !== "undefined" && module !== null ? module.exports : void 0) || (window.Base58 = {});

ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

ALPHABET_MAP = {};

i = 0;

while (i < ALPHABET.length) {
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
i++;
}

Base58.encode = function(buffer) {
var carry, digits, j;
if (buffer.length === 0) {
return "";
}
i = void 0;
j = void 0;
digits = [0];
i = 0;
while (i < buffer.length) {
j = 0;
while (j < digits.length) {
digits[j] <<= 8;
j++;
}
digits[0] += buffer[i];
carry = 0;
j = 0;
while (j < digits.length) {
digits[j] += carry;
carry = (digits[j] / 58) | 0;
digits[j] %= 58;
++j;
}
while (carry) {
digits.push(carry % 58);
carry = (carry / 58) | 0;
}
i++;
}
i = 0;
while (buffer[i] === 0 && i < buffer.length - 1) {
digits.push(0);
i++;
}
return digits.reverse().map(function(digit) {
return ALPHABET[digit];
}).join("");
};

Base58.decode = function(string) {
var bytes, c, carry, j;
if (string.length === 0) {
return new (typeof Uint8Array !== "undefined" && Uint8Array !== null ? Uint8Array : Buffer)(0);
}
i = void 0;
j = void 0;
bytes = [0];
i = 0;
while (i < string.length) {
c = string[i];
if (!(c in ALPHABET_MAP)) {
throw "Base58.decode received unacceptable input. Character '" + c + "' is not in the Base58 alphabet.";
}
j = 0;
while (j < bytes.length) {
bytes[j] *= 58;
j++;
}
bytes[0] += ALPHABET_MAP[c];
carry = 0;
j = 0;
while (j < bytes.length) {
bytes[j] += carry;
carry = bytes[j] >> 8;
bytes[j] &= 0xff;
++j;
}
while (carry) {
bytes.push(carry & 0xff);
carry >>= 8;
}
i++;
}
i = 0;
while (string[i] === "1" && i < string.length - 1) {
bytes.push(0);
i++;
}
return new (typeof Uint8Array !== "undefined" && Uint8Array !== null ? Uint8Array : Buffer)(bytes.reverse());
};

}).call(this);
Loading

0 comments on commit 7425c3e

Please sign in to comment.