nappup 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,7 +153,7 @@ export async function readEnvSetValue (args, {
153
153
  }
154
154
 
155
155
  export async function confirmArgs (args) {
156
- if (args.yes) return
156
+ if (args.yes) return true
157
157
  const rl = readline.createInterface({
158
158
  input: process.stdin,
159
159
  output: process.stdout
@@ -162,14 +162,18 @@ export async function confirmArgs (args) {
162
162
  return new Promise(resolve => rl.question(query, resolve))
163
163
  }
164
164
  const answer = await askQuestion(
165
- `Publish app from '${args.dir}' as '${args.dTag}' to the ${args.channel} release channel? (y/n) `
165
+ confirmationPrompt(args)
166
166
  )
167
+ rl.close()
167
168
  if (answer.toLowerCase() !== 'y') {
168
169
  console.log('Operation cancelled by user.')
169
- rl.close()
170
- process.exit(0)
170
+ return false
171
171
  }
172
- rl.close()
172
+ return true
173
+ }
174
+
175
+ export function confirmationPrompt (args) {
176
+ return `Publish app from '${args.dir}' as '${args.dTag}' to the ${args.channel} release channel using ${args.npub}? (y/n) `
173
177
  }
174
178
 
175
179
  export async function * getFiles (dir) {
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import path from 'node:path'
3
+ import { npubEncode } from 'libp2r2p/nip19'
3
4
  import { GENERIC_BUILD_FOLDER_NAMES } from '#helpers/app.js'
4
5
  import {
5
6
  parseArgs,
@@ -57,8 +58,6 @@ async function upload (args, dotenvState) {
57
58
  }
58
59
  args.dTag = dTag
59
60
 
60
- await confirmArgs(args)
61
- const fileList = await toFileList(getFiles(dir), dir)
62
61
  const bunkerUrl = sk?.startsWith('bunker://')
63
62
  ? sk
64
63
  : !sk && process.env.NOSTR_SECRET_KEY?.startsWith('bunker://')
@@ -73,10 +72,17 @@ async function upload (args, dotenvState) {
73
72
  })
74
73
  } else {
75
74
  const { default: NostrSigner } = await import('#services/nostr-signer.js')
76
- signer = await NostrSigner.create(sk)
75
+ signer = await NostrSigner.create(sk, {
76
+ deferInitialization: true,
77
+ dotenvFilePath: dotenvState.filePath
78
+ })
77
79
  }
78
80
 
79
81
  try {
82
+ args.npub = npubEncode(await signer.getPublicKey())
83
+ if (!await confirmArgs(args)) return
84
+ await signer.initialize?.()
85
+ const fileList = await toFileList(getFiles(dir), dir)
80
86
  const { default: toApp } = await import('#index.js')
81
87
  await toApp(fileList, signer, { log: console.log.bind(console), dTag, channel, shouldReupload })
82
88
  } finally {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/44billion/nappup.git"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "2.3.1",
9
+ "version": "2.3.2",
10
10
  "description": "Nostr App Uploader",
11
11
  "type": "module",
12
12
  "scripts": {
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import NMMR from 'nmmr'
2
- import { appEncode, npubEncode } from 'libp2r2p/nip19'
2
+ import { appEncode } from 'libp2r2p/nip19'
3
3
  import nostrRelays from '#services/nostr-relays.js'
4
4
  import { getRelays } from '#helpers/signer.js'
5
5
  import { streamToChunks, streamToText } from '#helpers/stream.js'
@@ -79,8 +79,7 @@ export async function toApp (fileList, nostrSigner, {
79
79
 
80
80
  const writeRelays = [...new Set((await nostrSigner.getRelays()).write
81
81
  .map(relay => relay.trim().replace(/\/$/, '')))]
82
- const npub = npubEncode(await nostrSigner.getPublicKey())
83
- log(`Found ${writeRelays.length} outbox relays for pubkey ${npub}:\n${writeRelays.join(', ')}`)
82
+ log(`Found ${writeRelays.length} outbox relays:\n${writeRelays.join(', ')}`)
84
83
  if (!writeRelays.length) throw new Error('No outbox relays found')
85
84
 
86
85
  if (typeof dTag === 'string') {
@@ -12,15 +12,19 @@ const createToken = Symbol('createToken')
12
12
  export default class NostrSigner {
13
13
  #secretKey // bytes
14
14
  #publicKey // hex
15
+ #needsInitialization
16
+ #dotenvFilePath
15
17
 
16
- constructor (token, skBytes) {
18
+ constructor (token, skBytes, { needsInitialization = false, dotenvFilePath } = {}) {
17
19
  if (token !== createToken) throw new Error('Use NostrSigner.create(?sk) to instantiate this class.')
18
20
  if (!skBytes) throw new Error('Secret key missing.')
19
21
 
20
22
  this.#secretKey = skBytes
23
+ this.#needsInitialization = needsInitialization
24
+ this.#dotenvFilePath = dotenvFilePath
21
25
  }
22
26
 
23
- static async create (sk) {
27
+ static async create (sk, { deferInitialization = false, dotenvFilePath } = {}) {
24
28
  if (sk) {
25
29
  if (sk.startsWith('nsec')) sk = nsecDecode(sk)
26
30
  return new this(createToken, base16ToBytes(sk))
@@ -37,13 +41,26 @@ export default class NostrSigner {
37
41
  } else {
38
42
  isNewSk = true
39
43
  skBytes = generateSecretKey()
40
- setEncryptedDotenvValue('NOSTR_SECRET_KEY', nsecEncode(bytesToBase16(skBytes)))
41
44
  }
42
- const ret = new this(createToken, skBytes)
43
- if (isNewSk) await ret.#initSk(sk)
45
+ const ret = new this(createToken, skBytes, {
46
+ needsInitialization: isNewSk,
47
+ dotenvFilePath
48
+ })
49
+ if (isNewSk && !deferInitialization) await ret.initialize()
44
50
  return ret
45
51
  }
46
52
 
53
+ async initialize () {
54
+ if (!this.#needsInitialization) return
55
+ setEncryptedDotenvValue(
56
+ 'NOSTR_SECRET_KEY',
57
+ nsecEncode(bytesToBase16(this.#secretKey)),
58
+ this.#dotenvFilePath ? { filePath: this.#dotenvFilePath } : undefined
59
+ )
60
+ this.#needsInitialization = false
61
+ await this.#initSk()
62
+ }
63
+
47
64
  async getRelays () {
48
65
  return getRelays.call(this)
49
66
  }