Stellar PHP SDK API Documentation

StrKey
in package

StrKey is a helper class that allows encoding and decoding Stellar keys to/from strings, i.e. between their binary and string (i.e. "GABCD...", etc.) representations.

Tags
see
https://developers.stellar.org

Stellar developer docs Address types documentation

Table of Contents

Methods

accountIdFromPrivateKey()  : string
Derives the account ID from a private key
accountIdFromSeed()  : string
Derives the account ID from a secret seed
decodeAccountId()  : string
Decodes strkey account id (ed25519 public key) to raw data.
decodeClaimableBalanceId()  : string
Decodes strkey claimable balance id (B...) to raw data.
decodeClaimableBalanceIdHex()  : string
Decodes strkey claimable balance id (B...) to hex representation of it`s raw data
decodeContractId()  : string
Decodes strkey contract id (C...) to raw data.
decodeContractIdHex()  : string
Decodes strkey contract id (C...) to hex representation of it`s raw data
decodeLiquidityPoolId()  : string
Decodes strkey liquidity pool id (L...) to raw data.
decodeLiquidityPoolIdHex()  : string
Decodes strkey liquidity pool id (L...) to hex representation of it`s raw data
decodeMuxedAccountId()  : string
Decodes strkey muxed account id (med25519 public key) to raw data.
decodeMuxedContractId()  : string
Decodes a strkey muxed contract id ("W...", SEP-23, CAP-0084) to raw data.
decodePreAuthTx()  : string
Decodes strkey PreAuthTx ("T...") to raw data.
decodeSeed()  : string
Decodes strkey ed25519 seed ("S...") to raw data.
decodeSha256Hash()  : string
Decodes strkey sha256 hash ("X...") to raw data.
decodeSignedPayload()  : SignedPayloadSigner
Decodes strkey signed payload ("P...") to a SignedPayloadSigner object.
decodeXdrSignedPayload()  : XdrSignedPayload
Decodes strkey signed payload ("P...") to a XdrSignedPayload object.
encodeAccountId()  : string
Encodes `data` to strkey account id (ed25519 public key).
encodeClaimableBalanceId()  : string
Encodes raw data to strkey claimable balance id (B...).
encodeClaimableBalanceIdHex()  : string
Encodes hex representation of raw data claimable balance id to strkey claimable balance id (B...).
encodeContractId()  : string
Encodes raw data to strkey contract id (C...).
encodeContractIdHex()  : string
Encodes hex representation of raw data contract id to strkey contract id (C...).
encodeLiquidityPoolId()  : string
Encodes raw data to strkey liquidity pool id (L...).
encodeLiquidityPoolIdHex()  : string
Encodes hex representation of raw data liquidity pool id to strkey liquidity pool id (L...).
encodeMuxedAccountId()  : string
Encodes data to strkey muxed account id (med25519 public key).
encodeMuxedContractId()  : string
Encodes data to a strkey muxed contract id ("W...", SEP-23, CAP-0084).
encodePreAuthTx()  : string
Encodes data to strkey PreAuthTx ("T...").
encodeSeed()  : string
Encodes data to strkey ed25519 seed ("S...")
encodeSha256Hash()  : string
Encodes data to strkey sha256 hash ("X...").
encodeSignedPayload()  : string
Encodes a SignedPayloadSigner to strkey signed payload (P...).
encodeXdrSignedPayload()  : string
Encodes a XdrSignedPayload to strkey signed payload (P...).
isValidAccountId()  : bool
Returns true if the given Stellar account id ("G...") is a valid ed25519 public key.
isValidClaimableBalanceId()  : bool
Returns true if the given strkey representation of the claimable balance id ("B...") is a valid claimable balance id.
isValidContractId()  : bool
Returns true if the given strkey representation of the contract id ("C...") is a valid contract id.
isValidLiquidityPoolId()  : bool
Returns true if the given strkey representation of the liquidity pool id ("L...") is a valid liquidity pool id.
isValidMuxedAccountId()  : bool
Returns true if the given Stellar muxed account id ("M...") is a valid med25519 public key.
isValidMuxedContractId()  : bool
Returns true if the given string is a valid muxed contract id ("W...").
isValidPreAuthTx()  : bool
Returns true if the given strkey PreAuthTx ("T...") is a valid stellar PreAuthTx strkey representation.
isValidSeed()  : bool
Returns true if the given Stellar secret key ("S...") is a valid ed25519 secret seed.
isValidSha256Hash()  : bool
Returns true if the given strkey Sha256Hash ("X...") is a valid stellar Sha256Hash strkey representation.
isValidSignedPayload()  : bool
Returns true if the given strkey representation ("P...") is a valid signed payload: correct structure and checksum, a payload of 1 to 64 bytes, zero padding after the payload, and no data beyond that padding.
publicKeyFromPrivateKey()  : string
Derives the public key from a private key

Methods

accountIdFromPrivateKey()

Derives the account ID from a private key

public static accountIdFromPrivateKey(string $privateKey) : string
Parameters
$privateKey : string

The Ed25519 private key (32 bytes)

Return values
string —

The account ID in strkey format (G...)

accountIdFromSeed()

Derives the account ID from a secret seed

public static accountIdFromSeed(string $seed) : string
Parameters
$seed : string

The secret seed in strkey format (S...)

Return values
string —

The account ID in strkey format (G...)

decodeAccountId()

Decodes strkey account id (ed25519 public key) to raw data.

public static decodeAccountId(string $accountId) : string
Parameters
$accountId : string

"G..." key representation to decode

Tags
throws
InvalidArgumentException

when $accountId is not a valid "G..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

raw key

decodeClaimableBalanceId()

Decodes strkey claimable balance id (B...) to raw data.

public static decodeClaimableBalanceId(string $claimableBalanceId) : string
Parameters
$claimableBalanceId : string

claimable balance id (B...) to decode

Tags
throws
InvalidArgumentException

when $claimableBalanceId is not a valid "B..." strkey: wrong encoded length, wrong version byte, bad checksum, a payload that is not 33 bytes, or a discriminant byte that is not 0

Return values
string —

raw data

decodeClaimableBalanceIdHex()

Decodes strkey claimable balance id (B...) to hex representation of it`s raw data

