From cddf39bfad06f8f9e9fbcb98126e34107aa297c1 Mon Sep 17 00:00:00 2001 From: dzdidi Date: Mon, 19 Feb 2024 18:16:17 +0000 Subject: [PATCH 1/3] cli: print help instead of trace Signed-off-by: dzdidi --- src/cli.js | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/cli.js b/src/cli.js index 2157036..cfb6a17 100755 --- a/src/cli.js +++ b/src/cli.js @@ -16,12 +16,14 @@ const { checkIfGitRepo } = require('./utils') const { remoteACL, share, remoteBranchProtectionRules, localACL, localBranchProtectionRules } = require('./cli-helpers') const pkg = require('../package.json') -program - .name('gitpear') + +const gitPear = program + .name('git pear') .description('CLI to gitpear') + .usage(' [options]') .version(pkg.version) -program +const commandInit = gitPear .command('init') .description('initialize a gitpear repo') .option('-s, --share [branch]', 'share the repo as public, default false, default branch is current', '') @@ -60,7 +62,7 @@ program if (options.share) await share(name, branchToShare) }) -program +const commandShare = gitPear .command('share') .description('share a gitpear repo') .option('-b, --branch [b]', 'branch to share, default is current branch', '') @@ -80,7 +82,7 @@ program await share(name, branchToShare, options) }) -program +const commandACL = gitPear .command('acl') .description('manage acl of a gitpear repo') .option('-u, --user', 'user to add/remove/list') @@ -89,13 +91,7 @@ program .addArgument(new commander.Argument('[a]', 'actiont to perform').choices(['add', 'remove', 'list']).default('list')) .addArgument(new commander.Argument('[n]', 'user or branch to add/remove/list').default('')) .action(async (a, n, options) => { - if (options.user && options.branch) { - throw new Error('Cannot perform both user and branch action at the same time') - } - - if (!options.user && !options.branch) { - throw new Error('Either user or branch option is required') - } + if (options.user === options.branch) commandACL.help() if (options.user) { if (options.path.startsWith('pear://')) { @@ -113,7 +109,7 @@ program } }) -program +const commandUnshare = gitPear .command('unshare') .description('unshare a gitpear repo') .option('-p, --path [path]', 'path to the repo', '.') @@ -133,7 +129,7 @@ program process.exit(1) }) -program +const commandList = gitPear .command('list') .description('list all gitpear repos') .addArgument(new commander.Argument('[u]', 'url to remote pear').default('')) @@ -146,28 +142,21 @@ program home.list(s).forEach(n => console.log(n, ...(s ? ['\t', `pear://${k}/${n}`] : []))) }) -program +const commandKey = gitPear .command('key') .description('get a public key of gitpear') .action((p, options) => { console.log('Public key:', home.readPk()) }) -program +const commandDaemon = gitPear .command('daemon') .description('start/stop gitpear daemon') .option('-s, --start', 'start daemon') .option('-k, --stop', 'stop daemon') .option('-a, --attach', 'watch daemon logs') .action((p, options) => { - if (options.opts().start && options.opts().stop) { - console.error('Cannot start and stop daemon at the same time') - process.exit(1) - } - if (!options.opts().start && !options.opts().stop) { - console.error('Need either start or stop option') - process.exit(1) - } + if (options.opts().start === options.opts().stop) commandDaemon.help() if (options.opts().start) { if (home.getDaemonPid()) { @@ -207,4 +196,4 @@ program } }) -program.parse() +gitPear.parse() From 5f1e3bd212faccc7f1b4b2718d4330da328c9bbc Mon Sep 17 00:00:00 2001 From: dzdidi Date: Wed, 28 Feb 2024 17:13:55 +0000 Subject: [PATCH 2/3] nip98: skip timestamp validation Signed-off-by: dzdidi --- npm-shrinkwrap.json | 29 ++++++++++++++--------------- package.json | 2 +- src/auth/nip98.js | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 82ec373..b63c205 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -15,7 +15,7 @@ "corestore": "^6.15.13", "hyperdrive": "^11.6.3", "hyperswarm": "^4.7.13", - "nostr-tools": "^2.1.5", + "nostr-tools": "github:dzdidi/nostr-tools", "protomux-rpc": "^1.5.1", "random-access-memory": "^6.2.0" }, @@ -241,9 +241,9 @@ } }, "node_modules/@noble/ciphers": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.2.0.tgz", - "integrity": "sha512-6YBxJDAapHSdd3bLDv6x2wRPwq4QFMUaB3HvljNBUTThDd12eSm7/3F+2lnfzx2jvM+S6Nsy0jEt9QbPqSwqRw==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.5.1.tgz", + "integrity": "sha512-aNE06lbe36ifvMbbWvmmF/8jx6EQPu2HVg70V95T+iGjOuYwPpAccwAQc2HlXO2D0aiQ3zavbMga4jjWnrpiPA==", "funding": { "url": "https://paulmillr.com/funding/" } @@ -3098,11 +3098,11 @@ } }, "node_modules/nostr-tools": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.1.5.tgz", - "integrity": "sha512-Gug/j54YGQ0ewB09dZW3mS9qfXWFlcOQMlyb1MmqQsuNO/95mfNOQSBi+jZ61O++Y+jG99SzAUPFLopUsKf0MA==", + "version": "2.3.1", + "resolved": "git+ssh://git@github.com/dzdidi/nostr-tools.git#83e1286d5e88c55348835def60d5cac64f474228", + "license": "Unlicense", "dependencies": { - "@noble/ciphers": "0.2.0", + "@noble/ciphers": "^0.5.1", "@noble/curves": "1.2.0", "@noble/hashes": "1.3.1", "@scure/base": "1.1.1", @@ -4958,9 +4958,9 @@ } }, "@noble/ciphers": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.2.0.tgz", - "integrity": "sha512-6YBxJDAapHSdd3bLDv6x2wRPwq4QFMUaB3HvljNBUTThDd12eSm7/3F+2lnfzx2jvM+S6Nsy0jEt9QbPqSwqRw==" + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.5.1.tgz", + "integrity": "sha512-aNE06lbe36ifvMbbWvmmF/8jx6EQPu2HVg70V95T+iGjOuYwPpAccwAQc2HlXO2D0aiQ3zavbMga4jjWnrpiPA==" }, "@noble/curves": { "version": "1.2.0", @@ -7161,11 +7161,10 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, "nostr-tools": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.1.5.tgz", - "integrity": "sha512-Gug/j54YGQ0ewB09dZW3mS9qfXWFlcOQMlyb1MmqQsuNO/95mfNOQSBi+jZ61O++Y+jG99SzAUPFLopUsKf0MA==", + "version": "git+ssh://git@github.com/dzdidi/nostr-tools.git#83e1286d5e88c55348835def60d5cac64f474228", + "from": "nostr-tools@github:dzdidi/nostr-tools", "requires": { - "@noble/ciphers": "0.2.0", + "@noble/ciphers": "^0.5.1", "@noble/curves": "1.2.0", "@noble/hashes": "1.3.1", "@scure/base": "1.1.1", diff --git a/package.json b/package.json index ed34376..ba85e55 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "corestore": "^6.15.13", "hyperdrive": "^11.6.3", "hyperswarm": "^4.7.13", - "nostr-tools": "^2.1.5", + "nostr-tools": "github:dzdidi/nostr-tools", "protomux-rpc": "^1.5.1", "random-access-memory": "^6.2.0" } diff --git a/src/auth/nip98.js b/src/auth/nip98.js index f693dc0..2883879 100644 --- a/src/auth/nip98.js +++ b/src/auth/nip98.js @@ -15,7 +15,7 @@ async function getToken ({ url, method, data }) { // FIXME async function getId ({ payload, url, method, data }) { const event = JSON.parse(Buffer.from(payload, 'base64').toString()) - const isValid = await nip98.validateEvent(event, url, method, data) + const isValid = await nip98.validateEvent(event, url, method, data, { skipTimestampValidation: true }) if (!isValid) throw new Error('Invalid event') return { ...event, From d6847e708a86cc9cd317395b44a89513836b922c Mon Sep 17 00:00:00 2001 From: dzdidi Date: Wed, 28 Feb 2024 17:30:45 +0000 Subject: [PATCH 3/3] personal nostr tools Signed-off-by: dzdidi --- npm-shrinkwrap.json | 77 +++++++++++++++++++++++---------------------- package.json | 2 +- src/auth/nip98.js | 2 +- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b63c205..43d6a39 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -10,12 +10,12 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { + "@dzdidi_restored/nostr-tools": "^2.3.1", "chokidar": "^3.5.3", "commander": "^11.0.0", "corestore": "^6.15.13", "hyperdrive": "^11.6.3", "hyperswarm": "^4.7.13", - "nostr-tools": "github:dzdidi/nostr-tools", "protomux-rpc": "^1.5.1", "random-access-memory": "^6.2.0" }, @@ -46,6 +46,30 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@dzdidi_restored/nostr-tools": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@dzdidi_restored/nostr-tools/-/nostr-tools-2.3.1.tgz", + "integrity": "sha512-N8q1FvFZuiB6UQHPFd0eexWM34pdMOzV1yGkALnDWuOqwRmyvoVXp6GMOOcgnXktZ8dSugS71ptgV3YKkzZkWA==", + "dependencies": { + "@noble/ciphers": "^0.5.1", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.1", + "@scure/base": "1.1.1", + "@scure/bip32": "1.3.1", + "@scure/bip39": "1.2.1" + }, + "optionalDependencies": { + "nostr-wasm": "v0.1.0" + }, + "peerDependencies": { + "typescript": ">=5.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -3097,30 +3121,6 @@ "node": ">=0.10.0" } }, - "node_modules/nostr-tools": { - "version": "2.3.1", - "resolved": "git+ssh://git@github.com/dzdidi/nostr-tools.git#83e1286d5e88c55348835def60d5cac64f474228", - "license": "Unlicense", - "dependencies": { - "@noble/ciphers": "^0.5.1", - "@noble/curves": "1.2.0", - "@noble/hashes": "1.3.1", - "@scure/base": "1.1.1", - "@scure/bip32": "1.3.1", - "@scure/bip39": "1.2.1" - }, - "optionalDependencies": { - "nostr-wasm": "v0.1.0" - }, - "peerDependencies": { - "typescript": ">=5.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/nostr-wasm": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz", @@ -4802,6 +4802,20 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "@dzdidi_restored/nostr-tools": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/@dzdidi_restored/nostr-tools/-/nostr-tools-2.3.1.tgz", + "integrity": "sha512-N8q1FvFZuiB6UQHPFd0eexWM34pdMOzV1yGkALnDWuOqwRmyvoVXp6GMOOcgnXktZ8dSugS71ptgV3YKkzZkWA==", + "requires": { + "@noble/ciphers": "^0.5.1", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.1", + "@scure/base": "1.1.1", + "@scure/bip32": "1.3.1", + "@scure/bip39": "1.2.1", + "nostr-wasm": "v0.1.0" + } + }, "@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -7160,19 +7174,6 @@ "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, - "nostr-tools": { - "version": "git+ssh://git@github.com/dzdidi/nostr-tools.git#83e1286d5e88c55348835def60d5cac64f474228", - "from": "nostr-tools@github:dzdidi/nostr-tools", - "requires": { - "@noble/ciphers": "^0.5.1", - "@noble/curves": "1.2.0", - "@noble/hashes": "1.3.1", - "@scure/base": "1.1.1", - "@scure/bip32": "1.3.1", - "@scure/bip39": "1.2.1", - "nostr-wasm": "v0.1.0" - } - }, "nostr-wasm": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz", diff --git a/package.json b/package.json index ba85e55..31a9592 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,12 @@ "typescript": "^5.1.3" }, "dependencies": { + "@dzdidi_restored/nostr-tools": "^2.3.1", "chokidar": "^3.5.3", "commander": "^11.0.0", "corestore": "^6.15.13", "hyperdrive": "^11.6.3", "hyperswarm": "^4.7.13", - "nostr-tools": "github:dzdidi/nostr-tools", "protomux-rpc": "^1.5.1", "random-access-memory": "^6.2.0" } diff --git a/src/auth/nip98.js b/src/auth/nip98.js index 2883879..38a553c 100644 --- a/src/auth/nip98.js +++ b/src/auth/nip98.js @@ -1,4 +1,4 @@ -const { nip98, nip19, finalizeEvent } = require('nostr-tools') +const { nip98, nip19, finalizeEvent } = require('@dzdidi_restored/nostr-tools') async function getToken ({ url, method, data }) { if (!process.env.GIT_PEAR_AUTH_NSEC) throw new Error('Missing NSEC')