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

can u give me signed function example? #48

Closed
joeg9soft opened this issue Feb 23, 2022 · 3 comments
Closed

can u give me signed function example? #48

joeg9soft opened this issue Feb 23, 2022 · 3 comments

Comments

@joeg9soft
Copy link

joeg9soft commented Feb 23, 2022

im trying to call signed functions but i don't understand how i get v,r,s
please give me example code to call signed functions

@mirceanis
Copy link
Contributor

Hi,
The *Signed() methods allow you to authorize modifications to the DID document without directly sending the transaction. The transaction can be called by a third party that needs to pay for the gas.

Each *Signed() method requires that you have access to the private key to produce the signatures.
There are examples for each doSomethingSigned() method in the test suite.
Example: changeOwnerSigned()

There is an example function signData that shows how to pack the required input and calculate the signature using the private key.

Each function has slightly different requirements, and each one is described in the readme.
For example, to add a delegate using the signed function call, the readme describes this:

The externally signed version has the following signature addDelegateSigned(address identity, uint8 sigV, bytes32 sigR, bytes32 sigS, bytes32 delegateType, address delegate, uint validity) .

The signature should be signed of the keccak256 hash of the following tightly packed parameters:
byte(0x19), byte(0), address of registry, nonce[currentOwner], identity, "addDelegate", delegateType, delegate, validity

The format of the message that gets signed is unfortunately not compatible with current implementations of eth_sign in web3 providers. This method was written before that was standardized, and the contract cannot be upgraded.
This means that you need access to the private key, and can't call these methods from a wallet like Metamask.
From a normal wallet, you would call the non-signed methods, in which case the validation is based on the transaction signature instead of the special message signature.

@joeg9soft
Copy link
Author

thank you for answer and i got signed fuction success finally,
and my question about delegate is what is purpose of delegate and usage.
i called addDelegate function and then it returned address and privatekey so after this,
i can get did document with delegate-1, delegate-2
at this point, what is delegate for? i wanna know delegate usage.

@mirceanis
Copy link
Contributor

The delegates that you add with addDelegate can be viewed as other addresses that can sign on your behalf.

It is almost equivalent to adding a Secp256k1 public key to the DID document (using setAttribute), with the exception that delegates can also be checked on-chain using the validDelegate function.

This pattern later became known as Contract signatures, under ERC1271.

I'll close this for now, please reopen if there are more questions on this topic.

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

2 participants