public static decodeClaimableBalanceIdHex(string $claimableBalanceId) : string
Parameters
$claimableBalanceId : string

strkey claimable balance id (B...) to decode

Tags
throws
InvalidArgumentException

when $claimableBalanceId is not a valid "B..." strkey: wrong encoded length, wrong version byte, bad checksum, a payload that is not 33 bytes, or a discriminant byte that is not 0

Return values
string —

hex representation of the claimable balance id's raw data

decodeContractId()

Decodes strkey contract id (C...) to raw data.

public static decodeContractId(string $contractId) : string
Parameters
$contractId : string

strkey contract id (C...) to decode

Tags
throws
InvalidArgumentException

when $contractId is not a valid "C..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

raw data

decodeContractIdHex()

Decodes strkey contract id (C...) to hex representation of it`s raw data

public static decodeContractIdHex(string $contractId) : string
Parameters
$contractId : string

strkey contract id (C...) to decode

Tags
throws
InvalidArgumentException

when $contractId is not a valid "C..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

hex representation of the contract id's raw data

decodeLiquidityPoolId()

Decodes strkey liquidity pool id (L...) to raw data.

public static decodeLiquidityPoolId(string $liquidityPoolId) : string
Parameters
$liquidityPoolId : string

liquidity pool id (L...) to decode

Tags
throws
InvalidArgumentException

when $liquidityPoolId is not a valid "L..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

raw data

decodeLiquidityPoolIdHex()

Decodes strkey liquidity pool id (L...) to hex representation of it`s raw data

public static decodeLiquidityPoolIdHex(string $liquidityPoolId) : string
Parameters
$liquidityPoolId : string

strkey liquidity pool id (L...) to decode

Tags
throws
InvalidArgumentException

when $liquidityPoolId is not a valid "L..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

hex representation of the liquidity pool id's raw data

decodeMuxedAccountId()

Decodes strkey muxed account id (med25519 public key) to raw data.

