@onekeyfe/inpage-providers-hub 2.2.66 → 2.2.68-alpha.0

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.
@@ -22,39 +22,65 @@ function injectClipboardOverride($private) {
22
22
  if (typeof navigator === 'undefined')
23
23
  return;
24
24
  console.log('[OneKey] Clipboard override: initializing');
25
- const rememberedOrigins = new Set();
25
+ // First decision per (origin, type) sticks for the rest of the page session.
26
+ // Matches Chrome native UX: deny once → deny until reload. Read and write are
27
+ // keyed separately so "allow read" does not implicitly grant write.
28
+ const sessionDecisions = new Map();
29
+ // Coalesces concurrent requests so a burst of readText() calls only opens one
30
+ // modal. Without this, DApps that fire N synchronous readText() calls stack N
31
+ // modals before the first decision can land in sessionDecisions.
32
+ const pendingRequests = new Map();
26
33
  const clipboardProxy = {
27
34
  readText() {
28
35
  return __awaiter(this, void 0, void 0, function* () {
29
- var _a;
30
36
  console.log('[OneKey] Clipboard: readText() intercepted');
31
- if (rememberedOrigins.has(window.location.origin)) {
32
- console.log('[OneKey] Clipboard: readText() - origin remembered, using original API');
37
+ const key = `${window.location.origin}:read`;
38
+ const decision = sessionDecisions.get(key);
39
+ if (decision === 'deny') {
40
+ console.log('[OneKey] Clipboard: readText() - session-denied, short-circuit');
41
+ throw createNotAllowedError();
42
+ }
43
+ if (decision === 'allow') {
44
+ console.log('[OneKey] Clipboard: readText() - session-allowed, native API');
33
45
  if (!originalClipboard) {
34
46
  throw new DOMException('Clipboard API not available', 'NotSupportedError');
35
47
  }
36
48
  return originalClipboard.readText();
37
49
  }
50
+ const existing = pendingRequests.get(key);
51
+ if (existing) {
52
+ console.log('[OneKey] Clipboard: readText() - coalescing with in-flight');
53
+ return existing;
54
+ }
38
55
  console.log('[OneKey] Clipboard: readText() requesting permission');
39
- try {
40
- const result = yield $private.request({
41
- method: 'wallet_requestClipboardPermission',
42
- params: { type: 'read' },
43
- });
44
- console.log('[OneKey] Clipboard: readText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
45
- if (!(result === null || result === void 0 ? void 0 : result.allowed))
56
+ const promise = (() => __awaiter(this, void 0, void 0, function* () {
57
+ var _a;
58
+ try {
59
+ const result = yield $private.request({
60
+ method: 'wallet_requestClipboardPermission',
61
+ params: { type: 'read' },
62
+ });
63
+ console.log('[OneKey] Clipboard: readText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
64
+ const allowed = Boolean(result === null || result === void 0 ? void 0 : result.allowed);
65
+ sessionDecisions.set(key, allowed ? 'allow' : 'deny');
66
+ if (!allowed)
67
+ throw createNotAllowedError();
68
+ return (_a = result === null || result === void 0 ? void 0 : result.content) !== null && _a !== void 0 ? _a : '';
69
+ }
70
+ catch (e) {
71
+ if (!sessionDecisions.has(key)) {
72
+ sessionDecisions.set(key, 'deny');
73
+ }
74
+ if (e instanceof DOMException)
75
+ throw e;
46
76
  throw createNotAllowedError();
47
- if (result.remember) {
48
- rememberedOrigins.add(window.location.origin);
49
- console.log('[OneKey] Clipboard: origin remembered for this session');
50
77
  }
51
- return (_a = result.content) !== null && _a !== void 0 ? _a : '';
52
- }
53
- catch (e) {
54
- if (e instanceof DOMException)
55
- throw e;
56
- throw createNotAllowedError();
57
- }
78
+ }))();
79
+ pendingRequests.set(key, promise);
80
+ void promise.finally(() => {
81
+ pendingRequests.delete(key);
82
+ });
83
+ return promise;
58
84
  });
59
85
  },
60
86
  read() {
@@ -69,32 +95,51 @@ function injectClipboardOverride($private) {
69
95
  writeText(text) {
70
96
  return __awaiter(this, void 0, void 0, function* () {
71
97
  console.log('[OneKey] Clipboard: writeText() intercepted');
72
- if (rememberedOrigins.has(window.location.origin)) {
73
- console.log('[OneKey] Clipboard: writeText() - origin remembered, using original API');
98
+ const key = `${window.location.origin}:write`;
99
+ const decision = sessionDecisions.get(key);
100
+ if (decision === 'deny') {
101
+ console.log('[OneKey] Clipboard: writeText() - session-denied, short-circuit');
102
+ throw createNotAllowedError();
103
+ }
104
+ if (decision === 'allow') {
105
+ console.log('[OneKey] Clipboard: writeText() - session-allowed, native API');
74
106
  if (!originalClipboard) {
75
107
  throw new DOMException('Clipboard API not available', 'NotSupportedError');
76
108
  }
77
109
  return originalClipboard.writeText(text);
78
110
  }
111
+ const existing = pendingRequests.get(key);
112
+ if (existing) {
113
+ console.log('[OneKey] Clipboard: writeText() - coalescing with in-flight');
114
+ return existing;
115
+ }
79
116
  console.log('[OneKey] Clipboard: writeText() requesting permission');
80
- try {
81
- const result = yield $private.request({
82
- method: 'wallet_requestClipboardPermission',
83
- params: { type: 'write', text },
84
- });
85
- console.log('[OneKey] Clipboard: writeText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
86
- if (!(result === null || result === void 0 ? void 0 : result.allowed))
117
+ const promise = (() => __awaiter(this, void 0, void 0, function* () {
118
+ try {
119
+ const result = yield $private.request({
120
+ method: 'wallet_requestClipboardPermission',
121
+ params: { type: 'write', text },
122
+ });
123
+ console.log('[OneKey] Clipboard: writeText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
124
+ const allowed = Boolean(result === null || result === void 0 ? void 0 : result.allowed);
125
+ sessionDecisions.set(key, allowed ? 'allow' : 'deny');
126
+ if (!allowed)
127
+ throw createNotAllowedError();
128
+ }
129
+ catch (e) {
130
+ if (!sessionDecisions.has(key)) {
131
+ sessionDecisions.set(key, 'deny');
132
+ }
133
+ if (e instanceof DOMException)
134
+ throw e;
87
135
  throw createNotAllowedError();
88
- if (result.remember) {
89
- rememberedOrigins.add(window.location.origin);
90
- console.log('[OneKey] Clipboard: origin remembered for this session');
91
136
  }
92
- }
93
- catch (e) {
94
- if (e instanceof DOMException)
95
- throw e;
96
- throw createNotAllowedError();
97
- }
137
+ }))();
138
+ pendingRequests.set(key, promise);
139
+ void promise.finally(() => {
140
+ pendingRequests.delete(key);
141
+ });
142
+ return promise;
98
143
  });
99
144
  },
100
145
  write(data) {
@@ -19,39 +19,65 @@ export function injectClipboardOverride($private) {
19
19
  if (typeof navigator === 'undefined')
20
20
  return;
21
21
  console.log('[OneKey] Clipboard override: initializing');
22
- const rememberedOrigins = new Set();
22
+ // First decision per (origin, type) sticks for the rest of the page session.
23
+ // Matches Chrome native UX: deny once → deny until reload. Read and write are
24
+ // keyed separately so "allow read" does not implicitly grant write.
25
+ const sessionDecisions = new Map();
26
+ // Coalesces concurrent requests so a burst of readText() calls only opens one
27
+ // modal. Without this, DApps that fire N synchronous readText() calls stack N
28
+ // modals before the first decision can land in sessionDecisions.
29
+ const pendingRequests = new Map();
23
30
  const clipboardProxy = {
24
31
  readText() {
25
32
  return __awaiter(this, void 0, void 0, function* () {
26
- var _a;
27
33
  console.log('[OneKey] Clipboard: readText() intercepted');
28
- if (rememberedOrigins.has(window.location.origin)) {
29
- console.log('[OneKey] Clipboard: readText() - origin remembered, using original API');
34
+ const key = `${window.location.origin}:read`;
35
+ const decision = sessionDecisions.get(key);
36
+ if (decision === 'deny') {
37
+ console.log('[OneKey] Clipboard: readText() - session-denied, short-circuit');
38
+ throw createNotAllowedError();
39
+ }
40
+ if (decision === 'allow') {
41
+ console.log('[OneKey] Clipboard: readText() - session-allowed, native API');
30
42
  if (!originalClipboard) {
31
43
  throw new DOMException('Clipboard API not available', 'NotSupportedError');
32
44
  }
33
45
  return originalClipboard.readText();
34
46
  }
47
+ const existing = pendingRequests.get(key);
48
+ if (existing) {
49
+ console.log('[OneKey] Clipboard: readText() - coalescing with in-flight');
50
+ return existing;
51
+ }
35
52
  console.log('[OneKey] Clipboard: readText() requesting permission');
36
- try {
37
- const result = yield $private.request({
38
- method: 'wallet_requestClipboardPermission',
39
- params: { type: 'read' },
40
- });
41
- console.log('[OneKey] Clipboard: readText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
42
- if (!(result === null || result === void 0 ? void 0 : result.allowed))
53
+ const promise = (() => __awaiter(this, void 0, void 0, function* () {
54
+ var _a;
55
+ try {
56
+ const result = yield $private.request({
57
+ method: 'wallet_requestClipboardPermission',
58
+ params: { type: 'read' },
59
+ });
60
+ console.log('[OneKey] Clipboard: readText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
61
+ const allowed = Boolean(result === null || result === void 0 ? void 0 : result.allowed);
62
+ sessionDecisions.set(key, allowed ? 'allow' : 'deny');
63
+ if (!allowed)
64
+ throw createNotAllowedError();
65
+ return (_a = result === null || result === void 0 ? void 0 : result.content) !== null && _a !== void 0 ? _a : '';
66
+ }
67
+ catch (e) {
68
+ if (!sessionDecisions.has(key)) {
69
+ sessionDecisions.set(key, 'deny');
70
+ }
71
+ if (e instanceof DOMException)
72
+ throw e;
43
73
  throw createNotAllowedError();
44
- if (result.remember) {
45
- rememberedOrigins.add(window.location.origin);
46
- console.log('[OneKey] Clipboard: origin remembered for this session');
47
74
  }
48
- return (_a = result.content) !== null && _a !== void 0 ? _a : '';
49
- }
50
- catch (e) {
51
- if (e instanceof DOMException)
52
- throw e;
53
- throw createNotAllowedError();
54
- }
75
+ }))();
76
+ pendingRequests.set(key, promise);
77
+ void promise.finally(() => {
78
+ pendingRequests.delete(key);
79
+ });
80
+ return promise;
55
81
  });
56
82
  },
57
83
  read() {
@@ -66,32 +92,51 @@ export function injectClipboardOverride($private) {
66
92
  writeText(text) {
67
93
  return __awaiter(this, void 0, void 0, function* () {
68
94
  console.log('[OneKey] Clipboard: writeText() intercepted');
69
- if (rememberedOrigins.has(window.location.origin)) {
70
- console.log('[OneKey] Clipboard: writeText() - origin remembered, using original API');
95
+ const key = `${window.location.origin}:write`;
96
+ const decision = sessionDecisions.get(key);
97
+ if (decision === 'deny') {
98
+ console.log('[OneKey] Clipboard: writeText() - session-denied, short-circuit');
99
+ throw createNotAllowedError();
100
+ }
101
+ if (decision === 'allow') {
102
+ console.log('[OneKey] Clipboard: writeText() - session-allowed, native API');
71
103
  if (!originalClipboard) {
72
104
  throw new DOMException('Clipboard API not available', 'NotSupportedError');
73
105
  }
74
106
  return originalClipboard.writeText(text);
75
107
  }
108
+ const existing = pendingRequests.get(key);
109
+ if (existing) {
110
+ console.log('[OneKey] Clipboard: writeText() - coalescing with in-flight');
111
+ return existing;
112
+ }
76
113
  console.log('[OneKey] Clipboard: writeText() requesting permission');
77
- try {
78
- const result = yield $private.request({
79
- method: 'wallet_requestClipboardPermission',
80
- params: { type: 'write', text },
81
- });
82
- console.log('[OneKey] Clipboard: writeText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
83
- if (!(result === null || result === void 0 ? void 0 : result.allowed))
114
+ const promise = (() => __awaiter(this, void 0, void 0, function* () {
115
+ try {
116
+ const result = yield $private.request({
117
+ method: 'wallet_requestClipboardPermission',
118
+ params: { type: 'write', text },
119
+ });
120
+ console.log('[OneKey] Clipboard: writeText() permission result:', result === null || result === void 0 ? void 0 : result.allowed);
121
+ const allowed = Boolean(result === null || result === void 0 ? void 0 : result.allowed);
122
+ sessionDecisions.set(key, allowed ? 'allow' : 'deny');
123
+ if (!allowed)
124
+ throw createNotAllowedError();
125
+ }
126
+ catch (e) {
127
+ if (!sessionDecisions.has(key)) {
128
+ sessionDecisions.set(key, 'deny');
129
+ }
130
+ if (e instanceof DOMException)
131
+ throw e;
84
132
  throw createNotAllowedError();
85
- if (result.remember) {
86
- rememberedOrigins.add(window.location.origin);
87
- console.log('[OneKey] Clipboard: origin remembered for this session');
88
133
  }
89
- }
90
- catch (e) {
91
- if (e instanceof DOMException)
92
- throw e;
93
- throw createNotAllowedError();
94
- }
134
+ }))();
135
+ pendingRequests.set(key, promise);
136
+ void promise.finally(() => {
137
+ pendingRequests.delete(key);
138
+ });
139
+ return promise;
95
140
  });
96
141
  },
97
142
  write(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/inpage-providers-hub",
3
- "version": "2.2.66",
3
+ "version": "2.2.68-alpha.0",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -27,28 +27,28 @@
27
27
  "start": "tsc --watch"
28
28
  },
29
29
  "dependencies": {
30
- "@onekeyfe/cross-inpage-provider-core": "2.2.66",
31
- "@onekeyfe/cross-inpage-provider-types": "2.2.66",
32
- "@onekeyfe/onekey-algo-provider": "2.2.66",
33
- "@onekeyfe/onekey-alph-provider": "2.2.66",
34
- "@onekeyfe/onekey-aptos-provider": "2.2.66",
35
- "@onekeyfe/onekey-bfc-provider": "2.2.66",
36
- "@onekeyfe/onekey-btc-provider": "2.2.66",
37
- "@onekeyfe/onekey-cardano-provider": "2.2.66",
38
- "@onekeyfe/onekey-conflux-provider": "2.2.66",
39
- "@onekeyfe/onekey-cosmos-provider": "2.2.66",
40
- "@onekeyfe/onekey-eth-provider": "2.2.66",
41
- "@onekeyfe/onekey-neo-provider": "2.2.66",
42
- "@onekeyfe/onekey-nostr-provider": "2.2.66",
43
- "@onekeyfe/onekey-polkadot-provider": "2.2.66",
44
- "@onekeyfe/onekey-private-provider": "2.2.66",
45
- "@onekeyfe/onekey-scdo-provider": "2.2.66",
46
- "@onekeyfe/onekey-solana-provider": "2.2.66",
47
- "@onekeyfe/onekey-stellar-provider": "2.2.66",
48
- "@onekeyfe/onekey-sui-provider": "2.2.66",
49
- "@onekeyfe/onekey-ton-provider": "2.2.66",
50
- "@onekeyfe/onekey-tron-provider": "2.2.66",
51
- "@onekeyfe/onekey-webln-provider": "2.2.66",
30
+ "@onekeyfe/cross-inpage-provider-core": "2.2.68-alpha.0",
31
+ "@onekeyfe/cross-inpage-provider-types": "2.2.68-alpha.0",
32
+ "@onekeyfe/onekey-algo-provider": "2.2.68-alpha.0",
33
+ "@onekeyfe/onekey-alph-provider": "2.2.68-alpha.0",
34
+ "@onekeyfe/onekey-aptos-provider": "2.2.68-alpha.0",
35
+ "@onekeyfe/onekey-bfc-provider": "2.2.68-alpha.0",
36
+ "@onekeyfe/onekey-btc-provider": "2.2.68-alpha.0",
37
+ "@onekeyfe/onekey-cardano-provider": "2.2.68-alpha.0",
38
+ "@onekeyfe/onekey-conflux-provider": "2.2.68-alpha.0",
39
+ "@onekeyfe/onekey-cosmos-provider": "2.2.68-alpha.0",
40
+ "@onekeyfe/onekey-eth-provider": "2.2.68-alpha.0",
41
+ "@onekeyfe/onekey-neo-provider": "2.2.68-alpha.0",
42
+ "@onekeyfe/onekey-nostr-provider": "2.2.68-alpha.0",
43
+ "@onekeyfe/onekey-polkadot-provider": "2.2.68-alpha.0",
44
+ "@onekeyfe/onekey-private-provider": "2.2.68-alpha.0",
45
+ "@onekeyfe/onekey-scdo-provider": "2.2.68-alpha.0",
46
+ "@onekeyfe/onekey-solana-provider": "2.2.68-alpha.0",
47
+ "@onekeyfe/onekey-stellar-provider": "2.2.68-alpha.0",
48
+ "@onekeyfe/onekey-sui-provider": "2.2.68-alpha.0",
49
+ "@onekeyfe/onekey-ton-provider": "2.2.68-alpha.0",
50
+ "@onekeyfe/onekey-tron-provider": "2.2.68-alpha.0",
51
+ "@onekeyfe/onekey-webln-provider": "2.2.68-alpha.0",
52
52
  "cipher-base": "^1.0.6",
53
53
  "lodash-es": "^4.17.21",
54
54
  "preact": "^10.25.1"
@@ -57,5 +57,5 @@
57
57
  "@types/lodash-es": "^4.17.12",
58
58
  "@types/node": "^20.12.7"
59
59
  },
60
- "gitHead": "9d42482e04f7562926dca8a47ef1617e7f77a91e"
60
+ "gitHead": "7788c790f4d387ff754ba35114eaeaa7486211c3"
61
61
  }