async def txn_endorse(
        self,
        request_json: str,
    ) -> str:
        """Endorse (sign) the provided transaction."""
        try:
            request = ledger.build_custom_request(request_json)
        except VdrError as err:
            raise BadLedgerRequestError(
                "Cannot endorse invalid request") from err

        async with self.profile.session() as session:
            wallet = session.inject(BaseWallet)
            sign_did = await wallet.get_public_did()
            if not sign_did:
                raise BadLedgerRequestError(
                    "Cannot endorse transaction without a public DID")
            request.set_multi_signature(
                sign_did.did,
                await wallet.sign_message(request.signature_input,
                                          sign_did.verkey),
            )
            del wallet

        return request.body
Beispiel #2
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)
    async def _submit(
        self,
        request: Union[str, Request],
        sign: bool = None,
        taa_accept: bool = None,
        sign_did: DIDInfo = sentinel,
        write_ledger: bool = True,
    ) -> dict:
        """
        Sign and submit request to ledger.

        Args:
            request_json: The json string to submit
            sign: whether or not to sign the request
            taa_accept: whether to apply TAA acceptance to the (signed, write) request
            sign_did: override the signing DID

        """

        if not self.pool_handle:
            raise ClosedPoolError(
                f"Cannot sign and submit request to closed pool '{self.pool_name}'"
            )

        if isinstance(request, str):
            request = ledger.build_custom_request(request)
        elif not isinstance(request, Request):
            raise BadLedgerRequestError("Expected str or Request")

        if sign is None or sign:
            if sign_did is sentinel:
                sign_did = await self.get_wallet_public_did()
            if sign is None:
                sign = bool(sign_did)

        if sign:
            if not sign_did:
                raise BadLedgerRequestError(
                    "Cannot sign request without a public DID")

            if taa_accept or taa_accept is None:
                acceptance = await self.get_latest_txn_author_acceptance()
                if acceptance:
                    acceptance = {
                        "taaDigest": acceptance["digest"],
                        "mechanism": acceptance["mechanism"],
                        "time": acceptance["time"],
                    }
                    request.set_txn_author_agreement_acceptance(acceptance)

            async with self.profile.session() as session:
                wallet = session.inject(BaseWallet)
                request.set_signature(await wallet.sign_message(
                    request.signature_input, sign_did.verkey))
                del wallet

        if not write_ledger:
            return json.loads(request.body)

        try:
            request_result = await self.pool.handle.submit_request(request)
        except VdrError as err:
            raise LedgerTransactionError("Ledger request error") from err

        return request_result