Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change local_acp implementation to use acp_core #2691

Merged
merged 46 commits into from
Jun 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
185ccec
refactor: replace Embedded ACP with ACP Core engine
Lodek Jun 6, 2024
bb0f676
doc: doc methods
Lodek Jun 5, 2024
1059f0a
test refactor wip
Lodek Jun 5, 2024
5aeab86
add_policy refactor
Lodek Jun 5, 2024
90cd3f1
fix: index test
Lodek Jun 5, 2024
4a555a4
fix p2p tests
Lodek Jun 5, 2024
4b233e9
fix: query tests
Lodek Jun 5, 2024
aa22100
schema test refactor
Lodek Jun 5, 2024
f108555
fix: acp integration
Lodek Jun 5, 2024
33b994c
test fixes
Lodek Jun 5, 2024
4b56a79
test fixes
Lodek Jun 6, 2024
c31efc8
doc: updated acp_local adapter docs
Lodek Jun 6, 2024
4ed1c0c
added defra policy abstraction
Lodek Jun 6, 2024
7e4982d
mod bump
Lodek Jun 6, 2024
dc907a9
fix: net peer tests
Lodek Jun 6, 2024
d5c1de1
remove helper methods from policy data types
Lodek Jun 6, 2024
a549c9d
fix: collection_description test fix
Lodek Jun 7, 2024
5af32f4
PR suggestins and toolchain update
Lodek Jun 7, 2024
edb060a
chore: update fixme docs
Lodek Jun 7, 2024
796454d
bump acp_core version
Lodek Jun 7, 2024
6682ba5
refactor identity
Lodek Jun 7, 2024
a198dd0
factor: Indetity DID generation and test fixes
Lodek Jun 7, 2024
3bcbc39
update license in file
Lodek Jun 7, 2024
cf27ec2
test: added missing tests
Lodek Jun 10, 2024
ee5fb03
refactor: identity returns error
Lodek Jun 11, 2024
dd34b38
refactor fixes
Lodek Jun 11, 2024
f5ceca9
Merge branch 'develop' into refactor/local-acp
Lodek Jun 11, 2024
d0db457
chore: go mod tidy
Lodek Jun 11, 2024
9308ad2
revert: change actor id to creator id in polcy create
Lodek Jun 11, 2024
d9cf7d6
test: FromPrivateKey, FromPublicKey
Lodek Jun 11, 2024
df10e84
fix: typo
Lodek Jun 11, 2024
67cb1c1
identity and did providers
Lodek Jun 13, 2024
71364aa
identity refactor
Lodek Jun 13, 2024
04cc0b7
ci fix
Lodek Jun 13, 2024
547e194
fix typo
Lodek Jun 13, 2024
b80aa03
provier rename
Lodek Jun 13, 2024
549c406
Revert "identity refactor"
Lodek Jun 14, 2024
6dbd782
producer refactor
Lodek Jun 14, 2024
6982d9e
cleanup
Lodek Jun 14, 2024
6205c7b
lint fix
Lodek Jun 14, 2024
568a46b
Merge branch 'develop' into refactor/local-acp
Lodek Jun 14, 2024
d28db70
revert identity provider
Lodek Jun 14, 2024
3b3bbe8
refactor: make identity err func private
Lodek Jun 14, 2024
e1135a1
revert policy marshal type location
Lodek Jun 14, 2024
10f5826
Merge branch 'develop' into refactor/local-acp
Lodek Jun 19, 2024
80beb43
chore: mod tidy
Lodek Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions acp/acp_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"context"
"crypto/ed25519"
"errors"
"strings"

protoTypes "github.com/cosmos/gogoproto/types"
"github.com/sourcenetwork/acp_core/pkg/auth"
Expand All @@ -36,6 +37,7 @@ var _ sourceHubClient = (*ACPLocal)(nil)
var _ Policy = (*localACPPolicyAdapter)(nil)
var _ Resource = (*localACPResourceAdapter)(nil)
var _ Permission = (*types.Permission)(nil)
var errGeneratingDIDFromNonAccAddr = errors.New("cannot generate did if address is not prefixed")
Lodek marked this conversation as resolved.
Show resolved Hide resolved

type localACPResourceAdapter struct {
resource *types.Resource
Expand Down Expand Up @@ -108,6 +110,7 @@ func (l *ACPLocal) AddPolicy(
policy string,
creationTime *protoTypes.Timestamp,
) (string, error) {
// FIXME remove once Identity is refactored
did, err := genDIDFromSourceHubAddr(creatorID)
if err != nil {
return "", err
Expand Down Expand Up @@ -167,6 +170,7 @@ func (l *ACPLocal) RegisterObject(
objectID string,
creationTime *protoTypes.Timestamp,
) (RegistrationResult, error) {
// FIXME remove once Identity is refactored
did, err := genDIDFromSourceHubAddr(actorID)
if err != nil {
return RegistrationResult_NoOp, err
Lodek marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -200,22 +204,22 @@ func (l *ACPLocal) ObjectOwner(
resourceName string,
objectID string,
) (immutable.Option[string], error) {
empty := immutable.None[string]()
none := immutable.None[string]()

req := types.GetObjectRegistrationRequest{
PolicyId: policyID,
Object: types.NewObject(resourceName, objectID),
}
result, err := l.engine.GetObjectRegistration(ctx, &req)
if err != nil {
return empty, err
return none, err
}

if result.IsRegistered {
return immutable.Some(result.OwnerId), nil
}

return empty, nil
return none, nil
}

func (l *ACPLocal) VerifyAccessRequest(
Expand All @@ -226,6 +230,7 @@ func (l *ACPLocal) VerifyAccessRequest(
resourceName string,
docID string,
) (bool, error) {
// FIXME remove once Identity is refactored
Lodek marked this conversation as resolved.
Show resolved Hide resolved
did, err := genDIDFromSourceHubAddr(actorID)
if err != nil {
return false, err
Expand Down Expand Up @@ -253,7 +258,23 @@ func (l *ACPLocal) VerifyAccessRequest(
return resp.Valid, nil
}

// genDIDFromSourceHubAddr uses an account addr as a seed to produce a key pair
// and consequently generate a DID.
//
// NOTE: This is by no means a *safe* practice, however it's "okay" for two reasons:
// 1. It's a temporary workaround which will be invalidated once the new identity system
// is in place (ie. Identity is a DID as opposed to a SourceHub Addr)
// 2. In Local ACP, the the temporary keys used to generate the DID aren't effectively
// used for any cryptographic operations.
//
// This method will produce an error if `addr` does not begin with "source".
// The error will ensure that the tests break after the identity system is refactored,
// which will be a sign that this method can be deleted entirely
func genDIDFromSourceHubAddr(addr string) (string, error) {
if !strings.HasPrefix(addr, "source") {
return "", errGeneratingDIDFromNonAccAddr
}

seed := make([]byte, ed25519.SeedSize)
copy(seed, []byte(addr))
did, _, err := did.ProduceDIDFromSeed(seed)
Expand Down