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 +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +0 -3
- data/exe/metadata +3 -3
- data/lib/address.rb +95 -0
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +2 -0
- data/scale_rb.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d53289f0b86d457c262f850a693fd75c8c007fe6fe6fb716241d30897c7f57c
|
4
|
+
data.tar.gz: 3784af581e51a87e7bdc10d6da633d719189e328f0d373ddfb93f1d120e6a44e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fa663c9058b64cb9b5f77450cfddf2eac1ddd582ce1c56445d0d255bddd479339b644f95cb436cb53e5e1e46698593dc862e7a6d6e77515ea17798427ec029
|
7
|
+
data.tar.gz: baf73201617384641f980d6aa8d83650edc483a60969c240c78ef935f22fce267b5084e9de30487a5b4a79bc4333f1b240f00003991ded04e3b32c94bca3df9d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
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
|
data/lib/scale_rb/version.rb
CHANGED
data/lib/scale_rb.rb
CHANGED
data/scale_rb.gemspec
CHANGED
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.
|
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-
|
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
|