diff --git a/apis/interfaces/address.js b/apis/interfaces/address.js new file mode 100644 index 0000000..783a14a --- /dev/null +++ b/apis/interfaces/address.js @@ -0,0 +1,65 @@ +/** + * Web唐明明 + * 匆匆数载恍如梦,岁月迢迢华发增。 + * 碌碌无为枉半生,一朝惊醒万事空。 + * moduleName: 地址管理 + */ + +import { request } from '../index' + +// 地址列表 +const list = () =>{ + return request({ + url: 'mall/addresses' + }) +} + +// 添加地址 +const add = data => { + return request({ + url: 'mall/addresses', + method: 'POST', + data + }) +} + +// 收货地址详情 +const info = id => { + return request({ + url: 'mall/addresses/' + id + }) +} + +// 修改收货地址 +const edit = (id, data) => { + return request({ + url: 'mall/addresses/' + id, + method: 'PUT', + data + }) +} + +// 删除收货地址 +const del = id => { + return request({ + url: 'mall/addresses/' + id, + method: 'DELETE' + }) +} + +// 获取省市区 +const addresses = data => { + return request({ + url: 'mall/addresses/create', + data + }) +} + +export { + list, + add, + info, + edit, + del, + addresses +} diff --git a/apis/interfaces/store.js b/apis/interfaces/store.js index c34249d..846f3f1 100644 --- a/apis/interfaces/store.js +++ b/apis/interfaces/store.js @@ -15,21 +15,58 @@ const mall = () =>{ } // 商品详情 -const goods = (id) => { +const goods = id => { return request({ url: 'mall/goods/' + id }) } // 套餐列表 -const meals = (id) => { +const meals = id => { return request({ url: 'mall/meals/' + id }) } +// 商品列表 +const lists = data => { + console.log(data) + return request({ + url: 'mall/goods', + data + }) +} + +// 确认订单 +const buy = data => { + return request({ + url: 'mall/buy/goods', + data + }) +} + +// 商品下单 +const verify = data => { + return request({ + url: 'mall/buy/goods', + method: 'POST', + data + }) +} + +// 商城二级分类 +const classify = id => { + return request({ + url: 'mall/categories/' + id + '/children' + }) +} + export { mall, goods, - meals + meals, + lists, + buy, + verify, + classify } diff --git a/package-lock.json b/package-lock.json index ed33bf0..cc66824 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2,6 +2,182 @@ "requires": true, "lockfileVersion": 1, "dependencies": { + "base-x": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz", + "integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "bech32": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz", + "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==" + }, + "bigi": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz", + "integrity": "sha1-nGZalfiLiwj8Bc/XMfVhhZ1yWCU=" + }, + "bip-schnorr": { + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/bip-schnorr/-/bip-schnorr-0.6.4.tgz", + "integrity": "sha512-dNKw7Lea8B0wMIN4OjEmOk/Z5qUGqoPDY0P2QttLqGk1hmDPytLWW8PR5Pb6Vxy6CprcdEgfJpOjUu+ONQveyg==", + "requires": { + "bigi": "^1.4.2", + "ecurve": "^1.0.6", + "js-sha256": "^0.9.0", + "randombytes": "^2.1.0", + "safe-buffer": "^5.2.1" + } + }, + "bitcore-lib": { + "version": "8.25.25", + "resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-8.25.25.tgz", + "integrity": "sha512-H6qNCVl4M8/MglXhvc04mmeus1d6nrmqTJGQ+xezJLvL7hs7R3dyBPtOqSP3YSw0iq/GWspMd8f5OOlyXVipJQ==", + "requires": { + "bech32": "=2.0.0", + "bip-schnorr": "=0.6.4", + "bn.js": "=4.11.8", + "bs58": "^4.0.1", + "buffer-compare": "=1.1.1", + "elliptic": "^6.5.3", + "inherits": "=2.0.1", + "lodash": "^4.17.20" + } + }, + "bitcore-mnemonic": { + "version": "8.25.25", + "resolved": "https://registry.npmjs.org/bitcore-mnemonic/-/bitcore-mnemonic-8.25.25.tgz", + "integrity": "sha512-7HvRxHrmd+Rh0Ohl0SEDMKQBAM+FoevXbCFnxGju6H+uZjtWMOToHA8vUg0+B91pfEMjdt9mQVB/wSA8GMqnCA==", + "requires": { + "bitcore-lib": "^8.25.25", + "unorm": "^1.4.1" + } + }, + "bn.js": { + "version": "4.11.8", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", + "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" + }, + "brorand": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", + "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" + }, + "bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", + "requires": { + "base-x": "^3.0.2" + } + }, + "buffer-compare": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-compare/-/buffer-compare-1.1.1.tgz", + "integrity": "sha1-W+e+hTr4kZjR9N3AkNHWakiu9ZY=" + }, + "ecurve": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz", + "integrity": "sha512-/BzEjNfiSuB7jIWKcS/z8FK9jNjmEWvUV2YZ4RLSmcDtP7Lq0m6FvDuSnJpBlDpGRpfRQeTLGLBI8H+kEv0r+w==", + "requires": { + "bigi": "^1.1.0", + "safe-buffer": "^5.0.1" + } + }, + "elliptic": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", + "requires": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + }, + "dependencies": { + "bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + } + } + }, + "hash.js": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", + "requires": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.1" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + } + } + }, + "hmac-drbg": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", + "requires": { + "hash.js": "^1.0.3", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.1" + } + }, + "inherits": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", + "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=" + }, + "js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "minimalistic-assert": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" + }, + "minimalistic-crypto-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" + }, + "randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "requires": { + "safe-buffer": "^5.1.0" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, "uni-read-pages": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/uni-read-pages/-/uni-read-pages-1.0.5.tgz", @@ -12,6 +188,11 @@ "resolved": "https://registry.npmjs.org/uni-simple-router/-/uni-simple-router-2.0.8-beta.3.tgz", "integrity": "sha512-Aiw9O7TzATZ0BH9e6p0hJsVy8K1lYjf3P9QMmskNqJaOh9jltCaurrw/dJZ7xUMGVu/K3XP1MxOotBAUjsiUZg==" }, + "unorm": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/unorm/-/unorm-1.6.0.tgz", + "integrity": "sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA==" + }, "uview-ui": { "version": "2.0.19", "resolved": "https://registry.npmjs.org/uview-ui/-/uview-ui-2.0.19.tgz", diff --git a/pages.json b/pages.json index 48cf772..e7c9273 100644 --- a/pages.json +++ b/pages.json @@ -95,27 +95,35 @@ "path": "pages/address/index", "name": "Address", "style": { - "navigationBarTitleText": "地址" + "navigationBarTitleText": "收货地址" } }, { "path": "pages/address/edit", "name": "AddressEdit", "style": { - "navigationBarTitleText": "编辑", + "navigationBarTitleText": "编辑", "enablePullDownRefresh": false } }, { - "path": "pages/pay/pay", + "path": "pages/pay/pay", "name": "Pay", "style": { "navigationBarTitleText": "收银台", "navigationBarBackgroundColor": "#FFFFFF" } }, { - "path": "pages/store/list", + "path": "pages/store/list", "name": "StoreList", "style": { - "navigationBarTitleText": "列表", + "navigationBarTitleText": "商品", + "navigationBarBackgroundColor": "#FFFFFF", + "enablePullDownRefresh": true + } + }, { + "path": "pages/store/meals", + "name": "StoreMeals", + "style": { + "navigationBarTitleText": "套餐", "navigationBarBackgroundColor": "#FFFFFF", "enablePullDownRefresh": true } diff --git a/pages/address/edit.vue b/pages/address/edit.vue index fb5fb47..271ab06 100644 --- a/pages/address/edit.vue +++ b/pages/address/edit.vue @@ -1,19 +1,303 @@ - diff --git a/pages/address/index.vue b/pages/address/index.vue index 2f13d2f..f328212 100644 --- a/pages/address/index.vue +++ b/pages/address/index.vue @@ -2,84 +2,50 @@ - + @onAdd="$Router.push({name: 'AddressEdit'})" + /> + diff --git a/pages/store/meals.vue b/pages/store/meals.vue new file mode 100644 index 0000000..b839d16 --- /dev/null +++ b/pages/store/meals.vue @@ -0,0 +1,74 @@ + + + + + diff --git a/pages/user/index.vue b/pages/user/index.vue index d7863f3..17d8b11 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -89,7 +89,7 @@ 健康档案 - + 地址管理 diff --git a/router/index.js b/router/index.js index 67faa31..524be61 100644 --- a/router/index.js +++ b/router/index.js @@ -13,7 +13,7 @@ router.beforeEach((to, from, next) => { // 全局路由后置守卫 router.afterEach((to, from) => { - console.log('跳转结束') + // console.log('跳转结束') }) export { diff --git a/static/icon/null-icon.png b/static/icon/null-icon.png new file mode 100644 index 0000000..9883886 Binary files /dev/null and b/static/icon/null-icon.png differ diff --git a/store/index.js b/store/index.js index 4483f7e..eddf8ed 100644 --- a/store/index.js +++ b/store/index.js @@ -13,18 +13,14 @@ Vue.use(Vuex) export default new Vuex.Store({ state: { token : uni.getStorageSync('token') || '', - code : uni.getStorageSync('wxCode') || '', - coupongoods : [] + address : {} }, getters: { getToken: state => { return state.token }, - getCoupongoods: state => { - return state.coupongoods - }, - getCode: state => { - return state.code + getAddress: state => { + return state.address } }, mutations: { @@ -32,12 +28,8 @@ export default new Vuex.Store({ state.token = tokenString uni.setStorageSync('token', tokenString) }, - setCoupongoods(state, value) { - state.coupongoods = value - }, - setCode(state, value) { - state.code = value - uni.setStorageSync('wxCode', value) + setAddress(state, value) { + state.address = value } } }) diff --git a/uni_modules/oct-address/components/oct-address/oct-address.vue b/uni_modules/oct-address/components/oct-address/oct-address.vue index 1ac0564..bc1e286 100644 --- a/uni_modules/oct-address/components/oct-address/oct-address.vue +++ b/uni_modules/oct-address/components/oct-address/oct-address.vue @@ -9,12 +9,14 @@ - 默认 - {{item.tag}} - {{item.city}} + + 默认 + + + {{item.province.name}}{{item.city.name}}{{item.district.name}} {{item.address}} - {{item.name}}{{item.phone}} + {{item.name}}{{item.mobile}} {{isEdit ? '编辑' : '选择'}} @@ -79,6 +81,11 @@ default : () => { return require('../../static/null-icon.png') } + }, + // 是否显示地址标签 + isTag: { + type : Boolean, + default : true } } } @@ -146,7 +153,7 @@ margin-right: $margin/2; } .city--default{ - background: #FF6160; + background: #e6576b; color: white; padding: 0 $margin/3; border-radius: $radius; diff --git a/uni_modules/uni-number-box/changelog.md b/uni_modules/uni-number-box/changelog.md new file mode 100644 index 0000000..82b8656 --- /dev/null +++ b/uni_modules/uni-number-box/changelog.md @@ -0,0 +1,25 @@ +## 1.2.1(2021-11-22) +- 修复 vue3中某些scss变量无法找到的问题 +## 1.2.0(2021-11-19) +- 优化 组件UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource) +- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-number-box](https://uniapp.dcloud.io/component/uniui/uni-number-box) +## 1.1.2(2021-11-09) +- 新增 提供组件设计资源,组件样式调整 +## 1.1.1(2021-07-30) +- 优化 vue3下事件警告的问题 +## 1.1.0(2021-07-13) +- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) +## 1.0.7(2021-05-12) +- 新增 组件示例地址 +## 1.0.6(2021-04-20) +- 修复 uni-number-box 浮点数运算不精确的 bug +- 修复 uni-number-box change 事件触发不正确的 bug +- 新增 uni-number-box v-model 双向绑定 +## 1.0.5(2021-02-05) +- 调整为uni_modules目录规范 + +## 1.0.7(2021-02-05) +- 调整为uni_modules目录规范 +- 新增 支持 v-model +- 新增 支持 focus、blur 事件 +- 新增 支持 PC 端 diff --git a/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.vue b/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.vue new file mode 100644 index 0000000..2d046cb --- /dev/null +++ b/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.vue @@ -0,0 +1,211 @@ + + + diff --git a/uni_modules/uni-number-box/package.json b/uni_modules/uni-number-box/package.json new file mode 100644 index 0000000..e774c3f --- /dev/null +++ b/uni_modules/uni-number-box/package.json @@ -0,0 +1,85 @@ +{ + "id": "uni-number-box", + "displayName": "uni-number-box 数字输入框", + "version": "1.2.1", + "description": "NumberBox 带加减按钮的数字输入框组件,用户可以控制每次点击增加的数值,支持小数。", + "keywords": [ + "uni-ui", + "uniui", + "数字输入框" +], + "repository": "https://github.com/dcloudio/uni-ui", + "engines": { + "HBuilderX": "" + }, + "directories": { + "example": "../../temps/example_temps" + }, + "dcloudext": { + "category": [ + "前端组件", + "通用组件" + ], + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "无", + "data": "无", + "permissions": "无" + }, + "npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui" + }, + "uni_modules": { + "dependencies": ["uni-scss"], + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "y", + "aliyun": "y" + }, + "client": { + "App": { + "app-vue": "y", + "app-nvue": "y" + }, + "H5-mobile": { + "Safari": "y", + "Android Browser": "y", + "微信浏览器(Android)": "y", + "QQ浏览器(Android)": "y" + }, + "H5-pc": { + "Chrome": "y", + "IE": "y", + "Edge": "y", + "Firefox": "y", + "Safari": "y" + }, + "小程序": { + "微信": "y", + "阿里": "y", + "百度": "y", + "字节跳动": "y", + "QQ": "y" + }, + "快应用": { + "华为": "u", + "联盟": "u" + }, + "Vue": { + "vue2": "y", + "vue3": "y" + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-number-box/readme.md b/uni_modules/uni-number-box/readme.md new file mode 100644 index 0000000..1037200 --- /dev/null +++ b/uni_modules/uni-number-box/readme.md @@ -0,0 +1,13 @@ + + +## NumberBox 数字输入框 +> **组件名:uni-number-box** +> 代码块: `uNumberBox` + + +带加减按钮的数字输入框。 + +### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-number-box) +#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839 + + diff --git a/wallet/Wallet.js b/wallet/Wallet.js new file mode 100644 index 0000000..217e7fc --- /dev/null +++ b/wallet/Wallet.js @@ -0,0 +1,126 @@ +import Bitcore from "bitcore-lib" +import Mnemonic from "bitcore-mnemonic" +import secp256k1 from 'secp256k1' +import { + Address, + pubToAddress, + toBuffer, + toChecksumAddress, + intToBuffer +} from 'ethereumjs-util' +import coinType from './networks.js' +import basex from 'base-x' + +export default class Wallet { + + static coinType = coinType + + /** + * 生成助记词 + * @param {Object} lang + */ + static generateMnemonic(lang) { + if (lang) { + return (new Mnemonic(this.getLanguage(lang))).toString(); + } else { + return (new Mnemonic()).toString(); + } + } + + /** + * 验证助记词 + * @param {Object} code + * @param {Object} lang + */ + static validMnemonic(code, lang) { + if (lang) { + return Mnemonic.isValid(code, this.getLanguage(lang)); + } else { + return Mnemonic.isValid(code); + } + } + + /** + * 获取助记词字典 + * @param {Object} lang + */ + static getLanguage(lang) { + return Mnemonic.Words[lang] + } + + /** + * 转成硬钱包私钥 + * @param {Object} code + */ + static toHDPrivateKey(code) { + return (new Mnemonic(code)).toHDPrivateKey() + } + + /** + * 验证地址是否合法 + * @param {Object} addr + */ + static isValidAddress(addr) { + return Bitcore.Address.isValid(addr) + } + + /** + * 硬钱包私钥转成对应网络的 地址 和 私钥 + * @param {Object} hdPrivateKey + * @param {Object} type + */ + static HDPrivateKeyToAddress(hdPrivateKey, type) { + const derived = hdPrivateKey.derive("m/44'/" + type.type + "'/0'/0/0"); + if (type.type === 195) { + const ethAddr = this.getEthereumAddress(derived) + const addressBuffer = Buffer.concat([intToBuffer(0x41), ethAddr.buf], 21) + return { + address: Bitcore.encoding.Base58Check.encode(addressBuffer), + public_key: derived.privateKey.publicKey.toString(), + private_key: derived.privateKey.toString() + } + } + if (type.type === 144) { + let addr = derived.privateKey.toAddress(type.network).toString() + let deco = Bitcore.encoding.Base58.decode(addr) + + return { + address: basex('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz').encode(deco), + public_key: derived.privateKey.publicKey.toString(), + private_key: derived.privateKey.toString() + } + } + if (this.networkIsEthereum(type)) { + return { + address: toChecksumAddress(this.getEthereumAddress(derived).toString()), + public_key: derived.privateKey.publicKey.toString(), + private_key: derived.privateKey.toString() + } + } + return { + address: derived.privateKey.toAddress(type.network).toString(), + public_key: derived.privateKey.publicKey.toString(), + private_key: derived.privateKey.toString() + } + } + + /** + * 以太坊地址格式转换 + * @param {Object} derived + */ + static getEthereumAddress(derived) { + const publicKey = derived.hdPublicKey.publicKey.toBuffer() + const ethPublicKey = secp256k1.publicKeyConvert(publicKey, false) + .slice(1) + return Address.fromPublicKey(toBuffer(ethPublicKey)) + } + + /** + * 是否是以太坊网络 + * @param {Object} type + */ + static networkIsEthereum(type) { + return type.isEthereum + } + +} diff --git a/wallet/_test.js b/wallet/_test.js new file mode 100644 index 0000000..a8c2e43 --- /dev/null +++ b/wallet/_test.js @@ -0,0 +1,29 @@ +import { + Wallet +} from "./Wallet.js" + +const code = Wallet.generateMnemonic(this.defaultLanguage) +this.mnemonicCode = code +const hdPrivateKey = Wallet.toHDPrivateKey(this.mnemonicCode) +// const derived = hdPrivateKey.derive("m/44'/61'/0'/0/0"); +// const publicKey = derived.hdPublicKey.publicKey.toBuffer() +// const ethPublicKey = secp256k1.publicKeyConvert(publicKey, false) +// .slice(1) + +// const ethAddr = Address.fromPublicKey(toBuffer(ethPublicKey)).toString(); + +// console.log(toChecksumAddress(ethAddr)); + +// console.log(Address.fromPrivateKey(hdPrivateKey.hdPublicKey.publicKey.toBuffer())); + +var addr = [] +for (var i in this.coinType) { + let whk = Wallet.HDPrivateKeyToAddress(hdPrivateKey, i) + let parmas = { + name: this.coinType[i], + address: whk.address, + private_key: whk.private_key, + } + addr.push(parmas) +} +this.address = addr diff --git a/wallet/index.js b/wallet/index.js new file mode 100644 index 0000000..62c9e5c --- /dev/null +++ b/wallet/index.js @@ -0,0 +1,24 @@ +import store from "@/store/index.js" + +const USE_SOTER_AUTH_KEY = 'USE_SOTER_AUTH_KEY' + +/** + * 初始化配置 + */ +const initWalletConfigs = () => { + // 生物识别 + const USE_SOTER = Boolean(uni.getStorageSync(USE_SOTER_AUTH_KEY)) + store.dispatch('wallet/setSoterAuth', USE_SOTER) + // 获取默认钱包 +} + +const setSoterAuthStatus = (opt) => { + uni.setStorageSync(USE_SOTER_AUTH_KEY, opt) + store.dispatch('wallet/setSoterAuth', opt) +} + +export default { + USE_SOTER_AUTH_KEY, + setSoterAuthStatus, + initWalletConfigs +} \ No newline at end of file diff --git a/wallet/networks.js b/wallet/networks.js new file mode 100644 index 0000000..179e338 --- /dev/null +++ b/wallet/networks.js @@ -0,0 +1,209 @@ +import Bitcore from "bitcore-lib" + +export default [{ + type: 0, + name: '比特币', + symbol: 'BTC', + code: 'btc', + isEthereum: false, + network: Bitcore.Networks.mainnet + }, + { + type: 60, + name: '以太坊', + symbol: 'ETH', + code: 'eth', + isEthereum: true + }, + { + type: 61, + name: '以太经典', + symbol: 'ETC', + code: 'etc', + isEthereum: true + }, + { + type: 60, + name: '赤子心', + symbol: 'CZX', + code: 'eth_0x3a2a239b1bdaae768ffa06314d523e88e98d4d1f', + isEthereum: true + }, + // { + // type: 2, + // name: '莱特币', + // symbol: 'LTC', + // isEthereum: false, + // network: Bitcore.Networks.add({ + // name: 'LTC', + // alias: 'LTC', + // pubkeyhash: 0x30, + // privatekey: 0x32, + // scripthash: 0xb0, + // bech32prefix: 'ltc', + // xpubkey: 0x019da462, + // xprivkey: 0x019d9cfe, + // networkMagic: 0xdbb6c0fb + // }) + // }, + { + type: 3, + name: '狗狗币', + symbol: 'DOGE', + code: 'doge', + isEthereum: false, + network: Bitcore.Networks.add({ + name: 'DOGE', + alias: 'DOGE', + pubkeyhash: 0x1e, + privatekey: 0x16, + scripthash: 0x9e, + bech32prefix: 'doge', + xpubkey: 0x02facafd, + xprivkey: 0x02fac398, + networkMagic: 0xc0c0c0c0 + }) + }, + + // { + // type: 133, + // name: '零币', + // symbol: 'ZEC', + // isEthereum: false, + // network: Bitcore.Networks.add({ + // name: 'ZEC', + // alias: 'ZEC', + // pubkeyhash: 0x1e, + // privatekey: 0x16, + // scripthash: 0x9e, + // bech32prefix: 'doge', + // xpubkey: 0x02facafd, + // xprivkey: 0x02fac398, + // networkMagic: 0xc0c0c0c0 + // }) + // }, + // { + // type: 144, + // name: 'XPR - 瑞波币', + // symbol: 'XPR', + // isEthereum: false, + // network: Bitcore.Networks.add({ + // name: 'XPR', + // alias: 'XPR', + // pubkeyhash: 0x1e, + // privatekey: 0x16, + // scripthash: 0x9e, + // bech32prefix: 'doge', + // xpubkey: 0x02facafd, + // xprivkey: 0x02fac398, + // networkMagic: 0xc0c0c0c0 + // }) + // }, + // { + // type: 145, + // name: '比特现金', + // symbol: 'BCH', + // isEthereum: false, + // network: Bitcore.Networks.add({ + // name: 'BCH', + // alias: 'BCH', + // pubkeyhash: 0x00, + // privatekey: 0x05, + // scripthash: 0x80, + // bech32prefix: 'bitcoincash', + // xpubkey: 0x0488b21e, + // xprivkey: 0x0488ade4, + // networkMagic: 0xd9b4bef9 + // }) + // }, + // { + // type: 195, + // name: '波场', + // symbol: 'TRX', + // isEthereum: false, + // network: Bitcore.Networks.add({ + // name: 'TRX', + // alias: 'TRX', + // pubkeyhash: 0x41, + // privatekey: 0x05, + // scripthash: 0x80, + // bech32prefix: '', + // xpubkey: 0x0488b21e, + // xprivkey: 0x0488ade4 + // }) + // }, + { + type: 195, + name: 'USDT(TRC20)', + symbol: 'USDT', + code: 'trx_TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', + isEthereum: false, + network: Bitcore.Networks.add({ + name: 'USDT', + alias: 'USDT', + pubkeyhash: 0x41, + privatekey: 0x05, + scripthash: 0x80, + bech32prefix: '', + xpubkey: 0x0488b21e, + xprivkey: 0x0488ade4 + }) + }, + { + type: 195, + name: 'USDT(ERC20)', + symbol: 'USDT', + code: 'eth_0xdac17f958d2ee523a2206206994597c13d831ec7', + isEthereum: true + }, + { + type: 0, + name: 'USDT(OMNI)', + symbol: 'USDT', + code: 'usdt', + isEthereum: false, + network: Bitcore.Networks.mainnet + }, + { + type: 13107, + name: '比特元', + symbol: 'BTY', + code: 'bty', + isEthereum: false, + network: Bitcore.Networks.add({ + name: 'BTY', + alias: 'BTY', + pubkeyhash: 0x00, + privatekey: 0x05, + scripthash: 0x80, + bech32prefix: 'bityuan', + xpubkey: 0x0488b21e, + xprivkey: 0x0488ade4, + networkMagic: 0xd9b4bef9 + }) + }, + // { + // type: 60, + // name: '元链', + // symbol: 'YCC', + // isEthereum: true + // }, + { + type: 13107, + name: 'JZC', + symbol: 'JZC', + code: 'bty', + isEthereum: false, + network: Bitcore.Networks.add({ + name: 'JZC', + alias: 'JZC', + pubkeyhash: 0x00, + privatekey: 0x05, + scripthash: 0x80, + bech32prefix: 'bityuan', + xpubkey: 0x0488b21e, + xprivkey: 0x0488ade4, + networkMagic: 0xd9b4bef9 + }) + } +]