Compare commits

..

74 Commits

Author SHA1 Message Date
semantic-release-bot 7c90b7e7b3 chore(release): 0.1.0-develop.22 [skip ci]
# [0.1.0-develop.22](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.21...v0.1.0-develop.22) (2023-09-11)

### Bug Fixes

* cid is a CID instance already ([5227acb](5227acb287))
2023-09-11 18:02:58 +00:00
Derrick Hammer 534a6accf1
Merge remote-tracking branch 'origin/develop' into develop 2023-09-11 14:01:35 -04:00
Derrick Hammer 5227acb287
fix: cid is a CID instance already 2023-09-11 14:01:31 -04:00
semantic-release-bot 481477cc05 chore(release): 0.1.0-develop.21 [skip ci]
# [0.1.0-develop.21](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.20...v0.1.0-develop.21) (2023-09-11)

### Bug Fixes

* resolverCid needs to be in string format ([a3cc5c1](a3cc5c1c71))
2023-09-11 17:34:57 +00:00
Derrick Hammer eeb8e35bf9
Merge remote-tracking branch 'origin/develop' into develop 2023-09-11 13:34:01 -04:00
Derrick Hammer a3cc5c1c71
fix: resolverCid needs to be in string format 2023-09-11 13:33:57 -04:00
semantic-release-bot 98c44d6ccc chore(release): 0.1.0-develop.20 [skip ci]
# [0.1.0-develop.20](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.19...v0.1.0-develop.20) (2023-09-11)
2023-09-11 17:30:21 +00:00
Derrick Hammer 8494313abd
Merge remote-tracking branch 'origin/develop' into develop 2023-09-11 13:29:13 -04:00
Derrick Hammer e8b3e03e7b
refactor: errtuples are no longer used, and switch to using the CID class 2023-09-11 13:29:04 -04:00
Derrick Hammer 3eda1bbc37
dep: update libweb 2023-09-11 13:28:27 -04:00
Derrick Hammer f68656fabd
dep: update libweb 2023-09-11 13:05:21 -04:00
semantic-release-bot d033360604 chore(release): 0.1.0-develop.19 [skip ci]
# [0.1.0-develop.19](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.18...v0.1.0-develop.19) (2023-09-04)
2023-09-04 09:52:18 +00:00
Derrick Hammer 1c2fc98799
Merge remote-tracking branch 'origin/develop' into develop 2023-09-04 05:51:26 -04:00
Derrick Hammer 9844d8edae
refactor: read module seed from file, if env not set, and fall back to generating one and saving it to disk 2023-09-04 05:51:20 -04:00
semantic-release-bot dc081553f3 chore(release): 0.1.0-develop.18 [skip ci]
# [0.1.0-develop.18](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.17...v0.1.0-develop.18) (2023-09-04)
2023-09-04 07:36:43 +00:00
Derrick Hammer a5818bc17d
Merge remote-tracking branch 'origin/develop' into develop 2023-09-04 03:35:24 -04:00
Derrick Hammer f0ecd5a3ba
refactor: remove unneeded imports 2023-09-04 03:35:17 -04:00
Derrick Hammer 0825f4c35d
dep: update libweb 2023-09-04 03:34:10 -04:00
Derrick Hammer e9e05b4caf
refactor: switch to using encodeRegistryValue, and encodeRegistryCid 2023-09-03 20:43:29 -04:00
Derrick Hammer db24524f87
dep: update libweb 2023-09-03 20:42:12 -04:00
Derrick Hammer dc5e44eb14
dep: update libweb 2023-09-03 13:01:37 -04:00
semantic-release-bot 70069471d0 chore(release): 0.1.0-develop.17 [skip ci]
# [0.1.0-develop.17](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.16...v0.1.0-develop.17) (2023-09-03)

### Bug Fixes

* need to slice out the key type byte ([7d0d1b9](7d0d1b9b2b))
2023-09-03 03:05:55 +00:00
Derrick Hammer 23b10c1c1d
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 23:05:02 -04:00
Derrick Hammer 7d0d1b9b2b
fix: need to slice out the key type byte 2023-09-02 23:04:52 -04:00
Derrick Hammer 3b70ba00af
refactor: switch to decodeCid 2023-09-02 23:04:47 -04:00
Derrick Hammer 5895485467
dep: update libweb 2023-09-02 23:03:18 -04:00
semantic-release-bot 8305d21af2 chore(release): 0.1.0-develop.16 [skip ci]
# [0.1.0-develop.16](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.15...v0.1.0-develop.16) (2023-09-02)

