Commit graph

77 commits

Author SHA1 Message Date
Anna Shaleva
8e05bfe99c rpc/crypto: fix validator field marshalling in getvalidators RPC server
Problem: wrong `PublicKey` field json marshalling of result.Validator

Solution: add marshaller to publickey (crypto)
2020-03-24 15:52:51 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
a3dacd3b74 tests: replace t.Fatal with require where possible
This makes tests less verbose and unifies the style
they are written in.
2020-03-02 17:22:27 +03:00
Roman Khimov
a903147b60 keys: rename Signature to GetScriptHash, make it return Uint160
Signature itself wasn't used at all and its name is very misleading, Uint160
script hash is way more useful.
2020-02-19 12:19:03 +03:00
Roman Khimov
32a064aa31 keys: add Cmp method to PublicKey
It can be used by code that doesn't operate with PublicKeys, but still needs
to be able to compare keys for some purposes.
2020-02-12 21:27:40 +03:00
Roman Khimov
141553da4c keys: fix PublicKeys decoding
It changes the slice, thus it has to work via a pointer.
2020-02-12 21:23:28 +03:00
Roman Khimov
46b82b4fb5 keys: don't return error from PrivateKey.Sign
As it can't ever happen.
2020-01-17 17:00:30 +03:00
Roman Khimov
e2fff3bb1d keys: update to newer rfc6979 package
Fixes #592.
2020-01-16 18:21:10 +03:00
Roman Khimov
951ee383e9 keys: improve NEP2 testing 2020-01-09 18:06:03 +03:00
Roman Khimov
b5b05a969c keys: make NEP2Decrypt return a PrivateKey rather than WIF
There is no point in encoding the output of this function in a WIF format,
most of the users actually want the real key and those who need a WIF can
easily get if from the key (and it's simpler than getting the key from the
WIF).

It also fixes a severe bug in NEP2Decrypt, base58 decoding errors were not
processed correctly.
2020-01-09 18:05:14 +03:00
Roman Khimov
604b2c8240 keys: add a successful test for 04-encoded public key 2019-12-25 18:06:25 +03:00
Roman Khimov
fa0537758f keys: add a test for X/Y > P decoding case 2019-12-25 18:01:54 +03:00
Roman Khimov
6c471ecd98 keys: move IsOnCurve decoding check, add a test for it
This check only makes sense for 04-encoded points, because 02 and 03 derive Y
from X and they're on the curve by definition.
2019-12-25 18:00:25 +03:00
Roman Khimov
5ac8cae221 keys: fix bad compressed public key decoding, add a test
The error was not propagated properly here.
2019-12-25 17:44:30 +03:00
Roman Khimov
b246653f62 address: rename functions as per #579 comments
Make them more clear to understand.
2019-12-25 17:34:18 +03:00
Roman Khimov
e25133a385 keys: reuse address package for address generation
Deduplicates code and makes prefix overridable.
2019-12-25 16:03:39 +03:00
Roman Khimov
e685e9bf9a address: move into its own package
Doesn't really belong to the crypto.
2019-12-25 15:22:02 +03:00
Roman Khimov
369ac01a27 base58: move into its own package
It doesn't belong to crypto in any way other than it uses hash function
internally.
2019-12-25 15:05:54 +03:00
Roman Khimov
5dd8d29534 hash: improve merkle tree testing
Make it 100% covered.
2019-12-25 14:43:50 +03:00
Roman Khimov
ddad9ac9a3 hash: simplify merkle tree error handling
buildMerkleTree() is internal to the hash package and if anyone calls it with
`len(leaves) == 0` he deserves a panic. As it's the only error case in it, we
can remove error value return from this function and simplify NewMerkleTree().
2019-12-25 14:38:48 +03:00
Roman Khimov
ee28fb08f6 crypto: move merkle tree into the hash package
It's all about hashes, so it makes sense putting it there.
2019-12-25 11:28:59 +03:00
Roman Khimov
db5555bb15 crypto: internalize aes functions into the keys package
This is the only user of it and no one outside should care about these
details.
2019-12-25 11:25:05 +03:00
Roman Khimov
8b3080b972 io: rename Read/WriteBytes to Read/WriteB
go vet is not happy about them:
  pkg/io/binaryReader.go:92:21: method ReadByte() byte should have signature ReadByte() (byte, error)
  pkg/io/binaryWriter.go:75:21: method WriteByte(u8 byte) should have signature WriteByte(byte) error
