von_anchor/anchor/issuer.py
async def send_cred_def(self, s_id: str, revocation: bool = True, rr_size: int = None) -> str:
        """
        Create a credential definition as Issuer, store it in its wallet, and send it to the ledger.

        Raise CorruptWallet for wallet not pertaining to current ledger, BadLedgerTxn on failure
        to send credential definition to ledger if need be, WalletState for closed wallet,
        or IndyError for any other failure to create and store credential definition in wallet.

        :param s_id: schema identifier
        :param revocation: whether to support revocation for cred def
        :param rr_size: size of initial revocation registry (default as per RevRegBuilder._create_rev_reg()),
            if revocation supported
        :return: json credential definition as it appears on ledger
        """

        LOGGER.debug('Issuer.send_cred_def >>> s_id: %s, revocation: %s, rr_size: %s', s_id, revocation, rr_size)

        if not ok_schema_id(s_id):
            LOGGER.debug('Issuer.send_cred_def <!< Bad schema id %s', s_id)
            raise BadIdentifier('Bad schema id {}'.format(s_id))

        if not self.wallet.handle:
            LOGGER.debug('Issuer.send_cred_def <!< Wallet %s is closed', self.wallet.name)
            raise WalletState('Wallet {} is closed'.format(self.wallet.name))

        if not self.pool:
            LOGGER.debug('Issuer.send_cred_def <!< issuer %s has no pool', self.wallet.name)
            raise AbsentPool('Issuer {} has no pool: cannot send cred def'.format(self.wallet.name))

        rv_json = json.dumps({})
        schema_json = await self.get_schema(schema_key(s_id))
        schema = json.loads(schema_json)

        cd_id = cred_def_id(self.did, schema['seqNo'], self.pool.protocol)
        private_key_ok = True
        with CRED_DEF_CACHE.lock:
            try:
                rv_json = await self.get_cred_def(cd_id)
                LOGGER.info(
                    'Cred def on schema %s version %s already exists on ledger; Issuer %s not sending another',
                    schema['name'],
                    schema['version'],
                    self.wallet.name)
            except AbsentCredDef:
                pass  # OK - about to create, store, and send it

            try:
                (_, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(
                    self.wallet.handle,
                    self.did,  # issuer DID
                    schema_json,
                    self.pool.protocol.cd_id_tag(False),  # expect only one cred def per schema and issuer
                    'CL',
                    json.dumps({'support_revocation': revocation}))
                if json.loads(rv_json):
                    private_key_ok = False
                    LOGGER.warning(
                        'New cred def on %s in wallet shadows existing one on ledger: private key not usable', cd_id)
                        # carry on though, this anchor may have other capacities so public key may be good enough
            except IndyError as x_indy:
                if x_indy.error_code == ErrorCode.AnoncredsCredDefAlreadyExistsError:
                    if json.loads(rv_json):
                        LOGGER.info(
                            'Issuer wallet %s reusing existing cred def on schema %s version %s',
                            self.wallet.name,
                            schema['name'],
                            schema['version'])
                    else:
                        LOGGER.debug('Issuer.send_cred_def <!< corrupt wallet %s', self.wallet.name)
                        raise CorruptWallet('Corrupt Issuer wallet {} has cred def on schema {} not on ledger'.format(
                            self.wallet.name,
                            s_id))
                else:
                    LOGGER.debug(
                        'Issuer.send_cred_def <!< cannot store cred def in wallet %s: indy error code %s',
                        self.wallet.name,
                        x_indy.error_code)
                    raise

            if not json.loads(rv_json):  # checking the ledger returned no cred def: send it
                req_json = await ledger.build_cred_def_request(self.did, cred_def_json)
                await self._sign_submit(req_json)

                for _ in range(16):  # reasonable timeout
                    try:
                        rv_json = await self.get_cred_def(cd_id)  # adds to cache
                        break
                    except AbsentCredDef:
                        await asyncio.sleep(1)
                        LOGGER.info('Sent cred def %s to ledger, waiting 1s for its appearance', cd_id)

                if not rv_json:
                    LOGGER.debug('Issuer.send_cred_def <!< timed out waiting on sent cred_def %s', cd_id)
                    raise BadLedgerTxn('Timed out waiting on sent cred_def {}'.format(cd_id))

                if revocation:  # create new rev reg for tag '0'
                    if self._rrbx:
                        (_, rr_size_suggested) = Tails.next_tag(self._dir_tails, cd_id)
                        rr_id = rev_reg_id(cd_id, '0')
                        try:
                            makedirs(join(self._dir_tails_sentinel, rr_id), exist_ok=False)
                        except FileExistsError:
                            LOGGER.warning('Rev reg %s construction already in progress', rr_id)
                        else:
                            open(
                                join(self._dir_tails_sentinel, rr_id, '.{}'.format(rr_size or rr_size_suggested)),
                                'w').close()

                    await self._sync_revoc_for_issue(rev_reg_id(cd_id, '0'), rr_size)  # sync rev reg on tag '0'

        if revocation and private_key_ok:
            for tag in [str(t) for t in range(1, int(Tails.next_tag(self._dir_tails, cd_id)[0]))]:  # '1' to str(next-1)
                await self._sync_revoc_for_issue(rev_reg_id(cd_id, tag), rr_size if tag == '0' else None)

        makedirs(join(self._dir_tails, cd_id), exist_ok=True)  # ensure dir exists for box id collection, revo or not

        LOGGER.debug('Issuer.send_cred_def <<< %s', rv_json)
        return rv_json

        Create a credential definition as Issuer, store it in its wallet, and send it to the ledger.

        Raise CorruptWallet for wallet not pertaining to current ledger, BadLedgerTxn on failure
        to send credential definition to ledger if need be, WalletState for closed wallet,
        or IndyError for any other failure to create and store credential definition in wallet.

        :param s_id: schema identifier
        :param revocation: whether to support revocation for cred def
        :param rr_size: size of initial revocation registry (default as per RevRegBuilder._create_rev_reg()),
            if revocation supported
        :return: json credential definition as it appears on ledger
        
Create a credential definition as Issuer, store it in its wallet, and send it to the ledger.
Raise CorruptWallet for wallet not pertaining to current ledger, BadLedgerTxn on failure
to send credential definition to ledger if need be, WalletState for closed wallet,
or IndyError for any other failure to create and store credential definition in wallet.
Create a credential definition as Issuer store it in its wallet and send it to the ledger . Raise CorruptWallet for wallet not pertaining to current ledger BadLedgerTxn on failure to send credential definition to ledger if need be WalletState for closed wallet or IndyError for any other failure to create and store credential definition in wallet .
async def send_cred_def(self, s_id: str, revocation: bool = True, rr_size: int = None) -> str:
        LOGGER.debug('Issuer.send_cred_def >>> s_id: %s, revocation: %s, rr_size: %s', s_id, revocation, rr_size)
        if not ok_schema_id(s_id):
            LOGGER.debug('Issuer.send_cred_def <!< Bad schema id %s', s_id)
            raise BadIdentifier('Bad schema id {}'.format(s_id))
        if not self.wallet.handle:
            LOGGER.debug('Issuer.send_cred_def <!< Wallet %s is closed', self.wallet.name)
            raise WalletState('Wallet {} is closed'.format(self.wallet.name))
        if not self.pool:
            LOGGER.debug('Issuer.send_cred_def <!< issuer %s has no pool', self.wallet.name)
            raise AbsentPool('Issuer {} has no pool: cannot send cred def'.format(self.wallet.name))
        rv_json = json.dumps({})
        schema_json = await self.get_schema(schema_key(s_id))
        schema = json.loads(schema_json)
        cd_id = cred_def_id(self.did, schema['seqNo'], self.pool.protocol)
        private_key_ok = True
        with CRED_DEF_CACHE.lock:
            try:
                rv_json = await self.get_cred_def(cd_id)
                LOGGER.info(
                    'Cred def on schema %s version %s already exists on ledger; Issuer %s not sending another',
                    schema['name'],
                    schema['version'],
                    self.wallet.name)
            except AbsentCredDef:
                pass  
            try:
                (_, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(
                    self.wallet.handle,
                    self.did,  
                    schema_json,
                    self.pool.protocol.cd_id_tag(False),  
                    'CL',
                    json.dumps({'support_revocation': revocation}))
                if json.loads(rv_json):
                    private_key_ok = False
                    LOGGER.warning(
                        'New cred def on %s in wallet shadows existing one on ledger: private key not usable', cd_id)
            except IndyError as x_indy:
                if x_indy.error_code == ErrorCode.AnoncredsCredDefAlreadyExistsError:
                    if json.loads(rv_json):
                        LOGGER.info(
                            'Issuer wallet %s reusing existing cred def on schema %s version %s',
                            self.wallet.name,
                            schema['name'],
                            schema['version'])
                    else:
                        LOGGER.debug('Issuer.send_cred_def <!< corrupt wallet %s', self.wallet.name)
                        raise CorruptWallet('Corrupt Issuer wallet {} has cred def on schema {} not on ledger'.format(
                            self.wallet.name,
                            s_id))
                else:
                    LOGGER.debug(
                        'Issuer.send_cred_def <!< cannot store cred def in wallet %s: indy error code %s',
                        self.wallet.name,
                        x_indy.error_code)
                    raise
            if not json.loads(rv_json):  
                req_json = await ledger.build_cred_def_request(self.did, cred_def_json)
                await self._sign_submit(req_json)
                for _ in range(16):  
                    try:
                        rv_json = await self.get_cred_def(cd_id)  
                        break
                    except AbsentCredDef:
                        await asyncio.sleep(1)
                        LOGGER.info('Sent cred def %s to ledger, waiting 1s for its appearance', cd_id)
                if not rv_json:
                    LOGGER.debug('Issuer.send_cred_def <!< timed out waiting on sent cred_def %s', cd_id)
                    raise BadLedgerTxn('Timed out waiting on sent cred_def {}'.format(cd_id))
                if revocation:  
                    if self._rrbx:
                        (_, rr_size_suggested) = Tails.next_tag(self._dir_tails, cd_id)
                        rr_id = rev_reg_id(cd_id, '0')
                        try:
                            makedirs(join(self._dir_tails_sentinel, rr_id), exist_ok=False)
                        except FileExistsError:
                            LOGGER.warning('Rev reg %s construction already in progress', rr_id)
                        else:
                            open(
                                join(self._dir_tails_sentinel, rr_id, '.{}'.format(rr_size or rr_size_suggested)),
                                'w').close()
                    await self._sync_revoc_for_issue(rev_reg_id(cd_id, '0'), rr_size)  
        if revocation and private_key_ok:
            for tag in [str(t) for t in range(1, int(Tails.next_tag(self._dir_tails, cd_id)[0]))]:  
                await self._sync_revoc_for_issue(rev_reg_id(cd_id, tag), rr_size if tag == '0' else None)
        makedirs(join(self._dir_tails, cd_id), exist_ok=True)  
        LOGGER.debug('Issuer.send_cred_def <<< %s', rv_json)
        return rv_json
async def send_cred_def ( self , s_id : str , revocation : bool = True , rr_size : int = None ) -> str : LOGGER . debug ( 'Issuer.send_cred_def >>> s_id: %s, revocation: %s, rr_size: %s' , s_id , revocation , rr_size ) if not ok_schema_id ( s_id ) : LOGGER . debug ( 'Issuer.send_cred_def <!< Bad schema id %s' , s_id ) raise BadIdentifier ( 'Bad schema id {}' . format ( s_id ) ) if not self . wallet . handle : LOGGER . debug ( 'Issuer.send_cred_def <!< Wallet %s is closed' , self . wallet . name ) raise WalletState ( 'Wallet {} is closed' . format ( self . wallet . name ) ) if not self . pool : LOGGER . debug ( 'Issuer.send_cred_def <!< issuer %s has no pool' , self . wallet . name ) raise AbsentPool ( 'Issuer {} has no pool: cannot send cred def' . format ( self . wallet . name ) ) rv_json = json . dumps ( { } ) schema_json = await self . get_schema ( schema_key ( s_id ) ) schema = json . loads ( schema_json ) cd_id = cred_def_id ( self . did , schema [ 'seqNo' ] , self . pool . protocol ) private_key_ok = True with CRED_DEF_CACHE . lock : try : rv_json = await self . get_cred_def ( cd_id ) LOGGER . info ( 'Cred def on schema %s version %s already exists on ledger; Issuer %s not sending another' , schema [ 'name' ] , schema [ 'version' ] , self . wallet . name ) except AbsentCredDef : pass try : ( _ , cred_def_json ) = await anoncreds . issuer_create_and_store_credential_def ( self . wallet . handle , self . did , schema_json , self . pool . protocol . cd_id_tag ( False ) , 'CL' , json . dumps ( { 'support_revocation' : revocation } ) ) if json . loads ( rv_json ) : private_key_ok = False LOGGER . warning ( 'New cred def on %s in wallet shadows existing one on ledger: private key not usable' , cd_id ) except IndyError as x_indy : if x_indy . error_code == ErrorCode . AnoncredsCredDefAlreadyExistsError : if json . loads ( rv_json ) : LOGGER . info ( 'Issuer wallet %s reusing existing cred def on schema %s version %s' , self . wallet . name , schema [ 'name' ] , schema [ 'version' ] ) else : LOGGER . debug ( 'Issuer.send_cred_def <!< corrupt wallet %s' , self . wallet . name ) raise CorruptWallet ( 'Corrupt Issuer wallet {} has cred def on schema {} not on ledger' . format ( self . wallet . name , s_id ) ) else : LOGGER . debug ( 'Issuer.send_cred_def <!< cannot store cred def in wallet %s: indy error code %s' , self . wallet . name , x_indy . error_code ) raise if not json . loads ( rv_json ) : req_json = await ledger . build_cred_def_request ( self . did , cred_def_json ) await self . _sign_submit ( req_json ) for _ in range ( 16 ) : try : rv_json = await self . get_cred_def ( cd_id ) break except AbsentCredDef : await asyncio . sleep ( 1 ) LOGGER . info ( 'Sent cred def %s to ledger, waiting 1s for its appearance' , cd_id ) if not rv_json : LOGGER . debug ( 'Issuer.send_cred_def <!< timed out waiting on sent cred_def %s' , cd_id ) raise BadLedgerTxn ( 'Timed out waiting on sent cred_def {}' . format ( cd_id ) ) if revocation : if self . _rrbx : ( _ , rr_size_suggested ) = Tails . next_tag ( self . _dir_tails , cd_id ) rr_id = rev_reg_id ( cd_id , '0' ) try : makedirs ( join ( self . _dir_tails_sentinel , rr_id ) , exist_ok = False ) except FileExistsError : LOGGER . warning ( 'Rev reg %s construction already in progress' , rr_id ) else : open ( join ( self . _dir_tails_sentinel , rr_id , '.{}' . format ( rr_size or rr_size_suggested ) ) , 'w' ) . close ( ) await self . _sync_revoc_for_issue ( rev_reg_id ( cd_id , '0' ) , rr_size ) if revocation and private_key_ok : for tag in [ str ( t ) for t in range ( 1 , int ( Tails . next_tag ( self . _dir_tails , cd_id ) [ 0 ] ) ) ] : await self . _sync_revoc_for_issue ( rev_reg_id ( cd_id , tag ) , rr_size if tag == '0' else None ) makedirs ( join ( self . _dir_tails , cd_id ) , exist_ok = True ) LOGGER . debug ( 'Issuer.send_cred_def <<< %s' , rv_json ) return rv_json
Create a credential definition as Issuer, store it in its wallet, and send it to the ledger.
Create a credential definition as Issuer store it in its wallet and send it to the ledger .
"""
        Create a credential definition as Issuer, store it in its wallet, and send it to the ledger.

        Raise CorruptWallet for wallet not pertaining to current ledger, BadLedgerTxn on failure
        to send credential definition to ledger if need be, WalletState for closed wallet,
        or IndyError for any other failure to create and store credential definition in wallet.

        :param s_id: schema identifier
        :param revocation: whether to support revocation for cred def
        :param rr_size: size of initial revocation registry (default as per RevRegBuilder._create_rev_reg()),
            if revocation supported
        :return: json credential definition as it appears on ledger
        """ # OK - about to create, store, and send it # issuer DID # expect only one cred def per schema and issuer # carry on though, this anchor may have other capacities so public key may be good enough # checking the ledger returned no cred def: send it # reasonable timeout # adds to cache # create new rev reg for tag '0' # sync rev reg on tag '0' # '1' to str(next-1) # ensure dir exists for box id collection, revo or not
json credential definition as it appears on ledger
json credential definition as it appears on ledger
self
s_id
str
None
revocation
bool
whether to support revocation for cred def
whether to support revocation for cred def
rr_size
int
size of initial revocation registry (default as per RevRegBuilder._create_rev_reg()),
if revocation supported
size of initial revocation registry ( default as per RevRegBuilder . _create_rev_reg () ) if revocation supported