import cryptoJs from 'crypto-js' const assetsUri = (src) => { if (src && (src.includes('https://') || src.includes('http://'))) { return src } return require(`~/static/${src}`) } function getUrlParams (params) { const urlObj = {} if (!window.location.search) { return false } const urlParams = window.location.search.substring(1) const urlArr = urlParams.split('&') for (let i = 0; i < urlArr.length; i++) { const urlArrItem = urlArr[i].split('=') urlObj[urlArrItem[0]] = urlArrItem[1] } // 判断是否有参数 if (arguments.length >= 1) { return urlObj[params] } return urlObj } // const staticUri = (src) => { // if (src && (src.includes('https://') || src.includes('http://'))) { // return src // } // return require(`/static/${src}`) // } class Web3Utils { static base64UrlEncode (str) { let encodedSource = cryptoJs.enc.Base64.stringify(str) const reg = new RegExp('/', 'g') encodedSource = encodedSource.replace(/[=]+$/, '').replace(/\+/g, '-').replace(reg, '_') return encodedSource } static jiami (accounts) { const header = JSON.stringify({ alg: 'HS256', typ: 'JWT' }) const payload = JSON.stringify({ address: accounts }) const secretSalt = 'JCA3bTd8XW7pkJmQMJT1ZiY75uhwjrmXPvisjAzVcWlOQ5LvqF' const before_sign = `${Web3Utils.base64UrlEncode(cryptoJs.enc.Utf8.parse(header))}.${Web3Utils.base64UrlEncode(cryptoJs.enc.Utf8.parse(payload))}` let signature = cryptoJs.HmacSHA256(before_sign, secretSalt) signature = Web3Utils.base64UrlEncode(signature) return `${before_sign}.${signature}` } } export { assetsUri, getUrlParams,Web3Utils }