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

@thorwallet/xchain-client

Package Overview
Dependencies
Maintainers
2
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thorwallet/xchain-client - npm Package Compare versions

Comparing version 0.0.1-alpha.900 to 0.0.1-alpha.978

lib/BaseXChainClient.d.ts

31

CHANGELOG.md

@@ -0,1 +1,32 @@

# v.0.10.3 (2021-09-02)
- updated to the latest dependencies
# v.0.10.2 (2021-07-18)
- optimized BaseXchainClient to skip creating an addres that just gets thown away in the constructor
# v.0.10.1 (2021-07-07)
### Update
- Use latest `@xchainjs/xchain-util@0.3.0`
# v.0.10.0 (2021-07-07)
### Breaking change
- Introduce `Network`, `TxType`, `FeeOption` enums
### Add
- Introduce `UTXOClient`
- Add fee rate helpers `singleFeeRate`, `standardFeeRates`
- Add fee helpers `singleFee`, `standardFees`, `calcFee`, `calcFeesAsync`
# v.0.9.4 (2021-06-25)
- added BaseXChainClient
- added support for fetch gas fees from thorchain
# v.0.9.3 (2021-06-01)

@@ -2,0 +33,0 @@

@@ -0,1 +1,6 @@

export * from './BaseXChainClient';
export * from './UTXOClient';
export * from './types';
export * from './feeRates';
export * from './fees';
export * from './types';

