rename all libs from xxx.yyy to xxx-yyy
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
"serve-favicon": "^2.4.5",
|
||||
"socket.io": "^2.1.1",
|
||||
"tic.action": "git+https://git.faronear.org/tic/tic.action#20190714_release_passtoken",
|
||||
"tic.crypto": "git+https://git.faronear.org/tic/tic.crypto#20190109_preview",
|
||||
"tic-crypto": "git+https://git.faronear.org/tic/tic-crypto#20190109_preview",
|
||||
"vue": "^2.5.17",
|
||||
"vue-axios": "^2.1.3",
|
||||
"vue-i18n": "^8.1.0",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import '../axios'
|
||||
import ticCrypto from 'tic.crypto'
|
||||
import ticrypto from 'tic-crypto'
|
||||
import { TIC } from '../tic'
|
||||
|
||||
export const seckey2pubkey = seckey => ticCrypto.seckey2pubkey(seckey)
|
||||
export const secword2address = secword => ticCrypto.secword2address(secword)
|
||||
export const secword2account = secword => ticCrypto.secword2account(secword)
|
||||
// export const randomSecword = lang => ticCrypto.randomSecword(lang)
|
||||
export const isAddress = address => ticCrypto.isAddress(address)
|
||||
export const seckey2pubkey = seckey => ticrypto.seckey2pubkey(seckey)
|
||||
export const secword2address = secword => ticrypto.secword2address(secword)
|
||||
export const secword2account = secword => ticrypto.secword2account(secword)
|
||||
// export const randomSecword = lang => ticrypto.randomSecword(lang)
|
||||
export const isAddress = address => ticrypto.isAddress(address)
|
||||
|
||||
export const transferTic = ({ mnemonic, to, amount, fee }) => {
|
||||
const instance = TIC.fromMnemonic(mnemonic)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import * as Ticrypto from 'tic.crypto'
|
||||
import * as Ticrypto from 'tic-crypto'
|
||||
import * as ticAction from 'tic.action'
|
||||
|
||||
const TicActionTransfer = ticAction.ActionTransfer
|
||||
@@ -7,103 +7,113 @@ const TicActionTransfer = ticAction.ActionTransfer
|
||||
const TIC_TXFEE = 10
|
||||
|
||||
export class TIC {
|
||||
constructor(seckey, option = {}) {
|
||||
if (!seckey || !Ticrypto.isSeckey(seckey)) throw Error('ERROR:Invalid Seckey')
|
||||
constructor (seckey, option = {}) {
|
||||
if (!seckey || !Ticrypto.isSeckey(seckey))
|
||||
throw Error('ERROR:Invalid Seckey')
|
||||
Object.defineProperties(this, {
|
||||
'seckey': {
|
||||
seckey: {
|
||||
value: seckey,
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
writable: false
|
||||
},
|
||||
'pubkey': {
|
||||
pubkey: {
|
||||
value: Ticrypto.seckey2pubkey(seckey),
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
writable: false
|
||||
},
|
||||
'address': {
|
||||
address: {
|
||||
value: Ticrypto.pubkey2address(Ticrypto.seckey2pubkey(seckey)),
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
},
|
||||
writable: false
|
||||
}
|
||||
})
|
||||
Object.assign(this, {
|
||||
_defaultFee: option.fee || TIC_TXFEE, // fee cannot be zero
|
||||
_defaultFee: option.fee || TIC_TXFEE // fee cannot be zero
|
||||
})
|
||||
}
|
||||
get txfee() {
|
||||
get txfee () {
|
||||
return this._defaultFee
|
||||
}
|
||||
set txfee(fee) {
|
||||
set txfee (fee) {
|
||||
this._defaultFee = fee
|
||||
}
|
||||
|
||||
static generateNewAccount() {
|
||||
static generateNewAccount () {
|
||||
var secword = Ticrypto.randomSecword()
|
||||
return Object.assign(new TIC(Ticrypto.secword2keypair(secword).seckey), {
|
||||
secword: secword,
|
||||
secword: secword
|
||||
})
|
||||
}
|
||||
static fromMnemonic(secword) {
|
||||
if (!secword || !Ticrypto.isSecword(secword)) throw Error('ERROR:Invalid Secword')
|
||||
static fromMnemonic (secword) {
|
||||
if (!secword || !Ticrypto.isSecword(secword))
|
||||
throw Error('ERROR:Invalid Secword')
|
||||
return new TIC(Ticrypto.secword2keypair(secword).seckey)
|
||||
}
|
||||
static async getBalance(address) {
|
||||
static async getBalance (address) {
|
||||
if (!address) {
|
||||
throw new Error('Address is required')
|
||||
}
|
||||
return (await axios.post('Account/getBalance', {
|
||||
'Account': {
|
||||
'address': address,
|
||||
},
|
||||
})).data
|
||||
return (
|
||||
await axios.post('Account/getBalance', {
|
||||
Account: {
|
||||
address: address
|
||||
}
|
||||
static async getActions(address) {
|
||||
})
|
||||
).data
|
||||
}
|
||||
static async getActions (address) {
|
||||
if (!address) {
|
||||
throw new Error('Address is required')
|
||||
}
|
||||
return (await axios.post('Action/getActionList', {
|
||||
'Action': {
|
||||
'actorAddress': address,
|
||||
'toAddress': address,
|
||||
return (
|
||||
await axios.post('Action/getActionList', {
|
||||
Action: {
|
||||
actorAddress: address,
|
||||
toAddress: address
|
||||
},
|
||||
'config': {
|
||||
'logic': 'OR',
|
||||
},
|
||||
})).data
|
||||
config: {
|
||||
logic: 'OR'
|
||||
}
|
||||
static encrypt(data, key) {
|
||||
})
|
||||
).data
|
||||
}
|
||||
static encrypt (data, key) {
|
||||
if (!data || !key) throw new Error('Required Params Missing')
|
||||
return Ticrypto.encrypt(data, key)
|
||||
}
|
||||
static decrypt(data, key) {
|
||||
static decrypt (data, key) {
|
||||
return Ticrypto.decrypt(data, key, {
|
||||
format: 'json',
|
||||
format: 'json'
|
||||
}) // return null for wrong key
|
||||
}
|
||||
|
||||
static isValidAddress(address) {
|
||||
static isValidAddress (address) {
|
||||
return Ticrypto.isAddress(address)
|
||||
}
|
||||
|
||||
async sendTransaction(toAddress, amount, option = {
|
||||
gasFee: TIC_TXFEE,
|
||||
}) {
|
||||
async sendTransaction (
|
||||
toAddress,
|
||||
amount,
|
||||
option = {
|
||||
gasFee: TIC_TXFEE
|
||||
}
|
||||
) {
|
||||
if (!toAddress || !amount) {
|
||||
throw new Error('ERROR:RequiredParamsMissing')
|
||||
} // amount cannot be zero
|
||||
let action = new TicActionTransfer({
|
||||
amount: parseInt(amount),
|
||||
toAddress: toAddress,
|
||||
fee: option.gasFee,
|
||||
fee: option.gasFee
|
||||
})
|
||||
// 对交易数据签名,packMe 内的参数是交易发起人的keypair
|
||||
action.packMe({
|
||||
seckey: this.seckey,
|
||||
pubkey: this.pubkey,
|
||||
address: this.address,
|
||||
address: this.address
|
||||
})
|
||||
let data = {
|
||||
Action: action,
|
||||
Action: action
|
||||
}
|
||||
try {
|
||||
let res = (await axios.post('Action/prepare', data)).data
|
||||
@@ -112,13 +122,13 @@ export class TIC {
|
||||
return null
|
||||
}
|
||||
}
|
||||
async getBalance() {
|
||||
async getBalance () {
|
||||
return TIC.getBalance(this.address)
|
||||
}
|
||||
async getActions() {
|
||||
async getActions () {
|
||||
return TIC.getActions(this.address)
|
||||
}
|
||||
getSerializedTx(option) {
|
||||
getSerializedTx (option) {
|
||||
if (!option.toAddress || !option.amount) {
|
||||
throw new Error('ERROR:RequiredParamsMissing')
|
||||
}
|
||||
@@ -126,24 +136,24 @@ export class TIC {
|
||||
amount: parseInt(option.amount),
|
||||
toAddress: option.toAddress,
|
||||
fee: option.fee || this._defaultFee,
|
||||
message: option.message || '',
|
||||
message: option.message || ''
|
||||
})
|
||||
// sign for txBody use function packMe, which needs actor's keypair as parameter
|
||||
action.packMe({
|
||||
seckey: this.seckey,
|
||||
pubkey: this.pubkey,
|
||||
address: this.address,
|
||||
address: this.address
|
||||
})
|
||||
return action
|
||||
}
|
||||
// default key for sign&encrypt is account's seckey,other keys are optional.
|
||||
sign(message, key = this.seckey) {
|
||||
sign (message, key = this.seckey) {
|
||||
return Ticrypto.sign(message, key)
|
||||
}
|
||||
verify(message, signature) {
|
||||
verify (message, signature) {
|
||||
return Ticrypto.sign(message, signature, this.seckey)
|
||||
}
|
||||
encrypt(key) {
|
||||
encrypt (key) {
|
||||
return TIC.encrypt(this, key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
import router from '../../router'
|
||||
import { i18n } from '../../i18n'
|
||||
import _ from 'lodash'
|
||||
import ticCrypto from 'tic.crypto'
|
||||
import ticrypto from 'tic-crypto'
|
||||
import axios from 'axios'
|
||||
import * as Ticrypto from 'tic.crypto'
|
||||
import * as Ticrypto from 'tic-crypto'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
@@ -14,44 +14,50 @@ export default {
|
||||
passwd: '',
|
||||
erroruser: '',
|
||||
signing: false,
|
||||
renewing: false,
|
||||
renewing: false
|
||||
},
|
||||
|
||||
getters: {
|
||||
inputError: state => !!state.erroruser,
|
||||
inputError: state => !!state.erroruser
|
||||
},
|
||||
|
||||
mutations: {
|
||||
updateUserName(state, username) {
|
||||
updateUserName (state, username) {
|
||||
if (state.errorMnemonic) {
|
||||
state.errorMnemonic = ''
|
||||
}
|
||||
state.username = username
|
||||
},
|
||||
updatePasswd(state, passwd) {
|
||||
updatePasswd (state, passwd) {
|
||||
if (state.errorMnemonic) {
|
||||
state.errorMnemonic = ''
|
||||
}
|
||||
state.passwd = passwd
|
||||
},
|
||||
|
||||
updateError(state, error) {
|
||||
updateError (state, error) {
|
||||
state.erroruser = error
|
||||
},
|
||||
|
||||
updateSign(state, signing) {
|
||||
updateSign (state, signing) {
|
||||
state.signing = signing
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
async login({ state, commit }) {
|
||||
async login ({ state, commit }) {
|
||||
commit('updateSign', true)
|
||||
const passwd = Ticrypto.hash(state.passwd)
|
||||
const ts = Date.now()
|
||||
const path = '/admin/in'
|
||||
const sig = ticCrypto.hash(ts + path + 'LimitSaltLOL8080', { hasher: 'md5' })
|
||||
let result = await axios.post('admin/in', { name: state.username, passwd }, { headers: { ts, sig } })
|
||||
const sig = ticrypto.hash(ts + path + 'LimitSaltLOL8080', {
|
||||
hasher: 'md5'
|
||||
})
|
||||
let result = await axios.post(
|
||||
'admin/in',
|
||||
{ name: state.username, passwd },
|
||||
{ headers: { ts, sig } }
|
||||
)
|
||||
commit('updateSign', false)
|
||||
if (result.data.code === 0) {
|
||||
commit('updateAccount', result.data.data, { root: true })
|
||||
@@ -61,9 +67,9 @@ export default {
|
||||
commit('updateError', result.data.msg)
|
||||
}
|
||||
},
|
||||
async createSecword({ state, commit }) {
|
||||
let secword = ticCrypto.randomSecword() // 不能用 webworker 里的randomSecword,会导致报错 "window is not defined"。猜测是 bitcore-mnemonic 用到了window。
|
||||
async createSecword ({ state, commit }) {
|
||||
let secword = ticrypto.randomSecword() // 不能用 webworker 里的randomSecword,会导致报错 "window is not defined"。猜测是 bitcore-mnemonic 用到了window。
|
||||
commit('updateMnemonic', secword)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9544,11 +9544,11 @@ thunky@^1.0.2:
|
||||
resolved "git+https://git.faronear.org/tic/tic.action.git#2a6607669a47d132a469984fef05004e2e4d1179"
|
||||
dependencies:
|
||||
so.ling "git+https://git.faronear.org/so/so.ling#20190427_fon2so"
|
||||
tic.crypto "git+https://git.faronear.org/tic/tic.crypto#20190109_preview"
|
||||
tic-crypto "git+https://git.faronear.org/tic/tic-crypto#20190109_preview"
|
||||
|
||||
"tic.crypto@git+https://git.faronear.org/tic/tic.crypto#20190109_preview":
|
||||
"tic-crypto@git+https://git.faronear.org/tic/tic-crypto#20190109_preview":
|
||||
version "0.1.0"
|
||||
resolved "git+https://git.faronear.org/tic/tic.crypto#15c35c803fb28ac0f289c367085620e800a5ddf9"
|
||||
resolved "git+https://git.faronear.org/tic/tic-crypto#15c35c803fb28ac0f289c367085620e800a5ddf9"
|
||||
dependencies:
|
||||
bignumber.js "^6.0.0"
|
||||
bitcore-mnemonic "^1.5.0"
|
||||
|
||||
Reference in New Issue
Block a user