2019-12-12 20:19:50 +03:00
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +03:00
Roman Khimov
7e83078d13 hash: remove useless no-op decoding
It changes nothing here.
2019-12-12 17:58:34 +03:00
Evgenii Stratonikov
fccb008594 io: implement ReadBytes() 2019-12-09 15:00:15 +03:00
Evgenii Stratonikov
7179e4ba9f util: add LE suffix to Uint256 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
57efad912c util: add LE suffix to Uint160 methods 2019-12-06 12:16:55 +03:00
Roman Khimov
138e125646 *: remove duplicate functions producing verification script
Drop wif.GetVerificationScript(), drop
smartcontract.CreateSignatureRedeemScript(), add GetVerificationScript()
directly to the PublicKey and use it everywhere.
2019-12-03 18:23:46 +03:00
Roman Khimov
f48228ef7d
Merge pull request #467 from nspcc-dev/errcheck_297
This patchset closes #297 and #457.
2019-12-03 15:06:11 +03:00
Vsevolod Brekelov
03ff2976ed io: refactoring for using WriteVarBytes instead of WriteLE
goal is to be consistent with C# implementation.
For writing []byte WriteBytes used and for byte - WriteVarByte.
2019-12-03 13:49:33 +03:00
Roman Khimov
bc5beb438f *: gofmt
Somehow these crept into the repository.
2019-12-02 10:10:50 +03:00
Evgenii Stratonikov
0a9a742019 crypto: add invalid testcase 2019-11-29 11:03:03 +03:00
Evgenii Stratonikov
4d82419776 crypto: add missing tests for hash pkg 2019-11-29 11:03:03 +03:00
Vsevolod Brekelov
38088b648a crypto: add unit tests for public key 2019-11-21 15:41:49 +03:00
Vsevolod Brekelov
d4e8846ed0 !squash core/crypto 2019-11-21 15:41:49 +03:00
Vsevolod Brekelov
c80ee952a1 core/crypto: add validators and interop for validators
add processing of validators while block persist;
add validator structure with decoding/encoding;
add validator get from store;
add EnrollmentTX and StateTX processing;
add pubkey decode bytes, unique and contains functions;
2019-11-21 15:23:35 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Roman Khimov
7ab58ff8cb keys: make public key's IsInfinity() public
It's gonna be used in interops for key validity check.
2019-10-15 12:56:25 +03:00
Roman Khimov
6b70c5f2bd keys: rename New*FromRawBytes to New*FromASN1
RawBytes is too confusing and may be read as being compatible with
NEO-serialized format.
2019-10-15 12:56:25 +03:00
Roman Khimov
bd1f70366a crypto: change files mode to 644 (some *.go had exec flags set) 2019-09-17 15:34:00 +03:00
Roman Khimov
d1a4e43c48 io: redo Serializable to return errors in BinReader/BinWriter
Further simplifies error handling.
2019-09-17 13:21:52 +03:00
Roman Khimov
5bf00db2c9 io: move BinReader/BinWriter there, redo Serializable with it
The logic here is that we'll have all binary encoding/decoding done via our io
package, which simplifies error handling. This functionality doesn't belong to
util, so it's moved.

This also expands BufBinWriter with Reset() method to fit the needs of core
package.
2019-09-16 23:39:51 +03:00
Roman Khimov
a039ae6cdb
Merge pull request #374 from nspcc-dev/makefile-and-gofmt
Makefile convenience targets and gofmt
2019-09-09 15:05:12 +03:00
Roman Khimov
8db9d2a976 crypto: use mr-tron/base58 for base58
Use more fast and reliable implementation. Add some tests for our wrappers,
deduplicate code in PublicKey.Adress(). Fixes #355.
2019-09-09 13:12:55 +03:00
Roman Khimov
fabd11699a *: gofmt -s
Appy gofmt for all the source tree.
2019-09-09 12:02:24 +03:00
Roman Khimov
e537dc9ee4 keys: improve publick key checks with a check against P
ANSI X9.62 says that if x or y coordinate are greater than or equal to
curve.Params().P, the conversion should return an error (see ANSI X9.62:2005
Section A.5.8 Step b, which invokes Section A.5.5, which does the check and
rejects when x or y are too big.

See https://github.com/golang/go/issues/20482 for more details.
2019-09-05 12:34:12 +03:00
Roman Khimov
f12194f3b0 keys: deduplicate DecodeBytes/DecodeBinary for PrivateKey
They shared prefix logic for no good reason, don't do that.
2019-09-05 12:34:12 +03:00
Roman Khimov
2c3e92923f keys: simplify error handling for PublicKey() and associated
PublicKey() for PrivateKey now just can't fail and it makes no sense to return
an error from it. There is a lot of associated functionality for which this
also is true, so adjust it accordingly and simplify a lot of code.
2019-09-05 12:34:12 +03:00
Roman Khimov
60bc2e8053 keys: simplify PublicKey() for PrivateKey
Public key is just a point, so use the coordinates obtained previously to
initialize the PublicKey structure without jumping through the hoops of
encoding/decoding.
2019-09-05 12:34:12 +03:00