tezos_client 1.2.2 → 1.2.3

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
  SHA256:
3
- metadata.gz: a1459f7dd534e408bd13520b14789b9f719a6cec9b004f5ab3ca00c151da1ac4
4
- data.tar.gz: 2aa7c36fc10c82537de03593e592703274daedcff36edec84130c98cc385098f
3
+ metadata.gz: 1edfdfe5f7332ebbe4ecafd4baa3f03998e02204e33f854d9f394ba84cbf98c3
4
+ data.tar.gz: 7544eba6b1a6d602b24025a5c2831c1e803f53f92ae5f0925daa05a0b2ef3167
5
5
  SHA512:
6
- metadata.gz: fa9dc95f337c4bbbda410392c03d6305c93ee8f4dfec1810f629c0143a4beb3ce88789f5c4eaa809ae572bb4871ad44b0e87d35071727f9800cc9167f290492f
7
- data.tar.gz: e625840ea65befc0adc6ece5e334d8e869daabbaa2e6a9fc51881dda0ba3971dcec2f0d3274968e07a7e9268e1af93469c1f70f1395fa3d773119e871ab55f2a
6
+ metadata.gz: 4a4e3ddacd06478d21821ce1e38ac5d731f2602d6cbca55e2440828de46c5933aaa8b77df00d3d989295ee325318ff53284725dc91d165ed32918cd2b3de9d8a
7
+ data.tar.gz: 980264f44b9761e4f7e716675a5775d1b2f3cbfd6de5d09024154c53000a1a95cc3c168efe259c1fd7b78d9a877d23a6c0fa4feea8a8bda942b753122cf73bc7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tezos_client (1.2.2)
4
+ tezos_client (1.2.3)
5
5
  active_interaction (~> 3.7)
6
6
  activesupport (~> 6.0.0)
7
7
  base58 (~> 0.2.3)
@@ -165,6 +165,22 @@ class TezosClient
165
165
  end
166
166
  end
167
167
 
168
+ # payload must be bytes
169
+ def check_signature(public_key:, signature:, payload:)
170
+ verify_key = RbNaCl::VerifyKey.new(decode_tz(public_key).to_bin)
171
+
172
+ bin_sig = decode_tz(signature).to_bin
173
+ payload_hash = RbNaCl::Hash::Blake2b.digest(ignore_0x(payload).to_bin, digest_size: 32)
174
+
175
+ verify_key.verify(bin_sig, payload_hash)
176
+ rescue RbNaCl::BadSignatureError
177
+ false
178
+ end
179
+
180
+ def check_signature!(public_key:, signature:, payload:)
181
+ check_signature(public_key: public_key, signature: signature, payload: payload) || raise(BadSignatureError)
182
+ end
183
+
168
184
  def operation_id(signed_operation_hex)
169
185
  hash = RbNaCl::Hash::Blake2b.digest(
170
186
  signed_operation_hex.to_bin,
@@ -220,5 +236,9 @@ class TezosClient
220
236
  RbNaCl::SigningKey.generate
221
237
  end
222
238
  end
239
+
240
+ def ignore_0x(payload)
241
+ payload.starts_with?("0x") ? payload[2..-1] : payload
242
+ end
223
243
  end
224
244
  end
@@ -23,6 +23,9 @@ class TezosClient
23
23
  class SmartPyError < SysCallError
24
24
  end
25
25
 
26
+ class BadSignatureError < StandardError
27
+ end
28
+
26
29
  class InvalidActivation < RpcRequestFailure
27
30
  attr_reader :pkh
28
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TezosClient
4
- VERSION = "1.2.2"
4
+ VERSION = "1.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tezos_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Michard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler