Use bare app name for NIP-46 in production builds #124

Merged
raucao merged 1 commits from chore/nostr_app_identity into master 2026-11-23 19:50:57 +00:00
2 changed files with 38 additions and 14 deletions

No files matched your search

+17 -11
View File
@@ -2,11 +2,12 @@
* How Marco describes itself to a NIP-46 remote signer.
*
* These fields are unauthenticated display hints: signers may show them, but
* must not use them for authorization. The origin is part of the app name
* because a signer's connection list usually renders only the app name and
* icon for a saved session; the canonical `url` is only visible on the
* approval screen (e.g. Amber >= 6.2.2). Without it, every Marco deployment
* would look like the same "Marco" session.
* must not use them for authorization. Outside of production builds the origin
* is part of the app name, so dev and self-hosted instances can be told apart
* in a signer's connection list. Production builds use the bare app name
* because signers truncate that label. The canonical `url` stays visible on
* the approval screen (e.g. Amber >= 6.2.2), so sessions remain identifiable
* there.
*/
/** Event kinds Marco signs, requested up front so signers can pre-approve them. */
@@ -20,19 +21,24 @@ export const MARCO_SIGNING_KINDS = [
/**
* Builds the NIP-46 client metadata for the given origin.
*
* The host (including a port) is part of the name, so self-hosted instances
* and dev servers are distinguishable in the signer app. The icon has to be
* an absolute https URL: signers fetch it from the user's device, so origins
* the device cannot reach (localhost, LAN) show no icon.
* In non-production builds the host (including a port) is part of the name,
* so self-hosted instances and dev servers are distinguishable in the signer
* app. Production builds use just "Marco". The icon has to be an absolute
* https URL: signers fetch it from the user's device, so origins the device
* cannot reach (localhost, LAN) show no icon.
*
* @param {string} [origin] Origin of the running app
* @param {{production?: boolean}} [options] Production flag, defaults to the build environment
* @returns {{name: string, url: string, image: string}}
*/
export function buildNostrAppMetadata(origin = window.location.origin) {
export function buildNostrAppMetadata(
origin = window.location.origin,
{ production = import.meta.env.PROD } = {}
) {
const { host, origin: canonicalOrigin } = new URL(origin);
return {
name: `Marco (${host})`,
name: production ? 'Marco' : `Marco (${host})`,
url: canonicalOrigin,
image: `${canonicalOrigin}/icons/icon-192.png`,
};
+21 -3
View File
@@ -11,7 +11,9 @@ import {
module('Unit | Utility | nostr-app-metadata', function () {
test('builds name, url and image from the origin', function (assert) {
const metadata = buildNostrAppMetadata('https://marco.kosmos.org');
const metadata = buildNostrAppMetadata('https://marco.kosmos.org', {
production: false,
});
assert.deepEqual(metadata, {
name: 'Marco (marco.kosmos.org)',
@@ -20,8 +22,22 @@ module('Unit | Utility | nostr-app-metadata', function () {
});
});
test('uses just the app name in production builds', function (assert) {
const metadata = buildNostrAppMetadata('https://marco.kosmos.org', {
production: true,
});
assert.deepEqual(metadata, {
name: 'Marco',
url: 'https://marco.kosmos.org',
image: 'https://marco.kosmos.org/icons/icon-192.png',
});
});
test('includes the port so self-hosted and dev instances differ', function (assert) {
const metadata = buildNostrAppMetadata('http://localhost:5173');
const metadata = buildNostrAppMetadata('http://localhost:5173', {
production: false,
});
assert.strictEqual(metadata.name, 'Marco (localhost:5173)');
assert.strictEqual(metadata.url, 'http://localhost:5173');
@@ -39,7 +55,9 @@ module('Unit | Utility | nostr-app-metadata', function () {
test('the connect URI carries the metadata and requested permissions', function (assert) {
const metadata = {
...buildNostrAppMetadata('https://marco.kosmos.org'),
...buildNostrAppMetadata('https://marco.kosmos.org', {
production: false,
}),
permissions:
NostrConnectSigner.buildSigningPermissions(MARCO_SIGNING_KINDS),
};