@@ -13,3 +13,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./BaseXChainClient"), exports);
__exportStar(require("./UTXOClient"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./feeRates"), exports);
__exportStar(require("./fees"), exports);
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

45

lib/types.d.ts
import { Asset, BaseAmount } from '@thorwallet/xchain-util';
export declare type Address = string;
export declare type Network = 'testnet' | 'mainnet';
export declare enum Network {
Mainnet = "mainnet",
Testnet = "testnet"
}
export declare type Balance = {

@@ -8,4 +11,6 @@ asset: Asset;

};
export declare type Balances = Balance[];
export declare type TxType = 'transfer' | 'unknown';
export declare enum TxType {
Transfer = "transfer",
Unknown = "unknown"
}
export declare type TxHash = string;

@@ -37,6 +42,5 @@ export declare type TxTo = {

};
export declare type Txs = Tx[];
export declare type TxsPage = {
total: number;
txs: Txs;
txs: Tx[];
};

@@ -57,15 +61,22 @@ export declare type TxHistoryParams = {

};
export declare type FeesParams = {
readonly empty?: '';
};
export declare type FeeOptionKey = 'average' | 'fast' | 'fastest';
export declare type FeeOption = Record<FeeOptionKey, BaseAmount>;
export declare type FeeType = 'byte' | 'base';
export declare type Fees = FeeOption & {
export declare enum FeeOption {
Average = "average",
Fast = "fast",
Fastest = "fastest"
}
export declare type FeeRate = number;
export declare type FeeRates = Record<FeeOption, FeeRate>;
export declare enum FeeType {
FlatFee = "base",
PerByte = "byte"
}
export declare type Fee = BaseAmount;
export declare type Fees = Record<FeeOption, Fee> & {
type: FeeType;
};
export declare type RootDerivationPaths = {
mainnet: string;
testnet: string;
export declare type FeesWithRates = {
rates: FeeRates;
fees: Fees;
};
export declare type RootDerivationPaths = Record<Network, string>;
export declare type XChainClientParams = {

@@ -85,8 +96,8 @@ network?: Network;

setPhrase(phrase: string, walletIndex: number): Promise<Address>;
getBalance(address: Address, assets?: Asset[]): Promise<Balances>;
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>;
getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
getTransactionData(txId: string, assetAddress?: Address): Promise<Tx>;
getFees(params?: FeesParams): Promise<Fees>;
getFees(): Promise<Fees>;
transfer(params: TxParams): Promise<TxHash>;
purgeClient(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeeType = exports.FeeOption = exports.TxType = exports.Network = void 0;
var Network;
(function (Network) {
Network["Mainnet"] = "mainnet";
Network["Testnet"] = "testnet";
})(Network = exports.Network || (exports.Network = {}));
var TxType;
(function (TxType) {
TxType["Transfer"] = "transfer";
TxType["Unknown"] = "unknown";
})(TxType = exports.TxType || (exports.TxType = {}));
var FeeOption;
(function (FeeOption) {
FeeOption["Average"] = "average";
FeeOption["Fast"] = "fast";
FeeOption["Fastest"] = "fastest";
})(FeeOption = exports.FeeOption || (exports.FeeOption = {}));
var FeeType;
(function (FeeType) {
FeeType["FlatFee"] = "base";
FeeType["PerByte"] = "byte";
})(FeeType = exports.FeeType || (exports.FeeType = {}));
//# sourceMappingURL=types.js.map
{
"name": "@thorwallet/xchain-client",
"version": "0.0.1-alpha.900+d9e80d5",
"version": "0.0.1-alpha.978+d4b2fe8",
"license": "MIT",

@@ -18,6 +18,10 @@ "main": "lib/index",

"devDependencies": {
"@thorwallet/xchain-util": "0.0.1-alpha.900+d9e80d5"
"@thorwallet/xchain-crypto": "0.0.1-alpha.978+d4b2fe8",
"@thorwallet/xchain-util": "0.0.1-alpha.978+d4b2fe8",
"axios": "^0.21.1"
},
"peerDependencies": {
"@thorwallet/xchain-util": "0.0.1-alpha.869+49db531"
"@thorwallet/xchain-crypto": "0.0.1-alpha.869+49db531",
"@thorwallet/xchain-util": "0.0.1-alpha.869+49db531",
"axios": "^0.21.1"
},

@@ -27,3 +31,3 @@ "publishConfig": {

},
"gitHead": "d9e80d5319b1af862491da0a60d76ebe9954bff0"
"gitHead": "d4b2fe8484e87bc3c08d79594bd384fbdf086c3d"
}
# XChainJS Wallet Client Interface
A specification for a generalised interface for crypto wallets clients, to be used by XChainJS implementations. The client should not have any functionality to generate a key, instead, the `asgardex-crypto` library should be used to ensure cross-chain compatible keystores are handled. The client is only ever passed a master BIP39 phrase, from which a temporary key and address is decoded.
A specification for a generalised interface for crypto wallets clients, to be used by XChainJS implementations. The client should not have any functionality to generate a key, instead, the `asgardex-crypto` library should be used to ensure cross-chain compatible keystores are handled. The client is only ever passed a master BIP39 phrase, from which a temporary key and address is decoded.
### Configuration
Initialise and set up the client to connect to its necessary third-party services to fulfil basic functionality. The third-party services used must be at a minimum to fulfil the wallet functionality, such as displaying balances and sending transactions.
Initialise and set up the client to connect to its necessary third-party services to fulfil basic functionality. The third-party services used must be at a minimum to fulfil the wallet functionality, such as displaying balances and sending transactions.
During configuration, the following can be passed in:
* Network choice (default is MAINNET)
* Phrase (mandatory)
* Service Keys (optional, if null, client will use config defaults or free service limits.)
- Network choice (default is MAINNET)
- Phrase (mandatory)
- Service Keys (optional, if null, client will use config defaults or free service limits.)
### Querying
Querying the client for balances and transaction history. Transaction history is optional.
Querying the client for balances and transaction history. Transaction history is optional.
Optional blockchain-specific queries can be added here, such as Binance Chain market information.
### Transactions
Making transfers.

@@ -23,3 +27,3 @@

----
---

@@ -29,15 +33,21 @@ # Class Variables

## Client
Public variable that returns the current client
```ts
public client: XChainClient
public client: XChainClient
```
## Network
Public variable that returns the current network
```ts
public network: Network
public network: Network
```
## PrivateKey
Private variable that retains the private key that was extracted from the phrase during initialisation. The phrase should not be retained.
```ts

@@ -48,3 +58,5 @@ private privkey: PrivKey | null = null

## Address
Public variable that returns the address decoded from the private key during initialisation.
```ts

@@ -57,29 +69,36 @@ public address: Address

## Set Network
Used to set a type of `Network`, which is either `'mainnet'` or `'testnet'`.
Used to set a type of `Network`, which is either `'mainnet'` or `'testnet'`.
```ts
setNetwork(net: Network): XChainClient
```
Returns the client.
Returns the client.
## Set Phrase
Used to set the master BIP39 phrase, from which the private key is extracted and the address decoded.
```ts
setPhrase(phrase: string): address
```
The function should store the private key and address, then return the address generated by the phrase.
The function should store the private key and address, then return the address generated by the phrase.
## Set Service Keys
The client is expected to know which services it needs, handle errors and have hard-coded sensible defaults if errors. The client should export a type allowing devs to know which services it needs, as well as documentation to explain how to get keys.
If no key is set, either the service has no API key or the client is expected to stay within node rate limits.
The client is expected to know which services it needs, handle errors and have hard-coded sensible defaults if errors. The client should export a type allowing devs to know which services it needs, as well as documentation to explain how to get keys.
If no key is set, either the service has no API key or the client is expected to stay within node rate limits.
Example:
1) Blockchair (for querying and broadcasting)
2) Ethplorer (for getting address balances)
3) EthGasStation (for getting gas prices)
4) Binance Chain node for Binance queries
* etc
1. Blockchair (for querying and broadcasting)
2. Ethplorer (for getting address balances)
3. EthGasStation (for getting gas prices)
4. Binance Chain node for Binance queries
- etc
Service keys will be passed into constructor by extending `XChainClientParams` interface.

@@ -99,3 +118,3 @@

// passing url and key of API service into constructor
constructor({ network = 'testnet', nodeUrl = '', nodeApiKey = '', phrase }: BitcoinClientParams) {
constructor({ network = Network.Testnet, nodeUrl = '', nodeApiKey = '', phrase }: BitcoinClientParams) {
...

@@ -107,3 +126,3 @@ }

----
---

@@ -113,7 +132,10 @@ # Querying

## Get Explorer URLs
Returns the correctly formatted url string with paths for:
* Addresses
* Transactions
- Addresses
- Transactions
The default Explorer URL can be hard-coded, or passed in as a service. It will be provided by `getExplorerUrl`
```ts

@@ -123,9 +145,10 @@ getExplorerUrl(): string

To get explorer's URL for an address, use `getExplorerAddressUrl` by passing an `address`.
To get explorer's URL for an address, use `getExplorerAddressUrl` by passing an `address`.
```ts
getExplorerAddressUrl = (address: Address): string
getExplorerAddressUrl = (address: Address): string
```
To get explorer's URL for a transaction, use `getExplorerTxUrl` by passing a transaction ID.
```ts

@@ -135,5 +158,6 @@ getExplorerTxUrl = (txID: string): string

All functions should return the correctly formatted url string.
All functions should return the correctly formatted url string.
**Example**
```

@@ -151,7 +175,9 @@ https://blockchair.com/bitcoin/transaction/d11ff3352c50b1f5c8e2030711702a2071ca0e65457b40e6e0bcbea99e5dc82e

## Get Balance
Returns the balance of an address.
* If address is not passed, gets the balance of the current client address.
* Optional asset can be passed, in which the query will be specific to that asset, such as ERC-20 token.
* Returns an array of assets and amounts, with assets in chain notation `CHAIN.SYMBOL-ID`
Returns the balance of an address.
- If address is not passed, gets the balance of the current client address.
- Optional asset can be passed, in which the query will be specific to that asset, such as ERC-20 token.
- Returns an array of assets and amounts, with assets in chain notation `CHAIN.SYMBOL-ID`
```ts

@@ -162,2 +188,3 @@ getBalance(address?: Address, asset?: string): Promise<Balances>

Example of third-party service queries to get balances:
```

@@ -168,6 +195,8 @@ https://api.blockchair.com/bitcoin/addresses/balances?addresses=34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo

```
Example of returned array:
```json
[
{
{
"asset" : "BTC.BTC"

@@ -180,3 +209,5 @@ "amount" : 100000000

## Get Transactions
Gets a simplied array of recent transactions for an address.
Gets a simplied array of recent transactions for an address.
```ts

@@ -196,2 +227,3 @@ // Defined in xchain-client/src/types.ts

Example of third party services to help:
```

@@ -208,5 +240,6 @@ // get UTXOS for address

Example of return:
```json
[
{
{
"hash" : "980D9519CCB39DC02F8B0208A4D181125EE8A2678B280AF70666288B62957DAE",

@@ -221,3 +254,3 @@ "from" : "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo",

},
{
{
"hash" : "0D9519CCB39DC02F8B0208A4D181125EE8A2678B280AF70666288B62957DAE98",

@@ -235,5 +268,5 @@ "from" : "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo",

> Due to the complexity of this function and dependence of third-party services, this function can be omitted in early versions of the client.
> Due to the complexity of this function and dependence of third-party services, this function can be omitted in early versions of the client.
----
---

@@ -243,17 +276,18 @@ # Transactions

## Get Fees
This function calculates and returns the fee object in a generalised way for a simple transfer function.
This function calculates and returns the fee object in a generalised way for a simple transfer function.
Since this depends on optional third-party services, sensible defaults should be hardcoded if there are errors.
The fastest fee rate should be guaranteed next block (1.5x Fast), fast should be 1-2 blocks (1x next block fee rate), average should be 2-3 blocks (0.5x Fast).
*Don't over-complicate this. PoW blockchains have no guarantees.*
The fastest fee rate should be guaranteed next block (1.5x Fast), fast should be 1-2 blocks (1x next block fee rate), average should be 2-3 blocks (0.5x Fast).
_Don't over-complicate this. PoW blockchains have no guarantees._
* Type should specify the units to display, or if flat fees, simply "flat". The client should interpret and display this, such as showing the user the fee rates and their units.
* Fastest (target of next block)
* Fast (target of 1-2 blocks)
* Average (target of 2-3 blocks)
- Type should specify the units to display, or if flat fees, simply "flat". The client should interpret and display this, such as showing the user the fee rates and their units.
- Fastest (target of next block)
- Fast (target of 1-2 blocks)
- Average (target of 2-3 blocks)
Third party services:
Bitcoin - returns next block feeRate (fast). Use multiples of this to extrapolate to Fastest/Average.
https://api.blockchair.com/bitcoin/stats
https://api.blockchair.com/bitcoin/stats

@@ -263,3 +297,2 @@ Ethereum - returns fastest/fast/average

```ts

@@ -270,2 +303,3 @@ getFees(): Promise<Fees>

**Examples**
```ts

@@ -293,13 +327,15 @@ // Bitcoin (sats/byte)

}
```
```
## Transfer
General transfer function that should be signed and broadcast using a third party service.
The fee should always be *rate*, which is units per transaction size. The size should be calculated on the fly or hardcoded:
* Bitcoin: 250 bytes is typical, so feeRate of 10 is 10 sats per byte, eg, 2500 sats
* Ethereum: gwei is standard, so a feeRate of 20 would be interpreted as 20 GWEI
* Binance Chain: fixed size, so the feeRate is ignored.
General transfer function that should be signed and broadcast using a third party service.
The fee should always be _rate_, which is units per transaction size. The size should be calculated on the fly or hardcoded:
- Bitcoin: 250 bytes is typical, so feeRate of 10 is 10 sats per byte, eg, 2500 sats
- Ethereum: gwei is standard, so a feeRate of 20 would be interpreted as 20 GWEI
- Binance Chain: fixed size, so the feeRate is ignored.
**Broadcast URLs**
```

@@ -315,3 +351,3 @@ https://api.blockchair.com/{:chain}/push/transaction

recipient: address // address
feeRate: number // optional feeRate
feeRate: number // optional feeRate
memo: string // optional memo to pass

@@ -322,6 +358,9 @@ }

```
The function should return the hash of the finalised transaction.
## Chain Specific
Chain-specific transactions can be added as well, such as Ethereum `approve()` or Binance Chain `freeze()/unfreeze()`
```ts

@@ -336,9 +375,11 @@ type ApproveParams = {

```
The function should return the hash of the finalised transaction.
## Purge
When a wallet is "locked" the private key should be purged in each client by setting it back to null. Also the phrase has to be cleared `this.phrase = ''`
When a wallet is "locked" the private key should be purged in each client by setting it back to null. Also the phrase has to be cleared `this.phrase = ''`
```ts
purgeClient()
```

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