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

Turn on support for muxed addresses by default. #485

Merged
merged 37 commits into from
Jan 11, 2022
Merged

Turn on support for muxed addresses by default. #485

merged 37 commits into from
Jan 11, 2022

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Jan 6, 2022

see stellar/go#4164 for context

@Shaptic Shaptic requested review from marcelosalloum and a team January 6, 2022 07:59
Copy link
Contributor

@marcelosalloum marcelosalloum left a 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.

src/operation.js Outdated Show resolved Hide resolved
src/operations/account_merge.js Outdated Show resolved Hide resolved
src/operations/path_payment_strict_send.js Outdated Show resolved Hide resolved
src/transaction_builder.js Outdated Show resolved Hide resolved
src/transaction_builder.js Outdated Show resolved Hide resolved
test/unit/operation_test.js Outdated Show resolved Hide resolved
test/unit/operation_test.js Outdated Show resolved Hide resolved
test/unit/operation_test.js Outdated Show resolved Hide resolved
test/unit/operation_test.js Outdated Show resolved Hide resolved
@Shaptic
Copy link
Contributor Author

Shaptic commented Jan 10, 2022

@marcelosalloum new requirements rolled in: We are not going to allow "opting out" of muxing support. Basically, the default for all of the withMuxing, supportMuxing, etc. is now true and there's no way to pass false. The latest set of pushes will do this. I've resolved your comments that talk about the flags since they're just gone now.

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 G... address when you have an xdr.MuxedAccount option. Most notably, this is done by the MuxedAccount.fromAddress helper function. I was considering moving this specific functionality to a separate helper (e.g. encodeMuxedAccountAsEd25519) to separate it, but maybe that's excessive. Wdyt?

src/muxed_account.js Outdated Show resolved Hide resolved
Copy link
Member

@leighmcculloch leighmcculloch left a 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?

src/muxed_account.js Outdated Show resolved Hide resolved
src/muxed_account.js Outdated Show resolved Hide resolved
src/operation.js Outdated Show resolved Hide resolved
src/operations/clawback.js Show resolved Hide resolved
src/transaction_builder.js Outdated Show resolved Hide resolved
*
* @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) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@leighmcculloch leighmcculloch Jan 10, 2022

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.

Copy link
Contributor Author

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 ↔️ M-address, xdr.MuxedAccount ↔️ G-address, and MuxedAccount ↔️ M-address), but I think the latest commit explains all that is needed: 10f14a3.

I've dropped the forceEd25519 flag and moved that subset of functionality to a new helper,

function extractBaseAddress(mAddress: string): string;

Does that help?

@Shaptic
Copy link
Contributor Author

Shaptic commented Jan 10, 2022

Thanks for your review, @leighmcculloch! The latest push should hyper-focus on the new muxing defaults delta.

Copy link
Member

@leighmcculloch leighmcculloch left a 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 (❔).

src/util/decode_encode_muxed_account.js Outdated Show resolved Hide resolved
Comment on lines 79 to 81
if (!StrKey.isValidMed25519PublicKey(address)) {
throw new TypeError('address should be a muxed account (M...)');
}
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@Shaptic Shaptic merged commit 510fcd4 into master Jan 11, 2022
@Shaptic Shaptic deleted the muxed-on branch January 11, 2022 19:06
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.

3 participants