ledger-rig 0.2.0__tar.gz

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 (39) hide show
  1. ledger_rig-0.2.0/.github/workflows/ci.yml +47 -0
  2. ledger_rig-0.2.0/.github/workflows/keychain-307.yml +199 -0
  3. ledger_rig-0.2.0/.github/workflows/keychain-runbook.yml +103 -0
  4. ledger_rig-0.2.0/.github/workflows/release.yml +42 -0
  5. ledger_rig-0.2.0/CHANGELOG.md +21 -0
  6. ledger_rig-0.2.0/LICENSE +21 -0
  7. ledger_rig-0.2.0/PKG-INFO +22 -0
  8. ledger_rig-0.2.0/README.md +111 -0
  9. ledger_rig-0.2.0/action.yml +52 -0
  10. ledger_rig-0.2.0/examples/keychain/README.md +6 -0
  11. ledger_rig-0.2.0/examples/keychain/keychain-307.md +108 -0
  12. ledger_rig-0.2.0/examples/keychain/runbook.md +25 -0
  13. ledger_rig-0.2.0/harness/keychain/Cargo.toml +10 -0
  14. ledger_rig-0.2.0/harness/keychain/patches/release-claim-before-reply-aa66be2.patch +35 -0
  15. ledger_rig-0.2.0/harness/keychain/patches/release-claim-before-reply-cd5982c.patch +35 -0
  16. ledger_rig-0.2.0/harness/keychain/patches/release-claim-before-reply.patch +35 -0
  17. ledger_rig-0.2.0/harness/keychain/src/main.rs +391 -0
  18. ledger_rig-0.2.0/ledger_rig/__init__.py +0 -0
  19. ledger_rig-0.2.0/ledger_rig/__main__.py +89 -0
  20. ledger_rig-0.2.0/ledger_rig/bridge.py +125 -0
  21. ledger_rig-0.2.0/ledger_rig/buttons.py +47 -0
  22. ledger_rig-0.2.0/ledger_rig/framing.py +56 -0
  23. ledger_rig-0.2.0/ledger_rig/hold.py +23 -0
  24. ledger_rig-0.2.0/ledger_rig/rig.py +98 -0
  25. ledger_rig-0.2.0/ledger_rig/seeds.py +22 -0
  26. ledger_rig-0.2.0/ledger_rig/uhid.py +42 -0
  27. ledger_rig-0.2.0/post/action.yml +10 -0
  28. ledger_rig-0.2.0/post/index.js +8 -0
  29. ledger_rig-0.2.0/pyproject.toml +35 -0
  30. ledger_rig-0.2.0/scripts/build-solana-app.sh +19 -0
  31. ledger_rig-0.2.0/tests/bip39_english.txt +2048 -0
  32. ledger_rig-0.2.0/tests/fake_apdu.py +27 -0
  33. ledger_rig-0.2.0/tests/test_bridge_uhid.py +232 -0
  34. ledger_rig-0.2.0/tests/test_buttons.py +153 -0
  35. ledger_rig-0.2.0/tests/test_framing.py +49 -0
  36. ledger_rig-0.2.0/tests/test_hold.py +81 -0
  37. ledger_rig-0.2.0/tests/test_release.py +33 -0
  38. ledger_rig-0.2.0/tests/test_rig_solana.py +116 -0
  39. ledger_rig-0.2.0/tests/test_runbook_workflow.py +47 -0
