ciri-crypto 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed1a25ffdb3a238cc655ca8240ce9628c4f2d2980b39c9bd9535ddc51a60a5a2
4
- data.tar.gz: '068652f8d6606fdf23eed3cfecceb099ba79889a0be1e85077ba7782c3fb996c'
3
+ metadata.gz: 456517177da7e8d25c25252e1ad9f05ece11fd3badaf12dbabdf204d6f21d310
4
+ data.tar.gz: d8b537b9dbd9e6a3e9ed082d23990f47ff60e025ccfd9170057b742e114915d7
5
5
  SHA512:
6
- metadata.gz: 2cbec214f56c456110e1c63332f8067cf9750e2545b58cd68a8bf6256ed5f13207394d7a3114d8340ca5c7876bae3b7f403799d1827070047fcb0ca82ed752f5
7
- data.tar.gz: 5f8ee8ed224fb3e4b5220dfe882f4e26b5c06ebb292414550572fcfac25b684a16ea0d66d79edd1282b60555c859b7c9d8f8e85afe853b9ba3470503bbbd3fd9
6
+ metadata.gz: 87a95cbc31d4ced2ca7ba222b8a706308cfa118ba10e8278bdcebf43867667639c7671a0b64b29db580f7f178d12d62595ef7bd12bdd71f896620fe96da2c519
7
+ data.tar.gz: e7ba8cc52e1c2df039b3b5c4af3ab011926744b64638e899289e6025c29e31536548a322720a9e4e890d9a0f0080e832cce4192f4e153e640951830c13259219
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ciri-crypto (0.1.0)
4
+ ciri-crypto (0.1.1)
5
5
  bitcoin-secp256k1 (~> 0.4.0)
6
6
  ciri-utils (~> 0.2.0)
7
7
 
data/README.md CHANGED
@@ -22,19 +22,21 @@ Or install it yourself as:
22
22
 
23
23
  ```ruby
24
24
  # signature
25
- Ciri::Crypto.esdsa_signature(key, data)
25
+ Ciri::Crypto.esdsa_signature("\x00...(privkey)", "\x00...(data)")
26
26
 
27
27
  # recover
28
- Ciri::Crypto.ecdsa_recover(msg, signature, return_raw_key: true)
28
+ Ciri::Crypto.ecdsa_recover("I\x90...(signed hash)", "f\xAA...(signature)", return_raw_key: true)
29
29
 
30
30
  # ecies encrypt
31
- Ciri::Crypto.ecies_encrypt(message, raw_pubkey, shared_mac_data = '')
31
+ key = OpenSSL::PKey::EC.new('secp256k1')
32
+ key.generate_key
33
+ encrypt_data = Ciri::Crypto.ecies_encrypt("hello ciri", key, shared_mac_data = '')
32
34
 
33
35
  # ecies decrypt
34
- Ciri::Crypto.ecies_encrypt(data, private_key, shared_mac_data = '')
36
+ Ciri::Crypto.ecies_decrypt(encrypt_data, key, shared_mac_data = '')
35
37
 
36
38
  # ensure secp256k1 key
37
- Ciri::Crypto.ensure_secp256k1_key(private_key)
39
+ Ciri::Crypto.ensure_secp256k1_key(privkey: "\x00...")
38
40
  ```
39
41
 
40
42
  ## Development
@@ -6,8 +6,8 @@ require "ciri/crypto/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ciri-crypto"
8
8
  spec.version = Ciri::Crypto::VERSION
