Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moneybutton/paymail-client

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moneybutton/paymail-client - npm Package Compare versions

Comparing version 0.27.0 to 0.28.0

169

dist/paymail-client.cjs.js

@@ -7,5 +7,4 @@ 'use strict';

var bsv = _interopDefault(require('bsv'));
var Message = _interopDefault(require('bsv/message'));
var moment = _interopDefault(require('moment'));
var fetch = _interopDefault(require('isomorphic-fetch'));

@@ -127,4 +126,4 @@ const Capabilities = {

class DnsOverHttps {
constructor(fetch, config) {
this.fetch = fetch;
constructor(fetch$$1, config) {
this.fetch = fetch$$1;
this.config = config;

@@ -146,17 +145,12 @@ }

class EndpointResolver {
constructor(dns = null, fetch) {
if (dns !== null) {
this.dnsClient = new DnsClient(dns, new DnsOverHttps(fetch, {
baseUrl: 'https://dns.google.com/resolve'
}));
} else {
this.dnsClient = null;
}
this.fetch = fetch;
constructor(dns = null, fetch$$1) {
this.dnsClient = new DnsClient(dns, new DnsOverHttps(fetch$$1, {
baseUrl: 'https://dns.google.com/resolve'
}));
this.fetch = fetch$$1;
this._cache = {};
}
static create(dnsClient, fetch) {
const instance = new EndpointResolver(null, fetch);
static create(dnsClient, fetch$$1) {
const instance = new EndpointResolver(null, fetch$$1);
instance.dnsClient = dnsClient;

@@ -218,3 +212,3 @@ return instance;

async fetchApiDescriptor(domain, port) {
const protocol = domain === 'localhost' ? 'http' : 'https';
const protocol = domain === 'localhost' || domain === 'localhost.' ? 'http' : 'https';
const wellKnown = await this.fetch(`${protocol}://${domain}:${port}/.well-known/bsvalias`, {

@@ -240,6 +234,12 @@ credentials: 'omit'

class VerifiableMessage {
constructor(parts) {
constructor(parts, bsv = null) {
if (bsv === null) {
bsv = require('bsv');
bsv.Message = require('bsv/message');
}
this.bsv = bsv;
const concatenated = Buffer.from(parts.join(''));
const hashed = bsv.crypto.Hash.sha256(concatenated).toString('hex');
this.message = new Message(hashed);
const hashed = this.bsv.crypto.Hash.sha256(concatenated).toString('hex');
this.message = new this.bsv.Message(hashed);
}

@@ -261,3 +261,3 @@

sign(wifPrivateKey) {
return this.message.sign(bsv.PrivateKey.fromWIF(wifPrivateKey));
return this.message.sign(this.bsv.PrivateKey.fromWIF(wifPrivateKey));
}

@@ -337,6 +337,52 @@

class BrowserDns {
constructor(fetch$$1) {
this.doh = new DnsOverHttps(fetch$$1, {
baseUrl: 'https://dns.google.com/resolve'
});
}
async resolveSrv(aDomain, aCallback) {
try {
const response = await this.doh.resolveSrv(aDomain);
if (response.Status === 0) {
const data = response.Answer.map(record => {
const [priority, weight, port, name] = record.data.split(' ');
return {
priority,
weight,
port,
name,
isSecure: response.AD
};
});
aCallback(null, data);
} else {
aCallback(new Error('error during dns query'));
}
} catch (e) {
aCallback(e);
}
}
}
class PaymailClient {
constructor(dns, fetch, clock = null) {
this.resolver = new EndpointResolver(dns, fetch);
this.fetch = fetch;
constructor(dns = null, fetch2 = null, clock = null, bsv = null) {
if (fetch2 === null) {
fetch2 = fetch;
}
if (dns === null) {
dns = new BrowserDns(fetch2);
}
if (bsv === null) {
bsv = require('bsv');
}
this.bsv = bsv;
this.resolver = new EndpointResolver(dns, fetch2);
this.fetch = fetch2;
this.requestBodyFactory = new RequestBodyFactory(clock !== null ? clock : new Clock());

@@ -362,3 +408,3 @@ }

/**
* Uses `Basic Address Reslotion` flow to query for a payment for output for the
* Uses `Basic Address Resolution` flow to query for a payment for output for the
* given paymail address.

@@ -422,3 +468,4 @@ *

* and the parameters Given. The priority order is.
* - Use provided key (and check that belongs to given paymail address)
* - If paymail is not provided, then normal signature verification is performed.
* - Use provided key (and check that belongs to given paymail address).
* - Get a new pubkey for given paymail address using pki.

@@ -434,26 +481,33 @@ * - If there is no way to intereact with the owner of the domain to verify the public key it returns false.

async isValidSignature(message, signature, paymail, pubkey = null) {
async isValidSignature(message, signature, paymail = null, pubkey = null) {
if (paymail == null && pubkey === null) {
throw new Error('Must specify either paymail or pubkey');
}
let senderPublicKey;
if (pubkey && (await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.verifyPublicKeyOwner))) {
if (await this.verifyPubkeyOwner(pubkey, paymail)) {
senderPublicKey = bsv.PublicKey.fromString(pubkey);
if (paymail) {
if (pubkey && (await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.verifyPublicKeyOwner))) {
if (await this.verifyPubkeyOwner(pubkey, paymail)) {
senderPublicKey = this.bsv.PublicKey.fromString(pubkey);
} else {
return false;
}
} else {
return false;
}
} else {
const hasPki = await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.pki);
const hasPki = await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.pki);
if (hasPki) {
const identityKey = await this.getPublicKey(paymail);
senderPublicKey = bsv.PublicKey.fromString(identityKey);
} else {
return false;
if (hasPki) {
const identityKey = await this.getPublicKey(paymail);
senderPublicKey = this.bsv.PublicKey.fromString(identityKey);
} else {
return false;
}
}
}
const senderKeyAddress = bsv.Address.fromPublicKey(senderPublicKey);
const senderKeyAddress = this.bsv.Address.fromPublicKey(senderPublicKey || pubkey);
try {
return message.verify(senderKeyAddress.toString(), signature);
const verified = message.verify(senderKeyAddress.toString(), signature);
return verified;
} catch (err) {

@@ -494,35 +548,2 @@ return false;

class BrowserDns {
constructor(fetch) {
this.doh = new DnsOverHttps(fetch, {
baseUrl: 'https://dns.google.com/resolve'
});
}
async resolveSrv(aDomain, aCallback) {
try {
const response = await this.doh.resolveSrv(aDomain);
if (response.Status === 0) {
const data = response.Answer.map(record => {
const [priority, weight, port, name] = record.data.split(' ');
return {
priority,
weight,
port,
name,
isSecure: response.AD
};
});
aCallback(null, data);
} else {
aCallback(new Error('error during dns query'));
}
} catch (e) {
aCallback(e);
}
}
}
exports.PaymailClient = PaymailClient;

@@ -529,0 +550,0 @@ exports.VerifiableMessage = VerifiableMessage;

@@ -1,4 +0,3 @@

import bsv from 'bsv';
import Message from 'bsv/message';
import moment from 'moment';
import fetch from 'isomorphic-fetch';

@@ -120,4 +119,4 @@ const Capabilities = {

class DnsOverHttps {
constructor(fetch, config) {
this.fetch = fetch;
constructor(fetch$$1, config) {
this.fetch = fetch$$1;
this.config = config;

@@ -139,17 +138,12 @@ }

class EndpointResolver {
constructor(dns = null, fetch) {
if (dns !== null) {
this.dnsClient = new DnsClient(dns, new DnsOverHttps(fetch, {
baseUrl: 'https://dns.google.com/resolve'
}));
} else {
this.dnsClient = null;
}
this.fetch = fetch;
constructor(dns = null, fetch$$1) {
this.dnsClient = new DnsClient(dns, new DnsOverHttps(fetch$$1, {
baseUrl: 'https://dns.google.com/resolve'
}));
this.fetch = fetch$$1;
this._cache = {};
}
static create(dnsClient, fetch) {
const instance = new EndpointResolver(null, fetch);
static create(dnsClient, fetch$$1) {
const instance = new EndpointResolver(null, fetch$$1);
instance.dnsClient = dnsClient;

@@ -211,3 +205,3 @@ return instance;

async fetchApiDescriptor(domain, port) {
const protocol = domain === 'localhost' ? 'http' : 'https';
const protocol = domain === 'localhost' || domain === 'localhost.' ? 'http' : 'https';
const wellKnown = await this.fetch(`${protocol}://${domain}:${port}/.well-known/bsvalias`, {

@@ -233,6 +227,12 @@ credentials: 'omit'

class VerifiableMessage {
constructor(parts) {
constructor(parts, bsv = null) {
if (bsv === null) {
bsv = require('bsv');
bsv.Message = require('bsv/message');
}
this.bsv = bsv;
const concatenated = Buffer.from(parts.join(''));
const hashed = bsv.crypto.Hash.sha256(concatenated).toString('hex');
this.message = new Message(hashed);
const hashed = this.bsv.crypto.Hash.sha256(concatenated).toString('hex');
this.message = new this.bsv.Message(hashed);
}

@@ -254,3 +254,3 @@

sign(wifPrivateKey) {
return this.message.sign(bsv.PrivateKey.fromWIF(wifPrivateKey));
return this.message.sign(this.bsv.PrivateKey.fromWIF(wifPrivateKey));
}

@@ -330,6 +330,52 @@

class BrowserDns {
constructor(fetch$$1) {
this.doh = new DnsOverHttps(fetch$$1, {
baseUrl: 'https://dns.google.com/resolve'
});
}
async resolveSrv(aDomain, aCallback) {
try {
const response = await this.doh.resolveSrv(aDomain);
if (response.Status === 0) {
const data = response.Answer.map(record => {
const [priority, weight, port, name] = record.data.split(' ');
return {
priority,
weight,
port,
name,
isSecure: response.AD
};
});
aCallback(null, data);
} else {
aCallback(new Error('error during dns query'));
}
} catch (e) {
aCallback(e);
}
}
}
class PaymailClient {
constructor(dns, fetch, clock = null) {
this.resolver = new EndpointResolver(dns, fetch);
this.fetch = fetch;
constructor(dns = null, fetch2 = null, clock = null, bsv = null) {
if (fetch2 === null) {
fetch2 = fetch;
}
if (dns === null) {
dns = new BrowserDns(fetch2);
}
if (bsv === null) {
bsv = require('bsv');
}
this.bsv = bsv;
this.resolver = new EndpointResolver(dns, fetch2);
this.fetch = fetch2;
this.requestBodyFactory = new RequestBodyFactory(clock !== null ? clock : new Clock());

@@ -355,3 +401,3 @@ }

/**
* Uses `Basic Address Reslotion` flow to query for a payment for output for the
* Uses `Basic Address Resolution` flow to query for a payment for output for the
* given paymail address.

@@ -415,3 +461,4 @@ *

* and the parameters Given. The priority order is.
* - Use provided key (and check that belongs to given paymail address)
* - If paymail is not provided, then normal signature verification is performed.
* - Use provided key (and check that belongs to given paymail address).
* - Get a new pubkey for given paymail address using pki.

@@ -427,26 +474,33 @@ * - If there is no way to intereact with the owner of the domain to verify the public key it returns false.

async isValidSignature(message, signature, paymail, pubkey = null) {
async isValidSignature(message, signature, paymail = null, pubkey = null) {
if (paymail == null && pubkey === null) {
throw new Error('Must specify either paymail or pubkey');
}
let senderPublicKey;
if (pubkey && (await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.verifyPublicKeyOwner))) {
if (await this.verifyPubkeyOwner(pubkey, paymail)) {
senderPublicKey = bsv.PublicKey.fromString(pubkey);
if (paymail) {
if (pubkey && (await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.verifyPublicKeyOwner))) {
if (await this.verifyPubkeyOwner(pubkey, paymail)) {
senderPublicKey = this.bsv.PublicKey.fromString(pubkey);
} else {
return false;
}
} else {
return false;
}
} else {
const hasPki = await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.pki);
const hasPki = await this.resolver.domainHasCapability(paymail.split('@')[1], Capabilities.pki);
if (hasPki) {
const identityKey = await this.getPublicKey(paymail);
senderPublicKey = bsv.PublicKey.fromString(identityKey);
} else {
return false;
if (hasPki) {
const identityKey = await this.getPublicKey(paymail);
senderPublicKey = this.bsv.PublicKey.fromString(identityKey);
} else {
return false;
}
}
}
const senderKeyAddress = bsv.Address.fromPublicKey(senderPublicKey);
const senderKeyAddress = this.bsv.Address.fromPublicKey(senderPublicKey || pubkey);
try {
return message.verify(senderKeyAddress.toString(), signature);
const verified = message.verify(senderKeyAddress.toString(), signature);
return verified;
} catch (err) {

@@ -487,36 +541,3 @@ return false;

class BrowserDns {
constructor(fetch) {
this.doh = new DnsOverHttps(fetch, {
baseUrl: 'https://dns.google.com/resolve'
});
}
async resolveSrv(aDomain, aCallback) {
try {
const response = await this.doh.resolveSrv(aDomain);
if (response.Status === 0) {
const data = response.Answer.map(record => {
const [priority, weight, port, name] = record.data.split(' ');
return {
priority,
weight,
port,
name,
isSecure: response.AD
};
});
aCallback(null, data);
} else {
aCallback(new Error('error during dns query'));
}
} catch (e) {
aCallback(e);
}
}
}
export { PaymailClient, VerifiableMessage, RequestBodyFactory, Clock, PaymailNotFound, BrowserDns };
//# sourceMappingURL=paymail-client.esm.js.map
{
"name": "@moneybutton/paymail-client",
"version": "0.27.0",
"version": "0.28.0",
"description": "Money Button isomorphic Paymail utilities.",

@@ -69,3 +69,3 @@ "main": "dist/paymail-client.cjs.js",

},
"gitHead": "b43182bbbf4310262214df97934f75d5cae6f559"
"gitHead": "69f62717b5c8d044da009f71833decbb14042eed"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc