Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@xchainjs/xchain-client
Advanced tools
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 com
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.
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:
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.
Making transfers.
Optional blockchain-specific transactions can be added here, such as Binance Chain freeze/unfreeze.
Public variable that returns the current client
public client: XChainClient
Public variable that returns the current network
public network: Network
Private variable that retains the private key that was extracted from the phrase during initialisation. The phrase should not be retained.
private privkey: PrivKey | null = null
Public variable that returns the address decoded from the private key during initialisation.
public address: Address
Used to set a type of NETWORK, which is either MAINNET or TESTNET.
enum Network {
TEST = 'testnet',
MAIN = 'mainnet',
}
setNetwork(net: Network): XChainClient
Returns the client.
Used to set the master BIP39 phrase, from which the private key is extracted and the address decoded.
setPhrase(phrase: string): address
The function should store the private key and address, then return the address generated by the phrase.
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:
export type ServiceKeys = {
[key: string]: { // name of the service (ie `blockchair`)
serviceKey: string // Optional API Key for the service
}
}
setServiceKeys(keys: ServiceKeys)
Returns the correctly formatted url string with paths for:
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.
enum Path {
address = 'address',
transaction = 'transaction',
}
getExplorerUrl(type: Path, param: string): string
The function should return the correctly formatted url string.
Example
https://blockchair.com/bitcoin/transaction/d11ff3352c50b1f5c8e2030711702a2071ca0e65457b40e6e0bcbea99e5dc82e
https://blockchair.com/bitcoin/address/19iqYbeATe4RxghQZJnYVFU4mjUUu76EA6
https://explorer.binance.org/tx/94F3A6257337052B04F9CC09F657966BFBD88546CA5C23F47AB0A601D29D8979
https://explorer.binance.org/address/bnb1z35wusfv8twfele77vddclka9z84ugywug48gn
https://etherscan.io/tx/0x87a4fa498cc48874631eaa776e84a49d28f42f01e22c51ff7cdfe1f2f6772f67
https://etherscan.io/address/0x8eb68e8f207be3dd1ec4baedf0b5c22245cda463
Returns the balance of an address.
CHAIN.SYMBOL-ID
getBalance(address?: Address, asset?: string): Promise<Balances>
Example of third-party service queries to get balances:
https://api.blockchair.com/bitcoin/addresses/balances?addresses=34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo
https://api.ethplorer.io/getAddressInfo/0xb00E81207bcDA63c9E290E0b748252418818c869?apiKey=freekey
https://dex.binance.org/api/v1/account/bnb1jxfh2g85q3v0tdq56fnevx6xcxtcnhtsmcu64m
Example of returned array:
[
{
"asset" : "BTC.BTC"
"amount" : 100000000
}
]
Gets a simplied array of recent transactions for an address.
export type TxHistoryParams = {
address: Address // Address to get history for
offset: number // Optional Offset
limit: string // Optional Limit of transactions
startTime: string // Optional start time
}
getTransactions(params?: TxHistoryParams): Promise<TxPage>
Example of third party services to help:
// get UTXOS for address
https://api.blockchair.com/bitcoin/outputs?recipient=34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo
// get tx details for each UTXO
https://api.blockchair.com/bitcoin/dashboards/transactions/ff0bd969cce99b8d8086e452d7b63167fc178680fee796fc742cb14a9a6ef929
https://api.ethplorer.io/getAddressTransactions/0xb297cacf0f91c86dd9d2fb47c6d12783121ab780?apiKey=freekey
https://dex.binance.org/api/v1/transactions?address=bnb1jxfh2g85q3v0tdq56fnevx6xcxtcnhtsmcu64m
Example of return:
[
{
"hash" : "980D9519CCB39DC02F8B0208A4D181125EE8A2678B280AF70666288B62957DAE",
"from" : "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo",
"to" : 34vRoCGJym3xR7yCVPFHoCNxv4Twseoxp4,
"amount": 100000000,
"asset" : "BTC.BTC",
"fee" : 2500,
"memo" : "transfer"
"date" : "2020-10-04T06:24:36.548Z"
},
{
"hash" : "0D9519CCB39DC02F8B0208A4D181125EE8A2678B280AF70666288B62957DAE98",
"from" : "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo",
"to" : 34vRoCGJym3xR7yCVPFHoCNxv4Twseoxp4,
"amount": 200000000,
"asset" : "BTC.BTC",
"fee" : 2500,
"memo" : "transfer"
"date" : "2020-10-04T06:24:36.548Z"
},
]
Due to the complexity of this function and dependence of third-party services, this function can be omitted in early versions of the client.
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.
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.
Third party services: Bitcoin - returns next block feeRate (fast). Use multiples of this to extrapolate to Fastest/Average. https://api.blockchair.com/bitcoin/stats
Ethereum - returns fastest/fast/average https://ethgasstation.info/api/ethgasAPI.json?api-key=XXAPI_Key_HereXXX
getFees(): Promise<Fees>
Examples
// Bitcoin (sats/byte)
{
"type" : "sats/byte"
"fastest" : 100
"fast" : 50
"average" : 20
}
// Ethereum (gwei)
{
"type" : "gwei"
"fastest" : 70
"fast" : 50
"average" : 40
}
// Binance Chain (flat rate)
{
"type" : "flat"
"average" : 37500
}
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:
Broadcast URLs
https://api.blockchair.com/{:chain}/push/transaction
https://dex.binance.org/api/v1/broadcast
export type TxParams = {
asset: string // BTC.BTC
amount: number // in base format (10**8)
recipient: address // address
feeRate: number // optional feeRate
memo: string // optional memo to pass
}
transfer(params: TxParams): Promise<TransferResult>
The function should return the hash of the finalised transaction.
Chain-specific transactions can be added as well, such as Ethereum approve()
or Binance Chain freeze()/unfreeze()
export type ApproveParams = {
asset: string // BTC.BTC
amount: number // in base format (10**8)
spender: address // address
}
approve(params: ApproveParams): Promise<TransferResult>
The function should return the hash of the finalised transaction.
When a wallet is "locked" the private key should be purged in each client by setting it back to null.
purgeClient()
FAQs
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 `xchain-crypto` library should be used to ensure cross-chain compa
The npm package @xchainjs/xchain-client receives a total of 50 weekly downloads. As such, @xchainjs/xchain-client popularity was classified as not popular.
We found that @xchainjs/xchain-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.