mixin_bot 0.0.1.2 → 0.0.1.4
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 +5 -5
- data/lib/mixin_bot/api.rb +7 -2
- data/lib/mixin_bot/api/auth.rb +10 -9
- data/lib/mixin_bot/api/conversation.rb +21 -8
- data/lib/mixin_bot/api/me.rb +2 -2
- data/lib/mixin_bot/api/message.rb +54 -3
- data/lib/mixin_bot/api/pin.rb +2 -2
- data/lib/mixin_bot/api/snapshot.rb +27 -0
- data/lib/mixin_bot/api/transfer.rb +0 -7
- data/lib/mixin_bot/client.rb +1 -1
- data/lib/mixin_bot/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc2618a1deab474b441b98f81845094b3178d3f5123d73a33aaefd0cc82f6e0d
|
4
|
+
data.tar.gz: 0da61f7a15af136541318f8af9fa107a864f5b4cdbc6c45ce17c8bea0ae8ac74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a474915b84c4fea0086aba993b5b4e0f43744aaa64808cd0728c966ad5f5d7c1375d6525fcedc203ec6943b1d163a8a56a0dc32e34cff15cdf3f55e0c15b7eaa
|
7
|
+
data.tar.gz: fcf9a02b7eb85c63e959bc47ea9054b7901d05bc68950ab8a90c99d976b424178f31db2fef693eb94c191480ebe77e27a5a21d6a8d326cc5a7c12d70f7f3d921
|
data/lib/mixin_bot/api.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
require_relative './client'
|
2
2
|
require_relative './errors'
|
3
3
|
require_relative './api/auth'
|
4
|
+
require_relative './api/conversation'
|
4
5
|
require_relative './api/me'
|
6
|
+
require_relative './api/message'
|
5
7
|
require_relative './api/payment'
|
6
8
|
require_relative './api/pin'
|
9
|
+
require_relative './api/snapshot'
|
7
10
|
require_relative './api/transfer'
|
8
11
|
require_relative './api/user'
|
9
12
|
|
10
13
|
module MixinBot
|
11
14
|
class API
|
12
|
-
attr_reader :client_id, :client_secret, :session_id, :pin_token, :private_key
|
15
|
+
attr_reader :client_id, :client_secret, :session_id, :pin_token, :private_key
|
13
16
|
attr_reader :client
|
14
17
|
|
15
18
|
def initialize(options={})
|
@@ -18,14 +21,16 @@ module MixinBot
|
|
18
21
|
@session_id = options[:session_id] || MixinBot.session_id
|
19
22
|
@pin_token = Base64.decode64 options[:pin_token] || MixinBot.pin_token
|
20
23
|
@private_key = OpenSSL::PKey::RSA.new options[:private_key] || MixinBot.private_key
|
21
|
-
@scope = options[:scope] || MixinBot.scope || 'PROFILE:READ+PHONE:READ+ASSETS:READ'
|
22
24
|
@client = Client.new
|
23
25
|
end
|
24
26
|
|
25
27
|
include MixinBot::API::Auth
|
28
|
+
include MixinBot::API::Conversation
|
26
29
|
include MixinBot::API::Me
|
30
|
+
include MixinBot::API::Message
|
27
31
|
include MixinBot::API::Payment
|
28
32
|
include MixinBot::API::Pin
|
33
|
+
include MixinBot::API::Snapshot
|
29
34
|
include MixinBot::API::Transfer
|
30
35
|
include MixinBot::API::User
|
31
36
|
end
|
data/lib/mixin_bot/api/auth.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module MixinBot
|
2
2
|
class API
|
3
3
|
module Auth
|
4
|
-
def access_token(method, uri, body)
|
4
|
+
def access_token(method, uri, body, exp_in=10.minutes)
|
5
5
|
sig = Digest::SHA256.hexdigest (method + uri + body)
|
6
6
|
iat = Time.now.utc.to_i
|
7
|
-
exp = (Time.now.utc +
|
7
|
+
exp = (Time.now.utc + exp_in).to_i
|
8
8
|
jti = SecureRandom.uuid
|
9
9
|
payload = {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
uid: client_id,
|
11
|
+
sid: session_id,
|
12
|
+
iat: iat,
|
13
|
+
exp: exp,
|
14
|
+
jti: jti,
|
15
|
+
sig: sig
|
16
16
|
}
|
17
17
|
JWT.encode payload, private_key, 'RS512'
|
18
18
|
end
|
@@ -31,7 +31,8 @@ module MixinBot
|
|
31
31
|
return r['data']['access_token']
|
32
32
|
end
|
33
33
|
|
34
|
-
def request_oauth
|
34
|
+
def request_oauth(scope=nil)
|
35
|
+
scope ||= (MixinBot.scope || 'PROFILE:READ+PHONE:READ')
|
35
36
|
format('https://mixin.one/oauth/authorize?client_id=%s&scope=%s', client_id, scope)
|
36
37
|
end
|
37
38
|
end
|
@@ -1,12 +1,23 @@
|
|
1
1
|
module MixinBot
|
2
2
|
class API
|
3
3
|
module Conversation
|
4
|
-
def
|
4
|
+
def read_conversation(conversation_id)
|
5
|
+
path = format('/conversations/%s', conversation_id)
|
6
|
+
_access_token ||= self.access_token('GET', path, '')
|
7
|
+
authorization = format('Bearer %s', _access_token)
|
8
|
+
client.get(path, headers: { 'Authorization': authorization })
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_conversation_by_user_id(user_id)
|
12
|
+
conversation_id = unique_conversation_id(user_id)
|
13
|
+
return self.read_conversation(conversation_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_contact_conversation(user_id)
|
5
17
|
path = '/conversations'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
conversation_id: conversation_id,
|
18
|
+
payload = {
|
19
|
+
category: 'CONTACT',
|
20
|
+
conversation_id: unique_conversation_id(user_id),
|
10
21
|
participants: [
|
11
22
|
{
|
12
23
|
action: 'ADD',
|
@@ -15,13 +26,15 @@ module MixinBot
|
|
15
26
|
}
|
16
27
|
]
|
17
28
|
}
|
18
|
-
|
29
|
+
_access_token ||= self.access_token('POST', path, payload.to_json)
|
30
|
+
authorization = format('Bearer %s', _access_token)
|
31
|
+
client.post(path, headers: { 'Authorization': authorization }, json: payload)
|
19
32
|
end
|
20
33
|
|
21
34
|
def unique_conversation_id(user_id)
|
22
35
|
md5 = Digest::MD5.new
|
23
|
-
md5 << user_id
|
24
|
-
md5 << client_id
|
36
|
+
md5 << [user_id, client_id].min
|
37
|
+
md5 << [user_id, client_id].max
|
25
38
|
digest = md5.digest
|
26
39
|
digest_6 = (digest[6].ord & 0x0f | 0x30).chr
|
27
40
|
digest_8 = (digest[8].ord & 0x3f | 0x80).chr
|
data/lib/mixin_bot/api/me.rb
CHANGED
@@ -11,8 +11,8 @@ module MixinBot
|
|
11
11
|
def update_me(full_name, avatar_base64, access_token=nil)
|
12
12
|
path = '/me'
|
13
13
|
payload = {
|
14
|
-
|
15
|
-
|
14
|
+
full_name: full_name,
|
15
|
+
avatar_base64: avatar_base64
|
16
16
|
}
|
17
17
|
access_token ||= self.access_token('POST', path, payload.to_json)
|
18
18
|
authorization = format('Bearer %s', access_token)
|
@@ -1,6 +1,57 @@
|
|
1
1
|
module MixinBot
|
2
2
|
class API
|
3
3
|
module Message
|
4
|
+
def list_pending_message
|
5
|
+
write_message('LIST_PENDING_MESSAGES', {})
|
6
|
+
end
|
7
|
+
|
8
|
+
def acknowledge_message_receipt(message_id)
|
9
|
+
params = {
|
10
|
+
message_id: message_id,
|
11
|
+
status: 'READ'
|
12
|
+
}
|
13
|
+
write_message('ACKNOWLEDGE_MESSAGE_RECEIPT', params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def plain_text_message(conversation_id, text)
|
17
|
+
encoded_text = Base64.encode64 text
|
18
|
+
|
19
|
+
params = {
|
20
|
+
conversation_id: conversation_id,
|
21
|
+
category: 'PLAIN_TEXT',
|
22
|
+
status: 'SENT',
|
23
|
+
message_id: SecureRandom.uuid,
|
24
|
+
data: encoded_text
|
25
|
+
}
|
26
|
+
|
27
|
+
write_message('CREATE_MESSAGE', params)
|
28
|
+
end
|
29
|
+
|
30
|
+
def app_card_message
|
31
|
+
# TODO:
|
32
|
+
end
|
33
|
+
|
34
|
+
def app_button_group_message(conversation_id, recipient_id, options={})
|
35
|
+
options = options.with_indifferent_access
|
36
|
+
label = options[:label] || ''
|
37
|
+
color = options[:color] || '#467fcf'
|
38
|
+
action = options[:action] || ''
|
39
|
+
|
40
|
+
data = [{ label: label, color: color, action: action }]
|
41
|
+
encoded_data = Base64.encode64 data.to_json
|
42
|
+
|
43
|
+
params = {
|
44
|
+
conversation_id: conversation_id,
|
45
|
+
recipient_id: recipient_id,
|
46
|
+
category: 'APP_BUTTON_GROUP',
|
47
|
+
status: 'SENT',
|
48
|
+
message_id: SecureRandom.uuid,
|
49
|
+
data: encoded_data
|
50
|
+
}
|
51
|
+
|
52
|
+
write_message('CREATE_MESSAGE', params)
|
53
|
+
end
|
54
|
+
|
4
55
|
def read_message(data)
|
5
56
|
io = StringIO.new(data.pack('c*'), 'rb')
|
6
57
|
gzip = Zlib::GzipReader.new io
|
@@ -11,9 +62,9 @@ module MixinBot
|
|
11
62
|
|
12
63
|
def write_message(action, params)
|
13
64
|
msg = {
|
14
|
-
|
15
|
-
|
16
|
-
|
65
|
+
id: SecureRandom.uuid,
|
66
|
+
action: action,
|
67
|
+
params: params
|
17
68
|
}.to_json
|
18
69
|
|
19
70
|
io = StringIO.new 'wb'
|
data/lib/mixin_bot/api/pin.rb
CHANGED
@@ -17,7 +17,7 @@ module MixinBot
|
|
17
17
|
iv = msg[0..15]
|
18
18
|
cipher = msg[16..47]
|
19
19
|
aes_key = JOSE::JWA::PKCS1::rsaes_oaep_decrypt('SHA256', pin_token, private_key, session_id)
|
20
|
-
alg =
|
20
|
+
alg = 'AES-256-CBC'
|
21
21
|
decode_cipher = OpenSSL::Cipher.new(alg)
|
22
22
|
decode_cipher.decrypt
|
23
23
|
decode_cipher.iv = iv
|
@@ -42,7 +42,7 @@ module MixinBot
|
|
42
42
|
padded_content = encrypt_content
|
43
43
|
end
|
44
44
|
|
45
|
-
alg =
|
45
|
+
alg = 'AES-256-CBC'
|
46
46
|
aes = OpenSSL::Cipher.new(alg)
|
47
47
|
iv = OpenSSL::Cipher.new(alg).random_iv
|
48
48
|
aes.encrypt
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MixinBot
|
2
|
+
class API
|
3
|
+
module Snapshot
|
4
|
+
def read_snapshots(options)
|
5
|
+
options = options.with_indifferent_access
|
6
|
+
limit = options['limit']
|
7
|
+
offset = options['offset']
|
8
|
+
asset = options['asset']
|
9
|
+
order = options['order']
|
10
|
+
|
11
|
+
path = 'network/snapshots'
|
12
|
+
payload = {
|
13
|
+
limit: limit,
|
14
|
+
offset: offset,
|
15
|
+
asset: asset,
|
16
|
+
order: order
|
17
|
+
}
|
18
|
+
client.get(path, params: payload)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_snapshot(snapshot_id)
|
22
|
+
path = format('network/snapshots/%s', snapshot_id)
|
23
|
+
client.get(path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,13 +2,6 @@ module MixinBot
|
|
2
2
|
class API
|
3
3
|
module Transfer
|
4
4
|
def create_transfer(pin, options)
|
5
|
-
# data for test:
|
6
|
-
# asset_id = '965e5c6e-434c-3fa9-b780-c50f43cd955c'
|
7
|
-
# opponent_id = '7ed9292d-7c95-4333-aa48-a8c640064186'
|
8
|
-
# amount = '1'
|
9
|
-
# encrypted_pin = MixinBot.api_pin.encrypted_pin
|
10
|
-
# memo = 'test'
|
11
|
-
|
12
5
|
options = options.with_indifferent_access
|
13
6
|
|
14
7
|
asset_id = options.fetch('asset_id')
|
data/lib/mixin_bot/client.rb
CHANGED
@@ -23,7 +23,7 @@ module MixinBot
|
|
23
23
|
end
|
24
24
|
|
25
25
|
begin
|
26
|
-
response = HTTP.timeout(
|
26
|
+
response = HTTP.timeout(connect: 5, write: 5, read: 5).request(verb, uri, options)
|
27
27
|
rescue HTTP::Error => ex
|
28
28
|
Rails.logger.error format('%s (%s):', ex.class.name, ex.message)
|
29
29
|
Rails.logger.error ex.backtrace.join("\n")
|
data/lib/mixin_bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixin_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- an-lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/mixin_bot/api/message.rb
|
97
97
|
- lib/mixin_bot/api/payment.rb
|
98
98
|
- lib/mixin_bot/api/pin.rb
|
99
|
+
- lib/mixin_bot/api/snapshot.rb
|
99
100
|
- lib/mixin_bot/api/transfer.rb
|
100
101
|
- lib/mixin_bot/api/user.rb
|
101
102
|
- lib/mixin_bot/client.rb
|
@@ -120,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.6.14
|
124
|
+
rubygems_version: 3.0.2
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: An API wrapper for Mixin Nexwork
|