Skip to content

Commit

Permalink
SLP.ECPair.toSLPAddress method and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed May 6, 2019
1 parent 37af3d8 commit bbbcea4
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const repl = require("repl")
const SLP = require("./lib/SLP")
const clone = require("git-clone")

program.version("4.0.0", "-v, --version")
program.version("4.2.0", "-v, --version")

program
.command("new <name>")
Expand Down
37 changes: 37 additions & 0 deletions lib/ECPair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
// require deps
var BITBOXECPair = require("bitbox-sdk/lib/ECPair").default;
var BITBOXSDK = require("bitbox-sdk");
var BITBOX = new BITBOXSDK();
var utils = require("slpjs").Utils;
var ECPair = /** @class */ (function (_super) {
__extends(ECPair, _super);
function ECPair() {
return _super !== null && _super.apply(this, arguments) || this;
}
ECPair.toSLPAddress = function (ecpair) {
try {
var slpAddress = utils.toSlpAddress(BITBOX.ECPair.toCashAddress(ecpair));
return slpAddress;
}
catch (err) {
return err;
}
};
return ECPair;
}(BITBOXECPair));
exports.default = ECPair;
2 changes: 2 additions & 0 deletions lib/SLP.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var __extends = (this && this.__extends) || (function () {
var BITBOXSDK = require("bitbox-sdk");
// import classes
var Address_1 = require("./Address");
var ECPair_1 = require("./ECPair");
var HDNode_1 = require("./HDNode");
var TokenType1_1 = require("./TokenType1");
var Utils_1 = require("./Utils");
Expand All @@ -31,6 +32,7 @@ var SLP = /** @class */ (function (_super) {
else
restURL = "https://rest.bitcoin.com/v2/";
_this.Address = new Address_1.default(restURL);
_this.ECPair = ECPair_1.default;
_this.HDNode = new HDNode_1.default(restURL);
_this.TokenType1 = new TokenType1_1.default(restURL);
_this.Utils = new Utils_1.default(restURL);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slp-sdk",
"version": "4.1.0",
"version": "4.2.0",
"description": "SLP SDK powered by BITBOX",
"main": "lib/SLP",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions src/ECPair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// require deps
const BITBOXECPair = require("bitbox-sdk/lib/ECPair").default
const BITBOXSDK = require("bitbox-sdk")
const BITBOX = new BITBOXSDK()
const utils = require("slpjs").Utils

class ECPair extends BITBOXECPair {
static toSLPAddress(ecpair: any): string {
try {
const slpAddress: string = utils.toSlpAddress(
BITBOX.ECPair.toCashAddress(ecpair)
)
return slpAddress
} catch (err) {
return err
}
}
}

export default ECPair
2 changes: 2 additions & 0 deletions src/SLP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IConfig } from "./interfaces/SLPInterfaces"

// import classes
import Address from "./Address"
import ECPair from "./ECPair"
import HDNode from "./HDNode"
import TokenType1 from "./TokenType1"
import Utils from "./Utils"
Expand All @@ -24,6 +25,7 @@ class SLP extends BITBOXSDK {
else restURL = "https://rest.bitcoin.com/v2/"

this.Address = new Address(restURL)
this.ECPair = ECPair
this.HDNode = new HDNode(restURL)
this.TokenType1 = new TokenType1(restURL)
this.Utils = new Utils(restURL)
Expand Down
1 change: 0 additions & 1 deletion test/Address.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use strict"
const assert = require("assert")
const slp = require("./../lib/SLP")
const SLP = new slp({
Expand Down
21 changes: 21 additions & 0 deletions test/ECPair.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fixtures = require("./fixtures/ECPair.json")
const assert = require("assert")
const assert2 = require("chai").assert
const slp = require("./../lib/SLP")
const SLP = new slp()

// Used for debugging and iterrogating JS objects.
const util = require("util")
util.inspect.defaultOptions = { depth: 1 }

describe("#ECPair", () => {
describe("#toSLPAddress", () => {
it(`should return slp address for ecpair`, async () => {
fixtures.wif.forEach((wif, index) => {
const ecpair = SLP.ECPair.fromWIF(wif)
const slpAddr = SLP.ECPair.toSLPAddress(ecpair)
assert.equal(slpAddr, fixtures.address[index])
})
})
})
})
10 changes: 10 additions & 0 deletions test/fixtures/ECPair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"wif": [
"cUCSrdhu7mCzx4sWqL6irqzprkofxPmLHYgkSnG2WaWVqJDXtWRS",
"cNVP2nTzUMFerfpjrTuDgoFGnKAfjZznKomknUVKQSdFHqK5cRc5"
],
"address": [
"slptest:qq835u5srlcqwrtwt6xm4efwan30fxg9hcqag6fk03",
"slptest:qrj9k49drcsk4al8wxn53hnkfvts6ew5jvv32952nh"
]
}

0 comments on commit bbbcea4

Please sign in to comment.