Skip to content

Commit

Permalink
Move utils from CredentialService
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Nikitin committed Aug 8, 2023
1 parent 7f9745a commit f474fbe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@cosmjs/tendermint-rpc": "^0.31.0",
"@cosmjs/utils": "^0.31.0",
"@stablelib/ed25519": "^1.0.3",
"@types/secp256k1": "^4.0.3",
"cosmjs-types": "^0.8.0",
"did-jwt": "^7.2.4",
"did-resolver": "^4.1.0",
Expand Down
15 changes: 15 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
} from '@stablelib/ed25519'
import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing'
import { EnglishMnemonic as _, sha256 } from '@cosmjs/crypto'
import { rawSecp256k1PubkeyToRawAddress } from '@cosmjs/amino'
import pkg from 'secp256k1'
import { v4 } from 'uuid'
import {
VerificationMethod as ProtoVerificationMethod,
Expand All @@ -36,6 +38,9 @@ import {
} from "@cheqd/ts-proto/cheqd/did/v2/index.js"
import { DIDModule } from "./modules/did.js"
import { MsgCreateResourcePayload } from "@cheqd/ts-proto/cheqd/resource/v2/index.js"
import { toBech32 } from "@cosmjs/encoding"
import { StargateClient } from "@cosmjs/stargate"
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"

export type TImportableEd25519Key = {
publicKeyHex: string
Expand Down Expand Up @@ -295,4 +300,14 @@ export function createMsgResourcePayloadToSign(payload: Partial<MsgCreateResourc
return MsgCreateResourcePayload.encode(
MsgCreateResourcePayload.fromPartial(payload)
).finish()
}

export function getCosmosAccount(kid: string): string {
const { publicKeyConvert } = pkg
return toBech32('cheqd', rawSecp256k1PubkeyToRawAddress(publicKeyConvert(fromString(kid, 'hex'), true)))
}

export async function checkBalance(address: string, rpcAddress: string): Promise<readonly Coin[]> {
const client = await StargateClient.connect(rpcAddress)
return await client.getAllBalances(address)
}

0 comments on commit f474fbe

Please sign in to comment.