@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,141 +1,141 @@
|
|
|
1
|
-
import { fromBase64, fromBech32, toHex } from "@cosmjs/encoding";
|
|
2
|
-
import { OfflineSigner, Registry, TxBodyEncodeObject, encodePubkey, makeAuthInfoBytes, makeSignDoc } from "@cosmjs/proto-signing"
|
|
3
|
-
import { AbstractWallet, Account, WalletArgument, WalletName, keyType } from "../Wallet"
|
|
4
|
-
import { Transaction } from "../../utils/type"
|
|
5
|
-
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
6
|
-
import { Any } from "cosmjs-types/google/protobuf/any";
|
|
7
|
-
import { PubKey } from 'cosmjs-types/cosmos/crypto/secp256k1/keys'
|
|
8
|
-
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
|
|
9
|
-
import { AminoTypes, createDefaultAminoConverters } from "@cosmjs/stargate";
|
|
10
|
-
import { encodeSecp256k1Pubkey, makeSignDoc as makeSignDocAmino } from "@cosmjs/amino";
|
|
11
|
-
import { createWasmAminoConverters } from "@cosmjs/cosmwasm-stargate";
|
|
12
|
-
|
|
13
|
-
export class LeapWallet implements AbstractWallet {
|
|
14
|
-
name: WalletName.Leap
|
|
15
|
-
chainId: string
|
|
16
|
-
registry: Registry
|
|
17
|
-
conf: WalletArgument
|
|
18
|
-
signer: OfflineSigner
|
|
19
|
-
aminoTypes = new AminoTypes( {...createDefaultAminoConverters(), ...createWasmAminoConverters()})
|
|
20
|
-
constructor(arg: WalletArgument, registry: Registry) {
|
|
21
|
-
this.chainId = arg.chainId || "cosmoshub"
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
if (!window.getOfflineSigner || !window.leap) {
|
|
24
|
-
throw new Error('Please install Leap extension')
|
|
25
|
-
}
|
|
26
|
-
this.registry = registry
|
|
27
|
-
this.conf = arg
|
|
28
|
-
}
|
|
29
|
-
async getAccounts(): Promise<Account[]> {
|
|
30
|
-
// const chainId = 'cosmoshub'
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
await window.leap.enable(this.chainId);
|
|
33
|
-
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
this.signer = await window.leap.getOfflineSigner(this.chainId);
|
|
36
|
-
return await this.signer.getAccounts();
|
|
37
|
-
}
|
|
38
|
-
supportCoinType(coinType?: string | undefined): Promise<boolean> {
|
|
39
|
-
return Promise.resolve(true);
|
|
40
|
-
}
|
|
41
|
-
isEthermint() {
|
|
42
|
-
return this.conf.hdPath && this.conf.hdPath.startsWith("m/44'/60")
|
|
43
|
-
}
|
|
44
|
-
async sign(transaction: Transaction): Promise<TxRaw> {
|
|
45
|
-
return this.signAmino(transaction)
|
|
46
|
-
}
|
|
47
|
-
// @deprecated use signAmino instead
|
|
48
|
-
// because signDirect is not supported ledger wallet
|
|
49
|
-
async signDirect(transaction: Transaction): Promise<TxRaw> {
|
|
50
|
-
const accouts = await this.getAccounts()
|
|
51
|
-
const hex = toHex(fromBech32(transaction.signerAddress).data)
|
|
52
|
-
const accountFromSigner = accouts.find((account) => toHex(fromBech32(account.address).data) === hex);
|
|
53
|
-
if (!accountFromSigner) {
|
|
54
|
-
throw new Error("Failed to retrieve account from signer");
|
|
55
|
-
}
|
|
56
|
-
const pubkey = Any.fromPartial({
|
|
57
|
-
typeUrl: keyType(transaction.chainId),
|
|
58
|
-
value: PubKey.encode({
|
|
59
|
-
key: accountFromSigner.pubkey,
|
|
60
|
-
}).finish()
|
|
61
|
-
})
|
|
62
|
-
const txBodyEncodeObject: TxBodyEncodeObject = {
|
|
63
|
-
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
64
|
-
value: {
|
|
65
|
-
messages: transaction.messages,
|
|
66
|
-
memo: transaction.memo,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
70
|
-
const gasLimit = Number(transaction.fee.gas);
|
|
71
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
72
|
-
[{ pubkey, sequence: transaction.signerData.sequence }],
|
|
73
|
-
transaction.fee.amount,
|
|
74
|
-
gasLimit,
|
|
75
|
-
transaction.fee.granter,
|
|
76
|
-
transaction.fee.payer,
|
|
77
|
-
);
|
|
78
|
-
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, transaction.chainId, transaction.signerData.accountNumber);
|
|
79
|
-
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
// const offlineSigner = await window.leap.getOfflineSignerAuto(this.chainId);
|
|
82
|
-
// console.log(offlineSigner)
|
|
83
|
-
const { signature, signed } = await this.signer.signDirect(transaction.signerAddress, signDoc);;
|
|
84
|
-
return TxRaw.fromPartial({
|
|
85
|
-
bodyBytes: signed.bodyBytes,
|
|
86
|
-
authInfoBytes: signed.authInfoBytes,
|
|
87
|
-
signatures: [fromBase64(signature.signature)],
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async signAmino(tx: Transaction): Promise<TxRaw> {
|
|
92
|
-
const accouts = await this.getAccounts()
|
|
93
|
-
const hex = toHex(fromBech32(tx.signerAddress).data)
|
|
94
|
-
const accountFromSigner = accouts.find((account) => toHex(fromBech32(account.address).data) === hex);
|
|
95
|
-
if (!accountFromSigner) {
|
|
96
|
-
throw new Error("Failed to retrieve account from signer");
|
|
97
|
-
}
|
|
98
|
-
// const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
99
|
-
const pubkey = Any.fromPartial({
|
|
100
|
-
typeUrl: keyType(tx.chainId),
|
|
101
|
-
value: PubKey.encode({
|
|
102
|
-
key: accountFromSigner.pubkey,
|
|
103
|
-
}).finish()
|
|
104
|
-
})
|
|
105
|
-
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
106
|
-
const msgs = tx.messages.map((msg) => this.aminoTypes.toAmino(msg));
|
|
107
|
-
const signDoc = makeSignDocAmino(msgs, tx.fee, tx.chainId, tx.memo, tx.signerData.accountNumber, tx.signerData.sequence);
|
|
108
|
-
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
// const offlineSigner = window.getOfflineSigner(this.chainId)
|
|
111
|
-
const { signature, signed } = await this.signer.signAmino(tx.signerAddress, signDoc);
|
|
112
|
-
|
|
113
|
-
console.log(signature, 'signature', signed)
|
|
114
|
-
|
|
115
|
-
const signedTxBody = {
|
|
116
|
-
messages: signed.msgs.map((msg) => this.aminoTypes.fromAmino(msg)),
|
|
117
|
-
memo: signed.memo,
|
|
118
|
-
};
|
|
119
|
-
const signedTxBodyEncodeObject: TxBodyEncodeObject = {
|
|
120
|
-
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
121
|
-
value: signedTxBody,
|
|
122
|
-
};
|
|
123
|
-
const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
|
|
124
|
-
|
|
125
|
-
const signedGasLimit = Number(signed.fee.gas);
|
|
126
|
-
const signedSequence = Number(signed.sequence);
|
|
127
|
-
const signedAuthInfoBytes = makeAuthInfoBytes(
|
|
128
|
-
[{ pubkey, sequence: signedSequence }],
|
|
129
|
-
signed.fee.amount,
|
|
130
|
-
signedGasLimit,
|
|
131
|
-
signed.fee.granter,
|
|
132
|
-
signed.fee.payer,
|
|
133
|
-
signMode,
|
|
134
|
-
);
|
|
135
|
-
return TxRaw.fromPartial({
|
|
136
|
-
bodyBytes: signedTxBodyBytes,
|
|
137
|
-
authInfoBytes: signedAuthInfoBytes,
|
|
138
|
-
signatures: [fromBase64(signature.signature)],
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
1
|
+
import { fromBase64, fromBech32, toHex } from "@cosmjs/encoding";
|
|
2
|
+
import { OfflineSigner, Registry, TxBodyEncodeObject, encodePubkey, makeAuthInfoBytes, makeSignDoc } from "@cosmjs/proto-signing"
|
|
3
|
+
import { AbstractWallet, Account, WalletArgument, WalletName, keyType } from "../Wallet"
|
|
4
|
+
import { Transaction } from "../../utils/type"
|
|
5
|
+
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
6
|
+
import { Any } from "cosmjs-types/google/protobuf/any";
|
|
7
|
+
import { PubKey } from 'cosmjs-types/cosmos/crypto/secp256k1/keys'
|
|
8
|
+
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
|
|
9
|
+
import { AminoTypes, createDefaultAminoConverters } from "@cosmjs/stargate";
|
|
10
|
+
import { encodeSecp256k1Pubkey, makeSignDoc as makeSignDocAmino } from "@cosmjs/amino";
|
|
11
|
+
import { createWasmAminoConverters } from "@cosmjs/cosmwasm-stargate";
|
|
12
|
+
|
|
13
|
+
export class LeapWallet implements AbstractWallet {
|
|
14
|
+
name: WalletName.Leap
|
|
15
|
+
chainId: string
|
|
16
|
+
registry: Registry
|
|
17
|
+
conf: WalletArgument
|
|
18
|
+
signer: OfflineSigner
|
|
19
|
+
aminoTypes = new AminoTypes( {...createDefaultAminoConverters(), ...createWasmAminoConverters()})
|
|
20
|
+
constructor(arg: WalletArgument, registry: Registry) {
|
|
21
|
+
this.chainId = arg.chainId || "cosmoshub"
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
if (!window.getOfflineSigner || !window.leap) {
|
|
24
|
+
throw new Error('Please install Leap extension')
|
|
25
|
+
}
|
|
26
|
+
this.registry = registry
|
|
27
|
+
this.conf = arg
|
|
28
|
+
}
|
|
29
|
+
async getAccounts(): Promise<Account[]> {
|
|
30
|
+
// const chainId = 'cosmoshub'
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
await window.leap.enable(this.chainId);
|
|
33
|
+
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
this.signer = await window.leap.getOfflineSigner(this.chainId);
|
|
36
|
+
return await this.signer.getAccounts();
|
|
37
|
+
}
|
|
38
|
+
supportCoinType(coinType?: string | undefined): Promise<boolean> {
|
|
39
|
+
return Promise.resolve(true);
|
|
40
|
+
}
|
|
41
|
+
isEthermint() {
|
|
42
|
+
return this.conf.hdPath && this.conf.hdPath.startsWith("m/44'/60")
|
|
43
|
+
}
|
|
44
|
+
async sign(transaction: Transaction): Promise<TxRaw> {
|
|
45
|
+
return this.signAmino(transaction)
|
|
46
|
+
}
|
|
47
|
+
// @deprecated use signAmino instead
|
|
48
|
+
// because signDirect is not supported ledger wallet
|
|
49
|
+
async signDirect(transaction: Transaction): Promise<TxRaw> {
|
|
50
|
+
const accouts = await this.getAccounts()
|
|
51
|
+
const hex = toHex(fromBech32(transaction.signerAddress).data)
|
|
52
|
+
const accountFromSigner = accouts.find((account) => toHex(fromBech32(account.address).data) === hex);
|
|
53
|
+
if (!accountFromSigner) {
|
|
54
|
+
throw new Error("Failed to retrieve account from signer");
|
|
55
|
+
}
|
|
56
|
+
const pubkey = Any.fromPartial({
|
|
57
|
+
typeUrl: keyType(transaction.chainId),
|
|
58
|
+
value: PubKey.encode({
|
|
59
|
+
key: accountFromSigner.pubkey,
|
|
60
|
+
}).finish()
|
|
61
|
+
})
|
|
62
|
+
const txBodyEncodeObject: TxBodyEncodeObject = {
|
|
63
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
64
|
+
value: {
|
|
65
|
+
messages: transaction.messages,
|
|
66
|
+
memo: transaction.memo,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
70
|
+
const gasLimit = Number(transaction.fee.gas);
|
|
71
|
+
const authInfoBytes = makeAuthInfoBytes(
|
|
72
|
+
[{ pubkey, sequence: transaction.signerData.sequence }],
|
|
73
|
+
transaction.fee.amount,
|
|
74
|
+
gasLimit,
|
|
75
|
+
transaction.fee.granter,
|
|
76
|
+
transaction.fee.payer,
|
|
77
|
+
);
|
|
78
|
+
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, transaction.chainId, transaction.signerData.accountNumber);
|
|
79
|
+
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
// const offlineSigner = await window.leap.getOfflineSignerAuto(this.chainId);
|
|
82
|
+
// console.log(offlineSigner)
|
|
83
|
+
const { signature, signed } = await this.signer.signDirect(transaction.signerAddress, signDoc);;
|
|
84
|
+
return TxRaw.fromPartial({
|
|
85
|
+
bodyBytes: signed.bodyBytes,
|
|
86
|
+
authInfoBytes: signed.authInfoBytes,
|
|
87
|
+
signatures: [fromBase64(signature.signature)],
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async signAmino(tx: Transaction): Promise<TxRaw> {
|
|
92
|
+
const accouts = await this.getAccounts()
|
|
93
|
+
const hex = toHex(fromBech32(tx.signerAddress).data)
|
|
94
|
+
const accountFromSigner = accouts.find((account) => toHex(fromBech32(account.address).data) === hex);
|
|
95
|
+
if (!accountFromSigner) {
|
|
96
|
+
throw new Error("Failed to retrieve account from signer");
|
|
97
|
+
}
|
|
98
|
+
// const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
99
|
+
const pubkey = Any.fromPartial({
|
|
100
|
+
typeUrl: keyType(tx.chainId),
|
|
101
|
+
value: PubKey.encode({
|
|
102
|
+
key: accountFromSigner.pubkey,
|
|
103
|
+
}).finish()
|
|
104
|
+
})
|
|
105
|
+
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
106
|
+
const msgs = tx.messages.map((msg) => this.aminoTypes.toAmino(msg));
|
|
107
|
+
const signDoc = makeSignDocAmino(msgs, tx.fee, tx.chainId, tx.memo, tx.signerData.accountNumber, tx.signerData.sequence);
|
|
108
|
+
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
// const offlineSigner = window.getOfflineSigner(this.chainId)
|
|
111
|
+
const { signature, signed } = await this.signer.signAmino(tx.signerAddress, signDoc);
|
|
112
|
+
|
|
113
|
+
console.log(signature, 'signature', signed)
|
|
114
|
+
|
|
115
|
+
const signedTxBody = {
|
|
116
|
+
messages: signed.msgs.map((msg) => this.aminoTypes.fromAmino(msg)),
|
|
117
|
+
memo: signed.memo,
|
|
118
|
+
};
|
|
119
|
+
const signedTxBodyEncodeObject: TxBodyEncodeObject = {
|
|
120
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
121
|
+
value: signedTxBody,
|
|
122
|
+
};
|
|
123
|
+
const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
|
|
124
|
+
|
|
125
|
+
const signedGasLimit = Number(signed.fee.gas);
|
|
126
|
+
const signedSequence = Number(signed.sequence);
|
|
127
|
+
const signedAuthInfoBytes = makeAuthInfoBytes(
|
|
128
|
+
[{ pubkey, sequence: signedSequence }],
|
|
129
|
+
signed.fee.amount,
|
|
130
|
+
signedGasLimit,
|
|
131
|
+
signed.fee.granter,
|
|
132
|
+
signed.fee.payer,
|
|
133
|
+
signMode,
|
|
134
|
+
);
|
|
135
|
+
return TxRaw.fromPartial({
|
|
136
|
+
bodyBytes: signedTxBodyBytes,
|
|
137
|
+
authInfoBytes: signedAuthInfoBytes,
|
|
138
|
+
signatures: [fromBase64(signature.signature)],
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|