mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-12 16:45:49 +00:00
docs: categorize utilities correctly (#1746)
* docs: categorize utilities correctly
This commit is contained in:
@@ -63,6 +63,8 @@ export interface PaymentChannelClaimFlagsInterface extends GlobalFlags {
|
|||||||
/**
|
/**
|
||||||
* Claim XRP from a payment channel, adjust the payment channel's expiration,
|
* Claim XRP from a payment channel, adjust the payment channel's expiration,
|
||||||
* or both.
|
* or both.
|
||||||
|
*
|
||||||
|
* @category Transaction Models
|
||||||
*/
|
*/
|
||||||
export interface PaymentChannelClaim extends BaseTransaction {
|
export interface PaymentChannelClaim extends BaseTransaction {
|
||||||
TransactionType: 'PaymentChannelClaim'
|
TransactionType: 'PaymentChannelClaim'
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ import { SignerListSet, validateSignerListSet } from './signerListSet'
|
|||||||
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
import { TicketCreate, validateTicketCreate } from './ticketCreate'
|
||||||
import { TrustSet, validateTrustSet } from './trustSet'
|
import { TrustSet, validateTrustSet } from './trustSet'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
export type Transaction =
|
export type Transaction =
|
||||||
| AccountDelete
|
| AccountDelete
|
||||||
| AccountSet
|
| AccountSet
|
||||||
@@ -58,6 +61,9 @@ export type Transaction =
|
|||||||
| TicketCreate
|
| TicketCreate
|
||||||
| TrustSet
|
| TrustSet
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category Transaction Models
|
||||||
|
*/
|
||||||
export interface TransactionAndMetadata {
|
export interface TransactionAndMetadata {
|
||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
metadata: TransactionMetadata
|
metadata: TransactionMetadata
|
||||||
@@ -69,6 +75,7 @@ export interface TransactionAndMetadata {
|
|||||||
*
|
*
|
||||||
* @param transaction - A Transaction.
|
* @param transaction - A Transaction.
|
||||||
* @throws ValidationError When the Transaction is malformed.
|
* @throws ValidationError When the Transaction is malformed.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function validate(transaction: Record<string, unknown>): void {
|
export function validate(transaction: Record<string, unknown>): void {
|
||||||
const tx = { ...transaction }
|
const tx = { ...transaction }
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ function getTrustlineQuantity(node: NormalizedNode): BalanceChange[] | null {
|
|||||||
*
|
*
|
||||||
* @param metadata - Transaction metada.
|
* @param metadata - Transaction metada.
|
||||||
* @returns Parsed balance changes.
|
* @returns Parsed balance changes.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export default function getBalanceChanges(
|
export default function getBalanceChanges(
|
||||||
metadata: TransactionMetadata,
|
metadata: TransactionMetadata,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface DeriveOptions {
|
|||||||
*
|
*
|
||||||
* @param options - Public key and destination tag to encode as an X-Address.
|
* @param options - Public key and destination tag to encode as an X-Address.
|
||||||
* @returns X-Address.
|
* @returns X-Address.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function deriveXAddress(options: DeriveOptions): string {
|
function deriveXAddress(options: DeriveOptions): string {
|
||||||
const classicAddress = deriveAddress(options.publicKey)
|
const classicAddress = deriveAddress(options.publicKey)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ function currencyToHex(currency: string): string {
|
|||||||
*
|
*
|
||||||
* @param txBlobHex - The binary transaction blob as a hexadecimal string.
|
* @param txBlobHex - The binary transaction blob as a hexadecimal string.
|
||||||
* @returns The hash to sign.
|
* @returns The hash to sign.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashTx(txBlobHex: string): string {
|
export function hashTx(txBlobHex: string): string {
|
||||||
const prefix = HashPrefix.TRANSACTION_SIGN.toString(HEX).toUpperCase()
|
const prefix = HashPrefix.TRANSACTION_SIGN.toString(HEX).toUpperCase()
|
||||||
@@ -65,6 +66,7 @@ export function hashTx(txBlobHex: string): string {
|
|||||||
*
|
*
|
||||||
* @param address - The classic account address.
|
* @param address - The classic account address.
|
||||||
* @returns The Ledger Object Index for the account.
|
* @returns The Ledger Object Index for the account.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashAccountRoot(address: string): string {
|
export function hashAccountRoot(address: string): string {
|
||||||
return sha512Half(ledgerSpaceHex('account') + addressToHex(address))
|
return sha512Half(ledgerSpaceHex('account') + addressToHex(address))
|
||||||
@@ -82,6 +84,7 @@ export function hashAccountRoot(address: string): string {
|
|||||||
*
|
*
|
||||||
* @param address - The classic account address of the SignerList owner (starting with r).
|
* @param address - The classic account address of the SignerList owner (starting with r).
|
||||||
* @returns The Index of the account's SignerList object.
|
* @returns The Index of the account's SignerList object.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashSignerListId(address: string): string {
|
export function hashSignerListId(address: string): string {
|
||||||
return sha512Half(
|
return sha512Half(
|
||||||
@@ -102,6 +105,7 @@ export function hashSignerListId(address: string): string {
|
|||||||
* @param address - The classic account address of the SignerList owner (starting with r).
|
* @param address - The classic account address of the SignerList owner (starting with r).
|
||||||
* @param sequence - Sequence of the Offer.
|
* @param sequence - Sequence of the Offer.
|
||||||
* @returns The Index of the account's Offer object.
|
* @returns The Index of the account's Offer object.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashOfferId(address: string, sequence: number): string {
|
export function hashOfferId(address: string, sequence: number): string {
|
||||||
const hexPrefix = ledgerSpaces.offer
|
const hexPrefix = ledgerSpaces.offer
|
||||||
@@ -120,6 +124,7 @@ export function hashOfferId(address: string, sequence: number): string {
|
|||||||
* @param address2 - The other address in the Trustline.
|
* @param address2 - The other address in the Trustline.
|
||||||
* @param currency - Currency in the Trustline.
|
* @param currency - Currency in the Trustline.
|
||||||
* @returns The hash of the Trustline.
|
* @returns The hash of the Trustline.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashTrustline(
|
export function hashTrustline(
|
||||||
address1: string,
|
address1: string,
|
||||||
@@ -147,6 +152,7 @@ export function hashTrustline(
|
|||||||
* @param address - Address of the Escrow.
|
* @param address - Address of the Escrow.
|
||||||
* @param sequence - OfferSequence of the Escrow.
|
* @param sequence - OfferSequence of the Escrow.
|
||||||
* @returns The hash of the Escrow LedgerEntry.
|
* @returns The hash of the Escrow LedgerEntry.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashEscrow(address: string, sequence: number): string {
|
export function hashEscrow(address: string, sequence: number): string {
|
||||||
return sha512Half(
|
return sha512Half(
|
||||||
@@ -163,6 +169,7 @@ export function hashEscrow(address: string, sequence: number): string {
|
|||||||
* @param dstAddress - Destination Account of the Payment Channel.
|
* @param dstAddress - Destination Account of the Payment Channel.
|
||||||
* @param sequence - Sequence number of the Transaction that created the Payment Channel.
|
* @param sequence - Sequence number of the Transaction that created the Payment Channel.
|
||||||
* @returns Hash of the Payment Channel.
|
* @returns Hash of the Payment Channel.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashPaymentChannel(
|
export function hashPaymentChannel(
|
||||||
address: string,
|
address: string,
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ function addLengthPrefix(hex: string): string {
|
|||||||
*
|
*
|
||||||
* @param tx - A transaction to hash. Tx may be in binary blob form. Tx must be signed.
|
* @param tx - A transaction to hash. Tx may be in binary blob form. Tx must be signed.
|
||||||
* @returns A hash of tx.
|
* @returns A hash of tx.
|
||||||
* @throws ValidationError if the Transaction is unsigned.
|
* @throws ValidationError if the Transaction is unsigned.\
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashSignedTx(tx: Transaction | string): string {
|
export function hashSignedTx(tx: Transaction | string): string {
|
||||||
let txBlob: string
|
let txBlob: string
|
||||||
@@ -96,6 +97,7 @@ export function hashSignedTx(tx: Transaction | string): string {
|
|||||||
*
|
*
|
||||||
* @param ledgerHeader - Ledger to compute the hash of.
|
* @param ledgerHeader - Ledger to compute the hash of.
|
||||||
* @returns The hash of the ledger.
|
* @returns The hash of the ledger.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashLedgerHeader(ledgerHeader: Ledger): string {
|
export function hashLedgerHeader(ledgerHeader: Ledger): string {
|
||||||
const prefix = HashPrefix.LEDGER.toString(HEX).toUpperCase()
|
const prefix = HashPrefix.LEDGER.toString(HEX).toUpperCase()
|
||||||
@@ -120,6 +122,7 @@ export function hashLedgerHeader(ledgerHeader: Ledger): string {
|
|||||||
*
|
*
|
||||||
* @param transactions - List of Transactions.
|
* @param transactions - List of Transactions.
|
||||||
* @returns The root hash of the SHAMap.
|
* @returns The root hash of the SHAMap.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashTxTree(
|
export function hashTxTree(
|
||||||
transactions: Array<Transaction & { metaData?: Metadata }>,
|
transactions: Array<Transaction & { metaData?: Metadata }>,
|
||||||
@@ -141,6 +144,7 @@ export function hashTxTree(
|
|||||||
*
|
*
|
||||||
* @param entries - List of LedgerEntries.
|
* @param entries - List of LedgerEntries.
|
||||||
* @returns Hash of SHAMap that consists of all entries.
|
* @returns Hash of SHAMap that consists of all entries.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function hashStateTree(entries: LedgerEntry[]): string {
|
export function hashStateTree(entries: LedgerEntry[]): string {
|
||||||
const shamap = new SHAMap()
|
const shamap = new SHAMap()
|
||||||
@@ -214,6 +218,7 @@ function computeStateHash(
|
|||||||
* @param ledger - Ledger to compute the hash for.
|
* @param ledger - Ledger to compute the hash for.
|
||||||
* @param options - Allow client to recompute Transaction and State Hashes.
|
* @param options - Allow client to recompute Transaction and State Hashes.
|
||||||
* @returns The has of ledger.
|
* @returns The has of ledger.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function hashLedger(
|
function hashLedger(
|
||||||
ledger: Ledger,
|
ledger: Ledger,
|
||||||
|
|||||||
@@ -14,8 +14,12 @@ import {
|
|||||||
isValidXAddress,
|
isValidXAddress,
|
||||||
xAddressToClassicAddress,
|
xAddressToClassicAddress,
|
||||||
} from 'ripple-address-codec'
|
} from 'ripple-address-codec'
|
||||||
|
import * as rbc from 'ripple-binary-codec'
|
||||||
|
|
||||||
|
import { LedgerEntry } from '../models/ledger'
|
||||||
import { Response } from '../models/methods'
|
import { Response } from '../models/methods'
|
||||||
|
import { PaymentChannelClaim } from '../models/transactions/paymentChannelClaim'
|
||||||
|
import { Transaction } from '../models/transactions/transaction'
|
||||||
|
|
||||||
import getBalanceChanges from './balanceChanges'
|
import getBalanceChanges from './balanceChanges'
|
||||||
import { deriveKeypair, deriveXAddress } from './derive'
|
import { deriveKeypair, deriveXAddress } from './derive'
|
||||||
@@ -67,12 +71,64 @@ function isValidSecret(secret: string): boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a LedgerEntry or Transaction into a hex string
|
||||||
|
*
|
||||||
|
* @param object - LedgerEntry or Transaction in JSON format.
|
||||||
|
* @returns A hex string representing the encoded object.
|
||||||
|
*/
|
||||||
|
function encode(object: Transaction | LedgerEntry): string {
|
||||||
|
return rbc.encode(object)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a Transaction for signing
|
||||||
|
*
|
||||||
|
* @param object - LedgerEntry in JSON or Transaction format.
|
||||||
|
* @returns A hex string representing the encoded object.
|
||||||
|
*/
|
||||||
|
function encodeForSigning(object: Transaction): string {
|
||||||
|
return rbc.encodeForSigning(object)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a PaymentChannelClaim for signing
|
||||||
|
*
|
||||||
|
* @param object - PaymentChannelClaim in JSON format.
|
||||||
|
* @returns A hex string representing the encoded object.
|
||||||
|
*/
|
||||||
|
function encodeForSigningClaim(object: PaymentChannelClaim): string {
|
||||||
|
return rbc.encodeForSigningClaim(object)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a Transaction for multi-signing
|
||||||
|
*
|
||||||
|
* @param object - Transaction in JSON format.
|
||||||
|
* @param signer - The address of the account signing this transaction
|
||||||
|
* @returns A hex string representing the encoded object.
|
||||||
|
*/
|
||||||
|
function encodeForMultiSigning(object: Transaction, signer: string): string {
|
||||||
|
return rbc.encodeForMultisigning(object, signer)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a hex string into a transaction | ledger entry
|
||||||
|
*
|
||||||
|
* @param hex - hex string in the XRPL serialization format.
|
||||||
|
* @returns The hex string decoded according to XRPL serialization format.
|
||||||
|
*/
|
||||||
|
function decode(hex: string): Record<string, unknown> {
|
||||||
|
return rbc.decode(hex)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates that a given address is a valid X-Address or a valid classic
|
* Validates that a given address is a valid X-Address or a valid classic
|
||||||
* address.
|
* address.
|
||||||
*
|
*
|
||||||
* @param address - Address to validate.
|
* @param address - Address to validate.
|
||||||
* @returns True if address is a valid X-Address or classic address.
|
* @returns True if address is a valid X-Address or classic address.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function isValidAddress(address: string): boolean {
|
function isValidAddress(address: string): boolean {
|
||||||
return isValidXAddress(address) || isValidClassicAddress(address)
|
return isValidXAddress(address) || isValidClassicAddress(address)
|
||||||
@@ -83,6 +139,7 @@ function isValidAddress(address: string): boolean {
|
|||||||
*
|
*
|
||||||
* @param string - The string to convert to Hex.
|
* @param string - The string to convert to Hex.
|
||||||
* @returns The Hex equivalent of the string.
|
* @returns The Hex equivalent of the string.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function convertStringToHex(string: string): string {
|
function convertStringToHex(string: string): string {
|
||||||
return Buffer.from(string, 'utf8').toString('hex').toUpperCase()
|
return Buffer.from(string, 'utf8').toString('hex').toUpperCase()
|
||||||
@@ -98,12 +155,16 @@ function convertStringToHex(string: string): string {
|
|||||||
*
|
*
|
||||||
* @param response - Response to check for more pages on.
|
* @param response - Response to check for more pages on.
|
||||||
* @returns Whether the response has more pages of data.
|
* @returns Whether the response has more pages of data.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function hasNextPage(response: Response): boolean {
|
function hasNextPage(response: Response): boolean {
|
||||||
// eslint-disable-next-line @typescript-eslint/dot-notation -- only checking if it exists
|
// eslint-disable-next-line @typescript-eslint/dot-notation -- only checking if it exists
|
||||||
return Boolean(response.result['marker'])
|
return Boolean(response.result['marker'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category Utilities
|
||||||
|
*/
|
||||||
const hashes = {
|
const hashes = {
|
||||||
hashSignedTx,
|
hashSignedTx,
|
||||||
hashTx,
|
hashTx,
|
||||||
@@ -156,4 +217,9 @@ export {
|
|||||||
decodeAccountPublic,
|
decodeAccountPublic,
|
||||||
encodeXAddress,
|
encodeXAddress,
|
||||||
decodeXAddress,
|
decodeXAddress,
|
||||||
|
encode,
|
||||||
|
decode,
|
||||||
|
encodeForMultiSigning,
|
||||||
|
encodeForSigning,
|
||||||
|
encodeForSigningClaim,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ function percentToDecimal(percent: string): string {
|
|||||||
* @returns A number in the "billionths" format.
|
* @returns A number in the "billionths" format.
|
||||||
* @throws ValidationError when the parameter is not convertible to
|
* @throws ValidationError when the parameter is not convertible to
|
||||||
* "billionths" format.
|
* "billionths" format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function decimalToTransferRate(decimal: string): number {
|
export function decimalToTransferRate(decimal: string): number {
|
||||||
const rate = new BigNumber(decimal).times(ONE_BILLION).plus(ONE_BILLION)
|
const rate = new BigNumber(decimal).times(ONE_BILLION).plus(ONE_BILLION)
|
||||||
@@ -59,6 +60,7 @@ export function decimalToTransferRate(decimal: string): number {
|
|||||||
* @returns A number in the "billionths" format.
|
* @returns A number in the "billionths" format.
|
||||||
* @throws ValidationError when the percent parameter is not convertible to
|
* @throws ValidationError when the percent parameter is not convertible to
|
||||||
* "billionths" format.
|
* "billionths" format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function percentToTransferRate(percent: string): number {
|
export function percentToTransferRate(percent: string): number {
|
||||||
return decimalToTransferRate(percentToDecimal(percent))
|
return decimalToTransferRate(percentToDecimal(percent))
|
||||||
@@ -72,6 +74,7 @@ export function percentToTransferRate(percent: string): number {
|
|||||||
* @returns A number in the "billionths" format.
|
* @returns A number in the "billionths" format.
|
||||||
* @throws ValidationError when the parameter is not convertible to
|
* @throws ValidationError when the parameter is not convertible to
|
||||||
* "billionths" format.
|
* "billionths" format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function decimalToQuality(decimal: string): number {
|
export function decimalToQuality(decimal: string): number {
|
||||||
const rate = new BigNumber(decimal).times(ONE_BILLION)
|
const rate = new BigNumber(decimal).times(ONE_BILLION)
|
||||||
@@ -103,6 +106,7 @@ export function decimalToQuality(decimal: string): number {
|
|||||||
* @param quality - Quality to convert to decimal.
|
* @param quality - Quality to convert to decimal.
|
||||||
* @returns decimal representation of quality.
|
* @returns decimal representation of quality.
|
||||||
* @throws ValidationError when quality is not convertible to decimal format.
|
* @throws ValidationError when quality is not convertible to decimal format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function qualityToDecimal(quality: number): string {
|
export function qualityToDecimal(quality: number): string {
|
||||||
if (!Number.isInteger(quality)) {
|
if (!Number.isInteger(quality)) {
|
||||||
@@ -127,7 +131,8 @@ export function qualityToDecimal(quality: number): string {
|
|||||||
*
|
*
|
||||||
* @param rate - TransferRate to convert to decimal.
|
* @param rate - TransferRate to convert to decimal.
|
||||||
* @returns decimal representation of transfer Rate.
|
* @returns decimal representation of transfer Rate.
|
||||||
* @throws ValidationError when it cannot convert from billionths format
|
* @throws ValidationError when it cannot convert from billionths format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function transferRateToDecimal(rate: number): string {
|
export function transferRateToDecimal(rate: number): string {
|
||||||
if (!Number.isInteger(rate)) {
|
if (!Number.isInteger(rate)) {
|
||||||
@@ -157,6 +162,7 @@ export function transferRateToDecimal(rate: number): string {
|
|||||||
* @returns A number in the "billionths" format.
|
* @returns A number in the "billionths" format.
|
||||||
* @throws ValidationError when the percent parameter is not convertible to
|
* @throws ValidationError when the percent parameter is not convertible to
|
||||||
* "billionths" format.
|
* "billionths" format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function percentToQuality(percent: string): number {
|
export function percentToQuality(percent: string): number {
|
||||||
return decimalToQuality(percentToDecimal(percent))
|
return decimalToQuality(percentToDecimal(percent))
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { xrpToDrops } from './xrpConversion'
|
|||||||
* @param amount - Amount specified by the paymentChannelClaim.
|
* @param amount - Amount specified by the paymentChannelClaim.
|
||||||
* @param privateKey - Private Key to sign paymentChannelClaim with.
|
* @param privateKey - Private Key to sign paymentChannelClaim with.
|
||||||
* @returns True if the channel is valid.
|
* @returns True if the channel is valid.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function signPaymentChannelClaim(
|
function signPaymentChannelClaim(
|
||||||
channel: string,
|
channel: string,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const RIPPLE_EPOCH_DIFF = 0x386d4380
|
|||||||
*
|
*
|
||||||
* @param rpepoch - (seconds since 1/1/2000 GMT).
|
* @param rpepoch - (seconds since 1/1/2000 GMT).
|
||||||
* @returns Milliseconds since unix epoch.
|
* @returns Milliseconds since unix epoch.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function rippleTimeToUnixTime(rpepoch: number): number {
|
function rippleTimeToUnixTime(rpepoch: number): number {
|
||||||
return (rpepoch + RIPPLE_EPOCH_DIFF) * 1000
|
return (rpepoch + RIPPLE_EPOCH_DIFF) * 1000
|
||||||
@@ -15,6 +16,7 @@ function rippleTimeToUnixTime(rpepoch: number): number {
|
|||||||
*
|
*
|
||||||
* @param timestamp - (ms since unix epoch).
|
* @param timestamp - (ms since unix epoch).
|
||||||
* @returns Seconds since Ripple Epoch (1/1/2000 GMT).
|
* @returns Seconds since Ripple Epoch (1/1/2000 GMT).
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function unixTimeToRippleTime(timestamp: number): number {
|
function unixTimeToRippleTime(timestamp: number): number {
|
||||||
return Math.round(timestamp / 1000) - RIPPLE_EPOCH_DIFF
|
return Math.round(timestamp / 1000) - RIPPLE_EPOCH_DIFF
|
||||||
@@ -25,6 +27,7 @@ function unixTimeToRippleTime(timestamp: number): number {
|
|||||||
*
|
*
|
||||||
* @param rippleTime - Is the number of seconds since Ripple Epoch (1/1/2000 GMT).
|
* @param rippleTime - Is the number of seconds since Ripple Epoch (1/1/2000 GMT).
|
||||||
* @returns Iso8601 international standard date format.
|
* @returns Iso8601 international standard date format.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function rippleTimeToISOTime(rippleTime: number): string {
|
function rippleTimeToISOTime(rippleTime: number): string {
|
||||||
return new Date(rippleTimeToUnixTime(rippleTime)).toISOString()
|
return new Date(rippleTimeToUnixTime(rippleTime)).toISOString()
|
||||||
@@ -35,6 +38,7 @@ function rippleTimeToISOTime(rippleTime: number): string {
|
|||||||
*
|
*
|
||||||
* @param iso8601 - International standard date format.
|
* @param iso8601 - International standard date format.
|
||||||
* @returns Seconds since ripple epoch (1/1/2000 GMT).
|
* @returns Seconds since ripple epoch (1/1/2000 GMT).
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function ISOTimeToRippleTime(iso8601: string): number {
|
function ISOTimeToRippleTime(iso8601: string): number {
|
||||||
return unixTimeToRippleTime(Date.parse(iso8601))
|
return unixTimeToRippleTime(Date.parse(iso8601))
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { xrpToDrops } from './xrpConversion'
|
|||||||
* @param signature - Signature produced from signing paymentChannelClaim.
|
* @param signature - Signature produced from signing paymentChannelClaim.
|
||||||
* @param publicKey - Public key that signed the paymentChannelClaim.
|
* @param publicKey - Public key that signed the paymentChannelClaim.
|
||||||
* @returns True if the channel is valid.
|
* @returns True if the channel is valid.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line max-params -- Needs 4 params
|
// eslint-disable-next-line max-params -- Needs 4 params
|
||||||
function verifyPaymentChannelClaim(
|
function verifyPaymentChannelClaim(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const SANITY_CHECK = /^-?[0-9.]+$/u
|
|||||||
* @param dropsToConvert - Drops to convert to XRP.
|
* @param dropsToConvert - Drops to convert to XRP.
|
||||||
* @returns Amount in XRP.
|
* @returns Amount in XRP.
|
||||||
* @throws When drops amount is invalid.
|
* @throws When drops amount is invalid.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function dropsToXrp(dropsToConvert: BigNumber.Value): string {
|
export function dropsToXrp(dropsToConvert: BigNumber.Value): string {
|
||||||
/*
|
/*
|
||||||
@@ -58,6 +59,7 @@ export function dropsToXrp(dropsToConvert: BigNumber.Value): string {
|
|||||||
* @param xrpToConvert - Amount in XRP.
|
* @param xrpToConvert - Amount in XRP.
|
||||||
* @returns Amount in drops.
|
* @returns Amount in drops.
|
||||||
* @throws When amount in xrp is invalid.
|
* @throws When amount in xrp is invalid.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
export function xrpToDrops(xrpToConvert: BigNumber.Value): string {
|
export function xrpToDrops(xrpToConvert: BigNumber.Value): string {
|
||||||
// Important: specify base BASE_TEN to avoid exponential notation, e.g. '1e-7'.
|
// Important: specify base BASE_TEN to avoid exponential notation, e.g. '1e-7'.
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ interface FromMnemonicOptions extends WalletBaseOptions {
|
|||||||
* // }
|
* // }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @category Offline Signing
|
* @category Signing
|
||||||
*/
|
*/
|
||||||
class Wallet {
|
class Wallet {
|
||||||
public readonly publicKey: string
|
public readonly publicKey: string
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import Wallet from '.'
|
|||||||
* - There were no transactions given to sign
|
* - There were no transactions given to sign
|
||||||
* - The SigningPubKey field is not the empty string in any given transaction
|
* - The SigningPubKey field is not the empty string in any given transaction
|
||||||
* - Any transaction is missing a Signers field.
|
* - Any transaction is missing a Signers field.
|
||||||
|
* @category Signing
|
||||||
*/
|
*/
|
||||||
function multisign(transactions: Array<Transaction | string>): string {
|
function multisign(transactions: Array<Transaction | string>): string {
|
||||||
if (transactions.length === 0) {
|
if (transactions.length === 0) {
|
||||||
@@ -70,6 +71,7 @@ function multisign(transactions: Array<Transaction | string>): string {
|
|||||||
* @param channelId - An id for the payment channel to redeem XRP from.
|
* @param channelId - An id for the payment channel to redeem XRP from.
|
||||||
* @param amount - The amount in drops to redeem.
|
* @param amount - The amount in drops to redeem.
|
||||||
* @returns A signature that can be used to redeem a specific amount of XRP from a payment channel.
|
* @returns A signature that can be used to redeem a specific amount of XRP from a payment channel.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function authorizeChannel(
|
function authorizeChannel(
|
||||||
wallet: Wallet,
|
wallet: Wallet,
|
||||||
@@ -89,6 +91,7 @@ function authorizeChannel(
|
|||||||
*
|
*
|
||||||
* @param tx - A transaction to verify the signature of. (Can be in object or encoded string format).
|
* @param tx - A transaction to verify the signature of. (Can be in object or encoded string format).
|
||||||
* @returns Returns true if tx has a valid signature, and returns false otherwise.
|
* @returns Returns true if tx has a valid signature, and returns false otherwise.
|
||||||
|
* @category Utilities
|
||||||
*/
|
*/
|
||||||
function verifySignature(tx: Transaction | string): boolean {
|
function verifySignature(tx: Transaction | string): boolean {
|
||||||
const decodedTx: Transaction = getDecodedTransaction(tx)
|
const decodedTx: Transaction = getDecodedTransaction(tx)
|
||||||
|
|||||||
@@ -4,13 +4,14 @@
|
|||||||
"categoryOrder": [
|
"categoryOrder": [
|
||||||
"Constructor",
|
"Constructor",
|
||||||
"Clients",
|
"Clients",
|
||||||
|
"Signing",
|
||||||
"Transaction Models",
|
"Transaction Models",
|
||||||
"Transaction Flags",
|
"Transaction Flags",
|
||||||
"Ledger Flags",
|
"Ledger Flags",
|
||||||
"Utilities",
|
"Utilities",
|
||||||
"Requests",
|
"Requests",
|
||||||
"Responses",
|
"Responses",
|
||||||
"Flags",
|
"Streams",
|
||||||
"Errors"
|
"Errors"
|
||||||
],
|
],
|
||||||
"categorizeByGroup": false
|
"categorizeByGroup": false
|
||||||
|
|||||||
Reference in New Issue
Block a user