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 +4 -4
- data/lib/stellar/base/version.rb +1 -1
- data/lib/stellar/signer_key.rb +11 -1
- data/spec/lib/stellar/signer_key_spec.rb +26 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bcdc8dd8ee4878dd631b013811444a2ae4cb55a3642beffc0e6a27edf78af0b
|
4
|
+
data.tar.gz: 46aa0348b3b4548af1ef03f1658990d479ae1f56c84bbb37c1b80017acb0e265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f67e3c1932f6ee43eb4b366f48873d19d6304115eb9ea4a47e4ca8dc17b0a25e2bc5129bc139ea94eb51e7ad3421d87ed1310cf758a88663b73096cb51c7ea6
|
7
|
+
data.tar.gz: f358ae8b004e7291e9beb56d12774a06ae60b1779b37583be1b6969aafbd5ecc2687e9ad86742674dba03dd5cb96649d93520c5ccc3bc36cff2c62d51c54ad81
|
data/lib/stellar/base/version.rb
CHANGED
data/lib/stellar/signer_key.rb
CHANGED
@@ -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.
|
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.
|
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-
|
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
|