rise-wallet 0.3.3 → 0.3.5

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.
@@ -224,6 +224,26 @@ export function iframe(options: iframe.Options = {}) {
224
224
  }
225
225
  })
226
226
 
227
+ // Safari ITP workaround: When accounts are set in the parent's store
228
+ // (after wallet_connect via popup), sync them to the iframe via postMessage.
229
+ // This is necessary because Safari's ITP partitions storage between windows
230
+ // opened from different origins, preventing the iframe from reading accounts
231
+ // stored by the popup even though they share the same origin.
232
+ if (UserAgent.isSafari()) {
233
+ internal.store.subscribe(
234
+ (state) => state.accounts,
235
+ (accounts, prevAccounts) => {
236
+ // Only sync when accounts are added (not when cleared)
237
+ if (accounts.length > 0 && prevAccounts.length === 0) {
238
+ messenger.send('__internal', {
239
+ accounts,
240
+ type: 'sync-accounts',
241
+ })
242
+ }
243
+ },
244
+ )
245
+ }
246
+
227
247
  let bodyStyle: CSSStyleDeclaration | null = null
228
248
 
229
249
  // store the opening element to restore the focus
@@ -988,16 +1008,21 @@ export function requiresConfirmation(
988
1008
  const { methodPolicies, targetOrigin } = options
989
1009
  const policy = methodPolicies?.find((x) => x.method === request.method)
990
1010
  if (!policy) return true
991
- if (policy.modes?.headless) {
1011
+ if (policy.modes && typeof policy.modes.headless === 'object') {
1012
+ if (
1013
+ policy.modes.headless.sameOrigin &&
1014
+ targetOrigin === window.location.origin
1015
+ )
1016
+ return false
992
1017
  if (
993
- typeof policy.modes.headless === 'object' &&
994
- ((policy.modes.headless.sameOrigin &&
995
- targetOrigin === window.location.origin) ||
996
- policy.modes.headless.privilegedOrigins?.some((origin) =>
997
- window.location.origin.endsWith(origin),
998
- ))
1018
+ policy.modes.headless.privilegedOrigins?.some((origin) =>
1019
+ window.location.origin.endsWith(origin),
1020
+ )
999
1021
  )
1000
1022
  return false
1023
+ return true
1024
+ }
1025
+ if (policy.modes?.headless !== undefined) {
1001
1026
  return false
1002
1027
  }
1003
1028
  return true
@@ -118,6 +118,11 @@ export type Schema = [
118
118
  type: 'dialog-lifecycle'
119
119
  action: 'request:close' | 'done:close'
120
120
  }
121
+ | {
122
+ // Sync accounts from popup to iframe (Safari ITP workaround)
123
+ type: 'sync-accounts'
124
+ accounts: Porto.State['accounts']
125
+ }
121
126
  response: undefined
122
127
  },
123
128
  ]
@@ -176,10 +181,8 @@ export function fromWindow(
176
181
  },
177
182
  async send(topic, payload, target) {
178
183
  const id = Utils.uuidv4()
179
- w.postMessage(
180
- Utils.normalizeValue({ id, payload, topic }),
181
- target ?? targetOrigin ?? '*',
182
- )
184
+ const normalizedPayload = Utils.normalizeValue({ id, payload, topic })
185
+ w.postMessage(normalizedPayload, target ?? targetOrigin ?? '*')
183
186
  return { id, payload, topic } as never
184
187
  },
185
188
  async sendAsync(topic, payload, target) {
@@ -210,13 +213,15 @@ export function bridge(parameters: bridge.Parameters): Bridge {
210
213
  let pending = false
211
214
 
212
215
  const ready = promise.withResolvers<ReadyOptions>()
216
+ // Prevent unhandled rejection if ready is rejected during destroy
217
+ ready.promise.catch(() => {})
213
218
  from_.on('ready', ready.resolve)
214
219
 
215
220
  const messenger = from({
216
221
  destroy() {
217
222
  from_.destroy()
218
223
  to.destroy()
219
- if (pending) ready.reject()
224
+ if (pending) ready.reject(new Error('Messenger destroyed'))
220
225
  },
221
226
  on(topic, listener, id) {
222
227
  return from_.on(topic, listener, id)
@@ -975,7 +975,7 @@ export function dialog(parameters: dialog.Parameters = {}) {
975
975
  const requests = requestQueue
976
976
  .map((x) => (x.status === 'pending' ? x : undefined))
977
977
  .filter(Boolean) as readonly QueuedRequest[]
978
- dialog.syncRequests(requests).catch(() => {})
978
+ if (requests.length > 0) dialog.syncRequests(requests).catch(() => {})
979
979
  if (requests.length === 0) dialog.close()
980
980
  },
981
981
  )
@@ -15,6 +15,7 @@ import * as ContractActions from '../../../viem/ContractActions.js'
15
15
  import * as RelayActions_internal from '../../../viem/internal/relayActions.js'
16
16
  import * as Key from '../../../viem/Key.js'
17
17
  import * as RelayActions from '../../../viem/RelayActions.js'
18
+ import { localStorage } from '../../Storage.js'
18
19
  import * as Erc8010 from '../erc8010.js'
19
20
  import * as Mode from '../mode.js'
20
21
  import * as PermissionsRequest from '../permissionsRequest.js'
@@ -548,6 +549,7 @@ export function relay(parameters: relay.Parameters = {}) {
548
549
  return await Key.sign(adminKey, {
549
550
  address: account.address,
550
551
  payload: digest,
552
+ storage: localStorage(),
551
553
  })
552
554
  })()
553
555
 
@@ -563,6 +565,7 @@ export function relay(parameters: relay.Parameters = {}) {
563
565
  address: null,
564
566
  payload: digest,
565
567
  typedData,
568
+ verificationOptional: true,
566
569
  })
567
570
  await RelayActions.sendPreparedCalls(client, {
568
571
  context,
@@ -86,17 +86,16 @@ export function onDialogRequest(
86
86
  if (!request) return false
87
87
 
88
88
  const rule = policy?.modes?.headless
89
- if (rule) {
90
- if (
91
- typeof rule === 'object' &&
92
- ((rule.sameOrigin && event.origin === window.location.origin) ||
93
- rule.privilegedOrigins?.some((origin) =>
94
- event.origin.endsWith(origin),
95
- ))
96
- ) {
97
- return true
98
- }
99
- return true
89
+ if (typeof rule === 'object') {
90
+ return (
91
+ (rule.sameOrigin && event.origin === window.location.origin) ||
92
+ rule.privilegedOrigins?.some((origin) =>
93
+ event.origin.endsWith(origin),
94
+ )
95
+ )
96
+ }
97
+ if (rule !== undefined) {
98
+ return rule
100
99
  }
101
100
 
102
101
  return false