@@ -1,155 +0,0 @@
1−import React, { useState } from 'react';
2−import { Grid, Text } from 'indigo-react';
3−import { useWallet } from 'store/wallet';
5−import { useLocalRouter } from 'lib/LocalRouter';
7−import ViewHeader from 'components/ViewHeader';
8−import View from 'components/View';
9−import WarningBox from 'components/WarningBox';
11−import CopiableAddressWrap from 'components/CopiableAddressWrap';
12−import Highlighted from 'components/Highlighted';
14−import { PsbtInput } from 'form/Inputs';
15−import BridgeForm from 'form/BridgeForm';
17−import * as need from 'lib/need';
18−import * as bitcoin from 'bitcoinjs-lib';
19−import * as bs58check from 'bs58check';
20−import { Buffer } from 'buffer';
21−import { composeValidator, buildPsbtValidator } from 'form/validators';
23−function xpubToZpub(xpub) {
24− var data = bs58check.decode(xpub);
25− data = data.slice(4);
26− data = Buffer.concat([Buffer.from('04b24746', 'hex'), data]);
27− return bs58check.encode(data);
30−export default function Bitcoin() {
31− const { pop } = useLocalRouter();
32− const { urbitWallet } = useWallet();
35− const empty = new bitcoin.Psbt();
37− const [signedTx, setSignedTx] = useState('');
38− const [psbt, setPsbt] = useState(empty);
40− const privKey = need.urbitWallet(urbitWallet).bitcoin.keys.private;
41− const pubKey = need.urbitWallet(urbitWallet).bitcoin.keys.public;
42− const chain = need.urbitWallet(urbitWallet).bitcoin.keys.chain;
44− const btcWallet = bitcoin.bip32.fromPrivateKey(
45− Buffer.from(privKey, 'hex'),
46− Buffer.from(chain, 'hex'),
47− bitcoin.networks.bitcoin
50− const zPub = xpubToZpub(
53− Buffer.from(pubKey, 'hex'),
54− Buffer.from(chain, 'hex'),
55− bitcoin.networks.bitcoin
60− const validate = composeValidator({
61− unsignedTransaction: buildPsbtValidator(btcWallet),
64− const onValues = ({ valid, values, form }) => {
66− const newPsbt = bitcoin.Psbt.fromBase64(values.unsignedTransaction);
67− const hex = newPsbt.data.inputs
68− .reduce((psbt, input, idx) => {
69− // removing already derived part, eg m/84'/0'/0'/0/0 becomes 0/0
70− const path = input.bip32Derivation[0].path
71− .split("m/84'/0'/0'/")
73− const prv = btcWallet.derivePath(path).privateKey;
75− return psbt.signInput(idx, bitcoin.ECPair.fromPrivateKey(prv));
81− .extractTransaction()
84− if (psbt.toHex() !== newPsbt.toHex()) {
94− <View pop={pop} inset>
95− <Grid className="mt4">
96− <Grid.Item full as={ViewHeader}>
99− <Grid.Item full as={WarningBox}>
100− We do not recommend using this feature for significant amounts of
101− money, since your private keys are exposed to the browser.
103− <Grid.Item full className="mt4" as={Text}>
104− Below is the bitcoin extended public key derived from your master
105− ticket. You can paste it to Landscape to generate an unsigned
108− <Grid.Item full className="mt4" as={Text}>
110− <CopiableAddressWrap>{zPub}</CopiableAddressWrap>
113− <Grid.Item full className="mt4" as={Text}>
114− Next, paste the unsigned transaction below to sign it with your
117− <BridgeForm validate={validate} onValues={onValues}>
122− name="unsignedTransaction"
123− label="Unsigned transaction"
129− <Grid.Item full className="mt4" as={Text}>
130− Transaction outputs:
134− psbt.txOutputs.map(e => (
135− <Grid.Item full className="mt4" key={e.address}>
136− <span>{e.address}</span>
137− <div className="mt1 mono black f6">{e.value} Satoshis</div>
142− <Grid.Item full className="mt4" as={ViewHeader}>
145− <Grid.Item full as={Text}>
147− <CopiableAddressWrap>{signedTx}</CopiableAddressWrap>