{"id":15671367,"url":"https://github.com/hexagon/decene","last_synced_at":"2025-05-06T20:25:23.667Z","repository":{"id":40749685,"uuid":"210448536","full_name":"Hexagon/decene","owner":"Hexagon","description":"Framework for decentralised and distributed network applications.","archived":false,"fork":false,"pushed_at":"2023-01-06T17:48:11.000Z","size":676,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T15:19:06.970Z","etag":null,"topics":["decentralised","distributed","dlt","framework","network","p2p"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Hexagon.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}},"created_at":"2019-09-23T20:42:09.000Z","updated_at":"2021-09-22T16:51:26.000Z","dependencies_parsed_at":"2023-02-06T07:30:39.369Z","dependency_job_id":null,"html_url":"https://github.com/Hexagon/decene","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexagon%2Fdecene","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexagon%2Fdecene/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexagon%2Fdecene/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hexagon%2Fdecene/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hexagon","download_url":"https://codeload.github.com/Hexagon/decene/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252762966,"owners_count":21800407,"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","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":["decentralised","distributed","dlt","framework","network","p2p"],"created_at":"2024-10-03T15:02:03.981Z","updated_at":"2025-05-06T20:25:23.638Z","avatar_url":"https://github.com/Hexagon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Work in progress\r\n\r\nFor real.\r\n\r\n# Usage\r\n\r\n## Short version\r\n\r\nSee repository [hexagon/decene-examples](https://github.com/hexagon/decene-examples)```\r\n\r\n## A little longer version\r\n\r\nFairly complete and minimal example of how to use decent... Untested code!\r\n\r\n```javascript\r\nconst \r\n    { network, encryption } = require(\"decene\"),\r\n    fs = require('fs'); // fs is used to read/write registry cache to disk\r\n\r\n// Settings\r\nlet idLocation = '~/.decene.id';\r\nlet cacheLocation = \"~/.decene.registy\";\r\n\r\n// Try to load identity from cache, or create a new identity\r\nlet id = encryption.loadIdentity(idLocation);\r\nif (!id) {\r\n    // Create\r\n    id = encryption.newIdentity(idLocation);\r\n    if (!id) {\r\n        console.log(\"Could not read or create identity, bailing out.\");\r\n        process.exit(0);\r\n    } else {\r\n        console.log(\"New identity generated and stored at \" + cacheLocation);\r\n    }\r\n} \r\n\r\n// Try to load registry cache\r\nlet cache;\r\ntry {\r\n    cache = JSON.parse(fs.readFileSync(cacheLocation, 'utf8'));\r\n} catch (err) {\r\n    console.error('Warning: Could not load cache.');\r\n}\r\n\r\n// Set up network client, listen at 0.0.0.0:47474, use my.decent.spawn.address.fake:47474 as \"spawn\" in case no local cache is available\r\nvar d = new network(id,\"0.0.0.0\",\"47474\",\"my.decent.spawn.address.fake:47474\",cache);\r\n\r\n// Handle network events\r\nd.events.on('state:changed',(prevState,curState) =\u003e {\r\n    console.log(\"State changed: \"+prevState+\" -\u003e \"+curState);\r\n});\r\nd.events.on('server:error', (err) =\u003e        console.error(\"Server Error:\"+err));\r\nd.events.on('socket:error', (err) =\u003e        console.error(\"Socket Error:\"+err));\r\nd.events.on('error', (err) =\u003e               console.error(\"Generic Error:\"+err));\r\n\r\nd.events.on('server:listening', (port) =\u003e   console.log(\"Listening at \" + port));\r\nd.events.on('ip:changed',(ip) =\u003e            console.log(\"Public ip verified: \"+ip));\r\n\r\n// A message is received (could be core, or application specific message)\r\nd.events.on('message:received', (message, socket) =\u003e {\r\n    if (message.type) {\r\n        let hasPayload = message.payload ? \"yes\" : \"no\";\r\n        console.log(message.type + ' \u003e payload : ' + hasPayload);\r\n    }\r\n});\r\n\r\n// A unhandled message is received this is an invalid, or application specific message\r\nd.events.on('message:unhandled', (message, socket) =\u003e {\r\n    if (message.type === \"mycustommessage\") {\r\n        let hasPayload = message.payload ? \"yes\" : \"no\";\r\n        console.log(\"Custom message received \u003e payload : \" + hasPayload);\r\n    }\r\n});\r\n\r\n// Handle registry events\r\nd.events.on('node:discover', (node) =\u003e {    console.log('Discover: ' + node.uuid );  });\r\n\r\n// Handle registry disk cache\r\nd.events.on('registry:batch', (node) =\u003e {\r\n    fs.writeFile(cacheLocation, JSON.stringify(d.reg.serialize()), err =\u003e {\r\n      if (err) {\r\n        gui.log.log(\"Registry cache flush failed: \" + err);\r\n        return;\r\n      } else {\r\n        gui.log.log(\"Registry cache flushed to disc\");\r\n      }\r\n    })\r\n});\r\n```\r\n\r\n\r\n# Development\r\n\r\n1. Clone decene adjacent to your reference project, using decent-examples\r\n\r\n```bash\r\ncd my-projects-folder\r\ngit clone ..../decene\r\ngit clone ..../decene-examples\r\n```\r\n\r\n2. Edit the decene imort in the reference project, example\r\n\r\n```javascript\r\n// Local decene development using adjacent dir\r\nvar {network, encryption } = require(\"../../decene/lib\"),\r\n\r\n// Normal mode, using decene from npmjs\r\n// var {network, encryption } = require(\"decene\"),\r\n```\r\n\r\n3. Build decene, to generate lib folder from typescript code\r\n\r\n```bash\r\ncd decene\r\nnpm run-script build\r\n```\r\n\r\n4. Run your reference project, now you are using the local version of decene\r\n\r\n5. When you are ready to commit to decene, make sure everything is formatted, linted, tested and do build\r\n\r\n```bash\r\nnpm run-script format\r\nnpm run-script lint\r\nnpm run-script test\r\nnpm run-script build\r\n\r\ngit add .\r\ngit commit -m \"Yay, committing working and tested code.\"\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexagon%2Fdecene","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexagon%2Fdecene","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexagon%2Fdecene/lists"}