@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.
Files changed (69) hide show
  1. package/.github/FUNDING.yml +3 -3
  2. package/.github/workflows/npm-publish.yml +34 -34
  3. package/.prettierrc.json +9 -9
  4. package/.vscode/extensions.json +3 -3
  5. package/LICENSE +674 -674
  6. package/README.md +41 -41
  7. package/dist/{main-d0e5d1e4.js → main-bbea3e54.js} +155 -153
  8. package/dist/ping-widget.js +2 -2
  9. package/dist/ping-widget.umd.cjs +18 -18
  10. package/dist/{query.lcd-3d4d3495.js → query.lcd-88036522.js} +1 -1
  11. package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-3a2b14f8.js} +1 -1
  12. package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-39f0b824.js} +1 -1
  13. package/example/.vscode/extensions.json +3 -3
  14. package/example/README.md +7 -7
  15. package/example/index.html +12 -12
  16. package/example/package.json +19 -19
  17. package/example/pnpm-lock.yaml +465 -465
  18. package/example/public/cdn.html +19 -19
  19. package/example/src/App.vue +73 -73
  20. package/example/src/main.js +4 -4
  21. package/example/vite.config.js +7 -7
  22. package/index.html +12 -12
  23. package/lib/components/ConnectWallet/index.vue +262 -262
  24. package/lib/components/TokenConvert/index.vue +1033 -1033
  25. package/lib/components/TokenConvert/tokens.ts +36 -36
  26. package/lib/components/TxDialog/index.vue +422 -422
  27. package/lib/components/TxDialog/messages/Delegate.vue +174 -174
  28. package/lib/components/TxDialog/messages/Deposit.vue +96 -96
  29. package/lib/components/TxDialog/messages/Redelegate.vue +160 -160
  30. package/lib/components/TxDialog/messages/Send.vue +142 -142
  31. package/lib/components/TxDialog/messages/Transfer.vue +248 -248
  32. package/lib/components/TxDialog/messages/Unbond.vue +103 -103
  33. package/lib/components/TxDialog/messages/Vote.vue +62 -62
  34. package/lib/components/TxDialog/messages/Withdraw.vue +55 -55
  35. package/lib/components/TxDialog/messages/WithdrawCommission.vue +74 -74
  36. package/lib/components/TxDialog/wasm/ClearAdmin.vue +55 -55
  37. package/lib/components/TxDialog/wasm/ExecuteContract.vue +98 -98
  38. package/lib/components/TxDialog/wasm/InstantiateContract.vue +108 -108
  39. package/lib/components/TxDialog/wasm/MigrateContract.vue +76 -76
  40. package/lib/components/TxDialog/wasm/MigrateContract2.vue +76 -76
  41. package/lib/components/TxDialog/wasm/StoreCode.vue +100 -100
  42. package/lib/components/TxDialog/wasm/UpdateAdmin.vue +74 -74
  43. package/lib/main.css +591 -7
  44. package/lib/main.ts +24 -23
  45. package/lib/utils/TokenUnitConverter.ts +44 -44
  46. package/lib/utils/format.ts +16 -16
  47. package/lib/utils/http.ts +154 -154
  48. package/lib/utils/type.ts +56 -56
  49. package/lib/wallet/EthermintMessageAdapter.ts +135 -135
  50. package/lib/wallet/UniClient.ts +144 -144
  51. package/lib/wallet/Wallet.ts +142 -142
  52. package/lib/wallet/wallets/KeplerWallet.ts +141 -141
  53. package/lib/wallet/wallets/LeapWallet.ts +141 -141
  54. package/lib/wallet/wallets/LedgerWallet.ts +202 -202
  55. package/lib/wallet/wallets/MetamaskSnapWallet.ts +105 -105
  56. package/lib/wallet/wallets/MetamaskWallet.ts +173 -173
  57. package/lib/wallet/wallets/OKXWallet.ts +202 -202
  58. package/lib/wallet/wallets/UnisatWallet.ts +198 -198
  59. package/package.json +5 -6
  60. package/postcss.config.js +6 -6
  61. package/src/App.vue +225 -225
  62. package/src/main.ts +7 -4
  63. package/src/styles/design-system.css +184 -0
  64. package/src/vite-env.d.ts +1 -1
  65. package/tailwind.config.js +158 -34
  66. package/tsconfig.json +25 -25
  67. package/tsconfig.node.json +10 -10
  68. package/vite.config.ts +62 -62
  69. 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
+ }