Skip to content

Commit 197c40b

Browse files
authoredJun 17, 2024··
feat: add sdk jwt revocation verification (#231)
Signed-off-by: Javier Ribó <elribonazo@gmail.com>
1 parent 9ba1950 commit 197c40b

File tree

18 files changed

+7381
-3767
lines changed

18 files changed

+7381
-3767
lines changed
 

‎package-lock.json

+3,021-3,625
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
"coverage": "npm run test -- --coverage",
4040
"lint": "npx eslint .",
4141
"docs": "npx typedoc --options typedoc.js",
42-
"prepare": "npx husky"
42+
"prepare": "npx husky",
43+
"preinstall": "sh preinstall.sh",
44+
"postinstall": "sh postinstall.sh"
4345
},
4446
"author": "IOHK",
4547
"repository": {
@@ -81,7 +83,9 @@
8183
"@types/elliptic": "^6.4.16",
8284
"@types/google-protobuf": "^3.15.6",
8385
"@types/jest": "^29.5.5",
86+
"@types/jsonld": "^1.5.14",
8487
"@types/node": "^18.14.2",
88+
"@types/pako": "^2.0.3",
8589
"@types/sinon": "^10.0.13",
8690
"@types/sinon-chai": "^3.2.9",
8791
"@types/uuid": "^9.0.1",
@@ -119,7 +123,7 @@
119123
"rollup-plugin-polyfill-node": "^0.12.0",
120124
"rollup-plugin-strip-code": "^0.2.7",
121125
"rollup-plugin-typescript2": "^0.34.1",
122-
"semantic-release": "^21.1.1",
126+
"semantic-release": "^24.0.0",
123127
"semantic-release-slack-bot": "^4.0.2",
124128
"sinon": "^15.0.1",
125129
"sinon-chai": "^3.7.0",
@@ -205,8 +209,12 @@
205209
"hash.js": "1.1.7",
206210
"isows": "^1.0.3",
207211
"jose": "^4.15.5",
212+
"jsonld": "^8.3.2",
208213
"jsonwebtoken": "^9.0.0",
209214
"multiformats": "^9.9.0",
215+
"pako": "^2.1.0",
216+
"patch-package": "^8.0.0",
217+
"postinstall-postinstall": "^2.1.0",
210218
"rxdb": "^14.17.1",
211219
"text-encoding": "^0.7.0",
212220
"util": "^0.12.5",

‎patches/rxdb+14.17.1.patch

+3,065
Large diffs are not rendered by default.

‎postinstall.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
FILE="./node_modules/rxdb"
3+
set -e
4+
# Patching RXDB package for 2 main reasons
5+
# 1. Its using crypto-js which is an insecure dependency we don't want to even
6+
# include in our package-locks, its 100% not used as we have created as we have
7+
# created our own package
8+
# 2. The second one is around a replication package that rxdb uses
9+
# firebase which includes a medium severity vuleranility which we also don't
10+
# want to be including in our package locks, despite 100% not being used.
11+
# Workaround: We install
12+
rm -rf ./package-lock.json
13+
rm -rf ./node_modules/.package-lock.json
14+
npm i --ignore-scripts

‎preinstall.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
FILE="./node_modules/rxdb"
3+
set -e
4+
5+
6+
7+
8+
if [ -z "./node_modules/rxdb/patched/done" ]; then
9+
echo "preinstall completed"
10+
else
11+
npm i rxdb@14.17.1 --ignore-scripts
12+
npx patch-package
13+
touch ./node_modules/rxdb/patched/done
14+
fi
15+
16+
17+
18+
19+
20+
21+

‎src/apollo/utils/Secp256k1PublicKey.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from "../../domain/models/keyManagement";
1414

1515
import ApolloPKG from "@atala/apollo";
16-
import { rawToDER } from "../../domain/utils/DER";
1716
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;
1817

1918
/**
@@ -188,9 +187,8 @@ export class Secp256k1PublicKey extends PublicKey implements StorableKey, Export
188187
}
189188

190189
verify(message: Buffer, signature: Buffer) {
191-
const normalised = rawToDER(signature)
192190
return this.native.verify(
193-
Int8Array.from(normalised),
191+
Int8Array.from(signature),
194192
Int8Array.from(message)
195193
);
196194
}

‎src/domain/buildingBlocks/Pollux.ts

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export interface Pollux {
5353
[name: string]: any
5454
}>;
5555

56+
isCredentialRevoked: (credential: Credential) => Promise<boolean>;
57+
5658
parseCredential: (
5759
credentialBuffer: Uint8Array,
5860
options?: { type: CredentialType;[name: string]: any; }

‎src/domain/models/VerifiableCredential.ts

+70-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export enum DescriptorItemFormat {
2121
}
2222

2323
export enum W3CVerifiableCredentialContext {
24-
credential = "https://www.w3.org/2018/credentials/v1"
24+
credential = "https://www.w3.org/2018/credentials/v1",
25+
revocation = "https://w3id.org/vc/status-list/2021/v1"
2526
}
2627

2728
export enum W3CVerifiableCredentialType {
2829
presentation = "VerifiablePresentation",
29-
credential = "VerifiableCredential"
30+
credential = "VerifiableCredential",
31+
revocation = "StatusList2021Credential"
3032
}
3133

3234
export enum SDJWTVerifiableCredentialProperties {
@@ -259,9 +261,73 @@ export type W3CVerifiableCredential = {
259261
id: string,
260262
type: string
261263
},
262-
credentialStatus?: {
264+
credentialStatus?: JWTRevocationStatus | unknown
265+
}
266+
267+
export interface W3CVerifiableCredentialData {
268+
id: string,
269+
type: string
270+
}
271+
272+
273+
export enum JWTRevocationStatusPurpose {
274+
Revocation = "Revocation",
275+
Suspension = 'Suspension'
276+
}
277+
278+
export enum CredentialStatusType {
279+
StatusList2021Entry = 'StatusList2021Entry'
280+
}
281+
282+
283+
export enum RevocationType {
284+
StatusList2021 = 'StatusList2021'
285+
}
286+
287+
export interface JWTRevocationStatus extends W3CVerifiableCredentialData {
288+
statusPurpose: JWTRevocationStatusPurpose,
289+
statusListIndex: number,
290+
id: string,
291+
type: RevocationType,
292+
statusListCredential: string
293+
}
294+
295+
export enum JWTProofType {
296+
EcdsaSecp256k1Signature2019 = "EcdsaSecp256k1Signature2019",
297+
DataIntegrityProof = "DataIntegrityProof",
298+
Unknown = "Unknown"
299+
}
300+
301+
export enum JWTProofPurpose {
302+
ProofPurpose = 'assertionMethod'
303+
}
304+
305+
export interface JWTStatusListResponse {
306+
"@context": [
307+
W3CVerifiableCredentialContext.credential,
308+
W3CVerifiableCredentialContext.revocation
309+
],
310+
type: [
311+
W3CVerifiableCredentialType.credential,
312+
W3CVerifiableCredentialType.revocation
313+
],
314+
issuer: string,
315+
id: string,
316+
issuanceDate: string,
317+
credentialSubject: {
263318
id: string,
264-
type: string
319+
type: string,
320+
statusPurpose: string,
321+
encodedList: string
322+
},
323+
proof: {
324+
type: JWTProofType,
325+
jws: string,
326+
proofPurpose: JWTProofPurpose,
327+
verificationMethod: string,
328+
created: string,
329+
proofValue: string,
330+
cryptoSuite: string
265331
}
266332
}
267333

‎src/domain/models/errors/Pollux.ts

+24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ export class InvalidPresentationProofArgs extends Error {
1616
}
1717
}
1818

19+
export class CredentialRevocationTypeInvalid extends Error {
20+
constructor(message?: string) {
21+
super(message || "CredentialStatus revocation type not supported");
22+
}
23+
}
24+
25+
export class InvalidCredentialStatus extends Error {
26+
constructor(message?: string) {
27+
super(message || "CredentialStatus status is invalid");
28+
}
29+
}
30+
31+
export class InvalidRevocationStatusResponse extends Error {
32+
constructor(message?: string) {
33+
super(message || "CredentialStatus response is invalid");
34+
}
35+
}
36+
37+
export class InvalidRevocationStatusResponseSignature extends Error {
38+
constructor(message?: string) {
39+
super(message || "CredentialStatus response proof signatue mismatch or invalid.");
40+
}
41+
}
42+
1943
export class CredentialTypeNotSupported extends Error {
2044
constructor(message?: string) {
2145
super(message || "Credential type not supported");

0 commit comments

Comments
 (0)