Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error calling createInvoice in router.js #17

Open
seak1234 opened this issue May 25, 2023 · 2 comments
Open

Error calling createInvoice in router.js #17

seak1234 opened this issue May 25, 2023 · 2 comments

Comments

@seak1234
Copy link

seak1234 commented May 25, 2023

Hey,

after updating my lnd node to lnd v0.16.2-beta I noticed that ligess on my node cannot create invoices anymore. It used to work a few weeks ago. Not sure if updating lnd is even related to this issue though.

Terminal out put:

yarn run v1.22.19
warning package.json: No license field
$ nodemon index.js
[nodemon] 2.0.12
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
{"level":30,"time":1684973619585,"pid":705738,"hostname":"raspibolt","msg":"Nostr NIP-57 enabled","npub":"npub195q6.....................3xcz"}
{"level":30,"time":1684973619616,"pid":705738,"hostname":"raspibolt","msg":"Server listening at http://127.0.0.1:3000"}
Unable to fetch pending invoices TypeError: Cannot read properties of undefined (reading 'map')
    at LndRest.getPendingInvoices (/home/ligess/ligess/node_modules/una-wrapper/dist/index.cjs:194:36)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
{"level":30,"time":1684973645487,"pid":705738,"hostname":"raspibolt","reqId":"req-1","req":{"method":"GET","url":"/.well-known/lnurlp/seak","hostname":"ln.satoshibox.org","remoteAddress":"127.0.0.1","remotePort":47532},"msg":"incoming request"}
{"level":30,"time":1684973645498,"pid":705738,"hostname":"raspibolt","reqId":"req-1","res":{"statusCode":200},"responseTime":9.093086987733841,"msg":"request completed"}
{"level":30,"time":1684973648261,"pid":705738,"hostname":"raspibolt","reqId":"req-2","req":{"method":"GET","url":"/.well-known/lnurlp/seak?amount=1000&nonce=1684973648224","hostname":"ln.satoshibox.org","remoteAddress":"127.0.0.1","remotePort":47532},"msg":"incoming request"}
{"level":40,"time":1684973649365,"pid":705738,"hostname":"raspibolt","reqId":"req-2","status":"ERROR","reason":"An error occured while getting invoice: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined"}
{"level":30,"time":1684973649367,"pid":705738,"hostname":"raspibolt","reqId":"req-2","res":{"statusCode":400},"responseTime":1105.8670839965343,"msg":"request completed"}

Initial debugging:
There seems to be two parts to this:

  1. The following only shows if I add my nostr private key:
Unable to fetch pending invoices TypeError: Cannot read properties of undefined (reading 'map')
    at LndRest.getPendingInvoices (/home/ligess/ligess/node_modules/una-wrapper/dist/index.cjs:194:36)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  1. The following will show when I try to send myself some sats form a different wallet
{"level":30,"time":1684973645487,"pid":705738,"hostname":"raspibolt","reqId":"req-1","req":{"method":"GET","url":"/.well-known/lnurlp/seak","hostname":"ln.satoshibox.org","remoteAddress":"127.0.0.1","remotePort":47532},"msg":"incoming request"}
{"level":30,"time":1684973645498,"pid":705738,"hostname":"raspibolt","reqId":"req-1","res":{"statusCode":200},"responseTime":9.093086987733841,"msg":"request completed"}
{"level":30,"time":1684973648261,"pid":705738,"hostname":"raspibolt","reqId":"req-2","req":{"method":"GET","url":"/.well-known/lnurlp/seak?amount=1000&nonce=1684973648224","hostname":"ln.satoshibox.org","remoteAddress":"127.0.0.1","remotePort":47532},"msg":"incoming request"}
{"level":40,"time":1684973649365,"pid":705738,"hostname":"raspibolt","reqId":"req-2","status":"ERROR","reason":"An error occured while getting invoice: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined"}
{"level":30,"time":1684973649367,"pid":705738,"hostname":"raspibolt","reqId":"req-2","res":{"statusCode":400},"responseTime":1105.8670839965343,"msg":"request completed"}

