Skip to content

Commit

Permalink
Add parameter password to DIDStore.synchronize()
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-yu-2013 authored and jingyu committed Oct 10, 2023
1 parent fe1d788 commit 96b1498
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/didstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,13 @@ export class DIDStore {
this.cache.invalidateAll();
}

public async synchronize(handle: ConflictHandle = null) {
/**
* Synchronize did and credentials with chain.
* @param handle Conflict handler.
* @param password Store password for all credentials.
* MUST contain password or not for all credentials at the same time.
*/
public async synchronize(handle: ConflictHandle = null, password?: string) {
if (handle == null)
handle = DefaultConflictHandle.getInstance();

Expand Down Expand Up @@ -1108,7 +1114,7 @@ export class DIDStore {

let vcIds = await this.storage.listCredentials(did);
for (let vcId of vcIds) {
let localVc = await this.loadCredential(vcId);
let localVc = await this.loadCredential(vcId, password);

let resolvedVc = await VerifiableCredential.resolve(vcId, localVc.getIssuer());
if (resolvedVc == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5
6
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5
6
31 changes: 29 additions & 2 deletions tests/src/didstore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,34 @@ describe("DIDStore Tests", ()=>{
await expect(await store.containsCredential(user.getSubject().toString() + "#passport")).toBeFalsy();
});

test("testSynchronizeStore", async ()=> {
test("testDIDStoreSynchronize", async ()=> {
let identity = await testData.getRootIdentity();
let valid : boolean;

const createCredential = async (doc) => {
let issuer = await Issuer.create(doc);

let props = {
name: "Testing Issuer",
nationality: "Singapore",
email: "issuer@example.com"
};

let cb = issuer.issueFor(doc.getSubject());
let vc = await cb.id("#myCredential")
.typeWithContext("SelfProclaimedCredential", "https://ns.elastos.org/credentials/v1")
.typeWithContext("ProfileCredential", "https://ns.elastos.org/credentials/profile/v1")
.typeWithContext("EmailCredential", "https://ns.elastos.org/credentials/email/v1")
.properties(props)
.seal(TestConfig.storePass);

const vcId = new DIDURL("#myCredential", doc.getSubject());

const store = await testData.getStore();
await store.storeCredential(vc, TestConfig.storePass);
await store.loadCredential(vcId, TestConfig.storePass);
}

for (let i = 0; i < 5; i++) {
let alias = "my did " + i;
let doc = await identity.newDid(TestConfig.storePass);
Expand All @@ -445,6 +470,8 @@ describe("DIDStore Tests", ()=>{

await doc.publish(TestConfig.storePass);

await createCredential(doc);

resolved = await doc.getSubject().resolve();
expect(resolved).not.toBeNull();
}
Expand All @@ -459,7 +486,7 @@ describe("DIDStore Tests", ()=>{
let empty: DID[] = Array.from(await store.listDids());
expect(empty.length).toBe(0);

await store.synchronize();
await store.synchronize(null, TestConfig.storePass);
let syncedDids: DID[] = Array.from(await store.listDids());
syncedDids.sort((a,b) => a.compareTo(b));

Expand Down
2 changes: 1 addition & 1 deletion tests/test-report.html

Large diffs are not rendered by default.

0 comments on commit 96b1498

Please sign in to comment.