Skip to content

Commit

Permalink
Merge pull request #75 from ticket721/fix/accept-hex-encoding-on-acco…
Browse files Browse the repository at this point in the history
…unts-sign

fix: add encoding argument on accounts/:name/sign
  • Loading branch information
cypherhat committed Mar 21, 2020
2 parents b813b34 + 0d6399b commit 9692ad3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
16 changes: 15 additions & 1 deletion API.md
Expand Up @@ -584,13 +584,27 @@ This endpoint will sign the provided data.
* `name` (`string: <required>`) - Specifies the name of the account to use for signing. This is specified as part of the URL.
* `data` (`string: <required>`) - Some data.
* `encoding` (`string: <required>`) - The encoding of the data.
#### Sample Payload
##### UTF8 Payload
```sh
{
"data": "this is very important"
"data": "this is very important",
"encoding": "utf8"
}
```
##### Hexadecimal Payload (remove `0x` prefix)
```sh
{
"data": "de0B295669a9FD93d5F28D9Ec85E40f4cb697BAe",
"encoding": "hex"
}
```
Expand Down
21 changes: 20 additions & 1 deletion path_accounts.go
Expand Up @@ -262,6 +262,10 @@ Sign data using a given Ethereum account.
Type: framework.TypeString,
Description: "The data to hash (keccak) and sign.",
},
"encoding": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Encoding of the provided data.",
},
},
ExistenceCheck: b.pathExistenceCheck,
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand Down Expand Up @@ -857,7 +861,22 @@ func (b *EthereumBackend) pathSign(ctx context.Context, req *logical.Request, da
}

name := data.Get("name").(string)
dataToSign := data.Get("data").(string)
rawData := data.Get("data").(string)
encoding := data.Get("encoding").(string)

var dataToSign []byte

if encoding == "hex" {
dataToSign, err = Decode([]byte(rawData))
if err != nil {
return nil, err
}
} else if encoding == "utf8" {
dataToSign = []byte(rawData)
} else {
return nil, fmt.Errorf("invalid encoding encountered - %s", encoding)
}

account, err := b.readAccount(ctx, req, name)
if err != nil {
return nil, fmt.Errorf("error reading account")
Expand Down

0 comments on commit 9692ad3

Please sign in to comment.