使用修改过的web3和eth-sig-util
This commit is contained in:
parent
715ef231f5
commit
a8fbfca0ce
@ -11,10 +11,8 @@
|
||||
"author": "zhl",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@metamask/eth-sig-util": "^4.0.1",
|
||||
"bip39": "^3.0.4",
|
||||
"ethereumjs-wallet": "^1.0.2",
|
||||
"web3": "^1.7.4",
|
||||
"whatwg-fetch": "^3.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { AbiItem } from "web3-utils"
|
||||
export const abiERC1155: AbiItem[] = [
|
||||
|
||||
export const abiERC1155 = [
|
||||
{
|
||||
inputs: [
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { AbiItem } from "web3-utils"
|
||||
|
||||
export let abiERC20: AbiItem[] = [
|
||||
|
||||
export let abiERC20 = [
|
||||
{
|
||||
constant: true,
|
||||
inputs: [],
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { AbiItem } from "web3-utils"
|
||||
|
||||
export const abiERC721: AbiItem[] = [
|
||||
export const abiERC721 = [
|
||||
{
|
||||
constant: true,
|
||||
inputs: [
|
||||
|
@ -22,14 +22,3 @@ export const WALLET_CHAIN_CHANGE = 'wallet_chain_change'
|
||||
export const WALLET_ACCOUNT_CHANGE = 'wallet_account_change'
|
||||
|
||||
export const WALLET_TOKEN_TYPE_CHANGE = 'wallet_token_type_change'
|
||||
|
||||
// BEGIN of UI
|
||||
export const WALLET_SHOW_QR = 'wallet_show_qr'
|
||||
|
||||
export const WALLET_SHOW_ACCOUNT_LIST = 'wallet_show_account_list'
|
||||
|
||||
export const WALLET_HIDE_ACCOUNT_LIST = 'wallet_hide_account_list'
|
||||
|
||||
export const WALLET_SHOW_MODAL = 'wallet_show_modal'
|
||||
|
||||
export const WALLET_HIDE_MODAL = 'wallet_hide_modal'
|
17
src/index.ts
17
src/index.ts
@ -1,6 +1,7 @@
|
||||
|
||||
import { singleton } from "./decorator/singleton.decorator";
|
||||
import Web3 from 'web3';
|
||||
import Web3 from './lib/web3.min.js';
|
||||
let sth = import('./lib/ethSigUtil.js');
|
||||
import 'whatwg-fetch'
|
||||
import { ZError } from "./common/ZError";
|
||||
import { AllChains } from "./data/allchain";
|
||||
@ -11,7 +12,7 @@ import { IAccount, initAccount } from "./data/DataModel";
|
||||
import { DataManage } from "./manage/DataManage";
|
||||
import { WALLET_STORAGE_KEY_NAME } from "./config/constants";
|
||||
import { DEFALUT_TOKENS } from "./config/chain_config";
|
||||
import { recoverTypedSignature, signTypedData, SignTypedDataVersion } from "@metamask/eth-sig-util";
|
||||
|
||||
|
||||
var global =
|
||||
(typeof globalThis !== 'undefined' && globalThis) ||
|
||||
@ -22,7 +23,8 @@ declare global {
|
||||
interface Window {
|
||||
jc: {
|
||||
wallet: JCWallet;
|
||||
}
|
||||
},
|
||||
ethSigUtil: any;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +47,6 @@ export default class JCWallet {
|
||||
public erc20Standard: ERC20Standard
|
||||
public erc721Standard: ERC721Standard
|
||||
public mainHandlers = createWalletEvents()
|
||||
public uiHandlers = createWalletEvents()
|
||||
private dataManage = new DataManage()
|
||||
public data: IAccount[] = []
|
||||
public iconType = 'jazz'
|
||||
@ -208,18 +209,18 @@ export default class JCWallet {
|
||||
|
||||
public signTypedDataV4(signObj: any) {
|
||||
const account = this.currentAccount()
|
||||
return signTypedData({
|
||||
return window.ethSigUtil.signTypedData({
|
||||
data: signObj,
|
||||
privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'),
|
||||
version: SignTypedDataVersion.V4
|
||||
version: 'V4'
|
||||
})
|
||||
}
|
||||
|
||||
public recoverTypedSignatureV4(signObj: any, signature: string) {
|
||||
return recoverTypedSignature({
|
||||
return window.ethSigUtil.recoverTypedSignature({
|
||||
data: signObj,
|
||||
signature,
|
||||
version: SignTypedDataVersion.V4
|
||||
version: 'V4'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
23
src/lib/ethSigUtil.js
Normal file
23
src/lib/ethSigUtil.js
Normal file
File diff suppressed because one or more lines are too long
42858
src/lib/web3.min.js
vendored
Normal file
42858
src/lib/web3.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
||||
import Web3 from "web3";
|
||||
import Web3 from '../lib/web3.min.js';
|
||||
import { abiERC20 } from "../abis/abiERC20";
|
||||
import { BN, toUtf8 } from 'ethereumjs-util';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
import Web3 from "web3";
|
||||
import Web3 from '../lib/web3.min.js';
|
||||
import { abiERC721 } from "../abis/abiERC721";
|
||||
import { timeoutFetch } from '../util/net.util';
|
||||
import { getFormattedIpfsUrl } from '../util/wallet.util';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Web3 from "web3";
|
||||
import Web3 from '../lib/web3.min.js';
|
||||
import { BN } from 'ethereumjs-util';
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@
|
||||
"outDir": "build",
|
||||
"lib": [ "dom", "es5", "es2015", "es2015.promise" ],
|
||||
"target": "es5",
|
||||
"sourceMap": true,
|
||||
"sourceMap": false,
|
||||
"experimentalDecorators": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
@ -3,20 +3,21 @@ const path = require("path");
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
// mode: 'development',
|
||||
entry: "./build/index.js",
|
||||
// entry: "./build/index.js",
|
||||
entry: "./src/index.ts",
|
||||
// devtool: "inline-source-map",
|
||||
target: "web",
|
||||
// module: {
|
||||
// rules: [
|
||||
// {
|
||||
// test: /\.ts?$/,
|
||||
// use: "ts-loader"
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// resolve: {
|
||||
// extensions: [".tsx", ".ts", ".js"],
|
||||
// },
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts?$/,
|
||||
use: "ts-loader"
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".tsx", ".ts", ".js"],
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "index.js",
|
||||
|
Loading…
x
Reference in New Issue
Block a user