check change address diversifier on spark address generate

This commit is contained in:
julian 2024-01-03 11:01:04 -06:00
parent 555448a0e9
commit 07b21a42c6

View file

@ -23,8 +23,6 @@ const kDefaultSparkIndex = 1;
// TODO dart style constants. Maybe move to spark lib?
const MAX_STANDARD_TX_WEIGHT = 400000;
const SPARK_CHANGE_D = 0x270F;
//https://github.com/firoorg/sparkmobile/blob/ef2e39aae18ecc49e0ddc63a3183e9764b96012e/include/spark.h#L16
const SPARK_OUT_LIMIT_PER_TX = 16;
@ -70,7 +68,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
_sparkChangeAddressCached = await LibSpark.getAddress(
privateKey: keys.privateKey.data,
index: kDefaultSparkIndex,
diversifier: SPARK_CHANGE_D,
diversifier: kSparkChange,
isTestNet: cryptoCurrency.network == CryptoCurrencyNetwork.test,
);
}
@ -116,7 +114,11 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
(await getCurrentReceivingSparkAddress())?.derivationIndex;
// default to starting at 1 if none found
final int diversifier = (highestStoredDiversifier ?? 0) + 1;
int diversifier = (highestStoredDiversifier ?? 0) + 1;
// change address check
if (diversifier == kSparkChange) {
diversifier++;
}
final root = await getRootHDNode();
final String derivationPath;