Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidra committed Aug 8, 2022
1 parent 35e4fc1 commit afc0325
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ xxxxx.yyyyy.zzzzz

## Header:

The header includes the signing scheme specified by "alg" field and the address type specified by "add" field and the token type specified by "typ" which is always set to "JW3T" for web3 tokens.
The header includes the signing scheme specified by "algorithm" field and the address type specified by "address_type" field and the token type specified by "token_type" which is always set to "JW3T" for web3 tokens.

e.g.

```json
{
"alg": "sr25519",
"add": "ss58",
"typ": "JW3T"
"algorithm": "sr25519",
"address_type": "ss58",
"token_type": "JW3T"
}
```

Expand All @@ -49,18 +49,18 @@ specifies that the token is a Json Web3 Token that is using sr25519 signing sche

The payload of the token is a json object which includes a required address claim that species the address of the account that has issued the token as well as some suggested claim fields:

- "add" (Address) Claim:
specifies the address of the account that has signed the token. This field is used during the token verification and if it is not a valid address of the type that is specified in the header `{"add":} ` the token verification should fail.
- "aud" (Audience) Claim :
The "aud" (audience) claim identifies the recipients that the JW3T is intended for. The audience is usually a uri that specifies the web resource or website that the token is issued for.
- "exp" (Expiration Time) Claim:
The "exp" (expiration time) claim identifies the expiration time on or after which the JW3T MUST NOT be accepted for processing. The processing of the "exp" claim requires that the current date/time MUST be before the expiration date/time listed in the "exp" claim.
- "nbf" (Not Before) Claim:
The "nbf" (not before) claim identifies the time before which the JWT MUST NOT be accepted for processing. The processing of the "nbf" claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the "nbf" claim.
- "address" (Address) Claim:
specifies the address of the account that has signed the token. This field is used during the token verification and if it is not a valid address of the type that is specified in the header `{"address_type":} ` the token verification should fail.
- "audience" (Audience) Claim :
The "audience" claim identifies the recipients that the JW3T is intended for. The audience is usually a uri that specifies the web resource or website that the token is issued for.
- "expires_at" (Expiration Time) Claim:
The "expires_at" (expiration time) claim identifies the expiration time on or after which the JW3T MUST NOT be accepted for processing. The processing of the "expires_at" claim requires that the current date/time MUST be before the expiration date/time listed in the "expires_at" claim.
- "not_before" (Not Before) Claim:
The "not_before" claim identifies the time before which the JWT MUST NOT be accepted for processing. The processing of the "not_before" claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the "not_before" claim.

## Signature:

The signature is generated by signing the header (as a JSON string) concatenated by a "." concatenated by the payload (as a JSON string) using the signing algorithm that is specified in the token header `{"alg":}`.
The signature is generated by signing the header (as a JSON string) concatenated by a "." concatenated by the payload (as a JSON string) using the signing algorithm that is specified in the token header `{"algorithm":}`.

`signature = sign(header + '.' + payload)`

Expand All @@ -83,7 +83,7 @@ To verify if a JW3T is valid, two verifications must be performed:

- the signatur should be verified to make sure it is a valid signature of the `header + "." + payload`.

- the address claim in the payload `header.add` should be a valid address of the address type that is specified in the header `payload.add` and match the address of the account that has signed the message `signature.address`
- the address claim in the payload `payload.address` should be a valid address of the address type that is specified in the header `header.address_type` and match the address of the account that has signed the message `signature.address`

# How to use this package?

Expand Down Expand Up @@ -119,21 +119,21 @@ let signingAccount = { account };
let address = account.address;

let header = {
alg: 'sr25519',
typ: 'JW3T',
add: 'ss58',
algorithm: 'sr25519',
token_type: 'JW3T',
address_type: 'ss58',
};

let payload = {
add: address,
address: address,
};

// set expire to 24 hours
let exp = Math.floor(Date.now() / 1000) + 24 * 3600;
let expires_at = Math.floor(Date.now() / 1000) + 24 * 3600;

let content = new jw3t.JW3TContent(header, payload)
.setAudience('uri:test')
.setExpiration(exp);
.setExpiration(expires_at);

let polkaJsSigner = new jw3t.PolkaJsSigner(signingAccount);
let signer = new jw3t.JW3TSigner(polkaJsSigner, content);
Expand All @@ -145,7 +145,7 @@ to verify a token is valid.

```js
let token =
'eyJhbGciOiJzcjI1NTE5IiwidHlwIjoiSlczVCIsImFkZCI6InNzNTgifQ.eyJhZGQiOiI1REFBbnJqN1ZIVHpubjJBV0JlbU11eUJ3WldzNkZORmpkeVZYVWVZdW0zUFRYRnkiLCJhdWQiOiJ1cmk6dGVzdCIsImV4cCI6MTY0MTkzODE0Nn0.Oh92A5DXXp2T6vfdwpM90uWyHjzohUxIJMbAG_cQ-1A8GJW_iGjWi5DT0VWEpoZ3UIj71lIxZ4GmWvKD0BCEhA';
'ewogImFsZ29yaXRobSI6ICJzcjI1NTE5IiwKICJ0b2tlbl90eXBlIjogIkpXM1QiLAogImFkZHJlc3NfdHlwZSI6ICJzczU4Igp9.ewogImFkZHJlc3MiOiAiNUdyd3ZhRUY1elhiMjZGejlyY1FwRFdTNTdDdEVSSHBOZWhYQ1BjTm9IR0t1dFFZIiwKICJub25jZSI6ICJmNzdiNzAiLAogIm9uX2JlaGFsZl9vZiI6ICI1RkhuZVc0NnhHWGdzNW1VaXZlVTRzYlR5R0J6bXN0VXNwWkM5MlVoakpNNjk0dHkiLAogInByb3h5X3R5cGUiOiAiZ292ZXJuYW5jZSIsCiAiYXVkaWVuY2UiOiAidXJpOnRlc3QiLAogImV4cGlyZXNfYXQiOiAxNjYwMDY3NDQ1Cn0.-GH6igp_L_egG0tJj18-hlZbllG0WliFa6JTEvLxa3RRvmVSD2gBHbFpNd0jaOTXLTpZ1asKCObtLYFw7jObhA';

let polkaJsVerifier = new jw3t.PolkaJsVerifier();
let verifier = new jw3t.JW3TVerifier(polkaJsVerifier);
Expand Down

0 comments on commit afc0325

Please sign in to comment.