-
Notifications
You must be signed in to change notification settings - Fork 137
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
Turn on support for muxed addresses by default. #485
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.
I've added a few suggestions and highlighted one breaking change❗about the base fee.
Please feel free to merge when you think it's ready.
@marcelosalloum new requirements rolled in: We are not going to allow "opting out" of muxing support. Basically, the default for all of the Please take another look! There is ONE case in which the above (no opt-out) will not hold: function encodeMuxedAccountToAddress(muxedAccount, forceEd25519) {} The purpose of leaving it here is because sometimes you only want to extract the underlying |
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.
Really excited to see this happening, and I like that we're going with the unconditional support route.
I have some questions and concerns inline. In a few places it feels like this PR is doing multiple things such as refactoring areas of the code and fixing other unrelated issues/cleanup. It is possible they are all related and I don't see the connections. Could this PR be hyperfocused on the functional changes required for muxed address by default?
* | ||
* @returns {string} stringified G... (corresponding to the underlying pubkey) | ||
* or M... address (corresponding to both the key and the muxed ID) | ||
*/ | ||
export function encodeMuxedAccountToAddress(muxedAccount, supportMuxing) { | ||
export function encodeMuxedAccountToAddress(muxedAccount, forceEd25519) { |
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 keep the forceEd25519? This function is named encodedMuxedAccountToAddress
, and the only valid address for a muxed account is a M address. If someone wants to encode the base account of a muxed accounmt to a G address, they should probably call mux.baseAccount() and go from there?
Is this required for compatibility?
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.
It's a separation of concerns: these functions are for operating between xdr.MuxedAccount
<--> string
, and then there's also the higher-level MuxedAccount
object that implements the Account
interface.
I touched on this a bit above (#485 (comment)), but basically we need to be able to forceEd25519 when actually building a MuxedAccount
object from an M-address in order to get its composite G-address and ID.
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.
Ah I see. I still think we should follow a deconstruct and a construct approach, rather than a parameter that makes a construction behave differently. By deconstruct I mean get the base address/account id out of the xdr.MuxedAccount. We should probably have a function on MuxedAccount to do this if we don't already.
Let me know what I'm missing if I'm way off here.
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.
I wrote up an overly-verbose comment on the design decisions I was making and all of the abstraction layers we need to deal with (the TL;DR is that we have xdr.MuxedAccount
xdr.MuxedAccount
MuxedAccount
I've dropped the forceEd25519
flag and moved that subset of functionality to a new helper,
function extractBaseAddress(mAddress: string): string;
Does that help?
Thanks for your review, @leighmcculloch! The latest push should hyper-focus on the new muxing defaults delta. |
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.
Looks great 👏🏻.
One suggested doc change (💡), very minor. And one question about how a new function will be used in one scenario (❔).
if (!StrKey.isValidMed25519PublicKey(address)) { | ||
throw new TypeError('address should be a muxed account (M...)'); | ||
} |
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 there a way to test if an address is a muxed address before passing it to this function? I'm wondering about the flow where someone has a value that might be an M or a G and they want to get the G. If they call this function on its own it might error in the G cases. How do they distinguish? Do they just check the first character? Or maybe this function should just return the G if the input is a G. I don't feel strongly what way we go, but curious what the story is for this use case.
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.
Haha, I realize the line I'm commenting on literally has the function for testing if an address is a muxed address.
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.
I still wonder if there is value in not erroring in the case a G is passed and just returning the G. It might make the API a little easier to use, albeit with no errors in a case that might be error worthy.
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.
That's an interesting question. I can't foresee when it would come up, but I don't have a strong opinion either way.
Callers can use the StrKey
validators (isValidEd25519PublicKey
and isValidMed25519PublicKey
, just like is done here) before calling the function. I added a check in 9e1ee1f to just pass G-addresses through, for convenience.
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.
Hah, should have refreshed before replying 🥷. But yeah, added the pass-through.
see stellar/go#4164 for context