Function PublicKey.fromString

static PublicKey fromString (
  scope const(char)[] str
) @trusted;

Parameters

NameDescription
str the string which should contain a public key

Returns

a Public key from Stellar's string representation

Throws

an Exception if the input string is not well-formed

Example

immutable address = `boa1xrv266cegdthdc87uche9zvj8842shz3sdyvw0qecpgeykyv4ynssuz4lg0`;
immutable uAddress = `bOA1xrv266cegdthdc87uche9zvj8842shz3SDYvw0qecpgeykyv4ynssuz4lg0`;
PublicKey pubkey = PublicKey.fromString(address);
PublicKey uPubkey = PublicKey.fromString(uAddress);
assert(pubkey.toString() == address);
assert(uPubkey == pubkey);
assert(uPubkey.toString() == address);
assertThrown(PublicKey.fromString(  // bad length
    "boa1xrv266cegdthdc87uche9zvj8842shz3sdyvw0qecpgeykyv4ynssuz4lg"));
assertThrown(PublicKey.fromString(  // bad version byte
    "boa1crv266cegdthdc87uche9zvj8842shz3sdyvw0qecpgeykyv4ynssuz4lg0"));

Example

import agora.crypto.Hash;

immutable address =
    `boa1xrra39xpg5q9zwhsq6u7pw508z2let6dj8r5lr4q0d0nff240fvd27yme3h`;
PublicKey pubkey = PublicKey.fromString(address);

() nothrow @safe @nogc
{
    auto hash = hashFull(pubkey);
    assert(hash != Hash.init);
}();

Example

PublicKey serialize & deserialize

testSymmetry!PublicKey();
testSymmetry(KeyPair.random().address);