Comparing version 1.0.0 to 1.0.1
112
index.js
@@ -1,1 +0,111 @@ | ||
'' | ||
const ecc = require('eosjs-ecc') | ||
const json = require('eosjs-json') | ||
const Fcbuffer = require('fcbuffer') | ||
const createHash = require('create-hash') | ||
const {Signature} = ecc | ||
/** | ||
config.network = Testnet() must be supplied until Mainnet is available.. | ||
@arg {object} [config.network = Mainnet()] | ||
*/ | ||
module.exports = (config = {}) => { | ||
const network = config.network //|| Mainnet() | ||
fcbuffer = Fcbuffer(json.schema.operations) | ||
if(!fcbuffer.errors.length === 0) { | ||
throw new Error(fcbuffer.errors) | ||
} | ||
/** | ||
@args {object} args - { | ||
messages: [{}, ..], | ||
sign: [wif_string] | ||
[expireInSeconds = 60], | ||
[broadcast = true] | ||
} | ||
*/ | ||
function transaction(args, callback) { | ||
if(typeof args !== 'object') { | ||
throw new TypeError('Expecting args object') | ||
} | ||
if(typeof callback !== 'function') { | ||
throw new TypeError('Expecting callback function as last argument') | ||
} | ||
if(!Array.isArray(args.messages)) { | ||
throw new TypeError('Expecting args.messages array') | ||
} | ||
if(!Array.isArray(args.sign)) { | ||
throw new TypeError('Expecting args.sign array') | ||
} | ||
const argsDefaults = {expireInSeconds: 60, broadcast: true} | ||
args = Object.assign(argsDefaults, args) | ||
network.createTransaction(args.expireInSeconds, checkError(callback, tx => { | ||
tx.messages = args.messages | ||
tx.permissions = args.permissions | ||
const {Transaction} = fcbuffer.structs | ||
const buf = Fcbuffer.toBuffer(Transaction, tx) | ||
for(const key of args.sign) { | ||
tx.signatures.push(sign(buf, key)) | ||
} | ||
if(!args.broadcast) { | ||
callback(null, tx) | ||
} else { | ||
network.pushTransaction(tx, error => { | ||
if(!error) { | ||
callback(null, tx) | ||
} else { | ||
callback({ | ||
error, | ||
digest: buf.toString('hex') | ||
}) | ||
} | ||
}) | ||
} | ||
})) | ||
} | ||
// Non "modules" exports should avoid custom objects as much as possible (for | ||
// example: wif string instead of a ecc.PrivateKey object) | ||
return { | ||
transaction, | ||
modules: { | ||
ecc, | ||
json, | ||
Fcbuffer, | ||
} | ||
} | ||
} | ||
/** | ||
The transaction function signs already. This is for signing other types | ||
of data. | ||
@arg {string|Buffer} data - Never sign anything without 100% validation or | ||
unless prefixing with a string constant. | ||
@arg {string|ecc.PrivateKey} key - string must be a valid WIF format | ||
@return {string} hex signature | ||
*/ | ||
function sign(data, key) { | ||
const privateKey = key.d ? key : ecc.PrivateKey.fromWif(key) | ||
const h = createHash('sha256').update(data).digest(); | ||
const sig = Signature.signBufferSha256(h, privateKey) | ||
return sig.toHex() | ||
} | ||
const checkError = (parentErr, parrentRes) => (error, result) => { | ||
if (error) { | ||
parentErr(error) | ||
} else { | ||
parrentRes(result) | ||
} | ||
} |
{ | ||
"name": "eosjs", | ||
"version": "1.0.0", | ||
"description": "", | ||
"version": "1.0.1", | ||
"description": "General purpose library for the EOS blockchain.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha index.test.js", | ||
"coverage": "istanbul cover _mocha -- -R spec index.test.js", | ||
"coveralls": "npm run coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/eosjs/eosjs.git" | ||
}, | ||
"keywords": [ | ||
"EOS", | ||
"Blockchain" | ||
], | ||
"author": "", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/eosjs/eosjs/issues" | ||
}, | ||
"homepage": "https://github.com/eosjs/eosjs#readme", | ||
"devDependencies": { | ||
"coveralls": "^2.13.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.4.2" | ||
}, | ||
"dependencies": { | ||
"create-hash": "^1.1.3", | ||
"eosjs-api": "^1.0.2", | ||
"eosjs-ecc": "^1.0.3", | ||
"eosjs-json": "^1.0.2", | ||
"fcbuffer": "^1.0.1" | ||
} | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
39434
6
94
1
0
58
0
5
3
+ Addedcreate-hash@^1.1.3
+ Addedeosjs-api@^1.0.2
+ Addedeosjs-ecc@^1.0.3
+ Addedeosjs-json@^1.0.2
+ Addedfcbuffer@^1.0.1
+ Addedbase-x@3.0.10(transitive)
+ Addedbigi@1.4.2(transitive)
+ Addedbn.js@4.12.1(transitive)
+ Addedbrowserify-aes@1.2.0(transitive)
+ Addedbs58@4.0.1(transitive)
+ Addedbuffer-xor@1.0.3(transitive)
+ Addedbytebuffer@5.0.1(transitive)
+ Addedcamel-case@3.0.0(transitive)
+ Addedcipher-base@1.0.6(transitive)
+ Addedcreate-hash@1.2.0(transitive)
+ Addedcreate-hmac@1.1.7(transitive)
+ Addedecurve@1.0.6(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedeosjs-api@1.2.11(transitive)
+ Addedeosjs-ecc@1.6.3(transitive)
+ Addedeosjs-json@1.4.1(transitive)
+ Addedevp_bytestokey@1.0.3(transitive)
+ Addedfcbuffer@1.2.4(transitive)
+ Addedhash-base@3.1.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addedlong@3.2.0(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedmd5.js@1.3.5(transitive)
+ Addedno-case@2.3.2(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedripemd160@2.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsha.js@2.4.11(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)