Skip to content

Commit

Permalink
XRPL Protocol = same BIP, normalise bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
WietseWind committed Apr 19, 2024
1 parent efb2c1a commit 55a322c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion libs/ledger-live-common/src/families/ripple/exchange.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { bip32asBuffer } from "../../crypto";
import { normalizeXrplProtocolPath } from "@ledgerhq/hw-app-xah";

const getSerializedAddressParameters = (
path: string,
): {
addressParameters: Buffer;
} => {
const addressParameters = bip32asBuffer(path);
const addressParameters = bip32asBuffer(normalizeXrplProtocolPath(path));
return {
addressParameters,
};
Expand Down
5 changes: 3 additions & 2 deletions libs/ledger-live-common/src/families/ripple/hw-getAddress.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Xrp from "@ledgerhq/hw-app-xrp";
import type { Resolver } from "../../hw/getAddress/types";
import { normalizeXrplProtocolPath } from "@ledgerhq/hw-app-xah";

const resolver: Resolver = async (transport, { path, verify, askChainCode }) => {
const xrp = new Xrp(transport);
const { address, publicKey, chainCode } = await xrp.getAddress(
path,
normalizeXrplProtocolPath(path),
verify,
askChainCode || false,
);
return {
path,
path: normalizeXrplProtocolPath(path),
address,
publicKey,
chainCode,
Expand Down
14 changes: 12 additions & 2 deletions libs/ledgerjs/packages/hw-app-xah/src/Xah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ import BIPPath from "bip32-path";
* .catch(e => console.log(`An error occurred (${e.message})`));
*/

/**
* normalize XRP Ledger Protocol address for non-mainnet.
*
* @param path a path in BIP 32 format, either XRPL or Xahau
* @return the same path in BIP 32 format, normalized to XRPL - XRPL Protocol chains use the same address
*/
export const normalizeXrplProtocolPath = (path: string) => {
return path.replace('21337', '144') // Xahau: treat like XRPL to match address
}

export default class Xah {
transport: Transport;

Expand Down Expand Up @@ -81,7 +91,7 @@ export default class Xah {
address: string;
chainCode?: string;
}> {
const bipPath = BIPPath.fromString(path).toPathArray();
const bipPath = BIPPath.fromString(normalizeXrplProtocolPath(path)).toPathArray();
const curveMask = ed25519 ? 0x80 : 0x40;
const cla = 0xe0;
const ins = 0x02;
Expand Down Expand Up @@ -128,7 +138,7 @@ export default class Xah {
* const signature = await xah.signTransaction("44'/144'/0'/0/0", "12000022800000002400000002614000000001315D3468400000000000000C73210324E5F600B52BB3D9246D49C4AB1722BA7F32B7A3E4F9F2B8A1A28B9118CC36C48114F31B152151B6F42C1D61FE4139D34B424C8647D183142ECFC1831F6E979C6DA907E88B1CAD602DB59E2F");
*/
async signTransaction(path: string, rawTxHex: string, ed25519?: boolean): Promise<string> {
const bipPath = BIPPath.fromString(path).toPathArray();
const bipPath = BIPPath.fromString(normalizeXrplProtocolPath(path)).toPathArray();
const rawTx = Buffer.from(rawTxHex, "hex");
const curveMask = ed25519 ? 0x80 : 0x40;
const apdus: {
Expand Down

0 comments on commit 55a322c

Please sign in to comment.