@konemono/nostr-login 1.7.56 → 1.7.57

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.7.56",
3
+ "version": "1.7.57",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -119,14 +119,7 @@ export class AmberDirectSigner implements Signer {
119
119
  }
120
120
 
121
121
  private generateUrl(content: string, type: string, id: string, recipient?: string): string {
122
- const url = new URL(window.location.href);
123
- const searchParams = url.searchParams;
124
- searchParams.delete('amberType');
125
- searchParams.delete('amberId');
126
- searchParams.delete('signature');
127
- searchParams.delete('result');
128
- url.hash = ''; // Amber/Android may not handle hash in callbackUrl well
129
-
122
+ const url = new URL(window.location.origin + window.location.pathname);
130
123
  url.searchParams.set('amberType', type);
131
124
  url.searchParams.set('amberId', id);
132
125
 
@@ -134,38 +127,32 @@ export class AmberDirectSigner implements Signer {
134
127
  params.set('type', type);
135
128
  params.set('id', id);
136
129
  params.set('callbackUrl', url.toString());
137
- params.set('name', document.location.host);
130
+ params.set('name', document.title || window.location.hostname || 'Nostr Login');
138
131
  if (recipient) {
139
132
  params.set('pubkey', recipient);
140
133
  } else if (this._pubkey) {
141
134
  params.set('pubkey', this._pubkey);
142
135
  }
143
136
 
144
- return `nostrsigner:${encodeURIComponent(content)}?${params.toString()}`;
137
+ const dataPart = content ? encodeURIComponent(content) : '/';
138
+ return `nostrsigner:${dataPart}?${params.toString()}`;
145
139
  }
146
140
 
147
141
  public static parseResponse(): { type: string; id: string; result: string } | null {
148
- const params = new URLSearchParams(window.location.search);
149
- let type = params.get('amberType');
150
- let id = params.get('amberId');
151
- let result = params.get('signature') || params.get('result'); // Amber uses signature for events, result for others?
152
-
153
- // Also check hash
154
- if (!type || !id || !result) {
155
- const hashParams = new URLSearchParams(window.location.hash.substring(1));
156
- type = type || hashParams.get('amberType');
157
- id = id || hashParams.get('amberId');
158
- result = result || hashParams.get('signature') || hashParams.get('result');
159
- }
142
+ const url = new URL(window.location.href);
143
+ const params = new URLSearchParams(url.search);
144
+ const hashParams = new URLSearchParams(url.hash.substring(1));
145
+
146
+ let type = params.get('amberType') || hashParams.get('amberType');
147
+ let id = params.get('amberId') || hashParams.get('amberId');
148
+ let result = params.get('signature') || params.get('result') || params.get('pubKey') ||
149
+ hashParams.get('signature') || hashParams.get('result') || hashParams.get('pubKey');
160
150
 
161
151
  if (type && id && result) {
162
152
  // Clean up URL
163
153
  const newUrl = new URL(window.location.href);
164
- newUrl.searchParams.delete('amberType');
165
- newUrl.searchParams.delete('amberId');
166
- newUrl.searchParams.delete('signature');
167
- newUrl.searchParams.delete('result');
168
- newUrl.hash = ''; // Clear hash too
154
+ ['amberType', 'amberId', 'signature', 'result', 'pubKey'].forEach(p => newUrl.searchParams.delete(p));
155
+ newUrl.hash = '';
169
156
  window.history.replaceState({}, '', newUrl.toString());
170
157
 
171
158
  return { type, id, result };
@@ -86,9 +86,10 @@ class AuthNostrService extends EventEmitter implements Signer {
86
86
  decrypt: this.decrypt44.bind(this),
87
87
  };
88
88
 
89
- setTimeout(() => this.checkAmberResponse(), 500);
89
+ setTimeout(() => this.checkAmberResponse(), 100);
90
90
 
91
91
  window.addEventListener('focus', () => {
92
+ console.log('Window focused, checking Amber response');
92
93
  this.checkAmberResponse();
93
94
  });
94
95
  }
@@ -96,11 +97,13 @@ class AuthNostrService extends EventEmitter implements Signer {
96
97
  private checkAmberResponse() {
97
98
  const response = AmberDirectSigner.parseResponse();
98
99
  if (response) {
100
+ console.log('Amber response detected', response);
99
101
  if (response.type === 'get_public_key') {
100
102
  const info: Info = {
101
103
  pubkey: response.result,
102
104
  authMethod: 'amber' as any,
103
105
  };
106
+ console.log('Amber login success', info);
104
107
  this.onAuth('login', info);
105
108
  } else {
106
109
  const pendingKey = `amber_pending_${response.id}`;