Skip to content

Commit

Permalink
refactor: simplify equals method in protocol objects
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jun 30, 2023
1 parent b9ddedc commit 58824c0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 37 deletions.
16 changes: 6 additions & 10 deletions src/characters/pre-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,11 @@ export class PreDecrypter {
}

public equals(other: PreDecrypter): boolean {
return (
this.porter.porterUrl.toString() === other.porter.porterUrl.toString() &&
this.policyEncryptingKey.equals(other.policyEncryptingKey) &&
// TODO: Replace with `equals` after https://github.com/nucypher/nucypher-core/issues/56 is fixed
bytesEquals(
this.encryptedTreasureMap.toBytes(),
other.encryptedTreasureMap.toBytes()
) &&
this.publisherVerifyingKey.equals(other.publisherVerifyingKey)
);
return [
this.porter.porterUrl.toString() === other.porter.porterUrl.toString(),
this.policyEncryptingKey.equals(other.policyEncryptingKey),
this.encryptedTreasureMap.equals(other.encryptedTreasureMap),
this.publisherVerifyingKey.equals(other.publisherVerifyingKey),
].every(Boolean);
}
}
8 changes: 4 additions & 4 deletions src/conditions/condition-expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export class ConditionExpression {
}

public equals(other: ConditionExpression): boolean {
return (
this.version === other.version &&
objectEquals(this.condition.toObj(), other.condition.toObj())
);
return [
this.version === other.version,
objectEquals(this.condition.toObj(), other.condition.toObj()),
].every(Boolean);
}
}
11 changes: 5 additions & 6 deletions src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ export class DkgRitual {
}

public equals(other: DkgRitual): boolean {
return (
this.id === other.id &&
// TODO: Replace with `equals` after https://github.com/nucypher/nucypher-core/issues/56 is fixed
bytesEquals(this.dkgPublicKey.toBytes(), other.dkgPublicKey.toBytes()) &&
this.threshold === other.threshold
);
return [
this.id === other.id,
this.dkgPublicKey.equals(other.dkgPublicKey),
this.threshold === other.threshold,
].every(Boolean);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/sdk/strategy/cbd-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export class DeployedCbdStrategy {
}

public equals(other: DeployedCbdStrategy) {
return (
this.decrypter.equals(other.decrypter) &&
bytesEqual(this.dkgPublicKey.toBytes(), other.dkgPublicKey.toBytes())
);
return [
this.decrypter.equals(other.decrypter),
this.dkgPublicKey.equals(other.dkgPublicKey),
].every(Boolean);
}
}
26 changes: 13 additions & 13 deletions src/sdk/strategy/pre-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ export class PreStrategy {
}

public equals(other: PreStrategy) {
return (
this.cohort.equals(other.cohort) &&
// TODO: Replace with `equals` after https://github.com/nucypher/nucypher-core/issues/56 is fixed
return [
this.cohort.equals(other.cohort),
// TODO: Replace with `equals` after https://github.com/nucypher/rust-umbral/pull/125 is released
bytesEquals(
this.aliceSecretKey.toBEBytes(),
other.aliceSecretKey.toBEBytes()
) &&
),
bytesEquals(
this.bobSecretKey.toBEBytes(),
other.bobSecretKey.toBEBytes()
) &&
this.startDate.toString() === other.startDate.toString() &&
this.endDate.toString() === other.endDate.toString()
);
),
this.startDate.toString() === other.startDate.toString(),
this.endDate.toString() === other.endDate.toString(),
].every(Boolean);
}
}

Expand Down Expand Up @@ -203,10 +203,10 @@ export class DeployedPreStrategy {
}

public equals(other: DeployedPreStrategy) {
return (
this.cohort.equals(other.cohort) &&
this.decrypter.equals(other.decrypter) &&
this.policyKey.equals(other.policyKey)
);
return [
this.cohort.equals(other.cohort),
this.decrypter.equals(other.decrypter),
this.policyKey.equals(other.policyKey),
].every(Boolean);
}
}

0 comments on commit 58824c0

Please sign in to comment.