public static ExtendedKey from_slice(Secp256K1 secp, byte[] slice) { // TODO change when ser. ext. size is fixed if (slice.Length != 79) { throw new Exception("InvalidSliceSize"); } var ext = new ExtendedKey { Depth = slice[0] }; var rootKeyBytes = slice.Skip(1).Take(10).ToArray(); ext.RootKeyId = ExtKey.Identifier.From_bytes(rootKeyBytes); var nchildBytes = slice.Skip(11).Take(4).ToArray(); Array.Reverse(nchildBytes); ext.NChild = BitConverter.ToUInt32(nchildBytes, 0); ext.Chaincode = slice.Skip(15).Take(32).ToArray(); var keyBytes = slice.Skip(47).Take(32).ToArray(); ext.Key = SecretKey.From_slice(secp, keyBytes); return(ext); }
/// Creates a new extended master key from a seed public static ExtendedKey from_seed(Secp256K1 secp, byte[] seed) { switch (seed.Length) { case 16: case 32: case 64: break; default: throw new Exception("InvalidSeedSize"); } var keyData = Encoding.ASCII.GetBytes("Mimble seed"); var blake2B = new HMACBlake2B(keyData, 512); var derived = blake2B.ComputeHash(seed); var chaincode = derived.Skip(32).ToArray(); var secretKeyBytes = derived.Take(32).ToArray(); var secretKey = SecretKey.From_slice(secp, secretKeyBytes); var ext = new ExtendedKey { Depth = 0, RootKeyId = ExtKey.Identifier.Zero(), NChild = 0, Chaincode = chaincode, Key = secretKey, }; ext.RootKeyId = ext.Identifier(secp); return(ext); }