moneybutton / express-paymail Goto Github PK
View Code? Open in Web Editor NEWExpress implementation for paymail specification.
License: Other
Express implementation for paymail specification.
License: Other
express-paymail uses senderPaymail
in the sender request:
but the spec calls for senderHandle
:
http://bsvalias.org/04-01-basic-address-resolution.html#sender-request
The regex here is too simplistic and too strict to validate email addresses:
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]+)?"
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
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
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"
}
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.
a
express-paymail uses "c318d09ed403":
https://github.com/moneybutton/express-paymail/blob/master/src/constants.js#L4
but the spec calls for "6745385c3fc0":
http://bsvalias.org/04-02-sender-validation.html
Is your impl developed against an older version of the spec?
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
Line 71 in 2f47f18
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.