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

cashaccounts

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cashaccounts - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

91

index.js

@@ -30,19 +30,15 @@ const EmojiList = require('./emoji_names.json');

/**
* get the address for user's handle
*
* @param {string} handle - ie: jonathan#100
* @returns {obj}
* @memberof CashAccount
*/
async getAddressByCashAccount(handle) {
buildSearchUrl(handle, lookupMethod) {
const split = this.splitHandle(handle);
const { username, number } = split;
const { username, number, collision } = split;
const csplit = number.split('.');
const url = `${this.server}/account/${csplit[0]}/${username}/${
csplit.length === 2 ? csplit[1] : ''
const url = `${this.server}/${lookupMethod}/${csplit[0]}/${username}/${
collision ? collision : ''
}`;
return url;
}
async performTrustedSearch(url) {
const data = await axios

@@ -54,3 +50,3 @@ .get(url)

.catch(err => {
console.log('error in getAddressByCashAccount', err.response);
console.log('error in performTrustedSearch', ' url', url, err.response);
});

@@ -97,9 +93,15 @@

*
* @param {*} transaction transaction hex
* @param {string} handle - ie: jonathan#100
* @returns {object}
* @memberof CashAccounts
*/
async trustlessLookup(transaction) {
const tx = await this.bchNode.decodeRawTransaction(transaction);
async trustlessLookup(handle) {
const url = await this.buildSearchUrl(handle, 'lookup');
const data = await this.performTrustedSearch(url);
const { results } = data;
// first result
const tx = await this.bchNode.decodeRawTransaction(results[0].transaction);
const raw = await this.bchNode.getRawTransaction(tx.txid, 1);

@@ -137,3 +139,3 @@

*
* @param {string} handle - ie: jonathan#100
* @param {string} handle - ie: jonathan#100, or with collision ectest#1106.9871360083
* @returns {object}

@@ -143,15 +145,14 @@ * @memberof CashAccounts

async trustedLookup(handle) {
const split = this.splitHandle(handle);
const { username, number } = split;
const url = await this.buildSearchUrl(handle, 'account');
let data = await this.TrustedBitdbLookup(username, number);
const data = await axios
.get(url)
.then(x => {
return x.data;
})
.catch(err => {
console.log('error in getAddressByCashAccount', err.response);
});
if (!data.c.length && !data.u.length) {
return {};
}
// take first confirmed
data = data.c[0];
const info = await this.parseBitdbObject(data);
return info;
return data;
}

@@ -162,3 +163,3 @@

*
* @param {*} handle
* @param {string} handle
* @memberof CashAccounts

@@ -168,3 +169,3 @@ */

const split = this.splitHandle(handle);
const { username, number } = split;
const { username, number, collision } = split;

@@ -247,3 +248,3 @@ const results = await this.TrustedBitdbLookup(username, number);

*
* @param {string} handle - ie: jonathan#100
* @param {string} handle - ie: jonathan#100, or with collision ectest#1106.9871360083
* @returns {object} payment information

@@ -265,3 +266,3 @@ * @memberof CashAccounts

*
* @param {string} handle - ie: jonathan#100
* @param {string} handle - ie: jonathan#100, or with collision ectest#1106.9871360083
* @returns {object} payment type and address

@@ -278,3 +279,3 @@ * @memberof CashAccounts

*
* @param {string} handle - ie: jonathan#100
* @param {string} handle - ie: jonathan#100, or with collision ectest#1106.9871360083
* @returns {object} token address

@@ -426,8 +427,10 @@ * @memberof CashAccounts

*
* @param {string} username
* @param {string} number
* @param {string} handle - ie: jonathan#100, or with collision ectest#1106.9871360083
* @returns {object} - array of confirmed and unconfirmed transactions
* @memberof CashAccounts
*/
async TrustedBitdbLookup(username, number) {
async trustedBitdbLookup(handle) {
const split = this.splitHandle(handle);
const { username, number, collision } = split;
number = parseInt(number);

@@ -757,3 +760,2 @@ const height = genesisBlock + number;

const cashAccountRegex = /^([a-zA-Z0-9_]+)(#([0-9]+)(([0-9]+))).([0-9]+)?$/i;
return cashAccountRegex.test(string);

@@ -765,11 +767,20 @@ }

*
* @param {string} handle - ie: jonathan#100
* @returns {object} {username: 'jonathan', number: '100'}
* @param {string} handle - ie: jonathan#100, or with collision ectest#1106.9871360083
* @returns {object} {username: 'jonathan', number: '100', collision: false}
* @memberof CashAccounts
*/
splitHandle(handle) {
handle = handle.split('#');
let collision;
if (handle.includes('.')) {
collision = handle.split('.');
handle = collision[0].split('#');
} else {
handle = handle.split('#');
}
return {
username: handle[0],
number: handle[1]
number: handle[1],
collision: collision !== undefined && collision[1]
};

@@ -776,0 +787,0 @@ }

{
"name": "cashaccounts",
"version": "0.2.2",
"version": "0.3.0",
"description": "decentralized identity system for bitcoin cash by Jonathan Silverblood",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,3 +8,3 @@ # Cash Accounts javascript library

`bitcoincash:qp3wjpa3tjlj042z2wv7hahsldgwhwy0rq9sywjpyy`. They look like
`Jonathan#100`; The usernamed followed by the number (based on block height
`Jonathan#100`; The username followed by the number (based on block height
registration).

@@ -48,6 +48,15 @@

#### cashAccounts.trustedRegistration(username, bchAddress, slpAddress)
#### trustedRegistration(username, bchAddress, slpAddress)
#### cashAccounts.trustedLookup(handle) // jonathan#100
returns
```
{
txid: "0e436928cb4370be2f46258ace2c70e81e4cc67d88cb75805c…",
hex: "0100000001cd90df45fba8dc4940eb72eb349a67ea63f9e451…"
}
```
#### trustedLookup(handle) // jonathan#100
returns

@@ -81,4 +90,10 @@

#### cashAccounts.TrustedBitdbLookup(handle) // jonathan#100
handles can include the collision hash noted with a `.`.
For example;
trustedLookup(ectest#1106.9871360083)
#### trustedBitdbLookup(handle) // jonathan#100
returns

@@ -108,10 +123,67 @@

### Trustless methods
#### accountLookupViaTxid(txid)
WIP
returns
#### cashAccounts.trustlessRegistration(username, bchAddress, slpAddress)
```
{
"blockhash" : "00000000000000000331f42d43f6a460e1bb634bd2e16a1fad9dbdf80beae100",
"blockheight" : 581590,
"data" : "01249a7741ea9f5106a9d25f156a348ee554688606",
"name" : "account1",
"opreturn" : "OP_RETURN 01010101 6163636f756e7431 01249a7741ea9f5106a9d25f156a348ee554688606 01dd4913aaef64d4e523fcb0034c41f85947590dc0",
"transactionhash" : "ca53a8c0f4af966a36ad9e5022c0d53f132caf4bbbafc4e0ebbc471bb4e261e5"
}
```
### Trustless methods
requires your own node via passing in the `nodeCredentials` object.
#### trustlessLookup(handle) // jonathan#100
returns
```
{
"identifier": "Jonathan#100;",
"information": {
"emoji": "☯",
"name": "Jonathan",
"number": 100,
"collision": {
"hash": "5876958390",
"count": 0,
"length": 0
},
"payment": [
{
"address": "bitcoincash:qr4aadjrpu73d2wxwkxkcrt6gqxgu6a7usxfm96fst",
"type": "Key Hash"
}
]
}
}
```
#### trustlessRegistration(username, bchAddress, slpAddress)
### Utils
#### splitHandle(handle)
returns an object with the username, number, and collision
```
{
username: 'jonathan',
number: '100',
collision: false
}
```
#### isCashAccount(handle)
returns boolean
## References

@@ -118,0 +190,0 @@

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