computeKeys method
Compute the subaddress keys based on minor and major indexes.
This method calculates Monero subaddress keys using the provided minorIndex
and majorIdx
.
If the indexes are out of valid range, it throws an ArgumentException
.
It returns a tuple of subaddress public spend key and subaddress public view key.
Implementation
Tuple<MoneroPublicKey, MoneroPublicKey> computeKeys(
int minorIndex, int majorIndex) {
if (minorIndex < 0 || minorIndex > MoneroSubaddressConst.subaddrMaxIdx) {
throw ArgumentException('Invalid minor index ($minorIndex)');
}
if (majorIndex < 0 || majorIndex > MoneroSubaddressConst.subaddrMaxIdx) {
throw ArgumentException('Invalid major index ($majorIndex)');
}
if (minorIndex == 0 && majorIndex == 0) {
return Tuple(pubSKey, pubVKey);
}
List<int> majorIdxBytes = IntUtils.toBytes(majorIndex,
length: MoneroSubaddressConst.subaddrIdxByteLen,
byteOrder: Endian.little);
List<int> minorIdxBytes = IntUtils.toBytes(minorIndex,
length: MoneroSubaddressConst.subaddrIdxByteLen,
byteOrder: Endian.little);
List<int> privVKeyBytes = privVKey.raw;
List<int> mBytes = QuickCrypto.keccack256Hash(List<int>.from([
...MoneroSubaddressConst.subaddrPrefix,
...privVKeyBytes,
...majorIdxBytes,
...minorIdxBytes
]));
BigInt mInt = BigintUtils.fromBytes(Ed25519Utils.scalarReduce(mBytes),
byteOrder: Endian.little);
final newPoint =
pubSKey.pubKey.point + (Curves.generatorED25519 * mInt) as EDPoint;
MoneroPublicKey subaddrPubSKey = MoneroPublicKey.fromPoint(newPoint);
MoneroPublicKey subaddrPubVKey = MoneroPublicKey.fromPoint(
(subaddrPubSKey.pubKey.point *
BigintUtils.fromBytes(privVKey.raw, byteOrder: Endian.little))
as EDPoint);
return Tuple(subaddrPubSKey, subaddrPubVKey);
}