Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@deanmlittle/rpuzzle
Advanced tools
A simple library to help you create, sign and spend any kind of R Puzzle.
A simple library to help you create, sign and spend any kind of R Puzzle.
Please note, RPuzzle has a peer dependency of bsv
which must be installed independently to avoid version collisions.
To get started, simply run:
npm i bsv https://github.com/deanmlittle/rpuzzle
In true Bitcoin fashion, code is well-commented, poorly documented. You can create them randomly, from a PrivateKey, a buffer, a hex string or even an XPriv path. Here's an example of creating and spending a HASH160 P2RPH from Random:
We're going to generate a valid R Puzzle script in ASM format and the K value used to unlock it. Make sure to save these two pieces of information as we'll need them to publish and unlock the puzzle later.
const RPuzzle = require('rpuzzle');
const rpuzzle = RPuzzle.fromRandom();
console.log(rpuzzle.toASM());
console.log(rpuzzle.k.toHex());
//Returns:
//k value hex string
//OP_OVER OP_3 OP_SPLIT OP_NIP OP_1 OP_SPLIT OP_SWAP OP_SPLIT OP_DROP OP_HASH160 <r hash> OP_EQUALVERIFY OP_CHECKSIG
One of the simplest ways to do this is with MoneyButton. Copy your ASM script into the script property in data-outputs
below:
<script src="https://www.moneybutton.com/moneybutton.js"></script>
<div class='money-button'
data-outputs='[
{
"script": "OP_OVER OP_3 OP_SPLIT OP_NIP OP_1 OP_SPLIT OP_SWAP OP_SPLIT OP_DROP OP_HASH160 <r hash> OP_EQUALVERIFY OP_CHECKSIG",
"amount": "0.0218",
"currency": "USD"
}
]'
></div>
Here's a jsfiddle to make the whole process a little easier: https://jsfiddle.net/wfotksg6/
Swipe to put the TX on chain, copy the TXID from your Moneybutton, then head over to: http://api.whatsonchain.com/v1/bsv/main/<txid>/hex
to get the raw hex of the transaction.
Remember that K value hex string from step 1? We'll need that here:
const RPuzzle = require('rpuzzle');
const Transaction = require('bsv').Transaction;
const Script = require('bsv').Script;
const Address = require('bsv').Address;
//Create an R puzzle from the K value
const rpuzzle = RPuzzle(RPuzzle.KValue.fromHex("k value hexstring"));
//Grab the UTXO output(s) we want to spend from the previous TX we made
const fromTX = Transaction("tx raw hex");
const utxos = rpuzzle.getUTXOs(fromTX);
//Create a new Transaction to spend these outputs
let toTx = Transaction();
toTx.from(utxos);
//Get total input amount from UTXO(s)
const amount = toTx._getInputAmount();
toTx.to(Address.fromString('<a bitcoin address>'), amount-1000); //1000 sats is a pretty generous fee!
//Sign it!
toTx = rpuzzle.sign(toTx);
//Copy the raw tx hex so we can publish it!
console.log(toTx.uncheckedSerialize());
Head on over to https://whatsonchain.com/broadcast and paste in your new raw tx hex. You can either preview the TX to make sure everything looks correct (also not a bad way to figure out your fee rate), or assuming everything looks okay, hit the broadcast button and you're done!
You can actually publish any kind of R Puzzle you want. Here's a transaction I made where I created one output of each type: https://whatsonchain.com/tx/1ea1d846d0e5212f28654ba0eeb1db346e38e245415bf90ccd70c95060cf7f80
And subsequently spent them: https://whatsonchain.com/tx/a61e8444b717da21da2e6b5d6cc8b2cb724123bc6c8f3f5c088839ed4d2d5f33
RPuzzle implements all of the native hashing functions of Bitcoin, defaulting to OP_HASH160 <r>
. You can also just pay to the R value itself. To set a specific puzzle type, simply call setType
on an RPuzzle instance like so:
const rpuzzle = RPuzzle.fromRandom();
rpuzzle.setType('PayToRHASH256');
The current type options include:
Puzzle Type | Script |
---|---|
PayToRHASH160 | OP_HASH160 |
PayToRRIPEMD160 | OP_RIPEMD160 |
PayToRSHA256 | OP_SHA256 |
PayToRHASH256 | OP_HASH256 |
PayToRSHA1 | OP_SHA1 |
PayToR |
Want to contribute? Please do! Feel free to submit bugs or pull requests to this repo.
You can also tip me at deanlittle@moneybutton.com
, 1deanlittle
or /pay @40
on Twetch.
This code is provided free of charge with no warranties. Use at your own risk. Besides that, I don't really care how you use it so long as you promise to go build something cool. ;)
FAQs
A simple library to help you create, sign and spend any kind of R Puzzle.
The npm package @deanmlittle/rpuzzle receives a total of 0 weekly downloads. As such, @deanmlittle/rpuzzle popularity was classified as not popular.
We found that @deanmlittle/rpuzzle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.