public static decodeMuxedAccountId(string $muxedAccountId) : string
Parameters
$muxedAccountId : string

address data to decode ("M...")

Tags
throws
InvalidArgumentException

when $muxedAccountId is not a valid "M..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 40 bytes

Return values
string —

raw key

decodeMuxedContractId()

Decodes a strkey muxed contract id ("W...", SEP-23, CAP-0084) to raw data.

public static decodeMuxedContractId(string $muxedContractId) : string
Parameters
$muxedContractId : string

muxed contract id to decode ("W...")

Tags
throws
InvalidArgumentException

when $muxedContractId is not a valid "W..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 40 bytes

Return values
string —

the 32-byte contract id followed by the 8-byte big-endian multiplexing id

decodePreAuthTx()

Decodes strkey PreAuthTx ("T...") to raw data.

public static decodePreAuthTx(string $preAuth) : string
Parameters
$preAuth : string

PreAuthTx ("T...") to decode

Tags
throws
InvalidArgumentException

when $preAuth is not a valid "T..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

raw PreAuthTx data

decodeSeed()

Decodes strkey ed25519 seed ("S...") to raw data.

public static decodeSeed(string $seed) : string
Parameters
$seed : string

seed ("S...") to decode

Tags
throws
InvalidArgumentException

when $seed is not a valid "S..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

raw seed data

decodeSha256Hash()

Decodes strkey sha256 hash ("X...") to raw data.

public static decodeSha256Hash(string $hash) : string
Parameters
$hash : string

strkey sha256 hash ("X...") to decode

Tags
throws
InvalidArgumentException

when $hash is not a valid "X..." strkey: wrong encoded length, wrong version byte, bad checksum, or a payload that is not 32 bytes

Return values
string —

raw sha256 hash data.

decodeSignedPayload()

Decodes strkey signed payload ("P...") to a SignedPayloadSigner object.

public static decodeSignedPayload(string $signedPayload) : SignedPayloadSigner
Parameters
$signedPayload : string

signed payload ("P...") to decode

Tags
throws
InvalidArgumentException

when $signedPayload is not a valid "P..." strkey: an encoded length outside the SEP-23 bounds, a wrong version byte, a bad checksum, or a decoded payload that is empty, longer than 64 bytes, padded with a non-zero byte, or followed by data beyond its padding

Return values
SignedPayloadSigner —

object decoded from the given strkey signed payload

decodeXdrSignedPayload()

Decodes strkey signed payload ("P...") to a XdrSignedPayload object.

public static decodeXdrSignedPayload(string $signedPayload) : XdrSignedPayload
Parameters
$signedPayload : string

signed payload ("P...") to decode

Tags
throws
InvalidArgumentException

when $signedPayload is not a valid "P..." strkey: an encoded length outside the SEP-23 bounds, a wrong version byte, a bad checksum, or a decoded payload that is empty, longer than 64 bytes, padded with a non-zero byte, or followed by data beyond its padding

Return values
XdrSignedPayload —

object decoded from the given strkey signed payload

encodeAccountId()

Encodes `data` to strkey account id (ed25519 public key).

public static encodeAccountId(string $data) : string
Parameters
$data : string

raw data to encode

Tags
throws
InvalidArgumentException

when $data is not 32 bytes long

Return values
string —

"G..." representation of the key

encodeClaimableBalanceId()

Encodes raw data to strkey claimable balance id (B...).

public static encodeClaimableBalanceId(string $data) : string
Parameters
$data : string

raw data to encode: the 33-byte strkey payload led by the discriminant, the bare 32-byte balance hash, to which the zero discriminant is prepended, or the 36-byte XDR form, whose 4-byte big-endian discriminant is narrowed to the 1-byte strkey discriminant

Tags
throws
InvalidArgumentException

when $data has none of the accepted lengths, or when the discriminant it carries is not 0

Return values
string —

strkey claimable balance id (B...).

encodeClaimableBalanceIdHex()

Encodes hex representation of raw data claimable balance id to strkey claimable balance id (B...).

