mixin_bot 3.0.3 → 3.1.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +12 -2
  3. data/CHANGELOG.md +135 -0
  4. data/README.md +3 -2
  5. data/docs/agent/cli.md +4 -2
  6. data/lib/mixin_bot/address.rb +73 -62
  7. data/lib/mixin_bot/api/attachment.rb +18 -8
  8. data/lib/mixin_bot/api/blaze.rb +7 -2
  9. data/lib/mixin_bot/api/blaze_async.rb +169 -4
  10. data/lib/mixin_bot/api/computer_api.rb +7 -7
  11. data/lib/mixin_bot/api/encrypted_message.rb +75 -52
  12. data/lib/mixin_bot/api/multisig.rb +9 -7
  13. data/lib/mixin_bot/api/pin.rb +9 -8
  14. data/lib/mixin_bot/api/tip.rb +1 -1
  15. data/lib/mixin_bot/api/transaction.rb +70 -41
  16. data/lib/mixin_bot/api/transfer.rb +3 -2
  17. data/lib/mixin_bot/api/user.rb +6 -6
  18. data/lib/mixin_bot/api.rb +1 -0
  19. data/lib/mixin_bot/bot_auth.rb +1 -1
  20. data/lib/mixin_bot/cli/schema.rb +2 -0
  21. data/lib/mixin_bot/cli.rb +9 -3
  22. data/lib/mixin_bot/client.rb +43 -19
  23. data/lib/mixin_bot/computer.rb +39 -23
  24. data/lib/mixin_bot/configuration.rb +48 -8
  25. data/lib/mixin_bot/invoice.rb +126 -77
  26. data/lib/mixin_bot/nfo.rb +54 -43
  27. data/lib/mixin_bot/proxy.rb +184 -0
  28. data/lib/mixin_bot/transaction/decoder.rb +201 -138
  29. data/lib/mixin_bot/transaction/encoder.rb +156 -118
  30. data/lib/mixin_bot/transaction.rb +15 -1
  31. data/lib/mixin_bot/utils/address.rb +1 -1
  32. data/lib/mixin_bot/utils/amount.rb +25 -0
  33. data/lib/mixin_bot/utils/base58.rb +97 -0
  34. data/lib/mixin_bot/utils/crypto.rb +188 -56
  35. data/lib/mixin_bot/utils/cursor.rb +147 -0
  36. data/lib/mixin_bot/utils/decoder.rb +111 -6
  37. data/lib/mixin_bot/utils/encoder.rb +90 -21
  38. data/lib/mixin_bot/utils/options.rb +26 -0
  39. data/lib/mixin_bot/utils/sodium.rb +169 -0
  40. data/lib/mixin_bot/utils.rb +17 -2
  41. data/lib/mixin_bot/uuid.rb +6 -13
  42. data/lib/mixin_bot/version.rb +1 -1
  43. data/lib/mixin_bot.rb +1 -3
  44. data/lib/mvm/client.rb +44 -9
  45. data/lib/mvm/registry.rb +45 -17
  46. data/llms.txt +1 -1
  47. metadata +6 -44
  48. data/lib/mixin_bot/transaction/buffer.rb +0 -34
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'async'
3
4
  require 'async/http/endpoint'
4
5
  require 'async/http/protocol/http11'
5
6
  require 'async/websocket/client'
7
+ require 'io/endpoint/generic'
8
+ require 'openssl'
9
+ require 'socket'
10
+ require 'uri'
6
11
 
7
12
  module MixinBot
8
13
  class API
@@ -27,6 +32,152 @@ module MixinBot
27
32
  # mirroring +blaze+. No per-IO read timeout by default: quiet-but-healthy
28
33
  # connections are legitimate; liveness is the caller's policy.
29
34
  module BlazeAsync
