nappup 2.3.0 → 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.
- package/bin/nappup/helpers.js +12 -6
- package/bin/nappup/index.js +9 -3
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/services/nostr-signer.js +22 -5
package/bin/nappup/helpers.js
CHANGED
|
@@ -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
|
-
|
|
165
|
+
confirmationPrompt(args)
|
|
166
166
|
)
|
|
167
|
+
rl.close()
|
|
167
168
|
if (answer.toLowerCase() !== 'y') {
|
|
168
169
|
console.log('Operation cancelled by user.')
|
|
169
|
-
|
|
170
|
-
process.exit(0)
|
|
170
|
+
return false
|
|
171
171
|
}
|
|
172
|
-
|
|
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) {
|
|
@@ -188,10 +192,12 @@ export async function toFileList (filesIterator, dir) {
|
|
|
188
192
|
const fileList = []
|
|
189
193
|
for await (const f of filesIterator) {
|
|
190
194
|
const fileType = mime.lookup(f)
|
|
195
|
+
const { size } = await fs.promises.stat(f)
|
|
191
196
|
const file = {
|
|
192
197
|
stream: () => Readable.toWeb(fs.createReadStream(f)),
|
|
193
198
|
webkitRelativePath: path.relative(dir.replace(/\/[^/]*$/, ''), f),
|
|
194
|
-
type: fileType || (await fileTypeFromFile(f))?.mime || ''
|
|
199
|
+
type: fileType || (await fileTypeFromFile(f))?.mime || '',
|
|
200
|
+
size
|
|
195
201
|
}
|
|
196
202
|
fileList.push(file)
|
|
197
203
|
}
|
package/bin/nappup/index.js
CHANGED
|
@@ -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
package/src/index.js
CHANGED
|
@@ -79,7 +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
|
-
log(`Found ${writeRelays.length} outbox relays
|
|
82
|
+
log(`Found ${writeRelays.length} outbox relays:\n${writeRelays.join(', ')}`)
|
|
83
83
|
if (!writeRelays.length) throw new Error('No outbox relays found')
|
|
84
84
|
|
|
85
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
|
-
|
|
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
|
}
|