{"id":15789929,"url":"https://github.com/gettocat/friday-primitives","last_synced_at":"2025-10-04T10:54:32.909Z","repository":{"id":94927219,"uuid":"254202947","full_name":"gettocat/friday-primitives","owner":"gettocat","description":"Primitive objects (transaction, block) for friday blockchain framework","archived":false,"fork":false,"pushed_at":"2020-05-16T20:48:46.000Z","size":87,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-05T22:04:13.680Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gettocat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-08T21:18:56.000Z","updated_at":"2020-05-16T20:48:48.000Z","dependencies_parsed_at":"2023-04-19T09:17:14.412Z","dependency_job_id":null,"html_url":"https://github.com/gettocat/friday-primitives","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gettocat/friday-primitives","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gettocat%2Ffriday-primitives","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gettocat%2Ffriday-primitives/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gettocat%2Ffriday-primitives/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gettocat%2Ffriday-primitives/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gettocat","download_url":"https://codeload.github.com/gettocat/friday-primitives/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gettocat%2Ffriday-primitives/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278302564,"owners_count":25964520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-04T22:04:13.572Z","updated_at":"2025-10-04T10:54:32.879Z","avatar_url":"https://github.com/gettocat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Serializable primitives\n\nSerializable primitives for friday blockchain framework. This module define and helps redefine primitives:\n- block\n- tx\n\nCan convert tx/block data into hex and json (and back). \n\n### App\n\nApp instance have next methods:\n`definePrimitive(cls)` - redefine abstract primitive class\n`defineTx(cls)` - redefine tx class\n`defineBlock(cls)` - redefine block class, must be invoked after tx redefine\n\nand getters:\n`app.Transaction` - tx class\n`app.Block` - block class\n\n## Config\n\n```javascript\n{\n    validationalert: true,\n    genesisMode: false, // genesisMode help make first block\n    blockversion: 1,//supperted block version\n    txversion: 1//supported transaction verion\n}\n```\n \n# validationalert\nIf true - throw exception on each validation error, false - only add errors to log.\n\n# genesisMode\nUsed for create genesis block with empty prev and 0 height.\n\n# versions\nIf transaction/block version is bigger then supported - tx/block fire event unsupportedversion with params `listenerCallback(supportedversion, blockOrTxversion) {...}` \n\n## Primitive\n\nPrimitive is abstract class, extends with EventEmitter. Some methods in primitive muse be redefined:\n```javascript\nthrowError(message, code); //create exception\ngetAddressByPublicKey(publicKeyHex); //generate address from public key\ngetPublicKeyByPrivateKey(privateKeyHex);//get public key by private key\ngetBlockValue(fee, height);//return block value for current height, based on emission\nisValidAddress(address);//check validity of address\naddressToHexValue(address);//return hex value(pubkeyhash) from address string\nhexValueToAddress(hex);//return address from pubkeyhash\ncreateHash(binaryOrHex);//hashing method\nsign(privateKeyBinary, hash);//sign data with EC\nverify(pubkey, sign, hash2sign);//verify {sign} for message {hash2sign} with {pubkey} EC\ngetOut(hash, index);//get previous output (proof) for input {hash:index}\ngetMerkleRoot(list);//generate merkle root for list\ngetMemPool();//return mempool list (json tx list)\ngetTop();//return {height: 'int-current-height', 'id':'current-top-block-hash'}\ngetCurrentTime(); //get current timestamp, by default: parseInt(Date.now()/1000);\n```\n\nThis methods must be redefined with your code, example in __tests/crypto.js\n\n## Tx\n\n# hex format\n\nHex buffers creates from json output with apply bitowl protocol https://www.npmjs.com/package/bitowl for more details you can read documentation here: https://github.com/gettocat/bitowl\n\n# json format\n\n```javascript\n{\n    v: 'int-supported-tx-version',\n    s: //signature data\n        [\n            [\n                'signdata of first input',\n                'pubkey of first input'\n            ],\n            //...\n        ],\n    in: //input data\n        [\n            {\n                hash:\n                    'prevout hash',\n                index: 'int-prevout index'\n            }\n            //...\n        ],\n    out://output tx info\n        [\n            {\n                address: 'address-destination',\n                amount: 'amount'\n            },\n            //...\n        ]\n}\n```\n\ncoinbase tx:\n```javascript\n{\n    v: 'int-supported-tx-version',\n    s: //signature data\n        [\n            [\n                'signdata of first input',\n                'pubkey of first input'\n            ],\n            //...\n        ],\n    out://output tx info\n        [\n            {\n                address: 'address-destination',\n                amount: 'amount'\n            },\n            //...\n        ],\n    cb: '001133',//coinbase bytes or hex\n    //next two params used for ddPoS from package, readmore: https://github.com/gettocat/consensusjs \n    m: 'merkle root of validator pubkeys list',\n    k: 'pubkey of block-creator'    \n}\n```\n\n# methods\n\n```javascript\n//setters: \nsetVersion(ver)\nsetInputs(arr)\nsetOutputs(arr)\n\n//for coinbase: \nsetMerkle(merkle)\nsetPublicKey(key)\nsetCoinbase(coinbaseData)\n\n//serialization: \ntoJSON()\nfromJSON(jsondata)\ntoHex()\ntoBuffer()\nfromHex(hexOrBufferdata)\n\n//additional:\nsetKeystore(keystore) // keystore is array of privatekeyhex, using for sign tx\nsetData(data) // additional data of tx (look https://github.com/gettocat/orwelldb) for more details\n\n//getters:\ngetId()\ngetHash()\ngetFee()\ngetSize()\nisCoinbase()\ngetInputs()\ngetOutputs()\n\nisValid(context) // execute validator rules on current tx\ngetLastErrorCodes() // validation errors\nsignTransaction(private_keys) // sign tx with private_keys, if private_keys is not defined - try use keystore params \nverifyTransaction() // verify signs of tx (return true if ok, and throw exception if not okay)\n```\n\n# static methods:\n```javascript\nTX.createFromJSON(jsondata, private_keys) // create from json and sign with private_keys\nTX.createFromRaw(inputs, outputs, keys, version, ds, coinbaseData) \nTX.createCoinbase(fee, coinbaseBytes, privateKey, merkle, height) // create coinbase tx\nTX.fromJSON(jsondata)\nTX.fromHEX(hexOrBuffer)\nTX.validate(tx, context)\n```\n\n# additional\nTX.VALIDATOR - validator class, have method:\n`TX.VALIDATOR.addRule(rulename, callback)` - creates validation rule with name and callback `callback(validator_instance)`, in callback you can return true if data is valid, false - if invalid, and throw exception if need more information in logs. `getLastErrorCodes()` returns log information after validation. Also, events `beforevalidation` and `aftervalidation` exists. `aftervalidation` event returns: `listener_callback(result, loglist, errors_list)`\n\n\nMethod `send` must be reimplemented in child tx.\n\n## Block\n\n# hex format\n\nHex buffers creates from json output with apply bitowl protocol https://www.npmjs.com/package/bitowl for more details you can read documentation here: https://github.com/gettocat/bitowl\n\n# json format\n\n```javascript\n{\n    v: 'current-block-version-int',\n    p: 'previous-block-hash',\n    m: 'merkle-root-of-txhashes list',\n    t: 'block timestamp',\n    b: 'additional info',\n    n: 'additional info 2',\n    tx: [txjson1,txjson2,...] //array with tx\n}\n```\n\n# methods\n```javascript\n//add tx to block:\naddTxFromHEX(hex)\naddTxFromJSON(json)\naddTx(tx)\naddTxList(HEXorJSONorTXObjectArr) // add tx from any types of serialization\n\n//serialization:\ntoHex()\ntoBuffer()\nfromHex(hex)\ntoJSON()\nfromJSON(json)\n\n//validation:\ngetLastErrorCodes()\nisValid(context)\n\n//getters:\ngetId()\ngetVersion()\ngetBits()\ngetPrevId()\ngetTime()\ngetNonce()\ngetHash()\n\n//txinfo:\ngetFee()\ngetSize()\n\n//header info:\ngetHeader()\ngetHeaderBytes()\ngetHeaderHex()\n```\n\n# static methods\n```javascript\nBLOCK.fromJSON(jsondata)\nBLOCK.fromHEX(hexdata)\nBLOCK.validate(block, context)\nBLOCK.generateNewBlockTemplate(timestamp, coinbaseBytes, keystore, currentValidatorsMerkle)  // creates new block template (json) with coinbase. keystore format is {public:'hex', private: 'hex'}\nBLOCK.createNewBlock = (coinbaseBytes, keystore, currentValidatorsMerkle) // creates new block with coinbase and mempool info\n```\n\n# additional\nBLOCK.VALIDATOR - validator class, have method:\n`BLOCK.VALIDATOR.addRule(rulename, callback)` - creates validation rule with name and callback `callback(validator_instance)`, in callback you can return true if data is valid, false - if invalid, and throw exception if need more information in logs. `getLastErrorCodes()` returns log information after validation. Also, events `beforevalidation` and `aftervalidation` exists. `aftervalidation` event returns: `listener_callback(result, loglist, errors_list)`\n\n\nMethod `send` must be reimplemented in child block.\n\n\n## Example\n\nLook ./example.js","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgettocat%2Ffriday-primitives","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgettocat%2Ffriday-primitives","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgettocat%2Ffriday-primitives/lists"}