@konemono/nostr-login 1.7.65 → 1.7.67

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.65",
3
+ "version": "1.7.67",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -173,6 +173,8 @@ export class NostrLoginInitializer {
173
173
  await this.extensionService.trySetExtensionForPubkey(info.pubkey);
174
174
  } else if (info.authMethod === 'connect' && info.sk && info.relays && info.relays[0]) {
175
175
  this.authNostrService.setConnect(info);
176
+ } else if (info.authMethod === ('amber' as any)) {
177
+ this.authNostrService.setAmber(info);
176
178
  } else {
177
179
  throw new Error('Bad auth info');
178
180
  }
@@ -307,7 +309,7 @@ export class NostrLoginInitializer {
307
309
  public setAuth = async (o: NostrLoginAuthOptions) => {
308
310
  if (!o.type) throw new Error('Invalid auth event');
309
311
  if (o.type !== 'login' && o.type !== 'logout' && o.type !== 'signup') throw new Error('Invalid auth event');
310
- if (o.method && o.method !== 'connect' && o.method !== 'extension' && o.method !== 'local' && o.method !== 'otp' && o.method !== 'readOnly')
312
+ if (o.method && o.method !== 'connect' && o.method !== 'extension' && o.method !== 'local' && o.method !== 'otp' && o.method !== 'readOnly' && o.method !== ('amber' as any))
311
313
  throw new Error('Invalid auth event');
312
314
 
313
315
  if (o.type === 'logout') return this.logout();
@@ -95,9 +95,9 @@ export class AmberDirectSigner implements Signer {
95
95
  const encodedContent = encodeURIComponent(content || '');
96
96
  const encodedCallback = encodeURIComponent(callbackUrl);
97
97
 
98
- sessionStorage.setItem('amber_last_type', type);
99
- sessionStorage.setItem('amber_last_id', id);
100
- sessionStorage.setItem('amber_last_timestamp', Date.now().toString());
98
+ localStorage.setItem('amber_last_type', type);
99
+ localStorage.setItem('amber_last_id', id);
100
+ localStorage.setItem('amber_last_timestamp', Date.now().toString());
101
101
 
102
102
  // NIP-55準拠: nostrsigner: スキーム
103
103
  let url = `nostrsigner:${encodedContent}`;
@@ -132,22 +132,24 @@ export class AmberDirectSigner implements Signer {
132
132
  }
133
133
  }
134
134
 
135
- console.log('Amber response detection:', {
136
- href: window.location.href,
137
- eventParam: url.searchParams.get('event'),
138
- pathResult: result,
139
- sessionId: sessionStorage.getItem('amber_last_id'),
140
- sessionType: sessionStorage.getItem('amber_last_type')
141
- });
135
+ if (result) {
136
+ console.log('Amber response detection:', {
137
+ href: window.location.href,
138
+ eventParam: url.searchParams.get('event'),
139
+ pathResult: result,
140
+ sessionId: localStorage.getItem('amber_last_id'),
141
+ sessionType: localStorage.getItem('amber_last_type')
142
+ });
143
+ }
142
144
 
143
145
  if (!result) return null;
144
146
 
145
- const id = sessionStorage.getItem('amber_last_id');
146
- const type = sessionStorage.getItem('amber_last_type');
147
+ const id = localStorage.getItem('amber_last_id');
148
+ const type = localStorage.getItem('amber_last_type');
147
149
 
148
- sessionStorage.removeItem('amber_last_id');
149
- sessionStorage.removeItem('amber_last_type');
150
- sessionStorage.removeItem('amber_last_timestamp');
150
+ localStorage.removeItem('amber_last_id');
151
+ localStorage.removeItem('amber_last_type');
152
+ localStorage.removeItem('amber_last_timestamp');
151
153
 
152
154
  if (id && type) {
153
155
  return { id, type, result };
@@ -130,10 +130,26 @@ class AuthNostrService extends EventEmitter implements Signer {
130
130
  // NIP-55では直接resultを使用するため、追加のキャッシュは不要
131
131
  }
132
132
 
133
- // ★ 追加: URLクエリパラメータをクリーンアップ
133
+ // ★ 追加: URLクリーンアップをより徹底的に
134
134
  const url = new URL(window.location.href);
135
- url.searchParams.delete('event');
136
- window.history.replaceState({}, '', url.toString());
135
+ let changed = false;
136
+ if (url.searchParams.has('event')) {
137
+ url.searchParams.delete('event');
138
+ changed = true;
139
+ }
140
+
141
+ // パス末尾が結果と一致する場合はパスもクリア
142
+ const pathParts = url.pathname.split('/');
143
+ if (pathParts.length > 0 && pathParts[pathParts.length - 1] === response.result) {
144
+ pathParts.pop();
145
+ url.pathname = pathParts.join('/') || '/';
146
+ changed = true;
147
+ }
148
+
149
+ if (changed) {
150
+ console.log('Cleaning up Amber response URL', url.toString());
151
+ window.history.replaceState({}, '', url.toString());
152
+ }
137
153
  }
138
154
  }
139
155