[ANN] offline transaction builder with peercoinjs-lib

As I was offering a helping hand at https://www.peercointalk.org/index.php?topic=4509.msg42481#msg42481
I thought of making a browserified library based on bitcoinjs-lib that you can include in your own peercoin related web page:

[sub]content of Peercoinjs.js[/sub]
https://jsfiddle.net/7htojnu5/

https://jsfiddle.net/mtof05u9/

with the above js file you can easily make an offline transaction builder like this:

[code]

offline transaction generator div { padding: 10px; }
.uppermargin {
    margin-bottom: 40px;
}
</style>

Offline peercoin transaction builder

Input 0:
Tx Id: (64 long hex string)
n: (> -1)
Private key WIF: (starts with U)
Output 0:
Amount: (ppc) Peercoin address: (starts with P)
 
[/code]

happy coding!

Why don’t you wrap the code in tag?

Hi,
Could you help me to develop a code for sign/verify message?
I try to use bitcoinjs but it not working for peercoin messages :frowning:

[code]const msg = require(‘bitcoinjs-lib/src/message’)
const bitcoin = require(‘bitcoinjs-lib’);
const ECPair = require(‘bitcoinjs-lib/src/ecpair’)

const network = bitcoin.networks[‘peercoin’];
const keyPair = ECPair.fromWIF(‘UBFEAigHah8pazgQJSZu4EuaabvuMEJofMgcQ4H6gSLregpHZyzH’, network)

console.log(’\nSigned message: ’ + msg.sign(keyPair, “1”, network).toString(‘base64’));[/code]

result:

Signed message: IJ248jgoV8v2TJQ6UfUSYlfktG3nS5GF9nkBuo5tGYTrAOps2WH8M0pFB0z4GJMi6mfh1mLj8IjbtnejLyUy7ls=

Try to verify with ppcoind:

curl --user kzv:pass  --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "verifymessage", "params": ["PJf7kR44b6ZZNtaSCCFBk24x5K57RzMp68", "IJ248jgoV8v2TJQ6UfUSYlfktG3nS5GF9nkBuo5tGYTrAOps2WH8M0pFB0z4GJMi6mfh1mLj8IjbtnejLyUy7ls=", "1"] }' -H 'content-type: text/plain;' http://127.0.0.1:9902/

Result:

{"result":false,"error":null,"id":"curltest"}

I am a little busy atm. But following this guide http://support.bitcoin.cz/Knowledgebase/Article/View/36/2/how-to-sign-a-message-using-bitcoin-client I have signed a message “1” myself and this is what I get:

IATFq0JErNbolStzl+xQA4ZN/k0jgnYCAt/VgcyqLSlwysmD02cy4JzFopWrBTOUA9AcO64GR5DKET5qz1UItBM=

which is not even remotely the same as IJ248jgoV8v2TJQ6UfUSYlfktG3nS5GF9nkBuo5tGYTrAOps2WH8M0pFB0z4GJMi6mfh1mLj8IjbtnejLyUy7ls

This could mean that maybe the values in the peercoin-network might not be correct. Just look up magicHash function e.g.

What the actual values ought to be I dont know myself, either the original ppcoin or ppc-go can help you here…

These are the differences found so far:

