1import React, { useState } from 'react';
2import { Grid, Text } from 'indigo-react';
4import { useLocalRouter } from 'lib/LocalRouter';
5import { COMMANDS, useFlowCommand } from 'lib/flowCommand';
7import View from 'components/View';
8import Highlighted from 'components/Highlighted';
9import CopiableAddressWrap from 'components/CopiableAddressWrap';
10import ViewHeader from 'components/ViewHeader';
11import SubmitButton from 'form/SubmitButton';
13import { useWallet } from 'store/wallet';
15import * as need from 'lib/need';
16import * as bitcoin from 'bitcoinjs-lib';
18import BridgeForm from 'form/BridgeForm';
19import { PsbtInput } from 'form/Inputs';
21import { Buffer } from 'buffer';
22import { composeValidator, buildPsbtValidator } from 'form/validators';
24export default function SignTransaction() {
25 const { pop } = useLocalRouter();
26 const { urbitWallet } = useWallet();
27 const flow = useFlowCommand();
29 const [signedTx, setSignedTx] = useState('');
30 const [psbt, setPsbt] = useState({});
32 const { private: privKey, chain } = need.urbitWallet(
36 const btcWallet = bitcoin.bip32.fromPrivateKey(
37 Buffer.from(privKey, 'hex'),
38 Buffer.from(chain, 'hex'),
39 bitcoin.networks.bitcoin
42 const validate = composeValidator({
43 unsignedTransaction: buildPsbtValidator(btcWallet),
46 const onSubmit = values => {
47 const newPsbt = bitcoin.Psbt.fromBase64(values.unsignedTransaction);
48 const hex = newPsbt.data.inputs
49 .reduce((psbt, input, idx) => {
50 // removing already derived part, eg m/84'/0'/0'/0/0 becomes 0/0
51 const path = input.bip32Derivation[0].path
52 .split("m/84'/0'/0'/")
54 const prv = btcWallet.derivePath(path).privateKey;
56 return psbt.signInput(idx, bitcoin.ECPair.fromPrivateKey(prv));
69 const initialValues = {};
70 if (flow && COMMANDS.BITCOIN === flow.kind) {
71 initialValues.unsignedTransaction = flow.utx;
75 <View pop={pop} inset>
76 <Grid className="mt4">
77 <Grid.Item full className="mt4" as={Text}>
78 Paste unsigned transactions from Landscape here
82 initialValues={initialValues}
84 {({ handleSubmit }) => (
89 name="unsignedTransaction"
90 label="Unsigned transaction"
98 handleSubmit={handleSubmit}
106 <Grid.Item full className="mt4" as={Text}>
111 psbt.txOutputs.map(e => (
112 <Grid.Item full className="mt4" key={e.address}>
113 <span>{e.address}</span>
114 <div className="mt1 mono black f6">{e.value} sats</div>
119 <Grid.Item full className="mt4" as={ViewHeader}>
122 <Grid.Item full as={Text}>
124 <CopiableAddressWrap>{signedTx}</CopiableAddressWrap>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list