mixin_bot 0.8.0 → 0.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a76c8b7d2c5d8cebc963a56d350e3fd5e4bbc1e18ad3e037b65cfb6e1d77b0d1
4
- data.tar.gz: 8c9813a57cb33f256c695a88e42f53feffb33a45979f5fbf788916f332a52d26
3
+ metadata.gz: 668a2577b6ceb0f2e78d47002062ff1f451006027a31b1bac2081864494cf9fe
4
+ data.tar.gz: 3c291ef3a6b7ed2c9ef9b6a56726c563639b575e05378e1ce15466cc00c23b15
5
5
  SHA512:
6
- metadata.gz: 999325d7c1b73c54b80a6a7a2e432e83aaff341997db01211fb43cddffa32448451aaf5c1d92852dfcda872d92b4724d938bacde83621650c20594aaa034ff32
7
- data.tar.gz: 7b49bda1bb1026823ca51301a7f61380db7714f9d9441c466ff0a0c2bb50be52e199900e13b0d7c5e8e6782f938c57f38562e9d56439346c62b7abb364d928e5
6
+ metadata.gz: c8b2d87ca9ff0293aa0e63ce3d82986b30df7fcfe6197eb415b0eee16da6ac00104899e1431bd0975cb11e08a8f5f2e7fac431c02204b73bb0b5b0278525afa5
7
+ data.tar.gz: 7a50ecdb7d683ef493fb5a60fa042ba7b3bb904eaa3fec589b3e7fa10a33968936bc2495aef5325c3636dce30ac69c85dcf486fe0764c6d522c54766b012be19
@@ -17,10 +17,11 @@ module MixinBot
17
17
  sig: sig,
18
18
  scp: scp
19
19
  }
20
- if pin_token.size == 32
20
+ case key_type
21
+ when :ed25519
21
22
  jwk = JOSE::JWK.from_okp [:Ed25519, private_key]
22
23
  jws = JOSE::JWS.from({ 'alg' => 'EdDSA' })
23
- else
24
+ when :rsa
24
25
  jwk = JOSE::JWK.from_pem private_key
25
26
  jws = JOSE::JWS.from({ 'alg' => 'RS512' })
26
27
  end
data/lib/mixin_bot/api.rb CHANGED
@@ -22,7 +22,7 @@ require_relative './api/withdraw'
22
22
 
23
23
  module MixinBot
24
24
  class API
25
- attr_reader :client_id, :client_secret, :session_id, :pin_token, :private_key, :client, :blaze_host, :schmoozer
25
+ attr_reader :client_id, :client_secret, :session_id, :pin_token, :private_key, :client, :blaze_host, :key_type
26
26
 
27
27
  def initialize(options = {})
28
28
  @client_id = options[:client_id] || MixinBot.client_id
@@ -37,12 +37,13 @@ module MixinBot
37
37
  ''
38
38
  end
39
39
  _private_key = options[:private_key] || MixinBot.private_key
40
- @private_key =
41
- if /^-----BEGIN RSA PRIVATE KEY-----/.match? _private_key
42
- _private_key.gsub('\\r\\n', "\n").gsub("\r\n", "\n")
43
- else
44
- Base64.urlsafe_decode64 _private_key
45
- end
40
+ if /^-----BEGIN RSA PRIVATE KEY-----/.match? _private_key
41
+ @private_key = _private_key.gsub('\\r\\n', "\n").gsub("\r\n", "\n")
42
+ @key_type = :rsa
43
+ else
44
+ @private_key = Base64.urlsafe_decode64 _private_key
45
+ @key_type = :ed25519
46
+ end
46
47
  end
47
48
 
48
49
  def sign_raw_transaction(tx)
@@ -16,9 +16,9 @@ module MixinBot
16
16
  @prefix = NFT_MEMO_PREFIX
17
17
  @version = NFT_MEMO_VERSION
18
18
  @mask = kwargs[:mask] || 0
19
- @chain = kwargs[:chain]
20
- @nm_class = kwargs[:nm_class]
21
- @collection = kwargs[:collection]
19
+ @chain = kwargs[:chain] || NFT_MEMO_DEFAULT_CHAIN
20
+ @nm_class = kwargs[:nm_class] || NFT_MEMO_DEFAULT_CLASS
21
+ @collection = kwargs[:collection] || NULL_UUID
22
22
  @token = kwargs[:token]
23
23
  @extra = kwargs[:extra]
24
24
  @memo = kwargs[:memo]
@@ -38,6 +38,25 @@ module MixinBot
38
38
  memo
39
39
  end
40
40
 
41
+ def unique_token_id
42
+ bytes = []
43
+ bytes += MixinBot::Utils::UUID.new(hex: chain).packed.bytes
44
+ bytes += [nm_class].pack('H*').bytes
45
+ bytes += MixinBot::Utils::UUID.new(hex: collection).packed.bytes
46
+ bytes += MixinBot::Utils.bytes_of token
47
+
48
+ md5 = Digest::MD5.new
49
+ md5.update bytes.pack('c*')
50
+ digest = [md5.hexdigest].pack('H*').bytes
51
+
52
+ digest[6] = (digest[6] & 0x0f) | 0x30
53
+ digest[8] = (digest[8] & 0x3f) | 0x80
54
+
55
+ hex = digest.pack('c*').unpack1('H*')
56
+
57
+ MixinBot::Utils::UUID.new(hex: hex).unpacked
58
+ end
59
+
41
60
  def mark(*indexes)
42
61
  indexes.map do |index|
43
62
  if index >= 64 || index < 0
@@ -70,6 +89,8 @@ module MixinBot
70
89
  token_bytes = MixinBot::Utils.bytes_of token
71
90
  bytes += MixinBot::Utils.bytes_of token_bytes.size
72
91
  bytes += token_bytes
92
+ else
93
+ bytes += [0]
73
94
  end
74
95
 
75
96
  extra_bytes = [extra].pack('H*').bytes
@@ -127,6 +148,8 @@ module MixinBot
127
148
 
128
149
  extra_length = bytes.shift
129
150
  @extra = bytes.shift(extra_length).pack('C*').unpack1('H*')
151
+
152
+ self
130
153
  end
131
154
 
132
155
  def to_h
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.3'
5
5
  end
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.8.0
4
+ version: 0.8.3
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-03-15 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport