https://github.com/golang/go/wiki/Ubuntu
$ go get github.com/skycoin/hardware-wallet-go
This project uses dep dependancy manager.
Don't modify anything under vendor/ directory without using dep commands.
Download dependencies using command:
$ make dep
$ go run cmd/cli/cli.go
See also CLI README for information about the Command Line Interface.
Code added in this repository should comply to development guidelines documented in Skycoin wiki.
The project has two branches: master
and develop
.
develop
is the default branch and will always have the latest code.master
will always be equal to the current stable release on the website, and should correspond with the latest release tag.
This go client library follows the versioning rules for SkyWallet client libraries .
Library test suite can be run by running the following command
make test
If a physical SkyWallet device is connected then the test suite will exchange test messages with it. Likewise, the emulator will reply to test messages if executed in advance as follows.
git clone https://github.com/skycoin/hardware-wallet /some/path/to/hardware-wallet
make clean -C /some/path/to/hardware-wallet && make -C /some/path/to/hardware-wallet run-emulator
If neither the emulator nor a physical device are connected then tests will be skipped silently.
- If the
master
branch has commits that are not indevelop
(e.g. due to a hotfix applied tomaster
), mergemaster
intodevelop
(and fix any build or test failures) - Switch to a new release branch named
release-X.Y.Z
for preparing the release. - Run
make build
to make sure that the code base is up to date - Update
CHANGELOG.md
: move the "unreleased" changes to the version and add the date. - Follow the steps in pre-release testing
- Make a PR merging the release branch into
master
- Review the PR and merge it
- Tag the
master
branch with the version number. Version tags start withv
, e.g.v0.20.0
. Sign the tag. If you have your GPG key in github, creating a release on the Github website will automatically tag the release. It can be tagged from the command line withgit tag -as v0.20.0 $COMMIT_ID
, but Github will not recognize it as a "release". - Tag the changeset of the
protob
submodule checkout with the same version number as above. - Release builds are created and uploaded by travis. To do it manually, checkout the master branch and follow the create release builds instructions.
- Checkout
develop
branch and bumptiny-firmware/VERSION
andtiny-firmware/bootloader/VERSION
to nextdev
version number.
Pre-release testing procedure requires skycoin-cli. Please install it if not available in your system. Some operations in the process require running a Skycoin node. Also clone Skywallet firmware repository in advance.
The instructions that follow are meant to be followed for Skywallet devices flashed without memory protection. If your device memory is protected then some values might be different e.g. firmwareFeatures
.
During the process beware of the fact that running an Skycoin node in the background can block the Skywallet from running.
Some values need to be known during the process. They are represented by the following variables:
WALLET1
,WALLET2
, ... names of wallets created byskycoin_cli
ADDRESS1
,ADDRESS2
, ... Skycoin addressesTXN1_RAW
,TXN2_RAW
, ... transactions data encoded in hex dump formatTXN1_JSON
,TXN2_JSON
, ... transactions data encoded in JSON format, if numeric index value matches the one of another variable withRAW
prefix then both refer to the same transactionTXN1_ID
,TXN2_ID
, ... Hash ID of transactions after broadcasting to the P2P networkAMOUNT
represents an arbitrary number of coinsID1
,ID2
,ID3
, ... unique ID values , usually strings identifying hardware or software artifactsAUTHTOKEN
is a CSRF token for the Skycoin REST API
Perform these actions before releasing:
Note : In all cases skycoin-cli
would be equivalent to go run cmd/cli/cli.go
if current working directory set to $GOPATH/src/github.com/skycoin/skycoin
.
- Open a terminal window and run Skywallet emulator. Wait for emulator UI to display.
- From a separate trminal window run the test suite as follows
npm run test
- Close emulator and plug Skywallet device. Run the same command another time.
- Create new wallet e.g. with
skycoin-cli
(or reuse existing wallet for testing purposes)
skycoin-cli walletCreate -f $WALLET1.wlt -l $WALLET1
- From command output take note of the seed
SEED1
and addressADDRESS1
- List wallet addresses and confirm that
ADDRESS1
is the only value in the list.
skycoin-cli listAddresses $WALLET1.wlt
- Transfer funds to
ADDRESS1
in new wallet in two transactions - Check balance
skycoin-cli addressBalance $ADDRESS1
- List address for
WALLET1
and check thathead_outputs
in response includes to outputs withaddress
set toADDRESS1
skycoin-cli walletOutputs $WALLET1.wlt
- Get device features and check that:
vendor
is set toSkycoin Foundation
deviceId
is a string of 24 chars, which we'll refer to asID1
- write down the value of
bootloaderHash
i.e.ID2
model
is set to'1'
fwMajor
is set to expected firmware major version numberfwMinor
is set to expected firmware minor version numberfwPatch
is set to expected firmware patch version numberfirmwareFeatures
is set to0
- Ensure device is seedless by wiping it. Check that device ends up in home screen with
NEEDS SEED!
message at the top. - Recover seed
SEED1
in Skywallet device (dry-run=false
). - Get device features and check that:
vendor
is set toSkycoin Foundation
deviceId
is set toID1
pinProtection
is seto tofalse
passphraseProtection
is set tofalse
label
is set toID1
initialized
is set totrue
bootloaderHash
is set toID2
passphraseCached
is set tofalse
needsBackup
is set tofalse
model
is set to'1'
fwMajor
is set to expected firmware major version numberfwMinor
is set to expected firmware minor version numberfwPatch
is set to expected firmware patch version numberfirmwareFeatures
is set to0
- Set device label to a new value , say
ID3
. SpecifyusePassphrase=false
. - Get device features and check that:
label
is set toID3
- all other values did not change with respect to previous step, especially
deviceId
- as a result device label is displayed on top of Skycoin logo in device home screen
- Ensure you know at least two addresses for test wallet, if not, generate some. Choose the second and third in order, hereinafter referred to as
ADDRESS2
,ADDRESS3
respectively - Check that address sequence generated by SkyWallet matches the values generated by
skycoin-cli
skycoin-cli walletAddAddresses -f $WALLET1.wlt -n 5
- Check once again with desktop wallet
- Create new transaction from
ADDRESS1
toADDRESS2
in test wallet (sayTXN_RAW1
) for an spendable amount higher than individual output's coins
export TXN1_RAW="$(skycoin-cli createRawTransaction -a $ADDRESS1 -f $WALLET1.wlt $ADDRESS2 $AMOUNT)"
echo $TXN1_RAW
- Display transaction details and confirm that it contains at least two inputs
export TXN1_JSON=$(skycoin-cli decodeRawTransaction $TXN1_RAW)
echo $TXN1_JSON
- Sign transaction with Skywallet by putting together a message using values resulting from previous step as follows.
- For each hash in transaction
inputs
array and in same order there should be- an instance of
--inputHash
command line argument set to the very same hash - an instance of
--inputIndex
set to0
.
- an instance of
- For each source item in transaction
outputs
array and in the same order there should be command-line arguments set as follows:--outputAddress
: source item'sdst
--coin
: source item'scoins * 1000000
--hour
: source item'shours
--addressIndex
: set to0
if source itemaddress
equalsADDRESS1
or to1
otherwise
- For each hash in transaction
- Check that
signatures
array returned by hardware wallet includes entries for each and every transaction input - Check signatures were signed by corresponding addresses
- Create transaction
TXN2_JSON
by replacingTXN1_JSON
signatures with the array returned by SkyWallet - Use
TXN2_JSON
to obtain encoded transactionTXN2_RAW
export $TXN2_RAW=$( echo "$TXN2_JSON" | skycoin-cli encodeJsonTransaction - | grep '"rawtx"' | cut -d '"' -f4)
echo $TXN2_RAW
- Broadcast transaction. Refer to its id as
TXN2_ID
export TXN2_ID=$(skycoin-cli broadcastTransaction $TXN2_RAW)
- After a a reasonable time check that balance changed.
skycoin-cli walletBalance $WALLET1.wlt
- Create a second wallet i.e.
WALLET2
skycoin-cli walletCreate -f $WALLET2.wlt -l $WALLET2
- From command output take note of the seed
SEED2
and addressADDRESS4
- List
WALLET2
addresses and confirm thatADDRESS4
is the only value in the list.
skycoin-cli lisAddresses $WALLET2.wlt
- Transfer funds to
WALLET2
(if not already done) and check balance
skycoin-cli addressBalance $ADDRESS4
- Request CSRF token (i.e.
AUTHTOKEN
) using Skycoin REST API.
curl http://127.0.0.1:6420/api/v1/csrf
- Use Skycoin REST API to create one transaction grabbing all funds from
ADDRESS1
(i.e. first address inWALLET1
previously recovered in Skywallet device),ADDRESS2
(i.e. second address inWALLET1
previously recovered in Skywallet device) andADDRESS4
(i.e. first address inWALLET2
) so as to transfer to the third address ofWALLET1
(i.e.ADDRESS3
). Change should be sent back toADDRESS1
. In server response transaction JSON object (a.k.aTNX3_JSON
) would be the object atdata.transaction
JSON path. If Skycoin node was started with default parameters this can be achieved as follows:
curl -X POST http://127.0.0.1:6420/api/v2/transaction -H 'content-type: application/json' -H "X-CSRF-Token: $AUTHTOKEN" -d "{
\"hours_selection\": {
\"type\": \"auto\",
\"mode\": \"share\",
\"share_factor\": \"0.5\"
},
\"addresses\": [\"$ADDRESS1\", \"$ADDRESS2\", \"$ADDRESS4\"],
\"change_address\": \"$ADDRESS1\",
\"to\": [{
\"address\": \"$ADDRESS3\",
\"coins\": \"$AMOUNT\"
}],
\"ignore_unconfirmed\": false
}"
- Sign transaction represented by
TXN3_JSON
for inputs owned by Skywallet (i.e.WALLET1
)- For each object in transaction
inputs
array there should be:- an instance of
--inputHash
command line argument set to the value bound to object'suxid
key - an instance of
--inputIndex
set as follows- empty string if input
address
isADDRESS4
0
if inputaddress
isADDRESS1
1
if inputaddress
isADDRESS2
- empty string if input
- an instance of
- For each source item in transaction
outputs
array there should be command-line arguments set as follows:--outputAddress
: source item'saddress
--coin
: source item'scoins * 1000000
--hour
: source item'shours
--addressIndex
set to 2 (since destination address isADDRESS3
)
- For each object in transaction
- Check that signatures array includes one entry for every input except the one associated to
ADDRESS4
, which should be an empty string - Recover seed
SEED2
in Skywallet device (dry-run=false
). - Sign transaction represented by
TXN3_JSON
for inputs owned by Skywallet (i.e.WALLET2
)- For each hash in transaction
inputs
array and in same order there should be:- an instance of
--inputHash
command line argument set to the value bound to object'suxid
key - an instance of
--inputIndex
set to a value as follows- not set if input
address
isADDRESS1
- not set if input
address
isADDRESS2
0
if inputaddress
isADDRESS4
- not set if input
- an instance of
- For each source item in transaction
outputs
array and in the same order there should be command-line arguments set as follows:--outputAddress
: source item'sdst
--coin
: source item'scoins * 1000000
--hour
: source item'shours
--addressIndex
empty (since destination addressADDRESS3
not owned by this wallet)
- For each hash in transaction
- Create a new transaction JSON object (a.k.a
TXN4_JSON
) fromTXN3_JSON
and the previous signatures like thistype
same as inTXN3_JSON
inner_hash
should be an empty stringsigs
returned by SkyWallet in same order as corresponding inputinputs
is an array of strings. For each item inTXN3_JSON
inputs
include the value of itsuxid
field inTXN4_JSON
inputs
array. Respect original order.outputs
is an array of objects constructed out ofTXN3_JSON
outputs
items, in te same order, as followsdst
: source item'saddress
coins
: source item'scoins * 1000000
hours
: source item'shours
as integer
- Use
TXN4_JSON
to obtain encoded transactionTXN4_RAW
export $TXN4_RAW=$( echo "$TXN4_JSON" | skycoin-cli encodeJsonTransaction - | grep '"rawtx"' | cut -d '"' -f4)
echo $TXN4_RAW
- Broadcast transaction. Refer to its id as
TXN4_ID
export TXN4_ID=$(skycoin-cli broadcastTransaction $TXN4_RAW)
- After a a reasonable time check that wallets balance changed.
skycoin-cli walletBalance $WALLET1.wlt
skycoin-cli walletBalance $WALLET2.wlt
More information in the wiki