测试开分支,去除对 tic.common 的依赖,转成对 tic.crypto 和 tic.action
This commit is contained in:
parent
006219b7ee
commit
efa4788bc3
21
btc.js
21
btc.js
@ -3,16 +3,15 @@
|
|||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const HDNode = require('./utils/hdnode');
|
const HDNode = require('./utils/hdnode');
|
||||||
const bitcoinjs = require('bitcoinjs-lib');
|
const bitcoinjs = require('bitcoinjs-lib');
|
||||||
// const bitcore = require('tic.common').Bitcore;
|
const Ticrypto = require('tic.crypto');
|
||||||
const ticCommon = require('tic.common').Crypto;
|
|
||||||
const BTC_NODE = require('./netConfig').BTC_NODE;
|
const BTC_NODE = require('./netConfig').BTC_NODE;
|
||||||
const BTC_NODE2 = require('./netConfig').BTC_NODE2;
|
const BTC_NODE2 = require('./netConfig').BTC_NODE2;
|
||||||
const BTC_TXFEE = 30;
|
const BTC_TXFEE = 30;
|
||||||
|
|
||||||
class BTC {
|
class BTC {
|
||||||
constructor(privateKey){
|
constructor(privateKey){
|
||||||
if(!ticCommon.isSeckey(privateKey)) throw new Error('Invalid PrivateKey')
|
if(!Ticrypto.isSeckey(privateKey)) throw new Error('Invalid PrivateKey')
|
||||||
var publicKey = ticCommon.seckey2pubkey(privateKey)
|
var publicKey = Ticrypto.seckey2pubkey(privateKey)
|
||||||
Object.defineProperties(this,{
|
Object.defineProperties(this,{
|
||||||
"privateKey" : {
|
"privateKey" : {
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
@ -22,12 +21,12 @@ class BTC {
|
|||||||
"publicKey": {
|
"publicKey": {
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
writable : false,
|
writable : false,
|
||||||
value : ticCommon.seckey2pubkey(privateKey,{coin:"BTC"})
|
value : Ticrypto.seckey2pubkey(privateKey,{coin:"BTC"})
|
||||||
},
|
},
|
||||||
"address" : {
|
"address" : {
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
writable : false,
|
writable : false,
|
||||||
value : ticCommon.pubkey2address(publicKey,{coin:"BTC"})
|
value : Ticrypto.pubkey2address(publicKey,{coin:"BTC"})
|
||||||
},
|
},
|
||||||
"url" : {
|
"url" : {
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
@ -51,12 +50,12 @@ class BTC {
|
|||||||
|
|
||||||
}
|
}
|
||||||
static generateNewAccount(){
|
static generateNewAccount(){
|
||||||
var mnemonic = ticCommon.randomSecword()
|
var mnemonic = Ticrypto.randomSecword()
|
||||||
return Object.assign(new BTC(ticCommon.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic : mnemonic})
|
return Object.assign(new BTC(Ticrypto.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic : mnemonic})
|
||||||
}
|
}
|
||||||
static fromMnemonic(mnemonic){
|
static fromMnemonic(mnemonic){
|
||||||
HDNode.isValidMnemonic(mnemonic)
|
HDNode.isValidMnemonic(mnemonic)
|
||||||
return Object.assign(new BTC(ticCommon.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic:mnemonic})
|
return Object.assign(new BTC(Ticrypto.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic:mnemonic})
|
||||||
}
|
}
|
||||||
static async getBalance(address){
|
static async getBalance(address){
|
||||||
return (await axios.get(`${BTC_NODE}/addrs/${address}/balance`)).data.balance
|
return (await axios.get(`${BTC_NODE}/addrs/${address}/balance`)).data.balance
|
||||||
@ -74,10 +73,10 @@ class BTC {
|
|||||||
}
|
}
|
||||||
static encrypt(data, key){
|
static encrypt(data, key){
|
||||||
if(!data || !key) throw new Error('Required Params Missing')
|
if(!data || !key) throw new Error('Required Params Missing')
|
||||||
return ticCommon.encrypt(data,key)
|
return Ticrypto.encrypt(data,key)
|
||||||
}
|
}
|
||||||
static decrypt(data, key){
|
static decrypt(data, key){
|
||||||
return ticCommon.decrypt(data, key, {format:"json"}) //return null for wrong key
|
return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key
|
||||||
}
|
}
|
||||||
static isValidAddress(address){
|
static isValidAddress(address){
|
||||||
return address.length == 34 && address[0] == '1'
|
return address.length == 34 && address[0] == '1'
|
||||||
|
8
eth.js
8
eth.js
@ -2,7 +2,7 @@
|
|||||||
const eth = require('etherscan-api').init('E3ZFFAEMNN33KX4HHVUZ4KF8XY1FXMR4BI');
|
const eth = require('etherscan-api').init('E3ZFFAEMNN33KX4HHVUZ4KF8XY1FXMR4BI');
|
||||||
const secretStorage = require('./utils/secret-storage');
|
const secretStorage = require('./utils/secret-storage');
|
||||||
const SigningKey = require('./utils/signing-key.js');
|
const SigningKey = require('./utils/signing-key.js');
|
||||||
const ticCommon = require('tic.common').Crypto;
|
const Ticrypto = require('tic.crypto');
|
||||||
const HDNode = require('./utils/hdnode');
|
const HDNode = require('./utils/hdnode');
|
||||||
const utils = require('./util.js');
|
const utils = require('./util.js');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
@ -68,7 +68,7 @@ class ETH {
|
|||||||
}
|
}
|
||||||
static generateNewAccount(option = {path:defaultPath}){
|
static generateNewAccount(option = {path:defaultPath}){
|
||||||
//major path as default path >/0'/0/0
|
//major path as default path >/0'/0/0
|
||||||
var mnemonic = ticCommon.randomSecword();
|
var mnemonic = Ticrypto.randomSecword();
|
||||||
return Object.assign(ETH.fromMnemonic(mnemonic, option),{mnemonic,mnemonic})
|
return Object.assign(ETH.fromMnemonic(mnemonic, option),{mnemonic,mnemonic})
|
||||||
}
|
}
|
||||||
static fromMnemonic(mnemonic, option = {path:defaultPath}){
|
static fromMnemonic(mnemonic, option = {path:defaultPath}){
|
||||||
@ -198,10 +198,10 @@ class ETH {
|
|||||||
}
|
}
|
||||||
static encrypt(data, key){
|
static encrypt(data, key){
|
||||||
if(!data || !key) throw new Error('Required Params Missing')
|
if(!data || !key) throw new Error('Required Params Missing')
|
||||||
return ticCommon.encrypt(data,key)
|
return Ticrypto.encrypt(data,key)
|
||||||
}
|
}
|
||||||
static decrypt(data, key){
|
static decrypt(data, key){
|
||||||
return ticCommon.decrypt(data, key, {format:"json"}) //return null for wrong key
|
return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key
|
||||||
}
|
}
|
||||||
static async estimateGasPrice(){
|
static async estimateGasPrice(){
|
||||||
try{
|
try{
|
||||||
|
2
index.js
2
index.js
@ -5,7 +5,7 @@ const ETH = require('./eth.js').ETH;
|
|||||||
const ERC20 = require('./eth.js').ERC20;
|
const ERC20 = require('./eth.js').ERC20;
|
||||||
const BTC = require('./btc.js').BTC;
|
const BTC = require('./btc.js').BTC;
|
||||||
const Account = require('./Account').Account;
|
const Account = require('./Account').Account;
|
||||||
const Crypto = require('tic.common').Crypto;
|
const Crypto = require('tic.crypto');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
TIC,
|
TIC,
|
||||||
ETH,
|
ETH,
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
"js-sha3": "^0.8.0",
|
"js-sha3": "^0.8.0",
|
||||||
"scrypt-js": "^2.0.3",
|
"scrypt-js": "^2.0.3",
|
||||||
"setimmediate": "^1.0.5",
|
"setimmediate": "^1.0.5",
|
||||||
"tic.common": "git+https://git.faronear.org/tic/tic.common.git",
|
"tic.action": "git+https://git.faronear.org/tic/tic.action",
|
||||||
|
"tic.crypto": "git+https://git.faronear.org/tic/tic.crypto",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
},
|
},
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
|
28
tic.js
28
tic.js
@ -1,14 +1,14 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const ticCommon = require('tic.common').Crypto
|
const Ticrypto = require('tic.crypto')
|
||||||
const ticActTransfer = require('tic.common').ActTransfer
|
const ticActTransfer = require('tic.action').ActTransfer
|
||||||
|
|
||||||
const TIC_TXFEE = 10;
|
const TIC_TXFEE = 10;
|
||||||
const TIC_NODE = require('./netConfig').TIC_NODE
|
const TIC_NODE = require('./netConfig').TIC_NODE
|
||||||
|
|
||||||
class TIC {
|
class TIC {
|
||||||
constructor(seckey,option={}){
|
constructor(seckey,option={}){
|
||||||
if(!seckey||!ticCommon.isSeckey(seckey)) throw "ERROR:Invalid Seckey"
|
if(!seckey||!Ticrypto.isSeckey(seckey)) throw "ERROR:Invalid Seckey"
|
||||||
Object.defineProperties(this, {
|
Object.defineProperties(this, {
|
||||||
'seckey' : {
|
'seckey' : {
|
||||||
value : seckey,
|
value : seckey,
|
||||||
@ -16,12 +16,12 @@ class TIC {
|
|||||||
writable : false,
|
writable : false,
|
||||||
},
|
},
|
||||||
'pubkey' : {
|
'pubkey' : {
|
||||||
value : ticCommon.seckey2pubkey(seckey),
|
value : Ticrypto.seckey2pubkey(seckey),
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
writable : false,
|
writable : false,
|
||||||
},
|
},
|
||||||
'address' : {
|
'address' : {
|
||||||
value : ticCommon.pubkey2address(ticCommon.seckey2pubkey(seckey)),
|
value : Ticrypto.pubkey2address(Ticrypto.seckey2pubkey(seckey)),
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
writable : false
|
writable : false
|
||||||
}
|
}
|
||||||
@ -37,12 +37,12 @@ class TIC {
|
|||||||
set txfee(fee){this._defaultFee = fee}
|
set txfee(fee){this._defaultFee = fee}
|
||||||
|
|
||||||
static generateNewAccount(){
|
static generateNewAccount(){
|
||||||
var secword = ticCommon.randomSecword()
|
var secword = Ticrypto.randomSecword()
|
||||||
return Object.assign(new TIC(ticCommon.secword2keypair(secword).seckey),{secword:secword})
|
return Object.assign(new TIC(Ticrypto.secword2keypair(secword).seckey),{secword:secword})
|
||||||
}
|
}
|
||||||
static fromMnemonic(secword){
|
static fromMnemonic(secword){
|
||||||
if(!secword||!ticCommon.isSecword(secword)) throw "ERROR:Invalid Secword"
|
if(!secword||!Ticrypto.isSecword(secword)) throw "ERROR:Invalid Secword"
|
||||||
return new TIC(ticCommon.secword2keypair(secword).seckey)
|
return new TIC(Ticrypto.secword2keypair(secword).seckey)
|
||||||
}
|
}
|
||||||
static async getBalance(address){
|
static async getBalance(address){
|
||||||
if(!address){ throw new Error('Address is required'); }
|
if(!address){ throw new Error('Address is required'); }
|
||||||
@ -66,14 +66,14 @@ class TIC {
|
|||||||
}
|
}
|
||||||
static encrypt(data, key){
|
static encrypt(data, key){
|
||||||
if(!data || !key) throw new Error('Required Params Missing')
|
if(!data || !key) throw new Error('Required Params Missing')
|
||||||
return ticCommon.encrypt(data,key)
|
return Ticrypto.encrypt(data,key)
|
||||||
}
|
}
|
||||||
static decrypt(data, key){
|
static decrypt(data, key){
|
||||||
return ticCommon.decrypt(data, key, {format:"json"}) //return null for wrong key
|
return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key
|
||||||
}
|
}
|
||||||
|
|
||||||
static isValidAddress(address){
|
static isValidAddress(address){
|
||||||
return ticCommon.isAddress(address)
|
return Ticrypto.isAddress(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendTransaction(toAddress, amount, option = {gasFee : TIC_TXFEE}){
|
async sendTransaction(toAddress, amount, option = {gasFee : TIC_TXFEE}){
|
||||||
@ -123,10 +123,10 @@ class TIC {
|
|||||||
}
|
}
|
||||||
//default key for sign&encrypt is account's seckey,other keys are optional.
|
//default key for sign&encrypt is account's seckey,other keys are optional.
|
||||||
sign(message,key = this.seckey){
|
sign(message,key = this.seckey){
|
||||||
return ticCommon.sign(message,key)
|
return Ticrypto.sign(message,key)
|
||||||
}
|
}
|
||||||
verify(message,signature){
|
verify(message,signature){
|
||||||
return ticCommon.sign(message,signature,this.seckey)
|
return Ticrypto.sign(message,signature,this.seckey)
|
||||||
}
|
}
|
||||||
encrypt(key){
|
encrypt(key){
|
||||||
return TIC.encrypt(this, key)
|
return TIC.encrypt(this, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user