/// <summary> /// - Verifies that we are allowed to update this chain /// - Enrolls a new candidate chain with a CandidateOldVersionRecord referencing the old chain /// - Adds a OldVersionRecord to the old chain referencing the new chain /// - Adds a ChainUpdateRecord to the chain requesting update, forwarding it to the new chain. /// This operation is irreversable. /// </summary> /// <param name="newCandidate">The updated candidate information</param> /// <param name="password">The password provided by the candidate</param> /// <param name="fp">The fingerprint to verify against</param> /// <param name="privKey">The private key to pack the data with</param> /// <param name="chainToUpdate">The chain ID of the chain to be updated</param> /// <returns>The chain ID pointing to the updated candidate</returns> public static byte[] UpdateCandidate(Candidate newCandidate, string password, Fingerprint fp, RSAParameters privKey, byte[] chainToUpdate) { if (FullVerifyFromChain(chainToUpdate, password, fp, privKey) < 50f) { throw new AccessConfidenceTooLowException("Access confidence too low to update candidate."); } var newChainId = EnrollCandidate(newCandidate, password, privKey); var ovr = new CandidateOldVersionRecord(chainToUpdate, newChainId); var cur = new CandidateUpdatedRecord(chainToUpdate, newChainId); var oldRecordEntry = Entry.NewEntry(ovr.Pack(privKey), null, newChainId); var newRecordEntry = Entry.NewEntry(cur.Pack(privKey), null, chainToUpdate); Entry.CommitEntry(oldRecordEntry, FactomWallet); Entry.CommitEntry(newRecordEntry, FactomWallet); Thread.Sleep(10100); Entry.RevealEntry(oldRecordEntry); Entry.RevealEntry(newRecordEntry); return(newChainId); }
/// <summary> /// </summary> /// <param name="chainId"></param> /// <param name="pubKey">The public key to verify the data with</param> /// <returns></returns> public static List <CandidateOldVersionRecord> GetOldVersionRecords(byte[] chainId, RSAParameters pubKey) { var entries = Chain.GetAllChainEntries(chainId); var entriesData = entries.Select(e => Entry.GetEntryData(e).Content).ToList(); var records = new List <CandidateOldVersionRecord>(); foreach (var data in entriesData) { if (Bytes.StartsWith(data, CandidateOldVersionRecord.CandidateOldVersionPrefix)) { records.Add(CandidateOldVersionRecord.Unpack(data, pubKey)); } } return(records); }
/// <summary> /// - Verifies that we are allowed to update this chain /// - Enrolls a new candidate chain with a CandidateOldVersionRecord referencing the old chain /// - Adds a OldVersionRecord to the old chain referencing the new chain /// - Adds a ChainUpdateRecord to the chain requesting update, forwarding it to the new chain. /// This operation is irreversable. /// </summary> /// <param name="newCandidate">The updated candidate information</param> /// <param name="password">The password provided by the candidate</param> /// <param name="fp">The fingerprint to verify against</param> /// <param name="privKey">The private key to pack the data with</param> /// <param name="chainToUpdate">The chain ID of the chain to be updated</param> /// <returns>The chain ID pointing to the updated candidate</returns> public static byte[] UpdateCandidate(Candidate newCandidate, string password, Fingerprint fp, RSAParameters privKey, byte[] chainToUpdate) { if (FullVerifyFromChain(chainToUpdate, password, fp, privKey) < 50f) throw new AccessConfidenceTooLowException("Access confidence too low to update candidate."); var newChainId = EnrollCandidate(newCandidate, password, privKey); var ovr = new CandidateOldVersionRecord(chainToUpdate, newChainId); var cur = new CandidateUpdatedRecord(chainToUpdate, newChainId); var oldRecordEntry = Entry.NewEntry(ovr.Pack(privKey), null, newChainId); var newRecordEntry = Entry.NewEntry(cur.Pack(privKey), null, chainToUpdate); Entry.CommitEntry(oldRecordEntry, FactomWallet); Entry.CommitEntry(newRecordEntry, FactomWallet); Thread.Sleep(10100); Entry.RevealEntry(oldRecordEntry); Entry.RevealEntry(newRecordEntry); return newChainId; }