rename all libs from xxx.yyy to xxx-yyy

This commit is contained in:
Luk Lu
2022-06-04 12:09:45 +08:00
parent 60c654c733
commit 70931ec22e
5 changed files with 93 additions and 77 deletions

View File

@@ -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",

View File

@@ -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)

View File

@@ -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
@@ -8,26 +8,27 @@ const TIC_TXFEE = 10
export class TIC {
constructor (seckey, option = {}) {
if (!seckey || !Ticrypto.isSeckey(seckey)) throw Error('ERROR:Invalid Seckey')
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 () {
@@ -40,36 +41,41 @@ export class TIC {
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')
if (!secword || !Ticrypto.isSecword(secword))
throw Error('ERROR:Invalid Secword')
return new TIC(Ticrypto.secword2keypair(secword).seckey)
}
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
}
})
).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'
}
})
).data
}
static encrypt (data, key) {
if (!data || !key) throw new Error('Required Params Missing')
@@ -77,7 +83,7 @@ export class TIC {
}
static decrypt (data, key) {
return Ticrypto.decrypt(data, key, {
format: 'json',
format: 'json'
}) // return null for wrong key
}
@@ -85,25 +91,29 @@ export class TIC {
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
@@ -126,13 +136,13 @@ 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
}

View File

@@ -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,11 +14,11 @@ export default {
passwd: '',
erroruser: '',
signing: false,
renewing: false,
renewing: false
},
getters: {
inputError: state => !!state.erroruser,
inputError: state => !!state.erroruser
},
mutations: {
@@ -41,7 +41,7 @@ export default {
updateSign (state, signing) {
state.signing = signing
},
}
},
actions: {
@@ -50,8 +50,14 @@ export default {
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 })
@@ -62,8 +68,8 @@ export default {
}
},
async createSecword ({ state, commit }) {
let secword = ticCrypto.randomSecword() // 不能用 webworker 里的randomSecword会导致报错 "window is not defined"。猜测是 bitcore-mnemonic 用到了window。
let secword = ticrypto.randomSecword() // 不能用 webworker 里的randomSecword会导致报错 "window is not defined"。猜测是 bitcore-mnemonic 用到了window。
commit('updateMnemonic', secword)
},
},
}
}
}

View File

@@ -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"