@@ -0,0 +1,47 @@
1
+ name: ci
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ env:
7
+ SOLANA_APP_TAG: af6ed454f0ed39cad8a5e1bca544ced18350a403
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - uses: actions/setup-python@v5
11
+ with:
12
+ python-version: "3.11"
13
+ - uses: actions/cache@v4
14
+ id: solana-app
15
+ with:
16
+ path: apps/solana-nanosp-${{ env.SOLANA_APP_TAG }}.elf
17
+ key: solana-nanosp-${{ env.SOLANA_APP_TAG }}
18
+ - if: steps.solana-app.outputs.cache-hit != 'true'
19
+ run: bash scripts/build-solana-app.sh "$SOLANA_APP_TAG"
20
+ - run: test "$(head -c 4 "apps/solana-nanosp-$SOLANA_APP_TAG.elf" | od -An -tx1 | tr -d ' \n')" = 7f454c46
21
+ - run: pip install -e ".[test]" solders==0.27.0
22
+ - run: ruff check .
23
+ - run: ruff format --check .
24
+ - run: pytest
25
+ - run: sudo apt-get install -y -qq libhidapi-hidraw0
26
+ - run: sudo modprobe uhid
27
+ - run: sudo SOLANA_APP_TAG="$SOLANA_APP_TAG" "$(which python)" -m pytest -m uhid
28
+ action:
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: ./post
33
+ with:
34
+ run: test -z "$(docker ps -q --filter label=ledger-rig)"
35
+ - uses: ./
36
+ id: rig
37
+ with:
38
+ count: 2
39
+ - env:
40
+ HIDRAW: ${{ steps.rig.outputs.hidraw }}
41
+ run: |
42
+ set -- $HIDRAW
43
+ test $# -eq 2
44
+ for path; do
45
+ test -c "$path"
46
+ test -r "$path" -a -w "$path"
47
+ done
@@ -0,0 +1,199 @@
1
+ name: keychain-307
2
+ on:
3
+ push:
4
+ workflow_dispatch:
5
+ inputs:
6
+ repeat:
7
+ type: number
8
+ default: 1
9
+ jobs:
10
+ run:
11
+ runs-on: ubuntu-latest
12
+ continue-on-error: true
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ commit: [cd5982c, cd5982c+claim, aa66be2, aa66be2+claim]
17
+ env:
18
+ COMMIT: ${{ matrix.commit }}
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/checkout@v4
22
+ with:
23
+ repository: caliperforge/solana-keychain
24
+ path: keychain
25
+ fetch-depth: 0
26
+ - run: |
27
+ git -C keychain fetch https://github.com/solana-foundation/solana-keychain cd5982c283e30328f1a0f13e754748633eb6bd06
28
+ git -C keychain checkout --detach "${COMMIT%+claim}"
29
+ - if: endsWith(matrix.commit, '+claim')
30
+ run: |
31
+ git -C keychain apply ../harness/keychain/patches/release-claim-before-reply-${COMMIT%+claim}.patch
32
+ git -C keychain diff --quiet && { echo "no reply.send line changed" >&2; exit 1; }
33
+ git -C keychain diff > "release-claim-${COMMIT%+claim}.patch"
34
+ echo "BASE=${COMMIT%+claim}" >> "$GITHUB_ENV"
35
+ - if: endsWith(matrix.commit, '+claim')
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: release-claim-${{ env.BASE }}.patch
39
+ path: release-claim-${{ env.BASE }}.patch
40
+ - run: sudo apt-get install -y -qq libudev-dev pkg-config strace
41
+ - uses: dtolnay/rust-toolchain@stable
42
+ - run: cp keychain/rust/Cargo.lock harness/keychain/
43
+ - run: cargo build --release
44
+ working-directory: harness/keychain
45
+ - uses: ./
46
+ id: rig
47
+ with:
48
+ count: 2
49
+ - id: keys
50
+ run: |
51
+ "$RUNNER_TEMP/ledger-rig/bin/pip" install solders==0.27.0
52
+ "$RUNNER_TEMP/ledger-rig/bin/python" - >> "$GITHUB_OUTPUT" <<'EOF'
53
+ import hashlib
54
+ from solders.keypair import Keypair
55
+ from ledger_rig.seeds import SEEDS
56
+ keys = []
57
+ for mnemonic in SEEDS[:2]:
58
+ seed = hashlib.pbkdf2_hmac("sha512", mnemonic.encode(), b"mnemonic", 2048)
59
+ keypair = Keypair.from_seed_and_derivation_path(seed, "m/44'/501'/0'")
60
+ keys.append(str(keypair.pubkey()))
61
+ print("keys=" + " ".join(keys))
62
+ EOF
63
+ - env:
64
+ KEYS: ${{ steps.keys.outputs.keys }}
65
+ REPEAT: ${{ inputs.repeat || 1 }}
66
+ run: |
67
+ bridge_logs="/tmp/ledger-rig/bridge-0000.log /tmp/ledger-rig/bridge-0001.log"
68
+ sizes=$(stat -c %s $bridge_logs)
69
+ last=
70
+ until [ "$sizes" = "$last" ]; do
71
+ [ "$SECONDS" -lt 60 ] || { echo "bridge logs still growing after 60 s" >&2; exit 1; }
72
+ last=$sizes
73
+ sleep 2
74
+ sizes=$(stat -c %s $bridge_logs)
75
+ done
76
+ mkdir logs
77
+ declare -A size
78
+ for pass in $(seq "$REPEAT"); do
79
+ hidraw=()
80
+ for serial in 0000 0001; do
81
+ node=$(grep -lx "HID_UNIQ=$serial" /sys/class/hidraw/*/device/uevent)
82
+ node=${node%/device/uevent}
83
+ hidraw+=("/dev/${node##*/}")
84
+ done
85
+ for scenario in A B C D E G; do
86
+ for serial in 0000 0001; do
87
+ size[$serial]=$(stat -c %s "/tmp/ledger-rig/bridge-$serial.log" 2>/dev/null || echo 0)
88
+ done
89
+ status=0
90
+ sudo strace -f -qq -e trace=openat -o "trace-$scenario" \
91
+ harness/keychain/target/release/keychain-harness "$scenario" "$COMMIT" "${hidraw[@]}" $KEYS \
92
+ > "line-$scenario" || status=$?
93
+ for serial in 0000 0001; do
94
+ tail -c +$((size[$serial] + 1)) "/tmp/ledger-rig/bridge-$serial.log" \
95
+ > "logs/bridge-$serial-$COMMIT-$scenario-$pass.log"
96
+ done
97
+ if [ ! -s "line-$scenario" ]; then
98
+ jq -nc --arg commit "$COMMIT" --arg scenario "$scenario" --arg error "no result (exit $status)" \
99
+ '{$commit, $scenario, pass: false, $error, detail: $error}' > "line-$scenario"
100
+ fi
101
+ opens=$(grep -c '"/dev/hidraw' "trace-$scenario" || true)
102
+ tail -n 1 "line-$scenario" | jq -c --argjson opens "$opens" '. + {hid_opens: $opens}' >> "results-$COMMIT.jsonl"
103
+ done
104
+ done
105
+ - env:
106
+ KEYS: ${{ steps.keys.outputs.keys }}
107
+ run: |
108
+ sudo "$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig down
109
+ while [ -e /tmp/ledger-rig/bridge-0000.sock ]; do
110
+ [ "$SECONDS" -lt 60 ] || { echo "bridge-0000.sock still there after 60 s" >&2; exit 1; }
111
+ sleep 1
112
+ done
113
+ hidraw=$(sudo "$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig up --count 1 --locked --app "$RUNNER_TEMP"/apps/solana-nanosp-*.elf | cut -d' ' -f1)
114
+ size=$(stat -c %s /tmp/ledger-rig/bridge-0000.log)
115
+ status=0
116
+ sudo env PATH="$RUNNER_TEMP/ledger-rig/bin:$PATH" \
117
+ harness/keychain/target/release/keychain-harness F "$COMMIT" "$hidraw" - $KEYS > line-F || status=$?
118
+ tail -c +$((size + 1)) /tmp/ledger-rig/bridge-0000.log > "logs/bridge-0000-$COMMIT-F.log"
119
+ if [ ! -s line-F ]; then
120
+ jq -nc --arg commit "$COMMIT" --arg error "no result (exit $status)" \
121
+ '{$commit, scenario: "F", pass: false, $error, detail: $error}' > line-F
122
+ fi
123
+ cat line-F >> "results-$COMMIT.jsonl"
124
+ - uses: actions/upload-artifact@v4
125
+ with:
126
+ name: results-${{ matrix.commit }}
127
+ path: results-${{ matrix.commit }}.jsonl
128
+ - uses: actions/upload-artifact@v4
129
+ with:
130
+ name: bridge-logs-${{ matrix.commit }}
131
+ path: logs
132
+ open-app:
133
+ runs-on: ubuntu-latest
134
+ steps:
135
+ - uses: actions/checkout@v4
136
+ - uses: actions/checkout@v4
137
+ with:
138
+ repository: caliperforge/solana-keychain
139
+ path: keychain
140
+ fetch-depth: 0
141
+ - run: |
142
+ git -C keychain fetch https://github.com/solana-foundation/solana-keychain cd5982c283e30328f1a0f13e754748633eb6bd06
143
+ git -C keychain checkout --detach cd5982c283e30328f1a0f13e754748633eb6bd06
144
+ - run: sudo apt-get install -y -qq libudev-dev pkg-config
145
+ - uses: dtolnay/rust-toolchain@stable
146
+ - uses: ./
147
+ with:
148
+ count: 1
149
+ dashboard: true
150
+ - working-directory: keychain/rust
151
+ run: |
152
+ bin=$(cargo test --no-run --lib --no-default-features --features all,sdk-v3,unsafe-debug,integration-tests,ledger --message-format=json | jq -r 'select(.profile.test == true) | .executable')
153
+ sudo "$bin" tests::test_ledger_integration::tests::test_ledger_integration_open_app --exact --ignored --nocapture | tee open-app.log
154
+ grep -q 'test_ledger_integration_open_app ... ok' open-app.log
155
+ table:
156
+ needs: run
157
+ if: always()
158
+ runs-on: ubuntu-latest
159
+ steps:
160
+ - uses: actions/download-artifact@v4
161
+ with:
162
+ pattern: results-*
163
+ merge-multiple: true
164
+ path: results
165
+ - run: |
166
+ shopt -s nullglob
167
+ jq -rs '
168
+ def cell: tostring | gsub("\\|"; "\\|") | gsub("\n"; " ");
169
+ "| commit | scenario | result | error | detail | wall ms | HID opens |",
170
+ "|---|---|---|---|---|---|---|",
171
+ (. as $rows | ("cd5982c", "aa66be2") as $c | ("A", "B", "C", "D", "E", "F", "G") as $s
172
+ | ($rows | map(select(.commit == $c and .scenario == $s)) | first) as $r
173
+ | if $r == null then "| \($c) | \($s) | missing | | | | |"
174
+ else "| \($c) | \($s) | \(if $r.pass then "pass" else "fail" end) | \($r.error // "" | cell) | \(($r.detail // "")[:200] | cell) | \($r.wall_ms // "") | \($r.hid_opens // "") |"
175
+ end)
176
+ ' /dev/null results/*.jsonl > results.md
177
+ echo >> results.md
178
+ jq -rs '
179
+ def busy: .detail // "" | test("Ledger is busy|call 2 of 2 returned false");
180
+ "| commit | runs | busy A | busy B | busy C | busy D | busy E (50 calls, 1 device) | other failures |",
181
+ "|---|---|---|---|---|---|---|---|",
182
+ (. as $rows | ("cd5982c", "cd5982c+claim", "aa66be2", "aa66be2+claim") as $c
183
+ | ($rows | map(select(.commit == $c and .scenario != "F" and (.pass | not)))) as $f
184
+ | "| \($c) | \($rows | map(select(.commit == $c and .scenario == "A")) | length) | \([("A", "B", "C", "D", "E") as $s | $f | map(select(.scenario == $s and busy)) | length] | join(" | ")) | \($f | map(select(busy | not)) | length) |")
185
+ ' /dev/null results/*.jsonl >> results.md
186
+ - uses: actions/upload-artifact@v4
187
+ with:
188
+ name: results
189
+ path: results.md
190
+ - run: |
191
+ cat results.md
192
+ jq -se 'all(.[]; .pass or ((.detail // "") != ""))' results/*.jsonl
193
+ if [ "$GITHUB_EVENT_NAME" = push ]; then
194
+ for scenario in A B C D E; do
195
+ grep -Eq "^\| aa66be2 \| $scenario \| (pass|fail \|[^|]*\|[^|]*(Ledger is busy|call 2 of 2 returned false)[^|]*) \|" results.md
196
+ done
197
+ grep -Eq '^\| aa66be2 \| G \| pass \|[^|]*\|[^|]*UserRejected' results.md
198
+ jq -se '[.[] | select(.scenario == "F")] | length == 4 and all(.pass)' results/*.jsonl
199
+ fi
@@ -0,0 +1,103 @@
1
+ name: keychain-runbook
2
+ on:
3
+ push:
4
+ workflow_dispatch:
5
+ jobs:
6
+ phase:
7
+ name: phase ${{ matrix.phase }}
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ include:
13
+ - { phase: "1", expect: pass, count: 1 }
14
+ - { phase: "2", expect: fail, count: 1, locked: true }
15
+ - { phase: "3", expect: fail, count: 1 }
16
+ - { phase: "4a", expect: pass, count: 1, dashboard: true }
17
+ - { phase: "4b", expect: pass, count: 1, dashboard: true }
18
+ - { phase: "5", expect: nocrash, count: 1 }
19
+ - { phase: "6", expect: nocrash, count: 1 }
20
+ - { phase: "7", expect: pass, count: 1 }
21
+ - { phase: "9", expect: pass, count: 1 }
22
+ - { phase: "10a", expect: fail, count: 2 }
23
+ - { phase: "11a", expect: pass, count: 1 }
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/checkout@v4
27
+ with:
28
+ repository: caliperforge/solana-keychain
29
+ path: keychain
30
+ fetch-depth: 0
31
+ - run: |
32
+ git -C keychain fetch https://github.com/solana-foundation/solana-keychain cd5982c283e30328f1a0f13e754748633eb6bd06
33
+ git -C keychain checkout --detach cd5982c283e30328f1a0f13e754748633eb6bd06
34
+ - run: sudo apt-get install -y -qq libudev-dev pkg-config
35
+ - uses: dtolnay/rust-toolchain@stable
36
+ - run: cargo install just --locked
37
+ - uses: ./
38
+ with:
39
+ count: ${{ matrix.count }}
40
+ dashboard: ${{ matrix.dashboard || false }}
41
+ - if: matrix.locked
42
+ run: |
43
+ sudo "$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig down
44
+ while [ -e /tmp/ledger-rig/bridge-0000.sock ]; do
45
+ [ "$SECONDS" -lt 60 ] || { echo "bridge-0000.sock still there after 60 s" >&2; exit 1; }
46
+ sleep 1
47
+ done
48
+ sudo "$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig up --count 1 --locked --app "$RUNNER_TEMP"/apps/solana-nanosp-*.elf
49
+ - working-directory: keychain
50
+ env:
51
+ PHASE: ${{ matrix.phase }}
52
+ EXPECT: ${{ matrix.expect }}
53
+ run: |
54
+ rig() { sudo "$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig "$@"; }
55
+ recipe() { sudo env "PATH=$PATH" "HOME=$HOME" ${blind:+"LEDGER_BLIND_SIGNING=$blind"} just "$@"; }
56
+ press() { for choice; do until rig "$choice" 0000; do :; done; done; }
57
+ node() { grep -qx HID_UNIQ=0000 /sys/class/hidraw/*/device/uevent; }
58
+ restart() {
59
+ pid=$(pgrep -f 'ledger_rig bridge .*--serial 0000')
60
+ mapfile -d '' argv < "/proc/$pid/cmdline"
61
+ sudo kill -9 "$pid"
62
+ while node; do sleep 0.1; done
63
+ sudo systemd-run --quiet --collect --property=StandardError=append:/tmp/ledger-rig/bridge-0000.log -- "${argv[@]}"
64
+ until node; do sleep 0.1; done
65
+ }
66
+ case $PHASE in
67
+ 7) set -- rust-ledger-hw-test test_ledger_rejection_does_not_kill_the_session ;;
68
+ 9) set -- rust-ledger-hw-test test_ledger_probe_returns_while_a_signature_is_pending ;;
69
+ 11a) blind=disabled; set -- rust-ledger-hw-test test_ledger_non_ascii_offchain_message_needs_blind_signing ;;
70
+ 4a) set -- rust-ledger-open-app ;;
71
+ 4b) recipe rust-ledger-open-app; set -- rust-test-ledger ;;
72
+ *) set -- rust-test-ledger ;;
73
+ esac
74
+ case $PHASE in
75
+ 1 | 4b) press approve approve > driver.log 2>&1 & ;;
76
+ 3) rig hold 0000 > driver.log 2>&1 & ;;
77
+ 5) { until grep -qs 'test_ledger_sign_offchain_message \.\.\.' phase.log; do sleep 1; done; restart; } > driver.log 2>&1 & ;;
78
+ 7) press reject approve > driver.log 2>&1 & ;;
79
+ 9) { until grep -qs 'You may now REJECT' phase.log; do sleep 1; done; press reject; } > driver.log 2>&1 & ;;
80
+ esac
81
+ if [ "$PHASE" = 6 ]; then
82
+ status=0
83
+ for run in $(seq 20); do
84
+ recipe rust-ledger-hw-reconnect 2>&1 | tee -a phase.log; rc=${PIPESTATUS[0]}
85
+ echo "run $run of 20: exit $rc"
86
+ [ "$rc" -le "$status" ] || status=$rc
87
+ done
88
+ else
89
+ recipe "$@" 2>&1 | tee phase.log; status=${PIPESTATUS[0]}
90
+ fi
91
+ kill $(jobs -p) 2>/dev/null || true
92
+ sudo pkill -f 'ledger_rig (approve|reject|hold) 0000' || true
93
+ cat driver.log 2>/dev/null || true
94
+ if [ "$EXPECT" = nocrash ]; then
95
+ grep -q NotAvailable phase.log && seen=seen || seen="not seen"
96
+ grep -q 'Ledger is busy' phase.log && busy=seen || busy="not seen"
97
+ echo "phase $PHASE: suite exit $status, NotAvailable $seen, busy $busy" >> "$GITHUB_STEP_SUMMARY"
98
+ fi
99
+ [ "$status" -le 128 ] || { echo "phase $PHASE crashed: signal $((status - 128))" >&2; exit 1; }
100
+ case $EXPECT:$status in
101
+ pass:0 | fail:[1-9]* | nocrash:*) ;;
102
+ *) echo "phase $PHASE expected $EXPECT, got exit $status" >&2; exit 1 ;;
103
+ esac
@@ -0,0 +1,42 @@
1
+ name: release
2
+ on: [push, pull_request]
3
+ jobs:
4
+ build:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: actions/setup-python@v5
9
+ with:
10
+ python-version: "3.11"
11
+ - run: pip install build
12
+ - run: python -m build
13
+ - run: ls dist/*.tar.gz dist/*.whl
14
+ - uses: actions/upload-artifact@v4
15
+ with:
16
+ name: dist
17
+ path: dist/
18
+ release:
19
+ needs: build
20
+ if: startsWith(github.ref, 'refs/tags/v')
21
+ runs-on: ubuntu-latest
22
+ environment: pypi
23
+ permissions:
24
+ contents: write
25
+ id-token: write
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - uses: actions/download-artifact@v4
29
+ with:
30
+ name: dist
31
+ path: dist/
32
+ - id: tag
33
+ run: |
34
+ if [[ $GITHUB_REF_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
35
+ echo "release=true" >> "$GITHUB_OUTPUT"
36
+ fi
37
+ - if: steps.tag.outputs.release == 'true'
38
+ uses: pypa/gh-action-pypi-publish@release/v1
39
+ - if: steps.tag.outputs.release == 'true'
40
+ run: |
41
+ git tag -f v0 "$GITHUB_SHA"
42
+ git push -f origin refs/tags/v0
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ - `up` and the Action's `count` take up to 8 devices.
6
+ - `up` prints `<hidraw> <serial> <apdu port> <api port>` for each device.
7
+ - `press` sends one button press; `approve` and `reject` walk a Solana sign review to that choice.
8
+ - `--locked` on `bridge` and `up` starts a bridge locked; `lock` and `unlock` toggle it.
9
+ - `--dashboard` on `bridge` and `up`, and the Action's `dashboard` input, start each device as the BOLOS dashboard.
10
+ - `hold` opens a device and sends get-app-version on a timer, as a stand-in for another app holding the Ledger.
11
+ - `.github/workflows/keychain-runbook.yml` and `examples/keychain/runbook.md` mark which phases of solana-keychain's hardware runbook run on the rig.
12
+ - The keychain docs move from `docs/` to `examples/keychain/`.
13
+ - The README leads with a quickstart.
14
+
15
+ ## 0.1.0
16
+
17
+ - `bridge` connects a Speculos APDU socket to a uhid hidraw device and logs one line per APDU.
18
+ - `up` and `down` start and remove at most 2 devices; `up` prints `<hidraw> <serial> <apdu port>` for each.
19
+ - `scripts/build-solana-app.sh` builds the app-solana ELF.
20
+ - The Action `caliperforge/ledger-rig@v0` takes `count` (at most 2) and `app-tag`, outputs `hidraw`, and removes the devices after the job.
21
+ - The keychain-307 harness, `docs/keychain-307.md` and `.github/workflows/keychain-307.yml` run solana-keychain against two rig devices.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CaliperForge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.5
2
+ Name: ledger-rig
3
+ Version: 0.2.0
4
+ Summary: Speculos Solana Ledger Nano S Plus devices as Linux hidraw devices, for CI
5
+ Project-URL: Homepage, https://github.com/caliperforge/ledger-rig
6
+ Project-URL: Source, https://github.com/caliperforge/ledger-rig
7
+ Project-URL: Changelog, https://github.com/caliperforge/ledger-rig/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/caliperforge/ledger-rig/issues
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Topic :: Software Development :: Testing
17
+ Requires-Python: >=3.11
18
+ Provides-Extra: test
19
+ Requires-Dist: hid; extra == 'test'
20
+ Requires-Dist: pytest; extra == 'test'
21
+ Requires-Dist: pyyaml; extra == 'test'
22
+ Requires-Dist: ruff; extra == 'test'
@@ -0,0 +1,111 @@
1
+ # ledger-rig
2
+
3
+ Runs Solana Ledger Nano S Plus devices on Linux for tests: each is a Speculos emulator bridged through uhid to a USB HID Ledger device, opened by clients as `/dev/hidraw*`. It is for hidapi and hidraw clients that need a Ledger in CI with no hardware, where the code cannot be pointed at Speculos over TCP, such as Rust `hidapi` wallets.
4
+
5
+ ## In GitHub Actions
6
+
7
+ ```yaml
8
+ - uses: caliperforge/ledger-rig@v0
9
+ id: rig
10
+ with:
11
+ count: 2
12
+ - run: pytest
13
+ env:
14
+ LEDGER_HIDRAW: ${{ steps.rig.outputs.hidraw }}
15
+ ```
16
+
17
+ `hidraw` holds the device paths, space-separated, readable and writable by the job user. `app-tag` sets the app-solana commit; its ELF is built once and cached. `dashboard: true` starts each device as the BOLOS dashboard, as `--dashboard` does; the node a device comes back at after opening Solana is root-only. The devices are removed after the job's main steps.
18
+
19
+ ## On your machine
20
+
21
+ - Linux with `/dev/uhid` (`sudo modprobe uhid`)
22
+ - root
23
+ - Python 3.11+
24
+
25
+ ```sh
26
+ pip install -e .
27
+ bash scripts/build-solana-app.sh <tag>
28
+ sudo python -m ledger_rig up --count 2 --app apps/solana-nanosp-<tag>.elf
29
+ python -m ledger_rig approve 0000
30
+ sudo python -m ledger_rig down
31
+ ```
32
+
33
+ `up` starts one Speculos container and one bridge per device and prints `<hidraw> <serial> <apdu port> <api port>` for each. Each bridge appends its log to `/tmp/ledger-rig/bridge-<serial>.log`. `down` removes the containers; their bridges exit with them.
34
+
35
+ `press` sends one `left`, `right` or `both` button press to that device's Speculos API. `approve` and `reject` wait for a Solana sign review, press right through its screens to that choice, then press both.
36
+
37
+ ## Commands
38
+
39
+ ```sh
40
+ sudo python -m ledger_rig up --count 2 --app apps/solana-nanosp-<tag>.elf --dashboard
41
+ python -m ledger_rig press 0000 right
42
+ python -m ledger_rig reject 0000
43
+ ```
44
+
45
+ ```sh
46
+ sudo python -m ledger_rig bridge --apdu 127.0.0.1:9999 --serial 0001
47
+ sudo python -m ledger_rig bridge --apdu 127.0.0.1:9999 --serial 0001 --dashboard
48
+ sudo python -m ledger_rig unlock 0001
49
+ sudo python -m ledger_rig lock 0001
50
+ ```
51
+
52
+ `9999` is the Speculos APDU port. Run one bridge per device, each with its own `--serial`.
53
+
54
+ ## Locked
55
+
56
+ With `--locked` on `bridge` or `up`, a bridge starts locked: it answers every APDU with `5515` and forwards nothing. `unlock <serial>` makes it forward, `lock <serial>` locks it again; both reach the bridge through `/tmp/ledger-rig/bridge-<serial>.sock`.
57
+
58
+ ## Dashboard
59
+
60
+ With `--dashboard` on `bridge` or `up`, the device starts as the BOLOS dashboard: it answers get-app-and-version with `BOLOS` and refuses other APDUs. Opening `Solana` answers `9000`, recreates the device at a new `/dev/hidraw*` path and forwards to Speculos from then on.
61
+
62
+ ## Hold
63
+
64
+ ```sh
65
+ sudo python -m ledger_rig hold 0001 --every 2
66
+ ```
67
+
68
+ `hold` is a stand-in for another app holding the Ledger, such as Ledger Live. It opens the device's `/dev/hidraw*` node and sends get-app-version (`e001000000`) every `--every` seconds (default 2) until interrupted. This is not Ledger Live's real traffic, which was never checked.
69
+
70
+ ## Logs
71
+
72
+ The bridge logs one line per APDU, command then response with its status word:
73
+
74
+ ```
75
+ 2026-11-10T12:00:00.000 -> 5 e001000000
76
+ 2026-11-10T12:00:00.004 <- 5 9000 0102039000
77
+ ```
78
+
79
+ A locked bridge logs its reply as `<- 2 5515 5515`.
80
+
81
+ It exits once the APDU socket closes.
82
+
83
+ ## Limits
84
+
85
+ - Linux only, with root for uhid
86
+ - hidraw behaviour only, not USB descriptors or macOS IOKit
87
+ - At most 8 devices
88
+ - Nano S Plus only
89
+ - Dashboard mode emulates only the hidraw path change on app launch, not the USB PID change
90
+
91
+ ## Tests
92
+
93
+ ```sh
94
+ pytest
95
+ sudo "$(which python)" -m pytest -m uhid
96
+ ```
97
+
98
+ ## Examples
99
+
100
+ [examples/keychain/](examples/keychain/) runs solana-keychain against two rig devices.
101
+
102
+ [examples/keychain/runbook.md](examples/keychain/runbook.md) marks which phases of solana-keychain's hardware runbook run on the rig.
103
+
104
+ ## Prior art
105
+
106
+ - [Speculos](https://github.com/LedgerHQ/speculos) is the emulator; this repo only bridges its APDU socket to the host.
107
+ - [Karrq/speculos-hid](https://github.com/Karrq/speculos-hid) (2023) bridged one Speculos to a uhid Ledger first. ledger-rig adds a second device, the GitHub Action, a cached app-solana build and the solana-keychain scenarios in `harness/`.
108
+
109
+ ## License
110
+
111
+ MIT
@@ -0,0 +1,52 @@
1
+ name: ledger-rig
2
+ description: Brings up Speculos Solana Ledger Nano S Plus devices as hidraw devices
3
+ inputs:
4
+ count:
5
+ description: Number of devices, at most 8
6
+ required: true
7
+ app-tag:
8
+ description: app-solana commit the ELF is built from
9
+ default: af6ed454f0ed39cad8a5e1bca544ced18350a403
10
+ dashboard:
11
+ description: Start each device as the BOLOS dashboard
12
+ default: false
13
+ outputs:
14
+ hidraw:
15
+ description: Space-separated hidraw paths, one per device
16
+ value: ${{ steps.up.outputs.hidraw }}
17
+ runs:
18
+ using: composite
19
+ steps:
20
+ - shell: bash
21
+ run: sudo modprobe uhid
22
+ - uses: actions/cache@v4
23
+ id: app
24
+ with:
25
+ path: ${{ runner.temp }}/apps/solana-nanosp-${{ inputs.app-tag }}.elf
26
+ key: ledger-rig-solana-nanosp-${{ inputs.app-tag }}
27
+ - if: steps.app.outputs.cache-hit != 'true'
28
+ shell: bash
29
+ working-directory: ${{ runner.temp }}
30
+ env:
31
+ TAG: ${{ inputs.app-tag }}
32
+ run: bash "$GITHUB_ACTION_PATH/scripts/build-solana-app.sh" "$TAG"
33
+ - shell: bash
34
+ run: |
35
+ python3 -m venv "$RUNNER_TEMP/ledger-rig"
36
+ "$RUNNER_TEMP/ledger-rig/bin/pip" install "$GITHUB_ACTION_PATH"
37
+ - shell: bash
38
+ run: cp -r "$GITHUB_ACTION_PATH/post" "$GITHUB_WORKSPACE/.ledger-rig-post"
39
+ - uses: ./.ledger-rig-post
40
+ with:
41
+ run: '"$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig down'
42
+ - id: up
43
+ shell: bash
44
+ env:
45
+ COUNT: ${{ inputs.count }}
46
+ TAG: ${{ inputs.app-tag }}
47
+ DASHBOARD: ${{ inputs.dashboard }}
48
+ run: |
49
+ [ "$DASHBOARD" = true ] && dashboard=--dashboard
50
+ hidraw=$(sudo "$RUNNER_TEMP/ledger-rig/bin/python" -m ledger_rig up --count "$COUNT" --app "$RUNNER_TEMP/apps/solana-nanosp-$TAG.elf" $dashboard | cut -d' ' -f1 | paste -sd' ')
51
+ sudo chmod a+rw $hidraw
52
+ echo "hidraw=$hidraw" >> "$GITHUB_OUTPUT"
@@ -0,0 +1,6 @@
1
+ # keychain example
2
+
3
+ Runs solana-keychain against two rig devices. Both workflows build the harness in `harness/keychain/`.
4
+
5
+ - `.github/workflows/keychain-307.yml` runs the two-device scenarios and the busy-race repeats: [keychain-307.md](keychain-307.md).
6
+ - `.github/workflows/keychain-runbook.yml` runs the runbook phases: [runbook.md](runbook.md).