Skip to content

Commit

Permalink
refactor(sdk): return xKey for taproot addresses in xverse wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
kranthicodes committed Jun 26, 2023
1 parent f7c5d34 commit 52935a4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/sdk/src/browser-wallets/xverse/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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) {
const result: Array<{
pub: string;
address: string;
format: string;
xKey?: string;
}> = [];

if (!isXverseInstalled()) {
Expand All @@ -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
});
});
};
Expand Down

0 comments on commit 52935a4

Please sign in to comment.