35
+ # Underlying IO endpoint that opens an HTTP/1.1 CONNECT tunnel through an
36
+ # HTTP/HTTPS proxy so +Async::HTTP::Endpoint+ can wrap the tunneled
37
+ # connection in TLS for +wss://+ targets.
38
+ class HttpConnectEndpoint < ::IO::Endpoint::Generic
39
+ MAX_HEADER_BYTES = 16_384
40
+
41
+ attr_reader :proxy, :authority
42
+
43
+ def initialize(proxy, authority, **)
44
+ super(**)
45
+ @proxy = proxy
46
+ @authority = authority
47
+ end
48
+
49
+ def to_s
50
+ "http-connect:#{@proxy.origin}->#{@authority}"
51
+ end
52
+
53
+ def inspect
54
+ "#<#{self.class} proxy=#{@proxy.origin} authority=#{@authority}>"
55
+ end
56
+
57
+ def connect(_wrapper = nil)
58
+ socket = open_tunnel
59
+ return socket unless block_given?
60
+
61
+ begin
62
+ yield socket
63
+ ensure
64
+ close_quietly(socket)
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def open_tunnel
71
+ proxy_opts = { alpn_protocols: Async::HTTP::Protocol::HTTP11.names }
72
+ proxy_opts[:timeout] = timeout if timeout
73
+
74
+ socket = Async::HTTP::Endpoint.parse(@proxy.origin, **proxy_opts).connect
75
+ begin
76
+ write_connect_request(socket)
77
+ read_connect_response!(socket)
78
+ rescue StandardError
79
+ close_quietly(socket)
80
+ raise
81
+ end
82
+
83
+ @proxy.https? ? bridge_ssl_socket(socket) : socket
84
+ end
85
+
86
+ def write_connect_request(socket)
87
+ lines = ["CONNECT #{@authority} HTTP/1.1"]
88
+ @proxy.connect_headers(@authority).each do |name, value|
89
+ lines << "#{name}: #{value}"
90
+ end
91
+ lines << '' << ''
92
+ write_all(socket, lines.join("\r\n"))
93
+ end
94
+
95
+ def write_all(socket, data)
96
+ bytes_written = 0
97
+ while bytes_written < data.bytesize
98
+ written = socket.write(data.byteslice(bytes_written..))
99
+ bytes_written += written
100
+ end
101
+ end
102
+
103
+ def read_connect_response!(socket)
104
+ buffer = +''
105
+ loop do
106
+ chunk = socket.readpartial(1)
107
+ buffer << chunk
108
+ raise MixinBot::HttpError, 'Proxy CONNECT response headers exceeded 16KB limit' if buffer.bytesize > MAX_HEADER_BYTES
109
+ break if buffer.end_with?("\r\n\r\n", "\n\n")
110
+ end
111
+
112
+ status_line = buffer.lines.first.to_s.strip
113
+ return if status_line.match?(%r{\AHTTP/1\.[01]\s+200\b}i)
114
+
115
+ raise MixinBot::HttpError, "Proxy CONNECT tunnel to #{@authority} failed: #{status_line}"
116
+ rescue EOFError
117
+ raise MixinBot::HttpError, "Proxy closed connection during CONNECT tunnel to #{@authority}"
118
+ end
119
+
120
+ # OpenSSL::SSL::SSLSocket rejects another SSLSocket as its underlying IO
121
+ # (TypeError: expected File), so an HTTPS proxy tunnel must be bridged
122
+ # over a Unix socket pair before the target SSL handshake wraps it.
123
+ def bridge_ssl_socket(ssl_socket)
124
+ head, tail = ::Socket.pair(::Socket::AF_UNIX, ::Socket::SOCK_STREAM)
125
+ state = { writer_finished: false, reader_task: nil }
126
+
127
+ pump_reader = lambda do |*|
128
+ pump_stream(ssl_socket, head)
129
+ ensure
130
+ close_write_quietly(head)
131
+ if state[:writer_finished]
132
+ close_quietly(head)
133
+ close_quietly(ssl_socket)
134
+ end
135
+ end
136
+
137
+ pump_writer = lambda do |*|
138
+ pump_stream(head, ssl_socket)
139
+ ensure
140
+ state[:writer_finished] = true
141
+ reader_task = state[:reader_task]
142
+ reader_task.stop if reader_task.respond_to?(:stop) && !reader_task.finished?
143
+ close_quietly(head)
144
+ close_quietly(ssl_socket)
145
+ end
146
+
147
+ if Async::Task.current?
148
+ parent = Async::Task.current
149
+ state[:reader_task] = parent.async(transient: true, &pump_reader)
150
+ parent.async(transient: true, &pump_writer)
151
+ else
152
+ Thread.new(&pump_reader)
153
+ Thread.new(&pump_writer)
154
+ end
155
+
156
+ tail
157
+ end
158
+
159
+ def pump_stream(source, dest)
160
+ loop do
161
+ chunk = source.readpartial(16_384)
162
+ write_all(dest, chunk)
163
+ end
164
+ rescue IOError, Errno::EPIPE, Errno::ECONNRESET, Errno::EBADF, OpenSSL::SSL::SSLError
165
+ nil
166
+ end
167
+
168
+ def close_write_quietly(io)
169
+ io.close_write unless io.closed?
170
+ rescue StandardError
171
+ nil
172
+ end
173
+
174
+ def close_quietly(io)
175
+ io.close unless io.closed?
176
+ rescue StandardError
177
+ nil
178
+ end
179
+ end
180
+
30
181
  # Returns the block-less +Client.connect+ connection, preserving
