{"_id":"@decentrawise/graphenejs","name":"@decentrawise/graphenejs","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@decentrawise/graphenejs","version":"1.0.0","description":"Pure JavaScript Graphene Protocol library for node.js and browsers.","browser":{"ws":false,"crypto":false},"scripts":{"test":"cross-env BABEL_ENV=test mocha --require @babel/register --recursive","test:chain":"cross-env BABEL_ENV=test mocha --require @babel/register ./test/chain --recursive --watch","test:trxbuilder":"cross-env BABEL_ENV=test mocha --require @babel/register ./test/chain/TransactionBuilder.js --watch","test:ecc":"cross-env BABEL_ENV=test mocha --require @babel/register ./test/ecc --recursive --watch","test:serializer":"cross-env BABEL_ENV=test mocha --require @babel/register ./test/serializer --recursive","test:watch":"yarn test -- --watch","clean":"rm -rf ./dist ./build ./es","prebuild":"yarn run clean","build":"cross-env BABEL_ENV=cjs babel lib -d dist","webpack":"webpack --config webpack.config.js","build-es":"cross-env BABEL_ENV=es babel lib -d es","postbuild":"yarn run browserify && yarn run build-es && yarn run webpack","build:watch":"babel lib -d dist --watch","browserify":"cross-env NODE_ENV=production browserify --full-paths false dist/browser.js --standalone graphene_js -o build/graphenejs.js -d","postbrowserify":"cross-env NODE_ENV=production minify build/graphenejs.js --mangle --outFile build/graphenejs.min.js","precommit":"npx pretty-quick --staged","docs":"npx esdoc","example:asset":"babel-node examples/updateAsset","example:transfer":"babel-node examples/transfer","example:feed":"babel-node examples/publishFeed","example:co-update":"babel-node examples/callOrderUpdate","example:chainStore":"babel-node examples/chainStore","example:privKey":"babel-node examples/privKey","example:createHtlc":"babel-node examples/createHtlc","example:redeemHtlc":"babel-node examples/redeemHtlc","example:anything":"babel-node examples/anything","example:broadcast":"babel-node examples/broadcast","prepare":"yarn run build"},"repository":{"type":"git","url":"git+https://github.com/decentrawise/graphenejs.git"},"license":"MIT","bugs":{"url":"https://github.com/decentrawise/graphenejs/issues"},"engines":{"node":">= 16.13.0"},"main":"./dist/index.js","jsnext:main":"./es/index.js","dependencies":{"@decentrawise/graphenejs-ws":"^1.0.0","bigi":"^1.4.2","bs58":"^4.0.1","bytebuffer":"^5.0.1","create-hash":"^1.2.0","create-hmac":"^1.1.7","crypto-js":"^4.1.1","deep-equal":"^2.0.5","ecurve":"^1.0.6","event-emitter":"^0.3.5","immutable":"^4.0.0","safe-buffer":"^5.2.1","secure-random":"^1.1.2"},"devDependencies":{"@babel/cli":"^7.16.7","@babel/core":"^7.16.7","@babel/node":"^7.16.7","@babel/preset-env":"^7.16.7","@babel/register":"^7.16.7","assert":"^2.0.0","babel-minify":"^0.5.1","babel-plugin-add-module-exports":"^1.0.4","babel-preset-minify":"^0.5.1","browserify":"^17.0.0","cross-env":"^7.0.3","esdoc":"^1.1.0","esdoc-standard-plugin":"^1.0.0","mocha":"^9.1.3","prettier":"^2.5.1","pretty-quick":"^3.1.3","rimraf":"^3.0.2","stream-browserify":"^3.0.0","webpack":"^5.76.0","webpack-cli":"^4.9.1"},"licenseText":"Copyright (c) Graphene Protocol contributors\n\nMIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@decentrawise/graphenejs@1.0.0","dist":{"shasum":"9beb33905c5b794eb681bb567f42b1edab8bf828","integrity":"sha512-m+TGUrnrTWM0Dp8M58CuQGlVzq0EOwWnaH4KTtfY49x0D4aCHYeBys/z7wcyw50a6YVtZKjOu4E8R39IEJhiig==","tarball":"https://registry.npmjs.org/@decentrawise/graphenejs/-/graphenejs-1.0.0.tgz","fileCount":315,"unpackedSize":62183031,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF+EUSN5ssNrH6F0tYUr2f9m8SBA/GIUjFKuazWqwrnjAiEA3vrVnCQcMrlxxo/v0scHfGG387y3YS2t25JWX9BpGeU="}]},"_npmUser":{"name":"prc","email":"prcolaco@gmail.com"},"directories":{},"maintainers":[{"name":"prc","email":"prcolaco@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphenejs_1.0.0_1709305636230_0.5627061199525156"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-01T15:07:16.128Z","1.0.0":"2024-03-01T15:07:16.532Z","modified":"2024-03-01T15:07:17.083Z"},"maintainers":[{"name":"prc","email":"prcolaco@gmail.com"}],"description":"Pure JavaScript Graphene Protocol library for node.js and browsers.","repository":{"type":"git","url":"git+https://github.com/decentrawise/graphenejs.git"},"bugs":{"url":"https://github.com/decentrawise/graphenejs/issues"},"license":"MIT","readme":"# GrapheneJS (graphenejs)\n\nPure JavaScript Graphene Protocol library for node.js and browsers. Can be used to construct, sign and broadcast transactions in JavaScript, and to easily obtain data from the blockchain via public APIs or local nodes.\n\n## Setup\n\nThis library can be obtained through npm:\n\n```\nnpm install --save @decentrawise/graphenejs\n```\n\nor\n\n```\nyarn add @decentrawise/graphenejs\n```\n\n## Usage\n\nSeveral examples are available in the /examples folder, and the tests in /test also show how to use the library.\n\nBrowser bundles are provided, see below. A variable `graphene_js` will be available in `window` object.\n\nThree sub-libraries are included: `ECC`, `Chain` and `Serializer`. Generally only the `ECC` and `Chain` libraries need to be used directly.\n\n### Chain\n\nThis library provides utility functions to handle blockchain state as well as a login class that can be used for simple login functionality using a specific key seed.\n\n#### Login\n\nThe login class uses the following format for keys:\n\n```\nkeySeed = accountName + role + password\n```\n\nUsing this seed, private keys are generated for each of the default roles `active, owner, memo`, or as specified. A minimum password length of 12 characters is enforced, but an even longer password is recommended. Three methods are provided:\n\n```\ngenerateKeys(account, password, [roles])\ncheckKeys(account, password, auths)\nsignTransaction(tr)\n```\n\nThe auths object should contain the auth arrays from the account object. An example is this:\n\n```\n{\n    active: [\n        [\"GPH5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL\", 1]\n    ]\n}\n```\n\nIf checkKeys is successful, you can use signTransaction to sign a TransactionBuilder transaction using the private keys for that account.\n\n#### State container\n\nThe Chain library contains a complete state container called the ChainStore. The ChainStore will automatically configure the `set_subscribe_callback` and handle any incoming state changes appropriately. It uses Immutable.js for storing the state, so all objects are returned as immutable objects. It has its own `subscribe` method that can be used to register a callback that will be called whenever a state change happens.\n\nThe ChainStore has several useful methods to retrieve, among other things, objects, assets and accounts using either object ids or asset/account names. These methods are synchronous and will return `undefined` to indicate fetching in progress, and `null` to indicate that the object does not exist.\n\n```\nimport {Apis} from \"@decentrawise/graphenejs-ws\";\nvar {ChainStore} = require(\"@decentrawise/graphenejs\");\n\nApis.instance(\"ws://127.0.0.1:8090\", true).init_promise.then((res) => {\n    console.log(\"connected to chain id:\", res[0].chain_id;\n    ChainStore.init().then(() => {\n        ChainStore.subscribe(updateState);\n    });\n});\n\nlet dynamicGlobal = null;\nfunction updateState(object) {\n    dynamicGlobal = ChainStore.getObject(\"2.1.0\");\n    console.log(\"ChainStore object update\\n\", dynamicGlobal ? dynamicGlobal.toJS() : dynamicGlobal);\n}\n```\n\n### ECC\n\nThe ECC library contains all the crypto functions for private and public keys as well as transaction creation/signing and encryption.\n\n#### Private keys\n\nAs a quick example, here's how to generate a new private key from a seed (a brainkey for example):\n\n```\nvar {PrivateKey, key} = require(\"@decentrawise/graphenejs\");\n\nlet seed = \"THIS IS A TERRIBLE BRAINKEY SEED WORD SEQUENCE\";\nlet pkey = PrivateKey.fromSeed( key.normalize_brainKey(seed) );\n\nconsole.log(\"\\nPrivate key:\", pkey.toWif());\nconsole.log(\"Public key :\", pkey.toPublicKey().toString(), \"\\n\");\n```\n\n#### Transactions\n\nTODO transaction signing example\n\n## Tests\n\nThe tests show several use cases, to run, simply type `yarn test`. The tests require a local Graphene node to be running, as well as an active internet connection.\n\n## Documentation (esdoc)\n\nYou can access the full documentation at: [https://decentrawise.github.io/graphenejs](https://decentrawise.github.io/graphenejs)\n\nIf you want to update the documentation, for example before releasing a new version, just run `yarn docs`.\n\n## Binaries / Browserified bundles\n\nPlease have a [look here](https://github.com/decentrawise/graphenejs/releases) to find your desired release.\n\nIf you want to build the binaries yourself you can clone this repository and run `yarn`. It will create:\n\n-   Browserified version `build/graphenejs.js`\n-   Browserified and minified (babel) version `build/graphenejs.min.js`\n-   CommonJS version using webpack `build/graphenejs.cjs`\n","readmeFilename":"README.md"}