New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@xlabs-libs/wallet-aggregator-cosmos

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xlabs-libs/wallet-aggregator-cosmos - npm Package Compare versions

Comparing version 0.0.1-alpha.7 to 0.0.1-alpha.8

dist/cjs/chains.js

52

dist/cjs/cosmos.js

@@ -18,5 +18,11 @@ "use strict";

const tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
const chains_1 = require("./chains");
const DEFAULT_RPCS = {};
const DEFAULT_RESTS = {};
const DEFAULT_CHAIN_ID = "cosmoshub-4";
const NO_CHAIN_MESSAGES = [
"There is no chain info",
"Invalid chain Id",
"No account found",
];
/**

@@ -74,5 +80,10 @@ * A class to interact with Cosmos blockchains.

return __awaiter(this, void 0, void 0, function* () {
if (chainId)
this.chainId = chainId;
if (!this.chainId)
if (chainId) {
const chainAdded = yield this.hasChain(chainId);
if (!chainAdded) {
yield this.addChain(chainId);
}
}
const id = chainId || this.chainId;
if (!id)
throw new Error("Chain id not set");

@@ -82,8 +93,41 @@ const extension = this.walletInfo.locate();

throw new Error("Wallet not found");
this.signer = yield extension.getOfflineSignerAuto(this.chainId);
this.signer = yield extension.getOfflineSignerAuto(id);
this.accounts = [...(yield this.signer.getAccounts())];
this.activeAccount = this.accounts[0];
this.chainId = chainId;
return this.accounts.map((a) => a.address);
});
}
hasChain(chainId) {
return __awaiter(this, void 0, void 0, function* () {
const extension = this.walletInfo.locate();
if (!extension)
throw new Error("Wallet not found");
try {
const key = yield extension.getKey(chainId);
return !!key;
}
catch (e) {
const isExpectedError = NO_CHAIN_MESSAGES.some((m) => e.message.includes(m));
if (!isExpectedError) {
throw e;
}
return false;
}
});
}
addChain(chainId) {
return __awaiter(this, void 0, void 0, function* () {
const extension = this.walletInfo.locate();
if (!extension)
throw new Error("Wallet not found");
const info = chains_1.COSMOS_CHAIN_INFOS[chainId];
if (!info)
throw new Error(`No chain info found for ${chainId}`);
if (!extension.experimentalSuggestChain) {
throw new Error(`Chain suggestions are not supported by ${this.walletInfo.name}`);
}
return extension.experimentalSuggestChain(info);
});
}
switchChain(chainId) {

@@ -90,0 +134,0 @@ return __awaiter(this, void 0, void 0, function* () {

@@ -6,5 +6,11 @@ import { SigningCosmWasmClient, } from "@cosmjs/cosmwasm-stargate";

import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { COSMOS_CHAIN_INFOS } from "./chains";
const DEFAULT_RPCS = {};
const DEFAULT_RESTS = {};
const DEFAULT_CHAIN_ID = "cosmoshub-4";
const NO_CHAIN_MESSAGES = [
"There is no chain info",
"Invalid chain Id",
"No account found",
];
/**

@@ -61,5 +67,10 @@ * A class to interact with Cosmos blockchains.

async connect({ chainId } = {}) {
if (chainId)
this.chainId = chainId;
if (!this.chainId)
if (chainId) {
const chainAdded = await this.hasChain(chainId);
if (!chainAdded) {
await this.addChain(chainId);
}
}
const id = chainId || this.chainId;
if (!id)
throw new Error("Chain id not set");

@@ -69,7 +80,36 @@ const extension = this.walletInfo.locate();

throw new Error("Wallet not found");
this.signer = await extension.getOfflineSignerAuto(this.chainId);
this.signer = await extension.getOfflineSignerAuto(id);
this.accounts = [...(await this.signer.getAccounts())];
this.activeAccount = this.accounts[0];
this.chainId = chainId;
return this.accounts.map((a) => a.address);
}
async hasChain(chainId) {
const extension = this.walletInfo.locate();
if (!extension)
throw new Error("Wallet not found");
try {
const key = await extension.getKey(chainId);
return !!key;
}
catch (e) {
const isExpectedError = NO_CHAIN_MESSAGES.some((m) => e.message.includes(m));
if (!isExpectedError) {
throw e;
}
return false;
}
}
async addChain(chainId) {
const extension = this.walletInfo.locate();
if (!extension)
throw new Error("Wallet not found");
const info = COSMOS_CHAIN_INFOS[chainId];
if (!info)
throw new Error(`No chain info found for ${chainId}`);
if (!extension.experimentalSuggestChain) {
throw new Error(`Chain suggestions are not supported by ${this.walletInfo.name}`);
}
return extension.experimentalSuggestChain(info);
}
async switchChain(chainId) {

@@ -76,0 +116,0 @@ await this.connect({ chainId });

4

dist/types/cosmos.d.ts

@@ -7,5 +7,5 @@ import { AccountData, StdSignature } from "@cosmjs/amino";

import { BaseFeatures, ChainId, SendTransactionResult, Wallet, WalletState } from "@xlabs-libs/wallet-aggregator-core";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { CosmosConnectOptions, CosmosExecuteTransaction, CosmosTransaction, CosmosWalletConfig, ResourceMap } from "./types";
import { WalletInfo } from "./wallets";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
/**

@@ -40,2 +40,4 @@ * A class to interact with Cosmos blockchains.

connect({ chainId }?: CosmosConnectOptions): Promise<string[]>;
private hasChain;
private addChain;
switchChain(chainId: string): Promise<void>;

@@ -42,0 +44,0 @@ disconnect(): Promise<void>;

@@ -45,2 +45,113 @@ import { ExecuteInstruction } from "@cosmjs/cosmwasm-stargate";

}
/** The types defined from here downwards were retrieved from the keplr repo:
* https://github.com/chainapsis/keplr-wallet/tree/af099a47421e4b75a34e87427510ea932dfc71c4/packages/types/src
*/
/**
* The currency that is supported on the chain natively.
*/
export interface Currency {
readonly coinDenom: string;
readonly coinMinimalDenom: string;
readonly coinDecimals: number;
/**
* This is used to fetch asset's fiat value from coingecko.
* You can get id from https://api.coingecko.com/api/v3/coins/list.
*/
readonly coinGeckoId?: string;
readonly coinImageUrl?: string;
}
/**
* The currency that is supported on the cosmwasm.
* This should be the CW-20 that confirms the standard.
* And, in this case, `coinMinimalDenom` must start with the type and contract address of currency such as "cw20:coral1vv6hruqu...3sfhwh:ukeplr".
*/
export interface CW20Currency extends Currency {
readonly type: "cw20";
readonly contractAddress: string;
}
export interface Secret20Currency extends Currency {
readonly type: "secret20";
readonly contractAddress: string;
readonly viewingKey: string;
}
/**
* IBCCurrency is the currency that is sent from the other chain via IBC.
* This will be handled as similar to the native currency.
* But, this has more information abounr IBC channel and paths.
*/
export interface IBCCurrency extends Currency {
readonly paths: {
portId: string;
channelId: string;
counterpartyChannelId?: string;
counterpartyPortId?: string;
clientChainId?: string;
}[];
/**
* The chain id that the currency is from.
* If that chain is unknown, this will be undefined.
*/
readonly originChainId: string | undefined;
readonly originCurrency: Currency | CW20Currency | Secret20Currency | undefined;
}
/**
* Any type of currency that Kepler applications can support.
*/
export type AppCurrency = Currency | CW20Currency | Secret20Currency | IBCCurrency;
export interface FiatCurrency {
readonly currency: string;
readonly symbol: string;
readonly maxDecimals: number;
readonly locale: string;
}
export type WithGasPriceStep<T> = T & {
/**
* This is used to set the fee of the transaction.
* If this field is empty, it just use the default gas price step (low: 0.01, average: 0.025, high: 0.04).
*/
readonly gasPriceStep?: {
readonly low: number;
readonly average: number;
readonly high: number;
};
};
export type FeeCurrency = WithGasPriceStep<AppCurrency>;
export interface BIP44 {
readonly coinType: number;
}
export interface Bech32Config {
readonly bech32PrefixAccAddr: string;
readonly bech32PrefixAccPub: string;
readonly bech32PrefixValAddr: string;
readonly bech32PrefixValPub: string;
readonly bech32PrefixConsAddr: string;
readonly bech32PrefixConsPub: string;
}
export interface ChainInfo {
readonly rpc: string;
readonly rest: string;
readonly chainId: string;
readonly chainName: string;
/**
* This indicates the type of coin that can be used for stake.
* You can get actual currency information from Currencies.
*/
readonly stakeCurrency: Currency;
readonly walletUrlForStaking?: string;
readonly bip44: {
coinType: number;
};
readonly alternativeBIP44s?: BIP44[];
readonly bech32Config: Bech32Config;
readonly currencies: AppCurrency[];
/**
* This indicates which coin or token can be used for fee to send transaction.
* You can get actual currency information from Currencies.
*/
readonly feeCurrencies: FeeCurrency[];
/**
* Indicate the features supported by this chain. Ex) cosmwasm, secretwasm ...
*/
readonly features?: string[];
}
//# sourceMappingURL=types.d.ts.map
import { StdSignature } from "@cosmjs/amino";
import { DirectSignResponse, OfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";
import Long from "long";
import { ChainInfo } from "./types";
declare global {

@@ -44,2 +45,3 @@ interface Window {

getKey: (chainId: string) => Promise<AccountKey>;
experimentalSuggestChain?(chainInfo: ChainInfo): Promise<void>;
}

@@ -46,0 +48,0 @@ type LocateFn = () => ExtensionWallet | undefined;

{
"name": "@xlabs-libs/wallet-aggregator-cosmos",
"repository": "https://github.com/XLabs/wallet-aggregator-sdk/tree/master/packages/wallets/cosmos",
"version": "0.0.1-alpha.7",
"version": "0.0.1-alpha.8",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "dist/cjs/index.js",

@@ -29,2 +29,3 @@ import { AccountData, StdSignature } from "@cosmjs/amino";

} from "@xlabs-libs/wallet-aggregator-core";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import {

@@ -38,3 +39,3 @@ CosmosConnectOptions,

import { WalletInfo } from "./wallets";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { COSMOS_CHAIN_INFOS } from "./chains";

@@ -45,2 +46,8 @@ const DEFAULT_RPCS: ResourceMap = {};

const NO_CHAIN_MESSAGES = [
"There is no chain info",
"Invalid chain Id",
"No account found",
];
/**

@@ -124,13 +131,52 @@ * A class to interact with Cosmos blockchains.

async connect({ chainId }: CosmosConnectOptions = {}): Promise<string[]> {
if (chainId) this.chainId = chainId;
if (!this.chainId) throw new Error("Chain id not set");
if (chainId) {
const chainAdded = await this.hasChain(chainId);
if (!chainAdded) {
await this.addChain(chainId);
}
}
const id = chainId || this.chainId;
if (!id) throw new Error("Chain id not set");
const extension = this.walletInfo.locate();
if (!extension) throw new Error("Wallet not found");
this.signer = await extension.getOfflineSignerAuto(this.chainId);
this.signer = await extension.getOfflineSignerAuto(id);
this.accounts = [...(await this.signer.getAccounts())];
this.activeAccount = this.accounts[0];
this.chainId = chainId;
return this.accounts.map((a) => a.address);
}
private async hasChain(chainId: string): Promise<boolean> {
const extension = this.walletInfo.locate();
if (!extension) throw new Error("Wallet not found");
try {
const key = await extension.getKey(chainId);
return !!key;
} catch (e: any) {
const isExpectedError = NO_CHAIN_MESSAGES.some((m) =>
e.message.includes(m)
);
if (!isExpectedError) {
throw e;
}
return false;
}
}
private async addChain(chainId: string): Promise<void> {
const extension = this.walletInfo.locate();
if (!extension) throw new Error("Wallet not found");
const info = COSMOS_CHAIN_INFOS[chainId];
if (!info) throw new Error(`No chain info found for ${chainId}`);
if (!extension.experimentalSuggestChain) {
throw new Error(
`Chain suggestions are not supported by ${this.walletInfo.name}`
);
}
return extension.experimentalSuggestChain(info);
}
async switchChain(chainId: string): Promise<void> {

@@ -137,0 +183,0 @@ await this.connect({ chainId });

@@ -52,1 +52,135 @@ import { ExecuteInstruction } from "@cosmjs/cosmwasm-stargate";

}
/** The types defined from here downwards were retrieved from the keplr repo:
* https://github.com/chainapsis/keplr-wallet/tree/af099a47421e4b75a34e87427510ea932dfc71c4/packages/types/src
*/
/**
* The currency that is supported on the chain natively.
*/
export interface Currency {
readonly coinDenom: string;
readonly coinMinimalDenom: string;
readonly coinDecimals: number;
/**
* This is used to fetch asset's fiat value from coingecko.
* You can get id from https://api.coingecko.com/api/v3/coins/list.
*/
readonly coinGeckoId?: string;
readonly coinImageUrl?: string;
}
/**
* The currency that is supported on the cosmwasm.
* This should be the CW-20 that confirms the standard.
* And, in this case, `coinMinimalDenom` must start with the type and contract address of currency such as "cw20:coral1vv6hruqu...3sfhwh:ukeplr".
*/
export interface CW20Currency extends Currency {
readonly type: "cw20";
readonly contractAddress: string;
}
export interface Secret20Currency extends Currency {
readonly type: "secret20";
readonly contractAddress: string;
readonly viewingKey: string;
}
/**
* IBCCurrency is the currency that is sent from the other chain via IBC.
* This will be handled as similar to the native currency.
* But, this has more information abounr IBC channel and paths.
*/
export interface IBCCurrency extends Currency {
readonly paths: {
portId: string;
channelId: string;
counterpartyChannelId?: string;
counterpartyPortId?: string;
clientChainId?: string;
}[];
/**
* The chain id that the currency is from.
* If that chain is unknown, this will be undefined.
*/
readonly originChainId: string | undefined;
readonly originCurrency:
| Currency
| CW20Currency
| Secret20Currency
| undefined;
}
/**
* Any type of currency that Kepler applications can support.
*/
export type AppCurrency =
| Currency
| CW20Currency
| Secret20Currency
| IBCCurrency;
export interface FiatCurrency {
readonly currency: string;
readonly symbol: string;
readonly maxDecimals: number;
readonly locale: string;
}
export type WithGasPriceStep<T> = T & {
/**
* This is used to set the fee of the transaction.
* If this field is empty, it just use the default gas price step (low: 0.01, average: 0.025, high: 0.04).
*/
readonly gasPriceStep?: {
readonly low: number;
readonly average: number;
readonly high: number;
};
};
export type FeeCurrency = WithGasPriceStep<AppCurrency>;
export interface BIP44 {
readonly coinType: number;
}
export interface Bech32Config {
readonly bech32PrefixAccAddr: string;
readonly bech32PrefixAccPub: string;
readonly bech32PrefixValAddr: string;
readonly bech32PrefixValPub: string;
readonly bech32PrefixConsAddr: string;
readonly bech32PrefixConsPub: string;
}
export interface ChainInfo {
readonly rpc: string;
readonly rest: string;
readonly chainId: string;
readonly chainName: string;
/**
* This indicates the type of coin that can be used for stake.
* You can get actual currency information from Currencies.
*/
readonly stakeCurrency: Currency;
readonly walletUrlForStaking?: string;
readonly bip44: {
coinType: number;
};
readonly alternativeBIP44s?: BIP44[];
readonly bech32Config: Bech32Config;
readonly currencies: AppCurrency[];
/**
* This indicates which coin or token can be used for fee to send transaction.
* You can get actual currency information from Currencies.
*/
readonly feeCurrencies: FeeCurrency[];
/**
* Indicate the features supported by this chain. Ex) cosmwasm, secretwasm ...
*/
readonly features?: string[];
}

@@ -8,2 +8,3 @@ import { StdSignature } from "@cosmjs/amino";

import Long from "long";
import { ChainInfo } from "./types";

@@ -65,2 +66,3 @@ declare global {

getKey: (chainId: string) => Promise<AccountKey>;
experimentalSuggestChain?(chainInfo: ChainInfo): Promise<void>;
}

@@ -67,0 +69,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc