-
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.
chore: begin msgBroadcaster abstraction
- Loading branch information
1 parent
f625e05
commit 2f603b1
Showing
28 changed files
with
9,318 additions
and
21 deletions.
There are no files selected for viewing
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
File renamed without changes.
1 change: 1 addition & 0 deletions
1
packages/wallet-ts/src/types/index.ts → packages/ts-types/src/wallet/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './enums' | ||
export * from './strategy' | ||
|
||
export type UnwrappedPromise<T> = T extends Promise<infer Return> ? Return : T |
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,226 @@ | ||
import type { DirectSignResponse } from '@cosmjs/proto-signing' | ||
import { | ||
AccountAddress, | ||
ChainId, | ||
CosmosChainId, | ||
EthereumChainId, | ||
} from '../index' | ||
import type { TxRaw, TxResponse } from '@injectivelabs/sdk-ts' | ||
import { AminoSignResponse, StdSignDoc } from '@keplr-wallet/types' | ||
import { Wallet, WalletDeviceType } from './enums' | ||
|
||
export type onAccountChangeCallback = (account: string) => void | ||
export type onChainIdChangeCallback = () => void | ||
|
||
export interface WalletStrategyEthereumOptions { | ||
ethereumChainId: EthereumChainId | ||
rpcUrl?: string | ||
} | ||
|
||
export interface SendTransactionOptions { | ||
address: string | ||
chainId: ChainId | ||
txTimeout?: number | ||
endpoints: { | ||
rest: string | ||
grpc: string | ||
tm?: string | ||
} | ||
} | ||
|
||
export interface EthereumWalletStrategyArgs { | ||
chainId: ChainId | ||
ethereumOptions: WalletStrategyEthereumOptions | ||
} | ||
|
||
export interface ConcreteCosmosWalletStrategy { | ||
/** | ||
* The accounts from the wallet (addresses) | ||
*/ | ||
getAddresses(args?: unknown): Promise<string[]> | ||
|
||
/** | ||
* Return the WalletDeviceType connected on the | ||
* wallet provider (extension, mobile, hardware wallet) | ||
*/ | ||
getWalletDeviceType(): Promise<WalletDeviceType> | ||
|
||
/** | ||
* Get the PubKey from the wallet | ||
* in base64 for Cosmos native wallets | ||
*/ | ||
getPubKey(address?: string): Promise<string> | ||
|
||
/** | ||
* Perform validations and checks | ||
* for the wallet (if the chain is supported, etc) | ||
*/ | ||
enable(args?: unknown): Promise<boolean> | ||
|
||
/** | ||
* Sends Cosmos transaction. Returns a transaction hash | ||
* @param transaction should implement TransactionConfig | ||
* @param options | ||
*/ | ||
sendTransaction( | ||
transaction: DirectSignResponse | TxRaw, | ||
options: SendTransactionOptions, | ||
): Promise<TxResponse> | ||
|
||
signTransaction(transaction: { | ||
txRaw: TxRaw | ||
chainId: string | ||
accountNumber: number | ||
address: string | ||
}): Promise<DirectSignResponse> | ||
|
||
signAminoTransaction(transaction: { | ||
stdSignDoc: StdSignDoc | ||
address: string | ||
}): Promise<AminoSignResponse> | ||
} | ||
|
||
export interface WalletStrategyOptions { | ||
privateKey?: string | ||
metadata?: Record<string, string | Record<string, string>> | ||
} | ||
|
||
export interface CosmosWalletStrategyArguments { | ||
chainId: CosmosChainId | ||
wallet?: Wallet | ||
} | ||
|
||
export interface WalletStrategyArguments | ||
extends Omit<CosmosWalletStrategyArguments, 'chainId'> { | ||
chainId: ChainId | ||
options?: WalletStrategyOptions | ||
ethereumOptions?: WalletStrategyEthereumOptions | ||
disabledWallets?: Wallet[] | ||
wallet?: Wallet | ||
} | ||
|
||
export interface ConcreteWalletStrategy | ||
extends Omit< | ||
ConcreteCosmosWalletStrategy, | ||
| 'sendTransaction' | ||
| 'signTransaction' | ||
| 'isChainIdSupported' | ||
| 'signAminoTransaction' | ||
> { | ||
/** | ||
* Sends Cosmos transaction. Returns a transaction hash | ||
* @param transaction should implement TransactionConfig | ||
* @param options | ||
*/ | ||
sendTransaction( | ||
transaction: DirectSignResponse | TxRaw, | ||
options: { | ||
address: string | ||
chainId: ChainId | ||
txTimeout?: number | ||
endpoints?: { | ||
rest: string | ||
grpc: string | ||
tm?: string | ||
} | ||
}, | ||
): Promise<TxResponse> | ||
|
||
/** | ||
* Confirm the address on the wallet | ||
* @param address address | ||
*/ | ||
getSessionOrConfirm(address?: string): Promise<string> | ||
|
||
/** | ||
* Sends Ethereum transaction. Returns a transaction hash | ||
* @param transaction should implement TransactionConfig | ||
* @param options | ||
*/ | ||
sendEthereumTransaction( | ||
transaction: unknown, | ||
options: { address: string; ethereumChainId: EthereumChainId }, | ||
): Promise<string> | ||
|
||
/** @deprecated * */ | ||
signTransaction( | ||
data: | ||
| string /* EIP712 Typed Data in JSON */ | ||
| { txRaw: TxRaw; accountNumber: number; chainId: string }, | ||
address: string, | ||
): Promise<string | DirectSignResponse> | ||
|
||
/** | ||
* Sign a cosmos transaction using the wallet provider | ||
* | ||
* @param transaction | ||
* @param address - injective address | ||
*/ | ||
signCosmosTransaction(transaction: { | ||
txRaw: TxRaw | ||
accountNumber: number | ||
chainId: string | ||
address: string | ||
}): Promise<DirectSignResponse> | ||
|
||
/** | ||
* Sign an amino sign doc using the wallet provider | ||
* | ||
* @param transaction | ||
* @param address - injective address | ||
*/ | ||
signAminoCosmosTransaction(transaction: { | ||
signDoc: any | ||
accountNumber: number | ||
chainId: string | ||
address: string | ||
}): Promise<string> | ||
|
||
/** | ||
* Sign EIP712 TypedData using the wallet provider | ||
* @param eip712TypedData | ||
* @param address - ethereum address | ||
*/ | ||
signEip712TypedData(eip712TypedData: string, address: string): Promise<string> | ||
|
||
signArbitrary(signer: string, data: string | Uint8Array): Promise<string> | ||
|
||
getEthereumChainId(): Promise<string> | ||
|
||
getEthereumTransactionReceipt(txHash: string): void | ||
|
||
onAccountChange?(callback: onAccountChangeCallback): Promise<void> | void | ||
|
||
onChainIdChange?(callback: onChainIdChangeCallback): Promise<void> | void | ||
|
||
disconnect?(): Promise<void> | void | ||
} | ||
|
||
export interface WalletStrategy { | ||
strategies: Record<Wallet, ConcreteWalletStrategy | undefined> | ||
wallet: Wallet | ||
args: WalletStrategyArguments | ||
|
||
getWallet(): Wallet | ||
setWallet(wallet: Wallet): void | ||
setOptions(options?: WalletStrategyOptions): void | ||
getStrategy(): ConcreteWalletStrategy | ||
getAddresses(args?: unknown): Promise<AccountAddress[]> | ||
getWalletDeviceType(): Promise<WalletDeviceType> | ||
getPubKey(address?: string): Promise<string> | ||
enable(args?: unknown): Promise<boolean> | ||
enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]> | ||
getEthereumChainId(): Promise<string> | ||
getEthereumTransactionReceipt(txHash: string): Promise<void> | ||
getSessionOrConfirm(address?: AccountAddress): Promise<string> | ||
sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse> | ||
sendEthereumTransaction(tx: any, options: { address: AccountAddress; ethereumChainId: EthereumChainId }): Promise<string> | ||
signTransaction(data: string | { txRaw: TxRaw; accountNumber: number; chainId: string }, address: AccountAddress): Promise<string | DirectSignResponse> | ||
signEip712TypedData(eip712TypedData: string, address: AccountAddress): Promise<string> | ||
signAminoCosmosTransaction(transaction: { signDoc: any; accountNumber: number; chainId: string; address: string }): Promise<string> | ||
signCosmosTransaction(transaction: { txRaw: TxRaw; accountNumber: number; chainId: string; address: string }): Promise<DirectSignResponse> | ||
signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void> | ||
onAccountChange(callback: onAccountChangeCallback): Promise<void> | ||
onChainIdChange(callback: onChainIdChangeCallback): Promise<void> | ||
disconnect(): Promise<void> | ||
} |
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,4 +1,3 @@ | ||
export * from './broadcaster' | ||
export * from './strategies' | ||
export * from './utils' | ||
export * from './types' |
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,60 @@ | ||
# 🌟 Injective Protocol - Ledger Wallet Strategy | ||
|
||
<!-- TODO --> | ||
|
||
[![downloads](https://img.shields.io/npm/dm/@injectivelabs/wallet-ts.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-ts) | ||
[![npm-version](https://img.shields.io/npm/v/@injectivelabs/wallet-ts.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-ts) | ||
[![license](https://img.shields.io/npm/l/express.svg)]() | ||
|
||
_Package to use Ledger Wallets on Injective via the wallet strategy._ | ||
|
||
--- | ||
|
||
## 📚 Installation | ||
|
||
```bash | ||
yarn add @injectivelabs/wallet-ledger | ||
``` | ||
|
||
--- | ||
|
||
## 📖 Documentation | ||
|
||
<!-- TODO --> | ||
|
||
Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy) | ||
|
||
--- | ||
|
||
## 📜 Contribution | ||
|
||
**Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.** | ||
|
||
--- | ||
|
||
## ⛑ Support | ||
|
||
Reach out to us at one of the following places! | ||
|
||
- Website at <a href="https://injective.com" target="_blank">`injective.com`</a> | ||
- Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a> | ||
- Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a> | ||
- Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a> | ||
|
||
--- | ||
|
||
## 🔓 License | ||
|
||
Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/) | ||
|
||
<a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" /> | ||
|
||
Originally released by Injective Labs Inc. under: <br /> | ||
Apache License <br /> | ||
Version 2.0, January 2004 <br /> | ||
http://www.apache.org/licenses/ | ||
|
||
<p> </p> | ||
<div align="center"> | ||
<sub><em>Powering the future of decentralized finance.</em></sub> | ||
</div> |
Oops, something went wrong.