Ejemplo n.º 1
0
    async def fetch_schema_by_seq_no(self, seq_no: int):
        """
        Fetch a schema by its sequence number.

        Args:
            seq_no: schema ledger sequence number

        Returns:
            Indy schema dict

        """
        # get txn by sequence number, retrieve schema identifier components
        try:
            request = ledger.build_get_txn_request(None, None, seq_no=seq_no)
        except VdrError as err:
            raise LedgerError(
                "Exception when building get-txn request") from err

        response = await self._submit(request)

        # transaction data format assumes node protocol >= 1.4 (circa 2018-07)
        data_txn = (response.get("data", {}) or {}).get("txn", {})
        if data_txn.get("type",
                        None) == "101":  # marks indy-sdk schema txn type
            (origin_did, name, version) = (
                data_txn["metadata"]["from"],
                data_txn["data"]["data"]["name"],
                data_txn["data"]["data"]["version"],
            )
            schema_id = f"{origin_did}:2:{name}:{version}"
            return await self.get_schema(schema_id)

        raise LedgerTransactionError(
            f"Could not get schema from ledger for seq no {seq_no}")
Ejemplo n.º 2
0
async def fetch_status(genesis_path: str,
                       nodes: str = None,
                       ident: DidKey = None,
                       status_only: bool = False):
    pool = await open_pool(transactions_path=genesis_path)
    result = []

    if ident:
        request = build_get_validator_info_request(ident.did)
        ident.sign_request(request)
    else:
        request = build_get_txn_request(None, 1, 1)

    from_nodes = []
    if nodes:
        from_nodes = nodes.split(",")
    response = await pool.submit_action(request, node_aliases=from_nodes)

    primary = ""
    packages = {}
    for node, val in response.items():
        jsval = []
        status = {}
        errors = []
        warnings = []
        entry = {"name": node}
        try:
            jsval = json.loads(val)
            if not primary:
                primary = await get_primary_name(jsval, node)
            errors, warnings = await detect_issues(jsval, node, primary, ident)
            packages[node] = await get_package_info(jsval)
        except json.JSONDecodeError:
            errors = [val]  # likely "timeout"

        # Status Summary
        entry["status"] = await get_status_summary(jsval, errors)
        # Errors / Warnings
        if len(errors) > 0:
            entry["status"]["errors"] = len(errors)
            entry["errors"] = errors
        if len(warnings) > 0:
            entry["status"]["warnings"] = len(warnings)
            entry["warnings"] = warnings
        # Full Response
        if not status_only and jsval:
            entry["response"] = jsval

        result.append(entry)

    # Package Mismatches
    if packages:
        await merge_package_mismatch_info(result, packages)

    print(json.dumps(result, indent=2))
Ejemplo n.º 3
0
    async def rotate_public_did_keypair(self, next_seed: str = None) -> None:
        """
        Rotate keypair for public DID: create new key, submit to ledger, update wallet.

        Args:
            next_seed: seed for incoming ed25519 keypair (default random)
        """
        # generate new key
        async with self.profile.transaction() as txn:
            wallet = txn.inject(BaseWallet)
            public_info = await wallet.get_public_did()
            public_did = public_info.did
            verkey = await wallet.rotate_did_keypair_start(
                public_did, next_seed)
            del wallet
            await txn.commit()

        # submit to ledger (retain role and alias)
        nym = self.did_to_nym(public_did)
        try:
            nym_req = ledger.build_get_nym_request(public_did, nym)
        except VdrError as err:
            raise LedgerError("Exception when building nym request") from err

        response = await self._submit(nym_req)
        data = json.loads(response["data"])
        if not data:
            raise BadLedgerRequestError(
                f"Ledger has no public DID for wallet {self.profile.name}")
        seq_no = data["seqNo"]

        try:
            txn_req = ledger.build_get_txn_request(None, None, seq_no)
        except VdrError as err:
            raise LedgerError(
                "Exception when building get-txn request") from err

        txn_resp = await self._submit(txn_req)
        txn_resp_data = txn_resp["data"]
        if not txn_resp_data:
            raise BadLedgerRequestError(
                f"Bad or missing ledger NYM transaction for DID {public_did}")
        txn_data_data = txn_resp_data["txn"]["data"]
        role_token = Role.get(txn_data_data.get("role")).token()
        alias = txn_data_data.get("alias")
        await self.register_nym(public_did, verkey, role_token, alias)

        # update wallet
        async with self.profile.transaction() as txn:
            wallet = txn.inject(BaseWallet)
            await wallet.rotate_did_keypair_apply(public_did)
            del wallet
            await txn.commit()
