diff --git a/package-lock.json b/package-lock.json index 03de82fd..dd1e728d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cheqd/sdk", - "version": "3.5.8-develop.1", + "version": "3.5.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cheqd/sdk", - "version": "3.5.8-develop.1", + "version": "3.5.8", "license": "Apache-2.0", "dependencies": { "@cheqd/ts-proto": "^3.3.0", @@ -19,11 +19,13 @@ "@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", "file-type": "^18.5.0", "multiformats": "^12.0.1", + "secp256k1": "^5.0.0", "uuid": "^9.0.0" }, "devDependencies": { @@ -2224,6 +2226,14 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, + "node_modules/@types/secp256k1": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/secp256k1/-/secp256k1-4.0.3.tgz", + "integrity": "sha512-Da66lEIFeIz9ltsdMZcpQvmrmmoqrfju8pm1BH8WbYjZSwUgCwXLb9C+9XYogwBITnbsSaMdVPb2ekf7TV+03w==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -5730,6 +5740,11 @@ "integrity": "sha512-EZSPZB70jiVsivaBLYDCyntd5eH8NTSMOn3rB+HxwdmKThGELLdYv8qVIMWvZEFy9w8ZZpW9h9OB32l1rGtj7g==", "dev": true }, + "node_modules/node-addon-api": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" + }, "node_modules/node-emoji": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz", @@ -5740,6 +5755,16 @@ "lodash": "^4.17.21" } }, + "node_modules/node-gyp-build": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz", + "integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -9869,6 +9894,20 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "node_modules/secp256k1": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-5.0.0.tgz", + "integrity": "sha512-TKWX8xvoGHrxVdqbYeZM9w+izTF4b9z3NhSaDkdn81btvuh+ivbIMGT/zQvDtTFWhRlThpoz6LEYTr7n8A5GcA==", + "hasInstallScript": true, + "dependencies": { + "elliptic": "^6.5.4", + "node-addon-api": "^5.0.0", + "node-gyp-build": "^4.2.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/semantic-release": { "version": "21.0.7", "resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-21.0.7.tgz", diff --git a/package.json b/package.json index 1718b1c5..39089054 100644 --- a/package.json +++ b/package.json @@ -61,11 +61,13 @@ "@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", "file-type": "^18.5.0", "multiformats": "^12.0.1", + "secp256k1": "^5.0.0", "uuid": "^9.0.0" }, "devDependencies": { diff --git a/src/utils.ts b/src/utils.ts index 815be775..da3e73ce 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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, @@ -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 @@ -295,4 +300,14 @@ export function createMsgResourcePayloadToSign(payload: Partial { + const client = await StargateClient.connect(rpcAddress) + return await client.getAllBalances(address) } \ No newline at end of file diff --git a/tests/testutils.test.ts b/tests/testutils.test.ts index 16f1efc6..bb7dae70 100644 --- a/tests/testutils.test.ts +++ b/tests/testutils.test.ts @@ -19,6 +19,15 @@ export const image_content = 'iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1 export const default_content = '

Test file content

' +// They are connected +export const pubkey_hex = "04adf6cad45e58a7e1908bebefcc358de229c108fb1170566f83be5ce028eb6b1997711067ffcb445532667ed4a4efc2b334c16421edb52ec5e0324a1c0e570663" + +export const bech32_account = "cheqd1ehcg0jarxkyxtkzrwcxayedxrskwyftxj4exm9" +// Testnet RPC and faucet address +export const faucet_address = "cheqd1rnr5jrt4exl0samwj0yegv99jeskl0hsxmcz96" + +export const testnet_rpc = "https://rpc.cheqd.network:443" + export function containsAll(array: T[], values: T[]): boolean { return values.every(value => array.includes(value)) } diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 1d83e558..575484f2 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -1,6 +1,8 @@ import { TImportableEd25519Key, - createSignInputsFromImportableEd25519Key + checkBalance, + createSignInputsFromImportableEd25519Key, + getCosmosAccount } from '../src/utils' import { createDidVerificationMethod, @@ -13,6 +15,7 @@ import { MethodSpecificIdAlgo, VerificationMethods } from '../src/types' +import { faucet_address, pubkey_hex, testnet_rpc } from './testutils.test' describe('createSignInputsFromImportableEd25519Key', () => { it('should create a sign input from an importable ed25519 key 2020', async () => { @@ -74,4 +77,19 @@ describe('createSignInputsFromImportableEd25519Key', () => { expect(signInput).toEqual({ verificationMethodId: verificationKeys.keyId, privateKeyHex: importableEd25519Key.privateKeyHex }) }) + + it('should get the cosmos account from publicKeyHex', () => { + // We know, that such point could be transformed to a cheqd account cheqd1ehcg0jarxkyxtkzrwcxayedxrskwyftxj4exm9 + const expectedAddress = "cheqd1ehcg0jarxkyxtkzrwcxayedxrskwyftxj4exm9" + + expect(expectedAddress).toEqual(getCosmosAccount(pubkey_hex)) + + }) + + it('should return not empty account balance', async () => { + const balances = await checkBalance(faucet_address, testnet_rpc) + expect(balances.length).toBeGreaterThan(0) + expect(balances[0].denom).toEqual("ncheq") + expect(+balances[0].amount).toBeGreaterThan(0) + }) }) \ No newline at end of file