Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## `v0.0.71`

### Features

- Add optional `label` field to `ConnectedWallet` instances, which contains the user-defined label of the wallet

### Fixes

- Handle more wallet errors in the `wrap` function

## `v0.0.70`

### Features

- Add legacy amino type to `MsgSend` model
- Add `MsgMigrateContract`, `MsgStoreCode`, `MsgBeginRedelegate`, `MsgDelegate`, `MsgUndelegate`, `MsgWithdrawDelegatorRewards`, `MsgWithdrawValidatorCommission` models
- Add ed25519 signature type

### Fixes

- Add Keplr default sign options to `WalletConnectV2`

## `v0.0.69`

### Chore
Expand Down
10 changes: 5 additions & 5 deletions examples/solid-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const CHAINS: Record<string, string> = {
const WALLETS: Record<WalletName, string> = {
[WalletName.KEPLR]: "Keplr",
[WalletName.COSMOSTATION]: "Cosmostation",
[WalletName.STATION]: "Terra Station",
[WalletName.STATION]: "Station",
[WalletName.LEAP]: "Leap",
[WalletName.COMPASS]: "Compass",
[WalletName.METAMASK_INJECTIVE]: "MetaMask",
Expand Down Expand Up @@ -325,13 +325,13 @@ const App: Component = () => {
Broadcast Tx
</button>

<div class="flex flex-col">
<code>CONNECTED WALLETS</code>
<div class="flex flex-col items-center border py-2 px-4 border-gray-400">
<div class="font-semibold">Connected Wallets</div>
<For each={Object.values(wallets)}>
{(wallet) => (
<code>
{wallet.address.slice(0, 10)}
...{wallet.address.slice(-5)} | {WALLETS[wallet.id]}
{wallet.address.slice(0, 10)}…{wallet.address.slice(-5)} [
{WALLETS[wallet.id]}: {wallet.label ?? "-"}]
</code>
)}
</For>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmes",
"version": "0.0.69",
"version": "0.0.71",
"private": false,
"packageManager": "pnpm@8.3.0",
"sideEffects": false,
Expand Down
6 changes: 4 additions & 2 deletions src/client/models/MsgSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ type Data = DeepPrettify<PlainMessage<ProtoMsgSend>>;

export class MsgSend implements Adapter {
private readonly data: Data;
private readonly legacy: boolean;

constructor(data: Data) {
constructor(data: Data, legacy = false) {
this.data = data;
this.legacy = legacy;
}

public toProto() {
Expand All @@ -19,7 +21,7 @@ export class MsgSend implements Adapter {

public toAmino() {
return {
type: "cosmos-sdk/MsgSend",
type: this.legacy ? "bank/MsgSend" : "cosmos-sdk/MsgSend",
value: {
from_address: this.data.fromAddress,
to_address: this.data.toAddress,
Expand Down
8 changes: 8 additions & 0 deletions src/wallet/walletconnect/WalletConnectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type StorageSession = {
};

type GetAccountResponse = {
name?: string | undefined;
address: string;
algo: string;
pubkey: string;
Expand Down Expand Up @@ -56,6 +57,11 @@ const Event = {
} as const;
type Event = (typeof Event)[keyof typeof Event];

const DEFAULT_SIGN_OPTIONS = {
preferNoSetFee: true,
preferNoSetMemo: true,
};

export class WalletConnectV2 {
private readonly projectId: string;
private readonly mobileAppDetails: MobileAppDetails;
Expand Down Expand Up @@ -191,6 +197,7 @@ export class WalletConnectV2 {
{
signerAddress,
signDoc: stdSignDoc,
signOptions: DEFAULT_SIGN_OPTIONS,
}
);
return {
Expand All @@ -210,6 +217,7 @@ export class WalletConnectV2 {
{
signerAddress,
signDoc,
signOptions: DEFAULT_SIGN_OPTIONS,
}
);
return {
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/wallets/ConnectedWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export abstract class ConnectedWallet {
public readonly id: WalletName;
/** The type of connection to the wallet. */
public readonly type: WalletType;
/** The user-defined label for this wallet, if any. */
public readonly label: string | undefined;
/** The chain ID this wallet is connected to. */
public readonly chainId: string;
/** The public key. */
Expand All @@ -62,6 +64,7 @@ export abstract class ConnectedWallet {
constructor(
id: WalletName,
type: WalletType,
label: string | undefined,
chainId: string,
pubKey: Secp256k1PubKey,
address: string,
Expand All @@ -70,6 +73,7 @@ export abstract class ConnectedWallet {
) {
this.id = id;
this.type = type;
this.label = label;
this.chainId = chainId;
this.pubKey = pubKey;
this.address = address;
Expand Down
9 changes: 7 additions & 2 deletions src/wallet/wallets/WalletError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ export class WalletError extends Error {
if (typeof err === "string") {
throw new WalletError(err, err);
}
if (err instanceof Error) {
throw new WalletError(err.message, err);
if (this.isRecord(err)) {
// Takes into account normal error instances and objects with the 'error' key
throw new WalletError(err.message ?? err.error ?? "unknown error", err);
}
throw new WalletError("unknown error", err);
}
}

private static isRecord(value: unknown): value is Record<string, string> {
return typeof value === "object" && value != null;
}
}
6 changes: 3 additions & 3 deletions src/wallet/wallets/compass/CompassController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export class CompassController extends WalletController {
}
await WalletError.wrap(ext.enable(chains.map(({ chainId }) => chainId)));
for (const { chainId, rpc, gasPrice } of Object.values(chains)) {
const { bech32Address, pubKey, isNanoLedger } = await WalletError.wrap(
ext.getKey(chainId)
);
const { name, bech32Address, pubKey, isNanoLedger } =
await WalletError.wrap(ext.getKey(chainId));
const key = new Secp256k1PubKey({
chainId,
key: pubKey,
Expand All @@ -49,6 +48,7 @@ export class CompassController extends WalletController {
chainId,
new CompassExtension(
this.id,
name,
ext,
chainId,
key,
Expand Down
9 changes: 5 additions & 4 deletions src/wallet/wallets/cosmostation/CosmostationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CosmostationController extends WalletController {
);
for (let i = 0; i < chains.length; i++) {
const { chainId, rpc, gasPrice } = chains[i];
const { pubkey, address } = await WalletError.wrap(
const { name, pubkey, address } = await WalletError.wrap(
this.wc.getAccount(chainId)
);
const key = new Secp256k1PubKey({
Expand All @@ -50,6 +50,7 @@ export class CosmostationController extends WalletController {
chainId,
new CosmostationWalletConnectV2(
this.id,
name,
this.wc,
chainId,
key,
Expand All @@ -71,9 +72,8 @@ export class CosmostationController extends WalletController {
}
await WalletError.wrap(ext.enable(chains.map(({ chainId }) => chainId)));
for (const { chainId, rpc, gasPrice } of Object.values(chains)) {
const { bech32Address, pubKey, isNanoLedger } = await WalletError.wrap(
ext.getKey(chainId)
);
const { name, bech32Address, pubKey, isNanoLedger } =
await WalletError.wrap(ext.getKey(chainId));
const key = new Secp256k1PubKey({
chainId,
key: pubKey,
Expand All @@ -82,6 +82,7 @@ export class CosmostationController extends WalletController {
chainId,
new CosmostationExtension(
this.id,
name,
ext,
chainId,
key,
Expand Down
9 changes: 5 additions & 4 deletions src/wallet/wallets/keplr/KeplrController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class KeplrController extends WalletController {
);
for (let i = 0; i < chains.length; i++) {
const { chainId, rpc, gasPrice } = chains[i];
const { pubkey, address } = await WalletError.wrap(
const { name, pubkey, address } = await WalletError.wrap(
this.wc.getAccount(chainId)
);
const key = new Secp256k1PubKey({
Expand All @@ -50,6 +50,7 @@ export class KeplrController extends WalletController {
chainId,
new KeplrWalletConnectV2(
this.id,
name,
this.wc,
chainId,
key,
Expand All @@ -71,9 +72,8 @@ export class KeplrController extends WalletController {
}
await WalletError.wrap(ext.enable(chains.map(({ chainId }) => chainId)));
for (const { chainId, rpc, gasPrice } of Object.values(chains)) {
const { bech32Address, pubKey, isNanoLedger } = await WalletError.wrap(
ext.getKey(chainId)
);
const { name, bech32Address, pubKey, isNanoLedger } =
await WalletError.wrap(ext.getKey(chainId));
const key = new Secp256k1PubKey({
key: pubKey,
chainId,
Expand All @@ -82,6 +82,7 @@ export class KeplrController extends WalletController {
chainId,
new KeplrExtension(
this.id,
name,
ext,
chainId,
key,
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallets/keplr/KeplrExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class KeplrExtension extends ConnectedWallet {

constructor(
walletName: WalletName,
label: string | undefined,
ext: Keplr,
chainId: string,
pubKey: Secp256k1PubKey,
Expand All @@ -39,6 +40,7 @@ export class KeplrExtension extends ConnectedWallet {
super(
walletName,
WalletType.EXTENSION,
label,
chainId,
pubKey,
address,
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallets/keplr/KeplrWalletConnectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class KeplrWalletConnectV2 extends ConnectedWallet {

constructor(
walletName: WalletName,
label: string | undefined,
wc: WalletConnectV2,
chainId: string,
pubKey: Secp256k1PubKey,
Expand All @@ -37,6 +38,7 @@ export class KeplrWalletConnectV2 extends ConnectedWallet {
super(
walletName,
WalletType.WALLETCONNECT,
label,
chainId,
pubKey,
address,
Expand Down
9 changes: 5 additions & 4 deletions src/wallet/wallets/leap/LeapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LeapController extends WalletController {
);
for (let i = 0; i < chains.length; i++) {
const { chainId, rpc, gasPrice } = chains[i];
const { pubkey, address } = await WalletError.wrap(
const { name, pubkey, address } = await WalletError.wrap(
this.wc.getAccount(chainId)
);
const key = new Secp256k1PubKey({
Expand All @@ -49,6 +49,7 @@ export class LeapController extends WalletController {
chainId,
new LeapWalletConnectV2(
this.id,
name,
this.wc,
chainId,
key,
Expand All @@ -70,9 +71,8 @@ export class LeapController extends WalletController {
}
await WalletError.wrap(ext.enable(chains.map(({ chainId }) => chainId)));
for (const { chainId, rpc, gasPrice } of Object.values(chains)) {
const { bech32Address, pubKey, isNanoLedger } = await WalletError.wrap(
ext.getKey(chainId)
);
const { name, bech32Address, pubKey, isNanoLedger } =
await WalletError.wrap(ext.getKey(chainId));
const key = new Secp256k1PubKey({
chainId,
key: pubKey,
Expand All @@ -81,6 +81,7 @@ export class LeapController extends WalletController {
chainId,
new LeapExtension(
this.id,
name,
ext,
chainId,
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class MetamaskInjectiveController extends WalletController {
chain.chainId,
new MetamaskInjectiveExtension(
this.id,
undefined,
ext,
chain.chainId,
pubKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class MetamaskInjectiveExtension extends ConnectedWallet {

constructor(
walletName: WalletName,
label: string | undefined,
ext: Ethereum,
chainId: string,
pubKey: Secp256k1PubKey,
Expand All @@ -36,6 +37,7 @@ export class MetamaskInjectiveExtension extends ConnectedWallet {
super(
walletName,
WalletType.EXTENSION,
label,
chainId,
pubKey,
bech32Address,
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallets/mnemonic/MnemonicWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class MnemonicWallet extends ConnectedWallet {
// unlikely to be used by most consumers of CosmES.
"mnemonic" as WalletName,
"mnemonic" as WalletType,
undefined,
chainId,
new Secp256k1PubKey({
chainId,
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallets/ninji/NinjiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export class NinjiController extends WalletController {
}
await WalletError.wrap(ext.enable(chains.map(({ chainId }) => chainId)));
for (const { chainId, rpc, gasPrice } of Object.values(chains)) {
const { bech32Address, pubKey, isNanoLedger } = await WalletError.wrap(
ext.getKey(chainId)
);
const { name, bech32Address, pubKey, isNanoLedger } =
await WalletError.wrap(ext.getKey(chainId));
const key = new Secp256k1PubKey({
chainId,
key: pubKey,
Expand All @@ -48,6 +47,7 @@ export class NinjiController extends WalletController {
chainId,
new NinjiExtension(
this.id,
name,
ext,
chainId,
key,
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallets/owallet/OWalletController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export class OWalletController extends WalletController {
}
await WalletError.wrap(ext.enable(chains.map(({ chainId }) => chainId)));
for (const { chainId, rpc, gasPrice } of Object.values(chains)) {
const { bech32Address, pubKey, isNanoLedger } = await WalletError.wrap(
ext.getKey(chainId)
);
const { name, bech32Address, pubKey, isNanoLedger } =
await WalletError.wrap(ext.getKey(chainId));
const key = new Secp256k1PubKey({
chainId,
key: pubKey,
Expand All @@ -49,6 +48,7 @@ export class OWalletController extends WalletController {
chainId,
new OWalletExtension(
this.id,
name,
ext,
chainId,
key,
Expand Down
Loading