derive Contract Address
suspend fun deriveContractAddress(credentialId: ByteArray, deployerPublicKey: String, networkPassphrase: String): String
Derives the smart account contract address from a credential ID and deployer.
Computes the deterministic contract address that will be created when deploying a smart account contract with the given credential ID from the specified deployer account on the specified network.
Algorithm:
salt = SHA256(credentialId)
deployerAddress = SCAddress::Account(deployerPublicKey)
networkId = SHA256(networkPassphrase as UTF-8)
preimage = HashIdPreimage::ContractId {
networkId: networkId,
contractIdPreimage: ContractIdPreimage::FromAddress {
address: deployerAddress,
salt: Uint256(salt)
}
}
contractIdBytes = SHA256(XDR_encode(preimage))
contractId = StrKey.encodeContract(contractIdBytes)Content copied to clipboard
Return
Contract address as a C-address (StrKey encoded)
Parameters
credential Id
WebAuthn credential ID used to generate the salt
deployer Public Key
Stellar account ID (G-address) of the deployer
network Passphrase
Network passphrase (e.g., "Test SDF Network ; September 2015")
Throws
if the deployer public key is invalid
if contract ID encoding fails
if hash computation fails
Example:
val credentialId = ... // from WebAuthn registration
val deployerKey = "GBXYZ..." // deployer G-address
val networkPassphrase = "Test SDF Network ; September 2015"
val contractAddress = SmartAccountUtils.deriveContractAddress(
credentialId,
deployerKey,
networkPassphrase
)
println("Contract will be deployed at: $contractAddress")Content copied to clipboard