private void SetMaster(byte[] seed) { var hashMAC = Hashes.HMACSHA512(hashkey, seed); key = new CCKey(hashMAC.SafeSubarray(0, 32)); Buffer.BlockCopy(hashMAC, 32, vchChainCode, 0, ChainCodeLength); }
public ExtKey(CCKey key, byte[] chainCode, byte depth, byte[] fingerprint, uint child) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (chainCode == null) { throw new ArgumentNullException(nameof(chainCode)); } if (fingerprint == null) { throw new ArgumentNullException(nameof(fingerprint)); } if (fingerprint.Length != 4) { throw new ArgumentException(string.Format("The fingerprint must be {0} bytes.", 4), "fingerprint"); } if (chainCode.Length != ChainCodeLength) { throw new ArgumentException(string.Format("The chain code must be {0} bytes.", ChainCodeLength), "chainCode"); } this.key = key; this.nDepth = depth; this.nChild = child; parentFingerprint = new HDFingerprint(fingerprint); Buffer.BlockCopy(chainCode, 0, vchChainCode, 0, ChainCodeLength); }
public CCKey GetCCKey(long aIndex) { CCKey lKey; if (aIndex == 0) { lKey = new CCKey(Encoding.ASCII.GetBytes(GetIndexKey(aIndex))); } else { lKey = new CCKey(HexStringToByteArray(GetIndexKey(aIndex))); } return(lKey); }
/// <summary> /// Constructor. Creates an extended key from the public key and corresponding private key. /// </summary> /// <remarks> /// <para> /// The ExtPubKey has the relevant values for child number, depth, chain code, and fingerprint. /// </para> /// </remarks> public ExtKey(ExtPubKey extPubKey, CCKey privateKey) { if (extPubKey == null) { throw new ArgumentNullException(nameof(extPubKey)); } if (privateKey == null) { throw new ArgumentNullException(nameof(privateKey)); } this.nChild = extPubKey.nChild; this.nDepth = extPubKey.nDepth; this.vchChainCode = extPubKey.vchChainCode; this.parentFingerprint = extPubKey.parentFingerprint; this.key = privateKey; }
private void SetMaster(ReadOnlySpan <byte> seed) { Span <byte> hashMAC = stackalloc byte[64]; if (Hashes.HMACSHA512(hashkey, seed, hashMAC, out int len) && len == 64 && NBitcoinContext.Instance.TryCreateECPrivKey(hashMAC.Slice(0, 32), out var k) && k is Secp256k1.ECPrivKey) { key = new Key(k, true); hashMAC.Slice(32, ChainCodeLength).CopyTo(vchChainCode); hashMAC.Clear(); } else { throw new InvalidOperationException("Invalid ExtKey (this should never happen)"); } }
/// <summary> /// Constructor. Creates an extended key from the private key, with the specified value /// for chain code. Depth, fingerprint, and child number, will have their default values. /// </summary> public ExtKey(CCKey masterKey, byte[] chainCode) { if (masterKey == null) { throw new ArgumentNullException(nameof(masterKey)); } if (chainCode == null) { throw new ArgumentNullException(nameof(chainCode)); } if (chainCode.Length != ChainCodeLength) { throw new ArgumentException(string.Format("The chain code must be {0} bytes.", ChainCodeLength), "chainCode"); } this.key = masterKey; Buffer.BlockCopy(chainCode, 0, vchChainCode, 0, ChainCodeLength); }