Skip to content

Commit

Permalink
feat: support eip 6963
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 committed Jan 4, 2024
1 parent 2724214 commit 56ad042
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/versionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const version = '1.1.48';
const version = '1.1.50';
const versionBuild = '2020-0101-1';

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { JsBridgeBase } from '@onekeyfe/cross-inpage-provider-core';
import { ProviderEthereum, shimWeb3 } from '@onekeyfe/onekey-eth-provider';
import { ProviderEthereum, shimWeb3, registerEIP6963Provider } from '@onekeyfe/onekey-eth-provider';
import { ProviderPrivate } from '@onekeyfe/onekey-private-provider';
import { ProviderSolana, registerSolanaWallet, WalletIcon } from '@onekeyfe/onekey-solana-provider';
import { ProviderStarcoin } from '@onekeyfe/onekey-starcoin-provider';
Expand Down Expand Up @@ -146,6 +146,11 @@ function injectWeb3Provider(): unknown {
});

defineWindowProperty('ethereum', ethereum);
registerEIP6963Provider({
image: WALLET_CONNECT_INFO.onekey.icon,
provider: ethereum,
});

defineWindowProperty('solana', solana);
defineWindowProperty('phantom', { solana });
defineWindowProperty('starcoin', starcoin);
Expand Down
6 changes: 5 additions & 1 deletion packages/providers/onekey-eth-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"@onekeyfe/cross-inpage-provider-errors": "1.1.50",
"@onekeyfe/cross-inpage-provider-types": "1.1.50",
"@onekeyfe/extension-bridge-injected": "1.1.50",
"eth-rpc-errors": "^4.0.3"
"eth-rpc-errors": "^4.0.3",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/uuid": "^8.3.2"
}
}
1 change: 1 addition & 0 deletions packages/providers/onekey-eth-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { shimWeb3 } from './ethereum';

export * from './ProviderEthereum';
export * from './registerEIP6963Provider';
export { shimWeb3 };
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { v4 as uuidV4 } from 'uuid';
import type { ProviderEthereum } from './ProviderEthereum';

export function registerEIP6963Provider({
image,
provider,
}: {
image: string;
provider: ProviderEthereum;
}) {
// EIP-6963: https://eips.ethereum.org/EIPS/eip-6963
const info = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
uuid: uuidV4(),
name: 'OneKey',
icon: image,
rdns: 'so.onekey.wallet',
};

function announceProvider() {
window.dispatchEvent(
new CustomEvent('eip6963:announceProvider', {
detail: Object.freeze({ info, provider: provider }),
}),
);
}
window.addEventListener('eip6963:requestProvider', announceProvider);
announceProvider();
}
64 changes: 63 additions & 1 deletion packages/providers/onekey-eth-provider/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,76 @@
# yarn lockfile v1


"@onekeyfe/[email protected]":
version "1.1.50"
resolved "https://registry.yarnpkg.com/@onekeyfe/cross-inpage-provider-core/-/cross-inpage-provider-core-1.1.50.tgz#6f80a13b748cc1aa00436ff02b47fd2d5edf90cc"
integrity sha512-JNZeMgGidPjqOXGX3qfprZ83ELmS22biWCoVvE1iBLvcRzCpbpjfHzCqAehE32EkQd2RwCmW9JTr/EdzPcK/lQ==
dependencies:
"@onekeyfe/cross-inpage-provider-errors" "1.1.50"
"@onekeyfe/cross-inpage-provider-events" "1.1.50"
"@onekeyfe/cross-inpage-provider-types" "1.1.50"
events "^3.3.0"
lodash "^4.17.21"
ms "^2.1.3"

"@onekeyfe/[email protected]":
version "1.1.50"
resolved "https://registry.yarnpkg.com/@onekeyfe/cross-inpage-provider-errors/-/cross-inpage-provider-errors-1.1.50.tgz#b0b5e7707ef08c1ea41efdf2278786095d109ad7"
integrity sha512-10zaE7u5Hsh1YdEDKbpTLQHLCyL04nRsbLJHEv2lycuTPq9xxkKqvVMRKaSzOlx6RlF7JSvhzHejXJioSVfA4g==
dependencies:
fast-safe-stringify "^2.1.1"

"@onekeyfe/[email protected]":
version "1.1.50"
resolved "https://registry.yarnpkg.com/@onekeyfe/cross-inpage-provider-events/-/cross-inpage-provider-events-1.1.50.tgz#888174bd8279787186dbd92c17f9532a218c1d4b"
integrity sha512-hOeAbsnvN8DUNxSOn0zJM47f+0lyOC6c+h/klcCvwLVyumjz/myqWeWBnSFk9aArCOIXR7HxJkFJYfkz0nAcYQ==

"@onekeyfe/[email protected]":
version "1.1.50"
resolved "https://registry.yarnpkg.com/@onekeyfe/cross-inpage-provider-types/-/cross-inpage-provider-types-1.1.50.tgz#6055a81303e4653e3130d8219c49e432f38638f6"
integrity sha512-vHz8b1BvFpYjy+JGxJWwd9r/FUQF54lAyAo7pDJAcsJ4CaDX6KCbKN6MwfFY/3mCN76vs1wkBbtc/s/PMivEQg==

"@onekeyfe/[email protected]":
version "1.1.50"
resolved "https://registry.yarnpkg.com/@onekeyfe/extension-bridge-injected/-/extension-bridge-injected-1.1.50.tgz#1812ccc97f161dcc485a016f39d28b71aa217119"
integrity sha512-8bCQta1UOM9NJCCby0bdagFqtgDdj2+aFyaKZ58NC9EHCwQdg8ksQDSjIY7FcTYQV6K0X7ep2aXPRKZYjS3egQ==
dependencies:
"@onekeyfe/cross-inpage-provider-core" "1.1.50"
"@onekeyfe/cross-inpage-provider-types" "1.1.50"

"@types/uuid@^8.3.0":
version "8.3.4"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==

eth-rpc-errors@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/eth-rpc-errors/-/eth-rpc-errors-4.0.3.tgz#6ddb6190a4bf360afda82790bb7d9d5e724f423a"
integrity sha512-Z3ymjopaoft7JDoxZcEb3pwdGh7yiYMhOwm2doUt6ASXlMavpNlK6Cre0+IMl2VSGyEU9rkiperQhp5iRxn5Pg==
dependencies:
fast-safe-stringify "^2.0.6"

fast-safe-stringify@^2.0.6:
events@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==

fast-safe-stringify@^2.0.6, fast-safe-stringify@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz#c406a83b6e70d9e35ce3b30a81141df30aeba884"
integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==

lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

uuid@^8.3.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

0 comments on commit 56ad042

Please sign in to comment.