Comparing version 1.8.0 to 1.8.1
@@ -0,1 +1,7 @@ | ||
# 1.8.1 | ||
## Added | ||
- Added `toString` and print methods to Transaction ([#243](https://github.com/algorand/js-algorand-sdk/pull/243)). | ||
- Added functions to create Transactions from objects ([#246](https://github.com/algorand/js-algorand-sdk/pull/246)). | ||
## Fixed | ||
- Fixed issues using the library with webpack, including switching dependencies from `keccak` to `js-sha3` ([#247](https://github.com/algorand/js-algorand-sdk/pull/247)). | ||
# 1.8.0 | ||
@@ -2,0 +8,0 @@ ## Added |
{ | ||
"name": "algosdk", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "algosdk is Algorand's official javascript SDK", | ||
@@ -15,6 +15,7 @@ "main": "index.js", | ||
"algo-msgpack-with-bigint": "^2.1.0", | ||
"buffer": "^6.0.2", | ||
"hi-base32": "^0.5.0", | ||
"js-sha256": "^0.9.0", | ||
"js-sha3": "^0.8.0", | ||
"js-sha512": "^0.8.0", | ||
"keccak": "^3.0.1", | ||
"superagent": "^6.1.0", | ||
@@ -24,11 +25,4 @@ "tweetnacl": "^1.0.3" | ||
"devDependencies": { | ||
"@babel/core": "^7.6.0", | ||
"@babel/preset-env": "^7.6.0", | ||
"assert": "^2.0.0", | ||
"babel-core": "^6.26.3", | ||
"babel-minify": "^0.5.1", | ||
"babelify": "^10.0.0", | ||
"browserify": "^16.5.0", | ||
"chromedriver": "^85.0.1", | ||
"common-shakeify": "^0.5.4", | ||
"chromedriver": "^87.0.0", | ||
"coveralls": "^3.0.6", | ||
@@ -42,4 +36,4 @@ "cucumber": "^5.1.0", | ||
"selenium-webdriver": "^4.0.0-alpha.7", | ||
"uglify-js": "^3.6.0", | ||
"watchify": "^3.11.1" | ||
"webpack": "^5.5.1", | ||
"webpack-cli": "^4.2.0" | ||
}, | ||
@@ -50,9 +44,6 @@ "files": [ | ||
], | ||
"browser": { | ||
"assert": "assert/" | ||
}, | ||
"scripts": { | ||
"test": "node tests/mocha.js", | ||
"prepare-browser-tests": "npm run build && mkdir -p tests/cucumber/browser/build && cp dist/algosdk.min.js tests/cucumber/browser/build/algosdk.min.js && browserify tests/cucumber/browser/test.js -o tests/cucumber/browser/build/test.js", | ||
"build": "browserify src/main.js -s algosdk | minify --simplify --mangle.keepClassName --deadcode.keepFnArgs --comments false --outFile dist/algosdk.min.js" | ||
"prepare-browser-tests": "npm run build && mkdir -p tests/cucumber/browser/build && cp dist/algosdk.min.* tests/cucumber/browser/build/ && webpack --config tests/cucumber/browser/webpack.config.js", | ||
"build": "webpack --config webpack.config.js" | ||
}, | ||
@@ -59,0 +50,0 @@ "author": "Algorand, llc", |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require("buffer"); | ||
const address = require("./encoding/address"); | ||
@@ -2,0 +3,0 @@ const encoding = require("./encoding/encoding"); |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const client = require('./client'); | ||
@@ -2,0 +3,0 @@ |
@@ -1,2 +0,3 @@ | ||
var request = require("superagent"); | ||
const { Buffer } = require("buffer"); | ||
const request = require("superagent"); | ||
@@ -3,0 +4,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const client = require('./client'); | ||
@@ -2,0 +3,0 @@ const txn = require("../transaction"); |
@@ -0,1 +1,3 @@ | ||
const { Buffer } = require('buffer'); | ||
class Compile { | ||
@@ -2,0 +4,0 @@ constructor(c, source) { |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const encoding = require('../../../encoding/encoding'); | ||
@@ -2,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
const assert = require('assert'); | ||
const { Buffer } = require('buffer'); | ||
@@ -10,6 +10,10 @@ class SendRawTransaction { | ||
if (Array.isArray(stx_or_stxs)) { | ||
assert(stx_or_stxs.every(isByteArray)); | ||
if (!stx_or_stxs.every(isByteArray)) { | ||
throw new TypeError("Array elements must be byte arrays"); | ||
} | ||
forPosting = Array.prototype.concat(...stx_or_stxs.map(arr => Array.from(arr))); | ||
} else { | ||
assert(isByteArray(forPosting)); | ||
if (!isByteArray(forPosting)) { | ||
throw new TypeError("Argument must be byte array"); | ||
} | ||
} | ||
@@ -16,0 +20,0 @@ this.txnBytesToPost = forPosting; |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require("buffer"); | ||
const txnBuilder = require('./transaction'); | ||
@@ -2,0 +3,0 @@ const nacl = require('./nacl/naclWrappers'); |
@@ -1,2 +0,2 @@ | ||
const assert = require('assert'); | ||
const { Buffer } = require('buffer'); | ||
const nacl = require('./nacl/naclWrappers'); | ||
@@ -18,5 +18,6 @@ const address = require('./encoding/address'); | ||
assert(logic.checkProgram(program, args)); | ||
if (!logic.checkProgram(program, args)) { | ||
throw new Error("Invalid program"); | ||
} | ||
if (args) { | ||
assert(Array.isArray(args)) | ||
function checkType(arg) { | ||
@@ -26,3 +27,5 @@ let theType = typeof arg; | ||
} | ||
assert(args.every(checkType)) | ||
if (!Array.isArray(args) || !args.every(checkType)) { | ||
throw new TypeError("Invalid arguments"); | ||
} | ||
} | ||
@@ -29,0 +32,0 @@ |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const address = require('../encoding/address'); | ||
@@ -2,0 +3,0 @@ const encoding = require('../encoding/encoding'); |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const logic = require('../logic/logic'); | ||
@@ -6,3 +7,3 @@ const logicSig = require('../logicsig'); | ||
const sha256 = require('js-sha256'); | ||
const createKeccakHash = require('keccak'); | ||
const keccak256 = require('js-sha3').keccak256; | ||
@@ -93,3 +94,3 @@ class HTLC { | ||
let hashFunction = contract[contract.length - 15]; | ||
if (hashFunction == 1) { | ||
if (hashFunction === 1) { | ||
let hash = sha256.create(); | ||
@@ -101,4 +102,6 @@ hash.update(preImageBytes); | ||
} | ||
} else if (hashFunction == 2) { | ||
let actualHashedOutput = createKeccakHash('keccak256').update(preImageBytes).digest(); | ||
} else if (hashFunction === 2) { | ||
let hash = keccak256.create(); | ||
hash.update(preImageBytes); | ||
let actualHashedOutput = Buffer.from(hash.hex(), 'hex'); | ||
if (!actualHashedOutput.equals(expectedHashedOutput)) { | ||
@@ -105,0 +108,0 @@ throw new Error("keccak256 hash of preimage did not match stored contract hash") |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const address = require('../encoding/address'); | ||
@@ -2,0 +3,0 @@ const makeTxn = require('../makeTxn'); |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const address = require("../encoding/address"); | ||
@@ -2,0 +3,0 @@ const makeTxn = require('../makeTxn'); |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const address = require('../encoding/address'); | ||
@@ -2,0 +3,0 @@ const makeTxn = require('../makeTxn'); |
@@ -1,2 +0,2 @@ | ||
const assert = require('assert'); | ||
const { Buffer } = require('buffer'); | ||
const address = require("../encoding/address"); | ||
@@ -22,4 +22,5 @@ | ||
function inject(orig, offsets, values, valueTypes) { | ||
assert.strictEqual(offsets.length, values.length); | ||
assert.strictEqual(offsets.length, valueTypes.length); | ||
if (offsets.length !== values.length || offsets.length !== valueTypes.length) { | ||
throw new Error("Lengths do not match"); | ||
} | ||
@@ -26,0 +27,0 @@ let res = orig; |
@@ -1,2 +0,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const nacl = require('./nacl/naclWrappers'); | ||
@@ -256,2 +256,9 @@ const address = require('./encoding/address'); | ||
makeAssetTransferTxnWithSuggestedParams: makeTxn.makeAssetTransferTxnWithSuggestedParams, | ||
makePaymentTxnWithSuggestedParamsFromObject: makeTxn.makePaymentTxnWithSuggestedParamsFromObject, | ||
makeKeyRegistrationTxnWithSuggestedParamsFromObject: makeTxn.makeKeyRegistrationTxnWithSuggestedParamsFromObject, | ||
makeAssetCreateTxnWithSuggestedParamsFromObject: makeTxn.makeAssetCreateTxnWithSuggestedParamsFromObject, | ||
makeAssetConfigTxnWithSuggestedParamsFromObject: makeTxn.makeAssetConfigTxnWithSuggestedParamsFromObject, | ||
makeAssetDestroyTxnWithSuggestedParamsFromObject: makeTxn.makeAssetDestroyTxnWithSuggestedParamsFromObject, | ||
makeAssetFreezeTxnWithSuggestedParamsFromObject: makeTxn.makeAssetFreezeTxnWithSuggestedParamsFromObject, | ||
makeAssetTransferTxnWithSuggestedParamsFromObject: makeTxn.makeAssetTransferTxnWithSuggestedParamsFromObject, | ||
OnApplicationComplete: makeTxn.OnApplicationComplete, | ||
@@ -265,2 +272,9 @@ makeApplicationCreateTxn: makeTxn.makeApplicationCreateTxn, | ||
makeApplicationNoOpTxn: makeTxn.makeApplicationNoOpTxn, | ||
makeApplicationCreateTxnFromObject: makeTxn.makeApplicationCreateTxnFromObject, | ||
makeApplicationUpdateTxnFromObject: makeTxn.makeApplicationUpdateTxnFromObject, | ||
makeApplicationDeleteTxnFromObject: makeTxn.makeApplicationDeleteTxnFromObject, | ||
makeApplicationOptInTxnFromObject: makeTxn.makeApplicationOptInTxnFromObject, | ||
makeApplicationCloseOutTxnFromObject: makeTxn.makeApplicationCloseOutTxnFromObject, | ||
makeApplicationClearStateTxnFromObject: makeTxn.makeApplicationClearStateTxnFromObject, | ||
makeApplicationNoOpTxnFromObject: makeTxn.makeApplicationNoOpTxnFromObject, | ||
encodeUnsignedTransaction: txnBuilder.encodeUnsignedTransaction, | ||
@@ -267,0 +281,0 @@ decodeUnsignedTransaction: txnBuilder.decodeUnsignedTransaction, |
@@ -64,2 +64,8 @@ const txnBuilder = require('./transaction'); | ||
// helper for above makePaymentTxnWithSuggestedParams, instead accepting an arguments object | ||
function makePaymentTxnWithSuggestedParamsFromObject(o) { | ||
return makePaymentTxnWithSuggestedParams(o.from, o.to, o.amount, o.closeRemainderTo, | ||
o.note, o.suggestedParams, o.rekeyTo); | ||
} | ||
/** | ||
@@ -137,2 +143,8 @@ * makeKeyRegistrationTxn takes key registration arguments and returns a Transaction object for | ||
// helper for above makeKeyRegistrationTxnWithSuggestedParams, instead accepting an arguments object | ||
function makeKeyRegistrationTxnWithSuggestedParamsFromObject(o) { | ||
return makeKeyRegistrationTxnWithSuggestedParams(o.from, o.note, o.voteKey, o.selectionKey, o.voteFirst, o.voteLast, | ||
o.voteKeyDilution, o.suggestedParams, o.rekeyTo); | ||
} | ||
/** makeAssetCreateTxn takes asset creation arguments and returns a Transaction object | ||
@@ -228,2 +240,9 @@ * for creating that asset | ||
// helper for above makeAssetCreateTxnWithSuggestedParams, instead accepting an arguments object | ||
function makeAssetCreateTxnWithSuggestedParamsFromObject(o) { | ||
return makeAssetCreateTxnWithSuggestedParams(o.from, o.note, o.total, o.decimals, o.defaultFrozen, o.manager, | ||
o.reserve, o.freeze, o.clawback, o.unitName, o.assetName, o.assetURL, o.assetMetadataHash, o.suggestedParams, | ||
o.rekeyTo) ; | ||
} | ||
/** makeAssetConfigTxn can be issued by the asset manager to change the manager, reserve, freeze, or clawback | ||
@@ -306,2 +325,8 @@ * you must respecify existing addresses to keep them the same; leaving a field blank is the same as turning | ||
// helper for above makeAssetConfigTxnWithSuggestedParams, instead accepting an arguments object | ||
function makeAssetConfigTxnWithSuggestedParamsFromObject(o) { | ||
return makeAssetConfigTxnWithSuggestedParams(o.from, o.note, o.assetIndex, | ||
o.manager, o.reserve, o.freeze, o.clawback, o.suggestedParams, o.strictEmptyAddressChecking, o.rekeyTo) ; | ||
} | ||
/** makeAssetDestroyTxn will allow the asset's manager to remove this asset from the ledger, so long | ||
@@ -363,2 +388,7 @@ * as all outstanding assets are held by the creator. | ||
// helper for above makeAssetDestroyTxnWithSuggestedParams, instead accepting an arguments object | ||
function makeAssetDestroyTxnWithSuggestedParamsFromObject(o) { | ||
return makeAssetDestroyTxnWithSuggestedParams(o.from, o.note, o.assetIndex, o.suggestedParams, o.rekeyTo); | ||
} | ||
/** makeAssetFreezeTxn will allow the asset's freeze manager to freeze or un-freeze an account, | ||
@@ -427,2 +457,7 @@ * blocking or allowing asset transfers to and from the targeted account. | ||
// helper for above makeAssetFreezeTxnWithSuggestedParams, instead accepting an arguments object | ||
function makeAssetFreezeTxnWithSuggestedParamsFromObject(o) { | ||
return makeAssetFreezeTxnWithSuggestedParams(o.from, o.note, o.assetIndex, o.freezeTarget, | ||
o.freezeState, o.suggestedParams, o.rekeyTo); | ||
} | ||
@@ -503,2 +538,8 @@ /** makeAssetTransferTxn allows for the creation of an asset transfer transaction. | ||
// helper for above makeAssetTransferTxnWithSuggestedParams, instead accepting an arguments object | ||
function makeAssetTransferTxnWithSuggestedParamsFromObject(o) { | ||
return makeAssetTransferTxnWithSuggestedParams(o.from, o.to, o.closeRemainderTo, o.revocationTarget, | ||
o.amount, o.note, o.assetIndex, o.suggestedParams, o.rekeyTo); | ||
} | ||
/* | ||
@@ -584,2 +625,8 @@ * Enums for application transactions on-transaction-complete behavior | ||
// helper for above makeApplicationCreateTxn, instead accepting an arguments object | ||
function makeApplicationCreateTxnFromObject(o) { | ||
return makeApplicationCreateTxn(o.from, o.suggestedParams, o.onComplete, o.approvalProgram, o.clearProgram, | ||
o.numLocalInts, o.numLocalByteSlices, o.numGlobalInts, o.numGlobalByteSlices, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo); | ||
} | ||
@@ -631,2 +678,8 @@ /** | ||
// helper for above makeApplicationUpdateTxn, instead accepting an arguments object | ||
function makeApplicationUpdateTxnFromObject(o) { | ||
return makeApplicationUpdateTxn(o.from, o.suggestedParams, o.appIndex, o.approvalProgram, o.clearProgram, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo); | ||
} | ||
/** | ||
@@ -673,2 +726,8 @@ * Make a transaction that deletes an application | ||
// helper for above makeApplicationDeleteTxn, instead accepting an arguments object | ||
function makeApplicationDeleteTxnFromObject(o) { | ||
return makeApplicationDeleteTxn(o.from, o.suggestedParams, o.appIndex, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo); | ||
} | ||
/** | ||
@@ -715,2 +774,8 @@ * Make a transaction that opts in to use an application | ||
// helper for above makeApplicationOptInTxn, instead accepting an argument object | ||
function makeApplicationOptInTxnFromObject(o) { | ||
return makeApplicationOptInTxn(o.from, o.suggestedParams, o.appIndex, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo); | ||
} | ||
/** | ||
@@ -757,2 +822,9 @@ * Make a transaction that closes out a user's state in an application | ||
// helper for above makeApplicationCloseOutTxn, instead accepting an argument object | ||
function makeApplicationCloseOutTxnFromObject(o) { | ||
return makeApplicationCloseOutTxn(o.from, o.suggestedParams, o.appIndex, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo); | ||
} | ||
/** | ||
@@ -799,2 +871,9 @@ * Make a transaction that clears a user's state in an application | ||
// helper for above makeApplicationClearStateTxn, instead accepting an argument object | ||
function makeApplicationClearStateTxnFromObject(o) { | ||
return makeApplicationClearStateTxn(o.from, o.suggestedParams, o.appIndex, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo) | ||
} | ||
/** | ||
@@ -841,25 +920,45 @@ * Make a transaction that just calls an application, doing nothing on completion | ||
// helper for above makeApplicationNoOpTxn, instead accepting an argument object | ||
function makeApplicationNoOpTxnFromObject(o) { | ||
return makeApplicationNoOpTxn(o.from, o.suggestedParams, o.appIndex, | ||
o.appArgs, o.accounts, o.foreignApps, o.foreignAssets, o.note, o.lease, o.rekeyTo); | ||
} | ||
module.exports = { | ||
makePaymentTxn, | ||
makePaymentTxnWithSuggestedParams, | ||
makePaymentTxnWithSuggestedParamsFromObject, | ||
makeKeyRegistrationTxn, | ||
makeKeyRegistrationTxnWithSuggestedParams, | ||
makeKeyRegistrationTxnWithSuggestedParamsFromObject, | ||
makeAssetCreateTxn, | ||
makeAssetCreateTxnWithSuggestedParams, | ||
makeAssetCreateTxnWithSuggestedParamsFromObject, | ||
makeAssetConfigTxn, | ||
makeAssetConfigTxnWithSuggestedParams, | ||
makeAssetConfigTxnWithSuggestedParamsFromObject, | ||
makeAssetDestroyTxn, | ||
makeAssetDestroyTxnWithSuggestedParams, | ||
makeAssetDestroyTxnWithSuggestedParamsFromObject, | ||
makeAssetFreezeTxn, | ||
makeAssetFreezeTxnWithSuggestedParams, | ||
makeAssetFreezeTxnWithSuggestedParamsFromObject, | ||
makeAssetTransferTxn, | ||
makeAssetTransferTxnWithSuggestedParams, | ||
makeAssetTransferTxnWithSuggestedParamsFromObject, | ||
OnApplicationComplete, | ||
makeApplicationCreateTxn, | ||
makeApplicationCreateTxnFromObject, | ||
makeApplicationUpdateTxn, | ||
makeApplicationUpdateTxnFromObject, | ||
makeApplicationDeleteTxn, | ||
makeApplicationDeleteTxnFromObject, | ||
makeApplicationOptInTxn, | ||
makeApplicationOptInTxnFromObject, | ||
makeApplicationCloseOutTxn, | ||
makeApplicationCloseOutTxnFromObject, | ||
makeApplicationClearStateTxn, | ||
makeApplicationClearStateTxnFromObject, | ||
makeApplicationNoOpTxn, | ||
makeApplicationNoOpTxnFromObject, | ||
}; |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require('buffer'); | ||
const nacl = require('./nacl/naclWrappers'); | ||
@@ -2,0 +3,0 @@ const address = require('./encoding/address'); |
@@ -0,1 +1,2 @@ | ||
const { Buffer } = require("buffer"); | ||
const address = require("./encoding/address"); | ||
@@ -594,2 +595,32 @@ const encoding = require("./encoding/encoding"); | ||
} | ||
// build display dict for prettyPrint and toString | ||
_getDictForDisplay() { | ||
let forPrinting = { | ||
...this | ||
}; | ||
forPrinting.tag = forPrinting.tag.toString(); | ||
forPrinting.from = address.encodeAddress(forPrinting.from.publicKey); | ||
if (forPrinting.to !== undefined) forPrinting.to = address.encodeAddress(forPrinting.to.publicKey); | ||
// things that need fixing: | ||
if (forPrinting.closeRemainderTo !== undefined) forPrinting.closeRemainderTo = address.encodeAddress(forPrinting.closeRemainderTo.publicKey); | ||
if (forPrinting.assetManager !== undefined) forPrinting.assetManager = address.encodeAddress(forPrinting.assetManager.publicKey); | ||
if (forPrinting.assetReserve !== undefined) forPrinting.assetReserve = address.encodeAddress(forPrinting.assetReserve.publicKey); | ||
if (forPrinting.assetFreeze !== undefined) forPrinting.assetFreeze = address.encodeAddress(forPrinting.assetFreeze.publicKey); | ||
if (forPrinting.assetClawback !== undefined) forPrinting.assetClawback = address.encodeAddress(forPrinting.assetClawback.publicKey); | ||
if (forPrinting.assetRevocationTarget !== undefined) forPrinting.assetRevocationTarget = address.encodeAddress(forPrinting.assetRevocationTarget.publicKey); | ||
if (forPrinting.reKeyTo !== undefined) forPrinting.reKeyTo = address.encodeAddress(forPrinting.reKeyTo.publicKey); | ||
forPrinting.genesisHash = forPrinting.genesisHash.toString('base64'); | ||
return forPrinting; | ||
} | ||
// pretty print the transaction to console | ||
prettyPrint() { | ||
console.log(this._getDictForDisplay()); | ||
} | ||
// get string representation | ||
toString() { | ||
return JSON.stringify(this._getDictForDisplay()); | ||
} | ||
} | ||
@@ -596,0 +627,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
321556
12
7965
8
1
+ Addedbuffer@^6.0.2
+ Addedjs-sha3@^0.8.0
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedjs-sha3@0.8.0(transitive)
- Removedkeccak@^3.0.1
- Removedkeccak@3.0.4(transitive)
- Removednode-addon-api@2.0.2(transitive)
- Removednode-gyp-build@4.8.3(transitive)