func GetOwnershipOfTwinFromRegisteredIdentity(resolverClient register.ResolverClient, twinID register.RegisteredIdentity, newOwnerID register.RegisteredIdentity, newOwnerKeyName string) error {
	return advancedapi.AddPublicKeyToDocument(resolverClient, nil, newOwnerKeyName, newOwnerID.KeyPair().PublicKeyBase58, twinID)
}
GetOwnershipOfTwinFromRegisteredIdentity Get Ownership of a twin using a registered identity you owned.
package api
import (
	"time"
	"github.com/Iotic-Labs/iotics-identity-go/pkg/advancedapi"
	"github.com/Iotic-Labs/iotics-identity-go/pkg/crypto"
	"github.com/Iotic-Labs/iotics-identity-go/pkg/identity"
	"github.com/Iotic-Labs/iotics-identity-go/pkg/register"
)
const (
	defaultSeedLength = 256
	defaultSeedMethod = crypto.SeedMethodBip39
)
func CreateUserAndAgentWithAuthDelegation(resolverClient register.ResolverClient, opts *CreateUserAndAgentWithAuthDelegationOpts) (userID register.RegisteredIdentity, agentID register.RegisteredIdentity, err error) {
	agentPath := crypto.PathForDIDType(opts.AgentKeyName, identity.Agent)
	agentSecrets, err := crypto.NewDefaultKeyPairSecretsWithPassword(opts.AgentSeed, agentPath, opts.AgentPassword)
	if err != nil {
		return nil, nil, err
	}
	agentKeyPair, err := crypto.GetKeyPair(agentSecrets)
	if err != nil {
		return nil, nil, err
	}
	agentID, agentDocument, err := advancedapi.CreateNewIdentityAndRegister(resolverClient, identity.Agent, agentKeyPair, opts.AgentName, false)
	if err != nil {
		return nil, nil, err
	}
	userPath := crypto.PathForDIDType(opts.UserKeyName, identity.User)
	userSecrets, err := crypto.NewKeyPairSecrets(opts.UserSeed, userPath, defaultSeedMethod, opts.UserPassword)
	if err != nil {
		return nil, nil, err
	}
	userKeyPair, err := crypto.GetKeyPair(userSecrets)
	if err != nil {
		return nil, nil, err
	}
	userDocument, userIssuer, err := advancedapi.CreateNewDocument(identity.User, userKeyPair, opts.UserName)
	if err != nil {
		return nil, nil, err
	}
	delegOpts := advancedapi.DelegationOpts{
		ResolverClient:     resolverClient,
		DelegatingKeyPair:  userKeyPair,
		DelegatingDid:      userIssuer.Did,
		DelegatingDocument: userDocument,
		SubjectKeyPair:     agentKeyPair,
		SubjectDid:         agentID.Did(),
		SubjectDocument:    agentDocument,
		Name:               opts.DelegationName,
	}
	err = advancedapi.DelegateAuthentication(delegOpts)
	if err != nil {
		return nil, nil, err
	}
	userID = register.NewRegisteredIdentity(userKeyPair, userIssuer)
	return userID, agentID, nil
}
func CreateAgentAuthToken(agentID register.RegisteredIdentity, userDid string, duration time.Duration, audience string) (register.JwtToken, error) {
	startOffset := register.DefaultAuthTokenStartOffset
	return advancedapi.CreateAgentAuthToken(agentID, userDid, duration, audience, startOffset)
}
func CreateTwinWithControlDelegation(resolverClient register.ResolverClient, opts *CreateTwinOpts) (register.RegisteredIdentity, error) {
	twinPath := crypto.PathForDIDType(opts.KeyName, identity.Twin)
	twinSecrets, err := crypto.NewKeyPairSecrets(opts.Seed, twinPath, defaultSeedMethod, opts.Password)
	if err != nil {
		return nil, err
	}
	twinKeyPair, err := crypto.GetKeyPair(twinSecrets)
	if err != nil {
		return nil, err
	}
	twinDocument, twinIssuer, err := advancedapi.CreateNewDocument(identity.Twin, twinKeyPair, opts.Name)
	if err != nil {
		return nil, err
	}
	delegOpts := advancedapi.DelegationOpts{
		ResolverClient:     resolverClient,
		DelegatingKeyPair:  twinKeyPair,
		DelegatingDid:      twinIssuer.Did,
		DelegatingDocument: twinDocument,
		SubjectKeyPair:     opts.AgentID.KeyPair(),
		SubjectDid:         opts.AgentID.Did(),
		SubjectDocument:    opts.AgentDoc,
		Name:               opts.DelegationName,
	}
	err = advancedapi.DelegateControl(delegOpts)
	if err != nil {
		return nil, err
	}
	twinIdentity := register.NewRegisteredIdentity(twinKeyPair, twinIssuer)
	return twinIdentity, nil
}
func DelegateControl(resolverClient register.ResolverClient, twinID register.RegisteredIdentity, agentID register.RegisteredIdentity, delegationName string) error {
	return TwinDelegatesControlToAgent(resolverClient, twinID, agentID, delegationName)
}