def test_all_error_codes(): max = 0 assert (VcxError(1079).error_msg == "Wallet Not Found") for e in ErrorCode: assert (VcxError(int(e)) != "Unknown Error") max = int(e) assert (VcxError(max + 1).error_msg == "Unknown Error")
async def deserialize(data: dict): """ Create the object from a previously serialized object. :param data: The output of the "serialize" call Example: source_id = 'foobar123' name = 'Address Schema' version = '1.0' attrs = ['address', 'city', 'state'] payment_handle = 0 schema1 = await Schema.create(source_id, name, version, attrs, payment_handle) data1 = await schema1.serialize() :return: A re-instantiated object """ try: # Todo: Find better way to access attr_names. Potential for issues. schema = await Schema._deserialize("vcx_schema_deserialize", json.dumps(data), data['data']['source_id'], data['data']['name'], data['data']['version'], data['data']['data']) schema.schema_id = await schema.get_schema_id() return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema)
def default_logger(): pattern = "info" c_pattern = c_char_p(pattern.encode('utf-8')) name = 'vcx_set_default_logger' err = getattr(_cdll(), name)(c_pattern) if err != ErrorCode.Success: raise VcxError(ErrorCode(err))
async def lookup(source_id: str, schema_id: str): """ Create a new schema object from an existing ledger schema :param source_id: Institution's personal identification for the schema :param schema_id: Ledger schema ID for lookup :return: schema object """ try: schema = Schema(source_id, '', '', []) if not hasattr(Schema.lookup, "cb"): schema.logger.debug( "vcx_schema_get_attributes: Creating callback") Schema.lookup.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_source_id = c_char_p(source_id.encode('utf-8')) c_schema_id = c_char_p(schema_id.encode('utf-8')) handle, data = await do_call('vcx_schema_get_attributes', c_source_id, c_schema_id, Schema.lookup.cb) schema.logger.debug("created schema object") schema_result = json.loads(data.decode()) schema.attrs = schema_result['data'] schema.name = schema_result['name'] schema.version = schema_result['version'] schema.handle = handle return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema)
async def deserialize(data: dict): try: credential_def = await CredentialDef._deserialize( "vcx_credentialdef_deserialize", json.dumps(data), data['source_id'], data['name'], data['id']) return credential_def except KeyError: raise VcxError(ErrorCode.InvalidCredentialDef, error_message(ErrorCode.InvalidCredentialDef))
async def deserialize(data: dict): try: # Todo: Find better way to access attr_names. Potential for issues. schema = await Schema._deserialize("vcx_schema_deserialize", json.dumps(data), data['source_id'], data['name'], data['version'], data['data']) schema.schema_id = await schema.get_schema_id() return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema, error_message(ErrorCode.InvalidSchema))
async def prepare_for_endorser(source_id: str, name: str, schema_id: str, endorser: str): """ Create a new CredentialDef object that will be published on the ledger by Endorser later. Note that CredentialDef can't be used for credential issuing until it will be published on the ledger. :param source_id: Institution's unique ID for the credential definition :param name: Name of credential definition :param schema_id: The schema ID given during the creation of the schema :param endorser: DID of the Endorser that will submit the transaction. Example: source_id = 'foobar123' schema_name = 'Schema Name' payment_handle = 0 credential_def1 = await CredentialDef.create(source_id, name, schema_id, payment_handle) :return: credential_def object, written to ledger """ try: credentialdef = CredentialDef(source_id, '', '') if not hasattr(CredentialDef.prepare_for_endorser, "cb"): credentialdef.logger.debug("vcx_prepare_for_endorser: Creating callback") CredentialDef.prepare_for_endorser.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p, c_char_p, c_char_p)) c_source_id = c_char_p(source_id.encode('utf-8')) c_name = c_char_p(name.encode('utf-8')) c_schema_id = c_char_p(schema_id.encode('utf-8')) c_endorser = c_char_p(endorser.encode('utf-8')) c_issuer_did = None c_tag = c_char_p('tag1'.encode('utf-8')) c_config = c_char_p('{"support_revocation":false}'.encode('utf-8')) handle, transaction, _, _ = await do_call('vcx_credentialdef_prepare_for_endorser', c_source_id, c_name, c_schema_id, c_issuer_did, c_tag, c_config, c_endorser, CredentialDef.prepare_for_endorser.cb) credentialdef.logger.debug("created credential def object") credentialdef.name = name credentialdef.handle = handle credentialdef.schema_id = schema_id credentialdef.transaction = transaction return credentialdef except KeyError: raise VcxError(ErrorCode.InvalidCredentialDef)
async def prepare_for_endorser(source_id: str, name: str, version: str, attrs: list, endorser: str): """ Create a new Schema object that will be published by Endorser later. Note that CredentialDef can't be used for credential issuing until it will be published on the ledger. :param source_id: Institution's unique ID for the schema :param name: Name of schema :param version: Version of the schema :param attrs: Atttributes of the schema :param endorser: DID of the Endorser that will submit the transaction. Example: source_id = 'foobar123' name = 'Address Schema' version = '1.0' attrs = ['address', 'city', 'state'] endorser = 'V4SGRU86Z58d6TV7PBUe6f' schema = await Schema.prepare_for_endorser(source_id, name, version, attrs, endorser) :return: schema object, schema transaction that should be passed to Endorser for witting to ledger """ try: schema = Schema(source_id, '', '', []) if not hasattr(Schema.prepare_for_endorser, "cb"): schema.logger.debug( "vcx_schema_prepare_for_endorser: Creating callback") Schema.prepare_for_endorser.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_source_id = c_char_p(source_id.encode('utf-8')) c_name = c_char_p(name.encode('utf-8')) c_version = c_char_p(version.encode('utf-8')) c_schema_data = c_char_p(json.dumps(attrs).encode('utf-8')) c_endorser = c_char_p(endorser.encode('utf-8')) handle, transaction = await do_call( 'vcx_schema_prepare_for_endorser', c_source_id, c_name, c_version, c_schema_data, c_endorser, Schema.prepare_for_endorser.cb) schema.logger.debug("created schema object") schema.attrs = attrs schema.name = name schema.version = version schema.handle = handle schema.transaction = transaction return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema)
async def deserialize(data: dict): """ Create the object from a previously serialized object. :param data: The output of the "serialize" call :return: A re-instantiated object """ try: credential_def = await CredentialDef._deserialize( "vcx_credentialdef_deserialize", json.dumps(data), data['data']['source_id'], data['data']['name'], data['data']['id']) return credential_def except KeyError: raise VcxError(ErrorCode.InvalidCredentialDef, error_message(ErrorCode.InvalidCredentialDef))
async def lookup(source_id: str, schema_id: str): """ Create a new schema object from an existing ledger schema :param source_id: Institution's personal identification for the schema :param schema_id: Ledger schema ID for lookup Example: source_id = 'foobar123' name = 'Address Schema' version = '1.0' attrs = ['address', 'city', 'state'] payment_handle = 0 schema1 = await Schema.create(source_id, name, version, attrs, payment_handle) id1 = await schema.get_schema_id() data = await Schema.lookup(source_id, schema_id) assert data.attrs.sort() == ['sex', 'age', 'name', 'height'].sort() assert data.name == 'test-licence' assert data.handle > 0 :return: schema object """ try: schema = Schema(source_id, '', '', []) if not hasattr(Schema.lookup, "cb"): schema.logger.debug( "vcx_schema_get_attributes: Creating callback") Schema.lookup.cb = create_cb( CFUNCTYPE(None, c_uint32, c_uint32, c_uint32, c_char_p)) c_source_id = c_char_p(source_id.encode('utf-8')) c_schema_id = c_char_p(schema_id.encode('utf-8')) handle, data = await do_call('vcx_schema_get_attributes', c_source_id, c_schema_id, Schema.lookup.cb) schema.logger.debug("created schema object") schema_result = json.loads(data.decode()) schema.attrs = schema_result['data'] schema.name = schema_result['name'] schema.version = schema_result['version'] schema.handle = handle return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema)
async def deserialize(data: dict): """ Create the object from a previously serialized object. :param data: The output of the "serialize" call :return: A re-instantiated object """ try: # Todo: Find better way to access attr_names. Potential for issues. schema = await Schema._deserialize("vcx_schema_deserialize", json.dumps(data), data['data']['source_id'], data['data']['name'], data['data']['version'], data['data']['data']) schema.schema_id = await schema.get_schema_id() return schema except KeyError: raise VcxError(ErrorCode.InvalidSchema, error_message(ErrorCode.InvalidSchema))
async def deserialize(data: dict): """ Create the object from a previously serialized object. :param data: The output of the "serialize" call Example: source_id = 'foobar123' schema_name = 'Schema Name' payment_handle = 0 credential_def1 = await CredentialDef.create(source_id, name, schema_id, payment_handle) data1 = await credential_def1.serialize() credential_def2 = await CredentialDef.deserialize(data1) :return: A re-instantiated object """ try: credential_def = await CredentialDef._deserialize( "vcx_credentialdef_deserialize", json.dumps(data), data['data']['source_id'], data['data']['name'], data['data']['id']) return credential_def except KeyError: raise VcxError(ErrorCode.InvalidCredentialDef)
def set_logger(user_set_logger_fn): logger = Logger() log_cb_converter = CFUNCTYPE(None, c_uint32, c_char_p, c_char_p, c_char_p, c_char_p, c_uint32) f2 = log_cb_converter(user_set_logger_fn) logger.log = f2 c_flush_converter = CFUNCTYPE(None, c_void_p) c_flush_fn = c_flush_converter(flush_cb) logger.flush = c_flush_fn _logger_obj_ptr = ctypes.pointer(logger) void_pointer_context = ctypes.cast(_logger_obj_ptr, ctypes.c_void_p) set_logger_converter = CFUNCTYPE(None, c_void_p, c_uint32, c_char_p, c_char_p, c_char_p, c_char_p, c_uint32) c_set_logger_fn = set_logger_converter(set_logger_fn) name = 'vcx_set_logger' err = getattr(_cdll(), name)(void_pointer_context, None, c_set_logger_fn, c_flush_fn) if err != ErrorCode.Success: raise VcxError(ErrorCode(err))
def get_logger(context, enabled_cb, log_cb, flush_cb): name = 'vcx_get_logger' err = getattr(_cdll(), name)(context, enabled_cb, log_cb, flush_cb) if err != ErrorCode.Success: raise VcxError(ErrorCode(err))