WietseWind / xrpl-accountlib

XRPL Account helper: generation, derivation and signing (family seed, mnemonic, passphrase)
MIT License
27 stars 12 forks source link

XRP asset is not correctly encoded on XAHAU #313

Closed tadejgolobic closed 1 year ago

tadejgolobic commented 1 year ago

When you are on non-xrp native ledger / sidechain, XRP currency is encoded as 00000...00. However, 0000...00 represents native currency (on Xahau network, that is XAH) adn thus transaction fails.

Imagine following scenario

{
    "TransactionType": "TrustSet",
    "Account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX",
    "LimitAmount": {
      "currency": "XRP",
      "issuer": "rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc",
      "value": "100"
    },
}

on Xahau chain, this will actually try to make trustline to above issuer for currency XAH. In order to create / use XRP in IOU way, you need to manually specify a long 40 nibble currency code with 'X' 'R' 'P' (0000000000000000000000005852500000000000) and then it is working.

I am also attaching binary visualizer of one of my trustset transaction (it is not the above transaction). Note the currency code, even though XRP was specified as currency. image

WietseWind commented 1 year ago

Good point!

Challenge. That's actually part of the ripple-binary-codec. Going to dive in and add something to make this a config option on xrpl-accountlib construction.

tadejgolobic commented 1 year ago

Yes, the perfect way to implement this would be probably in ripple-binary-codec however, that can probably take some time. This is why I opened issue here.

Not really sure what would be the best way to implement this in this library. I used it for signing transaction offline, and then copying transaction blob to online computer and submitting transaction there. This was my use case if it helps :)

WietseWind commented 1 year ago

@tadejgolobic Implemented and added to our custom repo used by xrpl-accountlib

  1. Fix in binary codec: https://github.com/XRPLF/xrpl.js/commit/94ad22162d39a8badf56a5d7beb634b1f96eef51
  2. Implementation in accountlib

This is now published in xrpl-accountlib@3.0.0 - https://www.npmjs.com/package/xrpl-accountlib/v/3.0.0

🎉

This implementation automatically determines the native asset and right encoding based on the NetworkID.

So: if you would try your TX again without NetworkID, it assumes default & XRP as native asset.

If you try your TX again with NetworkID 21337 or 21338 (Xahau mainnet & testnet) it will automatically use XAH as native asset and use a regular IOU XRP for XRP.