mirror of
https://github.com/selfxyz/self.git
synced 2026-01-13 16:47:57 -05:00
* feat: helper functions and constant for go-sdk * feat: formatRevealedDataPacked in go * chore: refactor * feat: define struct for selfBackendVerifier * feat: verify function for selfBackendVerifier * feat(wip): custom hasher * feat: SelfVerifierBacked in go * test(wip): scope and userContextHash is failing * test: zk proof verified * fix: MockConfigStore getactionId function * chore: refactor * chore: remove abi duplicate files * chore: move configStore to utils * chore: modified VcAndDiscloseProof struct * chore: more review changes * feat: impl DefaultConfig and InMemoryConfigStore * chore: refactor and export functions * fix: module import and README * chore: remove example folder * chore: remove pointers from VerificationConfig * chore: coderabbit review fixes * chore: more coderabbit review fix * chore: add license * fix: convert attestationIdd to int * chore: remove duplicate code --------- Co-authored-by: ayman <aymanshaik1015@gmail.com>
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package self
|
|
|
|
import (
|
|
"context"
|
|
|
|
)
|
|
|
|
// GetActionIdFunc is a function type for custom action ID generation
|
|
type GetActionIdFunc func(ctx context.Context, userIdentifier string, userDefinedData string) (string, error)
|
|
|
|
// InMemoryConfigStore provides an in-memory implementation of ConfigStore with custom action ID logic
|
|
type InMemoryConfigStore struct {
|
|
configs map[string]VerificationConfig
|
|
getActionIdFunc GetActionIdFunc
|
|
}
|
|
|
|
// Compile-time check to ensure InMemoryConfigStore implements ConfigStore interface
|
|
var _ ConfigStore = (*InMemoryConfigStore)(nil)
|
|
|
|
// NewInMemoryConfigStore creates a new instance of InMemoryConfigStore
|
|
func NewInMemoryConfigStore(getActionIdFunc GetActionIdFunc) *InMemoryConfigStore {
|
|
return &InMemoryConfigStore{
|
|
configs: make(map[string]VerificationConfig),
|
|
getActionIdFunc: getActionIdFunc,
|
|
}
|
|
}
|
|
|
|
// GetActionId uses the custom function to generate action IDs
|
|
func (store *InMemoryConfigStore) GetActionId(ctx context.Context, userIdentifier string, userDefinedData string) (string, error) {
|
|
return store.getActionIdFunc(ctx, userIdentifier, userDefinedData)
|
|
}
|
|
|
|
// SetConfig stores a configuration with the given ID
|
|
// Returns true if the configuration was newly created, false if it was updated
|
|
func (store *InMemoryConfigStore) SetConfig(ctx context.Context, id string, config VerificationConfig) (bool, error) {
|
|
_, existed := store.configs[id]
|
|
store.configs[id] = config
|
|
return !existed, nil
|
|
}
|
|
|
|
// GetConfig retrieves a configuration by ID
|
|
func (store *InMemoryConfigStore) GetConfig(ctx context.Context, id string) (VerificationConfig, error) {
|
|
config, exists := store.configs[id]
|
|
if !exists {
|
|
return VerificationConfig{}, nil
|
|
}
|
|
return config, nil
|
|
}
|