mixin_sdk 0.1.1
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 +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mixin_sdk.rb +115 -0
- data/lib/mixin_sdk/version.rb +3 -0
- data/mixin_sdk-0.1.0.gem +0 -0
- data/mixin_sdk.gemspec +28 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad99167dcf5ba2f43ff62939b864311a99fcbbc38f202f5a52cfe627eea373ef
|
4
|
+
data.tar.gz: 9a85ccb2d6f1ddaf909d54b067d23d22258634b8d363aa93f0a1a6e65eff50bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d1616c8aa937502736e5b36b54eb8c6af53ce120122a1c171346d307762dc0d54c44db9de9b60183040d37f6f3900291d617788a4e1df151dde988c9675ed13
|
7
|
+
data.tar.gz: 1cdfc3998e7e7a630a801ed6263a6cd62cd3ab356c573696634290cae045fb5497e1f513b867cfc51541a3cf33505b59e04ac628cfb156cd5d936abbb1e54c78
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at xue.shaojie@biaotutech.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 xueshaojie
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# MixinSdk
|
2
|
+
|
3
|
+
Ruby版本的MixinApi
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'mixin_sdk', github: 'xueshaojie/mixin_sdk', branch: 'master'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
``` ruby
|
15
|
+
$ gem install mixin_sdk
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
如果使用rails可以放到 config/initializers/mixin_sdk.rb
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
MixinSdk.configuration do |config|
|
23
|
+
config.client_id = your_client_id
|
24
|
+
config.session_id = your_session_id
|
25
|
+
config.private_key = your_private_key
|
26
|
+
config.pin_token = your_pin_token
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
如果不是rails中
|
31
|
+
```ruby
|
32
|
+
require 'mixin_sdk'
|
33
|
+
|
34
|
+
MixinSdk.configuration do |config|
|
35
|
+
config.client_id = your_client_id
|
36
|
+
config.session_id = your_session_id
|
37
|
+
config.private_key = your_private_key
|
38
|
+
config.pin_token = your_pin_token
|
39
|
+
end
|
40
|
+
```
|
41
|
+
使用示例 get方法的示例
|
42
|
+
```ruby
|
43
|
+
def read_profile
|
44
|
+
MixinSdk.mixin("get", "me")
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_profile
|
48
|
+
MixinSdk.mixin("get", "assets")
|
49
|
+
end
|
50
|
+
```
|
51
|
+
使用示例 post方法的示例
|
52
|
+
```ruby
|
53
|
+
def update_profile
|
54
|
+
options = {
|
55
|
+
full_name: "价格提醒助手"
|
56
|
+
}.to_json
|
57
|
+
MixinSdk.mixin("post", "me", options)
|
58
|
+
end
|
59
|
+
|
60
|
+
def tran_to_user
|
61
|
+
options = {
|
62
|
+
asset_id: "965e5c6e-434c-3fa9-b780-c50f43cd955c",
|
63
|
+
opponent_id: "c4d975b4-36ee-4ff5-8e08-13a86d495904",
|
64
|
+
amount: "1",
|
65
|
+
pin: MixinSdk.encrypt_pin("123456"), # pin_code = "123456"
|
66
|
+
trace_id: SecureRandom.uuid,
|
67
|
+
memo: "transfer"
|
68
|
+
}.to_json
|
69
|
+
MixinSdk.mixin("post", "transfers", options)
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
需要结合Mixin的开发文档来使用。例如,查看接口名称、请求类型、参数。
|
74
|
+
## References
|
75
|
+
[Mixin开发文档](https://developers.mixin.one/api)
|
76
|
+
[mixin_bot(ruby)](https://github.com/an-lee/mixin_bot)
|
77
|
+
[mixin-node (nodejs)](https://github.com/virushuo/mixin-node)
|
78
|
+
## License
|
79
|
+
|
80
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mixin_sdk"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/mixin_sdk.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require "mixin_sdk/version"
|
2
|
+
require 'securerandom'
|
3
|
+
require 'digest'
|
4
|
+
require 'jwt'
|
5
|
+
require 'jose'
|
6
|
+
require 'json'
|
7
|
+
require 'httparty'
|
8
|
+
require 'openssl'
|
9
|
+
require 'base64'
|
10
|
+
|
11
|
+
module MixinSdk
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :client_id, :session_id, :private_key, :pin_token
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@client_id = ''
|
18
|
+
@session_id = ''
|
19
|
+
@private_key = ''
|
20
|
+
@pin_token = ''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
|
26
|
+
attr_writer :configuration
|
27
|
+
|
28
|
+
def configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure
|
33
|
+
yield(configuration)
|
34
|
+
end
|
35
|
+
|
36
|
+
def jwt_token(method_name, uri, body)
|
37
|
+
now_time = Time.now.to_i
|
38
|
+
sign = method_name == "POST" ? "POST/#{uri}#{body}" : "GET/#{uri}"
|
39
|
+
payload = {
|
40
|
+
uid: configuration.client_id,
|
41
|
+
sid: configuration.session_id,
|
42
|
+
iat: now_time,
|
43
|
+
exp: now_time + 3600,
|
44
|
+
jti: SecureRandom.uuid,
|
45
|
+
sig: Digest::SHA256.hexdigest(sign)
|
46
|
+
}
|
47
|
+
rsa_private = OpenSSL::PKey::RSA.new(configuration.private_key)
|
48
|
+
JWT.encode(payload, rsa_private, 'RS512')
|
49
|
+
end
|
50
|
+
|
51
|
+
def mixin(method_type, method_name, body = '')
|
52
|
+
method_type = method_type.upcase
|
53
|
+
return p "没有此请求类型" unless ["GET", "POST"].include?(method_type)
|
54
|
+
|
55
|
+
url = 'https://api.mixin.one/' + method_name
|
56
|
+
token = jwt_token(method_type, method_name, body == '' ? '' : body)
|
57
|
+
|
58
|
+
if method_type == "GET"
|
59
|
+
result = HTTParty.get(url, headers:{'Authorization' => 'Bearer ' + token, 'Content-Type' => 'application/json'})
|
60
|
+
else
|
61
|
+
result = HTTParty.post(url, headers:{'Authorization' => 'Bearer '+ token, 'Content-Type' => 'application/json'}, body: body)
|
62
|
+
end
|
63
|
+
response = result.parsed_response
|
64
|
+
response["error"] ? response["error"]["description"] : response["data"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def encrypt_pin(pin_code)
|
68
|
+
pin_token = Base64.decode64(configuration.pin_token)
|
69
|
+
private_key = OpenSSL::PKey::RSA.new(configuration.private_key)
|
70
|
+
aes_key = JOSE::JWA::PKCS1::rsaes_oaep_decrypt('SHA256', pin_token, private_key, configuration.session_id)
|
71
|
+
now_time = Time.now.to_i
|
72
|
+
zero_time = now_time % 0x100
|
73
|
+
one_time = (now_time % 0x10000) >> 8
|
74
|
+
two_time = (now_time % 0x1000000) >> 16
|
75
|
+
three_time = (now_time % 0x100000000) >> 24
|
76
|
+
time_string = zero_time.chr + one_time.chr + two_time.chr + three_time.chr + "\0\0\0\0"
|
77
|
+
encrypt_content = pin_code + time_string + time_string
|
78
|
+
pad_count = 16 - encrypt_content.length % 16
|
79
|
+
|
80
|
+
if pad_count > 0
|
81
|
+
padded_content = encrypt_content + pad_count.chr * pad_count
|
82
|
+
else
|
83
|
+
padded_content = encrypt_content
|
84
|
+
end
|
85
|
+
|
86
|
+
alg = "AES-256-CBC"
|
87
|
+
aes = OpenSSL::Cipher.new(alg)
|
88
|
+
iv = OpenSSL::Cipher.new(alg).random_iv
|
89
|
+
aes.encrypt
|
90
|
+
aes.key = aes_key
|
91
|
+
aes.iv = iv
|
92
|
+
cipher = aes.update(padded_content)
|
93
|
+
msg = iv + cipher
|
94
|
+
return Base64.strict_encode64 msg
|
95
|
+
end
|
96
|
+
|
97
|
+
def decrypt_pin(msg)
|
98
|
+
msg = Base64.strict_decode64 msg
|
99
|
+
pin_token = Base64.decode64(configuration.pin_token)
|
100
|
+
private_key = OpenSSL::PKey::RSA.new(configuration.private_key)
|
101
|
+
iv = msg[0..15]
|
102
|
+
cipher = msg[16..47]
|
103
|
+
aes_key = JOSE::JWA::PKCS1::rsaes_oaep_decrypt('SHA256', pin_token, private_key, configuration.session_id)
|
104
|
+
alg = "AES-256-CBC"
|
105
|
+
decode_cipher = OpenSSL::Cipher.new(alg)
|
106
|
+
decode_cipher.decrypt
|
107
|
+
decode_cipher.iv = iv
|
108
|
+
decode_cipher.key = aes_key
|
109
|
+
plain = decode_cipher.update(cipher)
|
110
|
+
return plain
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/mixin_sdk-0.1.0.gem
ADDED
Binary file
|
data/mixin_sdk.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mixin_sdk/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mixin_sdk"
|
8
|
+
spec.version = MixinSdk::VERSION
|
9
|
+
spec.authors = ["xueshaojie"]
|
10
|
+
spec.email = ["xue.shaojie@biaotutech.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Write a short summary, because RubyGems requires one.}
|
13
|
+
spec.description = %q{Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/xueshaojie/mixin_sdk.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixin_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xueshaojie
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Write a longer description or delete this line.
|
42
|
+
email:
|
43
|
+
- xue.shaojie@biaotutech.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/mixin_sdk.rb
|
57
|
+
- lib/mixin_sdk/version.rb
|
58
|
+
- mixin_sdk-0.1.0.gem
|
59
|
+
- mixin_sdk.gemspec
|
60
|
+
homepage: https://github.com/xueshaojie/mixin_sdk.git
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.7.4
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Write a short summary, because RubyGems requires one.
|
84
|
+
test_files: []
|