async def test_box_ids(): print(Ink.YELLOW('\n\n== Testing Box Identifier Checks ==')) assert ok_did('Q4zqM7aXqm7gDQkUVLng9h') # quibble: not technically a box id assert not ok_did('Q4zqM7aXqm7gDQkUVLng9I') assert not ok_did('Q4zqM7aXqm7gDQkUVLng') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9h') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9h') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9hx') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng90') assert ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:3:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h::bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2::1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0a') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9I:2:bc-reg:1.0') # I is not in base58 assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag') # protocol >= 1.4 assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:4:CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h::CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9I:3:CL:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3::18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18z:tag') assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18') # protocol == 1.3 assert ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1') # protocol >= 1.4 assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:5:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:4:CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL::CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:NOT_CL:20:tag:CL_ACCUM:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20z:tag:CL_ACCUM:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20::CL_ACCUM:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag::1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:1') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:') assert not ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM') assert ok_rev_reg_id('LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1') # protocol == 1.3
async def post_tails(request, rr_id): """ Post tails file to server. Multipart file name must be tails hash. :param request: Sanic request structure :param rr_id: rev reg id for revocation registry to which tails file pertains :return: empty text string """ if not ok_rev_reg_id(rr_id): LOGGER.error('POST cited bad rev reg id %s', rr_id) raise InvalidUsage('POST cited bad rev reg id {}'.format(rr_id)) # curl uses 'data', python requests uses 'file', there may be others req_key = set(k for k in request.files if request.files[k] and isinstance(request.files[k], list) and isinstance(request.files[k][0], SanicReqFile)).pop() tails_hash = request.files[req_key][0].name if not Tails.ok_hash(tails_hash): LOGGER.error('POST attached file named with bad tails file hash %s', tails_hash) raise InvalidUsage('POST attached file named with bad tails file hash {}'.format(tails_hash)) dir_tails = pjoin(dirname(dirname(abspath(__file__))), 'tails') dir_cd_id = Tails.dir(dir_tails, rr_id) makedirs(dir_cd_id, exist_ok=True) if Tails.linked(dir_tails, rr_id): LOGGER.error('POST attached tails file %s, already present', rr_id) raise Forbidden('POST attached tails file {}, already present'.format(rr_id)) path_tails_hash = pjoin(dir_cd_id, tails_hash) if exists(path_tails_hash): LOGGER.error('POST attached tails file %s, already present at %s', rr_id, path_tails_hash) raise Forbidden('POST attached tails file {}, already present at {}'.format(rr_id, path_tails_hash)) with open(path_tails_hash, 'wb') as fh_tails: fh_tails.write(request.files[req_key][0].body) Tails.associate(dir_tails, rr_id, tails_hash) LOGGER.info('Associated link %s to POST tails file attachment saved to %s', rr_id, path_tails_hash) return response.text('')
async def post_tails(request: Request, rr_id: str, epoch: int) -> HTTPResponse: """ Post tails file to server, auth-encrypted from issuer (by DID) to tails server anchor. Multipart file name must be tails hash. :param request: Sanic request structure :param rr_id: revocation registry identifier :param epoch: current EPOCH time, must be within configured proximity to current server time :return: empty text response """ if not ok_rev_reg_id(rr_id): LOGGER.error('POST cited bad rev reg id %s', rr_id) return response.text('POST cited bad rev reg id {}'.format(rr_id), status=400) did = rr_id.split(':')[0] if not await is_current(int(epoch)): LOGGER.error('POST epoch %s in too far from current server time', epoch) return response.text('POST epoch {} is too far from current server time'.format(epoch), status=400) tails_hash = request.files['tails-file'][0].name if not Tails.ok_hash(tails_hash): LOGGER.error('POST attached file named with bad tails file hash %s', tails_hash) return response.text('POST attached file named with bad tails file hash {}'.format(tails_hash), status=400) dir_tails = join(dirname(dirname(realpath(__file__))), 'tails') dir_cd_id = Tails.dir(dir_tails, rr_id) makedirs(dir_cd_id, exist_ok=True) if Tails.linked(dir_tails, rr_id): LOGGER.error('POST attached tails file %s, already present', rr_id) return response.text('POST attached tails file {}, already present'.format(rr_id), status=403) path_tails_hash = join(dir_cd_id, tails_hash) if exists(path_tails_hash): LOGGER.error('POST attached tails file %s, already present at %s', rr_id, path_tails_hash) return response.text( 'POST attached tails file {}, already present at {}'.format(rr_id, path_tails_hash), status=403) tsan = await MEM_CACHE.get('tsan') signature = request.files['signature'][0].body epoch_tails = '{}||{}'.format(epoch, request.files['tails-file'][0].body) if not tsan.verify(epoch_tails, signature, did): LOGGER.error('POST attached file %s failed to verify', tails_hash) return response.text('POST attached file {} failed to verify'.format(tails_hash), status=400) try: rev_reg_def = json.loads(await tsan.get_rev_reg_def(rr_id)) ledger_hash = rev_reg_def.get('value', {}).get('tailsHash', None) if ledger_hash != tails_hash: LOGGER.error('POST attached tails file hash %s differs from ledger value %s', tails_hash, ledger_hash) return response.text( 'POST attached tails file hash {} differs from ledger value {}'.format(tails_hash, ledger_hash), status=400) except AbsentRevReg: LOGGER.error('POST revocation registry not present on ledger for %s', rr_id) return response.text('POST revocation registry not present on ledger for {}'.format(rr_id), status=400) with open(path_tails_hash, 'wb') as fh_tails: fh_tails.write(request.files['tails-file'][0].body) Tails.associate(dir_tails, rr_id, tails_hash) LOGGER.info('Associated link %s to POST tails file attachment saved to %s', rr_id, path_tails_hash) return response.text('')
async def test_ids(): print(Ink.YELLOW('\n\n== Testing Identifier Checks ==')) assert ok_wallet_reft('49ad0727-8663-45ae-a115-12b09860f9c6') assert not ok_wallet_reft('Q4zqM7aXqm7gDQkUVLng9I') assert not ok_wallet_reft('49ad0727-45ae-a115-12b09860f9c6') print('\n\n== 1 == Wallet referent identifier checks pass OK') assert ok_did('Q4zqM7aXqm7gDQkUVLng9h') assert not ok_did('Q4zqM7aXqm7gDQkUVLng9I') # 'I' not a base58 char assert not ok_did('Q4zqM7aXqm7gDQkUVLng') # too short print('\n\n== 2 == Distributed identifier checks pass OK') for value in (None, 'TRUSTEE', 'STEWARD', 'TRUST_ANCHOR', ''): assert ok_role(value) for value in (123, 'TRUSTY', 'STEW', 'ANCHOR', ' '): assert not ok_role(value) print('\n\n== 3 == Role identifier checks pass OK') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9h') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9h') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9hx') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng90') print('\n\n== 4 == Tails hash identifier checks pass OK') assert ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:3:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h::bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2::1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0a') assert not ok_schema_id( 'Q4zqM7aXqm7gDQkUVLng9I:2:bc-reg:1.0') # I is not in base58 print('\n\n== 5 == Schema identifier checks pass OK') assert ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag') # protocol >= 1.4 assert ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:Q4zqM7aXqm7gDQkUVLng9h:2:schema_name:1.0:tag' ) # long form assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag', 'Q4zqM7aXqm7gDQkUVLng9h') # issuer-did assert ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:Q999999999999999999999:2:schema_name:1.0:tag', 'Q4zqM7aXqm7gDQkUVLng9h') # long form, issuer-did assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag', 'Xxxxxxxxxxxxxxxxxxxxxx') assert not ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:Q4zqM7aXqm7gDQkUVLng9h:2:schema_name:1.0:tag', 'Xxxxxxxxxxxxxxxxxxxxxx') # long form, issuer-did assert ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:Q4zqM7aXqm7gDQkUVLng9h:2:schema_name:1.0:tag' ) # long form assert not ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:Q4zqM7aXqm7gDQkUVLng9h:schema_name:1.0:tag' ) # no :2: assert not ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:QIIIIIIIII7gDQkUVLng9h:schema_name:1.0:tag' ) # I not base58 assert not ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:QIIIIIIIII7gDQkUVLng9h:schema_name:v1.0:tag' ) # bad version assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:4:CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h::CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9I:3:CL:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3::18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18z:tag') assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18') # protocol == 1.3 assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18', 'Q4zqM7aXqm7gDQkUVLng9h') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18', 'Xxxxxxxxxxxxxxxxxxxxxx') assert ok_cred_def_id( rev_reg_id2cred_def_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:Q4zqM7aXqm7gDQkUVLng9h:2:schema_name:1.0:tag:CL_ACCUM:1' )) print('\n\n== 6 == Credential definition identifier checks pass OK') assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1' ) # protocol >= 1.4 assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert ok_rev_reg_id( # long form 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:Q4zqM7aXqm7gDQkUVLng9h:2:schema_name:1.0:tag:CL_ACCUM:1' ) assert ok_rev_reg_id( # long form 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:Q4zqM7aXqm7gDQkUVLng9h:2:schema_name:1.0:tag:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1', 'Xxxxxxxxxxxxxxxxxxxxxx') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:5:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:4:CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL::CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:NOT_CL:20:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20z:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20::CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag::1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM') assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1' ) # protocol == 1.3 assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1', 'Xxxxxxxxxxxxxxxxxxxxxx') print('\n\n== 7 == Revocation registry identifier checks pass OK')
async def test_box_ids(): print(Ink.YELLOW('\n\n== Testing Identifier Checks ==')) assert ok_wallet_reft('49ad0727-8663-45ae-a115-12b09860f9c6') assert not ok_wallet_reft('Q4zqM7aXqm7gDQkUVLng9I') assert not ok_wallet_reft('49ad0727-45ae-a115-12b09860f9c6') assert ok_did( 'Q4zqM7aXqm7gDQkUVLng9h') # quibble: not technically a box id assert not ok_did('Q4zqM7aXqm7gDQkUVLng9I') assert not ok_did('Q4zqM7aXqm7gDQkUVLng') for value in (None, 'TRUSTEE', 'STEWARD', 'TRUST_ANCHOR', ''): assert ok_role(value) for value in (123, 'TRUSTY', 'STEW', 'ANCHOR', ' '): assert not ok_role(value) assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9h') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9h') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9hx') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng90') assert ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:3:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h::bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2::1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0a') assert not ok_schema_id( 'Q4zqM7aXqm7gDQkUVLng9I:2:bc-reg:1.0') # I is not in base58 assert ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag') # protocol >= 1.4 assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag', 'Q4zqM7aXqm7gDQkUVLng9h') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag', 'Xxxxxxxxxxxxxxxxxxxxxx') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:4:CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h::CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9I:3:CL:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3::18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18z:tag') assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18') # protocol == 1.3 assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18', 'Q4zqM7aXqm7gDQkUVLng9h') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18', 'Xxxxxxxxxxxxxxxxxxxxxx') assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1' ) # protocol >= 1.4 assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1', 'Xxxxxxxxxxxxxxxxxxxxxx') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:5:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:4:CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL::CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:NOT_CL:20:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20z:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20::CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag::1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM') assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1' ) # protocol == 1.3 assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1', 'Xxxxxxxxxxxxxxxxxxxxxx') assert ok_endpoint('10.0.0.2:9702') assert ok_endpoint('0.0.0.0:0') assert not ok_endpoint('canada.gc.ca:8088') assert not ok_endpoint(':37') assert not ok_endpoint('http://url-wrong') assert not ok_endpoint('2.3.4.5') assert not ok_endpoint('2.3.4:8080') assert not ok_endpoint('1.2.3.4:abc') assert not ok_endpoint('1.2.3.4:1234.56')
async def test_ids(): print(Ink.YELLOW('\n\n== Testing Identifier Checks ==')) assert ok_wallet_reft('49ad0727-8663-45ae-a115-12b09860f9c6') assert not ok_wallet_reft('Q4zqM7aXqm7gDQkUVLng9I') assert not ok_wallet_reft('49ad0727-45ae-a115-12b09860f9c6') print('\n\n== 1 == Wallet referent identifier checks pass OK') assert ok_did('Q4zqM7aXqm7gDQkUVLng9h') assert not ok_did('Q4zqM7aXqm7gDQkUVLng9I') # 'I' not a base58 char assert not ok_did('Q4zqM7aXqm7gDQkUVLng') # too short print('\n\n== 2 == Distributed identifier checks pass OK') for value in (None, 'TRUSTEE', 'STEWARD', 'TRUST_ANCHOR', ''): assert ok_role(value) for value in (123, 'TRUSTY', 'STEW', 'ANCHOR', ' '): assert not ok_role(value) print('\n\n== 3 == Role identifier checks pass OK') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9h') assert Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9h') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng9hx') assert not Tails.ok_hash('Q4zqM7aXqm7gDQkUVLng9hQ4zqM7aXqm7gDQkUVLng90') print('\n\n== 4 == Tails hash identifier checks pass OK') assert ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:3:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h::bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:bc-reg:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2::1.0') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:') assert not ok_schema_id('Q4zqM7aXqm7gDQkUVLng9h:2:bc-reg:1.0a') assert not ok_schema_id( 'Q4zqM7aXqm7gDQkUVLng9I:2:bc-reg:1.0') # I is not in base58 print('\n\n== 5 == Schema identifier checks pass OK') assert ok_cred_def_id( 'Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag') # protocol >= 1.4 assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag', 'Q4zqM7aXqm7gDQkUVLng9h') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18:tag', 'Xxxxxxxxxxxxxxxxxxxxxx') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:4:CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h::CL:18:0') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9I:3:CL:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3::18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:18:tag') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18z:tag') assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18') # protocol == 1.3 assert ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18', 'Q4zqM7aXqm7gDQkUVLng9h') assert not ok_cred_def_id('Q4zqM7aXqm7gDQkUVLng9h:3:CL:18', 'Xxxxxxxxxxxxxxxxxxxxxx') print('\n\n== 6 == Credential definition identifier checks pass OK') assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1' ) # protocol >= 1.4 assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1', 'Xxxxxxxxxxxxxxxxxxxxxx') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:5:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:4:CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL::CL:20:0:CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:NOT_CL:20:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20z:tag:CL_ACCUM:1' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20::CL_ACCUM:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag::1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:1') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM:' ) assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:tag:CL_ACCUM') assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1' ) # protocol == 1.3 assert ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1', 'LjgpST2rjsoxYegQDRm7EL') assert not ok_rev_reg_id( 'LjgpST2rjsoxYegQDRm7EL:4:LjgpST2rjsoxYegQDRm7EL:3:CL:20:CL_ACCUM:1', 'Xxxxxxxxxxxxxxxxxxxxxx') print('\n\n== 7 == Revocation registry identifier checks pass OK') assert ok_endpoint('10.0.0.2:9702') assert ok_endpoint('0.0.0.0:0') assert not ok_endpoint('canada.gc.ca:8088') assert not ok_endpoint(':37') assert not ok_endpoint('http://url-wrong') assert not ok_endpoint('2.3.4.5') assert not ok_endpoint('2.3.4:8080') assert not ok_endpoint('1.2.3.4:abc') assert not ok_endpoint('1.2.3.4:1234.56') print('\n\n== 8 == Endpoint checks pass OK')