Giter VIP home page Giter VIP logo

express-paymail's Issues

Failing on buildRoutes Import

Hi Guys,

Node newbie here. I am having difficulties getting past the first line of your example. No matter what I have tried.

It does not seem to be set up as a type=module for importing in this style and even after I get passed that it fails to recognise the buildRoutes export (which I can see.)

Any help to get me past this would be awesome. Thanks.

body-parser limiting requests larger than 100kb

If this library is added to the express router in front of any endpoints it will reject any content-type: application/json requests larger than 100kb because of body-parser default limit. One fix would be to add in a config flag with a custom limit. Another fix would be to only use body-parser on the endpoints that match with this library.

https://github.com/expressjs/body-parser#limit

baseRouter.use(bodyParser.json({ type: 'application/json' }))

Getting an error TypeError: Cannot read property 'Hash' of undefined

Hi,

Here is my code snippet for using @moneybutton/express-paymail:

import { Address, Bip32, Ecdsa, Hash, PubKey, Sig } from 'bsv';
import { buildRouter } from '@moneybutton/express-paymail';
import cors from 'cors';
import crypto from 'crypto';
import express, { Request, Response, NextFunction } from 'express';
import createError from 'http-errors';
import morgan from 'morgan';

const paymailRouter = buildRouter(API, {
  basePath: '/api/bsvalias',
  getIdentityKey: async (name, domain) => {
    // A paymail has the form `name@domain`. You can find the appropiate
    // key using paymail data.
    return '0335e5e7b86c12a4b5df082acb43ca7805382b58c805172bdef20ced310df845aa' // Some public key
  },
  getPaymentDestination: async (name, domain, body, helpers) => {
    // This method have to return a valid bitcoin outputs. The third parameter is the
    // body of the request and the fourth parameter is a js object containing handful
    // methods to create outputs.
    return helpers.p2pkhFromAddress('1FJJkRqyxTKAVX3dGFpddERt9XRbiSRZkL')
  },
  verifyPublicKeyOwner: async (name, domain, publicKeyToCheck) => {
    // Returns true if the public key belongs to the user owning `name@domain`, false in
    // any other case.
    return '0335e5e7b86c12a4b5df082acb43ca7805382b58c805172bdef20ced310df845aa' === publicKeyToCheck
  }
})

app.enable('trust proxy');
app.use(cors());
app.use(express.json());
app.use(paymailRouter);
app.use((req, res, next) => {
    (req as any).id = `${Date.now()}-${Math.round(Math.random() * 10 ** 6)}`;
    next();
});
morgan.token('id', (req) => (req as any).id);
app.use(morgan(':id :method :url :status :res[content-length] - :response-time ms ":user-agent"'))

app.get('/', (req, res, next) => {
    res.status(200).send("UP");
});

app.get('/health', (req, res, next) => {
    res.status(200).send("UP");
});

app.listen(PORT || 8080, () => {
        console.log(`listening on *:${PORT}`);
});

However, when I run this, I get the following error:

$ ./node_modules/.bin/ts-node paymail.ts

/usr/local/src/Kronoverse/krono-stacks/docker/paymail/node_modules/@moneybutton/brfc/src/index.js:11
  let hash = bsv.crypto.Hash.sha256sha256(
                        ^
TypeError: Cannot read property 'Hash' of undefined
    at Object.brfc (/usr/local/src/Kronoverse/krono-stacks/docker/paymail/node_modules/@moneybutton/brfc/src/index.js:11:25)
    at Object.<anonymous> (/usr/local/src/Kronoverse/krono-stacks/docker/paymail/node_modules/@moneybutton/paymail-client/src/constants.js:6:28)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/local/src/Kronoverse/krono-stacks/docker/paymail/node_modules/@moneybutton/express-paymail/lib/buildGetPaymentDestinationRouter.js:28:22)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

Am I doing something wrong?

Thank you
Ashish

Paymail port ? Http 80, Https 443 ?

Hi,

Looking to do something with this, looks really interesting. I watched this

https://www.youtube.com/watch?v=WFuArXVe3bM&t=1945s

The only thing I am missing is the port that it should be listening on, so, for example, the nodejs is listening on port 3000. actually, in the readme code there is an issue as its using an env (API_REST_PORT) variable but its listening on 3000, its minimal - but doesn't line up :-)

app.listen('3000', () => {
  logger.info(`Listening on port ${API_REST_PORT}.`)
})

For example, if I own domain xyz.com, then although the express is listening on port 3000 (or whatever port), I should have this behind a reverse proxy.

so actually it would expect to answer to the following URL

xyz.com/api/bsvalias/id/{alias}@{domain.tld}

notice the xyz.com on the URL above..

BUT, is this HTTP (80) or HTTPS (443) ?

Can you confirm?

I was also looking at the paymail spec and maybe I overlooked it but I couldn't find specifics to this.

Thanks in advance

display error response pattern (set standard)

can you guys define a common pattern (set standard in docs)to display error as a response in paymail api .
this will be helpful to display error from any playform

like

{
   statusCode: 404,
   status: "error",
   message: "unable to get paymail address"
}

a

a

"Invalid sender paymail" error has a bad email validating regex

The regex here is too simplistic and too strict to validate email addresses:

https://github.com/moneybutton/express-paymail/blob/master/src/buildGetPaymentDestinationRouter.js#L28

A better JS-compatible regex to use can be found in the second note of this section in the WhatWG's HTML Living Standard:

https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)

or...
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

In my Java implementation of Paymail, I use this shorter & faster regex:
"[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:(?:[a-zA-Z0-9-]*|(?<!-)\\.(?![-.]))*[a-zA-Z0-9]+)?"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.