async def verify_message(ctx, msg): gc.collect() message = message_digest(msg.message) if len(msg.signature.nonce_pub.x) != 32 or len(msg.signature.sign_k) != 32: raise wire.DataError("Invalid size of signature params") is_valid = is_valid_beam_message(msg.signature, msg.public_key, message) if not is_valid: raise wire.InvalidSignature("Invalid signature") # Display message itself await require_validate_sign_message(ctx, str(msg.message, "utf-8")) # Display pub nonce part nonce_msg = "Sign_x: {}; Sign_y: {};".format( bin_to_str(msg.signature.nonce_pub.x), msg.signature.nonce_pub.y ) await require_validate_sign_message(ctx, nonce_msg) pubkey_msg = "Pubkey_x: {}; Pubkey_y: {};".format( bin_to_str(msg.public_key.x), msg.public_key.y ) await require_validate_sign_message(ctx, pubkey_msg) # Display sign_k part sign_k_msg = "Sign_k: {};".format(bin_to_str(msg.signature.sign_k)) await require_validate_sign_message(ctx, sign_k_msg) is_valid_msg = "Is valid: {}.".format(bool(is_valid)) await require_validate_sign_message(ctx, is_valid_msg) return Success(message="Message verified")
def test_generate_rangeproof(self): test_datasets = ( # Test params: # ( # KIDV.idx, KIDV.type, KIDV.sub_idx, KIDV.value # is_public_rangeproof, # expected rangeproof # ) (1, 2, 3, 4, False, "e07b3fb5f3fa1b3fd2cf7e7043f12c437489c16eb572ee31c610772edeb5fe2401c3333f901a2beb862b4858d59f7aea4b0978d396cae16cd4a5bf97c3d7a48e1101825de562c004e7485387e102c5677891384e14dda882ed4\ 738919bb5780fc23c00a9d9317a8b026e0f2e56fafdc2e01638d89c12dbfc5c74bff4b567774f41016f000771bd241a49aa6f73c68a4e5c66f2f905b85e7bed3fb2b74912934f885324f045ad92e277748df5d901141e484f555e3f65fc209deed742\ 9671eea4a0c89f74006530aff43cb1b873e77f7aba376ac6eaffa61d7e1763d7a32cdfdfdd0c6c66cc0179b94e85266852b459cb5d0c421004020c4d6a766b32b67a5b2db80b744bdb5901422d5bdf27999d63ac7e9dde0bdc2e718cad02d829addbd\ 5c3132108dacc924100f2924ad698f641786464be59b979b8f73a081d4946c0e9bc00ef8df32e8da8f500ee99cbcb72e3c958f4a41d5da34b957dc12fdf78c337725f42d49183808116a000b4a0695fdc85766416732889a59cb21df6a7211a92ca07\ 332e834087b486b083019b62e5457b4078fc0e978275d266dd160d87c4da893306ca7c297278b02feb1001e2231671f5f37cdafb32f5680b67f50772194000c09d87af2a955253a22d2329001d323b1bd64bb0490f78be6ab36b2d3beb70e1fad7c58\ d203236921ada7aa40a011f74281a315fdf2bc689d6a9a62cc8ea389a0ab4200e1ee04efe4b5fd538678f001766c12ddfa95f0c0878a938a632038fb0d297d5262c79755c62fa639c0905940199a99e4edfe6b3218e07db0c64ab5e60f3095cf8f803\ b8962dfeb8675af633a7d1a99857c11b26592b2a8b23dda679d8a2b398a30c1003e5c884513ded62c24318669dc6c4760281687f91ad4493a3262ad2a373ef0a2d3fa216adc9ee40bfbf01103585e8d34e73336b19f61845c6df7f1c4014a11c99482\ 4b7ba42ce5bf844"), (1, 11, 111, 23110, False, '2a44fb6cd5e465062feabe88fcbe0405abceac90eb04ba8dd21aae5fc6b8030101bf68a61abd528e5123cf2821139e0aa7af9ba394d62d7a331d30018eaee08948007084e76eb5297fff69811aed568a7d71234207e471b67153\ bd71d1cb1a5a746a010bb5c8a0055d878f8f4915f650e70280d129eff108062b909e55bdab19e4729d01f9f3c531a059dd45ecfacca651ef1a28275e811f8580b3a5a3c6dbb8fb8e5a2a0e4cf8cb2d70147f0d2b3628c94ac288cf3cea4e6d4b7efcb\ a63976deda5aed601abbc6d9f73a728685e0ced6fb6874b036e9211cbddeec538eacd68c489bdd8a000ebe4131c9bf9f979e8a32c474650c6913e13e063970c4db34954973d16c3cc30009a0642e36120597e61de2c351e6c751c65c62b89ef1bdb17\ 0dceeeb0de1fb4e501894918a1bec4fcf5340d72993bae0f8aad57b8a53ea63ceffff38b4485d23ddb00c8e6d8008472958a9e7f416fc03285b4a6cca4d9a5c5279a9a60e4606bd18176002a0d52513e8e13804d8114c1e06181e1995fd3e87dd6bea\ ae60da226d29e2b1a0096c531227d48a773299cb8f21789e496e6966df9d1d638cd8386fed9bf4d9ccc01552cb8f33bcd98591ea5fba648886f383dc816641d07f5705e4685a0253fd2a301f1c3b231cb4bd6cd2c66c8ebbbc8f801c6046635f4e22f\ a9770f327b2094a88900d70fa2629d583c7e74e311347beccb266a5a709749ffec89168d95a377b284f101ab3b7da1357b4978fa4ce70d9b8e03f9a06b62d4441ef0c0fab2eb24f7b8291a00ca124343a08dd3d9539adb45a356d3d28129a07c3e6b9\ 8e7fdeb6a76dbd47300183a2c54c18bf7ab967240ef04c4350e9c64c65be17a2afc7444d975c7bc286c0804555e6c08ab0aae70097f779d91547125d8701317d37baa562bc9399034dc4f08362e1537161166edd17d7cdbf23749d12fc6ca59a9189a\ 190b6a48f40c81'), (0, 0, 0, 3, False, 'add55fb422565311a0940bcffb84d1a1fe5561263c41d0c5557fdb41bc62de0e00b2092f8aebf26c252f2e5609324286f6b1610c210b50bba4470e8e0f76068484011146a35c268477d60a92432dfaf38633e8c94eb88c88d420\ 235d9dce3d2ab7e70171a9a46203336194078900390053efd05947f656339d44478b993d2b125e4a3300884bd1da5f13315f929d9cda40b4f3ddf89124c5514255f3eda19b9e51ffb4752fd3111d635563bafa8b4cd3fc858e4c4e7d87fe2744f2c55\ 4a860d009e0154a012d667ec625c368e663e856ea61310fa58e7197d6a135d09e394baf15b789410401749403c00827547c189cdb8757fd3175b29343ecd1da89b0cfee98fec61b86a401d9284b52e85c43f6535a9a740f86106c948b62ceb1973f16\ 7fd8521e5f61164001d053851eee209e72a2df5a7f314d170cecd7550939a3896d4e46d597623ca2fc0007f4819857c0cd5326c77ec24f82537270be96c08ac01f46db3cc690fdc483ae010f0805b64f9589baa57ac0fa4f25e21de87966c5e9f9320\ d9465382ac89b3df40190e7f97817dd3ece479122321593ffef20487601df681e80b8837deed98afd1a0026e8ac32ef097debef5fe051fa981dc05bcbf59d0749e3615111725bb79c00e9001a9cc2bb1d667c877b88dfcbb2f28feabca5022c44b63f\ ba8e8a0ff288dfe7ba0199ed51ce3651ac8c3d144662723db16768186f5c1fee2e2818407353d7a64cf401b290d7dfae00c75f9261ee044795cf375dc5b51ae482de7e3770ea1ecba1556500f0936899d729dfa5425e34dd21b58c73ac28784794c0a\ 27a6feb809a9591e9120dc0bb6acac4f8b8a3a9fd2881264b9b80cf0312a97429c185a77818720b800a8fc7d196c8705fb9fbb25c0df0d0c96ee45fe086ae5833943d2458967828bc38ca1885d0f6edb4f8254ae098edb83fa372410de51f55c46bea\ 1c0c90b54fe6b1'), ) for test_params in test_datasets: kid_idx = test_params[0] kid_type = test_params[1] kid_sub_idx = test_params[2] kid_value = test_params[3] is_public_rangeproof = int(test_params[4]) expected_rangeproof = test_params[5] is_public_rangeproof = 0 asset_id = bytearray(0) rangeproof_data = bytearray(688) beam.generate_rp_from_key_idv(kid_idx, kid_type, kid_sub_idx, kid_value, asset_id, is_public_rangeproof, self.seed, rangeproof_data) self.assertEqual(bin_to_str(rangeproof_data), expected_rangeproof)
def test_get_public_key(self): mnemonic = "all all all all all all all all all all all all" kdf = get_beam_kdf(mnemonic) test_datasets = ( (0, 0, "88b528eecb5ee5ae81e56e2105aca06997761c9cd2e566b25eaee1951be26688", 1), (0, 1, "53839a38c1089e28e901279266cff2da921ca82ed39c6ac0261a039157754e40", 1), (0, 8, "a3378664f9ada1a32cf860076ec6110621c7430d9b04316a20b56ced6fd73546", 1), (1, 1, "da2d246d99860617bd37755605f0584de6094b437efb4931ec20cf85b62631a5", 0), (1, 8, "54158bdbeef7292b96d5ea57b2eebc3ba6c8d4a16cfeb6cd75354e8497d009b8", 1), (2, 8, "bfb3e6e6eb8ee2b686aaa6a056fa2670a5c49d76583eb05fb84d9c5ab7227c71", 0), (3, 0, "22e6e269fb26638d8501583d5a7c0c8051315f9576174cc6f64dacfe9a01ef7f", 0), (3, 3, "392b73f534c490f614c36a3ad738a10b2cc4b08543e6250a2b2927d1c5ffa4ba", 1), (4, 4, "e5c551250ccb2dfbd11b5d38eae670d0476909acb7d1955c78c53647dd5de3e9", 0), (5, 2, "269c9a18d3a8f5acf4036a711e41cf7c5071aceac1fe95666040369a3311ac71", 0), (10, 3, "706bc1d21de9d4fdf4daef73b7774cb7e869e454a7776d8116c0ce86f9427577", 0), ) for test_params in test_datasets: kid_idx = test_params[0] kid_sub_idx = test_params[1] expected_public_key_x = test_params[2] expected_public_key_y = test_params[3] pk = get_beam_pk(kid_idx, kid_sub_idx, kdf) self.assertEqual(bin_to_str(pk[0]), expected_public_key_x) self.assertEqual(pk[1], expected_public_key_y)
def test_generate_nonce_singular(self): test_datasets = ( (1, "907356940fcc255479509517cfb381ea8c97631f116da551e1dbe958cb74977f", 0), (2, "7245e95ad17cea33fd91dffa041c93e6258c679a62651e0f155b253c29c0f4e4", 1), (3, "222f20219e08ab207b483d2bcb989b646281cf95b83ec35bf01246c9c24861ad", 0), (4, "18d2ac3f9dbc3d686352ce45390951077c1cb882cb8cf84ed2aaa32d0eaf6f0d", 1), (5, "18b34cb39a4a9e54dd71ffb7898ae29263fa7ea80048caa03dd39e3516b35237", 1), (6, "0643ac518336207ac327652d4266728afb30f99c772263caff38aee4f797c8a6", 0), (7, "ea0f4dc9323d9ebb323db74a7505220ce964a9a4f2f7b3f984b3ae17dcac8847", 1), (8, "f0ff98f3a9a6e49f0560789e56ffec9b9d30d026a4f7a3f3e88ad8b4cdd8c6ce", 1), (9, "59bf7dfce1afcb1147a9057640fbc74c054702b798da6dccaa09c08f8e023eab", 0), (10, "c63be273d84be79bf5ee205b13cdca7aad711ee87bf0d96cf602b252ac4e51de", 1), ) __init_and_unlock_config() create_master_nonce(self.seed) for test_params in test_datasets: slot = test_params[0] expected_pub_x = test_params[1] expected_pub_y = test_params[2] _, new_nonce = create_nonce(slot) pubkey_x, pubkey_y = calc_nonce_pub(new_nonce) self.assertEqual(bin_to_str(pubkey_x), expected_pub_x) self.assertEqual(pubkey_y[0], expected_pub_y)
def test_get_public_key_another_mnemonic(self): mnemonic = "abc abc abc abc abc abc abc abc abc abc abc abc" kdf = get_beam_kdf(mnemonic) test_datasets = ( (0, 0, "119a034ddd950028e45ee1d0c9b26efba0fb28af83e7f2ba83a5c0fa7ae2daee", 0), (0, 1, "2a4c57b74f1cc0ee995ceab14ae9e9bc581da8ccb290564d15b9079858635604", 1), (0, 8, "418ec586d5ff80c1d82b25892c64a45243d9630fec255580cb2f0ac95b614415", 1), (1, 1, "f3632a997e42ff854d8d450113e8bea6f47e2ef069ed6cf36188343a1c7df013", 0), (2, 8, "a135d3ddcbce9cc76e46c2c8374ab084e88e01d81eb8a9588bd19cb997a41f91", 1), (3, 0, "19812e15f636ae0df35cc158d3496dd33999cf8f18df939588248d3f8ff86bd7", 0), (3, 3, "9e2b9fb5178fb4e71a8242b658c249e0aceb7ac576fc20a034a67c8c4f5b1c61", 0), (4, 4, "d320b5f0fcdcbfe2d005bff93d0fec1e1ac33abeebe51b2c9322176f820252cf", 1), (5, 2, "3206c52f75f777b230f64e0d6dff6eb6c2a1566b3b887943939beb0d3a6444f1", 1), (10, 3, "ff33f03af33b4b062e69479327d1fc02c13a22354dcd9a3bc7162ad3b2768f1c", 1), ) for test_params in test_datasets: kid_idx = test_params[0] kid_sub_idx = test_params[1] expected_public_key_x = test_params[2] expected_public_key_y = test_params[3] pk = get_beam_pk(kid_idx, kid_sub_idx, kdf) self.assertEqual(bin_to_str(pk[0]), expected_public_key_x) self.assertEqual(pk[1], expected_public_key_y)
def test_message_digest(self): test_datasets = ( ( "Hello, world!", "1ab8816c3a4ba40c0857eb039445303126f103db4c3b848806a77ce61e860ab2", ), ( "abc", "6ed020d642e731d9d79da2dfa5b57c9c1ed148d00c9e23591459e563b10f23f2", ), ( "ABC", "6af3829a33662dd58ae51ee4bd23d1a718bb319f9b6cbd2048bc6ba27f18ba7e", ), ( "beam", "e21df0f5518a2ba06a122b54b09f33960e158bbd5269cd9477531a5301e18d14", ), ( "BEAM", "fe7634347119cb94bd374db7575cfd0ed7057e0615c99ae7e3bbd97b8a95c363", ), ( "beam beam beam", "e914080bb4e2c1591036c2181d5f0cb13dd6ceedc777b3e5f754e5fb8075b8a7", ), ( "beam,beam,beam", "0ddba34f96272d6d1690abdb0f1ee29cd18e61a33c6db592c54707b24955168d", ), ( "beam trezor integration", "1c956a830ce1602a47a843dbb664d28a164bbf9935de1d4002ef7d81449247ea", ), ) for test_params in test_datasets: message = test_params[0] expected_digest = test_params[1] msg_digest = message_digest(message) self.assertEqual(bin_to_str(msg_digest), expected_digest)
def test_generate_key(self): test_datasets = ( ( 0, 0, 0, 0, "6a11f21ad47da59863e7f7d2fc952677f8342f4a2f89eb4c281f3b832dca8afc", 0, ), ( 0, 0, 0, 1, "ecf1258affe8c0b11c5c954e997e7fe1f9d2988db19b491b39537fea9506a47e", 0, ), ( 0, 0, 1, 0, "53cb716a7cb3777f4ba1a55a241eee45ddb184601155887f90d465975aa3a714", 0, ), ( 0, 0, 1, 1, "25c93e889ffe9548f611a27d30eae3f8c7d6a57cfeb9d3ca282fdaa3c37464c0", 0, ), ( 0, 1, 0, 0, "e16fabeadd8bcb2135f50f87eb076c4c43662ed9c55f846e49772e6945446d74", 0, ), ( 0, 2, 0, 0, "a836e2f146905f6b2763cbf013a3bd3f586944fa415a31897b040b2eb53cbd71", 1, ), ( 0, 2, 3, 0, "e94c437859c3ae14a6c46a3c71d1f423c6cc1622a28a09ba404c12459fe20632", 1, ), ( 1, 0, 0, 0, "e37f48af79d74ad8618fc060cff066c6a814aefd38687133b168a4474640072f", 1, ), ( 1, 2, 3, 4, "ad875e9a938661b7928cbbefe917b67a994b76fcf8c9af4e7d31c30b9965dfd3", 1, ), ( 4, 3, 2, 1, "23e0c0e7f683cc720061da846753702ab0f07effbeb27d91e12fc806c8e89b37", 1, ), ( 0, 0, 1, 5, "28ba82826c91026cf6464d288aa48a83c16c1147674509645fdead09a8ba5a21", 0, ), ) is_coin_key = True for test_params in test_datasets: idx = test_params[0] type = test_params[1] sub_idx = test_params[2] value = test_params[3] expected_key_image_x = test_params[4] expected_key_image_y = test_params[5] key_image_x = bytearray(32) key_image_y = bytearray(1) beam.generate_key(idx, type, sub_idx, value, is_coin_key, self.seed, key_image_x, key_image_y) self.assertEqual(expected_key_image_x, bin_to_str(key_image_x)) self.assertEqual(expected_key_image_y, key_image_y[0])
def test_get_nonce_public(self): test_datasets = ( ( 1, "bc47be20f12041a1cbd1c9265b8397ed8249972ca3510629a5c6e3bd3e6e2793", 0, ), ( 2, "86820dfa982357dc9bebf7e0aa24bd800e29e9372b2c745545c037988ea1666f", 0, ), (3, "eff59e168bbfbb8696e0b695ab135a8e51d677dd11f4d444a4209c028ae43c44", 0), (4, "dc6192e3822950ee14c277aa16891461936d23aac6a283f26d1cf5580b9b286f", 1), (5, "309567c913ca0474491f9ed08e1d1da35a4c2f3a4db6c9d610220c6ccc1114d5", 0), (6, "2b070adfe1c6090280f48ea3d36e6fcd5ffe50bb5e9084af710b67786dce78af", 1), (7, "b941e433e0be60152fc7f0fefd9a2e539186dd7691c2acd040e86b89ded1732d", 1), (8, "a106ba444dc58efd0e7deacfae276a71970eb446aaa641aff31a0818400c52fa", 0), (9, "71d12f75072c62f2e2d41dcb9c06d5f1341412a189deb5e01ec007b3770fdd48", 1), (10, "4b66d33ab72fb6e30f7d3d265bb2132129dfa783ef0063514adc68f2da6a5699", 0), (11, "5f5afc9f87d9c5420007bb43f5b18b08c1ffda5095c3b85045e82248b74a4973", 0), (14, "77e8da5f5f89c5aeea33b74c20f03e9ad56ae34c693ca52722ee04eb53a04af4", 0), (15, "620033e2630dbd511bfd93e39af7a3ab7d18545d985fd21317b8689dd007f9cb", 0), (20, "4cfcfd48404e59952f3a777eef412726475fab8de47bc09515e74f923cba5d9b", 0), (42, "91079d4dd75e709e705db7bbfcdb4ac8f7c20aad91b259fba608bd3d1d1578f6", 0), ) __init_and_unlock_config() create_master_nonce(self.seed) for test_params in test_datasets: slot = test_params[0] expected_pub_x = test_params[1] expected_pub_y = test_params[2] pubkey_x, pubkey_y = get_nonce_pub(slot) self.assertEqual(bin_to_str(pubkey_x), expected_pub_x) self.assertEqual(pubkey_y[0], expected_pub_y)
def test_generate_nonce_derived(self): test_datasets = ( ( # Slot number 1, ( # Expected derivables (each next result is influenced by previous) ("907356940fcc255479509517cfb381ea8c97631f116da551e1dbe958cb74977f", 0), ("dd54c9e2da23f6918547f884dfe998db4a8724654c772c7e113f897c3c9aa414", 1), ), ), ( # Slot number 2, ( # Expected derivables (each next result is influenced by previous) ("7245e95ad17cea33fd91dffa041c93e6258c679a62651e0f155b253c29c0f4e4", 1), ("e548866f0aabe149f3111ad69b3eb49fd5955356ac01404e89ac8f5d652a20da", 1), ("df449a81066451123154ce2894f1d2cac88cf079a76a9016c94937b3934a9ad5", 1), ("5ac9af998e236b01c5b8623fd8a59a30bf4884cd1c633ba717362428739a8107", 1), ), ), ( # Slot number 20, ( # Expected derivables (each next result is influenced by previous) ("93062b41367dcf42b77b5b712d4dd3cec5b34e80defc750a4748e7e03b643027", 1), ("9c2e6c6ce8627be88e1165ed7fbc2f7d88483c59e904ff7d27e734c412747b72", 1), ("749532358b78ed8be86c4022e8241fe8a9198ce4c6f974300bfc072b67517fa7", 1), ("baa63f8cbabcfa115ade13fd876c959cc38467e9e80e052916e51f21de79ec58", 0), ("e3bf982bb5a4c49e449e7f82fb0b74fa60bb1ba033b7891797e1694969fd5630", 1), ), ), ( # Slot number 42, ( # Expected derivables (each next result is influenced by previous) ("43b867b1d20d303652879902f67c4e6bfc602429e414d9035a160c60e4d97a34", 0), ("1fca3baba4542ac31bde0ca854c2df5ee0490be6c37d9fa9ee7b81a4fea01198", 1), ("76c2ee37fce19ee912c765f9a1e1a6c477a7eae61903f60bdea263ba602faa99", 1), ("12e4d7efeee2950637b700bb1a11884af585ac15b38166b2af181af36f2126ae", 0), ("f8db921a659decdbf67556bdd11d4c416d796a8c21303f06913b89755a639f14", 0), ("cd62c77950f269d0fa9d24d08418c1c1cda6f820acfa65a23ec15373cfeeceb5", 0), ("a90626fe6ca8ff9c295a0476c6635c27b8db52fb0e1ebac5df7b948733f0eb99", 1), ), ), ) __init_and_unlock_config() create_master_nonce(self.seed) for test_params in test_datasets: slot = test_params[0] expected_derivables = test_params[1] for expected in expected_derivables: expected_pub_x = expected[0] expected_pub_y = expected[1] _, new_nonce = create_nonce(slot) pubkey_x, pubkey_y = calc_nonce_pub(new_nonce) self.assertEqual(bin_to_str(pubkey_x), expected_pub_x) self.assertEqual(pubkey_y[0], expected_pub_y)
def test_consume_nonce(self): test_datasets = ( ( # Slot number 1, ( # Expected public keys (each next result is influenced by previous) ("bc47be20f12041a1cbd1c9265b8397ed8249972ca3510629a5c6e3bd3e6e2793", 0), ("907356940fcc255479509517cfb381ea8c97631f116da551e1dbe958cb74977f", 0), ), ), ( # Slot number 2, ( # Expected public keys (each next result is influenced by previous) ("86820dfa982357dc9bebf7e0aa24bd800e29e9372b2c745545c037988ea1666f", 0), ("7245e95ad17cea33fd91dffa041c93e6258c679a62651e0f155b253c29c0f4e4", 1), ("e548866f0aabe149f3111ad69b3eb49fd5955356ac01404e89ac8f5d652a20da", 1), ("df449a81066451123154ce2894f1d2cac88cf079a76a9016c94937b3934a9ad5", 1), ("5ac9af998e236b01c5b8623fd8a59a30bf4884cd1c633ba717362428739a8107", 1), ), ), ( # Slot number 20, ( # Expected public keys (each next result is influenced by previous) ("4cfcfd48404e59952f3a777eef412726475fab8de47bc09515e74f923cba5d9b", 0), ("93062b41367dcf42b77b5b712d4dd3cec5b34e80defc750a4748e7e03b643027", 1), ("9c2e6c6ce8627be88e1165ed7fbc2f7d88483c59e904ff7d27e734c412747b72", 1), ("749532358b78ed8be86c4022e8241fe8a9198ce4c6f974300bfc072b67517fa7", 1), ("baa63f8cbabcfa115ade13fd876c959cc38467e9e80e052916e51f21de79ec58", 0), ("e3bf982bb5a4c49e449e7f82fb0b74fa60bb1ba033b7891797e1694969fd5630", 1), ), ), ( # Slot number 42, ( # Expected public keys (each next result is influenced by previous) ("91079d4dd75e709e705db7bbfcdb4ac8f7c20aad91b259fba608bd3d1d1578f6", 0), ("43b867b1d20d303652879902f67c4e6bfc602429e414d9035a160c60e4d97a34", 0), ("1fca3baba4542ac31bde0ca854c2df5ee0490be6c37d9fa9ee7b81a4fea01198", 1), ("76c2ee37fce19ee912c765f9a1e1a6c477a7eae61903f60bdea263ba602faa99", 1), ("12e4d7efeee2950637b700bb1a11884af585ac15b38166b2af181af36f2126ae", 0), ("f8db921a659decdbf67556bdd11d4c416d796a8c21303f06913b89755a639f14", 0), ("cd62c77950f269d0fa9d24d08418c1c1cda6f820acfa65a23ec15373cfeeceb5", 0), ("a90626fe6ca8ff9c295a0476c6635c27b8db52fb0e1ebac5df7b948733f0eb99", 1), ), ), ) __init_and_unlock_config() create_master_nonce(self.seed) for test_params in test_datasets: slot = test_params[0] expected_derivables = test_params[1] for expected in expected_derivables: expected_pub_x = expected[0] expected_pub_y = expected[1] pubkey_x, pubkey_y = get_nonce_pub(slot) consume_nonce(slot) #print("Slot: {}; X: {}; Y: {}".format(slot, bin_to_str(pubkey_x), pubkey_y[0])) self.assertEqual(bin_to_str(pubkey_x), expected_pub_x) self.assertEqual(pubkey_y[0], expected_pub_y)
def test_sign_message(self): test_datasets = ( ( 0, 0, "hello world", "94bb1f34c5e970136d4f1ff769e3332e4e5f430122ebe7e7720c754713adfab6", 0, "9f01b0eb202cd0780e35f0cf20c06cd930af8bb55db9c9c3e2146f34de1239d9", ), ( 0, 1, "hello world", "39e2014221f59c4f887be7158df22ef996ff061b7411a6d915ac91dc5a336d4b", 0, "a7b9447e39eb14e0c3167496ba53b3253918577c1c4bc0084fe8105ea6d520e5", ), ( 5, 2, "hello world", "848824bb7e3ee53ecc0d9ecdbacd8e7015d80ebaa3f50a0147d65a92e8d61894", 0, "d6d4b41ba3c858d99bb454155b9e9d531c35fc8f1535807a38e9509cb7314a75", ), ( 0, 0, "hello world", "9f315b9105225a0493d072d345b0e9a96e7c68395f004676c508259a16ade81e", 1, "3a303f731efb81d035cc98d835b66e109dd17921ec0e14091aecc72d64d7ab40", ), ( 1, 8, "hello from BEAM", "50d1f214d345a0f9cab5f7299f8e300ff1ee7c1201646bd67132203526593263", 0, "a49d590c6894f1675b5d6a43bb7845c9277d66d70c1114927a7870c6c6e95492", ), ( 4, 4, "abcdefg", "ec088ee2b66fab3b3c43337e8ad992dcc81e69a55f40b36b181a6899fc08a0f8", 0, "177a773a6278a87f03606edb5237f83bd40ea2e2954649e20930c42eb4bd7f17", ), ) print() for test_params in test_datasets: kdf = get_beam_kdf(self.mnemonic) kid_idx = test_params[0] kid_sub_idx = test_params[1] message = test_params[2] expected_nonce_pub_x = test_params[3] expected_nonce_pub_y = test_params[4] expected_sign_k = test_params[5] sign_nonce_pub_x = bytearray(32) sign_nonce_pub_y = bytearray(1) sign_k = bytearray(32) sk = get_beam_sk(kid_idx, kid_sub_idx, kdf) digest = message_digest(message) beam.signature_sign(digest, sk, sign_nonce_pub_x, sign_nonce_pub_y, sign_k) #print("Idx: {}; Sub idx: {}, message: {}".format(kid_idx, kid_sub_idx, message)) #print("Digest: {}; Sk: {}".format(bin_to_str(digest), bin_to_str(sk))) #print("X: {}, y: {}, k: {}".format(bin_to_str(sign_nonce_pub_x), sign_nonce_pub_y[0], bin_to_str(sign_k))) self.assertEqual(bin_to_str(sign_nonce_pub_x), expected_nonce_pub_x) self.assertEqual(sign_nonce_pub_y[0], expected_nonce_pub_y) self.assertEqual(bin_to_str(sign_k), expected_sign_k)
def test_sign_transaction(self): test_datasets = ( ( # Inputs: [ # KIDV: # idx, type, sub_idx, value [1, 1, 1, 2], [2, 2, 2, 5], ], # Outputs: [ # KIDV: # idx, type, sub_idx, value [3, 3, 3, 3], ], # Nonce slot: 2, # Kernel params: # fee, min_height, max_height, # commitment_x, commitment_y, # multisig_nonce_x, multisig_nonce_y, # offset_sk # expected_signature, expected_is_signed 1, 1, 5, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", 0, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", 0, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", "614856ca69245fd9c6e8db15a256c050ca078e79a6f49e61e24688fdcad73bf6", True), ([ [1, 0, 1, 8], [2, 0, 0, 5], ], [ [1, 0, 1, 4], ], 2, 1, 1, 5, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", 0, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", 0, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", "7c4fe694451b28159e5407714072acd1eae4da18aef1dfd42bb165405f529a04", True), ([ [0, 0, 0, 40], ], [ [0, 0, 0, 16], [0, 0, 0, 24], ], 1, 0, 25000, 27500, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", 0, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", 0, "0x12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef12abcdef", "60e3e9d87bd264bdcac4518284bd4f850561c3bb251bd758bb1349a44188a28c", True), ) config.init() config.wipe() config.unlock(pin_to_int('')) create_master_nonce(self.seed) for test_params in test_datasets: inputs = create_kidv_list_from(test_params[0]) outputs = create_kidv_list_from(test_params[1]) nonce_slot = test_params[2] fee = test_params[3] min_height = test_params[4] max_height = test_params[5] commitment_x = test_params[6] commitment_y = test_params[7] multisig_nonce_x = test_params[8] multisig_nonce_y = test_params[9] offset_sk = test_params[10] expected_signature = test_params[11] expected_is_signed = test_params[12] tm = beam.TransactionMaker() sk_total, value_transferred = sign_tx_part_1( tm, self.mnemonic, inputs, outputs, fee, min_height, max_height, commitment_x, commitment_y, multisig_nonce_x, multisig_nonce_y, nonce_slot, offset_sk) signature, is_signed = sign_tx_part_2(tm, sk_total, nonce_slot) self.assertEqual(bin_to_str(signature), expected_signature) self.assertEqual(is_signed, expected_is_signed)