starkbank-ecdsa 0.0.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 +7 -0
- data/lib/ecdsa.rb +28 -0
- data/lib/privatekey.rb +49 -0
- data/lib/publickey.rb +33 -0
- data/lib/signature.rb +32 -0
- data/lib/starkbank-ecdsa.rb +19 -0
- data/lib/utils/file.rb +10 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f76cd19f97c1e6621a584f9f154cfb954831837b1b78d6dd1d594bebbc6d2b5
|
4
|
+
data.tar.gz: 815499dddec80fe726c1421091347f3947476ffb7a2670bacac94ef88a1ef3fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccaa0451f8dc4e6307b9150700eb13d974459809920ef8cf2c8ee0a0b1a0731d2ceb1a066ffb535e7759765d9f84b3a2c3855104c83c9676645c94674a7c0d04
|
7
|
+
data.tar.gz: f9d8f43de27589a4646098711d1e7d71e8590bb74e1f9ffb0184df6cfa9a8ef7dc153d1720f664c36a19147ec22eac47895feeeb11e4a97b8b967382785a0d0a
|
data/lib/ecdsa.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'openssl'
|
3
|
+
require 'signature'
|
4
|
+
|
5
|
+
|
6
|
+
module Ecdsa
|
7
|
+
|
8
|
+
def self.sign(message, privateKey, hashfunc=nil)
|
9
|
+
if hashfunc.nil?
|
10
|
+
message = Digest::SHA256.digest(message)
|
11
|
+
else
|
12
|
+
message = hashfunc(message)
|
13
|
+
end
|
14
|
+
|
15
|
+
signature = privateKey.openSslPrivateKey.dsa_sign_asn1(message)
|
16
|
+
return Signature.new(signature)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.verify(message, signature, publicKey, hashfunc=nil)
|
20
|
+
if hashfunc.nil?
|
21
|
+
message = Digest::SHA256.digest(message)
|
22
|
+
else
|
23
|
+
message = hashfunc(message)
|
24
|
+
end
|
25
|
+
return publicKey.openSslPublicKey.dsa_verify_asn1(message, signature.toDer())
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/privatekey.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "base64"
|
3
|
+
require_relative "publickey"
|
4
|
+
|
5
|
+
|
6
|
+
class PrivateKey
|
7
|
+
|
8
|
+
def initialize(curve="secp256k1", openSslKey=nil)
|
9
|
+
if openSslKey.nil?
|
10
|
+
@openSslPrivateKey = OpenSSL::PKey::EC.new(curve)
|
11
|
+
@openSslPrivateKey.generate_key
|
12
|
+
else
|
13
|
+
@openSslPrivateKey = openSslKey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :openSslPrivateKey
|
18
|
+
|
19
|
+
def publicKey
|
20
|
+
dupKey = OpenSSL::PKey::EC.new(@openSslPrivateKey.to_der())
|
21
|
+
dupKey.private_key = nil
|
22
|
+
return PublicKey.new(dupKey)
|
23
|
+
end
|
24
|
+
|
25
|
+
def toString
|
26
|
+
return Base64.encode64(self.toDer())
|
27
|
+
end
|
28
|
+
|
29
|
+
def toDer
|
30
|
+
return @openSslPrivateKey.to_der()
|
31
|
+
end
|
32
|
+
|
33
|
+
def toPem
|
34
|
+
return @openSslPrivateKey.to_pem()
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.fromPem(string)
|
38
|
+
return PrivateKey.new(nil, OpenSSL::PKey::EC.new(string))
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.fromDer(string)
|
42
|
+
return PrivateKey.new(nil, OpenSSL::PKey::EC.new(string))
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.fromString(string)
|
46
|
+
return PrivateKey.new(nil, OpenSSL::PKey::EC.new(Base64.decode64(string)))
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/lib/publickey.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class PublicKey
|
2
|
+
|
3
|
+
def initialize(openSslPublicKey)
|
4
|
+
@openSslPublicKey = openSslPublicKey
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :openSslPublicKey
|
8
|
+
|
9
|
+
def toString
|
10
|
+
return Base64.encode64(self.toDer())
|
11
|
+
end
|
12
|
+
|
13
|
+
def toDer
|
14
|
+
@openSslPublicKey.to_der()
|
15
|
+
end
|
16
|
+
|
17
|
+
def toPem
|
18
|
+
@openSslPublicKey.to_pem()
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.fromPem(string)
|
22
|
+
return PublicKey.new(OpenSSL::PKey::EC.new(string))
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.fromDer(string)
|
26
|
+
return PublicKey.new(OpenSSL::PKey::EC.new(string))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.fromString(string)
|
30
|
+
return PublicKey.new(OpenSSL::PKey::EC.new(Base64.decode64(string)))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/signature.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "openSSL"
|
3
|
+
|
4
|
+
|
5
|
+
class Signature
|
6
|
+
|
7
|
+
def initialize(der)
|
8
|
+
@der = der
|
9
|
+
decoded = OpenSSL::ASN1.decode(der).value
|
10
|
+
@r = decoded[0].value
|
11
|
+
@s = decoded[1].value
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :r, :s
|
15
|
+
|
16
|
+
def toDer
|
17
|
+
return @der
|
18
|
+
end
|
19
|
+
|
20
|
+
def toBase64
|
21
|
+
Base64.encode64(self.toDer()).gsub("\n", "")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.fromDer(string)
|
25
|
+
return Signature.new(string)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.fromBase64(string)
|
29
|
+
self.fromDer(Base64.decode64(string))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "signature"
|
2
|
+
require_relative "publickey"
|
3
|
+
require_relative "privatekey"
|
4
|
+
require_relative "ecdsa"
|
5
|
+
require_relative "utils/file"
|
6
|
+
|
7
|
+
|
8
|
+
module EllipticCurve
|
9
|
+
|
10
|
+
Signature = Signature
|
11
|
+
PublicKey = PublicKey
|
12
|
+
PrivateKey = PrivateKey
|
13
|
+
Ecdsa = Ecdsa
|
14
|
+
|
15
|
+
module Utils
|
16
|
+
File = File
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/utils/file.rb
ADDED
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: starkbank-ecdsa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- starkbank
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ecdsa.rb
|
20
|
+
- lib/privatekey.rb
|
21
|
+
- lib/publickey.rb
|
22
|
+
- lib/signature.rb
|
23
|
+
- lib/starkbank-ecdsa.rb
|
24
|
+
- lib/utils/file.rb
|
25
|
+
homepage: https://github.com/starkbank/ecdsa-ruby
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.3'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.0.6
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: fast openSSL-compatible implementation of the Elliptic Curve Digital Signature
|
48
|
+
Algorithm (ECDSA)
|
49
|
+
test_files: []
|