-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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
?
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, | ||
}, | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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, | ||
}; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
taprootAddresses: string[]; | ||
}; | ||
} | ||
export function getPsbtDetails({ inputs, indexesToSign, outputs, options }: GetPsbtDetailsArgs) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
No description provided.