class MixinBot::API
Attributes
blaze_host[R]
client[R]
client_id[R]
client_secret[R]
pin_token[R]
private_key[R]
schmoozer[R]
session_id[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/mixin_bot/api.rb, line 25 def initialize(options = {}) @client_id = options[:client_id] || MixinBot.client_id @client_secret = options[:client_secret] || MixinBot.client_secret @session_id = options[:session_id] || MixinBot.session_id @client = Client.new(MixinBot.api_host || 'api.mixin.one') @blaze_host = MixinBot.blaze_host || 'blaze.mixin.one' @pin_token = begin Base64.urlsafe_decode64 options[:pin_token] || MixinBot.pin_token rescue StandardError '' end _private_key = options[:private_key] || MixinBot.private_key @private_key = if /^-----BEGIN RSA PRIVATE KEY-----/.match? _private_key _private_key.gsub('\\r\\n', "\n").gsub("\r\n", "\n") else Base64.urlsafe_decode64 _private_key end end
Public Instance Methods
_generate_aes_key()
click to toggle source
# File lib/mixin_bot/api/pin.rb, line 77 def _generate_aes_key if pin_token.size == 32 JOSE::JWA::X25519.x25519( JOSE::JWA::Ed25519.secret_to_curve25519(private_key[0..31]), pin_token ) else JOSE::JWA::PKCS1.rsaes_oaep_decrypt( 'SHA256', pin_token, OpenSSL::PKey::RSA.new(private_key), session_id ) end end
sign_raw_transaction(json)
click to toggle source
Use a mixin software to implement transaction build
# File lib/mixin_bot/api.rb, line 47 def sign_raw_transaction(json) ensure_mixin_command_exist command = format("mixin signrawtransaction --raw '%<arg>s'", arg: json) output, error = Open3.capture3(command) raise error unless error.empty? output.chomp end
Private Instance Methods
command?(name)
click to toggle source
# File lib/mixin_bot/api.rb, line 82 def command?(name) `which #{name}` $CHILD_STATUS.success? end
ensure_mixin_command_exist()
click to toggle source
# File lib/mixin_bot/api.rb, line 76 def ensure_mixin_command_exist return if command?('mixin') raise '`mixin` command is not valid!' end