Skip to content

Commit

Permalink
add validation for inbox id key packages via new method
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed May 17, 2024
1 parent aff1e2b commit c7b7c7c
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions pkg/mlsvalidate/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

identity_proto "github.com/xmtp/xmtp-node-go/pkg/proto/identity"
identity "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1"
associations "github.com/xmtp/xmtp-node-go/pkg/proto/identity/associations"
mlsv1 "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1"
Expand Down Expand Up @@ -122,25 +123,54 @@ func (s *MLSValidationServiceImpl) validateInboxIdKeyPackages(ctx context.Contex
}
}

// TODO: do we need to take sequence ID Into account?
request := &identity.GetIdentityUpdatesRequest{Requests: identityUpdatesRequest}
identity_updates, err := s.identityStore.GetInboxLogs(ctx, request)

/*
for i, response := range response.Responses {
if !response.IsOk {
return nil, fmt.Errorf("validation failed with error %s", response.ErrorMessage)
}
out[i] = IdentityValidationResult{
AccountAddress: response.AccountAddress,
InstallationKey: response.InstallationId,
CredentialIdentity: response.CredentialIdentityBytes,
Expiration: response.Expiration,
}
}
*/
if err != nil {
return nil, err
}

validation_requests := make([]*svc.ValidateInboxIdsRequest_ValidationRequest, len(identity_updates.Responses))
for i, response := range identity_updates.Responses {
validation_requests[i] = makeValidationRequest(response, installationPublicKeys)
}

validation_request := svc.ValidateInboxIdsRequest{Requests: validation_requests}
s.grpcClient.ValidateInboxIds(ctx, &validation_request)
if err != nil {
return nil, err
}

for i, response := range response.Responses {
if !response.IsOk {
return nil, fmt.Errorf("validation failed with error %s", response.ErrorMessage)
}
out[i] = IdentityValidationResult{
// AccountAddress: response.AccountAddress,
InstallationKey: response.InstallationPublicKey,
CredentialIdentity: response.credential,

Check failure on line 152 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Build

response.credential undefined (type *mls_validationv1.ValidateInboxIdKeyPackagesResponse_Response has no field or method credential, but does have Credential)

Check failure on line 152 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Build

response.credential undefined (type *mls_validationv1.ValidateInboxIdKeyPackagesResponse_Response has no field or method credential, but does have Credential)

Check failure on line 152 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Lint

response.credential undefined (type *mls_validationv1.ValidateInboxIdKeyPackagesResponse_Response has no field or method credential, but does have Credential)

Check failure on line 152 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Lint

response.credential undefined (type *mls_validationv1.ValidateInboxIdKeyPackagesResponse_Response has no field or method credential, but does have Credential)

Check failure on line 152 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Lint

response.credential undefined (type *mls_validationv1.ValidateInboxIdKeyPackagesResponse_Response has no field or method credential, but does have Credential)
Expiration: null,

Check failure on line 153 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Build

undefined: null

Check failure on line 153 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Build

undefined: null

Check failure on line 153 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: null) (typecheck)

Check failure on line 153 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: null) (typecheck)

Check failure on line 153 in pkg/mlsvalidate/service.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: null) (typecheck)
}
}
return out, nil
}

func makeValidationRequest(update *identity.GetIdentityUpdatesResponse_Response, pub_keys map[string][]byte) *svc.ValidateInboxIdsRequest_ValidationRequest {
identity_updates := make([]*associations.IdentityUpdate, len(update.Updates))
for i, identity_log := range update.Updates {
identity_updates[i] = identity_log.Update
}

out := svc.ValidateInboxIdsRequest_ValidationRequest{
Credential: &identity_proto.MlsCredential{InboxId: update.InboxId},
InstallationPublicKey: pub_keys[update.InboxId],
IdentityUpdates: identity_updates,
}

return &out
}

func (s *MLSValidationServiceImpl) validateV3KeyPackages(ctx context.Context, keyPackages [][]byte, req *svc.ValidateKeyPackagesRequest) ([]IdentityValidationResult, error) {
response, err := s.grpcClient.ValidateKeyPackages(ctx, req)
if err != nil {
Expand Down

0 comments on commit c7b7c7c

Please sign in to comment.