Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
rename project name to *Ciri*
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed May 18, 2018
1 parent 2974a63 commit 2651a04
Show file tree
Hide file tree
Showing 42 changed files with 325 additions and 332 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -2,6 +2,6 @@ source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}"}

# Specify your gem's dependencies in ethruby.gemspec
# Specify your gem's dependencies in ciri.gemspec
gemspec

4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ethruby (0.0.0)
ciri (0.0.0)
bitcoin-secp256k1 (~> 0.4.0)
concurrent-ruby (~> 1.0.5)
digest-sha3 (~> 1.1.0)
Expand Down Expand Up @@ -37,7 +37,7 @@ PLATFORMS

DEPENDENCIES
bundler (~> 1.16)
ethruby!
ciri!
rake (~> 10.0)
rspec (~> 3.0)

Expand Down
14 changes: 7 additions & 7 deletions README.md
@@ -1,7 +1,7 @@
Ethruby
Ciri
===============

Ethruby project intent to implement full feature set of ethereum in pure ruby, to provide both usable cli and well documented ruby library.
Ciri project intent to implement a full feature set ethereum client.

### Check List

Expand All @@ -26,23 +26,23 @@ Ethruby project intent to implement full feature set of ethereum in pure ruby, t
### Install

``` bash
gem install ethruby
gem install ciri
```

As library

``` ruby
require 'ethruby'
puts ETH::Version
require 'ciri'
puts Ciri::Version
```

### Command line

`eth -h`
`ciri -h`

### Documentation

