def main() :
    parser = argparse.ArgumentParser(description='Construct a paperwallet and return svg content')
    parser.add_argument('filename', type=str, help='Output file name to store SVG in')
    parser.add_argument('--amount', type=str, help='Text (amount) to be placed on the paper wallet')
    parser.add_argument('--asset', type=str, help='Asset label to be placed on the paper wallet')
    parser.add_argument('--design', type=str, help='Design of the paperwallet (defaults to "cass")')
    parser.add_argument('-encrypt', help='Encrypt private key with BIP38!', action='store_true')
    parser.add_argument('--back_qr', help='Content of the QR-code on the back of the paper wallet', action='store_true')
    parser.add_argument('--back_text1', help='Text field 1 on the back of the paper wallet', action='store_true')
    parser.add_argument('--back_text2', help='Text field 2 on the back of the paper wallet', action='store_true')
    parser.add_argument('--back_text3', help='Text field 3 on the back of the paper wallet', action='store_true')
    parser.set_defaults(design="cass")
    parser.set_defaults(back_text1="Install the BitShares App.", back_text2="Load your funds from the wallet", back_text3="Buy the BitShares 101 Book for $1", back_qr="http://cryptofresh.com/products/8?r=xeroc")
    args = parser.parse_args()

    ''' Generate new wif and address '''
    wif = Address.newwif()
    add = Address.wif2btsaddr(wif)

    ''' Verify that the private keys gives access to address in add '''
    assert Address.priv2btsaddr(Address.wif2hex(wif)) is not add, "private key for address %s is different from given address %s" %(Address.priv2btsaddr(Address.wif2hex(wif)), add) 

    pw = ""
    if args.encrypt :
        import getpass
        while True :
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if(pw == pwck) : 
                break
            else :
                print("Given Passphrases do not match!")

    front,back = Paper.paperwallet(wif, add, args.amount, args.asset, encrypt=pw, design=args.design, backtext1=args.back_text1, backtext2=args.back_text2, backtext3=args.back_text3, backQRcode=args.back_qr)

    extension = os.path.splitext(args.filename)[1]
    if extension == ".svg" :
        open(args.filename, 'wb').write(front)
        open(args.filename.replace('.svg','-back.svg'), 'wb').write(back)
    elif extension == ".pdf" :
        import svg2pdf
        import io
        from PyPDF2 import PdfFileMerger, PdfFileReader
        merger = PdfFileMerger()
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(front)))))
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(back)))))
        merger.write(args.filename)
    else :
        print("unknown extension %s" % extension)
        return
def main():
    parser = argparse.ArgumentParser(description="Construct paperwallets according to file")
    parser.add_argument("--design", type=str, help='Design of the paperwallet (defaults to "cass")')
    parser.add_argument("-svg", help="Store as SVG instead of PDF", action="store_true")
    parser.add_argument("--amount", type=str, help="Text (amount) to be placed on the paper wallet")
    parser.add_argument("--asset", type=str, help="Asset label to be placed on the paper wallet")
    parser.add_argument("-encrypt", help="Encrypt private key with BIP38!", action="store_true")
    parser.add_argument("--back_qr", help="Content of the QR-code on the back of the paper wallet", action="store_true")
    parser.add_argument("--back_text1", help="Text field 1 on the back of the paper wallet", action="store_true")
    parser.add_argument("--back_text2", help="Text field 2 on the back of the paper wallet", action="store_true")
    parser.add_argument("--back_text3", help="Text field 3 on the back of the paper wallet", action="store_true")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--wallet", type=str, help="wallet csv file (i.e. generated by sharedrop.py)")
    group.add_argument("--number", type=int, help="Number of wallets to create randomly")
    parser.set_defaults(design="cass", amount="", asset=None)
    parser.set_defaults(
        back_text1="Install the BitShares App.",
        back_text2="Load your funds from the wallet",
        back_text3="Buy the BitShares 101 Book for $1",
        back_qr="http://cryptofresh.com/products/8?r=xeroc",
    )
    args = parser.parse_args()

    """
    Optionally encrypt with BIP38
    """
    pw = ""
    if args.encrypt:
        import getpass

        while True:
            pw = getpass.getpass("Passphrase: ")
            pwck = getpass.getpass("Retype passphrase: ")
            if pw == pwck:
                break
            else:
                print("Given Passphrases do not match!")

    """
    Construct data or read data from file
    """
    wallet = []
    if args.wallet:
        with open(args.wallet, "r") as csvfile:
            spamwriter = csv.reader(csvfile, delimiter=";")
            for wif, add, amount, asset in spamwriter:
                """ Verify that the private keys gives access to address in add """
                assert Address.priv2btsaddr(Address.wif2hex(wif)) is not add, (
                    "private key for address %s is different from given address %s"
                    % (Address.priv2btsaddr(Address.wif2hex(wif)), add)
                )
                wallet.append([wif, add, amount, asset])
    else:
        for i in xrange(0, args.number):
            wif = Address.newwif()
            add = Address.wif2btsaddr(wif)
            wallet.append([wif, add, args.amount, args.asset])

    """
    Construct paper wallets
    """
    print("Constructing paper wallets")
    if not args.svg:
        import svg2pdf
        import io
        from PyPDF2 import PdfFileMerger, PdfFileReader

        mergerfront = PdfFileMerger()
        mergerback = PdfFileMerger()
        for w in wallet:
            wif, add, amount, asset = w
            print("Creating Paperwallet for %s" % (add))
            front, back = Paper.paperwallet(
                wif,
                add,
                amount,
                asset,
                encrypt=pw,
                design=args.design,
                backtext1=args.back_text1,
                backtext2=args.back_text2,
                backtext3=args.back_text3,
                backQRcode=args.back_qr,
            )

            if args.svg:
                filename = "paperwallets/%s.svg" % add
                open(filename.replace(".svg", "-front.svg"), "wb").write(front)
                open(filename.replace(".svg", "-back.svg"), "wb").write(back)
            else:
                mergerfront.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(front)))))
                mergerback.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(back)))))
        mergerfront.write("paperwallets-front.pdf")
        mergerback.write("paperwallets-back.pdf")
    else:
        for w in wallet:
            wif, add, amount, asset = w
            print("Creating Paperwallet for %s" % (add))
            front, back = Paper.paperwallet(
                wif,
                add,
                amount,
                asset,
                encrypt=pw,
                design=args.design,
                backtext1=args.back_text1,
                backtext2=args.back_text2,
                backtext3=args.back_text3,
                backQRcode=args.back_qr,
            )

            filename = "paperwallets/%s.svg" % add
            open(filename.replace(".svg", "-front.svg"), "wb").write(front)
            open(filename.replace(".svg", "-back.svg"), "wb").write(back)
    print("Done.")
