Socket
Socket
Sign inDemoInstall

@xchainjs/xchain-client

Package Overview
Dependencies
Maintainers
5
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-client - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# v.x.x.x (2020-XX-XX)
# v.0.2.0 (2020-12-11)
### Update
- Update dependencies
- Add `getDefaultFees`
# v.0.1.0 (2020-11-12)

@@ -2,0 +11,0 @@

1

lib/types.d.ts

@@ -67,4 +67,5 @@ import { Asset, BaseAmount } from '@xchainjs/xchain-util';

getFees(): Promise<Fees>;
getDefaultFees(): Fees;
transfer(params: TxParams): Promise<TxHash>;
purgeClient(): void;
}

19

package.json
{
"name": "@xchainjs/xchain-client",
"version": "0.1.0",
"version": "0.2.0",
"license": "MIT",

@@ -17,19 +17,6 @@ "main": "lib/index",

},
"devDependencies": {
"@types/jest": "^26.0.14",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.4.2",
"prettier": "^2.1.2",
"rimraf": "~3.0.2",
"ts-jest": "^26.4.1",
"typescript": "~4.0.0"
},
"gitHead": "3989696361e640b3dd55138772a43fc301797cd2",
"devDependencies": {},
"dependencies": {
"@xchainjs/xchain-util": "^0.1.0"
"@xchainjs/xchain-util": "^0.2.0"
}
}

@@ -29,3 +29,3 @@ # XChainJS Wallet Client Interface

Public variable that returns the current client
```
```ts
public client: XChainClient

@@ -36,3 +36,3 @@ ```

Public variable that returns the current network
```
```ts
public network: Network

@@ -43,3 +43,3 @@ ```

Private variable that retains the private key that was extracted from the phrase during initialisation. The phrase should not be retained.
```
```ts
private privkey: PrivKey | null = null

@@ -50,3 +50,3 @@ ```

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

@@ -58,8 +58,5 @@ ```

## Set Network
Used to set a type of NETWORK, which is either MAINNET or TESTNET.
```
enum Network {
TEST = 'testnet',
MAIN = 'mainnet',
}
Used to set a type of `Network`, which is either `'mainnet'` or `'testnet'`.
```ts
setNetwork(net: Network): XChainClient

@@ -71,3 +68,3 @@ ```

Used to set the master BIP39 phrase, from which the private key is extracted and the address decoded.
```
```ts
setPhrase(phrase: string): address

@@ -90,9 +87,21 @@ ```

```
export type ServiceKeys = {
[key: string]: { // name of the service (ie `blockchair`)
serviceKey: string // Optional API Key for the service
Service keys will be passed into constructor by extending `XChainClientParams` interface.
Example BitcoinClient:
```ts
// extending `XChainClientParams` to provide url and key of API service
type BitcoinClientParams = XChainClientParams & {
nodeUrl?: string
nodeApiKey?: string
}
class Client implements BitcoinClient, XChainClient {
// passing url and key of API service into constructor
constructor({ network = 'testnet', nodeUrl = '', nodeApiKey = '', phrase }: BitcoinClientParams) {
...
}
}
setServiceKeys(keys: ServiceKeys)
```

@@ -104,3 +113,3 @@

## Get Explorer URL
## Get Explorer URLs
Returns the correctly formatted url string with paths for:

@@ -110,12 +119,20 @@ * Addresses

The default Explorer URL can be hard-coded, or passed in as a service. The object to be cast into the explorer link should be passed in as a string, like a transaction ID or an address.
The default Explorer URL can be hard-coded, or passed in as a service. It will be provided by `getExplorerUrl`
```ts
getExplorerUrl(): string
```
enum Path {
address = 'address',
transaction = 'transaction',
}
getExplorerUrl(type: Path, param: string): string
To get explorer's URL for an address, use `getExplorerAddressUrl` by passing an `address`.
```ts
getExplorerAddressUrl = (address: Address): string
```
The function should return the correctly formatted url string.
To get explorer's URL for a transaction, use `getExplorerTxUrl` by passing a transaction ID.
```ts
getExplorerTxUrl = (txID: string): string
```
All functions should return the correctly formatted url string.
**Example**

@@ -138,5 +155,4 @@ ```

* Returns an array of assets and amounts, with assets in chain notation `CHAIN.SYMBOL-ID`
* Converts to 8 decimal places for conformity
```
```ts
getBalance(address?: Address, asset?: string): Promise<Balances>

@@ -152,3 +168,3 @@ ```

Example of returned array:
```
```json
[

@@ -164,9 +180,12 @@ {

Gets a simplied array of recent transactions for an address.
```
export type TxHistoryParams = {
```ts
// Defined in xchain-client/src/types.ts
type TxHistoryParams = {
address: Address // Address to get history for
offset: number // Optional Offset
limit: string // Optional Limit of transactions
startTime: string // Optional start time
offset?: number // Optional Offset
limit?: number // Optional Limit of transactions
startTime?: Date // Optional start time
asset?: string // Optional asset. Result transactions will be filtered by this asset
}
getTransactions(params?: TxHistoryParams): Promise<TxPage>

@@ -187,3 +206,3 @@ ```

Example of return:
```
```json
[

@@ -220,3 +239,3 @@ {

## Get Fees
This function calculates and returns the fee object in a generalised way for a simple transfer function. ASGARDEX userbase has high time preferences, so high fee rates are preferred.
This function calculates and returns the fee object in a generalised way for a simple transfer function.

@@ -241,3 +260,3 @@ Since this depends on optional third-party services, sensible defaults should be hardcoded if there are errors.

```
```ts
getFees(): Promise<Fees>

@@ -247,6 +266,6 @@ ```

**Examples**
```
```ts
// Bitcoin (sats/byte)
{
"type" : "sats/byte"
"type" : "byte"
"fastest" : 100

@@ -258,3 +277,3 @@ "fast" : 50

{
"type" : "gwei"
"type" : "base"
"fastest" : 70

@@ -266,3 +285,5 @@ "fast" : 50

{
"type" : "flat"
"type" : "base"
"fastest" : 37500
"fast" : 37500
"average" : 37500

@@ -286,3 +307,3 @@ }

```
```ts
export type TxParams = {

@@ -302,9 +323,9 @@ asset: string // BTC.BTC

Chain-specific transactions can be added as well, such as Ethereum `approve()` or Binance Chain `freeze()/unfreeze()`
```ts
type ApproveParams = {
asset: Asset
amount: BaseAmount
spender: Address
}
```
export type ApproveParams = {
asset: string // BTC.BTC
amount: number // in base format (10**8)
spender: address // address
}
approve(params: ApproveParams): Promise<TransferResult>

@@ -315,6 +336,6 @@ ```

## Purge
When a wallet is "locked" the private key should be purged in each client by setting it back to null.
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()
```
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