[YARD documentation](https://www.rubydoc.info/github/ruby-ethereum/ethereum/master)
[YARD documentation](https://www.rubydoc.info/github/ruby-ethereum/ciri/master)

### Author

Expand Down
2 changes: 1 addition & 1 deletion bin/console
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "ethruby"
require "ciri"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
8 changes: 4 additions & 4 deletions ethruby.gemspec → ciri.gemspec
@@ -1,16 +1,16 @@

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "ethruby/version"
require "ciri/version"

Gem::Specification.new do |spec|
spec.name = "ethruby"
spec.version = ETH::VERSION
spec.name = "ciri"
spec.version = Ciri::VERSION
spec.authors = ["Jiang Jinyang"]
spec.email = ["jjyruby@gmail.com"]

spec.summary = %q{Ruby implementation of the ethereum}
spec.description = %q{Ethruby project intent to implement full feature set of ethereum in pure ruby, to provide both usable cli and well documented ruby library.}
spec.description = %q{Ciri project intent to implement full feature set of ethereum in pure ruby, to provide both usable cli and well documented ruby library.}
spec.homepage = "https://github.com/ruby-ethereum/ethereum"
spec.license = "MIT"

Expand Down
4 changes: 2 additions & 2 deletions lib/ethruby.rb → lib/ciri.rb
Expand Up @@ -19,8 +19,8 @@
# THE SOFTWARE.


require "ethruby/version"
require "ciri/version"

module ETH
module Ciri
# Your code goes here...
end
12 changes: 6 additions & 6 deletions lib/ethruby/crypto.rb → lib/ciri/crypto.rb
Expand Up @@ -24,10 +24,10 @@
# this module include several methods translated from pydevp2p.devp2p.crypto

require 'openssl'
require 'ethruby/utils'
require 'ciri/utils'
require 'secp256k1'

module ETH
module Ciri
module Crypto
extend self

Expand All @@ -39,12 +39,12 @@ class ECIESDecryptionError < StandardError
def ecdsa_signature(key, data)
secp256k1_key = ensure_secp256k1_key(privkey: key)
signature, recid = secp256k1_key.ecdsa_recoverable_serialize(secp256k1_key.ecdsa_sign_recoverable(data, raw: true))
signature + ETH::Utils.big_endian_encode(recid, "\x00")
signature + Ciri::Utils.big_endian_encode(recid, "\x00")
end

def ecdsa_recover(msg, signature, return_raw_key: true)
pk = Secp256k1::PrivateKey.new(flags: Secp256k1::ALL_FLAGS)
sig, recid = signature[0..-2], ETH::Utils.big_endian_decode(signature[-1])
sig, recid = signature[0..-2], Ciri::Utils.big_endian_decode(signature[-1])

recsig = pk.ecdsa_recoverable_deserialize(sig, recid)
pubkey = pk.ecdsa_recover(msg, recsig, raw: true)
Expand Down Expand Up @@ -91,7 +91,7 @@ def ecies_decrypt(data, priv_key, shared_mac_data = '')
# verify data
key_mac = Digest::SHA256.digest(key_mac)
tag = data[-32..-1]
unless ETH::Utils.secret_compare(hmac_sha256(key_mac, data[65...-32] + shared_mac_data), tag)
unless Ciri::Utils.secret_compare(hmac_sha256(key_mac, data[65...-32] + shared_mac_data), tag)
raise ECIESDecryptionError.new("Fail to verify data")
end

Expand Down Expand Up @@ -136,7 +136,7 @@ def hmac_sha256(key, data)
end

def ec_pkey_from_raw(raw_pubkey, raw_privkey: nil)
ETH::Utils.create_ec_pk(raw_pubkey: raw_pubkey, raw_privkey: raw_privkey)
Ciri::Utils.create_ec_pk(raw_pubkey: raw_pubkey, raw_privkey: raw_privkey)
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/ethruby/devp2p/actor.rb → lib/ciri/devp2p/actor.rb
Expand Up @@ -23,7 +23,7 @@

require 'logger'

module ETH
module Ciri
module DevP2P

# simple actor model implementation
Expand Down Expand Up @@ -166,9 +166,9 @@ def wait

# start loop
def start_loop
loop_callback do
loop_callback do |wait_message: true|
# check inbox
next Thread.pass if @inbox.empty?
next Thread.pass if @inbox.empty? && !wait_message
msg = @inbox.pop

# extract sync or async call
Expand Down
5 changes: 2 additions & 3 deletions lib/ethruby/devp2p/peer.rb → lib/ciri/devp2p/peer.rb
Expand Up @@ -26,7 +26,7 @@
require_relative 'actor'
require_relative 'protocol_io'

module ETH
module Ciri
module DevP2P

# represent a connected remote node
Expand Down Expand Up @@ -74,8 +74,7 @@ def read_loop

def start_protocols
@protocols.each do |protocol|
protocol.executor ||= executor
protocol.start(self, @protocol_io_hash[protocol.name])
protocol.start.(self, @protocol_io_hash[protocol.name])
end
end

Expand Down
12 changes: 2 additions & 10 deletions lib/ethruby/devp2p/protocol.rb → lib/ciri/devp2p/protocol.rb
Expand Up @@ -24,27 +24,19 @@

require_relative 'actor'

module ETH
module Ciri
module DevP2P

# protocol represent DevP2P sub protocols
class Protocol

include Actor

attr_reader :name, :version, :length
attr_accessor :node_info, :peer_info
attr_accessor :node_info, :peer_info, :start

def initialize(name:, version:, length:)
@name = name
@version = version
@length = length
super()
end

# start protocol handling
def start(peer, io)
super()
end
end

Expand Down
Expand Up @@ -24,7 +24,7 @@
require_relative 'actor'
require_relative 'rlpx/message'

module ETH
module Ciri
module DevP2P

# send/read sub protocol msg
Expand Down
File renamed without changes.
Expand Up @@ -21,15 +21,15 @@
# THE SOFTWARE.


require 'ethruby/rlp'
require 'ciri/rlp'
require 'socket'
require 'forwardable'
require_relative 'frame_io'
require_relative 'protocol_messages'
require_relative 'error'
require_relative 'encryption_handshake'

module ETH
module Ciri
module DevP2P
module RLPX

Expand Down Expand Up @@ -120,7 +120,7 @@ def read_enc_handshake_msg(plain_size, private_key)

# try decode eip8 format
prefix = packet[0...2]
size = ETH::Utils.big_endian_decode(prefix)
size = Ciri::Utils.big_endian_decode(prefix)
raise FormatError.new("EIP8 format message size #{size} less than plain_size #{plain_size}") if size < plain_size

# continue read remain bytes
Expand Down
Expand Up @@ -22,11 +22,11 @@
# THE SOFTWARE.


require 'ethruby/key'
require 'ciri/key'
require 'digest/sha3'
require_relative 'secrets'

module ETH
module Ciri
module DevP2P
module RLPX

Expand Down Expand Up @@ -56,7 +56,7 @@ def remote_key
end

def random_key
@random_key ||= ETH::Key.random
@random_key ||= Ciri::Key.random
end

def auth_msg
Expand All @@ -75,12 +75,12 @@ def auth_msg
end

def handle_auth_msg(msg)
@remote_key = ETH::Key.new(raw_public_key: "\x04" + msg.initiator_pubkey)
@remote_key = Ciri::Key.new(raw_public_key: "\x04" + msg.initiator_pubkey)
@initiator_nonce = msg.nonce

token = dh_compute_key(private_key, @remote_key)
signed = xor(token, msg.nonce)
@remote_random_key = ETH::Key.ecdsa_recover(signed, msg.signature)
@remote_random_key = Ciri::Key.ecdsa_recover(signed, msg.signature)
end

def auth_ack_msg
Expand All @@ -94,14 +94,14 @@ def auth_ack_msg
def handle_auth_ack_msg(msg)
# make nonce bytes
@receiver_nonce = msg.nonce
@remote_random_key = ETH::Key.new(raw_public_key: "\x04" + msg.random_pubkey)
@remote_random_key = Ciri::Key.new(raw_public_key: "\x04" + msg.random_pubkey)
end

def extract_secrets(auth_packet, auth_ack_packet, initiator:)
secret = dh_compute_key(random_key, remote_random_key)
shared_secret = ETH::Utils.sha3(secret, ETH::Utils.sha3(receiver_nonce, initiator_nonce))
aes_secret = ETH::Utils.sha3(secret, shared_secret)
mac = ETH::Utils.sha3(secret, aes_secret)
shared_secret = Ciri::Utils.sha3(secret, Ciri::Utils.sha3(receiver_nonce, initiator_nonce))
aes_secret = Ciri::Utils.sha3(secret, shared_secret)
mac = Ciri::Utils.sha3(secret, aes_secret)
secrets = Secrets.new(remote_id: remote_id, aes: aes_secret, mac: mac)

# initial secrets macs
Expand Down
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.


module ETH
module Ciri
module DevP2P
module RLPX

Expand Down
Expand Up @@ -22,13 +22,13 @@


require 'stringio'
require 'ethruby/rlp/serializable'
require 'ciri/rlp/serializable'
require_relative 'error'
require_relative 'message'

require 'snappy'

module ETH
module Ciri
module DevP2P
module RLPX

Expand Down Expand Up @@ -118,7 +118,7 @@ def read_msg
# verify header mac
head_buf = read(32)
verify_mac = update_mac(@secrets.ingress_mac, head_buf[0...16])
unless ETH::Utils.secret_compare(verify_mac, head_buf[16...32])
unless Ciri::Utils.secret_compare(verify_mac, head_buf[16...32])
raise InvalidError.new('bad header mac')
end

Expand All @@ -138,7 +138,7 @@ def read_msg
verify_mac = update_mac(@secrets.ingress_mac, frame_digest)
# clear head_buf 16...32 bytes(header mac), since we will not need it
frame_mac = head_buf[16...32] = read(16)
unless ETH::Utils.secret_compare(verify_mac, frame_mac)
unless Ciri::Utils.secret_compare(verify_mac, frame_mac)
raise InvalidError.new('bad frame mac')
end

Expand Down
Expand Up @@ -21,15 +21,15 @@
# THE SOFTWARE.


require 'ethruby/rlp/serializable'
require 'ciri/rlp/serializable'

module ETH
module Ciri
module DevP2P
module RLPX

# RLPX message
class Message
include ETH::RLP::Serializable
include Ciri::RLP::Serializable

schema [
{code: Integer},
Expand Down

0 comments on commit 2651a04

Please sign in to comment.