### Bug Fixes

* if seed is false or 0 as a string, set it to false ([bdbb090](bdbb090c7d))
2023-09-02 13:56:25 +00:00
Derrick Hammer 15dc2382f0
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 09:55:22 -04:00
Derrick Hammer bdbb090c7d
fix: if seed is false or 0 as a string, set it to false 2023-09-02 09:55:15 -04:00
semantic-release-bot d9f2221272 chore(release): 0.1.0-develop.15 [skip ci]
# [0.1.0-develop.15](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.14...v0.1.0-develop.15) (2023-09-02)

### Bug Fixes

* only submit a new registry entry if the data has changed ([39b0117](39b0117e4f))
2023-09-02 12:55:50 +00:00
Derrick Hammer 98a91cc873
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 08:54:49 -04:00
Derrick Hammer 39b0117e4f
fix: only submit a new registry entry if the data has changed 2023-09-02 08:54:45 -04:00
semantic-release-bot 49c2e1430f chore(release): 0.1.0-develop.14 [skip ci]
# [0.1.0-develop.14](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.13...v0.1.0-develop.14) (2023-09-02)

### Bug Fixes

* need to use the sre.pk not cidBytes ([c65a212](c65a212e56))
2023-09-02 12:43:55 +00:00
Derrick Hammer 704e78b421
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 08:42:56 -04:00
Derrick Hammer c65a212e56
fix: need to use the sre.pk not cidBytes 2023-09-02 08:42:46 -04:00
semantic-release-bot 5d79fed53a chore(release): 0.1.0-develop.13 [skip ci]
# [0.1.0-develop.13](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.12...v0.1.0-develop.13) (2023-09-02)

### Bug Fixes

* restore bootstrap nodes list ([b7caaa0](b7caaa09da))
2023-09-02 11:05:11 +00:00
Derrick Hammer ab785eab9d
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 07:04:16 -04:00
Derrick Hammer b7caaa09da
fix: restore bootstrap nodes list 2023-09-02 07:04:12 -04:00
semantic-release-bot dfb3764a59 chore(release): 0.1.0-develop.12 [skip ci]
# [0.1.0-develop.12](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.11...v0.1.0-develop.12) (2023-09-02)

### Features

* add support for creating a resolver CID for the module if MODULE_SEED is not false ([fd2ff5c](fd2ff5c556))
2023-09-02 11:03:59 +00:00
Derrick Hammer 6e84338ddc
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 07:03:03 -04:00
Derrick Hammer fd2ff5c556
feat: add support for creating a resolver CID for the module if MODULE_SEED is not false 2023-09-02 07:02:53 -04:00
semantic-release-bot cb3e0b54f2 chore(release): 0.1.0-develop.11 [skip ci]
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-08-10)
2023-08-10 06:31:01 +00:00
Derrick Hammer a2f9e9aeff
Merge remote-tracking branch 'origin/develop' into develop 2023-08-10 02:30:05 -04:00
Derrick Hammer eceed29613
dep: update libweb 2023-08-10 02:30:00 -04:00
semantic-release-bot f46cc8f19e chore(release): 0.1.0-develop.10 [skip ci]
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-08-10)
2023-08-10 05:54:58 +00:00
Derrick Hammer a5d211bd8e
Merge remote-tracking branch 'origin/develop' into develop 2023-08-10 01:53:58 -04:00
Derrick Hammer f65590e494
dep: update libweb 2023-08-10 01:53:49 -04:00
semantic-release-bot 8e6e62c5ae chore(release): 0.1.0-develop.9 [skip ci]
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-06-29)
2023-06-29 06:32:16 +00:00
Derrick Hammer a522175336
dep: update node-library-preset 2023-06-29 02:31:17 -04:00
semantic-release-bot 1284575571 chore(release): 0.1.0-develop.8 [skip ci]
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-06-29)
2023-06-29 05:47:34 +00:00
Derrick Hammer 225e97f932
Merge remote-tracking branch 'origin/develop' into develop 2023-06-29 01:46:39 -04:00
Derrick Hammer 0c556e4f79
dep: use @lumeweb/node-library-preset npm, not git 2023-06-29 01:46:33 -04:00
semantic-release-bot 73fc94ca0c chore(release): 0.1.0-develop.7 [skip ci]
# [0.1.0-develop.7](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.6...v0.1.0-develop.7) (2023-06-29)
2023-06-29 05:40:44 +00:00
Derrick Hammer 774082b901
dep: update libweb, remove libportal and community-portals since they are in the dep chain already 2023-06-29 01:39:41 -04:00
semantic-release-bot dba6bc4c10 chore(release): 0.1.0-develop.6 [skip ci]
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-06-26)