public static encodeClaimableBalanceIdHex(string $claimableBalanceId) : string
Parameters
$claimableBalanceId : string

hex representation of the claimable balance id: 66 characters (the 33-byte strkey payload), 64 characters (the bare balance hash), or 72 characters (the XDR form, as Horizon reports balance ids)

Tags
throws
InvalidArgumentException

when $claimableBalanceId is not hexadecimal, decodes to none of the accepted lengths, or carries a discriminant that is not 0

Return values
string —

strkey representation of the claimable balance id (B...).

encodeContractId()

Encodes raw data to strkey contract id (C...).

public static encodeContractId(string $data) : string
Parameters
$data : string

data to encode

Tags
throws
InvalidArgumentException

when $data is not 32 bytes long

Return values
string —

strkey contract id (C...).

encodeContractIdHex()

Encodes hex representation of raw data contract id to strkey contract id (C...).

public static encodeContractIdHex(string $contractId) : string
Parameters
$contractId : string

hex representation of raw data contract id

Tags
throws
InvalidArgumentException

when $contractId is not a hexadecimal string, or when it does not decode to 32 bytes, that is when it is not 64 hex characters long

Return values
string —

strkey representation of the contract id (C...).

encodeLiquidityPoolId()

Encodes raw data to strkey liquidity pool id (L...).

public static encodeLiquidityPoolId(string $data) : string
Parameters
$data : string

raw data to encode

Tags
throws
InvalidArgumentException

when $data is not 32 bytes long

Return values
string —

strkey liquidity pool id (L...).

encodeLiquidityPoolIdHex()

Encodes hex representation of raw data liquidity pool id to strkey liquidity pool id (L...).

public static encodeLiquidityPoolIdHex(string $liquidityPoolId) : string
Parameters
$liquidityPoolId : string

hex representation of raw data liquidity pool id

Tags
throws
InvalidArgumentException

when $liquidityPoolId is not a hexadecimal string, or when it does not decode to 32 bytes, that is when it is not 64 hex characters long

Return values
string —

strkey representation of the liquidity pool id (L...).

encodeMuxedAccountId()

Encodes data to strkey muxed account id (med25519 public key).

public static encodeMuxedAccountId(string $data) : string
Parameters
$data : string

data data to encode

Tags
throws
InvalidArgumentException

when $data is not 40 bytes long

Return values
string —

"M..." representation of the key

encodeMuxedContractId()

Encodes data to a strkey muxed contract id ("W...", SEP-23, CAP-0084).

public static encodeMuxedContractId(string $data) : string
Parameters
$data : string

the 32-byte contract id followed by the 8-byte big-endian multiplexing id, the reverse of the XDR MuxedContract field order

Tags
throws
InvalidArgumentException

when $data is not 40 bytes long

Return values
string —

"W..." representation of the muxed contract

encodePreAuthTx()

Encodes data to strkey PreAuthTx ("T...").

public static encodePreAuthTx(string $data) : string
Parameters
$data : string

data to encode

Tags
throws
InvalidArgumentException

when $data is not 32 bytes long

Return values
string —

"T..." representation of the PreAuthTx

encodeSeed()

Encodes data to strkey ed25519 seed ("S...")

public static encodeSeed(string $data) : string
Parameters
$data : string

data to encode

Tags
throws
InvalidArgumentException

when $data is not 32 bytes long

Return values
string —

"S..." representation of the seed

encodeSha256Hash()

Encodes data to strkey sha256 hash ("X...").

public static encodeSha256Hash(string $data) : string
Parameters
$data : string

data to encode

Tags
throws
InvalidArgumentException

when $data is not 32 bytes long

Return values
string —

"X..." representation of the sha256 hash

encodeSignedPayload()

Encodes a SignedPayloadSigner to strkey signed payload (P...).

public static encodeSignedPayload(SignedPayloadSigner $signedPayloadSigner) : string
Parameters
$signedPayloadSigner : SignedPayloadSigner

SignedPayloadSigner to encode

Tags
throws
InvalidArgumentException

when the payload is empty or longer than 64 bytes, or when the signer account id is not a valid "G..." strkey