31
182
  # +blaze+'s "returns a client the caller drives" contract.
32
183
  #
@@ -41,14 +192,28 @@ module MixinBot
41
192
  def blaze_async(handler: Async::WebSocket::Connection, endpoint_options: {})
42
193
  access_token = access_token('GET', '/', '')
43
194
  authorization = format('Bearer %<access_token>s', access_token:)
44
-
45
- endpoint = Async::HTTP::Endpoint.parse(
46
- format('wss://%<host>s/', host: config.blaze_host),
195
+ url = format('wss://%<host>s/', host: config.blaze_host)
196
+ opts = {
47
197
  # Force the HTTP/1 upgrade path: avoids the RFC 8441 (h2 CONNECT)
48
198
  # route, which not every gateway negotiates the same way.
49
199
  alpn_protocols: Async::HTTP::Protocol::HTTP11.names,
50
200
  **endpoint_options
51
- )
201
+ }
202
+
203
+ endpoint =
204
+ if config.proxy_config
205
+ target_uri = URI.parse(url)
206
+ target_host = opts[:hostname] || target_uri.host
207
+ target_port = opts[:port] || target_uri.port || 443
208
+ tunnel = HttpConnectEndpoint.new(
209
+ config.proxy_config,
210
+ "#{target_host}:#{target_port}",
211
+ timeout: opts[:timeout]
212
+ )
213
+ Async::HTTP::Endpoint.parse(url, tunnel, **opts)
214
+ else
215
+ Async::HTTP::Endpoint.parse(url, **opts)
216
+ end
52
217
 
