@mictonode/widget 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +3 -3
- package/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc.json +9 -9
- package/.vscode/extensions.json +3 -3
- package/LICENSE +674 -674
- package/README.md +41 -41
- package/dist/{main-d0e5d1e4.js → main-bbea3e54.js} +155 -153
- package/dist/ping-widget.js +2 -2
- package/dist/ping-widget.umd.cjs +18 -18
- package/dist/{query.lcd-3d4d3495.js → query.lcd-88036522.js} +1 -1
- package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-3a2b14f8.js} +1 -1
- package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-39f0b824.js} +1 -1
- package/example/.vscode/extensions.json +3 -3
- package/example/README.md +7 -7
- package/example/index.html +12 -12
- package/example/package.json +19 -19
- package/example/pnpm-lock.yaml +465 -465
- package/example/public/cdn.html +19 -19
- package/example/src/App.vue +73 -73
- package/example/src/main.js +4 -4
- package/example/vite.config.js +7 -7
- package/index.html +12 -12
- package/lib/components/ConnectWallet/index.vue +262 -262
- package/lib/components/TokenConvert/index.vue +1033 -1033
- package/lib/components/TokenConvert/tokens.ts +36 -36
- package/lib/components/TxDialog/index.vue +422 -422
- package/lib/components/TxDialog/messages/Delegate.vue +174 -174
- package/lib/components/TxDialog/messages/Deposit.vue +96 -96
- package/lib/components/TxDialog/messages/Redelegate.vue +160 -160
- package/lib/components/TxDialog/messages/Send.vue +142 -142
- package/lib/components/TxDialog/messages/Transfer.vue +248 -248
- package/lib/components/TxDialog/messages/Unbond.vue +103 -103
- package/lib/components/TxDialog/messages/Vote.vue +62 -62
- package/lib/components/TxDialog/messages/Withdraw.vue +55 -55
- package/lib/components/TxDialog/messages/WithdrawCommission.vue +74 -74
- package/lib/components/TxDialog/wasm/ClearAdmin.vue +55 -55
- package/lib/components/TxDialog/wasm/ExecuteContract.vue +98 -98
- package/lib/components/TxDialog/wasm/InstantiateContract.vue +108 -108
- package/lib/components/TxDialog/wasm/MigrateContract.vue +76 -76
- package/lib/components/TxDialog/wasm/MigrateContract2.vue +76 -76
- package/lib/components/TxDialog/wasm/StoreCode.vue +100 -100
- package/lib/components/TxDialog/wasm/UpdateAdmin.vue +74 -74
- package/lib/main.css +591 -7
- package/lib/main.ts +24 -23
- package/lib/utils/TokenUnitConverter.ts +44 -44
- package/lib/utils/format.ts +16 -16
- package/lib/utils/http.ts +154 -154
- package/lib/utils/type.ts +56 -56
- package/lib/wallet/EthermintMessageAdapter.ts +135 -135
- package/lib/wallet/UniClient.ts +144 -144
- package/lib/wallet/Wallet.ts +142 -142
- package/lib/wallet/wallets/KeplerWallet.ts +141 -141
- package/lib/wallet/wallets/LeapWallet.ts +141 -141
- package/lib/wallet/wallets/LedgerWallet.ts +202 -202
- package/lib/wallet/wallets/MetamaskSnapWallet.ts +105 -105
- package/lib/wallet/wallets/MetamaskWallet.ts +173 -173
- package/lib/wallet/wallets/OKXWallet.ts +202 -202
- package/lib/wallet/wallets/UnisatWallet.ts +198 -198
- package/package.json +5 -6
- package/postcss.config.js +6 -6
- package/src/App.vue +225 -225
- package/src/main.ts +7 -4
- package/src/styles/design-system.css +184 -0
- package/src/vite-env.d.ts +1 -1
- package/tailwind.config.js +158 -34
- package/tsconfig.json +25 -25
- package/tsconfig.node.json +10 -10
- package/vite.config.ts +62 -62
- package/vue-shim.d.ts +6 -6
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
import { AbstractWallet, Account, WalletArgument, WalletName, extractChainId, keyType } from '../Wallet';
|
|
2
|
-
import { fromBase64, fromBech32, toHex, fromHex, toBase64 } from '@cosmjs/encoding';
|
|
3
|
-
import {
|
|
4
|
-
Registry,
|
|
5
|
-
encodePubkey,
|
|
6
|
-
makeAuthInfoBytes,
|
|
7
|
-
} from '@cosmjs/proto-signing';
|
|
8
|
-
import { Transaction } from '../../utils/type';
|
|
9
|
-
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
10
|
-
import { hashMessage } from '@ethersproject/hash';
|
|
11
|
-
import { computePublicKey, recoverPublicKey } from '@ethersproject/signing-key';
|
|
12
|
-
import { ethToEthermint, ethermintToEth } from '../../utils/format';
|
|
13
|
-
import { AminoTypes, createDefaultAminoConverters } from "@cosmjs/stargate"
|
|
14
|
-
import { Chain, createTxRawEIP712, signatureToWeb3Extension } from "@tharsis/transactions";
|
|
15
|
-
import { createEIP712, generateFee, generateMessageWithMultipleTransactions, generateTypes } from "@tharsis/eip712";
|
|
16
|
-
import { defaultMessageAdapter } from '../EthermintMessageAdapter';
|
|
17
|
-
import { Any } from "cosmjs-types/google/protobuf/any";
|
|
18
|
-
import { PubKey } from 'cosmjs-types/cosmos/crypto/secp256k1/keys'
|
|
19
|
-
|
|
20
|
-
export class MetamaskWallet implements AbstractWallet {
|
|
21
|
-
name: WalletName.Metamask;
|
|
22
|
-
chainId: string;
|
|
23
|
-
registry: Registry;
|
|
24
|
-
prefix: string;
|
|
25
|
-
aminoTypes = new AminoTypes(createDefaultAminoConverters())
|
|
26
|
-
|
|
27
|
-
constructor(arg: WalletArgument, registry: Registry) {
|
|
28
|
-
this.chainId = arg.chainId || 'cosmoshub';
|
|
29
|
-
this.registry = registry;
|
|
30
|
-
this.prefix = arg.prefix || 'evmos'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async getAccounts(): Promise<Account[]> {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
if (!window.ethereum || !window.ethereum.request) {
|
|
36
|
-
throw new Error('Please install Metamask extension');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// @ts-ignore46
|
|
40
|
-
const accounts = await window.ethereum.request({
|
|
41
|
-
method: 'eth_requestAccounts',
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const message = 'Verify Public Key';
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
const signature = await window?.ethereum?.request({
|
|
47
|
-
method: 'personal_sign',
|
|
48
|
-
params: [message, accounts[0], ''],
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const uncompressedPk = recoverPublicKey(
|
|
52
|
-
hashMessage(message),
|
|
53
|
-
signature
|
|
54
|
-
);
|
|
55
|
-
const hexPk = computePublicKey(uncompressedPk, true);
|
|
56
|
-
const pk = toBase64(fromHex(hexPk.replace('0x', '')));
|
|
57
|
-
|
|
58
|
-
const connected = accounts.map((address) => ({
|
|
59
|
-
address: ethToEthermint(address, this.prefix),
|
|
60
|
-
algo: 'secp256k1',
|
|
61
|
-
pubkey: pk,
|
|
62
|
-
}))
|
|
63
|
-
|
|
64
|
-
localStorage.setItem("metamask-connected", JSON.stringify(connected))
|
|
65
|
-
|
|
66
|
-
return connected;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async getConnectedAccounts() {
|
|
70
|
-
const connected = localStorage.getItem("metamask-connected")
|
|
71
|
-
if(connected) {
|
|
72
|
-
return JSON.parse(connected) as Account[]
|
|
73
|
-
}
|
|
74
|
-
return this.getAccounts()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async supportCoinType(coinType?: string): Promise<boolean> {
|
|
78
|
-
// Here, you can check if Metamask supports a specific type of cryptocurrency.
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async sign(transaction: Transaction): Promise<TxRaw | Uint8Array> {
|
|
83
|
-
const { signerAddress, messages, fee, signerData } =
|
|
84
|
-
transaction;
|
|
85
|
-
|
|
86
|
-
const senderHexAddress = ethermintToEth(signerAddress);
|
|
87
|
-
const chain: Chain = {
|
|
88
|
-
chainId: extractChainId(signerData.chainId),
|
|
89
|
-
cosmosChainId: signerData.chainId,
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// getAccounts
|
|
93
|
-
const accounts = await this.getConnectedAccounts();
|
|
94
|
-
const account = accounts.find(acc => ethermintToEth(acc.address) === senderHexAddress );
|
|
95
|
-
if (!account) {
|
|
96
|
-
throw new Error('Account not found');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
console.log("account:", account)
|
|
100
|
-
|
|
101
|
-
const pubkeyBytes = String(account.pubkey)
|
|
102
|
-
console.log("toBase64(pubkeyBytes)", pubkeyBytes)
|
|
103
|
-
|
|
104
|
-
const sender = {
|
|
105
|
-
accountAddress: transaction.signerAddress,
|
|
106
|
-
sequence: transaction.signerData.sequence,
|
|
107
|
-
accountNumber: transaction.signerData.accountNumber,
|
|
108
|
-
pubkey: pubkeyBytes,
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const fees = generateFee(transaction.fee.amount[0].amount, transaction.fee.amount[0].denom, transaction.fee.gas, transaction.signerAddress)
|
|
112
|
-
|
|
113
|
-
const msgs = transaction.messages.map(x => this.aminoTypes.toAmino(x))
|
|
114
|
-
const toSignTx = generateMessageWithMultipleTransactions(
|
|
115
|
-
sender.accountNumber.toString(),
|
|
116
|
-
sender.sequence.toString(),
|
|
117
|
-
transaction.signerData.chainId,
|
|
118
|
-
transaction.memo,
|
|
119
|
-
fees,
|
|
120
|
-
msgs,
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
const types = generateTypes(defaultMessageAdapter[transaction.messages[0].typeUrl].getTypes())
|
|
124
|
-
const eip712Payload = createEIP712(types, chain.chainId, toSignTx)
|
|
125
|
-
|
|
126
|
-
// Obtaining the data required for MetaMask signature
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
// const acc = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
|
129
|
-
// console.log("accounts: ", acc)
|
|
130
|
-
|
|
131
|
-
// const eip712Payload = JSON.stringify(messages[0]);
|
|
132
|
-
|
|
133
|
-
// Signing an EIP-712 payload using MetaMask.
|
|
134
|
-
// @ts-ignore
|
|
135
|
-
const signature = await window.ethereum.request({
|
|
136
|
-
method: 'eth_signTypedData_v4',
|
|
137
|
-
params: [senderHexAddress, JSON.stringify(eip712Payload)],
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Creating a TxRaw object after signing.
|
|
141
|
-
const signatureBytes = fromHex(signature.replace('0x', ''));
|
|
142
|
-
const txBodyBytes = this.registry.encode({
|
|
143
|
-
typeUrl: '/cosmos.tx.v1beta1.TxBody',
|
|
144
|
-
value: { messages },
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// NOTE: assume ethsecp256k1 by default because after mainnet is the only one that is going to be supported
|
|
150
|
-
const pubkey = Any.fromPartial({
|
|
151
|
-
typeUrl: keyType(signerData.chainId),
|
|
152
|
-
value: PubKey.encode({
|
|
153
|
-
key: fromBase64(pubkeyBytes),
|
|
154
|
-
}).finish()
|
|
155
|
-
})
|
|
156
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
157
|
-
[{ pubkey, sequence: signerData.sequence }],
|
|
158
|
-
fee.amount,
|
|
159
|
-
Number(fee.gas),
|
|
160
|
-
undefined, // feeGranter
|
|
161
|
-
undefined // feePayer
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// Using TxRaw.fromPartial to create a TxRaw object with attribute values.
|
|
165
|
-
const signedTx: TxRaw = TxRaw.fromPartial({
|
|
166
|
-
bodyBytes: txBodyBytes,
|
|
167
|
-
authInfoBytes: authInfoBytes,
|
|
168
|
-
signatures: [signatureBytes],
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
return signedTx; // Create the txRaw
|
|
172
|
-
}
|
|
173
|
-
}
|
|
1
|
+
import { AbstractWallet, Account, WalletArgument, WalletName, extractChainId, keyType } from '../Wallet';
|
|
2
|
+
import { fromBase64, fromBech32, toHex, fromHex, toBase64 } from '@cosmjs/encoding';
|
|
3
|
+
import {
|
|
4
|
+
Registry,
|
|
5
|
+
encodePubkey,
|
|
6
|
+
makeAuthInfoBytes,
|
|
7
|
+
} from '@cosmjs/proto-signing';
|
|
8
|
+
import { Transaction } from '../../utils/type';
|
|
9
|
+
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
10
|
+
import { hashMessage } from '@ethersproject/hash';
|
|
11
|
+
import { computePublicKey, recoverPublicKey } from '@ethersproject/signing-key';
|
|
12
|
+
import { ethToEthermint, ethermintToEth } from '../../utils/format';
|
|
13
|
+
import { AminoTypes, createDefaultAminoConverters } from "@cosmjs/stargate"
|
|
14
|
+
import { Chain, createTxRawEIP712, signatureToWeb3Extension } from "@tharsis/transactions";
|
|
15
|
+
import { createEIP712, generateFee, generateMessageWithMultipleTransactions, generateTypes } from "@tharsis/eip712";
|
|
16
|
+
import { defaultMessageAdapter } from '../EthermintMessageAdapter';
|
|
17
|
+
import { Any } from "cosmjs-types/google/protobuf/any";
|
|
18
|
+
import { PubKey } from 'cosmjs-types/cosmos/crypto/secp256k1/keys'
|
|
19
|
+
|
|
20
|
+
export class MetamaskWallet implements AbstractWallet {
|
|
21
|
+
name: WalletName.Metamask;
|
|
22
|
+
chainId: string;
|
|
23
|
+
registry: Registry;
|
|
24
|
+
prefix: string;
|
|
25
|
+
aminoTypes = new AminoTypes(createDefaultAminoConverters())
|
|
26
|
+
|
|
27
|
+
constructor(arg: WalletArgument, registry: Registry) {
|
|
28
|
+
this.chainId = arg.chainId || 'cosmoshub';
|
|
29
|
+
this.registry = registry;
|
|
30
|
+
this.prefix = arg.prefix || 'evmos'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getAccounts(): Promise<Account[]> {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
if (!window.ethereum || !window.ethereum.request) {
|
|
36
|
+
throw new Error('Please install Metamask extension');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// @ts-ignore46
|
|
40
|
+
const accounts = await window.ethereum.request({
|
|
41
|
+
method: 'eth_requestAccounts',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const message = 'Verify Public Key';
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
const signature = await window?.ethereum?.request({
|
|
47
|
+
method: 'personal_sign',
|
|
48
|
+
params: [message, accounts[0], ''],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const uncompressedPk = recoverPublicKey(
|
|
52
|
+
hashMessage(message),
|
|
53
|
+
signature
|
|
54
|
+
);
|
|
55
|
+
const hexPk = computePublicKey(uncompressedPk, true);
|
|
56
|
+
const pk = toBase64(fromHex(hexPk.replace('0x', '')));
|
|
57
|
+
|
|
58
|
+
const connected = accounts.map((address) => ({
|
|
59
|
+
address: ethToEthermint(address, this.prefix),
|
|
60
|
+
algo: 'secp256k1',
|
|
61
|
+
pubkey: pk,
|
|
62
|
+
}))
|
|
63
|
+
|
|
64
|
+
localStorage.setItem("metamask-connected", JSON.stringify(connected))
|
|
65
|
+
|
|
66
|
+
return connected;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getConnectedAccounts() {
|
|
70
|
+
const connected = localStorage.getItem("metamask-connected")
|
|
71
|
+
if(connected) {
|
|
72
|
+
return JSON.parse(connected) as Account[]
|
|
73
|
+
}
|
|
74
|
+
return this.getAccounts()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async supportCoinType(coinType?: string): Promise<boolean> {
|
|
78
|
+
// Here, you can check if Metamask supports a specific type of cryptocurrency.
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async sign(transaction: Transaction): Promise<TxRaw | Uint8Array> {
|
|
83
|
+
const { signerAddress, messages, fee, signerData } =
|
|
84
|
+
transaction;
|
|
85
|
+
|
|
86
|
+
const senderHexAddress = ethermintToEth(signerAddress);
|
|
87
|
+
const chain: Chain = {
|
|
88
|
+
chainId: extractChainId(signerData.chainId),
|
|
89
|
+
cosmosChainId: signerData.chainId,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// getAccounts
|
|
93
|
+
const accounts = await this.getConnectedAccounts();
|
|
94
|
+
const account = accounts.find(acc => ethermintToEth(acc.address) === senderHexAddress );
|
|
95
|
+
if (!account) {
|
|
96
|
+
throw new Error('Account not found');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log("account:", account)
|
|
100
|
+
|
|
101
|
+
const pubkeyBytes = String(account.pubkey)
|
|
102
|
+
console.log("toBase64(pubkeyBytes)", pubkeyBytes)
|
|
103
|
+
|
|
104
|
+
const sender = {
|
|
105
|
+
accountAddress: transaction.signerAddress,
|
|
106
|
+
sequence: transaction.signerData.sequence,
|
|
107
|
+
accountNumber: transaction.signerData.accountNumber,
|
|
108
|
+
pubkey: pubkeyBytes,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const fees = generateFee(transaction.fee.amount[0].amount, transaction.fee.amount[0].denom, transaction.fee.gas, transaction.signerAddress)
|
|
112
|
+
|
|
113
|
+
const msgs = transaction.messages.map(x => this.aminoTypes.toAmino(x))
|
|
114
|
+
const toSignTx = generateMessageWithMultipleTransactions(
|
|
115
|
+
sender.accountNumber.toString(),
|
|
116
|
+
sender.sequence.toString(),
|
|
117
|
+
transaction.signerData.chainId,
|
|
118
|
+
transaction.memo,
|
|
119
|
+
fees,
|
|
120
|
+
msgs,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
const types = generateTypes(defaultMessageAdapter[transaction.messages[0].typeUrl].getTypes())
|
|
124
|
+
const eip712Payload = createEIP712(types, chain.chainId, toSignTx)
|
|
125
|
+
|
|
126
|
+
// Obtaining the data required for MetaMask signature
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
// const acc = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
|
129
|
+
// console.log("accounts: ", acc)
|
|
130
|
+
|
|
131
|
+
// const eip712Payload = JSON.stringify(messages[0]);
|
|
132
|
+
|
|
133
|
+
// Signing an EIP-712 payload using MetaMask.
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
const signature = await window.ethereum.request({
|
|
136
|
+
method: 'eth_signTypedData_v4',
|
|
137
|
+
params: [senderHexAddress, JSON.stringify(eip712Payload)],
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Creating a TxRaw object after signing.
|
|
141
|
+
const signatureBytes = fromHex(signature.replace('0x', ''));
|
|
142
|
+
const txBodyBytes = this.registry.encode({
|
|
143
|
+
typeUrl: '/cosmos.tx.v1beta1.TxBody',
|
|
144
|
+
value: { messages },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
// NOTE: assume ethsecp256k1 by default because after mainnet is the only one that is going to be supported
|
|
150
|
+
const pubkey = Any.fromPartial({
|
|
151
|
+
typeUrl: keyType(signerData.chainId),
|
|
152
|
+
value: PubKey.encode({
|
|
153
|
+
key: fromBase64(pubkeyBytes),
|
|
154
|
+
}).finish()
|
|
155
|
+
})
|
|
156
|
+
const authInfoBytes = makeAuthInfoBytes(
|
|
157
|
+
[{ pubkey, sequence: signerData.sequence }],
|
|
158
|
+
fee.amount,
|
|
159
|
+
Number(fee.gas),
|
|
160
|
+
undefined, // feeGranter
|
|
161
|
+
undefined // feePayer
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Using TxRaw.fromPartial to create a TxRaw object with attribute values.
|
|
165
|
+
const signedTx: TxRaw = TxRaw.fromPartial({
|
|
166
|
+
bodyBytes: txBodyBytes,
|
|
167
|
+
authInfoBytes: authInfoBytes,
|
|
168
|
+
signatures: [signatureBytes],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return signedTx; // Create the txRaw
|
|
172
|
+
}
|
|
173
|
+
}
|