Skip to content

Commit

Permalink
Merge pull request #45 from cosmology-tech/fix-doc
Browse files Browse the repository at this point in the history
fixed missing references in docs
  • Loading branch information
Zetazzz authored Oct 20, 2024
2 parents 17f18a4 + 4c0ef13 commit 4bb487d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 109 deletions.
18 changes: 14 additions & 4 deletions docs/signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ import { DirectSigner } from "@interchainjs/cosmos/signers/direct";
import { toEncoder } from "@interchainjs/cosmos/utils";
import { Secp256k1Auth } from "@interchainjs/auth/secp256k1";
import { MsgSend } from "@interchainjs/cosmos-types/cosmos/bank/v1beta1/tx";
import {
HDPath
} from '@interchainjs/types';


const [auth] = Secp256k1Auth.fromMnemonic("<MNEMONIC_WORDS>", [
HDPath.cosmos().toString(),
]);
// use cosmos hdpath built by HDPath
// we can get cosmos hdpath "m/44'/118'/0'/0/0" by this:
HDPath.cosmos().toString(),
]);
const signer = new DirectSigner(auth, [toEncoder(MsgSend)], <RPC_ENDPOINT>);
```

Expand All @@ -165,11 +171,15 @@ import { DirectSigner } from "@interchainjs/cosmos/signers/direct";
import { DirectWallet, SignDoc } from "@interchainjs/cosmos/types";
import { toEncoder } from "@interchainjs/cosmos/utils";
import { MsgSend } from "@interchainjs/cosmos-types/cosmos/bank/v1beta1/tx";
import { HDPath } from "@interchainjs/types";

const directWallet = Secp256k1HDWallet.fromMnemonic("<MNEMONIC_WORDS>", [
{
prefix: commonPrefix,
hdPath: cosmosHdPath,
// bech32_prefix
prefix: "cosmos",
// use cosmos hdpath built by HDPath
// we can get cosmos hdpath "m/44'/118'/0'/0/0" by this:
hdPath: HDPath.cosmos().toString(),
},
]);
const signer = await DirectSigner.fromWallet(wallet, [toEncoder(MsgSend)], <RPC_ENDPOINT>);
Expand Down
4 changes: 3 additions & 1 deletion docs/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ import { HDPath } from "@interchainjs/types";
// init wallet with two accounts using two hd paths
const wallet = Secp256k1HDWallet.fromMnemonic(
"<MNEMONIC_WORDS>",
// use cosmos hdpath built by HDPath
// we can get cosmos hdpath "m/44'/118'/0'/0/0" and "m/44'/118'/0'/0/1" by this:
[0, 1].map((i) => ({
prefix: commonPrefix,
prefix: "cosmos",
hdPath: HDPath.cosmos(0, 0, i).toString(),
}))
);
Expand Down
51 changes: 2 additions & 49 deletions libs/cosmos-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,9 @@
<a href="https://github.com/cosmology-tech/interchainjs/blob/main/LICENSE-Apache"><img height="20" src="https://img.shields.io/badge/license-Apache-blue.svg"></a>
</p>

Cosmos message codecs (including Cosmos( Stargate ) and CosmWasm messages) and query implementation generated by telescope for cosmos chains
Fundamental types for Networks/Cosmos to use.

## Usage

```sh
npm install @interchainjs/cosmos-types
```

### Message

Make `Encoder` and `Converter` used by `Cosmos` signers (taking `MsgSend` as example)

```ts
import { MsgSend } from "@interchainjs/cosmos-types/cosmos/bank/v1beta1/tx";
import { toConverter, toEncoder } from "@interchainjs/cosmos/utils";
import { AminoSigner } from "@interchainjs/cosmos/signers/amino";

const encoder = toEncoder(MsgSend);
const converter = toConverter(MsgSend);

const signer = new AminoSigner(<AUTH>, [encoder], [converter], <rpc-endpoint>);
```

- See [@interchainjs/auth](/packages/auth/README.md) to construct `<AUTH>`
- See [@interchainjs/cosmos](/packages/cosmos/README.md) to construct different `<signer>`s

Message groups

```ts
import { Msgs } from "@interchainjs/cosmos-types/cosmos";
import { CosmWasmMsgs } from "@interchainjs/cosmos-types/cosmwasm";
```

### Query

Make queries (taking querying `validators` as example)

```ts
import { RpcQuery } from "@interchainjs/cosmos-types/rpc";

const rpcQuery = new RpcQuery(<rpc-endpoint>);
const { validators } = await rpcQuery.validators({
status: bondStatusToJSON(BondStatus.BOND_STATUS_BONDED),
});
```

## Implementations

- **query**
- **rpc query client** from `@interchainjs/cosmos-types/rpc`
Generated by Telescope. (Will generate code with less redundancy in future version.)

## License

Expand Down
57 changes: 2 additions & 55 deletions libs/interchainjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,9 @@
<a href="https://github.com/cosmology-tech/interchainjs/blob/main/LICENSE-Apache"><img height="20" src="https://img.shields.io/badge/license-Apache-blue.svg"></a>
</p>

Wrapper of `@interchainjs/auth` and `@interchainjs/cosmos` to fit corresponding interfaces in `@cosmjs`
Functionalities(Tx, Query) generated by Telescope.

## Usage

```sh
npm install interchainjs
```

To sign messages (taking cosmos`stargate` signing client as example)

```ts
// import * from "interchainjs"; // Error: use sub-imports, to ensure small app size
import { CosmosSigningClient } from "interchainjs/cosmos";

const directWallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [
{
prefix: commonPrefix,
hdPath: cosmosHdPath,
},
]);

const directSigner = directWallet.toOfflineDirectSigner();

const signingClient = await CosmosSigningClient.connectWithSigner(
await getRpcEndpoint(),
directSigner
);

const result = await signingClient.signAndBroadcast(<ADDRESS>, <MESSAGE>[], "auto");
// or you can use helper functions to do `signAndBroadcast`. taking send tokens as example
const result = await signingClient.helpers.send(<ADDRESS>, <MsgSend message>, "auto", "");

console.log(result.transactionHash); // the hash of TxRaw
```

To construct an offline signer (taking `direct` signer as example)

```ts
const directWallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [
{
prefix: commonPrefix,
hdPath: cosmosHdPath,
},
]);

const directSigner = directWallet.toOfflineDirectSigner();
```

## Implementations

- **signing client**
- **signing client** from `interchainjs/signing-client`
- **cosmos( stargate ) signing client** from `interchainjs/cosmos`
- **cosmwasm signing client** from `interchainjs/cosmwasm`
- **wallet**
- **secp256k1 wallet** from `@interchainjs/cosmos/wallets/secp256k1hd`
⚠️ **This software is currently in a Development Preview Alpha stage.** We're refactoring helper functions generated by Telescope. Leaner helper functions coming soon!

## License

Expand Down
1 change: 1 addition & 0 deletions networks/cosmos/starship/__tests__/gov.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('Governance tests for osmosis', () => {
]);
const [aminoAuth] = Secp256k1Auth.fromMnemonic(generateMnemonic(), [
// use cosmos hdpath built by HDPath
// we can get cosmos hdpath "m/44'/118'/0'/0/0" by this:
HDPath.cosmos().toString(),
]);
directSigner = new DirectSigner(
Expand Down
4 changes: 4 additions & 0 deletions packages/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ console.log(signature.toHex());
It's easy to derive _cosmos/injective/ethereum_ network HD path (taking `cosmos` as example)

```ts
import { HDPath } from "@interchainjs/types";

// derive with Cosmos default HD path "m/44'/118'/0'/0/0"
const [auth] = Secp256k1Auth.fromMnemonic("<MNEMONIC_WORDS>", [
// use cosmos hdpath built by HDPath
// we can get cosmos hdpath "m/44'/118'/0'/0/0" by this:
HDPath.cosmos().toString(),
]);
// is identical to
Expand Down

0 comments on commit 4bb487d

Please sign in to comment.