pakstr 0.13.3 ā 0.14.0
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/dist/commands/publish.js +32 -9
- package/dist/core/nostr.js +30 -0
- package/dist/core/zapStore.js +92 -0
- package/dist/core/zapstoreConfig.js +59 -1
- package/package.json +1 -1
package/dist/commands/publish.js
CHANGED
|
@@ -26,7 +26,15 @@ const zapstoreConfig_1 = require("../core/zapstoreConfig");
|
|
|
26
26
|
async function publishCommand(configPath, options = {}) {
|
|
27
27
|
const config = (0, pakstrConfig_1.loadPakstrConfig)(configPath);
|
|
28
28
|
const apkPath = path_1.default.resolve(config.build.out);
|
|
29
|
+
const zapstoreConfig = options.dryRun
|
|
30
|
+
? undefined
|
|
31
|
+
: (0, zapstoreConfig_1.loadZapstorePublisherConfig)(config.configDir);
|
|
29
32
|
const publishNsec = (0, zapStore_1.resolvePublishSecret)(config.publish.publishKey, process.env);
|
|
33
|
+
const pubkeyHex = await (0, nostr_1.getNpubHex)(publishNsec.bytes);
|
|
34
|
+
const npub = (0, nostr_1.pubkeyHexToNpub)(pubkeyHex);
|
|
35
|
+
if (zapstoreConfig && zapstoreConfig.pubkeyHex !== pubkeyHex) {
|
|
36
|
+
throw new Error(`Publisher npub mismatch: ${zapstoreConfig_1.ZAPSTORE_CONFIG_FILENAME} configures ${zapstoreConfig.pubkey}, but the active Pakstr signer is ${npub}`);
|
|
37
|
+
}
|
|
30
38
|
console.log("\nš¤ pakstr publish" + (options.dryRun ? " (dry-run)" : ""));
|
|
31
39
|
console.log("App:", config.app.appName, `(${config.app.appId})`);
|
|
32
40
|
console.log("Publishing as:", publishNsec.envVar);
|
|
@@ -39,7 +47,7 @@ async function publishCommand(configPath, options = {}) {
|
|
|
39
47
|
let filename = "";
|
|
40
48
|
let identityProof;
|
|
41
49
|
const transport = options.transport ?? (options.dryRun ? new zapStore_1.MockRelayTransport() : new zapStore_1.WebsocketRelayTransport());
|
|
42
|
-
const repository = (0, zapstoreConfig_1.loadZapstoreRepository)(config.configDir);
|
|
50
|
+
const repository = zapstoreConfig?.repository ?? (0, zapstoreConfig_1.loadZapstoreRepository)(config.configDir);
|
|
43
51
|
const app = {
|
|
44
52
|
appId: config.app.appId,
|
|
45
53
|
appName: config.app.appName,
|
|
@@ -79,10 +87,25 @@ async function publishCommand(configPath, options = {}) {
|
|
|
79
87
|
console.log(" Re-run `pakstr sign` with a publish nsec available to generate it.");
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
|
-
// Publish the application event first
|
|
83
|
-
//
|
|
90
|
+
// Publish the application event first when Zapstore does not already have
|
|
91
|
+
// the current metadata, preserving first-publish repository authorization.
|
|
84
92
|
const appPublish = await (0, zapStore_1.buildAppMetadataEvent)({ app, publishNsec, target });
|
|
85
|
-
|
|
93
|
+
const existingAppMetadata = options.dryRun
|
|
94
|
+
? undefined
|
|
95
|
+
: await (0, zapStore_1.findAppMetadataEvent)(transport, {
|
|
96
|
+
appId: app.appId,
|
|
97
|
+
pubkeyHex,
|
|
98
|
+
relayUrl: config.publish.relay,
|
|
99
|
+
});
|
|
100
|
+
const appMetadata = existingAppMetadata && (0, zapStore_1.isCurrentAppMetadataEvent)(existingAppMetadata, appPublish.appMetadata)
|
|
101
|
+
? existingAppMetadata
|
|
102
|
+
: appPublish.appMetadata;
|
|
103
|
+
if (appMetadata === appPublish.appMetadata) {
|
|
104
|
+
await transport.publish(appMetadata, config.publish.relay);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
console.log("š± Existing Zapstore application metadata is current; skipping kind 32267 publish.");
|
|
108
|
+
}
|
|
86
109
|
if (options.dryRun) {
|
|
87
110
|
// No network, no APK required. Synthesize a stub descriptor so the events
|
|
88
111
|
// can still be built and printed for preview.
|
|
@@ -97,7 +120,7 @@ async function publishCommand(configPath, options = {}) {
|
|
|
97
120
|
signature: "dry-run-stub==",
|
|
98
121
|
createdAt: Math.floor(Date.now() / 1000),
|
|
99
122
|
expiry: Math.floor(Date.now() / 1000) + 365 * 24 * 3600,
|
|
100
|
-
pubkeyHex
|
|
123
|
+
pubkeyHex,
|
|
101
124
|
};
|
|
102
125
|
console.log("š¦ (dry-run) Blossom URL:", blossomUrl);
|
|
103
126
|
}
|
|
@@ -133,14 +156,14 @@ async function publishCommand(configPath, options = {}) {
|
|
|
133
156
|
await transport.publish(releasePublish.identityProof, config.publish.relay);
|
|
134
157
|
}
|
|
135
158
|
const result = {
|
|
136
|
-
npub
|
|
137
|
-
pubkeyHex
|
|
138
|
-
appMetadataEventId:
|
|
159
|
+
npub,
|
|
160
|
+
pubkeyHex,
|
|
161
|
+
appMetadataEventId: appMetadata.id,
|
|
139
162
|
releaseEventId: releasePublish.release.id,
|
|
140
163
|
assetEventId: releasePublish.asset.id,
|
|
141
164
|
identityProofEventId: releasePublish.identityProof?.id,
|
|
142
165
|
events: {
|
|
143
|
-
appMetadata
|
|
166
|
+
appMetadata,
|
|
144
167
|
release: releasePublish.release,
|
|
145
168
|
asset: releasePublish.asset,
|
|
146
169
|
identityProof: releasePublish.identityProof,
|
package/dist/core/nostr.js
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NsecError = exports.NPUB_HRP = exports.NSEC_HRP = exports.PAKSTR_PUBLISH_NSEC_ENV = exports.PAKSTR_NSEC_ENV = void 0;
|
|
4
4
|
exports.decodeNsec = decodeNsec;
|
|
5
5
|
exports.encodeNsec = encodeNsec;
|
|
6
|
+
exports.decodeNpub = decodeNpub;
|
|
6
7
|
exports.encodeNpub = encodeNpub;
|
|
8
|
+
exports.npubToPubkeyHex = npubToPubkeyHex;
|
|
7
9
|
exports.requireSigningNsec = requireSigningNsec;
|
|
8
10
|
exports.resolvePublishNsec = resolvePublishNsec;
|
|
9
11
|
exports.isPublishNsecPresent = isPublishNsecPresent;
|
|
@@ -23,6 +25,7 @@ exports.PAKSTR_PUBLISH_NSEC_ENV = "PAKSTR_PUBLISH_NSEC";
|
|
|
23
25
|
exports.NSEC_HRP = "nsec";
|
|
24
26
|
exports.NPUB_HRP = "npub";
|
|
25
27
|
const NSEC_PAYLOAD_BYTES = 32;
|
|
28
|
+
const NPUB_PAYLOAD_BYTES = 32;
|
|
26
29
|
class NsecError extends Error {
|
|
27
30
|
envVar;
|
|
28
31
|
constructor(message, envVar) {
|
|
@@ -77,10 +80,37 @@ function encodeNsec(bytes) {
|
|
|
77
80
|
}
|
|
78
81
|
return base_1.bech32.encodeFromBytes(exports.NSEC_HRP, bytes);
|
|
79
82
|
}
|
|
83
|
+
/** Decode a Bech32 `npub1ā¦` string into 32 raw public-key bytes. */
|
|
84
|
+
function decodeNpub(value) {
|
|
85
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
86
|
+
throw new NsecError("npub is missing or empty");
|
|
87
|
+
}
|
|
88
|
+
if (value !== value.toLowerCase()) {
|
|
89
|
+
throw new NsecError("npub must be lowercase bech32");
|
|
90
|
+
}
|
|
91
|
+
let decoded;
|
|
92
|
+
try {
|
|
93
|
+
decoded = base_1.bech32.decodeToBytes(value);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new NsecError("npub is not valid bech32");
|
|
97
|
+
}
|
|
98
|
+
if (decoded.prefix !== exports.NPUB_HRP) {
|
|
99
|
+
throw new NsecError(`npub must use the "${exports.NPUB_HRP}" human-readable part`);
|
|
100
|
+
}
|
|
101
|
+
if (decoded.bytes.length !== NPUB_PAYLOAD_BYTES) {
|
|
102
|
+
throw new NsecError("npub payload must be exactly 32 bytes");
|
|
103
|
+
}
|
|
104
|
+
return decoded.bytes;
|
|
105
|
+
}
|
|
80
106
|
/** Encode 32 raw pubkey bytes as `npub1ā¦`. */
|
|
81
107
|
function encodeNpub(pubkey) {
|
|
82
108
|
return base_1.bech32.encodeFromBytes(exports.NPUB_HRP, pubkey);
|
|
83
109
|
}
|
|
110
|
+
/** Convert a bech32 npub to a lowercase hex public key. */
|
|
111
|
+
function npubToPubkeyHex(npub) {
|
|
112
|
+
return Buffer.from(decodeNpub(npub)).toString("hex");
|
|
113
|
+
}
|
|
84
114
|
/**
|
|
85
115
|
* Read and decode the signing nsec from `PAKSTR_NSEC`. Fails fast with a
|
|
86
116
|
* clear message if unset/empty/malformed. Never echoes the nsec value.
|
package/dist/core/zapStore.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MockRelayTransport = exports.WebsocketRelayTransport = exports.IDENTITY_PROOF_MESSAGE = exports.KIND_IDENTITY_PROOF = exports.KIND_ASSET = exports.KIND_RELEASE = exports.KIND_APP_METADATA = exports.DEFAULT_COMMUNITY = void 0;
|
|
4
4
|
exports.formatIdentityProofMessage = formatIdentityProofMessage;
|
|
5
|
+
exports.findAppMetadataEvent = findAppMetadataEvent;
|
|
6
|
+
exports.isCurrentAppMetadataEvent = isCurrentAppMetadataEvent;
|
|
5
7
|
exports.buildAppMetadataEvent = buildAppMetadataEvent;
|
|
6
8
|
exports.buildReleaseEvents = buildReleaseEvents;
|
|
7
9
|
exports.buildSignedPublishEvents = buildSignedPublishEvents;
|
|
8
10
|
exports.publishToZapStore = publishToZapStore;
|
|
9
11
|
exports.resolvePublishSecret = resolvePublishSecret;
|
|
10
12
|
exports.publishEventToRelay = publishEventToRelay;
|
|
13
|
+
exports.queryRelayForFilter = queryRelayForFilter;
|
|
11
14
|
exports.verifyPublish = verifyPublish;
|
|
12
15
|
exports.queryRelayForEvent = queryRelayForEvent;
|
|
13
16
|
const nostr_1 = require("./nostr");
|
|
@@ -38,6 +41,36 @@ function formatIdentityProofMessage(createdAt, expiry, pubkeyHex) {
|
|
|
38
41
|
const PLATFORM = "android-arm64-v8a";
|
|
39
42
|
const MIN_SDK = 28;
|
|
40
43
|
const TARGET_SDK = 36;
|
|
44
|
+
/** Query for this publisher's replaceable application event. */
|
|
45
|
+
async function findAppMetadataEvent(transport, input) {
|
|
46
|
+
if (!transport.query)
|
|
47
|
+
return undefined;
|
|
48
|
+
const event = await transport.query({
|
|
49
|
+
kinds: [exports.KIND_APP_METADATA],
|
|
50
|
+
authors: [input.pubkeyHex],
|
|
51
|
+
"#d": [input.appId],
|
|
52
|
+
limit: 1,
|
|
53
|
+
}, input.relayUrl);
|
|
54
|
+
if (!event)
|
|
55
|
+
return undefined;
|
|
56
|
+
const dTag = event.tags.find(tag => tag[0] === "d");
|
|
57
|
+
if (event.kind !== exports.KIND_APP_METADATA
|
|
58
|
+
|| event.pubkey !== input.pubkeyHex
|
|
59
|
+
|| dTag?.[1] !== input.appId) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return event;
|
|
63
|
+
}
|
|
64
|
+
/** Whether an existing replaceable application event contains the current metadata. */
|
|
65
|
+
function isCurrentAppMetadataEvent(existing, expected) {
|
|
66
|
+
if (existing.kind !== expected.kind
|
|
67
|
+
|| existing.pubkey !== expected.pubkey
|
|
68
|
+
|| existing.content !== expected.content) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return expected.tags.every(expectedTag => existing.tags.some(existingTag => existingTag.length === expectedTag.length
|
|
72
|
+
&& existingTag.every((value, index) => value === expectedTag[index])));
|
|
73
|
+
}
|
|
41
74
|
/** Build the kind-32267 application event independently of the APK upload. */
|
|
42
75
|
async function buildAppMetadataEvent(input) {
|
|
43
76
|
const pubkeyHex = await (0, nostr_1.getNpubHex)(input.publishNsec.bytes);
|
|
@@ -171,6 +204,9 @@ class WebsocketRelayTransport {
|
|
|
171
204
|
constructor(webSocketCtor) {
|
|
172
205
|
this.WebSocketCtor = (webSocketCtor ?? WebSocket);
|
|
173
206
|
}
|
|
207
|
+
async query(filter, relayUrl) {
|
|
208
|
+
return await queryRelayForFilter(this.WebSocketCtor, relayUrl, filter);
|
|
209
|
+
}
|
|
174
210
|
async publish(event, relayUrl) {
|
|
175
211
|
await publishEventToRelay(this.WebSocketCtor, event, relayUrl);
|
|
176
212
|
}
|
|
@@ -179,6 +215,9 @@ exports.WebsocketRelayTransport = WebsocketRelayTransport;
|
|
|
179
215
|
/** A no-op transport for tests / dry-runs (no network). */
|
|
180
216
|
class MockRelayTransport {
|
|
181
217
|
published = [];
|
|
218
|
+
async query(_filter, _relayUrl) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
182
221
|
async publish(event, _relayUrl) {
|
|
183
222
|
this.published.push(event);
|
|
184
223
|
}
|
|
@@ -232,6 +271,59 @@ function publishEventToRelay(WebSocketCtor, event, relayUrl, timeoutMs = 30000)
|
|
|
232
271
|
};
|
|
233
272
|
});
|
|
234
273
|
}
|
|
274
|
+
/** Query a relay for the first event matching a Nostr filter. */
|
|
275
|
+
function queryRelayForFilter(WebSocketCtor, relayUrl, filter, timeoutMs = 30000) {
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
let settled = false;
|
|
278
|
+
const subscriptionId = `pakstr-app-${Date.now().toString(36)}`;
|
|
279
|
+
const ws = new WebSocketCtor(relayUrl);
|
|
280
|
+
const finish = (event, error) => {
|
|
281
|
+
if (settled)
|
|
282
|
+
return;
|
|
283
|
+
settled = true;
|
|
284
|
+
clearTimeout(timer);
|
|
285
|
+
try {
|
|
286
|
+
ws.send(JSON.stringify(["CLOSE", subscriptionId]));
|
|
287
|
+
}
|
|
288
|
+
catch { /* ignore */ }
|
|
289
|
+
try {
|
|
290
|
+
ws.close();
|
|
291
|
+
}
|
|
292
|
+
catch { /* ignore */ }
|
|
293
|
+
if (error)
|
|
294
|
+
reject(error);
|
|
295
|
+
else
|
|
296
|
+
resolve(event);
|
|
297
|
+
};
|
|
298
|
+
const timer = setTimeout(() => {
|
|
299
|
+
finish(undefined, new Error(`Relay query timed out: ${relayUrl}`));
|
|
300
|
+
}, timeoutMs);
|
|
301
|
+
ws.onopen = () => {
|
|
302
|
+
ws.send(JSON.stringify(["REQ", subscriptionId, filter]));
|
|
303
|
+
};
|
|
304
|
+
ws.onmessage = (msg) => {
|
|
305
|
+
let data;
|
|
306
|
+
try {
|
|
307
|
+
data = JSON.parse(typeof msg.data === "string" ? msg.data : msg.data.toString());
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (!Array.isArray(data) || data[1] !== subscriptionId)
|
|
313
|
+
return;
|
|
314
|
+
if (data[0] === "EVENT" && data[2])
|
|
315
|
+
finish(data[2]);
|
|
316
|
+
else if (data[0] === "EOSE")
|
|
317
|
+
finish(undefined);
|
|
318
|
+
else if (data[0] === "CLOSED") {
|
|
319
|
+
finish(undefined, new Error(`Relay closed query: ${relayUrl} ${data[2] ?? "unknown"}`));
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
ws.onerror = (error) => {
|
|
323
|
+
finish(undefined, new Error(`Relay connection error: ${relayUrl} ${error?.message ?? ""}`));
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
}
|
|
235
327
|
/**
|
|
236
328
|
* Verify a publish by querying the relay for the asset event and confirming
|
|
237
329
|
* the APK is retrievable from Blossom. Returns true if both check out.
|
|
@@ -3,12 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ZAPSTORE_CONFIG_FILENAME = void 0;
|
|
6
|
+
exports.ZapstoreConfigError = exports.ZAPSTORE_CONFIG_FILENAME = void 0;
|
|
7
7
|
exports.loadZapstoreRepository = loadZapstoreRepository;
|
|
8
|
+
exports.loadZapstorePublisherConfig = loadZapstorePublisherConfig;
|
|
8
9
|
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
12
|
+
const nostr_1 = require("./nostr");
|
|
11
13
|
exports.ZAPSTORE_CONFIG_FILENAME = "zapstore.yaml";
|
|
14
|
+
class ZapstoreConfigError extends Error {
|
|
15
|
+
configPath;
|
|
16
|
+
constructor(message, configPath) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.configPath = configPath;
|
|
19
|
+
this.name = "ZapstoreConfigError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ZapstoreConfigError = ZapstoreConfigError;
|
|
12
23
|
/** Read the repository URL from the zapstore.yaml beside pakstr.yaml. */
|
|
13
24
|
function loadZapstoreRepository(configDir) {
|
|
14
25
|
const configPath = path_1.default.join(configDir, exports.ZAPSTORE_CONFIG_FILENAME);
|
|
@@ -20,3 +31,50 @@ function loadZapstoreRepository(configDir) {
|
|
|
20
31
|
return undefined;
|
|
21
32
|
return repository.trim();
|
|
22
33
|
}
|
|
34
|
+
/** Load and validate the Zapstore publisher configuration used for publication. */
|
|
35
|
+
function loadZapstorePublisherConfig(configDir) {
|
|
36
|
+
const configPath = path_1.default.join(configDir, exports.ZAPSTORE_CONFIG_FILENAME);
|
|
37
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
38
|
+
throw new ZapstoreConfigError(`Zapstore configuration not found: ${configPath}`, configPath);
|
|
39
|
+
}
|
|
40
|
+
let parsed;
|
|
41
|
+
try {
|
|
42
|
+
parsed = js_yaml_1.default.load(fs_1.default.readFileSync(configPath, "utf8"), { filename: configPath });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new ZapstoreConfigError(`Invalid ${exports.ZAPSTORE_CONFIG_FILENAME}: ${error instanceof Error ? error.message : String(error)}`, configPath);
|
|
46
|
+
}
|
|
47
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
48
|
+
throw new ZapstoreConfigError(`${exports.ZAPSTORE_CONFIG_FILENAME} must contain a YAML mapping`, configPath);
|
|
49
|
+
}
|
|
50
|
+
const config = parsed;
|
|
51
|
+
const repository = requireString(config.repository, "repository", configPath);
|
|
52
|
+
validateRepositoryUrl(repository, configPath);
|
|
53
|
+
const pubkey = requireString(config.pubkey, "pubkey", configPath);
|
|
54
|
+
let pubkeyHex;
|
|
55
|
+
try {
|
|
56
|
+
pubkeyHex = (0, nostr_1.npubToPubkeyHex)(pubkey);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw new ZapstoreConfigError(`Invalid publisher npub in ${exports.ZAPSTORE_CONFIG_FILENAME}: ${error instanceof Error ? error.message : String(error)}`, configPath);
|
|
60
|
+
}
|
|
61
|
+
return { repository, pubkey, pubkeyHex };
|
|
62
|
+
}
|
|
63
|
+
function requireString(value, field, configPath) {
|
|
64
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
65
|
+
throw new ZapstoreConfigError(`${exports.ZAPSTORE_CONFIG_FILENAME} is missing required field: ${field}`, configPath);
|
|
66
|
+
}
|
|
67
|
+
return value.trim();
|
|
68
|
+
}
|
|
69
|
+
function validateRepositoryUrl(repository, configPath) {
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = new URL(repository);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new ZapstoreConfigError(`${exports.ZAPSTORE_CONFIG_FILENAME} repository must be a valid absolute URL`, configPath);
|
|
76
|
+
}
|
|
77
|
+
if (!["https:", "http:", "ssh:"].includes(parsed.protocol) || !parsed.hostname) {
|
|
78
|
+
throw new ZapstoreConfigError(`${exports.ZAPSTORE_CONFIG_FILENAME} repository must use an http, https, or ssh URL with a host`, configPath);
|
|
79
|
+
}
|
|
80
|
+
}
|