123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contexttypet={pkh:Signature.Public_key_hash.t;pk:Signature.Public_key.t;sk:Signature.Secret_key.t;}typeaccount=tletknown_accounts=Signature.Public_key_hash.Table.create17letrandom_seed~rng_state=Bytes.initTezos_crypto.Hacl.Ed25519.sk_size(fun_i->Char.chr(Random.State.intrng_state256))letrandom_algo~rng_state:Signature.algo=matchRandom.State.intrng_state3with|0->Ed25519|1->Secp256k1|2->P256|3->Bls|_->assertfalseletnew_account?(rng_state=Random.State.make_self_init())?(seed=random_seed~rng_state)?(algo=random_algo~rng_state)()=letpkh,pk,sk=Signature.generate_key~algo~seed()inletaccount={pkh;pk;sk}inSignature.Public_key_hash.Table.addknown_accountspkhaccount;accountletadd_account({pkh;_}asaccount)=Signature.Public_key_hash.Table.addknown_accountspkhaccountletactivator_account=letseed=random_seed~rng_state:(Random.State.make[|0x1337533D|])innew_account~seed()letfindpkh=letopenLwt_result_syntaxinmatchSignature.Public_key_hash.Table.findknown_accountspkhwith|Somek->returnk|None->failwith"Missing account: %a"Signature.Public_key_hash.pppkhletfind_alternatepkh=letexceptionFoundoftintrySignature.Public_key_hash.Table.iter(funpkh'account->ifnot(Signature.Public_key_hash.equalpkhpkh')thenraise(Foundaccount))known_accounts;raiseNot_foundwithFoundaccount->accountletdummy_account=letseed=random_seed~rng_state:(Random.State.make[|0x1337533D;0x1337533D|])innew_account~seed()letdefault_initial_balance=Tez.of_mutez_exn4_000_000_000_000Lletgenerate_accounts?rng_staten:tlisttzresult=Signature.Public_key_hash.Table.clearknown_accounts;List.init~when_negative_length:[]n(fun_i->new_account?rng_state())letcommitment_secret=Blinded_public_key_hash.activation_code_of_hex"aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb"|>WithExceptions.Option.get~loc:__LOC__letnew_commitment?seed()=letopenLwt_result_wrap_syntaxinletpkh,pk,sk=Signature.generate_key?seed~algo:Ed25519()inletunactivated_account={pkh;pk;sk}inletopenCommitmentinletpkh=matchpkhwithEd25519pkh->pkh|_->assertfalseinletbpkh=Blinded_public_key_hash.of_ed25519_pkhcommitment_secretpkhinlet*?@amount=Tez.(one*?4_000L)inreturn(unactivated_account,{blinded_public_key_hash=bpkh;amount})letpkh_of_contract_exn=function|Contract.Implicitpkh->pkh|Originated_->assertfalseletmake_bootstrap_account?(balance=default_initial_balance)?(delegate_to=None)?(consensus_key=None)account=Parameters.{public_key_hash=account.pkh;public_key=Someaccount.pk;amount=balance;delegate_to;consensus_key;}letrecmake_bootstrap_accounts?(bootstrap_balances=[])?(bootstrap_delegations=[])?(bootstrap_consensus_keys=[])accounts=letdecons_of_opt=functionx::xs->(x,xs)|[]->(None,[])inletdecons=functionx::xs->(Somex,xs)|[]->(None,[])inmatchaccountswith|account::accounts->letbalance,bootstrap_balances=deconsbootstrap_balancesinletdelegate_to,bootstrap_delegations=decons_of_optbootstrap_delegationsinletconsensus_key,bootstrap_consensus_keys=decons_of_optbootstrap_consensus_keysinmake_bootstrap_account?balance:(Option.mapTez.of_mutez_exnbalance)~delegate_to~consensus_keyaccount::make_bootstrap_accounts~bootstrap_balances~bootstrap_delegations~bootstrap_consensus_keysaccounts|[]->[]