diff --git a/index.js b/index.js index 2461a5f..fc0d403 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,14 @@ let Address = { - BTC: require("./lib/btc.address"), + BTC: require("./lib/btc.series.address"), + BCH: require("./lib/btc.series.address"), + LTC: require("./lib/btc.series.address"), ETH: require("./lib/eth.address"), TRX: require("./lib/trx.address") } module.exports = class ChainAddress { constructor(coin, networkType) { + networkType = networkType || coin this.address = new Address[coin](coin, networkType) } diff --git a/test/index.test.js b/test/index.test.js index f4f65d7..304cb77 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,65 +1,55 @@ 'use strict'; let Address = require("../index") +let addrValid = require("./benchmark/address.valid") +let hdData = require("./lib/base/data").hd +let hdIndex = hdData.index +let getKeyPairTest = async (coinSymbol) => { + let chain = new Address(coinSymbol) + let {address, pri, pub} = await chain.getKeyPair(hdIndex) + let validAddress = addrValid(chain.address.coin, address) + console.assert(validAddress, "address invalid") + console.assert(address == hdData[coinSymbol], "address is diff") -let userId = 123456 + let priAddr = await chain.address.getAddressByPrivateKey(pri) + console.assert(priAddr.address == hdData[coinSymbol], "address is diff") -// 0x833F5230f7443761AfC8282829989E25f0Fc0A71 -it("ETH getAddress and ", async () => { - let chain = new Address("ETH") - let {address} = await chain.address.getAddress(userId) + let pubAddr = await chain.address.getAddressByPublicKey(pub) + console.assert(pubAddr.address == hdData[coinSymbol], "address is diff") +} - let foo = await chain.address.isAddress(address) - console.log(foo) +it("BTC getKeyPair", async () => { + let ok =await getKeyPairTest("BTC") }) + it("BTC TEST getKeyPair", async () => { let chain = new Address("BTC", "TEST") - let foo = await chain.getKeyPair(userId) - console.log(foo) + let {address} = await chain.getKeyPair(hdIndex) + let validAddress = addrValid(chain.address.coin, address, "TEST") + console.assert(validAddress, "address invalid") + console.assert(address == hdData.BTC_TEST, "address is diff") }) -it("BTC getAddressEx", async () => { - let chain = new Address("BTC", "TEST") - let foo = await chain.getAddressEx(userId) - console.log(foo) +it("BCH getKeyPair", async () => { + let ok =await getKeyPairTest("BCH") }) -it("BTC getKeyPair", async () => { - let chain = new Address("BTC", "BTC") - let foo = await chain.getKeyPair(userId) +it("LTC getKeyPair", async () => { + let ok =await getKeyPairTest("LTC") +}) - console.log(foo.address) - let priAddr = await chain.address.getAddressByPrivateKey(foo.pri) - console.log(priAddr.address) - let pubAddr = await chain.address.getAddressByPublicKey(foo.pub) - console.log(pubAddr.address) -}) -it("ETH getKeyPair", async () => { - let chain = new Address("ETH") - let foo = await chain.getKeyPair(userId) - console.log(foo.address) - let priAddr = await chain.address.getAddressByPrivateKey(foo.pri) - console.log(priAddr.address) - let pubAddr = await chain.address.getAddressByPublicKey(foo.pub) - console.log(pubAddr.address) +it("ETH getKeyPair ", async () => { + let ok =await getKeyPairTest("ETH") - console.assert(pubAddr.address == "0x833F5230f7443761AfC8282829989E25f0Fc0A71") }) + it("TRX getKeyPair", async () => { - let chain = new Address("TRX") - let foo = await chain.getKeyPair(userId) - console.log(foo.address) - let priAddr = await chain.address.getAddressByPrivateKey(foo.pri) - console.log(priAddr.address) - let pubAddr = await chain.address.getAddressByPublicKey(foo.pub) - console.log(pubAddr.address) - console.assert(pubAddr.address == "TDmpo4ZwgpJ5aMfuqiK4mKcbY131STyybh") - // + let ok =await getKeyPairTest("TRX") }) diff --git a/test/lib/base/data.js b/test/lib/base/data.js index e3746b3..792fd4e 100644 --- a/test/lib/base/data.js +++ b/test/lib/base/data.js @@ -1,5 +1,6 @@ let authData = require("./auth.data") +let starData = require("./star.6677.data") module.exports = { - hd: authData.hd + hd: starData.hd } \ No newline at end of file diff --git a/test/lib/base/star.6677.data.js b/test/lib/base/star.6677.data.js index d8a66ee..5e3fb72 100644 --- a/test/lib/base/star.6677.data.js +++ b/test/lib/base/star.6677.data.js @@ -2,11 +2,11 @@ module.exports = { "hd": { "mnemonic": "star star star star star star", "index": 6677, - "BTC": "1HthGRdzxunKAiMSazDdL8PZhE4qWpeBNK", - "BTC_TEST": "mxQeZUiymwDZwpq4JZC1A3btZDfYRhqRwS", - "BCH": "12owPGh3cXLk8HevCEx5fZAMPqZPBgvgmX", - "LTC": "LchXCPCtYTKUvksjf5RvkZhCwvYQrYewaa", - "ETH": "0x4E04823FDF08E862201a4cfA595dc1Ec72AdF3Ab", - "TRX": "TZFH9KReZpsWZZ9Q2bVyXGQtmvVL3PV8gE", - }, + "BTC": "1442MZYQMh17ZoWdLMferxM4U9ppqGQbuK", + "BTC_TEST": "miZyecdPAiSNLuzF3ve2gsZPL9RXjA51JS", + "BCH": "12Ut7DckjmdzU4Kx8cZeCfsyqufcrTFkFq", + "LTC": "LbspHRvEu8PpyMq2EpR7rJNN5D3kzzsk9a", + "ETH": "0xe4fa4CEFEa4ebfB79f4527a71EEF983700119d58", + "TRX": "TQawSTYUsWvibpQURRUxJhUcLZdEbuFdGT", + } } \ No newline at end of file