def main():
    parser = argparse.ArgumentParser(
        description='Construct a paperwallet and return svg content')
    parser.add_argument('filename',
                        type=str,
                        help='Output file name to store SVG in')
    parser.add_argument('--amount',
                        type=str,
                        help='Text (amount) to be placed on the paper wallet')
    parser.add_argument('--asset',
                        type=str,
                        help='Asset label to be placed on the paper wallet')
    parser.add_argument('--design',
                        type=str,
                        help='Design of the paperwallet (defaults to "cass")')
    parser.add_argument('-encrypt',
                        help='Encrypt private key with BIP38!',
                        action='store_true')
    parser.add_argument(
        '--back_qr',
        help='Content of the QR-code on the back of the paper wallet',
        action='store_true')
    parser.add_argument('--back_text1',
                        help='Text field 1 on the back of the paper wallet',
                        action='store_true')
    parser.add_argument('--back_text2',
                        help='Text field 2 on the back of the paper wallet',
                        action='store_true')
    parser.add_argument('--back_text3',
                        help='Text field 3 on the back of the paper wallet',
                        action='store_true')
    parser.set_defaults(design="cass")
    parser.set_defaults(back_text1="Install the BitShares App.",
                        back_text2="Load your funds from the wallet",
                        back_text3="Buy the BitShares 101 Book for $1",
                        back_qr="http://cryptofresh.com/products/8?r=xeroc")
    args = parser.parse_args()
    ''' Generate new wif and address '''
    wif = Address.newwif()
    add = Address.wif2btsaddr(wif)
    ''' Verify that the private keys gives access to address in add '''
    assert Address.priv2btsaddr(
        Address.wif2hex(wif)
    ) is not add, "private key for address %s is different from given address %s" % (
        Address.priv2btsaddr(Address.wif2hex(wif)), add)

    pw = ""
    if args.encrypt:
        import getpass
        while True:
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if (pw == pwck):
                break
            else:
                print("Given Passphrases do not match!")

    front, back = Paper.paperwallet(wif,
                                    add,
                                    args.amount,
                                    args.asset,
                                    encrypt=pw,
                                    design=args.design,
                                    backtext1=args.back_text1,
                                    backtext2=args.back_text2,
                                    backtext3=args.back_text3,
                                    backQRcode=args.back_qr)

    extension = os.path.splitext(args.filename)[1]
    if extension == ".svg":
        open(args.filename, 'wb').write(front)
        open(args.filename.replace('.svg', '-back.svg'), 'wb').write(back)
    elif extension == ".pdf":
        import svg2pdf
        import io
        from PyPDF2 import PdfFileMerger, PdfFileReader
        merger = PdfFileMerger()
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(front)))))
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(back)))))
        merger.write(args.filename)
    else:
        print("unknown extension %s" % extension)
        return
