@multiplatform.one/web3 7.32.0 → 7.33.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.
Files changed (46) hide show
  1. package/README.md +21 -0
  2. package/dist/cjs/phantom/evm.cjs +133 -0
  3. package/dist/cjs/phantom/evm.native.js +269 -0
  4. package/dist/cjs/phantom/evm.native.js.map +1 -0
  5. package/dist/cjs/phantom/index.cjs +36 -0
  6. package/dist/cjs/phantom/index.native.js +39 -0
  7. package/dist/cjs/phantom/index.native.js.map +1 -0
  8. package/dist/cjs/phantom/urls.cjs +33 -0
  9. package/dist/cjs/phantom/urls.native.js +38 -0
  10. package/dist/cjs/phantom/urls.native.js.map +1 -0
  11. package/dist/esm/phantom/evm.mjs +103 -0
  12. package/dist/esm/phantom/evm.mjs.map +1 -0
  13. package/dist/esm/phantom/evm.native.js +236 -0
  14. package/dist/esm/phantom/evm.native.js.map +1 -0
  15. package/dist/esm/phantom/index.mjs +4 -0
  16. package/dist/esm/phantom/index.mjs.map +1 -0
  17. package/dist/esm/phantom/index.native.js +4 -0
  18. package/dist/esm/phantom/index.native.js.map +1 -0
  19. package/dist/esm/phantom/urls.mjs +7 -0
  20. package/dist/esm/phantom/urls.mjs.map +1 -0
  21. package/dist/esm/phantom/urls.native.js +9 -0
  22. package/dist/esm/phantom/urls.native.js.map +1 -0
  23. package/dist/jsx/phantom/evm.mjs +103 -0
  24. package/dist/jsx/phantom/evm.mjs.map +1 -0
  25. package/dist/jsx/phantom/evm.native.js +269 -0
  26. package/dist/jsx/phantom/evm.native.js.map +1 -0
  27. package/dist/jsx/phantom/index.mjs +4 -0
  28. package/dist/jsx/phantom/index.mjs.map +1 -0
  29. package/dist/jsx/phantom/index.native.js +39 -0
  30. package/dist/jsx/phantom/index.native.js.map +1 -0
  31. package/dist/jsx/phantom/urls.mjs +7 -0
  32. package/dist/jsx/phantom/urls.mjs.map +1 -0
  33. package/dist/jsx/phantom/urls.native.js +38 -0
  34. package/dist/jsx/phantom/urls.native.js.map +1 -0
  35. package/package.json +12 -6
  36. package/src/phantom/evm.spec.ts +195 -0
  37. package/src/phantom/evm.ts +163 -0
  38. package/src/phantom/index.ts +16 -0
  39. package/src/phantom/urls.spec.ts +29 -0
  40. package/src/phantom/urls.ts +16 -0
  41. package/types/phantom/evm.d.ts +76 -0
  42. package/types/phantom/evm.d.ts.map +1 -0
  43. package/types/phantom/index.d.ts +3 -0
  44. package/types/phantom/index.d.ts.map +1 -0
  45. package/types/phantom/urls.d.ts +11 -0
  46. package/types/phantom/urls.d.ts.map +1 -0
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var evm_exports = {};
26
+ __export(evm_exports, {
27
+ PhantomNotInjectedError: () => PhantomNotInjectedError,
28
+ connectPhantomEvm: () => connectPhantomEvm,
29
+ discoverPhantomEthereumProvider: () => discoverPhantomEthereumProvider,
30
+ openInPhantom: () => openInPhantom,
31
+ phantomEthereumProvider: () => phantomEthereumProvider,
32
+ phantomEvmRoute: () => phantomEvmRoute
33
+ });
34
+ module.exports = __toCommonJS(evm_exports);
35
+ var import_viem = require("viem");
36
+ var import_evm = require("../clients/evm.native.js");
37
+ var import_urls = require("./urls.native.js");
38
+ function _assert_this_initialized(self) {
39
+ if (self === void 0) {
40
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
41
+ }
42
+ return self;
43
+ }
44
+ function _call_super(_this, derived, args) {
45
+ derived = _get_prototype_of(derived);
46
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
47
+ }
48
+ function _class_call_check(instance, Constructor) {
49
+ if (!(instance instanceof Constructor)) {
50
+ throw new TypeError("Cannot call a class as a function");
51
+ }
52
+ }
53
+ function _construct(Parent, args, Class) {
54
+ if (_is_native_reflect_construct()) {
55
+ _construct = Reflect.construct;
56
+ } else {
57
+ _construct = function construct(Parent2, args2, Class2) {
58
+ var a = [null];
59
+ a.push.apply(a, args2);
60
+ var Constructor = Function.bind.apply(Parent2, a);
61
+ var instance = new Constructor();
62
+ if (Class2) _set_prototype_of(instance, Class2.prototype);
63
+ return instance;
64
+ };
65
+ }
66
+ return _construct.apply(null, arguments);
67
+ }
68
+ function _get_prototype_of(o) {
69
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
70
+ return o2.__proto__ || Object.getPrototypeOf(o2);
71
+ };
72
+ return _get_prototype_of(o);
73
+ }
74
+ function _inherits(subClass, superClass) {
75
+ if (typeof superClass !== "function" && superClass !== null) {
76
+ throw new TypeError("Super expression must either be null or a function");
77
+ }
78
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
79
+ constructor: {
80
+ value: subClass,
81
+ writable: true,
82
+ configurable: true
83
+ }
84
+ });
85
+ if (superClass) _set_prototype_of(subClass, superClass);
86
+ }
87
+ function _is_native_function(fn) {
88
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
89
+ }
90
+ function _possible_constructor_return(self, call) {
91
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
92
+ return call;
93
+ }
94
+ return _assert_this_initialized(self);
95
+ }
96
+ function _set_prototype_of(o, p) {
97
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
98
+ o2.__proto__ = p2;
99
+ return o2;
100
+ };
101
+ return _set_prototype_of(o, p);
102
+ }
103
+ function _type_of(obj) {
104
+ "@swc/helpers - typeof";
105
+
106
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
107
+ }
108
+ function _wrap_native_super(Class) {
109
+ var _cache = typeof Map === "function" ? /* @__PURE__ */new Map() : void 0;
110
+ _wrap_native_super = function wrapNativeSuper(Class2) {
111
+ if (Class2 === null || !_is_native_function(Class2)) return Class2;
112
+ if (typeof Class2 !== "function") {
113
+ throw new TypeError("Super expression must either be null or a function");
114
+ }
115
+ if (typeof _cache !== "undefined") {
116
+ if (_cache.has(Class2)) return _cache.get(Class2);
117
+ _cache.set(Class2, Wrapper);
118
+ }
119
+ function Wrapper() {
120
+ return _construct(Class2, arguments, _get_prototype_of(this).constructor);
121
+ }
122
+ Wrapper.prototype = Object.create(Class2.prototype, {
123
+ constructor: {
124
+ value: Wrapper,
125
+ enumerable: false,
126
+ writable: true,
127
+ configurable: true
128
+ }
129
+ });
130
+ return _set_prototype_of(Wrapper, Class2);
131
+ };
132
+ return _wrap_native_super(Class);
133
+ }
134
+ function _is_native_reflect_construct() {
135
+ try {
136
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
137
+ } catch (_) {}
138
+ return (_is_native_reflect_construct = function () {
139
+ return !!result;
140
+ })();
141
+ }
142
+ var phantomRdns = "app.phantom";
143
+ function phantomEthereumProvider() {
144
+ var win = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : globalThis;
145
+ var _win_phantom, _win_ethereum;
146
+ var own = (_win_phantom = win.phantom) === null || _win_phantom === void 0 ? void 0 : _win_phantom.ethereum;
147
+ if (own === null || own === void 0 ? void 0 : own.isPhantom) return own;
148
+ if ((_win_ethereum = win.ethereum) === null || _win_ethereum === void 0 ? void 0 : _win_ethereum.isPhantom) return win.ethereum;
149
+ return void 0;
150
+ }
151
+ function discoverPhantomEthereumProvider() {
152
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
153
+ var _options_window;
154
+ var win = (_options_window = options.window) !== null && _options_window !== void 0 ? _options_window : globalThis;
155
+ var found = phantomEthereumProvider(win);
156
+ if (found || !win.addEventListener || !win.dispatchEvent) return Promise.resolve(found);
157
+ return new Promise(function (resolve) {
158
+ var _options_timeout;
159
+ var _win_addEventListener, _win_dispatchEvent;
160
+ var onAnnounce = function onAnnounce2(event) {
161
+ var _detail_info;
162
+ var detail = event.detail;
163
+ if ((detail === null || detail === void 0 ? void 0 : (_detail_info = detail.info) === null || _detail_info === void 0 ? void 0 : _detail_info.rdns) !== phantomRdns || !detail.provider) return;
164
+ done(detail.provider);
165
+ };
166
+ var timer = setTimeout(function () {
167
+ return done(phantomEthereumProvider(win));
168
+ }, (_options_timeout = options.timeout) !== null && _options_timeout !== void 0 ? _options_timeout : 500);
169
+ var done = function done2(provider) {
170
+ var _win_removeEventListener;
171
+ clearTimeout(timer);
172
+ (_win_removeEventListener = win.removeEventListener) === null || _win_removeEventListener === void 0 ? void 0 : _win_removeEventListener.call(win, "eip6963:announceProvider", onAnnounce);
173
+ resolve(provider);
174
+ };
175
+ (_win_addEventListener = win.addEventListener) === null || _win_addEventListener === void 0 ? void 0 : _win_addEventListener.call(win, "eip6963:announceProvider", onAnnounce);
176
+ (_win_dispatchEvent = win.dispatchEvent) === null || _win_dispatchEvent === void 0 ? void 0 : _win_dispatchEvent.call(win, new Event("eip6963:requestProvider"));
177
+ });
178
+ }
179
+ function phantomEvmRoute() {
180
+ var win = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : globalThis;
181
+ return phantomEthereumProvider(win) ? "injected" : "browse";
182
+ }
183
+ function openInPhantom() {
184
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
185
+ var _options_window, _options_url, _ref, _options_ref, _options_navigate;
186
+ var _win_location, _win_location1;
187
+ var win = (_options_window = options.window) !== null && _options_window !== void 0 ? _options_window : globalThis;
188
+ var url = (_options_url = options.url) !== null && _options_url !== void 0 ? _options_url : (_win_location = win.location) === null || _win_location === void 0 ? void 0 : _win_location.href;
189
+ var ref = (_ref = (_options_ref = options.ref) !== null && _options_ref !== void 0 ? _options_ref : (_win_location1 = win.location) === null || _win_location1 === void 0 ? void 0 : _win_location1.origin) !== null && _ref !== void 0 ? _ref : url;
190
+ if (!url || !ref) throw new Error("openInPhantom: no page URL here; pass `url` and `ref`");
191
+ var link = (0, import_urls.phantomBrowseUrl)(url, ref, {
192
+ base: options.base
193
+ });
194
+ ((_options_navigate = options.navigate) !== null && _options_navigate !== void 0 ? _options_navigate : function (target) {
195
+ var _win_location2;
196
+ return (_win_location2 = win.location) === null || _win_location2 === void 0 ? void 0 : _win_location2.assign(target);
197
+ })(link);
198
+ return link;
199
+ }
200
+ var PhantomNotInjectedError = /* @__PURE__ */function (Error1) {
201
+ "use strict";
202
+
203
+ _inherits(PhantomNotInjectedError2, Error1);
204
+ function PhantomNotInjectedError2() {
205
+ _class_call_check(this, PhantomNotInjectedError2);
206
+ var _this;
207
+ _this = _call_super(this, PhantomNotInjectedError2, ["Phantom's EVM provider is not on this page: on a phone, reopen it in Phantom with openInPhantom()"]);
208
+ _this.name = "PhantomNotInjectedError";
209
+ return _this;
210
+ }
211
+ return PhantomNotInjectedError2;
212
+ }(_wrap_native_super(Error));
213
+ var errorCode = function errorCode2(error) {
214
+ var _ref;
215
+ var _error_cause;
216
+ return (_ref = error === null || error === void 0 ? void 0 : error.code) !== null && _ref !== void 0 ? _ref : error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.code;
217
+ };
218
+ async function ensureChain(provider, chain) {
219
+ var current = await provider.request({
220
+ method: "eth_chainId"
221
+ });
222
+ if (Number(current) === chain.id) return;
223
+ var chainId = (0, import_viem.numberToHex)(chain.id);
224
+ try {
225
+ await provider.request({
226
+ method: "wallet_switchEthereumChain",
227
+ params: [{
228
+ chainId
229
+ }]
230
+ });
231
+ } catch (error) {
232
+ if (errorCode(error) !== 4902) throw error;
233
+ await provider.request({
234
+ method: "wallet_addEthereumChain",
235
+ params: [{
236
+ chainId,
237
+ chainName: chain.name,
238
+ nativeCurrency: chain.nativeCurrency,
239
+ rpcUrls: [...chain.rpcUrls.default.http],
240
+ blockExplorerUrls: chain.blockExplorers ? [chain.blockExplorers.default.url] : void 0
241
+ }]
242
+ });
243
+ await provider.request({
244
+ method: "wallet_switchEthereumChain",
245
+ params: [{
246
+ chainId
247
+ }]
248
+ });
249
+ }
250
+ }
251
+ async function connectPhantomEvm(options) {
252
+ var _options_provider;
253
+ var provider = (_options_provider = options.provider) !== null && _options_provider !== void 0 ? _options_provider : phantomEthereumProvider();
254
+ if (!provider) throw new PhantomNotInjectedError();
255
+ var accounts = await provider.request({
256
+ method: "eth_requestAccounts"
257
+ });
258
+ var account = accounts[0];
259
+ if (!account) throw new Error("Phantom returned no EVM account");
260
+ await ensureChain(provider, options.chain);
261
+ return (0, import_evm.evmClient)({
262
+ provider,
263
+ account,
264
+ chain: options.chain,
265
+ publicClient: options.publicClient,
266
+ rpcUrl: options.rpcUrl
267
+ });
268
+ }
269
+ //# sourceMappingURL=evm.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","evm_exports","PhantomNotInjectedError","connectPhantomEvm","discoverPhantomEthereumProvider","openInPhantom","phantomEthereumProvider","phantomEvmRoute","module","exports","import_viem","require","import_evm","import_urls","_assert_this_initialized","self","ReferenceError","_call_super","_this","derived","args","_get_prototype_of","_possible_constructor_return","_is_native_reflect_construct","Reflect","construct","constructor","apply","_class_call_check","instance","Constructor","TypeError","_construct","Parent","Class","Parent2","args2","Class2","a","push","Function","bind","_set_prototype_of","arguments","o","setPrototypeOf","getPrototypeOf","o2","__proto__","_inherits","subClass","superClass","create","writable","configurable","_is_native_function","fn","toString","indexOf","_type_of"],"sources":["../../../src/phantom/evm.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAS;;AACT,IAAAA,SAAS,GAAAC,MAAA,CAAAC,cAAiC;AAC1C,IAAAC,gBAAS,GAAAF,MAAA,CAAAG,wBAAwB;AAajC,IAAAC,iBAAoB,GAAAJ,MAAA,CAAAK,mBAAA;AAOb,IAAAC,YAAS,GAAAN,MAAA,CAAAO,SACd,CAAAC,cAAqB;AAErB,IAAAC,QAAM,GAAMA,CAAAC,MAAI,EAAAC,GAAS;EACzB,KAAI,IAAKC,IAAA,IAAAD,GAAW,EACpBZ,SAAQ,CAAAW,MAAU,EAAAE,IAAA;IAAWC,GAAA,EAAAF,GAAO,CAAAC,IAAI;IAAAE,UAAA;EAAA;AACxC;AACF,IAAAC,WAAA,GAAAA,CAAAC,EAAA,EAAAC,IAAA,EAAAC,MAAA,EAAAC,IAAA;EAOO,IAAAF,IAAS,WAAAA,IAAA,iBACd,OAAAA,IAAyD,KACX;IAC9C,KAAM,IAAAG,GAAM,IAAAhB,iBAAmB,CAAAa,IAAA,GAC/B,IAAM,CAAAX,YAAQ,CAAAe,IAAA,CAAAL,EAAA,EAAAI,GAAA,KAAwBA,GAAG,KAAAF,MAAA,EACrCnB,SAAU,CAAAiB,EAAI,EAAAI,GAAA;MAAAP,GAAA,EAAAA,CAAA,KAAoBI,IAAC,CAAIG,GAAA;MAAAN,UAAe,IAAAK,IAAO,GAAAjB,gBAAqB,CAAAe,IAAA,EAAAG,GAAA,MAAAD,IAAA,CAAAL;IAAA;EACtF;EACE,OAAAE,EAAM;AACJ;AAGA,IAAAM,YAAI,GAAQC,GAAA,IAAMR,WAAS,CAAAhB,SAAgB,iBAAiB;EAAAyB,KAAA;AAAA,I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AAA;EACH","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import { connectPhantomEvm, discoverPhantomEthereumProvider, openInPhantom, phantomEthereumProvider, phantomEvmRoute, PhantomNotInjectedError } from "./evm.mjs";
2
+ import { phantomBrowseUrl, phantomUniversalLinkBase } from "./urls.mjs";
3
+ export { PhantomNotInjectedError, connectPhantomEvm, discoverPhantomEthereumProvider, openInPhantom, phantomBrowseUrl, phantomEthereumProvider, phantomEvmRoute, phantomUniversalLinkBase };
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["connectPhantomEvm","discoverPhantomEthereumProvider","openInPhantom","phantomEthereumProvider","phantomEvmRoute","PhantomNotInjectedError","phantomBrowseUrl","phantomUniversalLinkBase"],"sources":["../../../src/phantom/index.ts"],"sourcesContent":[null],"mappings":"AAIA,SACEA,iBAAA,EACAC,+BAAA,EACAC,aAAA,EACAC,uBAAA,EACAC,eAAA,EACAC,uBAAA,QAIK;AACP,SAASC,gBAAA,EAAkBC,wBAAA,QAAgC","ignoreList":[]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var phantom_exports = {};
26
+ __export(phantom_exports, {
27
+ PhantomNotInjectedError: () => import_evm.PhantomNotInjectedError,
28
+ connectPhantomEvm: () => import_evm.connectPhantomEvm,
29
+ discoverPhantomEthereumProvider: () => import_evm.discoverPhantomEthereumProvider,
30
+ openInPhantom: () => import_evm.openInPhantom,
31
+ phantomBrowseUrl: () => import_urls.phantomBrowseUrl,
32
+ phantomEthereumProvider: () => import_evm.phantomEthereumProvider,
33
+ phantomEvmRoute: () => import_evm.phantomEvmRoute,
34
+ phantomUniversalLinkBase: () => import_urls.phantomUniversalLinkBase
35
+ });
36
+ module.exports = __toCommonJS(phantom_exports);
37
+ var import_evm = require("./evm.native.js");
38
+ var import_urls = require("./urls.native.js");
39
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable"],"sources":["../../../src/phantom/index.ts"],"sourcesContent":[null],"mappings":"AAIA;;AAAA,IACEA,SAAA,GAAAC,MAAA,CAAAC,cAAA;AAAA,IACAC,gBAAA,GAAAF,MAAA,CAAAG,wBAAA;AAAA,IACAC,iBAAA,GAAAJ,MAAA,CAAAK,mBAAA;AAAA,IACAC,YAAA,GAAAN,MAAA,CAAAO,SAAA,CAAAC,cAAA;AAAA,IACAC,QAAA,GAAAA,CAAAC,MAAA,EAAAC,GAAA;EACA,SAAAC,IAAA,IAAAD,GAAA,EAAAZ,SAIK,CAAAW,MAAA,EAAAE,IAAA;IAAAC,GAAA,EAAAF,GAAA,CAAAC,IAAA;IAAAE,UAAA;EAAA;AACP","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ const phantomUniversalLinkBase = "https://phantom.com/ul";
2
+ function phantomBrowseUrl(url, ref, options = {}) {
3
+ const base = (options.base ?? phantomUniversalLinkBase).replace(/\/+$/, "");
4
+ return `${base}/browse/${encodeURIComponent(url)}?ref=${encodeURIComponent(ref)}`;
5
+ }
6
+ export { phantomBrowseUrl, phantomUniversalLinkBase };
7
+ //# sourceMappingURL=urls.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["phantomUniversalLinkBase","phantomBrowseUrl","url","ref","options","base","replace","encodeURIComponent"],"sources":["../../../src/phantom/urls.ts"],"sourcesContent":[null],"mappings":"AACO,MAAMA,wBAAA,GAA2B;AAOjC,SAASC,iBACdC,GAAA,EACAC,GAAA,EACAC,OAAA,GAA6B,CAAC,GACtB;EACR,MAAMC,IAAA,IAAQD,OAAA,CAAQC,IAAA,IAAQL,wBAAA,EAA0BM,OAAA,CAAQ,QAAQ,EAAE;EAC1E,OAAO,GAAGD,IAAI,WAAWE,kBAAA,CAAmBL,GAAG,CAAC,QAAQK,kBAAA,CAAmBJ,GAAG,CAAC;AACjF","ignoreList":[]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var urls_exports = {};
26
+ __export(urls_exports, {
27
+ phantomBrowseUrl: () => phantomBrowseUrl,
28
+ phantomUniversalLinkBase: () => phantomUniversalLinkBase
29
+ });
30
+ module.exports = __toCommonJS(urls_exports);
31
+ var phantomUniversalLinkBase = "https://phantom.com/ul";
32
+ function phantomBrowseUrl(url, ref) {
33
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
34
+ var _options_base;
35
+ var base = ((_options_base = options.base) !== null && _options_base !== void 0 ? _options_base : phantomUniversalLinkBase).replace(/\/+$/, "");
36
+ return `${base}/browse/${encodeURIComponent(url)}?ref=${encodeURIComponent(ref)}`;
37
+ }
38
+ //# sourceMappingURL=urls.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty"],"sources":["../../../src/phantom/urls.ts"],"sourcesContent":[null],"mappings":"AACO,YAAM;;AAON,IAAAA,SAAS,GAAAC,MAAA,CAAAC,cAGd;AAEA,IAAAC,gBAAc,GAAAF,MAAQ,CAAAG,wBAAQ;AAC9B,IAAAC,iBAAc,GAAAJ,MAAW,CAAAK,mBAAuB;AAClD,IAAAC,YAAA,GAAAN,MAAA,CAAAO,SAAA,CAAAC,cAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/web3",
3
- "version": "7.32.0",
3
+ "version": "7.33.0",
4
4
  "description": "Web3 wallet integration for multiplatform.one ecosystem with ConnectKit and wagmi",
