Module: MixinBot::API::Tip
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/tip.rb
Constant Summary collapse
- TIP_ACTIONS =
%w[ TIP:VERIFY: TIP:ADDRESS:ADD: TIP:ADDRESS:REMOVE: TIP:USER:DEACTIVATE: TIP:EMERGENCY:CONTACT:CREATE: TIP:EMERGENCY:CONTACT:READ: TIP:EMERGENCY:CONTACT:REMOVE: TIP:PHONE:NUMBER:UPDATE: TIP:MULTISIG:REQUEST:SIGN: TIP:MULTISIG:REQUEST:UNLOCK: TIP:COLLECTIBLE:REQUEST:SIGN: TIP:COLLECTIBLE:REQUEST:UNLOCK: TIP:TRANSFER:CREATE: TIP:WITHDRAW: TIP:WITHDRAWAL:CREATE: TIP:TRANSACTION:CREATE: TIP:OAUTH:APPROVE: TIP:PROVISIONING:UPDATE: TIP:APP:OWNERSHIP:TRANSFER: SEQUENCER:REGISTER: ].freeze
Instance Method Summary collapse
- #encrypt_tip_pin(pin, action, *params) ⇒ Object
- #get_tip_node(path, request_id: nil, access_token: nil) ⇒ Object (also: #get_tip_node_by_path)
- #tip_body(str) ⇒ Object
- #tip_body_for_address_add(asset_id, public_key, key_tag, name) ⇒ Object
- #tip_body_for_emergency_contact_create(verification_id, code) ⇒ Object
- #tip_body_for_ownership_transfer(user_id) ⇒ Object
- #tip_body_for_phone_number_update(verification_id, code) ⇒ Object
- #tip_body_for_provisioning_update(device_id, secret) ⇒ Object
- #tip_body_for_raw_transaction_create(asset_id, opponent_key, opponent_receivers, opponent_threshold, amount, trace_id, memo) ⇒ Object
- #tip_body_for_sequencer_register(user_id, public_key) ⇒ Object
- #tip_body_for_transfer(asset_id, counter_user_id, amount, trace_id, memo) ⇒ Object
- #tip_body_for_verify(timestamp = (Time.now.to_f * 1e9).to_i) ⇒ Object
- #tip_body_for_withdrawal_create(address_id, amount, fee, trace_id, memo) ⇒ Object
- #tip_migrate_body(pub_hex) ⇒ Object
Instance Method Details
#encrypt_tip_pin(pin, action, *params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mixin_bot/api/tip.rb', line 29 def encrypt_tip_pin(pin, action, *params) raise ArgumentError, 'invalid action' unless TIP_ACTIONS.include? action pin_key = MixinBot.utils.decode_key pin msg = action + params.join msg = Digest::SHA256.digest(msg) unless action == 'TIP:VERIFY:' signature = JOSE::JWA::Ed25519.sign msg, pin_key encrypt_pin signature end |
#get_tip_node(path, request_id: nil, access_token: nil) ⇒ Object Also known as: get_tip_node_by_path
43 44 45 46 47 48 49 50 |
# File 'lib/mixin_bot/api/tip.rb', line 43 def get_tip_node(path, request_id: nil, access_token: nil) url = format('/external/tip/%<path>s', path:) if request_id.present? client.fetch_get url, access_token: access_token || '' else client.get url, access_token: access_token || '' end end |
#tip_body(str) ⇒ Object
111 112 113 |
# File 'lib/mixin_bot/api/tip.rb', line 111 def tip_body(str) str.to_s.b end |
#tip_body_for_address_add(asset_id, public_key, key_tag, name) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/mixin_bot/api/tip.rb', line 92 def tip_body_for_address_add(asset_id, public_key, key_tag, name) format( 'TIP:ADDRESS:ADD:%<asset_id>s%<public_key>s%<key_tag>s%<name>s', asset_id:, public_key:, key_tag:, name: ) end |
#tip_body_for_emergency_contact_create(verification_id, code) ⇒ Object
88 89 90 |
# File 'lib/mixin_bot/api/tip.rb', line 88 def tip_body_for_emergency_contact_create(verification_id, code) format('TIP:EMERGENCY:CONTACT:CREATE:%<verification_id>s%<code>s', verification_id:, code:) end |
#tip_body_for_ownership_transfer(user_id) ⇒ Object
103 104 105 |
# File 'lib/mixin_bot/api/tip.rb', line 103 def tip_body_for_ownership_transfer(user_id) format('TIP:APP:OWNERSHIP:TRANSFER:%<user_id>s', user_id:) end |
#tip_body_for_phone_number_update(verification_id, code) ⇒ Object
84 85 86 |
# File 'lib/mixin_bot/api/tip.rb', line 84 def tip_body_for_phone_number_update(verification_id, code) format('TIP:PHONE:NUMBER:UPDATE:%<verification_id>s%<code>s', verification_id:, code:) end |
#tip_body_for_provisioning_update(device_id, secret) ⇒ Object
99 100 101 |
# File 'lib/mixin_bot/api/tip.rb', line 99 def tip_body_for_provisioning_update(device_id, secret) format('TIP:PROVISIONING:UPDATE:%<device_id>s%<secret>s', device_id:, secret:) end |
#tip_body_for_raw_transaction_create(asset_id, opponent_key, opponent_receivers, opponent_threshold, amount, trace_id, memo) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/mixin_bot/api/tip.rb', line 61 def tip_body_for_raw_transaction_create(asset_id, opponent_key, opponent_receivers, opponent_threshold, amount, trace_id, memo) receivers = Array(opponent_receivers).join format( 'TIP:TRANSACTION:CREATE:%<asset_id>s%<opponent_key>s%<receivers>s%<opponent_threshold>s%<amount>s%<trace_id>s%<memo>s', asset_id:, opponent_key:, receivers:, opponent_threshold:, amount:, trace_id:, memo: ) end |
#tip_body_for_sequencer_register(user_id, public_key) ⇒ Object
107 108 109 |
# File 'lib/mixin_bot/api/tip.rb', line 107 def tip_body_for_sequencer_register(user_id, public_key) format('SEQUENCER:REGISTER:%<user_id>s%<public_key>s', user_id:, public_key:) end |
#tip_body_for_transfer(asset_id, counter_user_id, amount, trace_id, memo) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/mixin_bot/api/tip.rb', line 77 def tip_body_for_transfer(asset_id, counter_user_id, amount, trace_id, memo) format( 'TIP:TRANSFER:CREATE:%<asset_id>s%<counter_user_id>s%<amount>s%<trace_id>s%<memo>s', asset_id:, counter_user_id:, amount:, trace_id:, memo: ) end |
#tip_body_for_verify(timestamp = (Time.now.to_f * 1e9).to_i) ⇒ Object
57 58 59 |
# File 'lib/mixin_bot/api/tip.rb', line 57 def tip_body_for_verify( = (Time.now.to_f * 1e9).to_i) format('TIP:VERIFY:%032d', ) end |
#tip_body_for_withdrawal_create(address_id, amount, fee, trace_id, memo) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/mixin_bot/api/tip.rb', line 70 def tip_body_for_withdrawal_create(address_id, amount, fee, trace_id, memo) format( 'TIP:WITHDRAWAL:CREATE:%<address_id>s%<amount>s%<fee>s%<trace_id>s%<memo>s', address_id:, amount:, fee:, trace_id:, memo: ) end |
#tip_migrate_body(pub_hex) ⇒ Object
53 54 55 |
# File 'lib/mixin_bot/api/tip.rb', line 53 def tip_migrate_body(pub_hex) "TIP:MIGRATE:#{pub_hex}" end |