### Bug Fixes

* fix util import ([ab820fe](ab820fe346))
2023-06-26 08:04:31 +00:00
Derrick Hammer 1ac101396a
Merge remote-tracking branch 'origin/develop' into develop 2023-06-26 04:03:07 -04:00
Derrick Hammer ab820fe346
fix: fix util import 2023-06-26 04:02:57 -04:00
semantic-release-bot fce3907be6 chore(release): 0.1.0-develop.5 [skip ci]
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-06-26)
2023-06-26 07:53:22 +00:00
Derrick Hammer 934cff2aa8
dep: ensure absolute dependency versions 2023-06-26 03:52:06 -04:00
Derrick Hammer c1d0857b35
Merge remote-tracking branch 'origin/develop' into develop 2023-06-26 03:42:00 -04:00
Derrick Hammer 6782f649d6
dep: update @lumeweb/community-portals 2023-06-26 03:41:56 -04:00
Derrick Hammer 74674c91cb
dep: update @lumeweb/libportal 2023-06-26 03:39:06 -04:00
semantic-release-bot fbb0990c12 chore(release): 0.1.0-develop.4 [skip ci]
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-06-26)
2023-06-26 07:25:04 +00:00
Derrick Hammer 43570de7c2
Merge remote-tracking branch 'origin/develop' into develop 2023-06-26 03:23:48 -04:00
Derrick Hammer d8fe7cb912
dep: update @lumeweb/node-library-preset 2023-06-26 03:23:44 -04:00
semantic-release-bot b2127c9db8 chore(release): 0.1.0-develop.3 [skip ci]
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-06-26)

### Bug Fixes

* check if presetter exists before running bootstrap ([0003b60](0003b60184))
2023-06-26 06:59:08 +00:00
Derrick Hammer 41f3204fee
Merge remote-tracking branch 'origin/develop' into develop 2023-06-26 02:58:11 -04:00
Derrick Hammer 0003b60184
fix: check if presetter exists before running bootstrap 2023-06-26 02:58:06 -04:00
semantic-release-bot e43062cf87 chore(release): 0.1.0-develop.2 [skip ci]
# [0.1.0-develop.2](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.1...v0.1.0-develop.2) (2023-06-26)
2023-06-26 06:39:54 +00:00
Derrick Hammer 09ba506c76
Merge remote-tracking branch 'origin/develop' into develop 2023-06-26 02:38:41 -04:00
Derrick Hammer 233b989212
refactor: change KERNEL_FILE env to MODULE_FILE env 2023-06-26 02:38:29 -04:00
semantic-release-bot fceb7e1987 chore(release): 0.1.0-develop.1 [skip ci]
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.0.1...v0.1.0-develop.1) (2023-06-26)

### Features

* initial version ([65f3dcc](65f3dcca6f))
2023-06-26 06:34:52 +00:00
Derrick Hammer c914ed92d9
ci: update @lumeweb/node-library-preset 2023-06-26 02:31:56 -04:00
Derrick Hammer 65f3dcca6f
feat: initial version 2023-06-26 02:24:33 -04:00
8 changed files with 19609 additions and 1 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

98
CHANGELOG.md Normal file
View File

