Remote signers truncate the app name in their connection list, and Amber turns the space in "Marco (host)" into a literal plus sign. Keep the host suffix only outside of production builds, where distinguishing dev and self-hosted instances is useful.
46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
/**
|
|
* 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. 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. */
|
|
export const MARCO_SIGNING_KINDS = [
|
|
5, // NIP-09 deletion (removing a photo)
|
|
360, // Place Photos
|
|
9734, // NIP-57 zap request
|
|
24242, // Blossom authorization (upload/delete)
|
|
];
|
|
|
|
/**
|
|
* Builds the NIP-46 client metadata for the given origin.
|
|
*
|
|
* 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,
|
|
{ production = import.meta.env.PROD } = {}
|
|
) {
|
|
const { host, origin: canonicalOrigin } = new URL(origin);
|
|
|
|
return {
|
|
name: production ? 'Marco' : `Marco (${host})`,
|
|
url: canonicalOrigin,
|
|
image: `${canonicalOrigin}/icons/icon-192.png`,
|
|
};
|
|
}
|