mirror of https://github.com/certusone/oyster.git
parent
7dda1281a3
commit
b7c3cc6366
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="226.000000pt" height="248.000000pt" viewBox="0 0 226.000000 248.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.16, written by Peter Selinger 2001-2019
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,248.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M482 2143 c-43 -21 -79 -64 -92 -111 -13 -48 -13 -246 0 -294 29
|
||||
-103 92 -128 322 -128 l158 0 0 -588 0 -589 23 -43 c16 -30 37 -51 67 -67 39
|
||||
-21 56 -23 182 -23 94 0 149 4 171 14 43 17 95 78 102 118 3 18 5 389 3 825
|
||||
l-3 791 -31 39 c-59 74 -52 73 -484 73 -334 0 -389 -3 -418 -17z"/>
|
||||
<path d="M1743 2144 c-57 -21 -126 -84 -154 -141 -35 -73 -32 -171 6 -241 54
|
||||
-100 132 -146 245 -146 115 0 197 50 246 151 108 220 -110 459 -343 377z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 957 B |
|
@ -9,6 +9,7 @@ import { useLocalStorageState } from "../utils/utils";
|
|||
import { LedgerProvider } from "@solana/wallet-ledger";
|
||||
import { SolongWalletAdapter } from "../wallet-adapters/solong";
|
||||
import { PhantomWalletAdapter } from "../wallet-adapters/phantom";
|
||||
import { TorusWalletAdapter } from "../wallet-adapters/torus";
|
||||
|
||||
const ASSETS_URL = 'https://raw.githubusercontent.com/solana-labs/oyster/main/assets/wallets/';
|
||||
export const WALLET_PROVIDERS = [
|
||||
|
@ -37,6 +38,12 @@ export const WALLET_PROVIDERS = [
|
|||
icon: `https://www.phantom.app/img/logo.png`,
|
||||
adapter: PhantomWalletAdapter,
|
||||
},
|
||||
{
|
||||
name: 'Torus',
|
||||
url: 'https://tor.us',
|
||||
icon: `${ASSETS_URL}torus.svg`,
|
||||
adapter: TorusWalletAdapter,
|
||||
}
|
||||
];
|
||||
|
||||
const WalletContext = React.createContext<{
|
||||
|
@ -90,6 +97,7 @@ export function WalletProvider({ children = null as any }) {
|
|||
|
||||
wallet.on("disconnect", () => {
|
||||
setConnected(false);
|
||||
// setProviderUrl(null)
|
||||
notify({
|
||||
message: "Wallet update",
|
||||
description: "Disconnected from wallet",
|
||||
|
@ -99,6 +107,7 @@ export function WalletProvider({ children = null as any }) {
|
|||
|
||||
return () => {
|
||||
setConnected(false);
|
||||
// setProviderUrl(null)
|
||||
if (wallet) {
|
||||
wallet.disconnect();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
import EventEmitter from "eventemitter3"
|
||||
import solanaWeb3 from "@solana/web3.js"
|
||||
import { Account, PublicKey, Transaction, Connection } from "@solana/web3.js"
|
||||
import { WalletAdapter } from "@solana/wallet-base"
|
||||
import Torus from "@toruslabs/torus-embed"
|
||||
import OpenLogin from "@toruslabs/openlogin"
|
||||
import { getED25519Key } from "@toruslabs/openlogin-ed25519"
|
||||
import { notify } from "../../utils/notifications"
|
||||
import { ENDPOINTS } from "../../contexts"
|
||||
// import { useConnection } from "../../contexts"
|
||||
|
||||
type TorusEvent = "disconnect" | "connect";
|
||||
type TorusRequestMethod =
|
||||
| "connect"
|
||||
| "disconnect"
|
||||
| "signTransaction"
|
||||
| "signAllTransactions";
|
||||
|
||||
// interface TorusProvider {
|
||||
// publicKey?: PublicKey;
|
||||
// isConnected?: boolean;
|
||||
// autoApprove?: boolean;
|
||||
// signTransaction: (transaction: Transaction) => Promise<Transaction>;
|
||||
// signAllTransactions: (transactions: Transaction[]) => Promise<Transaction[]>;
|
||||
// connect: () => Promise<void>;
|
||||
// disconnect: () => Promise<void>;
|
||||
// on: (event: TorusEvent, handler: (args: any) => void) => void;
|
||||
// request: (method: TorusRequestMethod, params: any) => Promise<any>;
|
||||
// }
|
||||
|
||||
const getSolanaPrivateKey = (openloginKey: string)=>{
|
||||
const { sk } = getED25519Key(openloginKey)
|
||||
return sk
|
||||
}
|
||||
|
||||
export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
|
||||
_provider: Torus | undefined;
|
||||
// _provider: OpenLogin | undefined;
|
||||
_publicKey: PublicKey | null;
|
||||
|
||||
constructor(providerUrl: string, endpoint: string) {
|
||||
super()
|
||||
this._publicKey = null
|
||||
this.connect = this.connect.bind(this)
|
||||
console.log("Constructing...", {providerUrl, endpoint})
|
||||
}
|
||||
|
||||
// get connected() {
|
||||
// return this._provider?.isConnected || false;
|
||||
// }
|
||||
|
||||
// get autoApprove() {
|
||||
// return this._provider?.autoApprove || false;
|
||||
// }
|
||||
|
||||
async signAllTransactions(transactions: Transaction[]): Promise<Transaction[]> {
|
||||
return transactions
|
||||
}
|
||||
|
||||
get publicKey() {
|
||||
return this._publicKey;
|
||||
}
|
||||
|
||||
async signTransaction(transaction: Transaction) {
|
||||
return transaction
|
||||
}
|
||||
|
||||
connect = async () => {
|
||||
console.log("Connecting...")
|
||||
// const connection = useConnection()
|
||||
const solanaNetwork = ENDPOINTS.find(end => end.name === "testnet")
|
||||
if (!solanaNetwork) return
|
||||
|
||||
const connection = new Connection(solanaNetwork.endpoint)
|
||||
|
||||
// this._provider = new OpenLogin({
|
||||
// clientId: "BFvMIZJz9gVTzTXzJg_WezLkhUib-U2Q1wgDR1x95UzU5i-s642W8yxUvBXs4Sj1JuhRohgxvZL2nYnCA1_ZDbE",
|
||||
// network: "testnet", // mainnet, testnet, development
|
||||
// })
|
||||
// await this._provider.init()
|
||||
// console.log({openlogin: this._provider})
|
||||
|
||||
// if (this._provider.privKey) { // already logged in
|
||||
// const privateKey = this._provider.privKey
|
||||
// const secretKey = getSolanaPrivateKey(privateKey)
|
||||
// console.log("secretKey", secretKey)
|
||||
// const account = new Account(secretKey)
|
||||
// const accountInfo = await connection.getAccountInfo(account.publicKey)
|
||||
// console.log("accountInfo", accountInfo)
|
||||
// } else {
|
||||
// const privKey = await this._provider.login()
|
||||
// console.log("privKey", privKey)
|
||||
// const solanaPrivateKey = getSolanaPrivateKey(privKey.privKey);
|
||||
// console.log("solanaPrivateKey", solanaPrivateKey)
|
||||
// // await getAccountInfo(solanaNetwork.url,solanaPrivateKey)
|
||||
// }
|
||||
|
||||
this._provider = new Torus({})
|
||||
await this._provider.init({})
|
||||
await this._provider.login({})
|
||||
// const sWeb3 = new solanaWeb3(torus.provider)
|
||||
console.log({torus: this._provider})
|
||||
console.log({solanaWeb3})
|
||||
// result=eyJwcml2S2V5IjoiMmE3ZDUxOTBiYzA4MmUxMzYyZDE5NjVkNzI3OWQ1OWE0ZDY5ZDJlZWUzZGVmYzBiNThmMTk4OGE4YTY1YTA1YSIsInN0b3JlIjp7InRvdWNoSURQcmVmZXJlbmNlIjoidW5zZXQiLCJhcHBTdGF0ZSI6IiJ9fQ==
|
||||
|
||||
const userInfo = await this._provider.getUserInfo("Holi")
|
||||
console.log({userInfo})
|
||||
|
||||
// const publicAddress = await this._provider.getPublicAddress({
|
||||
// verifier: "google",
|
||||
// verifierId: "random@gmail.com",
|
||||
// })
|
||||
|
||||
// const sdkInstance = new OpenLogin({
|
||||
// clientId: "YOUR_PROJECT_ID",
|
||||
// network: "testnet"
|
||||
// });
|
||||
// async function initializeOpenlogin() {
|
||||
// await sdkInstance.init();
|
||||
// if (sdkInstance.privKey) {
|
||||
// // qpp has access ot private key now
|
||||
// ...
|
||||
// ...
|
||||
// }
|
||||
// setSdk(sdkInstance);
|
||||
// setLoading(false)
|
||||
// }
|
||||
// initializeOpenlogin()
|
||||
// if (this._provider) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// let provider: TorusProvider;
|
||||
// if ((window as any)?.solana?.isTorus) {
|
||||
// provider = (window as any).solana;
|
||||
// } else {
|
||||
// window.open("https://Torus.app/", "_blank");
|
||||
// notify({
|
||||
// message: "Torus Error",
|
||||
// description: "Please install Torus wallet from Chrome ",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// provider.on('connect', () => {
|
||||
// this._provider = provider;
|
||||
// this.emit("connect");
|
||||
// })
|
||||
|
||||
// if (!provider.isConnected) {
|
||||
// await provider.connect();
|
||||
// }
|
||||
|
||||
// this._provider = provider;
|
||||
this.emit("connect");
|
||||
}
|
||||
|
||||
disconnect = async () => {
|
||||
console.log("Disconecting...")
|
||||
if (this._provider) {
|
||||
// await this._provider.cleanUp()
|
||||
await this._provider.logout()
|
||||
this._provider = undefined;
|
||||
this.emit("disconnect");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,9 @@
|
|||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.5.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
"@toruslabs/openlogin": "^0.7.0",
|
||||
"@toruslabs/openlogin-ed25519": "^0.7.0",
|
||||
"@toruslabs/openlogin-utils": "^0.7.0",
|
||||
"@toruslabs/torus-embed": "^1.9.10",
|
||||
"@types/animejs": "^3.1.3",
|
||||
"@types/chart.js": "^2.9.29",
|
||||
|
|
56
yarn.lock
56
yarn.lock
|
@ -3345,7 +3345,7 @@
|
|||
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
|
||||
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==
|
||||
|
||||
"@toruslabs/eccrypto@^1.1.5":
|
||||
"@toruslabs/eccrypto@^1.1.5", "@toruslabs/eccrypto@^1.1.6":
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/eccrypto/-/eccrypto-1.1.6.tgz#ce877cf00d6f9cf7ab3daa6ac4d6d540110b813b"
|
||||
integrity sha512-L3TAsdEARouyzTbSKE0PqcYXmHQiFh95FB2YnsRbWERCAF0VWg3kY/YA//M/HBZqCJoRwa5WRA61lWbM7zAX5Q==
|
||||
|
@ -3372,6 +3372,44 @@
|
|||
dependencies:
|
||||
deepmerge "^4.2.2"
|
||||
|
||||
"@toruslabs/openlogin-ed25519@^0.7.0":
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/openlogin-ed25519/-/openlogin-ed25519-0.7.0.tgz#836bb22b2daf0034e73d3666ad0c98227d342f36"
|
||||
integrity sha512-+JjCadlbBI1sBie+Z/CS5EHVjjCThxq0imj0VNEcNDJUqdF91uJJghyWx46GllSHoJhWh7BsZUpVU0WZZMBPmw==
|
||||
dependencies:
|
||||
"@toruslabs/tweetnacl-js" "^1.0.3"
|
||||
|
||||
"@toruslabs/openlogin-jrpc@^0.7.0":
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/openlogin-jrpc/-/openlogin-jrpc-0.7.0.tgz#72fee3a94e9488ae133b0595bdf4d272ca01010d"
|
||||
integrity sha512-BO6QnMQoZDp6O/JPVRj216es2m+10JcvtvudNhtfeCBPEXw/uc/OBRBBM0CC002zAHDgivSlPCc+8KOvNRXl1w==
|
||||
dependencies:
|
||||
"@toruslabs/openlogin-utils" "^0.7.0"
|
||||
end-of-stream "^1.4.4"
|
||||
fast-safe-stringify "^2.0.7"
|
||||
once "^1.4.0"
|
||||
pump "^3.0.0"
|
||||
|
||||
"@toruslabs/openlogin-utils@^0.7.0":
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/openlogin-utils/-/openlogin-utils-0.7.0.tgz#d612aacd0daaaf48734c7512335777569113902b"
|
||||
integrity sha512-6caBBLGKjcDulU6oD0p7obtg0dTQlCLTAkDStkwSK9VObMOA/eR92jn3ivjE+r+epiU0LH7kFLAE8/ZFbtpNCw==
|
||||
dependencies:
|
||||
base64url "^3.0.1"
|
||||
keccak "^3.0.1"
|
||||
randombytes "^2.1.0"
|
||||
|
||||
"@toruslabs/openlogin@^0.7.0":
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/openlogin/-/openlogin-0.7.0.tgz#0169a38b0ab634f13354ded010565ff8ba179db1"
|
||||
integrity sha512-p3s1i3VaHOLBdSjgYtUhW59FdYuAp3FkTxoQHmVr2Yr8NoIhAtRBd9JWKuHm5kGtjmb6+eI7pQx1CVoIph5yWw==
|
||||
dependencies:
|
||||
"@toruslabs/eccrypto" "^1.1.6"
|
||||
"@toruslabs/openlogin-jrpc" "^0.7.0"
|
||||
"@toruslabs/openlogin-utils" "^0.7.0"
|
||||
lodash.merge "^4.6.2"
|
||||
pump "^3.0.0"
|
||||
|
||||
"@toruslabs/torus-embed@^1.8.0", "@toruslabs/torus-embed@^1.9.10":
|
||||
version "1.9.14"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/torus-embed/-/torus-embed-1.9.14.tgz#6d487a735ec6e570d62a044069581dc372ab193e"
|
||||
|
@ -3409,6 +3447,11 @@
|
|||
memory-cache "^0.2.0"
|
||||
web3-utils "^1.3.3"
|
||||
|
||||
"@toruslabs/tweetnacl-js@^1.0.3":
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@toruslabs/tweetnacl-js/-/tweetnacl-js-1.0.3.tgz#52abbcd2a6b77959ef6a98afedce77764d87226d"
|
||||
integrity sha512-WQJYMTR/bkqvpk3DWOqRt5e24RhwJp9PXUoSj4zSthd3+fDhKYCI56YVMPNDKah1fCffOe9F3m8iZ5SgDZ+Csw==
|
||||
|
||||
"@typechain/ethers-v4@^1.0.0":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@typechain/ethers-v4/-/ethers-v4-1.0.1.tgz#268b619c2660bf7689cda86e30798bd30753ae94"
|
||||
|
@ -5977,6 +6020,11 @@ base64-js@^1.0.2, base64-js@^1.3.0, base64-js@^1.3.1:
|
|||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
||||
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
|
||||
|
||||
base64url@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d"
|
||||
integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==
|
||||
|
||||
base@^0.11.1:
|
||||
version "0.11.2"
|
||||
resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
|
||||
|
@ -8835,7 +8883,7 @@ encoding@^0.1.11:
|
|||
dependencies:
|
||||
iconv-lite "^0.6.2"
|
||||
|
||||
end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.0, end-of-stream@^1.4.1:
|
||||
end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.0, end-of-stream@^1.4.1, end-of-stream@^1.4.4:
|
||||
version "1.4.4"
|
||||
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
|
||||
integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
|
||||
|
@ -10018,7 +10066,7 @@ fast-memoize@^2.5.2:
|
|||
resolved "https://registry.yarnpkg.com/fast-memoize/-/fast-memoize-2.5.2.tgz#79e3bb6a4ec867ea40ba0e7146816f6cdce9b57e"
|
||||
integrity sha512-Ue0LwpDYErFbmNnZSF0UH6eImUwDmogUO1jyE+JbN2gsQz/jICm1Ve7t9QT0rNSsfJt+Hs4/S3GnsDVjL4HVrw==
|
||||
|
||||
fast-safe-stringify@^2.0.6:
|
||||
fast-safe-stringify@^2.0.6, fast-safe-stringify@^2.0.7:
|
||||
version "2.0.7"
|
||||
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743"
|
||||
integrity sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==
|
||||
|
@ -13524,7 +13572,7 @@ lodash.memoize@4.x, lodash.memoize@^4.1.2:
|
|||
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
|
||||
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
|
||||
|
||||
lodash.merge@^4.4.0:
|
||||
lodash.merge@^4.4.0, lodash.merge@^4.6.2:
|
||||
version "4.6.2"
|
||||
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
||||
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
||||
|
|
Loading…
Reference in New Issue