question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Btcpayserver refuses to work with a new token

See original GitHub issue

The guys when I try to create an invoice, I constantly have a 401 error, although I do everything according to the instructions:

info: BTCPayServer.Security.BitpayAuthentication+BitpayAuthHandler: Bitpay.Auth was not authenticated. Failure message: Invalid credentials
info: BTCPayServer.Security.BitpayAuthentication+BitpayAuthHandler: AuthenticationScheme: Bitpay.Auth was challenged.

perform the following steps:

  • create a private key
  • I get clientId using it (that is, I get SIN)
  • I create a new token in the admin panel btcpayserver-> stores-> Access token
  • copying the pairing code and sending a request to /tokens, the request looks like this: body {pairingCode: ‘j6jfkaf’, id: ‘Tf3WxtCNvPR9ATBjc14Wrw6EBxBS5AWn8Li’}
  • in response, I successfully receive the token
  • then I create an invoice {price: 900, currency: ‘USD’, token: ‘****’}
  • add X-Identity and X-Signature headers
{
'X-Identity': Buffer.from(this.keypar.getPublic().EncodeCompressed()).ToString('hex'),
'X-Signature': this.sign(url, this.keypar).toString ('hex')
}

where url is host + uri + payload, and payload is JSON request body

After that, I successfully create an invoice, everything works! But after all, the current token will become obsolete after some time, and I added functionality to update it for example after 10 hours.

I save the private key to a file:

fs.writeFile('./key', JSON.stringify(keys.priv), 'utf-8', (err) => {
  if (err) console.log('err generateKeys:', err)
})

Then, when restarting the service, I load the private key:

const file = fs.readFileSync('./key', 'utf8')
this.keypar = ec.keyFromPrivate(Buffer.from(JSON.parse(file), 'hex'))

To get a new token, I send a request to / tokens with the following parameters

{
  label: 'label', // obtained by pairing pair code
  id: 'Tf3WxtCNvPR9ATBjc14Wrw6EBxBS5AWn8Li',
  facade: 'merchant'
}

In response, I get a new token and using it I try to create an invoice, but I get the error 401 (

Guys, explain to me how to organize work with the API?

I want to know, after pairing paircode, I can use the received data to create a new token, right? but it does not work (

The source code for my implementation is here: https://github.com/hazratgs/btcpay-node/blob/master/payqr.js

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hazratgscommented, Mar 11, 2019

@hazratgs has your issue been resolved?

Yes, thank

1reaction
NicolasDoriercommented, Feb 2, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Frequently Asked Questions and Common Issues
General, non-technical questions about BTCPay. What it is, how it works, what are its features, why is it different and who can use...
Read more >
General FAQ | BTCPay Server
What is BTCPay Server? BTCPay Server is a free and open-source cryptocurrency payment processor which allows you to receive payments in Bitcoin (on-chain ......
Read more >
BTCPay Server FAQ - Voltage
What is the API Key in my BTCPay account labeled 'Voltage Generated Token'? ... This is an API Key we generate when we...
Read more >
Hosting BTCPayserver (#33750) · Issues - Tor gitLab
LitecoinD and other coin daemons. It seems the bitcoin client needs to be installed and synced locally, therefore I am a bit concerned...
Read more >
BTCPay Server AspNetCore Antiforgery Token could not ...
I am running BTCPay Server behind a nginx reverse proxy and get this error. I believe this is why lightning addresses are not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found