@ -0,0 +1,98 @@
# [0.1.0-develop.22](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.21...v0.1.0-develop.22) (2023-09-11)
### Bug Fixes
* cid is a CID instance already ([5227acb](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/5227acb2876f97ccf041bfe6f4c63622294b003e))
# [0.1.0-develop.21](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.20...v0.1.0-develop.21) (2023-09-11)
### Bug Fixes
* resolverCid needs to be in string format ([a3cc5c1](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/a3cc5c1c71c6665d1b0af165b0e4395058a60ff0))
# [0.1.0-develop.20](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.19...v0.1.0-develop.20) (2023-09-11)
# [0.1.0-develop.19](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.18...v0.1.0-develop.19) (2023-09-04)
# [0.1.0-develop.18](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.17...v0.1.0-develop.18) (2023-09-04)
# [0.1.0-develop.17](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.16...v0.1.0-develop.17) (2023-09-03)
### Bug Fixes
* need to slice out the key type byte ([7d0d1b9](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/7d0d1b9b2bec62d369a255cb3a7545febfb4ad56))
# [0.1.0-develop.16](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.15...v0.1.0-develop.16) (2023-09-02)
### Bug Fixes
* if seed is false or 0 as a string, set it to false ([bdbb090](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/bdbb090c7d2764d178f2578c8a1eb792e0a180e9))
# [0.1.0-develop.15](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.14...v0.1.0-develop.15) (2023-09-02)
### Bug Fixes
* only submit a new registry entry if the data has changed ([39b0117](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/39b0117e4f02550c9ac7b58961e83b2e82757b41))
# [0.1.0-develop.14](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.13...v0.1.0-develop.14) (2023-09-02)
### Bug Fixes
* need to use the sre.pk not cidBytes ([c65a212](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/c65a212e567e6a9695b9525db70cd09256342293))
# [0.1.0-develop.13](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.12...v0.1.0-develop.13) (2023-09-02)
### Bug Fixes
* restore bootstrap nodes list ([b7caaa0](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/b7caaa09da49dd5a3793711ca5ad24878c9502d8))
# [0.1.0-develop.12](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.11...v0.1.0-develop.12) (2023-09-02)
### Features
* add support for creating a resolver CID for the module if MODULE_SEED is not false ([fd2ff5c](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/fd2ff5c556c0823ec4d7d91d31146f812f8d508a))
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-08-10)
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-08-10)
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-06-29)
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-06-29)
# [0.1.0-develop.7](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.6...v0.1.0-develop.7) (2023-06-29)
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-06-26)
### Bug Fixes
* fix util import ([ab820fe](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/ab820fe346e4364722d22d83fadaed65d329e3b2))
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-06-26)
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-06-26)
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-06-26)
### Bug Fixes
* check if presetter exists before running bootstrap ([0003b60](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/0003b601847c6e1e29f59bce600c2ccf16c4166b))
# [0.1.0-develop.2](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.1.0-develop.1...v0.1.0-develop.2) (2023-06-26)
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/publish-kernel-module/compare/v0.0.1...v0.1.0-develop.1) (2023-06-26)
### Features
* initial version ([65f3dcc](https://git.lumeweb.com/LumeWeb/publish-kernel-module/commit/65f3dcca6fe2cb3d65be7e4dc11e529f1bf06370))

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) <year> <copyright holders> Copyright (c) 2023 Hammer Technologies LLC
Permission 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: Permission 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:

19233
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

36
package.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "@lumeweb/publish-kernel-module",
"version": "0.1.0-develop.22",
"type": "module",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/publish-kernel-module.git"
},
"devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"@types/prompts": "^2.4.4",
"presetter": "*"
},
"readme": "ERROR: No README data found!",
"scripts": {
"prepare": "bash -c 'if command -v presetter &> /dev/null; then presetter bootstrap; fi'",
"build": "run build",
"semantic-release": "semantic-release"
},
"publishConfig": {
"access": "public"
},
"files": [
"lib/**"
],
"dependencies": {
"@lumeweb/libweb": "0.2.0-develop.58",
"@scure/bip39": "^1.2.1",
"chalk": "^5.2.0",
"ed25519-keygen": "^0.4.8",
"memory-level": "^1.0.0",
"p-defer": "^4.0.0",
"prompts": "^2.4.2"
},
"bin": "./lib/index.js"
}

212
src/index.ts Normal file
View File

