def recover_wallet(sk, **kwargs): if not kwargs.get('did'): did_type = did.AbtDid(**kwargs, form='short') else: did_type = did.AbtDid.parse_type_from_did(kwargs.get('did')) return protos.WalletInfo(sk=sk, pk=did_type.signer.sk_to_pk(sk), address=did_type.sk_to_did(sk))
def deploy(m_wallet): with open(input) as f: raw = json.load(f).get('event_chain') logger.info("Protocol json loaded!") decoded = utils.multibase_b64decode(raw) itx = utils.parse_to_proto(decoded, protos.DeployProtocolTx) itx_hash = mcrypto.Hasher('sha3').hash(itx.SerializeToString()) addr = did.AbtDid(role_type='tx', form='short').hash_to_did(itx_hash) itx.address = addr res = forge.rpc.send_itx(tx=itx, wallet=m_wallet, type_url='fg:t:deploy_protocol', nonce=0) if res.code == 0: logger.info("Success: event_chain tx deployed.") else: logger.error("Fail: Error in deploying event_chain tx.") logger.error(res)
def deploy(forge, input_file): m_wallet = get_moderator_wallet() with open(input_file) as f: raw = list(json.load(f).values())[0] logger.info("Protocol json loaded!") decoded = utils.multibase_b64decode(raw) itx = utils.parse_to_proto(decoded, protos.DeployProtocolTx) itx_hash = mcrypto.Hasher('sha3').hash(itx.SerializeToString()) addr = did.AbtDid(role_type='tx', form='short').hash_to_did(itx_hash) itx.address = addr res = forge.rpc.send_itx(tx=itx, wallet=m_wallet, type_url='fg:t:deploy_protocol', nonce=0) if res.code == 0: logger.info("Successfully deployed new transaction protocol.") else: logger.error("Fail to deploy new transaction protocol.") logger.error(res)
def to_asset_address(itx): """ Calculate asset address for provided CreateAssetTx Args: did_address(string): user's did address to create this asset itx(:obj:`google.protobuf.any`): encoded createAssetTx Returns: asset_address(string) Examples: >>> from forge_sdk import protos, utils >>> itx = protos.CreateAssetTx(data=utils.encode_to_any(None,b'123')) >>> res = to_asset_address(itx) """ data = itx.SerializeToString() asset_did = did.AbtDid(role_type='asset', form='short') asset_address = asset_did.pk_to_did(data) return asset_address
def generate_wallet(**kwargs): did_type = did.AbtDid(**kwargs, form='short') sk, pk, address = did_type.new() return protos.WalletInfo(sk=sk, pk=pk, address=address)
def to_tx_address(tx): tx_did = did.AbtDid(role_type='tx', form='short') tx_hash = Hasher('sha3').hash(tx.SerializeToString()) return tx_did.hash_to_did(tx_hash)
def to_delegate_address(addr1, addr2): data = (addr1 + addr2).encode() delegate_did = did.AbtDid(role_type='delegate', form='short') return delegate_did.hash_to_did(Hasher('sha3').hash(data))
def to_tether_address(hash): tether_did = did.AbtDid(role_type='tether', hash_type='sha2', round=1, form='short') return tether_did.hash_to_did(hash)
def to_stake_address(addr1, addr2): hasher = Hasher('sha3') hash = hasher.hash((addr1 + addr2).encode()) stake_did = did.AbtDid(role_type='stake', form='short') stake_address = stake_did.hash_to_did(hash) return stake_address