@sphereon/ssi-types 0.33.1-next.2 → 0.33.1-next.68
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/dist/index.cjs +1773 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1589 -0
- package/dist/index.d.ts +1589 -6
- package/dist/index.js +1741 -24
- package/dist/index.js.map +1 -1
- package/package.json +23 -14
- package/src/index.ts +3 -2
- package/src/logging/index.ts +6 -4
- package/src/mapper/credential-constraints.ts +14 -1
- package/src/mapper/credential-mapper.ts +61 -23
- package/src/mapper/index.ts +1 -0
- package/src/types/cose.ts +5 -51
- package/src/types/did.ts +0 -90
- package/src/types/index.ts +13 -13
- package/src/types/jose.ts +18 -65
- package/src/types/mso_mdoc.ts +10 -138
- package/src/types/sd-jwt-vc.ts +4 -178
- package/src/types/status-list.ts +1 -8
- package/src/types/vc.ts +7 -29
- package/src/types/w3c-vc.ts +3 -26
- package/src/utils/cose.ts +46 -0
- package/src/utils/did.ts +91 -0
- package/src/utils/hasher.ts +5 -2
- package/src/utils/index.ts +6 -0
- package/src/utils/jose.ts +47 -0
- package/src/utils/mdoc.ts +144 -0
- package/src/utils/sd-jwt.ts +179 -0
- package/src/utils/vc.ts +54 -0
- package/dist/events/index.d.ts +0 -116
- package/dist/events/index.d.ts.map +0 -1
- package/dist/events/index.js +0 -165
- package/dist/events/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logging/index.d.ts +0 -73
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/logging/index.js +0 -186
- package/dist/logging/index.js.map +0 -1
- package/dist/mapper/credential-constraints.d.ts +0 -16
- package/dist/mapper/credential-constraints.d.ts.map +0 -1
- package/dist/mapper/credential-constraints.js +0 -3
- package/dist/mapper/credential-constraints.js.map +0 -1
- package/dist/mapper/credential-mapper.d.ts +0 -124
- package/dist/mapper/credential-mapper.d.ts.map +0 -1
- package/dist/mapper/credential-mapper.js +0 -774
- package/dist/mapper/credential-mapper.js.map +0 -1
- package/dist/mapper/index.d.ts +0 -3
- package/dist/mapper/index.d.ts.map +0 -1
- package/dist/mapper/index.js +0 -19
- package/dist/mapper/index.js.map +0 -1
- package/dist/mapper/jsonld-language-values.d.ts +0 -18
- package/dist/mapper/jsonld-language-values.d.ts.map +0 -1
- package/dist/mapper/jsonld-language-values.js +0 -79
- package/dist/mapper/jsonld-language-values.js.map +0 -1
- package/dist/types/cose.d.ts +0 -77
- package/dist/types/cose.d.ts.map +0 -1
- package/dist/types/cose.js +0 -51
- package/dist/types/cose.js.map +0 -1
- package/dist/types/dcql.d.ts +0 -33
- package/dist/types/dcql.d.ts.map +0 -1
- package/dist/types/dcql.js +0 -4
- package/dist/types/dcql.js.map +0 -1
- package/dist/types/did.d.ts +0 -186
- package/dist/types/did.d.ts.map +0 -1
- package/dist/types/did.js +0 -78
- package/dist/types/did.js.map +0 -1
- package/dist/types/generic.d.ts +0 -44
- package/dist/types/generic.d.ts.map +0 -1
- package/dist/types/generic.js +0 -3
- package/dist/types/generic.js.map +0 -1
- package/dist/types/index.d.ts +0 -14
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -30
- package/dist/types/index.js.map +0 -1
- package/dist/types/jose.d.ts +0 -89
- package/dist/types/jose.d.ts.map +0 -1
- package/dist/types/jose.js +0 -55
- package/dist/types/jose.js.map +0 -1
- package/dist/types/metadata-types.d.ts +0 -5
- package/dist/types/metadata-types.d.ts.map +0 -1
- package/dist/types/metadata-types.js +0 -3
- package/dist/types/metadata-types.js.map +0 -1
- package/dist/types/mso_mdoc.d.ts +0 -94
- package/dist/types/mso_mdoc.d.ts.map +0 -1
- package/dist/types/mso_mdoc.js +0 -121
- package/dist/types/mso_mdoc.js.map +0 -1
- package/dist/types/pex.d.ts +0 -36
- package/dist/types/pex.d.ts.map +0 -1
- package/dist/types/pex.js +0 -3
- package/dist/types/pex.js.map +0 -1
- package/dist/types/sd-jwt-type-metadata.d.ts +0 -191
- package/dist/types/sd-jwt-type-metadata.d.ts.map +0 -1
- package/dist/types/sd-jwt-type-metadata.js +0 -3
- package/dist/types/sd-jwt-type-metadata.js.map +0 -1
- package/dist/types/sd-jwt-vc.d.ts +0 -196
- package/dist/types/sd-jwt-vc.d.ts.map +0 -1
- package/dist/types/sd-jwt-vc.js +0 -142
- package/dist/types/sd-jwt-vc.js.map +0 -1
- package/dist/types/status-list.d.ts +0 -10
- package/dist/types/status-list.d.ts.map +0 -1
- package/dist/types/status-list.js +0 -9
- package/dist/types/status-list.js.map +0 -1
- package/dist/types/vc.d.ts +0 -28
- package/dist/types/vc.d.ts.map +0 -1
- package/dist/types/vc.js +0 -28
- package/dist/types/vc.js.map +0 -1
- package/dist/types/w3c-vc.d.ts +0 -243
- package/dist/types/w3c-vc.d.ts.map +0 -1
- package/dist/types/w3c-vc.js +0 -26
- package/dist/types/w3c-vc.js.map +0 -1
- package/dist/utils/hasher.d.ts +0 -4
- package/dist/utils/hasher.d.ts.map +0 -1
- package/dist/utils/hasher.js +0 -40
- package/dist/utils/hasher.js.map +0 -1
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -19
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/object.d.ts +0 -8
- package/dist/utils/object.d.ts.map +0 -1
- package/dist/utils/object.js +0 -28
- package/dist/utils/object.js.map +0 -1
package/src/types/cose.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as mdoc from '@sphereon/kmp-mdoc-core'
|
|
2
|
+
import { ICoseCurve, ICoseKeyOperation, ICoseKeyType, ICoseSignatureAlgorithm } from '../utils'
|
|
3
|
+
type KeyType = mdoc.com.sphereon.crypto.generic.KeyType
|
|
4
|
+
type KeyOperations = mdoc.com.sphereon.crypto.generic.KeyOperations
|
|
5
|
+
type SignatureAlgorithm = mdoc.com.sphereon.crypto.generic.SignatureAlgorithm
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* See our mdl-mdoc and crypto library for more information
|
|
@@ -33,50 +34,3 @@ export interface ICoseKeyJson {
|
|
|
33
34
|
|
|
34
35
|
[k: string]: unknown
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
export enum ICoseKeyType {
|
|
38
|
-
OKP = 1,
|
|
39
|
-
EC2 = 2,
|
|
40
|
-
RSA = 3,
|
|
41
|
-
Symmetric = 4,
|
|
42
|
-
Reserved = 0,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export enum ICoseSignatureAlgorithm {
|
|
46
|
-
ES256 = -7,
|
|
47
|
-
ES256K = -47,
|
|
48
|
-
ES384 = -35,
|
|
49
|
-
ES512 = -36,
|
|
50
|
-
EdDSA = -8,
|
|
51
|
-
HS256_64 = 4,
|
|
52
|
-
HS256 = 5,
|
|
53
|
-
HS384 = 6,
|
|
54
|
-
HS512 = 7,
|
|
55
|
-
PS256 = -37,
|
|
56
|
-
PS384 = -38,
|
|
57
|
-
PS512 = -39,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export enum ICoseKeyOperation {
|
|
61
|
-
SIGN = 1,
|
|
62
|
-
VERIFY = 2,
|
|
63
|
-
ENCRYPT = 3,
|
|
64
|
-
DECRYPT = 4,
|
|
65
|
-
WRAP_KEY = 5,
|
|
66
|
-
UNWRAP_KEY = 6,
|
|
67
|
-
DERIVE_KEY = 7,
|
|
68
|
-
DERIVE_BITS = 8,
|
|
69
|
-
MAC_CREATE = 9,
|
|
70
|
-
MAC_VERIFY = 10,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export enum ICoseCurve {
|
|
74
|
-
P_256 = 1,
|
|
75
|
-
P_384 = 2,
|
|
76
|
-
P_521 = 3,
|
|
77
|
-
X25519 = 4,
|
|
78
|
-
X448 = 5,
|
|
79
|
-
Ed25519 = 6,
|
|
80
|
-
Ed448 = 7,
|
|
81
|
-
secp256k1 = -1,
|
|
82
|
-
}
|
package/src/types/did.ts
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
export enum IProofPurpose {
|
|
2
|
-
verificationMethod = 'verificationMethod',
|
|
3
|
-
assertionMethod = 'assertionMethod',
|
|
4
|
-
authentication = 'authentication',
|
|
5
|
-
keyAgreement = 'keyAgreement',
|
|
6
|
-
contractAgreement = 'contactAgreement',
|
|
7
|
-
capabilityInvocation = 'capabilityInvocation',
|
|
8
|
-
capabilityDelegation = 'capabilityDelegation',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum IProofType {
|
|
12
|
-
Ed25519Signature2018 = 'Ed25519Signature2018',
|
|
13
|
-
Ed25519Signature2020 = 'Ed25519Signature2020',
|
|
14
|
-
EcdsaSecp256k1Signature2019 = 'EcdsaSecp256k1Signature2019',
|
|
15
|
-
EcdsaSecp256k1RecoverySignature2020 = 'EcdsaSecp256k1RecoverySignature2020',
|
|
16
|
-
JsonWebSignature2020 = 'JsonWebSignature2020',
|
|
17
|
-
RsaSignature2018 = 'RsaSignature2018',
|
|
18
|
-
GpgSignature2020 = 'GpgSignature2020',
|
|
19
|
-
JcsEd25519Signature2020 = 'JcsEd25519Signature2020',
|
|
20
|
-
BbsBlsSignatureProof2020 = 'BbsBlsSignatureProof2020',
|
|
21
|
-
BbsBlsBoundSignatureProof2020 = 'BbsBlsBoundSignatureProof2020',
|
|
22
|
-
JwtProof2020 = 'JwtProof2020',
|
|
23
|
-
SdJwtProof2024 = 'SdJwtProof2024',
|
|
24
|
-
MdocProof2024 = 'MsoMdocProof2024',
|
|
25
|
-
}
|
|
26
|
-
|
|
27
1
|
export interface IParsedDID {
|
|
28
2
|
did: string
|
|
29
3
|
didUrl: string
|
|
@@ -37,70 +11,6 @@ export interface IParsedDID {
|
|
|
37
11
|
}
|
|
38
12
|
}
|
|
39
13
|
|
|
40
|
-
export const parseDid = (did: string): IParsedDID => {
|
|
41
|
-
const parsedDid = parse(did)
|
|
42
|
-
if (parsedDid === null) {
|
|
43
|
-
throw new Error('invalid did')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return parsedDid
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const parse = (didUrl: string): IParsedDID | null => {
|
|
50
|
-
const PCT_ENCODED = '(?:%[0-9a-fA-F]{2})'
|
|
51
|
-
const ID_CHAR = `(?:[a-zA-Z0-9._-]|${PCT_ENCODED})`
|
|
52
|
-
const METHOD = '([a-z0-9]+)'
|
|
53
|
-
const METHOD_ID = `((?:${ID_CHAR}*:)*(${ID_CHAR}+))`
|
|
54
|
-
const PARAM_CHAR = '[a-zA-Z0-9_.:%-]'
|
|
55
|
-
const PARAM = `;${PARAM_CHAR}+=${PARAM_CHAR}*`
|
|
56
|
-
const PARAMS = `((${PARAM})*)`
|
|
57
|
-
const PATH = `(/[^#?]*)?`
|
|
58
|
-
const QUERY = `([?][^#]*)?`
|
|
59
|
-
const FRAGMENT = `(#.*)?`
|
|
60
|
-
const DID_MATCHER = new RegExp(`^did:${METHOD}:${METHOD_ID}${PARAMS}${PATH}${QUERY}${FRAGMENT}$`)
|
|
61
|
-
|
|
62
|
-
if (didUrl === '' || !didUrl) return null
|
|
63
|
-
const sections = didUrl.match(DID_MATCHER)
|
|
64
|
-
if (sections) {
|
|
65
|
-
const parts: IParsedDID = {
|
|
66
|
-
did: `did:${sections[1]}:${sections[2]}`,
|
|
67
|
-
method: sections[1],
|
|
68
|
-
id: sections[2],
|
|
69
|
-
didUrl,
|
|
70
|
-
}
|
|
71
|
-
if (sections[4]) {
|
|
72
|
-
const params = sections[4].slice(1).split(';')
|
|
73
|
-
parts.params = {}
|
|
74
|
-
for (const p of params) {
|
|
75
|
-
const kv = p.split('=')
|
|
76
|
-
parts.params[kv[0]] = kv[1]
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (sections[6]) parts.path = sections[6]
|
|
80
|
-
if (sections[7]) parts.query = sections[7].slice(1)
|
|
81
|
-
if (sections[8]) parts.fragment = sections[8].slice(1)
|
|
82
|
-
return parts
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return null
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Copied from did-resolver, so we have types without external dep
|
|
89
|
-
|
|
90
|
-
// Copyright 2018 Consensys AG
|
|
91
|
-
|
|
92
|
-
// Licensed under the Apache License, Version 2.0(the "License");
|
|
93
|
-
// you may not use this file except in compliance with the License.
|
|
94
|
-
// You may obtain a copy of the License at
|
|
95
|
-
|
|
96
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
97
|
-
|
|
98
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
99
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
100
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
101
|
-
// See the License for the specific language governing permissions and
|
|
102
|
-
// limitations under the License.
|
|
103
|
-
|
|
104
14
|
/**
|
|
105
15
|
* Defines an object type that can be extended with other properties.
|
|
106
16
|
*/
|
package/src/types/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './sd-jwt-vc'
|
|
6
|
-
export * from './sd-jwt-type-metadata'
|
|
7
|
-
export * from './w3c-vc'
|
|
8
|
-
export * from './jose'
|
|
9
|
-
export * from './cose'
|
|
10
|
-
export * from './mso_mdoc'
|
|
11
|
-
export * from './metadata-types'
|
|
12
|
-
export * from './status-list'
|
|
13
|
-
export * from './dcql'
|
|
1
|
+
export type * from './generic'
|
|
2
|
+
export type * from './did'
|
|
3
|
+
export type * from './pex'
|
|
4
|
+
export type * from './vc'
|
|
5
|
+
export type * from './sd-jwt-vc'
|
|
6
|
+
export type * from './sd-jwt-type-metadata'
|
|
7
|
+
export type * from './w3c-vc'
|
|
8
|
+
export type * from './jose'
|
|
9
|
+
export type * from './cose'
|
|
10
|
+
export type * from './mso_mdoc'
|
|
11
|
+
export type * from './metadata-types'
|
|
12
|
+
export type * from './status-list'
|
|
13
|
+
export type * from './dcql'
|
package/src/types/jose.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Conversion functions to Cose available for TS in our @sphereon/ssi-sdk-ext.key-utils package
|
|
3
3
|
*/
|
|
4
|
+
import { JoseCurve, JoseKeyOperation, JoseSignatureAlgorithm, JwkKeyType } from '../utils'
|
|
4
5
|
|
|
5
6
|
export interface BaseJWK {
|
|
6
7
|
kty: JwkKeyType | JwkKeyTypeString
|
|
@@ -12,6 +13,23 @@ export interface BaseJWK {
|
|
|
12
13
|
n?: string
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
export type JoseSignatureAlgorithmString =
|
|
17
|
+
| 'RS256'
|
|
18
|
+
| 'RS384'
|
|
19
|
+
| 'RS512'
|
|
20
|
+
| 'ES256'
|
|
21
|
+
| 'ES256K'
|
|
22
|
+
| 'ES384'
|
|
23
|
+
| 'ES512'
|
|
24
|
+
| 'EdDSA'
|
|
25
|
+
| 'HS256'
|
|
26
|
+
| 'HS384'
|
|
27
|
+
| 'HS512'
|
|
28
|
+
| 'PS256'
|
|
29
|
+
| 'PS384'
|
|
30
|
+
| 'PS512'
|
|
31
|
+
| 'none'
|
|
32
|
+
|
|
15
33
|
export interface JWK extends BaseJWK {
|
|
16
34
|
d?: string
|
|
17
35
|
dp?: string
|
|
@@ -43,73 +61,8 @@ export interface JWK extends BaseJWK {
|
|
|
43
61
|
[propName: string]: unknown
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
export enum JwkKeyType {
|
|
47
|
-
EC = 'EC',
|
|
48
|
-
RSA = 'RSA',
|
|
49
|
-
oct = 'oct',
|
|
50
|
-
OKP = 'OKP',
|
|
51
|
-
}
|
|
52
|
-
|
|
53
64
|
export type JwkKeyTypeString = 'EC' | 'RSA' | 'oct' | 'OKP'
|
|
54
65
|
|
|
55
|
-
export enum JoseSignatureAlgorithm {
|
|
56
|
-
RS256 = 'RS256',
|
|
57
|
-
RS384 = 'RS384',
|
|
58
|
-
RS512 = 'RS512',
|
|
59
|
-
ES256 = 'ES256',
|
|
60
|
-
ES256K = 'ES256K',
|
|
61
|
-
ES384 = 'ES384',
|
|
62
|
-
ES512 = 'ES512',
|
|
63
|
-
EdDSA = 'EdDSA',
|
|
64
|
-
HS256 = 'HS256',
|
|
65
|
-
HS384 = 'HS384',
|
|
66
|
-
HS512 = 'HS512',
|
|
67
|
-
PS256 = 'PS256',
|
|
68
|
-
PS384 = 'PS384',
|
|
69
|
-
PS512 = 'PS512',
|
|
70
|
-
none = 'none',
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type JoseSignatureAlgorithmString =
|
|
74
|
-
| 'RS256'
|
|
75
|
-
| 'RS384'
|
|
76
|
-
| 'RS512'
|
|
77
|
-
| 'ES256'
|
|
78
|
-
| 'ES256K'
|
|
79
|
-
| 'ES384'
|
|
80
|
-
| 'ES512'
|
|
81
|
-
| 'EdDSA'
|
|
82
|
-
| 'HS256'
|
|
83
|
-
| 'HS384'
|
|
84
|
-
| 'HS512'
|
|
85
|
-
| 'PS256'
|
|
86
|
-
| 'PS384'
|
|
87
|
-
| 'PS512'
|
|
88
|
-
| 'none'
|
|
89
|
-
|
|
90
|
-
export enum JoseKeyOperation {
|
|
91
|
-
SIGN = 'sign',
|
|
92
|
-
VERIFY = 'verify',
|
|
93
|
-
ENCRYPT = 'encrypt',
|
|
94
|
-
DECRYPT = 'decrypt',
|
|
95
|
-
WRAP_KEY = 'wrapKey',
|
|
96
|
-
UNWRAP_KEY = 'unwrapKey',
|
|
97
|
-
DERIVE_KEY = 'deriveKey',
|
|
98
|
-
DERIVE_BITS = 'deriveBits',
|
|
99
|
-
}
|
|
100
|
-
|
|
101
66
|
export type JoseKeyOperationString = 'sign' | 'verify' | 'encrypt' | 'decrypt' | 'wrapKey' | 'unwrapKey' | 'deriveKey' | 'deriveBits'
|
|
102
67
|
|
|
103
|
-
export enum JoseCurve {
|
|
104
|
-
P_256 = 'P-256',
|
|
105
|
-
P_384 = 'P-384',
|
|
106
|
-
P_521 = 'P-521',
|
|
107
|
-
X25519 = 'X25519',
|
|
108
|
-
X448 = 'X448',
|
|
109
|
-
EdDSA = 'EdDSA',
|
|
110
|
-
Ed25519 = 'Ed25519',
|
|
111
|
-
Ed448 = 'Ed448',
|
|
112
|
-
secp256k1 = 'secp256k1',
|
|
113
|
-
}
|
|
114
|
-
|
|
115
68
|
export type JoseCurveString = 'P-256' | 'P-384' | 'P-521' | 'X25519' | 'X448' | 'EdDSA' | 'Ed25519' | 'Ed448' | 'secp256k1'
|
package/src/types/mso_mdoc.ts
CHANGED
|
@@ -4,30 +4,23 @@
|
|
|
4
4
|
* but it would be nice if we can remove the imports and just have some interfaces here we can then use, like done
|
|
5
5
|
* for sd-jwts
|
|
6
6
|
*/
|
|
7
|
+
import * as mdoc from '@sphereon/kmp-mdoc-core'
|
|
8
|
+
import { OriginalType } from '../mapper'
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { OriginalType, WrappedVerifiableCredential, WrappedVerifiablePresentation } from './vc'
|
|
11
|
-
import { IVerifiableCredential } from './w3c-vc'
|
|
12
|
-
import decodeFrom = com.sphereon.kmp.decodeFrom
|
|
13
|
-
import encodeTo = com.sphereon.kmp.encodeTo
|
|
14
|
-
import Encoding = com.sphereon.kmp.Encoding
|
|
15
|
-
import DeviceResponseCbor = com.sphereon.mdoc.data.device.DeviceResponseCbor
|
|
16
|
-
import DocumentJson = com.sphereon.mdoc.data.device.DocumentJson
|
|
17
|
-
import IssuerSignedCbor = com.sphereon.mdoc.data.device.IssuerSignedCbor
|
|
18
|
-
import IssuerSignedItemJson = com.sphereon.mdoc.data.device.IssuerSignedItemJson
|
|
10
|
+
export type DocumentJson = mdoc.com.sphereon.mdoc.data.device.DocumentJson
|
|
11
|
+
export type IssuerSignedItemJson = mdoc.com.sphereon.mdoc.data.device.IssuerSignedItemJson
|
|
19
12
|
|
|
20
13
|
/**
|
|
21
14
|
* Represents a selective disclosure JWT vc in compact form.
|
|
22
15
|
*/
|
|
23
16
|
export type MdocOid4vpIssuerSigned = string
|
|
24
17
|
export type MdocOid4vpMdocVpToken = string
|
|
25
|
-
export type MdocIssuerSigned = com.sphereon.mdoc.data.device.IssuerSignedCbor
|
|
26
|
-
export type MdocDocument = com.sphereon.mdoc.data.device.DocumentCbor
|
|
27
|
-
export type MdocDocumentJson = com.sphereon.mdoc.data.device.DocumentJson
|
|
28
|
-
export type IssuerSignedJson = com.sphereon.mdoc.data.device.IssuerSignedJson
|
|
29
|
-
export type DeviceSignedJson = com.sphereon.mdoc.data.device.DeviceSignedJson
|
|
30
|
-
export type MdocDeviceResponse = com.sphereon.mdoc.data.device.DeviceResponseCbor
|
|
18
|
+
export type MdocIssuerSigned = mdoc.com.sphereon.mdoc.data.device.IssuerSignedCbor
|
|
19
|
+
export type MdocDocument = mdoc.com.sphereon.mdoc.data.device.DocumentCbor
|
|
20
|
+
export type MdocDocumentJson = mdoc.com.sphereon.mdoc.data.device.DocumentJson
|
|
21
|
+
export type IssuerSignedJson = mdoc.com.sphereon.mdoc.data.device.IssuerSignedJson
|
|
22
|
+
export type DeviceSignedJson = mdoc.com.sphereon.mdoc.data.device.DeviceSignedJson
|
|
23
|
+
export type MdocDeviceResponse = mdoc.com.sphereon.mdoc.data.device.DeviceResponseCbor
|
|
31
24
|
|
|
32
25
|
export interface WrappedMdocCredential {
|
|
33
26
|
/**
|
|
@@ -81,128 +74,7 @@ export interface WrappedMdocPresentation {
|
|
|
81
74
|
vcs: WrappedMdocCredential[]
|
|
82
75
|
}
|
|
83
76
|
|
|
84
|
-
export function isWrappedMdocCredential(vc: WrappedVerifiableCredential): vc is WrappedMdocCredential {
|
|
85
|
-
return vc.format === 'mso_mdoc'
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function isWrappedMdocPresentation(vp: WrappedVerifiablePresentation): vp is WrappedMdocPresentation {
|
|
89
|
-
return vp.format === 'mso_mdoc'
|
|
90
|
-
}
|
|
91
77
|
/**
|
|
92
78
|
* Record where keys are the namespaces and the values are objects again with the namespace values
|
|
93
79
|
*/
|
|
94
80
|
export type MdocDecodedPayload = Record<string, Record<string, string | number | boolean>>
|
|
95
|
-
export function getMdocDecodedPayload(mdoc: MdocDocument): MdocDecodedPayload {
|
|
96
|
-
const mdocJson = mdoc.toJson()
|
|
97
|
-
if (!mdocJson.issuerSigned.nameSpaces) {
|
|
98
|
-
throw Error(`Cannot access Issuer Signed items from the Mdoc`)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const issuerSignedJson = mdoc.issuerSigned.toJsonDTO()
|
|
102
|
-
const namespaces = issuerSignedJson.nameSpaces as unknown as Record<string, IssuerSignedItemJson[]>
|
|
103
|
-
|
|
104
|
-
const decodedPayload: MdocDecodedPayload = {}
|
|
105
|
-
for (const [namespace, items] of Object.entries(namespaces)) {
|
|
106
|
-
decodedPayload[namespace] = items.reduce(
|
|
107
|
-
(acc, item) => ({
|
|
108
|
-
...acc,
|
|
109
|
-
[item.key]: item.value.value,
|
|
110
|
-
}),
|
|
111
|
-
{},
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return decodedPayload
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Decode an Mdoc from its issuerSigned OID4VP Base64URL (string) to an object containing the disclosures,
|
|
120
|
-
* signed payload, decoded payload
|
|
121
|
-
*
|
|
122
|
-
*/
|
|
123
|
-
export function decodeMdocIssuerSigned(oid4vpIssuerSigned: MdocOid4vpIssuerSigned): MdocDocument {
|
|
124
|
-
// Issuer signed according to 18013-7 in base64url
|
|
125
|
-
const issuerSigned: MdocIssuerSigned = IssuerSignedCbor.Static.cborDecode(decodeFrom(oid4vpIssuerSigned, Encoding.BASE64URL))
|
|
126
|
-
// Create an mdoc from it. // Validations need to be performed by the caller after this!
|
|
127
|
-
const holderMdoc: MdocDocument = issuerSigned.toDocument()
|
|
128
|
-
return holderMdoc
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function encodeMdocIssuerSigned(issuerSigned: MdocIssuerSigned, encoding: 'base64url' = 'base64url') {
|
|
132
|
-
return encodeTo(issuerSigned.cborEncode(), Encoding.BASE64URL)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Decode an Mdoc from its vp_token OID4VP Base64URL (string) to an object containing the disclosures,
|
|
137
|
-
* signed payload, decoded payload
|
|
138
|
-
*
|
|
139
|
-
*/
|
|
140
|
-
export function decodeMdocDeviceResponse(vpToken: MdocOid4vpMdocVpToken): MdocDeviceResponse {
|
|
141
|
-
const deviceResponse = DeviceResponseCbor.Static.cborDecode(decodeFrom(vpToken, Encoding.BASE64URL))
|
|
142
|
-
return deviceResponse
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// TODO naive implementation of mapping a mdoc onto a IVerifiableCredential. Needs some fixes and further implementation and needs to be moved out of ssi-types
|
|
146
|
-
export const mdocDecodedCredentialToUniformCredential = (
|
|
147
|
-
decoded: MdocDocument,
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
opts?: { maxTimeSkewInMS?: number },
|
|
150
|
-
): IVerifiableCredential => {
|
|
151
|
-
const mdoc = decoded.toJson()
|
|
152
|
-
const json = mdoc.toJsonDTO<DocumentJson>()
|
|
153
|
-
const type = 'Personal Identification Data'
|
|
154
|
-
const MSO = mdoc.MSO
|
|
155
|
-
if (!MSO || !json.issuerSigned?.nameSpaces) {
|
|
156
|
-
throw Error(`Cannot access Mobile Security Object or Issuer Signed items from the Mdoc`)
|
|
157
|
-
}
|
|
158
|
-
const nameSpaces = json.issuerSigned.nameSpaces as unknown as Record<string, IssuerSignedItemJson[]>
|
|
159
|
-
if (!('eu.europa.ec.eudi.pid.1' in nameSpaces)) {
|
|
160
|
-
throw Error(`Only PID supported at present`)
|
|
161
|
-
}
|
|
162
|
-
const items = nameSpaces['eu.europa.ec.eudi.pid.1']
|
|
163
|
-
if (!items || items.length === 0) {
|
|
164
|
-
throw Error(`No issuer signed items were found`)
|
|
165
|
-
}
|
|
166
|
-
type DisclosuresAccumulator = {
|
|
167
|
-
[key: string]: any
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const credentialSubject = items.reduce((acc: DisclosuresAccumulator, item: IssuerSignedItemJson) => {
|
|
171
|
-
if (Array.isArray(item.value)) {
|
|
172
|
-
acc[item.key] = item.value.map((val) => val.value).join(', ')
|
|
173
|
-
} else {
|
|
174
|
-
acc[item.key] = item.value.value
|
|
175
|
-
}
|
|
176
|
-
return acc
|
|
177
|
-
}, {})
|
|
178
|
-
const validFrom = MSO.validityInfo.validFrom
|
|
179
|
-
const validUntil = MSO.validityInfo.validUntil
|
|
180
|
-
const docType = MSO.docType
|
|
181
|
-
const expirationDate = validUntil
|
|
182
|
-
let issuanceDateStr = validFrom
|
|
183
|
-
|
|
184
|
-
const issuanceDate = issuanceDateStr
|
|
185
|
-
if (!issuanceDate) {
|
|
186
|
-
throw Error(`JWT issuance date is required but was not present`)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const credential: Omit<IVerifiableCredential, 'issuer' | 'issuanceDate'> = {
|
|
190
|
-
type: [docType], // Mdoc not a W3C VC, so no VerifiableCredential
|
|
191
|
-
'@context': [], // Mdoc has no JSON-LD by default. Certainly not the VC DM1 default context for JSON-LD
|
|
192
|
-
credentialSubject: {
|
|
193
|
-
type,
|
|
194
|
-
...credentialSubject,
|
|
195
|
-
},
|
|
196
|
-
issuanceDate,
|
|
197
|
-
expirationDate,
|
|
198
|
-
proof: {
|
|
199
|
-
type: IProofType.MdocProof2024,
|
|
200
|
-
created: issuanceDate,
|
|
201
|
-
proofPurpose: IProofPurpose.authentication,
|
|
202
|
-
verificationMethod: json.issuerSigned.issuerAuth.payload,
|
|
203
|
-
mso_mdoc: encodeTo(decoded.cborEncode(), Encoding.BASE64URL),
|
|
204
|
-
},
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return credential as IVerifiableCredential
|
|
208
|
-
}
|
package/src/types/sd-jwt-vc.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { IProofPurpose, IProofType } from './did'
|
|
5
|
-
import { OrPromise } from './generic'
|
|
1
|
+
import { type CompactJWT } from './w3c-vc'
|
|
2
|
+
import { type OrPromise } from './generic'
|
|
3
|
+
import { OriginalType } from '../mapper'
|
|
6
4
|
|
|
7
5
|
type JsonValue = string | number | boolean | { [x: string]: JsonValue | undefined } | Array<JsonValue>
|
|
8
6
|
|
|
@@ -47,7 +45,7 @@ export type CompactSdJwtVc = string
|
|
|
47
45
|
/**
|
|
48
46
|
* The signed payload of an SD-JWT. Includes fields such as `_sd`, `...` and `_sd_alg`
|
|
49
47
|
*/
|
|
50
|
-
interface SdJwtSignedVerifiableCredentialPayload extends SdJwtDecodedVerifiableCredentialPayload {
|
|
48
|
+
export interface SdJwtSignedVerifiableCredentialPayload extends SdJwtDecodedVerifiableCredentialPayload {
|
|
51
49
|
// Only present if there are any selectively discloseable claims
|
|
52
50
|
_sd?: string[]
|
|
53
51
|
_sd_alg?: string
|
|
@@ -198,175 +196,3 @@ export interface WrappedSdJwtVerifiablePresentation {
|
|
|
198
196
|
*/
|
|
199
197
|
vcs: [WrappedSdJwtVerifiableCredential]
|
|
200
198
|
}
|
|
201
|
-
|
|
202
|
-
export function isWrappedSdJwtVerifiableCredential(vc: WrappedVerifiableCredential): vc is WrappedSdJwtVerifiableCredential {
|
|
203
|
-
return vc.format === 'vc+sd-jwt'
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function isWrappedSdJwtVerifiablePresentation(vp: WrappedVerifiablePresentation): vp is WrappedSdJwtVerifiablePresentation {
|
|
207
|
-
return vp.format === 'vc+sd-jwt'
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Decode an SD-JWT vc from its compact format (string) to an object containing the disclosures,
|
|
212
|
-
* signed payload, decoded payload and the compact SD-JWT vc.
|
|
213
|
-
*
|
|
214
|
-
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
|
|
215
|
-
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
|
|
216
|
-
*/
|
|
217
|
-
export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: HasherSync): SdJwtDecodedVerifiableCredential {
|
|
218
|
-
const { jwt, disclosures, kbJwt } = decodeSdJwtSync(compactSdJwtVc, hasher)
|
|
219
|
-
|
|
220
|
-
const signedPayload = jwt.payload as SdJwtSignedVerifiableCredentialPayload
|
|
221
|
-
const decodedPayload = getClaimsSync(signedPayload, disclosures, hasher)
|
|
222
|
-
const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split('~').pop() : undefined
|
|
223
|
-
|
|
224
|
-
return {
|
|
225
|
-
compactSdJwtVc,
|
|
226
|
-
decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
227
|
-
disclosures: disclosures.map((d) => {
|
|
228
|
-
const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]
|
|
229
|
-
if (!d._digest) throw new Error('Implementation error: digest not present in disclosure')
|
|
230
|
-
return {
|
|
231
|
-
decoded: decoded as SdJwtDecodedDisclosure,
|
|
232
|
-
digest: d._digest,
|
|
233
|
-
encoded: d.encode(),
|
|
234
|
-
} satisfies SdJwtDisclosure
|
|
235
|
-
}),
|
|
236
|
-
signedPayload: signedPayload as SdJwtSignedVerifiableCredentialPayload,
|
|
237
|
-
...(compactKeyBindingJwt &&
|
|
238
|
-
kbJwt && {
|
|
239
|
-
kbJwt: {
|
|
240
|
-
header: kbJwt.header as SdJwtVcKbJwtHeader,
|
|
241
|
-
compact: compactKeyBindingJwt,
|
|
242
|
-
payload: kbJwt.payload as SdJwtVcKbJwtPayload,
|
|
243
|
-
},
|
|
244
|
-
}),
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Decode an SD-JWT vc from its compact format (string) to an object containing the disclosures,
|
|
250
|
-
* signed payload, decoded payload and the compact SD-JWT vc.
|
|
251
|
-
*
|
|
252
|
-
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
|
|
253
|
-
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
|
|
254
|
-
*/
|
|
255
|
-
export async function decodeSdJwtVcAsync(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): Promise<SdJwtDecodedVerifiableCredential> {
|
|
256
|
-
const { jwt, disclosures, kbJwt } = await decodeSdJwt(compactSdJwtVc, hasher)
|
|
257
|
-
|
|
258
|
-
const signedPayload = jwt.payload as SdJwtSignedVerifiableCredentialPayload
|
|
259
|
-
const decodedPayload = await getClaims(signedPayload, disclosures, hasher)
|
|
260
|
-
const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split('~').pop() : undefined
|
|
261
|
-
|
|
262
|
-
return {
|
|
263
|
-
compactSdJwtVc,
|
|
264
|
-
decodedPayload: decodedPayload as SdJwtDecodedVerifiableCredentialPayload,
|
|
265
|
-
disclosures: disclosures.map((d) => {
|
|
266
|
-
const decoded = d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]
|
|
267
|
-
if (!d._digest) throw new Error('Implementation error: digest not present in disclosure')
|
|
268
|
-
return {
|
|
269
|
-
decoded: decoded as SdJwtDecodedDisclosure,
|
|
270
|
-
digest: d._digest,
|
|
271
|
-
encoded: d.encode(),
|
|
272
|
-
} satisfies SdJwtDisclosure
|
|
273
|
-
}),
|
|
274
|
-
signedPayload: signedPayload as SdJwtSignedVerifiableCredentialPayload,
|
|
275
|
-
...(compactKeyBindingJwt &&
|
|
276
|
-
kbJwt && {
|
|
277
|
-
kbJwt: {
|
|
278
|
-
header: kbJwt.header as SdJwtVcKbJwtHeader,
|
|
279
|
-
payload: kbJwt.payload as SdJwtVcKbJwtPayload,
|
|
280
|
-
compact: compactKeyBindingJwt,
|
|
281
|
-
},
|
|
282
|
-
}),
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export const sdJwtDecodedCredentialToUniformCredential = (
|
|
287
|
-
decoded: SdJwtDecodedVerifiableCredential,
|
|
288
|
-
opts?: { maxTimeSkewInMS?: number },
|
|
289
|
-
): IVerifiableCredential => {
|
|
290
|
-
const { decodedPayload } = decoded
|
|
291
|
-
const { exp, nbf, iss, iat, vct, cnf, status, sub, jti } = decodedPayload
|
|
292
|
-
|
|
293
|
-
const maxSkewInMS = opts?.maxTimeSkewInMS ?? 1500
|
|
294
|
-
|
|
295
|
-
const expirationDate = jwtDateToISOString({ jwtClaim: exp, claimName: 'exp' })
|
|
296
|
-
let issuanceDateStr = jwtDateToISOString({ jwtClaim: iat, claimName: 'iat' })
|
|
297
|
-
|
|
298
|
-
let nbfDateAsStr: string | undefined
|
|
299
|
-
if (nbf) {
|
|
300
|
-
nbfDateAsStr = jwtDateToISOString({ jwtClaim: nbf, claimName: 'nbf' })
|
|
301
|
-
if (issuanceDateStr && nbfDateAsStr && issuanceDateStr !== nbfDateAsStr) {
|
|
302
|
-
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(iss).getTime())
|
|
303
|
-
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
304
|
-
throw Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${iss})`)
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
issuanceDateStr = nbfDateAsStr
|
|
308
|
-
}
|
|
309
|
-
const issuanceDate = issuanceDateStr
|
|
310
|
-
if (!issuanceDate) {
|
|
311
|
-
throw Error(`JWT issuance date is required but was not present`)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Filter out the fields we don't want in credentialSubject
|
|
315
|
-
const excludedFields = new Set(['vct', 'cnf', 'iss', 'iat', 'exp', 'nbf', 'jti', 'sub'])
|
|
316
|
-
const credentialSubject = Object.entries(decodedPayload).reduce(
|
|
317
|
-
(acc, [key, value]) => {
|
|
318
|
-
if (
|
|
319
|
-
!excludedFields.has(key) &&
|
|
320
|
-
value !== undefined &&
|
|
321
|
-
value !== '' &&
|
|
322
|
-
!(typeof value === 'object' && value !== null && Object.keys(value).length === 0)
|
|
323
|
-
) {
|
|
324
|
-
acc[key] = value
|
|
325
|
-
}
|
|
326
|
-
return acc
|
|
327
|
-
},
|
|
328
|
-
{} as Record<string, any>,
|
|
329
|
-
)
|
|
330
|
-
|
|
331
|
-
const credential: Omit<IVerifiableCredential, 'issuer' | 'issuanceDate'> = {
|
|
332
|
-
type: [vct], // SDJwt is not a W3C VC, so no VerifiableCredential
|
|
333
|
-
'@context': [], // SDJwt has no JSON-LD by default. Certainly not the VC DM1 default context for JSON-LD
|
|
334
|
-
credentialSubject: {
|
|
335
|
-
...credentialSubject,
|
|
336
|
-
id: credentialSubject.id ?? sub ?? jti,
|
|
337
|
-
},
|
|
338
|
-
issuanceDate,
|
|
339
|
-
expirationDate,
|
|
340
|
-
issuer: iss,
|
|
341
|
-
...(cnf && { cnf }),
|
|
342
|
-
...(status && { status }),
|
|
343
|
-
proof: {
|
|
344
|
-
type: IProofType.SdJwtProof2024,
|
|
345
|
-
created: nbfDateAsStr ?? issuanceDate,
|
|
346
|
-
proofPurpose: IProofPurpose.authentication,
|
|
347
|
-
verificationMethod: iss,
|
|
348
|
-
jwt: decoded.compactSdJwtVc,
|
|
349
|
-
},
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return credential as IVerifiableCredential
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const jwtDateToISOString = ({
|
|
356
|
-
jwtClaim,
|
|
357
|
-
claimName,
|
|
358
|
-
isRequired = false,
|
|
359
|
-
}: {
|
|
360
|
-
jwtClaim?: number
|
|
361
|
-
claimName: string
|
|
362
|
-
isRequired?: boolean
|
|
363
|
-
}): string | undefined => {
|
|
364
|
-
if (jwtClaim) {
|
|
365
|
-
const claim = parseInt(jwtClaim.toString())
|
|
366
|
-
// change JWT seconds to millisecond for the date
|
|
367
|
-
return new Date(claim * (claim < 9999999999 ? 1000 : 1)).toISOString().replace(/\.000Z/, 'Z')
|
|
368
|
-
} else if (isRequired) {
|
|
369
|
-
throw Error(`JWT claim ${claimName} is required but was not present`)
|
|
370
|
-
}
|
|
371
|
-
return undefined
|
|
372
|
-
}
|
package/src/types/status-list.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { W3CVerifiableCredential } from './w3c-vc'
|
|
2
|
-
import { ProofFormat as VeramoProofFormat } from '@veramo/core'
|
|
1
|
+
import { type W3CVerifiableCredential } from './w3c-vc'
|
|
3
2
|
|
|
4
|
-
export enum StatusListType {
|
|
5
|
-
StatusList2021 = 'StatusList2021',
|
|
6
|
-
OAuthStatusList = 'OAuthStatusList',
|
|
7
|
-
}
|
|
8
3
|
export type CWT = string
|
|
9
4
|
|
|
10
5
|
export type StatusListCredential = W3CVerifiableCredential | CWT
|
|
11
|
-
|
|
12
|
-
export type ProofFormat = VeramoProofFormat | 'cbor'
|