Uref constructor
Uref(
- String value
Creates a Uref object with a hex string that contains an access rights suffix.
The hex string value
can be prefixed with "uref-" or not.
Implementation
Uref(String value) {
bool isPrefixed = value.startsWith(KeyIdentifier.uref.prefix);
int partCount = (isPrefixed ? 3 : 2);
final parts = value.split("-");
if (parts.length != partCount) {
throw ArgumentError.value(
value, 'value', 'Uref key must contain 3 (or 2 if not prefixed) parts, separated by "-"');
}
keyIdentifier = KeyIdentifier.uref;
final key = parts[isPrefixed ? 1 : 0];
final accessRightsStr = parts[isPrefixed ? 2 : 1];
if (key.length != 64) {
throw ArgumentError.value(value, 'value', 'Uref key must contain 32 bytes');
}
final bytes = GlobalStateKey._verifyChecksum(key);
this.key = keyIdentifier.prefix + Cep57Checksum.encode(bytes) + "-" + accessRightsStr;
accessRights = AccessRightsExt.fromString(accessRightsStr);
}