Comparing version
42
index.js
@@ -8,2 +8,4 @@ const CryptoJS = require('crypto-js') | ||
const fetch = require('node-fetch') | ||
const bip39 = require('bip39') | ||
const bip32 = require('bip32') | ||
@@ -167,2 +169,13 @@ let avalon = { | ||
}, | ||
generateMnemonic: () => { | ||
return bip39.generateMnemonic() | ||
}, | ||
mnemonicToKeyPair: (mnemonic) => { | ||
const seed = bip39.mnemonicToSeedSync(mnemonic) | ||
const bip32key = bip32.fromSeed(seed) | ||
return { | ||
pub: bs58.encode(bip32key.publicKey), | ||
priv: bs58.encode(bip32key.privateKey) | ||
} | ||
}, | ||
privToPub: (priv) => { | ||
@@ -193,2 +206,26 @@ return bs58.encode( | ||
}, | ||
signMultisig: (privKeys = [], sender, tx) => { | ||
if (typeof tx !== 'object') | ||
try { | ||
tx = JSON.parse(tx) | ||
} catch(e) { | ||
console.log('invalid transaction') | ||
return | ||
} | ||
if (!tx.sender) | ||
tx.sender = sender | ||
if (!tx.ts) | ||
tx.ts = new Date().getTime() | ||
if (!tx.hash) | ||
tx.hash = CryptoJS.SHA256(JSON.stringify(tx)).toString() | ||
if (!tx.signature || !Array.isArray(tx.signature)) | ||
tx.signature = [] | ||
for (let k in privKeys) { | ||
let sign = secp256k1.ecdsaSign(Buffer.from(tx.hash, 'hex'), bs58.decode(privKeys[k])) | ||
tx.signature.push([bs58.encode(sign.signature),sign.recid]) | ||
} | ||
return tx | ||
}, | ||
sendTransaction: (tx, cb) => { | ||
@@ -390,3 +427,6 @@ // sends a transaction to a node | ||
ENABLE_NODE: 18, | ||
TIPPED_VOTE: 19 | ||
TIPPED_VOTE: 19, | ||
NEW_WEIGHTED_KEY: 20, | ||
SET_SIG_THRESHOLD: 21, | ||
SET_PASSWORD_WEIGHT: 22 | ||
} | ||
@@ -393,0 +433,0 @@ } |
{ | ||
"name": "javalon", | ||
"version": "1.0.33", | ||
"version": "1.0.34", | ||
"description": "javascript api for the avalon blockchain", | ||
@@ -25,2 +25,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"bip32": "^2.0.6", | ||
"bip39": "^3.0.4", | ||
"bs58": "^4.0.1", | ||
@@ -27,0 +29,0 @@ "crypto-js": "^3.1.9-1", |
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
807289
61.25%7
16.67%498
9.21%4
-20%9
28.57%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added