SorobanCredentials
in package
Credentials for Soroban authorization.
Represents one of four credential arms:
- SOURCE_ACCOUNT: uses the transaction source account; no address credentials.
- ADDRESS (legacy): address credentials without an address-bound preimage.
- ADDRESS_V2 (Protocol 27, CAP-71): address credentials with an address-bound preimage (ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS). Opt-in; invalid on pre-27 networks.
- ADDRESS_WITH_DELEGATES (Protocol 27, CAP-71): ADDRESS_V2 with a recursive delegate tree. Opt-in; invalid on pre-27 networks.
The property $addressCredentials carries the inner SorobanAddressCredentials for the ADDRESS and ADDRESS_V2 arms. For ADDRESS_WITH_DELEGATES, $addressWithDelegates carries the full credentials-plus-delegates payload; $addressCredentials is null in that arm.
Legacy behavior is preserved: the default arm is ADDRESS when address credentials are set; existing callers that only use forSourceAccount() / forAddressCredentials() are unaffected.
Tags
Table of Contents
Properties
- $addressCredentials : SorobanAddressCredentials|null
- $addressWithDelegates : SorobanAddressCredentialsWithDelegates|null
- $credentialType : int
Methods
- __construct() : mixed
- Creates new Soroban credentials.
- forAddress() : SorobanCredentials
- Creates legacy ADDRESS credentials.
- forAddressCredentials() : SorobanCredentials
- Creates legacy ADDRESS credentials from existing address credentials.
- forAddressCredentialsV2() : SorobanCredentials
- Creates ADDRESS_V2 credentials (Protocol 27, CAP-71).
- forAddressWithDelegates() : SorobanCredentials
- Creates ADDRESS_WITH_DELEGATES credentials (Protocol 27, CAP-71).
- forSourceAccount() : SorobanCredentials
- Creates source-account credentials.
- fromXdr() : SorobanCredentials
- Decodes a SorobanCredentials from its XDR representation.
- getAddressCredentials() : SorobanAddressCredentials|null
- Returns the inner SorobanAddressCredentials for any address arm.
- getAddressWithDelegates() : SorobanAddressCredentialsWithDelegates|null
- Returns the ADDRESS_WITH_DELEGATES payload, or null for other arms.
- getCredentialType() : int
- Returns the credential type constant.
- isAddressBased() : bool
- Returns true when this is an address-based credential (any of ADDRESS, ADDRESS_V2, or ADDRESS_WITH_DELEGATES).
- isSourceAccount() : bool
- Returns true when this is a source-account credential.
- setAddressCredentials() : void
- Sets the address credentials for ADDRESS and ADDRESS_V2 arms.
- setAddressWithDelegates() : void
- Sets the ADDRESS_WITH_DELEGATES payload.
- setCredentialType() : void
- Sets the credential type constant.
- toXdr() : XdrSorobanCredentials
- Converts this object to its XDR representation.
- writeBackAddressCredentials() : void
- Writes back updated inner SorobanAddressCredentials while preserving the credential arm.
Properties
$addressCredentials
public
SorobanAddressCredentials|null
$addressCredentials
= null
address credentials for ADDRESS and ADDRESS_V2 arms; null otherwise
$addressWithDelegates
public
SorobanAddressCredentialsWithDelegates|null
$addressWithDelegates
= null
credentials-with-delegates for ADDRESS_WITH_DELEGATES arm; null otherwise
$credentialType
public
int
$credentialType
one of XdrSorobanCredentialsType constants
Methods
__construct()
Creates new Soroban credentials.
public
__construct([int|SorobanAddressCredentials $credentialType = XdrSorobanCredentialsType::SOROBAN_CREDENTIALS_SOURCE_ACCOUNT ][, SorobanAddressCredentials|null $addressCredentials = null ][, SorobanAddressCredentialsWithDelegates|null $addressWithDelegates = null ]) : mixed
The first argument is normally one of the XdrSorobanCredentialsType constants (int). Passing a SorobanAddressCredentials object as the first argument is also accepted for backward compatibility with the legacy single-argument calling convention — in that case the arm defaults to ADDRESS and addressCredentials is set from the object.
Parameters
- $credentialType : int|SorobanAddressCredentials = XdrSorobanCredentialsType::SOROBAN_CREDENTIALS_SOURCE_ACCOUNT
-
one of XdrSorobanCredentialsType constants, or a SorobanAddressCredentials object for legacy compatibility
- $addressCredentials : SorobanAddressCredentials|null = null
-
required for ADDRESS and ADDRESS_V2 arms
- $addressWithDelegates : SorobanAddressCredentialsWithDelegates|null = null
-
required for ADDRESS_WITH_DELEGATES arm
forAddress()
Creates legacy ADDRESS credentials.
public
static forAddress(Address $address, int $nonce, int $signatureExpirationLedger, XdrSCVal $signature) : SorobanCredentials
Uses ENVELOPE_TYPE_SOROBAN_AUTHORIZATION (not address-bound). This is the default arm and is valid on all protocol versions.
Parameters
- $address : Address
-
the address to authorize
- $nonce : int
-
unique nonce for replay protection
- $signatureExpirationLedger : int
-
ledger after which the signature expires
- $signature : XdrSCVal
-
the signature data
Return values
SorobanCredentials —legacy ADDRESS credentials
forAddressCredentials()
Creates legacy ADDRESS credentials from existing address credentials.
public
static forAddressCredentials(SorobanAddressCredentials $addressCredentials) : SorobanCredentials
Parameters
- $addressCredentials : SorobanAddressCredentials
-
the address credentials
Return values
SorobanCredentials —legacy ADDRESS credentials
forAddressCredentialsV2()
Creates ADDRESS_V2 credentials (Protocol 27, CAP-71).
public
static forAddressCredentialsV2(SorobanAddressCredentials $addressCredentials) : SorobanCredentials
Uses ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS (address-bound preimage). Invalid on networks below Protocol 27.
Parameters
- $addressCredentials : SorobanAddressCredentials
-
the address credentials
Return values
SorobanCredentials —ADDRESS_V2 credentials
forAddressWithDelegates()
Creates ADDRESS_WITH_DELEGATES credentials (Protocol 27, CAP-71).
public
static forAddressWithDelegates(SorobanAddressCredentialsWithDelegates $addressWithDelegates) : SorobanCredentials
Uses ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS with a recursive delegate tree. Invalid on networks below Protocol 27.
Parameters
- $addressWithDelegates : SorobanAddressCredentialsWithDelegates
-
the credentials-plus-delegates payload
Return values
SorobanCredentials —ADDRESS_WITH_DELEGATES credentials
forSourceAccount()
Creates source-account credentials.
public
static forSourceAccount() : SorobanCredentials
Source-account credentials authorize using the transaction source account without additional signatures.
Return values
SorobanCredentials —credentials using the source account
fromXdr()
Decodes a SorobanCredentials from its XDR representation.
public
static fromXdr(XdrSorobanCredentials $xdr) : SorobanCredentials
All four credential arms are decoded faithfully. An unknown arm value throws InvalidArgumentException.
Parameters
- $xdr : XdrSorobanCredentials
-
the XDR object to decode
Tags
Return values
SorobanCredentials —the decoded credentials
getAddressCredentials()
Returns the inner SorobanAddressCredentials for any address arm.
public
getAddressCredentials() : SorobanAddressCredentials|null
- ADDRESS: returns $addressCredentials directly.
- ADDRESS_V2: returns $addressCredentials directly.
- ADDRESS_WITH_DELEGATES: returns $addressWithDelegates->addressCredentials.
- SOURCE_ACCOUNT: returns null.
Return values
SorobanAddressCredentials|null —the inner address credentials, or null for source-account
getAddressWithDelegates()
Returns the ADDRESS_WITH_DELEGATES payload, or null for other arms.
public
getAddressWithDelegates() : SorobanAddressCredentialsWithDelegates|null
Return values
SorobanAddressCredentialsWithDelegates|nullgetCredentialType()
Returns the credential type constant.
public
getCredentialType() : int
Return values
int —one of XdrSorobanCredentialsType constants
isAddressBased()
Returns true when this is an address-based credential (any of ADDRESS, ADDRESS_V2, or ADDRESS_WITH_DELEGATES).
public
isAddressBased() : bool
Return values
bool —true for all three address arms
isSourceAccount()
Returns true when this is a source-account credential.
public
isSourceAccount() : bool
Return values
bool —true for SOURCE_ACCOUNT arm
setAddressCredentials()
Sets the address credentials for ADDRESS and ADDRESS_V2 arms.
public
setAddressCredentials(SorobanAddressCredentials|null $addressCredentials) : void
Parameters
- $addressCredentials : SorobanAddressCredentials|null
-
the address credentials
setAddressWithDelegates()
Sets the ADDRESS_WITH_DELEGATES payload.
public
setAddressWithDelegates(SorobanAddressCredentialsWithDelegates|null $addressWithDelegates) : void
Parameters
- $addressWithDelegates : SorobanAddressCredentialsWithDelegates|null
setCredentialType()
Sets the credential type constant.
public
setCredentialType(int $credentialType) : void
Parameters
- $credentialType : int
-
one of XdrSorobanCredentialsType constants
toXdr()
Converts this object to its XDR representation.
public
toXdr() : XdrSorobanCredentials
Tags
Return values
XdrSorobanCredentials —the XDR encoded credentials
writeBackAddressCredentials()
Writes back updated inner SorobanAddressCredentials while preserving the credential arm.
public
writeBackAddressCredentials(SorobanAddressCredentials $addressCredentials) : void
ADDRESS and ADDRESS_V2: sets $addressCredentials. ADDRESS_WITH_DELEGATES: sets $addressWithDelegates->addressCredentials. SOURCE_ACCOUNT: no-op.
Parameters
- $addressCredentials : SorobanAddressCredentials
-
the updated address credentials