@sphereon/ssi-sdk.vc-status-list 0.33.0 → 0.33.1-feature.vcdm2.4
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/functions.js +140 -168
- package/dist/functions.js.map +1 -1
- package/dist/impl/IStatusList.js +1 -2
- package/dist/impl/OAuthStatusList.js +131 -142
- package/dist/impl/OAuthStatusList.js.map +1 -1
- package/dist/impl/StatusList2021.js +157 -164
- package/dist/impl/StatusList2021.js.map +1 -1
- package/dist/impl/StatusListFactory.js +9 -12
- package/dist/impl/StatusListFactory.js.map +1 -1
- package/dist/impl/encoding/cbor.js +34 -51
- package/dist/impl/encoding/cbor.js.map +1 -1
- package/dist/impl/encoding/common.js +6 -14
- package/dist/impl/encoding/common.js.map +1 -1
- package/dist/impl/encoding/jwt.js +27 -40
- package/dist/impl/encoding/jwt.js.map +1 -1
- package/dist/index.js +2 -18
- package/dist/index.js.map +1 -1
- package/dist/types/index.js +4 -7
- package/dist/types/index.js.map +1 -1
- package/dist/utils.js +22 -31
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,173 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
indexingDirection: 'rightToLeft',
|
|
39
|
-
},
|
|
40
|
-
length,
|
|
41
|
-
type: ssi_types_1.StatusListType.StatusList2021,
|
|
42
|
-
proofFormat,
|
|
43
|
-
id,
|
|
44
|
-
correlationId,
|
|
45
|
-
issuer,
|
|
46
|
-
statuslistContentType: this.buildContentType(proofFormat),
|
|
47
|
-
};
|
|
48
|
-
});
|
|
1
|
+
import { CredentialMapper, StatusListType } from '@sphereon/ssi-types';
|
|
2
|
+
import { StatusList } from '@sphereon/vc-status-list';
|
|
3
|
+
import { Status2021, } from '../types';
|
|
4
|
+
import { assertValidProofType, getAssertedProperty, getAssertedValue, getAssertedValues } from '../utils';
|
|
5
|
+
export const DEFAULT_LIST_LENGTH = 250000;
|
|
6
|
+
export const DEFAULT_PROOF_FORMAT = 'lds';
|
|
7
|
+
export class StatusList2021Implementation {
|
|
8
|
+
async createNewStatusList(args, context) {
|
|
9
|
+
const length = args?.length ?? DEFAULT_LIST_LENGTH;
|
|
10
|
+
const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT;
|
|
11
|
+
assertValidProofType(StatusListType.StatusList2021, proofFormat);
|
|
12
|
+
const veramoProofFormat = proofFormat;
|
|
13
|
+
const { issuer, id } = args;
|
|
14
|
+
const correlationId = getAssertedValue('correlationId', args.correlationId);
|
|
15
|
+
const list = new StatusList({ length });
|
|
16
|
+
const encodedList = await list.encode();
|
|
17
|
+
const statusPurpose = 'revocation';
|
|
18
|
+
const statusListCredential = await this.createVerifiableCredential({
|
|
19
|
+
...args,
|
|
20
|
+
encodedList,
|
|
21
|
+
proofFormat: veramoProofFormat,
|
|
22
|
+
}, context);
|
|
23
|
+
return {
|
|
24
|
+
encodedList,
|
|
25
|
+
statusListCredential: statusListCredential,
|
|
26
|
+
statusList2021: {
|
|
27
|
+
statusPurpose,
|
|
28
|
+
indexingDirection: 'rightToLeft',
|
|
29
|
+
},
|
|
30
|
+
length,
|
|
31
|
+
type: StatusListType.StatusList2021,
|
|
32
|
+
proofFormat,
|
|
33
|
+
id,
|
|
34
|
+
correlationId,
|
|
35
|
+
issuer,
|
|
36
|
+
statuslistContentType: this.buildContentType(proofFormat),
|
|
37
|
+
};
|
|
49
38
|
}
|
|
50
|
-
updateStatusListIndex(args, context) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
39
|
+
async updateStatusListIndex(args, context) {
|
|
40
|
+
const credential = args.statusListCredential;
|
|
41
|
+
const uniform = CredentialMapper.toUniformCredential(credential);
|
|
42
|
+
const { issuer, credentialSubject } = uniform;
|
|
43
|
+
const id = getAssertedValue('id', uniform.id);
|
|
44
|
+
const origEncodedList = getAssertedProperty('encodedList', credentialSubject);
|
|
45
|
+
const index = typeof args.statusListIndex === 'number' ? args.statusListIndex : parseInt(args.statusListIndex);
|
|
46
|
+
const statusList = await StatusList.decode({ encodedList: origEncodedList });
|
|
47
|
+
statusList.setStatus(index, args.value != 0);
|
|
48
|
+
const encodedList = await statusList.encode();
|
|
49
|
+
const proofFormat = CredentialMapper.detectDocumentType(credential) === 0 /* DocumentFormat.JWT */ ? 'jwt' : 'lds';
|
|
50
|
+
const updatedCredential = await this.createVerifiableCredential({
|
|
51
|
+
...args,
|
|
52
|
+
id,
|
|
53
|
+
issuer,
|
|
54
|
+
encodedList,
|
|
55
|
+
proofFormat: proofFormat,
|
|
56
|
+
}, context);
|
|
57
|
+
return {
|
|
58
|
+
statusListCredential: updatedCredential,
|
|
59
|
+
encodedList,
|
|
60
|
+
statusList2021: {
|
|
61
|
+
...('statusPurpose' in credentialSubject ? { statusPurpose: credentialSubject.statusPurpose } : {}),
|
|
62
|
+
indexingDirection: 'rightToLeft',
|
|
63
|
+
},
|
|
64
|
+
length: statusList.length - 1,
|
|
65
|
+
type: StatusListType.StatusList2021,
|
|
66
|
+
proofFormat: proofFormat,
|
|
67
|
+
id,
|
|
68
|
+
issuer,
|
|
69
|
+
statuslistContentType: this.buildContentType(proofFormat),
|
|
70
|
+
};
|
|
77
71
|
}
|
|
78
|
-
updateStatusListFromEncodedList(args, context) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
statuslistContentType: this.buildContentType(proofFormat),
|
|
112
|
-
};
|
|
113
|
-
});
|
|
72
|
+
async updateStatusListFromEncodedList(args, context) {
|
|
73
|
+
if (!args.statusList2021) {
|
|
74
|
+
throw new Error('statusList2021 options required for type StatusList2021');
|
|
75
|
+
}
|
|
76
|
+
const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT;
|
|
77
|
+
assertValidProofType(StatusListType.StatusList2021, proofFormat);
|
|
78
|
+
const veramoProofFormat = proofFormat;
|
|
79
|
+
const { issuer, id } = getAssertedValues(args);
|
|
80
|
+
const statusList = await StatusList.decode({ encodedList: args.encodedList });
|
|
81
|
+
const index = typeof args.statusListIndex === 'number' ? args.statusListIndex : parseInt(args.statusListIndex);
|
|
82
|
+
statusList.setStatus(index, args.value);
|
|
83
|
+
const newEncodedList = await statusList.encode();
|
|
84
|
+
const credential = await this.createVerifiableCredential({
|
|
85
|
+
id,
|
|
86
|
+
issuer,
|
|
87
|
+
encodedList: newEncodedList,
|
|
88
|
+
proofFormat: veramoProofFormat,
|
|
89
|
+
keyRef: args.keyRef,
|
|
90
|
+
}, context);
|
|
91
|
+
return {
|
|
92
|
+
type: StatusListType.StatusList2021,
|
|
93
|
+
statusListCredential: credential,
|
|
94
|
+
encodedList: newEncodedList,
|
|
95
|
+
statusList2021: {
|
|
96
|
+
statusPurpose: args.statusList2021.statusPurpose,
|
|
97
|
+
indexingDirection: 'rightToLeft',
|
|
98
|
+
},
|
|
99
|
+
length: statusList.length,
|
|
100
|
+
proofFormat: args.proofFormat ?? 'lds',
|
|
101
|
+
id: id,
|
|
102
|
+
issuer: issuer,
|
|
103
|
+
statuslistContentType: this.buildContentType(proofFormat),
|
|
104
|
+
};
|
|
114
105
|
}
|
|
115
|
-
checkStatusIndex(args) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return status ? types_1.Status2021.Invalid : types_1.Status2021.Valid;
|
|
123
|
-
});
|
|
106
|
+
async checkStatusIndex(args) {
|
|
107
|
+
const uniform = CredentialMapper.toUniformCredential(args.statusListCredential);
|
|
108
|
+
const { credentialSubject } = uniform;
|
|
109
|
+
const encodedList = getAssertedProperty('encodedList', credentialSubject);
|
|
110
|
+
const statusList = await StatusList.decode({ encodedList });
|
|
111
|
+
const status = statusList.getStatus(typeof args.statusListIndex === 'number' ? args.statusListIndex : parseInt(args.statusListIndex));
|
|
112
|
+
return status ? Status2021.Invalid : Status2021.Valid;
|
|
124
113
|
}
|
|
125
|
-
toStatusListDetails(args) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
114
|
+
async toStatusListDetails(args) {
|
|
115
|
+
const { statusListPayload } = args;
|
|
116
|
+
const uniform = CredentialMapper.toUniformCredential(statusListPayload);
|
|
117
|
+
const { issuer, credentialSubject } = uniform;
|
|
118
|
+
const id = getAssertedValue('id', uniform.id);
|
|
119
|
+
const encodedList = getAssertedProperty('encodedList', credentialSubject);
|
|
120
|
+
const proofFormat = CredentialMapper.detectDocumentType(statusListPayload) === 0 /* DocumentFormat.JWT */ ? 'jwt' : 'lds';
|
|
121
|
+
const statusPurpose = getAssertedProperty('statusPurpose', credentialSubject);
|
|
122
|
+
const list = await StatusList.decode({ encodedList });
|
|
123
|
+
return {
|
|
124
|
+
id,
|
|
125
|
+
encodedList,
|
|
126
|
+
issuer,
|
|
127
|
+
type: StatusListType.StatusList2021,
|
|
128
|
+
proofFormat,
|
|
129
|
+
length: list.length,
|
|
130
|
+
statusListCredential: statusListPayload,
|
|
131
|
+
statuslistContentType: this.buildContentType(proofFormat),
|
|
132
|
+
statusList2021: {
|
|
133
|
+
indexingDirection: 'rightToLeft',
|
|
134
|
+
statusPurpose,
|
|
135
|
+
},
|
|
136
|
+
...(args.correlationId && { correlationId: args.correlationId }),
|
|
137
|
+
...(args.driverType && { driverType: args.driverType }),
|
|
138
|
+
};
|
|
142
139
|
}
|
|
143
|
-
createVerifiableCredential(args, context) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
140
|
+
async createVerifiableCredential(args, context) {
|
|
141
|
+
const identifier = await context.agent.identifierManagedGet({
|
|
142
|
+
identifier: typeof args.issuer === 'string' ? args.issuer : args.issuer.id,
|
|
143
|
+
vmRelationship: 'assertionMethod',
|
|
144
|
+
offlineWhenNoDIDRegistered: true,
|
|
145
|
+
});
|
|
146
|
+
const credential = {
|
|
147
|
+
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/vc/status-list/2021/v1'],
|
|
148
|
+
id: args.id,
|
|
149
|
+
issuer: args.issuer,
|
|
150
|
+
type: ['VerifiableCredential', 'StatusList2021Credential'],
|
|
151
|
+
credentialSubject: {
|
|
153
152
|
id: args.id,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
credential,
|
|
165
|
-
keyRef: (_a = args.keyRef) !== null && _a !== void 0 ? _a : identifier.kmsKeyRef,
|
|
166
|
-
proofFormat: args.proofFormat,
|
|
167
|
-
fetchRemoteContexts: true,
|
|
168
|
-
});
|
|
169
|
-
return ssi_types_1.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
|
|
153
|
+
type: 'StatusList2021',
|
|
154
|
+
statusPurpose: 'revocation',
|
|
155
|
+
encodedList: args.encodedList,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const verifiableCredential = await context.agent.createVerifiableCredential({
|
|
159
|
+
credential,
|
|
160
|
+
keyRef: args.keyRef ?? identifier.kmsKeyRef,
|
|
161
|
+
proofFormat: args.proofFormat,
|
|
162
|
+
fetchRemoteContexts: true,
|
|
170
163
|
});
|
|
164
|
+
return CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
|
|
171
165
|
}
|
|
172
166
|
buildContentType(proofFormat) {
|
|
173
167
|
switch (proofFormat) {
|
|
@@ -182,5 +176,4 @@ class StatusList2021Implementation {
|
|
|
182
176
|
}
|
|
183
177
|
}
|
|
184
178
|
}
|
|
185
|
-
exports.StatusList2021Implementation = StatusList2021Implementation;
|
|
186
179
|
//# sourceMappingURL=StatusList2021.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatusList2021.js","sourceRoot":"","sources":["../../src/impl/StatusList2021.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StatusList2021.js","sourceRoot":"","sources":["../../src/impl/StatusList2021.ts"],"names":[],"mappings":"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WAAW,oBAAoB,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const ssi_types_1 = require("@sphereon/ssi-types");
|
|
8
|
-
class StatusListFactory {
|
|
1
|
+
import { StatusList2021Implementation } from './StatusList2021';
|
|
2
|
+
import { OAuthStatusListImplementation } from './OAuthStatusList';
|
|
3
|
+
import { StatusListType } from '@sphereon/ssi-types';
|
|
4
|
+
export class StatusListFactory {
|
|
5
|
+
static instance;
|
|
6
|
+
implementations;
|
|
9
7
|
constructor() {
|
|
10
8
|
this.implementations = new Map();
|
|
11
|
-
this.implementations.set(
|
|
12
|
-
this.implementations.set(
|
|
9
|
+
this.implementations.set(StatusListType.StatusList2021, new StatusList2021Implementation());
|
|
10
|
+
this.implementations.set(StatusListType.OAuthStatusList, new OAuthStatusListImplementation());
|
|
13
11
|
}
|
|
14
12
|
static getInstance() {
|
|
15
13
|
if (!StatusListFactory.instance) {
|
|
@@ -25,8 +23,7 @@ class StatusListFactory {
|
|
|
25
23
|
return statusList;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
function getStatusListImplementation(type) {
|
|
26
|
+
export function getStatusListImplementation(type) {
|
|
30
27
|
return StatusListFactory.getInstance().getByType(type);
|
|
31
28
|
}
|
|
32
29
|
//# sourceMappingURL=StatusListFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatusListFactory.js","sourceRoot":"","sources":["../../src/impl/StatusListFactory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StatusListFactory.js","sourceRoot":"","sources":["../../src/impl/StatusListFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAC,QAAQ,CAAmB;IAClC,eAAe,CAAkC;IAEzD;QACE,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAA;QAChC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,4BAA4B,EAAE,CAAC,CAAA;QAC3F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,cAAc,CAAC,eAAe,EAAE,IAAI,6BAA6B,EAAE,CAAC,CAAA;IAC/F,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC;YAChC,iBAAiB,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;QACtD,CAAC;QACD,OAAO,iBAAiB,CAAC,QAAQ,CAAA;IACnC,CAAC;IAEM,SAAS,CAAC,IAAoB;QACnC,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,iDAAiD,IAAI,EAAE,CAAC,CAAA;QAC1E,CAAC;QACD,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CAAC,IAAoB;IAC9D,OAAO,iBAAiB,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;AACxD,CAAC"}
|
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.decodeStatusListCWT = exports.createSignedCbor = void 0;
|
|
16
|
-
const jwt_status_list_1 = require("@sd-jwt/jwt-status-list");
|
|
17
|
-
const pako_1 = require("pako");
|
|
18
|
-
const kmp_cbor_1 = require("@sphereon/kmp-cbor");
|
|
19
|
-
const base64url_1 = __importDefault(require("base64url"));
|
|
20
|
-
const common_1 = require("./common");
|
|
21
|
-
const cbor = kmp_cbor_1.com.sphereon.cbor;
|
|
22
|
-
const kmp = kmp_cbor_1.com.sphereon.kmp;
|
|
23
|
-
const decompressRawStatusList = jwt_status_list_1.StatusList.decodeStatusList.bind(jwt_status_list_1.StatusList);
|
|
1
|
+
import { StatusList } from '@sd-jwt/jwt-status-list';
|
|
2
|
+
import { deflate, inflate } from 'pako';
|
|
3
|
+
import { com, kotlin } from '@sphereon/kmp-cbor';
|
|
4
|
+
import base64url from 'base64url';
|
|
5
|
+
import { resolveIdentifier } from './common';
|
|
6
|
+
const cbor = com.sphereon.cbor;
|
|
7
|
+
const kmp = com.sphereon.kmp;
|
|
8
|
+
const decompressRawStatusList = StatusList.decodeStatusList.bind(StatusList);
|
|
24
9
|
const CWT_CLAIMS = {
|
|
25
10
|
SUBJECT: 2,
|
|
26
11
|
ISSUER: 1,
|
|
@@ -29,42 +14,41 @@ const CWT_CLAIMS = {
|
|
|
29
14
|
TIME_TO_LIVE: 65534,
|
|
30
15
|
STATUS_LIST: 65533,
|
|
31
16
|
};
|
|
32
|
-
const createSignedCbor = (context, statusList, issuerString, id, expiresAt, keyRef) =>
|
|
33
|
-
const identifier =
|
|
17
|
+
export const createSignedCbor = async (context, statusList, issuerString, id, expiresAt, keyRef) => {
|
|
18
|
+
const identifier = await resolveIdentifier(context, issuerString, keyRef);
|
|
34
19
|
const encodeStatusList = statusList.encodeStatusList();
|
|
35
|
-
const compressedList =
|
|
20
|
+
const compressedList = deflate(encodeStatusList, { level: 9 });
|
|
36
21
|
const compressedBytes = new Int8Array(compressedList);
|
|
37
|
-
const statusListMap = new cbor.CborMap(
|
|
22
|
+
const statusListMap = new cbor.CborMap(kotlin.collections.KtMutableMap.fromJsMap(new Map([
|
|
38
23
|
[new cbor.CborString('bits'), new cbor.CborUInt(kmp.LongKMP.fromNumber(statusList.getBitsPerStatus()))],
|
|
39
24
|
[new cbor.CborString('lst'), new cbor.CborByteString(compressedBytes)],
|
|
40
25
|
])));
|
|
41
|
-
const protectedHeader = new cbor.CborMap(
|
|
26
|
+
const protectedHeader = new cbor.CborMap(kotlin.collections.KtMutableMap.fromJsMap(new Map([[new cbor.CborUInt(kmp.LongKMP.fromNumber(16)), new cbor.CborString('statuslist+cwt')]])));
|
|
42
27
|
const protectedHeaderEncoded = cbor.Cbor.encode(protectedHeader);
|
|
43
28
|
const claimsMap = buildClaimsMap(id, issuerString, statusListMap, expiresAt);
|
|
44
29
|
const claimsEncoded = cbor.Cbor.encode(claimsMap);
|
|
45
|
-
const signedCWT =
|
|
30
|
+
const signedCWT = await context.agent.keyManagerSign({
|
|
46
31
|
keyRef: identifier.kmsKeyRef,
|
|
47
|
-
data:
|
|
32
|
+
data: base64url.encode(Buffer.from(claimsEncoded)), // TODO test on RN
|
|
48
33
|
encoding: undefined,
|
|
49
34
|
});
|
|
50
35
|
const protectedHeaderEncodedInt8 = new Int8Array(protectedHeaderEncoded);
|
|
51
36
|
const claimsEncodedInt8 = new Int8Array(claimsEncoded);
|
|
52
|
-
const signatureBytes =
|
|
37
|
+
const signatureBytes = base64url.decode(signedCWT);
|
|
53
38
|
const signatureInt8 = new Int8Array(Buffer.from(signatureBytes));
|
|
54
39
|
const cwtArrayElements = [
|
|
55
40
|
new cbor.CborByteString(protectedHeaderEncodedInt8),
|
|
56
41
|
new cbor.CborByteString(claimsEncodedInt8),
|
|
57
42
|
new cbor.CborByteString(signatureInt8),
|
|
58
43
|
];
|
|
59
|
-
const cwtArray = new cbor.CborArray(
|
|
44
|
+
const cwtArray = new cbor.CborArray(kotlin.collections.KtMutableList.fromJsArray(cwtArrayElements));
|
|
60
45
|
const cwtEncoded = cbor.Cbor.encode(cwtArray);
|
|
61
46
|
const cwtBuffer = Buffer.from(cwtEncoded);
|
|
62
47
|
return {
|
|
63
|
-
statusListCredential:
|
|
64
|
-
encodedList:
|
|
48
|
+
statusListCredential: base64url.encode(cwtBuffer),
|
|
49
|
+
encodedList: base64url.encode(compressedList), // JS in @sd-jwt/jwt-status-list drops it in like this, so keep the same method
|
|
65
50
|
};
|
|
66
|
-
}
|
|
67
|
-
exports.createSignedCbor = createSignedCbor;
|
|
51
|
+
};
|
|
68
52
|
function buildClaimsMap(id, issuerString, statusListMap, expiresAt) {
|
|
69
53
|
const ttl = 65535; // FIXME figure out what value should be / come from and what the difference is with exp
|
|
70
54
|
const claimsEntries = [
|
|
@@ -88,7 +72,7 @@ function buildClaimsMap(id, issuerString, statusListMap, expiresAt) {
|
|
|
88
72
|
]);
|
|
89
73
|
}
|
|
90
74
|
claimsEntries.push([new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.STATUS_LIST)), statusListMap]);
|
|
91
|
-
const claimsMap = new cbor.CborMap(
|
|
75
|
+
const claimsMap = new cbor.CborMap(kotlin.collections.KtMutableMap.fromJsMap(new Map(claimsEntries)));
|
|
92
76
|
return claimsMap;
|
|
93
77
|
}
|
|
94
78
|
const getCborValueFromMap = (map, key) => {
|
|
@@ -99,34 +83,34 @@ const getCborValueFromMap = (map, key) => {
|
|
|
99
83
|
return value;
|
|
100
84
|
};
|
|
101
85
|
const getCborOptionalValueFromMap = (map, key) => {
|
|
102
|
-
const value = map.get(new
|
|
86
|
+
const value = map.get(new com.sphereon.cbor.CborUInt(kmp.LongKMP.fromNumber(key)));
|
|
103
87
|
if (!value) {
|
|
104
88
|
return undefined;
|
|
105
89
|
}
|
|
106
90
|
return value.value;
|
|
107
91
|
};
|
|
108
|
-
const decodeStatusListCWT = (cwt) => {
|
|
109
|
-
const encodedCbor =
|
|
92
|
+
export const decodeStatusListCWT = (cwt) => {
|
|
93
|
+
const encodedCbor = base64url.toBuffer(cwt);
|
|
110
94
|
const encodedCborArray = new Int8Array(encodedCbor);
|
|
111
|
-
const decodedCbor =
|
|
112
|
-
if (!(decodedCbor instanceof
|
|
95
|
+
const decodedCbor = com.sphereon.cbor.Cbor.decode(encodedCborArray);
|
|
96
|
+
if (!(decodedCbor instanceof com.sphereon.cbor.CborArray)) {
|
|
113
97
|
throw new Error('Invalid CWT format: Expected a CBOR array');
|
|
114
98
|
}
|
|
115
99
|
const [, payload] = decodedCbor.value.asJsArrayView();
|
|
116
|
-
if (!(payload instanceof
|
|
100
|
+
if (!(payload instanceof com.sphereon.cbor.CborByteString)) {
|
|
117
101
|
throw new Error('Invalid payload format: Expected a CBOR ByteString');
|
|
118
102
|
}
|
|
119
|
-
const claims =
|
|
120
|
-
if (!(claims instanceof
|
|
103
|
+
const claims = com.sphereon.cbor.Cbor.decode(payload.value);
|
|
104
|
+
if (!(claims instanceof com.sphereon.cbor.CborMap)) {
|
|
121
105
|
throw new Error('Invalid claims format: Expected a CBOR map');
|
|
122
106
|
}
|
|
123
107
|
const claimsMap = claims.value.asJsMapView();
|
|
124
|
-
const statusListMap = claimsMap.get(new
|
|
125
|
-
const bits = Number(statusListMap.get(new
|
|
126
|
-
const decoded = new Uint8Array(statusListMap.get(new
|
|
127
|
-
const uint8Array =
|
|
108
|
+
const statusListMap = claimsMap.get(new com.sphereon.cbor.CborUInt(kmp.LongKMP.fromNumber(65533))).value.asJsMapView();
|
|
109
|
+
const bits = Number(statusListMap.get(new com.sphereon.cbor.CborString('bits')).value);
|
|
110
|
+
const decoded = new Uint8Array(statusListMap.get(new com.sphereon.cbor.CborString('lst')).value);
|
|
111
|
+
const uint8Array = inflate(decoded);
|
|
128
112
|
const rawStatusList = decompressRawStatusList(uint8Array, bits);
|
|
129
|
-
const statusList = new
|
|
113
|
+
const statusList = new StatusList(rawStatusList, bits);
|
|
130
114
|
return {
|
|
131
115
|
issuer: getCborValueFromMap(claimsMap, CWT_CLAIMS.ISSUER),
|
|
132
116
|
id: getCborValueFromMap(claimsMap, CWT_CLAIMS.SUBJECT),
|
|
@@ -136,5 +120,4 @@ const decodeStatusListCWT = (cwt) => {
|
|
|
136
120
|
ttl: getCborOptionalValueFromMap(claimsMap, CWT_CLAIMS.TIME_TO_LIVE),
|
|
137
121
|
};
|
|
138
122
|
};
|
|
139
|
-
exports.decodeStatusListCWT = decodeStatusListCWT;
|
|
140
123
|
//# sourceMappingURL=cbor.js.map
|