NBitcoin/BIP174/PartiallySignedTransaction.cs
/// <summary>
/// Rebase the keypaths.
/// If a PSBT updater only know the child HD public key but not the root one, another updater knowing the parent master key it is based on
/// can rebase the paths. If the PSBT is all finalized this operation is a no-op
/// </summary>
/// <param name="accountKey">The current account key</param>
/// <param name="newRoot">The KeyPath with the fingerprint of the new root key</param>
/// <returns>This PSBT</returns>
Rebase the keypaths.
If a PSBT updater only know the child HD public key but not the root one, another updater knowing the parent master key it is based on
can rebase the paths. If the PSBT is all finalized this operation is a no-op
Rebase the keypaths . If a PSBT updater only know the child HD public key but not the root one another updater knowing the parent master key it is based on can rebase the paths . If the PSBT is all finalized this operation is a no - op
public PSBT RebaseKeyPaths(IHDKey accountKey, RootedKeyPath newRoot)
		{
			if (accountKey == null)
				throw new ArgumentNullException(nameof(accountKey));
			if (newRoot == null)
				throw new ArgumentNullException(nameof(newRoot));
			if (IsAllFinalized())
				return this;
			accountKey = accountKey.AsHDKeyCache();
			var accountKeyFP = accountKey.GetPublicKey().GetHDFingerPrint();
			foreach (var o in HDKeysFor(accountKey).GroupBy(c => c.Coin))
			{
				if (o.Key is PSBTInput i && i.IsFinalized())
					continue;
				foreach (var keyPath in o)
				{
					if (keyPath.RootedKeyPath.MasterFingerprint != newRoot.MasterFingerprint)
					{
						o.Key.HDKeyPaths.Remove(keyPath.PubKey);
						o.Key.HDKeyPaths.Add(keyPath.PubKey, newRoot.Derive(keyPath.RootedKeyPath.KeyPath));
					}
				}
			}
			foreach (var xpub in GlobalXPubs.ToList())
			{
				if (xpub.Key.ExtPubKey.PubKey == accountKey.GetPublicKey())
				{
					if (xpub.Value.MasterFingerprint != newRoot.MasterFingerprint)
					{
						GlobalXPubs.Remove(xpub.Key);
						GlobalXPubs.Add(xpub.Key, newRoot.Derive(xpub.Value.KeyPath));
					}
				}
			}
			return this;
		}
public PSBT RebaseKeyPaths ( IHDKey accountKey , RootedKeyPath newRoot ) { if ( accountKey == null ) throw new ArgumentNullException ( nameof ( accountKey ) ) ; if ( newRoot == null ) throw new ArgumentNullException ( nameof ( newRoot ) ) ; if ( IsAllFinalized ( ) ) return this ; accountKey = accountKey . AsHDKeyCache ( ) ; var accountKeyFP = accountKey . GetPublicKey ( ) . GetHDFingerPrint ( ) ; foreach ( var o in HDKeysFor ( accountKey ) . GroupBy ( c => c . Coin ) ) { if ( o . Key is PSBTInput i && i . IsFinalized ( ) ) continue ; foreach ( var keyPath in o ) { if ( keyPath . RootedKeyPath . MasterFingerprint != newRoot . MasterFingerprint ) { o . Key . HDKeyPaths . Remove ( keyPath . PubKey ) ; o . Key . HDKeyPaths . Add ( keyPath . PubKey , newRoot . Derive ( keyPath . RootedKeyPath . KeyPath ) ) ; } } } foreach ( var xpub in GlobalXPubs . ToList ( ) ) { if ( xpub . Key . ExtPubKey . PubKey == accountKey . GetPublicKey ( ) ) { if ( xpub . Value . MasterFingerprint != newRoot . MasterFingerprint ) { GlobalXPubs . Remove ( xpub . Key ) ; GlobalXPubs . Add ( xpub . Key , newRoot . Derive ( xpub . Value . KeyPath ) ) ; } } } return this ; }
Rebase the keypaths.
Rebase the keypaths .
None
accountKey
IHDKey
The current account key
The current account key
newRoot
RootedKeyPath
The KeyPath with the fingerprint of the new root key
The KeyPath with the fingerprint of the new root key