diff --git a/README.md b/README.md index 5d06c19d9..253f16b38 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ You can use the [wallets](https://github.com/solana-labs/wallet-adapter/tree/mas | [nufi](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/nufi) | Adapter for [NuFi](https://nu.fi) | [`@solana/wallet-adapter-nufi`](https://npmjs.com/package/@solana/wallet-adapter-nufi) | | [phantom](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/phantom) | Adapter for [Phantom](https://phantom.app) | [`@solana/wallet-adapter-phantom`](https://npmjs.com/package/@solana/wallet-adapter-phantom) | | [safepal](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/safepal) | Adapter for [SafePal](https://safepal.io) | [`@solana/wallet-adapter-safepal`](https://npmjs.com/package/@solana/wallet-adapter-safepal) | +| [saifu](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/saifu) | Adapter for [Saifu](https://saifuwallet.com/) | [`@solana/wallet-adapter-saifu`](https://npmjs.com/package/@solana/wallet-adapter-safepal) | | [slope](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/slope) | Adapter for [Slope](https://slope.finance) | [`@solana/wallet-adapter-slope`](https://npmjs.com/package/@solana/wallet-adapter-slope) | | [solflare](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/solflare) | Adapter for [Solflare](https://solflare.com) | [`@solana/wallet-adapter-solflare`](https://npmjs.com/package/@solana/wallet-adapter-solflare) | | [sollet](https://github.com/solana-labs/wallet-adapter/tree/master/packages/wallets/sollet) | Adapter for [Sollet](https://www.sollet.io) | [`@solana/wallet-adapter-sollet`](https://npmjs.com/package/@solana/wallet-adapter-sollet) | diff --git a/packages/wallets/saifu/.gitignore b/packages/wallets/saifu/.gitignore new file mode 100644 index 000000000..a65b41774 --- /dev/null +++ b/packages/wallets/saifu/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/wallets/saifu/.prettierignore b/packages/wallets/saifu/.prettierignore new file mode 100644 index 000000000..a65b41774 --- /dev/null +++ b/packages/wallets/saifu/.prettierignore @@ -0,0 +1 @@ +lib diff --git a/packages/wallets/saifu/LICENSE b/packages/wallets/saifu/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/packages/wallets/saifu/LICENSE @@ -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. diff --git a/packages/wallets/saifu/README.md b/packages/wallets/saifu/README.md new file mode 100644 index 000000000..d69a8c0b8 --- /dev/null +++ b/packages/wallets/saifu/README.md @@ -0,0 +1,3 @@ +# `@solana/wallet-adapter-saifu` + +Wallet adapter for integrating https://saifuwallet.com/ diff --git a/packages/wallets/saifu/package.json b/packages/wallets/saifu/package.json new file mode 100644 index 000000000..7c9464e66 --- /dev/null +++ b/packages/wallets/saifu/package.json @@ -0,0 +1,38 @@ +{ + "name": "@solana/wallet-adapter-saifu", + "version": "0.1.0", + "author": "Solana Maintainers ", + "repository": "https://github.com/solana-labs/wallet-adapter", + "license": "Apache-2.0", + "type": "module", + "sideEffects": false, + "main": "lib/cjs/index.js", + "module": "lib/esm/index.mjs", + "types": "lib/types/index.d.ts", + "exports": { + "import": "./lib/esm/index.mjs", + "require": "./lib/cjs/index.js" + }, + "files": [ + "lib", + "src", + "LICENSE" + ], + "publishConfig": { + "access": "public" + }, + "scripts": { + "clean": "shx rm -rf lib/*", + "build": "yarn clean && tsc -p tsconfig.json && tsc-esm -p tsconfig.json && tsc -p tsconfig.cjs.json", + "postbuild": "echo '{\"type\":\"commonjs\"}' | npx json > lib/cjs/package.json && echo '{\"type\":\"module\"} ' | npx json > lib/esm/package.json" + }, + "peerDependencies": { + "@solana/web3.js": "^1.36.0" + }, + "dependencies": { + "@solana/wallet-adapter-base": "^0.9.4" + }, + "devDependencies": { + "@solana/web3.js": "^1.36.0" + } +} diff --git a/packages/wallets/saifu/src/adapter.ts b/packages/wallets/saifu/src/adapter.ts new file mode 100644 index 000000000..918d55703 --- /dev/null +++ b/packages/wallets/saifu/src/adapter.ts @@ -0,0 +1,239 @@ +import { + BaseMessageSignerWalletAdapter, + EventEmitter, + scopePollingDetectionStrategy, + SendTransactionOptions, + WalletAccountError, + WalletConnectionError, + WalletDisconnectedError, + WalletDisconnectionError, + WalletError, + WalletName, + WalletNotConnectedError, + WalletNotReadyError, + WalletPublicKeyError, + WalletReadyState, + WalletSignTransactionError, + WalletWindowClosedError, +} from '@solana/wallet-adapter-base'; +import { Connection, PublicKey, SendOptions, Transaction, TransactionSignature } from '@solana/web3.js'; + +interface SaifuWalletEvents { + connect(...args: unknown[]): unknown; + disconnect(...args: unknown[]): unknown; +} + +interface SaifuWallet extends EventEmitter { + isSaifu?: boolean; + publicKey?: { toBytes(): Uint8Array }; + isConnected: boolean; + signTransaction(transaction: Transaction): Promise; + signAllTransactions(transactions: Transaction[]): Promise; + signAndSendTransaction?( + transaction: Transaction, + options?: SendOptions + ): Promise<{ signature: TransactionSignature }>; + signMessage(message: Uint8Array): Promise<{ signature: Uint8Array }>; + connect(): Promise; + disconnect(): Promise; +} + +interface SolanaWindow extends Window { + saifu: SaifuWallet; +} + +declare const window: SolanaWindow; + +export interface SaifuWalletAdapterConfig {} + +export const SaifuWalletName = 'Saifu' as WalletName; + +export class SaifuWalletAdapter extends BaseMessageSignerWalletAdapter { + name = SaifuWalletName; + url = 'https://saifuwallet.com'; + icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZG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3LDMyMy44NjM0MjEgWiIgaWQ9IlNoYXBlIj48L3BhdGg+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4='; + + private _connecting: boolean; + private _wallet: SaifuWallet | null; + private _publicKey: PublicKey | null; + private _readyState: WalletReadyState = + typeof window === 'undefined' || typeof document === 'undefined' + ? WalletReadyState.Unsupported + : WalletReadyState.NotDetected; + + constructor(config: SaifuWalletAdapterConfig = {}) { + super(); + this._connecting = false; + this._wallet = null; + this._publicKey = null; + + if (this._readyState !== WalletReadyState.Unsupported) { + scopePollingDetectionStrategy(() => { + if (window.saifu) { + this._readyState = WalletReadyState.Installed; + this.emit('readyStateChange', this._readyState); + return true; + } + return false; + }); + } + } + + get publicKey(): PublicKey | null { + return this._publicKey; + } + + get connecting(): boolean { + return this._connecting; + } + + get connected(): boolean { + return !!this._wallet?.isConnected; + } + + get readyState(): WalletReadyState { + return this._readyState; + } + + async connect(): Promise { + try { + if (this.connected || this.connecting) return; + if (this._readyState !== WalletReadyState.Installed) throw new WalletNotReadyError(); + + this._connecting = true; + + const wallet = window.saifu; + + if (!wallet?.isConnected) { + try { + await wallet.connect(); + } catch (error: any) { + throw new WalletConnectionError(error?.message, error); + } + } + + if (!wallet.publicKey) throw new WalletAccountError(); + + let publicKey: PublicKey; + try { + publicKey = new PublicKey(wallet.publicKey.toBytes()); + } catch (error: any) { + throw new WalletPublicKeyError(error?.message, error); + } + + wallet.on('disconnect', this._disconnected); + + this._wallet = wallet; + this._publicKey = publicKey; + + this.emit('connect', publicKey); + } catch (error: any) { + this.emit('error', error); + throw error; + } finally { + this._connecting = false; + } + } + + async disconnect(): Promise { + const wallet = this._wallet; + if (wallet) { + wallet.off('disconnect', this._disconnected); + + this._wallet = null; + this._publicKey = null; + + try { + await wallet.disconnect(); + } catch (error: any) { + this.emit('error', new WalletDisconnectionError(error?.message, error)); + } + } + + this.emit('disconnect'); + } + + async sendTransaction( + transaction: Transaction, + connection: Connection, + options: SendTransactionOptions = {} + ): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + // fallback to parent if not implemented yet + if (!wallet.signAndSendTransaction) { + return super.sendTransaction(transaction, connection, options); + } + + const { signature } = await wallet.signAndSendTransaction(transaction, options); + return signature; + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + async signTransaction(transaction: Transaction): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + return (await wallet.signTransaction(transaction)) || transaction; + } catch (error: any) { + throw new WalletSignTransactionError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + async signAllTransactions(transactions: Transaction[]): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + return (await wallet.signAllTransactions(transactions)) || transactions; + } catch (error: any) { + throw new WalletSignTransactionError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + async signMessage(message: Uint8Array): Promise { + try { + const wallet = this._wallet; + if (!wallet) throw new WalletNotConnectedError(); + + try { + const { signature } = await wallet.signMessage(message); + return signature; + } catch (error: any) { + throw new WalletSignTransactionError(error?.message, error); + } + } catch (error: any) { + this.emit('error', error); + throw error; + } + } + + private _disconnected = () => { + const wallet = this._wallet; + if (wallet) { + wallet.off('disconnect', this._disconnected); + + this._wallet = null; + this._publicKey = null; + + this.emit('error', new WalletDisconnectedError()); + this.emit('disconnect'); + } + }; +} diff --git a/packages/wallets/saifu/src/index.ts b/packages/wallets/saifu/src/index.ts new file mode 100644 index 000000000..7e77e9fc2 --- /dev/null +++ b/packages/wallets/saifu/src/index.ts @@ -0,0 +1 @@ +export * from './adapter'; diff --git a/packages/wallets/saifu/tsconfig.cjs.json b/packages/wallets/saifu/tsconfig.cjs.json new file mode 100644 index 000000000..443b583a0 --- /dev/null +++ b/packages/wallets/saifu/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "outDir": "lib/cjs", + "declarationDir": null, + "declaration": false + } +} diff --git a/packages/wallets/saifu/tsconfig.json b/packages/wallets/saifu/tsconfig.json new file mode 100644 index 000000000..ea51e41c4 --- /dev/null +++ b/packages/wallets/saifu/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../../tsconfig.json", + "include": ["src"], + "compilerOptions": { + "outDir": "lib/esm", + "declarationDir": "lib/types", + "noEmit": false + } +} diff --git a/packages/wallets/wallets/package.json b/packages/wallets/wallets/package.json index 1eb52a27d..73890e119 100644 --- a/packages/wallets/wallets/package.json +++ b/packages/wallets/wallets/package.json @@ -45,6 +45,7 @@ "@solana/wallet-adapter-nufi": "^0.1.0", "@solana/wallet-adapter-phantom": "^0.9.2", "@solana/wallet-adapter-safepal": "^0.5.2", + "@solana/wallet-adapter-saifu": "^0.1.0", "@solana/wallet-adapter-slope": "^0.5.2", "@solana/wallet-adapter-solflare": "^0.6.3", "@solana/wallet-adapter-sollet": "^0.11.0", diff --git a/packages/wallets/wallets/src/index.ts b/packages/wallets/wallets/src/index.ts index 7754123b0..8b9e31a45 100644 --- a/packages/wallets/wallets/src/index.ts +++ b/packages/wallets/wallets/src/index.ts @@ -14,6 +14,7 @@ export * from '@solana/wallet-adapter-nightly'; export * from '@solana/wallet-adapter-nufi'; export * from '@solana/wallet-adapter-phantom'; export * from '@solana/wallet-adapter-safepal'; +export * from '@solana/wallet-adapter-saifu'; export * from '@solana/wallet-adapter-slope'; export * from '@solana/wallet-adapter-solflare'; export * from '@solana/wallet-adapter-sollet';