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.
- checksums.yaml +4 -4
- data/AGENTS.md +12 -2
- data/CHANGELOG.md +135 -0
- data/README.md +3 -2
- data/docs/agent/cli.md +4 -2
- data/lib/mixin_bot/address.rb +73 -62
- data/lib/mixin_bot/api/attachment.rb +18 -8
- data/lib/mixin_bot/api/blaze.rb +7 -2
- data/lib/mixin_bot/api/blaze_async.rb +169 -4
- data/lib/mixin_bot/api/computer_api.rb +7 -7
- data/lib/mixin_bot/api/encrypted_message.rb +75 -52
- data/lib/mixin_bot/api/multisig.rb +9 -7
- data/lib/mixin_bot/api/pin.rb +9 -8
- data/lib/mixin_bot/api/tip.rb +1 -1
- data/lib/mixin_bot/api/transaction.rb +70 -41
- data/lib/mixin_bot/api/transfer.rb +3 -2
- data/lib/mixin_bot/api/user.rb +6 -6
- data/lib/mixin_bot/api.rb +1 -0
- data/lib/mixin_bot/bot_auth.rb +1 -1
- data/lib/mixin_bot/cli/schema.rb +2 -0
- data/lib/mixin_bot/cli.rb +9 -3
- data/lib/mixin_bot/client.rb +43 -19
- data/lib/mixin_bot/computer.rb +39 -23
- data/lib/mixin_bot/configuration.rb +48 -8
- data/lib/mixin_bot/invoice.rb +126 -77
- data/lib/mixin_bot/nfo.rb +54 -43
- data/lib/mixin_bot/proxy.rb +184 -0
- data/lib/mixin_bot/transaction/decoder.rb +201 -138
- data/lib/mixin_bot/transaction/encoder.rb +156 -118
- data/lib/mixin_bot/transaction.rb +15 -1
- data/lib/mixin_bot/utils/address.rb +1 -1
- data/lib/mixin_bot/utils/amount.rb +25 -0
- data/lib/mixin_bot/utils/base58.rb +97 -0
- data/lib/mixin_bot/utils/crypto.rb +188 -56
- data/lib/mixin_bot/utils/cursor.rb +147 -0
- data/lib/mixin_bot/utils/decoder.rb +111 -6
- data/lib/mixin_bot/utils/encoder.rb +90 -21
- data/lib/mixin_bot/utils/options.rb +26 -0
- data/lib/mixin_bot/utils/sodium.rb +169 -0
- data/lib/mixin_bot/utils.rb +17 -2
- data/lib/mixin_bot/uuid.rb +6 -13
- data/lib/mixin_bot/version.rb +1 -1
- data/lib/mixin_bot.rb +1 -3
- data/lib/mvm/client.rb +44 -9
- data/lib/mvm/registry.rb +45 -17
- data/llms.txt +1 -1
- metadata +6 -44
- data/lib/mixin_bot/transaction/buffer.rb +0 -34
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdbe63784f325c7f9de793704f3899c211ac93dd0990e96cb107237a5048f0e0
|
|
4
|
+
data.tar.gz: 35faf5c6115025fc5383114fbfef4a1c0da0b14574940521485dc7b852edc5bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 160144bbe2bdf479d67565c128b2e7ffefab91580a951872cc15bf8a93ec3e150afaed166942da76d8e341ae6fceb4375866a24b7d8a83a1c3733d707c3f596d
|
|
7
|
+
data.tar.gz: 6231ccc10d771e08389bdb4665484e602cc51f00dac278d9b3cad0b26596e127c56dc4ed262c2b192635055cdd4c567570539e1acd0e32a47fefb6b33becdfa4
|
data/AGENTS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AGENTS.md — MixinBot
|
|
2
2
|
|
|
3
|
-
Ruby gem (v3.0
|
|
3
|
+
Ruby gem (v3.1.0): Mixin Network REST SDK + `mixinbot` CLI. Parity targets: [bot-api-go-client](https://github.com/MixinNetwork/bot-api-go-client), [bot-api-nodejs-client](https://github.com/MixinNetwork/bot-api-nodejs-client).
|
|
4
4
|
|
|
5
5
|
## Commands
|
|
6
6
|
|
|
@@ -10,6 +10,8 @@ rake # default: test + rubocop (in that order)
|
|
|
10
10
|
rake test # offline suite only
|
|
11
11
|
rake test_live # LIVE=1 rake test (requires test/config.yml)
|
|
12
12
|
rake mixin_bot:api_coverage # check API_COVERAGE.md has no missing entries
|
|
13
|
+
bundle exec ruby benchmark/binary_codec.rb [path/to/lib] # codec benchmark (allocs + us per call); optional arg = another checkout to compare against
|
|
14
|
+
bundle exec ruby benchmark/curve_math.rb [path/to/lib] # curve math benchmark (keypairs, signatures, encrypted messages, Safe / TIP signing)
|
|
13
15
|
rake build # build .gem
|
|
14
16
|
rake rdoc # generate doc/
|
|
15
17
|
```
|
|
@@ -25,10 +27,11 @@ lib/mixin_bot/
|
|
|
25
27
|
cli.rb + cli/*.rb # mixinbot CLI (Thor)
|
|
26
28
|
configuration.rb # Credentials and hosts
|
|
27
29
|
transaction/ # Raw transaction encode/decode
|
|
28
|
-
utils.rb
|
|
30
|
+
utils.rb + utils/*.rb # Crypto (curve math through libsodium), binary codecs (pack_*, Cursor, Base58), key decoding
|
|
29
31
|
lib/mvm/ # MVM helpers (excluded from default rake test)
|
|
30
32
|
bin/mixinbot # CLI entrypoint
|
|
31
33
|
test/ # Minitest + WebMock (offline by default)
|
|
34
|
+
benchmark/ # reproducible perf benchmarks (not run by rake test)
|
|
32
35
|
docs/agent/ # LLM-oriented CLI and cookbook docs
|
|
33
36
|
```
|
|
34
37
|
|
|
@@ -46,6 +49,11 @@ docs/agent/ # LLM-oriented CLI and cookbook docs
|
|
|
46
49
|
- **Legacy APIs**: `create_legacy_transfer`, `POST /transfers` — deprecated, warns once
|
|
47
50
|
- **Tests**: offline WebMock stubs by default; `LIVE=1 rake test` for integration
|
|
48
51
|
- **MVM tests**: excluded from `rake test`; run separately if needed
|
|
52
|
+
- **Binary codecs** (transactions, NFO memos, invoices): build payloads in one ASCII-8BIT String (`MixinBot.utils.pack_uint16/32/64`, `pack_int` + `<<`) and read them with `MixinBot::Utils::Cursor`. Do not reintroduce Integer-array carriers; the Array-based `encode_uint*` / `encode_int` / `decode_*` helpers stay only for backward compatibility
|
|
53
|
+
- **Curve arithmetic**: go through `MixinBot.utils.ed25519_keypair` / `ed25519_sign` / `ed25519_pk_to_curve25519` / `x25519` (libsodium, bound in `lib/mixin_bot/utils/sodium.rb`). Do not call `JOSE::JWA::Ed25519`, `JOSE::JWA::X25519` or `JOSE::JWA::Edwards25519Point` for keys, signatures or scalar multiplication: pure Ruby, about 6 ms and 44 000 objects per scalar multiplication. They remain only as the fallback inside `utils/crypto.rb`, for the points libsodium refuses
|
|
54
|
+
- **Scalar multiplication** is libsodium's `crypto_scalarmult_ed25519_noclamp` / `..._base_noclamp`: one multiplication per product, the scalar taken as it is (the gem's scalars are reduced modulo L, so there is nothing to clamp), and the point validated by the call itself. They refuse what `crypto_core_ed25519_is_valid_point` refuses, plus a product that is the identity — `ed25519_base_mult` / `ed25519_point_mult` return that themselves. Do not reintroduce a clamping decomposition or a separate `ed25519_point?` check in front of them
|
|
55
|
+
- **JWTs**: `MixinBot.utils.ed25519_jwt` writes the compact JWS for an Ed25519 key (JOSE's header, claims sorted by name, libsodium signature). Do not rebuild it on `JOSE::JWK` / `JOSE::JWT`; the RSA path and a key libsodium does not sign with still go through JOSE
|
|
56
|
+
- **Addresses**: `MIX` / `XIN` addresses are Base58 through `MixinBot::Utils::Base58` (bitcoin alphabet, same output as the base58 gem, which is much slower). Pass binary Strings: it rejects other encodings as the gem does
|
|
49
57
|
- **Lint**: RuboCop via `rake` (runs after tests in default task)
|
|
50
58
|
|
|
51
59
|
## CLI boundaries
|
|
@@ -66,6 +74,8 @@ See [docs/agent/cli.md](docs/agent/cli.md).
|
|
|
66
74
|
|
|
67
75
|
Custom errors in `lib/mixin_bot/errors.rb`: `ResponseError`, `UnauthorizedError`, `InsufficientBalanceError`, `UtxoInsufficientError`, `PinError`, `NotFoundError`, etc.
|
|
68
76
|
|
|
77
|
+
`MixinBot::ArgumentError` subclasses `StandardError`, not Ruby's `ArgumentError`: inside `module MixinBot` a bare `raise ArgumentError` raises it. Write `::ArgumentError` when Ruby's class is meant — `MixinBot::Utils::Base58` does, so that a `rescue ArgumentError` around address parsing keeps catching what the base58 gem raised.
|
|
78
|
+
|
|
69
79
|
CLI maps these to structured error kinds (`auth`, `api_error`, `not_found`, …) when `--output json`.
|
|
70
80
|
|
|
71
81
|
## What not to do
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,141 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.1.0] - 2026-12-06
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Scalar multiplications go through libsodium's `noclamp` functions, and a point the gem produced is not validated twice.** The previous round bound the *clamping* public functions, so every scalar multiplication had to undo the clamping: `a * P` was computed as `clamp(a) * P − 2**254 * P + (a & 7) * P`, two scalar multiplications and a subtraction, and every point was checked with `crypto_core_ed25519_is_valid_point` (a scalar multiplication by L of its own) on top of that. libsodium ≥ 1.0.18 also exports `crypto_scalarmult_ed25519_noclamp` and `crypto_scalarmult_ed25519_base_noclamp`, which take the scalar as it is — every scalar the gem passes is reduced modulo L, so there is nothing to clamp — and which validate their point argument themselves. `MixinBot::Utils::Sodium` now binds those: one scalar multiplication per product, and no separate point check. `ed25519_add` takes an `other_is_valid:` keyword for a point the gem produced itself (`derive_ghost_public_key` passes the output of `ed25519_base_mult` that way), so only the operand that came from outside is checked.
|
|
13
|
+
|
|
14
|
+
What the noclamp functions refuse is what `crypto_core_ed25519_is_valid_point` refuses — not canonical, not on the curve, of low order, off the main subgroup — checked on nine such encodings against the previous implementation, plus 40 random scalars and 20 random point/scalar pairs against JOSE. They refuse one more thing, a product that is the identity point, which is what a scalar that is a multiple of L multiplies to; `ed25519_base_mult` and `ed25519_point_mult` return that product themselves (as `(0, 1)`, the encoding JOSE gives it) instead of falling back to the pure-Ruby code. Results are unchanged: the golden fixture recorded from the JOSE implementation still replays, including the inputs libsodium refuses, and the point arithmetic is still cross-checked against JOSE on random inputs.
|
|
15
|
+
|
|
16
|
+
- **`access_token` signs its Ed25519 JWTs with libsodium** instead of building a `JOSE::JWK`, a `JOSE::JWS` and a `JOSE::JWT` for every request. `MixinBot.utils.ed25519_jwt` writes the same compact JWS byte for byte — JOSE's protected header (`{"alg":"EdDSA","typ":"JWT"}`), the claims sorted by name, and the Ed25519 signature over `header.claims` — and `access_token` keeps the JOSE path for a key libsodium does not sign with and for RSA keys. Pinned against `JOSE::JWT.sign` for the same payload and key.
|
|
17
|
+
|
|
18
|
+
Allocations and wall time per call, Ruby 4.0.10 on x86_64 Linux, the minimum of 5 × 300 calls (`bundle exec ruby benchmark/curve_math.rb [path/to/old/lib]`, which gained a `-- libsodium primitives --` section):
|
|
19
|
+
|
|
20
|
+
| | before | after |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `Sodium.ed25519_base_mult` | 17 allocs, 25.9 µs | 4 allocs, 10.3 µs (−76% / −60%) |
|
|
23
|
+
| `Sodium.ed25519_point_mult` | 31 allocs, 144.5 µs | 4 allocs, 49.5 µs (−87% / −66%) |
|
|
24
|
+
| `Sodium.ed25519_add` | 4 allocs, 52.0 µs | 4 allocs, 52.0 µs |
|
|
25
|
+
| `Sodium.ed25519_add` with `other_is_valid:` | — | 3 allocs, 29.9 µs |
|
|
26
|
+
| `utils.sign` — one input of a Safe transaction | 90 allocs, 45.6 µs | 80 allocs, 29.8 µs (−11% / −35%) |
|
|
27
|
+
| `utils.derive_ghost_public_key` | 80 allocs, 249.9 µs | 50 allocs, 95.6 µs (−38% / −62%) |
|
|
28
|
+
| `access_token` — a JWT, every request | 212 allocs, 49.5 µs | 37 allocs, 17.6 µs (−83% / −64%) |
|
|
29
|
+
| `generate_safe_keys` — 1 XIN recipient | 141 allocs, 276.4 µs | 110 allocs, 117.3 µs (−22% / −58%) |
|
|
30
|
+
| `sign_safe_transaction` — 1 input | 263 allocs, 126.7 µs | 242 allocs, 85.4 µs (−8% / −33%) |
|
|
31
|
+
|
|
32
|
+
`encrypt_message`, `decrypt_message`, `Configuration.new`, `generate_shared_key_with_server` and `encrypt_tip_pin` do no point arithmetic of their own and are unchanged. What is left is the floor: one Ed25519 scalar multiplication is about 10 µs for the base point and 50 µs for an arbitrary point in libsodium.
|
|
33
|
+
|
|
34
|
+
- **Curve arithmetic runs in libsodium instead of JOSE's pure Ruby.** The gem called `JOSE::JWA::Ed25519`, `JOSE::JWA::X25519` and `JOSE::JWA::Edwards25519Point` directly — about 6 ms and 44 000 objects per scalar multiplication, paid by every `Configuration` built from a seed, every encrypted message (once more per session), every input of a Safe signature, every ghost key and every TIP signature. The work now goes through `MixinBot::Utils::Sodium`, bound to libsodium with RbNaCl's FFI setup: `rbnacl` was already a runtime dependency and loaded libsodium on `require`. Results are byte for byte the same — pinned against `test/fixtures/golden/curve_math.json`, recorded from the previous implementation (keypairs, signatures, shared secrets, ghost keys, Safe signatures, three encrypted messages and 231 damaged ones), and the new `MixinBot.utils` wrappers are checked against RbNaCl besides. Inputs libsodium refuses (low-order or non-canonical points, a shared secret of all zeros) still take the JOSE code, which computes or raises exactly as before. Allocations and wall time per call, Ruby 4.0.10 on x86_64 Linux, median of 3 interleaved runs each the minimum of 5 × 200 calls (`bundle exec ruby benchmark/curve_math.rb [path/to/old/lib]`):
|
|
35
|
+
|
|
36
|
+
| | before | after |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `ed25519_keypair` from a seed | 46 666 allocs, 7.22 ms | 4 allocs, 10.7 µs |
|
|
39
|
+
| `ed25519_sign` | 45 345 allocs, 7.45 ms | 3 allocs, 11.4 µs |
|
|
40
|
+
| `x25519` shared secret | 32 187 allocs, 6.52 ms | 2 allocs, 24.1 µs |
|
|
41
|
+
| `utils.sign` — one input of a Safe transaction | 89 278 allocs, 14.88 ms | 90 allocs, 50.6 µs |
|
|
42
|
+
| `utils.derive_ghost_public_key` | 88 019 allocs, 14.77 ms | 80 allocs, 274.4 µs |
|
|
43
|
+
| `encrypt_message` — 100 B, 1 session | 32 398 allocs, 6.79 ms | 48 allocs, 59.7 µs |
|
|
44
|
+
| `encrypt_message` — 100 B, 3 sessions | 96 838 allocs, 20.33 ms | 98 allocs, 118.6 µs |
|
|
45
|
+
| `decrypt_message` — 100 B, 1 session | 32 254 allocs, 6.61 ms | 46 allocs, 31.5 µs |
|
|
46
|
+
| `Configuration.new` from a seed | 46 814 allocs, 7.88 ms | 14 allocs, 41.4 µs |
|
|
47
|
+
| `generate_shared_key_with_server` | 32 187 allocs, 6.58 ms | 2 allocs, 24.1 µs |
|
|
48
|
+
| `generate_safe_keys` — 1 XIN recipient | 134 405 allocs, 22.11 ms | 141 allocs, 306.8 µs |
|
|
49
|
+
| `sign_safe_transaction` — 1 input | 132 585 allocs, 22.47 ms | 260 allocs, 140.9 µs |
|
|
50
|
+
| `encrypt_tip_pin` (`TIP:VERIFY:`) | 76 185 allocs, 13.48 ms | 32 allocs, 48.1 µs |
|
|
51
|
+
| `ed25519_pk_to_curve25519` (no scalar multiplication) | 150 allocs, 61.2 µs | 2 allocs, 25.7 µs |
|
|
52
|
+
| `access_token` — a JWT, not touched | 215 allocs, 57.7 µs | 212 allocs, 56.8 µs |
|
|
53
|
+
|
|
54
|
+
`access_token` is listed for scale only: JOSE signs JWTs through its own RbNaCl backend already. The Edwards point functions need **libsodium >= 1.0.18** (2019); where they are missing, those calls stay on JOSE.
|
|
55
|
+
|
|
56
|
+
- **`encrypt_message` / `decrypt_message` build and read one binary String** instead of an `Array` of every byte (`bytes.concat(….bytes)`, `pack('C*')` on every slice). Valid payloads are unchanged: the three messages in the fixture decrypt the same, and what `encrypt_message` writes now is read by a copy of the previous `decrypt_message`. Two readings change on purpose:
|
|
57
|
+
- The session count is the little-endian `uint16` it was always written as. Its high byte used to be dropped, so a message for 256 or more sessions came back as `''`.
|
|
58
|
+
- A session slot that the payload cuts in two is skipped, instead of raising from inside it. Over the 534 cut points of a three-session message, read for its first and its last session: for the last one the previous code raised `NoMethodError` (80) or `InvalidUuidFormatError` (19) where `''` comes back now; for the first one a cut inside the GCM nonce raised `NoMethodError` (116) where the `ArgumentError` it already raised for 12 such cuts comes back now (`iv must be 12 bytes`). The other 319 outcomes are the same.
|
|
59
|
+
|
|
60
|
+
- **Addresses are Base58-ed in the gem** (`MixinBot::Utils::Base58`, bitcoin alphabet) rather than by the base58 gem, whose every digit cost a big integer division and a String rebuild: that is where `MainAddress` and `MixAddress` encode and decode spent most of their time. The output is the gem's down to the encoding of the result and its treatment of leading zeros, empty input and all-`1` strings (checked against it on 4 761 values and on random input in the tests), and so are the errors: a byte that is not a Base58 digit still raises Ruby's `ArgumentError`. Along the same lines `MixinBot::UUID`, `MixinBot::MixAddress`, `MixinBot::Invoice` and `MixinBot::InvoiceEntry` no longer copy their options through `with_indifferent_access` (String keys are still accepted), `MixAddress#decode` slices members with `byteslice` instead of `chars.each_slice`, and `UUID#unpacked` interpolates instead of `format`ing. That closes what the previous release note left open — invoice *decode* was dominated by address and UUID parsing. Median of 3 interleaved runs each the minimum of 5 × 10 000 calls (`bundle exec ruby benchmark/binary_codec.rb [path/to/old/lib]`):
|
|
61
|
+
|
|
62
|
+
| | before | after |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `UUID.new(hex:).packed` | 11 allocs, 2.1 µs | 6 allocs, 0.8 µs (−45% / −61%) |
|
|
65
|
+
| `MainAddress.new(public_key:)` | 777 allocs, 33.0 µs | 48 allocs, 10.5 µs (−94% / −68%) |
|
|
66
|
+
| `MainAddress.new(address:)` | 907 allocs, 47.8 µs | 39 allocs, 9.9 µs (−96% / −79%) |
|
|
67
|
+
| `MixAddress.from_members` — 2 UUIDs | 464 allocs, 28.7 µs | 54 allocs, 10.4 µs (−88% / −64%) |
|
|
68
|
+
| `MixAddress.parse` — 2 UUIDs | 534 allocs, 39.1 µs | 57 allocs, 12.6 µs (−89% / −68%) |
|
|
69
|
+
| `MixAddress.parse` — 1 XIN | 1 811 allocs, 90.7 µs | 94 allocs, 23.4 µs (−95% / −74%) |
|
|
70
|
+
| invoice encode — 2 entries | 89 allocs, 21.3 µs | 67 allocs, 12.5 µs (−25% / −41%) |
|
|
71
|
+
| invoice decode — 2 entries | 600 allocs, 58.7 µs | 145 allocs, 27.5 µs (−76% / −53%) |
|
|
72
|
+
|
|
73
|
+
Of 807 recorded calls to these classes — every kind of member list and address, payloads of every length around the header, invoices cut and garbled at every byte, wrong types — 800 give the same result or raise the same error; the others are the blank member and the short payload below, and a `NoMethodError` message for an `Integer` given as hex.
|
|
74
|
+
|
|
75
|
+
- **`MVM::Registry` reads and writes binary Strings.** `users_from_contract` went through `Array#shift` and `pack('C*')` and `contract_from_multisig` built an `Array` of every byte; both now go through `MixinBot::Utils::Cursor` and `MixinBot.utils.pack_uint16`, in `MVM::Registry.decode_users` and `MVM::Registry.multisig_id`. Well-formed payloads give the same group and the same id (`test/fixtures/golden/mvm_registry.json`); a truncated one raises `MixinBot::ArgumentError` (`not enough bytes: …`) where the previous code raised `NoMethodError` or `InvalidUuidFormatError` — or returned a group without a threshold (below).
|
|
76
|
+
|
|
77
|
+
- **Binary codecs build and read binary Strings instead of Arrays of Integers.** `MixinBot::Transaction::Encoder`/`Decoder`, `MixinBot::Nfo` and `MixinBot::Invoice` collected every byte as an `Integer` in an `Array` (one `pack('C*')` at the end) and decoded through `raw.bytes` plus `Array#shift(n)` — a memmove of the unconsumed tail per field. They now append to one ASCII-8BIT String buffer (`MixinBot.utils.pack_*` + `<<`) and read through the new `MixinBot::Utils::Cursor` (`byteslice`/`getbyte`). Wire bytes and decoded values are unchanged: pinned against fixtures captured from the previous codec (`test/fixtures/transactions/golden_encodes.json`) and the existing NFO / invoice goldens. Allocations and wall time per call, Ruby 4.0.10 on x86_64 Linux, median of 3 interleaved runs each the minimum of 5 × 10 000 calls (`bundle exec ruby benchmark/binary_codec.rb [path/to/old/lib]`):
|
|
78
|
+
|
|
79
|
+
| | before | after |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| raw transaction encode — 4 inputs / 2 outputs | 100 allocs, 22.2 µs | 58 allocs, 12.7 µs (−42% / −43%) |
|
|
82
|
+
| raw transaction encode — 4 signatures | 144 allocs, 35.2 µs | 82 allocs, 18.5 µs (−43% / −47%) |
|
|
83
|
+
| raw transaction decode — 4 signatures | 189 allocs, 44.1 µs | 96 allocs, 21.7 µs (−49% / −51%) |
|
|
84
|
+
| `utils.encode_raw_transaction` | 118 allocs, 35.0 µs | 76 allocs, 23.9 µs (−36% / −32%) |
|
|
85
|
+
| `utils.decode_raw_transaction` | 191 allocs, 44.6 µs | 98 allocs, 23.2 µs (−49% / −48%) |
|
|
86
|
+
| NFO `mint_memo` | 51 allocs, 8.8 µs | 39 allocs, 6.0 µs (−24% / −31%) |
|
|
87
|
+
| NFO `decode` | 58 allocs, 8.9 µs | 47 allocs, 7.5 µs (−19% / −16%) |
|
|
88
|
+
| invoice encode — 2 entries | 117 allocs, 24.4 µs | 89 allocs, 18.1 µs (−24% / −26%) |
|
|
89
|
+
|
|
90
|
+
Every safe transfer encodes a raw transaction twice and decodes it once (`build_safe_transaction` → `sign_safe_transaction`), so the codec cost of a transfer drops from about 115 µs to 70 µs. Invoice *decode* is dominated by address / UUID parsing and barely moves (−6%).
|
|
91
|
+
|
|
92
|
+
- **`MixinBot.utils.encode_uint16/32/64` and `encode_int` keep their Array contract** (same bytes, same `MixinBot::ArgumentError` for non-Integers) and are now `pack_uint16/32/64(int).bytes` / `pack_int(int).bytes`. They are big-endian on every host; the previous `[int].pack('S*').bytes.reverse` only came out big-endian on little-endian hosts. `encode_int` allocates one more object but is ~35% faster.
|
|
93
|
+
|
|
94
|
+
- **Cut-short input raises instead of decoding short values.** The new readers are bounds-checked, so malformed payloads fail at the field that is missing rather than wherever a `nil` happened to land:
|
|
95
|
+
- `MixinBot::Transaction#decode` / `MixinBot.utils.decode_raw_transaction`: a raw that ends before every field is read raises `MixinBot::ArgumentError` (`not enough bytes: need N at P, have M`). Of the 808 prefixes of a signed raw transaction, the previous decoder raised `NoMethodError` for 663, raised `ArgumentError` for 36, and **returned a transaction with missing or truncated signatures for 109**. A raw that announces signatures but ends right after the signature count is now rejected too. Bytes after the signatures are still ignored.
|
|
96
|
+
- `MixinBot::Nfo#decode`: a memo that ends before every field is read raises `InvalidNfoFormatError` (`truncated NFO memo: …`); it used to raise `TypeError`.
|
|
97
|
+
- `MixinBot::Invoice#decode`: a payload that passes the checksum but is cut inside an entry raises `InvalidInvoiceFormatError` (`invalid invoice payload: …`). Of 294 such cut points in a two-entry invoice, the previous decoder returned a wrong invoice for **210** and raised `InvalidInvoiceFormatError`, `InvalidUuidFormatError` or `NoMethodError` for the rest. Any other `MixinBot::ArgumentError` raised while reading the payload is reported the same way. An invoice may still end right after the entry count or between entries.
|
|
98
|
+
|
|
99
|
+
- **`MixinBot::Transaction::Buffer` is removed.** The Array-backed decode cursor was only used by the decoder; `MixinBot::Utils::Cursor` replaces it.
|
|
100
|
+
|
|
101
|
+
### Removed
|
|
102
|
+
|
|
103
|
+
- **`bcrypt`** and **`msgpack`** are no longer runtime dependencies: nothing in the gem, its tests or its examples refers to `BCrypt` or `MessagePack`. `require 'msgpack'` is gone from `lib/mixin_bot.rb` with them.
|
|
104
|
+
- **`base58`** is no longer a runtime dependency. `MixinBot::Utils::Base58` replaced it, and `require 'base58'` is gone from `lib/mixin_bot.rb`; it stays in the `Gemfile` as the oracle `test/mixin_bot/utils/test_base58.rb` and `benchmark/binary_codec.rb` check the gem's own implementation against. Code that reached the `base58` gem through `require 'mixin_bot'` has to require it itself.
|
|
105
|
+
- **`simplecov`** is gone from the `Gemfile`; nothing required it.
|
|
106
|
+
|
|
107
|
+
`benchmark` and `cli-ui` stay: activesupport 7's `core_ext/benchmark` requires the former (and it is not a default gem on Ruby 4), and `MixinBot::CLI` / `MixinBot::NodeCLI` use `CLI::UI`.
|
|
108
|
+
|
|
109
|
+
### Added
|
|
110
|
+
|
|
111
|
+
- **`MixinBot.utils.ed25519_keypair(seed)` / `ed25519_sign(message, signing_key)` / `ed25519_pk_to_curve25519(public_key)` / `x25519(scalar, point)`** — Ed25519 and Curve25519 primitives through libsodium, the calls the gem itself was making on `JOSE::JWA`. Results are what JOSE returns; an argument JOSE rejects raises what JOSE raises (`ArgumentError` for a key of the wrong size, `OpenSSL::BNError` for a point of small order).
|
|
112
|
+
|
|
113
|
+
- `benchmark/curve_math.rb` — the benchmark behind the first table.
|
|
114
|
+
|
|
115
|
+
- `benchmark/binary_codec.rb` has an Address section — the benchmark behind the address table above.
|
|
116
|
+
|
|
117
|
+
- **`MVM::Registry.decode_users(payload)` / `MVM::Registry.multisig_id(user_ids, threshold)`** — the codec behind `users_from_contract` and `contract_from_multisig`.
|
|
118
|
+
|
|
119
|
+
- **`MixinBot.utils.pack_uint16` / `pack_uint32` / `pack_uint64` / `pack_int`** — the `encode_uint16/32/64` and `encode_int` layouts as binary Strings (big-endian; `pack_int` is minimal, no leading zero bytes), ready to append with `<<`.
|
|
120
|
+
- **`MixinBot.utils.unpack_uint16` / `unpack_uint32` / `unpack_uint64` / `unpack_int`** — the same layouts read from a binary String.
|
|
121
|
+
- **`MixinBot::Utils::Cursor`** — forward-only reader over a binary String: `read`, `read_uint8/16/32/64`, `read_int`, `peek`, `size`, `empty?`, `pos`. Every reader except `peek` raises `MixinBot::ArgumentError` when the input is cut short, and leaves the cursor where it was.
|
|
122
|
+
- **`MixinBot::InvoiceEntry#encode_to(buffer)`** — appends the entry's wire bytes to a binary buffer; `#encode` still returns an Array of bytes.
|
|
123
|
+
- **`MixinBot::Transaction::MAGIC_BINARY` / `NULL_BINARY`** — binary String forms of `MAGIC` / `NULL_BYTES`.
|
|
124
|
+
- `benchmark/binary_codec.rb` — the codec benchmark behind the table above.
|
|
125
|
+
|
|
126
|
+
### Fixed
|
|
127
|
+
|
|
128
|
+
- Align Safe v5 with the official Mixin SDKs and Kernel: XIN masks and ghost keys derive from the same scalar, amounts stay exact through signing, and v5 withdrawals, deposits, mints, aggregate masks and transaction IDs use the Kernel wire format. The older transaction layouts remain available by version. Object storage uses the official recipient and its paid limit, subject to the Kernel's complete transaction size limit.
|
|
129
|
+
- Preserve MIX member order, validate address layouts, write MIN invoice amounts with eight decimal places, and encode NFO token zero with an empty magnitude. Previously emitted noncanonical invoice amount strings still decode.
|
|
130
|
+
- Encode PIN/TIP timestamps and iterators as separate little-endian uint64 fields. Validate encrypted-message framing and wrapped-key padding. `decrypt_message` now raises `MixinBot::ArgumentError` for a malformed envelope or a message addressed to another session instead of returning an empty string.
|
|
131
|
+
- Verify a single Safe transaction with one HTTP POST. Reuse the transaction hash and input public key while signing, and perform fixed sender-key and padding preparation once per encrypted message.
|
|
132
|
+
|
|
133
|
+
- **`MixinBot::MixAddress` wrote an address whose member count no member list matched for a blank UUID member.** `MixAddress.new(members: ['', uuid], threshold: 1)` returned an address for two members with one member's bytes in it. It raises `MixinBot::ArgumentError` (`invalid member: blank UUID`) now.
|
|
134
|
+
- **`MixinBot::MixAddress.new(payload:)` with a payload shorter than its three header bytes** raised `NoMethodError`; it raises the `invalid address, …` `MixinBot::ArgumentError` the code has for it.
|
|
135
|
+
|
|
136
|
+
- **`MVM::Registry.users_from_contract` returned a group with `threshold: nil` for a payload that ends after its members.** It raises `MixinBot::ArgumentError` now.
|
|
137
|
+
- **`MVM::Registry.contract_from_multisig` hashed whatever it was given**: a user id that is not 32 hex digits (`'abc'`, `''`) produced an id, a lookup that could only miss. It raises `InvalidUuidFormatError` (`ArgumentError` for a blank one) now.
|
|
138
|
+
|
|
139
|
+
- **Decoding a raw transaction with deposit or mint inputs raised `NoMethodError`** (`Array#unpack1`: the old cursor returned an Array where the decoder expected a String). Those inputs now decode.
|
|
140
|
+
- **`MixinBot.utils.encode_int` never returned on a negative Integer** (it looped until the process ran out of memory). It now raises `MixinBot::ArgumentError`.
|
|
141
|
+
- **`MixinBot.utils.decode_key` no longer misclassifies base64 keys.** Three heuristics fought valid input: (1) the unanchored `/\d{6}/` sniff — meant to pass six-digit PINs through untouched — matched digit runs anywhere, so roughly 1 in 2,000 base64url-encoded 32-byte keys was handed back as text and only failed later with `OpenSSL::PKey::PKeyError` in `access_token`; the test is now anchored (`/\A\d{6}\z/`) so PIN handling is unchanged but keys with embedded digit runs decode. (2) With base64 0.3.0's strict decoder, any whitespace inside a base64 key (stray spaces, line wrapping in hand-copied keystores) raised `ArgumentError: invalid base64`; all text formats (hex, base64, RSA PEM, PIN) are now sniffed and decoded against a whitespace-stripped copy — keys with characters outside the base64 alphabet still raise — while the raw-binary pass-through keeps checking the original string's `size % 32`. (3) The RSA header test was line-anchored (`^`), so text before `-----BEGIN RSA PRIVATE KEY-----` kept the whole string undecoded; a key now must start with the header (whitespace around it forgiven), and a key that contains the header but is preceded by other text raises `ArgumentError` instead of being returned undecoded. The escaped-newline normalisation is unchanged.
|
|
142
|
+
|
|
8
143
|
## [3.0.3] - 2026-11-20
|
|
9
144
|
|
|
10
145
|
### Changed
|
data/README.md
CHANGED
|
@@ -55,6 +55,7 @@ MixinBot.configure do
|
|
|
55
55
|
# self.pin = self.spend_key # optional; used where PIN material is required
|
|
56
56
|
# self.api_host = 'api.mixin.one'
|
|
57
57
|
# self.blaze_host = 'blaze.mixin.one'
|
|
58
|
+
# self.proxy = 'http://127.0.0.1:7890' # optional HTTP/HTTPS proxy for all requests
|
|
58
59
|
# self.http_timeout = 30 # request timeout in seconds (nil = no timeout)
|
|
59
60
|
# self.debug = true # Faraday response logging
|
|
60
61
|
end
|
|
@@ -197,7 +198,7 @@ The adapter maps `store(user_id, nil)` to `cache.delete`, so sessions the server
|
|
|
197
198
|
|------|-------------|
|
|
198
199
|
| **`MixinBot::Client`** | Faraday HTTP client (JSON, retries, optional debug). |
|
|
199
200
|
| **`MixinBot::Configuration`** | Credentials and hosts. |
|
|
200
|
-
| **`MixinBot::Utils`** | Crypto, JWT, encoding, `unique_object_id`, `generate_user_checksum`, … |
|
|
201
|
+
| **`MixinBot::Utils`** | Crypto, JWT, encoding, `unique_object_id`, `generate_user_checksum`, … Binary payloads: `pack_uint16/32/64`, `pack_int` (binary Strings) and `MixinBot::Utils::Cursor` (bounds-checked reader). |
|
|
201
202
|
| **`MixinBot::Transaction`** | Encode/decode raw Safe transactions. |
|
|
202
203
|
| **`MixinBot::MixAddress`** | Parse/build `MIX…` addresses; `request_or_generate_ghost_keys`. |
|
|
203
204
|
| **`MixinBot::Invoice`** | `MIN…` payment invoices. |
|
|
@@ -418,7 +419,7 @@ token = client.sign_request(Time.now.to_i, bot_user_id, 'GET', '/some/path')
|
|
|
418
419
|
|
|
419
420
|
## CLI
|
|
420
421
|
|
|
421
|
-
Invoke **`mixinbot`** (global options: `-a` / `--apihost`, `-o` / `--output pretty|json|yaml`, `-r` / `--pretty`).
|
|
422
|
+
Invoke **`mixinbot`** (global options: `-a` / `--apihost`, `--proxy`, `-o` / `--output pretty|json|yaml`, `-r` / `--pretty`).
|
|
422
423
|
|
|
423
424
|
When stdout is piped, output defaults to JSON. Use `mixinbot schema -o json` for machine-readable command discovery. See [docs/agent/cli.md](docs/agent/cli.md).
|
|
424
425
|
|
data/docs/agent/cli.md
CHANGED
|
@@ -7,6 +7,7 @@ The `mixinbot` executable wraps `MixinBot::API` and utilities for scripting and
|
|
|
7
7
|
| Flag | Description |
|
|
8
8
|
|------|-------------|
|
|
9
9
|
| `-a`, `--apihost` | Mixin API host (default: `api.mixin.one`) |
|
|
10
|
+
| `--proxy` | HTTP/HTTPS proxy URL (e.g. `http://127.0.0.1:7890`) |
|
|
10
11
|
| `-o`, `--output` | Output format: `pretty`, `json`, `yaml` |
|
|
11
12
|
| `-r`, `--pretty` | Alias for `--output pretty` (default in TTY) |
|
|
12
13
|
|
|
@@ -28,11 +29,12 @@ API commands accept `-k` / `--keystore`: path to JSON or inline JSON:
|
|
|
28
29
|
"server_public_key": "hex-or-base64",
|
|
29
30
|
"spend_key": "hex",
|
|
30
31
|
"client_secret": "...",
|
|
31
|
-
"pin": "123456"
|
|
32
|
+
"pin": "123456",
|
|
33
|
+
"proxy": "http://127.0.0.1:7890"
|
|
32
34
|
}
|
|
33
35
|
```
|
|
34
36
|
|
|
35
|
-
Aliases: `client_id` → `app_id`, `private_key` → `session_private_key`, `pin_token` → `server_public_key`.
|
|
37
|
+
Aliases: `client_id` → `app_id`, `private_key` → `session_private_key`, `pin_token` → `server_public_key`. Optional `"proxy"` routes requests from that keystore through an HTTP/HTTPS proxy (overridden by `--proxy`).
|
|
36
38
|
|
|
37
39
|
Without `-k`, the CLI uses global `MixinBot.configure` credentials.
|
|
38
40
|
|
data/lib/mixin_bot/address.rb
CHANGED
|
@@ -19,7 +19,7 @@ module MixinBot
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def initialize(**args)
|
|
22
|
-
args = args
|
|
22
|
+
args = MixinBot::Utils::Options.symbolize args
|
|
23
23
|
|
|
24
24
|
if args[:address]
|
|
25
25
|
@address = args[:address]
|
|
@@ -30,8 +30,11 @@ module MixinBot
|
|
|
30
30
|
else
|
|
31
31
|
@version = args[:version] || MIX_ADDRESS_VERSION
|
|
32
32
|
|
|
33
|
-
if args
|
|
34
|
-
|
|
33
|
+
if args.key?(:members)
|
|
34
|
+
members = args[:members]
|
|
35
|
+
raise ArgumentError, 'members should be an array of addresses' unless members.is_a?(Array) && members.all?(String)
|
|
36
|
+
|
|
37
|
+
@xin_members, @uuid_members = members.partition do |member|
|
|
35
38
|
member.start_with?(MAIN_ADDRESS_PREFIX)
|
|
36
39
|
end
|
|
37
40
|
else
|
|
@@ -39,9 +42,6 @@ module MixinBot
|
|
|
39
42
|
@xin_members = args[:xin_members] || []
|
|
40
43
|
end
|
|
41
44
|
|
|
42
|
-
@uuid_members = @uuid_members.sort
|
|
43
|
-
@xin_members = @xin_members.sort
|
|
44
|
-
|
|
45
45
|
@threshold = args[:threshold]
|
|
46
46
|
encode
|
|
47
47
|
end
|
|
@@ -64,16 +64,7 @@ module MixinBot
|
|
|
64
64
|
|
|
65
65
|
def request_or_generate_ghost_keys(output_index = 0, api: MixinBot.api)
|
|
66
66
|
if xin_members.present?
|
|
67
|
-
|
|
68
|
-
gk = { 'mask' => key[0].unpack1('H*'), 'keys' => [] }
|
|
69
|
-
xin_members.each do |member|
|
|
70
|
-
payload = MixinBot.utils.parse_main_address(member)
|
|
71
|
-
spend_key = payload[0...32]
|
|
72
|
-
view_key = payload[-32..]
|
|
73
|
-
ghost = MixinBot.utils.derive_ghost_public_key(key[1], view_key, spend_key, output_index)
|
|
74
|
-
gk['keys'] << ghost.unpack1('H*')
|
|
75
|
-
end
|
|
76
|
-
gk
|
|
67
|
+
MixinBot.utils.generate_xin_ghost_keys(xin_members, output_index)
|
|
77
68
|
else
|
|
78
69
|
hint = SecureRandom.uuid
|
|
79
70
|
api.create_safe_keys(
|
|
@@ -83,46 +74,37 @@ module MixinBot
|
|
|
83
74
|
end
|
|
84
75
|
|
|
85
76
|
def encode
|
|
86
|
-
raise ArgumentError, 'members should be an array' unless uuid_members.is_a?(Array)
|
|
87
|
-
raise ArgumentError, '
|
|
88
|
-
raise ArgumentError, 'members length should less than 256' if uuid_members.length + xin_members.length > 255
|
|
77
|
+
raise ArgumentError, 'members should be an array' unless uuid_members.is_a?(Array) && xin_members.is_a?(Array)
|
|
78
|
+
raise ArgumentError, 'cannot mix UUID and XIN members' if uuid_members.present? && xin_members.present?
|
|
89
79
|
|
|
90
80
|
member_count = uuid_members.length + xin_members.length
|
|
91
|
-
|
|
92
|
-
# XIN-only mix (Go NewMainnetMixAddress): threshold may exceed member count (sparse), e.g. storage 1-of-64 style.
|
|
93
|
-
if uuid_members.present? && xin_members.empty?
|
|
94
|
-
raise ArgumentError, "invalid threshold: #{threshold}" unless threshold.positive? && threshold <= member_count
|
|
95
|
-
elsif xin_members.present? && uuid_members.empty?
|
|
96
|
-
raise ArgumentError, "invalid threshold: #{threshold}" unless threshold.positive?
|
|
97
|
-
raise ArgumentError, 'too many XIN members' if member_count > 64
|
|
98
|
-
elsif threshold > member_count
|
|
99
|
-
raise ArgumentError, "invalid threshold: #{threshold}"
|
|
100
|
-
end
|
|
81
|
+
validate_header(member_count, xin: xin_members.present?)
|
|
101
82
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
msg =
|
|
107
|
-
uuid_members&.map(&->(member) { MixinBot::UUID.new(hex: member).packed })&.join.to_s +
|
|
108
|
-
xin_members&.map(&->(member) { MainAddress.new(address: member).public_key })&.join.to_s
|
|
83
|
+
payload = [version, threshold, member_count].pack('C*')
|
|
84
|
+
uuid_members.each do |member|
|
|
85
|
+
valid = member.is_a?(String) && member.match?(/\A(?:\h{32}|\h{8}-\h{4}-\h{4}-\h{4}-\h{12})\z/)
|
|
86
|
+
raise ArgumentError, 'invalid member UUID' unless valid
|
|
109
87
|
|
|
110
|
-
|
|
88
|
+
payload << MixinBot::UUID.new(hex: member).packed
|
|
89
|
+
end
|
|
90
|
+
xin_members.each { |member| payload << MainAddress.new(address: member).public_key }
|
|
91
|
+
self.payload = payload
|
|
111
92
|
|
|
112
93
|
checksum = SHA3::Digest::SHA3_256.digest(MIX_ADDRESS_PREFIX + payload)
|
|
113
|
-
data = payload + checksum[0...4]
|
|
114
|
-
data = Base58.binary_to_base58 data, :bitcoin
|
|
94
|
+
data = MixinBot::Utils::Base58.encode(payload + checksum[0...4])
|
|
115
95
|
self.address = "#{MIX_ADDRESS_PREFIX}#{data}"
|
|
116
96
|
|
|
117
97
|
address
|
|
118
98
|
end
|
|
119
99
|
|
|
100
|
+
# Fills {#version}, {#threshold} and the member lists from {#address} or
|
|
101
|
+
# {#payload}. Everything after the three header bytes is either
|
|
102
|
+
# {#members_count} UUID members or XIN members of 64 bytes each.
|
|
120
103
|
def decode
|
|
121
104
|
if address.present?
|
|
122
105
|
raise ArgumentError, 'invalid address' unless address&.start_with? MIX_ADDRESS_PREFIX
|
|
123
106
|
|
|
124
|
-
data = address[MIX_ADDRESS_PREFIX.length..]
|
|
125
|
-
data = Base58.base58_to_binary data, :bitcoin
|
|
107
|
+
data = MixinBot::Utils::Base58.decode(address[MIX_ADDRESS_PREFIX.length..])
|
|
126
108
|
raise ArgumentError, 'invalid address, length invalid' if data.length < 3 + 16 + 4
|
|
127
109
|
|
|
128
110
|
self.payload = data[...-4]
|
|
@@ -130,33 +112,50 @@ module MixinBot
|
|
|
130
112
|
raise ArgumentError, 'invalid address, checksum invalid' unless checksum == data[-4..]
|
|
131
113
|
else
|
|
132
114
|
checksum = SHA3::Digest::SHA3_256.digest(MIX_ADDRESS_PREFIX + payload)[0...4]
|
|
133
|
-
data = payload + checksum
|
|
134
|
-
data = Base58.binary_to_base58 data, :bitcoin
|
|
115
|
+
data = MixinBot::Utils::Base58.encode(payload + checksum)
|
|
135
116
|
self.address = "#{MIX_ADDRESS_PREFIX}#{data}"
|
|
136
117
|
end
|
|
137
118
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
self.threshold = payload
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
119
|
+
raise ArgumentError, 'invalid address, length invalid' if payload.bytesize < 3
|
|
120
|
+
|
|
121
|
+
self.version = payload.getbyte(0)
|
|
122
|
+
self.threshold = payload.getbyte(1)
|
|
123
|
+
members_count = payload.getbyte(2)
|
|
124
|
+
members = payload.byteslice(3..)
|
|
125
|
+
xin = members.bytesize == members_count * MAIN_ADDRESS_LENGTH
|
|
126
|
+
validate_header(members_count, xin:)
|
|
127
|
+
if xin
|
|
128
|
+
self.xin_members = Array.new(members_count) do |index|
|
|
129
|
+
key = members.byteslice(index * MAIN_ADDRESS_LENGTH, MAIN_ADDRESS_LENGTH)
|
|
130
|
+
MainAddress.new(public_key: key).address
|
|
131
|
+
end
|
|
132
|
+
self.uuid_members = []
|
|
133
|
+
elsif members.bytesize == members_count * UUID_ADDRESS_LENGTH
|
|
134
|
+
self.uuid_members = Array.new(members_count) do |index|
|
|
135
|
+
MixinBot::UUID.new(raw: members.byteslice(index * UUID_ADDRESS_LENGTH, UUID_ADDRESS_LENGTH)).unpacked
|
|
136
|
+
end
|
|
150
137
|
self.xin_members = []
|
|
151
138
|
else
|
|
152
|
-
|
|
153
|
-
self.xin_members = xin_members.map(&->(member) { MainAddress.new(public_key: member).address })
|
|
154
|
-
self.uuid_members = []
|
|
139
|
+
raise ArgumentError, 'invalid address, member length invalid'
|
|
155
140
|
end
|
|
156
141
|
end
|
|
142
|
+
|
|
143
|
+
private
|
|
144
|
+
|
|
145
|
+
def validate_header(member_count, xin:)
|
|
146
|
+
raise ArgumentError, 'invalid address version' unless version == MIX_ADDRESS_VERSION
|
|
147
|
+
raise ArgumentError, 'invalid address member count' unless member_count.between?(1, 64)
|
|
148
|
+
|
|
149
|
+
# Kernel storage uses a sparse XIN threshold of 64 with a single key.
|
|
150
|
+
return if threshold.is_a?(Integer) && threshold.between?(1, xin ? 255 : member_count)
|
|
151
|
+
|
|
152
|
+
raise ArgumentError, 'invalid address threshold'
|
|
153
|
+
end
|
|
157
154
|
end
|
|
158
155
|
|
|
159
156
|
class MainAddress
|
|
157
|
+
STORAGE_ADDRESS = 'XINSwYaJPnKiwBWqXm4i3e3My9GKguReMRyB1sRSexeHcQ7V66RWsicAiR2dokcQ5kiJsfY5QbEjTcqRQRCxkEyENBaz4AeB'
|
|
158
|
+
|
|
160
159
|
attr_accessor :public_key, :address
|
|
161
160
|
|
|
162
161
|
def initialize(**args)
|
|
@@ -170,10 +169,12 @@ module MixinBot
|
|
|
170
169
|
end
|
|
171
170
|
|
|
172
171
|
def encode
|
|
172
|
+
raise ArgumentError, 'invalid XIN public key length' unless public_key.is_a?(String) && public_key.bytesize == MAIN_ADDRESS_LENGTH
|
|
173
|
+
|
|
173
174
|
msg = MAIN_ADDRESS_PREFIX + public_key
|
|
174
175
|
checksum = SHA3::Digest::SHA3_256.digest msg
|
|
175
176
|
data = public_key + checksum[0...4]
|
|
176
|
-
base58 = Base58.
|
|
177
|
+
base58 = MixinBot::Utils::Base58.encode data
|
|
177
178
|
self.address = "#{MAIN_ADDRESS_PREFIX}#{base58}"
|
|
178
179
|
|
|
179
180
|
address
|
|
@@ -182,8 +183,8 @@ module MixinBot
|
|
|
182
183
|
def decode
|
|
183
184
|
raise ArgumentError, 'invalid address' unless address.start_with? MAIN_ADDRESS_PREFIX
|
|
184
185
|
|
|
185
|
-
data = address[MAIN_ADDRESS_PREFIX.length..]
|
|
186
|
-
|
|
186
|
+
data = MixinBot::Utils::Base58.decode(address[MAIN_ADDRESS_PREFIX.length..])
|
|
187
|
+
raise ArgumentError, 'invalid XIN address length' unless data.bytesize == MAIN_ADDRESS_LENGTH + 4
|
|
187
188
|
|
|
188
189
|
payload = data[...-4]
|
|
189
190
|
|
|
@@ -192,6 +193,7 @@ module MixinBot
|
|
|
192
193
|
|
|
193
194
|
raise ArgumentError, 'invalid address' unless checksum[0...4] == data[-4..]
|
|
194
195
|
|
|
196
|
+
validate_public_key(payload)
|
|
195
197
|
self.public_key = payload
|
|
196
198
|
|
|
197
199
|
public_key
|
|
@@ -207,7 +209,16 @@ module MixinBot
|
|
|
207
209
|
spend_key = MixinBot::Utils.shared_public_key(seed)
|
|
208
210
|
view_key = MixinBot::Utils.shared_public_key(src)
|
|
209
211
|
|
|
210
|
-
|
|
212
|
+
new(public_key: spend_key + view_key)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
private
|
|
216
|
+
|
|
217
|
+
def validate_public_key(key)
|
|
218
|
+
valid = key.is_a?(String) && key.bytesize == MAIN_ADDRESS_LENGTH &&
|
|
219
|
+
MixinBot.utils.valid_xin_point?(key.byteslice(0, 32)) &&
|
|
220
|
+
MixinBot.utils.valid_xin_point?(key.byteslice(32, 32))
|
|
221
|
+
raise ArgumentError, 'invalid XIN public key' unless valid
|
|
211
222
|
end
|
|
212
223
|
end
|
|
213
224
|
end
|
|
@@ -22,14 +22,7 @@ module MixinBot
|
|
|
22
22
|
attachment = create_attachment['data']
|
|
23
23
|
|
|
24
24
|
url = attachment.delete('upload_url')
|
|
25
|
-
conn =
|
|
26
|
-
f.adapter :net_http
|
|
27
|
-
|
|
28
|
-
f.request :multipart
|
|
29
|
-
f.request :retry
|
|
30
|
-
f.response :raise_error
|
|
31
|
-
f.response :logger if config.debug
|
|
32
|
-
end
|
|
25
|
+
conn = build_upload_connection(url)
|
|
33
26
|
|
|
34
27
|
conn.put(url) do |req|
|
|
35
28
|
req.headers = {
|
|
@@ -52,6 +45,23 @@ module MixinBot
|
|
|
52
45
|
path = format('/attachments/%<id>s', id: attachment_id)
|
|
53
46
|
client.get path, access_token:
|
|
54
47
|
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def build_upload_connection(url)
|
|
52
|
+
conn_opts = { url: }
|
|
53
|
+
conn_opts[:proxy] = config.proxy_config.faraday_options if config.proxy_config
|
|
54
|
+
|
|
55
|
+
Faraday.new(**conn_opts) do |f|
|
|
56
|
+
f.adapter :net_http
|
|
57
|
+
|
|
58
|
+
f.request :multipart
|
|
59
|
+
f.request :retry
|
|
60
|
+
f.options.timeout = config.http_timeout if config.http_timeout
|
|
61
|
+
f.response :raise_error
|
|
62
|
+
f.response :logger if config.debug
|
|
63
|
+
end
|
|
64
|
+
end
|
|
55
65
|
end
|
|
56
66
|
end
|
|
57
67
|
end
|
data/lib/mixin_bot/api/blaze.rb
CHANGED
|
@@ -7,11 +7,16 @@ module MixinBot
|
|
|
7
7
|
access_token = access_token('GET', '/', '')
|
|
8
8
|
|
|
9
9
|
authorization = format('Bearer %<access_token>s', access_token:)
|
|
10
|
+
options = {
|
|
11
|
+
headers: { 'Authorization' => authorization, 'User-Agent' => "mixin_bot/#{MixinBot::VERSION}" },
|
|
12
|
+
ping: 60
|
|
13
|
+
}
|
|
14
|
+
options[:proxy] = config.proxy_config.faye_options if config.proxy_config
|
|
15
|
+
|
|
10
16
|
Faye::WebSocket::Client.new(
|
|
11
17
|
format('wss://%<host>s/', host: config.blaze_host),
|
|
12
18
|
['Mixin-Blaze-1'],
|
|
13
|
-
|
|
14
|
-
ping: 60
|
|
19
|
+
options
|
|
15
20
|
)
|
|
16
21
|
end
|
|
17
22
|
|