scale_rb 0.1.6 → 0.1.7

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: 3c6c07616c5b65f7aee2b0504956231534d94cd3df9eba9320e4a22d2a38aed2
4
- data.tar.gz: f2f3572c5d7ed389d5772c6245fb2e02eb75d57cf5ff28b78a8db82642d47402
3
+ metadata.gz: 7d53289f0b86d457c262f850a693fd75c8c007fe6fe6fb716241d30897c7f57c
4
+ data.tar.gz: 3784af581e51a87e7bdc10d6da633d719189e328f0d373ddfb93f1d120e6a44e
5
5
  SHA512:
6
- metadata.gz: 1709366a718feafae82a60b5a5aeb05e5e78fbc3160c151de66b2be25e62ad3f6031c50db0097cc1880c00ec263962f45b4cf3fcb6f4ccd0d13ab48ce9b84976
7
- data.tar.gz: 231963a7fc17cc7d25ec5aded79120f11733e97d81edf58f4f2fc31edbb11865b435bd286b9817db744d98bad8751433eb68e809d567f9590d5ee70c5687b97d
6
+ metadata.gz: a6fa663c9058b64cb9b5f77450cfddf2eac1ddd582ce1c56445d0d255bddd479339b644f95cb436cb53e5e1e46698593dc862e7a6d6e77515ea17798427ec029
7
+ data.tar.gz: baf73201617384641f980d6aa8d83650edc483a60969c240c78ef935f22fce267b5084e9de30487a5b4a79bc4333f1b240f00003991ded04e3b32c94bca3df9d
data/Gemfile.lock CHANGED
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scale_rb (0.1.6)
4
+ scale_rb (0.1.7)
5
+ base58
5
6
  blake2b_rs (~> 0.1.4)
6
7
  xxhash
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
12
+ base58 (0.2.3)
11
13
  blake2b_rs (0.1.4)
12
14
  ffi (~> 1.0)
13
15
  thermite (~> 0)
data/README.md CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  *WARNING: UNDER DEVELOPMENT*
4
4
 
5
- * Only support metadata v14.
6
- * Http & WebSocket client helper. No Client in this repo.
7
-
8
5
  ## Installation
9
6
 
10
7
  Add this line to your application's Gemfile:
data/exe/metadata CHANGED
@@ -6,7 +6,7 @@ require 'json'
6
6
  require 'optparse'
7
7
 
8
8
  def print_metadata(url, at = nil)
9
- puts JSON.pretty_generate(HttpClient.get_metadata(url, at))
9
+ puts JSON.pretty_generate(ScaleRb::HttpClient.get_metadata(url, at))
10
10
  end
11
11
 
12
12
  # ./bin/metadata http://g2.dev.darwinia.network:2234 -b 0x23ebddd6519aaf1b7fc916c3709af13d7a4010943fb53038406581171000a58e
@@ -31,10 +31,10 @@ else
31
31
  block_hash = @options[:block]
32
32
  else
33
33
  block_number = @options[:block].to_i
34
- block_hash = HttpClient.chain_getBlockHash url, block_number
34
+ block_hash = ScaleRb::HttpClient.chain_getBlockHash url, block_number
35
35
  end
36
36
  else
37
- block_hash = HttpClient.chain_getBlockHash url
37
+ block_hash = ScaleRb::HttpClient.chain_getBlockHash url
38
38
  end
39
39
 
40
40
  print_metadata url, block_hash
data/lib/address.rb ADDED
@@ -0,0 +1,95 @@
1
+ require 'base58'
2
+
3
+ # Warning: Just for test
4
+ class Address
5
+ SS58_PREFIX = 'SS58PRE'
6
+
7
+ TYPES = [
8
+ # Polkadot Live (SS58, AccountId)
9
+ 0, 1,
10
+ # Polkadot Canary (SS58, AccountId)
11
+ 2, 3,
12
+ # Kulupu (SS58, Reserved)
13
+ 16, 17,
14
+ # Darwinia Live
15
+ 18,
16
+ # Dothereum (SS58, AccountId)
17
+ 20, 21,
18
+ # Generic Substrate wildcard (SS58, AccountId)
19
+ 42, 43,
20
+
21
+ # Schnorr/Ristretto 25519 ("S/R 25519") key
22
+ 48,
23
+ # Edwards Ed25519 key
24
+ 49,
25
+ # ECDSA SECP256k1 key
26
+ 50,
27
+
28
+ # Reserved for future address format extensions.
29
+ *64..255
30
+ ]
31
+
32
+ class << self
33
+
34
+ def array_to_hex_string(arr)
35
+ body = arr.map { |i| i.to_s(16).rjust(2, '0') }.join
36
+ "0x#{body}"
37
+ end
38
+
39
+ def decode(address, addr_type = 42, ignore_checksum = true)
40
+ decoded = Base58.base58_to_binary(address, :bitcoin)
41
+ is_pubkey = decoded.size == 35
42
+
43
+ size = decoded.size - ( is_pubkey ? 2 : 1 )
44
+
45
+ prefix = decoded[0, 1].unpack("C*").first
46
+
47
+ raise "Invalid address type" unless TYPES.include?(addr_type)
48
+
49
+ hash_bytes = make_hash(decoded[0, size])
50
+ if is_pubkey
51
+ is_valid_checksum = decoded[-2].unpack("C*").first == hash_bytes[0] && decoded[-1].unpack("C*").first == hash_bytes[1]
52
+ else
53
+ is_valid_checksum = decoded[-1].unpack("C*").first == hash_bytes[0]
54
+ end
55
+
56
+ # raise "Invalid decoded address checksum" unless is_valid_checksum && ignore_checksum
57
+
58
+ decoded[1...size].unpack("H*").first
59
+ end
60
+
61
+
62
+ def encode(pubkey, addr_type = 42)
63
+ pubkey = pubkey[2..-1] if pubkey =~ /^0x/i
64
+ key = [pubkey].pack("H*")
65
+
66
+ u8_array = key.bytes
67
+
68
+ u8_array.unshift(addr_type)
69
+
70
+ bytes = make_hash(u8_array.pack("C*"))
71
+
72
+ checksum = bytes[0, key.size == 32 ? 2 : 1]
73
+
74
+ u8_array.push(*checksum)
75
+
76
+ input = u8_array.pack("C*")
77
+
78
+ Base58.binary_to_base58(input, :bitcoin)
79
+ end
80
+
81
+ def make_hash(body)
82
+ Blake2b.hex("#{SS58_PREFIX}#{body}".bytes, 64)
83
+ end
84
+
85
+ def is_ss58_address?(address)
86
+ begin
87
+ decode(address)
88
+ rescue
89
+ return false
90
+ end
91
+ return true
92
+ end
93
+
94
+ end
95
+ end
@@ -1,3 +1,3 @@
1
1
  module ScaleRb
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
data/lib/scale_rb.rb CHANGED
@@ -28,6 +28,8 @@ require 'client/abstract_ws_client'
28
28
  # get registry from config
29
29
  require 'registry'
30
30
 
31
+ require 'address'
32
+
31
33
  module ScaleRb
32
34
  class << self
33
35
  attr_writer :logger
data/scale_rb.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  # for hashers
29
29
  spec.add_dependency 'blake2b_rs', '~> 0.1.4'
30
30
  spec.add_dependency 'xxhash'
31
+ spec.add_dependency "base58"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scale_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aki Wu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-01 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blake2b_rs
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: base58
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Ruby implementation of the parity SCALE data format
42
56
  email:
43
57
  - wuminzhe@gmail.com
@@ -59,6 +73,7 @@ files:
59
73
  - bin/console
60
74
  - bin/setup
61
75
  - exe/metadata
76
+ - lib/address.rb
62
77
  - lib/client/abstract_ws_client.rb
63
78
  - lib/client/http_client.rb
64
79
  - lib/client/rpc_request_builder.rb