@owf/token-status-list 0.1.0-alpha-20260302093714

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # @owf/token-status-list
2
+
3
+ Implementation of [Token Status List (draft-ietf-oauth-status-list)](https://datatracker.ietf.org/doc/draft-ietf-oauth-status-list/)
4
+ with core bitstring handling, JWT transport, and CWT/CBOR transport — all in one package.
5
+
6
+ ## Features
7
+
8
+ - **Core StatusList**: Variable bit-width (1/2/4/8-bit) status entries with deflate compression
9
+ - **JWT transport**: Create and decode Status List Tokens in JWT format
10
+ - **CWT transport**: Create and decode Status List Tokens in CWT/CBOR format
11
+ - **Referenced Token support**: Extract status claims from both JWT and CWT referenced tokens
12
+ - **COSE algorithm constants**: Standard IANA COSE algorithm identifiers
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @owf/token-status-list
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Core — create and query a status list
23
+
24
+ ```typescript
25
+ import { StatusList, StatusTypes } from '@owf/token-status-list'
26
+
27
+ // Create a list of 100 000 entries at 1 bit each
28
+ const list = new StatusList(new Array(100_000).fill(0), 1)
29
+
30
+ // Mark some entries
31
+ list.setStatus(42, StatusTypes.INVALID)
32
+ list.setStatus(99, StatusTypes.INVALID)
33
+
34
+ // Query a status
35
+ list.getStatus(42) // 1 (INVALID)
36
+ list.getStatus(0) // 0 (VALID)
37
+
38
+ // Compress / decompress for transport
39
+ const compressed = list.compressStatusListToBytes()
40
+ const restored = StatusList.decompressStatusListFromBytes(compressed, 1)
41
+ ```
42
+
43
+ ### JWT transport — issue and read a Status List Token
44
+
45
+ ```typescript
46
+ import { StatusList, createHeaderAndPayload, getListFromStatusListJWT } from '@owf/token-status-list'
47
+
48
+ const list = new StatusList(new Array(100_000).fill(0), 1)
49
+ list.setStatus(42, 1)
50
+
51
+ // Build header + payload (sign with your own JOSE library)
52
+ const { header, payload } = createHeaderAndPayload(
53
+ list,
54
+ { iss: 'https://issuer.example', sub: 'https://issuer.example/statuslists/1', iat: Math.floor(Date.now() / 1000) },
55
+ { alg: 'ES256', typ: '' },
56
+ )
57
+
58
+ // Later — decode the list back from a JWT string
59
+ const decoded = getListFromStatusListJWT(jwt)
60
+ decoded.getStatus(42) // 1
61
+ ```
62
+
63
+ ### JWT transport — read a referenced token's status entry
64
+
65
+ ```typescript
66
+ import { getStatusListFromJWT } from '@owf/token-status-list'
67
+
68
+ const entry = getStatusListFromJWT(referencedTokenJWT)
69
+ // entry.idx — index into the status list
70
+ // entry.uri — URI of the Status List Token
71
+ ```
72
+
73
+ ### CWT transport — issue and read a Status List Token
74
+
75
+ ```typescript
76
+ import {
77
+ StatusList,
78
+ COSEAlgorithms,
79
+ createStatusListCWTPayload,
80
+ createStatusListCWTHeader,
81
+ encodeCWTPayload,
82
+ decodeCWTPayload,
83
+ } from '@owf/token-status-list'
84
+
85
+ const list = new StatusList(new Array(100_000).fill(0), 1)
86
+ list.setStatus(42, 1)
87
+
88
+ // Build CWT claims and header (sign with your own COSE library)
89
+ const payload = createStatusListCWTPayload(list, 'https://issuer.example/statuslists/1', Math.floor(Date.now() / 1000))
90
+ const header = createStatusListCWTHeader(COSEAlgorithms.ES256, 'key-id-1')
91
+
92
+ // Encode to CBOR
93
+ const cborPayload = encodeCWTPayload(list, 'https://issuer.example/statuslists/1', Math.floor(Date.now() / 1000))
94
+
95
+ // Decode
96
+ const { subject, issuedAt, statusList } = decodeCWTPayload(cborPayload)
97
+ statusList.getStatus(42) // 1
98
+ ```
99
+
100
+ ### CWT transport — referenced token status claim
101
+
102
+ ```typescript
103
+ import { createCWTStatusClaim, encodeCWTStatusClaim, decodeCWTStatusClaim } from '@owf/token-status-list'
104
+
105
+ // Create
106
+ const claim = createCWTStatusClaim(42, 'https://issuer.example/statuslists/1')
107
+
108
+ // Encode/decode via CBOR
109
+ const encoded = encodeCWTStatusClaim(42, 'https://issuer.example/statuslists/1')
110
+ const decoded = decodeCWTStatusClaim(encoded)
111
+ // decoded.idx === 42, decoded.uri === '...'
112
+ ```
113
+
114
+ ## API
115
+
116
+ ### Core
117
+
118
+ | Export | Description |
119
+ |--------|-------------|
120
+ | `StatusList` | Main class — construct, get/set status, compress/decompress |
121
+ | `SLException` | Error class thrown by status-list operations |
122
+ | `StatusTypes` | Constants: `VALID`, `INVALID`, `SUSPENDED`, etc. |
123
+ | `MediaTypes` | MIME types for JWT and CWT status list tokens |
124
+ | `BitsPerStatus` | Type: `1 \| 2 \| 4 \| 8` |
125
+ | `StatusListEntry` | Type: `{ idx: number; uri: string }` |
126
+
127
+ ### JWT Transport
128
+
129
+ | Export | Description |
130
+ |--------|-------------|
131
+ | `createHeaderAndPayload` | Build JWT header + payload from a `StatusList` |
132
+ | `getListFromStatusListJWT` | Decode a `StatusList` from a JWT string |
133
+ | `getStatusListFromJWT` | Extract `StatusListEntry` from a referenced token JWT |
134
+ | `JWT_STATUS_LIST_TYPE` | `"statuslist+jwt"` |
135
+ | `JWTClaimNames` | Claim name constants |
136
+
137
+ ### CWT Transport
138
+
139
+ | Export | Description |
140
+ |--------|-------------|
141
+ | `createStatusListCWTPayload` | Build CWT claims from a `StatusList` |
142
+ | `createStatusListCWTHeader` | Build COSE protected header |
143
+ | `encodeCWTPayload` / `decodeCWTPayload` | CBOR encode/decode full payload |
144
+ | `encodeStatusListToCBOR` / `decodeStatusListFromCBOR` | CBOR encode/decode the status list only |
145
+ | `createCWTStatusClaim` | Build a referenced-token status claim object |
146
+ | `encodeCWTStatusClaim` / `decodeCWTStatusClaim` | CBOR encode/decode a status claim |
147
+ | `getListFromStatusListCWT` | Extract `StatusList` from CWT payload bytes |
148
+ | `getStatusListFromCWT` | Extract `StatusListEntry` from CWT payload bytes |
149
+ | `COSEAlgorithms` | IANA COSE algorithm identifiers (ES256, ES384, EdDSA, …) |
150
+ | `CWT_STATUS_LIST_TYPE` | `"application/statuslist+cwt"` |
151
+ | `CWTClaimKeys` / `CWTStatusListKeys` / `CWTStatusListInfoKeys` / `COSEHeaderKeys` | Numeric/string key constants |
@@ -0,0 +1,320 @@
1
+ import { JwtPayload } from "@owf/identity-common";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * Status Type values as defined in the spec.
6
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-7
7
+ */
8
+ declare const StatusTypes: {
9
+ /** The status of the Referenced Token is valid, correct or legal. */readonly VALID: 0; /** The status of the Referenced Token is revoked, annulled, taken back, recalled or cancelled. */
10
+ readonly INVALID: 1; /** The status of the Referenced Token is temporarily invalid, hanging, debarred from privilege. */
11
+ readonly SUSPENDED: 2; /** Application-specific status (0x03). */
12
+ readonly APPLICATION_SPECIFIC_3: 3; /** Application-specific status range start (0x0C). */
13
+ readonly APPLICATION_SPECIFIC_RANGE_START: 12; /** Application-specific status range end (0x0F). */
14
+ readonly APPLICATION_SPECIFIC_RANGE_END: 15;
15
+ };
16
+ type StatusType = (typeof StatusTypes)[keyof typeof StatusTypes] | number;
17
+ /**
18
+ * Media types for Status List Tokens
19
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-14.7
20
+ */
21
+ declare const MediaTypes: {
22
+ /** Media type for JWT-based Status List Token */readonly STATUS_LIST_JWT: "application/statuslist+jwt"; /** Media type for CWT-based Status List Token */
23
+ readonly STATUS_LIST_CWT: "application/statuslist+cwt";
24
+ };
25
+ /**
26
+ * BitsPerStatus type.
27
+ */
28
+ type BitsPerStatus = 1 | 2 | 4 | 8;
29
+ /**
30
+ * Reference to a status list entry.
31
+ */
32
+ interface StatusListEntry {
33
+ idx: number;
34
+ uri: string;
35
+ }
36
+ //#endregion
37
+ //#region src/cwt-types.d.ts
38
+ /**
39
+ * CWT Claim Keys as defined in draft-ietf-oauth-status-list
40
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.2
41
+ */
42
+ declare const CWTClaimKeys: {
43
+ readonly SUB: 2;
44
+ readonly EXP: 4;
45
+ readonly IAT: 6;
46
+ readonly TTL: 65534;
47
+ readonly STATUS_LIST: 65533;
48
+ readonly STATUS: 65535;
49
+ };
50
+ /**
51
+ * CWT Status List map keys
52
+ */
53
+ declare const CWTStatusListKeys: {
54
+ readonly BITS: "bits";
55
+ readonly LST: "lst";
56
+ readonly AGGREGATION_URI: "aggregation_uri";
57
+ };
58
+ /**
59
+ * CWT Status List Info keys (for referenced tokens)
60
+ */
61
+ declare const CWTStatusListInfoKeys: {
62
+ readonly IDX: "idx";
63
+ readonly URI: "uri";
64
+ };
65
+ /**
66
+ * COSE Header type parameter value for Status List CWT
67
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.2
68
+ */
69
+ declare const CWT_STATUS_LIST_TYPE = "application/statuslist+cwt";
70
+ /**
71
+ * CoAP Content-Format ID for Status List CWT (TBD in IANA registry)
72
+ */
73
+ declare const CWT_STATUS_LIST_CONTENT_FORMAT_ID: number | undefined;
74
+ /**
75
+ * COSE Header parameter keys
76
+ * @see https://www.iana.org/assignments/cose/cose.xhtml#header-parameters
77
+ */
78
+ declare const COSEHeaderKeys: {
79
+ readonly ALG: 1;
80
+ readonly CRIT: 2;
81
+ readonly CONTENT_TYPE: 3;
82
+ readonly KID: 4;
83
+ readonly IV: 5;
84
+ readonly PARTIAL_IV: 6;
85
+ readonly TYPE: 16;
86
+ readonly X5CHAIN: 33;
87
+ readonly X5T: 34;
88
+ readonly X5U: 35;
89
+ };
90
+ /**
91
+ * Status List in CBOR format
92
+ */
93
+ interface StatusListCBOR {
94
+ bits: BitsPerStatus;
95
+ lst: Uint8Array;
96
+ aggregation_uri?: string;
97
+ }
98
+ /**
99
+ * CWT Claims Set for a Status List Token
100
+ */
101
+ interface StatusListCWTPayload {
102
+ [CWTClaimKeys.SUB]: string;
103
+ [CWTClaimKeys.IAT]: number;
104
+ [CWTClaimKeys.EXP]?: number;
105
+ [CWTClaimKeys.TTL]?: number;
106
+ [CWTClaimKeys.STATUS_LIST]: StatusListCBOR;
107
+ }
108
+ /**
109
+ * CWT Claims Set for a Referenced Token with status
110
+ */
111
+ interface CWTwithStatusListPayload {
112
+ [CWTClaimKeys.SUB]?: string;
113
+ [CWTClaimKeys.IAT]?: number;
114
+ [CWTClaimKeys.EXP]?: number;
115
+ [CWTClaimKeys.STATUS]: {
116
+ status_list: StatusListEntry;
117
+ };
118
+ }
119
+ /**
120
+ * COSE protected header for Status List CWT
121
+ */
122
+ interface StatusListCWTHeader {
123
+ [COSEHeaderKeys.ALG]: number;
124
+ [COSEHeaderKeys.TYPE]: string | number;
125
+ [COSEHeaderKeys.KID]?: Uint8Array | string;
126
+ [COSEHeaderKeys.X5CHAIN]?: Uint8Array | Uint8Array[];
127
+ [COSEHeaderKeys.X5T]?: Uint8Array;
128
+ [COSEHeaderKeys.X5U]?: string;
129
+ }
130
+ //#endregion
131
+ //#region src/jwt-types.d.ts
132
+ /**
133
+ * JWT type header value for Status List Token
134
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.1
135
+ */
136
+ declare const JWT_STATUS_LIST_TYPE = "statuslist+jwt";
137
+ /**
138
+ * JWT claim names for Status List
139
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-14.1
140
+ */
141
+ declare const JWTClaimNames: {
142
+ readonly STATUS: "status";
143
+ readonly STATUS_LIST: "status_list";
144
+ readonly TTL: "ttl";
145
+ readonly IDX: "idx";
146
+ readonly URI: "uri";
147
+ readonly BITS: "bits";
148
+ readonly LST: "lst";
149
+ readonly AGGREGATION_URI: "aggregation_uri";
150
+ };
151
+ /**
152
+ * Payload for a JWT with a status reference.
153
+ */
154
+ interface JWTwithStatusListPayload extends JwtPayload {
155
+ status: {
156
+ status_list: StatusListEntry;
157
+ };
158
+ }
159
+ /**
160
+ * Payload for a Status List JWT.
161
+ */
162
+ interface StatusListJWTPayload extends JwtPayload {
163
+ ttl?: number;
164
+ status_list: {
165
+ bits: BitsPerStatus;
166
+ lst: string;
167
+ };
168
+ }
169
+ /**
170
+ * Header parameters for a JWT Status List Token.
171
+ */
172
+ type StatusListJWTHeaderParameters = {
173
+ alg: string;
174
+ typ: typeof JWT_STATUS_LIST_TYPE;
175
+ [key: string]: unknown;
176
+ };
177
+ //#endregion
178
+ //#region src/status-list.d.ts
179
+ /**
180
+ * StatusList is a class that manages a list of statuses with variable bit size.
181
+ */
182
+ declare class StatusList {
183
+ private _statusList;
184
+ private bitsPerStatus;
185
+ private totalStatuses;
186
+ constructor(statusList: number[], bitsPerStatus: BitsPerStatus);
187
+ /** Get the status list. */
188
+ get statusList(): number[];
189
+ /** Get the number of bits per status. */
190
+ getBitsPerStatus(): BitsPerStatus;
191
+ /** Get the status at a specific index. */
192
+ getStatus(index: number): number;
193
+ /** Set the status at a specific index. */
194
+ setStatus(index: number, value: number): void;
195
+ /** Compress the status list and return as raw bytes. */
196
+ compressStatusListToBytes(): Uint8Array;
197
+ /** Decompress a raw byte array and return a new StatusList instance. */
198
+ static decompressStatusListFromBytes(compressed: Uint8Array, bitsPerStatus: BitsPerStatus): StatusList;
199
+ /** Encode the status list into a byte array. */
200
+ encodeStatusList(): Uint8Array;
201
+ /** Decode the byte array into a status list. */
202
+ private static decodeStatusList;
203
+ }
204
+ //#endregion
205
+ //#region src/status-list-cwt.d.ts
206
+ /**
207
+ * Creates the CWT claims payload for a Status List Token.
208
+ */
209
+ declare function createStatusListCWTPayload(list: StatusList, subject: string, issuedAt: number, options?: {
210
+ exp?: number;
211
+ ttl?: number;
212
+ aggregationUri?: string;
213
+ }): StatusListCWTPayload;
214
+ /**
215
+ * Key resolution options for CWT header
216
+ */
217
+ interface CWTHeaderKeyOptions {
218
+ kid?: string | Uint8Array;
219
+ x5chain?: Uint8Array | Uint8Array[];
220
+ x5t?: Uint8Array;
221
+ x5u?: string;
222
+ }
223
+ /**
224
+ * Creates the protected header for a Status List CWT.
225
+ */
226
+ declare function createStatusListCWTHeader(alg: number, kidOrOptions?: string | Uint8Array | CWTHeaderKeyOptions): StatusListCWTHeader;
227
+ /**
228
+ * Encodes a Status List into CBOR format for CWT.
229
+ */
230
+ declare function encodeStatusListToCBOR(list: StatusList, aggregationUri?: string): Uint8Array;
231
+ /**
232
+ * Decodes a CBOR-encoded status list.
233
+ */
234
+ declare function decodeStatusListFromCBOR(cborData: Uint8Array): StatusList;
235
+ /**
236
+ * Encodes the full CWT claims payload to CBOR.
237
+ */
238
+ declare function encodeCWTPayload(list: StatusList, subject: string, issuedAt: number, options?: {
239
+ exp?: number;
240
+ ttl?: number;
241
+ aggregationUri?: string;
242
+ }): Uint8Array;
243
+ /**
244
+ * Decodes a CBOR-encoded CWT payload.
245
+ */
246
+ declare function decodeCWTPayload(cborData: Uint8Array): {
247
+ subject: string;
248
+ issuedAt: number;
249
+ exp?: number;
250
+ ttl?: number;
251
+ statusList: StatusList;
252
+ aggregationUri?: string;
253
+ };
254
+ /**
255
+ * Creates a status claim for a Referenced Token in CWT format.
256
+ */
257
+ declare function createCWTStatusClaim(idx: number, uri: string): CWTwithStatusListPayload[65535];
258
+ /**
259
+ * Encodes a status claim for a Referenced Token to CBOR.
260
+ */
261
+ declare function encodeCWTStatusClaim(idx: number, uri: string): Uint8Array;
262
+ /**
263
+ * Decodes a status claim from a Referenced Token CWT.
264
+ */
265
+ declare function decodeCWTStatusClaim(cborData: Uint8Array): StatusListEntry;
266
+ /**
267
+ * Extracts the status list from a decoded CWT payload.
268
+ */
269
+ declare function getListFromStatusListCWT(cwtPayload: Uint8Array): StatusList;
270
+ /**
271
+ * Extracts the status list entry from a decoded Referenced Token CWT.
272
+ */
273
+ declare function getStatusListFromCWT(cwtPayload: Uint8Array): StatusListEntry;
274
+ /**
275
+ * COSE Algorithm identifiers
276
+ * @see https://www.iana.org/assignments/cose/cose.xhtml#algorithms
277
+ */
278
+ declare const COSEAlgorithms: {
279
+ readonly ES256: -7;
280
+ readonly ES384: -35;
281
+ readonly ES512: -36;
282
+ readonly EdDSA: -8;
283
+ readonly PS256: -37;
284
+ readonly PS384: -38;
285
+ readonly PS512: -39;
286
+ readonly RS256: -257;
287
+ readonly RS384: -258;
288
+ readonly RS512: -259;
289
+ };
290
+ type COSEAlgorithm = (typeof COSEAlgorithms)[keyof typeof COSEAlgorithms];
291
+ //#endregion
292
+ //#region src/status-list-exception.d.ts
293
+ /**
294
+ * SLException is a custom error class for Status List related exceptions.
295
+ */
296
+ declare class SLException extends Error {
297
+ details?: unknown;
298
+ constructor(message: string, details?: unknown);
299
+ getFullMessage(): string;
300
+ }
301
+ //#endregion
302
+ //#region src/status-list-jwt.d.ts
303
+ /**
304
+ * Adds the status list to the payload and header of a JWT.
305
+ */
306
+ declare function createHeaderAndPayload(list: StatusList, payload: JwtPayload, header: StatusListJWTHeaderParameters): {
307
+ header: StatusListJWTHeaderParameters;
308
+ payload: JwtPayload;
309
+ };
310
+ /**
311
+ * Get the status list from a JWT, but do not verify the signature.
312
+ */
313
+ declare function getListFromStatusListJWT(jwt: string): StatusList;
314
+ /**
315
+ * Get the status list entry from a JWT, but do not verify the signature.
316
+ */
317
+ declare function getStatusListFromJWT(jwt: string): StatusListEntry;
318
+ //#endregion
319
+ export { type BitsPerStatus, type COSEAlgorithm, COSEAlgorithms, COSEHeaderKeys, CWTClaimKeys, type CWTHeaderKeyOptions, CWTStatusListInfoKeys, CWTStatusListKeys, CWT_STATUS_LIST_CONTENT_FORMAT_ID, CWT_STATUS_LIST_TYPE, type CWTwithStatusListPayload, JWTClaimNames, JWT_STATUS_LIST_TYPE, type JWTwithStatusListPayload, MediaTypes, SLException, StatusList, type StatusListCBOR, type StatusListCWTHeader, type StatusListCWTPayload, type StatusListEntry, type StatusListJWTHeaderParameters, type StatusListJWTPayload, type StatusType, StatusTypes, createCWTStatusClaim, createHeaderAndPayload, createStatusListCWTHeader, createStatusListCWTPayload, decodeCWTPayload, decodeCWTStatusClaim, decodeStatusListFromCBOR, encodeCWTPayload, encodeCWTStatusClaim, encodeStatusListToCBOR, getListFromStatusListCWT, getListFromStatusListJWT, getStatusListFromCWT, getStatusListFromJWT };
320
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,452 @@
1
+ import { deflate, inflate } from "pako";
2
+ import * as cbor from "cbor-x";
3
+ import { base64UrlToUint8Array, base64urlDecode, uint8ArrayToBase64Url } from "@owf/identity-common";
4
+
5
+ //#region src/cwt-types.ts
6
+ /**
7
+ * CWT Claim Keys as defined in draft-ietf-oauth-status-list
8
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.2
9
+ */
10
+ const CWTClaimKeys = {
11
+ SUB: 2,
12
+ EXP: 4,
13
+ IAT: 6,
14
+ TTL: 65534,
15
+ STATUS_LIST: 65533,
16
+ STATUS: 65535
17
+ };
18
+ /**
19
+ * CWT Status List map keys
20
+ */
21
+ const CWTStatusListKeys = {
22
+ BITS: "bits",
23
+ LST: "lst",
24
+ AGGREGATION_URI: "aggregation_uri"
25
+ };
26
+ /**
27
+ * CWT Status List Info keys (for referenced tokens)
28
+ */
29
+ const CWTStatusListInfoKeys = {
30
+ IDX: "idx",
31
+ URI: "uri"
32
+ };
33
+ /**
34
+ * COSE Header type parameter value for Status List CWT
35
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.2
36
+ */
37
+ const CWT_STATUS_LIST_TYPE = "application/statuslist+cwt";
38
+ /**
39
+ * CoAP Content-Format ID for Status List CWT (TBD in IANA registry)
40
+ */
41
+ const CWT_STATUS_LIST_CONTENT_FORMAT_ID = void 0;
42
+ /**
43
+ * COSE Header parameter keys
44
+ * @see https://www.iana.org/assignments/cose/cose.xhtml#header-parameters
45
+ */
46
+ const COSEHeaderKeys = {
47
+ ALG: 1,
48
+ CRIT: 2,
49
+ CONTENT_TYPE: 3,
50
+ KID: 4,
51
+ IV: 5,
52
+ PARTIAL_IV: 6,
53
+ TYPE: 16,
54
+ X5CHAIN: 33,
55
+ X5T: 34,
56
+ X5U: 35
57
+ };
58
+
59
+ //#endregion
60
+ //#region src/jwt-types.ts
61
+ /**
62
+ * JWT type header value for Status List Token
63
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.1
64
+ */
65
+ const JWT_STATUS_LIST_TYPE = "statuslist+jwt";
66
+ /**
67
+ * JWT claim names for Status List
68
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-14.1
69
+ */
70
+ const JWTClaimNames = {
71
+ STATUS: "status",
72
+ STATUS_LIST: "status_list",
73
+ TTL: "ttl",
74
+ IDX: "idx",
75
+ URI: "uri",
76
+ BITS: "bits",
77
+ LST: "lst",
78
+ AGGREGATION_URI: "aggregation_uri"
79
+ };
80
+
81
+ //#endregion
82
+ //#region src/status-list-exception.ts
83
+ /**
84
+ * SLException is a custom error class for Status List related exceptions.
85
+ */
86
+ var SLException = class SLException extends Error {
87
+ constructor(message, details) {
88
+ super(message);
89
+ Object.setPrototypeOf(this, SLException.prototype);
90
+ this.name = "SLException";
91
+ this.details = details;
92
+ }
93
+ getFullMessage() {
94
+ return `${this.name}: ${this.message} ${this.details ? `- ${JSON.stringify(this.details)}` : ""}`;
95
+ }
96
+ };
97
+
98
+ //#endregion
99
+ //#region src/status-list.ts
100
+ /**
101
+ * StatusList is a class that manages a list of statuses with variable bit size.
102
+ */
103
+ var StatusList = class StatusList {
104
+ constructor(statusList, bitsPerStatus) {
105
+ if (![
106
+ 1,
107
+ 2,
108
+ 4,
109
+ 8
110
+ ].includes(bitsPerStatus)) throw new SLException("bitsPerStatus must be 1, 2, 4, or 8");
111
+ for (let i = 0; i < statusList.length; i++) if (statusList[i] > 2 ** bitsPerStatus) throw new SLException(`Status value out of range at index ${i} with value ${statusList[i]}`);
112
+ this._statusList = statusList;
113
+ this.bitsPerStatus = bitsPerStatus;
114
+ this.totalStatuses = statusList.length;
115
+ }
116
+ /** Get the status list. */
117
+ get statusList() {
118
+ return this._statusList;
119
+ }
120
+ /** Get the number of bits per status. */
121
+ getBitsPerStatus() {
122
+ return this.bitsPerStatus;
123
+ }
124
+ /** Get the status at a specific index. */
125
+ getStatus(index) {
126
+ if (index < 0 || index >= this.totalStatuses) throw new Error("Index out of bounds");
127
+ return this._statusList[index];
128
+ }
129
+ /** Set the status at a specific index. */
130
+ setStatus(index, value) {
131
+ if (index < 0 || index >= this.totalStatuses) throw new Error("Index out of bounds");
132
+ this._statusList[index] = value;
133
+ }
134
+ /** Compress the status list and return as raw bytes. */
135
+ compressStatusListToBytes() {
136
+ return deflate(this.encodeStatusList(), { level: 9 });
137
+ }
138
+ /** Decompress a raw byte array and return a new StatusList instance. */
139
+ static decompressStatusListFromBytes(compressed, bitsPerStatus) {
140
+ try {
141
+ const decompressed = inflate(compressed);
142
+ return new StatusList(StatusList.decodeStatusList(decompressed, bitsPerStatus), bitsPerStatus);
143
+ } catch (err) {
144
+ throw new Error(`Decompression failed: ${err}`);
145
+ }
146
+ }
147
+ /** Encode the status list into a byte array. */
148
+ encodeStatusList() {
149
+ const numBits = this.bitsPerStatus;
150
+ const numBytes = Math.ceil(this.totalStatuses * numBits / 8);
151
+ const byteArray = new Uint8Array(numBytes);
152
+ let byteIndex = 0;
153
+ let bitIndex = 0;
154
+ let currentByte = "";
155
+ for (let i = 0; i < this.totalStatuses; i++) {
156
+ currentByte = this._statusList[i].toString(2).padStart(numBits, "0") + currentByte;
157
+ bitIndex += numBits;
158
+ if (bitIndex >= 8 || i === this.totalStatuses - 1) {
159
+ if (i === this.totalStatuses - 1 && bitIndex % 8 !== 0) currentByte = currentByte.padStart(8, "0");
160
+ byteArray[byteIndex] = Number.parseInt(currentByte, 2);
161
+ currentByte = "";
162
+ bitIndex = 0;
163
+ byteIndex++;
164
+ }
165
+ }
166
+ return byteArray;
167
+ }
168
+ /** Decode the byte array into a status list. */
169
+ static decodeStatusList(byteArray, bitsPerStatus) {
170
+ const numBits = bitsPerStatus;
171
+ const totalStatuses = byteArray.length * 8 / numBits;
172
+ const statusList = new Array(totalStatuses);
173
+ let bitIndex = 0;
174
+ for (let i = 0; i < totalStatuses; i++) {
175
+ let byteString = byteArray[Math.floor(i * numBits / 8)].toString(2);
176
+ if (byteString.length < 8) byteString = "0".repeat(8 - byteString.length) + byteString;
177
+ const status = byteString.slice(bitIndex, bitIndex + numBits);
178
+ const group = Math.floor(i / (8 / numBits));
179
+ const indexInGroup = i % (8 / numBits);
180
+ const position = group * (8 / numBits) + (8 / numBits + -1 - indexInGroup);
181
+ statusList[position] = Number.parseInt(status, 2);
182
+ bitIndex = (bitIndex + numBits) % 8;
183
+ }
184
+ return statusList;
185
+ }
186
+ };
187
+
188
+ //#endregion
189
+ //#region src/status-list-cwt.ts
190
+ function encodeCBORMap(obj) {
191
+ return cbor.encode(obj);
192
+ }
193
+ function decodeCBOR(data) {
194
+ return cbor.decode(data);
195
+ }
196
+ /**
197
+ * Creates the CWT claims payload for a Status List Token.
198
+ */
199
+ function createStatusListCWTPayload(list, subject, issuedAt, options) {
200
+ if (!subject) throw new SLException("subject is required");
201
+ if (!issuedAt) throw new SLException("issuedAt is required");
202
+ const statusListCBOR = {
203
+ bits: list.getBitsPerStatus(),
204
+ lst: list.compressStatusListToBytes()
205
+ };
206
+ if (options?.aggregationUri) statusListCBOR.aggregation_uri = options.aggregationUri;
207
+ const payload = {
208
+ 2: subject,
209
+ 6: issuedAt,
210
+ 65533: statusListCBOR
211
+ };
212
+ if (options?.exp !== void 0) payload[4] = options.exp;
213
+ if (options?.ttl !== void 0) payload[65534] = options.ttl;
214
+ return payload;
215
+ }
216
+ /**
217
+ * Creates the protected header for a Status List CWT.
218
+ */
219
+ function createStatusListCWTHeader(alg, kidOrOptions) {
220
+ const header = {
221
+ 1: alg,
222
+ 16: CWT_STATUS_LIST_TYPE
223
+ };
224
+ if (kidOrOptions !== void 0) if (typeof kidOrOptions === "string" || kidOrOptions instanceof Uint8Array) header[4] = kidOrOptions;
225
+ else {
226
+ if (kidOrOptions.kid !== void 0) header[4] = kidOrOptions.kid;
227
+ if (kidOrOptions.x5chain !== void 0) header[33] = kidOrOptions.x5chain;
228
+ if (kidOrOptions.x5t !== void 0) header[34] = kidOrOptions.x5t;
229
+ if (kidOrOptions.x5u !== void 0) header[35] = kidOrOptions.x5u;
230
+ }
231
+ return header;
232
+ }
233
+ /**
234
+ * Encodes a Status List into CBOR format for CWT.
235
+ */
236
+ function encodeStatusListToCBOR(list, aggregationUri) {
237
+ const statusListMap = {
238
+ [CWTStatusListKeys.BITS]: list.getBitsPerStatus(),
239
+ [CWTStatusListKeys.LST]: list.compressStatusListToBytes()
240
+ };
241
+ if (aggregationUri) statusListMap[CWTStatusListKeys.AGGREGATION_URI] = aggregationUri;
242
+ return encodeCBORMap(statusListMap);
243
+ }
244
+ /**
245
+ * Decodes a CBOR-encoded status list.
246
+ */
247
+ function decodeStatusListFromCBOR(cborData) {
248
+ const decoded = decodeCBOR(cborData);
249
+ return StatusList.decompressStatusListFromBytes(decoded.lst, decoded.bits);
250
+ }
251
+ /**
252
+ * Encodes the full CWT claims payload to CBOR.
253
+ */
254
+ function encodeCWTPayload(list, subject, issuedAt, options) {
255
+ const payload = createStatusListCWTPayload(list, subject, issuedAt, options);
256
+ const cborPayload = /* @__PURE__ */ new Map();
257
+ cborPayload.set(2, payload[2]);
258
+ cborPayload.set(6, payload[6]);
259
+ if (payload[4] !== void 0) cborPayload.set(4, payload[4]);
260
+ if (payload[65534] !== void 0) cborPayload.set(65534, payload[65534]);
261
+ const statusListMap = /* @__PURE__ */ new Map();
262
+ statusListMap.set("bits", payload[65533].bits);
263
+ statusListMap.set("lst", payload[65533].lst);
264
+ if (payload[65533].aggregation_uri) statusListMap.set("aggregation_uri", payload[65533].aggregation_uri);
265
+ cborPayload.set(65533, statusListMap);
266
+ return cbor.encode(cborPayload);
267
+ }
268
+ /**
269
+ * Decodes a CBOR-encoded CWT payload.
270
+ */
271
+ function decodeCWTPayload(cborData) {
272
+ const decoded = decodeCBOR(cborData);
273
+ const getValue = (key) => {
274
+ if (decoded instanceof Map) return decoded.get(key);
275
+ return decoded[key];
276
+ };
277
+ const subject = getValue(2);
278
+ const issuedAt = getValue(6);
279
+ const exp = getValue(4);
280
+ const ttl = getValue(65534);
281
+ const statusListData = getValue(65533);
282
+ let bits;
283
+ let lst;
284
+ let aggregationUri;
285
+ if (statusListData instanceof Map) {
286
+ bits = statusListData.get("bits");
287
+ lst = statusListData.get("lst");
288
+ aggregationUri = statusListData.get("aggregation_uri");
289
+ } else {
290
+ bits = statusListData.bits;
291
+ lst = statusListData.lst;
292
+ aggregationUri = statusListData.aggregation_uri;
293
+ }
294
+ return {
295
+ subject,
296
+ issuedAt,
297
+ exp,
298
+ ttl,
299
+ statusList: StatusList.decompressStatusListFromBytes(lst, bits),
300
+ aggregationUri
301
+ };
302
+ }
303
+ /**
304
+ * Creates a status claim for a Referenced Token in CWT format.
305
+ */
306
+ function createCWTStatusClaim(idx, uri) {
307
+ return { status_list: {
308
+ idx,
309
+ uri
310
+ } };
311
+ }
312
+ /**
313
+ * Encodes a status claim for a Referenced Token to CBOR.
314
+ */
315
+ function encodeCWTStatusClaim(idx, uri) {
316
+ const statusClaim = /* @__PURE__ */ new Map();
317
+ const statusListInfo = /* @__PURE__ */ new Map();
318
+ statusListInfo.set(CWTStatusListInfoKeys.IDX, idx);
319
+ statusListInfo.set(CWTStatusListInfoKeys.URI, uri);
320
+ statusClaim.set("status_list", statusListInfo);
321
+ return cbor.encode(statusClaim);
322
+ }
323
+ /**
324
+ * Decodes a status claim from a Referenced Token CWT.
325
+ */
326
+ function decodeCWTStatusClaim(cborData) {
327
+ const decoded = decodeCBOR(cborData);
328
+ let statusList;
329
+ if (decoded instanceof Map) statusList = decoded.get("status_list");
330
+ else statusList = decoded.status_list;
331
+ if (statusList instanceof Map) return {
332
+ idx: statusList.get(CWTStatusListInfoKeys.IDX),
333
+ uri: statusList.get(CWTStatusListInfoKeys.URI)
334
+ };
335
+ return {
336
+ idx: statusList[CWTStatusListInfoKeys.IDX],
337
+ uri: statusList[CWTStatusListInfoKeys.URI]
338
+ };
339
+ }
340
+ /**
341
+ * Extracts the status list from a decoded CWT payload.
342
+ */
343
+ function getListFromStatusListCWT(cwtPayload) {
344
+ const { statusList } = decodeCWTPayload(cwtPayload);
345
+ return statusList;
346
+ }
347
+ /**
348
+ * Extracts the status list entry from a decoded Referenced Token CWT.
349
+ */
350
+ function getStatusListFromCWT(cwtPayload) {
351
+ const decoded = decodeCBOR(cwtPayload);
352
+ let statusClaim;
353
+ if (decoded instanceof Map) statusClaim = decoded.get(65535);
354
+ else statusClaim = decoded[65535];
355
+ if (!statusClaim) throw new SLException("No status claim found in CWT payload");
356
+ let statusList;
357
+ if (statusClaim instanceof Map) statusList = statusClaim.get("status_list");
358
+ else statusList = statusClaim.status_list;
359
+ if (!statusList) throw new SLException("No status_list found in status claim");
360
+ if (statusList instanceof Map) return {
361
+ idx: statusList.get("idx"),
362
+ uri: statusList.get("uri")
363
+ };
364
+ return {
365
+ idx: statusList.idx,
366
+ uri: statusList.uri
367
+ };
368
+ }
369
+ /**
370
+ * COSE Algorithm identifiers
371
+ * @see https://www.iana.org/assignments/cose/cose.xhtml#algorithms
372
+ */
373
+ const COSEAlgorithms = {
374
+ ES256: -7,
375
+ ES384: -35,
376
+ ES512: -36,
377
+ EdDSA: -8,
378
+ PS256: -37,
379
+ PS384: -38,
380
+ PS512: -39,
381
+ RS256: -257,
382
+ RS384: -258,
383
+ RS512: -259
384
+ };
385
+
386
+ //#endregion
387
+ //#region src/status-list-jwt.ts
388
+ /**
389
+ * Decode a JWT and return the payload.
390
+ * @param jwt JWT token in compact JWS serialization.
391
+ */
392
+ function decodeJwtPayload(jwt) {
393
+ const parts = jwt.split(".");
394
+ return JSON.parse(base64urlDecode(parts[1]));
395
+ }
396
+ /**
397
+ * Adds the status list to the payload and header of a JWT.
398
+ */
399
+ function createHeaderAndPayload(list, payload, header) {
400
+ if (!payload.sub) throw new SLException("sub field is required");
401
+ if (!payload.iat) throw new SLException("iat field is required");
402
+ header.typ = JWT_STATUS_LIST_TYPE;
403
+ payload.status_list = {
404
+ bits: list.getBitsPerStatus(),
405
+ lst: uint8ArrayToBase64Url(list.compressStatusListToBytes())
406
+ };
407
+ return {
408
+ header,
409
+ payload
410
+ };
411
+ }
412
+ /**
413
+ * Get the status list from a JWT, but do not verify the signature.
414
+ */
415
+ function getListFromStatusListJWT(jwt) {
416
+ const statusList = decodeJwtPayload(jwt).status_list;
417
+ const compressed = base64UrlToUint8Array(statusList.lst);
418
+ return StatusList.decompressStatusListFromBytes(compressed, statusList.bits);
419
+ }
420
+ /**
421
+ * Get the status list entry from a JWT, but do not verify the signature.
422
+ */
423
+ function getStatusListFromJWT(jwt) {
424
+ return decodeJwtPayload(jwt).status.status_list;
425
+ }
426
+
427
+ //#endregion
428
+ //#region src/types.ts
429
+ /**
430
+ * Status Type values as defined in the spec.
431
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-7
432
+ */
433
+ const StatusTypes = {
434
+ VALID: 0,
435
+ INVALID: 1,
436
+ SUSPENDED: 2,
437
+ APPLICATION_SPECIFIC_3: 3,
438
+ APPLICATION_SPECIFIC_RANGE_START: 12,
439
+ APPLICATION_SPECIFIC_RANGE_END: 15
440
+ };
441
+ /**
442
+ * Media types for Status List Tokens
443
+ * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-14.7
444
+ */
445
+ const MediaTypes = {
446
+ STATUS_LIST_JWT: "application/statuslist+jwt",
447
+ STATUS_LIST_CWT: "application/statuslist+cwt"
448
+ };
449
+
450
+ //#endregion
451
+ export { COSEAlgorithms, COSEHeaderKeys, CWTClaimKeys, CWTStatusListInfoKeys, CWTStatusListKeys, CWT_STATUS_LIST_CONTENT_FORMAT_ID, CWT_STATUS_LIST_TYPE, JWTClaimNames, JWT_STATUS_LIST_TYPE, MediaTypes, SLException, StatusList, StatusTypes, createCWTStatusClaim, createHeaderAndPayload, createStatusListCWTHeader, createStatusListCWTPayload, decodeCWTPayload, decodeCWTStatusClaim, decodeStatusListFromCBOR, encodeCWTPayload, encodeCWTStatusClaim, encodeStatusListToCBOR, getListFromStatusListCWT, getListFromStatusListJWT, getStatusListFromCWT, getStatusListFromJWT };
452
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/cwt-types.ts","../src/jwt-types.ts","../src/status-list-exception.ts","../src/status-list.ts","../src/status-list-cwt.ts","../src/status-list-jwt.ts","../src/types.ts"],"sourcesContent":["import type { BitsPerStatus, StatusListEntry } from './types'\n\n// ==================== CWT Types ====================\n\n/**\n * CWT Claim Keys as defined in draft-ietf-oauth-status-list\n * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.2\n */\nexport const CWTClaimKeys = {\n SUB: 2,\n EXP: 4,\n IAT: 6,\n TTL: 65534,\n STATUS_LIST: 65533,\n STATUS: 65535,\n} as const\n\n/**\n * CWT Status List map keys\n */\nexport const CWTStatusListKeys = {\n BITS: 'bits',\n LST: 'lst',\n AGGREGATION_URI: 'aggregation_uri',\n} as const\n\n/**\n * CWT Status List Info keys (for referenced tokens)\n */\nexport const CWTStatusListInfoKeys = {\n IDX: 'idx',\n URI: 'uri',\n} as const\n\n/**\n * COSE Header type parameter value for Status List CWT\n * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.2\n */\nexport const CWT_STATUS_LIST_TYPE = 'application/statuslist+cwt'\n\n/**\n * CoAP Content-Format ID for Status List CWT (TBD in IANA registry)\n */\nexport const CWT_STATUS_LIST_CONTENT_FORMAT_ID: number | undefined = undefined\n\n/**\n * COSE Header parameter keys\n * @see https://www.iana.org/assignments/cose/cose.xhtml#header-parameters\n */\nexport const COSEHeaderKeys = {\n ALG: 1,\n CRIT: 2,\n CONTENT_TYPE: 3,\n KID: 4,\n IV: 5,\n PARTIAL_IV: 6,\n TYPE: 16,\n X5CHAIN: 33,\n X5T: 34,\n X5U: 35,\n} as const\n\n/**\n * Status List in CBOR format\n */\nexport interface StatusListCBOR {\n bits: BitsPerStatus\n lst: Uint8Array\n aggregation_uri?: string\n}\n\n/**\n * CWT Claims Set for a Status List Token\n */\nexport interface StatusListCWTPayload {\n [CWTClaimKeys.SUB]: string\n [CWTClaimKeys.IAT]: number\n [CWTClaimKeys.EXP]?: number\n [CWTClaimKeys.TTL]?: number\n [CWTClaimKeys.STATUS_LIST]: StatusListCBOR\n}\n\n/**\n * CWT Claims Set for a Referenced Token with status\n */\nexport interface CWTwithStatusListPayload {\n [CWTClaimKeys.SUB]?: string\n [CWTClaimKeys.IAT]?: number\n [CWTClaimKeys.EXP]?: number\n [CWTClaimKeys.STATUS]: {\n status_list: StatusListEntry\n }\n}\n\n/**\n * COSE protected header for Status List CWT\n */\nexport interface StatusListCWTHeader {\n [COSEHeaderKeys.ALG]: number\n [COSEHeaderKeys.TYPE]: string | number\n [COSEHeaderKeys.KID]?: Uint8Array | string\n [COSEHeaderKeys.X5CHAIN]?: Uint8Array | Uint8Array[]\n [COSEHeaderKeys.X5T]?: Uint8Array\n [COSEHeaderKeys.X5U]?: string\n}\n","import type { JwtPayload } from '@owf/identity-common'\nimport type { BitsPerStatus, StatusListEntry } from './types'\n\n// ==================== JWT Types & Constants ====================\n\n/**\n * JWT type header value for Status List Token\n * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-5.1\n */\nexport const JWT_STATUS_LIST_TYPE = 'statuslist+jwt'\n\n/**\n * JWT claim names for Status List\n * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-14.1\n */\nexport const JWTClaimNames = {\n STATUS: 'status',\n STATUS_LIST: 'status_list',\n TTL: 'ttl',\n IDX: 'idx',\n URI: 'uri',\n BITS: 'bits',\n LST: 'lst',\n AGGREGATION_URI: 'aggregation_uri',\n} as const\n\n/**\n * Payload for a JWT with a status reference.\n */\nexport interface JWTwithStatusListPayload extends JwtPayload {\n status: {\n status_list: StatusListEntry\n }\n}\n\n/**\n * Payload for a Status List JWT.\n */\nexport interface StatusListJWTPayload extends JwtPayload {\n ttl?: number\n status_list: {\n bits: BitsPerStatus\n lst: string\n }\n}\n\n/**\n * Header parameters for a JWT Status List Token.\n */\nexport type StatusListJWTHeaderParameters = {\n alg: string\n typ: typeof JWT_STATUS_LIST_TYPE\n [key: string]: unknown\n}\n","/**\n * SLException is a custom error class for Status List related exceptions.\n */\nexport class SLException extends Error {\n public details?: unknown\n\n constructor(message: string, details?: unknown) {\n super(message)\n Object.setPrototypeOf(this, SLException.prototype)\n this.name = 'SLException'\n this.details = details\n }\n\n getFullMessage(): string {\n return `${this.name}: ${this.message} ${this.details ? `- ${JSON.stringify(this.details)}` : ''}`\n }\n}\n","import { deflate, inflate } from 'pako'\nimport { SLException } from './status-list-exception'\nimport type { BitsPerStatus } from './types'\n\n/**\n * StatusList is a class that manages a list of statuses with variable bit size.\n */\nexport class StatusList {\n private _statusList: number[]\n private bitsPerStatus: BitsPerStatus\n private totalStatuses: number\n\n constructor(statusList: number[], bitsPerStatus: BitsPerStatus) {\n if (![1, 2, 4, 8].includes(bitsPerStatus)) {\n throw new SLException('bitsPerStatus must be 1, 2, 4, or 8')\n }\n for (let i = 0; i < statusList.length; i++) {\n if (statusList[i] > 2 ** bitsPerStatus) {\n throw new SLException(`Status value out of range at index ${i} with value ${statusList[i]}`)\n }\n }\n this._statusList = statusList\n this.bitsPerStatus = bitsPerStatus\n this.totalStatuses = statusList.length\n }\n\n /** Get the status list. */\n get statusList(): number[] {\n return this._statusList\n }\n\n /** Get the number of bits per status. */\n getBitsPerStatus(): BitsPerStatus {\n return this.bitsPerStatus\n }\n\n /** Get the status at a specific index. */\n getStatus(index: number): number {\n if (index < 0 || index >= this.totalStatuses) {\n throw new Error('Index out of bounds')\n }\n return this._statusList[index]\n }\n\n /** Set the status at a specific index. */\n setStatus(index: number, value: number): void {\n if (index < 0 || index >= this.totalStatuses) {\n throw new Error('Index out of bounds')\n }\n this._statusList[index] = value\n }\n\n /** Compress the status list and return as raw bytes. */\n compressStatusListToBytes(): Uint8Array {\n const byteArray = this.encodeStatusList()\n return deflate(byteArray, { level: 9 })\n }\n\n /** Decompress a raw byte array and return a new StatusList instance. */\n static decompressStatusListFromBytes(compressed: Uint8Array, bitsPerStatus: BitsPerStatus): StatusList {\n try {\n const decompressed = inflate(compressed)\n const statusList = StatusList.decodeStatusList(decompressed, bitsPerStatus)\n return new StatusList(statusList, bitsPerStatus)\n } catch (err: unknown) {\n throw new Error(`Decompression failed: ${err}`)\n }\n }\n\n /** Encode the status list into a byte array. */\n public encodeStatusList(): Uint8Array {\n const numBits = this.bitsPerStatus\n const numBytes = Math.ceil((this.totalStatuses * numBits) / 8)\n const byteArray = new Uint8Array(numBytes)\n let byteIndex = 0\n let bitIndex = 0\n let currentByte = ''\n for (let i = 0; i < this.totalStatuses; i++) {\n const status = this._statusList[i]\n currentByte = status.toString(2).padStart(numBits, '0') + currentByte\n bitIndex += numBits\n\n if (bitIndex >= 8 || i === this.totalStatuses - 1) {\n if (i === this.totalStatuses - 1 && bitIndex % 8 !== 0) {\n currentByte = currentByte.padStart(8, '0')\n }\n byteArray[byteIndex] = Number.parseInt(currentByte, 2)\n currentByte = ''\n bitIndex = 0\n byteIndex++\n }\n }\n\n return byteArray\n }\n\n /** Decode the byte array into a status list. */\n private static decodeStatusList(byteArray: Uint8Array, bitsPerStatus: BitsPerStatus): number[] {\n const numBits = bitsPerStatus\n const totalStatuses = (byteArray.length * 8) / numBits\n const statusList = new Array<number>(totalStatuses)\n let bitIndex = 0\n for (let i = 0; i < totalStatuses; i++) {\n const byte = byteArray[Math.floor((i * numBits) / 8)]\n let byteString = byte.toString(2)\n if (byteString.length < 8) {\n byteString = '0'.repeat(8 - byteString.length) + byteString\n }\n const status = byteString.slice(bitIndex, bitIndex + numBits)\n const group = Math.floor(i / (8 / numBits))\n const indexInGroup = i % (8 / numBits)\n const position = group * (8 / numBits) + (8 / numBits + -1 - indexInGroup)\n statusList[position] = Number.parseInt(status, 2)\n bitIndex = (bitIndex + numBits) % 8\n }\n return statusList\n }\n}\n","import * as cbor from 'cbor-x'\nimport type { CWTwithStatusListPayload, StatusListCBOR, StatusListCWTHeader, StatusListCWTPayload } from './cwt-types'\nimport { CWT_STATUS_LIST_TYPE, CWTStatusListInfoKeys, CWTStatusListKeys } from './cwt-types'\nimport { StatusList } from './status-list'\nimport { SLException } from './status-list-exception'\nimport type { BitsPerStatus, StatusListEntry } from './types'\n\nfunction encodeCBORMap(obj: Record<string | number, unknown>): Uint8Array {\n return cbor.encode(obj)\n}\n\nfunction decodeCBOR<T>(data: Uint8Array): T {\n return cbor.decode(data) as T\n}\n\n/**\n * Creates the CWT claims payload for a Status List Token.\n */\nexport function createStatusListCWTPayload(\n list: StatusList,\n subject: string,\n issuedAt: number,\n options?: {\n exp?: number\n ttl?: number\n aggregationUri?: string\n }\n): StatusListCWTPayload {\n if (!subject) {\n throw new SLException('subject is required')\n }\n if (!issuedAt) {\n throw new SLException('issuedAt is required')\n }\n\n const statusListCBOR: StatusListCBOR = {\n bits: list.getBitsPerStatus(),\n lst: list.compressStatusListToBytes(),\n }\n\n if (options?.aggregationUri) {\n statusListCBOR.aggregation_uri = options.aggregationUri\n }\n\n const payload: StatusListCWTPayload = {\n 2: subject,\n 6: issuedAt,\n 65533: statusListCBOR,\n }\n\n if (options?.exp !== undefined) {\n payload[4] = options.exp\n }\n\n if (options?.ttl !== undefined) {\n payload[65534] = options.ttl\n }\n\n return payload\n}\n\n/**\n * Key resolution options for CWT header\n */\nexport interface CWTHeaderKeyOptions {\n kid?: string | Uint8Array\n x5chain?: Uint8Array | Uint8Array[]\n x5t?: Uint8Array\n x5u?: string\n}\n\n/**\n * Creates the protected header for a Status List CWT.\n */\nexport function createStatusListCWTHeader(\n alg: number,\n kidOrOptions?: string | Uint8Array | CWTHeaderKeyOptions\n): StatusListCWTHeader {\n const header: StatusListCWTHeader = {\n 1: alg,\n 16: CWT_STATUS_LIST_TYPE,\n }\n\n if (kidOrOptions !== undefined) {\n if (typeof kidOrOptions === 'string' || kidOrOptions instanceof Uint8Array) {\n header[4] = kidOrOptions\n } else {\n if (kidOrOptions.kid !== undefined) {\n header[4] = kidOrOptions.kid\n }\n if (kidOrOptions.x5chain !== undefined) {\n header[33] = kidOrOptions.x5chain\n }\n if (kidOrOptions.x5t !== undefined) {\n header[34] = kidOrOptions.x5t\n }\n if (kidOrOptions.x5u !== undefined) {\n header[35] = kidOrOptions.x5u\n }\n }\n }\n\n return header\n}\n\n/**\n * Encodes a Status List into CBOR format for CWT.\n */\nexport function encodeStatusListToCBOR(list: StatusList, aggregationUri?: string): Uint8Array {\n const statusListMap: Record<string, unknown> = {\n [CWTStatusListKeys.BITS]: list.getBitsPerStatus(),\n [CWTStatusListKeys.LST]: list.compressStatusListToBytes(),\n }\n\n if (aggregationUri) {\n statusListMap[CWTStatusListKeys.AGGREGATION_URI] = aggregationUri\n }\n\n return encodeCBORMap(statusListMap)\n}\n\n/**\n * Decodes a CBOR-encoded status list.\n */\nexport function decodeStatusListFromCBOR(cborData: Uint8Array): StatusList {\n const decoded = decodeCBOR<StatusListCBOR>(cborData)\n return StatusList.decompressStatusListFromBytes(decoded.lst, decoded.bits)\n}\n\n/**\n * Encodes the full CWT claims payload to CBOR.\n */\nexport function encodeCWTPayload(\n list: StatusList,\n subject: string,\n issuedAt: number,\n options?: {\n exp?: number\n ttl?: number\n aggregationUri?: string\n }\n): Uint8Array {\n const payload = createStatusListCWTPayload(list, subject, issuedAt, options)\n\n const cborPayload = new Map<number, unknown>()\n cborPayload.set(2, payload[2])\n cborPayload.set(6, payload[6])\n\n if (payload[4] !== undefined) {\n cborPayload.set(4, payload[4])\n }\n if (payload[65534] !== undefined) {\n cborPayload.set(65534, payload[65534])\n }\n\n const statusListMap = new Map<string, unknown>()\n statusListMap.set('bits', payload[65533].bits)\n statusListMap.set('lst', payload[65533].lst)\n if (payload[65533].aggregation_uri) {\n statusListMap.set('aggregation_uri', payload[65533].aggregation_uri)\n }\n cborPayload.set(65533, statusListMap)\n\n return cbor.encode(cborPayload)\n}\n\n/**\n * Decodes a CBOR-encoded CWT payload.\n */\nexport function decodeCWTPayload(cborData: Uint8Array): {\n subject: string\n issuedAt: number\n exp?: number\n ttl?: number\n statusList: StatusList\n aggregationUri?: string\n} {\n const decoded = decodeCBOR<Map<number, unknown>>(cborData)\n\n const getValue = (key: number): unknown => {\n if (decoded instanceof Map) {\n return decoded.get(key)\n }\n return (decoded as Record<number, unknown>)[key]\n }\n\n const subject = getValue(2) as string\n const issuedAt = getValue(6) as number\n const exp = getValue(4) as number | undefined\n const ttl = getValue(65534) as number | undefined\n const statusListData = getValue(65533) as Map<string, unknown> | Record<string, unknown>\n\n let bits: BitsPerStatus\n let lst: Uint8Array\n let aggregationUri: string | undefined\n\n if (statusListData instanceof Map) {\n bits = statusListData.get('bits') as BitsPerStatus\n lst = statusListData.get('lst') as Uint8Array\n aggregationUri = statusListData.get('aggregation_uri') as string | undefined\n } else {\n bits = statusListData.bits as BitsPerStatus\n lst = statusListData.lst as Uint8Array\n aggregationUri = statusListData.aggregation_uri as string | undefined\n }\n\n const statusList = StatusList.decompressStatusListFromBytes(lst, bits)\n\n return {\n subject,\n issuedAt,\n exp,\n ttl,\n statusList,\n aggregationUri,\n }\n}\n\n/**\n * Creates a status claim for a Referenced Token in CWT format.\n */\nexport function createCWTStatusClaim(idx: number, uri: string): CWTwithStatusListPayload[65535] {\n return {\n status_list: {\n idx,\n uri,\n },\n }\n}\n\n/**\n * Encodes a status claim for a Referenced Token to CBOR.\n */\nexport function encodeCWTStatusClaim(idx: number, uri: string): Uint8Array {\n const statusClaim = new Map<string, unknown>()\n const statusListInfo = new Map<string, unknown>()\n statusListInfo.set(CWTStatusListInfoKeys.IDX, idx)\n statusListInfo.set(CWTStatusListInfoKeys.URI, uri)\n statusClaim.set('status_list', statusListInfo)\n\n return cbor.encode(statusClaim)\n}\n\n/**\n * Decodes a status claim from a Referenced Token CWT.\n */\nexport function decodeCWTStatusClaim(cborData: Uint8Array): StatusListEntry {\n const decoded = decodeCBOR<Map<string, unknown> | Record<string, unknown>>(cborData)\n\n let statusList: Map<string, unknown> | Record<string, unknown>\n\n if (decoded instanceof Map) {\n statusList = decoded.get('status_list') as Map<string, unknown> | Record<string, unknown>\n } else {\n statusList = decoded.status_list as Map<string, unknown> | Record<string, unknown>\n }\n\n if (statusList instanceof Map) {\n return {\n idx: statusList.get(CWTStatusListInfoKeys.IDX) as number,\n uri: statusList.get(CWTStatusListInfoKeys.URI) as string,\n }\n }\n return {\n idx: statusList[CWTStatusListInfoKeys.IDX] as number,\n uri: statusList[CWTStatusListInfoKeys.URI] as string,\n }\n}\n\n/**\n * Extracts the status list from a decoded CWT payload.\n */\nexport function getListFromStatusListCWT(cwtPayload: Uint8Array): StatusList {\n const { statusList } = decodeCWTPayload(cwtPayload)\n return statusList\n}\n\n/**\n * Extracts the status list entry from a decoded Referenced Token CWT.\n */\nexport function getStatusListFromCWT(cwtPayload: Uint8Array): StatusListEntry {\n const decoded = decodeCBOR<Map<number, unknown> | Record<number, unknown>>(cwtPayload)\n\n let statusClaim: Map<string, unknown> | Record<string, unknown>\n\n if (decoded instanceof Map) {\n statusClaim = decoded.get(65535) as Map<string, unknown> | Record<string, unknown>\n } else {\n statusClaim = decoded[65535] as Map<string, unknown> | Record<string, unknown>\n }\n\n if (!statusClaim) {\n throw new SLException('No status claim found in CWT payload')\n }\n\n let statusList: Map<string, unknown> | Record<string, unknown>\n\n if (statusClaim instanceof Map) {\n statusList = statusClaim.get('status_list') as Map<string, unknown> | Record<string, unknown>\n } else {\n statusList = statusClaim.status_list as Map<string, unknown> | Record<string, unknown>\n }\n\n if (!statusList) {\n throw new SLException('No status_list found in status claim')\n }\n\n if (statusList instanceof Map) {\n return {\n idx: statusList.get('idx') as number,\n uri: statusList.get('uri') as string,\n }\n }\n\n return {\n idx: statusList.idx as number,\n uri: statusList.uri as string,\n }\n}\n\n/**\n * COSE Algorithm identifiers\n * @see https://www.iana.org/assignments/cose/cose.xhtml#algorithms\n */\nexport const COSEAlgorithms = {\n ES256: -7,\n ES384: -35,\n ES512: -36,\n EdDSA: -8,\n PS256: -37,\n PS384: -38,\n PS512: -39,\n RS256: -257,\n RS384: -258,\n RS512: -259,\n} as const\n\nexport type COSEAlgorithm = (typeof COSEAlgorithms)[keyof typeof COSEAlgorithms]\n","import type { JwtPayload } from '@owf/identity-common'\nimport { base64UrlToUint8Array, base64urlDecode, uint8ArrayToBase64Url } from '@owf/identity-common'\nimport type { JWTwithStatusListPayload, StatusListJWTHeaderParameters, StatusListJWTPayload } from './jwt-types'\nimport { JWT_STATUS_LIST_TYPE } from './jwt-types'\nimport { StatusList } from './status-list'\nimport { SLException } from './status-list-exception'\nimport type { StatusListEntry } from './types'\n\n/**\n * Decode a JWT and return the payload.\n * @param jwt JWT token in compact JWS serialization.\n */\nfunction decodeJwtPayload<T>(jwt: string): T {\n const parts = jwt.split('.')\n return JSON.parse(base64urlDecode(parts[1]))\n}\n\n/**\n * Adds the status list to the payload and header of a JWT.\n */\nexport function createHeaderAndPayload(list: StatusList, payload: JwtPayload, header: StatusListJWTHeaderParameters) {\n if (!payload.sub) {\n throw new SLException('sub field is required')\n }\n if (!payload.iat) {\n throw new SLException('iat field is required')\n }\n\n header.typ = JWT_STATUS_LIST_TYPE\n payload.status_list = {\n bits: list.getBitsPerStatus(),\n lst: uint8ArrayToBase64Url(list.compressStatusListToBytes()),\n }\n return { header, payload }\n}\n\n/**\n * Get the status list from a JWT, but do not verify the signature.\n */\nexport function getListFromStatusListJWT(jwt: string): StatusList {\n const payload = decodeJwtPayload<StatusListJWTPayload>(jwt)\n const statusList = payload.status_list\n const compressed = base64UrlToUint8Array(statusList.lst)\n return StatusList.decompressStatusListFromBytes(compressed, statusList.bits)\n}\n\n/**\n * Get the status list entry from a JWT, but do not verify the signature.\n */\nexport function getStatusListFromJWT(jwt: string): StatusListEntry {\n const payload = decodeJwtPayload<JWTwithStatusListPayload>(jwt)\n return payload.status.status_list\n}\n","// ==================== Common Types & Constants ====================\n\n/**\n * Status Type values as defined in the spec.\n * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-7\n */\nexport const StatusTypes = {\n /** The status of the Referenced Token is valid, correct or legal. */\n VALID: 0x00,\n /** The status of the Referenced Token is revoked, annulled, taken back, recalled or cancelled. */\n INVALID: 0x01,\n /** The status of the Referenced Token is temporarily invalid, hanging, debarred from privilege. */\n SUSPENDED: 0x02,\n /** Application-specific status (0x03). */\n APPLICATION_SPECIFIC_3: 0x03,\n /** Application-specific status range start (0x0C). */\n APPLICATION_SPECIFIC_RANGE_START: 0x0c,\n /** Application-specific status range end (0x0F). */\n APPLICATION_SPECIFIC_RANGE_END: 0x0f,\n} as const\n\nexport type StatusType = (typeof StatusTypes)[keyof typeof StatusTypes] | number\n\n/**\n * Media types for Status List Tokens\n * @see https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-16.html#section-14.7\n */\nexport const MediaTypes = {\n /** Media type for JWT-based Status List Token */\n STATUS_LIST_JWT: 'application/statuslist+jwt',\n /** Media type for CWT-based Status List Token */\n STATUS_LIST_CWT: 'application/statuslist+cwt',\n} as const\n\n/**\n * BitsPerStatus type.\n */\nexport type BitsPerStatus = 1 | 2 | 4 | 8\n\n/**\n * Reference to a status list entry.\n */\nexport interface StatusListEntry {\n idx: number\n uri: string\n}\n"],"mappings":";;;;;;;;;AAQA,MAAa,eAAe;CAC1B,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,aAAa;CACb,QAAQ;CACT;;;;AAKD,MAAa,oBAAoB;CAC/B,MAAM;CACN,KAAK;CACL,iBAAiB;CAClB;;;;AAKD,MAAa,wBAAwB;CACnC,KAAK;CACL,KAAK;CACN;;;;;AAMD,MAAa,uBAAuB;;;;AAKpC,MAAa,oCAAwD;;;;;AAMrE,MAAa,iBAAiB;CAC5B,K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AExB,iBAAiB;CAEjB,iBAAiB;CAClB"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@owf/token-status-list",
3
+ "version": "0.1.0-alpha-20260302093714",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "license": "Apache-2.0",
8
+ "exports": {
9
+ ".": "./dist/index.mjs",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "homepage": "https://github.com/openwallet-foundation-labs/identity-common-ts/tree/main/packages/token-status-list",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/openwallet-foundation-labs/identity-common-ts",
16
+ "directory": "packages/token-status-list"
17
+ },
18
+ "dependencies": {
19
+ "cbor-x": "^1.6.0",
20
+ "pako": "^2.1.0",
21
+ "@owf/identity-common": "0.1.0-alpha-20260302093714"
22
+ },
23
+ "devDependencies": {
24
+ "@types/pako": "^2.0.4"
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown src/index.ts --format esm --dts --sourcemap"
28
+ },
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.mts"
31
+ }