def sign_tx_part_1(transaction_maker, mnemonic, inputs, outputs, fee, min_height, max_height, commitment_x, commitment_y, multisig_nonce_x, multisig_nonce_y, nonce_slot, offset_sk): transaction_maker.set_transaction_data(fee, min_height, max_height, commitment_x, commitment_y, multisig_nonce_x, multisig_nonce_y, nonce_slot, offset_sk) for input in inputs: kidv = beam.KeyIDV() kidv.set(input.idx, input.type, input.sub_idx, input.value) transaction_maker.add_input(kidv) for output in outputs: kidv = beam.KeyIDV() kidv.set(output.idx, output.type, output.sub_idx, output.value) transaction_maker.add_output(kidv) seed = beam.from_mnemonic_beam(mnemonic) sk_total = bytearray(32) value_transferred = transaction_maker.sign_transaction_part_1( seed, sk_total) return (sk_total, value_transferred)
class TestBeamGenerateRangeproof(unittest.TestCase): mnemonic = "all all all all all all all all all all all all" seed = beam.from_mnemonic_beam(mnemonic) 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 get_beam_kdf(mnemonic=None): if mnemonic is None: # Get kdf mnemonic = storage.device.get_mnemonic_secret() seed = beam.from_mnemonic_beam(mnemonic) seed_size = 32 secret_key = bytearray(32) cofactor = bytearray(32) beam.seed_to_kdf(seed, seed_size, secret_key, cofactor) return (secret_key, cofactor)
async def generate_rangeproof(ctx, msg): asset_id = bytearray(0) rangeproof_data = bytearray(688) mnemonic = storage.device.get_mnemonic_secret() seed = beam.from_mnemonic_beam(mnemonic) beam.generate_rp_from_key_idv(msg.kidv.idx, msg.kidv.type, msg.kidv.sub_idx, msg.kidv.value, asset_id, msg.is_public, seed, rangeproof_data) return BeamRangeproofData(data=rangeproof_data, is_public=msg.is_public)
async def generate_key(ctx, msg): key_image_x = bytearray(32) key_image_y = bytearray(1) mnemonic = storage.get_mnemonic_secret() seed = beam.from_mnemonic_beam(mnemonic) beam.generate_key(msg.kidv.idx, msg.kidv.type, msg.kidv.sub_idx, msg.kidv.value, msg.is_coin_key, seed, key_image_x, key_image_y) return BeamECCPoint(x=key_image_x, y=int(key_image_y[0]))
class TestBeamGetOwnerKey(unittest.TestCase): mnemonic = "abc abc abc abc abc abc abc abc abc abc abc abc" seed = beam.from_mnemonic_beam(mnemonic) def test_get_owner_key(self): test_suite = ( ("1234", "YrJfzUs9hCG1JG1dknRxfou6NjRPn+Yh0FYlIHJ3uUq8LF81GUG2zYutSna7BgMDaH+K731lyikWmmtk5k0IyPK/SnmoniIc9irYJ0TWZSGlRC3ctL1Ccuip8fM13S4omMNLmKf0JzIj+jy2\n"), ("abcd", "YC0lfYSLKzUxHDdauwFQ0yAisxwPZrvOT3xR3hF4qCAVvoHIm10SmnDwj26CgtUEEtFFDAgNMQX5bgnsdBTYick9eZ14azERxplja/zXzY7R4z/SBnO6q8M10pR33cBnOYkq4lnFg8LtUF7F\n"), ("keykeykey", "myoDbg9dafcY/GyknXORNqkXNZdly5MqM1u30Js3PL+wLcjsnYPf5KNxxQY3MgqIBghu5KFwN7A27J/rPol52QBnnntodTga9volL8STzhWZPwSnboapz/MRV2HAL7U/DMEFyldd49HQQ6Fd\n"), ("work", "Wyen27GnxY24BV/sohamyOy2Er6m/Uuz2bFb+PJzrD5Av9iwKF0p+wPs7bWmcoZ0N3WGCMhn+FSYBbHDI37ngBbpZFDzx/Jzrrq+J39QgCzcQx/clWI9WigvsCEuvXDCTh1ymWIoalugnDCe\n"), ("beam", "2PaixGmhXXW8JvzFPLVVnxWAvx3NpWI8X+4VgL+BA159qfXmwcMUZkYAf8vj9WSpOtuszt00vTRI94cFiCZ0UU513qrxjYbc301PCUpiUR2I1qBoLr+2mFEgFMSJ/gCIx4KsjYcuxNwoagZv\n"), ) for test_params in test_suite: passphrase = test_params[0] expected_owner_key = test_params[1] owner_key = generate_owner_key(passphrase, self.mnemonic) self.assertEqual(str(owner_key, 'utf-8'), expected_owner_key)
class TestBeamGenerateKey(unittest.TestCase): mnemonic = "abc abc abc abc abc abc abc abc abc abc abc abc" seed = beam.from_mnemonic_beam(mnemonic) 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])
class TestBeamGenerateNonce(unittest.TestCase): mnemonic = "all all all all all all all all all all all all" seed = beam.from_mnemonic_beam(mnemonic) def test_master_nonce(self): self.assertEqual(is_master_nonce_created(), False) config.init() config.wipe() config.unlock(pin_to_int('')) self.assertEqual(is_master_nonce_created(), False) create_master_nonce(self.seed) self.assertEqual(is_master_nonce_created(), True) 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_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_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_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)
class TestBeamSignTransaction(unittest.TestCase): mnemonic = "all all all all all all all all all all all all" seed = beam.from_mnemonic_beam(mnemonic) 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)