4

In another question How do I work with SS58 encoded addresses? the same question was addressed, this is however about how to do it without the std lib.

How to convert an ss58 stored in a String to an AccountId32 or [u8;32]

When running in rich environment, it is easy to convert from ss58 format to AccountId32 using:

use sp_core::{crypto::AccountId32, sp_std};


let a:AccountId32 = sp_std::str::FromStr::from_str(&s);

But checking the source code in sp-core-20.0.0/src/crypto.rs I can see the FromStr trait is guarded by a feature flag #[cfg(feature = "std")] and defined only when compiled in std.

It would of course be possible for me to clone and duplicate this code for core but is there a better way to run this conversion in a no_std environment?

Edit: There is a similar question Is there any way to convert an ss58 address to the 32 bytes pubkey? but the answers is all about running in a shell which is not what I'm asking for

7
  • Does this answer your question? Is there any way to convert an ss58 address to the 32 bytes pubkey? Apr 19 at 2:26
  • No answer yet, but duplicated. Apr 19 at 2:28
  • The question asks the same thing but I think my question is better phrased and more likely to be helpful in the future. Also as you point out there are no answers to it
    – Simson
    Apr 19 at 3:43
  • Yep. But I hope we can close one. (maybe that one) Apr 19 at 4:13
  • 1
    I believe this is not possible. And most probably this is intended to discourage passing ss58-encoded addresses to the runtime. The recommended way of passing data is with scale codec, not any string-based serialization. Apr 20 at 9:33

1 Answer 1

0

I had the same challenge, but could not find a way. At the end I listed my addresses as [u8;32] but using hex-literalfor some ergonomic, and had a [std] test asserting the list against the same list of address in ss58 format.

1
  • This does not answer my question but it solves the problem. Accepted and upvoted.
    – Simson
    May 12 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.