{"_attachments":{},"_id":"arkjs","_rev":"330333-61f1e86eccf505988810d597","author":{"name":"FX Thoorens","email":"fx@ark.io"},"description":"JavaScript library for sending Ark transactions from the client or server","dist-tags":{"latest":"0.2.1"},"license":"MIT","maintainers":[{"name":"arkio","email":"support@ark.io"}],"name":"arkjs","readme":"# Ark JS\n\n[![Build Status](https://travis-ci.org/ArkEcosystem/ark-js.svg?branch=master)](https://travis-ci.org/ArkEcosystem/ark-js)\n\nArk JS is a JavaScript library for sending Ark transactions. It's main benefit is that it does not require a locally installed Ark node, and instead utilizes the existing peers on the network. It can be used from the client as a [browserify](http://browserify.org/) compiled module, or on the server as a standard Node.js module.\n\n## Installation\n\n[![npm package](https://nodei.co/npm/arkjs.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/arkjs/)\n\n## Tests\n\n```\nnpm test\n```\n\nTests written using mocha + schedule.js.\n\n***\n\n## Usage\n\nOn the client:\n\n```html\n\n```\n\nOn the server:\n\n```js\nvar ark = require('arkjs');\n```\n\n### Generating a key pair\n\nTo generate a public / private key pair from a given passphrase:\n\n```js\nvar keys = ark.crypto.getKeys(\"passphrase\");\n```\n\nReturning:\n\n```js\n{\n publicKey: \"5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09\",\n privateKey: \"2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a2…44491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09\"\n}\n```\n\n### Generating an address\n\nTo generate a unique Ark address from a given public key:\n\n```js\nvar address = ark.crypto.getAddress(\"5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09\");\n```\n\nReturning:\n\n```\nAGihocTkwDygiFvmg6aG8jThYTic47GzU9\n```\n\n### Creating a transaction\n\nTo create a signed transaction object, which can then be posted onto the network:\n\n```js\nvar amount = 1000 * Math.pow(10, 8); // 100000000000\nvar transaction = ark.transaction.createTransaction(\"AGihocTkwDygiFvmg6aG8jThYTic47GzU9\", amount, null, \"passphrase\", \"secondPassphrase\");\n```\n\nReturning:\n\n```js\n{\n type: 0, // Transaction type. 0 = Normal transaction.\n amount: 100000000000, // The amount to send expressed as an integer value.\n asset: {}, // Transaction asset, dependent on tx type.\n fee: 100000000, // 0.1 ARK expressed as an integer value.\n id: \"500224999259823996\", // Transaction ID.\n recipientId: \"AGihocTkwDygiFvmg6aG8jThYTic47GzU9\", // Recipient ID.\n senderPublicKey: \"56e106a1d4a53dbe22cac52fefd8fc4123cfb4ee482f8f25a4fc72eb459b38a5\", // Sender's public key.\n signSignature: \"03fdd33bed30270b97e77ada44764cc8628f6ad3bbd84718571695262a5a18baa37bd76a62dd25bc21beacd61eaf2c63af0cf34edb0d191d225f4974cd3aa509\", // Sender's second passphrase signature.\n signature: \"9419ca3cf11ed2e3fa4c63bc9a4dc18b5001648e74522bc0f22bda46a188e462da4785e5c71a43cfc0486af08d447b9340ba8b93258c4c7f50798060fff2d709\", // Transaction signature.\n timestamp: 27953413 // Based on UTC time of genesis since epoch.\n}\n```\n\n### Network identification with Nethash\n\nYou need to obtain the nethash in order to be sure you are posting to the right network (testnet, mainnet or others). The nethash is simply the payload hash from the genesisBlock. If no nethash or wrong nethash is provided in the headers, the request will be rejected returning the expected nethash.\n\n```json\n{ \"success\": false, \"message\": \"Request is made on the wrong network\", \"expected\":\"e2f8f69ec6ab4b12550a314bd867c46e64e429961bb427514a3a534c602ff467\", \"received\":\"wrong-nethash\" }\n```\n\nThe nethash for a given network can be obtained at the following API endpoint:\n\n```\n/api/blocks/getNetHash\n```\n\nYou can also get the nethash from a peer this way:\n\nOn the client using [jQuery](https://jquery.com/):\n\n```js\nvar nethash;\n$.ajax({\n url: 'https://api.arknode.net/peer/transactions/',\n data: JSON.stringify({}),\n dataType: 'json',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'os': 'linux3.2.0-4-amd64',\n 'version': '0.3.0',\n 'port': 1,\n 'nethash': \"wrong-nethash\"\n },\n success: function(data) {\n nethash = data.body.expected;\n }\n});\n```\n\nFrom a server using [Request](https://github.com/request/request):\n\n```js\nvar nethash;\nrequest({\n url: 'https://api.arknode.net/peer/transactions',\n json: { },\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'os': 'linux3.2.0-4-amd64',\n 'version': '0.3.0',\n 'port': 1,\n 'nethash': \"wrong-nethash\"\n }\n}, function(error, response, body) {\n nethash = body.expected;\n });\n```\n\n### Posting a transaction\n\nTransaction objects are sent to `/peer/transactions`, using the `POST` method.\n\nExample:\n\n```js\nMethod: POST\nContent-Type: application/json\n\n{\n \"transactions\" : [{\n ...\n }]\n}\n```\n\n#### Sending transaction on the Client\n\nUsing [jQuery](https://jquery.com/):\n\n```js\nvar success = function(data) {\n console.log(data);\n};\n\n$.ajax({\n url: 'https://api.arknode.net/peer/transactions',\n data: JSON.stringify({ transactions: [transaction] }),\n dataType: 'json',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'os': 'linux3.2.0-4-amd64',\n 'version': '0.3.0',\n 'port': 1,\n 'nethash':nethash\n },\n success: success\n});\n```\n\n#### Sending transaction on the Server\n\nUsing [Request](https://github.com/request/request):\n\n\n```js\nvar request = require('request');\n\nvar callback = function(error, response, body) {\n console.log(error || body);\n};\n\nrequest({\n url: 'https://api.arknode.net/peer/transactions',\n json: { transactions: [transaction] },\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'os': 'linux3.2.0-4-amd64',\n 'version': '0.3.0',\n 'port': 1,\n 'nethash': nethash\n }\n}, callback);\n```\n\n#### Peer Response\n\nUpon successfully accepting a transaction, the receiving node will respond with:\n\n```json\n{ \"success\": true, \"result\": \"5318121831703437738\" }\n```\n\nIf the transaction is deemed invalid, or an error is encountered, the receiving node will respond with:\n\n```json\n{ \"success\": false, \"message\": \"Error message\" }\n```\n\n***\n\n### Other transaction types\n\n#### Creating a delegate transaction\n\n```js\nvar transaction = ark.delegate.createDelegate(\"secret\", \"username\", \"secondSecret\");\n```\n\n#### Creating a second signature transaction\n\n```js\nvar transaction = ark.signature.createTransaction(\"secret\", \"secondSecret\");\n```\n\n#### Creating a vote transaction\n\n```js\nvar transaction = ark.vote.createVote(\"secret\", [\"+58199578191950019299181920120128129\"], \"secondSecret\");\n```\n\n***\n\n## Authors\n- FX Thoorens \n- Guillaume Verbal \n- Boris Povod \n- Oliver Beddows \n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Ark
\nCopyright (c) 2016 Lisk
\nCopyright (c) 2015 Crypti\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","time":{"created":"2022-01-27T00:33:50.819Z","modified":"2022-01-27T00:33:50.819Z","0.1.0":"2016-11-11T21:57:11.648Z","0.2.0":"2016-12-13T13:10:27.512Z","0.2.1":"2017-08-03T17:27:35.288Z"},"versions":{"0.1.0":{"name":"arkjs","version":"0.1.0","description":"JavaScript library for sending Ark transactions from the client or server","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/ArkEcosystem/ark-js.git"},"author":{"name":"FX Thoorens","email":"fx@ark.io"},"license":"MIT","dependencies":{"browserify-bignum":"=1.3.0-2","buffer":"=4.9.1","bytebuffer":"=5.0.1","crypto-browserify":"=3.11.0","js-nacl":"github:tonyg/js-nacl#6dc1417","mocha":"=3.1.0"},"devDependencies":{"should":"=11.1.0"},"gitHead":"fbec31468f01406e8c0641ff6639c35ed176d0cf","bugs":{"url":"https://github.com/ArkEcosystem/ark-js/issues"},"homepage":"https://github.com/ArkEcosystem/ark-js#readme","_id":"arkjs@0.1.0","_shasum":"fc387c97145567be2dd2fb90016cc4bb84cef3d6","_from":".","_npmVersion":"2.11.3","_nodeVersion":"4.6.1","_npmUser":{"name":"arkio","email":"support@ark.io"},"dist":{"shasum":"fc387c97145567be2dd2fb90016cc4bb84cef3d6","tarball":"https://registry.npmmirror.com/arkjs/-/arkjs-0.1.0.tgz","size":10519,"integrity":"sha512-RAqRUQhF2W+DFwxoG87CNdW5ZffGD6vAEQOp7zFHumU0KvVDvL96svzc37N9hEVHJYLcUY40UYdkNbbxxp3wYA=="},"maintainers":[{"name":"arkio","email":"support@ark.io"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/arkjs-0.1.0.tgz_1478901431416_0.2391839842312038"},"directories":{},"_cnpmcore_publish_time":"2021-12-20T09:52:37.866Z"},"0.2.0":{"name":"arkjs","version":"0.2.0","description":"JavaScript library for sending Ark transactions from the client or server","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/ArkEcosystem/ark-js.git"},"author":{"name":"FX Thoorens","email":"fx@ark.io"},"license":"MIT","dependencies":{"browserify-bignum":"=1.3.0-2","bs58check":"^1.1.1","buffer":"=4.9.1","bytebuffer":"=5.0.1","crypto-browserify":"=3.11.0","js-nacl":"github:tonyg/js-nacl#6dc1417","mocha":"=3.1.0"},"devDependencies":{"should":"=11.1.0"},"gitHead":"0fd136b3c417fbe91df8fd985cbe7add03b30c04","bugs":{"url":"https://github.com/ArkEcosystem/ark-js/issues"},"homepage":"https://github.com/ArkEcosystem/ark-js#readme","_id":"arkjs@0.2.0","_shasum":"eda863cc671ac1692d6952cb0bcefd2e3da43885","_from":".","_npmVersion":"2.11.3","_nodeVersion":"4.6.1","_npmUser":{"name":"arkio","email":"support@ark.io"},"dist":{"shasum":"eda863cc671ac1692d6952cb0bcefd2e3da43885","tarball":"https://registry.npmmirror.com/arkjs/-/arkjs-0.2.0.tgz","size":10730,"integrity":"sha512-NQMgyxHRu3ZGRXURxGo5s4mVNzKTm8s83NgT+b9Q2kjJ8fq5t23GtC8SvHER0JzJaUUETNRj6RS3RKnj3mou7A=="},"maintainers":[{"name":"arkio","email":"support@ark.io"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/arkjs-0.2.0.tgz_1481634625686_0.07868998823687434"},"directories":{},"_cnpmcore_publish_time":"2021-12-20T09:52:38.774Z"},"0.2.1":{"name":"arkjs","version":"0.2.1","description":"JavaScript library for sending Ark transactions from the client or server","main":"index.js","scripts":{"lint":"eslint .","test":"mocha test/ark.js test/*/*"},"repository":{"type":"git","url":"git+https://github.com/ArkEcosystem/ark-js.git"},"author":{"name":"FX Thoorens","email":"fx@ark.io"},"license":"MIT","dependencies":{"bigi":"^1.4.2","bip66":"^1.1.4","browserify-bignum":"=1.3.0-2","bs58check":"^1.1.1","buffer":"=4.9.1","bytebuffer":"=5.0.1","create-hmac":"^1.1.4","crypto-browserify":"=3.11.0","ecdsa":"^0.7.0","ecurve":"^1.0.5","js-nacl":"github:tonyg/js-nacl#6dc1417","mocha":"=3.1.0","randombytes":"^2.0.3","secp256k1":"^3.2.2","typeforce":"^1.10.3","wif":"^2.0.4"},"devDependencies":{"eslint":"^4.2.0","proxyquire":"^1.7.10","should":"=11.1.0","sinon":"^1.17.7"},"gitHead":"0147906a6e978bdf782eb76cd2209ad115c2414f","bugs":{"url":"https://github.com/ArkEcosystem/ark-js/issues"},"homepage":"https://github.com/ArkEcosystem/ark-js#readme","_id":"arkjs@0.2.1","_shasum":"613bc85db9c237514be0d819ce68ac2fc0268d51","_from":".","_npmVersion":"3.6.0","_nodeVersion":"6.9.5","_npmUser":{"name":"arkio","email":"fx.thoorens@ark.io"},"dist":{"shasum":"613bc85db9c237514be0d819ce68ac2fc0268d51","tarball":"https://registry.npmmirror.com/arkjs/-/arkjs-0.2.1.tgz","size":226758,"integrity":"sha512-TIjoq9vN49tcfUGU2qGEV9MDzM8x5EqWQPYgQdiSkrfNcmyb8it4Bta25IZvIbWegUj+/thcsDIn66dT4zU6Dg=="},"maintainers":[{"name":"arkio","email":"support@ark.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/arkjs-0.2.1.tgz_1501781253914_0.23827112186700106"},"directories":{},"_cnpmcore_publish_time":"2021-12-20T09:52:40.232Z"}},"_source_registry_name":"default"}