Focussing on point 2
There seems to be an issue with the una-wrapper (Universal Node API) when creating an invoice in router.js, executing the createInvoice function call:

const invoice = await unaWrapper.createInvoice({
        amountMsats: msat,
        descriptionHash: crypto
          .createHash('sha256')
          .update(metadata)
          .digest('hex')
      })

Function call uses the following inputs according to console.log():

msat:
1000
crypto:
{"constants":{"OPENSSL_VERSION_NUMBER":269488463,"SSL_OP_ALL":2147485780,"SSL_OP_ALLOW_NO_DHE_KEX":1024,"SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION":262144,"SSL_OP_CIPHER_SERVER_PREFERENCE":4194304,"SSL_OP_CISCO_ANYCONNECT":32768,"SSL_OP_COOKIE_EXCHANGE":8192,"SSL_OP_CRYPTOPRO_TLSEXT_BUG":2147483648,"SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS":2048,"SSL_OP_EPHEMERAL_RSA":0,"SSL_OP_LEGACY_SERVER_CONNECT":4,"SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER":0,"SSL_OP_MICROSOFT_SESS_ID_BUG":0,"SSL_OP_MSIE_SSLV2_RSA_PADDING":0,"SSL_OP_NETSCAPE_CA_DN_BUG":0,"SSL_OP_NETSCAPE_CHALLENGE_BUG":0,"SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG":0,"SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG":0,"SSL_OP_NO_COMPRESSION":131072,"SSL_OP_NO_ENCRYPT_THEN_MAC":524288,"SSL_OP_NO_QUERY_MTU":4096,"SSL_OP_NO_RENEGOTIATION":1073741824,"SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION":65536,"SSL_OP_NO_SSLv2":0,"SSL_OP_NO_SSLv3":33554432,"SSL_OP_NO_TICKET":16384,"SSL_OP_NO_TLSv1":67108864,"SSL_OP_NO_TLSv1_1":268435456,"SSL_OP_NO_TLSv1_2":134217728,"SSL_OP_NO_TLSv1_3":536870912,"SSL_OP_PKCS1_CHECK_1":0,"SSL_OP_PKCS1_CHECK_2":0,"SSL_OP_PRIORITIZE_CHACHA":2097152,"SSL_OP_SINGLE_DH_USE":0,"SSL_OP_SINGLE_ECDH_USE":0,"SSL_OP_SSLEAY_080_CLIENT_DH_BUG":0,"SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG":0,"SSL_OP_TLS_BLOCK_PADDING_BUG":0,"SSL_OP_TLS_D5_BUG":0,"SSL_OP_TLS_ROLLBACK_BUG":8388608,"ENGINE_METHOD_RSA":1,"ENGINE_METHOD_DSA":2,"ENGINE_METHOD_DH":4,"ENGINE_METHOD_RAND":8,"ENGINE_METHOD_EC":2048,"ENGINE_METHOD_CIPHERS":64,"ENGINE_METHOD_DIGESTS":128,"ENGINE_METHOD_PKEY_METHS":512,"ENGINE_METHOD_PKEY_ASN1_METHS":1024,"ENGINE_METHOD_ALL":65535,"ENGINE_METHOD_NONE":0,"DH_CHECK_P_NOT_SAFE_PRIME":2,"DH_CHECK_P_NOT_PRIME":1,"DH_UNABLE_TO_CHECK_GENERATOR":4,"DH_NOT_SUITABLE_GENERATOR":8,"ALPN_ENABLED":1,"RSA_PKCS1_PADDING":1,"RSA_SSLV23_PADDING":2,"RSA_NO_PADDING":3,"RSA_PKCS1_OAEP_PADDING":4,"RSA_X931_PADDING":5,"RSA_PKCS1_PSS_PADDING":6,"RSA_PSS_SALTLEN_DIGEST":-1,"RSA_PSS_SALTLEN_MAX_SIGN":-2,"RSA_PSS_SALTLEN_AUTO":-2,"defaultCoreCipherList":"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA","TLS1_VERSION":769,"TLS1_1_VERSION":770,"TLS1_2_VERSION":771,"TLS1_3_VERSION":772,"POINT_CONVERSION_COMPRESSED":2,"POINT_CONVERSION_UNCOMPRESSED":4,"POINT_CONVERSION_HYBRID":6},"webcrypto":{}}`
metadata:
[["text/identifier","[email protected]"],["text/plain","Satoshis to [email protected]"]]

This will lead to:

{"level":50,"time":1684974094646,"pid":710310,"hostname":"raspibolt","reqId":"req-2",
"req":{"method":"GET","url":"/.well-known/lnurlp/seak?amount=1000&nonce=1684974093505","hostname":"ln.satoshibox.org","remoteAddress":"127.0.0.1","remotePort":49076},"res":{"statusCode":500},
"err":{"type":"TypeError","message":"The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined",
"stack":"TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
\n    at new NodeError (node:internal/errors:387:5)
\n    at Function.from (node:buffer:328:9)
\n    at base64ToHex (/home/ligess/ligess/node_modules/una-wrapper/dist/index.cjs:554:17)
\n    at LndRest.createInvoice (/home/ligess/ligess/node_modules/una-wrapper/dist/index.cjs:161:34)
\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)
\n    at async Una.createInvoice (/home/ligess/ligess/node_modules/una-wrapper/dist/index.cjs:817:12)
\n    at async Object.<anonymous> (/home/ligess/ligess/router.js:69:23)","code":"ERR_INVALID_ARG_TYPE"},
"msg":"The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined"}
{"level":30,"time":1684974094650,"pid":710310,"hostname":"raspibolt","reqId":"req-2","res":{"statusCode":500},"responseTime":1103.6004920005798,"msg":"request completed"}

Unfortunately, I am not a java script guy. Debugging this issue by myself will take forever. Does anyone have an idea what is going on and point me to something?

Any help is much appreciated!

@seak1234 seak1234 changed the title createInvoice error - lnd v0.16.2-beta & una-wrapper compatibility issue? createInvoice error - una-wrapper compatibility issue? May 25, 2023
@seak1234
Copy link
Author

I believe createInvoice is called from inside of ligess\node_modules\una-wrapper\dist\index.cjs. Error occurs at line 135 when calling base64ToHex(response.r_hash), where response.r_hash = undefined);

    const body = this.prepareBody(data);
    const options = this.getRequestOptions(EHttpVerb.POST, "/v1/invoices");
    const response = await this.request(options, body);
    return await this.getInvoice(base64ToHex(response.r_hash));

Values of variables

body value:
{"value_msat":"1000","description_hash":"uWrBTOziVlvmnxUY5aB2odQU6VDeVcQ8JSmMIHkKrBA="}

option value:

{"method":"POST","path":"/v1/invoices",
"agent":{"_events":{},"_eventsCount":0,"timeout":null,
"maxFreeSockets":1,"maxSockets":1,"maxTotalSockets":null,
"sockets":{},"freeSockets":{},"requests":{},"options":{},
"shouldLookup":false,"proxy":{"host":"127.0.0.1","port":9050,"type":5},
"tlsConnectionOptions":{"rejectUnauthorized":false}},
"headers":{"Grpc-Metadata-macaroon":
"0201036c6e640258030a10...............#shortened#...................33c987a"},
"protocol":"https:","hostname":"lnd.satoshibox.org","port":"","pathname":"/"}

response value:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Just a moment...</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="robots" content="noindex,nofollow">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link href="/cdn-cgi/styles/challenges.css" rel="stylesheet">


</head>
<body class="no-js">
    <div class="main-wrapper" role="main">
    <div class="main-content">
        <noscript>
            <div id="challenge-error-title">
                <div class="h2">
                    <span class="icon-wrapper">
                        <div class="heading-icon warning-icon"></div>
                    </span>
                    <span id="challenge-error-text">
                        Enable JavaScript and cookies to continue
                    </span>
                </div>
            </div>
        </noscript>
        <div id="trk_jschal_js" style="display:none;background-image:url('/cdn-cgi/images/trace/managed/nojs/transparent.gif?ray=7cca3313bbc0b72a')"></div>
        <form id="challenge-form" action="/v1/invoices?__cf_chl_f_tk=................#shortened#........-1684980181-0-gaNycGzNCzs" method="POST" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="md" value="P.VxGUCm6g0Vaz560BPi8_WoCHtwoH7ryY..................................#shortened#...............t7q3rAHXLbmJof073IssQ_CDKfQiuzUr9b4MJXUNcFKTQ">
        </form>
    </div>
</div>

<script>
    (function(){
        window._cf_chl_opt={
            cvId: '2',
            cZone: 'lnd.satoshibox.org',
            cType: 'managed',
            cNounce: '22253',
            cRay: '7cca3313bbc0b72a',
            cHash: '015a14e25fb260a',
            cUPMDTk: "\/v1\/invoices?__cf_chl_tk=D5dVe3DKpXNXA065T2acJt068D1viDZdMGZc52Z2mHA-1684980181-0-gaNycGzNCzs",
            cFPWv: 'b',
            cTTimeMs: '1000',
            cMTimeMs: '0',
            cTplV: 5,
            cTplB: 'cf',
            cK: "",
            cRq: {
                ru: 'aHR0cHM6Ly9sbmQuc2F0b3NoaWJveC5vcmcvdjEvaW52b2ljZXM=',
                ra: 'Tk9fVUE=',
                rm: 'UE9TVA==',
                d: 'PARCN8x9oKwceJ0CDyUDbO................#shortened#........IESzu6kJS0zKbQt',
                t: 'MTY4NDk4MDE4MS4wNzIwMDA=',
                m: 'Cq2MVxkRrw1QIgLjfuMxT8CHAbAJ4YII/zDOFUXODp8=',
                i1: 'bUDVr5h20w4uguFL43obJg==',
                i2: 'm4m3zBiwORZkTxCdcIUA9A==',
                zh: 'QqOYPcTxAjVIi5IUERncwNkdUsKJiHsMXNqipqg3jb8=',
                uh: 'DV4j3Tmrbi5Rs1q3ahwVS6SgbPbI7np5884QO1u1Cgg=',
                hh: 'Hizy1AJuAvrKivs3L0g7lArjQ/B/Yt6zYxrCMOAOR2o=',
            }
        };
        var trkjs = document.createElement('img');
        trkjs.setAttribute('src', '/cdn-cgi/images/trace/managed/js/transparent.gif?ray=7cca3313bbc0b72a');
        trkjs.setAttribute('alt', '');
        trkjs.setAttribute('style', 'display: none');
        document.body.appendChild(trkjs);
        var cpo = document.createElement('script');
        cpo.src = '/cdn-cgi/challenge-platform/h/b/orchestrate/managed/v1?ray=7cca3313bbc0b72a';
        window._cf_chl_opt.cOgUHash = location.hash === '' && location.href.indexOf('#') !== -1 ? '#' : location.hash;
        window._cf_chl_opt.cOgUQuery = location.search === '' && location.href.slice(0, location.href.length - window._cf_chl_opt.cOgUHash.length).indexOf('?') !== -1 ? '?' : location.search;
        if (window.history && window.history.replaceState) {
            var ogU = location.pathname + window._cf_chl_opt.cOgUQuery + window._cf_chl_opt.cOgUHash;
            history.replaceState(null, null, "\/v1\/invoices?__cf_chl_rt_tk=D5dVe3DKpXNXA065T2acJt068D1viDZdMGZc52Z2mHA-1684980181-0-gaNycGzNCzs" + window._cf_chl_opt.cOgUHash);
            cpo.onload = function() {
                history.replaceState(null, null, ogU);
            };
        }
        document.getElementsByTagName('head')[0].appendChild(cpo);
    }());
</script>


</body>
</html>

response.r_hash value:
undefined

This is where I am stuck currently. response looks incorrect to me

@seak1234 seak1234 changed the title createInvoice error - una-wrapper compatibility issue? Error calling createInvoice in router.js May 25, 2023
@seak1234
Copy link
Author

Issue could be recreated running yarn dev & docker-compose up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant