修改购买盒子的签名方法
This commit is contained in:
parent
204403a0f5
commit
b33473f1c5
@ -1,9 +1,9 @@
|
|||||||
VUE_APP_WALLET_INFURAID='e7743d46923911fa8850619b7a7f6d9d'
|
VUE_APP_WALLET_INFURAID='e7743d46923911fa8850619b7a7f6d9d'
|
||||||
VUE_APP_BASE_API='https://market-test.kingsome.cn'
|
VUE_APP_BASE_API='https://market-test.kingsome.cn'
|
||||||
VUE_APP_CHAIN_ID=322
|
VUE_APP_CHAIN_ID=1338
|
||||||
VUE_APP_CHAIN_RPC='https://rpc-testnet.kcc.network'
|
VUE_APP_CHAIN_RPC='http://192.168.100.22:8545'
|
||||||
VUE_APP_CHAIN_NAME='KCC-TESTNET'
|
VUE_APP_CHAIN_NAME='22'
|
||||||
VUE_APP_CHAIN_EXPLORERURL='https://scan-testnet.kcc.network
|
VUE_APP_CHAIN_EXPLORERURL=''
|
||||||
VUE_APP_CHAIN_CURRENCY_NAME='name'
|
VUE_APP_CHAIN_CURRENCY_NAME='name'
|
||||||
VUE_APP_CHAIN_CURRENCY_SYMBOL='KCS'
|
VUE_APP_CHAIN_CURRENCY_SYMBOL='BEC'
|
||||||
VUE_APP_CHAIN_CURRENCY_DECIMALS=18
|
VUE_APP_CHAIN_CURRENCY_DECIMALS=18
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build",
|
||||||
"lint": "vue-cli-service lint",
|
"lint": "vue-cli-service lint",
|
||||||
"deploy": "ztools png ./dist && rm -f ./dist/.DS_Store && aws s3 sync ./dist s3://cebg.games"
|
"deploy": "rm -f ./dist/.DS_Store && aws s3 sync ./dist s3://cebg.games",
|
||||||
|
"deploy:test": "rm -f ./dist/.DS_Store && aws s3 sync ./dist s3://test.cebg.games"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@walletconnect/web3-provider": "^1.7.1",
|
"@walletconnect/web3-provider": "^1.7.1",
|
||||||
|
@ -7,15 +7,14 @@
|
|||||||
<!-- <meta name="viewport" content="width=device-width,initial-scale=1.0">-->
|
<!-- <meta name="viewport" content="width=device-width,initial-scale=1.0">-->
|
||||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||||
<script src="assets/libs/spine-webgl.js"></script>
|
|
||||||
<style>
|
<style>
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: title;
|
font-family: title;
|
||||||
src: url('assets/fonts/title.ttf');
|
src: url('/assets/fonts/title.ttf');
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: zitic;
|
font-family: zitic;
|
||||||
src: url('assets/fonts/zitic.ttf');
|
src: url('/assets/fonts/zitic.ttf');
|
||||||
}
|
}
|
||||||
html *
|
html *
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,13 @@ import { MessageBox } from 'element-ui'
|
|||||||
import { ERC20ABI, MALL_ADDRESS } from '@/utils/config_chain'
|
import { ERC20ABI, MALL_ADDRESS } from '@/utils/config_chain'
|
||||||
import { EventBus, NEED_LOGIN } from '@/utils/event-bus'
|
import { EventBus, NEED_LOGIN } from '@/utils/event-bus'
|
||||||
|
|
||||||
|
const EIP721_DOMAIN_DATA = [
|
||||||
|
{ name: 'name', type: 'string' },
|
||||||
|
{ name: 'version', type: 'string' },
|
||||||
|
{ name: 'chainId', type: 'uint256' },
|
||||||
|
{ name: 'verifyingContract', type: 'address' }
|
||||||
|
]
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
export class BlockChain {
|
export class BlockChain {
|
||||||
provider:any
|
provider:any
|
||||||
@ -196,12 +203,29 @@ export class BlockChain {
|
|||||||
buyerAddress: string
|
buyerAddress: string
|
||||||
}) {
|
}) {
|
||||||
const nonce = Math.random() * 100000 | 0
|
const nonce = Math.random() * 100000 | 0
|
||||||
const signStr: string = this.web3.utils.soliditySha3(type, paymentTokenAddress, price, nonce)!
|
|
||||||
const signStr2 = this.web3.eth.accounts.hashMessage(signStr)
|
const signMsg = {
|
||||||
let signature = await this.web3.eth.sign(signStr2, buyerAddress)
|
item: type,
|
||||||
// console.log(paymentTokenAddress, type, nonce, price, signature)
|
token: paymentTokenAddress,
|
||||||
// const whoSigned1 = await this.web3.eth.accounts.recover(signStr2, signature, true)
|
price: price,
|
||||||
signature = signature.replace(/00$/, '1b').replace(/01$/, '1c')
|
salt: nonce
|
||||||
|
}
|
||||||
|
const signCfg = {
|
||||||
|
name: 'BEBoxMall',
|
||||||
|
version: '1',
|
||||||
|
contract: MALL_ADDRESS,
|
||||||
|
signer: buyerAddress,
|
||||||
|
types: {
|
||||||
|
EIP712Domain: EIP721_DOMAIN_DATA,
|
||||||
|
set: [
|
||||||
|
{ name: 'item', type: 'uint256' },
|
||||||
|
{ name: 'token', type: 'address' },
|
||||||
|
{ name: 'price', type: 'uint256' },
|
||||||
|
{ name: 'salt', type: 'uint256' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const signature = await this.signData(signCfg, signMsg)
|
||||||
return { nonce, signature }
|
return { nonce, signature }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,4 +240,48 @@ export class BlockChain {
|
|||||||
const priceStr = (price / v) + ''
|
const priceStr = (price / v) + ''
|
||||||
return this.web3.utils.toWei(priceStr)
|
return this.web3.utils.toWei(priceStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async signData(cfg: any, msg: any) {
|
||||||
|
const netId = await this.web3.eth.getChainId()
|
||||||
|
const msgParams = JSON.stringify({
|
||||||
|
types: cfg.types,
|
||||||
|
// make sure to replace verifyingContract with address of deployed contract
|
||||||
|
primaryType: 'set',
|
||||||
|
domain: {
|
||||||
|
name: cfg.name,
|
||||||
|
version: cfg.version,
|
||||||
|
chainId: netId,
|
||||||
|
verifyingContract: cfg.contract
|
||||||
|
},
|
||||||
|
message: msg
|
||||||
|
})
|
||||||
|
const from = cfg.signer
|
||||||
|
console.log('clicked, sending personal sign req', 'from', from, msgParams)
|
||||||
|
const params = [from, msgParams]
|
||||||
|
const result: any = await this.sendCmd({
|
||||||
|
method: 'eth_signTypedData_v4',
|
||||||
|
params,
|
||||||
|
from
|
||||||
|
})
|
||||||
|
console.log(result)
|
||||||
|
return result.result
|
||||||
|
}
|
||||||
|
|
||||||
|
public async sendCmd({ method, params, from }: any) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
this.web3.currentProvider.sendAsync({
|
||||||
|
method,
|
||||||
|
params,
|
||||||
|
from
|
||||||
|
}, async function(err: any, result: any) {
|
||||||
|
if (err) {
|
||||||
|
reject && reject(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve && resolve(result)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user