def main() :
    parser = argparse.ArgumentParser(description='Construct a paperwallet and store svg file')
    parser.add_argument('filename', type=str, help='Output file name to store SVG in')
    parser.add_argument('--amount', type=str, help='Text (amount) to be placed on the paper wallet')
    parser.add_argument('--asset', type=str, help='Asset label to be placed on the paper wallet')
    parser.add_argument('--design', type=str, help='Design of the paperwallet (defaults to "cass")')
    parser.add_argument('-encrypt', help='Encrypt private key with BIP38!', action='store_true')
    parser.set_defaults(design="cass")
    args = parser.parse_args()

    while True : 
        lines = ""
        try : 
            for line in sys.stdin :
                lines += line
        except (EOFError, KeyboardInterrupt):
            print # end in newline
            sys.exit(1)
            print( lines )
        try :
            j = json.loads(lines)
        except :
            print( "Error parsing JSON!" )
            continue
        break

        if  not "wif_private_key" in j or \
            not "native_address" in j :
            print( "invalid JSON format! Missing native_address and private_key!" )
            continue

    wif = j[ "wif_private_key" ]
    add = j[ "native_address" ]
    ''' Verify that the private keys gives access to address in add '''
    assert Address.priv2btsaddr(Address.wif2hex(wif)) is not add, "private key for address %s is different from given address %s" %(Address.priv2btsaddr(Address.wif2hex(wif)), add) 

    pw = ""
    if args.encrypt :
        import getpass
        while True :
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if(pw == pwck) : 
                break
            else :
                print("Given Passphrases do not match!")

    front,back = Paper.paperwallet(wif, add, args.amount, args.asset, encrypt=pw, design=args.design)

    extension = os.path.splitext(args.filename)[1]
    if extension == ".svg" :
        open(args.filename, 'wb').write(front)
        open(args.filename.replace('.svg','-back.svg'), 'wb').write(back)
    elif extension == ".pdf" :
        import svg2pdf
        import io
        from PyPDF2 import PdfFileMerger, PdfFileReader
        merger = PdfFileMerger()
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(front)))))
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(back)))))
        merger.write(args.filename)
    else :
        print("unknown extension %s" % extension)
        return
Exemple #5
0
def main():
    parser = argparse.ArgumentParser(
        description='Construct a paperwallet and store svg file')
    parser.add_argument('filename',
                        type=str,
                        help='Output file name to store SVG in')
    parser.add_argument('--amount',
                        type=str,
                        help='Text (amount) to be placed on the paper wallet')
    parser.add_argument('--asset',
                        type=str,
                        help='Asset label to be placed on the paper wallet')
    parser.add_argument('--design',
                        type=str,
                        help='Design of the paperwallet (defaults to "cass")')
    parser.add_argument('-encrypt',
                        help='Encrypt private key with BIP38!',
                        action='store_true')
    parser.set_defaults(design="cass")
    args = parser.parse_args()

    while True:
        lines = ""
        try:
            for line in sys.stdin:
                lines += line
        except (EOFError, KeyboardInterrupt):
            print  # end in newline
            sys.exit(1)
            print(lines)
        try:
            j = json.loads(lines)
        except:
            print("Error parsing JSON!")
            continue
        break

        if  not "wif_private_key" in j or \
            not "native_address" in j :
            print(
                "invalid JSON format! Missing native_address and private_key!")
            continue

    wif = j["wif_private_key"]
    add = j["native_address"]
    ''' Verify that the private keys gives access to address in add '''
    assert Address.priv2btsaddr(
        Address.wif2hex(wif)
    ) is not add, "private key for address %s is different from given address %s" % (
        Address.priv2btsaddr(Address.wif2hex(wif)), add)

    pw = ""
    if args.encrypt:
        import getpass
        while True:
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if (pw == pwck):
                break
            else:
                print("Given Passphrases do not match!")

    front, back = Paper.paperwallet(wif,
                                    add,
                                    args.amount,
                                    args.asset,
                                    encrypt=pw,
                                    design=args.design)

    extension = os.path.splitext(args.filename)[1]
    if extension == ".svg":
        open(args.filename, 'wb').write(front)
        open(args.filename.replace('.svg', '-back.svg'), 'wb').write(back)
    elif extension == ".pdf":
        import svg2pdf
        import io
        from PyPDF2 import PdfFileMerger, PdfFileReader
        merger = PdfFileMerger()
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(front)))))
        merger.append(PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(back)))))
        merger.write(args.filename)
    else:
        print("unknown extension %s" % extension)
        return
