Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
/* If sequence is 0 this is the first lookup, so check at least the first 10 positions */
const loopMax = !sequence
? Math.max(sequence + this.brainkey_look_ahead, 10)
: sequence + this.brainkey_look_ahead;
// console.log("generateNextKey, save:", save, "sequence:", sequence, "loopMax", loopMax, "brainkey_look_ahead:", this.brainkey_look_ahead);
for (let i = sequence; i < loopMax; i++) {
let private_key = key.get_brainPrivateKey(brainkey, i);
let pubkey = this.generateNextKey_pubcache[i]
? this.generateNextKey_pubcache[i]
: (this.generateNextKey_pubcache[
i
] = private_key.toPublicKey().toPublicKeyString());
let next_key = ChainStore.getAccountRefsOfKey(pubkey);
// TODO if ( next_key === undefined ) return undefined
/* If next_key exists, it means the generated private key controls an account, so we need to save it */
if (next_key && next_key.size) {
used_sequence = i;
console.log(
"WARN: Private key sequence " +
used_sequence +
" in-use. " +
"I am saving the private key and will go onto the next one."
);
this.saveKey(private_key, used_sequence);
// this.brainkey_look_ahead++;
}
}
if (used_sequence !== null) {
new_state[key] = name;
++all_objects_counter;
if (name !== undefined) ++resolved_objects_counter;
} else {
if (this.state[key]) new_state[key] = null;
}
}
/* Resolve account key references */
for (let key of this.chain_key_refs) {
let prop =
props[key] ||
this.dynamic_prop[key] ||
this.default_props[key];
if (prop) {
let new_obj = ChainStore.getAccountRefsOfKey(prop);
if (
new_obj === undefined &&
this.required_props.indexOf(key) === -1 &&
new_obj !== this.state[key]
)
new_state[key] = new_obj;
else if (new_obj && new_obj !== this.state[key])
new_state[key] = new_obj;
++all_objects_counter;
if (new_obj !== undefined) ++resolved_objects_counter;
} else {
if (this.state[key]) new_state[key] = null;
}
}
/* Resolve balance objects */
.forEach(pubkey => {
if (no_account_refs.has(pubkey)) return;
let refs = ChainStore.getAccountRefsOfKey(pubkey);
if (refs === undefined) return;
if (!refs.size) {
// Performance optimization...
// There are no references for this public key, this is going
// to block it. There many be many TITAN keys that do not have
// accounts for example.
{
// Do Not block brainkey generated keys.. Those are new and
// account references may be pending.
let private_key_object = PrivateKeyStore.getState().keys.get(
pubkey
);
if (
typeof private_key_object.brainkey_sequence ===
"number"
) {
var isPendingFromChain = derived_key =>
ChainStore.getAccountRefsOfKey(derived_key.public_string) === undefined;
if(prop[0] === "#" && Number.parseInt(prop.substring(1)))
prop = "1.2." + prop.substring(1);
let new_obj = ChainStore.getAccount(prop);
if (new_obj === undefined && this.required_props.indexOf(key) === -1 && new_obj !== this.state[key]) new_state[key] = new_obj;
else if (new_obj && new_obj !== this.state[key]) new_state[key] = new_obj;
++all_objects_counter;
if (new_obj !== undefined) ++resolved_objects_counter;
} else {
if(this.state[key]) new_state[key] = null;
}
}
for( let key of this.chain_key_refs )
{
let prop = props[key] || this.dynamic_prop[key] || this.default_props[key];
if(prop) {
let new_obj = ChainStore.getAccountRefsOfKey(prop);
if (new_obj === undefined && this.required_props.indexOf(key) === -1 && new_obj !== this.state[key]) new_state[key] = new_obj;
else if (new_obj && new_obj !== this.state[key]) new_state[key] = new_obj;
++all_objects_counter;
if (new_obj !== undefined) ++resolved_objects_counter;
} else {
if(this.state[key]) new_state[key] = null;
}
}
for( let key of this.chain_address_balances )
{
let prop = props[key] || this.dynamic_props[key] || this.default_props[key];
if(prop) {
let new_obj = ChainStore.getBalanceObjects(prop);
if (new_obj === undefined && this.required_props.indexOf(key) === -1 && new_obj !== this.state[key]) new_state[key] = new_obj;
else if (new_obj && new_obj !== this.state[key]) new_state[key] = new_obj;
++all_objects_counter;
var updatePubkey = public_string => {
var chain_account_ids = ChainStore.getAccountRefsOfKey(
public_string
);
if (chain_account_ids)
chain_account_ids.forEach(chain_account_id => {
new_ids.add(chain_account_id);
});
};
this.derived_keys.forEach(derived_key =>
onAddPrivateKey({private_key_object}) {
if (
ChainStore.getAccountRefsOfKey(private_key_object.pubkey) !==
undefined
)
this.chainStoreUpdate();
}