Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cert-issuer fails when using the example verifiable-credential.json #247

Open
pranayperiwal opened this issue Sep 16, 2022 · 6 comments
Open

Comments

@pranayperiwal
Copy link

pranayperiwal commented Sep 16, 2022

This is my verifiable-credential.json:
{ "@context": [ "https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1", "https://w3id.org/blockcerts/v3" ], "id": "urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c", "type": [ "VerifiableCredential", "BlockcertsCredential" ], "issuer": "did:example:23adb1f712ebc6f1c276eba4dfa", "issuanceDate": "2022-01-01T19:33:24Z", "credentialSubject": { "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", "alumniOf": { "id": "did:example:c276e12ec21ebfeb1f712ebc6f1" } } }

I am not sure if I am supposed to change anything here, but when I try to run cert-issuer -c /etc/cert-issuer/conf.ini --verification_method "did:example:23adb1f712ebc6f1c276eba4dfa", I get the following error:

WARNING - Your app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
INFO - This run will try to issue on the bitcoin_regtest chain
INFO - Set cost constants to recommended_tx_fee=0.000600,min_per_output=0.000028,satoshi_per_byte=250
INFO - Processing 1 certificates
INFO - Processing 1 certificates under work path=/etc/cert-issuer/work
INFO - Total cost will be 133500 satoshis
INFO - Starting finalizable signer
WARNING - app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
INFO - Stopping finalizable signer
WARNING - app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1134, in to_rdf
    expanded = self.expand(input_, options)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 835, in expand
    expanded = self._expand(active_ctx, None, document, options, False)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 2089, in _expand
    active_ctx = self._process_context(
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 2737, in _process_context
    raise JsonLdError(
pyld.jsonld.JsonLdError: ('Invalid JSON-LD syntax; @context must be an object.',)
Type: jsonld.SyntaxError
Code: invalid local context
Details: {'context': 'https://w3id.org/blockcerts/v3'}


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1052, in normalize
    dataset = self.to_rdf(input_, opts)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1136, in to_rdf
    raise JsonLdError(
pyld.jsonld.JsonLdError: ('Could not expand input before serialization to RDF.',)
Type: jsonld.RdfError
Cause: ('Invalid JSON-LD syntax; @context must be an object.',)
Type: jsonld.SyntaxError
Code: invalid local context
Details: {'context': 'https://w3id.org/blockcerts/v3'}  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1134, in to_rdf
    expanded = self.expand(input_, options)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 835, in expand
    expanded = self._expand(active_ctx, None, document, options, False)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 2089, in _expand
    active_ctx = self._process_context(
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 2737, in _process_context
    raise JsonLdError(


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/cert-issuer", line 8, in <module>
    sys.exit(cert_issuer_main())
  File "/usr/lib/python3.8/site-packages/cert_issuer/__main__.py", line 17, in cert_issuer_main
    issue_certificates.main(parsed_config)
  File "/usr/lib/python3.8/site-packages/cert_issuer/issue_certificates.py", line 34, in main
    return issue(app_config, certificate_batch_handler, transaction_handler)
  File "/usr/lib/python3.8/site-packages/cert_issuer/issue_certificates.py", line 20, in issue
    tx_id = issuer.issue(app_config.chain)
  File "/usr/lib/python3.8/site-packages/cert_issuer/issuer.py", line 23, in issue
    blockchain_bytes = self.certificate_batch_handler.prepare_batch()
  File "/usr/lib/python3.8/site-packages/cert_issuer/certificate_handlers.py", line 104, in prepare_batch
    self.merkle_tree.populate(self.get_certificate_generator())
  File "/usr/lib/python3.8/site-packages/cert_issuer/merkle_tree_generator.py", line 34, in populate
    for data in node_generator:
  File "/usr/lib/python3.8/site-packages/cert_issuer/certificate_handlers.py", line 114, in get_certificate_generator
    data_to_issue = self.certificate_handler.get_byte_array_to_issue(metadata)
  File "/usr/lib/python3.8/site-packages/cert_issuer/certificate_handlers.py", line 16, in get_byte_array_to_issue
    return JSONLDHandler.normalize_to_utf8(certificate_json)
  File "/usr/lib/python3.8/site-packages/cert_issuer/normalization_handler.py", line 12, in normalize_to_utf8
    normalized = normalize_jsonld(certificate_json, detect_unmapped_fields=False)
  File "/usr/lib/python3.8/site-packages/cert_schema/jsonld_helpers.py", line 237, in normalize_jsonld
    normalized = jsonld.normalize(json_ld, options=options)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 249, in normalize
    return JsonLdProcessor().normalize(input_, options)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1054, in normalize
    raise JsonLdError(
pyld.jsonld.JsonLdError: ('Could not convert input to RDF dataset before normalization.',)
Type: jsonld.NormalizeError
Cause: ('Could not expand input before serialization to RDF.',)
Type: jsonld.RdfError
Cause: ('Invalid JSON-LD syntax; @context must be an object.',)
Type: jsonld.SyntaxError
Code: invalid local context
Details: {'context': 'https://w3id.org/blockcerts/v3'}  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1134, in to_rdf
    expanded = self.expand(input_, options)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 835, in expand
    expanded = self._expand(active_ctx, None, document, options, False)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 2089, in _expand
    active_ctx = self._process_context(
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 2737, in _process_context
    raise JsonLdError(
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1052, in normalize
    dataset = self.to_rdf(input_, opts)
  File "/usr/lib/python3.8/site-packages/pyld/jsonld.py", line 1136, in to_rdf
    raise JsonLdError(

Could someone tell me what I am doing wrong?

@lemoustachiste
Copy link
Member

hmm, I think it could be related to the fact that you are using the examples context: https://www.w3.org/2018/credentials/examples/v1 and that it's not "preloaded" to jsonld. To make sure, try to remove this context from the list, you should get a different error on alumniOf.

If that's the case, and you really want to use the examples context, there 2 ways you can preload the context.

Either in conf.ini:

context_urls=[https://www.w3.org/2018/credentials/examples/v1]
context_file_paths=[your-path-to-the-local-context-file]

Tip: you can do something like curl -L https://www.w3.org/2018/credentials/examples/v1 >> your-path-to-the-local-context-file to quickly store the file locally.

Or with the CLI:

python -m cert_issuer -c conf.ini --context_urls https://www.w3.org/2018/credentials/examples/v1 --context_file_paths your-path-to-the-local-context-file

@pranayperiwal
Copy link
Author

pranayperiwal commented Sep 16, 2022

Hi! Thank you for your quick reply.
If I remove the line https://www.w3.org/2018/credentials/examples/v1 from verifiable-credential.json, I get this response:

bash-5.0# cert-issuer -c /etc/cert-issuer/conf.ini
WARNING - Your app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
INFO - This run will try to issue on the bitcoin_regtest chain
INFO - Set cost constants to recommended_tx_fee=0.000600,min_per_output=0.000028,satoshi_per_byte=250
INFO - Processing 1 certificates
INFO - Processing 1 certificates under work path=/etc/cert-issuer/work
INFO - Total cost will be 133500 satoshis
INFO - Starting finalizable signer
WARNING - app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
INFO - Stopping finalizable signer
WARNING - app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
INFO - here is the op_return_code data: f4906de7db4f9a826b5998472f51eaac762d429b29b6c2496f38870a477929d9
INFO - Unsigned hextx=0100000001556154cba262e3795d9925b9c83bd1bbefc4a0c59f617c1efbd262b8f5032dff0100000000ffffffff02a07acc1d0000000016001425e2b1a1d9f2496c0d04c7c19592dc4214c9e5c40000000000000000226a20f4906de7db4f9a826b5998472f51eaac762d429b29b6c2496f38870a477929d900000000
INFO - Preparing tx for signing
INFO - Starting finalizable signer
WARNING - app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
ERROR - Unable to sign transaction. hextx=01000000000101556154cba262e3795d9925b9c83bd1bbefc4a0c59f617c1efbd262b8f5032dff0100000000ffffffff02a07acc1d0000000016001425e2b1a1d9f2496c0d04c7c19592dc4214c9e5c40000000000000000226a20f4906de7db4f9a826b5998472f51eaac762d429b29b6c2496f38870a477929d902473044022028e084bbf275b27f7d796a299ce53ee4e0af94c71fbbc70fe49d7f53d00a2aff022006e9a873c64d3685d7131704fc119f22e6303ec574783607dfa2e1027670500b0121026f62fd7d68fa3ac1add38c9b30b033af1c5b7de2522742ede2cbd3a51433ac7000000000
INFO - Stopping finalizable signer
WARNING - app is configured to skip the wifi check when the USB is plugged in. Read the documentation to ensure this is what you want, since this is less secure
Traceback (most recent call last):
  File "/usr/bin/cert-issuer", line 8, in <module>
    sys.exit(cert_issuer_main())
  File "/usr/lib/python3.8/site-packages/cert_issuer/__main__.py", line 17, in cert_issuer_main
    issue_certificates.main(parsed_config)
  File "/usr/lib/python3.8/site-packages/cert_issuer/issue_certificates.py", line 34, in main
    return issue(app_config, certificate_batch_handler, transaction_handler)
  File "/usr/lib/python3.8/site-packages/cert_issuer/issue_certificates.py", line 20, in issue
    tx_id = issuer.issue(app_config.chain)
  File "/usr/lib/python3.8/site-packages/cert_issuer/issuer.py", line 27, in issue
    txid = self.transaction_handler.issue_transaction(blockchain_bytes)
  File "/usr/lib/python3.8/site-packages/cert_issuer/blockchain_handlers/bitcoin/transaction_handlers.py", line 56, in issue_transaction
    signed_tx = self.sign_transaction(prepared_tx)
  File "/usr/lib/python3.8/site-packages/cert_issuer/blockchain_handlers/bitcoin/transaction_handlers.py", line 92, in sign_transaction
    signed_tx = signer.sign_transaction(prepared_tx)
  File "/usr/lib/python3.8/site-packages/cert_issuer/models/__init__.py", line 99, in sign_transaction
    return self.signer.sign_transaction(self.wif, transaction_to_sign)
  File "/usr/lib/python3.8/site-packages/cert_issuer/blockchain_handlers/bitcoin/signer.py", line 35, in sign_transaction
    raise UnableToSignTxError('Unable to sign transaction')
cert_issuer.errors.UnableToSignTxError: Unable to sign transaction

If I don't remove the line from the file, I get the same error even after downloading the context file and adding the lines you mentioned in conf.ini

@lemoustachiste
Copy link
Member

You should look at the reason why the Error is raised from there:

 File "/usr/lib/python3.8/site-packages/cert_issuer/blockchain_handlers/bitcoin/signer.py", line 35, in sign_transaction
    raise UnableToSignTxError('Unable to sign transaction')

Reasons could be different, but the low hanging one could be: is your wallet funded?

@pranayperiwal
Copy link
Author

I have tried to debug it but not sure what else can I do. There is enough balance in the wallet yup. I am not sure if there is a problem with the docker container or if there is some issue with the default files given. Apologies, I am new to blockchain so any advice would be helpful. Also if you would like, all I did was follow the steps in the Readme of cert-issuer while choosing 'sample unsigned certificate' for the issuing certificate,

@lemoustachiste
Copy link
Member

is your private key correctly defined in pk_issuer.txt?
It should be in the WIF format: https://github.com/blockchain-certificates/did-generator/blob/master/key-management/generateKeyPair.ts#L75

@owenwu811
Copy link

you @context property needs to be an object, not an array:

{
"@context": {
"@Version": 1.1,
"schema": "http://schema.org/",
"cred": "https://www.w3.org/2018/credentials#",
"Blockcerts": "https://w3id.org/blockcerts#"
},
"id": "urn:uuid:bbba8553-8ec1-445f-82c9-a57251dd731c",
"type": ["VerifiableCredential", "BlockcertsCredential"],
"issuer": "did:example:23adb1f712ebc6f1c276eba4dfa",
"issuanceDate": "2022-01-01T19:33:24Z",
"credentialSubject": {
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
"alumniOf": {
"id": "did:example:c276e12ec21ebfeb1f712ebc6f1"
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants