stellar-base 0.16.0 → 0.17.0

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: 2062b56ea0a8fd01a7917fe0e602098d9233896c0189bc3551ce594397f394a4
4
- data.tar.gz: 9dfca2d0f18a86ec0d36c3b7e97fd9c75e61339c39d0f4a7c834129ad48bdf46
3
+ metadata.gz: 4bcdc8dd8ee4878dd631b013811444a2ae4cb55a3642beffc0e6a27edf78af0b
4
+ data.tar.gz: 46aa0348b3b4548af1ef03f1658990d479ae1f56c84bbb37c1b80017acb0e265
5
5
  SHA512:
6
- metadata.gz: fcf5bca3ecc1b9bfc27198bf8d0712a4c0f4780ef851f8894c67a5bdaea13ae82b34696618ba298f31ddec9f726f298d6e6242b8474a29d1a225cbd206bb1bc0
7
- data.tar.gz: 92f331fdad439135cac96063346ce2e1426efe1766a73e8c2151e87ecd7f7a351b76028569566a84431887ee67e45b8437f8824defb50fd051cbc99f02d75e52
6
+ metadata.gz: 7f67e3c1932f6ee43eb4b366f48873d19d6304115eb9ea4a47e4ca8dc17b0a25e2bc5129bc139ea94eb51e7ad3421d87ed1310cf758a88663b73096cb51c7ea6
7
+ data.tar.gz: f358ae8b004e7291e9beb56d12774a06ae60b1779b37583be1b6969aafbd5ecc2687e9ad86742674dba03dd5cb96649d93520c5ccc3bc36cff2c62d51c54ad81
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.16.0"
3
+ VERSION = "0.17.0"
4
4
  end
5
5
  end
@@ -1,6 +1,8 @@
1
1
  module Stellar
2
2
  class SignerKey
3
3
 
4
+ PREIMAGE_LENGTH = 32
5
+
4
6
  def self.ed25519(keypair)
5
7
  raise ArgumentError, "Bad keypair" unless keypair.is_a?(KeyPair)
6
8
  new(:signer_key_type_ed25519, keypair.raw_public_key)
@@ -12,7 +14,10 @@ module Stellar
12
14
  end
13
15
 
14
16
 
15
- def self.onetime_signer(preimage)
17
+ def self.hash_x(preimage)
18
+ raise ArgumentError, "Must be string" unless preimage.is_a?(String)
19
+ raise ArgumentError, "Must be 32 bytes" unless preimage.bytesize == PREIMAGE_LENGTH
20
+
16
21
  hash_x = Digest::SHA256.digest(preimage)
17
22
  new(:signer_key_type_hash_x, hash_x)
18
23
  end
@@ -36,5 +41,10 @@ module Stellar
36
41
  "#<Stellar::SignerKey #{to_s}>"
37
42
  end
38
43
 
44
+ def signature_hint
45
+ # take last 4 bytes
46
+ value.to_xdr.slice(-4, 4)
47
+ end
48
+
39
49
  end
40
50
  end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe Stellar::SignerKey, ".hash_x" do
4
+
5
+ subject{ Stellar::SignerKey }
6
+
7
+ let(:hash_preimage){ "a" * 32 }
8
+ let(:hash){ Digest::SHA256.digest(hash_preimage) }
9
+
10
+ it "raises an argument error when not provided a 32-byte string" do
11
+ expect{subject.hash_x("hello world")}.to raise_error(ArgumentError)
12
+ expect{subject.hash_x("")}.to raise_error(ArgumentError)
13
+ expect{subject.hash_x("a" * 31)}.to raise_error(ArgumentError)
14
+ expect{subject.hash_x("a" * 33)}.to raise_error(ArgumentError)
15
+ expect{subject.hash_x([0] * 32)}.to raise_error(ArgumentError)
16
+
17
+ end
18
+
19
+ it "creates a HashX signer key" do
20
+ sk = subject.hash_x(hash_preimage)
21
+ expect(sk.switch).to eq(Stellar::SignerKeyType.signer_key_type_hash_x)
22
+ expect(sk.value).to be_an_instance_of(String)
23
+ expect(sk.value).to eq(hash)
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xdr
@@ -414,6 +414,7 @@ files:
414
414
  - spec/lib/stellar/operation_spec.rb
415
415
  - spec/lib/stellar/path_payment_result_spec.rb
416
416
  - spec/lib/stellar/price_spec.rb
417
+ - spec/lib/stellar/signer_key_spec.rb
417
418
  - spec/lib/stellar/thresholds_spec.rb
418
419
  - spec/lib/stellar/transaction_envelope_spec.rb
419
420
  - spec/lib/stellar/transaction_spec.rb
@@ -465,6 +466,7 @@ test_files:
465
466
  - spec/lib/stellar/operation_spec.rb
466
467
  - spec/lib/stellar/path_payment_result_spec.rb
467
468
  - spec/lib/stellar/price_spec.rb
469
+ - spec/lib/stellar/signer_key_spec.rb
468
470
  - spec/lib/stellar/thresholds_spec.rb
469
471
  - spec/lib/stellar/transaction_envelope_spec.rb
470
472
  - spec/lib/stellar/transaction_spec.rb