From fd2ff5c556c0823ec4d7d91d31146f812f8d508a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 2 Sep 2023 07:02:53 -0400 Subject: [PATCH] feat: add support for creating a resolver CID for the module if MODULE_SEED is not false --- npm-shrinkwrap.json | 310 +++++++++++++++++++++++++++++++++++++++++--- package.json | 6 +- src/index.ts | 118 ++++++++++++++++- 3 files changed, 415 insertions(+), 19 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b3e6b5a..129083c 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -8,8 +8,12 @@ "name": "@lumeweb/publish-kernel-module", "version": "0.1.0-develop.10", "dependencies": { - "@lumeweb/libweb": "0.2.0-develop.29", + "@lumeweb/libweb": "0.2.0-develop.36", + "@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": { @@ -1907,10 +1911,11 @@ } }, "node_modules/@lumeweb/libportal": { - "version": "0.2.0-develop.17", - "resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.17.tgz", - "integrity": "sha512-V8ac4NvRNCeE87rXNi9GX4J+ueztIWofBWMs24bmxWxrA46XOXC1Gm475IlAp4mSkyyUmy3vnnwQ4nYOi1U8Ew==", + "version": "0.2.0-develop.20", + "resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.20.tgz", + "integrity": "sha512-9bjyih7fyXpkcOYSue/jcLufcXQckkp30Ptigg2qFIDJOnxiv3ymRr2aq7rvXspnmTxnaQgwND0nQ0W0YOCnGA==", "dependencies": { + "@lumeweb/libs5": "^0.1.0-develop.43", "@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git", "@noble/curves": "^1.1.0", "@noble/hashes": "^1.3.1", @@ -1923,16 +1928,40 @@ "web-streams-polyfill": "^3.2.1" } }, + "node_modules/@lumeweb/libs5": { + "version": "0.1.0-develop.43", + "resolved": "https://registry.npmjs.org/@lumeweb/libs5/-/libs5-0.1.0-develop.43.tgz", + "integrity": "sha512-kUGuT4kK9YVggqyMUj+pPY7okAFKxzACZTlA4BBBsgxAGIdr+iZLQwMfDlwzE4bdxndS52g1XM39Xv3K2xA/lQ==", + "dependencies": { + "@noble/curves": "^1.1.0", + "@noble/hashes": "^1.3.1", + "detect-node": "^2.1.0", + "level": "^8.0.0", + "multiformats": "^12.0.1", + "p-defer": "^4.0.0", + "ws": "^8.13.0" + } + }, + "node_modules/@lumeweb/libs5/node_modules/multiformats": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.1.0.tgz", + "integrity": "sha512-/qTOKKnU8nwcVURjRcS+UN0QYgdS5BPZzY10Aiciu2SqncyCVMGV8KtD83EBFmsuJDsSEmT4sGvzcTkCoMw0sQ==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/@lumeweb/libweb": { - "version": "0.2.0-develop.29", - "resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.29.tgz", - "integrity": "sha512-Hnzuz3KKY2UsPn9r2O0rJrnim6m6k12Bzd06/zlP4wyCFwhx/C1vEIRJupyFdMSN/nflk68aKsQixY094U8FZQ==", + "version": "0.2.0-develop.36", + "resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.36.tgz", + "integrity": "sha512-17jj7UnKDwYMBmpquVOJmLVuKlRGOUfJDD+iWYOqle8gEekA5EwBIskB3NqFL99iw8dDax/MyqQUr5kSi4GyIQ==", "dependencies": { "@lumeweb/community-portals": "^0.1.0-develop.6", - "@lumeweb/libportal": "0.2.0-develop.17", + "@lumeweb/libportal": "0.2.0-develop.20", "@lumeweb/node-library-preset": "0.2.7", "@noble/curves": "^1.1.0", - "@noble/hashes": "^1.3.1" + "@noble/hashes": "^1.3.1", + "binconv": "^0.2.0" } }, "node_modules/@lumeweb/node-library-preset": { @@ -1948,20 +1977,20 @@ } }, "node_modules/@noble/curves": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.1.0.tgz", - "integrity": "sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", "dependencies": { - "@noble/hashes": "1.3.1" + "@noble/hashes": "1.3.2" }, "funding": { "url": "https://paulmillr.com/funding/" } }, "node_modules/@noble/hashes": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", - "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", "engines": { "node": ">= 16" }, @@ -2618,6 +2647,26 @@ "node": ">=12" } }, + "node_modules/@scure/base": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.3.tgz", + "integrity": "sha512-/+SgoRjLq7Xlf0CWuLHq2LUZeL/w65kfzAPG5NH9pcmBhs+nunQTn4gvdwgMTIXnt9b2C/1SeL2XiysZEyIC9Q==", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip39": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz", + "integrity": "sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==", + "dependencies": { + "@noble/hashes": "~1.3.0", + "@scure/base": "~1.1.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@semantic-release/changelog": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@semantic-release/changelog/-/changelog-6.0.3.tgz", @@ -3576,6 +3625,23 @@ "node": ">=6.5" } }, + "node_modules/abstract-level": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/abstract-level/-/abstract-level-1.0.3.tgz", + "integrity": "sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA==", + "dependencies": { + "buffer": "^6.0.3", + "catering": "^2.1.0", + "is-buffer": "^2.0.5", + "level-supports": "^4.0.0", + "level-transcoder": "^1.0.1", + "module-error": "^1.0.1", + "queue-microtask": "^1.2.3" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/acorn": { "version": "8.9.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.9.0.tgz", @@ -4085,6 +4151,11 @@ "node": ">=8" } }, + "node_modules/binconv": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/binconv/-/binconv-0.2.0.tgz", + "integrity": "sha512-FAVbv8Fe1lsk1XQeWaYzfIQ9EnBgLJxjlqVA5XzbusP1YCzFgXUfIfmuanNmfM7i0XsNCNnYOnnq7NRLVKRgdQ==" + }, "node_modules/bottleneck": { "version": "2.19.5", "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz", @@ -4110,6 +4181,17 @@ "node": ">=8" } }, + "node_modules/browser-level": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/browser-level/-/browser-level-1.0.1.tgz", + "integrity": "sha512-XECYKJ+Dbzw0lbydyQuJzwNXtOpbMSq737qxJN11sIRTErOMShvDpbzTlgju7orJKvx4epULolZAuJGLzCmWRQ==", + "dependencies": { + "abstract-level": "^1.0.2", + "catering": "^2.1.1", + "module-error": "^1.0.2", + "run-parallel-limit": "^1.1.0" + } + }, "node_modules/browserslist": { "version": "4.21.9", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.9.tgz", @@ -4434,6 +4516,14 @@ "cdl": "bin/cdl.js" } }, + "node_modules/catering": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz", + "integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==", + "engines": { + "node": ">=6" + } + }, "node_modules/chalk": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz", @@ -4521,6 +4611,22 @@ "integrity": "sha512-0TNiGstbQmCFwt4akjjBg5pLRTSyj/PkWQ1ZoO2zntmg9yLqSRxwEa4iCfQLGjqhiqBfOJa7W/E8wfGrTDmlZQ==", "peer": true }, + "node_modules/classic-level": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/classic-level/-/classic-level-1.3.0.tgz", + "integrity": "sha512-iwFAJQYtqRTRM0F6L8h4JCt00ZSGdOyqh7yVrhhjrOpFhmBjNlRUey64MCiyo6UmQHMJ+No3c81nujPv+n9yrg==", + "hasInstallScript": true, + "dependencies": { + "abstract-level": "^1.0.2", + "catering": "^2.1.0", + "module-error": "^1.0.1", + "napi-macros": "^2.2.2", + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -5851,6 +5957,23 @@ "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" }, + "node_modules/ed25519-keygen": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/ed25519-keygen/-/ed25519-keygen-0.4.8.tgz", + "integrity": "sha512-rsdNLL15/MmdGZ+I5f7/lVBk1+lZmd/Cw60QEuR5X6gebyBgBImCSLRk2J/REaoRvWwpWuaeOu5Y2Y9deyWNmA==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "@noble/curves": "~1.2.0", + "@noble/hashes": "~1.3.2", + "@scure/base": "~1.1.2", + "micro-packed": "^0.3.2" + } + }, "node_modules/electron-to-chromium": { "version": "1.4.440", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.440.tgz", @@ -7056,6 +7179,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==" + }, "node_modules/functions-have-names": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", @@ -8094,6 +8222,28 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "engines": { + "node": ">=4" + } + }, "node_modules/is-builtin-module": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", @@ -10002,6 +10152,42 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/level": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/level/-/level-8.0.0.tgz", + "integrity": "sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ==", + "dependencies": { + "browser-level": "^1.0.1", + "classic-level": "^1.2.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/level" + } + }, + "node_modules/level-supports": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-4.0.1.tgz", + "integrity": "sha512-PbXpve8rKeNcZ9C1mUicC9auIYFyGpkV9/i6g76tLgANwWhtG2v7I4xNBUlkn3lE2/dZF3Pi0ygYGtLc4RXXdA==", + "engines": { + "node": ">=12" + } + }, + "node_modules/level-transcoder": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/level-transcoder/-/level-transcoder-1.0.1.tgz", + "integrity": "sha512-t7bFwFtsQeD8cl8NIoQ2iwxA0CL/9IFw7/9gAjOonH0PWTTiRfY7Hq+Ejbsxh86tXobDQ6IOiddjNYIfOBs06w==", + "dependencies": { + "buffer": "^6.0.3", + "module-error": "^1.0.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -10726,6 +10912,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/memory-level": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/memory-level/-/memory-level-1.0.0.tgz", + "integrity": "sha512-UXzwewuWeHBz5krr7EvehKcmLFNoXxGcvuYhC41tRnkrTbJohtS7kVn9akmgirtRygg+f7Yjsfi8Uu5SGSQ4Og==", + "dependencies": { + "abstract-level": "^1.0.0", + "functional-red-black-tree": "^1.0.1", + "module-error": "^1.0.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/meow": { "version": "8.1.2", "resolved": "https://registry.npmjs.org/meow/-/meow-8.1.2.tgz", @@ -10941,6 +11140,20 @@ "node": ">= 8" } }, + "node_modules/micro-packed": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/micro-packed/-/micro-packed-0.3.2.tgz", + "integrity": "sha512-D1Bq0/lVOzdxhnX5vylCxZpdw5LylH7Vd81py0DfRsKUP36XYpwvy8ZIsECVo3UfnoROn8pdKqkOzL7Cd82sGA==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "@scure/base": "~1.1.1" + } + }, "node_modules/micromatch": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", @@ -11216,6 +11429,14 @@ "node": ">=0.10.0" } }, + "node_modules/module-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz", + "integrity": "sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==", + "engines": { + "node": ">=10" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -11248,6 +11469,11 @@ "url": "https://github.com/sponsors/raouldeheer" } }, + "node_modules/napi-macros": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.2.2.tgz", + "integrity": "sha512-hmEVtAGYzVQpCKdbQea4skABsdXW4RUh5t5mJ2zzqowJS2OyXZTU1KhDVFhx+NlWZ4ap9mqR9TcDO3LTTttd+g==" + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -11345,6 +11571,16 @@ "node": "^12.13 || ^14.13 || >=16" } }, + "node_modules/node-gyp-build": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz", + "integrity": "sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-gyp/node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -16301,6 +16537,28 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/run-parallel-limit": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz", + "integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, "node_modules/rxjs": { "version": "7.8.1", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", @@ -18840,6 +19098,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/ws": { + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", + "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 9ce5c4c..7b9b59c 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,12 @@ "lib/**" ], "dependencies": { - "@lumeweb/libweb": "0.2.0-develop.29", + "@lumeweb/libweb": "0.2.0-develop.36", + "@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" diff --git a/src/index.ts b/src/index.ts index d710fde..7c548a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import * as process from "process"; import fs from "fs/promises"; import path from "path"; import { + concatBytes, hexToBytes, maybeInitDefaultPortals, setActivePortalMasterKey, @@ -12,7 +13,28 @@ import { } from "@lumeweb/libweb"; import chalk from "chalk"; import * as util from "util"; -import { fileExists } from "#utils.js"; +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 { + CID_HASH_TYPES, + CID_TYPES, + createKeyPair, + createNode, + Logger, + REGISTRY_TYPES, + S5NodeConfig, +} from "@lumeweb/libs5"; + +import { MemoryLevel } from "memory-level"; +import { base58btc } from "multiformats/bases/base58"; +import KeyPairEd25519 from "@lumeweb/libs5/lib/ed25519.js"; +import defer from "p-defer"; +import { encodeCid } from "@lumeweb/libportal"; + +const BIP44_PATH = "m/44'/1627'/0'/0'/0'"; let key = process.env.PORTAL_PRIVATE_KEY; @@ -20,11 +42,27 @@ if (!key) { // @ts-ignore key = await prompts.prompts.password({ name: "private_key", - message: "Enter your private key", + message: "Enter your portal private key", validate: (prev) => prev && prev.length === 64, }); } +let seed = process.env.MODULE_SEED; +if (!seed && seed === undefined) { + // @ts-ignore + seed = await prompts.prompts.password({ + name: "module_seed", + message: "Enter your module seed", + validate: (prev) => prev && bip39.validateMnemonic(prev, wordlist), + }); +} + +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))) { @@ -82,3 +120,79 @@ console.log( cid, ), ); + +if (!hdKey) { + process.exit(0); +} + +const db = new MemoryLevel({ + storeEncoding: "view", + valueEncoding: "buffer", +}); +await db.open(); + +let config = { + keyPair: createKeyPair(), + db, + p2p: { + peers: { + initial: [ + // ...BOOTSTRAP_NODES, + "ws://z2DX2geLzZnff444mUFXZj7F3J2PA4SbRbfUiPwofk8Umix@127.0.0.1:5050/s5/p2p", + ], + }, + }, + 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 cidBytes = base58btc.decode(cid); + const key = hdKey as HDKey; + + let revision = 0; + + const ret = await node.services.registry.get( + new KeyPairEd25519(key.privateKey).publicKey, + ); + + if (ret) { + revision = ret.revision + 1; + } + const sre = node.services.registry.signRegistryEntry({ + kp: new KeyPairEd25519((hdKey as HDKey).privateKey), + data: concatBytes( + Uint8Array.from([ + REGISTRY_TYPES.CID, + CID_TYPES.RESOLVER, + CID_HASH_TYPES.BLAKE3, + ]), + cidBytes, + ), + revision, + }); + + await node.services.registry.set(sre); + + console.log( + util.format( + "%s: %s", + chalk.green("Resolver entry"), + encodeCid(cidBytes, 0, CID_TYPES.RESOLVER, CID_HASH_TYPES.ED25519), + ), + ); + await node.stop(); +}