Skip to content

Commit

Permalink
Bring back methods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed May 11, 2019
1 parent a247d69 commit e2ab760
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const repl = require("repl")
const BITBOX = require("./lib/BITBOX").BITBOX
const clone = require("git-clone")

program.version("7.0.17 ", "-v, --version")
program.version("7.0.18 ", "-v, --version")

program
.command("new <name>")
Expand Down
11 changes: 11 additions & 0 deletions lib/BitcoinCash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface BitcoinCash {
_address: any
toSatoshi(coins: number): number
toBitcoinCash(satoshis: number): number
toBits(satoshis: number): number
satsToBits(satoshis: number): number
signMessageWithPrivKey(privateKeyWIF: string, message: string): string
verifyMessage(address: string, signature: string, message: string): boolean
encodeBase58Check(hex: string): string
Expand Down Expand Up @@ -71,6 +73,15 @@ export class BitcoinCash implements BitcoinCash {
return sb.toBitcoin(satoshis)
}

toBits(satoshis: number): number {
return satoshis / 100
}

// Translate satoshi to bits denomination
satsToBits(satoshis: number): number {
return satoshis / 100
}

// sign message
signMessageWithPrivKey(privateKeyWIF: string, message: string): string {
const network: string =
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitbox-sdk",
"version": "7.0.17",
"version": "7.0.18",
"description": "BITBOX SDK for Bitcoin Cash",
"author": "Gabriel Cardona <[email protected]>",
"contributors": [
Expand Down
22 changes: 22 additions & 0 deletions test/unit/BitcoinCash.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ describe("#BitcoinCash", () => {
})
})

describe("#satsToBits", () => {
fixtures.conversion.satsToBits.bch.forEach(bch => {
it(`should convert ${bch[0]} BCH to ${bch[1]} bits`, () => {
assert.equal(
bitbox.BitcoinCash.satsToBits(bitbox.BitcoinCash.toSatoshi(bch[0])),
bch[1]
)
})
})

fixtures.conversion.satsToBits.strings.forEach(bch => {
it(`should convert "${bch[0]}" BCH as a string to ${
bch[1]
} bits`, () => {
assert.equal(
bitbox.BitcoinCash.satsToBits(bitbox.BitcoinCash.toSatoshi(bch[0])),
bch[1]
)
})
})
})

describe("sign and verify messages", () => {
describe("#signMessageWithPrivKey", () => {
fixtures.signatures.sign.forEach(sign => {
Expand Down

0 comments on commit e2ab760

Please sign in to comment.