Skip to content

Commit 0e877b0

Browse files
committed
Pass edvClient list classes; use indexAllocator to cache shards.
1 parent d3089d8 commit 0e877b0

File tree

5 files changed

+30
-40
lines changed

5 files changed

+30
-40
lines changed

lib/CredentialStatusIssuer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {constants as rlConstants} from '@bedrock/vc-revocation-list-context';
99
import {constants as slConstants} from '@bedrock/vc-status-list-context';
1010

1111
export class CredentialStatusIssuer {
12-
constructor({config, documentLoader, documentStore} = {}) {
12+
constructor({config, documentLoader, edvClient} = {}) {
1313
assert.object(config, 'config');
1414
assert.func(documentLoader, 'documentLoader');
15-
assert.object(documentStore, 'documentStore');
15+
assert.object(edvClient, 'edvClient');
1616
this.config = config;
1717
this.documentLoader = documentLoader;
18-
this.documentStore = documentStore;
18+
this.edvClient = edvClient;
1919
this.credential = null;
2020
this.writers = [];
2121
this.statusResultMap = null;
@@ -26,7 +26,7 @@ export class CredentialStatusIssuer {
2626
this.credential = credential;
2727

2828
// see if config indicates a credential status should be set
29-
const {config, documentLoader, documentStore, writers} = this;
29+
const {config, documentLoader, edvClient, writers} = this;
3030
const {statusListOptions = []} = config;
3131

3232
if(statusListOptions.length === 0) {
@@ -68,10 +68,10 @@ export class CredentialStatusIssuer {
6868

6969
const {issuer, suite} = await getIssuerAndSuite({config, suiteName});
7070
writers.push(new CredentialStatusWriter({
71+
statusListConfig,
7172
documentLoader,
72-
documentStore,
73+
edvClient,
7374
issuer,
74-
statusListConfig,
7575
suite
7676
}));
7777
}

lib/CredentialStatusWriter.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,38 @@ writer.finish():
7878
*/
7979
export class CredentialStatusWriter {
8080
constructor({
81-
documentLoader, documentStore,
82-
issuer, statusListConfig, suite
81+
statusListConfig, documentLoader, edvClient,
82+
issuer, suite
8383
} = {}) {
84+
assert.object(statusListConfig, 'statusListConfig');
8485
assert.func(documentLoader, 'documentLoader');
85-
// FIXME: use `edvClient` directly
86-
assert.object(documentStore, 'documentStore');
86+
assert.object(edvClient, 'edvClient');
8787
assert.string(issuer, 'issuer');
88-
assert.object(statusListConfig, 'statusListConfig');
8988
assert.object(suite, 'suite');
9089
if(!issuer) {
9190
throw new TypeError('"issuer" must be a non-empty string.');
9291
}
92+
this.statusListConfig = statusListConfig;
9393
this.documentLoader = documentLoader;
94-
this.documentStore = documentStore;
94+
this.edvClient = edvClient;
9595
this.issuer = issuer;
96-
this.statusListConfig = statusListConfig;
9796
this.suite = suite;
9897
this.listShard = null;
9998
}
10099

101100
async write({credential} = {}) {
102101
assert.object(credential, 'credential');
103102

104-
const {documentStore: {serviceObjectId}, statusListConfig} = this;
105-
let shardQueue = SHARD_QUEUE_CACHE.get(serviceObjectId);
103+
const {edvClient, statusListConfig, listShard} = this;
104+
const {indexAllocator} = statusListConfig;
105+
let shardQueue = SHARD_QUEUE_CACHE.get(indexAllocator);
106106
if(!shardQueue) {
107107
shardQueue = [];
108-
SHARD_QUEUE_CACHE.set(serviceObjectId, shardQueue);
108+
SHARD_QUEUE_CACHE.set(indexAllocator, shardQueue);
109109
}
110110

111-
// get `edvClient` directly; do not use cache in `documentStore` to ensure
112-
// latest docs are used
113-
const {documentStore: {edvClient}} = this;
114-
115111
// 1. If an LS has been assigned to the writer instance (then a duplicate
116112
// error for the VC is being handled):
117-
const {listShard} = this;
118113
let existingCredentialStatus;
119114
if(listShard) {
120115
// FIXME: might be multiple `credentialStatus` results for a given
@@ -183,13 +178,11 @@ export class CredentialStatusWriter {
183178
if(shardQueue.length === 0) {
184179
// 2.1. Create a ListManager instance `listManager`.
185180
// 2.2. Call listManager.getShard() and store result in the instance.
186-
const {documentLoader, documentStore, issuer, suite} = this;
187-
// pass `edvClient` directly; do not use cache in `documentStore` to
188-
// ensure latest docs are used in list management
181+
const {documentLoader, edvClient, issuer, suite} = this;
189182
const listManager = new ListManager({
190183
statusListConfig,
191184
documentLoader,
192-
edvClient: documentStore.edvClient,
185+
edvClient,
193186
issuer,
194187
suite
195188
});
@@ -222,17 +215,13 @@ export class CredentialStatusWriter {
222215
}
223216

224217
async finish() {
225-
const {listShard} = this;
218+
const {edvClient, listShard} = this;
226219
if(!listShard) {
227220
// `finish` should never be called when no `listShard` is available
228221
throw new Error(
229222
'Invalid state error; "finish()" must only be called after "write()".');
230223
}
231224

232-
// get `edvClient` directly; do not use cache in `documentStore` to ensure
233-
// latest docs are used
234-
const {documentStore: {edvClient, serviceObjectId}} = this;
235-
236225
// 1. Increment instance's IAD's latest index value.
237226
const {
238227
indexAssignmentDoc,
@@ -282,10 +271,11 @@ export class CredentialStatusWriter {
282271
}
283272
} else {
284273
// 4. Otherwise, add LS back to in-memory set.
285-
let shardQueue = SHARD_QUEUE_CACHE.get(serviceObjectId);
274+
const {statusListConfig: {indexAllocator}} = this;
275+
let shardQueue = SHARD_QUEUE_CACHE.get(indexAllocator);
286276
if(!shardQueue) {
287277
shardQueue = [];
288-
SHARD_QUEUE_CACHE.set(serviceObjectId, shardQueue);
278+
SHARD_QUEUE_CACHE.set(indexAllocator, shardQueue);
289279
}
290280
shardQueue.push(listShard);
291281
}
@@ -297,7 +287,7 @@ export class CredentialStatusWriter {
297287
assert.object(statusMeta, 'statusMeta');
298288
// check every `statusMeta`'s `credentialStatus.id` for duplicates
299289
const counts = await Promise.all(statusMeta.map(
300-
async ({credentialStatus}) => this.documentStore.edvClient.count({
290+
async ({credentialStatus}) => this.edvClient.count({
301291
equals: {'meta.credentialStatus.id': credentialStatus.id}
302292
})));
303293
return counts.some(count => count !== 0);

lib/ListManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ export class ListManager {
224224

225225
// FIXME: pass in list source instance
226226
this.listSource = new ListSource({
227-
documentLoader, edvClient,
228-
issuer, statusListConfig, suite
227+
statusListConfig, documentLoader, edvClient,
228+
issuer, suite
229229
});
230230
}
231231

lib/ListSource.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ import {issue} from './helpers.js';
1515

1616
export class ListSource {
1717
constructor({
18-
documentLoader, edvClient,
19-
issuer, statusListConfig, suite
18+
statusListConfig, documentLoader, edvClient,
19+
issuer, suite
2020
} = {}) {
21+
assert.object(statusListConfig, 'statusListConfig');
2122
assert.func(documentLoader, 'documentLoader');
2223
assert.object(edvClient, 'edvClient');
23-
assert.object(statusListConfig, 'statusListConfig');
2424
assert.string(issuer, 'issuer');
2525
assert.object(suite, 'suite');
2626
if(!issuer) {
2727
throw new TypeError('"issuer" must be a non-empty string.');
2828
}
29+
this.statusListConfig = statusListConfig;
2930
this.documentLoader = documentLoader;
3031
this.edvClient = edvClient;
3132
this.issuer = issuer;
32-
this.statusListConfig = statusListConfig;
3333
this.suite = suite;
3434
}
3535

lib/issuer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function issue({credential, config} = {}) {
4747

4848
// initialize `CredentialStatusIssuer` for handling any credential statuses
4949
const credentialStatusIssuer = new CredentialStatusIssuer({
50-
config, documentLoader, documentStore
50+
config, documentLoader, edvClient
5151
});
5252
await credentialStatusIssuer.initialize({credential});
5353

0 commit comments

Comments
 (0)