From 8cc1c0f968077c420c19363084c0b25b56668527 Mon Sep 17 00:00:00 2001 From: Soralit Date: Sat, 24 Aug 2024 04:58:30 +0800 Subject: [PATCH] add versioned transaction support for keystone (#1002) --- packages/wallets/keystone/package.json | 2 +- packages/wallets/keystone/src/adapter.ts | 20 +++- pnpm-lock.yaml | 115 ++++++++++------------- 3 files changed, 64 insertions(+), 73 deletions(-) diff --git a/packages/wallets/keystone/package.json b/packages/wallets/keystone/package.json index f24da7435..8eabd0a19 100644 --- a/packages/wallets/keystone/package.json +++ b/packages/wallets/keystone/package.json @@ -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": { diff --git a/packages/wallets/keystone/src/adapter.ts b/packages/wallets/keystone/src/adapter.ts index 820e52349..f3fd2d38f 100644 --- a/packages/wallets/keystone/src/adapter.ts +++ b/packages/wallets/keystone/src/adapter.ts @@ -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, @@ -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 {} @@ -22,7 +23,7 @@ export class KeystoneWalletAdapter extends BaseMessageSignerWalletAdapter { url = 'https://keyst.one'; icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxjaX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LjE5MzkgMjEuNjE3MiAxNC4yODIyTDE5Ljc4MjggMTEuMTI4QzE5LjI1NTggMTAuMjIxOCAxNy45NDcxIDEwLjIyMTIgMTcuNDE5MiAxMS4xMjY5TDE1LjQzMDkgMTQuNTM4MUMxNC45NjYgMTUuMzM1OCAxNS41NDE0IDE2LjMzNzIgMTYuNDY0NyAxNi4zMzcyTDIwLjQzNSAxNi4zMzcyWiIgZmlsbD0iYmxhY2siLz4KICAgIDxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMjEuNzMwMyAxNy42NDU5QzIyLjg3MTMgMTcuNjQ1OSAyMy45MjYxIDE4LjI1MjcgMjQuNDk5OCAxOS4yMzlWMTkuMjM5QzI0LjY3NjMgMTkuNTQyNyAyNC42MjQ3IDE5LjkyNzQgMjQuMzc0MyAyMC4xNzM3TDIyLjA1MTEgMjIuNDU5QzIxLjQ1MDkgMjMuMDQ5NCAyMC40ODc3IDIzLjA0NzggMTkuODg5NSAyMi40NTUzTDE2LjUxMDEgMTkuMTA3OEMxNS45Njc3IDE4LjU3MDYgMTYuMzQ4MSAxNy42NDU5IDE3LjExMTYgMTcuNjQ1OUwyMS43MzAzIDE3LjY0NTlaIiBmaWxsPSIjMjE2MUZGIi8+Cjwvc3ZnPgo='; - readonly supportedTransactionVersions = null; + supportedTransactionVersions: ReadonlySet = new Set(['legacy', 0]); private _keyring: DefaultKeyring | null; private _publicKey: PublicKey | null; @@ -102,14 +103,23 @@ export class KeystoneWalletAdapter extends BaseMessageSignerWalletAdapter { this.emit('disconnect'); } - async signTransaction(transaction: T): Promise { + async signTransaction(transaction: T): Promise { 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); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e029e12d8..c941a4c06 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -770,8 +770,8 @@ importers: packages/wallets/keystone: dependencies: '@keystonehq/sol-keyring': - specifier: ^0.3.1 - version: 0.3.1(bufferutil@4.0.7)(utf-8-validate@5.0.10) + specifier: ^0.20.0 + version: 0.20.0(bufferutil@4.0.7)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(utf-8-validate@5.0.10) '@solana/wallet-adapter-base': specifier: workspace:^ version: link:../../core/base @@ -2791,17 +2791,23 @@ packages: '@keystonehq/alias-sampling@0.1.2': resolution: {integrity: sha512-5ukLB3bcgltgaFfQfYKYwHDUbwHicekYo53fSEa7xhVkAEqsA74kxdIwoBIURmGUtXe3EVIRm4SYlgcrt2Ri0w==} - '@keystonehq/bc-ur-registry-sol@0.3.1': - resolution: {integrity: sha512-Okr5hwPxBZxB4EKLK1GSC9vsrh/tFMQ5dvs3EQ9NCOmCn7CXdXIMSeafrpGCHk484Jf5c6X0Wq0yf0VqY2A/8Q==} + '@keystonehq/bc-ur-registry-sol@0.9.3': + resolution: {integrity: sha512-ZjTeInzS4y10tIZlgEN4NGW9W6vTBxzZrM9CaNNeVqTgtyiOB2JvPIW8buxlZUKYj2M5Mu5jPHuAjVRCK6Jm9Q==} - '@keystonehq/bc-ur-registry@0.5.5': - resolution: {integrity: sha512-PoclPHf0OhpIKLfLwzymsu+CjkWf5ZKvaVjpkq3HUalcI4KW8wLk0m8qI2kBVv6F0BQ0ERPqW8OfjLTVqIgWLA==} + '@keystonehq/bc-ur-registry@0.5.4': + resolution: {integrity: sha512-z7bZe10I5k0zz9znmDTXh+o3Rzb5XsRVpwAzexubOaLxVdZ0F7aMbe2LoEsw766Hpox/7zARi7UGmLz5C8BAzA==} - '@keystonehq/sdk@0.13.1': - resolution: {integrity: sha512-545l83TE5t1cyUZUaNqZOAh15ibWOg9QbK/YeLwnrxt+GOod+ATk3j9SpN6yTSLO8DNl2/x6dKRIFVtTEkZDAg==} + '@keystonehq/bc-ur-registry@0.6.4': + resolution: {integrity: sha512-j8Uy44DuAkvYkbf0jMxRY3UizJfn8wsEQr7GS3miRF44vcq7k0/yemVkftbn3jQ+0JYaUXf5wY7lVpLhAeW5nQ==} - '@keystonehq/sol-keyring@0.3.1': - resolution: {integrity: sha512-RU6I3HQrQ9NpRDP9TwlBIy5DftVcNcyk0NWfhkPy/YanhMcCB0cRPw68iQl1rMnR6n1G2+YrBHMxm6swCW+B4Q==} + '@keystonehq/sdk@0.19.2': + resolution: {integrity: sha512-ilA7xAhPKvpHWlxjzv3hjMehD6IKYda4C1TeG2/DhFgX9VSffzv77Eebf8kVwzPLdYV4LjX1KQ2ZDFoN1MsSFQ==} + peerDependencies: + react: '*' + react-dom: '*' + + '@keystonehq/sol-keyring@0.20.0': + resolution: {integrity: sha512-UBeMlecybTDQaFMI951LBEVRyZarqKHOcwWqqvphV+x7WquYz0SZ/wf/PhizV0MWoGTQwt2m5aqROzksi6svqw==} '@ledgerhq/devices@6.27.1': resolution: {integrity: sha512-jX++oy89jtv7Dp2X6gwt3MMkoajel80JFWcdc0HCouwDsV1mVJ3SQdwl/bQU0zd8HI6KebvUP95QTwbQLLK/RQ==} @@ -9879,11 +9885,6 @@ packages: react-devtools-core@4.28.0: resolution: {integrity: sha512-E3C3X1skWBdBzwpOUbmXG8SgH6BtsluSMe+s6rRcujNKG1DGi8uIfhdhszkgDpAsMoE55hwqRUzeXCmETDBpTg==} - react-dom@16.13.1: - resolution: {integrity: sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==} - peerDependencies: - react: ^16.13.1 - react-dom@18.2.0: resolution: {integrity: sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==} peerDependencies: @@ -9966,10 +9967,6 @@ packages: react: '>=16.6.0' react-dom: '>=16.6.0' - react@16.13.1: - resolution: {integrity: sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==} - engines: {node: '>=0.10.0'} - react@18.2.0: resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} engines: {node: '>=0.10.0'} @@ -10278,9 +10275,6 @@ packages: resolution: {integrity: sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==} engines: {node: '>=10'} - scheduler@0.19.1: - resolution: {integrity: sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==} - scheduler@0.23.0: resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==} @@ -13955,41 +13949,47 @@ snapshots: '@keystonehq/alias-sampling@0.1.2': {} - '@keystonehq/bc-ur-registry-sol@0.3.1': + '@keystonehq/bc-ur-registry-sol@0.9.3': dependencies: - '@keystonehq/bc-ur-registry': 0.5.5 + '@keystonehq/bc-ur-registry': 0.6.4 bs58check: 2.1.2 uuid: 8.3.2 - '@keystonehq/bc-ur-registry@0.5.5': + '@keystonehq/bc-ur-registry@0.5.4': dependencies: '@ngraveio/bc-ur': 1.1.12 bs58check: 2.1.2 - tslib: 2.6.0 + tslib: 2.6.2 - '@keystonehq/sdk@0.13.1': + '@keystonehq/bc-ur-registry@0.6.4': dependencies: '@ngraveio/bc-ur': 1.1.12 - qrcode.react: 1.0.1(react@16.13.1) - react: 16.13.1 - react-dom: 16.13.1(react@16.13.1) - react-modal: 3.16.1(react-dom@16.13.1(react@16.13.1))(react@16.13.1) - react-qr-reader: 2.2.1(react-dom@16.13.1(react@16.13.1))(react@16.13.1) + bs58check: 2.1.2 + tslib: 2.6.2 + + '@keystonehq/sdk@0.19.2(react-dom@18.2.0(react@18.2.0))(react@18.2.0)': + dependencies: + '@ngraveio/bc-ur': 1.1.12 + qrcode.react: 1.0.1(react@18.2.0) + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + react-modal: 3.16.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0) + react-qr-reader: 2.2.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0) rxjs: 6.6.7 - typescript: 4.7.4 - '@keystonehq/sol-keyring@0.3.1(bufferutil@4.0.7)(utf-8-validate@5.0.10)': + '@keystonehq/sol-keyring@0.20.0(bufferutil@4.0.7)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(utf-8-validate@5.0.10)': dependencies: - '@keystonehq/bc-ur-registry': 0.5.5 - '@keystonehq/bc-ur-registry-sol': 0.3.1 - '@keystonehq/sdk': 0.13.1 - '@solana/web3.js': 1.78.0(bufferutil@4.0.7)(utf-8-validate@5.0.10) + '@keystonehq/bc-ur-registry': 0.5.4 + '@keystonehq/bc-ur-registry-sol': 0.9.3 + '@keystonehq/sdk': 0.19.2(react-dom@18.2.0(react@18.2.0))(react@18.2.0) + '@solana/web3.js': 1.90.1(bufferutil@4.0.7)(utf-8-validate@5.0.10) bs58: 5.0.0 uuid: 8.3.2 transitivePeerDependencies: - bufferutil - encoding - - supports-color + - react + - react-dom - utf-8-validate '@ledgerhq/devices@6.27.1': @@ -14276,7 +14276,7 @@ snapshots: dependencies: '@keystonehq/alias-sampling': 0.1.2 assert: 2.0.0 - bignumber.js: 9.1.1 + bignumber.js: 9.1.2 cbor-sync: 1.0.4 crc: 3.8.0 jsbi: 3.2.5 @@ -22841,12 +22841,12 @@ snapshots: qrcode-terminal@0.11.0: {} - qrcode.react@1.0.1(react@16.13.1): + qrcode.react@1.0.1(react@18.2.0): dependencies: loose-envify: 1.4.0 prop-types: 15.8.1 qr.js: 0.0.0 - react: 16.13.1 + react: 18.2.0 qrcode@1.4.4: dependencies: @@ -23306,14 +23306,6 @@ snapshots: - bufferutil - utf-8-validate - react-dom@16.13.1(react@16.13.1): - dependencies: - loose-envify: 1.4.0 - object-assign: 4.1.1 - prop-types: 15.8.1 - react: 16.13.1 - scheduler: 0.19.1 - react-dom@18.2.0(react@18.2.0): dependencies: loose-envify: 1.4.0 @@ -23332,12 +23324,12 @@ snapshots: react-lifecycles-compat@3.0.4: {} - react-modal@3.16.1(react-dom@16.13.1(react@16.13.1))(react@16.13.1): + react-modal@3.16.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0): dependencies: exenv: 1.2.2 prop-types: 15.8.1 - react: 16.13.1 - react-dom: 16.13.1(react@16.13.1) + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) react-lifecycles-compat: 3.0.4 warning: 4.0.3 @@ -23435,12 +23427,12 @@ snapshots: - utf-8-validate optional: true - react-qr-reader@2.2.1(react-dom@16.13.1(react@16.13.1))(react@16.13.1): + react-qr-reader@2.2.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0): dependencies: jsqr: 1.4.0 prop-types: 15.8.1 - react: 16.13.1 - react-dom: 16.13.1(react@16.13.1) + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) webrtc-adapter: 7.7.1 react-refresh@0.11.0: {} @@ -23552,12 +23544,6 @@ snapshots: react: 18.2.0 react-dom: 18.2.0(react@18.2.0) - react@16.13.1: - dependencies: - loose-envify: 1.4.0 - object-assign: 4.1.1 - prop-types: 15.8.1 - react@18.2.0: dependencies: loose-envify: 1.4.0 @@ -23898,11 +23884,6 @@ snapshots: dependencies: xmlchars: 2.2.0 - scheduler@0.19.1: - dependencies: - loose-envify: 1.4.0 - object-assign: 4.1.1 - scheduler@0.23.0: dependencies: loose-envify: 1.4.0