-
Couldn't load subscription status.
- Fork 5
feat: implemented cwt status list #81
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
Draft
dinkar-jain
wants to merge
24
commits into
main
Choose a base branch
from
cwt-status-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
795ad38
feat: implement credential status management with StatusArray, Status…
dinkar-jain 0e82b46
refactor: update StatusArray and StatusList constructors to use optio…
dinkar-jain bd500cf
refactor: update StatusArray and StatusList to use AllowedBitsPerEntr…
dinkar-jain 8a552a4
refactor: update enum values in CwtStatusListClaims and CwtStandardCl…
dinkar-jain 6f54b85
feat: added CWT status token verification
dinkar-jain 113785c
refactor: rename constructor parameter in StatusArray and update vari…
dinkar-jain f95c6f9
refactor: simplify return statements in StatusList and CWTStatusToken…
dinkar-jain 1ed21b0
feat: implement CoseType enum and update CWTStatusToken to use CoseTy…
dinkar-jain 4c33d5d
fix: standardize error message formatting in CWTStatusToken verification
dinkar-jain fcb5c8f
feat: migrate zlib usage to pako for compression and decompression in…
dinkar-jain 19a72b6
feat: add fetchStatusListUri method to retrieve status list from a gi…
dinkar-jain e4af828
feat: add abort-controller and node-fetch for improved fetch handling…
dinkar-jain 21fdb40
refactor: rename CoseType to CoseStructureType and update related ref…
dinkar-jain 142974b
refactor: update interface visibility and method names in CwtStatusTo…
dinkar-jain 8328285
refactor: remove unused dependencies and update TypeScript lib config…
dinkar-jain b354d29
refactor: update StatusArray property naming and improve error messag…
dinkar-jain 13caadc
refactor: update CoseStructureType usage in CwtStatusTokenOptions and…
dinkar-jain e7cb9af
refactor: add mdocContext to CwtStatusTokenOptions and CwtVerifyOptio…
dinkar-jain e6b52b7
refactor: update CwtStatusToken to use new claims enumeration and dat…
dinkar-jain 6b2285f
refactor: introduce custom error classes for status list validation; …
dinkar-jain 6e9ca7b
refactor: add StatusInfo model and integrate status handling in Mobil…
dinkar-jain 87a85a5
refactor: update StatusInfo handling in IssuerSignedBuilder and Mobil…
dinkar-jain e239bb1
refactor: simplify StatusInfo structure by removing unnecessary claim…
dinkar-jain 9ffcc8b
refactor: rename fetchStatusListUri to fetchStatusList for consistenc…
dinkar-jain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| export enum CoseStructureType { | ||
| Sign = 'sign', | ||
| Sign1 = 'sign1', | ||
| Encrypt = 'encrypt', | ||
| Encrypt0 = 'encrypt0', | ||
| Mac = 'mac', | ||
| Mac0 = 'mac0', | ||
| } | ||
| export enum CoseStructureTag { | ||
| Sign = 98, | ||
| Sign1 = 18, | ||
| Encrypt = 96, | ||
| Encrypt0 = 16, | ||
| Mac = 97, | ||
| Mac0 = 17, | ||
| } | ||
| export const CoseTypeToTag: Record<CoseStructureType, CoseStructureTag> = { | ||
| [CoseStructureType.Sign]: CoseStructureTag.Sign, | ||
| [CoseStructureType.Sign1]: CoseStructureTag.Sign1, | ||
| [CoseStructureType.Encrypt]: CoseStructureTag.Encrypt, | ||
| [CoseStructureType.Encrypt0]: CoseStructureTag.Encrypt0, | ||
| [CoseStructureType.Mac]: CoseStructureTag.Mac, | ||
| [CoseStructureType.Mac0]: CoseStructureTag.Mac0, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // biome-ignore format: | ||
| class StatusListError extends Error { constructor(message: string = new.target.name) { super(message) } } | ||
|
|
||
| export class InvalidStatusListFormatError extends StatusListError {} | ||
| export class InvalidStatusListBitsError extends StatusListError { | ||
| constructor(bits: number, allowedBits: readonly number[]) { | ||
| super(`Invalid bits per entry: ${bits}. Allowed values are ${allowedBits.join(', ')}.`) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './status-array' | ||
| export * from './status-list' | ||
| export * from './status-token' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import * as zlib from 'pako' | ||
|
|
||
| const arraySize = 1024 | ||
| export const allowedBitsPerEntry = [1, 2, 4, 8] as const | ||
| export type AllowedBitsPerEntry = (typeof allowedBitsPerEntry)[number] | ||
|
|
||
| export class StatusArray { | ||
| private readonly _bitsPerEntry: AllowedBitsPerEntry | ||
| private readonly statusBitMask: number | ||
| private readonly data: Uint8Array | ||
|
|
||
| constructor(bitsPerEntry: AllowedBitsPerEntry, byteArr?: Uint8Array) { | ||
| if (!allowedBitsPerEntry.includes(bitsPerEntry)) { | ||
| throw new Error(`Only bits ${allowedBitsPerEntry.join(', ')} per entry are allowed.`) | ||
| } | ||
|
|
||
| this._bitsPerEntry = bitsPerEntry | ||
| this.statusBitMask = (1 << bitsPerEntry) - 1 | ||
| this.data = byteArr ? byteArr : new Uint8Array(arraySize) | ||
| } | ||
|
|
||
| private computeByteAndOffset(index: number): { byteIndex: number; bitOffset: number } { | ||
| const byteIndex = Math.floor((index * this._bitsPerEntry) / 8) | ||
| const bitOffset = (index * this._bitsPerEntry) % 8 | ||
|
|
||
| return { byteIndex, bitOffset } | ||
| } | ||
|
|
||
| get bitsPerEntry(): AllowedBitsPerEntry { | ||
| return this._bitsPerEntry | ||
| } | ||
|
|
||
| set(index: number, status: number): void { | ||
| if (status < 0 || status > this.statusBitMask) { | ||
| throw new Error(`Invalid status: ${status}. Must be between 0 and ${this.statusBitMask}.`) | ||
| } | ||
|
|
||
| const { byteIndex, bitOffset } = this.computeByteAndOffset(index) | ||
|
|
||
| // Clear current bits | ||
| this.data[byteIndex] &= ~(this.statusBitMask << bitOffset) | ||
|
|
||
| // Set new status bits | ||
| this.data[byteIndex] |= (status & this.statusBitMask) << bitOffset | ||
| } | ||
|
|
||
| get(index: number): number { | ||
| const { byteIndex, bitOffset } = this.computeByteAndOffset(index) | ||
|
|
||
| return (this.data[byteIndex] >> bitOffset) & this.statusBitMask | ||
| } | ||
|
|
||
| compress(): Uint8Array { | ||
| return zlib.deflate(this.data) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import * as zlib from 'pako' | ||
| import { cborDecode, cborEncode } from '../cbor' | ||
| import { InvalidStatusListBitsError, InvalidStatusListFormatError } from './error' | ||
| import { type AllowedBitsPerEntry, StatusArray, allowedBitsPerEntry } from './status-array' | ||
|
|
||
| export interface CborStatusListOptions { | ||
| statusArray: StatusArray | ||
| aggregationUri?: string | ||
| } | ||
|
|
||
| export interface CborStatusList { | ||
| bits: AllowedBitsPerEntry | ||
| lst: Uint8Array | ||
| aggregation_uri?: string | ||
| } | ||
|
|
||
| export class StatusList { | ||
| static buildCborStatusList(options: CborStatusListOptions): Uint8Array { | ||
| const compressed = options.statusArray.compress() | ||
|
|
||
| const statusList: CborStatusList = { | ||
| bits: options.statusArray.bitsPerEntry, | ||
| lst: compressed, | ||
| } | ||
|
|
||
| if (options.aggregationUri) { | ||
| statusList.aggregation_uri = options.aggregationUri | ||
| } | ||
| return cborEncode(statusList) | ||
| } | ||
|
|
||
| static verifyStatus(cborStatusList: Uint8Array, index: number, expectedStatus: number): boolean { | ||
| const decoded = cborDecode(cborStatusList) | ||
| if (!(decoded instanceof Map)) { | ||
| throw new Error('Decoded CBOR data is not a Map.') | ||
| } | ||
|
|
||
| const statusList: CborStatusList = { | ||
| bits: decoded.get('bits') as AllowedBitsPerEntry, | ||
| lst: decoded.get('lst') as Uint8Array, | ||
| aggregation_uri: decoded.get('aggregation_uri') as string | undefined, | ||
| } | ||
| const { bits, lst } = statusList | ||
|
|
||
| if (!statusList || !lst || !bits) { | ||
| throw new InvalidStatusListFormatError() | ||
| } | ||
| if (!allowedBitsPerEntry.includes(bits)) { | ||
| throw new InvalidStatusListBitsError(bits, allowedBitsPerEntry) | ||
| } | ||
|
|
||
| const statusArray = new StatusArray(bits, zlib.inflate(lst)) | ||
| const actualStatus = statusArray.get(index) | ||
| return actualStatus === expectedStatus | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we hardcode it to 1024?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the specs there is no limit actually