@ -0,0 +1,212 @@
#! /usr/bin/env node
import prompts from "prompts";
import * as process from "process";
import fs from "fs/promises";
import path from "path";
import {
equalBytes,
hexToBytes,
maybeInitDefaultPortals,
setActivePortalMasterKey,
uploadObject,
} from "@lumeweb/libweb";
import chalk from "chalk";
import * as util from "util";
import { fileExists } from "./utils.js";
import * as bip39 from "@scure/bip39";
import { wordlist } from "@scure/bip39/wordlists/english";
import { HDKey } from "ed25519-keygen/hdkey";
import {
BOOTSTRAP_NODES,
CID,
createKeyPair,
createNode,
S5NodeConfig,
SignedRegistryEntry,
} from "@lumeweb/libs5";
import { MemoryLevel } from "memory-level";
import KeyPairEd25519 from "@lumeweb/libs5/lib/ed25519.js";
import defer from "p-defer";
const BIP44_PATH = "m/44'/1627'/0'/0'/0'";
let key = process.env.PORTAL_PRIVATE_KEY;
if (!key) {
// @ts-ignore
key = await prompts.prompts.password({
name: "private_key",
message: "Enter your portal private key",
validate: (prev) => prev && prev.length === 64,
});
}
let seed = process.env.MODULE_SEED;
if (["0", "false"].includes(seed as string)) {
seed = false as any;
}
if (!seed && seed === undefined) {
const seedFile = path.join(process.cwd(), ".module-seed");
if (await fileExists(seedFile)) {
seed = await fs.readFile(seedFile, "utf8");
}
if (!seed) {
seed = bip39.generateMnemonic(wordlist);
await fs.writeFile(seedFile, seed);
}
}
const hdKey = seed
? HDKey.fromMasterSeed(await bip39.mnemonicToSeed(seed as string)).derive(
BIP44_PATH,
)
: false;
let file = process.env.MODULE_FILE;
if (!file || !(await fileExists(file))) {
const cwd = process.cwd();
const locations = [
"dist/module.js",
"dist/index.js",
"lib/module.js",
"lib/index.js",
];
const promises = locations.map((item) => {
item = path.join(cwd, item);
return [item, fileExists(item)];
});
const pResults: boolean[] = await Promise.all(
promises.map((item) => item[1] as Promise<boolean>),
);
const results = pResults.reduce((prev, cur, index) => {
if (cur) {
prev.push(locations[index]);
}
return prev;
}, [] as any);
if (!results.length) {
console.error("Kernel module could not be found");
process.exit(1);
}
file = results[0];
}
setActivePortalMasterKey(hexToBytes(key as string));
maybeInitDefaultPortals();
const fd = await fs.open(file as string);
let cid: CID;
try {
cid = await uploadObject(
fd.createReadStream(),
BigInt((await fd.stat()).size),
);
} catch (e) {
console.error("Failed to publish: ", e.message);
process.exit();
}
console.log(
util.format(
"%s: %s",
chalk.green("Kernel module successfully published"),
cid,
),
);
if (!hdKey) {
process.exit(0);
}
const db = new MemoryLevel<string, Uint8Array>({
storeEncoding: "view",
valueEncoding: "buffer",
});
await db.open();
let config = {
keyPair: createKeyPair(),
db,
p2p: {
peers: {
initial: [...BOOTSTRAP_NODES],
},
},
logger: {
info: (s: string) => {},
verbose: (s: string) => {},
warn: (s: string) => {},
error: (s: string) => {},
catched: (e: any, context?: string | null) => {},
},
} as S5NodeConfig;
const node = createNode(config);
await node.start();
const peerDefer = defer();
node.services.p2p.once("peerConnected", peerDefer.resolve);
await peerDefer.promise;
{
const key = hdKey as HDKey;
let revision = 0;
let sre: SignedRegistryEntry;
const ret = await node.services.registry.get(
new KeyPairEd25519(key.privateKey).publicKey,
);
if (ret) {
revision = ret.revision + 1;
}
let newEntry;
try {
newEntry = cid.toRegistryEntry();
} catch (e) {
console.error("Failed to publish: ", e.message);
process.exit();
}
if (!equalBytes(ret?.data ?? new Uint8Array(), newEntry)) {
sre = node.services.registry.signRegistryEntry({
kp: new KeyPairEd25519((hdKey as HDKey).privateKey),
data: newEntry,
revision,
});
await node.services.registry.set(sre);
} else {
sre = ret as SignedRegistryEntry;
}
let resolverCid;
try {
resolverCid = CID.fromRegistryPublicKey(sre.pk).toString();
} catch (e) {
console.error("Failed to publish: ", e.message);
process.exit();
}
console.log(
util.format("%s: %s", chalk.green("Resolver entry"), resolverCid),
);
await node.stop();
}

11
src/utils.ts Normal file
View File

@ -0,0 +1,11 @@
import fs from "fs/promises";
export async function fileExists(path: string) {
try {
await fs.stat(path);
} catch {
return false;
}
return true;
}