Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff S committed Jul 18, 2021
0 parents commit bb8e2d6
Show file tree
Hide file tree
Showing 9,343 changed files with 4,324,192 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Compiled Sources
###################
*.o
*.a
*.elf
*.bin
*.map
*.hex
*.dis
*.exe

# Packages
############

# Logs and Databases
######################
*.log

# VIM Swap Files
######################
*.swp

# Build directories
######################
build/
build-*/

# Test failure outputs
######################
tests/results/*

# Python cache files
######################
__pycache__/
*.pyc

# Customized Makefile/project overrides
######################
GNUmakefile
user.props

# Generated rst files
######################
genrst/

# MacOS desktop metadata files
######################
.DS_Store
37 changes: 37 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

License
======

All the source code in this repository is either MIT or Apache v2.0 licensed. Most of the source files contain a license and copyright notice, so please check the individual files and subdirectories for more information.

The source code for the `MaixPy` firmware (which has been modified by the repository owner) is under the Apache v2.0 license. The source code within it related to `MicroPython` and `OpenMV` is released separately under the MIT license.

The source code for the `embit` library is under the MIT license.

The source code for the `Adafruit Thermal Printer` library is under the MIT license.

The source code for this project created and modified by the repository owner is released under the MIT license that follows:

```
The MIT License (MIT)
Copyright (c) 2021 Tom J. Sun
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Krux

---
## Disclaimer
**WARNING**: *While functional, this is alpha-quality software and could have bugs or other issues that might cause you to lose your coins. Use at your own risk!*

---

Krux is an open-source, airgapped bitcoin hardware wallet built with off-the-shelf parts that never stores your keys to disk and only works as a signer in a multisig setup.

To use Krux, you will need to buy an [M5StickV](https://shop.m5stack.com/products/stickv). The M5StickV was chosen because it has a processor, battery, buttons, screen, camera, and SD card slot all in one small unit, has no WiFi or Bluetooth functionality, and is cheap (< $50).

All operations in Krux are done via QR code. It loads your recovery phrase, imports a multisig wallet descriptor, and signs transactions all via QR code. It reads QR codes in with its camera and writes QR codes out to its screen or [to paper via an optional thermal printer attachment](#printing-qrs).

We don't want users to rely on Krux for anything except being a safe way to sign off on a multisig transaction when supplied a key. To this end, Krux will not generate new keys for you. Good random number generation is frought with peril, so we're sidestepping the issue by expecting you to [generate your own offline](https://vault12.rebelmouse.com/seed-phrase-generation-2650084084.html).

Krux is built to work with [Specter Desktop](https://github.com/cryptoadvance/specter-desktop), a desktop application where you can create and manage your multisig wallet, generate receive addresses, and send funds by creating partially signed bitcoin transactions (PSBTs) that you can sign with your hardware wallets.

# Getting Started
## Requirements
Python 3 (?)

## Load the firmware
First, head over to the `firmware` directory and follow the README there to build and install the firmware on your M5StickV's internal flash memory.

## Load the software
Then, plug a [supported microSD card](https://github.com/m5stack/m5-docs/blob/master/docs/en/core/m5stickv.md#tf-cardmicrosd-test) into your computer and run the following:

```
python3 flash_sd.py path/to/sd/card
```

This is a simple script that effectively copies the contents of the `src` directory onto the root of the card to be run by the firmware.

Finally, put the microSD card in your device and long-press its power button (left side) to boot it up! You should soon see the Krux logo appear on the screen. If after 30 seconds you still see a black screen, try power cycling the device by holding down the power button for six seconds.

# Using
## Opening Wallets
As stated above, Krux does not generate a 12-word BIP-39 passphrase for you, but it does expect you to have one in order to use it.

### Method: Manual
Enter each word of your 12-word BIP-39 passphrase one at a time. Krux will attempt to autocomplete your word to speed up the process.

### Method: QR
It's unpleasant having to manually enter 12 words each time you want to use Krux. To remedy this you can instead use the device's camera to read a QR code containing the 12 words (encoded as a single space-separated string). To make a QR code for this purpose in Krux, you can connect a thermal printer and print your recovery phrase after opening your wallet via the manual method first. Check out the [Printing QRs section](#printing-qrs) below for more information.

## Configuring Multisig
To setup a new multisig wallet, you will need to first add Krux as a new device in Specter by exporting your Extended Master Public Key (xpub) to it. When adding to Specter, choose the `Other` device type and click `Scan QR Code`. Go to your Krux, select `Public Key (xpub)`, and scan the QR code. It should import as a `#0 Multisig Sig (Segwit)` key. Repeat this process for as many keys / hardware wallets as you want to be in the multisig setup.

Once you've added all your devices to Specter, add a new wallet and select the devices you want to be in the multisig. A new wallet will then be created, which you will want to import into your Krux via `Multisig Policy`. In Specter, navigate to the `Advanced` section and find `Export to Wallet` to display a QR code that Krux can read. Once loaded, you can then print this QR code to have as a backup.

## Signing PSBTs
Krux will only sign transactions for multisig wallets, so make sure you have first set up a multisig policy and imported it into Krux before continuing.

Signing is straightforward, you just need to create a transaction to send funds somewhere in Specter via the `Send` section, then select to sign off on it with your Krux. Specter will display a QR code for the unsigned PSBT that you can read in with your Krux at which point you will see details about the transaction to confirm they match. It will then ask you for confirmation to sign the PSBT and will then generate its own QR code that you can either display directly back to Specter or print for use at a later time. Once all necessary cosigners have signed the PSBT, you can choose to broadcast it from Specter to the Bitcoin network.

## Printing QRs
Krux has the ability to print all QR codes it generates, including recovery phrase, xpub, multisig policy, and signed PSBT, via a locally-connected thermal printer over its serial port. Any of [these printers from Adafruit](https://www.adafruit.com/?q=thermal+printer) should do, but [this starter pack](https://www.adafruit.com/product/600) would be the quickest way to get started. You'll also need a conversion cable with a 4-pin female Grove connector on one end (to connect to the Krux) and 4-pin male jumpers on the other end (to connect to the printer).

Once connected and powered on, all screens that display a QR code will begin showing a follow-up screen asking if you want to `Print to QR?`. You can use the middle button to confirm or the right-side button to cancel.

Originally, the idea was to print out a QR code of the recovery phrase to enable faster wallet opening over the manual method of having to input each word. Then, we realized it would be useful to backup a wallet's multisig policy on paper as well (since you need knowledge of all xpubs in a multisig wallet in order to spend from it). After that, we decided to just make it a feature across the board. Want to make a "multisig paper wallet" with codes for your recovery phrase, xpub, and multisig policy on one sheet? You can! Want to print out a signed PSBT and send it in the mail? You can!

Just be careful what you do with the codes, since most smartphones can now quickly and easily read QR codes. Treat your QR passphrase the same way you would treat a plaintext copy of it.

# Inspired by these similar projects:
- https://github.com/SeedSigner/seedsigner for Raspberry Pi (Zero)
- https://github.com/diybitcoinhardware/f469-disco for the F469-Discovery board

# Support the Project
If you would like to help support the project, BTC is kindly accepted!

`19f8HVt8LZKzBv8CuBYnxCqn5sd75V658J`
33 changes: 33 additions & 0 deletions firmware/MaixPy/.github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Actual behaviour**
Tell us what happens instead

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Please complete the following information**
- IDE version: [e.g. 0.2.5]
- Firmware version: [e.g. 0.6.2]
- Board: [e.g. Maix Amigo]
- OS: [e.g. Windows/Linux/ios]
37 changes: 37 additions & 0 deletions firmware/MaixPy/.github/workflows/compile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is a basic workflow to help you get started with Actions

name: compile test and publish

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ develop ]
pull_request:
branches: [ master ]
# on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
compile_publish:
name: compile test
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code from github
uses: actions/checkout@v2

# Runs a set of commands using the runners shell
- name: sync shell cmd
run: |
git submodule update --init --recursive
wget https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190409/kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz
sudo tar -Jxf kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz -C /opt
rm -f kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz
cd tools/release
chmod +x release.sh && ./release.sh
48 changes: 48 additions & 0 deletions firmware/MaixPy/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This is a basic workflow to help you get started with Actions

name: compile test and publish

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
# on: [push, pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
compile_publish:
name: compile test and publish
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkout code from github
uses: actions/checkout@v2

# Runs a set of commands using the runners shell
- name: sync shell cmd
run: |
curr_branch=master
git fetch --unshallow
git submodule update --init --recursive
wget https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190409/kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz
sudo tar -Jxf kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz -C /opt
rm -f kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz
cd tools/release
chmod +x release.sh && ./release.sh
time_now=$(date "+%Y_%m_%d_%H_%M_%S")
cd bin
firmware_dir=`ls`
SSHPATH="$HOME/.ssh"
rm -rf "$SSHPATH"
mkdir -p "$SSHPATH"
echo "${{ secrets.ACCESSS_KEY }}" > "$SSHPATH/id_rsa"
chmod 600 "$SSHPATH/id_rsa"
sudo sh -c "echo StrictHostKeyChecking no >>/etc/ssh/ssh_config"
chmod -R 777 $firmware_dir
rsync -av --progress $firmware_dir ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_ADDR }}:${{ secrets.SERVER_FOLDER_PATH }}/${curr_branch}/
45 changes: 45 additions & 0 deletions firmware/MaixPy/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
language:
- c
compiler:
- gcc
cache:
directories:
- "${HOME}/.maixpy_cache"
env:
global:
- rev=$(git rev-parse --short HEAD)
- BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- curr_branch=$TRAVIS_BRANCH
branches:
only:
- master

stages:
- name: maixpy_build

jobs:
include:
- stage: maixpy_build
env: NAME="maixpy build"
install:
- sudo apt-get update
- sudo apt-get install -y sshpass p7zip-full
- wget https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190409/kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz
- sudo tar -Jxf kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz -C /opt
- rm -f kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz
script:
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, BRANCH=$BRANCH"
- cd tools/release
- chmod +x release.sh && ./release.sh || travis_terminate 1;
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then exit 0; fi
- time_now=$(date "+%Y_%m_%d_%H_%M_%S")
- cd bin
- firmware_dir=`ls`
- sudo sh -c "echo StrictHostKeyChecking no >>/etc/ssh/ssh_config"
- chmod -R 777 $firmware_dir
- SSHPATH="$HOME/.ssh"
- rm -rf "$SSHPATH"
- mkdir -p "$SSHPATH"
- echo "${ACCESS_KEY}" > "$SSHPATH/id_rsa"
- chmod 600 "$SSHPATH/id_rsa"
- rsync -av --progress $firmware_dir ${SERVER_USER}@${SERVER_ADDR}:${SERVER_FOLDER_PATH}/${curr_branch}/
26 changes: 26 additions & 0 deletions firmware/MaixPy/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

mainmenu "C/CPP CMake project framework Kconfig configuration"

menu "Toolchain configuration"
config TOOLCHAIN_PATH
string "toolchain path"
default "/opt/kendryte-toolchain/bin"

config TOOLCHAIN_PREFIX
string "toolchain prefix"
default "riscv64-unknown-elf-"
endmenu

menu "Components configuration"
osource "${SDK_PATH}/components/*/Kconfig"
osource "${PROJECT_PATH}/*/Kconfig"
endmenu

menu "Others"
config LIB_NNCASE_SOURCE_CODE_ENABLE
bool "compile nncase source code"
default n
endmenu



Loading

0 comments on commit bb8e2d6

Please sign in to comment.