mixin_bot 0.11.2 → 0.12.0

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: 630485777ae51872c9c3f5835375f63bc192918dfd354c9ac2d2346b1fcf1835
4
- data.tar.gz: fbcc1ca362beed41d977e2a9f6e0ebdf1c23fc0ee1ee373593372b221e6d0a43
3
+ metadata.gz: 5281229704ca2a0c90428a5f74d6d581bc79e19fe50b842ef1b517524aa206c6
4
+ data.tar.gz: 8e3961405502a068167665c596cf3d1b97a13e3fe9d5c0a217213db50317cc3f
5
5
  SHA512:
6
- metadata.gz: 37ee5ff2ecd52af503fa3d2ae49fc1ea730201b34ab99d9c184cab3d914bb565b245940b4df67d2801615a144f3daedb13ff4e921c597e11b0c8e4b18b017457
7
- data.tar.gz: b77cb941c1a9dac7abb840190a333eda86b8a2536a876ea81ff2471d2951ba867ded88ae6a3dfc36fb803dfbd7898f8a0bbadf43cfd01336b050f9c7ee751750
6
+ metadata.gz: d87f1bb6e3079edd9a5a0759a61396aaa1c886793362fd759f5f191926b16deb0bbbee497fc9f9b534ea769780a2807264518725ab4747e9c6e864651d5bb574
7
+ data.tar.gz: 61af8a4a4dc9b1521dd4e3e47bb228605325abd4f3717e5ac8df928eb2314e00548a1b65c88eecf5a7417992d3318cd6eea0fb596404df83d2dc62123c972f5d
@@ -52,6 +52,56 @@ module MixinBot
52
52
  scope: scope
53
53
  )
54
54
  end
55
+
56
+ def authorize_code(**kwargs)
57
+ path = '/oauth/authorize'
58
+ data = authorization_data(
59
+ kwargs[:user_id],
60
+ kwargs[:scope] || ['PROFILE:READ']
61
+ )
62
+
63
+ payload = {
64
+ authorization_id: data['authorization_id'],
65
+ scopes: data['scopes'],
66
+ pin_base64: encrypt_pin(kwargs[:pin])
67
+ }
68
+
69
+ access_token = kwargs[:access_token]
70
+ access_token ||= access_token('POST', path, payload.to_json)
71
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
72
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
73
+ end
74
+
75
+ def authorization_data(user_id, scope = ['PROFILE:READ'])
76
+ @_client_id = user_id
77
+ @_scope = scope.join(' ')
78
+ EM.run do
79
+ start_blaze_connect do
80
+ def on_open(ws, event)
81
+ ws.send write_ws_message(
82
+ action: 'REFRESH_OAUTH_CODE',
83
+ params: {
84
+ client_id: @_client_id,
85
+ scope: @_scope,
86
+ authorization_id: '',
87
+ code_challenge: ''
88
+ }
89
+ )
90
+ end
91
+
92
+ def on_message(ws, event)
93
+ raw = JSON.parse read_ws_message(event.data)
94
+ @_data = raw['data']
95
+ ws.close
96
+ end
97
+
98
+ def on_close(ws, event)
99
+ EM.stop_event_loop
100
+ end
101
+ end
102
+ end
103
+ @_data
104
+ end
55
105
  end
56
106
  end
57
107
  end
@@ -49,5 +49,23 @@ module MixinBot
49
49
 
50
50
  log res['data']
51
51
  end
52
+
53
+ desc 'authcode', 'code to authorize other mixin account'
54
+ option :keystore, type: :string, aliases: '-k', required: true, desc: 'keystore or keystore.json file path'
55
+ option :client_id, type: :string, required: true, aliases: '-c', desc: "client_id of bot to authorize"
56
+ option :scope, type: :array, default: ['PROFILE:READ'], aliases: '-s', desc: 'scope to authorize'
57
+ option :pin, type: :string, required: true, aliases: '-p', desc: 'pin'
58
+ def authcode
59
+ res = {}
60
+ CLI::UI::Spinner.spin("POST /oauth/authorize") do |_spinner|
61
+ res =
62
+ api_instance.authorize_code(
63
+ user_id: options[:client_id],
64
+ scope: options[:scope],
65
+ pin: options[:pin]
66
+ )
67
+ end
68
+ log res['data']
69
+ end
52
70
  end
53
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.11.2'
4
+ VERSION = '0.12.0'
5
5
  end
data/lib/mvm/registry.rb CHANGED
@@ -9,15 +9,48 @@ module MVM
9
9
  @registry = Eth::Contract.from_abi name: 'Registry', address: registry_address, abi: File.open(File.expand_path('./abis/registry.json', __dir__)).read
10
10
  end
11
11
 
12
- def asset(asset_id)
12
+ def pid
13
+ hex = @rpc.call(@registry, 'PID').to_s(16)
14
+ MixinBot::Utils::UUID.new(hex:hex).unpacked
15
+ end
16
+
17
+ def version
18
+ @rpc.call @registry, 'VERSION'
19
+ end
20
+
21
+ def asset_from_contract(contract)
22
+ hex = @rpc.call(@registry, 'assets', contract).to_s(16)
23
+ MixinBot::Utils::UUID.new(hex:hex).unpacked
24
+ end
25
+
26
+ def users_from_contract(contract)
27
+ bytes = @rpc.call(@registry, 'users', contract).bytes
28
+ members = []
29
+ length = bytes.shift(2).reverse.pack('C*').unpack1('S*')
30
+ length.times do
31
+ members << MixinBot::Utils::UUID.new(raw: bytes.shift(16).pack('C*')).unpacked
32
+ end
33
+ threshold = bytes.shift(2).reverse.pack('C*').unpack1('S*')
34
+ {
35
+ members: members,
36
+ threshold: threshold
37
+ }.with_indifferent_access
38
+ end
39
+
40
+ def user_from_contract(contract)
41
+ group = users_from_contract contract
42
+ group[:members].first
43
+ end
44
+
45
+ def contract_from_asset(asset_id)
13
46
  @rpc.call @registry, 'contracts', asset_id.gsub('-', '').to_i(16)
14
47
  end
15
48
 
16
- def user(user_id)
17
- multisig [user_id], 1
49
+ def contract_from_user(user_id)
50
+ contract_from_multisig [user_id], 1
18
51
  end
19
52
 
20
- def multisig(user_ids, threshold)
53
+ def contract_from_multisig(user_ids, threshold)
21
54
  bytes = []
22
55
  bytes += MixinBot::Utils.encode_int(user_ids.length)
23
56
  bytes += [user_ids.sort.join('').gsub('-', '')].pack('H*').bytes
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.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2023-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -347,7 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
347
  - !ruby/object:Gem::Version
348
348
  version: '0'
349
349
  requirements: []
350
- rubygems_version: 3.3.4
350
+ rubygems_version: 3.4.2
351
351
  signing_key:
352
352
  specification_version: 4
353
353
  summary: An API wrapper for Mixin Nexwork