FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

View File

@@ -0,0 +1,440 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _StandardWalletAdapter_instances, _StandardWalletAdapter_account, _StandardWalletAdapter_publicKey, _StandardWalletAdapter_connecting, _StandardWalletAdapter_disconnecting, _StandardWalletAdapter_off, _StandardWalletAdapter_supportedTransactionVersions, _StandardWalletAdapter_wallet, _StandardWalletAdapter_readyState, _StandardWalletAdapter_connect, _StandardWalletAdapter_connected, _StandardWalletAdapter_disconnected, _StandardWalletAdapter_reset, _StandardWalletAdapter_changed, _StandardWalletAdapter_signTransaction, _StandardWalletAdapter_signAllTransactions, _StandardWalletAdapter_signMessage, _StandardWalletAdapter_signIn;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandardWalletAdapter = void 0;
const wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
const wallet_standard_features_1 = require("@solana/wallet-standard-features");
const wallet_standard_util_1 = require("@solana/wallet-standard-util");
const web3_js_1 = require("@solana/web3.js");
const features_1 = require("@wallet-standard/features");
const wallet_1 = require("@wallet-standard/wallet");
const bs58_1 = __importDefault(require("bs58"));
/** TODO: docs */
class StandardWalletAdapter extends wallet_adapter_base_1.BaseWalletAdapter {
get name() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").name;
}
get url() {
return 'https://github.com/solana-labs/wallet-standard';
}
get icon() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").icon;
}
get readyState() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_readyState, "f");
}
get publicKey() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_publicKey, "f");
}
get connecting() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_connecting, "f");
}
get supportedTransactionVersions() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_supportedTransactionVersions, "f");
}
get wallet() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f");
}
get standard() {
return true;
}
constructor({ wallet }) {
super();
_StandardWalletAdapter_instances.add(this);
_StandardWalletAdapter_account.set(this, void 0);
_StandardWalletAdapter_publicKey.set(this, void 0);
_StandardWalletAdapter_connecting.set(this, void 0);
_StandardWalletAdapter_disconnecting.set(this, void 0);
_StandardWalletAdapter_off.set(this, void 0);
_StandardWalletAdapter_supportedTransactionVersions.set(this, void 0);
_StandardWalletAdapter_wallet.set(this, void 0);
_StandardWalletAdapter_readyState.set(this, typeof window === 'undefined' || typeof document === 'undefined'
? wallet_adapter_base_1.WalletReadyState.Unsupported
: wallet_adapter_base_1.WalletReadyState.Installed);
_StandardWalletAdapter_changed.set(this, (properties) => {
// If accounts have changed on the wallet, reflect this on the adapter.
if ('accounts' in properties) {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").accounts[0];
// If the adapter isn't connected, or is disconnecting, or the first account hasn't changed, do nothing.
if (__classPrivateFieldGet(this, _StandardWalletAdapter_account, "f") && !__classPrivateFieldGet(this, _StandardWalletAdapter_disconnecting, "f") && account !== __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f")) {
// If there's a connected account, connect the adapter. Otherwise, disconnect it.
if (account) {
// Connect the adapter.
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connected).call(this, account);
}
else {
// Emit an error because the wallet spontaneously disconnected.
this.emit('error', new wallet_adapter_base_1.WalletDisconnectedError());
// Disconnect the adapter.
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_disconnected).call(this);
}
}
}
// After reflecting account changes, if features have changed on the wallet, reflect this on the adapter.
if ('features' in properties) {
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
}
});
__classPrivateFieldSet(this, _StandardWalletAdapter_wallet, wallet, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_account, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, false, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, false, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_off, __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[features_1.StandardEvents].on('change', __classPrivateFieldGet(this, _StandardWalletAdapter_changed, "f")), "f");
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
}
destroy() {
__classPrivateFieldSet(this, _StandardWalletAdapter_account, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, false, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, false, "f");
const off = __classPrivateFieldGet(this, _StandardWalletAdapter_off, "f");
if (off) {
__classPrivateFieldSet(this, _StandardWalletAdapter_off, null, "f");
off();
}
}
autoConnect() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connect).call(this, { silent: true });
});
}
connect() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connect).call(this);
});
}
disconnect() {
return __awaiter(this, void 0, void 0, function* () {
if (features_1.StandardDisconnect in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
try {
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, true, "f");
yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[features_1.StandardDisconnect].disconnect();
}
catch (error) {
this.emit('error', new wallet_adapter_base_1.WalletDisconnectionError(error === null || error === void 0 ? void 0 : error.message, error));
}
finally {
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, false, "f");
}
}
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_disconnected).call(this);
});
}
sendTransaction(transaction_1, connection_1) {
return __awaiter(this, arguments, void 0, function* (transaction, connection, options = {}) {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new wallet_adapter_base_1.WalletNotConnectedError();
let feature;
if (wallet_standard_features_1.SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
if (account.features.includes(wallet_standard_features_1.SolanaSignAndSendTransaction)) {
feature = wallet_standard_features_1.SolanaSignAndSendTransaction;
}
else if (wallet_standard_features_1.SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features &&
account.features.includes(wallet_standard_features_1.SolanaSignTransaction)) {
feature = wallet_standard_features_1.SolanaSignTransaction;
}
else {
throw new wallet_adapter_base_1.WalletAccountError();
}
}
else if (wallet_standard_features_1.SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
if (!account.features.includes(wallet_standard_features_1.SolanaSignTransaction))
throw new wallet_adapter_base_1.WalletAccountError();
feature = wallet_standard_features_1.SolanaSignTransaction;
}
else {
throw new wallet_adapter_base_1.WalletConfigError();
}
const chain = (0, wallet_standard_util_1.getChainForEndpoint)(connection.rpcEndpoint);
if (!account.chains.includes(chain))
throw new wallet_adapter_base_1.WalletSendTransactionError();
try {
const { signers } = options, sendOptions = __rest(options, ["signers"]);
let serializedTransaction;
if ((0, wallet_adapter_base_1.isVersionedTransaction)(transaction)) {
(signers === null || signers === void 0 ? void 0 : signers.length) && transaction.sign(signers);
serializedTransaction = transaction.serialize();
}
else {
transaction = (yield this.prepareTransaction(transaction, connection, sendOptions));
(signers === null || signers === void 0 ? void 0 : signers.length) && transaction.partialSign(...signers);
serializedTransaction = new Uint8Array(transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
}));
}
if (feature === wallet_standard_features_1.SolanaSignAndSendTransaction) {
const [output] = yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignAndSendTransaction].signAndSendTransaction({
account,
chain,
transaction: serializedTransaction,
options: {
preflightCommitment: (0, wallet_standard_util_1.getCommitment)(sendOptions.preflightCommitment || connection.commitment),
skipPreflight: sendOptions.skipPreflight,
maxRetries: sendOptions.maxRetries,
minContextSlot: sendOptions.minContextSlot,
},
});
return bs58_1.default.encode(output.signature);
}
else {
const [output] = yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignTransaction].signTransaction({
account,
chain,
transaction: serializedTransaction,
options: {
preflightCommitment: (0, wallet_standard_util_1.getCommitment)(sendOptions.preflightCommitment || connection.commitment),
minContextSlot: sendOptions.minContextSlot,
},
});
return yield connection.sendRawTransaction(output.signedTransaction, Object.assign(Object.assign({}, sendOptions), { preflightCommitment: (0, wallet_standard_util_1.getCommitment)(sendOptions.preflightCommitment || connection.commitment) }));
}
}
catch (error) {
if (error instanceof wallet_adapter_base_1.WalletError)
throw error;
throw new wallet_adapter_base_1.WalletSendTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
});
}
}
exports.StandardWalletAdapter = StandardWalletAdapter;
_StandardWalletAdapter_account = new WeakMap(), _StandardWalletAdapter_publicKey = new WeakMap(), _StandardWalletAdapter_connecting = new WeakMap(), _StandardWalletAdapter_disconnecting = new WeakMap(), _StandardWalletAdapter_off = new WeakMap(), _StandardWalletAdapter_supportedTransactionVersions = new WeakMap(), _StandardWalletAdapter_wallet = new WeakMap(), _StandardWalletAdapter_readyState = new WeakMap(), _StandardWalletAdapter_changed = new WeakMap(), _StandardWalletAdapter_instances = new WeakSet(), _StandardWalletAdapter_connect = function _StandardWalletAdapter_connect(input) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (this.connected || this.connecting)
return;
if (__classPrivateFieldGet(this, _StandardWalletAdapter_readyState, "f") !== wallet_adapter_base_1.WalletReadyState.Installed)
throw new wallet_adapter_base_1.WalletNotReadyError();
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, true, "f");
if (!__classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").accounts.length) {
try {
yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[features_1.StandardConnect].connect(input);
}
catch (error) {
throw new wallet_adapter_base_1.WalletConnectionError(error === null || error === void 0 ? void 0 : error.message, error);
}
}
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").accounts[0];
if (!account)
throw new wallet_adapter_base_1.WalletAccountError();
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connected).call(this, account);
}
catch (error) {
this.emit('error', error);
throw error;
}
finally {
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, false, "f");
}
});
}, _StandardWalletAdapter_connected = function _StandardWalletAdapter_connected(account) {
let publicKey;
try {
// Use account.address instead of account.publicKey since address could be a PDA
publicKey = new web3_js_1.PublicKey(account.address);
}
catch (error) {
throw new wallet_adapter_base_1.WalletPublicKeyError(error === null || error === void 0 ? void 0 : error.message, error);
}
__classPrivateFieldSet(this, _StandardWalletAdapter_account, account, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, publicKey, "f");
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
this.emit('connect', publicKey);
}, _StandardWalletAdapter_disconnected = function _StandardWalletAdapter_disconnected() {
__classPrivateFieldSet(this, _StandardWalletAdapter_account, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, null, "f");
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
this.emit('disconnect');
}, _StandardWalletAdapter_reset = function _StandardWalletAdapter_reset() {
var _a, _b;
const supportedTransactionVersions = wallet_standard_features_1.SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features
? __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignAndSendTransaction].supportedTransactionVersions
: __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignTransaction].supportedTransactionVersions;
__classPrivateFieldSet(this, _StandardWalletAdapter_supportedTransactionVersions, (0, wallet_1.arraysEqual)(supportedTransactionVersions, ['legacy'])
? null
: new Set(supportedTransactionVersions), "f");
if (wallet_standard_features_1.SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features && ((_a = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f")) === null || _a === void 0 ? void 0 : _a.features.includes(wallet_standard_features_1.SolanaSignTransaction))) {
this.signTransaction = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signTransaction);
this.signAllTransactions = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signAllTransactions);
}
else {
delete this.signTransaction;
delete this.signAllTransactions;
}
if (wallet_standard_features_1.SolanaSignMessage in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features && ((_b = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f")) === null || _b === void 0 ? void 0 : _b.features.includes(wallet_standard_features_1.SolanaSignMessage))) {
this.signMessage = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signMessage);
}
else {
delete this.signMessage;
}
if (wallet_standard_features_1.SolanaSignIn in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
this.signIn = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signIn);
}
else {
delete this.signIn;
}
}, _StandardWalletAdapter_signTransaction = function _StandardWalletAdapter_signTransaction(transaction) {
return __awaiter(this, void 0, void 0, function* () {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new wallet_adapter_base_1.WalletNotConnectedError();
if (!(wallet_standard_features_1.SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new wallet_adapter_base_1.WalletConfigError();
if (!account.features.includes(wallet_standard_features_1.SolanaSignTransaction))
throw new wallet_adapter_base_1.WalletAccountError();
try {
const signedTransactions = yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignTransaction].signTransaction({
account,
transaction: (0, wallet_adapter_base_1.isVersionedTransaction)(transaction)
? transaction.serialize()
: new Uint8Array(transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})),
});
const serializedTransaction = signedTransactions[0].signedTransaction;
return ((0, wallet_adapter_base_1.isVersionedTransaction)(transaction)
? web3_js_1.VersionedTransaction.deserialize(serializedTransaction)
: web3_js_1.Transaction.from(serializedTransaction));
}
catch (error) {
if (error instanceof wallet_adapter_base_1.WalletError)
throw error;
throw new wallet_adapter_base_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
});
}, _StandardWalletAdapter_signAllTransactions = function _StandardWalletAdapter_signAllTransactions(transactions) {
return __awaiter(this, void 0, void 0, function* () {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new wallet_adapter_base_1.WalletNotConnectedError();
if (!(wallet_standard_features_1.SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new wallet_adapter_base_1.WalletConfigError();
if (!account.features.includes(wallet_standard_features_1.SolanaSignTransaction))
throw new wallet_adapter_base_1.WalletAccountError();
try {
const signedTransactions = yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignTransaction].signTransaction(...transactions.map((transaction) => ({
account,
transaction: (0, wallet_adapter_base_1.isVersionedTransaction)(transaction)
? transaction.serialize()
: new Uint8Array(transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})),
})));
return transactions.map((transaction, index) => {
const signedTransaction = signedTransactions[index].signedTransaction;
return ((0, wallet_adapter_base_1.isVersionedTransaction)(transaction)
? web3_js_1.VersionedTransaction.deserialize(signedTransaction)
: web3_js_1.Transaction.from(signedTransaction));
});
}
catch (error) {
throw new wallet_adapter_base_1.WalletSignTransactionError(error === null || error === void 0 ? void 0 : error.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
});
}, _StandardWalletAdapter_signMessage = function _StandardWalletAdapter_signMessage(message) {
return __awaiter(this, void 0, void 0, function* () {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new wallet_adapter_base_1.WalletNotConnectedError();
if (!(wallet_standard_features_1.SolanaSignMessage in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new wallet_adapter_base_1.WalletConfigError();
if (!account.features.includes(wallet_standard_features_1.SolanaSignMessage))
throw new wallet_adapter_base_1.WalletAccountError();
try {
const signedMessages = yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignMessage].signMessage({
account,
message,
});
return signedMessages[0].signature;
}
catch (error) {
throw new wallet_adapter_base_1.WalletSignMessageError(error === null || error === void 0 ? void 0 : error.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
});
}, _StandardWalletAdapter_signIn = function _StandardWalletAdapter_signIn() {
return __awaiter(this, arguments, void 0, function* (input = {}) {
try {
if (!(wallet_standard_features_1.SolanaSignIn in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new wallet_adapter_base_1.WalletConfigError();
let output;
try {
[output] = yield __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[wallet_standard_features_1.SolanaSignIn].signIn(input);
}
catch (error) {
throw new wallet_adapter_base_1.WalletSignInError(error === null || error === void 0 ? void 0 : error.message, error);
}
if (!output)
throw new wallet_adapter_base_1.WalletSignInError();
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connected).call(this, output.account);
return output;
}
catch (error) {
this.emit('error', error);
throw error;
}
});
};
//# sourceMappingURL=adapter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,20 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./adapter.js"), exports);
__exportStar(require("./types.js"), exports);
__exportStar(require("./wallet.js"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,6CAA2B;AAC3B,8CAA4B"}

View File

@@ -0,0 +1 @@
{ "type": "commonjs" }

View File

@@ -0,0 +1 @@
{"root":["../../src/adapter.ts","../../src/index.ts","../../src/types.ts","../../src/wallet.ts"],"version":"5.7.3"}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWalletAdapterCompatibleWallet = void 0;
const wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
/**
* @deprecated Use `isWalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
exports.isWalletAdapterCompatibleWallet = wallet_adapter_base_1.isWalletAdapterCompatibleStandardWallet;
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAAA,qEAIqC;AAgBrC;;;;GAIG;AACU,QAAA,+BAA+B,GAAG,6DAAuC,CAAC"}

View File

@@ -0,0 +1,368 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _SolanaWalletAdapterWalletAccount_adapter, _SolanaWalletAdapterWallet_instances, _SolanaWalletAdapterWallet_listeners, _SolanaWalletAdapterWallet_adapter, _SolanaWalletAdapterWallet_supportedTransactionVersions, _SolanaWalletAdapterWallet_chain, _SolanaWalletAdapterWallet_endpoint, _SolanaWalletAdapterWallet_account, _SolanaWalletAdapterWallet_connected, _SolanaWalletAdapterWallet_disconnected, _SolanaWalletAdapterWallet_connect, _SolanaWalletAdapterWallet_disconnect, _SolanaWalletAdapterWallet_on, _SolanaWalletAdapterWallet_emit, _SolanaWalletAdapterWallet_off, _SolanaWalletAdapterWallet_deserializeTransaction, _SolanaWalletAdapterWallet_signAndSendTransaction, _SolanaWalletAdapterWallet_signTransaction, _SolanaWalletAdapterWallet_signMessage, _SolanaWalletAdapterWallet_signIn;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SolanaWalletAdapterWallet = exports.SolanaWalletAdapterWalletAccount = void 0;
exports.registerWalletAdapter = registerWalletAdapter;
const wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
const wallet_standard_chains_1 = require("@solana/wallet-standard-chains");
const wallet_standard_features_1 = require("@solana/wallet-standard-features");
const wallet_standard_util_1 = require("@solana/wallet-standard-util");
const web3_js_1 = require("@solana/web3.js");
const app_1 = require("@wallet-standard/app");
const features_1 = require("@wallet-standard/features");
const wallet_1 = require("@wallet-standard/wallet");
const bs58_1 = __importDefault(require("bs58"));
/** TODO: docs */
class SolanaWalletAdapterWalletAccount extends wallet_1.ReadonlyWalletAccount {
constructor({ adapter, address, publicKey, chains, }) {
const features = [wallet_standard_features_1.SolanaSignAndSendTransaction];
if ('signTransaction' in adapter) {
features.push(wallet_standard_features_1.SolanaSignTransaction);
}
if ('signMessage' in adapter) {
features.push(wallet_standard_features_1.SolanaSignMessage);
}
if ('signIn' in adapter) {
features.push(wallet_standard_features_1.SolanaSignIn);
}
super({ address, publicKey, chains, features });
// eslint-disable-next-line no-unused-private-class-members
_SolanaWalletAdapterWalletAccount_adapter.set(this, void 0);
if (new.target === SolanaWalletAdapterWalletAccount) {
Object.freeze(this);
}
__classPrivateFieldSet(this, _SolanaWalletAdapterWalletAccount_adapter, adapter, "f");
}
}
exports.SolanaWalletAdapterWalletAccount = SolanaWalletAdapterWalletAccount;
_SolanaWalletAdapterWalletAccount_adapter = new WeakMap();
/** TODO: docs */
class SolanaWalletAdapterWallet {
get version() {
return '1.0.0';
}
get name() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").name;
}
get icon() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").icon;
}
get chains() {
return [__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_chain, "f")];
}
get features() {
const features = {
[features_1.StandardConnect]: {
version: '1.0.0',
connect: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_connect, "f"),
},
[features_1.StandardDisconnect]: {
version: '1.0.0',
disconnect: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_disconnect, "f"),
},
[features_1.StandardEvents]: {
version: '1.0.0',
on: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_on, "f"),
},
[wallet_standard_features_1.SolanaSignAndSendTransaction]: {
version: '1.0.0',
supportedTransactionVersions: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f"),
signAndSendTransaction: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signAndSendTransaction, "f"),
},
};
let signTransactionFeature;
if ('signTransaction' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")) {
signTransactionFeature = {
[wallet_standard_features_1.SolanaSignTransaction]: {
version: '1.0.0',
supportedTransactionVersions: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f"),
signTransaction: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signTransaction, "f"),
},
};
}
let signMessageFeature;
if ('signMessage' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")) {
signMessageFeature = {
[wallet_standard_features_1.SolanaSignMessage]: {
version: '1.0.0',
signMessage: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signMessage, "f"),
},
};
}
let signInFeature;
if ('signIn' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")) {
signInFeature = {
[wallet_standard_features_1.SolanaSignIn]: {
version: '1.0.0',
signIn: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signIn, "f"),
},
};
}
return Object.assign(Object.assign(Object.assign({}, features), signTransactionFeature), signMessageFeature);
}
get accounts() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f") ? [__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f")] : [];
}
get endpoint() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_endpoint, "f");
}
constructor(adapter, chain, endpoint) {
_SolanaWalletAdapterWallet_instances.add(this);
_SolanaWalletAdapterWallet_listeners.set(this, {});
_SolanaWalletAdapterWallet_adapter.set(this, void 0);
_SolanaWalletAdapterWallet_supportedTransactionVersions.set(this, void 0);
_SolanaWalletAdapterWallet_chain.set(this, void 0);
_SolanaWalletAdapterWallet_endpoint.set(this, void 0);
_SolanaWalletAdapterWallet_account.set(this, void 0);
_SolanaWalletAdapterWallet_connect.set(this, (...args_1) => __awaiter(this, [...args_1], void 0, function* ({ silent } = {}) {
if (!silent && !__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").connected) {
yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").connect();
}
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected).call(this);
return { accounts: this.accounts };
}));
_SolanaWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").disconnect();
}));
_SolanaWalletAdapterWallet_on.set(this, (event, listener) => {
var _a;
((_a = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event] = [listener]);
return () => __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_off).call(this, event, listener);
});
_SolanaWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
const outputs = [];
if (inputs.length === 1) {
const input = inputs[0];
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
if (!(0, wallet_standard_chains_1.isSolanaChain)(input.chain))
throw new Error('invalid chain');
const transaction = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_deserializeTransaction).call(this, input.transaction);
const { commitment, preflightCommitment, skipPreflight, maxRetries, minContextSlot } = input.options || {};
const endpoint = (0, wallet_standard_util_1.getEndpointForChain)(input.chain, __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_endpoint, "f"));
const connection = new web3_js_1.Connection(endpoint, commitment || 'confirmed');
const latestBlockhash = commitment
? yield connection.getLatestBlockhash({
commitment: preflightCommitment || commitment,
minContextSlot,
})
: undefined;
const signature = yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").sendTransaction(transaction, connection, {
preflightCommitment,
skipPreflight,
maxRetries,
minContextSlot,
});
if (latestBlockhash) {
yield connection.confirmTransaction(Object.assign(Object.assign({}, latestBlockhash), { signature }), commitment || 'confirmed');
}
outputs.push({ signature: bs58_1.default.decode(signature) });
}
else if (inputs.length > 1) {
// Adapters have no `sendAllTransactions` method, so just sign and send each transaction in serial.
for (const input of inputs) {
outputs.push(...(yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signAndSendTransaction, "f").call(this, input)));
}
}
return outputs;
}));
_SolanaWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
if (!('signTransaction' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")))
throw new Error('signTransaction not implemented by adapter');
const outputs = [];
if (inputs.length === 1) {
const input = inputs[0];
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
if (input.chain && !(0, wallet_standard_chains_1.isSolanaChain)(input.chain))
throw new Error('invalid chain');
const transaction = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_deserializeTransaction).call(this, input.transaction);
const signedTransaction = yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signTransaction(transaction);
const serializedTransaction = (0, wallet_adapter_base_1.isVersionedTransaction)(signedTransaction)
? signedTransaction.serialize()
: new Uint8Array(signedTransaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
}));
outputs.push({ signedTransaction: serializedTransaction });
}
else if (inputs.length > 1) {
for (const input of inputs) {
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
if (input.chain && !(0, wallet_standard_chains_1.isSolanaChain)(input.chain))
throw new Error('invalid chain');
}
const transactions = inputs.map(({ transaction }) => __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_deserializeTransaction).call(this, transaction));
const signedTransactions = yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signAllTransactions(transactions);
outputs.push(...signedTransactions.map((signedTransaction) => {
const serializedTransaction = (0, wallet_adapter_base_1.isVersionedTransaction)(signedTransaction)
? signedTransaction.serialize()
: new Uint8Array(signedTransaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
}));
return { signedTransaction: serializedTransaction };
}));
}
return outputs;
}));
_SolanaWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
if (!('signMessage' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")))
throw new Error('signMessage not implemented by adapter');
const outputs = [];
if (inputs.length === 1) {
const input = inputs[0];
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
const signature = yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signMessage(input.message);
outputs.push({ signedMessage: input.message, signature });
}
else if (inputs.length > 1) {
// Adapters have no `signAllMessages` method, so just sign each message in serial.
for (const input of inputs) {
outputs.push(...(yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signMessage, "f").call(this, input)));
}
}
return outputs;
}));
_SolanaWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
if (!('signIn' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")))
throw new Error('signIn not implemented by adapter');
if (inputs.length > 1) {
// Adapters don't support `signIn` with multiple inputs, so just sign in with each input in serial.
const outputs = [];
for (const input of inputs) {
outputs.push(yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signIn(input));
}
return outputs;
}
else {
return [yield __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signIn(inputs[0])];
}
}));
if (new.target === SolanaWalletAdapterWallet) {
Object.freeze(this);
}
const supportedTransactionVersions = [...(adapter.supportedTransactionVersions || ['legacy'])];
if (!supportedTransactionVersions.length) {
supportedTransactionVersions.push('legacy');
}
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_adapter, adapter, "f");
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, supportedTransactionVersions, "f");
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_chain, chain, "f");
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_endpoint, endpoint, "f");
adapter.on('connect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected), this);
adapter.on('disconnect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_disconnected), this);
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected).call(this);
}
destroy() {
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").off('connect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected), this);
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").off('disconnect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_disconnected), this);
}
}
exports.SolanaWalletAdapterWallet = SolanaWalletAdapterWallet;
_SolanaWalletAdapterWallet_listeners = new WeakMap(), _SolanaWalletAdapterWallet_adapter = new WeakMap(), _SolanaWalletAdapterWallet_supportedTransactionVersions = new WeakMap(), _SolanaWalletAdapterWallet_chain = new WeakMap(), _SolanaWalletAdapterWallet_endpoint = new WeakMap(), _SolanaWalletAdapterWallet_account = new WeakMap(), _SolanaWalletAdapterWallet_connect = new WeakMap(), _SolanaWalletAdapterWallet_disconnect = new WeakMap(), _SolanaWalletAdapterWallet_on = new WeakMap(), _SolanaWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _SolanaWalletAdapterWallet_signTransaction = new WeakMap(), _SolanaWalletAdapterWallet_signMessage = new WeakMap(), _SolanaWalletAdapterWallet_signIn = new WeakMap(), _SolanaWalletAdapterWallet_instances = new WeakSet(), _SolanaWalletAdapterWallet_connected = function _SolanaWalletAdapterWallet_connected() {
var _a;
const publicKey = (_a = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").publicKey) === null || _a === void 0 ? void 0 : _a.toBytes();
if (publicKey) {
const address = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").publicKey.toBase58();
const account = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f");
if (!account ||
account.address !== address ||
account.chains.includes(__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_chain, "f")) ||
!(0, wallet_1.bytesEqual)(account.publicKey, publicKey)) {
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_account, new SolanaWalletAdapterWalletAccount({
adapter: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f"),
address,
publicKey,
chains: [__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_chain, "f")],
}), "f");
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
}
}
}, _SolanaWalletAdapterWallet_disconnected = function _SolanaWalletAdapterWallet_disconnected() {
if (__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f")) {
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_account, undefined, "f");
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
}
}, _SolanaWalletAdapterWallet_emit = function _SolanaWalletAdapterWallet_emit(event, ...args) {
var _a;
// eslint-disable-next-line prefer-spread
(_a = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
}, _SolanaWalletAdapterWallet_off = function _SolanaWalletAdapterWallet_off(event, listener) {
var _a;
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
}, _SolanaWalletAdapterWallet_deserializeTransaction = function _SolanaWalletAdapterWallet_deserializeTransaction(serializedTransaction) {
const transaction = web3_js_1.VersionedTransaction.deserialize(serializedTransaction);
if (!__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f").includes(transaction.version))
throw new Error('unsupported transaction version');
if (transaction.version === 'legacy' && (0, wallet_1.arraysEqual)(__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f"), ['legacy']))
return web3_js_1.Transaction.from(serializedTransaction);
return transaction;
};
/** TODO: docs */
function registerWalletAdapter(adapter, chain, endpoint, match = (wallet) => wallet.name === adapter.name) {
const { register, get, on } = (0, app_1.getWallets)();
const destructors = [];
function destroy() {
destructors.forEach((destroy) => destroy());
destructors.length = 0;
}
function setup() {
// If the adapter is unsupported, or a standard wallet that matches it has already been registered, do nothing.
if (adapter.readyState === wallet_adapter_base_1.WalletReadyState.Unsupported || get().some(match))
return true;
// If the adapter isn't ready, try again later.
const ready = adapter.readyState === wallet_adapter_base_1.WalletReadyState.Installed || adapter.readyState === wallet_adapter_base_1.WalletReadyState.Loadable;
if (ready) {
const wallet = new SolanaWalletAdapterWallet(adapter, chain, endpoint);
destructors.push(() => wallet.destroy());
// Register the adapter wrapped as a standard wallet, and receive a function to unregister the adapter.
destructors.push(register(wallet));
// Whenever a standard wallet is registered ...
destructors.push(on('register', (...wallets) => {
// ... check if it matches the adapter.
if (wallets.some(match)) {
// If it does, remove the event listener and unregister the adapter.
destroy();
}
}));
}
return ready;
}
if (!setup()) {
function listener() {
if (setup()) {
adapter.off('readyStateChange', listener);
}
}
adapter.on('readyStateChange', listener);
destructors.push(() => adapter.off('readyStateChange', listener));
}
return destroy;
}
//# sourceMappingURL=wallet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,397 @@
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _StandardWalletAdapter_instances, _StandardWalletAdapter_account, _StandardWalletAdapter_publicKey, _StandardWalletAdapter_connecting, _StandardWalletAdapter_disconnecting, _StandardWalletAdapter_off, _StandardWalletAdapter_supportedTransactionVersions, _StandardWalletAdapter_wallet, _StandardWalletAdapter_readyState, _StandardWalletAdapter_connect, _StandardWalletAdapter_connected, _StandardWalletAdapter_disconnected, _StandardWalletAdapter_reset, _StandardWalletAdapter_changed, _StandardWalletAdapter_signTransaction, _StandardWalletAdapter_signAllTransactions, _StandardWalletAdapter_signMessage, _StandardWalletAdapter_signIn;
import { BaseWalletAdapter, isVersionedTransaction, WalletAccountError, WalletConfigError, WalletConnectionError, WalletDisconnectedError, WalletDisconnectionError, WalletError, WalletNotConnectedError, WalletNotReadyError, WalletPublicKeyError, WalletReadyState, WalletSendTransactionError, WalletSignInError, WalletSignMessageError, WalletSignTransactionError, } from '@solana/wallet-adapter-base';
import { SolanaSignAndSendTransaction, SolanaSignIn, SolanaSignMessage, SolanaSignTransaction, } from '@solana/wallet-standard-features';
import { getChainForEndpoint, getCommitment } from '@solana/wallet-standard-util';
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
import { StandardConnect, StandardDisconnect, StandardEvents, } from '@wallet-standard/features';
import { arraysEqual } from '@wallet-standard/wallet';
import bs58 from 'bs58';
/** TODO: docs */
export class StandardWalletAdapter extends BaseWalletAdapter {
get name() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").name;
}
get url() {
return 'https://github.com/solana-labs/wallet-standard';
}
get icon() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").icon;
}
get readyState() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_readyState, "f");
}
get publicKey() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_publicKey, "f");
}
get connecting() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_connecting, "f");
}
get supportedTransactionVersions() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_supportedTransactionVersions, "f");
}
get wallet() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f");
}
get standard() {
return true;
}
constructor({ wallet }) {
super();
_StandardWalletAdapter_instances.add(this);
_StandardWalletAdapter_account.set(this, void 0);
_StandardWalletAdapter_publicKey.set(this, void 0);
_StandardWalletAdapter_connecting.set(this, void 0);
_StandardWalletAdapter_disconnecting.set(this, void 0);
_StandardWalletAdapter_off.set(this, void 0);
_StandardWalletAdapter_supportedTransactionVersions.set(this, void 0);
_StandardWalletAdapter_wallet.set(this, void 0);
_StandardWalletAdapter_readyState.set(this, typeof window === 'undefined' || typeof document === 'undefined'
? WalletReadyState.Unsupported
: WalletReadyState.Installed);
_StandardWalletAdapter_changed.set(this, (properties) => {
// If accounts have changed on the wallet, reflect this on the adapter.
if ('accounts' in properties) {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").accounts[0];
// If the adapter isn't connected, or is disconnecting, or the first account hasn't changed, do nothing.
if (__classPrivateFieldGet(this, _StandardWalletAdapter_account, "f") && !__classPrivateFieldGet(this, _StandardWalletAdapter_disconnecting, "f") && account !== __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f")) {
// If there's a connected account, connect the adapter. Otherwise, disconnect it.
if (account) {
// Connect the adapter.
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connected).call(this, account);
}
else {
// Emit an error because the wallet spontaneously disconnected.
this.emit('error', new WalletDisconnectedError());
// Disconnect the adapter.
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_disconnected).call(this);
}
}
}
// After reflecting account changes, if features have changed on the wallet, reflect this on the adapter.
if ('features' in properties) {
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
}
});
__classPrivateFieldSet(this, _StandardWalletAdapter_wallet, wallet, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_account, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, false, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, false, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_off, __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[StandardEvents].on('change', __classPrivateFieldGet(this, _StandardWalletAdapter_changed, "f")), "f");
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
}
destroy() {
__classPrivateFieldSet(this, _StandardWalletAdapter_account, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, false, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, false, "f");
const off = __classPrivateFieldGet(this, _StandardWalletAdapter_off, "f");
if (off) {
__classPrivateFieldSet(this, _StandardWalletAdapter_off, null, "f");
off();
}
}
async autoConnect() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connect).call(this, { silent: true });
}
async connect() {
return __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connect).call(this);
}
async disconnect() {
if (StandardDisconnect in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
try {
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, true, "f");
await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[StandardDisconnect].disconnect();
}
catch (error) {
this.emit('error', new WalletDisconnectionError(error?.message, error));
}
finally {
__classPrivateFieldSet(this, _StandardWalletAdapter_disconnecting, false, "f");
}
}
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_disconnected).call(this);
}
async sendTransaction(transaction, connection, options = {}) {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new WalletNotConnectedError();
let feature;
if (SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
if (account.features.includes(SolanaSignAndSendTransaction)) {
feature = SolanaSignAndSendTransaction;
}
else if (SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features &&
account.features.includes(SolanaSignTransaction)) {
feature = SolanaSignTransaction;
}
else {
throw new WalletAccountError();
}
}
else if (SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
if (!account.features.includes(SolanaSignTransaction))
throw new WalletAccountError();
feature = SolanaSignTransaction;
}
else {
throw new WalletConfigError();
}
const chain = getChainForEndpoint(connection.rpcEndpoint);
if (!account.chains.includes(chain))
throw new WalletSendTransactionError();
try {
const { signers, ...sendOptions } = options;
let serializedTransaction;
if (isVersionedTransaction(transaction)) {
signers?.length && transaction.sign(signers);
serializedTransaction = transaction.serialize();
}
else {
transaction = (await this.prepareTransaction(transaction, connection, sendOptions));
signers?.length && transaction.partialSign(...signers);
serializedTransaction = new Uint8Array(transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
}));
}
if (feature === SolanaSignAndSendTransaction) {
const [output] = await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignAndSendTransaction].signAndSendTransaction({
account,
chain,
transaction: serializedTransaction,
options: {
preflightCommitment: getCommitment(sendOptions.preflightCommitment || connection.commitment),
skipPreflight: sendOptions.skipPreflight,
maxRetries: sendOptions.maxRetries,
minContextSlot: sendOptions.minContextSlot,
},
});
return bs58.encode(output.signature);
}
else {
const [output] = await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignTransaction].signTransaction({
account,
chain,
transaction: serializedTransaction,
options: {
preflightCommitment: getCommitment(sendOptions.preflightCommitment || connection.commitment),
minContextSlot: sendOptions.minContextSlot,
},
});
return await connection.sendRawTransaction(output.signedTransaction, {
...sendOptions,
preflightCommitment: getCommitment(sendOptions.preflightCommitment || connection.commitment),
});
}
}
catch (error) {
if (error instanceof WalletError)
throw error;
throw new WalletSendTransactionError(error?.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
}
}
_StandardWalletAdapter_account = new WeakMap(), _StandardWalletAdapter_publicKey = new WeakMap(), _StandardWalletAdapter_connecting = new WeakMap(), _StandardWalletAdapter_disconnecting = new WeakMap(), _StandardWalletAdapter_off = new WeakMap(), _StandardWalletAdapter_supportedTransactionVersions = new WeakMap(), _StandardWalletAdapter_wallet = new WeakMap(), _StandardWalletAdapter_readyState = new WeakMap(), _StandardWalletAdapter_changed = new WeakMap(), _StandardWalletAdapter_instances = new WeakSet(), _StandardWalletAdapter_connect = async function _StandardWalletAdapter_connect(input) {
try {
if (this.connected || this.connecting)
return;
if (__classPrivateFieldGet(this, _StandardWalletAdapter_readyState, "f") !== WalletReadyState.Installed)
throw new WalletNotReadyError();
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, true, "f");
if (!__classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").accounts.length) {
try {
await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[StandardConnect].connect(input);
}
catch (error) {
throw new WalletConnectionError(error?.message, error);
}
}
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").accounts[0];
if (!account)
throw new WalletAccountError();
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connected).call(this, account);
}
catch (error) {
this.emit('error', error);
throw error;
}
finally {
__classPrivateFieldSet(this, _StandardWalletAdapter_connecting, false, "f");
}
}, _StandardWalletAdapter_connected = function _StandardWalletAdapter_connected(account) {
let publicKey;
try {
// Use account.address instead of account.publicKey since address could be a PDA
publicKey = new PublicKey(account.address);
}
catch (error) {
throw new WalletPublicKeyError(error?.message, error);
}
__classPrivateFieldSet(this, _StandardWalletAdapter_account, account, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, publicKey, "f");
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
this.emit('connect', publicKey);
}, _StandardWalletAdapter_disconnected = function _StandardWalletAdapter_disconnected() {
__classPrivateFieldSet(this, _StandardWalletAdapter_account, null, "f");
__classPrivateFieldSet(this, _StandardWalletAdapter_publicKey, null, "f");
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_reset).call(this);
this.emit('disconnect');
}, _StandardWalletAdapter_reset = function _StandardWalletAdapter_reset() {
const supportedTransactionVersions = SolanaSignAndSendTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features
? __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignAndSendTransaction].supportedTransactionVersions
: __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignTransaction].supportedTransactionVersions;
__classPrivateFieldSet(this, _StandardWalletAdapter_supportedTransactionVersions, arraysEqual(supportedTransactionVersions, ['legacy'])
? null
: new Set(supportedTransactionVersions), "f");
if (SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features && __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f")?.features.includes(SolanaSignTransaction)) {
this.signTransaction = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signTransaction);
this.signAllTransactions = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signAllTransactions);
}
else {
delete this.signTransaction;
delete this.signAllTransactions;
}
if (SolanaSignMessage in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features && __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f")?.features.includes(SolanaSignMessage)) {
this.signMessage = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signMessage);
}
else {
delete this.signMessage;
}
if (SolanaSignIn in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features) {
this.signIn = __classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_signIn);
}
else {
delete this.signIn;
}
}, _StandardWalletAdapter_signTransaction = async function _StandardWalletAdapter_signTransaction(transaction) {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new WalletNotConnectedError();
if (!(SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new WalletConfigError();
if (!account.features.includes(SolanaSignTransaction))
throw new WalletAccountError();
try {
const signedTransactions = await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignTransaction].signTransaction({
account,
transaction: isVersionedTransaction(transaction)
? transaction.serialize()
: new Uint8Array(transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})),
});
const serializedTransaction = signedTransactions[0].signedTransaction;
return (isVersionedTransaction(transaction)
? VersionedTransaction.deserialize(serializedTransaction)
: Transaction.from(serializedTransaction));
}
catch (error) {
if (error instanceof WalletError)
throw error;
throw new WalletSignTransactionError(error?.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
}, _StandardWalletAdapter_signAllTransactions = async function _StandardWalletAdapter_signAllTransactions(transactions) {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new WalletNotConnectedError();
if (!(SolanaSignTransaction in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new WalletConfigError();
if (!account.features.includes(SolanaSignTransaction))
throw new WalletAccountError();
try {
const signedTransactions = await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignTransaction].signTransaction(...transactions.map((transaction) => ({
account,
transaction: isVersionedTransaction(transaction)
? transaction.serialize()
: new Uint8Array(transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})),
})));
return transactions.map((transaction, index) => {
const signedTransaction = signedTransactions[index].signedTransaction;
return (isVersionedTransaction(transaction)
? VersionedTransaction.deserialize(signedTransaction)
: Transaction.from(signedTransaction));
});
}
catch (error) {
throw new WalletSignTransactionError(error?.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
}, _StandardWalletAdapter_signMessage = async function _StandardWalletAdapter_signMessage(message) {
try {
const account = __classPrivateFieldGet(this, _StandardWalletAdapter_account, "f");
if (!account)
throw new WalletNotConnectedError();
if (!(SolanaSignMessage in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new WalletConfigError();
if (!account.features.includes(SolanaSignMessage))
throw new WalletAccountError();
try {
const signedMessages = await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignMessage].signMessage({
account,
message,
});
return signedMessages[0].signature;
}
catch (error) {
throw new WalletSignMessageError(error?.message, error);
}
}
catch (error) {
this.emit('error', error);
throw error;
}
}, _StandardWalletAdapter_signIn = async function _StandardWalletAdapter_signIn(input = {}) {
try {
if (!(SolanaSignIn in __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features))
throw new WalletConfigError();
let output;
try {
[output] = await __classPrivateFieldGet(this, _StandardWalletAdapter_wallet, "f").features[SolanaSignIn].signIn(input);
}
catch (error) {
throw new WalletSignInError(error?.message, error);
}
if (!output)
throw new WalletSignInError();
__classPrivateFieldGet(this, _StandardWalletAdapter_instances, "m", _StandardWalletAdapter_connected).call(this, output.account);
return output;
}
catch (error) {
this.emit('error', error);
throw error;
}
};
//# sourceMappingURL=adapter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
export * from './adapter.js';
export * from './types.js';
export * from './wallet.js';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}

View File

@@ -0,0 +1 @@
{"root":["../../src/adapter.ts","../../src/index.ts","../../src/types.ts","../../src/wallet.ts"],"version":"5.7.3"}

View File

@@ -0,0 +1,8 @@
import { isWalletAdapterCompatibleStandardWallet, } from '@solana/wallet-adapter-base';
/**
* @deprecated Use `isWalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export const isWalletAdapterCompatibleWallet = isWalletAdapterCompatibleStandardWallet;
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uCAAuC,GAG1C,MAAM,6BAA6B,CAAC;AAgBrC;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,uCAAuC,CAAC"}

View File

@@ -0,0 +1,349 @@
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _SolanaWalletAdapterWalletAccount_adapter, _SolanaWalletAdapterWallet_instances, _SolanaWalletAdapterWallet_listeners, _SolanaWalletAdapterWallet_adapter, _SolanaWalletAdapterWallet_supportedTransactionVersions, _SolanaWalletAdapterWallet_chain, _SolanaWalletAdapterWallet_endpoint, _SolanaWalletAdapterWallet_account, _SolanaWalletAdapterWallet_connected, _SolanaWalletAdapterWallet_disconnected, _SolanaWalletAdapterWallet_connect, _SolanaWalletAdapterWallet_disconnect, _SolanaWalletAdapterWallet_on, _SolanaWalletAdapterWallet_emit, _SolanaWalletAdapterWallet_off, _SolanaWalletAdapterWallet_deserializeTransaction, _SolanaWalletAdapterWallet_signAndSendTransaction, _SolanaWalletAdapterWallet_signTransaction, _SolanaWalletAdapterWallet_signMessage, _SolanaWalletAdapterWallet_signIn;
import { isVersionedTransaction, WalletReadyState } from '@solana/wallet-adapter-base';
import { isSolanaChain } from '@solana/wallet-standard-chains';
import { SolanaSignAndSendTransaction, SolanaSignIn, SolanaSignMessage, SolanaSignTransaction, } from '@solana/wallet-standard-features';
import { getEndpointForChain } from '@solana/wallet-standard-util';
import { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';
import { getWallets } from '@wallet-standard/app';
import { StandardConnect, StandardDisconnect, StandardEvents, } from '@wallet-standard/features';
import { arraysEqual, bytesEqual, ReadonlyWalletAccount } from '@wallet-standard/wallet';
import bs58 from 'bs58';
/** TODO: docs */
export class SolanaWalletAdapterWalletAccount extends ReadonlyWalletAccount {
constructor({ adapter, address, publicKey, chains, }) {
const features = [SolanaSignAndSendTransaction];
if ('signTransaction' in adapter) {
features.push(SolanaSignTransaction);
}
if ('signMessage' in adapter) {
features.push(SolanaSignMessage);
}
if ('signIn' in adapter) {
features.push(SolanaSignIn);
}
super({ address, publicKey, chains, features });
// eslint-disable-next-line no-unused-private-class-members
_SolanaWalletAdapterWalletAccount_adapter.set(this, void 0);
if (new.target === SolanaWalletAdapterWalletAccount) {
Object.freeze(this);
}
__classPrivateFieldSet(this, _SolanaWalletAdapterWalletAccount_adapter, adapter, "f");
}
}
_SolanaWalletAdapterWalletAccount_adapter = new WeakMap();
/** TODO: docs */
export class SolanaWalletAdapterWallet {
get version() {
return '1.0.0';
}
get name() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").name;
}
get icon() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").icon;
}
get chains() {
return [__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_chain, "f")];
}
get features() {
const features = {
[StandardConnect]: {
version: '1.0.0',
connect: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_connect, "f"),
},
[StandardDisconnect]: {
version: '1.0.0',
disconnect: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_disconnect, "f"),
},
[StandardEvents]: {
version: '1.0.0',
on: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_on, "f"),
},
[SolanaSignAndSendTransaction]: {
version: '1.0.0',
supportedTransactionVersions: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f"),
signAndSendTransaction: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signAndSendTransaction, "f"),
},
};
let signTransactionFeature;
if ('signTransaction' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")) {
signTransactionFeature = {
[SolanaSignTransaction]: {
version: '1.0.0',
supportedTransactionVersions: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f"),
signTransaction: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signTransaction, "f"),
},
};
}
let signMessageFeature;
if ('signMessage' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")) {
signMessageFeature = {
[SolanaSignMessage]: {
version: '1.0.0',
signMessage: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signMessage, "f"),
},
};
}
let signInFeature;
if ('signIn' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")) {
signInFeature = {
[SolanaSignIn]: {
version: '1.0.0',
signIn: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signIn, "f"),
},
};
}
return { ...features, ...signTransactionFeature, ...signMessageFeature };
}
get accounts() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f") ? [__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f")] : [];
}
get endpoint() {
return __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_endpoint, "f");
}
constructor(adapter, chain, endpoint) {
_SolanaWalletAdapterWallet_instances.add(this);
_SolanaWalletAdapterWallet_listeners.set(this, {});
_SolanaWalletAdapterWallet_adapter.set(this, void 0);
_SolanaWalletAdapterWallet_supportedTransactionVersions.set(this, void 0);
_SolanaWalletAdapterWallet_chain.set(this, void 0);
_SolanaWalletAdapterWallet_endpoint.set(this, void 0);
_SolanaWalletAdapterWallet_account.set(this, void 0);
_SolanaWalletAdapterWallet_connect.set(this, async ({ silent } = {}) => {
if (!silent && !__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").connected) {
await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").connect();
}
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected).call(this);
return { accounts: this.accounts };
});
_SolanaWalletAdapterWallet_disconnect.set(this, async () => {
await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").disconnect();
});
_SolanaWalletAdapterWallet_on.set(this, (event, listener) => {
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event]?.push(listener) || (__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event] = [listener]);
return () => __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_off).call(this, event, listener);
});
_SolanaWalletAdapterWallet_signAndSendTransaction.set(this, async (...inputs) => {
const outputs = [];
if (inputs.length === 1) {
const input = inputs[0];
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
if (!isSolanaChain(input.chain))
throw new Error('invalid chain');
const transaction = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_deserializeTransaction).call(this, input.transaction);
const { commitment, preflightCommitment, skipPreflight, maxRetries, minContextSlot } = input.options || {};
const endpoint = getEndpointForChain(input.chain, __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_endpoint, "f"));
const connection = new Connection(endpoint, commitment || 'confirmed');
const latestBlockhash = commitment
? await connection.getLatestBlockhash({
commitment: preflightCommitment || commitment,
minContextSlot,
})
: undefined;
const signature = await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").sendTransaction(transaction, connection, {
preflightCommitment,
skipPreflight,
maxRetries,
minContextSlot,
});
if (latestBlockhash) {
await connection.confirmTransaction({
...latestBlockhash,
signature,
}, commitment || 'confirmed');
}
outputs.push({ signature: bs58.decode(signature) });
}
else if (inputs.length > 1) {
// Adapters have no `sendAllTransactions` method, so just sign and send each transaction in serial.
for (const input of inputs) {
outputs.push(...(await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signAndSendTransaction, "f").call(this, input)));
}
}
return outputs;
});
_SolanaWalletAdapterWallet_signTransaction.set(this, async (...inputs) => {
if (!('signTransaction' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")))
throw new Error('signTransaction not implemented by adapter');
const outputs = [];
if (inputs.length === 1) {
const input = inputs[0];
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
if (input.chain && !isSolanaChain(input.chain))
throw new Error('invalid chain');
const transaction = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_deserializeTransaction).call(this, input.transaction);
const signedTransaction = await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signTransaction(transaction);
const serializedTransaction = isVersionedTransaction(signedTransaction)
? signedTransaction.serialize()
: new Uint8Array(signedTransaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
}));
outputs.push({ signedTransaction: serializedTransaction });
}
else if (inputs.length > 1) {
for (const input of inputs) {
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
if (input.chain && !isSolanaChain(input.chain))
throw new Error('invalid chain');
}
const transactions = inputs.map(({ transaction }) => __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_deserializeTransaction).call(this, transaction));
const signedTransactions = await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signAllTransactions(transactions);
outputs.push(...signedTransactions.map((signedTransaction) => {
const serializedTransaction = isVersionedTransaction(signedTransaction)
? signedTransaction.serialize()
: new Uint8Array(signedTransaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
}));
return { signedTransaction: serializedTransaction };
}));
}
return outputs;
});
_SolanaWalletAdapterWallet_signMessage.set(this, async (...inputs) => {
if (!('signMessage' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")))
throw new Error('signMessage not implemented by adapter');
const outputs = [];
if (inputs.length === 1) {
const input = inputs[0];
if (input.account !== __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f"))
throw new Error('invalid account');
const signature = await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signMessage(input.message);
outputs.push({ signedMessage: input.message, signature });
}
else if (inputs.length > 1) {
// Adapters have no `signAllMessages` method, so just sign each message in serial.
for (const input of inputs) {
outputs.push(...(await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_signMessage, "f").call(this, input)));
}
}
return outputs;
});
_SolanaWalletAdapterWallet_signIn.set(this, async (...inputs) => {
if (!('signIn' in __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f")))
throw new Error('signIn not implemented by adapter');
if (inputs.length > 1) {
// Adapters don't support `signIn` with multiple inputs, so just sign in with each input in serial.
const outputs = [];
for (const input of inputs) {
outputs.push(await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signIn(input));
}
return outputs;
}
else {
return [await __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").signIn(inputs[0])];
}
});
if (new.target === SolanaWalletAdapterWallet) {
Object.freeze(this);
}
const supportedTransactionVersions = [...(adapter.supportedTransactionVersions || ['legacy'])];
if (!supportedTransactionVersions.length) {
supportedTransactionVersions.push('legacy');
}
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_adapter, adapter, "f");
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, supportedTransactionVersions, "f");
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_chain, chain, "f");
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_endpoint, endpoint, "f");
adapter.on('connect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected), this);
adapter.on('disconnect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_disconnected), this);
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected).call(this);
}
destroy() {
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").off('connect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_connected), this);
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").off('disconnect', __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_disconnected), this);
}
}
_SolanaWalletAdapterWallet_listeners = new WeakMap(), _SolanaWalletAdapterWallet_adapter = new WeakMap(), _SolanaWalletAdapterWallet_supportedTransactionVersions = new WeakMap(), _SolanaWalletAdapterWallet_chain = new WeakMap(), _SolanaWalletAdapterWallet_endpoint = new WeakMap(), _SolanaWalletAdapterWallet_account = new WeakMap(), _SolanaWalletAdapterWallet_connect = new WeakMap(), _SolanaWalletAdapterWallet_disconnect = new WeakMap(), _SolanaWalletAdapterWallet_on = new WeakMap(), _SolanaWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _SolanaWalletAdapterWallet_signTransaction = new WeakMap(), _SolanaWalletAdapterWallet_signMessage = new WeakMap(), _SolanaWalletAdapterWallet_signIn = new WeakMap(), _SolanaWalletAdapterWallet_instances = new WeakSet(), _SolanaWalletAdapterWallet_connected = function _SolanaWalletAdapterWallet_connected() {
const publicKey = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").publicKey?.toBytes();
if (publicKey) {
const address = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f").publicKey.toBase58();
const account = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f");
if (!account ||
account.address !== address ||
account.chains.includes(__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_chain, "f")) ||
!bytesEqual(account.publicKey, publicKey)) {
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_account, new SolanaWalletAdapterWalletAccount({
adapter: __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_adapter, "f"),
address,
publicKey,
chains: [__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_chain, "f")],
}), "f");
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
}
}
}, _SolanaWalletAdapterWallet_disconnected = function _SolanaWalletAdapterWallet_disconnected() {
if (__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_account, "f")) {
__classPrivateFieldSet(this, _SolanaWalletAdapterWallet_account, undefined, "f");
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_instances, "m", _SolanaWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
}
}, _SolanaWalletAdapterWallet_emit = function _SolanaWalletAdapterWallet_emit(event, ...args) {
// eslint-disable-next-line prefer-spread
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event]?.forEach((listener) => listener.apply(null, args));
}, _SolanaWalletAdapterWallet_off = function _SolanaWalletAdapterWallet_off(event, listener) {
__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event] = __classPrivateFieldGet(this, _SolanaWalletAdapterWallet_listeners, "f")[event]?.filter((existingListener) => listener !== existingListener);
}, _SolanaWalletAdapterWallet_deserializeTransaction = function _SolanaWalletAdapterWallet_deserializeTransaction(serializedTransaction) {
const transaction = VersionedTransaction.deserialize(serializedTransaction);
if (!__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f").includes(transaction.version))
throw new Error('unsupported transaction version');
if (transaction.version === 'legacy' && arraysEqual(__classPrivateFieldGet(this, _SolanaWalletAdapterWallet_supportedTransactionVersions, "f"), ['legacy']))
return Transaction.from(serializedTransaction);
return transaction;
};
/** TODO: docs */
export function registerWalletAdapter(adapter, chain, endpoint, match = (wallet) => wallet.name === adapter.name) {
const { register, get, on } = getWallets();
const destructors = [];
function destroy() {
destructors.forEach((destroy) => destroy());
destructors.length = 0;
}
function setup() {
// If the adapter is unsupported, or a standard wallet that matches it has already been registered, do nothing.
if (adapter.readyState === WalletReadyState.Unsupported || get().some(match))
return true;
// If the adapter isn't ready, try again later.
const ready = adapter.readyState === WalletReadyState.Installed || adapter.readyState === WalletReadyState.Loadable;
if (ready) {
const wallet = new SolanaWalletAdapterWallet(adapter, chain, endpoint);
destructors.push(() => wallet.destroy());
// Register the adapter wrapped as a standard wallet, and receive a function to unregister the adapter.
destructors.push(register(wallet));
// Whenever a standard wallet is registered ...
destructors.push(on('register', (...wallets) => {
// ... check if it matches the adapter.
if (wallets.some(match)) {
// If it does, remove the event listener and unregister the adapter.
destroy();
}
}));
}
return ready;
}
if (!setup()) {
function listener() {
if (setup()) {
adapter.off('readyStateChange', listener);
}
}
adapter.on('readyStateChange', listener);
destructors.push(() => adapter.off('readyStateChange', listener));
}
return destroy;
}
//# sourceMappingURL=wallet.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,32 @@
import { BaseWalletAdapter, type SendTransactionOptions, type StandardWalletAdapter as StandardWalletAdapterType, type SupportedTransactionVersions, type WalletAdapterCompatibleStandardWallet, type WalletName, WalletReadyState } from '@solana/wallet-adapter-base';
import { type SolanaSignInInput, type SolanaSignInOutput } from '@solana/wallet-standard-features';
import type { Connection, TransactionSignature } from '@solana/web3.js';
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
/** TODO: docs */
export interface StandardWalletAdapterConfig {
wallet: WalletAdapterCompatibleStandardWallet;
}
/** TODO: docs */
export declare class StandardWalletAdapter extends BaseWalletAdapter implements StandardWalletAdapterType {
#private;
get name(): WalletName;
get url(): string;
get icon(): `data:image/svg+xml;base64,${string}` | `data:image/webp;base64,${string}` | `data:image/png;base64,${string}` | `data:image/gif;base64,${string}`;
get readyState(): WalletReadyState;
get publicKey(): PublicKey | null;
get connecting(): boolean;
get supportedTransactionVersions(): SupportedTransactionVersions;
get wallet(): WalletAdapterCompatibleStandardWallet;
get standard(): true;
constructor({ wallet }: StandardWalletAdapterConfig);
destroy(): void;
autoConnect(): Promise<void>;
connect(): Promise<void>;
disconnect(): Promise<void>;
sendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, connection: Connection, options?: SendTransactionOptions): Promise<TransactionSignature>;
signTransaction: (<T extends Transaction | VersionedTransaction>(transaction: T) => Promise<T>) | undefined;
signAllTransactions: (<T extends Transaction | VersionedTransaction>(transaction: T[]) => Promise<T[]>) | undefined;
signMessage: ((message: Uint8Array) => Promise<Uint8Array>) | undefined;
signIn: ((input?: SolanaSignInInput) => Promise<SolanaSignInOutput>) | undefined;
}
//# sourceMappingURL=adapter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EAEjB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,4BAA4B,EAEjC,KAAK,qCAAqC,EAM1C,KAAK,UAAU,EAIf,gBAAgB,EAKnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAIH,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAI1B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAY/E,iBAAiB;AACjB,MAAM,WAAW,2BAA2B;IACxC,MAAM,EAAE,qCAAqC,CAAC;CACjD;AAED,iBAAiB;AACjB,qBAAa,qBAAsB,SAAQ,iBAAkB,YAAW,yBAAyB;;IAa7F,IAAI,IAAI,IACwB,UAAU,CACzC;IAED,IAAI,GAAG,WAEN;IAED,IAAI,IAAI,uJAEP;IAED,IAAI,UAAU,qBAEb;IAED,IAAI,SAAS,qBAEZ;IAED,IAAI,UAAU,YAEb;IAED,IAAI,4BAA4B,iCAE/B;IAED,IAAI,MAAM,IAAI,qCAAqC,CAElD;IAED,IAAI,QAAQ,IACD,IAAI,CACd;gBAEW,EAAE,MAAM,EAAE,EAAE,2BAA2B;IAanD,OAAO,IAAI,IAAI;IAaT,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4F3B,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,oBAAoB,EAC9D,WAAW,EAAE,CAAC,EACd,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,sBAA2B,GACrC,OAAO,CAAC,oBAAoB,CAAC;IA6FhC,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,WAAW,GAAG,oBAAoB,EAAE,WAAW,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAuC5G,mBAAmB,EAAE,CAAC,CAAC,CAAC,SAAS,WAAW,GAAG,oBAAoB,EAAE,WAAW,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IA0CpH,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC;IAyBxE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC,GAAG,SAAS,CAAC;CAoBpF"}

View File

@@ -0,0 +1,4 @@
export * from './adapter.js';
export * from './types.js';
export * from './wallet.js';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}

View File

@@ -0,0 +1,20 @@
import { isWalletAdapterCompatibleStandardWallet, type StandardWalletAdapter, type WalletAdapterCompatibleStandardWallet } from '@solana/wallet-adapter-base';
/**
* @deprecated Use `StandardWalletAdapter` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export type StandardAdapter = StandardWalletAdapter;
/**
* @deprecated Use `WalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export type WalletAdapterCompatibleWallet = WalletAdapterCompatibleStandardWallet;
/**
* @deprecated Use `isWalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export declare const isWalletAdapterCompatibleWallet: typeof isWalletAdapterCompatibleStandardWallet;
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uCAAuC,EACvC,KAAK,qBAAqB,EAC1B,KAAK,qCAAqC,EAC7C,MAAM,6BAA6B,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,GAAG,qCAAqC,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,gDAA0C,CAAC"}

View File

@@ -0,0 +1,32 @@
import { type Adapter } from '@solana/wallet-adapter-base';
import { type SolanaChain } from '@solana/wallet-standard-chains';
import { type SolanaSignAndSendTransactionFeature, type SolanaSignInFeature, type SolanaSignMessageFeature, type SolanaSignTransactionFeature } from '@solana/wallet-standard-features';
import type { Wallet, WalletIcon } from '@wallet-standard/base';
import { type StandardConnectFeature, type StandardDisconnectFeature, type StandardEventsFeature } from '@wallet-standard/features';
import { ReadonlyWalletAccount } from '@wallet-standard/wallet';
/** TODO: docs */
export declare class SolanaWalletAdapterWalletAccount extends ReadonlyWalletAccount {
#private;
constructor({ adapter, address, publicKey, chains, }: {
adapter: Adapter;
address: string;
publicKey: Uint8Array;
chains: readonly SolanaChain[];
});
}
/** TODO: docs */
export declare class SolanaWalletAdapterWallet implements Wallet {
#private;
get version(): "1.0.0";
get name(): import("@solana/wallet-adapter-base").WalletName<string>;
get icon(): WalletIcon;
get chains(): ("solana:mainnet" | "solana:devnet" | "solana:testnet" | "solana:localnet")[];
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SolanaSignAndSendTransactionFeature & Partial<SolanaSignTransactionFeature & SolanaSignMessageFeature & SolanaSignInFeature>;
get accounts(): SolanaWalletAdapterWalletAccount[];
get endpoint(): string | undefined;
constructor(adapter: Adapter, chain: SolanaChain, endpoint?: string);
destroy(): void;
}
/** TODO: docs */
export declare function registerWalletAdapter(adapter: Adapter, chain: SolanaChain, endpoint?: string, match?: (wallet: Wallet) => boolean): () => void;
//# sourceMappingURL=wallet.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAA4C,MAAM,6BAA6B,CAAC;AACrG,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAEH,KAAK,mCAAmC,EAIxC,KAAK,mBAAmB,EAIxB,KAAK,wBAAwB,EAI7B,KAAK,4BAA4B,EAIpC,MAAM,kCAAkC,CAAC;AAI1C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAEH,KAAK,sBAAsB,EAG3B,KAAK,yBAAyB,EAG9B,KAAK,qBAAqB,EAI7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAA2B,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGzF,iBAAiB;AACjB,qBAAa,gCAAiC,SAAQ,qBAAqB;;gBAI3D,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,MAAM,GACT,EAAE;QACC,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,UAAU,CAAC;QACtB,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;KAClC;CAsBJ;AAED,iBAAiB;AACjB,qBAAa,yBAA0B,YAAW,MAAM;;IAUpD,IAAI,OAAO,IACA,OAAO,CACjB;IAED,IAAI,IAAI,6DAEP;IAED,IAAI,IAAI,IACyB,UAAU,CAC1C;IAED,IAAI,MAAM,kFAET;IAED,IAAI,QAAQ,IAAI,sBAAsB,GAClC,yBAAyB,GACzB,qBAAqB,GACrB,mCAAmC,GACnC,OAAO,CAAC,4BAA4B,GAAG,wBAAwB,GAAG,mBAAmB,CAAC,CAwDzF;IAED,IAAI,QAAQ,uCAEX;IAED,IAAI,QAAQ,uBAEX;gBAEW,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,MAAM;IAqBnE,OAAO,IAAI,IAAI;CA2MlB;AAED,iBAAiB;AACjB,wBAAgB,qBAAqB,CACjC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,KAAK,GAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAkD,GAC9E,MAAM,IAAI,CA+CZ"}

