2017-02-08 07:53:02 -06:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// URL represents the canonical identification URL of a wallet or account.
|
|
|
|
//
|
|
|
|
// It is a simplified version of url.URL, with the important limitations (which
|
|
|
|
// are considered features here) that it contains value-copyable components only,
|
|
|
|
// as well as that it doesn't do any URL encoding/decoding of special characters.
|
|
|
|
//
|
|
|
|
// The former is important to allow an account to be copied without leaving live
|
|
|
|
// references to the original version, whereas the latter is important to ensure
|
|
|
|
// one single canonical form opposed to many allowed ones by the RFC 3986 spec.
|
|
|
|
//
|
|
|
|
// As such, these URLs should not be used outside of the scope of an Ethereum
|
|
|
|
// wallet or account.
|
|
|
|
type URL struct {
|
|
|
|
Scheme string // Protocol scheme to identify a capable account backend
|
|
|
|
Path string // Path for the backend to identify a unique entity
|
|
|
|
}
|
|
|
|
|
|
|
|
// parseURL converts a user supplied URL into the accounts specific structure.
|
|
|
|
func parseURL(url string) (URL, error) {
|
|
|
|
parts := strings.Split(url, "://")
|
|
|
|
if len(parts) != 2 || parts[0] == "" {
|
|
|
|
return URL{}, errors.New("protocol scheme missing")
|
|
|
|
}
|
|
|
|
return URL{
|
|
|
|
Scheme: parts[0],
|
|
|
|
Path: parts[1],
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the stringer interface.
|
|
|
|
func (u URL) String() string {
|
|
|
|
if u.Scheme != "" {
|
|
|
|
return fmt.Sprintf("%s://%s", u.Scheme, u.Path)
|
|
|
|
}
|
|
|
|
return u.Path
|
|
|
|
}
|
|
|
|
|
2017-03-02 07:06:16 -06:00
|
|
|
// TerminalString implements the log.TerminalStringer interface.
|
|
|
|
func (u URL) TerminalString() string {
|
|
|
|
url := u.String()
|
|
|
|
if len(url) > 32 {
|
2021-04-15 12:35:00 -05:00
|
|
|
return url[:31] + ".."
|
2017-03-02 07:06:16 -06:00
|
|
|
}
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
2017-02-08 07:53:02 -06:00
|
|
|
// MarshalJSON implements the json.Marshaller interface.
|
|
|
|
func (u URL) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(u.String())
|
|
|
|
}
|
|
|
|
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 07:04:32 -05:00
|
|
|
// UnmarshalJSON parses url.
|
|
|
|
func (u *URL) UnmarshalJSON(input []byte) error {
|
2018-07-18 03:32:49 -05:00
|
|
|
var textURL string
|
|
|
|
err := json.Unmarshal(input, &textURL)
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 07:04:32 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-18 03:32:49 -05:00
|
|
|
url, err := parseURL(textURL)
|
cmd/clef, signer: initial poc of the standalone signer (#16154)
* signer: introduce external signer command
* cmd/signer, rpc: Implement new signer. Add info about remote user to Context
* signer: refactored request/response, made use of urfave.cli
* cmd/signer: Use common flags
* cmd/signer: methods to validate calldata against abi
* cmd/signer: work on abi parser
* signer: add mutex around UI
* cmd/signer: add json 4byte directory, remove passwords from api
* cmd/signer: minor changes
* cmd/signer: Use ErrRequestDenied, enable lightkdf
* cmd/signer: implement tests
* cmd/signer: made possible for UI to modify tx parameters
* cmd/signer: refactors, removed channels in ui comms, added UI-api via stdin/out
* cmd/signer: Made lowercase json-definitions, added UI-signer test functionality
* cmd/signer: update documentation
* cmd/signer: fix bugs, improve abi detection, abi argument display
* cmd/signer: minor change in json format
* cmd/signer: rework json communication
* cmd/signer: implement mixcase addresses in API, fix json id bug
* cmd/signer: rename fromaccount, update pythonpoc with new json encoding format
* cmd/signer: make use of new abi interface
* signer: documentation
* signer/main: remove redundant option
* signer: implement audit logging
* signer: create package 'signer', minor changes
* common: add 0x-prefix to mixcaseaddress in json marshalling + validation
* signer, rules, storage: implement rules + ephemeral storage for signer rules
* signer: implement OnApprovedTx, change signing response (API BREAKAGE)
* signer: refactoring + documentation
* signer/rules: implement dispatching to next handler
* signer: docs
* signer/rules: hide json-conversion from users, ensure context is cleaned
* signer: docs
* signer: implement validation rules, change signature of call_info
* signer: fix log flaw with string pointer
* signer: implement custom 4byte databsae that saves submitted signatures
* signer/storage: implement aes-gcm-backed credential storage
* accounts: implement json unmarshalling of url
* signer: fix listresponse, fix gas->uint64
* node: make http/ipc start methods public
* signer: add ipc capability+review concerns
* accounts: correct docstring
* signer: address review concerns
* rpc: go fmt -s
* signer: review concerns+ baptize Clef
* signer,node: move Start-functions to separate file
* signer: formatting
2018-04-16 07:04:32 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
u.Scheme = url.Scheme
|
|
|
|
u.Path = url.Path
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-08 07:53:02 -06:00
|
|
|
// Cmp compares x and y and returns:
|
|
|
|
//
|
2022-09-10 06:25:40 -05:00
|
|
|
// -1 if x < y
|
|
|
|
// 0 if x == y
|
|
|
|
// +1 if x > y
|
2017-02-08 07:53:02 -06:00
|
|
|
func (u URL) Cmp(url URL) int {
|
|
|
|
if u.Scheme == url.Scheme {
|
|
|
|
return strings.Compare(u.Path, url.Path)
|
|
|
|
}
|
|
|
|
return strings.Compare(u.Scheme, url.Scheme)
|
|
|
|
}
|