Ejemplo n.º 4
0
    async def fetch(self, network_id: str, monitor_plugins: PluginCollection, nodes: str = None, ident: DidKey = None):
        result = []
        verifiers = {}

        pool, network_name = await self.pool_collection.get_pool(network_id)
        if ident:
            log(f"Building request with did: {ident.did} ...")
            request = build_get_validator_info_request(ident.did)
            ident.sign_request(request)
        else:
            log("Building an anonymous request ...")
            request = build_get_txn_request(None, 1, 1)

        from_nodes = []
        if nodes:
            from_nodes = nodes.split(",")

        try:
            # Introduced in https://github.com/hyperledger/indy-vdr/commit/ce0e7c42491904e0d563f104eddc2386a52282f7
            log("Getting list of verifiers ...")
            verifiers = await pool.get_verifiers()
        except AttributeError:
            log("Unable to get list of verifiers. Please make sure you have the latest version of indy-vdr.")
            pass

        if verifiers and from_nodes:
            for node in from_nodes:
                if not node in verifiers:
                    raise NodeNotFound(f'{node} is not a member of {network_name}.')

        log("Submitting request ...")
        response = await pool.submit_action(request, node_aliases = from_nodes)

        log("Passing results to plugins for processing ...")
        result = await monitor_plugins.apply_all_plugins_on_value(result, network_name, response, verifiers)
        log("Processing complete.")
        return result
Ejemplo n.º 5
0
async def fetch_status(genesis_path: str, nodes: str = None, ident: DidKey = None, network_name: str = None):
    # Start Of Engine
    attempt = 3
    while attempt:
        try:
            pool = await open_pool(transactions_path=genesis_path)
        except:
            log("Pool Timed Out! Trying again...")
            if not attempt:
                print("Unable to get pool Response! 3 attempts where made. Exiting...")
                exit()
            attempt -= 1
            continue
        break

    result = []
    verifiers = {}

    if ident:
        request = build_get_validator_info_request(ident.did)
        ident.sign_request(request)
    else:
        request = build_get_txn_request(None, 1, 1)

    from_nodes = []
    if nodes:
        from_nodes = nodes.split(",")
    response = await pool.submit_action(request, node_aliases = from_nodes)
    try:
        # Introduced in https://github.com/hyperledger/indy-vdr/commit/ce0e7c42491904e0d563f104eddc2386a52282f7
        verifiers = await pool.get_verifiers()
    except AttributeError:
        pass
    # End Of Engine

    result = await monitor_plugins.apply_all_plugins_on_value(result, network_name, response, verifiers)
    print(json.dumps(result, indent=2))
async def get_txn(pool: Pool, seq_no: int):
    req = build_get_txn_request(None, LedgerType.DOMAIN, seq_no)
    return await pool.submit_request(req)
