Merge branch 'dzdidi:master' into master

This commit is contained in:
2024-07-08 14:32:22 +02:00
committed by GitHub
4 changed files with 62 additions and 73 deletions

90
npm-shrinkwrap.json generated
View File

@@ -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": "^2.1.5",
"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",
@@ -241,9 +265,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/"
}
@@ -3097,30 +3121,6 @@
"node": ">=0.10.0"
}
},
"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==",
"dependencies": {
"@noble/ciphers": "0.2.0",
"@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",
@@ -4958,9 +4972,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",
@@ -7160,20 +7174,6 @@
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"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==",
"requires": {
"@noble/ciphers": "0.2.0",
"@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",

View File

@@ -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": "^2.1.5",
"protomux-rpc": "^1.5.1",
"random-access-memory": "^6.2.0"
}

View File

@@ -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')
@@ -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,

View File

@@ -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('<command> [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()