bitcoin magic bytes: magic = 0xd9b4bef9
peercoin magic bytes: 0xe6e8e9e5 (src: https://wiki.peercointalk.org/index.php?title=Peercoin_magic_bytes)

magichash function as implemented in bitcore: (https://github.com/bitpay/bitcore-message/blob/master/lib/message.js)

Message.MAGIC_BYTES = new Buffer('Bitcoin Signed Message:\n');

Message.prototype.magicHash = function magicHash() {
  var prefix1 = BufferWriter.varintBufNum(Message.MAGIC_BYTES.length);
  var messageBuffer = new Buffer(this.message);
  var prefix2 = BufferWriter.varintBufNum(messageBuffer.length);
  var buf = Buffer.concat([prefix1, Message.MAGIC_BYTES, prefix2, messageBuffer]);
  var hash = sha256sha256(buf);
  return hash;
};

and this is how magicHash is implemented by bitcoinjs:

function magicHash (message, network) {
  var messagePrefix = new Buffer(network.messagePrefix)
  var messageBuffer = new Buffer(message)
  var lengthBuffer = bufferutils.varIntBuffer(messageBuffer.length)

  var buffer = Buffer.concat([messagePrefix, lengthBuffer, messageBuffer])
  return bcrypto.hash256(buffer)
}

I am sure you can deduct what network.messagePrefix ought to be here. I hope this helps to see if it value as set in network is set correctly

1 Like

I see peercoin source https://github.com/ppcoin/ppcoin/blob/master/src/main.cpp#L60

const string strMessageMagic = "PPCoin Signed Message:\n";

And my fork of bitcoinjs https://github.com/3s3s/bitcoinjs-lib/blob/master/src/networks.js#L54

messagePrefix: '\x17PPcoin Signed Message:\n'

It seems, that “messagePrefix” is set corretly.

The string in bitcore

var buf = Buffer.concat([prefix1, Message.MAGIC_BYTES, prefix2, messageBuffer]);

(where prefix1 = ‘\x17’; Message.MAGIC_BYTES = ‘PPcoin Signed Message\n’)

is fully equivalent this string in bitcoinjs

var buffer = Buffer.concat([messagePrefix, lengthBuffer, messageBuffer])

(where messagePrefix = ‘\x17PPcoin Signed Message:\n’)

yes it should be
const string strMessageMagic = “PPCoin Signed Message:\n”;

not messagePrefix: ‘\x17PPcoin Signed Message:\n’,

[quote=“thehuntergames, post:7, topic:3851”]yes it should be
const string strMessageMagic = “PPCoin Signed Message:\n”;

not messagePrefix: ‘\x17PPcoin Signed Message:\n’,[/quote]

YES!!!
It’s work!
Thank you very much !!! :slight_smile: :slight_smile: :slight_smile:

You are welcome. I look forward seeing multicoins.org with peercoin support.
I am sure that it will be listed here too once it completes

Great work guys!
I guess this will become my default client once it is finished.

Hi,
i have released https://multicoins.org
Now Peercoin is supported too.

Thanks!

Unfortunately, blockr.io has still not cofirmed to update for the upcoming hard fork.
https://www.peercointalk.org/index.php?topic=4501.0

Not sure if that’s really needed to have multicoins fully working though.

[quote=“hrobeers, post:12, topic:3851”]Thanks!

Unfortunately, blockr.io has still not cofirmed to update for the upcoming hard fork.
https://www.peercointalk.org/index.php?topic=4501.0

Not sure if that’s really needed to have multicoins fully working though.[/quote]

It seems that blockr.io no longer support their site. Last news date 25.08.2014 http://ppc.blockr.io/news
If they stop supporting peercoin, my wallet can not support peercoin too. :frowning:

Hi kzv,

If you can’t find an up to date block explorer that exposes “sendrawtransaction”, we might need to implement our own.
We can start a peer4commit, and I can do back-end development.

But first please try to find an up to date explorer.

[quote=“hrobeers, post:14, topic:3851”]Hi kzv,

If you can’t find an up to date block explorer that exposes “sendrawtransaction”, we might need to implement our own.
We can start a peer4commit, and I can do back-end development.

But first please try to find an up to date explorer.[/quote]

Thanks for the offer.
I’ve already implemented my own “sendrawtransaction”, because blockr.io does not support it for now.

I am concerned about the possibility that blockr.io will stop supporting this API:

  1. Transaction info (This API call returns transaction data for unconfirmed and normal blockchain transactions. )
  2. Address balance (This api call can be used to fast request only the address balance.)
  3. Address transactions (Returns transactions for given address. )

You can use this one as backup.
However still not confirmed to update and also very inactive.

http://bkchain.org/static/api.txt

But it’s open source, so you might be able to add it next to your “sedrawtransaction” service?

[quote=“hrobeers, post:16, topic:3851”]You can use this one as backup.
However still not confirmed to update and also very inactive.

http://bkchain.org/static/api.txt

But it’s open source, so you might be able to add it next to your “sedrawtransaction” service?[/quote]

yes if blockr.io is stops working then i will use API bkchain.org.
Also maybe I will develop my own blockexplorer like blockr.io if my service will be popular :slight_smile:

Projects like PeerAssets and others PeerApps will also benefit from this.
So I’m quite sure there is a need for such an API service.

Having multiple fallbacks also increases reliability of the thin clients by taking away the single point of failure.

The guys at Ethereum would most likely implement it on Ethereum creating Methereum.

Hi
I tested a push tx and it worked! d9a43628b04a3ae9c3ff3c392144fd6a86752bca17aa848fc8f72657c88af1f9

however it says it has a limit of 5 request per day? Is that correct?

There is a need to have a page like this https://blockr.io/tx/push
or better yet, a API that does sendrawtransaction only

Any ideas how we can get this up?

[quote=“thehuntergames, post:19, topic:3851”]Hi
I tested a push tx and it worked! d9a43628b04a3ae9c3ff3c392144fd6a86752bca17aa848fc8f72657c88af1f9

however it says it has a limit of 5 request per day? Is that correct?[/quote]

Push TX has an active limit of 5 API requests per minute, not per day.