Ejemplo n.º 7
0
async def basic_test(transactions_path):
    pool = await open_pool(transactions_path=transactions_path)
    log(f"Created pool: {pool}")

    test_req = {
        "operation": {
            "data": 1,
            "ledgerId": 1,
            "type": "3"
        },
        "protocolVersion": 2,
        "reqId": 123,
        "identifier": "LibindyDid111111111111"
    }
    req = build_custom_request(test_req)
    log("Custom request body:", req.body)
    #
    sig_in = req.signature_input
    log("Custom request signature input:", sig_in)

    req = build_get_txn_author_agreement_request()
    log(await pool.submit_request(req))

    req = build_get_acceptance_mechanisms_request()
    log(await pool.submit_request(req))

    acceptance = prepare_txn_author_agreement_acceptance("acceptance text",
                                                         "1.1.1",
                                                         None,
                                                         mechanism="manual")
    req = build_get_txn_request(None, 1, 15)
    req.set_txn_author_agreement_acceptance(acceptance)
    req.set_endorser("V4SGRU86Z58d6TV7PBUe6f")
    log("Request with TAA acceptance and endorser:", req.body)

    # req = build_disable_all_txn_author_agreements_request("V4SGRU86Z58d6TV7PBUe6f")
    # log(await pool.submit_request(req))

    txn = await get_txn(pool, 11)
    log(json.dumps(txn, indent=2))

    req = build_get_schema_request(
        None, "6qnvgJtqwK44D8LFYnV5Yf:2:relationship.dflow:1.0.0")
    log("Get schema request:", req.body)

    req = build_get_cred_def_request(None,
                                     "A9Rsuu7FNquw8Ne2Smu5Nr:3:CL:15:tag")
    log("Get cred def request:", req.body)

    revoc_id = ("L5wx9FUxCDpFJEdFc23jcn:4:L5wx9FUxCDpFJEdFc23jcn:3:CL:1954:"
                "default:CL_ACCUM:c024e30d-f3eb-42c5-908a-ff885667588d")

    req = build_get_revoc_reg_def_request(None, revoc_id)
    log("Get revoc reg def request:", req.body)

    req = build_get_revoc_reg_request(None, revoc_id, timestamp=1)
    log("Get revoc reg request:", req.body)

    req = build_get_revoc_reg_delta_request(None,
                                            revoc_id,
                                            from_ts=None,
                                            to_ts=1)
    log("Get revoc reg delta request:", req.body)
Ejemplo n.º 8
0
async def fetch_status(genesis_path: str, nodes: str = None, ident: DidKey = None, status_only: bool = False, alerts_only: bool = False):
    pool = await open_pool(transactions_path=genesis_path)
    result = []
    verifiers = {}

    if ident:
        request = build_get_validator_info_request(ident.did)
        ident.sign_request(request)
    else:
        request = build_get_txn_request(None, 1, 1)

    from_nodes = []
    if nodes:
        from_nodes = nodes.split(",")
    response = await pool.submit_action(request, node_aliases = from_nodes)
    try:
        # Introduced in https://github.com/hyperledger/indy-vdr/commit/ce0e7c42491904e0d563f104eddc2386a52282f7
        verifiers = await pool.get_verifiers()
    except AttributeError:
        pass

    primary = ""
    packages = {}
    for node, val in response.items():
        jsval = []
        status = {}
        errors = []
        warnings = []
        info = []
        entry = {"name": node}
        try:
            await get_node_addresses(entry, verifiers)
            jsval = json.loads(val)
            if not primary:
                primary = await get_primary_name(jsval, node)
            errors, warnings = await detect_issues(jsval, node, primary, ident)
            info = await get_info(jsval, ident)
            packages[node] = await get_package_info(jsval)
        except json.JSONDecodeError:
            errors = [val]  # likely "timeout"

        # Status Summary
        entry["status"] = await get_status_summary(jsval, errors)
        # Info
        if len(info) > 0:
            entry["status"]["info"] = len(info)
            entry["info"] = info
        # Errors / Warnings
        if len(errors) > 0:
            entry["status"]["errors"] = len(errors)
            entry["errors"] = errors
        if len(warnings) > 0:
            entry["status"]["warnings"] = len(warnings)
            entry["warnings"] = warnings
        # Full Response
        if not status_only and jsval:
            entry["response"] = jsval

        result.append(entry)

    # Package Mismatches
    if packages:
        await merge_package_mismatch_info(result, packages)

    # Connection Issues
    await detect_connection_issues(result)

    # Filter on alerts
    if alerts_only:
        filtered_result = []
        for item in result:
            if ("info" in item["status"]) or ("warnings" in  item["status"]) or ("errors" in  item["status"]):
                filtered_result.append(item)
        result = filtered_result

    print(json.dumps(result, indent=2))