View File

@@ -0,0 +1,51 @@
{
"name": "@solana/wallet-standard-wallet-adapter-base",
"version": "1.1.4",
"author": "Solana Maintainers <maintainers@solana.foundation>",
"repository": "https://github.com/solana-labs/wallet-standard",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"files": [
"lib",
"src",
"LICENSE"
],
"engines": {
"node": ">=16"
},
"type": "module",
"sideEffects": false,
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts"
},
"peerDependencies": {
"@solana/web3.js": "^1.98.0",
"bs58": "^6.0.0"
},
"dependencies": {
"@solana/wallet-adapter-base": "^0.9.23",
"@wallet-standard/app": "^1.1.0",
"@wallet-standard/base": "^1.1.0",
"@wallet-standard/features": "^1.1.0",
"@wallet-standard/wallet": "^1.1.0",
"@solana/wallet-standard-chains": "^1.1.1",
"@solana/wallet-standard-features": "^1.3.0",
"@solana/wallet-standard-util": "^1.1.2"
},
"devDependencies": {
"@solana/web3.js": "^1.98.0",
"bs58": "^6.0.0",
"shx": "^0.3.4"
},
"scripts": {
"clean": "shx mkdir -p lib && shx rm -rf lib",
"package": "shx mkdir -p lib/cjs && shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json"
}
}

