Skip to content

JWZ - JSON Web Zero Knowledge

JSON Web Zero-knowledge (JWZ) is an open standard for representing messages proven with zero-knowledge technology.

In Iden3 Protocol, JWZ is the core primitive to manage communications between different parties. A JWZ expands the signature schema of the popular JWT standard.

Any message can be packed inside a JWZ while the signature guarantees data integrity and provenance of the message, providing helpful metadata among the message.

JWZ

This is an example of a JWZ generated by an identity wallet as a response to the auth request generated in the ZK-login Integration Demo.

JWZ consists of three parts separated by dots (.), which are:

  • Header
  • Payload message
  • Signature

eyJhbGciOiJncm90aDE2IiwiY2lyY3VpdElkIjoiYXV0aCIsImNyaXQiOlsiY2lyY3VpdElkIl0sInR5cCI6ImFwcGxpY2F0aW9uL2lkZW4zLXprcC1qc29uIn0.eyJpZCI6IjZhOWU4MDlhLTAwNzktNDI2OS1hMzA5LTdlYmIyZDE2YTIzYyIsInR5cCI6ImFwcGxpY2F0aW9uL2lkZW4zY29tbS1wbGFpbi1qc29uIiwidHlwZSI6Imh0dHBzOi8vaWRlbjMtY29tbXVuaWNhdGlvbi5pby9hdXRob3JpemF0aW9uLzEuMC9yZXNwb25zZSIsInRoaWQiOiI3ZjM4YTE5My0wOTE4LTRhNDgtOWZhYy0zNmFkZmRiOGI1NDIiLCJmcm9tIjoiMTFCckE5cmhiWEJwWEMyS0tUOTlzNTEyc1htYnlWa3V1MjFuWWU0NHFiIiwidG8iOiIxMTI1R0pxZ3c2WUVzS0Z3ajYzR1k4N01NeFBMOWt3REt4UFVpd01MTloiLCJib2R5Ijp7Im1lc3NhZ2UiOiJtZXNzYWdlIHRvIHNpZ24iLCJzY29wZSI6W3siaWQiOjEsImNpcmN1aXRfaWQiOiJjcmVkZW50aWFsQXRvbWljUXVlcnlTaWciLCJwcm9vZiI6eyJwaV9hIjpbIjIzNDkzNTkyMTg4NjIyMTAxOTk4NTgzMTc3MTE2OTMwMDAyNTg2MzIwMjQxMzk4MjE2NTQ0MTk1Nzg4MTg3MTc0MDk5MTExMDMzNDUiLCI5NzgzNjU5NTQyNzg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4NjY1NTIzNjkxNDc0NjgxNjY5MDIzNzg3OTA5MTIiXX0

Each part of the token can be parse into human-readable string by base 64 decoding.

Defines the feature of the token.

{
    "alg":"groth16",
    "circuitId":"auth",
    "crit":["circuitId"],
    "typ":"application/iden3-zkp-json"
}

alg - is a zero-knowledge algorithm that is used for proof generation.

circuitId - is a circuit that is used for proof generation. For authentication - auth circuit must be used.

crit describes the list of header keys that the verifier must support.

typ is the media type of the message. In our case, it’s the protocol type of packed message application/iden3-zkp-json

Payload Message

Contains the message that wants to be shared with another party

In this example the message is the proof related to the query analysed previously. However, any type of message can be included in the payload.

{
    "id":"6a9e809a-0079-4269-a309-7ebb2d16a23c",
    "typ":"application/iden3comm-plain-json",
    "type":"https://iden3-communication.io/authorization/1.0/response",
    "thid":"7f38a193-0918-4a48-9fac-36adfdb8b542",
    "from":"11BrA9rhbXBpXC2KKT99s512sXmbyVkuu21nYe44qb",
    "to":"1125GJqgw6YEsKFwj63GY87MMxPL9kwDKxPUiwMLNZ",
    "body": {
        "message":"message to sign",
        "scope":[
                    {"id":1,
                    "circuit_id":"credentialAtomicQuerySig",
                    "proof":
                        {"pi_a":["2349359218862210199858317711693000258632024139821654419578818717409911103345","9783659542781935947594271195809997372938499745037725231480617782895108798638","1"],
                        "pi_b":[["2722574881281545082903602222060947207904770262330936547149603701719115676966","9125080078643389548237112954563029185556286301890398763514523119480036570311"],["13640309800784055202696099782919798561985490702663538168219115175849999919373","10363320462296001798560505781397373032943297571589677076420550877863634477652"],["1","0"]],
                        "pi_c":["19468289507428515297055423521369058514858228111400619397089184798795502030434","6184574667862689946294380001099683927560394818236379313581126620262051325990","1"],
                        "curve":null,
                        "protocol":"groth16"},
                    "pub_signals":["16516191222276484743019422039821108870627271580720329599340789241270015286288","378188866234679794171665698554648912262550143866552369147468166902378790912","12975766351353223580809906170006466070394741783925392691515947652647516746182","1","53103020833917443995100151185922895916219347076953603032182812222607392768","15586519700705912779173573830121623565889728172039195968425571091013745698866","1655304049","210459579859058135404770043788028292398","2","2","20000101","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]
                    }
                ]
            }
}

Signature

It represents a ZK authentication proof based on the auth circuit

{
    "proof":
        {"pi_a":["21790803226415443587503298769240809063119183268333855738128458006625138738120","16698620236621729523865377919383263607734895464901046682727441847387053452223","1"],
        "pi_b":[["4535748847451620727030850968348283533221892156479784478550576291967870146369","9738273818404832763797755729364469359032589374257077987314840074291700046663"],["8042153050904814753524299936973688033484759099000616952597240924020161522903",
        "1218003154957903599251594293450972807444603590560917060011174380810363153016"],["1","0"]],"pi_c":["10794433255457405457150965108242418679271264291142079358387795050871818405862","20942055211064325866586510007566802726876816237121828360483948741223991935198","1"],
        "protocol":"groth16"},
    "pub_signals":["18016462927783600482822681548985061099369144273315905055378451289735264127532","12975766351353223580809906170006466070394741783925392691515947652647516746182","378188866234679794171665698554648912262550143866552369147468166902378790912"]
}

Difference between JWT and JWZ

JWT relies on digital signatures for secure transmission of information. In particular "JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA". (JWT.io). In JWZ, this signature is performed with Zero Knowledge. In particular:

  • The header and the payload gets hashed together using the poseidon hash
  • The JWZ initiator signs the hashed content using his/her private key
  • The JWZ creator generates a proof using the authorization circuit to demonstrate that his/her identity signed the content
  • The proof gets included in the zero knowledge proof of the JWZ together with the public inputs used inside the circuit to generate the proof
  • Any third party that access the JWZ can verify the proof to check if the information contained in the payload actually originated from that identity and hasn't tampered with.

Usage

JWZ represents the main instrument to communicate securely between parties off-chain. This data primitive integrates seamlessy withing web2 architectures for authentication purposes.

Here we used the JWZ to manage the communication between user and verifier. A JWZ can also be used in the communiciation between user and issuer for user to prove their identity in order to fetch the claims associated with their identity.

For web3/smart contract based authentication the data must be passed in a different format. This will be the subject of the next section of the tutorial.

Libraries

  • js-jwz for JavaScript implementation
  • go-jwz for Go implementation