mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Remove deprecated functions from api.ts (aka client.ts) (#1534)
* Removed deprecated functions from client.ts * Renamed files to be camelCase * Created top-level utils folder and tied all sub-references to it * Grouped tests for those utils into their own section Co-authored-by: Nathan Nichols <natenichols@cox.net>
This commit is contained in:
committed by
Mayukha Vadari
parent
8e52854773
commit
da9feffada
@@ -33,7 +33,7 @@ class BroadcastClient extends Client {
|
||||
|
||||
// synchronous methods are all passed directly to the first client instance
|
||||
const defaultClient = clients[0]
|
||||
const syncMethods = ['sign', 'generateAddress', 'computeLedgerHash']
|
||||
const syncMethods = ['sign']
|
||||
syncMethods.forEach((name) => {
|
||||
this[name] = defaultClient[name].bind(defaultClient)
|
||||
})
|
||||
|
||||
@@ -3,11 +3,7 @@ import {
|
||||
constants,
|
||||
errors,
|
||||
validate,
|
||||
xrpToDrops,
|
||||
dropsToXrp,
|
||||
rippleTimeToISO8601,
|
||||
iso8601ToRippleTime,
|
||||
txFlags
|
||||
txFlags,
|
||||
} from '../common'
|
||||
import { Connection, ConnectionUserOptions } from './connection'
|
||||
import getTrustlines from '../ledger/trustlines'
|
||||
@@ -31,11 +27,7 @@ import prepareSettings from '../transaction/settings'
|
||||
import prepareTicketCreate from '../transaction/ticket'
|
||||
import {sign} from '../transaction/sign'
|
||||
import combine from '../transaction/combine'
|
||||
import { generateAddress, generateXAddress } from '../offline/utils'
|
||||
import {deriveKeypair, deriveAddress, deriveXAddress} from '../offline/derive'
|
||||
import computeLedgerHash from '../offline/ledgerhash'
|
||||
import signPaymentChannelClaim from '../offline/sign-payment-channel-claim'
|
||||
import verifyPaymentChannelClaim from '../offline/verify-payment-channel-claim'
|
||||
import {deriveAddress, deriveXAddress} from '../utils/derive'
|
||||
import {
|
||||
Request,
|
||||
Response,
|
||||
@@ -130,19 +122,6 @@ import {
|
||||
encodeXAddress,
|
||||
decodeXAddress
|
||||
} from 'ripple-address-codec'
|
||||
import {
|
||||
computeBinaryTransactionHash,
|
||||
computeTransactionHash,
|
||||
computeBinaryTransactionSigningHash,
|
||||
computeAccountLedgerObjectID,
|
||||
computeSignerListLedgerObjectID,
|
||||
computeOrderID,
|
||||
computeTrustlineHash,
|
||||
computeTransactionTreeHash,
|
||||
computeStateTreeHash,
|
||||
computeEscrowHash,
|
||||
computePaymentChannelHash
|
||||
} from '../common/hashes'
|
||||
import generateFaucetWallet from '../wallet/wallet-generation'
|
||||
import { ValidationError } from '../common/errors'
|
||||
|
||||
@@ -389,10 +368,6 @@ class Client extends EventEmitter {
|
||||
return results
|
||||
}
|
||||
|
||||
// @deprecated Use X-addresses instead & Invoke from top-level package instead
|
||||
generateAddress = generateAddress
|
||||
generateXAddress = generateXAddress // @deprecated Invoke from top-level package instead
|
||||
|
||||
isConnected(): boolean {
|
||||
return this.connection.isConnected()
|
||||
}
|
||||
@@ -432,12 +407,6 @@ class Client extends EventEmitter {
|
||||
sign = sign
|
||||
combine = combine
|
||||
|
||||
deriveKeypair = deriveKeypair // @deprecated Invoke from top-level package instead
|
||||
deriveAddress = deriveAddress // @deprecated Invoke from top-level package instead
|
||||
computeLedgerHash = computeLedgerHash // @deprecated Invoke from top-level package instead
|
||||
signPaymentChannelClaim = signPaymentChannelClaim // @deprecated Invoke from top-level package instead
|
||||
verifyPaymentChannelClaim = verifyPaymentChannelClaim // @deprecated Invoke from top-level package instead
|
||||
|
||||
generateFaucetWallet = generateFaucetWallet
|
||||
|
||||
errors = errors
|
||||
@@ -467,48 +436,6 @@ class Client extends EventEmitter {
|
||||
static encodeXAddress = encodeXAddress
|
||||
static decodeXAddress = decodeXAddress
|
||||
|
||||
/**
|
||||
* Static methods that replace functionality from the now-deprecated ripple-hashes library
|
||||
*/
|
||||
// Compute the hash of a binary transaction blob.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeBinaryTransactionHash = computeBinaryTransactionHash // (txBlobHex: string): string
|
||||
// Compute the hash of a transaction in txJSON format.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeTransactionHash = computeTransactionHash // (txJSON: any): string
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeBinaryTransactionSigningHash =
|
||||
computeBinaryTransactionSigningHash // (txBlobHex: string): string
|
||||
// Compute the hash of an account, given the account's classic address (starting with `r`).
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeAccountLedgerObjectID = computeAccountLedgerObjectID // (address: string): string
|
||||
// Compute the hash (ID) of an account's SignerList.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeSignerListLedgerObjectID = computeSignerListLedgerObjectID // (address: string): string
|
||||
// Compute the hash of an order, given the owner's classic address (starting with `r`) and the account sequence number of the `OfferCreate` order transaction.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeOrderID = computeOrderID // (address: string, sequence: number): string
|
||||
// Compute the hash of a trustline, given the two parties' classic addresses (starting with `r`) and the currency code.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeTrustlineHash = computeTrustlineHash // (address1: string, address2: string, currency: string): string
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeTransactionTreeHash = computeTransactionTreeHash // (transactions: any[]): string
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeStateTreeHash = computeStateTreeHash // (entries: any[]): string
|
||||
// Compute the hash of a ledger.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeLedgerHash = computeLedgerHash // (ledgerHeader): string
|
||||
// Compute the hash of an escrow, given the owner's classic address (starting with `r`) and the account sequence number of the `EscrowCreate` escrow transaction.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computeEscrowHash = computeEscrowHash // (address, sequence): string
|
||||
// Compute the hash of a payment channel, given the owner's classic address (starting with `r`), the classic address of the destination, and the account sequence number of the `PaymentChannelCreate` payment channel transaction.
|
||||
// @deprecated Invoke from top-level package instead
|
||||
static computePaymentChannelHash = computePaymentChannelHash // (address, dstAddress, sequence): string
|
||||
|
||||
xrpToDrops = xrpToDrops // @deprecated Invoke from top-level package instead
|
||||
dropsToXrp = dropsToXrp // @deprecated Invoke from top-level package instead
|
||||
rippleTimeToISO8601 = rippleTimeToISO8601 // @deprecated Invoke from top-level package instead
|
||||
iso8601ToRippleTime = iso8601ToRippleTime // @deprecated Invoke from top-level package instead
|
||||
txFlags = txFlags
|
||||
static txFlags = txFlags
|
||||
accountSetFlags = constants.AccountSetFlags
|
||||
|
||||
@@ -24,13 +24,4 @@ export function ensureClassicAddress(account: string): string {
|
||||
}
|
||||
|
||||
export {constants, errors, validate}
|
||||
export {
|
||||
dropsToXrp,
|
||||
xrpToDrops,
|
||||
toRippledAmount,
|
||||
removeUndefined,
|
||||
convertKeysFromSnakeCaseToCamelCase,
|
||||
iso8601ToRippleTime,
|
||||
rippleTimeToISO8601
|
||||
} from './utils'
|
||||
export {txFlags} from './txflags'
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as assert from 'assert'
|
||||
const {Validator} = require('jsonschema')
|
||||
import {ValidationError} from './errors'
|
||||
import {isValidClassicAddress, isValidXAddress} from 'ripple-address-codec'
|
||||
import {isValidSecret} from './utils'
|
||||
import {isValidSecret} from '../utils'
|
||||
|
||||
function loadSchemas() {
|
||||
// listed explicitly for webpack (instead of scanning schemas directory)
|
||||
|
||||
@@ -6,7 +6,7 @@ export * from './common/types/objects/ledger'
|
||||
|
||||
export * from './models/methods'
|
||||
|
||||
export * from './offline/utils'
|
||||
export * from './utils'
|
||||
|
||||
// Broadcast client is experimental
|
||||
export {BroadcastClient} from './client/broadcast'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {classicAddressToXAddress} from 'ripple-address-codec'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import BigNumber from 'bignumber.js'
|
||||
import parseAmount from './amount'
|
||||
import {parseTimestamp, adjustQualityForXRP} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {orderFlags} from './flags'
|
||||
import {FormattedOrderSpecification} from '../../common/types/objects'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {parseQuality} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {
|
||||
Trustline,
|
||||
FormattedTrustline
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import * as common from '../../common'
|
||||
import {Amount, RippledAmount} from '../../common/types/objects'
|
||||
import {dropsToXrp} from '../../utils'
|
||||
|
||||
function parseAmount(amount: RippledAmount): Amount {
|
||||
if (typeof amount === 'string') {
|
||||
return {
|
||||
currency: 'XRP',
|
||||
value: common.dropsToXrp(amount)
|
||||
value: dropsToXrp(amount)
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
export type FormattedCheckCancel = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import parseAmount from './amount'
|
||||
import {Amount} from '../../common/types/objects'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {parseTimestamp} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import parseAmount from './amount'
|
||||
import {Amount} from '../../common/types/objects'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
export type FormattedDepositPreauth = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
|
||||
function parseEscrowCancellation(tx: any): object {
|
||||
assert.ok(tx.TransactionType === 'EscrowCancel')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as assert from 'assert'
|
||||
import parseAmount from './amount'
|
||||
import {parseTimestamp, parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
|
||||
function parseEscrowCreation(tx: any): object {
|
||||
assert.ok(tx.TransactionType === 'EscrowCreate')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
|
||||
function parseEscrowExecution(tx: any): object {
|
||||
assert.ok(tx.TransactionType === 'EscrowFinish')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {dropsToXrp} from '../../common'
|
||||
import {dropsToXrp} from '../../utils'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
function parseFeeUpdate(tx: any) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as _ from 'lodash'
|
||||
import {removeUndefined, rippleTimeToISO8601} from '../../common'
|
||||
import {removeUndefined, rippleTimeToISOTime} from '../../utils'
|
||||
import parseTransaction from './transaction'
|
||||
import { TransactionAndMetadata } from '../../models/transactions'
|
||||
|
||||
@@ -62,7 +62,7 @@ function parseState(state) {
|
||||
/**
|
||||
* @param {Ledger} ledger must be a *closed* ledger with valid `close_time` and `parent_close_time`
|
||||
* @returns {FormattedLedger} formatted ledger
|
||||
* @throws RangeError: Invalid time value (rippleTimeToISO8601)
|
||||
* @throws RangeError: Invalid time value (rippleTimeToISOTime)
|
||||
*/
|
||||
export function parseLedger(ledger): FormattedLedger {
|
||||
const ledgerVersion = parseInt(ledger.ledger_index, 10)
|
||||
@@ -70,13 +70,13 @@ export function parseLedger(ledger): FormattedLedger {
|
||||
Object.assign(
|
||||
{
|
||||
stateHash: ledger.account_hash,
|
||||
closeTime: rippleTimeToISO8601(ledger.close_time),
|
||||
closeTime: rippleTimeToISOTime(ledger.close_time),
|
||||
closeTimeResolution: ledger.close_time_resolution,
|
||||
closeFlags: ledger.close_flags,
|
||||
ledgerHash: ledger.ledger_hash,
|
||||
ledgerVersion: ledgerVersion,
|
||||
parentLedgerHash: ledger.parent_hash,
|
||||
parentCloseTime: rippleTimeToISO8601(ledger.parent_close_time),
|
||||
parentCloseTime: rippleTimeToISOTime(ledger.parent_close_time),
|
||||
totalDrops: ledger.total_coins,
|
||||
transactionHash: ledger.transaction_hash
|
||||
},
|
||||
|
||||
@@ -2,7 +2,8 @@ import * as assert from 'assert'
|
||||
import {parseTimestamp} from './utils'
|
||||
import {parseMemos} from './utils'
|
||||
import parseAmount from './amount'
|
||||
import {removeUndefined, txFlags} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {txFlags} from '../../common'
|
||||
import {
|
||||
FormattedOrderSpecification,
|
||||
OfferCreateTransaction
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as _ from 'lodash'
|
||||
import {parseTimestamp, adjustQualityForXRP} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
|
||||
import {orderFlags} from './flags'
|
||||
import parseAmount from './amount'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined, txFlags} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {txFlags} from '../../common'
|
||||
import parseAmount from './amount'
|
||||
import {parseMemos} from './utils'
|
||||
const claimFlags = txFlags.PaymentChannelClaim
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {parseTimestamp,parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function parsePaymentChannelCreate(tx: any): object {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {parseTimestamp,parseMemos} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function parsePaymentChannelFund(tx: any): object {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {parseTimestamp, parseMemos} from './utils'
|
||||
import {removeUndefined, dropsToXrp} from '../../common'
|
||||
import {removeUndefined, dropsToXrp} from '../../utils'
|
||||
import { PayChannel } from '../../models/ledger'
|
||||
|
||||
export type FormattedPaymentChannel = {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as _ from 'lodash'
|
||||
import _ from 'lodash'
|
||||
import * as assert from 'assert'
|
||||
import * as utils from './utils'
|
||||
import {txFlags, removeUndefined} from '../../common'
|
||||
import {txFlags} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import parseAmount from './amount'
|
||||
|
||||
function isNoDirectRipple(tx) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as assert from 'assert'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
import {parseMemos} from './utils'
|
||||
|
||||
function parseTicketCreate(tx: any): object {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {parseOutcome} from './utils'
|
||||
import {removeUndefined} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
|
||||
import parseSettings from './settings'
|
||||
import parseAccountDelete from './account-delete'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as assert from 'assert'
|
||||
import {parseQuality, parseMemos} from './utils'
|
||||
import {txFlags, removeUndefined} from '../../common'
|
||||
import {txFlags} from '../../common'
|
||||
import {removeUndefined} from '../../utils'
|
||||
const flags = txFlags.TrustSet
|
||||
|
||||
function parseFlag(flagsValue, trueValue, falseValue) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import transactionParser from 'ripple-lib-transactionparser'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import * as common from '../../common'
|
||||
import parseAmount from './amount'
|
||||
|
||||
import {Amount, Memo} from '../../common/types/objects'
|
||||
import {txFlags} from '../../common'
|
||||
import {removeUndefined, dropsToXrp, rippleTimeToISOTime} from '../../utils'
|
||||
|
||||
type OfferDescription = {
|
||||
direction: string,
|
||||
@@ -54,7 +55,7 @@ function parseTimestamp(rippleTime?: number | null): string | undefined {
|
||||
if (typeof rippleTime !== 'number') {
|
||||
return undefined
|
||||
}
|
||||
return common.rippleTimeToISO8601(rippleTime)
|
||||
return rippleTimeToISOTime(rippleTime)
|
||||
}
|
||||
|
||||
function removeEmptyCounterparty(amount) {
|
||||
@@ -78,7 +79,7 @@ function removeEmptyCounterpartyInOrderbookChanges(orderbookChanges: Orderbook)
|
||||
}
|
||||
|
||||
function isPartialPayment(tx: any) {
|
||||
return (tx.Flags & common.txFlags.Payment.PartialPayment) !== 0
|
||||
return (tx.Flags & txFlags.Payment.PartialPayment) !== 0
|
||||
}
|
||||
|
||||
function parseDeliveredAmount(tx: any): Amount | void {
|
||||
@@ -133,10 +134,10 @@ function parseOutcome(tx: any): any | undefined {
|
||||
removeEmptyCounterpartyInBalanceChanges(balanceChanges)
|
||||
removeEmptyCounterpartyInOrderbookChanges(orderbookChanges)
|
||||
|
||||
return common.removeUndefined({
|
||||
return removeUndefined({
|
||||
result: tx.meta.TransactionResult,
|
||||
timestamp: parseTimestamp(tx.date),
|
||||
fee: common.dropsToXrp(tx.Fee),
|
||||
fee: dropsToXrp(tx.Fee),
|
||||
balanceChanges: balanceChanges,
|
||||
orderbookChanges: orderbookChanges,
|
||||
channelChanges: channelChanges,
|
||||
@@ -155,7 +156,7 @@ function parseMemos(tx: any): Array<Memo> | undefined {
|
||||
return undefined
|
||||
}
|
||||
return tx.Memos.map((m) => {
|
||||
return common.removeUndefined({
|
||||
return removeUndefined({
|
||||
type: m.Memo.parsed_memo_type || hexToString(m.Memo.MemoType),
|
||||
format: m.Memo.parsed_memo_format || hexToString(m.Memo.MemoFormat),
|
||||
data: m.Memo.parsed_memo_data || hexToString(m.Memo.MemoData)
|
||||
|
||||
@@ -3,11 +3,9 @@ import BigNumber from 'bignumber.js'
|
||||
import {getXRPBalance, renameCounterpartyToIssuer} from './utils'
|
||||
import {
|
||||
validate,
|
||||
toRippledAmount,
|
||||
errors,
|
||||
xrpToDrops,
|
||||
dropsToXrp
|
||||
errors
|
||||
} from '../common'
|
||||
import {toRippledAmount, xrpToDrops, dropsToXrp} from '../utils'
|
||||
import {Connection} from '../client'
|
||||
import parsePathfind from './parse/pathfind'
|
||||
import {RippledAmount, Amount} from '../common/types/objects'
|
||||
|
||||
@@ -6,6 +6,7 @@ import {FormattedTransactionType} from '../transaction/types'
|
||||
import {Issue} from '../common/types/objects'
|
||||
import {Client} from '..'
|
||||
import {AccountInfoRequest} from '../models/methods'
|
||||
import {dropsToXrp} from '..'
|
||||
|
||||
export type RecursiveData = {
|
||||
marker: string
|
||||
@@ -31,7 +32,7 @@ async function getXRPBalance(
|
||||
}
|
||||
const data = await client
|
||||
.request(request)
|
||||
return common.dropsToXrp(data.result.account_data.Balance)
|
||||
return dropsToXrp(data.result.account_data.Balance)
|
||||
}
|
||||
|
||||
// If the marker is omitted from a response, you have reached the end
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import { deriveKeypair, deriveAddress, deriveXAddress } from './derive'
|
||||
import computeLedgerHeaderHash from './ledgerhash'
|
||||
import signPaymentChannelClaim from './sign-payment-channel-claim'
|
||||
import verifyPaymentChannelClaim from './verify-payment-channel-claim'
|
||||
import { dropsToXrp,
|
||||
xrpToDrops,
|
||||
toRippledAmount,
|
||||
convertKeysFromSnakeCaseToCamelCase,
|
||||
removeUndefined,
|
||||
rippleTimeToISO8601,
|
||||
iso8601ToRippleTime,
|
||||
isValidSecret,
|
||||
} from '../common/utils'
|
||||
import {
|
||||
computeBinaryTransactionHash,
|
||||
computeTransactionHash,
|
||||
computeBinaryTransactionSigningHash,
|
||||
computeAccountLedgerObjectID,
|
||||
computeSignerListLedgerObjectID,
|
||||
computeOrderID,
|
||||
computeTrustlineHash,
|
||||
computeTransactionTreeHash,
|
||||
computeStateTreeHash,
|
||||
computeLedgerHash,
|
||||
computeEscrowHash,
|
||||
computePaymentChannelHash,
|
||||
} from '../common/hashes'
|
||||
import { generateAddressAPI, GenerateAddressOptions, GeneratedAddress } from '../offline/generate-address'
|
||||
|
||||
// @deprecated Use X-addresses instead
|
||||
const generateAddress = (options: GenerateAddressOptions = {}): GeneratedAddress => (
|
||||
generateAddressAPI({...options, includeClassicAddress: true})
|
||||
)
|
||||
|
||||
export {
|
||||
computeLedgerHeaderHash,
|
||||
dropsToXrp,
|
||||
xrpToDrops,
|
||||
toRippledAmount,
|
||||
convertKeysFromSnakeCaseToCamelCase,
|
||||
removeUndefined,
|
||||
rippleTimeToISO8601,
|
||||
iso8601ToRippleTime,
|
||||
isValidSecret,
|
||||
computeBinaryTransactionHash,
|
||||
computeTransactionHash,
|
||||
computeBinaryTransactionSigningHash,
|
||||
computeAccountLedgerObjectID,
|
||||
computeSignerListLedgerObjectID,
|
||||
computeOrderID,
|
||||
computeTrustlineHash,
|
||||
computeTransactionTreeHash,
|
||||
computeStateTreeHash,
|
||||
computeLedgerHash,
|
||||
computeEscrowHash,
|
||||
computePaymentChannelHash,
|
||||
generateAddress,
|
||||
generateAddressAPI as generateXAddress,
|
||||
deriveKeypair,
|
||||
deriveAddress,
|
||||
deriveXAddress,
|
||||
signPaymentChannelClaim,
|
||||
verifyPaymentChannelClaim,
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import * as utils from './utils'
|
||||
const ValidationError = utils.common.errors.ValidationError
|
||||
const toRippledAmount = utils.common.toRippledAmount
|
||||
import {validate} from '../common'
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {Amount} from '../common/types/objects'
|
||||
import {Client} from '..'
|
||||
import {toRippledAmount} from '../utils'
|
||||
import {ValidationError} from '../common/errors'
|
||||
|
||||
export type CheckCashParameters = {
|
||||
checkID: string
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as utils from './utils'
|
||||
const toRippledAmount = utils.common.toRippledAmount
|
||||
import {validate, iso8601ToRippleTime} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {ISOTimeToRippleTime, toRippledAmount} from '../utils'
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {Amount} from '../common/types/objects'
|
||||
import {Client} from '..'
|
||||
@@ -29,7 +29,7 @@ function createCheckCreateTransaction(
|
||||
}
|
||||
|
||||
if (check.expiration != null) {
|
||||
txJSON.Expiration = iso8601ToRippleTime(check.expiration)
|
||||
txJSON.Expiration = ISOTimeToRippleTime(check.expiration)
|
||||
}
|
||||
|
||||
if (check.invoiceID != null) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js'
|
||||
import {ValidationError} from '../common/errors'
|
||||
import {decodeAccountID} from 'ripple-address-codec'
|
||||
import {validate} from '../common'
|
||||
import {computeBinaryTransactionHash} from '../common/hashes'
|
||||
import {computeBinaryTransactionHash} from '../utils/hashes'
|
||||
import {JsonObject} from 'ripple-binary-codec/dist/types/serialized-type'
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as utils from './utils'
|
||||
import {validate, iso8601ToRippleTime, xrpToDrops} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {ISOTimeToRippleTime, xrpToDrops} from '../utils'
|
||||
const ValidationError = utils.common.errors.ValidationError
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {Memo} from '../common/types/objects'
|
||||
@@ -31,10 +32,10 @@ function createEscrowCreationTransaction(
|
||||
txJSON.Condition = payment.condition
|
||||
}
|
||||
if (payment.allowCancelAfter != null) {
|
||||
txJSON.CancelAfter = iso8601ToRippleTime(payment.allowCancelAfter)
|
||||
txJSON.CancelAfter = ISOTimeToRippleTime(payment.allowCancelAfter)
|
||||
}
|
||||
if (payment.allowExecuteAfter != null) {
|
||||
txJSON.FinishAfter = iso8601ToRippleTime(payment.allowExecuteAfter)
|
||||
txJSON.FinishAfter = ISOTimeToRippleTime(payment.allowExecuteAfter)
|
||||
}
|
||||
if (payment.sourceTag != null) {
|
||||
txJSON.SourceTag = payment.sourceTag
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as utils from './utils'
|
||||
const offerFlags = utils.common.txFlags.OfferCreate
|
||||
import {validate, iso8601ToRippleTime, toRippledAmount} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {ISOTimeToRippleTime, toRippledAmount} from '../utils'
|
||||
import {Instructions, Prepare, OfferCreateTransaction} from './types'
|
||||
import {FormattedOrderSpecification} from '../common/types/objects/index'
|
||||
import {Client} from '..'
|
||||
@@ -36,7 +37,7 @@ function createOrderTransaction(
|
||||
txJSON.Flags |= offerFlags.FillOrKill
|
||||
}
|
||||
if (order.expirationTime != null) {
|
||||
txJSON.Expiration = iso8601ToRippleTime(order.expirationTime)
|
||||
txJSON.Expiration = ISOTimeToRippleTime(order.expirationTime)
|
||||
}
|
||||
if (order.orderToReplace != null) {
|
||||
txJSON.OfferSequence = order.orderToReplace
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as utils from './utils'
|
||||
const ValidationError = utils.common.errors.ValidationError
|
||||
const claimFlags = utils.common.txFlags.PaymentChannelClaim
|
||||
import {validate, xrpToDrops} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {xrpToDrops} from '../utils'
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {Client} from '..'
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as utils from './utils'
|
||||
import {validate, iso8601ToRippleTime, xrpToDrops} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {ISOTimeToRippleTime, xrpToDrops} from '../utils'
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {Client} from '..'
|
||||
|
||||
@@ -27,7 +28,7 @@ function createPaymentChannelCreateTransaction(
|
||||
}
|
||||
|
||||
if (paymentChannel.cancelAfter != null) {
|
||||
txJSON.CancelAfter = iso8601ToRippleTime(paymentChannel.cancelAfter)
|
||||
txJSON.CancelAfter = ISOTimeToRippleTime(paymentChannel.cancelAfter)
|
||||
}
|
||||
if (paymentChannel.sourceTag != null) {
|
||||
txJSON.SourceTag = paymentChannel.sourceTag
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as utils from './utils'
|
||||
import {validate, iso8601ToRippleTime, xrpToDrops} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {ISOTimeToRippleTime, xrpToDrops} from '../utils'
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {Client} from '..'
|
||||
|
||||
@@ -21,7 +22,7 @@ function createPaymentChannelFundTransaction(
|
||||
}
|
||||
|
||||
if (fund.expiration != null) {
|
||||
txJSON.Expiration = iso8601ToRippleTime(fund.expiration)
|
||||
txJSON.Expiration = ISOTimeToRippleTime(fund.expiration)
|
||||
}
|
||||
|
||||
return txJSON
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
MinAdjustment,
|
||||
Memo
|
||||
} from '../common/types/objects'
|
||||
import {toRippledAmount, xrpToDrops} from '../common'
|
||||
import {toRippledAmount, xrpToDrops} from '../utils'
|
||||
import {Client} from '..'
|
||||
import {getClassicAccountAndTag, ClassicAccountAndTag} from './utils'
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ import _ from 'lodash'
|
||||
import * as utils from './utils'
|
||||
import keypairs from 'ripple-keypairs'
|
||||
import binaryCodec from 'ripple-binary-codec'
|
||||
import {computeBinaryTransactionHash} from '../common/hashes'
|
||||
import {computeBinaryTransactionHash} from '../utils/hashes'
|
||||
import {SignOptions, KeyPair, TransactionJSON} from './types'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {xrpToDrops} from '../common'
|
||||
import {xrpToDrops} from '../utils'
|
||||
import {Client} from '..'
|
||||
import Wallet from '../Wallet'
|
||||
import {SignedTransaction} from '../common/types/objects'
|
||||
|
||||
@@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js'
|
||||
import * as common from '../common'
|
||||
import {Memo} from '../common/types/objects'
|
||||
import {Instructions, Prepare, TransactionJSON} from './types'
|
||||
import {toRippledAmount} from '../common'
|
||||
import {toRippledAmount, dropsToXrp, removeUndefined, xrpToDrops} from '../utils'
|
||||
import {Client} from '..'
|
||||
import {ValidationError} from '../common/errors'
|
||||
import {xAddressToClassicAddress, isValidXAddress} from 'ripple-address-codec'
|
||||
@@ -23,7 +23,7 @@ export type ApiMemo = {
|
||||
|
||||
function formatPrepareResponse(txJSON: any): Prepare {
|
||||
const instructions = {
|
||||
fee: common.dropsToXrp(txJSON.Fee),
|
||||
fee: dropsToXrp(txJSON.Fee),
|
||||
maxLedgerVersion:
|
||||
txJSON.LastLedgerSequence == null ? null : txJSON.LastLedgerSequence
|
||||
}
|
||||
@@ -310,7 +310,7 @@ function prepareTransaction(
|
||||
)
|
||||
}
|
||||
newTxJSON.Fee = scaleValue(
|
||||
common.xrpToDrops(instructions.fee),
|
||||
xrpToDrops(instructions.fee),
|
||||
multiplier
|
||||
)
|
||||
return Promise.resolve()
|
||||
@@ -331,11 +331,11 @@ function prepareTransaction(
|
||||
Math.floor(
|
||||
Buffer.from(newTxJSON.Fulfillment, 'hex').length / 16
|
||||
))
|
||||
const feeDrops = common.xrpToDrops(fee)
|
||||
const feeDrops = xrpToDrops(fee)
|
||||
const maxFeeXRP = instructions.maxFee
|
||||
? BigNumber.min(client._maxFeeXRP, instructions.maxFee)
|
||||
: client._maxFeeXRP
|
||||
const maxFeeDrops = common.xrpToDrops(maxFeeXRP)
|
||||
const maxFeeDrops = xrpToDrops(maxFeeXRP)
|
||||
const normalFee = scaleValue(feeDrops, multiplier, extraFee)
|
||||
newTxJSON.Fee = BigNumber.min(normalFee, maxFeeDrops).toString(10)
|
||||
|
||||
@@ -398,7 +398,7 @@ function convertStringToHex(string: string): string {
|
||||
|
||||
function convertMemo(memo: Memo): {Memo: ApiMemo} {
|
||||
return {
|
||||
Memo: common.removeUndefined({
|
||||
Memo: removeUndefined({
|
||||
MemoData: memo.data ? convertStringToHex(memo.data) : undefined,
|
||||
MemoType: memo.type ? convertStringToHex(memo.type) : undefined,
|
||||
MemoFormat: memo.format ? convertStringToHex(memo.format) : undefined
|
||||
|
||||
@@ -26,7 +26,8 @@ export interface GenerateAddressOptions {
|
||||
includeClassicAddress?: boolean
|
||||
}
|
||||
|
||||
function generateAddressAPI(options: GenerateAddressOptions = {}): GeneratedAddress {
|
||||
// TODO: move this function to be a static function of the Wallet class (Along with its helper data types)
|
||||
function generateXAddress(options: GenerateAddressOptions = {}): GeneratedAddress {
|
||||
validate.generateAddress({options})
|
||||
try {
|
||||
const generateSeedOptions: {
|
||||
@@ -59,4 +60,4 @@ function generateAddressAPI(options: GenerateAddressOptions = {}): GeneratedAddr
|
||||
}
|
||||
}
|
||||
|
||||
export {generateAddressAPI}
|
||||
export {generateXAddress}
|
||||
@@ -1,10 +1,10 @@
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {decodeAccountID} from 'ripple-address-codec'
|
||||
import sha512Half from './sha512Half'
|
||||
import HashPrefix from './hash-prefix'
|
||||
import HashPrefix from './hashPrefix'
|
||||
import {SHAMap, NodeType} from './shamap'
|
||||
import {encode} from 'ripple-binary-codec'
|
||||
import ledgerspaces from './ledgerspaces'
|
||||
import ledgerSpaces from './ledgerSpaces'
|
||||
|
||||
const padLeftZero = (string: string, length: number): string => {
|
||||
return Array(length - string.length + 1).join('0') + string
|
||||
@@ -27,7 +27,7 @@ const bigintToHex = (
|
||||
}
|
||||
|
||||
const ledgerSpaceHex = (name: string): string => {
|
||||
return intToHex(ledgerspaces[name].charCodeAt(0), 2)
|
||||
return intToHex(ledgerSpaces[name].charCodeAt(0), 2)
|
||||
}
|
||||
|
||||
const addressToHex = (address: string): string => {
|
||||
@@ -84,36 +84,36 @@ export const computeBinaryTransactionSigningHash = (
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute Account Ledger Object ID
|
||||
* Compute Account Root Index
|
||||
*
|
||||
* All objects in a ledger's state tree have a unique ID.
|
||||
* The Account Ledger Object ID is derived by hashing the
|
||||
* All objects in a ledger's state tree have a unique index.
|
||||
* The Account Root index is derived by hashing the
|
||||
* address with a namespace identifier. This ensures every
|
||||
* ID is unique.
|
||||
* index is unique.
|
||||
*
|
||||
* See [Ledger Object IDs](https://xrpl.org/ledger-object-ids.html)
|
||||
*
|
||||
* @param address The classic account address
|
||||
* @returns {string} The Ledger Object ID for the account
|
||||
* @returns {string} The Ledger Object Index for the account
|
||||
*/
|
||||
export const computeAccountLedgerObjectID = (address: string): string => {
|
||||
export const computeAccountRootIndex = (address: string): string => {
|
||||
return sha512Half(ledgerSpaceHex('account') + addressToHex(address))
|
||||
}
|
||||
|
||||
/**
|
||||
* [SignerList ID Format](https://xrpl.org/signerlist.html#signerlist-id-format)
|
||||
*
|
||||
* The ID of a SignerList object is the SHA-512Half of the following values, concatenated in order:
|
||||
* The index of a SignerList object is the SHA-512Half of the following values, concatenated in order:
|
||||
* * The RippleState space key (0x0053)
|
||||
* * The AccountID of the owner of the SignerList
|
||||
* * The SignerListID (currently always 0)
|
||||
*
|
||||
* This method computes a SignerList Ledger Object ID.
|
||||
* This method computes a SignerList index.
|
||||
*
|
||||
* @param address The classic account address of the SignerList owner (starting with r)
|
||||
* @return {string} The ID of the account's SignerList object
|
||||
*/
|
||||
export const computeSignerListLedgerObjectID = (address: string): string => {
|
||||
export const computeSignerListIndex = (address: string): string => {
|
||||
return sha512Half(
|
||||
ledgerSpaceHex('signerList') + addressToHex(address) + '00000000'
|
||||
) // uint32(0) signer list index
|
||||
@@ -122,18 +122,18 @@ export const computeSignerListLedgerObjectID = (address: string): string => {
|
||||
/**
|
||||
* [Offer ID Format](https://xrpl.org/offer.html#offer-id-format)
|
||||
*
|
||||
* The ID of a Offer object is the SHA-512Half of the following values, concatenated in order:
|
||||
* The index of a Offer object is the SHA-512Half of the following values, concatenated in order:
|
||||
* * The Offer space key (0x006F)
|
||||
* * The AccountID of the account placing the offer
|
||||
* * The Sequence number of the OfferCreate transaction that created the offer
|
||||
*
|
||||
* This method computes an Offer ID (aka Order ID).
|
||||
* This method computes an Offer Index (aka Order Index).
|
||||
*
|
||||
* @param address The classic account address of the SignerList owner (starting with r)
|
||||
* @returns {string} The ID of the account's Offer object
|
||||
* @returns {string} The index of the account's Offer object
|
||||
*/
|
||||
export const computeOrderID = (address: string, sequence: number): string => {
|
||||
const prefix = '00' + intToHex(ledgerspaces.offer.charCodeAt(0), 1)
|
||||
export const computeOfferIndex = (address: string, sequence: number): string => {
|
||||
const prefix = '00' + intToHex(ledgerSpaces.offer.charCodeAt(0), 1)
|
||||
return sha512Half(prefix + addressToHex(address) + intToHex(sequence, 4))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import hashPrefix from './hash-prefix'
|
||||
import hashPrefix from './hashPrefix'
|
||||
import sha512Half from './sha512Half'
|
||||
const HEX_ZERO =
|
||||
'0000000000000000000000000000000000000000000000000000000000000000'
|
||||
@@ -1,8 +1,27 @@
|
||||
import * as _ from 'lodash'
|
||||
import { deriveKeypair, deriveAddress, deriveXAddress } from './derive'
|
||||
import computeLedgerHeaderHash from './ledgerHash'
|
||||
import signPaymentChannelClaim from './signPaymentChannelClaim'
|
||||
import verifyPaymentChannelClaim from './verifyPaymentChannelClaim'
|
||||
import {
|
||||
computeBinaryTransactionHash,
|
||||
computeTransactionHash,
|
||||
computeBinaryTransactionSigningHash,
|
||||
computeAccountRootIndex,
|
||||
computeSignerListIndex,
|
||||
computeOfferIndex,
|
||||
computeTrustlineHash,
|
||||
computeTransactionTreeHash,
|
||||
computeStateTreeHash,
|
||||
computeLedgerHash,
|
||||
computeEscrowHash,
|
||||
computePaymentChannelHash,
|
||||
} from './hashes'
|
||||
import { generateXAddress } from './generateAddress'
|
||||
|
||||
import _ from 'lodash'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import {deriveKeypair} from 'ripple-keypairs'
|
||||
import {RippledAmount} from './types/objects'
|
||||
import {ValidationError} from './errors'
|
||||
import {RippledAmount} from '../common/types/objects'
|
||||
import {ValidationError} from '../common/errors'
|
||||
import {xAddressToClassicAddress} from 'ripple-address-codec'
|
||||
|
||||
function isValidSecret(secret: string): boolean {
|
||||
@@ -170,13 +189,17 @@ function rippleToUnixTimestamp(rpepoch: number): number {
|
||||
|
||||
/**
|
||||
* @param {Number|Date} timestamp (ms since unix epoch)
|
||||
* @return {Number} seconds since ripple epoch (1/1/2000 GMT)
|
||||
* @return {Number} seconds since Ripple Epoch (1/1/2000 GMT)
|
||||
*/
|
||||
function unixToRippleTimestamp(timestamp: number): number {
|
||||
return Math.round(timestamp / 1000) - 0x386d4380
|
||||
}
|
||||
|
||||
function rippleTimeToISO8601(rippleTime: number): string {
|
||||
/**
|
||||
* @param {number} rippleTime is the number of seconds since Ripple Epoch (1/1/2000 GMT)
|
||||
* @return {string} iso8601 international standard date format
|
||||
*/
|
||||
function rippleTimeToISOTime(rippleTime: number): string {
|
||||
return new Date(rippleToUnixTimestamp(rippleTime)).toISOString()
|
||||
}
|
||||
|
||||
@@ -184,17 +207,36 @@ function rippleTimeToISO8601(rippleTime: number): string {
|
||||
* @param {string} iso8601 international standard date format
|
||||
* @return {number} seconds since ripple epoch (1/1/2000 GMT)
|
||||
*/
|
||||
function iso8601ToRippleTime(iso8601: string): number {
|
||||
function ISOTimeToRippleTime(iso8601: string): number {
|
||||
return unixToRippleTimestamp(Date.parse(iso8601))
|
||||
}
|
||||
|
||||
export {
|
||||
computeLedgerHeaderHash,
|
||||
dropsToXrp,
|
||||
xrpToDrops,
|
||||
toRippledAmount,
|
||||
convertKeysFromSnakeCaseToCamelCase,
|
||||
removeUndefined,
|
||||
rippleTimeToISO8601,
|
||||
iso8601ToRippleTime,
|
||||
isValidSecret
|
||||
rippleTimeToISOTime,
|
||||
ISOTimeToRippleTime,
|
||||
isValidSecret,
|
||||
computeBinaryTransactionHash,
|
||||
computeTransactionHash,
|
||||
computeBinaryTransactionSigningHash,
|
||||
computeAccountRootIndex,
|
||||
computeSignerListIndex,
|
||||
computeOfferIndex,
|
||||
computeTrustlineHash,
|
||||
computeTransactionTreeHash,
|
||||
computeStateTreeHash,
|
||||
computeLedgerHash,
|
||||
computeEscrowHash,
|
||||
computePaymentChannelHash,
|
||||
generateXAddress,
|
||||
deriveKeypair,
|
||||
deriveAddress,
|
||||
deriveXAddress,
|
||||
signPaymentChannelClaim,
|
||||
verifyPaymentChannelClaim,
|
||||
}
|
||||
@@ -1,22 +1,23 @@
|
||||
import * as _ from 'lodash'
|
||||
import _ from 'lodash'
|
||||
import { ISOTimeToRippleTime } from '.'
|
||||
import { ValidationError } from '../common/errors'
|
||||
import {
|
||||
computeLedgerHash,
|
||||
computeTransactionTreeHash,
|
||||
computeStateTreeHash
|
||||
} from '../common/hashes'
|
||||
import * as common from '../common'
|
||||
} from '../utils/hashes'
|
||||
|
||||
function convertLedgerHeader(header): any {
|
||||
return {
|
||||
account_hash: header.stateHash,
|
||||
close_time: common.iso8601ToRippleTime(header.closeTime),
|
||||
close_time: ISOTimeToRippleTime(header.closeTime),
|
||||
close_time_resolution: header.closeTimeResolution,
|
||||
close_flags: header.closeFlags,
|
||||
hash: header.ledgerHash,
|
||||
ledger_hash: header.ledgerHash,
|
||||
ledger_index: header.ledgerVersion.toString(),
|
||||
parent_hash: header.parentLedgerHash,
|
||||
parent_close_time: common.iso8601ToRippleTime(header.parentCloseTime),
|
||||
parent_close_time: ISOTimeToRippleTime(header.parentCloseTime),
|
||||
total_coins: header.totalDrops,
|
||||
transaction_hash: header.transactionHash
|
||||
}
|
||||
@@ -45,14 +46,14 @@ function computeTransactionHash(
|
||||
'SyntaxError: Unexpected' + ' token u in JSON at position 0'
|
||||
) {
|
||||
// one or more of the `tx.rawTransaction`s is undefined
|
||||
throw new common.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
'ledger' + ' is missing raw transactions'
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (options.computeTreeHashes) {
|
||||
throw new common.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
'transactions' + ' property is missing from the ledger'
|
||||
)
|
||||
}
|
||||
@@ -73,7 +74,7 @@ function computeTransactionHash(
|
||||
ledger.transactionHash != null &&
|
||||
ledger.transactionHash !== transactionHash
|
||||
) {
|
||||
throw new common.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
'transactionHash in header' +
|
||||
' does not match computed hash of transactions',
|
||||
{
|
||||
@@ -88,7 +89,7 @@ function computeTransactionHash(
|
||||
function computeStateHash(ledger, options: ComputeLedgerHeaderHashOptions) {
|
||||
if (ledger.rawState == null) {
|
||||
if (options.computeTreeHashes) {
|
||||
throw new common.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
'rawState' + ' property is missing from the ledger'
|
||||
)
|
||||
}
|
||||
@@ -97,7 +98,7 @@ function computeStateHash(ledger, options: ComputeLedgerHeaderHashOptions) {
|
||||
const state = JSON.parse(ledger.rawState)
|
||||
const stateHash = computeStateTreeHash(state)
|
||||
if (ledger.stateHash != null && ledger.stateHash !== stateHash) {
|
||||
throw new common.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
'stateHash in header' + ' does not match computed hash of state'
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as common from '../common'
|
||||
import keypairs from 'ripple-keypairs'
|
||||
import binary from 'ripple-binary-codec'
|
||||
const {validate, xrpToDrops} = common
|
||||
import { validate } from '../common'
|
||||
import { xrpToDrops } from '.'
|
||||
|
||||
function signPaymentChannelClaim(
|
||||
channel: string,
|
||||
@@ -9,7 +9,6 @@ function signPaymentChannelClaim(
|
||||
privateKey: string
|
||||
): string {
|
||||
validate.signPaymentChannelClaim({channel, amount, privateKey})
|
||||
|
||||
const signingData = binary.encodeForSigningClaim({
|
||||
channel: channel,
|
||||
amount: xrpToDrops(amount)
|
||||
@@ -1,6 +1,7 @@
|
||||
import keypairs from 'ripple-keypairs'
|
||||
import binary from 'ripple-binary-codec'
|
||||
import {validate, xrpToDrops} from '../common'
|
||||
import {validate} from '../common'
|
||||
import {xrpToDrops} from '.'
|
||||
|
||||
function verifyPaymentChannelClaim(
|
||||
channel: string,
|
||||
@@ -2,7 +2,7 @@ import https = require('https')
|
||||
|
||||
import {Client} from '..'
|
||||
import {errors} from '../common'
|
||||
import {GeneratedAddress} from '../offline/generate-address'
|
||||
import {GeneratedAddress} from '../utils/generateAddress'
|
||||
import {isValidAddress} from '../common/schema-validator'
|
||||
import {RippledError} from '../common/errors'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"diff": true,
|
||||
"spec": ["./test/*.ts", "./test/models/**/*.ts"],
|
||||
"spec": ["./test/*.ts", "./test/models/**/*.ts", "./test/utils/**/*.ts"],
|
||||
"extension": ["ts"],
|
||||
"package": "../package.json",
|
||||
"require": "ts-node/register",
|
||||
|
||||
@@ -3,7 +3,7 @@ import assert from 'assert-diff'
|
||||
import setupClient from './setup-client'
|
||||
import responses from './fixtures/responses'
|
||||
import rippled from './fixtures/rippled'
|
||||
import {ignoreWebSocketDisconnect} from './utils'
|
||||
import {ignoreWebSocketDisconnect} from './testUtils'
|
||||
|
||||
const TIMEOUT = 20000
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import assert from 'assert-diff'
|
||||
import binary from 'ripple-binary-codec'
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const {combine: REQUEST_FIXTURES} = requests
|
||||
const {combine: RESPONSE_FIXTURES} = responses
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
import {Client} from 'xrpl-local'
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
* - Check out the "TestSuite" type for documentation on the interface.
|
||||
* - Check out "test/client/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
'returns address for public key': async (client, address) => {
|
||||
var address = client.deriveAddress(
|
||||
'035332FBA71D705BD5D97014A833BE2BBB25BEFCD3506198E14AFEA241B98C2D06'
|
||||
)
|
||||
assert.equal(address, 'rLczgQHxPhWtjkaQqn3Q6UM8AbRbbRvs5K')
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
* - Check out the "TestSuite" type for documentation on the interface.
|
||||
* - Check out "test/client/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
'returns keypair for secret': async (client, address) => {
|
||||
var keypair = client.deriveKeypair('snsakdSrZSLkYpCXxfRkS4Sh96PMK')
|
||||
assert.equal(
|
||||
keypair.privateKey,
|
||||
'008850736302221AFD59FF9CA1A29D4975F491D726249302EE48A3078A8934D335'
|
||||
)
|
||||
assert.equal(
|
||||
keypair.publicKey,
|
||||
'035332FBA71D705BD5D97014A833BE2BBB25BEFCD3506198E14AFEA241B98C2D06'
|
||||
)
|
||||
},
|
||||
|
||||
'returns keypair for ed25519 secret': async (client, address) => {
|
||||
var keypair = client.deriveKeypair('sEdV9eHWbibBnTj7b1H5kHfPfv7gudx')
|
||||
assert.equal(
|
||||
keypair.privateKey,
|
||||
'ED5C2EF6C2E3200DFA6B72F47935C7F64D35453646EA34919192538F458C7BC30F'
|
||||
)
|
||||
assert.equal(
|
||||
keypair.publicKey,
|
||||
'ED0805EC4E728DB87C0CA6C420751F296C57A5F42D02E9E6150CE60694A44593E5'
|
||||
)
|
||||
},
|
||||
|
||||
'throws with an invalid secret': async (client, address) => {
|
||||
assert.throws(() => {
|
||||
client.deriveKeypair('...')
|
||||
}, /^Error: Non-base58 character$/)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
import {Client} from '../../../src'
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// import {Client} from 'xrpl-local'
|
||||
// import requests from '../../fixtures/requests'
|
||||
// import responses from '../../fixtures/responses'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
|
||||
// function checkSortingOfOrders(orders) {
|
||||
// let previousRate = '0'
|
||||
|
||||
@@ -1,252 +0,0 @@
|
||||
import assert from 'assert-diff'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {TestSuite} from '../../utils'
|
||||
import ECDSA from '../../../src/common/ecdsa'
|
||||
import {GenerateAddressOptions} from '../../../src/offline/generate-address'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
* - Check out the "TestSuite" type for documentation on the interface.
|
||||
* - Check out "test/client/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
'generateXAddress': async (client) => {
|
||||
// GIVEN entropy of all zeros
|
||||
function random() {
|
||||
return new Array(16).fill(0)
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
// WHEN generating an X-address
|
||||
client.generateXAddress({entropy: random()}),
|
||||
|
||||
// THEN we get the expected return value
|
||||
responses.generateXAddress
|
||||
)
|
||||
},
|
||||
|
||||
'generateXAddress invalid entropy': async (client) => {
|
||||
assert.throws(() => {
|
||||
// GIVEN entropy of 1 byte
|
||||
function random() {
|
||||
return new Array(1).fill(0)
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
client.generateXAddress({entropy: random()})
|
||||
|
||||
// THEN an UnexpectedError is thrown
|
||||
// because 16 bytes of entropy are required
|
||||
}, client.errors.UnexpectedError)
|
||||
},
|
||||
|
||||
'generateXAddress with no options object': async (client) => {
|
||||
// GIVEN no options
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress()
|
||||
|
||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
||||
assert(
|
||||
account.xAddress.startsWith('X'),
|
||||
'By default X-addresses start with X'
|
||||
)
|
||||
assert(account.secret.startsWith('s'), 'Secrets start with s')
|
||||
},
|
||||
|
||||
'generateXAddress with empty options object': async (client) => {
|
||||
// GIVEN an empty options object
|
||||
const options = {}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
||||
assert(
|
||||
account.xAddress.startsWith('X'),
|
||||
'By default X-addresses start with X'
|
||||
)
|
||||
assert(account.secret.startsWith('s'), 'Secrets start with s')
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ecdsa-secp256k1`': async (client) => {
|
||||
// GIVEN we want to use 'ecdsa-secp256k1'
|
||||
const options: GenerateAddressOptions = {algorithm: ECDSA.secp256k1}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 's'
|
||||
assert(
|
||||
account.xAddress.startsWith('X'),
|
||||
'By default X-addresses start with X'
|
||||
)
|
||||
assert.deepEqual(
|
||||
account.secret.slice(0, 1),
|
||||
's',
|
||||
`Secret ${account.secret} must start with 's'`
|
||||
)
|
||||
assert.notStrictEqual(
|
||||
account.secret.slice(0, 3),
|
||||
'sEd',
|
||||
`secp256k1 secret ${account.secret} must not start with 'sEd'`
|
||||
)
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ed25519`': async (client) => {
|
||||
// GIVEN we want to use 'ed25519'
|
||||
const options: GenerateAddressOptions = {algorithm: ECDSA.ed25519}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get an object with an xAddress starting with 'X' and a secret starting with 'sEd'
|
||||
assert(
|
||||
account.xAddress.startsWith('X'),
|
||||
'By default X-addresses start with X'
|
||||
)
|
||||
assert.deepEqual(
|
||||
account.secret.slice(0, 3),
|
||||
'sEd',
|
||||
`Ed25519 secret ${account.secret} must start with 'sEd'`
|
||||
)
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy': async (
|
||||
client
|
||||
) => {
|
||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||
const options: GenerateAddressOptions = {
|
||||
algorithm: ECDSA.secp256k1,
|
||||
entropy: new Array(16).fill(0)
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get the expected return value
|
||||
assert.deepEqual(account, responses.generateXAddress)
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ed25519` and given entropy': async (
|
||||
client
|
||||
) => {
|
||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||
const options: GenerateAddressOptions = {
|
||||
algorithm: ECDSA.ed25519,
|
||||
entropy: new Array(16).fill(0)
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get the expected return value
|
||||
assert.deepEqual(account, {
|
||||
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE'
|
||||
})
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async (
|
||||
client
|
||||
) => {
|
||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||
const options: GenerateAddressOptions = {
|
||||
algorithm: ECDSA.secp256k1,
|
||||
entropy: new Array(16).fill(0),
|
||||
includeClassicAddress: true
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get the expected return value
|
||||
assert.deepEqual(account, responses.generateAddress)
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ed25519` and given entropy; include classic address': async (
|
||||
client
|
||||
) => {
|
||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||
const options: GenerateAddressOptions = {
|
||||
algorithm: ECDSA.ed25519,
|
||||
entropy: new Array(16).fill(0),
|
||||
includeClassicAddress: true
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get the expected return value
|
||||
assert.deepEqual(account, {
|
||||
xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB',
|
||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
||||
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7'
|
||||
})
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async (
|
||||
client
|
||||
) => {
|
||||
// GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero
|
||||
const options: GenerateAddressOptions = {
|
||||
algorithm: ECDSA.secp256k1,
|
||||
entropy: new Array(16).fill(0),
|
||||
includeClassicAddress: true,
|
||||
test: true
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get the expected return value
|
||||
const response = Object.assign({}, responses.generateAddress, {
|
||||
xAddress: 'TVG3TcCD58BD6MZqsNuTihdrhZwR8SzvYS8U87zvHsAcNw4'
|
||||
})
|
||||
assert.deepEqual(account, response)
|
||||
},
|
||||
|
||||
'generateXAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async (
|
||||
client
|
||||
) => {
|
||||
// GIVEN we want to use 'ed25519' with entropy of zero
|
||||
const options: GenerateAddressOptions = {
|
||||
algorithm: ECDSA.ed25519,
|
||||
entropy: new Array(16).fill(0),
|
||||
includeClassicAddress: true,
|
||||
test: true
|
||||
}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get the expected return value
|
||||
assert.deepEqual(account, {
|
||||
xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo',
|
||||
secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE',
|
||||
classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7',
|
||||
address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7'
|
||||
})
|
||||
},
|
||||
|
||||
'generateXAddress for test network use': async (client) => {
|
||||
// GIVEN we want an X-address for test network use
|
||||
const options: GenerateAddressOptions = {test: true}
|
||||
|
||||
// WHEN generating an X-address
|
||||
const account = client.generateXAddress(options)
|
||||
|
||||
// THEN we get an object with xAddress starting with 'T' and a secret starting with 's'
|
||||
assert.deepEqual(
|
||||
account.xAddress.slice(0, 1),
|
||||
'T',
|
||||
'Test X-addresses start with T'
|
||||
)
|
||||
assert.deepEqual(
|
||||
account.secret.slice(0, 1),
|
||||
's',
|
||||
`Secret ${account.secret} must start with 's'`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import responses from '../../fixtures/responses'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import assert from 'assert-diff'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../../test/testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from 'assert-diff'
|
||||
import responses from '../../fixtures/responses'
|
||||
import requests from '../../fixtures/requests'
|
||||
import {TestSuite, assertResultMatch, assertRejects} from '../../utils'
|
||||
import {TestSuite, assertResultMatch, assertRejects} from '../../testUtils'
|
||||
// import BigNumber from 'bignumber.js'
|
||||
|
||||
// function checkSortingOfOrders(orders) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import { assertRejects, TestSuite } from '../../utils'
|
||||
import { assertRejects, TestSuite } from '../../testUtils'
|
||||
import requests from '../../fixtures/requests'
|
||||
// import responses from '../../fixtures/responses'
|
||||
import addresses from '../../fixtures/addresses.json'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import addresses from '../../fixtures/addresses.json'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const {getTrustlines: RESPONSE_FIXTURES} = responses
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
import addresses from '../../fixtures/addresses.json'
|
||||
|
||||
export default <TestSuite>{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
|
||||
export default <TestSuite>{
|
||||
'returns true for valid secret': async (client, address) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
export const config = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {TestSuite, assertRejects, assertResultMatch} from '../../utils'
|
||||
import {TestSuite, assertRejects, assertResultMatch} from '../../testUtils'
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {assertResultMatch, TestSuite, assertRejects} from '../../utils'
|
||||
import {assertResultMatch, TestSuite, assertRejects} from '../../testUtils'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import requests from '../../fixtures/requests'
|
||||
|
||||
@@ -2,7 +2,7 @@ import assert from 'assert-diff'
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
const {preparePaymentChannelClaim: REQUEST_FIXTURES} = requests
|
||||
const {preparePaymentChannelClaim: RESPONSE_FIXTURES} = responses
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
export const config = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ import assert from 'assert-diff'
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertResultMatch, TestSuite} from '../../testUtils'
|
||||
// import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
// import requests from '../../fixtures/requests'
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {ValidationError} from 'xrpl-local/common/errors'
|
||||
// import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {xrpToDrops, ISOTimeToRippleTime} from '../../../src/utils'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
export const config = {
|
||||
@@ -1188,7 +1189,7 @@ export default <TestSuite>{
|
||||
PublicKey:
|
||||
'32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A'
|
||||
// If cancelAfter is used, you must use RippleTime.
|
||||
// You can use `iso8601ToRippleTime()` to convert to RippleTime.
|
||||
// You can use `ISOTimeToRippleTime()` to convert to RippleTime.
|
||||
|
||||
// Other fields are available (but not used in this test),
|
||||
// including `sourceTag` and `destinationTag`.
|
||||
@@ -1207,12 +1208,12 @@ export default <TestSuite>{
|
||||
const txJSON = {
|
||||
Account: address,
|
||||
TransactionType: 'PaymentChannelCreate',
|
||||
Amount: client.xrpToDrops('1'), // or '1000000'
|
||||
Amount: xrpToDrops('1'), // or '1000000'
|
||||
Destination: 'rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW',
|
||||
SettleDelay: 86400,
|
||||
// Ensure this is in upper case if it is not already
|
||||
PublicKey: '32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A'.toUpperCase(),
|
||||
CancelAfter: client.iso8601ToRippleTime('2017-02-17T15:04:57Z'),
|
||||
CancelAfter: ISOTimeToRippleTime('2017-02-17T15:04:57Z'),
|
||||
SourceTag: 11747,
|
||||
DestinationTag: 23480
|
||||
}
|
||||
@@ -1236,7 +1237,7 @@ export default <TestSuite>{
|
||||
TransactionType: 'PaymentChannelFund',
|
||||
Channel:
|
||||
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
|
||||
Amount: client.xrpToDrops('1') // or '1000000'
|
||||
Amount: xrpToDrops('1') // or '1000000'
|
||||
}
|
||||
const response = await client.prepareTransaction(txJSON, localInstructions)
|
||||
assertResultMatch(
|
||||
@@ -1253,8 +1254,8 @@ export default <TestSuite>{
|
||||
TransactionType: 'PaymentChannelFund',
|
||||
Channel:
|
||||
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
|
||||
Amount: client.xrpToDrops('1'), // or '1000000'
|
||||
Expiration: client.iso8601ToRippleTime('2017-02-17T15:04:57Z')
|
||||
Amount: xrpToDrops('1'), // or '1000000'
|
||||
Expiration: ISOTimeToRippleTime('2017-02-17T15:04:57Z')
|
||||
}
|
||||
|
||||
const response = await client.prepareTransaction(txJSON)
|
||||
@@ -1300,8 +1301,8 @@ export default <TestSuite>{
|
||||
TransactionType: 'PaymentChannelClaim',
|
||||
Channel:
|
||||
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
|
||||
Balance: client.xrpToDrops('1'), // or '1000000'
|
||||
Amount: client.xrpToDrops('1'), // or '1000000'
|
||||
Balance: xrpToDrops('1'), // or '1000000'
|
||||
Amount: xrpToDrops('1'), // or '1000000'
|
||||
Signature:
|
||||
'30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA3CD7B9B',
|
||||
PublicKey:
|
||||
@@ -1330,8 +1331,8 @@ export default <TestSuite>{
|
||||
TransactionType: 'PaymentChannelClaim',
|
||||
Channel:
|
||||
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
|
||||
Balance: client.xrpToDrops('1'), // or 1000000
|
||||
Amount: client.xrpToDrops('1'), // or 1000000
|
||||
Balance: xrpToDrops('1'), // or 1000000
|
||||
Amount: xrpToDrops('1'), // or 1000000
|
||||
Signature:
|
||||
'30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA3CD7B9B',
|
||||
PublicKey:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../utils'
|
||||
import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {TestSuite, assertResultMatch} from '../../utils'
|
||||
import {TestSuite, assertResultMatch} from '../../testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert-diff'
|
||||
import {assertRejects, TestSuite} from '../../utils'
|
||||
import {assertRejects, TestSuite} from '../../testUtils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
|
||||
@@ -4,7 +4,7 @@ import binary from 'ripple-binary-codec'
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import rippled from '../../fixtures/rippled'
|
||||
import {TestSuite} from '../../utils'
|
||||
import {TestSuite} from '../../testUtils'
|
||||
|
||||
const {schemaValidator} = Client._PRIVATE
|
||||
const {sign: REQUEST_FIXTURES} = requests
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import {TestSuite, assertResultMatch} from '../../utils'
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
* - Check out the "TestSuite" type for documentation on the interface.
|
||||
* - Check out "test/client/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
signPaymentChannelClaim: async (client, address) => {
|
||||
const privateKey =
|
||||
'ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A'
|
||||
const result = client.signPaymentChannelClaim(
|
||||
requests.signPaymentChannelClaim.channel,
|
||||
requests.signPaymentChannelClaim.amount,
|
||||
privateKey
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.signPaymentChannelClaim,
|
||||
'signPaymentChannelClaim'
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
* - Check out the "TestSuite" type for documentation on the interface.
|
||||
* - Check out "test/client/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
'verifyPaymentChannelClaim': async (client, address) => {
|
||||
const publicKey =
|
||||
'02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8'
|
||||
const result = client.verifyPaymentChannelClaim(
|
||||
requests.signPaymentChannelClaim.channel,
|
||||
requests.signPaymentChannelClaim.amount,
|
||||
responses.signPaymentChannelClaim,
|
||||
publicKey
|
||||
)
|
||||
assertResultMatch(result, true, 'verifyPaymentChannelClaim')
|
||||
},
|
||||
|
||||
'verifyPaymentChannelClaim - invalid': async (client, address) => {
|
||||
const publicKey =
|
||||
'03A6523FE4281DA48A6FD77FAF3CB77F5C7001ABA0B32BCEDE0369AC009758D7D9'
|
||||
const result = client.verifyPaymentChannelClaim(
|
||||
requests.signPaymentChannelClaim.channel,
|
||||
requests.signPaymentChannelClaim.amount,
|
||||
responses.signPaymentChannelClaim,
|
||||
publicKey
|
||||
)
|
||||
assertResultMatch(result, false, 'verifyPaymentChannelClaim')
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import net from 'net'
|
||||
import assert from 'assert-diff'
|
||||
import setupClient from './setup-client'
|
||||
import {Client} from 'xrpl-local'
|
||||
import {ignoreWebSocketDisconnect} from './utils'
|
||||
import {ignoreWebSocketDisconnect} from './testUtils'
|
||||
const utils = Client._PRIVATE.ledgerUtils
|
||||
|
||||
const TIMEOUT = 200000 // how long before each test case times out
|
||||
|
||||
@@ -3,10 +3,11 @@ import assert from 'assert'
|
||||
import wallet from './wallet'
|
||||
import requests from '../fixtures/requests'
|
||||
import {Client} from 'xrpl-local'
|
||||
import {isValidClassicAddress} from 'ripple-address-codec'
|
||||
import {payTo, ledgerAccept} from './utils'
|
||||
import {errors} from 'xrpl-local/common'
|
||||
import {isValidSecret} from 'xrpl-local/common/utils'
|
||||
import {isValidSecret} from 'xrpl-local/utils'
|
||||
import { generateXAddress } from '../../src/utils/generateAddress'
|
||||
import { isValidXAddress } from 'ripple-address-codec'
|
||||
|
||||
// how long before each test case times out
|
||||
const TIMEOUT = 20000
|
||||
@@ -160,7 +161,7 @@ function setupAccounts(testcase) {
|
||||
|
||||
const promise = payTo(client, 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM')
|
||||
.then(() => payTo(client, wallet.getAddress()))
|
||||
.then(() => payTo(client, testcase.newWallet.address))
|
||||
.then(() => payTo(client, testcase.newWallet.xAddress))
|
||||
.then(() => payTo(client, 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc'))
|
||||
.then(() => payTo(client, 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q'))
|
||||
.then(() => {
|
||||
@@ -176,7 +177,7 @@ function setupAccounts(testcase) {
|
||||
.then(() =>
|
||||
makeTrustLine(
|
||||
testcase,
|
||||
testcase.newWallet.address,
|
||||
testcase.newWallet.xAddress,
|
||||
testcase.newWallet.secret
|
||||
)
|
||||
)
|
||||
@@ -197,7 +198,7 @@ function setupAccounts(testcase) {
|
||||
}
|
||||
return makeOrder(
|
||||
testcase.client,
|
||||
testcase.newWallet.address,
|
||||
testcase.newWallet.xAddress,
|
||||
orderSpecification,
|
||||
testcase.newWallet.secret
|
||||
)
|
||||
@@ -236,7 +237,7 @@ function suiteSetup(this: any) {
|
||||
setup
|
||||
.bind(this)(serverUrl)
|
||||
.then(() => ledgerAccept(this.client))
|
||||
.then(() => (this.newWallet = this.client.generateAddress()))
|
||||
.then(() => (this.newWallet = generateXAddress()))
|
||||
// two times to give time to server to send `ledgerClosed` event
|
||||
// so getLedgerVersion will return right value
|
||||
.then(() => ledgerAccept(this.client))
|
||||
@@ -501,9 +502,9 @@ describe('integration tests', function () {
|
||||
// })
|
||||
|
||||
it('generateWallet', function () {
|
||||
const newWallet = this.client.generateAddress()
|
||||
assert(newWallet && newWallet.address && newWallet.secret)
|
||||
assert(isValidClassicAddress(newWallet.address))
|
||||
const newWallet = generateXAddress()
|
||||
assert(newWallet && newWallet.xAddress && newWallet.secret)
|
||||
assert(isValidXAddress(newWallet.xAddress))
|
||||
assert(isValidSecret(newWallet.secret))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ import hashes from './fixtures/hashes.json'
|
||||
import transactionsResponse from './fixtures/rippled/account-tx'
|
||||
import accountLinesResponse from './fixtures/rippled/account-lines'
|
||||
import fullLedger from './fixtures/rippled/ledger-full-38129.json'
|
||||
import {getFreePort} from './utils'
|
||||
import {getFreePort} from './testUtils'
|
||||
import { Request } from '../src'
|
||||
|
||||
function isUSD(json) {
|
||||
|
||||
@@ -2,9 +2,10 @@ import assert from 'assert-diff'
|
||||
import _ from 'lodash'
|
||||
import {Client} from 'xrpl-local'
|
||||
import {RecursiveData} from 'xrpl-local/ledger/utils'
|
||||
import {assertRejects} from './utils'
|
||||
import {assertRejects} from './testUtils'
|
||||
import addresses from './fixtures/addresses.json'
|
||||
import setupClient from './setup-client'
|
||||
import {toRippledAmount} from '../src'
|
||||
|
||||
const {validate, schemaValidator, ledgerUtils} = Client._PRIVATE
|
||||
const address = addresses.ACCOUNT
|
||||
@@ -123,7 +124,7 @@ describe('Client', function () {
|
||||
|
||||
it('common utils - toRippledAmount', async () => {
|
||||
const amount = {issuer: 'is', currency: 'c', value: 'v'}
|
||||
assert.deepEqual(ledgerUtils.common.toRippledAmount(amount), {
|
||||
assert.deepEqual(toRippledAmount(amount), {
|
||||
issuer: 'is',
|
||||
currency: 'c',
|
||||
value: 'v'
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user