Skip to content

Commit 23cd52e

Browse files
committed
do not attempt to infer the author automatically for CausalArray derivatives, better error logging
1 parent 56fe3aa commit 23cd52e

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

src/data/collections/causal/CausalArray.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
255255

256256
if (author !== undefined) {
257257
insertOp.setAuthor(author);
258-
} else {
258+
} else if (this.getClassName() === CausalArray.className) {
259259
CausalCollectionOp.setSingleAuthorIfNecessary(insertOp);
260260
}
261261

@@ -389,7 +389,7 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
389389

390390
if (author !== undefined) {
391391
deleteOp.setAuthor(author);
392-
} else {
392+
} else if (this.getClassName() === CausalArray.className) {
393393
CausalCollectionOp.setSingleAuthorIfNecessary(deleteOp);
394394
}
395395

@@ -593,8 +593,6 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
593593

594594
shouldAcceptMutationOp(op: MutationOp, opReferences: Map<Hash, HashedObject>): boolean {
595595

596-
console.log('VALIDATING....')
597-
598596
if (!super.shouldAcceptMutationOp(op, opReferences)) {
599597
return false;
600598
}
@@ -612,26 +610,17 @@ class CausalArray<T> extends BaseCausalCollection<T> implements CausalCollection
612610
this.createDeleteAuthorizerByHash(
613611
HashedObject.hashElement(op.getInsertOp().element), author);
614612

615-
console.log('verifying mutation op for ' + this.hash());
616-
console.log('auth', auth);
617-
618613
const usedKeys = new Set<string>();
619614

620615
if (!auth.verify(op, usedKeys)) {
621-
console.log('verification failed')
616+
HashedObject.validationLog.warning('Could not verify authorization for op ' + op.hash() + ', a ' + op.getClassName() + ' being applied to ' + this.hash() + ', a ' + this.getClassName());
622617
return false;
623618
}
624619

625-
console.log('verification OK')
626-
627620
if (!Verification.checkKeys(usedKeys, op)) {
628-
console.log('usedKeys', Array.from(usedKeys));
629-
console.log('op', Array.from(op.getCausalOps().keys()))
621+
HashedObject.validationLog.warning('Authorization key checking step failed for op ' + op.hash() + ', a ' + op.getClassName() + ' being applied to ' + this.hash() + ', a ' + this.getClassName());
630622
return false;
631623
}
632-
633-
console.log('keys OK: ', usedKeys);
634-
635624
}
636625

637626
return true;

src/data/collections/causal/CausalSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class CausalSet<T> extends BaseCausalCollection<T> implements CausalCollection<T
334334
} else {
335335
return false;
336336
}
337-
337+
338338
}
339339

340340
verifyMembershipAttestationForOp(elmt: T, op: MutationOp, usedKeys: Set<string>): boolean {

src/data/identity/Identity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Identity extends HashedObject {
8686
getKeyPair(): RSAKeyPair {
8787

8888
if (!this.hasKeyPair()) {
89-
throw new Error('Trying to get key pair, but it is missing from Identity.');
89+
throw new Error('Trying to get key pair, but it is missing from Identity ' + this.hash() + ' (info=' + JSON.stringify(this.info) + ').');
9090
}
9191

9292
return this._keyPair as RSAKeyPair;

0 commit comments

Comments
 (0)