secp256k1zkp 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f9f439836bf01ac6f1b0ac87ffe86d574fb0940
4
- data.tar.gz: e4aa8985dd05aa5be9cb5defa141876ad21aaf10
3
+ metadata.gz: a575be3ded4533ceb6e1a6e4d89b671dfbf0b56f
4
+ data.tar.gz: 4217153dd20cff3488438c4eceb0ae4df002c551
5
5
  SHA512:
6
- metadata.gz: becdcd95251016ab442147136c8ceb95d98a66395a96357e4311acb28428f8e85df084b28c18ea4bb8c88bc234b1adead3963b3ac7fba964744a8876b183f58f
7
- data.tar.gz: f1cf4ed558e7017f36427b1571918ae788c94a7885d2526c2f46b1ccc0bb7237f688449b318e53761f541347eb7649246134232869b3564a13ba547fb04bd5ff
6
+ metadata.gz: da15c704b58c37ff56ec6f30d098b358b80af891cd9770126d6141c86985376a131e89222c3b8730bec826b6f57837a7b354a2c809bf5a77ead7664f569c9c74
7
+ data.tar.gz: 04aff797d4b9764eb24ef0e6b896457513d8ccc042d5d0e4ac9bb2b28fcf3e74a64e676325caf1437a8d70c7b072060bcbaa7a0d963b127ae6600aa450b5bee1
@@ -6,39 +6,43 @@ class Secp256k1Zkp::PrivateKey
6
6
 
7
7
  include Secp256k1Zkp::Utility
8
8
 
9
- SECP256K1_CURVE_ORDER = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
9
+ class << self
10
+
11
+ SECP256K1_CURVE_ORDER = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
12
+
13
+ def nonce
14
+ # => 私钥有效范围。[1, SECP256K1_CURVE_ORDER)。 REMARK:大部分 lib 范围是 [1, SECP256K1_CURVE_ORDER] 的闭区间,该C库范围为开区间。
15
+ SecureRandom.random_number(SECP256K1_CURVE_ORDER - 1) + 1
16
+ end
17
+
18
+ def random
19
+ new(hex_decode("%064x" % self.nonce))
20
+ end
21
+
22
+ # => role - owner / active
23
+ def from_account_and_password(account, password, role = 'active')
24
+ return from_seed(format("%s%s%s", account, role, password))
25
+ end
26
+
27
+ def from_seed(seed)
28
+ return new(sha256(seed))
29
+ end
30
+
31
+ def from_wif(wif_private_key_string)
32
+ raw = base58_decode(wif_private_key_string)
33
+ version = raw[0].unpack("C").first
34
+ raise 'invalid private key.' if version != 0x80
35
+ # => raw = [1B]0x80 + [32B]privatekey + [4B]checksum
36
+ checksum_size = 4
37
+ checksum4 = raw[-checksum_size..-1]
38
+ private_key_with_prefix = raw[0...-checksum_size]
39
+ digest = sha256(sha256(private_key_with_prefix))
40
+ raise 'invalid private key.' if checksum4 != digest[0, checksum_size]
41
+ return new(raw[1, 32])
42
+ end
10
43
 
11
- def self.nonce
12
- # => 私钥有效范围。[1, SECP256K1_CURVE_ORDER)。 REMARK:大部分 lib 范围是 [1, SECP256K1_CURVE_ORDER] 的闭区间,该C库范围为开区间。
13
- SecureRandom.random_number(SECP256K1_CURVE_ORDER - 1) + 1
14
44
  end
15
-
16
- def self.random
17
- new(hex_decode("%064x" % self.nonce))
18
- end
19
-
20
- # => role - owner / active
21
- def self.from_account_and_password(account, password, role = 'active')
22
- return from_seed(format("%s%s%s", account, role, password))
23
- end
24
-
25
- def self.from_seed(seed)
26
- return new(sha256(seed))
27
- end
28
-
29
- def self.from_wif(wif_private_key_string)
30
- raw = base58_decode(wif_private_key_string)
31
- version = raw[0].unpack("C").first
32
- raise 'invalid private key.' if version != 0x80
33
- # => raw = [1B]0x80 + [32B]privatekey + [4B]checksum
34
- checksum_size = 4
35
- checksum4 = raw[-checksum_size..-1]
36
- private_key_with_prefix = raw[0...-checksum_size]
37
- digest = sha256(sha256(private_key_with_prefix))
38
- raise 'invalid private key.' if checksum4 != digest[0, checksum_size]
39
- return new(raw[1, 32])
40
- end
41
-
45
+
42
46
  def to_wif
43
47
  private_key_with_prefix = 0x80.chr + self.bytes
44
48
  checksum = sha256(sha256(private_key_with_prefix))[0, 4]
@@ -4,17 +4,23 @@ class Secp256k1Zkp::PublicKey
4
4
 
5
5
  include Secp256k1Zkp::Utility
6
6
 
7
- def self.from_wif(wif_public_key, public_key_prefix = 'BTS')
8
- prefix_size = public_key_prefix.bytesize
9
- prefix = wif_public_key[0, prefix_size]
10
- raise 'invalid public key prefix.' if prefix != public_key_prefix
11
-
12
- raw = base58_decode(wif_public_key[prefix_size..-1])
13
- checksum_size = 4
14
- compression_public_key = raw[0, raw.bytesize - checksum_size]
15
- checksum4 = raw[-checksum_size..-1]
16
- raise 'invalid public key.' if checksum4 != rmd160(compression_public_key)[0, checksum_size]
17
- return new(compression_public_key)
7
+ class << self
8
+
9
+ include Secp256k1Zkp::Utility
10
+
11
+ def from_wif(wif_public_key, public_key_prefix = 'BTS')
12
+ prefix_size = public_key_prefix.bytesize
13
+ prefix = wif_public_key[0, prefix_size]
14
+ raise 'invalid public key prefix.' if prefix != public_key_prefix
15
+
16
+ raw = base58_decode(wif_public_key[prefix_size..-1])
17
+ checksum_size = 4
18
+ compression_public_key = raw[0, raw.bytesize - checksum_size]
19
+ checksum4 = raw[-checksum_size..-1]
20
+ raise 'invalid public key.' if checksum4 != rmd160(compression_public_key)[0, checksum_size]
21
+ return new(compression_public_key)
22
+ end
23
+
18
24
  end
19
25
 
20
26
  def to_wif(public_key_prefix = 'BTS')
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Secp256k1Zkp
4
4
 
5
- VERSION = '0.9.4'.freeze
5
+ VERSION = '0.9.5'.freeze
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secp256k1zkp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jokenshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-21 00:00:00.000000000 Z
11
+ date: 2020-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58