@sphereon/ssi-sdk.vc-status-list 0.33.1-feature.vcdm2.tsup.49 → 0.33.1-feature.vcdm2.tsup.51

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/src/functions.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
1
+ import type { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
2
2
  import {
3
3
  CredentialMapper,
4
4
  DocumentFormat,
5
5
  type CredentialProofFormat,
6
- StatusListCredential,
6
+ type StatusListCredential,
7
7
  StatusListDriverType,
8
8
  StatusListType,
9
- StatusPurpose2021,
9
+ type StatusPurpose2021,
10
10
  } from '@sphereon/ssi-types'
11
- import { CredentialStatus, DIDDocument, IAgentContext, ICredentialPlugin, ProofFormat as VeramoProofFormat } from '@veramo/core'
11
+ import type { CredentialStatus, DIDDocument, IAgentContext, ICredentialPlugin, ProofFormat as VeramoProofFormat } from '@veramo/core'
12
12
 
13
13
  import { checkStatus } from '@sphereon/vc-status-list'
14
14
 
@@ -1,6 +1,6 @@
1
- import { IAgentContext, ICredentialPlugin } from '@veramo/core'
2
- import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
3
- import {
1
+ import type { IAgentContext, ICredentialPlugin } from '@veramo/core'
2
+ import type { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
3
+ import type {
4
4
  CheckStatusIndexArgs,
5
5
  CreateStatusListArgs,
6
6
  Status2021,
@@ -1,6 +1,6 @@
1
- import { IAgentContext, ICredentialPlugin, IKeyManager } from '@veramo/core'
2
- import { CompactJWT, CWT, type CredentialProofFormat, StatusListType } from '@sphereon/ssi-types'
3
- import {
1
+ import type { IAgentContext, ICredentialPlugin, IKeyManager } from '@veramo/core'
2
+ import { type CompactJWT, type CWT, type CredentialProofFormat, StatusListType } from '@sphereon/ssi-types'
3
+ import type {
4
4
  CheckStatusIndexArgs,
5
5
  CreateStatusListArgs,
6
6
  SignedStatusListData,
@@ -11,10 +11,10 @@ import {
11
11
  UpdateStatusListIndexArgs,
12
12
  } from '../types'
13
13
  import { determineProofFormat, getAssertedValue, getAssertedValues } from '../utils'
14
- import { IStatusList } from './IStatusList'
14
+ import type { IStatusList } from './IStatusList'
15
15
  import { StatusList } from '@sd-jwt/jwt-status-list'
16
- import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
17
- import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
16
+ import type { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
17
+ import type { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
18
18
  import { createSignedJwt, decodeStatusListJWT } from './encoding/jwt'
19
19
  import { createSignedCbor, decodeStatusListCWT } from './encoding/cbor'
20
20
 
@@ -1,18 +1,26 @@
1
- import { IAgentContext, ICredentialPlugin, ProofFormat as VeramoProofFormat } from '@veramo/core'
2
- import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
3
- import { CredentialMapper, DocumentFormat, IIssuer, type CredentialProofFormat, StatusListCredential, StatusListType } from '@sphereon/ssi-types'
1
+ import type { IAgentContext, ICredentialPlugin, ProofFormat as VeramoProofFormat } from '@veramo/core'
2
+ import type { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
3
+ import {
4
+ CredentialMapper,
5
+ DocumentFormat,
6
+ type IIssuer,
7
+ type CredentialProofFormat,
8
+ type StatusListCredential,
9
+ StatusListType,
10
+ } from '@sphereon/ssi-types'
4
11
 
5
12
  import { StatusList } from '@sphereon/vc-status-list'
6
- import { IStatusList } from './IStatusList'
7
- import {
13
+ import type { IStatusList } from './IStatusList'
14
+ import type {
8
15
  CheckStatusIndexArgs,
9
16
  CreateStatusListArgs,
10
- Status2021,
11
17
  StatusListResult,
12
18
  ToStatusListDetailsArgs,
13
19
  UpdateStatusListFromEncodedListArgs,
14
20
  UpdateStatusListIndexArgs,
15
21
  } from '../types'
22
+
23
+ import { Status2021 } from '../types'
16
24
  import { assertValidProofType, getAssertedProperty, getAssertedValue, getAssertedValues } from '../utils'
17
25
 
18
26
  export const DEFAULT_LIST_LENGTH = 250000
@@ -1,4 +1,4 @@
1
- import { IStatusList } from './IStatusList'
1
+ import type { IStatusList } from './IStatusList'
2
2
  import { StatusList2021Implementation } from './StatusList2021'
3
3
  import { OAuthStatusListImplementation } from './OAuthStatusList'
4
4
  import { StatusListType } from '@sphereon/ssi-types'
@@ -1,14 +1,24 @@
1
+ import type { BitsPerStatus } from '@sd-jwt/jwt-status-list'
1
2
  import { StatusList } from '@sd-jwt/jwt-status-list'
2
3
  import { deflate, inflate } from 'pako'
3
- import * as cborpkg from '@sphereon/kmp-cbor'
4
+ import { com, kotlin } from '@sphereon/kmp-mdoc-core'
5
+ // import * as cborpkg from '@sphereon/kmp-cbor'
4
6
  import base64url from 'base64url'
5
- import { IRequiredContext, SignedStatusListData } from '../../types'
6
- import { DecodedStatusListPayload, resolveIdentifier } from './common'
7
- import { BitsPerStatus } from '@sd-jwt/jwt-status-list'
8
-
9
- const cbor = cborpkg.com.sphereon.cbor
10
- const kmp = cborpkg.com.sphereon.kmp
11
- const kotlin = cborpkg.kotlin
7
+ import type { IRequiredContext, SignedStatusListData } from '../../types'
8
+ import { type DecodedStatusListPayload, resolveIdentifier } from './common'
9
+
10
+ export type IKey = com.sphereon.crypto.IKey
11
+ export type CborItem<T> = com.sphereon.cbor.CborItem<T>
12
+ export const CborByteString = com.sphereon.cbor.CborByteString
13
+ export type CborByteStringType = com.sphereon.cbor.CborByteString
14
+ export const CborUInt = com.sphereon.cbor.CborUInt
15
+ export type CborUIntType = com.sphereon.cbor.CborUInt
16
+ export const CborString = com.sphereon.cbor.CborString
17
+ export type CborStringType = com.sphereon.cbor.CborString
18
+
19
+ // const cbor = cborpkg.com.sphereon.cbor
20
+ // const kmp = cborpkg.com.sphereon.kmp
21
+ // const kotlin = cborpkg.kotlin
12
22
  const decompressRawStatusList = (StatusList as any).decodeStatusList.bind(StatusList)
13
23
 
14
24
  const CWT_CLAIMS = {
@@ -34,23 +44,26 @@ export const createSignedCbor = async (
34
44
  const compressedList = deflate(encodeStatusList, { level: 9 })
35
45
  const compressedBytes = new Int8Array(compressedList)
36
46
 
37
- const statusListMap = new cbor.CborMap(
47
+ const statusListMap = new com.sphereon.cbor.CborMap(
38
48
  kotlin.collections.KtMutableMap.fromJsMap(
39
- new Map<cborpkg.com.sphereon.cbor.CborString, cborpkg.com.sphereon.cbor.CborItem<any>>([
40
- [new cbor.CborString('bits'), new cbor.CborUInt(kmp.LongKMP.fromNumber(statusList.getBitsPerStatus()))],
41
- [new cbor.CborString('lst'), new cbor.CborByteString(compressedBytes)],
49
+ new Map<CborStringType, CborItem<any>>([
50
+ [
51
+ new com.sphereon.cbor.CborString('bits'),
52
+ new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(statusList.getBitsPerStatus())),
53
+ ],
54
+ [new com.sphereon.cbor.CborString('lst'), new com.sphereon.cbor.CborByteString(compressedBytes)],
42
55
  ]),
43
56
  ),
44
57
  )
45
58
 
46
- const protectedHeader = new cbor.CborMap(
59
+ const protectedHeader = new com.sphereon.cbor.CborMap(
47
60
  kotlin.collections.KtMutableMap.fromJsMap(
48
- new Map([[new cbor.CborUInt(kmp.LongKMP.fromNumber(16)), new cbor.CborString('statuslist+cwt')]]), // "type"
61
+ new Map([[new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(16)), new com.sphereon.cbor.CborString('statuslist+cwt')]]), // "type"
49
62
  ),
50
63
  )
51
- const protectedHeaderEncoded = cbor.Cbor.encode(protectedHeader)
64
+ const protectedHeaderEncoded = com.sphereon.cbor.Cbor.encode(protectedHeader)
52
65
  const claimsMap = buildClaimsMap(id, issuerString, statusListMap, expiresAt)
53
- const claimsEncoded: Int8Array = cbor.Cbor.encode(claimsMap)
66
+ const claimsEncoded: Int8Array = com.sphereon.cbor.Cbor.encode(claimsMap)
54
67
 
55
68
  const signedCWT: string = await context.agent.keyManagerSign({
56
69
  keyRef: identifier.kmsKeyRef,
@@ -63,13 +76,13 @@ export const createSignedCbor = async (
63
76
  const signatureBytes = base64url.decode(signedCWT)
64
77
  const signatureInt8 = new Int8Array(Buffer.from(signatureBytes))
65
78
 
66
- const cwtArrayElements: Array<cborpkg.com.sphereon.cbor.CborItem<any>> = [
67
- new cbor.CborByteString(protectedHeaderEncodedInt8),
68
- new cbor.CborByteString(claimsEncodedInt8),
69
- new cbor.CborByteString(signatureInt8),
79
+ const cwtArrayElements: Array<CborItem<any>> = [
80
+ new CborByteString(protectedHeaderEncodedInt8),
81
+ new CborByteString(claimsEncodedInt8),
82
+ new CborByteString(signatureInt8),
70
83
  ]
71
- const cwtArray = new cbor.CborArray(kotlin.collections.KtMutableList.fromJsArray(cwtArrayElements))
72
- const cwtEncoded = cbor.Cbor.encode(cwtArray)
84
+ const cwtArray = new com.sphereon.cbor.CborArray(kotlin.collections.KtMutableList.fromJsArray(cwtArrayElements))
85
+ const cwtEncoded = com.sphereon.cbor.Cbor.encode(cwtArray)
73
86
  const cwtBuffer = Buffer.from(cwtEncoded)
74
87
  return {
75
88
  statusListCredential: base64url.encode(cwtBuffer),
@@ -77,43 +90,38 @@ export const createSignedCbor = async (
77
90
  }
78
91
  }
79
92
 
80
- function buildClaimsMap(
81
- id: string,
82
- issuerString: string,
83
- statusListMap: cborpkg.com.sphereon.cbor.CborMap<cborpkg.com.sphereon.cbor.CborString, cborpkg.com.sphereon.cbor.CborItem<any>>,
84
- expiresAt?: Date,
85
- ) {
93
+ function buildClaimsMap(id: string, issuerString: string, statusListMap: com.sphereon.cbor.CborMap<CborStringType, CborItem<any>>, expiresAt?: Date) {
86
94
  const ttl = 65535 // FIXME figure out what value should be / come from and what the difference is with exp
87
- const claimsEntries: Array<[cborpkg.com.sphereon.cbor.CborUInt, cborpkg.com.sphereon.cbor.CborItem<any>]> = [
88
- [new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.SUBJECT)), new cbor.CborString(id)], // "sub"
89
- [new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.ISSUER)), new cbor.CborString(issuerString)], // "iss"
95
+ const claimsEntries: Array<[CborUIntType, CborItem<any>]> = [
96
+ [new CborUInt(com.sphereon.kmp.LongKMP.fromNumber(CWT_CLAIMS.SUBJECT)), new com.sphereon.cbor.CborString(id)], // "sub"
97
+ [new CborUInt(com.sphereon.kmp.LongKMP.fromNumber(CWT_CLAIMS.ISSUER)), new com.sphereon.cbor.CborString(issuerString)], // "iss"
90
98
  [
91
- new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.ISSUED_AT)),
92
- new cbor.CborUInt(kmp.LongKMP.fromNumber(Math.floor(Date.now() / 1000))), // "iat"
99
+ new CborUInt(com.sphereon.kmp.LongKMP.fromNumber(CWT_CLAIMS.ISSUED_AT)),
100
+ new CborUInt(com.sphereon.kmp.LongKMP.fromNumber(Math.floor(Date.now() / 1000))), // "iat"
93
101
  ],
94
102
  ]
95
103
 
96
104
  if (expiresAt) {
97
105
  claimsEntries.push([
98
- new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.EXPIRATION)),
99
- new cbor.CborUInt(kmp.LongKMP.fromNumber(Math.floor(expiresAt.getTime() / 1000))), // "exp"
106
+ new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(CWT_CLAIMS.EXPIRATION)),
107
+ new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(Math.floor(expiresAt.getTime() / 1000))), // "exp"
100
108
  ])
101
109
  }
102
110
 
103
111
  if (ttl) {
104
112
  claimsEntries.push([
105
- new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.TIME_TO_LIVE)),
106
- new cbor.CborUInt(kmp.LongKMP.fromNumber(ttl)), // "time to live"
113
+ new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(CWT_CLAIMS.TIME_TO_LIVE)),
114
+ new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(ttl)), // "time to live"
107
115
  ])
108
116
  }
109
117
 
110
- claimsEntries.push([new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.STATUS_LIST)), statusListMap])
118
+ claimsEntries.push([new com.sphereon.cbor.CborUInt(com.sphereon.kmp.LongKMP.fromNumber(CWT_CLAIMS.STATUS_LIST)), statusListMap])
111
119
 
112
- const claimsMap = new cbor.CborMap(kotlin.collections.KtMutableMap.fromJsMap(new Map(claimsEntries)))
120
+ const claimsMap = new com.sphereon.cbor.CborMap(kotlin.collections.KtMutableMap.fromJsMap(new Map(claimsEntries)))
113
121
  return claimsMap
114
122
  }
115
123
 
116
- const getCborValueFromMap = <T>(map: Map<cborpkg.com.sphereon.cbor.CborItem<any>, cborpkg.com.sphereon.cbor.CborItem<any>>, key: number): T => {
124
+ const getCborValueFromMap = <T>(map: Map<CborItem<any>, CborItem<any>>, key: number): T => {
117
125
  const value = getCborOptionalValueFromMap<T>(map, key)
118
126
  if (value === undefined) {
119
127
  throw new Error(`Required claim ${key} not found`)
@@ -121,11 +129,8 @@ const getCborValueFromMap = <T>(map: Map<cborpkg.com.sphereon.cbor.CborItem<any>
121
129
  return value
122
130
  }
123
131
 
124
- const getCborOptionalValueFromMap = <T>(
125
- map: Map<cborpkg.com.sphereon.cbor.CborItem<any>, cborpkg.com.sphereon.cbor.CborItem<any>>,
126
- key: number,
127
- ): T | undefined | never => {
128
- const value = map.get(new cborpkg.com.sphereon.cbor.CborUInt(kmp.LongKMP.fromNumber(key)))
132
+ const getCborOptionalValueFromMap = <T>(map: Map<CborItem<any>, CborItem<any>>, key: number): T | undefined | never => {
133
+ const value = map.get(new CborUInt(com.sphereon.kmp.LongKMP.fromNumber(key)))
129
134
  if (!value) {
130
135
  return undefined
131
136
  }
@@ -135,28 +140,28 @@ const getCborOptionalValueFromMap = <T>(
135
140
  export const decodeStatusListCWT = (cwt: string): DecodedStatusListPayload => {
136
141
  const encodedCbor = base64url.toBuffer(cwt)
137
142
  const encodedCborArray = new Int8Array(encodedCbor)
138
- const decodedCbor = cborpkg.com.sphereon.cbor.Cbor.decode(encodedCborArray)
143
+ const decodedCbor = com.sphereon.cbor.Cbor.decode(encodedCborArray)
139
144
 
140
- if (!(decodedCbor instanceof cborpkg.com.sphereon.cbor.CborArray)) {
145
+ if (!(decodedCbor instanceof com.sphereon.cbor.CborArray)) {
141
146
  throw new Error('Invalid CWT format: Expected a CBOR array')
142
147
  }
143
148
 
144
149
  const [, payload] = decodedCbor.value.asJsArrayView()
145
- if (!(payload instanceof cborpkg.com.sphereon.cbor.CborByteString)) {
150
+ if (!(payload instanceof com.sphereon.cbor.CborByteString)) {
146
151
  throw new Error('Invalid payload format: Expected a CBOR ByteString')
147
152
  }
148
153
 
149
- const claims = cborpkg.com.sphereon.cbor.Cbor.decode(payload.value)
150
- if (!(claims instanceof cborpkg.com.sphereon.cbor.CborMap)) {
154
+ const claims = com.sphereon.cbor.Cbor.decode(payload.value)
155
+ if (!(claims instanceof com.sphereon.cbor.CborMap)) {
151
156
  throw new Error('Invalid claims format: Expected a CBOR map')
152
157
  }
153
158
 
154
159
  const claimsMap = claims.value.asJsMapView()
155
160
 
156
- const statusListMap = claimsMap.get(new cborpkg.com.sphereon.cbor.CborUInt(kmp.LongKMP.fromNumber(65533))).value.asJsMapView()
161
+ const statusListMap = claimsMap.get(new CborUInt(com.sphereon.kmp.LongKMP.fromNumber(65533))).value.asJsMapView()
157
162
 
158
- const bits = Number(statusListMap.get(new cborpkg.com.sphereon.cbor.CborString('bits')).value) as BitsPerStatus
159
- const decoded = new Uint8Array(statusListMap.get(new cborpkg.com.sphereon.cbor.CborString('lst')).value)
163
+ const bits = Number(statusListMap.get(new CborString('bits')).value) as BitsPerStatus
164
+ const decoded = new Uint8Array(statusListMap.get(new CborString('lst')).value)
160
165
  const uint8Array = inflate(decoded)
161
166
  const rawStatusList = decompressRawStatusList(uint8Array, bits)
162
167
  const statusList = new StatusList(rawStatusList, bits)
@@ -1,4 +1,4 @@
1
- import { IRequiredContext } from '../../types'
1
+ import type { IRequiredContext } from '../../types'
2
2
  import { StatusList } from '@sd-jwt/jwt-status-list'
3
3
 
4
4
  export interface DecodedStatusListPayload {
@@ -1,10 +1,10 @@
1
- import { CompactJWT, JoseSignatureAlgorithm } from '@sphereon/ssi-types'
2
- import { createHeaderAndPayload, StatusList, StatusListJWTHeaderParameters, StatusListJWTPayload } from '@sd-jwt/jwt-status-list'
1
+ import { type CompactJWT, JoseSignatureAlgorithm } from '@sphereon/ssi-types'
2
+ import { createHeaderAndPayload, StatusList, type StatusListJWTHeaderParameters, type StatusListJWTPayload } from '@sd-jwt/jwt-status-list'
3
3
  import base64url from 'base64url'
4
- import { JWTPayload } from 'did-jwt'
5
- import { IRequiredContext, SignedStatusListData } from '../../types'
6
- import { DecodedStatusListPayload, resolveIdentifier } from './common'
7
- import { TKeyType } from '@veramo/core'
4
+ import type { JWTPayload } from 'did-jwt'
5
+ import type { IRequiredContext, SignedStatusListData } from '../../types'
6
+ import { type DecodedStatusListPayload, resolveIdentifier } from './common'
7
+ import type { TKeyType } from '@veramo/core'
8
8
  import { ensureManagedIdentifierResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
9
9
 
10
10
  const STATUS_LIST_JWT_TYP = 'statuslist+jwt'
@@ -1,19 +1,19 @@
1
- import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
1
+ import type { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
2
2
  import {
3
- ICredential,
4
- ICredentialStatus,
5
- IIssuer,
6
- IVerifiableCredential,
7
- OrPromise,
3
+ type ICredential,
4
+ type ICredentialStatus,
5
+ type IIssuer,
6
+ type IVerifiableCredential,
7
+ type OrPromise,
8
8
  type CredentialProofFormat,
9
- StatusListCredential,
9
+ type StatusListCredential,
10
10
  StatusListCredentialIdMode,
11
11
  StatusListDriverType,
12
- StatusListIndexingDirection,
12
+ type StatusListIndexingDirection,
13
13
  StatusListType,
14
- StatusPurpose2021,
14
+ type StatusPurpose2021,
15
15
  } from '@sphereon/ssi-types'
16
- import {
16
+ import type {
17
17
  CredentialPayload,
18
18
  IAgentContext,
19
19
  ICredentialIssuer,
@@ -23,9 +23,9 @@ import {
23
23
  IPluginMethodMap,
24
24
  } from '@veramo/core'
25
25
  import { DataSource } from 'typeorm'
26
- import { BitsPerStatus } from '@sd-jwt/jwt-status-list'
27
- import { SdJwtVcPayload } from '@sd-jwt/sd-jwt-vc'
28
- import { StatusListOpts } from '@sphereon/oid4vci-common'
26
+ import type { BitsPerStatus } from '@sd-jwt/jwt-status-list'
27
+ import type { SdJwtVcPayload } from '@sd-jwt/sd-jwt-vc'
28
+ import type { StatusListOpts } from '@sphereon/oid4vci-common'
29
29
 
30
30
  export enum StatusOAuth {
31
31
  Valid = 0,
package/src/utils.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  CredentialMapper,
3
- IIssuer,
3
+ type IIssuer,
4
4
  type CredentialProofFormat,
5
5
  StatusListType,
6
6
  StatusListType as StatusListTypeW3C,
7
- StatusListCredential,
7
+ type StatusListCredential,
8
8
  DocumentFormat,
9
9
  } from '@sphereon/ssi-types'
10
10
  import { jwtDecode } from 'jwt-decode'