View File

@@ -0,0 +1,479 @@
import {
BaseWalletAdapter,
isVersionedTransaction,
type SendTransactionOptions,
type StandardWalletAdapter as StandardWalletAdapterType,
type SupportedTransactionVersions,
WalletAccountError,
type WalletAdapterCompatibleStandardWallet,
WalletConfigError,
WalletConnectionError,
WalletDisconnectedError,
WalletDisconnectionError,
WalletError,
type WalletName,
WalletNotConnectedError,
WalletNotReadyError,
WalletPublicKeyError,
WalletReadyState,
WalletSendTransactionError,
WalletSignInError,
WalletSignMessageError,
WalletSignTransactionError,
} from '@solana/wallet-adapter-base';
import {
SolanaSignAndSendTransaction,
type SolanaSignAndSendTransactionFeature,
SolanaSignIn,
type SolanaSignInInput,
type SolanaSignInOutput,
SolanaSignMessage,
SolanaSignTransaction,
type SolanaSignTransactionFeature,
} from '@solana/wallet-standard-features';
import { getChainForEndpoint, getCommitment } from '@solana/wallet-standard-util';
import type { Connection, TransactionSignature } from '@solana/web3.js';
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
import type { WalletAccount } from '@wallet-standard/base';
import {
StandardConnect,
type StandardConnectInput,
StandardDisconnect,
StandardEvents,
type StandardEventsListeners,
} from '@wallet-standard/features';
import { arraysEqual } from '@wallet-standard/wallet';
import bs58 from 'bs58';
/** TODO: docs */
export interface StandardWalletAdapterConfig {
wallet: WalletAdapterCompatibleStandardWallet;
}
/** TODO: docs */
export class StandardWalletAdapter extends BaseWalletAdapter implements StandardWalletAdapterType {
#account: WalletAccount | null;
#publicKey: PublicKey | null;
#connecting: boolean;
#disconnecting: boolean;
#off: (() => void) | null;
#supportedTransactionVersions: SupportedTransactionVersions;
readonly #wallet: WalletAdapterCompatibleStandardWallet;
readonly #readyState: WalletReadyState =
typeof window === 'undefined' || typeof document === 'undefined'
? WalletReadyState.Unsupported
: WalletReadyState.Installed;
get name() {
return this.#wallet.name as WalletName;
}
get url() {
return 'https://github.com/solana-labs/wallet-standard';
}
get icon() {
return this.#wallet.icon;
}
get readyState() {
return this.#readyState;
}
get publicKey() {
return this.#publicKey;
}
get connecting() {
return this.#connecting;
}
get supportedTransactionVersions() {
return this.#supportedTransactionVersions;
}
get wallet(): WalletAdapterCompatibleStandardWallet {
return this.#wallet;
}
get standard() {
return true as const;
}
constructor({ wallet }: StandardWalletAdapterConfig) {
super();
this.#wallet = wallet;
this.#account = null;
this.#publicKey = null;
this.#connecting = false;
this.#disconnecting = false;
this.#off = this.#wallet.features[StandardEvents].on('change', this.#changed);
this.#reset();
}
destroy(): void {
this.#account = null;
this.#publicKey = null;
this.#connecting = false;
this.#disconnecting = false;
const off = this.#off;
if (off) {
this.#off = null;
off();
}
}
async autoConnect(): Promise<void> {
return this.#connect({ silent: true });
}
async connect(): Promise<void> {
return this.#connect();
}
async #connect(input?: StandardConnectInput): Promise<void> {
try {
if (this.connected || this.connecting) return;
if (this.#readyState !== WalletReadyState.Installed) throw new WalletNotReadyError();
this.#connecting = true;
if (!this.#wallet.accounts.length) {
try {
await this.#wallet.features[StandardConnect].connect(input);
} catch (error: any) {
throw new WalletConnectionError(error?.message, error);
}
}
const account = this.#wallet.accounts[0];
if (!account) throw new WalletAccountError();
this.#connected(account);
} catch (error: any) {
this.emit('error', error);
throw error;
} finally {
this.#connecting = false;
}
}
async disconnect(): Promise<void> {
if (StandardDisconnect in this.#wallet.features) {
try {
this.#disconnecting = true;
await this.#wallet.features[StandardDisconnect].disconnect();
} catch (error: any) {
this.emit('error', new WalletDisconnectionError(error?.message, error));
} finally {
this.#disconnecting = false;
}
}
this.#disconnected();
}
#connected(account: WalletAccount) {
let publicKey: PublicKey;
try {
// Use account.address instead of account.publicKey since address could be a PDA
publicKey = new PublicKey(account.address);
} catch (error: any) {
throw new WalletPublicKeyError(error?.message, error);
}
this.#account = account;
this.#publicKey = publicKey;
this.#reset();
this.emit('connect', publicKey);
}
#disconnected(): void {
this.#account = null;
this.#publicKey = null;
this.#reset();
this.emit('disconnect');
}
#reset() {
const supportedTransactionVersions =
SolanaSignAndSendTransaction in this.#wallet.features
? this.#wallet.features[SolanaSignAndSendTransaction].supportedTransactionVersions
: this.#wallet.features[SolanaSignTransaction].supportedTransactionVersions;
this.#supportedTransactionVersions = arraysEqual(supportedTransactionVersions, ['legacy'])
? null
: new Set(supportedTransactionVersions);
if (SolanaSignTransaction in this.#wallet.features && this.#account?.features.includes(SolanaSignTransaction)) {
this.signTransaction = this.#signTransaction;
this.signAllTransactions = this.#signAllTransactions;
} else {
delete this.signTransaction;
delete this.signAllTransactions;
}
if (SolanaSignMessage in this.#wallet.features && this.#account?.features.includes(SolanaSignMessage)) {
this.signMessage = this.#signMessage;
} else {
delete this.signMessage;
}
if (SolanaSignIn in this.#wallet.features) {
this.signIn = this.#signIn;
} else {
delete this.signIn;
}
}
#changed: StandardEventsListeners['change'] = (properties) => {
// If accounts have changed on the wallet, reflect this on the adapter.
if ('accounts' in properties) {
const account = this.#wallet.accounts[0];
// If the adapter isn't connected, or is disconnecting, or the first account hasn't changed, do nothing.
if (this.#account && !this.#disconnecting && account !== this.#account) {
// If there's a connected account, connect the adapter. Otherwise, disconnect it.
if (account) {
// Connect the adapter.
this.#connected(account);
} else {
// Emit an error because the wallet spontaneously disconnected.
this.emit('error', new WalletDisconnectedError());
// Disconnect the adapter.
this.#disconnected();
}
}
}
// After reflecting account changes, if features have changed on the wallet, reflect this on the adapter.
if ('features' in properties) {
this.#reset();
}
};
async sendTransaction<T extends Transaction | VersionedTransaction>(
transaction: T,
connection: Connection,
options: SendTransactionOptions = {}
): Promise<TransactionSignature> {
try {
const account = this.#account;
if (!account) throw new WalletNotConnectedError();
let feature: typeof SolanaSignAndSendTransaction | typeof SolanaSignTransaction;
if (SolanaSignAndSendTransaction in this.#wallet.features) {
if (account.features.includes(SolanaSignAndSendTransaction)) {
feature = SolanaSignAndSendTransaction;
} else if (
SolanaSignTransaction in this.#wallet.features &&
account.features.includes(SolanaSignTransaction)
) {
feature = SolanaSignTransaction;
} else {
throw new WalletAccountError();
}
} else if (SolanaSignTransaction in this.#wallet.features) {
if (!account.features.includes(SolanaSignTransaction)) throw new WalletAccountError();
feature = SolanaSignTransaction;
} else {
throw new WalletConfigError();
}
const chain = getChainForEndpoint(connection.rpcEndpoint);
if (!account.chains.includes(chain)) throw new WalletSendTransactionError();
try {
const { signers, ...sendOptions } = options;
let serializedTransaction: Uint8Array;
if (isVersionedTransaction(transaction)) {
signers?.length && transaction.sign(signers);
serializedTransaction = transaction.serialize();
} else {
transaction = (await this.prepareTransaction(transaction, connection, sendOptions)) as T;
signers?.length && (transaction as Transaction).partialSign(...signers);
serializedTransaction = new Uint8Array(
(transaction as Transaction).serialize({
requireAllSignatures: false,
verifySignatures: false,
})
);
}
if (feature === SolanaSignAndSendTransaction) {
const [output] = await (this.#wallet.features as SolanaSignAndSendTransactionFeature)[
SolanaSignAndSendTransaction
].signAndSendTransaction({
account,
chain,
transaction: serializedTransaction,
options: {
preflightCommitment: getCommitment(
sendOptions.preflightCommitment || connection.commitment
),
skipPreflight: sendOptions.skipPreflight,
maxRetries: sendOptions.maxRetries,
minContextSlot: sendOptions.minContextSlot,
},
});
return bs58.encode(output!.signature);
} else {
const [output] = await (this.#wallet.features as SolanaSignTransactionFeature)[
SolanaSignTransaction
].signTransaction({
account,
chain,
transaction: serializedTransaction,
options: {
preflightCommitment: getCommitment(
sendOptions.preflightCommitment || connection.commitment
),
minContextSlot: sendOptions.minContextSlot,
},
});
return await connection.sendRawTransaction(output!.signedTransaction, {
...sendOptions,
preflightCommitment: getCommitment(sendOptions.preflightCommitment || connection.commitment),
});
}
} catch (error: any) {
if (error instanceof WalletError) throw error;
throw new WalletSendTransactionError(error?.message, error);
}
} catch (error: any) {
this.emit('error', error);
throw error;
}
}
signTransaction: (<T extends Transaction | VersionedTransaction>(transaction: T) => Promise<T>) | undefined;
async #signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
try {
const account = this.#account;
if (!account) throw new WalletNotConnectedError();
if (!(SolanaSignTransaction in this.#wallet.features)) throw new WalletConfigError();
if (!account.features.includes(SolanaSignTransaction)) throw new WalletAccountError();
try {
const signedTransactions = await this.#wallet.features[SolanaSignTransaction].signTransaction({
account,
transaction: isVersionedTransaction(transaction)
? transaction.serialize()
: new Uint8Array(
transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})
),
});
const serializedTransaction = signedTransactions[0]!.signedTransaction;
return (
isVersionedTransaction(transaction)
? VersionedTransaction.deserialize(serializedTransaction)
: Transaction.from(serializedTransaction)
) as T;
} catch (error: any) {
if (error instanceof WalletError) throw error;
throw new WalletSignTransactionError(error?.message, error);
}
} catch (error: any) {
this.emit('error', error);
throw error;
}
}
signAllTransactions: (<T extends Transaction | VersionedTransaction>(transaction: T[]) => Promise<T[]>) | undefined;
async #signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]> {
try {
const account = this.#account;
if (!account) throw new WalletNotConnectedError();
if (!(SolanaSignTransaction in this.#wallet.features)) throw new WalletConfigError();
if (!account.features.includes(SolanaSignTransaction)) throw new WalletAccountError();
try {
const signedTransactions = await this.#wallet.features[SolanaSignTransaction].signTransaction(
...transactions.map((transaction) => ({
account,
transaction: isVersionedTransaction(transaction)
? transaction.serialize()
: new Uint8Array(
transaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})
),
}))
);
return transactions.map((transaction, index) => {
const signedTransaction = signedTransactions[index]!.signedTransaction;
return (
isVersionedTransaction(transaction)
? VersionedTransaction.deserialize(signedTransaction)
: Transaction.from(signedTransaction)
) as T;
});
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
} catch (error: any) {
this.emit('error', error);
throw error;
}
}
signMessage: ((message: Uint8Array) => Promise<Uint8Array>) | undefined;
async #signMessage(message: Uint8Array): Promise<Uint8Array> {
try {
const account = this.#account;
if (!account) throw new WalletNotConnectedError();
if (!(SolanaSignMessage in this.#wallet.features)) throw new WalletConfigError();
if (!account.features.includes(SolanaSignMessage)) throw new WalletAccountError();
try {
const signedMessages = await this.#wallet.features[SolanaSignMessage].signMessage({
account,
message,
});
return signedMessages[0]!.signature;
} catch (error: any) {
throw new WalletSignMessageError(error?.message, error);
}
} catch (error: any) {
this.emit('error', error);
throw error;
}
}
signIn: ((input?: SolanaSignInInput) => Promise<SolanaSignInOutput>) | undefined;
async #signIn(input: SolanaSignInInput = {}): Promise<SolanaSignInOutput> {
try {
if (!(SolanaSignIn in this.#wallet.features)) throw new WalletConfigError();
let output: SolanaSignInOutput | undefined;
try {
[output] = await this.#wallet.features[SolanaSignIn].signIn(input);
} catch (error: any) {
throw new WalletSignInError(error?.message, error);
}
if (!output) throw new WalletSignInError();
this.#connected(output.account);
return output;
} catch (error: any) {
this.emit('error', error);
throw error;
}
}
}

