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.
88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { NostrConnectSigner } from 'applesauce-signers';
|
|
import {
|
|
createNostrConnectURI,
|
|
parseNostrConnectURI,
|
|
} from 'applesauce-signers/helpers/nostr-connect';
|
|
import {
|
|
buildNostrAppMetadata,
|
|
MARCO_SIGNING_KINDS,
|
|
} from 'marco/utils/nostr-app-metadata';
|
|
|
|
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', {
|
|
production: false,
|
|
});
|
|
|
|
assert.deepEqual(metadata, {
|
|
name: 'Marco (marco.kosmos.org)',
|
|
url: 'https://marco.kosmos.org',
|
|
image: 'https://marco.kosmos.org/icons/icon-192.png',
|
|
});
|
|
});
|
|
|
|
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', {
|
|
production: false,
|
|
});
|
|
|
|
assert.strictEqual(metadata.name, 'Marco (localhost:5173)');
|
|
assert.strictEqual(metadata.url, 'http://localhost:5173');
|
|
});
|
|
|
|
test('normalizes the origin', function (assert) {
|
|
const metadata = buildNostrAppMetadata('https://marco.kosmos.org/');
|
|
|
|
assert.strictEqual(metadata.url, 'https://marco.kosmos.org');
|
|
assert.strictEqual(
|
|
metadata.image,
|
|
'https://marco.kosmos.org/icons/icon-192.png'
|
|
);
|
|
});
|
|
|
|
test('the connect URI carries the metadata and requested permissions', function (assert) {
|
|
const metadata = {
|
|
...buildNostrAppMetadata('https://marco.kosmos.org', {
|
|
production: false,
|
|
}),
|
|
permissions:
|
|
NostrConnectSigner.buildSigningPermissions(MARCO_SIGNING_KINDS),
|
|
};
|
|
|
|
const uri = createNostrConnectURI({
|
|
client: 'a'.repeat(64),
|
|
connectSecret: 'test-secret',
|
|
relays: ['wss://relay.example'],
|
|
metadata,
|
|
});
|
|
const parsed = parseNostrConnectURI(uri);
|
|
|
|
assert.strictEqual(parsed.metadata.name, 'Marco (marco.kosmos.org)');
|
|
assert.strictEqual(parsed.metadata.url, 'https://marco.kosmos.org');
|
|
assert.strictEqual(
|
|
parsed.metadata.image,
|
|
'https://marco.kosmos.org/icons/icon-192.png'
|
|
);
|
|
assert.deepEqual(parsed.metadata.permissions, [
|
|
'get_public_key',
|
|
'sign_event:5',
|
|
'sign_event:360',
|
|
'sign_event:9734',
|
|
'sign_event:24242',
|
|
]);
|
|
});
|
|
});
|