peercoin / perpera

Typescript implementation of the PeerAssets Data Audit Protocol (PADAP)
BSD 3-Clause "New" or "Revised" License
5 stars 6 forks source link

CLI instead of Web-Frontend? #20

Open michael-holzheu opened 2 years ago

michael-holzheu commented 2 years ago

I would like to use "Perpera" to save hashes of documents on the peercoin blockchain.

Up to now I only found your Web-Frontend: https://perpera.peercoin.net

This is almost what I was looking for, but I don't want to paste my private key into an unknown browser window.

Is there any other easy way (e.g. a command line interface) to use "Perpera" without having to transfer the private key via an unsecured connection?

jointhepartypooper commented 2 years ago

i suppose you can run the code on https://github.com/peercoin/perpera-web on localhost?

michael-holzheu commented 2 years ago

Ok, I now got it running in a Docker container with an Ubuntu image and "npm install/start" as described in the README, thanks :+1:!

michael-holzheu commented 2 years ago

I assume the private key is not sent to the outside by the script, right?

michael-holzheu commented 2 years ago

When I enter the private key, which I got by "dumpprivkey ..." from the peercoin-qt console, "perpera-web" shows me "Your wallet has no funds", which is not true.

In the PeerCoin Explorer I see enough coins on the corresponding public key: https://chainz.cryptoid.info/ppc/address.dws?PRoiyRWKx1HtKQsV2CibjcyHA2B8Fo9B91.htm

Any idea?

michael-holzheu commented 2 years ago

The error seems to occur in src/services/Perpera.ts#getFee.

peerchemist commented 2 years ago

I assume the private key is not sent to the outside by the script, right?

It's only used by the spender to sign the transaction.

michael-holzheu commented 2 years ago

The failing function is public/perpera.js:update.add():

const utxos = this.spender.allocate(fee - balance);
if (utxos === null)
    throw new Error('Insufficient funds.');

For my sample document and private key the values of "fee" and "balance" are:

The callstack up to this point is as follows:

michael-holzheu commented 2 years ago

I now tried to switch to the Peercoin "testnet" by the following change:

git diff src/services/Perpera.ts
diff --git a/src/services/Perpera.ts b/src/services/Perpera.ts
index 91d2f61..f78028e 100644
--- a/src/services/Perpera.ts
+++ b/src/services/Perpera.ts
@@ -4,7 +4,7 @@ export default class PerperaService {

   constructor(network?: string) {
     this.perpera = window['perpera'];
-    this.network = network || window['perpera'].networks['peercoin'];
+    this.network = network || window['perpera'].networks['peercoin-testnet'];
   }

   public getDocument(hash: string) {

With the corresponding private key for my new peercoins, I now get "WIF invalid" respectively "TypeError: Private key network mismatch".

peerchemist commented 2 years ago

It seems you are trying to use it on mainnet, so just leave it on mainnet.

peerchemist commented 2 years ago

I believe that fee calculation logic was extremely out of date. This bit of software is unmaintained for about 4 years.

https://github.com/peercoin/perpera/pull/21

I think this will resolve it.

michael-holzheu commented 2 years ago

I believe that fee calculation logic was extremely out of date. This bit of software is unmaintained for about 4 years.

21

I think this will resolve it.

I changed the file public/perpera.js accordingly, but unfortunately it did not fix the problem. The fee is still "1000". I assume that the "balance" is the problem here?

michael-holzheu commented 2 years ago

It seems you are trying to use it on mainnet, so just leave it on mainnet.

Nevertheless for development it would be nice to be able to switch to "testnet". Could you tell me what is necessary to do that?

peerchemist commented 2 years ago

Well, sorry I can't do much to help you out. I'm totally not into frontends or JS ecosystem in general. Unfortunately, the person who wrote this frontend is absent for a while.

But really this should not be so difficult to update, patch and deploy fixed version,

michael-holzheu commented 2 years ago

Is your public Web-Frontend (https://perpera.peercoin.net) working for you, or does it show the same problem?

peerchemist commented 2 years ago

Yes, same problem.

I've figured out it calls now defunct explorer API. I've removed the support for that API from the source. Could you build and try again?

michael-holzheu commented 2 years ago

I've figured out it calls now defunct explorer API. I've removed the support for that API from the source. Could you build and try again?

What do I have to do here exactly? You removed the file "explorer.ts" in the "perpera" git repository. I don't find this file in the "perpera-web" git repository.

peerchemist commented 2 years ago

Now, this lib must be built and included into the perpera-web.