From 52935a46e86b1a591f714adbad5dd8476a968b38 Mon Sep 17 00:00:00 2001 From: Sai Kranthi Date: Mon, 26 Jun 2023 16:00:22 +0530 Subject: [PATCH] refactor(sdk): return xKey for taproot addresses in xverse wallet --- .../sdk/src/browser-wallets/xverse/addresses.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/browser-wallets/xverse/addresses.ts b/packages/sdk/src/browser-wallets/xverse/addresses.ts index d1e7c353..8d7129c9 100644 --- a/packages/sdk/src/browser-wallets/xverse/addresses.ts +++ b/packages/sdk/src/browser-wallets/xverse/addresses.ts @@ -1,6 +1,6 @@ import { AddressPurposes, getAddress } from "sats-connect"; -import { getAddressFormat } from "../../addresses"; +import { getAddressesFromPublicKey, getAddressFormat } from "../../addresses"; import { Network } from "../../config/types"; import { isXverseInstalled, XverseNetwork } from "./utils"; export async function getAddresses(options: XverseGetAddressOptions) { @@ -8,6 +8,7 @@ export async function getAddresses(options: XverseGetAddressOptions) { pub: string; address: string; format: string; + xKey?: string; }> = []; if (!isXverseInstalled()) { @@ -20,10 +21,19 @@ export async function getAddresses(options: XverseGetAddressOptions) { } response.addresses.forEach((addressObj) => { + const format = getAddressFormat(addressObj.address, network).format; + + let xKey; + if (format === "taproot") { + const userAddresses = getAddressesFromPublicKey(addressObj.publicKey, options.network, "p2tr"); + xKey = userAddresses[0].xkey; + } + result.push({ pub: addressObj.publicKey, address: addressObj.address, - format: getAddressFormat(addressObj.address, network).format + format, + xKey }); }); };