53
218
  Async::WebSocket::Client.connect(
54
219
  endpoint,
@@ -5,31 +5,31 @@ module MixinBot
5
5
  # Delegates to {MixinBot::Computer} for API surface parity with Go SDK.
6
6
  module ComputerApi
7
7
  def get_computer_info
8
- MixinBot::Computer.info
8
+ MixinBot::Computer.info(proxy: config.proxy_config)
9
9
  end
10
10
 
11
11
  def get_computer_user(addr)
12
- MixinBot::Computer.user(addr)
12
+ MixinBot::Computer.user(addr, proxy: config.proxy_config)
13
13
  end
14
14
 
15
15
  def get_computer_deployed_assets
16
- MixinBot::Computer.deployed_assets
16
+ MixinBot::Computer.deployed_assets(proxy: config.proxy_config)
17
17
  end
18
18
 
19
19
  def get_computer_system_call(id)
20
- MixinBot::Computer.system_call(id)
20
+ MixinBot::Computer.system_call(id, proxy: config.proxy_config)
21
21
  end
22
22
 
23
23
  def computer_deploy_external_asset(assets)
24
- MixinBot::Computer.deploy_external_assets(assets)
24
+ MixinBot::Computer.deploy_external_assets(assets, proxy: config.proxy_config)
25
25
  end
26
26
 
27
27
  def lock_computer_nonce_account(mix)
28
- MixinBot::Computer.lock_nonce_account(mix)
28
+ MixinBot::Computer.lock_nonce_account(mix, proxy: config.proxy_config)
29
29
  end
30
30
 
31
31
  def get_fee_on_xin_based_on_sol(sol_amount)
32
- MixinBot::Computer.fee_on_xin_from_sol(sol_amount)
32
+ MixinBot::Computer.fee_on_xin_from_sol(sol_amount, proxy: config.proxy_config)
33
33
  end
34
34
 
35
35
  def register_computer
@@ -248,8 +248,21 @@ module MixinBot
248
248
  [results, failures]
249
249
  end
250
250
 
251
+ SESSION_SLOT_SIZE = 64
252
+ MESSAGE_HEADER_SIZE = 35
253
+ MESSAGE_NONCE_SIZE = 12
254
+ MESSAGE_TAG_SIZE = 16
255
+ WRAPPED_KEY_PADDING = ("\x10".b * 16).freeze
256
+
257
+ # Builds the payload in one binary String buffer:
258
+ # version 1, the session count as a little-endian uint16, the sender's
259
+ # Curve25519 public key, one (session id, iv, encrypted key) triple per
260
+ # session, then the GCM nonce, ciphertext and tag. Returns it base64url-encoded.
251
261
  def encrypt_message(data, sessions = [], sk: nil, pk: nil) # rubocop:disable Naming/MethodParameterName
252
- raise ArgumentError, 'Wrong sessions format!' unless sessions.all?(&->(s) { s.key?('session_id') && s.key?('public_key') })
262
+ unless sessions.is_a?(Array) && sessions.size.between?(1, 65_535) &&
263
+ sessions.all? { |session| session.is_a?(Hash) && session.key?('session_id') && session.key?('public_key') }
264
+ raise ArgumentError, 'invalid encrypted message recipient sessions'
265
+ end
253
266
 
254
267
  sk ||= config.session_private_key[0...32]
255
268
  pk ||= config.session_private_key[32...]
@@ -262,79 +275,89 @@ module MixinBot
262
275
  encrypter.auth_data = ''
263
276
  ciphertext = encrypter.update(Base64.urlsafe_decode64(data)) + encrypter.final + encrypter.auth_tag
264
277
 
265
- bytes = [1]
266
- bytes.concat([sessions.size].pack('v*').bytes)
267
- bytes.concat(JOSE::JWA::Ed25519.pk_to_curve25519(pk).bytes)
278
+ bytes = [1, sessions.size].pack('Cv')
279
+ bytes << MixinBot.utils.ed25519_pk_to_curve25519(pk)
280
+ curve_secret = JOSE::JWA::Ed25519.secret_to_curve25519(sk)
281
+ wrapped_key = key + WRAPPED_KEY_PADDING
268
282
 
269
283
  sessions.each do |session|
270
- aes_key = JOSE::JWA::X25519.shared_secret(
271
- Base64.urlsafe_decode64(session['public_key']),
272
- JOSE::JWA::Ed25519.secret_to_curve25519(sk)
273
- )
274
-
275
- padding = 16 - (key.size % 16)
276
- padtext = ([padding] * padding).pack('C*')
284
+ session_key = Base64.urlsafe_decode64(session['public_key'])
285
+ aes_key = MixinBot.utils.message_shared_key(curve_secret, session_key)
277
286
 
278
287
  encrypter = OpenSSL::Cipher.new('AES-256-CBC').encrypt
288
+ encrypter.padding = 0
279
289
  encrypter.key = aes_key
280
290
  iv = encrypter.random_iv
281
291
  encrypter.iv = iv
282
292
 
283
- bytes.concat((MixinBot::UUID.new(hex: session['session_id']).packed + iv).bytes)
284
- bytes.concat(encrypter.update(key + padtext).bytes)
293
+ bytes << packed_message_session(session['session_id'])
294
+ bytes << iv
295
+ bytes << encrypter.update(wrapped_key) << encrypter.final
285
296
  end
286
297
 
287
- bytes.concat(nounce.bytes)
288
- bytes.concat(ciphertext.bytes)
298
+ bytes << nounce
299
+ bytes << ciphertext
289
300
 
290
- Base64.urlsafe_encode64 bytes.pack('C*'), padding: false
301
+ Base64.urlsafe_encode64 bytes, padding: false
291
302
  end
292
303
 
304
+ # Validates the framing before unwrapping the session key. The
305
+ # plaintext stays in the historically returned padded base64 format.
293
306
  def decrypt_message(data, sk: nil, si: nil) # rubocop:disable Naming/MethodParameterName
294
- bytes = Base64.urlsafe_decode64(data).bytes
307
+ bytes = Base64.urlsafe_decode64 data
295
308
 
296
309
  si ||= config.session_id
297
310
  sk ||= config.session_private_key[0...32]
298
311
 
299
- size = 16 + 48
300
- return '' if bytes.size < 1 + 2 + 32 + size + 12
301
-
302
- session_length = bytes[1...3].pack('v*').unpack1('C*')
303
- prefix_size = 35 + (session_length * size)
304
-
305
- i = 35
306
- key = ''
307
- while i < prefix_size
308
- uuid = MixinBot::UUID.new(raw: bytes[i...(i + 16)].pack('C*')).unpacked
309
- if uuid == si
310
- pub = bytes[3...35]
311
- aes_key = JOSE::JWA::X25519.shared_secret(
312
- pub.pack('C*'),
313
- JOSE::JWA::Ed25519.secret_to_curve25519(sk)
314
- )
315
- iv = bytes[(i + 16)...(i + 16 + 16)].pack('C*')
316
- encrypted_key = bytes[(i + 16 + 16)...(i + size)].pack('C*')
317
-
318
- decrypter = OpenSSL::Cipher.new('AES-256-CBC').decrypt
319
- decrypter.iv = iv
320
- decrypter.key = aes_key
321
- cipher = decrypter.update(encrypted_key)
322
- key = cipher[...16]
323
- break
324
- end
325
- i += size
312
+ raise ArgumentError, 'invalid encrypted message header' if bytes.bytesize < MESSAGE_HEADER_SIZE || bytes.getbyte(0) != 1
313
+
314
+ session_length = bytes.unpack1('v', offset: 1)
315
+ prefix_size = MESSAGE_HEADER_SIZE + (session_length * SESSION_SLOT_SIZE)
316
+ if session_length.zero? || bytes.bytesize < prefix_size + MESSAGE_NONCE_SIZE + MESSAGE_TAG_SIZE
317
+ raise ArgumentError, 'invalid encrypted message session count or length'
326
318
  end
327
319
 
328
- return '' unless key.size == 16
320
+ session = packed_message_session(si)
321
+ offset = MESSAGE_HEADER_SIZE.step(prefix_size - SESSION_SLOT_SIZE, SESSION_SLOT_SIZE).find do |position|
322
+ bytes.byteslice(position, 16) == session
323
+ end
324
+ raise ArgumentError, 'encrypted message recipient not found' unless offset
329
325
 
330
- decrypter = OpenSSL::Cipher.new('AES-128-GCM').decrypt
331
- decrypter.key = key
332
- decrypter.iv = bytes[prefix_size...(prefix_size + 12)].pack('C*')
333
- decrypter.auth_tag = bytes.last(16).pack('C*')
334
- decrypted = decrypter.update(bytes[(prefix_size + 12)...-16].pack('C*'))
335
- decrypter.final
326
+ decrypt_message_payload(bytes, offset, prefix_size, sk)
327
+ end
336
328
 
337
- Base64.urlsafe_encode64 decrypted
329
+ private
330
+
331
+ def packed_message_session(session_id)
332
+ unless session_id.is_a?(String) && session_id.match?(/\A(?:\h{32}|\h{8}-\h{4}-\h{4}-\h{4}-\h{12})\z/)
333
+ raise ArgumentError, 'invalid encrypted message session ID'
334
+ end
335
+
336
+ MixinBot::UUID.new(hex: session_id).packed
337
+ end
338
+
339
+ def decrypt_message_payload(bytes, offset, prefix_size, secret)
340
+ decrypter = OpenSSL::Cipher.new('AES-256-CBC').decrypt
341
+ decrypter.padding = 0
342
+ decrypter.key = MixinBot.utils.message_shared_key(
343
+ JOSE::JWA::Ed25519.secret_to_curve25519(secret), bytes.byteslice(3, 32)
344
+ )
345
+ decrypter.iv = bytes.byteslice(offset + 16, 16)
346
+ wrapped_key = decrypter.update(bytes.byteslice(offset + 32, 32)) + decrypter.final
347
+ padding_valid = OpenSSL.fixed_length_secure_compare(wrapped_key.byteslice(16, 16), WRAPPED_KEY_PADDING)
348
+
349
+ decrypter = OpenSSL::Cipher.new('AES-128-GCM').decrypt
350
+ decrypter.key = wrapped_key.byteslice(0, 16)
351
+ decrypter.iv = bytes.byteslice(prefix_size, MESSAGE_NONCE_SIZE)
352
+ decrypter.auth_tag = bytes.byteslice(-MESSAGE_TAG_SIZE, MESSAGE_TAG_SIZE)
353
+ decrypter.auth_data = ''
354
+ ciphertext = bytes[(prefix_size + MESSAGE_NONCE_SIZE)...-MESSAGE_TAG_SIZE]
355
+ plaintext = decrypter.update(ciphertext) + decrypter.final
356
+ raise OpenSSL::Cipher::CipherError unless padding_valid
357
+
358
+ Base64.urlsafe_encode64(plaintext)
359
+ rescue OpenSSL::Cipher::CipherError, OpenSSL::BNError
360
+ raise OpenSSL::Cipher::CipherError, 'invalid encrypted message ciphertext'
338
361
  end
339
362
  end
340
363
  end
@@ -44,13 +44,15 @@ module MixinBot
44
44
  { receivers:, index: 0, hint: out_hint },
45
45
  { receivers: senders, index: 1, hint: change_hint }
46
46
  )['data']
