-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3268f77
commit 5ac0bc3
Showing
20 changed files
with
424 additions
and
332 deletions.
There are no files selected for viewing
32 changes: 16 additions & 16 deletions
32
packages/wallet-ts/src/strategies/wallet-strategy/strategies/Ledger/Base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Wallet } from '@injectivelabs/wallet-base' | ||
|
||
export const cosmosWallets = [ | ||
Wallet.Leap, | ||
Wallet.Ninji, | ||
Wallet.Keplr, | ||
Wallet.OWallet, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { CosmosWallet } from './wallet.js' | ||
export { CosmosWalletStrategy } from './strategy/strategy.js' | ||
export * from './utils/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { Keplr } from '@keplr-wallet/types' | ||
import { ChainId } from '@injectivelabs/ts-types' | ||
import { PublicKey } from '@injectivelabs/sdk-ts' | ||
import { Wallet, capitalize } from '@injectivelabs/wallet-base' | ||
import { CosmosWalletException } from '@injectivelabs/exceptions' | ||
import { CosmosWallet } from './../wallet.js' | ||
import { cosmosWallets } from './../data/index.js' | ||
|
||
export const isCosmosWalletInstalled = (wallet: Wallet) => { | ||
const $window = (typeof window !== 'undefined' ? window : {}) as Window & { | ||
leap?: Keplr | ||
keplr?: Keplr | ||
ninji?: Keplr | ||
} | ||
|
||
switch (wallet) { | ||
case Wallet.Keplr: | ||
return $window.keplr !== undefined | ||
case Wallet.Ninji: | ||
return $window.ninji !== undefined | ||
case Wallet.Leap: | ||
return $window.leap !== undefined | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
export const confirmCosmosAddress = async ({ | ||
wallet, | ||
chainId, | ||
injectiveAddress, | ||
}: { | ||
wallet: Wallet | ||
chainId: ChainId | ||
injectiveAddress: string | ||
}) => { | ||
if (!cosmosWallets.includes(wallet)) { | ||
throw new CosmosWalletException( | ||
new Error(`Cosmos Wallet for ${capitalize(wallet)} is not supported.`), | ||
) | ||
} | ||
|
||
const keplr = new CosmosWallet({ chainId, wallet }) | ||
const key = await keplr.getKey() | ||
const publicKey = PublicKey.fromBase64( | ||
Buffer.from(key.pubKey).toString('base64'), | ||
) | ||
|
||
const { address: derivedAddress } = publicKey.toAddress() | ||
|
||
if (derivedAddress !== injectiveAddress) { | ||
throw new CosmosWalletException( | ||
new Error( | ||
`Connected ${capitalize( | ||
wallet, | ||
)} address is wrong. Please update Injective on ${capitalize(wallet)}.`, | ||
), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { CosmostationWallet } from './wallet.js' | ||
export { Cosmostation as CosmostationWalletStrategy } from './strategy/strategy.js' | ||
export * from './utils/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Cosmos } from '@cosmostation/extension-client' | ||
|
||
export const isCosmosStationWalletInstalled = () => { | ||
const $window = (typeof window !== 'undefined' ? window : {}) as Window & { | ||
cosmostation?: Cosmos | ||
} | ||
|
||
return $window.cosmostation !== undefined | ||
} |
Oops, something went wrong.