Skip to content

Commit

Permalink
Rename to authentication, endorsements, receipts
Browse files Browse the repository at this point in the history
controller signatures --> authentication
witness receipts --> endorsements
other receipts --> receipts
  • Loading branch information
stevetodd committed Apr 28, 2021
1 parent d875f00 commit a8ccd79
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ public byte[] serialize(AttachmentEvent event) {
var mapper = this.mapper(StandardFormats.JSON);
var rootNode = mapper.createObjectNode();

var vrc = event.signatures().isEmpty()
&& event.receipts().isEmpty()
&& event.otherReceipts().size() == 1;
var vrc = event.authentication().isEmpty()
&& event.endorsements().isEmpty()
&& event.receipts().size() == 1;

rootNode.put(VERSION.label(), version(Version.CURRENT, StandardFormats.JSON, 0));
rootNode.put(IDENTIFIER.label(), qb64(event.coordinates().identifier()));
Expand All @@ -294,7 +294,7 @@ public byte[] serialize(AttachmentEvent event) {
rootNode.put(EVENT_DIGEST.label(), qb64(event.coordinates().digest()));

if (vrc) {
var vrcSigs = event.otherReceipts().entrySet().stream().findFirst().get();
var vrcSigs = event.receipts().entrySet().stream().findFirst().get();
var establishmentEvent = vrcSigs.getKey();
var anchorNode = mapper.createObjectNode();
anchorNode.put(IDENTIFIER.label(), qb64(establishmentEvent.identifier()));
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/foundation/identity/keri/KeyEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public void process(KeyEvent event) throws KeyEventProcessingException {

var newState = KeyStateProcessor.apply(previousState, event);

var validControllerSignatures = this.verifyControllerSignatures(newState, event, event.signatures());
var validWitnessReceipts = this.verifyWitnessReceipts(newState, event, event.receipts());
var validOtherReceipts = this.verifyOtherReceipts(event, event.otherReceipts());
var validControllerSignatures = this.verifyAuthentication(newState, event, event.authentication());
var validWitnessReceipts = this.verifyEndorsements(newState, event, event.endorsements());
var validOtherReceipts = this.verifyReceipts(event, event.receipts());

// TODO remove invalid signatures before appending
this.keyEventStore.append(event);
Expand All @@ -74,14 +74,14 @@ public void process(AttachmentEvent attachmentEvent) throws AttachmentEventProce
var state = this.keyEventStore.getKeyState(attachmentEvent.coordinates())
.orElseThrow(() -> new MissingReferencedEventException(attachmentEvent, attachmentEvent.coordinates()));

var validControllerSignatures = this.verifyControllerSignatures(state, event, event.signatures());
var validWitnessReceipts = this.verifyWitnessReceipts(state, event, event.receipts());
var validOtherReceipts = this.verifyOtherReceipts(event, event.otherReceipts());
var validControllerSignatures = this.verifyAuthentication(state, event, event.authentication());
var validWitnessReceipts = this.verifyEndorsements(state, event, event.endorsements());
var validOtherReceipts = this.verifyReceipts(event, event.receipts());

this.keyEventStore.append(attachmentEvent);
}

private HashMap<Integer, Signature> verifyControllerSignatures(KeyState state, KeyEvent event, Map<Integer, Signature> signatures) {
private HashMap<Integer, Signature> verifyAuthentication(KeyState state, KeyEvent event, Map<Integer, Signature> signatures) {
var kee = state.lastEstablishmentEvent();

var verifiedSignatures = new HashMap<Integer, Signature>();
Expand Down Expand Up @@ -115,13 +115,13 @@ private HashMap<Integer, Signature> verifyControllerSignatures(KeyState state, K
return verifiedSignatures;
}

private Map<Integer, Signature> verifyWitnessReceipts(KeyState state, KeyEvent event, Map<Integer, Signature> receipts) {
private Map<Integer, Signature> verifyEndorsements(KeyState state, KeyEvent event, Map<Integer, Signature> receipts) {
var validReceipts = new HashMap<Integer, Signature>();
for (var kv : receipts.entrySet()) {
var witnessIndex = kv.getKey();

if (witnessIndex < 0 || witnessIndex >= state.witnesses().size()) {
LOGGER.debug("witness index out of range: {}", witnessIndex);
LOGGER.debug("endorsement index out of range: {}", witnessIndex);
continue;
}

Expand All @@ -143,7 +143,7 @@ private Map<Integer, Signature> verifyWitnessReceipts(KeyState state, KeyEvent e
return validReceipts;
}

private Map<KeyEventCoordinates, Map<Integer, Signature>> verifyOtherReceipts(KeyEvent event, Map<KeyEventCoordinates,
private Map<KeyEventCoordinates, Map<Integer, Signature>> verifyReceipts(KeyEvent event, Map<KeyEventCoordinates,
Map<Integer, Signature>> otherReceipts) {
var verified = new HashMap<KeyEventCoordinates, Map<Integer, Signature>>();
for (var kv : otherReceipts.entrySet()) {
Expand All @@ -154,7 +154,7 @@ private Map<KeyEventCoordinates, Map<Integer, Signature>> verifyOtherReceipts(Ke
continue;
}

var verifiedSignatures = this.verifyControllerSignatures(keyState.get(), event, kv.getValue());
var verifiedSignatures = this.verifyAuthentication(keyState.get(), event, kv.getValue());
verified.put(kv.getKey(), verifiedSignatures);
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/foundation/identity/keri/KeyEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static String toString(KeyEvent e) {
sb.append("d: ").append(add.coordinates().digest()).append("\n");
}

sb.append("--- CONTROLLER SIGNATURES").append("\n");
e.signatures()
sb.append("--- AUTHENTICATION").append("\n");
e.authentication()
.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
Expand All @@ -76,8 +76,8 @@ public static String toString(KeyEvent e) {
sb.append("\n");
});

sb.append("--- WITNESS RECEIPTS").append("\n");
e.receipts()
sb.append("--- ENDORSEMENTS").append("\n");
e.endorsements()
.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
Expand All @@ -88,8 +88,8 @@ public static String toString(KeyEvent e) {
sb.append("\n");
});

sb.append("--- OTHER RECEIPTS").append("\n");
e.otherReceipts()
sb.append("--- RECEIPTS").append("\n");
e.receipts()
.entrySet()
.stream()
.map(kv -> Map.entry(kv.getKey().toString(), kv.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ public interface AttachmentEvent {

KeyEventCoordinates coordinates();

Map<Integer, Signature> signatures();
Map<Integer, Signature> authentication();

Map<Integer, Signature> receipts();
Map<Integer, Signature> endorsements();

Map<KeyEventCoordinates, Map<Integer, Signature>> receipts();

Map<KeyEventCoordinates, Map<Integer, Signature>> otherReceipts();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ default Digest digest() {

// attachments

Map<Integer, Signature> signatures();
Map<Integer, Signature> authentication();

Map<Integer, Signature> receipts();
Map<Integer, Signature> endorsements();

Map<KeyEventCoordinates, Map<Integer, Signature>> otherReceipts();
Map<KeyEventCoordinates, Map<Integer, Signature>> receipts();

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ public KeyEventCoordinates previous() {
}

@Override
public Map<Integer, Signature> signatures() {
public Map<Integer, Signature> authentication() {
return this.signatures;
}

@Override
public Map<Integer, Signature> receipts() {
public Map<Integer, Signature> endorsements() {
return this.receipts;
}

@Override
public Map<KeyEventCoordinates, Map<Integer, Signature>> otherReceipts() {
public Map<KeyEventCoordinates, Map<Integer, Signature>> receipts() {
return this.otherReceipts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public KeyEventCoordinates coordinates() {
}

@Override
public Map<Integer, Signature> signatures() {
public Map<Integer, Signature> authentication() {
return this.signatures;
}

@Override
public Map<Integer, Signature> receipts() {
public Map<Integer, Signature> endorsements() {
return this.receipts;
}

@Override
public Map<KeyEventCoordinates, Map<Integer, Signature>> otherReceipts() {
public Map<KeyEventCoordinates, Map<Integer, Signature>> receipts() {
return this.otherReceipts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class InMemoryKeyEventStore implements KeyEventStore {

private final ArrayList<KeyEvent> events = new ArrayList<>();
private final Map<KeyEventCoordinates, KeyState> states = new HashMap<>();
private final Map<KeyEventCoordinates, Map<Integer, Signature>> controllerSignatures = new HashMap<>();
private final Map<KeyEventCoordinates, Map<Integer, Signature>> receipts = new HashMap<>();
private final Map<OtherReceiptKey, Map<Integer, Signature>> otherReceipts = new HashMap<>();
private final Map<KeyEventCoordinates, Map<Integer, Signature>> authentications = new HashMap<>();
private final Map<KeyEventCoordinates, Map<Integer, Signature>> endorsements = new HashMap<>();
private final Map<ReceiptKey, Map<Integer, Signature>> receipts = new HashMap<>();

@Override
public void append(KeyEvent event) {
Expand All @@ -41,32 +41,34 @@ public void append(KeyEvent event) {

this.appendAttachments(
event.coordinates(),
event.signatures(),
event.receipts(),
event.otherReceipts());
event.authentication(),
event.endorsements(),
event.receipts());

this.states.put(event.coordinates(), newState);
}

private void appendAttachments(KeyEventCoordinates event, Map<Integer, Signature> signatures,
private void appendAttachments(
KeyEventCoordinates event, Map<Integer,
Signature> signatures,
Map<Integer, Signature> receipts,
Map<KeyEventCoordinates, Map<Integer, Signature>> otherReceipts) {
this.controllerSignatures.computeIfAbsent(event, k -> new HashMap<>())
this.authentications.computeIfAbsent(event, k -> new HashMap<>())
.putAll(signatures);

this.receipts.computeIfAbsent(event, k -> new HashMap<>())
this.endorsements.computeIfAbsent(event, k -> new HashMap<>())
.putAll(receipts);

for (var otherReceipt : otherReceipts.entrySet()) {
var key = new OtherReceiptKey(event, otherReceipt.getKey());
this.otherReceipts.computeIfAbsent(key, k -> new HashMap<>())
var key = new ReceiptKey(event, otherReceipt.getKey());
this.receipts.computeIfAbsent(key, k -> new HashMap<>())
.putAll(otherReceipt.getValue());
}
}

@Override
public void append(AttachmentEvent event) {
this.appendAttachments(event.coordinates(), event.signatures(), event.receipts(), event.otherReceipts());
this.appendAttachments(event.coordinates(), event.authentication(), event.endorsements(), event.receipts());
}

@Override
Expand Down Expand Up @@ -120,19 +122,19 @@ public Optional<KeyState> getKeyState(KeyEventCoordinates coordinates) {
@Override
public OptionalLong findLatestReceipt(
Identifier forIdentifier, Identifier byIdentifier) {
return this.otherReceipts.keySet()
return this.receipts.keySet()
.stream()
.filter(receiptKey -> receiptKey.event().identifier().equals(forIdentifier))
.filter(receiptKey -> receiptKey.signer().identifier().equals(byIdentifier))
.mapToLong(receiptKey -> receiptKey.event().sequenceNumber())
.max();
}

private static class OtherReceiptKey {
private static class ReceiptKey {
private final KeyEventCoordinates event;
private final KeyEventCoordinates signer;

public OtherReceiptKey(KeyEventCoordinates event, KeyEventCoordinates signer) {
public ReceiptKey(KeyEventCoordinates event, KeyEventCoordinates signer) {
this.event = ImmutableKeyEventCoordinates.convert(event);
this.signer = ImmutableKeyEventCoordinates.convert(signer);
}
Expand All @@ -150,10 +152,10 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof OtherReceiptKey)) {
if (!(o instanceof ReceiptKey)) {
return false;
}
OtherReceiptKey that = (OtherReceiptKey) o;
ReceiptKey that = (ReceiptKey) o;
return this.event.equals(that.event)
&& this.signer.equals(that.signer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected void encode(ChannelHandlerContext ctx, AttachmentEvent event, ByteBuf
out.writeBytes(SERIALIZER.serialize(event));

// TODO: still a hack
var signatures = event.otherReceipts()
var signatures = event.receipts()
.values()
.stream()
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ protected void encode(ChannelHandlerContext ctx, KeyEvent event, ByteBuf out) {
out.writeBytes(event.bytes());

// this will be replaced when we support new framing. For now, direct mode
var eventSignature = event.signatures();
var eventSignature = event.authentication();

out.writeCharSequence("-A", UTF_8);
out.writeCharSequence(base64(event.signatures().size(), 2), UTF_8);
out.writeCharSequence(base64(event.authentication().size(), 2), UTF_8);

event.signatures()
event.authentication()
.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
Expand Down

0 comments on commit a8ccd79

Please sign in to comment.