5
5
  "keywords": [
6
6
  "connectkit",
@@ -105,6 +105,12 @@
105
105
  "import": "./dist/esm/solana.mjs",
106
106
  "require": "./dist/cjs/solana.cjs"
107
107
  },
108
+ "./phantom": {
109
+ "source": "./src/phantom/index.ts",
110
+ "types": "./types/phantom/index.d.ts",
111
+ "import": "./dist/esm/phantom/index.mjs",
112
+ "require": "./dist/cjs/phantom/index.cjs"
113
+ },
108
114
  "./keycloak/login.iife.js": "./dist/keycloak/login.iife.js"
109
115
  },
110
116
  "publishConfig": {
@@ -114,10 +120,10 @@
114
120
  "@aave/account": "^0.2.0",
115
121
  "@coinbase/wallet-sdk": "^4.3.6",
116
122
  "@metamask/connect-evm": "^2.1.1",
117
- "@multiplatform.one/connectkit": "7.32.0",
118
- "@multiplatform.one/gpg": "7.32.0",
119
- "@multiplatform.one/platform": "7.32.0",
120
- "@multiplatform.one/theme": "7.32.0",
123
+ "@multiplatform.one/connectkit": "7.33.0",
124
+ "@multiplatform.one/gpg": "7.33.0",
125
+ "@multiplatform.one/platform": "7.33.0",
126
+ "@multiplatform.one/theme": "7.33.0",
121
127
  "@noble/curves": "^1.9.7",
122
128
  "@solana/kit": "^8.3.0",
123
129
  "@solana/wallet-adapter-base": "^0.9.27",
@@ -139,7 +145,7 @@
139
145
  "wagmi": "^3.7.1"
140
146
  },
