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