This repo contains a suit of tools for testing, generating data and cross checking against different tech env.
The swap payload used by the Nano is in Protobuf format.
The private and public key are expected to be in ES256 format, using a secp256k1 or secp256r1 curve.
./exchange-tool generate (swap|sell) -c <curve> -p <private_key_file> [-f (raw|jwt)] <payload_in_json_format>
Example:
./exchange-tool generate swap -c k1 -p ./samples/sample-priv-key-secp256k1.pem ./samples/swap-payload-example.json./exchange-tool check -c <curve> (-p <public_key_file> | -x <public_key_in_hex_format>) [-f (raw|jwt)] <binary_payload_in_base64> <signature_in_base64>
Example:
./exchange-tool check -c k1 -p ../samples/sample-pub-key-secp256k1.pem CipiYzFxYXIwc3Jycjd4Zmt2eTVsNjQzbHlkbnc5cmU1OWd0enp3ZjVtZHEaKmJjMXFhcjBzcnJyN3hma3Z5NWw2NDNseWRudzlyZTU5Z3R6endmNHRlcSoqMHhiNzk0ZjVlYTBiYTM5NDk0Y2U4Mzk2MTNmZmZiYTc0Mjc5NTc5MjY4OgNCVENCA0JBVEoCBH5SBgV0-95gAGIgNQrqDJf3R_HQ92CBRhSkdSOAGxrrfQvLuqKk9Gv4GEs= ky2iRewy2Lbm8tR-kvnUGRKJBrUPwzQwPWWyP_xbNI3vxR9VSfdDvRW5pWEPU1nMbgJj4NuFw6WSOfEDDnupqg==./exchange-tool read -e (swap|sell) <binary_payload_in_base64>
Example:
./exchange-tool read -e swap CipiYzFxYXIwc3Jycjd4Zmt2eTVsNjQzbHlkbnc5cmU1OWd0enp3ZjVtZHEaKmJjMXFhcjBzcnJyN3hma3Z5NWw2NDNseWRudzlyZTU5Z3R6endmNHRlcSoqMHhiNzk0ZjVlYTBiYTM5NDk0Y2U4Mzk2MTNmZmZiYTc0Mjc5NTc5MjY4OgNCVENCA0JBVEoIMTIwMDAwMDBSCDExNTAwMDAwWgpBQkNERUZHSElK./exchange-tool hex -c <curve> -t (private|public) <provider_public_key>
Example:
./exchange-tool hex -c k1 -t public ./samples/sample-pub-key-secp256k1.pemGenerate an APDU to sign by Ledger, with the provider infos (name and public key).
./exchange-tool sign -c <curve> -n <provider_name> <provider_public_key>
Example:
./exchange-tool sign -c k1 -n SELL_TEST ./samples/sample-pub-key-secp256k1.pemGenerate 2 provider info in CAL format: one for LedgerLive (test purpose only), one for CAL (example purpose only).
./exchange-tool cal -c <curve> -n <provider_name> -p <provider_public_key> -v <version> -a <application_name>
Example:
./exchange-tool cal -c k1 -p ./sample-public-key.pem -n SWAP_TEST -v 2 -a swapDisclaimer DO NOT USE private key provided in this repository. Their goal is for test purpose only.
The code use to generate a payload has an amount limitation. To ease the JSON serialization, we are relying on uint64 type, which is not the best to suit crypto units.
Private key:
openssl ecparam -name secp256k1 -genkey -noout -out sample-priv-key-secp256k1.pemPublic key (from private key):
openssl ec -in sample-priv-key.pem -pubout > sample-pub-key-secp256k1.pemRead file info
openssl ec -text -in sample-priv-key-secp256k1.pem(ecparam is for Eliptic Curves params)
To check if the code is still consistent with what is expected from Ledger:
go test .
# For log info
go test . -v # Sign 'encoded_payload' content
openssl dgst -sha256 -sign sample-priv-key-secp256r1.pem encoded_payload.txt > signature.der
# Display R and S from DER format signature
openssl asn1parse -inform DER -in signature.der
# Verify signature
openssl dgst -sha256 -verify sample-pub-key-secp256r1.pem -signature signature.der encoded_payload.txtWith current example value
openssl dgst -sha256 -verify example/sample-pub-key-secp256k1.pem -signature example/signature-example-k1.der example/encoded_payload.txt- Copy
asn1rs.template.cnffile (ex: intoasn1rs-example.cnf) - Edit this file and replace
{rvalue_in_hex}and{svalue_in_hex}value with R and S value - Call
openssl asn1parse -genconf asn1rs-example.cnf -out signature-example.der
var=$(basenc --base64url -d signature.txt | hexdump -ve '1/1 "%.2x"')
printf '%s\n' "${var:0:${#var}/2}" "${var:${#var}/2}"
unset var