Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add psbt functionality #641

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

feat: add psbt functionality #641

wants to merge 2 commits into from

Conversation

edgarkhanzadian
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @edgarkhanzadian, just dropping some comments in here. Main thoughts is that I think it isn't necessary to pass around addresses the way being done here.

import { Approver, ArrowLeftIcon, Box, Button, Text, Theme } from '@leather.io/ui/native';

export function SignPsbt() {
const theme = useTheme<Theme>();
const psbt = new btc.Transaction();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As on the extension, could we use a more action-based name for this component like PsbtSigner?

Comment on lines +58 to +77
psbt.addInput({
txid: 'c5fcf6fc646c33a49e4a0772a351a8ce942e7caf04aafc689eb599ca9c8f57d0',
index: 0,
tapInternalKey: taprootPayer.payment.tapInternalKey,
tapBip32Derivation: [payerToTapBip32Derivation(taprootPayer)],
witnessUtxo: {
script: taprootPayer.payment.script,
amount: 20000n,
},
});
psbt.addInput({
txid: 'c5fcf6fc646c33a49e4a0772a351a8ce942e7caf04aafc689eb599ca9c8f57d1',
index: 1,
tapInternalKey: taprootPayer2.payment.tapInternalKey,
tapBip32Derivation: [payerToTapBip32Derivation(taprootPayer2)],
witnessUtxo: {
script: taprootPayer2.payment.script,
amount: 100500n,
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though some of this is demo code, can we pass in the psbt from outside the component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap it's going to be passed as psbtHex

Comment on lines +116 to +143
export function useBitcoinPayerAddresses() {
const bitcoinAccounts = useBitcoinAccounts();
const taprootAddresses = useMemo(
() =>
bitcoinAccounts.list
.filter(isTaprootAccount)
.map(acc => acc.derivePayer({ addressIndex: 0 }).address),
[bitcoinAccounts]
);
const nativeSegwitAddresses = useMemo(
() =>
bitcoinAccounts.list
.filter(isNativeSegwitAccount)
.map(acc => acc.derivePayer({ addressIndex: 0 }).address),
[bitcoinAccounts]
);

const allAddresses = useMemo(
() => [...taprootAddresses, ...nativeSegwitAddresses],
[taprootAddresses, nativeSegwitAddresses]
);

return {
taprootAddresses,
nativeSegwitAddresses,
allAddresses,
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed when using the BIP32_DERIVATION to read the details? Why do we need the addresses?

I kind feel like we should stick to the Payer object and just read address as and when needed, rather than first creating a big list of addresses. What if we need to access another property of the payer later?

Also, what if some is trying to sign on non-zero index?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point, we won't need this anymore as we would use the psbt defined derivation path

packages/bitcoin/src/psbt/psbt-details.ts Show resolved Hide resolved
taprootAddresses: string[];
};
}
export function getPsbtDetails({ inputs, indexesToSign, outputs, options }: GetPsbtDetailsArgs) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass the psbt itself to this fn?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that would give a better api to this function for sure

inputs: TransactionInput[];
indexesToSign?: number[];
options: {
network: NetworkConfiguration;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to pass the whole network config, versus a more scoped parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm probably not, i'll check now

export function getPsbtInscriptions({
psbtInputs,
psbtOutputs,
options: { nativeSegwitAddress, taprootAddress },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these the addresses of? Why do we pass them in separately?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well on extension those were used as useCurrentNativeSegwitAddress, when moving it to a function i had to change it to a function parameter. I've commented out the inscription part because it is not a part of the release so i was thinking we could finish it up later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants