Skip to content

Commit

Permalink
Fix demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
22388o committed Dec 6, 2024
1 parent e05f93c commit 652265a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"payjoin-react-native": "1.0.3-alpha",
"react": "18.2.0",
"react-native": "0.76.3"
}
19 changes: 8 additions & 11 deletions src/demo/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,23 @@ async function finalizeAndBroadcast(
modifiedPsbt: bitcoin.Psbt,
senderPrivateKey: string
): Promise<void> {
const keyPair = bitcoin.payments.p2pkh({ wif: senderPrivateKey }).keys[0];
const keyPair = bitcoin.fromWIF(senderPrivateKey);

// Sign the transaction
modifiedPsbt.signAllInputs(keyPair);

// Validate and finalize

modifiedPsbt.validateSignaturesOfAllInputs((pubkey, msghash, signature) => {
return bitcoin.verify(msghash, pubkey, signature);
});
modifiedPsbt.finalizeAllInputs();
return bitcoin.fromPublicKey(pubkey).verify(msghash, signature);
}); modifiedPsbt.finalizeAllInputs();

const txHex = modifiedPsbt.extractTransaction().toHex();

// Broadcast transaction (placeholder logic)
await broadcastTransaction(txHex);

}// Fetch UTXOs for a given address (placeholder implementation)
async function fetchUtxos(senderAddress: string): Promise<Utxo[]> {
}// Fetch UTXOs for a given address (placeholder implementation)async function fetchUtxos(senderAddress: string): Promise<Utxo[]> {
// Replace with actual API call to fetch UTXOs
return [
{
Expand All @@ -103,24 +101,23 @@ async function fetchUtxos(senderAddress: string): Promise<Utxo[]> {
hex: 'dummy-hex',
timelock: 0,
amount: 1000000,
address: senderAddress,
address: address,
preimage: '',
scriptPubKey: '',
confirmations: 10,
is_coinbase: false,
},
];
}
];}

async function broadcastTransaction(txHex: string): Promise<void> {
console.log(`Broadcasting transaction: ${txHex}`);
// Implement actual broadcasting logic using a Bitcoin node or API
}

const { YourLibrary } = NativeModules;
const PayjoinReactNative = NativeModules.PayjoinReactNative;

const sampleMethod = async (input: string): Promise<string> => {
return await YourLibrary.sampleMethod(input);
return await PayjoinReactNative.sampleMethod(input);
};

export default {
Expand Down

0 comments on commit 652265a

Please sign in to comment.