project-serum / sol-wallet-adapter Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Is this interesting to you guys?
When using the web version, if the popup is blocked by the browser or closed by the user, the connect
call will hang and never emit an event or reject its promise.
Similarly for the extension, if the user declines permission to connect or closes the extension popup, the connect
call will never emit an event. It also resolves its promise immediately (#24).
Dapps can listen for a connect
event but cannot reliably detect the connection failure and are left in an unknown state.
hey,
i wonder how to create stakeAccount using this wallet adapter, since the current signTransaction wallet method expect TransactionInstruction type while create stakeAccount is Transaction type, so it already signed
any ideas?
C:\Users\Bloctech\Documents\solana\solr-token-sale\js\node_modules@project-serum\sol-wallet-adapter\dist\cjs\index.js:79
import EventEmitter from 'eventemitter3';
^^^^^^
SyntaxError: Cannot use import statement outside a module
When oconnect called from within a frame, after successful connect a new window is opened with a blank page.
Although the calling window gets correct events (on('connec')... ) the usability is suffering.
need to remember that the method can be called form a frame or iframe.
example
https://codesandbox.io/s/intelligent-bardeen-4vwft?file=/src/index.js
The adapter on Firefox has a couple of usability issues that I've found so far.
Whenever you connect the wallet, or approve a transaction, a new empty tab is opened on the dApp window.
If you send an approval request from the dApp the wallet popup doesn't focus so you don't realize you need to perform an action on this popup as it's hidden behind the main window.
The steps to reproduce these issues are pretty simple, but if you have any question please let me know.
After creating the staking account, I tried to retrieve it using let stakeState = await connection.getStakeActivation(stakeAccount.publicKey);
.
But it gives an error as follows
Invalid param: stake account not initialized.
When I search for the address on the solana explorer I can see the account as a staking account. How long will it take to get activated? I am using the devnet at the moment
For example, client set the "Loading" flag before call connect, but if user closes the popup and doesn't connect, there is no way to even figure out that it was closed and set "Loading" to false.
SystemProgram.transfer does not return a tx but an ix
The connect function is working properly with sollet
But when used with https://www.solflare.com/access-wallet the popup closes after a bit without any interaction
Under TypeScript Node 16 module resolution (has type: module
in the package.json
and moduleResolution: Node16
in tsconfig.json
), this package cannot be imported correctly.
import Wallet from '@project-serum/sol-wallet-adapter'
new Wallet()
// type error!
new Wallet.default(provider, 'network')
// runtime error!
I'm running the code below with some logs and at the point of running wallet.signTransaction it fails with the error given in the title. The entire error below. The code to get connections and setup and connect the wallet all work. As does the setup of the Transaction itself.
I am running:
devnet
solana: 1.6.6
sol-wallet-adapter: 0.2.0
web3.js: 1.9.1
react_devtools_backend.js:2557 Failed TypeError: Cannot read property 'toString' of undefined
at transaction.ts:271
at Array.forEach ()
at Transaction.compileMessage (transaction.ts:270)
at Transaction._compile (transaction.ts:376)
at Transaction.serializeMessage (transaction.ts:402)
at Wallet.signTransaction (index.js:184)
at sendTransaction (wallet.js:33)
`
import Wallet from "@project-serum/sol-wallet-adapter";
import {
Connection,
SystemProgram,
Transaction,
clusterApiUrl,
sendAndConfirmTransaction,
} from "@solana/web3.js";
const network = clusterApiUrl("devnet");
const connection = new Connection("https://devnet.solana.com", "confirmed");
const wallet = new Wallet("https://www.sollet.io", network);
export async function sendTransaction() {
try {
await wallet.connect();
console.log("network", network);
console.log("connection", connection);
console.log("wallet", wallet);
let transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: wallet.publickey,
toPubkey: wallet.publicKey,
lamports: 100,
})
);
transaction.recentBlockhash = (
await connection.getRecentBlockhash()
).blockhash;
transaction.feePayer = wallet.publicKey;
console.log("finished setting up transaction");
let signed = await wallet.signTransaction(transaction);
console.log("signed transaction");
let signature = await connection.sendRawTransaction(signed.serialize());
console.log("sent raw transaction");
await connection.confirmTransaction(signature, "singleGossip");
console.log("transaction attempt confirm");
} catch (e) {
console.warn("Failed", e);
}
}
`
How could I do that.
problem solved
Hello when someone mints how can NFT transfer to their wallet
Resigning transactions using a popup is tedious to users who are using it for the same action over and over, ie interacting with a dApp that requires multiple transactions in a short period of time.
Would be great to have a checkmark that adds the site to a temporary (1 hr?) whitelist allows the site's function signs to bypass manual popup signs.
project-serum/spl-token-wallet#143 introduces a new sign
api to sign arbitrary data. This should be added to the adapter.
I installed the unpacked extension built through https://github.com/project-serum/spl-token-wallet yarn build:extension
in chrome.
However, it does not seem like it ends up being injected into window.solana
Am i missing something or should we add the injection at the other side?
API consumers shouldn't have access to this knowledge, this should be strictly on the wallet side.
Why? Today I was investigation a couple of phishing websites, and both of them check if the user has auto approved or not.
Both were acting differently, but both were abusing this information.
https://github.com/project-serum/sol-wallet-adapter/blob/master/src/index.js#L69
When using an injected provider the Promise resolve immediately, while for the pop up version it will resolve once the 'connected' even has been received from the pop up. Why this discrepancy of behavior? I believe the later approach is better (i.e the connect
method returns only once the user has clicked connect in the UI)
When this package is built into a CommonJS file, it still contains ES6 imports. From the latest version (0.2.4
), the following lines will cause runners such as Jest (which assume node_modules
as built CommonJS) to break:
import EventEmitter from 'eventemitter3';
import { PublicKey } from '@solana/web3.js';
import bs58 from 'bs58';
In the meantime, a workaround for anyone experiencing this is to add the following to your Jest configuration:
"transform": {
"(@project-serum/sol-wallet-adapter).+\\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"/node_modules/(?!@project-serum/sol-wallet-adapter)"
]
https://www.sollet.io vs https://sollet.io
How to reproduce:
Use sol-wallet-adapter example,
choose wallet provider: https://sollet.io
yes, without the www
then click on Connect to wallet
sollet popup open, click Connect
.
Connect event never occurs at the other side (example side)
I am not certain what side is causing the problem but it took me a while to find out. I find out running the example and noticing that it just works.
We need an injected interface design so dapps can interact with browser extension wallets (MathWallet, eDeFi, etc.)
Goals:
Ethereum dapps rely on a single injection point (window.ethereum
) for wallet interaction. All wallet extensions (MetaMask, ezDeFi, etc.) must compete for the chance to get injected since there's only 1 extension is active at a time. This is very simple for dapp to use but dapp also doesn't know which wallet is used (for display).
Solution 1: single interface - single wallet (same with Ethereum with extra info)
window.solana
for all wallet extensions. The name of the wallet can be queried in window.solana.name
and window.solana.desc
, but they're optional for both dapp and wallets.window.solana.name
or just injected
.Solution 2: single interface - multiple wallets
window.solana[walletname]
, and dapps can use any of the wallets in the array they preferred, using the same interface as the current window.solana
. Or just select the first one if they don't care.Solution 3: single dispatcher - multiple wallets
window.solana
is injected to be a dispatcher, so it can be used just like window.ethereum
window.solana.wallet[name]
is injected by each extensions.window.solana.selectWallet(name)
tells the dispatcher to redirect all requests to window.solana.wallets[name]
. If none is set, the first wallet will be used.window.solana.getWallets()
returns all injected wallets.Please discuss.
Having created a signed message I'm unsure how to use the resulting signature to verify the message using the publicKey.
My use case is: I'm wanting to use a Solana Wallet to login to an API server with a pattern like:
GET message: String (from API server)
sign message with privateKey
POST signature (to API server)
verify signature with stored publicKey
I've attempted to use crypto.verify
to decode the signed message on the API side but am a bit out of my depth digging into Buffers and elliptic curves:
// Front-end code
const toHexString = (buffer: Buffer) =>
buffer.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
const data = new TextEncoder().encode('message to verify');
const signed = await wallet.sign(data, "hex");
await setLogin({ // sends API post call to backend
variables: {
publicAddress: walletPublicKey,
signature: toHexString(signed.signature),
},
});
// Current WIP for backend code
const ALGORITHM = "ed25519";
const fromHexString = (hexString) =>
new Uint8Array(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
const signature = fromHexString(args.signature);
const nonceUint8 = new TextEncoder().encode('message to verify');
const verified = crypto.verify(
ALGORITHM,
nonceUint8,
`-----BEGIN PUBLIC KEY-----\n${user.publicAddress}\n-----END PUBLIC KEY-----`,
signature
);
console.log("isVerified: ", verified);
I'm pretty sure I'm going about this the wrong way and there must be an obvious method I'm missing.
Ideally it seems like there should be a verify function to consume the output of const signed = await wallet.sign(data, "hex");
Something like:
import { VerifyMessage } from '@solana/web3.js';
const verified = VerifyMessage(message, publicKey, signature, 'hex');
But after 3 days of pushing hard I'm starting to hit my limits and my brain is failing. Any help or direction where to look much appreciated ๐
I have a simple client.js
import Wallet from '@project-serum/sol-wallet-adapter';
And create a bundle using
esbuild ./client.js --bundle --outfile=./build/js/client.js
When including the bundled file on a simple page I am getting a bunch of bundling issues and can not use the output bundle.
Uncaught ReferenceError: process is not defined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.