lbd_sdk 0.1.2 → 0.1.3
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/.gitignore +2 -1
- data/.rubocop.yml +3 -0
- data/.vscode/settings.json +7 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +3 -1
- data/README.md +60 -36
- data/lib/lbd_sdk/client.rb +514 -151
- data/lib/lbd_sdk/hash_converter.rb +17 -0
- data/lib/lbd_sdk/http_client.rb +3 -7
- data/lib/lbd_sdk/request.rb +267 -190
- data/lib/lbd_sdk/request_body_flattener.rb +10 -6
- data/lib/lbd_sdk/request_param_validator.rb +31 -0
- data/lib/lbd_sdk/signature_generator.rb +36 -16
- data/lib/lbd_sdk/version.rb +1 -1
- data/package-lock.json +53 -0
- data/package.json +5 -0
- metadata +6 -2
|
@@ -19,14 +19,18 @@ module LbdSdk
|
|
|
19
19
|
(l_key_value.keys | elm.keys).each do |lkey|
|
|
20
20
|
l_value = ''
|
|
21
21
|
l_value = elm[lkey] if elm.keys.include?(lkey)
|
|
22
|
-
l_key_value[lkey] =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
l_key_value[lkey] =
|
|
23
|
+
if l_key_value.keys.include?(lkey)
|
|
24
|
+
"#{l_key_value[lkey]},#{l_value}"
|
|
25
|
+
else
|
|
26
|
+
"#{',' * i}#{l_value}"
|
|
27
|
+
end
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
|
-
l_key_value
|
|
30
|
+
l_key_value
|
|
31
|
+
.sort
|
|
32
|
+
.map { |lkey, lvalue| "#{key}.#{lkey}=#{lvalue}" }
|
|
33
|
+
.join('&')
|
|
30
34
|
end
|
|
31
35
|
end
|
|
32
36
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LbdSdk
|
|
4
|
+
module RequestParamValidator
|
|
5
|
+
WALLET_ADDRESS_REGEX = '^t?link[a-zA-Z0-9]{39}$'
|
|
6
|
+
TOKEN_NAME_REGEX = '^[a-zA-Z0-9]{3,20}$'
|
|
7
|
+
SYMBOL_NAME_REGEX = '^[A-Z][A-Z0-9]{1,4}$'
|
|
8
|
+
NUMBER_FORMAT_REGEX = '^\d+$'
|
|
9
|
+
BASE_URI_OR_EMPTY_REGEX = '^(^(https:\/\/)[\w\.\-\~\/]+(:[0-9]{1,5})?\/$)?$'
|
|
10
|
+
|
|
11
|
+
def is_valid_wallet_address(wallet_address)
|
|
12
|
+
wallet_address.to_s.match?(/#{WALLET_ADDRESS_REGEX}/)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def is_valid_token_name(name)
|
|
16
|
+
name.to_s.match?(/#{TOKEN_NAME_REGEX}/)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def is_valid_symbol(symbol)
|
|
20
|
+
symbol.to_s.match?(/#{SYMBOL_NAME_REGEX}/)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def is_valid_initial_supply(initial_supply)
|
|
24
|
+
initial_supply.to_s.match?(/#{NUMBER_FORMAT_REGEX}/)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def is_valid_base_uri(base_uri)
|
|
28
|
+
base_uri.to_s.match?(/#{BASE_URI_OR_EMPTY_REGEX}/)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -5,30 +5,50 @@ require 'openssl'
|
|
|
5
5
|
|
|
6
6
|
module LbdSdk
|
|
7
7
|
class SignatureGenerator
|
|
8
|
-
def generate(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
def generate(
|
|
9
|
+
secret:,
|
|
10
|
+
method:,
|
|
11
|
+
endpoint_path:,
|
|
12
|
+
timestamp:,
|
|
13
|
+
nonce:,
|
|
14
|
+
query_params: {},
|
|
15
|
+
body: {}
|
|
16
|
+
)
|
|
17
|
+
sign_target =
|
|
18
|
+
sign_target(
|
|
19
|
+
method: method,
|
|
20
|
+
endpoint_path: endpoint_path,
|
|
21
|
+
timestamp: timestamp,
|
|
22
|
+
nonce: nonce,
|
|
23
|
+
query_params: query_params.merge(body),
|
|
24
|
+
)
|
|
16
25
|
|
|
17
|
-
sign_target +=
|
|
26
|
+
sign_target +=
|
|
27
|
+
LbdSdk::RequestParamFlattener.new.flatten(
|
|
28
|
+
query_params,
|
|
29
|
+
) unless query_params.empty?
|
|
18
30
|
|
|
19
31
|
unless body.empty?
|
|
20
|
-
sign_target +=
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
sign_target +=
|
|
33
|
+
if query_params.empty?
|
|
34
|
+
RequestBodyFlattener.new.flatten(body)
|
|
35
|
+
else
|
|
36
|
+
"&#{RequestBodyFlattener.new.flatten(body)}"
|
|
37
|
+
end
|
|
25
38
|
end
|
|
26
39
|
|
|
27
|
-
raw_hmac =
|
|
40
|
+
raw_hmac =
|
|
41
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), secret, sign_target)
|
|
28
42
|
Base64.strict_encode64(raw_hmac).strip
|
|
29
43
|
end
|
|
30
44
|
|
|
31
|
-
def sign_target(
|
|
45
|
+
def sign_target(
|
|
46
|
+
method:,
|
|
47
|
+
endpoint_path:,
|
|
48
|
+
timestamp:,
|
|
49
|
+
nonce:,
|
|
50
|
+
query_params: {}
|
|
51
|
+
)
|
|
32
52
|
result = "#{nonce}#{timestamp}#{method}#{endpoint_path}"
|
|
33
53
|
query_params.empty? ? result : "#{result}?"
|
|
34
54
|
end
|
data/lib/lbd_sdk/version.rb
CHANGED
data/package-lock.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lbd_sdk_rb",
|
|
3
|
+
"lockfileVersion": 2,
|
|
4
|
+
"requires": true,
|
|
5
|
+
"packages": {
|
|
6
|
+
"": {
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@prettier/plugin-ruby": "^2.0.0"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"node_modules/@prettier/plugin-ruby": {
|
|
12
|
+
"version": "2.0.0",
|
|
13
|
+
"resolved": "https://registry.npmjs.org/@prettier/plugin-ruby/-/plugin-ruby-2.0.0.tgz",
|
|
14
|
+
"integrity": "sha512-pA0rjTi5J7cT86XPNhXp7CpdV2Tlyj5oqDIsnQRxMu2P7LY2KJI/pyOSM8pzTH8BgRyQfe1P1NPCcTwxUnUWtQ==",
|
|
15
|
+
"dev": true,
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"prettier": ">=2.3.0"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"node_modules/prettier": {
|
|
21
|
+
"version": "2.6.0",
|
|
22
|
+
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.0.tgz",
|
|
23
|
+
"integrity": "sha512-m2FgJibYrBGGgQXNzfd0PuDGShJgRavjUoRCw1mZERIWVSXF0iLzLm+aOqTAbLnC3n6JzUhAA8uZnFVghHJ86A==",
|
|
24
|
+
"dev": true,
|
|
25
|
+
"bin": {
|
|
26
|
+
"prettier": "bin-prettier.js"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=10.13.0"
|
|
30
|
+
},
|
|
31
|
+
"funding": {
|
|
32
|
+
"url": "https://github.com/prettier/prettier?sponsor=1"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@prettier/plugin-ruby": {
|
|
38
|
+
"version": "2.0.0",
|
|
39
|
+
"resolved": "https://registry.npmjs.org/@prettier/plugin-ruby/-/plugin-ruby-2.0.0.tgz",
|
|
40
|
+
"integrity": "sha512-pA0rjTi5J7cT86XPNhXp7CpdV2Tlyj5oqDIsnQRxMu2P7LY2KJI/pyOSM8pzTH8BgRyQfe1P1NPCcTwxUnUWtQ==",
|
|
41
|
+
"dev": true,
|
|
42
|
+
"requires": {
|
|
43
|
+
"prettier": ">=2.3.0"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"prettier": {
|
|
47
|
+
"version": "2.6.0",
|
|
48
|
+
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.0.tgz",
|
|
49
|
+
"integrity": "sha512-m2FgJibYrBGGgQXNzfd0PuDGShJgRavjUoRCw1mZERIWVSXF0iLzLm+aOqTAbLnC3n6JzUhAA8uZnFVghHJ86A==",
|
|
50
|
+
"dev": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
data/package.json
ADDED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lbd_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- YuheiNakasaka
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: LINE Blockchain Developer SDK for Ruby. This SDK is not official LINE
|
|
14
14
|
SDK.
|
|
@@ -37,12 +37,16 @@ files:
|
|
|
37
37
|
- lbd_sdk.gemspec
|
|
38
38
|
- lib/lbd_sdk.rb
|
|
39
39
|
- lib/lbd_sdk/client.rb
|
|
40
|
+
- lib/lbd_sdk/hash_converter.rb
|
|
40
41
|
- lib/lbd_sdk/http_client.rb
|
|
41
42
|
- lib/lbd_sdk/request.rb
|
|
42
43
|
- lib/lbd_sdk/request_body_flattener.rb
|
|
43
44
|
- lib/lbd_sdk/request_param_flattener.rb
|
|
45
|
+
- lib/lbd_sdk/request_param_validator.rb
|
|
44
46
|
- lib/lbd_sdk/signature_generator.rb
|
|
45
47
|
- lib/lbd_sdk/version.rb
|
|
48
|
+
- package-lock.json
|
|
49
|
+
- package.json
|
|
46
50
|
homepage: https://github.com/YuheiNakasaka/lbd_sdk_rb
|
|
47
51
|
licenses:
|
|
48
52
|
- MIT
|