ciri-crypto 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -5
- data/ciri-crypto.gemspec +2 -2
- data/lib/ciri/crypto.rb +2 -3
- data/lib/ciri/crypto/signature.rb +1 -1
- data/lib/ciri/crypto/version.rb +1 -1
- metadata +5 -4
- data/lib/ciri/key.rb +0 -88
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 456517177da7e8d25c25252e1ad9f05ece11fd3badaf12dbabdf204d6f21d310
|
4
|
+
data.tar.gz: d8b537b9dbd9e6a3e9ed082d23990f47ff60e025ccfd9170057b742e114915d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87a95cbc31d4ced2ca7ba222b8a706308cfa118ba10e8278bdcebf43867667639c7671a0b64b29db580f7f178d12d62595ef7bd12bdd71f896620fe96da2c519
|
7
|
+
data.tar.gz: e7ba8cc52e1c2df039b3b5c4af3ab011926744b64638e899289e6025c29e31536548a322720a9e4e890d9a0f0080e832cce4192f4e153e640951830c13259219
|
data/Gemfile.lock
CHANGED
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(
|
25
|
+
Ciri::Crypto.esdsa_signature("\x00...(privkey)", "\x00...(data)")
|
26
26
|
|
27
27
|
# recover
|
28
|
-
Ciri::Crypto.ecdsa_recover(
|
28
|
+
Ciri::Crypto.ecdsa_recover("I\x90...(signed hash)", "f\xAA...(signature)", return_raw_key: true)
|
29
29
|
|
30
30
|
# ecies encrypt
|
31
|
-
|
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.
|
36
|
+
Ciri::Crypto.ecies_decrypt(encrypt_data, key, shared_mac_data = '')
|
35
37
|
|
36
38
|
# ensure secp256k1 key
|
37
|
-
Ciri::Crypto.ensure_secp256k1_key(
|
39
|
+
Ciri::Crypto.ensure_secp256k1_key(privkey: "\x00...")
|
38
40
|
```
|
39
41
|
|
40
42
|
## Development
|
data/ciri-crypto.gemspec
CHANGED
@@ -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}
|
data/lib/ciri/crypto.rb
CHANGED
@@ -28,9 +28,8 @@ require 'openssl'
|
|
28
28
|
require 'ciri/utils'
|
29
29
|
require 'secp256k1'
|
30
30
|
|
31
|
-
require_relative "
|
32
|
-
require_relative "
|
33
|
-
require_relative "./key"
|
31
|
+
require_relative "crypto/errors"
|
32
|
+
require_relative "crypto/signature"
|
34
33
|
|
35
34
|
module Ciri
|
36
35
|
module Crypto
|
data/lib/ciri/crypto/version.rb
CHANGED
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.
|
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-
|
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:
|
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)
|
data/lib/ciri/key.rb
DELETED
@@ -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
|