9
- spec.authors = ["classicalliu"]
10
- spec.email = ["classicalliu@gmail.com"]
9
+ spec.authors = ["classicalliu", "Jiang Jinyang"]
10
+ spec.email = ["classicalliu@gmail.com", "jjyruby@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Crypto module of [Ciri](https://github.com/ciri-ethereum/ciri)}
13
13
  spec.description = %q{A Ciri crypto module}
@@ -28,9 +28,8 @@ require 'openssl'
28
28
  require 'ciri/utils'
29
29
  require 'secp256k1'
30
30
 
31
- require_relative "./crypto/errors"
32
- require_relative "./crypto/signature"
33
- require_relative "./key"
31
+ require_relative "crypto/errors"
32
+ require_relative "crypto/signature"
34
33
 
35
34
  module Ciri
36
35
  module Crypto
@@ -21,7 +21,7 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  require "ciri/utils"
24
- require_relative "./errors"
24
+ require_relative "errors"
25
25
 
26
26
  module Ciri
27
27
  module Crypto
@@ -1,5 +1,5 @@
1
1
  module Ciri
2
2
  module Crypto
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ciri-crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - classicalliu
8
+ - Jiang Jinyang
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2018-07-15 00:00:00.000000000 Z
12
+ date: 2018-07-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -83,6 +84,7 @@ dependencies:
83
84
  description: A Ciri crypto module
84
85
  email:
85
86
  - classicalliu@gmail.com
87
+ - jjyruby@gmail.com
86
88
  executables: []
87
89
  extensions: []
88
90
  extra_rdoc_files: []
@@ -103,7 +105,6 @@ files:
103
105
  - lib/ciri/crypto/errors.rb
104
106
  - lib/ciri/crypto/signature.rb
105
107
  - lib/ciri/crypto/version.rb
106
- - lib/ciri/key.rb
107
108
  homepage: https://github.com/ciri-ethereum/ciri
108
109
  licenses:
109
110
  - MIT
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  version: '0'
126
127
  requirements: []
127
128
  rubyforge_project:
128
- rubygems_version: 2.7.6
129
+ rubygems_version: 3.0.0.beta1
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: Crypto module of [Ciri](https://github.com/ciri-ethereum/ciri)
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018, by Jiang Jinyang. <https://justjjy.com>, classicalliu.
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
-
24
- require 'openssl'
25
- require 'ciri/utils'
26
- require_relative 'crypto'
27
-
28
- module Ciri
29
-
30
- # Ciri::Key represent private/public key pair, it support several encryption methods used in Ethereum
31
- #
32
- # Examples:
33
- #
34
- # key = Ciri::Key.random
35
- # key.ecdsa_signature(data)
36
- #
37
- class Key
38
-
39
- class << self
40
- def ecdsa_recover(msg, signature)
41
- raw_public_key = Crypto.ecdsa_recover(msg, signature, return_raw_key: true)
42
- Ciri::Key.new(raw_public_key: raw_public_key)
43
- end
44
-
45
- def random
46
- ec_key = OpenSSL::PKey::EC.new('secp256k1')
47
- ec_key.generate_key
48
- Ciri::Key.new(ec_key: ec_key)
49
- end
50
- end
51
-
52
- attr_reader :ec_key
53
-
54
- # initialized from ec_key or raw keys
55
- # ec_key is a OpenSSL::PKey::EC object, raw keys is bytes presented keys
56
- def initialize(ec_key: nil, raw_public_key: nil, raw_private_key: nil)
57
- @ec_key = ec_key || Ciri::Utils.create_ec_pk(raw_privkey: raw_private_key, raw_pubkey: raw_public_key)
58
- end
59
-
60
- # raw public key
61
- def raw_public_key
62
- @raw_public_key ||= ec_key.public_key.to_bn.to_s(2)
63
- end
64
-
65
- def ecdsa_signature(data)
66
- Crypto.ecdsa_signature(secp256k1_key, data)
67
- end
68
-
69
- def ecies_encrypt(message, shared_mac_data = '')
70
- Crypto.ecies_encrypt(message, ec_key, shared_mac_data)
71
- end
72
-
73
- def ecies_decrypt(data, shared_mac_data = '')
74
- Crypto.ecies_decrypt(data, ec_key, shared_mac_data)
75
- end
76
-
77
- private
78
-
79
- def secp256k1_key
80
- privkey = ec_key.private_key.to_s(2)
81
- # some times below error will occurs, raise error with more detail
82
- unless privkey.instance_of?(String) && privkey.size == 32
83
- raise ArgumentError, "privkey must be composed of 32 bytes, #{bytes}: #{privkey.size} privkey: #{Utils.to_hex privkey}"
84
- end
85
- @secp256k1_key ||= Crypto.ensure_secp256k1_key(privkey: privkey)
86
- end
87
- end
88
- end