Return values
string —

"P..." representation of the signed payload

encodeXdrSignedPayload()

Encodes a XdrSignedPayload to strkey signed payload (P...).

public static encodeXdrSignedPayload(XdrSignedPayload $signedPayload) : string
Parameters
$signedPayload : XdrSignedPayload

XdrSignedPayload to encode

Tags
throws
InvalidArgumentException

when the payload is empty or longer than 64 bytes

Return values
string —

"P..." representation of the signed payload

isValidAccountId()

Returns true if the given Stellar account id ("G...") is a valid ed25519 public key.

public static isValidAccountId(string $accountId) : bool
Parameters
$accountId : string

account id ("G...") to check

Return values
bool —

true if valid

isValidClaimableBalanceId()

Returns true if the given strkey representation of the claimable balance id ("B...") is a valid claimable balance id.

public static isValidClaimableBalanceId(string $claimableBalanceId) : bool
Parameters
$claimableBalanceId : string

the claimable balance id ("B...") to check.

Return values
bool —

true if valid: correct structure and checksum, a 33-byte payload, and a discriminant byte of 0

isValidContractId()

Returns true if the given strkey representation of the contract id ("C...") is a valid contract id.

public static isValidContractId(string $contractId) : bool
Parameters
$contractId : string

contract id ("C...") to check

Return values
bool —

true if valid contract id strkey representation.

isValidLiquidityPoolId()

Returns true if the given strkey representation of the liquidity pool id ("L...") is a valid liquidity pool id.

public static isValidLiquidityPoolId(string $liquidityPoolId) : bool
Parameters
$liquidityPoolId : string

the liquidity pool id ("L...") to check.

Return values
bool —

true if valid

isValidMuxedAccountId()

Returns true if the given Stellar muxed account id ("M...") is a valid med25519 public key.

public static isValidMuxedAccountId(string $muxedAccountId) : bool
Parameters
$muxedAccountId : string

muxed account id ("M...") to check

Return values
bool —

true if valid

isValidMuxedContractId()

Returns true if the given string is a valid muxed contract id ("W...").

public static isValidMuxedContractId(string $muxedContractId) : bool

A muxed contract id (SEP-23, CAP-0084) pairs a contract with a 64-bit multiplexing id, for example WA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAAAWWC.

Parameters
$muxedContractId : string

muxed contract id ("W...") to check

Return values
bool —

true if valid

isValidPreAuthTx()

Returns true if the given strkey PreAuthTx ("T...") is a valid stellar PreAuthTx strkey representation.

public static isValidPreAuthTx(string $preAuth) : bool
Parameters
$preAuth : string

strkey PreAuthTx ("T...") to check

Return values
bool —

true if valid stellar PreAuthTx strkey representation.

isValidSeed()

Returns true if the given Stellar secret key ("S...") is a valid ed25519 secret seed.

public static isValidSeed(string $seed) : bool
Parameters
$seed : string

seed to check ("S...")

Return values
bool —

true if valid

isValidSha256Hash()

Returns true if the given strkey Sha256Hash ("X...") is a valid stellar Sha256Hash strkey representation.

public static isValidSha256Hash(string $hash) : bool
Parameters
$hash : string

strkey Sha256Hash ("X...") to ckeck

Return values
bool —

true if valid stellar Sha256Hash strkey representation.

isValidSignedPayload()

Returns true if the given strkey representation ("P...") is a valid signed payload: correct structure and checksum, a payload of 1 to 64 bytes, zero padding after the payload, and no data beyond that padding.

public static isValidSignedPayload(string $signedPayload) : bool
Parameters
$signedPayload : string

signed payload ("P...") to check

Return values
bool —

true if valid signed payload strkey representation.

publicKeyFromPrivateKey()

Derives the public key from a private key

public static publicKeyFromPrivateKey(string $privateKey) : string
Parameters
$privateKey : string

The Ed25519 private key (32 bytes)

Tags
throws
Exception

If the private key is invalid or key derivation fails

Return values
string —

The corresponding Ed25519 public key (32 bytes)

On this page

Search results