Skip to content

Commit

Permalink
add versioned transaction support for keystone (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
soralit authored Aug 23, 2024
1 parent f372188 commit 8cc1c0f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 73 deletions.
2 changes: 1 addition & 1 deletion packages/wallets/keystone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@solana/web3.js": "^1.77.3"
},
"dependencies": {
"@keystonehq/sol-keyring": "^0.3.1",
"@keystonehq/sol-keyring": "^0.20.0",
"@solana/wallet-adapter-base": "workspace:^"
},
"devDependencies": {
Expand Down
20 changes: 15 additions & 5 deletions packages/wallets/keystone/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { DefaultKeyring } from '@keystonehq/sol-keyring';
import type { WalletName } from '@solana/wallet-adapter-base';
import {
BaseMessageSignerWalletAdapter,
isVersionedTransaction,
WalletAccountError,
WalletLoadError,
WalletNotConnectedError,
Expand All @@ -10,7 +11,7 @@ import {
WalletReadyState,
WalletSignTransactionError,
} from '@solana/wallet-adapter-base';
import type { Transaction } from '@solana/web3.js';
import type { Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
import { PublicKey } from '@solana/web3.js';

export interface KeystoneWalletAdapterConfig {}
Expand All @@ -22,7 +23,7 @@ export class KeystoneWalletAdapter extends BaseMessageSignerWalletAdapter {
url = 'https://keyst.one';
icon =
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxjaXJjbGUgY3g9IjE2IiBjeT0iMTYiIHI9IjE2IiBmaWxsPSJ3aGl0ZSIvPgogICAgPHJlY3QgeD0iNSIgeT0iNSIgd2lkdGg9IjIyIiBoZWlnaHQ9IjIyIiBmaWxsPSJ3aGl0ZSIg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jYgMTUuMzM1OCAxNS41NDE0IDE2LjMzNzIgMTYuNDY0NyAxNi4zMzcyTDIwLjQzNSAxNi4zMzcyWiIgZmlsbD0iYmxhY2siLz4KICAgIDxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMjEuNzMwMyAxNy42NDU5QzIyLjg3MTMgMTcuNjQ1OSAyMy45MjYxIDE4LjI1MjcgMjQuNDk5OCAxOS4yMzlWMTkuMjM5QzI0LjY3NjMgMTkuNTQyNyAyNC42MjQ3IDE5LjkyNzQgMjQuMzc0MyAyMC4xNzM3TDIyLjA1MTEgMjIuNDU5QzIxLjQ1MDkgMjMuMDQ5NCAyMC40ODc3IDIzLjA0NzggMTkuODg5NSAyMi40NTUzTDE2LjUxMDEgMTkuMTA3OEMxNS45Njc3IDE4LjU3MDYgMTYuMzQ4MSAxNy42NDU5IDE3LjExMTYgMTcuNjQ1OUwyMS43MzAzIDE3LjY0NTlaIiBmaWxsPSIjMjE2MUZGIi8+Cjwvc3ZnPgo=';
readonly supportedTransactionVersions = null;
supportedTransactionVersions: ReadonlySet<TransactionVersion> = new Set(['legacy', 0]);

private _keyring: DefaultKeyring | null;
private _publicKey: PublicKey | null;
Expand Down Expand Up @@ -102,14 +103,23 @@ export class KeystoneWalletAdapter extends BaseMessageSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
async signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
try {
const keyring = this._keyring;
const publicKey = this._publicKey?.toString();
const publicKey = this._publicKey;
if (!keyring || !publicKey) throw new WalletNotConnectedError();

try {
return (await keyring.signTransaction(publicKey, transaction)) as T;
if (isVersionedTransaction(transaction)) {
const txHex = transaction.serialize();
const signature = await keyring.signTransaction(publicKey.toString(), txHex);
transaction.addSignature(publicKey, signature);
} else {
const txHex = transaction.serializeMessage();
const signature = await keyring.signTransaction(publicKey.toString(), txHex);
transaction.addSignature(publicKey, Buffer.from(signature));
}
return transaction;
} catch (error: any) {
throw new WalletSignTransactionError(error?.message, error);
}
Expand Down
115 changes: 48 additions & 67 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cc1c0f

Please sign in to comment.