Skip to content

Commit

Permalink
Sync workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Aug 28, 2024
1 parent 97ab3d1 commit 9b10a3d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0

- name: Initialise CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: 'javascript'
queries: security-and-quality
Expand All @@ -37,4 +37,4 @@ jobs:
npm run build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
5 changes: 2 additions & 3 deletions .github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ jobs:

call-build:
name: "Build & Test"
needs: call-lint
uses: ./.github/workflows/build.yml
secrets: inherit

call-release:
name: "Release"
needs: call-build
needs: [ call-lint, call-build ]
if: ${{ github.ref_protected == true }}
uses: ./.github/workflows/release.yml
secrets: inherit
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
fetch-depth: 0 # Required to fetch version

- name: Run Super Linter
uses: github/super-linter/slim@v4
uses: github/super-linter/slim@v6
env:
IGNORE_GITIGNORED_FILES: true
DEFAULT_BRANCH: main
Expand Down
19 changes: 18 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import {
} from '@cheqd/ts-proto/cheqd/did/v2';
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2';
import { DIDModule } from './modules/did';
import { toBech32 } from '@cosmjs/encoding';
import { StargateClient } from '@cosmjs/stargate';
import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin';
import { rawSecp256k1PubkeyToRawAddress } from '@cosmjs/amino';
import pkg from 'secp256k1';

export type TImportableEd25519Key = {
publicKeyHex: string;
Expand Down Expand Up @@ -265,7 +270,7 @@ export function createCosmosPayerWallet(
: DirectSecp256k1Wallet.fromKey(fromString(cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
}

function toMultibaseRaw(key: Uint8Array) {
export function toMultibaseRaw(key: Uint8Array) {
const multibase = new Uint8Array(MULTICODEC_ED25519_HEADER.length + key.length);

multibase.set(MULTICODEC_ED25519_HEADER);
Expand Down Expand Up @@ -305,6 +310,18 @@ export function createMsgDeactivateDidDocPayloadToSign(didPayload: DIDDocument,
).finish();
}

export function getCosmosAccount(publicKeyHex: string): string {
const { publicKeyConvert } = pkg;

return toBech32('cheqd', rawSecp256k1PubkeyToRawAddress(publicKeyConvert(fromString(publicKeyHex, 'hex'), true)));
}

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

return await client.getAllBalances(address);
}

export function createMsgResourcePayloadToSign(payload: Partial<MsgCreateResourcePayload> | MsgCreateResourcePayload) {
return MsgCreateResourcePayload.encode(MsgCreateResourcePayload.fromPartial(payload)).finish();
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testutils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export const image_content =

export const default_content = '<p>Test file content</p>';

// 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<T>(array: T[], values: T[]): boolean {
return values.every((value) => array.includes(value));
}
Expand Down
29 changes: 27 additions & 2 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { TImportableEd25519Key, createSignInputsFromImportableEd25519Key, isJSON } from '../src/utils';
import { createDidVerificationMethod, createVerificationKeys, createKeyPairRaw } from '../src/utils';
import {
TImportableEd25519Key,
checkBalance,
createSignInputsFromImportableEd25519Key,
isJSON,
createDidVerificationMethod,
createVerificationKeys,
createKeyPairRaw,
getCosmosAccount,
} from '../src/utils';
import { toString } from 'uint8arrays';
import { IKeyPair, 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 () => {
Expand Down Expand Up @@ -73,6 +82,22 @@ describe('createSignInputsFromImportableEd25519Key', () => {
});
});

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)
})
})

it('should return valid json', async () => {
// define invalid cases
const invalid = [
Expand Down

0 comments on commit 9b10a3d

Please sign in to comment.