diff --git a/packages/provider/src/babylon.ts b/packages/provider/src/babylon.ts new file mode 100644 index 0000000000..c37569c48b --- /dev/null +++ b/packages/provider/src/babylon.ts @@ -0,0 +1,99 @@ +import { + IBBNProvider, + Keplr, + OfflineAminoSigner, + OfflineDirectSigner, +} from "@keplr-wallet/types"; + +const BabylonChainInfo = { + chainId: "bbn-test-5", + chainName: "Babylon Phase-2 Testnet", + chainSymbolImageUrl: + "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", + rpc: "https://babylon-testnet-rpc.nodes.guru", + rest: "https://babylon-testnet-api.nodes.guru", + nodeProvider: { + name: "NodesGuru", + email: "security@nodes.guru", + website: "https://nodes.guru/", + }, + bip44: { + coinType: 118, + }, + bech32Config: { + bech32PrefixAccAddr: "bbn", + bech32PrefixAccPub: "bbnpub", + bech32PrefixValAddr: "bbnvaloper", + bech32PrefixValPub: "bbnvaloperpub", + bech32PrefixConsAddr: "bbnvalcons", + bech32PrefixConsPub: "bbnvalconspub", + }, + currencies: [ + { + coinDenom: "BABY", + coinMinimalDenom: "ubbn", + coinDecimals: 6, + coinImageUrl: + "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", + }, + ], + feeCurrencies: [ + { + coinDenom: "BABY", + coinMinimalDenom: "ubbn", + coinDecimals: 6, + coinImageUrl: + "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", + gasPriceStep: { + low: 0.007, + average: 0.007, + high: 0.01, + }, + }, + ], + stakeCurrency: { + coinDenom: "BABY", + coinMinimalDenom: "ubbn", + coinDecimals: 6, + coinImageUrl: + "https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", + }, + features: ["cosmwasm"], +}; + +export class KeplrBBNProvider implements IBBNProvider { + constructor(protected readonly keplr: Keplr) {} + + async connectWallet(): Promise { + await this.keplr.experimentalSuggestChain(BabylonChainInfo); + await this.keplr.enable(BabylonChainInfo.chainId); + } + + async getAddress(): Promise { + await this.keplr.experimentalSuggestChain(BabylonChainInfo); + await this.keplr.enable(BabylonChainInfo.chainId); + return (await this.keplr.getKey(BabylonChainInfo.chainId)).bech32Address; + } + + async getOfflineSigner(): Promise { + return this.keplr.getOfflineSigner(BabylonChainInfo.chainId); + } + + async getPublicKeyHex(): Promise { + await this.keplr.experimentalSuggestChain(BabylonChainInfo); + await this.keplr.enable(BabylonChainInfo.chainId); + return Array.from( + (await this.keplr.getKey(BabylonChainInfo.chainId)).pubKey + ) + .map((byte) => byte.toString(16).padStart(2, "0")) + .join(""); + } + + async getWalletProviderIcon(): Promise { + return process.env["KEPLR_EXT_EIP6963_PROVIDER_INFO_ICON"] || ""; + } + + async getWalletProviderName(): Promise { + return "Keplr"; + } +} diff --git a/packages/provider/src/inject.ts b/packages/provider/src/inject.ts index dad055e9e5..d9b1c9287e 100644 --- a/packages/provider/src/inject.ts +++ b/packages/provider/src/inject.ts @@ -47,6 +47,7 @@ import { InvocationsSignerDetails, ProviderInterface, } from "starknet"; +import { KeplrBBNProvider } from "./babylon"; export interface ProxyRequest { type: "proxy-request"; @@ -105,6 +106,11 @@ export function injectKeplrToWindow(keplr: IKeplr): void { ); defineUnwritablePropertyIfPossible(window, "starknet_keplr", keplr.starknet); + defineUnwritablePropertyIfPossible( + window, + "bbnwallet", + new KeplrBBNProvider(keplr) + ); } /** diff --git a/packages/types/src/babylon.ts b/packages/types/src/babylon.ts new file mode 100644 index 0000000000..9972fb7e0d --- /dev/null +++ b/packages/types/src/babylon.ts @@ -0,0 +1,43 @@ +import { OfflineAminoSigner, OfflineDirectSigner } from "./cosmjs"; + +export interface IBBNProvider { + /** + * Connects to the wallet and returns the instance of the wallet provider. + * @returns A promise that resolves to an instance of the wrapper wallet provider. + * @throws An error if the wallet is not installed or if connection fails. + */ + connectWallet(): Promise; + + /** + * Gets the address of the connected wallet. + * @returns A promise that resolves to the address of the connected wallet. + */ + getAddress(): Promise; + + /** + * Gets the public key of the connected wallet. + * @returns A promise that resolves to the public key of the connected wallet. + */ + getPublicKeyHex(): Promise; + + /** + * Gets the name of the wallet provider. + * @returns A promise that resolves to the name of the wallet provider. + */ + getWalletProviderName(): Promise; + + /** + * Gets the icon of the wallet provider. + * @returns A promise that resolves to the icon of the wallet provider. + */ + getWalletProviderIcon(): Promise; + + /** + * Retrieves an offline signer that supports both Amino and Direct signing methods. + * This signer is used for signing transactions offline before broadcasting them to the network. + * + * @returns {Promise} A promise that resolves to a signer supporting both Amino and Direct signing + * @throws {Error} If wallet connection is not established or signer cannot be retrieved + */ + getOfflineSigner(): Promise; +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index ba19eb81fc..402e970658 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -9,3 +9,4 @@ export * from "./cosmjs"; export * from "./cosmjs-alt"; export * from "./secretjs"; export * from "./settled"; +export * from "./babylon";