I’m trying to understand Concordium account aliases. I just found this page Concordium Client transactions — Concordium documentation . I need to generate new addresses on request for a user account (without having his private key, just the canonical account). Can I get the first bytes 29 bytes of the canonical account and then append aliasIndex.toString(16).padStart(6, '0');
where aliasIndex is an integer? Otherwise, do I have to comply with a particular format?
Hey,
The three last bytes of the canonical address determines the alias.
Depending on which language you use, you can use one of our SDKs for this.
Rust:
Javascript:
);
}
/**
* Given an AccountAddress and a counter, returns an alias for the address.
* @param address the account address for which the function should get an alias for
* @param counter number s.t. 0 <= counter < 2^24, decides which alias is returned.
* If a counter outside this scope is given, then the function will throw an exception
* @returns an AccountAddress, which is an alias to the given address
*/
export function getAlias(
address: AccountAddress,
counter: number
): AccountAddress {
if (counter < 0 || counter > maxCount) {
throw new Error(
`An invalid counter value was given: ${counter}. The value has to satisfy that 0 <= counter < 2^24`
);
}
const commonBytes = address.decodedAddress.slice(0, commonBytesLength);
const aliasBytes = Buffer.alloc(aliasBytesLength);
Java:
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
@EqualsAndHashCode
public final class AccountAddress {
public static final int BYTES = 32;
private final static int VERSION = 1;
private final static int ACCOUNT_ADDRESS_PREFIX_SIZE = 29;
private final static int ALIAS_MAX_VALUE = (2 << 23); // 2^24
@Getter
private final byte[] bytes;
private AccountAddress(byte[] bytes) {
this.bytes = bytes;
}
public byte[] getEncodedBytes() {
return Base58.encodeChecked(VERSION, bytes).getBytes(StandardCharsets.UTF_8);
C#:
Thank you very much @EmilLai