cashaccounts
Advanced tools
Comparing version 0.2.1 to 0.2.2
55
index.js
@@ -93,2 +93,41 @@ const EmojiList = require('./emoji_names.json'); | ||
/** | ||
* get metadata on cashaccount from your node | ||
* | ||
* @param {*} transaction transaction hex | ||
* @returns {object} | ||
* @memberof CashAccounts | ||
*/ | ||
async trustlessLookup(transaction) { | ||
const tx = await this.bchNode.decodeRawTransaction(transaction); | ||
const raw = await this.bchNode.getRawTransaction(tx.txid, 1); | ||
const { blockhash, txid } = raw; | ||
const block = await this.bchNode.getBlock(blockhash); | ||
const { height } = block; | ||
const opreturn = tx.vout.find(x => x.scriptPubKey.type === 'nulldata') | ||
.scriptPubKey.asm; | ||
let number = this.calculateNumber(height); | ||
const emoji = this.calculateEmoji(txid, blockhash); | ||
const payment = await this.parsePaymentInfo(opreturn); | ||
const collision = this.calculateCollisionHash(blockhash, txid); | ||
const name = await this.parseName(opreturn); | ||
const object = { | ||
identifier: `${name}#${number}`, | ||
information: { | ||
emoji: emoji, | ||
name: name, | ||
number: number, | ||
collision: { hash: collision, count: 0, length: 0 }, | ||
payment: payment | ||
} | ||
}; | ||
return object; | ||
} | ||
/** | ||
* get metadata on cashaccount | ||
@@ -165,3 +204,3 @@ * | ||
/** | ||
* Parse cashaccount OPRETURN | ||
* Parse cashaccount payment info | ||
* | ||
@@ -187,2 +226,16 @@ * @param {string} opreturn | ||
/** | ||
* Parse cashaccount name | ||
* | ||
* @param {string} opreturn | ||
* @returns {object} get name from registration opreturn | ||
* @memberof CashAccount | ||
*/ | ||
async parseName(opreturn) { | ||
const split = opreturn.split(' '); | ||
const name = Buffer.from(split[2], 'hex'); | ||
let string = name.toString('ascii'); | ||
return string; | ||
} | ||
/** | ||
* get address(es) by handle | ||
@@ -189,0 +242,0 @@ * |
{ | ||
"name": "cashaccounts", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "decentralized identity system for bitcoin cash by Jonathan Silverblood", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
25765
810