public void TestEncodeBytes() { var bytes = Base16.Decode("CCAC2AED591056BE4F90FD441C534766"); var words = Rfc1751.Encode(bytes); Assert.Equal("RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE", words); }
public Property TestRoundTrip() { return(Prop.ForAll( Arb.From <ulong>(), bits => { var words = Rfc1751.Encode(bits); var split = words.Split(" "); var result = Rfc1751.Decode(split[0], split[1], split[2], split[3], split[4], split[5], out var parityError); Assert.Equal(bits, result); Assert.False(parityError); })); }
public Property TestRoundTripBytes() { var arb = Arb.From <byte[]>().Filter(bytes => bytes.Length % 8 == 0); return(Prop.ForAll( arb, bytes => { var words = Rfc1751.Encode(bytes); var result = Rfc1751.Decode(words, out var parityError); Assert.Equal(Base16.Encode(bytes), Base16.Encode(result.Span)); Assert.False(parityError); })); }
public async void TestWalletPropose_NoEntropy(KeyType?keyType) { var request = new WalletProposeRequest { KeyType = keyType, }; var response = await Api.WalletPropose(request); Assert.Equal(keyType == KeyType.Ed25519 ? "ed25519" : "secp256k1", response.KeyType); Assert.NotNull(response.AccountId); Assert.NotNull(response.PublicKey); Assert.NotNull(response.MasterSeed); var masterEntropy = Base16.Decode(response.MasterSeedHex); var masterSeed = new Seed(masterEntropy, keyType ?? KeyType.Secp256k1); masterSeed.GetKeyPairs(out _, out var keyPair); var publicKey = keyPair.PublicKey.GetCanoncialBytes(); Assert.Equal(response.PublicKeyHex, Base16.Encode(publicKey)); var accountId = AccountId.FromPublicKey(publicKey); Assert.Equal(response.AccountId, accountId.ToString()); var buffer = new byte[publicKey.Length + 1]; buffer[0] = 35; publicKey.CopyTo(buffer, 1); var base58PublicKey = Base58Check.ConvertTo(buffer); Assert.Equal(base58PublicKey, response.PublicKey); // The hex is a 256 bit little endian number, so reverse the bits for RFC1751 encoding Array.Reverse(masterEntropy); var masterKey = Rfc1751.Encode(masterEntropy); Assert.Equal(masterKey, response.MasterKey); }
public void TestEncode(ulong bits, string expected) { var words = Rfc1751.Encode(bits); Assert.Equal(expected, words); }