Esempio n. 1
0
 def getSchema(self,
               author: str,
               schemaName: str,
               schemaVersion: str,
               isCommitted=True) -> (str, int, int, list):
     assert author is not None
     assert schemaName is not None
     assert schemaVersion is not None
     path = domain.make_state_path_for_schema(author, schemaName, schemaVersion)
     try:
         keys, seqno, lastUpdateTime, proof = self.lookup(path, isCommitted)
         return keys, seqno, lastUpdateTime, proof
     except KeyError:
         return None, None, None, None
 def getSchema(self,
               author: str,
               schemaName: str,
               schemaVersion: str,
               isCommitted=True) -> (str, int, int, list):
     assert author is not None
     assert schemaName is not None
     assert schemaVersion is not None
     path = domain.make_state_path_for_schema(author, schemaName, schemaVersion)
     try:
         keys, seqno, lastUpdateTime, proof = self.lookup(path, isCommitted)
         return keys, seqno, lastUpdateTime, proof
     except KeyError:
         return None, None, None, None
Esempio n. 3
0
 def get_schema(self,
                author: str,
                schema_name: str,
                schema_version: str,
                is_committed=True,
                with_proof=True) -> (str, int, int, list):
     assert author is not None
     assert schema_name is not None
     assert schema_version is not None
     path = domain.make_state_path_for_schema(author, schema_name, schema_version)
     try:
         keys, seq_no, last_update_time, proof = self.lookup(path, is_committed, with_proof=with_proof)
         return keys, seq_no, last_update_time, proof
     except KeyError:
         return None, None, None, None
Esempio n. 4
0
def test_state_proofs_for_get_schema(write_manager, read_manager, db_manager):
    # Adding schema
    nym = 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'

    seq_no = 0
    txn_time = int(time.time())
    identifier = "6ouriXMZkLeHsuXrN1X1fd"

    schema_name = "schema_a"
    schema_version = "1.0"
    # data = '{"name": "schema_a", "version": "1.0"}'
    schema_key = {SCHEMA_NAME: schema_name, SCHEMA_VERSION: schema_version}
    data = {**schema_key, SCHEMA_ATTR_NAMES: ["Some_Attr", "Attr1"]}
    txn = {
        TXN_TYPE: SCHEMA,
        DATA: data,
    }
    txn = append_txn_metadata(reqToTxn(
        Request(operation=txn,
                protocolVersion=CURRENT_PROTOCOL_VERSION,
                identifier=identifier)),
                              seq_no=seq_no,
                              txn_time=txn_time)
    txn = append_payload_metadata(txn, frm=nym)

    write_manager.update_state(txn)
    db_manager.get_state(DOMAIN_LEDGER_ID).commit()
    multi_sig = save_multi_sig(db_manager)

    # Getting schema
    request = Request(operation={
        TARGET_NYM: nym,
        DATA: schema_key,
        TXN_TYPE: GET_SCHEMA
    },
                      signatures={},
                      protocolVersion=CURRENT_PROTOCOL_VERSION)

    result = read_manager.get_result(request)
    proof = extract_proof(result, multi_sig)
    assert result[DATA] == data

    data.pop(NAME)
    data.pop(VERSION)

    # Verifying signed state proof
    path = domain.make_state_path_for_schema(nym, schema_name, schema_version)
    assert is_proof_verified(db_manager, proof, path, data, seq_no, txn_time)
Esempio n. 5
0
def test_state_proofs_for_get_schema(request_handler):
    # Adding schema
    nym = 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'

    seq_no = 0
    txn_time = int(time.time())

    schema_name = "schema_a"
    schema_version = "1.0"
    # data = '{"name": "schema_a", "version": "1.0"}'
    schema_key = {NAME: schema_name, VERSION: schema_version}
    data = {**schema_key, "Some_Attr": "Attr1"}
    txn = {
        TXN_TYPE: SCHEMA,
        IDENTIFIER: nym,
        f.SEQ_NO.nm: seq_no,
        DATA: data,
        TXN_TIME: txn_time,
    }

    request_handler._addSchema(txn)
    request_handler.state.commit()
    multi_sig = save_multi_sig(request_handler)

    # Getting schema
    request = Request(
        operation={
            TARGET_NYM: nym,
            DATA: schema_key
        },
        signatures={},
        protocolVersion=CURRENT_PROTOCOL_VERSION
    )

    result = request_handler.handleGetSchemaReq(request)
    proof = extract_proof(result, multi_sig)
    result[DATA].pop(NAME)
    result[DATA].pop(VERSION)
    assert result[DATA] == data

    # Verifying signed state proof
    path = domain.make_state_path_for_schema(nym, schema_name, schema_version)
    assert is_proof_verified(request_handler,
                             proof, path,
                             data, seq_no, txn_time)