addOwnership method
Add an ownership with a secret and its authorized public keys
secret
: Secret encrypted (hexadecimal)authorizedKeys
: List of authorizedKeys
Implementation
Transaction addOwnership(String secret, List<AuthorizedKey> authorizedKeys) {
if (!isHex(secret)) {
throw const FormatException("'Secret' must be an hexadecimal string");
}
for (final authorizedKey in authorizedKeys) {
if (!isHex(authorizedKey.publicKey!)) {
throw const FormatException(
"'Authorized public key' must be an hexadecimal string",
);
}
if (!isHex(authorizedKey.encryptedSecretKey!)) {
throw const FormatException(
"'Encrypted secret' must be an hexadecimal string",
);
}
}
final newAuthorizedPublicKeys = <AuthorizedKey>[];
for (final element in authorizedKeys) {
if (element.publicKey != null) {
newAuthorizedPublicKeys.add(
AuthorizedKey(
encryptedSecretKey: element.encryptedSecretKey,
publicKey: element.publicKey!.toUpperCase(),
),
);
}
}
final newOwnership = data!.ownerships
..add(
Ownership(
secret: secret,
authorizedPublicKeys: newAuthorizedPublicKeys,
),
);
return copyWith.data!(
ownerships: newOwnership,
);
}