New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.5.0 to 1.0.0

111

index.js

@@ -10,2 +10,4 @@ const EmojiList = require('./emoji_names.json');

let BITBOX = require('bitbox-sdk').BITBOX;
let bitbox = new BITBOX();
const genesisBlock = 563720 - 100;

@@ -555,18 +557,2 @@

/**
* broadcast cashaccount registration with your own node
*
* @param {string} username
* @param {string} bchAddress
* @param {string} slpAddress
* @returns {string} txid - registration transaction hash
* @memberof CashAccounts
*/
async trustlessRegistration(username, bchAddress, slpAddress) {
let txString = await this.generateRawTx(username, bchAddress, slpAddress);
let hex = await bchNode.signRawTransaction(txString);
let txid = await bchNode.sendRawTransaction(hex.hex);
return txid;
}
/**
* find cash accounts associated with an address

@@ -597,95 +583,16 @@ *

/**
* creates the raw transaction to be broadcast later
* turn string username into hex'ed string for registration
*
* @param {string} username
* @param {string} bchAddress
* @param {string} slpAddress
* @returns {string} raw transaction of registration
* @returns string
* @memberof CashAccounts
*/
async generateRawTx(username, bchAddress, slpAddress) {
let registrationObj = this.createRegistrationObj(
username,
bchAddress,
slpAddress
);
let script = this.buildScript(registrationObj);
let unspent = await this.bchNode.listUnspent(1);
if (unspent === undefined || unspent.length === 0) {
unspent = await this.bchNode.listUnspent(0);
}
if (unspent === undefined || unspent.length === 0) {
return { status: 'no UTXOs available' };
}
const changeAddr = await this.bchNode.getRawChangeAddress();
let tx = new bch.Transaction().from(unspent).feePerKb(1002);
tx.addOutput(new bch.Transaction.Output({ script: script, satoshis: 0 }));
tx.change(changeAddr);
return tx.toString();
encodeUsername(username) {
const buffer = Buffer.from(username, 'utf8');
let encoded = bitbox.Script.encodeNullDataOutput(buffer);
const encodedUsername = bitbox.Script.toASM(encoded).split('OP_RETURN ')[1];
return encodedUsername;
}
/**
* creates the raw op return script
*
* @param {string} username
* @param {string} bchAddress
* @param {string} slpAddress
* @returns {string} registration script
* @memberof CashAccounts
*/
async createRawOpReturn(username, bchAddress, slpAddress) {
let registrationObj = this.createRegistrationObj(
username,
bchAddress,
slpAddress
);
let script = this.buildScript(registrationObj);
return script.toString();
}
/**
*
build opreturn script
*
* @param {oject} registrationObj
* @returns
* @memberof CashAccounts
*/
buildScript(registrationObj) {
const { username, bchHash, slpHash } = registrationObj;
let bch_map = {
p2pkh: '01',
p2sh: '02',
p2pc: '03',
p2sk: '04'
};
let token_map = {
p2pkh: '81',
p2sh: '82',
p2pc: '83',
p2sk: '84'
};
const s = new bch.Script();
s.add(bch.Opcode.OP_RETURN);
s.add(Buffer.from('01010101', 'hex'));
s.add(Buffer.from(username, 'utf8'));
for (let [key, value] of Object.entries(bchHash)) {
s.add(Buffer.from(bch_map[key] + value, 'hex'));
}
if (slpHash !== undefined) {
for (let [key, value] of Object.entries(slpHash)) {
s.add(Buffer.from(token_map[key] + value, 'hex'));
}
}
return s;
}
/**
* get hash from address for registration protocol

@@ -692,0 +599,0 @@ *

3

package.json
{
"name": "cashaccounts",
"version": "0.5.0",
"version": "1.0.0",
"description": "decentralized identity system for bitcoin cash by Jonathan Silverblood",

@@ -15,2 +15,3 @@ "main": "index.js",

"bchaddrjs-slp": "https://github.com/simpleledger/bchaddrjs.git",
"bitbox-sdk": "^8.4.2",
"bitcoin-cash-rpc": "^0.4.2",

@@ -17,0 +18,0 @@ "bitcoincashjs-lib": "https://github.com/Bitcoin-com/bitcoincashjs-lib.git",

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