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

Validate Ownership #159

Open
digimbyte opened this issue Nov 23, 2022 · 3 comments
Open

Validate Ownership #159

digimbyte opened this issue Nov 23, 2022 · 3 comments

Comments

@digimbyte
Copy link

I am working on some tools for blockchain and Neo, but part of this requires that users are able to validate ownership on the chain.
its common for developers to create a getOwner() script but its not a standard. this means that without these on contracts that we risk any user claiming ownership of that contract and fraudulently configuring for those contracts.

I propose a universal standard to find a contracts current owner address, allowing websites and tools to validate contracts and any configuration related to them and their respective developers, owners, etc.

an alternative is a forced mint or transaction on the contract to validate ownership rights similar to DNS validation but on the blockchain itself.

looking to see what options exist and what solutions we can bring to better integrate validation and security to neo projects.

@roman-khimov
Copy link
Contributor

Some getOwner/setOwner pair seems to be appropriate here.

@cschuchardt88
Copy link
Member

I think it should emit an event too.

As Follows:

private const byte Prefix_Owner = 0x02;

[InitialValue("<Owner Address Here>", Neo.SmartContract.ContractParameterType.Hash160)]
private static readonly UInt160 InitialOwner = default;

[Safe]
public static UInt160 GetOwner()
{
    var currentOwner = Storage.Get(new[] { Prefix_Owner });

    if (currentOwner == null)
        return InitialOwner;

    return (UInt160)currentOwner;
}

private static bool IsOwner() =>
    Runtime.CheckWitness(GetOwner());

public delegate void OnSetOwnerDelegate(UInt160 newOwner);

[DisplayName("SetOwner")]
public static event OnSetOwnerDelegate OnSetOwner;

public static void SetOwner(UInt160 newOwner)
{
    if (IsOwner() == false)
        throw new InvalidOperationException("No Authorization!");
    if (newOwner != null && newOwner.IsValid)
    {
        Storage.Put(new[] { Prefix_Owner }, newOwner);
        OnSetOwner(newOwner);
    }
}

@shargon
Copy link
Member

shargon commented Feb 26, 2024

We should create a nep standard for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@shargon @digimbyte @cschuchardt88 @roman-khimov and others