@mictonode/widget 0.3.16 → 0.3.17
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-465ae991.js} +151 -149
- package/dist/ping-widget.js +2 -2
- package/dist/ping-widget.umd.cjs +17 -17
- package/dist/{query.lcd-3d4d3495.js → query.lcd-d9c6163c.js} +1 -1
- package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-a479e6f9.js} +1 -1
- package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-7444045d.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 +8 -8
- 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 +132 -7
- package/lib/main.ts +23 -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 +3 -3
- package/postcss.config.js +6 -6
- package/src/App.vue +225 -225
- package/src/main.ts +7 -4
- package/src/styles/design-system.css +150 -0
- package/src/vite-env.d.ts +1 -1
- package/tailwind.config.js +211 -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
package/lib/wallet/UniClient.ts
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import { toBase64, fromBase64, toHex, fromBech32 } from "@cosmjs/encoding";
|
|
2
|
-
import { EncodeObject, encodePubkey, Registry } from '@cosmjs/proto-signing'
|
|
3
|
-
import { encodeSecp256k1Pubkey } from "@cosmjs/amino";
|
|
4
|
-
import { defaultRegistryTypes } from "@cosmjs/stargate";
|
|
5
|
-
import { AuthInfo, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
6
|
-
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
|
|
7
|
-
import { AbstractWallet, WalletArgument, WalletName, createWallet } from "./Wallet";
|
|
8
|
-
import { post } from "../utils/http";
|
|
9
|
-
import { BroadcastMode, Transaction, TxResponse } from "../utils/type";
|
|
10
|
-
import { wasmTypes } from "@cosmjs/cosmwasm-stargate/build/modules";
|
|
11
|
-
import { makeAuthInfoBytes, makeSignDoc, TxBodyEncodeObject } from "@cosmjs/proto-signing/build";
|
|
12
|
-
import { Any } from "cosmjs-types/google/protobuf/any";
|
|
13
|
-
|
|
14
|
-
export function isEthermint(chainId: string) {
|
|
15
|
-
return chainId.search(/\w+_\d+-\d+/g) > -1
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class UniClient {
|
|
19
|
-
registry: Registry
|
|
20
|
-
wallet: AbstractWallet
|
|
21
|
-
constructor(name: WalletName, arg: WalletArgument) {
|
|
22
|
-
this.registry = new Registry([...defaultRegistryTypes, ...wasmTypes])
|
|
23
|
-
this.wallet = createWallet(name, arg, this.registry)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async getAccounts() {
|
|
27
|
-
return this.wallet.getAccounts()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async sign(transaction: Transaction): Promise<TxRaw> {
|
|
31
|
-
// const { signature, signed } = await this.wallet.sign(transaction);
|
|
32
|
-
// return TxRaw.fromPartial({
|
|
33
|
-
// bodyBytes: signed.bodyBytes,
|
|
34
|
-
// authInfoBytes: signed.authInfoBytes,
|
|
35
|
-
// signatures: [fromBase64(signature.signature)],
|
|
36
|
-
// });
|
|
37
|
-
return this.wallet.sign(transaction)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async simulate (
|
|
41
|
-
endpoint: string,
|
|
42
|
-
transaction: Transaction,
|
|
43
|
-
mode: BroadcastMode = BroadcastMode.SYNC
|
|
44
|
-
) {
|
|
45
|
-
|
|
46
|
-
const pubkey = Any.fromPartial({
|
|
47
|
-
typeUrl: '/cosmos.crypto.ed25519.PubKey',
|
|
48
|
-
value: new Uint8Array()
|
|
49
|
-
})
|
|
50
|
-
const txBodyEncodeObject: TxBodyEncodeObject = {
|
|
51
|
-
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
52
|
-
value: {
|
|
53
|
-
messages: transaction.messages,
|
|
54
|
-
memo: transaction.memo,
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
59
|
-
const gasLimit = Number(transaction.fee.gas);
|
|
60
|
-
const authInfoBytes = makeAuthInfoBytes(
|
|
61
|
-
[{ pubkey, sequence: transaction.signerData.sequence }],
|
|
62
|
-
transaction.fee.amount,
|
|
63
|
-
gasLimit,
|
|
64
|
-
transaction.fee.granter,
|
|
65
|
-
transaction.fee.payer,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const txRaw = TxRaw.fromPartial({
|
|
69
|
-
bodyBytes: txBodyBytes,
|
|
70
|
-
authInfoBytes: authInfoBytes,
|
|
71
|
-
signatures: [new Uint8Array()],
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const txbytes = toBase64(TxRaw.encode(txRaw).finish())
|
|
75
|
-
const request = {
|
|
76
|
-
tx_bytes: txbytes,
|
|
77
|
-
mode, // BROADCAST_MODE_SYNC, BROADCAST_MODE_BLOCK, BROADCAST_MODE_ASYNC
|
|
78
|
-
}
|
|
79
|
-
return post(`${endpoint}/cosmos/tx/v1beta1/simulate`, request).then(res => {
|
|
80
|
-
if (res.code && res.code !== 0) {
|
|
81
|
-
throw new Error(res.message)
|
|
82
|
-
}
|
|
83
|
-
if (res.tx_response && res.tx_response.code !== 0) {
|
|
84
|
-
throw new Error(res.tx_response.raw_log)
|
|
85
|
-
}
|
|
86
|
-
return Number(res.gas_info.gas_used)
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// async simulate2(
|
|
91
|
-
// endpoint: string,
|
|
92
|
-
// messages: readonly EncodeObject[],
|
|
93
|
-
// memo: string | undefined,
|
|
94
|
-
// sequence: number
|
|
95
|
-
// ) {
|
|
96
|
-
|
|
97
|
-
// const [first] = await this.wallet.getAccounts()
|
|
98
|
-
// const pubkey = encodeSecp256k1Pubkey(first.pubkey);
|
|
99
|
-
// const anyMsgs = messages.map((m) => this.registry.encodeAsAny(m));
|
|
100
|
-
// const url = `${endpoint}/cosmos/tx/v1beta1/simulate`
|
|
101
|
-
// const tx = Tx.fromPartial({
|
|
102
|
-
// authInfo: AuthInfo.fromPartial({
|
|
103
|
-
// fee: Fee.fromPartial({}),
|
|
104
|
-
// signerInfos: [
|
|
105
|
-
// {
|
|
106
|
-
// publicKey: encodePubkey(pubkey),
|
|
107
|
-
// sequence: sequence,
|
|
108
|
-
// modeInfo: { single: { mode: SignMode.SIGN_MODE_UNSPECIFIED } },
|
|
109
|
-
// },
|
|
110
|
-
// ],
|
|
111
|
-
// }),
|
|
112
|
-
// body: TxBody.fromPartial({
|
|
113
|
-
// messages: Array.from(anyMsgs),
|
|
114
|
-
// memo: memo,
|
|
115
|
-
// }),
|
|
116
|
-
// signatures: [new Uint8Array()],
|
|
117
|
-
// });
|
|
118
|
-
// const request = SimulateRequest.fromPartial({
|
|
119
|
-
// tx
|
|
120
|
-
// // txBytes: Tx.encode(tx).finish(),
|
|
121
|
-
// });
|
|
122
|
-
// console.log(tx, request)
|
|
123
|
-
// return await post(url, request)
|
|
124
|
-
// }
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
async broadcastTx(endpoint, bodyBytes: TxRaw, mode: BroadcastMode = BroadcastMode.SYNC) : Promise<{tx_response: TxResponse}> {
|
|
128
|
-
// const txbytes = bodyBytes.authInfoBytes ? TxRaw.encode(bodyBytes).finish() : bodyBytes
|
|
129
|
-
const txbytes = TxRaw.encode(bodyBytes).finish()
|
|
130
|
-
const txString = toBase64(txbytes)
|
|
131
|
-
const txRaw = {
|
|
132
|
-
tx_bytes: txString,
|
|
133
|
-
mode, // BROADCAST_MODE_SYNC, BROADCAST_MODE_BLOCK, BROADCAST_MODE_ASYNC
|
|
134
|
-
}
|
|
135
|
-
return post(`${endpoint}/cosmos/tx/v1beta1/txs`, txRaw).then(res => {
|
|
136
|
-
if (res.code && res.code !== 0) {
|
|
137
|
-
throw new Error(res.message)
|
|
138
|
-
}
|
|
139
|
-
if (res.tx_response && res.tx_response.code !== 0) {
|
|
140
|
-
throw new Error(res.tx_response.raw_log)
|
|
141
|
-
}
|
|
142
|
-
return res
|
|
143
|
-
})
|
|
144
|
-
}
|
|
1
|
+
import { toBase64, fromBase64, toHex, fromBech32 } from "@cosmjs/encoding";
|
|
2
|
+
import { EncodeObject, encodePubkey, Registry } from '@cosmjs/proto-signing'
|
|
3
|
+
import { encodeSecp256k1Pubkey } from "@cosmjs/amino";
|
|
4
|
+
import { defaultRegistryTypes } from "@cosmjs/stargate";
|
|
5
|
+
import { AuthInfo, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
6
|
+
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
|
|
7
|
+
import { AbstractWallet, WalletArgument, WalletName, createWallet } from "./Wallet";
|
|
8
|
+
import { post } from "../utils/http";
|
|
9
|
+
import { BroadcastMode, Transaction, TxResponse } from "../utils/type";
|
|
10
|
+
import { wasmTypes } from "@cosmjs/cosmwasm-stargate/build/modules";
|
|
11
|
+
import { makeAuthInfoBytes, makeSignDoc, TxBodyEncodeObject } from "@cosmjs/proto-signing/build";
|
|
12
|
+
import { Any } from "cosmjs-types/google/protobuf/any";
|
|
13
|
+
|
|
14
|
+
export function isEthermint(chainId: string) {
|
|
15
|
+
return chainId.search(/\w+_\d+-\d+/g) > -1
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class UniClient {
|
|
19
|
+
registry: Registry
|
|
20
|
+
wallet: AbstractWallet
|
|
21
|
+
constructor(name: WalletName, arg: WalletArgument) {
|
|
22
|
+
this.registry = new Registry([...defaultRegistryTypes, ...wasmTypes])
|
|
23
|
+
this.wallet = createWallet(name, arg, this.registry)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getAccounts() {
|
|
27
|
+
return this.wallet.getAccounts()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async sign(transaction: Transaction): Promise<TxRaw> {
|
|
31
|
+
// const { signature, signed } = await this.wallet.sign(transaction);
|
|
32
|
+
// return TxRaw.fromPartial({
|
|
33
|
+
// bodyBytes: signed.bodyBytes,
|
|
34
|
+
// authInfoBytes: signed.authInfoBytes,
|
|
35
|
+
// signatures: [fromBase64(signature.signature)],
|
|
36
|
+
// });
|
|
37
|
+
return this.wallet.sign(transaction)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async simulate (
|
|
41
|
+
endpoint: string,
|
|
42
|
+
transaction: Transaction,
|
|
43
|
+
mode: BroadcastMode = BroadcastMode.SYNC
|
|
44
|
+
) {
|
|
45
|
+
|
|
46
|
+
const pubkey = Any.fromPartial({
|
|
47
|
+
typeUrl: '/cosmos.crypto.ed25519.PubKey',
|
|
48
|
+
value: new Uint8Array()
|
|
49
|
+
})
|
|
50
|
+
const txBodyEncodeObject: TxBodyEncodeObject = {
|
|
51
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
52
|
+
value: {
|
|
53
|
+
messages: transaction.messages,
|
|
54
|
+
memo: transaction.memo,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
59
|
+
const gasLimit = Number(transaction.fee.gas);
|
|
60
|
+
const authInfoBytes = makeAuthInfoBytes(
|
|
61
|
+
[{ pubkey, sequence: transaction.signerData.sequence }],
|
|
62
|
+
transaction.fee.amount,
|
|
63
|
+
gasLimit,
|
|
64
|
+
transaction.fee.granter,
|
|
65
|
+
transaction.fee.payer,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const txRaw = TxRaw.fromPartial({
|
|
69
|
+
bodyBytes: txBodyBytes,
|
|
70
|
+
authInfoBytes: authInfoBytes,
|
|
71
|
+
signatures: [new Uint8Array()],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const txbytes = toBase64(TxRaw.encode(txRaw).finish())
|
|
75
|
+
const request = {
|
|
76
|
+
tx_bytes: txbytes,
|
|
77
|
+
mode, // BROADCAST_MODE_SYNC, BROADCAST_MODE_BLOCK, BROADCAST_MODE_ASYNC
|
|
78
|
+
}
|
|
79
|
+
return post(`${endpoint}/cosmos/tx/v1beta1/simulate`, request).then(res => {
|
|
80
|
+
if (res.code && res.code !== 0) {
|
|
81
|
+
throw new Error(res.message)
|
|
82
|
+
}
|
|
83
|
+
if (res.tx_response && res.tx_response.code !== 0) {
|
|
84
|
+
throw new Error(res.tx_response.raw_log)
|
|
85
|
+
}
|
|
86
|
+
return Number(res.gas_info.gas_used)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// async simulate2(
|
|
91
|
+
// endpoint: string,
|
|
92
|
+
// messages: readonly EncodeObject[],
|
|
93
|
+
// memo: string | undefined,
|
|
94
|
+
// sequence: number
|
|
95
|
+
// ) {
|
|
96
|
+
|
|
97
|
+
// const [first] = await this.wallet.getAccounts()
|
|
98
|
+
// const pubkey = encodeSecp256k1Pubkey(first.pubkey);
|
|
99
|
+
// const anyMsgs = messages.map((m) => this.registry.encodeAsAny(m));
|
|
100
|
+
// const url = `${endpoint}/cosmos/tx/v1beta1/simulate`
|
|
101
|
+
// const tx = Tx.fromPartial({
|
|
102
|
+
// authInfo: AuthInfo.fromPartial({
|
|
103
|
+
// fee: Fee.fromPartial({}),
|
|
104
|
+
// signerInfos: [
|
|
105
|
+
// {
|
|
106
|
+
// publicKey: encodePubkey(pubkey),
|
|
107
|
+
// sequence: sequence,
|
|
108
|
+
// modeInfo: { single: { mode: SignMode.SIGN_MODE_UNSPECIFIED } },
|
|
109
|
+
// },
|
|
110
|
+
// ],
|
|
111
|
+
// }),
|
|
112
|
+
// body: TxBody.fromPartial({
|
|
113
|
+
// messages: Array.from(anyMsgs),
|
|
114
|
+
// memo: memo,
|
|
115
|
+
// }),
|
|
116
|
+
// signatures: [new Uint8Array()],
|
|
117
|
+
// });
|
|
118
|
+
// const request = SimulateRequest.fromPartial({
|
|
119
|
+
// tx
|
|
120
|
+
// // txBytes: Tx.encode(tx).finish(),
|
|
121
|
+
// });
|
|
122
|
+
// console.log(tx, request)
|
|
123
|
+
// return await post(url, request)
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
async broadcastTx(endpoint, bodyBytes: TxRaw, mode: BroadcastMode = BroadcastMode.SYNC) : Promise<{tx_response: TxResponse}> {
|
|
128
|
+
// const txbytes = bodyBytes.authInfoBytes ? TxRaw.encode(bodyBytes).finish() : bodyBytes
|
|
129
|
+
const txbytes = TxRaw.encode(bodyBytes).finish()
|
|
130
|
+
const txString = toBase64(txbytes)
|
|
131
|
+
const txRaw = {
|
|
132
|
+
tx_bytes: txString,
|
|
133
|
+
mode, // BROADCAST_MODE_SYNC, BROADCAST_MODE_BLOCK, BROADCAST_MODE_ASYNC
|
|
134
|
+
}
|
|
135
|
+
return post(`${endpoint}/cosmos/tx/v1beta1/txs`, txRaw).then(res => {
|
|
136
|
+
if (res.code && res.code !== 0) {
|
|
137
|
+
throw new Error(res.message)
|
|
138
|
+
}
|
|
139
|
+
if (res.tx_response && res.tx_response.code !== 0) {
|
|
140
|
+
throw new Error(res.tx_response.raw_log)
|
|
141
|
+
}
|
|
142
|
+
return res
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
145
|
}
|
package/lib/wallet/Wallet.ts
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import { Registry } from '@cosmjs/proto-signing'
|
|
2
|
-
import { defaultRegistryTypes } from "@cosmjs/stargate";
|
|
3
|
-
import { Transaction } from "../utils/type";
|
|
4
|
-
import { KeplerWallet } from './wallets/KeplerWallet';
|
|
5
|
-
import { LedgerWallet } from './wallets/LedgerWallet';
|
|
6
|
-
import { MetamaskWallet } from './wallets/MetamaskWallet';
|
|
7
|
-
import { MetamaskSnapWallet } from './wallets/MetamaskSnapWallet';
|
|
8
|
-
import { LeapWallet } from './wallets/LeapWallet';
|
|
9
|
-
import { OKXWallet } from "./wallets/OKXWallet";
|
|
10
|
-
import { UnisatWallet } from "./wallets/UnisatWallet";
|
|
11
|
-
|
|
12
|
-
export enum WalletName {
|
|
13
|
-
Keplr = "Keplr",
|
|
14
|
-
Ledger = "LedgerUSB",
|
|
15
|
-
LedgerBLE = "LedgerBLE",
|
|
16
|
-
Metamask = "Metamask",
|
|
17
|
-
MetamaskSnap = "MetamaskSnap",
|
|
18
|
-
Leap = "Leap",
|
|
19
|
-
OKX = "OKX Wallet",
|
|
20
|
-
Unisat = "UniSat Wallet",
|
|
21
|
-
// None Signning
|
|
22
|
-
Address = "Address",
|
|
23
|
-
NameService = "Nameservice",
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface IChain {
|
|
27
|
-
chainID: string;
|
|
28
|
-
name: string;
|
|
29
|
-
prefix: string;
|
|
30
|
-
rpcUrl: string;
|
|
31
|
-
restUrl: string;
|
|
32
|
-
denom: string;
|
|
33
|
-
hdPath: string;
|
|
34
|
-
logo: string;
|
|
35
|
-
faucetUrl: string;
|
|
36
|
-
explorerUrl: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface ConnectedWallet {
|
|
40
|
-
wallet: WalletName,
|
|
41
|
-
cosmosAddress: string
|
|
42
|
-
hdPath?: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface Account {
|
|
46
|
-
address: string,
|
|
47
|
-
algo: string,
|
|
48
|
-
pubkey: Uint8Array,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface WalletArgument {
|
|
52
|
-
chainId?: string,
|
|
53
|
-
hdPath?: string,
|
|
54
|
-
address?: string,
|
|
55
|
-
name?: string,
|
|
56
|
-
transport?: string
|
|
57
|
-
prefix?: string,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface AbstractWallet {
|
|
61
|
-
name: WalletName
|
|
62
|
-
/**
|
|
63
|
-
* The the accounts from the wallet (addresses)
|
|
64
|
-
*/
|
|
65
|
-
getAccounts(): Promise<Account[]>
|
|
66
|
-
supportCoinType(coinType?: string): Promise<boolean>
|
|
67
|
-
sign(transaction: Transaction): Promise<any>
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const DEFAULT_HDPATH = "m/44'/118/0'/0/0";
|
|
71
|
-
|
|
72
|
-
export function keyType(chainId: string) {
|
|
73
|
-
switch (true) {
|
|
74
|
-
// Cosmos EVM chains (Warden, etc.) - uses cosmos.evm module
|
|
75
|
-
case chainId.startsWith("warden"):
|
|
76
|
-
case chainId.startsWith("barra"): // Warden testnet
|
|
77
|
-
return "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey";
|
|
78
|
-
// Ethermint-like chains: evmos_9002-1, cronos_25-1, etc.
|
|
79
|
-
case chainId.search(/\w+_\d+-\d+/g) > -1:
|
|
80
|
-
return "/ethermint.crypto.v1.ethsecp256k1.PubKey"
|
|
81
|
-
case chainId.startsWith("injective"):
|
|
82
|
-
return "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
|
|
83
|
-
case chainId.startsWith("stratos"):
|
|
84
|
-
return "/stratos.crypto.v1.ethsecp256k1.PubKey";
|
|
85
|
-
default:
|
|
86
|
-
return "/cosmos.crypto.secp256k1.PubKey"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Check if chain is EVM-based (requires higher fees)
|
|
91
|
-
export function isEvmChain(chainId: string): boolean {
|
|
92
|
-
return chainId.startsWith("warden") ||
|
|
93
|
-
chainId.startsWith("barra") ||
|
|
94
|
-
chainId.search(/\w+_\d+-\d+/g) > -1 ||
|
|
95
|
-
chainId.startsWith("injective") ||
|
|
96
|
-
chainId.startsWith("stratos");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function readWallet(hdPath?: string) {
|
|
100
|
-
return JSON.parse(
|
|
101
|
-
localStorage.getItem(hdPath || DEFAULT_HDPATH) || '{}'
|
|
102
|
-
) as ConnectedWallet
|
|
103
|
-
}
|
|
104
|
-
export function writeWallet(connected: ConnectedWallet, hdPath?: string) {
|
|
105
|
-
localStorage.setItem(hdPath || DEFAULT_HDPATH, JSON.stringify(connected))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function removeWallet(hdPath?: string) {
|
|
109
|
-
localStorage.removeItem(hdPath || DEFAULT_HDPATH);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function extractChainId(chainId: string) {
|
|
113
|
-
const start = chainId.indexOf('_')
|
|
114
|
-
const end = chainId.indexOf('-')
|
|
115
|
-
if (end > start && start > 0) {
|
|
116
|
-
return Number(chainId.substring(start + 1, end))
|
|
117
|
-
}
|
|
118
|
-
return 0
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function createWallet(name: WalletName, arg: WalletArgument, registry?: Registry, chain?: IChain,): AbstractWallet {
|
|
122
|
-
const reg = registry || new Registry(defaultRegistryTypes)
|
|
123
|
-
switch (name) {
|
|
124
|
-
case WalletName.OKX:
|
|
125
|
-
return new OKXWallet(arg, <IChain>chain, reg);
|
|
126
|
-
case WalletName.Unisat:
|
|
127
|
-
return new UnisatWallet(arg, <IChain>chain, reg);
|
|
128
|
-
case WalletName.Keplr:
|
|
129
|
-
return new KeplerWallet(arg, reg)
|
|
130
|
-
case WalletName.Ledger:
|
|
131
|
-
return new LedgerWallet(arg, reg)
|
|
132
|
-
case WalletName.Leap:
|
|
133
|
-
return new LeapWallet(arg, reg)
|
|
134
|
-
case WalletName.MetamaskSnap:
|
|
135
|
-
return new MetamaskSnapWallet(arg, reg)
|
|
136
|
-
case WalletName.Metamask:
|
|
137
|
-
return arg.hdPath &&
|
|
138
|
-
(arg.hdPath.startsWith('m/44/60') || arg.hdPath.startsWith("m/44'/60"))
|
|
139
|
-
? new MetamaskWallet(arg, reg) : new MetamaskSnapWallet(arg, reg)
|
|
140
|
-
}
|
|
141
|
-
throw new Error("No wallet connected")
|
|
142
|
-
}
|
|
1
|
+
import { Registry } from '@cosmjs/proto-signing'
|
|
2
|
+
import { defaultRegistryTypes } from "@cosmjs/stargate";
|
|
3
|
+
import { Transaction } from "../utils/type";
|
|
4
|
+
import { KeplerWallet } from './wallets/KeplerWallet';
|
|
5
|
+
import { LedgerWallet } from './wallets/LedgerWallet';
|
|
6
|
+
import { MetamaskWallet } from './wallets/MetamaskWallet';
|
|
7
|
+
import { MetamaskSnapWallet } from './wallets/MetamaskSnapWallet';
|
|
8
|
+
import { LeapWallet } from './wallets/LeapWallet';
|
|
9
|
+
import { OKXWallet } from "./wallets/OKXWallet";
|
|
10
|
+
import { UnisatWallet } from "./wallets/UnisatWallet";
|
|
11
|
+
|
|
12
|
+
export enum WalletName {
|
|
13
|
+
Keplr = "Keplr",
|
|
14
|
+
Ledger = "LedgerUSB",
|
|
15
|
+
LedgerBLE = "LedgerBLE",
|
|
16
|
+
Metamask = "Metamask",
|
|
17
|
+
MetamaskSnap = "MetamaskSnap",
|
|
18
|
+
Leap = "Leap",
|
|
19
|
+
OKX = "OKX Wallet",
|
|
20
|
+
Unisat = "UniSat Wallet",
|
|
21
|
+
// None Signning
|
|
22
|
+
Address = "Address",
|
|
23
|
+
NameService = "Nameservice",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IChain {
|
|
27
|
+
chainID: string;
|
|
28
|
+
name: string;
|
|
29
|
+
prefix: string;
|
|
30
|
+
rpcUrl: string;
|
|
31
|
+
restUrl: string;
|
|
32
|
+
denom: string;
|
|
33
|
+
hdPath: string;
|
|
34
|
+
logo: string;
|
|
35
|
+
faucetUrl: string;
|
|
36
|
+
explorerUrl: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ConnectedWallet {
|
|
40
|
+
wallet: WalletName,
|
|
41
|
+
cosmosAddress: string
|
|
42
|
+
hdPath?: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Account {
|
|
46
|
+
address: string,
|
|
47
|
+
algo: string,
|
|
48
|
+
pubkey: Uint8Array,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface WalletArgument {
|
|
52
|
+
chainId?: string,
|
|
53
|
+
hdPath?: string,
|
|
54
|
+
address?: string,
|
|
55
|
+
name?: string,
|
|
56
|
+
transport?: string
|
|
57
|
+
prefix?: string,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface AbstractWallet {
|
|
61
|
+
name: WalletName
|
|
62
|
+
/**
|
|
63
|
+
* The the accounts from the wallet (addresses)
|
|
64
|
+
*/
|
|
65
|
+
getAccounts(): Promise<Account[]>
|
|
66
|
+
supportCoinType(coinType?: string): Promise<boolean>
|
|
67
|
+
sign(transaction: Transaction): Promise<any>
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const DEFAULT_HDPATH = "m/44'/118/0'/0/0";
|
|
71
|
+
|
|
72
|
+
export function keyType(chainId: string) {
|
|
73
|
+
switch (true) {
|
|
74
|
+
// Cosmos EVM chains (Warden, etc.) - uses cosmos.evm module
|
|
75
|
+
case chainId.startsWith("warden"):
|
|
76
|
+
case chainId.startsWith("barra"): // Warden testnet
|
|
77
|
+
return "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey";
|
|
78
|
+
// Ethermint-like chains: evmos_9002-1, cronos_25-1, etc.
|
|
79
|
+
case chainId.search(/\w+_\d+-\d+/g) > -1:
|
|
80
|
+
return "/ethermint.crypto.v1.ethsecp256k1.PubKey"
|
|
81
|
+
case chainId.startsWith("injective"):
|
|
82
|
+
return "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
|
|
83
|
+
case chainId.startsWith("stratos"):
|
|
84
|
+
return "/stratos.crypto.v1.ethsecp256k1.PubKey";
|
|
85
|
+
default:
|
|
86
|
+
return "/cosmos.crypto.secp256k1.PubKey"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check if chain is EVM-based (requires higher fees)
|
|
91
|
+
export function isEvmChain(chainId: string): boolean {
|
|
92
|
+
return chainId.startsWith("warden") ||
|
|
93
|
+
chainId.startsWith("barra") ||
|
|
94
|
+
chainId.search(/\w+_\d+-\d+/g) > -1 ||
|
|
95
|
+
chainId.startsWith("injective") ||
|
|
96
|
+
chainId.startsWith("stratos");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function readWallet(hdPath?: string) {
|
|
100
|
+
return JSON.parse(
|
|
101
|
+
localStorage.getItem(hdPath || DEFAULT_HDPATH) || '{}'
|
|
102
|
+
) as ConnectedWallet
|
|
103
|
+
}
|
|
104
|
+
export function writeWallet(connected: ConnectedWallet, hdPath?: string) {
|
|
105
|
+
localStorage.setItem(hdPath || DEFAULT_HDPATH, JSON.stringify(connected))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function removeWallet(hdPath?: string) {
|
|
109
|
+
localStorage.removeItem(hdPath || DEFAULT_HDPATH);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function extractChainId(chainId: string) {
|
|
113
|
+
const start = chainId.indexOf('_')
|
|
114
|
+
const end = chainId.indexOf('-')
|
|
115
|
+
if (end > start && start > 0) {
|
|
116
|
+
return Number(chainId.substring(start + 1, end))
|
|
117
|
+
}
|
|
118
|
+
return 0
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function createWallet(name: WalletName, arg: WalletArgument, registry?: Registry, chain?: IChain,): AbstractWallet {
|
|
122
|
+
const reg = registry || new Registry(defaultRegistryTypes)
|
|
123
|
+
switch (name) {
|
|
124
|
+
case WalletName.OKX:
|
|
125
|
+
return new OKXWallet(arg, <IChain>chain, reg);
|
|
126
|
+
case WalletName.Unisat:
|
|
127
|
+
return new UnisatWallet(arg, <IChain>chain, reg);
|
|
128
|
+
case WalletName.Keplr:
|
|
129
|
+
return new KeplerWallet(arg, reg)
|
|
130
|
+
case WalletName.Ledger:
|
|
131
|
+
return new LedgerWallet(arg, reg)
|
|
132
|
+
case WalletName.Leap:
|
|
133
|
+
return new LeapWallet(arg, reg)
|
|
134
|
+
case WalletName.MetamaskSnap:
|
|
135
|
+
return new MetamaskSnapWallet(arg, reg)
|
|
136
|
+
case WalletName.Metamask:
|
|
137
|
+
return arg.hdPath &&
|
|
138
|
+
(arg.hdPath.startsWith('m/44/60') || arg.hdPath.startsWith("m/44'/60"))
|
|
139
|
+
? new MetamaskWallet(arg, reg) : new MetamaskSnapWallet(arg, reg)
|
|
140
|
+
}
|
|
141
|
+
throw new Error("No wallet connected")
|
|
142
|
+
}
|