View File

@@ -0,0 +1,3 @@
export * from './adapter.js';
export * from './types.js';
export * from './wallet.js';

View File

@@ -0,0 +1,26 @@
import {
isWalletAdapterCompatibleStandardWallet,
type StandardWalletAdapter,
type WalletAdapterCompatibleStandardWallet,
} from '@solana/wallet-adapter-base';
/**
* @deprecated Use `StandardWalletAdapter` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export type StandardAdapter = StandardWalletAdapter;
/**
* @deprecated Use `WalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export type WalletAdapterCompatibleWallet = WalletAdapterCompatibleStandardWallet;
/**
* @deprecated Use `isWalletAdapterCompatibleStandardWallet` from `@solana/wallet-adapter-base` instead.
*
* @group Deprecated
*/
export const isWalletAdapterCompatibleWallet = isWalletAdapterCompatibleStandardWallet;

View File

@@ -0,0 +1,457 @@
import { type Adapter, isVersionedTransaction, WalletReadyState } from '@solana/wallet-adapter-base';
import { isSolanaChain, type SolanaChain } from '@solana/wallet-standard-chains';
import {
SolanaSignAndSendTransaction,
type SolanaSignAndSendTransactionFeature,
type SolanaSignAndSendTransactionMethod,
type SolanaSignAndSendTransactionOutput,
SolanaSignIn,
type SolanaSignInFeature,
type SolanaSignInMethod,
type SolanaSignInOutput,
SolanaSignMessage,
type SolanaSignMessageFeature,
type SolanaSignMessageMethod,
type SolanaSignMessageOutput,
SolanaSignTransaction,
type SolanaSignTransactionFeature,
type SolanaSignTransactionMethod,
type SolanaSignTransactionOutput,
type SolanaTransactionVersion,
} from '@solana/wallet-standard-features';
import { getEndpointForChain } from '@solana/wallet-standard-util';
import { Connection, Transaction, VersionedTransaction } from '@solana/web3.js';
import { getWallets } from '@wallet-standard/app';
import type { Wallet, WalletIcon } from '@wallet-standard/base';
import {
StandardConnect,
type StandardConnectFeature,
type StandardConnectMethod,
StandardDisconnect,
type StandardDisconnectFeature,
type StandardDisconnectMethod,
StandardEvents,
type StandardEventsFeature,
type StandardEventsListeners,
type StandardEventsNames,
type StandardEventsOnMethod,
} from '@wallet-standard/features';
import { arraysEqual, bytesEqual, ReadonlyWalletAccount } from '@wallet-standard/wallet';
import bs58 from 'bs58';
/** TODO: docs */
export class SolanaWalletAdapterWalletAccount extends ReadonlyWalletAccount {
// eslint-disable-next-line no-unused-private-class-members
readonly #adapter: Adapter;
constructor({
adapter,
address,
publicKey,
chains,
}: {
adapter: Adapter;
address: string;
publicKey: Uint8Array;
chains: readonly SolanaChain[];
}) {
const features: (keyof (SolanaSignAndSendTransactionFeature &
SolanaSignTransactionFeature &
SolanaSignMessageFeature &
SolanaSignInFeature))[] = [SolanaSignAndSendTransaction];
if ('signTransaction' in adapter) {
features.push(SolanaSignTransaction);
}
if ('signMessage' in adapter) {
features.push(SolanaSignMessage);
}
if ('signIn' in adapter) {
features.push(SolanaSignIn);
}
super({ address, publicKey, chains, features });
if (new.target === SolanaWalletAdapterWalletAccount) {
Object.freeze(this);
}
this.#adapter = adapter;
}
}
/** TODO: docs */
export class SolanaWalletAdapterWallet implements Wallet {
readonly #listeners: {
[E in StandardEventsNames]?: StandardEventsListeners[E][];
} = {};
readonly #adapter: Adapter;
readonly #supportedTransactionVersions: readonly SolanaTransactionVersion[];
readonly #chain: SolanaChain;
readonly #endpoint: string | undefined;
#account: SolanaWalletAdapterWalletAccount | undefined;
get version() {
return '1.0.0' as const;
}
get name() {
return this.#adapter.name;
}
get icon() {
return this.#adapter.icon as WalletIcon;
}
get chains() {
return [this.#chain];
}
get features(): StandardConnectFeature &
StandardDisconnectFeature &
StandardEventsFeature &
SolanaSignAndSendTransactionFeature &
Partial<SolanaSignTransactionFeature & SolanaSignMessageFeature & SolanaSignInFeature> {
const features: StandardConnectFeature &
StandardDisconnectFeature &
StandardEventsFeature &
SolanaSignAndSendTransactionFeature = {
[StandardConnect]: {
version: '1.0.0',
connect: this.#connect,
},
[StandardDisconnect]: {
version: '1.0.0',
disconnect: this.#disconnect,
},
[StandardEvents]: {
version: '1.0.0',
on: this.#on,
},
[SolanaSignAndSendTransaction]: {
version: '1.0.0',
supportedTransactionVersions: this.#supportedTransactionVersions,
signAndSendTransaction: this.#signAndSendTransaction,
},
};
let signTransactionFeature: SolanaSignTransactionFeature | undefined;
if ('signTransaction' in this.#adapter) {
signTransactionFeature = {
[SolanaSignTransaction]: {
version: '1.0.0',
supportedTransactionVersions: this.#supportedTransactionVersions,
signTransaction: this.#signTransaction,
},
};
}
let signMessageFeature: SolanaSignMessageFeature | undefined;
if ('signMessage' in this.#adapter) {
signMessageFeature = {
[SolanaSignMessage]: {
version: '1.0.0',
signMessage: this.#signMessage,
},
};
}
let signInFeature: SolanaSignInFeature | undefined;
if ('signIn' in this.#adapter) {
signInFeature = {
[SolanaSignIn]: {
version: '1.0.0',
signIn: this.#signIn,
},
};
}
return { ...features, ...signTransactionFeature, ...signMessageFeature };
}
get accounts() {
return this.#account ? [this.#account] : [];
}
get endpoint() {
return this.#endpoint;
}
constructor(adapter: Adapter, chain: SolanaChain, endpoint?: string) {
if (new.target === SolanaWalletAdapterWallet) {
Object.freeze(this);
}
const supportedTransactionVersions = [...(adapter.supportedTransactionVersions || ['legacy'])];
if (!supportedTransactionVersions.length) {
supportedTransactionVersions.push('legacy');
}
this.#adapter = adapter;
this.#supportedTransactionVersions = supportedTransactionVersions;
this.#chain = chain;
this.#endpoint = endpoint;
adapter.on('connect', this.#connected, this);
adapter.on('disconnect', this.#disconnected, this);
this.#connected();
}
destroy(): void {
this.#adapter.off('connect', this.#connected, this);
this.#adapter.off('disconnect', this.#disconnected, this);
}
#connected(): void {
const publicKey = this.#adapter.publicKey?.toBytes();
if (publicKey) {
const address = this.#adapter.publicKey!.toBase58();
const account = this.#account;
if (
!account ||
account.address !== address ||
account.chains.includes(this.#chain) ||
!bytesEqual(account.publicKey, publicKey)
) {
this.#account = new SolanaWalletAdapterWalletAccount({
adapter: this.#adapter,
address,
publicKey,
chains: [this.#chain],
});
this.#emit('change', { accounts: this.accounts });
}
}
}
#disconnected(): void {
if (this.#account) {
this.#account = undefined;
this.#emit('change', { accounts: this.accounts });
}
}
#connect: StandardConnectMethod = async ({ silent } = {}) => {
if (!silent && !this.#adapter.connected) {
await this.#adapter.connect();
}
this.#connected();
return { accounts: this.accounts };
};
#disconnect: StandardDisconnectMethod = async () => {
await this.#adapter.disconnect();
};
#on: StandardEventsOnMethod = (event, listener) => {
this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
return (): void => this.#off(event, listener);
};
#emit<E extends StandardEventsNames>(event: E, ...args: Parameters<StandardEventsListeners[E]>): void {
// eslint-disable-next-line prefer-spread
this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
}
#off<E extends StandardEventsNames>(event: E, listener: StandardEventsListeners[E]): void {
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
}
#deserializeTransaction(serializedTransaction: Uint8Array): Transaction | VersionedTransaction {
const transaction = VersionedTransaction.deserialize(serializedTransaction);
if (!this.#supportedTransactionVersions.includes(transaction.version))
throw new Error('unsupported transaction version');
if (transaction.version === 'legacy' && arraysEqual(this.#supportedTransactionVersions, ['legacy']))
return Transaction.from(serializedTransaction);
return transaction;
}
#signAndSendTransaction: SolanaSignAndSendTransactionMethod = async (...inputs) => {
const outputs: SolanaSignAndSendTransactionOutput[] = [];
if (inputs.length === 1) {
const input = inputs[0]!;
if (input.account !== this.#account) throw new Error('invalid account');
if (!isSolanaChain(input.chain)) throw new Error('invalid chain');
const transaction = this.#deserializeTransaction(input.transaction);
const { commitment, preflightCommitment, skipPreflight, maxRetries, minContextSlot } = input.options || {};
const endpoint = getEndpointForChain(input.chain, this.#endpoint);
const connection = new Connection(endpoint, commitment || 'confirmed');
const latestBlockhash = commitment
? await connection.getLatestBlockhash({
commitment: preflightCommitment || commitment,
minContextSlot,
})
: undefined;
const signature = await this.#adapter.sendTransaction(transaction, connection, {
preflightCommitment,
skipPreflight,
maxRetries,
minContextSlot,
});
if (latestBlockhash) {
await connection.confirmTransaction(
{
...latestBlockhash,
signature,
},
commitment || 'confirmed'
);
}
outputs.push({ signature: bs58.decode(signature) });
} else if (inputs.length > 1) {
// Adapters have no `sendAllTransactions` method, so just sign and send each transaction in serial.
for (const input of inputs) {
outputs.push(...(await this.#signAndSendTransaction(input)));
}
}
return outputs;
};
#signTransaction: SolanaSignTransactionMethod = async (...inputs) => {
if (!('signTransaction' in this.#adapter)) throw new Error('signTransaction not implemented by adapter');
const outputs: SolanaSignTransactionOutput[] = [];
if (inputs.length === 1) {
const input = inputs[0]!;
if (input.account !== this.#account) throw new Error('invalid account');
if (input.chain && !isSolanaChain(input.chain)) throw new Error('invalid chain');
const transaction = this.#deserializeTransaction(input.transaction);
const signedTransaction = await this.#adapter.signTransaction(transaction);
const serializedTransaction = isVersionedTransaction(signedTransaction)
? signedTransaction.serialize()
: new Uint8Array(
signedTransaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})
);
outputs.push({ signedTransaction: serializedTransaction });
} else if (inputs.length > 1) {
for (const input of inputs) {
if (input.account !== this.#account) throw new Error('invalid account');
if (input.chain && !isSolanaChain(input.chain)) throw new Error('invalid chain');
}
const transactions = inputs.map(({ transaction }) => this.#deserializeTransaction(transaction));
const signedTransactions = await this.#adapter.signAllTransactions(transactions);
outputs.push(
...signedTransactions.map((signedTransaction) => {
const serializedTransaction = isVersionedTransaction(signedTransaction)
? signedTransaction.serialize()
: new Uint8Array(
signedTransaction.serialize({
requireAllSignatures: false,
verifySignatures: false,
})
);
return { signedTransaction: serializedTransaction };
})
);
}
return outputs;
};
#signMessage: SolanaSignMessageMethod = async (...inputs) => {
if (!('signMessage' in this.#adapter)) throw new Error('signMessage not implemented by adapter');
const outputs: SolanaSignMessageOutput[] = [];
if (inputs.length === 1) {
const input = inputs[0]!;
if (input.account !== this.#account) throw new Error('invalid account');
const signature = await this.#adapter.signMessage(input.message);
outputs.push({ signedMessage: input.message, signature });
} else if (inputs.length > 1) {
// Adapters have no `signAllMessages` method, so just sign each message in serial.
for (const input of inputs) {
outputs.push(...(await this.#signMessage(input)));
}
}
return outputs;
};
#signIn: SolanaSignInMethod = async (...inputs) => {
if (!('signIn' in this.#adapter)) throw new Error('signIn not implemented by adapter');
if (inputs.length > 1) {
// Adapters don't support `signIn` with multiple inputs, so just sign in with each input in serial.
const outputs: SolanaSignInOutput[] = [];
for (const input of inputs) {
outputs.push(await this.#adapter.signIn(input));
}
return outputs;
} else {
return [await this.#adapter.signIn(inputs[0])];
}
};
}
/** TODO: docs */
export function registerWalletAdapter(
adapter: Adapter,
chain: SolanaChain,
endpoint?: string,
match: (wallet: Wallet) => boolean = (wallet) => wallet.name === adapter.name
): () => void {
const { register, get, on } = getWallets();
const destructors: (() => void)[] = [];
function destroy(): void {
destructors.forEach((destroy) => destroy());
destructors.length = 0;
}
function setup(): boolean {
// If the adapter is unsupported, or a standard wallet that matches it has already been registered, do nothing.
if (adapter.readyState === WalletReadyState.Unsupported || get().some(match)) return true;
// If the adapter isn't ready, try again later.
const ready =
adapter.readyState === WalletReadyState.Installed || adapter.readyState === WalletReadyState.Loadable;
if (ready) {
const wallet = new SolanaWalletAdapterWallet(adapter, chain, endpoint);
destructors.push(() => wallet.destroy());
// Register the adapter wrapped as a standard wallet, and receive a function to unregister the adapter.
destructors.push(register(wallet));
// Whenever a standard wallet is registered ...
destructors.push(
on('register', (...wallets) => {
// ... check if it matches the adapter.
if (wallets.some(match)) {
// If it does, remove the event listener and unregister the adapter.
destroy();
}
})
);
}
return ready;
}
if (!setup()) {
function listener(): void {
if (setup()) {
adapter.off('readyStateChange', listener);
}
}
adapter.on('readyStateChange', listener);
destructors.push(() => adapter.off('readyStateChange', listener));
}
return destroy;
}