47
-
48
- receivers_list = [
49
- { members: receivers, threshold: 1, amount: amount.to_s, ghosts: [keys[0]] },
50
- { members: senders, threshold:, amount: nil, ghosts: [keys[1]] }
51
- ].compact
52
-
53
- tx = build_safe_transaction(utxos: inputs, receivers: receivers_list, extra:)
47
+ raise InvalidTransactionFormatError, 'missing multisig ghost keys' unless keys.is_a?(Array) && keys.size == 2
48
+
49
+ tx = build_safe_transaction(
50
+ utxos: inputs,
51
+ receivers: [{ members: receivers, threshold: 1, amount: }],
52
+ change_receiver: { members: senders, threshold: },
53
+ ghosts: keys,
54
+ extra:
55
+ )
54
56
  MixinBot.utils.encode_raw_transaction(tx)
55
57
  end
56
58
  end
@@ -12,7 +12,8 @@ module MixinBot
12
12
 
13
13
  payload =
14
14
  if pin.length > 6
15
- timestamp = (Time.now.utc.to_f * 1e9).to_i
15
+ now = Time.now
16
+ timestamp = (now.to_i * 1_000_000_000) + now.nsec
16
17
  pin_base64 = encrypt_tip_pin pin, 'TIP:VERIFY:', timestamp.to_s.rjust(32, '0')
