computeChainCode property
Computes the chain code based on the path element and its data type.
Implementation
List<int> get computeChainCode {
SubstrateScaleEncoderBase? scaleEnc;
final BigInt? toInt = BigInt.tryParse(elem);
if (toInt != null) {
final bitLen = toInt.bitLength;
for (final minBitLen in SubstratePathConst.scaleIntEncoders.keys) {
if (bitLen <= minBitLen) {
scaleEnc = SubstratePathConst.scaleIntEncoders[minBitLen];
break;
}
}
if (scaleEnc == null) {
throw SubstratePathError("Invalid integer bit length ($bitLen)");
}
} else {
scaleEnc = const SubstrateScaleBytesEncoder();
}
final encData = scaleEnc.encode(elem);
const maxLen = SubstratePathConst.encodedElemMaxByteLen;
if (encData.length > maxLen) {
return QuickCrypto.blake2b256Hash(encData);
} else {
return List<int>.from(
encData.toList() + List.filled(maxLen - encData.length, 0));
}
}