Merge branch 'main' into amm

This commit is contained in:
Omar Khan
2022-11-16 13:55:34 -05:00
5 changed files with 43 additions and 4 deletions

View File

@@ -2,12 +2,17 @@
Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release.
## Unreleased
### Added
* Optional custom amount field to `fundWallet`.
### Changed
* Add support for Transaction objects in `verifyTransaction`
## 2.5.0 (2022-10-13)
### Added
* Support for ExpandedSignerList amendment that expands the maximum signer list to 32 entries.
* Add `cookie` and `data` to `ValidationStream` interface
* Addtional check for memos field format, provide more detailed error messages.
* Additional check for memos field format, provide more detailed error messages.
## 2.4.0 (2022-09-01)
### Added

View File

@@ -47,15 +47,18 @@ const MAX_ATTEMPTS = 20
* automatically. In other environments, or if you would like to customize the
* faucet host in devnet or testnet, you should provide the host using this
* option.
* @param options.amount - A custom amount to fund, if undefined or null, the default amount will be 1000.
* @returns A Wallet on the Testnet or Devnet that contains some amount of XRP,
* and that wallet's balance in XRP.
* @throws When either Client isn't connected or unable to fund wallet address.
*/
// eslint-disable-next-line max-lines-per-function -- this function needs to display and do with more information.
async function fundWallet(
this: Client,
wallet?: Wallet | null,
options?: {
faucetHost?: string
amount?: string
},
): Promise<{
wallet: Wallet
@@ -76,6 +79,7 @@ async function fundWallet(
new TextEncoder().encode(
JSON.stringify({
destination: walletToFund.classicAddress,
xrpAmount: options?.amount,
}),
),
)

View File

@@ -375,8 +375,11 @@ class Wallet {
* @param signedTransaction - A signed transaction (hex string of signTransaction result) to be verified offline.
* @returns Returns true if a signedTransaction is valid.
*/
public verifyTransaction(signedTransaction: string): boolean {
const tx = decode(signedTransaction)
public verifyTransaction(signedTransaction: Transaction | string): boolean {
const tx =
typeof signedTransaction === 'string'
? decode(signedTransaction)
: signedTransaction
const messageHex: string = encodeForSigning(tx)
const signature = tx.TxnSignature
return verify(messageHex, signature, this.publicKey)

View File

@@ -129,4 +129,21 @@ describe('fundWallet', function () {
await api.disconnect()
})
it('submit funds wallet with custom amount', async function () {
const api = new Client('wss://s.altnet.rippletest.net:51233')
await api.connect()
const { wallet, balance } = await api.fundWallet(null, { amount: '2000' })
assert.equal(balance, '2000')
assert.notEqual(wallet, undefined)
assert(isValidClassicAddress(wallet.classicAddress))
assert(isValidXAddress(wallet.getXAddress()))
const info = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(dropsToXrp(info.result.account_data.Balance), balance)
await api.disconnect()
})
})

View File

@@ -1,5 +1,5 @@
import { assert } from 'chai'
import { decode } from 'ripple-binary-codec/dist'
import { decode } from 'ripple-binary-codec'
import { NFTokenMint, Payment, Transaction } from 'xrpl-local'
import ECDSA from 'xrpl-local/ECDSA'
import Wallet from 'xrpl-local/Wallet'
@@ -949,6 +949,16 @@ describe('Wallet', function () {
assert.equal(isVerified, false)
})
it('returns true when verifying a deserialized Transaction object', function () {
const wallet = new Wallet(publicKey, privateKey)
const decodedTransaction = decode(
prepared.signedTransaction,
) as unknown as Transaction
const isVerified: boolean = wallet.verifyTransaction(decodedTransaction)
assert.equal(isVerified, true)
})
})
describe('getXAddress', function () {