def main():
    parser = argparse.ArgumentParser(
        description='Construct paperwallets according to file')
    parser.add_argument('--design',
                        type=str,
                        help='Design of the paperwallet (defaults to "cass")')
    parser.add_argument('-svg',
                        help='Store as SVG instead of PDF',
                        action='store_true')
    parser.add_argument('--amount',
                        type=str,
                        help='Text (amount) to be placed on the paper wallet')
    parser.add_argument('--asset',
                        type=str,
                        help='Asset label to be placed on the paper wallet')
    parser.add_argument('-encrypt',
                        help='Encrypt private key with BIP38!',
                        action='store_true')
    parser.add_argument(
        '--back_qr',
        help='Content of the QR-code on the back of the paper wallet',
        action='store_true')
    parser.add_argument('--back_text1',
                        help='Text field 1 on the back of the paper wallet',
                        action='store_true')
    parser.add_argument('--back_text2',
                        help='Text field 2 on the back of the paper wallet',
                        action='store_true')
    parser.add_argument('--back_text3',
                        help='Text field 3 on the back of the paper wallet',
                        action='store_true')
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('--wallet',
                       type=str,
                       help='wallet csv file (i.e. generated by sharedrop.py)')
    group.add_argument('--number',
                       type=int,
                       help='Number of wallets to create randomly')
    parser.set_defaults(design="cass", amount="", asset=None)
    parser.set_defaults(back_text1="Install the BitShares App.",
                        back_text2="Load your funds from the wallet",
                        back_text3="Buy the BitShares 101 Book for $1",
                        back_qr="http://cryptofresh.com/products/8?r=xeroc")
    args = parser.parse_args()
    '''
    Optionally encrypt with BIP38
    '''
    pw = ""
    if args.encrypt:
        import getpass
        while True:
            pw = getpass.getpass('Passphrase: ')
            pwck = getpass.getpass('Retype passphrase: ')
            if (pw == pwck):
                break
            else:
                print("Given Passphrases do not match!")
    '''
    Construct data or read data from file
    '''
    wallet = []
    if args.wallet:
        with open(args.wallet, 'r') as csvfile:
            spamwriter = csv.reader(csvfile, delimiter=';')
            for wif, add, amount, asset in spamwriter:
                ''' Verify that the private keys gives access to address in add '''
                assert Address.priv2btsaddr(
                    Address.wif2hex(wif)
                ) is not add, "private key for address %s is different from given address %s" % (
                    Address.priv2btsaddr(Address.wif2hex(wif)), add)
                wallet.append([wif, add, amount, asset])
    else:
        for i in xrange(0, args.number):
            wif = Address.newwif()
            add = Address.wif2btsaddr(wif)
            wallet.append([wif, add, args.amount, args.asset])
    '''
    Construct paper wallets
    '''
    print("Constructing paper wallets")
    if not args.svg:
        import svg2pdf
        import io
        from PyPDF2 import PdfFileMerger, PdfFileReader
        mergerfront = PdfFileMerger()
        mergerback = PdfFileMerger()
        for w in wallet:
            wif, add, amount, asset = w
            print("Creating Paperwallet for %s" % (add))
            front, back = Paper.paperwallet(wif,
                                            add,
                                            amount,
                                            asset,
                                            encrypt=pw,
                                            design=args.design,
                                            backtext1=args.back_text1,
                                            backtext2=args.back_text2,
                                            backtext3=args.back_text3,
                                            backQRcode=args.back_qr)

            if args.svg:
                filename = "paperwallets/%s.svg" % add
                open(filename.replace('.svg', '-front.svg'), 'wb').write(front)
                open(filename.replace('.svg', '-back.svg'), 'wb').write(back)
            else:
                mergerfront.append(
                    PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(front)))))
                mergerback.append(
                    PdfFileReader(io.BytesIO(bytes(svg2pdf.svg2pdf(back)))))
        mergerfront.write("paperwallets-front.pdf")
        mergerback.write("paperwallets-back.pdf")
    else:
        for w in wallet:
            wif, add, amount, asset = w
            print("Creating Paperwallet for %s" % (add))
            front, back = Paper.paperwallet(wif,
                                            add,
                                            amount,
                                            asset,
                                            encrypt=pw,
                                            design=args.design,
                                            backtext1=args.back_text1,
                                            backtext2=args.back_text2,
                                            backtext3=args.back_text3,
                                            backQRcode=args.back_qr)

            filename = "paperwallets/%s.svg" % add
            open(filename.replace('.svg', '-front.svg'), 'wb').write(front)
            open(filename.replace('.svg', '-back.svg'), 'wb').write(back)
    print("Done.")