module static method

List<int> module(
  1. String moduleName, {
  2. List<List<int>> derivationKeys = const [],
})

Module is a specialized version of a composed address for modules. Each module account is constructed from a module name and a sequence of derivation keys (at least one derivation key must be provided). The derivation keys must be unique in the module scope, and is usually constructed from some object id. Example, let's a x/dao module, and a new DAO object, it's address would be:

address.Module(dao.ModuleName, newDAO.ID)

Implementation

static List<int> module(String moduleName,
    {List<List<int>> derivationKeys = const []}) {
  List<int> keyBytes = StringUtils.encode(moduleName);
  if (derivationKeys.isEmpty) {
    return QuickCrypto.sha256Hash(keyBytes).sublist(0, 20);
  }
  keyBytes = [...keyBytes, 0];
  List<int> addr = AtomAddressUtils.hash(
      "module".codeUnits, [...keyBytes, ...derivationKeys[0]]);
  for (int i = 1; i < derivationKeys.length; i++) {
    addr = AtomAddressUtils.hash(addr, derivationKeys[i]);
  }
  return addr;
}