141
147
  "devDependencies": {
142
- "@multiplatform.one/config": "7.32.0",
148
+ "@multiplatform.one/config": "7.33.0",
143
149
  "@tamagui/build": "2.7.6",
144
150
  "@tanstack/react-query": "^5.100.7",
145
151
  "@testing-library/jest-dom": "^6.9.1",
@@ -0,0 +1,195 @@
1
+ import { baseSepolia } from "viem/chains";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import {
4
+ connectPhantomEvm,
5
+ discoverPhantomEthereumProvider,
6
+ openInPhantom,
7
+ phantomEthereumProvider,
8
+ phantomEvmRoute,
9
+ PhantomNotInjectedError,
10
+ type PhantomEthereumProvider,
11
+ } from "./evm";
12
+
13
+ const account = "0x1111111111111111111111111111111111111111";
14
+
15
+ function fakeProvider(chainId: number, opts: { unknownChain?: boolean } = {}) {
16
+ let current = chainId;
17
+ let known = !opts.unknownChain;
18
+ const calls: { method: string; params?: unknown }[] = [];
19
+ const request = vi.fn(async ({ method, params }: { method: string; params?: unknown }) => {
20
+ calls.push({ method, params });
21
+ switch (method) {
22
+ case "eth_requestAccounts":
23
+ case "eth_accounts":
24
+ return [account];
25
+ case "eth_chainId":
26
+ return `0x${current.toString(16)}`;
27
+ case "wallet_switchEthereumChain": {
28
+ if (!known) throw Object.assign(new Error("Unrecognized chain"), { code: 4902 });
29
+ current = Number((params as [{ chainId: string }])[0].chainId);
30
+ return null;
31
+ }
32
+ case "wallet_addEthereumChain":
33
+ known = true;
34
+ return null;
35
+ default:
36
+ throw new Error(`unexpected ${method}`);
37
+ }
38
+ });
39
+ const provider = { isPhantom: true, request, on: vi.fn(), removeListener: vi.fn() };
40
+ return { provider: provider as unknown as PhantomEthereumProvider, calls };
41
+ }
42
+
43
+ describe("phantom evm", () => {
44
+ it("finds window.phantom.ethereum, then a Phantom window.ethereum, and nothing else", () => {
45
+ const own = { isPhantom: true } as unknown as PhantomEthereumProvider;
46
+ const other = { isMetaMask: true } as unknown as PhantomEthereumProvider;
47
+ expect(phantomEthereumProvider({ phantom: { ethereum: own }, ethereum: other })).toBe(own);
48
+ expect(phantomEthereumProvider({ ethereum: own })).toBe(own);
49
+ expect(phantomEthereumProvider({ ethereum: other })).toBeUndefined();
50
+ expect(phantomEvmRoute({ ethereum: other })).toBe("browse");
51
+ expect(phantomEvmRoute({ phantom: { ethereum: own } })).toBe("injected");
52
+ });
53
+
54
+ it("takes Phantom's EIP-6963 announcement", async () => {
55
+ const provider = { isPhantom: true } as unknown as PhantomEthereumProvider;
56
+ const target = new EventTarget();
57
+ target.addEventListener("eip6963:requestProvider", () => {
58
+ target.dispatchEvent(
59
+ Object.assign(new Event("eip6963:announceProvider"), {
60
+ detail: { info: { rdns: "io.metamask" }, provider: {} },
61
+ }),
62
+ );
63
+ target.dispatchEvent(
64
+ Object.assign(new Event("eip6963:announceProvider"), {
65
+ detail: { info: { rdns: "app.phantom" }, provider },
66
+ }),
67
+ );
68
+ });
69
+ const win = {
70
+ addEventListener: target.addEventListener.bind(target),
71
+ removeEventListener: target.removeEventListener.bind(target),
72
+ dispatchEvent: target.dispatchEvent.bind(target),
73
+ };
74
+ await expect(discoverPhantomEthereumProvider({ window: win as never })).resolves.toBe(provider);
75
+ });
76
+
77
+ it("resolves undefined when nothing announces", async () => {
78
+ const target = new EventTarget();
79
+ const win = {
80
+ addEventListener: target.addEventListener.bind(target),
81
+ removeEventListener: target.removeEventListener.bind(target),
82
+ dispatchEvent: target.dispatchEvent.bind(target),
83
+ };
84
+ await expect(
85
+ discoverPhantomEthereumProvider({ window: win as never, timeout: 5 }),
86
+ ).resolves.toBeUndefined();
87
+ });
88
+
89
+ it("opens this page in Phantom's browser synchronously", () => {
90
+ const assign = vi.fn();
91
+ const link = openInPhantom({
92
+ window: {
93
+ location: {
94
+ href: "https://dev.promanager.vip/u/buy?mobile=1",
95
+ origin: "https://dev.promanager.vip",
96
+ assign,
97
+ },
98
+ },
99
+ });
100
+ expect(link).toBe(
101
+ "https://phantom.com/ul/browse/https%3A%2F%2Fdev.promanager.vip%2Fu%2Fbuy%3Fmobile%3D1?ref=https%3A%2F%2Fdev.promanager.vip",
102
+ );
103
+ expect(assign).toHaveBeenCalledWith(link);
104
+ });
105
+
106
+ it("connects, switches to Base Sepolia, and returns a client on it", async () => {
107
+ const { provider, calls } = fakeProvider(1);
108
+ const client = await connectPhantomEvm({ chain: baseSepolia, provider });
109
+ expect(client.address.toLowerCase()).toBe(account);
110
+ expect(client.chainId).toBe(84532);
111
+ expect(calls.map((c) => c.method)).toEqual([
112
+ "eth_requestAccounts",
113
+ "eth_chainId",
114
+ "wallet_switchEthereumChain",
115
+ ]);
116
+ expect(calls[2].params).toEqual([{ chainId: "0x14a34" }]);
117
+ });
118
+
119
+ it("adds the chain when Phantom does not know it", async () => {
120
+ const { provider, calls } = fakeProvider(1, { unknownChain: true });
121
+ await connectPhantomEvm({ chain: baseSepolia, provider });
122
+ expect(calls.map((c) => c.method)).toEqual([
123
+ "eth_requestAccounts",
124
+ "eth_chainId",
125
+ "wallet_switchEthereumChain",
126
+ "wallet_addEthereumChain",
127
+ "wallet_switchEthereumChain",
128
+ ]);
129
+ expect((calls[3].params as [{ chainId: string; rpcUrls: string[] }])[0]).toMatchObject({
130
+ chainId: "0x14a34",
131
+ rpcUrls: [...baseSepolia.rpcUrls.default.http],
132
+ });
133
+ });
134
+
135
+ it("skips the switch when already on the chain", async () => {
136
+ const { provider, calls } = fakeProvider(84532);
137
+ await connectPhantomEvm({ chain: baseSepolia, provider });
138
+ expect(calls.map((c) => c.method)).toEqual(["eth_requestAccounts", "eth_chainId"]);
139
+ });
140
+
141
+ it("sends an ERC-20 transfer to Phantom as eth_sendTransaction", async () => {
142
+ const { provider } = fakeProvider(84532);
143
+ const sent: unknown[] = [];
144
+ const request = provider.request as unknown as ReturnType<typeof vi.fn>;
145
+ const base = request.getMockImplementation() as (a: {
146
+ method: string;
147
+ params?: unknown;
148
+ }) => Promise<unknown>;
149
+ request.mockImplementation(async (args: { method: string; params?: unknown }) => {
150
+ if (args.method === "eth_sendTransaction") {
151
+ sent.push(args.params);
152
+ return `0x${"ab".repeat(32)}`;
153
+ }
154
+ return base(args);
155
+ });
156
+ const client = await connectPhantomEvm({ chain: baseSepolia, provider });
157
+ const hash = await client.walletClient.writeContract({
158
+ address: "0xc6fe3521644e0f5439fe345f64d372cd6ed37491",
159
+ abi: [
160
+ {
161
+ type: "function",
162
+ name: "transfer",
163
+ stateMutability: "nonpayable",
164
+ inputs: [
165
+ { name: "to", type: "address" },
166
+ { name: "amount", type: "uint256" },
167
+ ],
168
+ outputs: [{ type: "bool" }],
169
+ },
170
+ ],
171
+ functionName: "transfer",
172
+ args: ["0x2222222222222222222222222222222222222222", 10n ** 18n],
173
+ gas: 100000n,
174
+ });
175
+ expect(hash).toBe(`0x${"ab".repeat(32)}`);
176
+ expect(sent[0]).toEqual([
177
+ expect.objectContaining({
178
+ from: account,
179
+ to: "0xc6fe3521644e0f5439fe345f64d372cd6ed37491",
180
+ data: expect.stringMatching(/^0xa9059cbb0{24}2{40}/),
181
+ }),
182
+ ]);
183
+ });
184
+
185
+ it("says to reopen in Phantom when nothing is injected", async () => {
186
+ vi.stubGlobal("phantom", undefined);
187
+ try {
188
+ await expect(connectPhantomEvm({ chain: baseSepolia })).rejects.toBeInstanceOf(
189
+ PhantomNotInjectedError,
190
+ );
191
+ } finally {
192
+ vi.unstubAllGlobals();
193
+ }
194
+ });
195
+ });