@multiplatform.one/web3 7.33.1 → 7.34.1
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/README.md +24 -6
- package/dist/cjs/phantom/crypto.cjs +108 -0
- package/dist/cjs/phantom/crypto.native.js +224 -0
- package/dist/cjs/phantom/crypto.native.js.map +1 -0
- package/dist/cjs/phantom/index.cjs +16 -1
- package/dist/cjs/phantom/index.native.js +16 -1
- package/dist/cjs/phantom/index.native.js.map +1 -1
- package/dist/cjs/phantom/solana.cjs +309 -0
- package/dist/cjs/phantom/solana.native.js +466 -0
- package/dist/cjs/phantom/solana.native.js.map +1 -0
- package/dist/cjs/phantom/urls.cjs +68 -3
- package/dist/cjs/phantom/urls.native.js +92 -4
- package/dist/cjs/phantom/urls.native.js.map +1 -1
- package/dist/esm/phantom/crypto.mjs +67 -0
- package/dist/esm/phantom/crypto.mjs.map +1 -0
- package/dist/esm/phantom/crypto.native.js +180 -0
- package/dist/esm/phantom/crypto.native.js.map +1 -0
- package/dist/esm/phantom/index.mjs +4 -2
- package/dist/esm/phantom/index.mjs.map +1 -1
- package/dist/esm/phantom/index.native.js +4 -2
- package/dist/esm/phantom/index.native.js.map +1 -1
- package/dist/esm/phantom/solana.mjs +271 -0
- package/dist/esm/phantom/solana.mjs.map +1 -0
- package/dist/esm/phantom/solana.native.js +425 -0
- package/dist/esm/phantom/solana.native.js.map +1 -0
- package/dist/esm/phantom/urls.mjs +53 -3
- package/dist/esm/phantom/urls.mjs.map +1 -1
- package/dist/esm/phantom/urls.native.js +77 -4
- package/dist/esm/phantom/urls.native.js.map +1 -1
- package/dist/jsx/phantom/crypto.mjs +67 -0
- package/dist/jsx/phantom/crypto.mjs.map +1 -0
- package/dist/jsx/phantom/crypto.native.js +224 -0
- package/dist/jsx/phantom/crypto.native.js.map +1 -0
- package/dist/jsx/phantom/index.mjs +4 -2
- package/dist/jsx/phantom/index.mjs.map +1 -1
- package/dist/jsx/phantom/index.native.js +16 -1
- package/dist/jsx/phantom/index.native.js.map +1 -1
- package/dist/jsx/phantom/solana.mjs +271 -0
- package/dist/jsx/phantom/solana.mjs.map +1 -0
- package/dist/jsx/phantom/solana.native.js +466 -0
- package/dist/jsx/phantom/solana.native.js.map +1 -0
- package/dist/jsx/phantom/urls.mjs +53 -3
- package/dist/jsx/phantom/urls.mjs.map +1 -1
- package/dist/jsx/phantom/urls.native.js +92 -4
- package/dist/jsx/phantom/urls.native.js.map +1 -1
- package/package.json +7 -6
- package/src/phantom/crypto.spec.ts +61 -0
- package/src/phantom/crypto.ts +88 -0
- package/src/phantom/index.ts +38 -5
- package/src/phantom/solana.spec.ts +262 -0
- package/src/phantom/solana.ts +374 -0
- package/src/phantom/urls.spec.ts +101 -10
- package/src/phantom/urls.ts +119 -4
- package/types/phantom/crypto.d.ts +27 -0
- package/types/phantom/crypto.d.ts.map +1 -0
- package/types/phantom/index.d.ts +3 -1
- package/types/phantom/index.d.ts.map +1 -1
- package/types/phantom/solana.d.ts +113 -0
- package/types/phantom/solana.d.ts.map +1 -0
- package/types/phantom/urls.d.ts +46 -2
- package/types/phantom/urls.d.ts.map +1 -1
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
36
|
+
var solana_exports = {};
|
|
37
|
+
__export(solana_exports, {
|
|
38
|
+
PhantomNotConnectedError: () => PhantomNotConnectedError,
|
|
39
|
+
phantomDeeplink: () => phantomDeeplink,
|
|
40
|
+
sendSolanaTransaction: () => sendSolanaTransaction
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(solana_exports);
|
|
43
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
44
|
+
var import_crypto = require("./crypto.native.js");
|
|
45
|
+
var import_urls = require("./urls.native.js");
|
|
46
|
+
function _assert_this_initialized(self) {
|
|
47
|
+
if (self === void 0) {
|
|
48
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
49
|
+
}
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
function _call_super(_this, derived, args) {
|
|
53
|
+
derived = _get_prototype_of(derived);
|
|
54
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
55
|
+
}
|
|
56
|
+
function _class_call_check(instance, Constructor) {
|
|
57
|
+
if (!(instance instanceof Constructor)) {
|
|
58
|
+
throw new TypeError("Cannot call a class as a function");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function _construct(Parent, args, Class) {
|
|
62
|
+
if (_is_native_reflect_construct()) {
|
|
63
|
+
_construct = Reflect.construct;
|
|
64
|
+
} else {
|
|
65
|
+
_construct = function construct(Parent2, args2, Class2) {
|
|
66
|
+
var a = [null];
|
|
67
|
+
a.push.apply(a, args2);
|
|
68
|
+
var Constructor = Function.bind.apply(Parent2, a);
|
|
69
|
+
var instance = new Constructor();
|
|
70
|
+
if (Class2) _set_prototype_of(instance, Class2.prototype);
|
|
71
|
+
return instance;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return _construct.apply(null, arguments);
|
|
75
|
+
}
|
|
76
|
+
function _get_prototype_of(o) {
|
|
77
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
|
|
78
|
+
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
79
|
+
};
|
|
80
|
+
return _get_prototype_of(o);
|
|
81
|
+
}
|
|
82
|
+
function _inherits(subClass, superClass) {
|
|
83
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
84
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
85
|
+
}
|
|
86
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
87
|
+
constructor: {
|
|
88
|
+
value: subClass,
|
|
89
|
+
writable: true,
|
|
90
|
+
configurable: true
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
94
|
+
}
|
|
95
|
+
function _is_native_function(fn) {
|
|
96
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
97
|
+
}
|
|
98
|
+
function _possible_constructor_return(self, call) {
|
|
99
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
100
|
+
return call;
|
|
101
|
+
}
|
|
102
|
+
return _assert_this_initialized(self);
|
|
103
|
+
}
|
|
104
|
+
function _set_prototype_of(o, p) {
|
|
105
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
|
|
106
|
+
o2.__proto__ = p2;
|
|
107
|
+
return o2;
|
|
108
|
+
};
|
|
109
|
+
return _set_prototype_of(o, p);
|
|
110
|
+
}
|
|
111
|
+
function _type_of(obj) {
|
|
112
|
+
"@swc/helpers - typeof";
|
|
113
|
+
|
|
114
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
115
|
+
}
|
|
116
|
+
function _wrap_native_super(Class) {
|
|
117
|
+
var _cache = typeof Map === "function" ? /* @__PURE__ */new Map() : void 0;
|
|
118
|
+
_wrap_native_super = function wrapNativeSuper(Class2) {
|
|
119
|
+
if (Class2 === null || !_is_native_function(Class2)) return Class2;
|
|
120
|
+
if (typeof Class2 !== "function") {
|
|
121
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
122
|
+
}
|
|
123
|
+
if (typeof _cache !== "undefined") {
|
|
124
|
+
if (_cache.has(Class2)) return _cache.get(Class2);
|
|
125
|
+
_cache.set(Class2, Wrapper);
|
|
126
|
+
}
|
|
127
|
+
function Wrapper() {
|
|
128
|
+
return _construct(Class2, arguments, _get_prototype_of(this).constructor);
|
|
129
|
+
}
|
|
130
|
+
Wrapper.prototype = Object.create(Class2.prototype, {
|
|
131
|
+
constructor: {
|
|
132
|
+
value: Wrapper,
|
|
133
|
+
enumerable: false,
|
|
134
|
+
writable: true,
|
|
135
|
+
configurable: true
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return _set_prototype_of(Wrapper, Class2);
|
|
139
|
+
};
|
|
140
|
+
return _wrap_native_super(Class);
|
|
141
|
+
}
|
|
142
|
+
function _is_native_reflect_construct() {
|
|
143
|
+
try {
|
|
144
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
145
|
+
} catch (_) {}
|
|
146
|
+
return (_is_native_reflect_construct = function () {
|
|
147
|
+
return !!result;
|
|
148
|
+
})();
|
|
149
|
+
}
|
|
150
|
+
var PhantomNotConnectedError = /* @__PURE__ */function (Error1) {
|
|
151
|
+
"use strict";
|
|
152
|
+
|
|
153
|
+
_inherits(PhantomNotConnectedError2, Error1);
|
|
154
|
+
function PhantomNotConnectedError2() {
|
|
155
|
+
_class_call_check(this, PhantomNotConnectedError2);
|
|
156
|
+
var _this;
|
|
157
|
+
_this = _call_super(this, PhantomNotConnectedError2, ["no Phantom deeplink session: call connect() first"]);
|
|
158
|
+
_this.name = "PhantomNotConnectedError";
|
|
159
|
+
return _this;
|
|
160
|
+
}
|
|
161
|
+
return PhantomNotConnectedError2;
|
|
162
|
+
}(_wrap_native_super(Error));
|
|
163
|
+
var defaultStorageKey = "mpo.web3.phantom.deeplink";
|
|
164
|
+
function defaultStorage() {
|
|
165
|
+
var storage = globalThis.localStorage;
|
|
166
|
+
if (!storage) throw new Error("phantomDeeplink: no localStorage here; pass `storage`");
|
|
167
|
+
return storage;
|
|
168
|
+
}
|
|
169
|
+
function currentHref() {
|
|
170
|
+
var _globalThis_location;
|
|
171
|
+
var href = (_globalThis_location = globalThis.location) === null || _globalThis_location === void 0 ? void 0 : _globalThis_location.href;
|
|
172
|
+
if (!href) throw new Error("phantomDeeplink: no location here; pass `redirectLink`");
|
|
173
|
+
return href;
|
|
174
|
+
}
|
|
175
|
+
function phantomDeeplink(config) {
|
|
176
|
+
var _config_storageKey, _config_now, _config_navigate;
|
|
177
|
+
var storageKey = (_config_storageKey = config.storageKey) !== null && _config_storageKey !== void 0 ? _config_storageKey : defaultStorageKey;
|
|
178
|
+
var storage = function storage2() {
|
|
179
|
+
var _config_storage;
|
|
180
|
+
return (_config_storage = config.storage) !== null && _config_storage !== void 0 ? _config_storage : defaultStorage();
|
|
181
|
+
};
|
|
182
|
+
var now = (_config_now = config.now) !== null && _config_now !== void 0 ? _config_now : Date.now;
|
|
183
|
+
var navigate = (_config_navigate = config.navigate) !== null && _config_navigate !== void 0 ? _config_navigate : function (url) {
|
|
184
|
+
return globalThis.location.assign(url);
|
|
185
|
+
};
|
|
186
|
+
var redirectLink = function redirectLink2() {
|
|
187
|
+
var _config_redirectLink;
|
|
188
|
+
return (_config_redirectLink = config.redirectLink) !== null && _config_redirectLink !== void 0 ? _config_redirectLink : (0, import_urls.stripPhantomRedirect)(currentHref());
|
|
189
|
+
};
|
|
190
|
+
var load = function load2() {
|
|
191
|
+
var raw = storage().getItem(storageKey);
|
|
192
|
+
if (!raw) return void 0;
|
|
193
|
+
try {
|
|
194
|
+
return JSON.parse(raw);
|
|
195
|
+
} catch (unused) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var save = function save2(record) {
|
|
200
|
+
return storage().setItem(storageKey, JSON.stringify(record));
|
|
201
|
+
};
|
|
202
|
+
var connected = function connected2() {
|
|
203
|
+
var record = load();
|
|
204
|
+
if (!(record === null || record === void 0 ? void 0 : record.session) || !record.phantomEncryptionPublicKey) throw new PhantomNotConnectedError();
|
|
205
|
+
return record;
|
|
206
|
+
};
|
|
207
|
+
var methodUrl = function methodUrl2(record, method, payload) {
|
|
208
|
+
var keyPair = (0, import_crypto.boxKeyPairFromSecretKey)(import_bs58.default.decode(record.dappSecretKey));
|
|
209
|
+
return (0, import_urls.phantomMethodUrl)({
|
|
210
|
+
method,
|
|
211
|
+
payload,
|
|
212
|
+
session: record.session,
|
|
213
|
+
dappEncryptionPublicKey: keyPair.publicKey,
|
|
214
|
+
sharedSecret: (0, import_crypto.sharedSecret)(import_bs58.default.decode(record.phantomEncryptionPublicKey), keyPair.secretKey),
|
|
215
|
+
redirectLink: redirectLink(),
|
|
216
|
+
base: config.base
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
var request = function request2(method, payload) {
|
|
220
|
+
var record = connected();
|
|
221
|
+
var url = methodUrl(record, method, payload);
|
|
222
|
+
save({
|
|
223
|
+
...record,
|
|
224
|
+
pending: {
|
|
225
|
+
method,
|
|
226
|
+
at: now()
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
navigate(url);
|
|
230
|
+
return url;
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
get publicKey() {
|
|
234
|
+
var _load;
|
|
235
|
+
return (_load = load()) === null || _load === void 0 ? void 0 : _load.publicKey;
|
|
236
|
+
},
|
|
237
|
+
get connected() {
|
|
238
|
+
var record = load();
|
|
239
|
+
return !!((record === null || record === void 0 ? void 0 : record.session) && record.phantomEncryptionPublicKey);
|
|
240
|
+
},
|
|
241
|
+
get pending() {
|
|
242
|
+
var _load1;
|
|
243
|
+
return (_load1 = load()) === null || _load1 === void 0 ? void 0 : _load1.pending;
|
|
244
|
+
},
|
|
245
|
+
connect() {
|
|
246
|
+
var keyPair = (0, import_crypto.generateBoxKeyPair)();
|
|
247
|
+
var url = (0, import_urls.phantomConnectUrl)({
|
|
248
|
+
appUrl: config.appUrl,
|
|
249
|
+
dappEncryptionPublicKey: keyPair.publicKey,
|
|
250
|
+
redirectLink: redirectLink(),
|
|
251
|
+
cluster: config.cluster,
|
|
252
|
+
base: config.base
|
|
253
|
+
});
|
|
254
|
+
save({
|
|
255
|
+
dappSecretKey: import_bs58.default.encode(keyPair.secretKey),
|
|
256
|
+
cluster: config.cluster,
|
|
257
|
+
pending: {
|
|
258
|
+
method: "connect",
|
|
259
|
+
at: now()
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
navigate(url);
|
|
263
|
+
return url;
|
|
264
|
+
},
|
|
265
|
+
signTransaction(serializedTransaction) {
|
|
266
|
+
return request("signTransaction", {
|
|
267
|
+
transaction: import_bs58.default.encode(serializedTransaction)
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
signAllTransactions(serializedTransactions) {
|
|
271
|
+
return request("signAllTransactions", {
|
|
272
|
+
transactions: serializedTransactions.map(function (tx) {
|
|
273
|
+
return import_bs58.default.encode(tx);
|
|
274
|
+
})
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
signAndSendTransaction(serializedTransaction, sendOptions) {
|
|
278
|
+
return request("signAndSendTransaction", {
|
|
279
|
+
transaction: import_bs58.default.encode(serializedTransaction),
|
|
280
|
+
...(sendOptions ? {
|
|
281
|
+
sendOptions
|
|
282
|
+
} : {})
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
signMessage(message, display) {
|
|
286
|
+
var bytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
287
|
+
return request("signMessage", {
|
|
288
|
+
message: import_bs58.default.encode(bytes),
|
|
289
|
+
...(display ? {
|
|
290
|
+
display
|
|
291
|
+
} : {})
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
disconnect() {
|
|
295
|
+
var url = methodUrl(connected(), "disconnect", {});
|
|
296
|
+
storage().removeItem(storageKey);
|
|
297
|
+
navigate(url);
|
|
298
|
+
return url;
|
|
299
|
+
},
|
|
300
|
+
handleRedirect(href) {
|
|
301
|
+
var _record_pending;
|
|
302
|
+
var params = (0, import_urls.parsePhantomRedirect)(href !== null && href !== void 0 ? href : currentHref());
|
|
303
|
+
if (!params) return void 0;
|
|
304
|
+
var record = load();
|
|
305
|
+
var method = record === null || record === void 0 ? void 0 : (_record_pending = record.pending) === null || _record_pending === void 0 ? void 0 : _record_pending.method;
|
|
306
|
+
if (params.errorCode) {
|
|
307
|
+
var _params_errorMessage;
|
|
308
|
+
if (record) save({
|
|
309
|
+
...record,
|
|
310
|
+
pending: void 0
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
ok: false,
|
|
314
|
+
method,
|
|
315
|
+
errorCode: params.errorCode,
|
|
316
|
+
errorMessage: (_params_errorMessage = params.errorMessage) !== null && _params_errorMessage !== void 0 ? _params_errorMessage : ""
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
if (!record || !params.data || !params.nonce) {
|
|
320
|
+
return {
|
|
321
|
+
ok: false,
|
|
322
|
+
method,
|
|
323
|
+
errorCode: "-32603",
|
|
324
|
+
errorMessage: "Phantom answered, but this browser holds no matching request"
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
var secretKey = import_bs58.default.decode(record.dappSecretKey);
|
|
328
|
+
var phantomKey = method === "connect" ? params.phantomEncryptionPublicKey : record.phantomEncryptionPublicKey;
|
|
329
|
+
if (!phantomKey) {
|
|
330
|
+
return {
|
|
331
|
+
ok: false,
|
|
332
|
+
method,
|
|
333
|
+
errorCode: "-32603",
|
|
334
|
+
errorMessage: "Phantom's answer carries no encryption key"
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
var data = (0, import_crypto.decryptPayload)(params.data, params.nonce, (0, import_crypto.sharedSecret)(import_bs58.default.decode(phantomKey), secretKey));
|
|
338
|
+
switch (method) {
|
|
339
|
+
case "connect":
|
|
340
|
+
{
|
|
341
|
+
var publicKey = String(data.public_key);
|
|
342
|
+
var session = String(data.session);
|
|
343
|
+
save({
|
|
344
|
+
...record,
|
|
345
|
+
phantomEncryptionPublicKey: phantomKey,
|
|
346
|
+
publicKey,
|
|
347
|
+
session,
|
|
348
|
+
pending: void 0
|
|
349
|
+
});
|
|
350
|
+
return {
|
|
351
|
+
ok: true,
|
|
352
|
+
method,
|
|
353
|
+
publicKey,
|
|
354
|
+
session
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
case "signTransaction":
|
|
358
|
+
save({
|
|
359
|
+
...record,
|
|
360
|
+
pending: void 0
|
|
361
|
+
});
|
|
362
|
+
return {
|
|
363
|
+
ok: true,
|
|
364
|
+
method,
|
|
365
|
+
transaction: import_bs58.default.decode(String(data.transaction))
|
|
366
|
+
};
|
|
367
|
+
case "signAllTransactions":
|
|
368
|
+
save({
|
|
369
|
+
...record,
|
|
370
|
+
pending: void 0
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
ok: true,
|
|
374
|
+
method,
|
|
375
|
+
transactions: data.transactions.map(function (tx) {
|
|
376
|
+
return import_bs58.default.decode(tx);
|
|
377
|
+
})
|
|
378
|
+
};
|
|
379
|
+
case "signAndSendTransaction":
|
|
380
|
+
save({
|
|
381
|
+
...record,
|
|
382
|
+
pending: void 0
|
|
383
|
+
});
|
|
384
|
+
return {
|
|
385
|
+
ok: true,
|
|
386
|
+
method,
|
|
387
|
+
signature: String(data.signature)
|
|
388
|
+
};
|
|
389
|
+
case "signMessage":
|
|
390
|
+
save({
|
|
391
|
+
...record,
|
|
392
|
+
pending: void 0
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
ok: true,
|
|
396
|
+
method,
|
|
397
|
+
signature: import_bs58.default.decode(String(data.signature))
|
|
398
|
+
};
|
|
399
|
+
default:
|
|
400
|
+
return {
|
|
401
|
+
ok: false,
|
|
402
|
+
method,
|
|
403
|
+
errorCode: "-32603",
|
|
404
|
+
errorMessage: "Phantom answered a request this browser did not make"
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
forget() {
|
|
409
|
+
storage().removeItem(storageKey);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function toBase64(bytes) {
|
|
414
|
+
var binary = "";
|
|
415
|
+
var _iteratorNormalCompletion = true,
|
|
416
|
+
_didIteratorError = false,
|
|
417
|
+
_iteratorError = void 0;
|
|
418
|
+
try {
|
|
419
|
+
for (var _iterator = bytes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
420
|
+
var byte = _step.value;
|
|
421
|
+
binary += String.fromCharCode(byte);
|
|
422
|
+
}
|
|
423
|
+
} catch (err) {
|
|
424
|
+
_didIteratorError = true;
|
|
425
|
+
_iteratorError = err;
|
|
426
|
+
} finally {
|
|
427
|
+
try {
|
|
428
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
429
|
+
_iterator.return();
|
|
430
|
+
}
|
|
431
|
+
} finally {
|
|
432
|
+
if (_didIteratorError) {
|
|
433
|
+
throw _iteratorError;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return btoa(binary);
|
|
438
|
+
}
|
|
439
|
+
async function sendSolanaTransaction(rpcUrl, signedTransaction) {
|
|
440
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
441
|
+
var _options_fetch, _options_skipPreflight;
|
|
442
|
+
var response = await ((_options_fetch = options.fetch) !== null && _options_fetch !== void 0 ? _options_fetch : fetch)(rpcUrl, {
|
|
443
|
+
method: "POST",
|
|
444
|
+
headers: {
|
|
445
|
+
"content-type": "application/json"
|
|
446
|
+
},
|
|
447
|
+
body: JSON.stringify({
|
|
448
|
+
jsonrpc: "2.0",
|
|
449
|
+
id: 1,
|
|
450
|
+
method: "sendTransaction",
|
|
451
|
+
params: [toBase64(signedTransaction), {
|
|
452
|
+
encoding: "base64",
|
|
453
|
+
skipPreflight: (_options_skipPreflight = options.skipPreflight) !== null && _options_skipPreflight !== void 0 ? _options_skipPreflight : false
|
|
454
|
+
}]
|
|
455
|
+
})
|
|
456
|
+
});
|
|
457
|
+
var body = await response.json();
|
|
458
|
+
if (body.error) {
|
|
459
|
+
throw Object.assign(new Error(`sendTransaction failed: ${body.error.message}`), {
|
|
460
|
+
code: body.error.code
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
if (typeof body.result !== "string") throw new Error("sendTransaction returned no signature");
|
|
464
|
+
return body.result;
|
|
465
|
+
}
|
|
466
|
+
//# sourceMappingURL=solana.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","solana_exports","__export","PhantomNotConnectedError","phantomDeeplink","sendSolanaTransaction","module","exports","import_bs58","__toESM","require","import_crypto","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","prototype","arguments","o","Object","setPrototypeOf","getPrototypeOf","o2","__proto__","_inherits","subClass","superClass","create","writable","configurable","_is_native_function","fn","toString","call","indexOf","_type_of","p","p2","obj","Symbol","_wrap_native_super","_cache","Map","wrapNativeSuper","has","get","set","Wrapper","enumerable","result","Boolean","valueOf","_","Error1","PhantomNotConnectedError2","name","Error","defaultStorageKey","defaultStorage","storage","globalThis","localStorage","currentHref","_globalThis_location","href","location","config","_config_storageKey","_config_now","_config_navigate","storageKey","storage2","_config_storage","now","Date","navigate","url","assign","redirectLink","redirectLink2","_config_redirectLink","stripPhantomRedirect","load","load2","raw","getItem","JSON","parse","unused","save","save2","record","setItem","stringify","connected","connected2","session","phantomEncryptionPublicKey","methodUrl","methodUrl2","method","payload","keyPair","boxKeyPairFromSecretKey","default","decode","dappSecretKey","phantomMethodUrl","dappEncryptionPublicKey","publicKey","sharedSecret","secretKey","base","request","request2","pending","at","_load","_load1","connect","generateBoxKeyPair","phantomConnectUrl","appUrl","cluster","encode"],"sources":["../../../src/phantom/solana.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,cAAA;AAAAC,QAAA,CAAAD,cAAA;EAAAE,wBAAA,EAAAA,CAAA,KAAAA,wBAAA;EAAAC,eAAA,EAAAA,CAAA,KAAAA,eAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAX,YAAiB,CAAAK,cAAA;AACjB,IAAAO,WAAA,GAAAC,OAKO,CAAAC,OAAA;AACP,IAAAC,aAAA,GAOOD,OAAA;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AAgC;QAC5DY,OAAM,EAAKzD,MAAM,CAAAyD,OAAA;QAClBR,OAAA;UACHf,MAAA;UACIgB,EAAA,EAAO3C,GAAA,CAAK;QAChB;MACF","ignoreList":[]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all) __defProp(target, name, {
|
|
@@ -17,17 +19,80 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
19
|
}
|
|
18
20
|
return to;
|
|
19
21
|
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
20
31
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
32
|
value: true
|
|
22
33
|
}), mod);
|
|
23
34
|
var urls_exports = {};
|
|
24
35
|
__export(urls_exports, {
|
|
36
|
+
parsePhantomRedirect: () => parsePhantomRedirect,
|
|
25
37
|
phantomBrowseUrl: () => phantomBrowseUrl,
|
|
26
|
-
|
|
38
|
+
phantomConnectUrl: () => phantomConnectUrl,
|
|
39
|
+
phantomMethodUrl: () => phantomMethodUrl,
|
|
40
|
+
phantomUniversalLinkBase: () => phantomUniversalLinkBase,
|
|
41
|
+
stripPhantomRedirect: () => stripPhantomRedirect
|
|
27
42
|
});
|
|
28
43
|
module.exports = __toCommonJS(urls_exports);
|
|
44
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
45
|
+
var import_crypto = require("./crypto.cjs");
|
|
29
46
|
const phantomUniversalLinkBase = "https://phantom.com/ul";
|
|
47
|
+
const base = override => (override ?? phantomUniversalLinkBase).replace(/\/+$/, "");
|
|
30
48
|
function phantomBrowseUrl(url, ref, options = {}) {
|
|
31
|
-
|
|
32
|
-
|
|
49
|
+
return `${base(options.base)}/browse/${encodeURIComponent(url)}?ref=${encodeURIComponent(ref)}`;
|
|
50
|
+
}
|
|
51
|
+
function phantomConnectUrl(params) {
|
|
52
|
+
const query = new URLSearchParams({
|
|
53
|
+
app_url: params.appUrl,
|
|
54
|
+
dapp_encryption_public_key: import_bs58.default.encode(params.dappEncryptionPublicKey),
|
|
55
|
+
redirect_link: params.redirectLink
|
|
56
|
+
});
|
|
57
|
+
if (params.cluster) query.set("cluster", params.cluster);
|
|
58
|
+
return `${base(params.base)}/v1/connect?${query}`;
|
|
59
|
+
}
|
|
60
|
+
function phantomMethodUrl(params) {
|
|
61
|
+
const sealed = (0, import_crypto.encryptPayload)({
|
|
62
|
+
...params.payload,
|
|
63
|
+
session: params.session
|
|
64
|
+
}, params.sharedSecret, params.nonce);
|
|
65
|
+
const query = new URLSearchParams({
|
|
66
|
+
dapp_encryption_public_key: import_bs58.default.encode(params.dappEncryptionPublicKey),
|
|
67
|
+
nonce: sealed.nonce,
|
|
68
|
+
redirect_link: params.redirectLink,
|
|
69
|
+
payload: sealed.payload
|
|
70
|
+
});
|
|
71
|
+
return `${base(params.base)}/v1/${params.method}?${query}`;
|
|
72
|
+
}
|
|
73
|
+
const responseKeys = ["phantom_encryption_public_key", "nonce", "data", "errorCode", "errorMessage"];
|
|
74
|
+
function parsePhantomRedirect(href) {
|
|
75
|
+
const [beforeHash] = href.split("#");
|
|
76
|
+
const at = beforeHash.indexOf("?");
|
|
77
|
+
if (at < 0) return void 0;
|
|
78
|
+
const query = new URLSearchParams(beforeHash.slice(at + 1).replace(/\?/g, "&"));
|
|
79
|
+
if (!query.has("errorCode") && !(query.has("data") && query.has("nonce"))) return void 0;
|
|
80
|
+
return {
|
|
81
|
+
phantomEncryptionPublicKey: query.get("phantom_encryption_public_key") ?? void 0,
|
|
82
|
+
nonce: query.get("nonce") ?? void 0,
|
|
83
|
+
data: query.get("data") ?? void 0,
|
|
84
|
+
errorCode: query.get("errorCode") ?? void 0,
|
|
85
|
+
errorMessage: query.get("errorMessage") ?? void 0
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function stripPhantomRedirect(href) {
|
|
89
|
+
const hashAt = href.indexOf("#");
|
|
90
|
+
const hash = hashAt >= 0 ? href.slice(hashAt) : "";
|
|
91
|
+
const beforeHash = hashAt >= 0 ? href.slice(0, hashAt) : href;
|
|
92
|
+
const at = beforeHash.indexOf("?");
|
|
93
|
+
if (at < 0) return href;
|
|
94
|
+
const query = new URLSearchParams(beforeHash.slice(at + 1).replace(/\?/g, "&"));
|
|
95
|
+
for (const key of responseKeys) query.delete(key);
|
|
96
|
+
const rest = query.toString();
|
|
97
|
+
return `${beforeHash.slice(0, at)}${rest ? `?${rest}` : ""}${hash}`;
|
|
33
98
|
}
|