mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
add xpubaddrgen utility
This commit is contained in:
parent
795579cbac
commit
280310c8a0
1
tools/.gitignore
vendored
Normal file
1
tools/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
xpubaddrgen
|
37
tools/Makefile
Normal file
37
tools/Makefile
Normal file
@ -0,0 +1,37 @@
|
||||
CC = gcc
|
||||
|
||||
OPTFLAGS = -O3
|
||||
|
||||
CFLAGS += $(OPTFLAGS) \
|
||||
-W \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Wimplicit-function-declaration \
|
||||
-Wredundant-decls \
|
||||
-Wstrict-prototypes \
|
||||
-Wundef \
|
||||
-Wshadow \
|
||||
-Wpointer-arith \
|
||||
-Wformat \
|
||||
-Wreturn-type \
|
||||
-Wsign-compare \
|
||||
-Wmultichar \
|
||||
-Wformat-nonliteral \
|
||||
-Winit-self \
|
||||
-Wuninitialized \
|
||||
-Wformat-security \
|
||||
-Werror \
|
||||
-I..
|
||||
|
||||
all: xpubaddrgen
|
||||
|
||||
OBJS = ../bip32.o ../ecdsa.o ../sha2.o ../bignum.o ../base58.o ../secp256k1.o ../ripemd160.o ../hmac.o ../rand.o
|
||||
|
||||
%.o: %.c %.h options.h
|
||||
$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
xpubaddrgen: xpubaddrgen.o $(OBJS)
|
||||
$(CC) xpubaddrgen.o $(OBJS) -o xpubaddrgen
|
||||
|
||||
clean:
|
||||
rm -f *.o xpubaddrgen
|
36
tools/README
Normal file
36
tools/README
Normal file
@ -0,0 +1,36 @@
|
||||
trezor-crypto tools
|
||||
===================
|
||||
|
||||
Set of small utilities using the trezor-crypto library.
|
||||
|
||||
xpubaddrgen
|
||||
-----------
|
||||
|
||||
xpubaddrgen reads job specification from stdin in format:
|
||||
|
||||
<jobid> <xpub> <change> <from> <to>
|
||||
|
||||
and prints the results to stdout in format:
|
||||
|
||||
<jobid> <index> <address>
|
||||
|
||||
Example input:
|
||||
|
||||
23 xpub6BcjTvRCYD4VvFQ8whztSXhbNyhS56eTd5P3g9Zvd3zPEeUeL5CUqBYX8NSd1b6Thitr8bZcSnesmXZH7KerMcc4tUkenBShYCtQ1L8ebVe 0 0 5
|
||||
42 xpub6AT2YrLinU4Be5UWUxMaUz3zTA99CSGvXt1jt2Lgym8PqXbTzmpQ8MHjoLnx8YJiMMUP5iEfR97YQVmgF6B2tAhbCZrXqn65ur526NkZ6ey 1 1000 1005
|
||||
|
||||
Example output:
|
||||
|
||||
23 0 14vb5Cws75p2i5rmSiF5CKMyezUX4hxSb9
|
||||
23 1 1Lf4ciA36dsi1niF6smVcpCiHcpj2skaPq
|
||||
23 2 1LraByp7gQAipvHnFS1gTSzixBtYaVyQGp
|
||||
23 3 1Hy6n56qZj1EefLVfDAeEpmveNteY9jpiG
|
||||
23 4 183Nn4mrUjPizM3xu8C6SrmViaWrk8YyRS
|
||||
42 1000 12eAFGAqGUtszc9R7euRqk7DUcQNXvQZSg
|
||||
42 1001 1BrLbFCD3MNYedJaz92U9iqy9ukHrtQ1A6
|
||||
42 1002 1Jhv33bJy229ThM7HKxUa92cMK5gi7DyPC
|
||||
42 1003 13LxbTjQPByisj4F4sZEivUBdnJwigzg6R
|
||||
42 1004 1BWBpSWkPwcKxVr2WDyUqQbmvk5SGihcx9
|
||||
|
||||
It will print "<jobid> error" when there was an error processing job <jobid>.
|
||||
It will print "error" when it encountered a malformed line.
|
43
tools/xpubaddrgen.c
Normal file
43
tools/xpubaddrgen.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <bip32.h>
|
||||
#include <ecdsa.h>
|
||||
|
||||
void process_job(uint32_t jobid, const char *xpub, uint32_t change, uint32_t from, uint32_t to)
|
||||
{
|
||||
HDNode node, child;
|
||||
if (change > 1 || to <= from || hdnode_deserialize(xpub, &node) != 0) {
|
||||
printf("%d error\n", jobid);
|
||||
return;
|
||||
}
|
||||
hdnode_public_ckd(&node, change);
|
||||
uint32_t i;
|
||||
char address[36];
|
||||
for (i = from; i < to; i++) {
|
||||
memcpy(&child, &node, sizeof(HDNode));
|
||||
hdnode_public_ckd(&child, i);
|
||||
ecdsa_get_address(child.public_key, 0, address, sizeof(address));
|
||||
printf("%d %d %s\n", jobid, i, address);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char line[1024], xpub[1024];
|
||||
uint32_t jobid, change, from, to;
|
||||
int r;
|
||||
for (;;) {
|
||||
fgets(line, sizeof(line), stdin);
|
||||
r = sscanf(line, "%u %s %u %u %u\n", &jobid, xpub, &change, &from, &to);
|
||||
if (r < 1) {
|
||||
printf("error\n");
|
||||
} else if (r != 5) {
|
||||
printf("%d error\n", jobid);
|
||||
} else {
|
||||
process_job(jobid, xpub, change, from, to);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user