17
18
 
18
19
  {
@@ -35,9 +36,9 @@ module MixinBot
35
36
  raise ArgumentError, 'invalid old pin' if old_pin.present? && old_pin.length != 6
36
37
 
37
38
  path = '/pin/update'
38
- encrypted_old_pin = old_pin.nil? ? '' : encrypt_pin(old_pin, iterator: Time.now.utc.to_i)
39
+ encrypted_old_pin = old_pin.nil? ? '' : encrypt_pin(old_pin)
39
40
 
40
- encrypted_pin = encrypt_pin(pin, iterator: Time.now.utc.to_i + 1)
41
+ encrypted_pin = encrypt_pin(pin)
41
42
  payload = {
42
43
  old_pin_base64: encrypted_old_pin,
43
44
  pin_base64: encrypted_pin
@@ -47,21 +48,21 @@ module MixinBot
47
48
  end
48
49
 
49
50
  def update_tip_pin(pin, pub_tip)
50
- old_encrypted = encrypt_pin(pin, iterator: (Time.now.utc.to_f * 1e9).to_i)
51
+ old_encrypted = encrypt_pin(pin)
51
52
  pub_buf = [pub_tip].pack('H*')
52
53
  raise ArgumentError, 'invalid public key' unless pub_buf.bytesize == 32
53
54
 
54
55
  pub_tip_buf = pub_buf + [1].pack('Q>')
55
- encrypted_pin = encrypt_pin(pub_tip_buf.unpack1('H*'), iterator: (Time.now.utc.to_f * 1e9).to_i + 1)
56
+ encrypted_pin = encrypt_pin(pub_tip_buf.unpack1('H*'))
56
57
  path = '/pin/update'
57
58
  client.post path, old_pin_base64: old_encrypted, pin_base64: encrypted_pin
58
59
  end
59
60
 
60
61
  def prepare_tip_key(counter = 0)
61
- ed25519_key = JOSE::JWA::Ed25519.keypair
62
+ ed25519_key = MixinBot.utils.ed25519_keypair
62
63
 
63
64
  private_key = ed25519_key[1].unpack1('H*')
64
- public_key = (ed25519_key[0].bytes + MixinBot::Utils.encode_uint64(counter + 1)).pack('c*').unpack1('H*')
65
+ public_key = MixinBot.utils.tip_public_key(ed25519_key[0], counter:)
65
66
 
66
67
  {
67
68
  private_key:,
@@ -80,7 +81,7 @@ module MixinBot
80
81
 
81
82
  def generate_shared_key_with_server
82
83
  if config.server_public_key.size == 32
83
- JOSE::JWA::X25519.x25519(
84
+ MixinBot.utils.x25519(
84
85
  config.session_private_key_curve25519,
85
86
  config.server_public_key_curve25519
86
87
  )
@@ -35,7 +35,7 @@ module MixinBot
35
35
 
36
36
  msg = Digest::SHA256.digest(msg) unless action == 'TIP:VERIFY:'
37
37
 
38
- signature = JOSE::JWA::Ed25519.sign msg, pin_key
38
+ signature = MixinBot.utils.ed25519_sign msg, pin_key
39
39
 
40
40
  encrypt_pin signature
41
41
  end