Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Jul 2, 2024
2 parents e063941 + f31d2df commit cebea14
Show file tree
Hide file tree
Showing 37 changed files with 316 additions and 106 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TEST_PRIVATE_KEY=
TEST_SEED_PHASE=

This file was deleted.

1 change: 0 additions & 1 deletion docs/interfaces/_injectivelabs_sdk_ts.internal.PubKey.html

This file was deleted.

4 changes: 4 additions & 0 deletions packages/exceptions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.14.12](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/[email protected]...@injectivelabs/[email protected]) (2024-06-18)

**Note:** Version bump only for package @injectivelabs/exceptions

## [1.14.11](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/[email protected]...@injectivelabs/[email protected]) (2024-06-10)

**Note:** Version bump only for package @injectivelabs/exceptions
Expand Down
4 changes: 2 additions & 2 deletions packages/exceptions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@injectivelabs/exceptions",
"description": "List of exceptions that can be reused throughout Injective's projects.",
"version": "1.14.12-beta.0",
"version": "1.14.13-beta.0",
"sideEffects": false,
"license": "Apache-2.0",
"types": "dist/cjs/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@injectivelabs/grpc-web": "^0.0.1",
"@injectivelabs/ts-types": "^1.14.12-beta.0",
"@injectivelabs/ts-types": "^1.14.13-beta.0",
"http-status-codes": "^2.2.0",
"link-module-alias": "^1.2.0",
"shx": "^0.3.2"
Expand Down
4 changes: 4 additions & 0 deletions packages/networks/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.14.12](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/[email protected]...@injectivelabs/[email protected]) (2024-06-18)

**Note:** Version bump only for package @injectivelabs/networks

## [1.14.11](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/[email protected]...@injectivelabs/[email protected]) (2024-06-10)

**Note:** Version bump only for package @injectivelabs/networks
Expand Down
8 changes: 4 additions & 4 deletions packages/networks/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@injectivelabs/networks",
"description": "Endpoints, networks, etc. Can be reused throughout Injective's projects.",
"version": "1.14.12-beta.0",
"version": "1.14.13-beta.0",
"sideEffects": false,
"license": "Apache-2.0",
"author": {
Expand Down Expand Up @@ -32,9 +32,9 @@
"start": "node dist/index.js"
},
"dependencies": {
"@injectivelabs/exceptions": "^1.14.12-beta.0",
"@injectivelabs/ts-types": "^1.14.12-beta.0",
"@injectivelabs/utils": "^1.14.12-beta.0",
"@injectivelabs/exceptions": "^1.14.13-beta.0",
"@injectivelabs/ts-types": "^1.14.13-beta.0",
"@injectivelabs/utils": "^1.14.13-beta.0",
"link-module-alias": "^1.2.0",
"shx": "^0.3.2"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.14.12](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/[email protected]...@injectivelabs/[email protected]) (2024-06-18)

**Note:** Version bump only for package @injectivelabs/sdk-ts

## [1.14.11](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/[email protected]...@injectivelabs/[email protected]) (2024-06-10)

**Note:** Version bump only for package @injectivelabs/sdk-ts
Expand Down
14 changes: 7 additions & 7 deletions packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@injectivelabs/sdk-ts",
"description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
"version": "1.14.12-beta.7",
"version": "1.14.13-beta.5",
"sideEffects": false,
"license": "Apache-2.0",
"author": {
Expand Down Expand Up @@ -39,24 +39,24 @@
"@ethersproject/bytes": "^5.7.0",
"@injectivelabs/core-proto-ts": "^0.0.21",
"@injectivelabs/dmm-proto-ts": "1.0.20",
"@injectivelabs/exceptions": "^1.14.12-beta.0",
"@injectivelabs/exceptions": "^1.14.13-beta.0",
"@injectivelabs/grpc-web": "^0.0.1",
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
"@injectivelabs/indexer-proto-ts": "1.11.42",
"@injectivelabs/mito-proto-ts": "1.0.65",
"@injectivelabs/networks": "^1.14.12-beta.0",
"@injectivelabs/test-utils": "^1.14.6-beta.0",
"@injectivelabs/ts-types": "^1.14.12-beta.0",
"@injectivelabs/utils": "^1.14.12-beta.0",
"@injectivelabs/networks": "^1.14.13-beta.0",
"@injectivelabs/test-utils": "^1.14.13-beta.0",
"@injectivelabs/ts-types": "^1.14.13-beta.0",
"@injectivelabs/utils": "^1.14.13-beta.0",
"@metamask/eth-sig-util": "^4.0.0",
"@noble/curves": "^1.4.0",
"axios": "^1.6.4",
"bech32": "^2.0.0",
"bip39": "^3.0.4",
"cosmjs-types": "^0.9.0",
"ethereumjs-util": "^7.1.4",
"ethers": "^5.7.2",
"ethers": "^6.5.1",
"google-protobuf": "^3.21.0",
"graphql": "^16.3.0",
"http-status-codes": "^2.2.0",
Expand Down
72 changes: 60 additions & 12 deletions packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,71 @@
import { generateArbitrarySignDoc } from '../modules'
import { PrivateKey } from './PrivateKey'

const privateKey =
'f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3'
const pk = 'f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3'
const seedPhase = process.env.TEST_SEED_PHASE as string

describe('PrivateKey', () => {
it('returns the correct PublicKey is derived from a private key', () => {
const publicKey = PrivateKey.fromPrivateKey(privateKey)
it('returns the correct address derived from a mnemonic', () => {
const privateKey = PrivateKey.fromMnemonic(seedPhase)

expect(publicKey.toPublicKey().toBase64()).toEqual(
expect(privateKey.toBech32()).toEqual(
'inj1u3f7yuwl8mkd88ryzdhxt6kt90a60rgl0nmxyq',
)
})

it('returns the correct PublicKey derived from a private key', () => {
const privateKey = PrivateKey.fromHex(pk)

expect(privateKey.toPublicKey().toBase64()).toEqual(
'A13cTVZCuTg+Lwh7LuiLcgf2KG68nzEOnfFAbszCwxgT',
)
})

it('returns the correct PublicKey is derived from a private key starting with 0x', () => {
const publicKey = PrivateKey.fromPrivateKey('0x' + privateKey)
it('returns the correct PublicKey derived from a private key starting with 0x', () => {
const privateKey = PrivateKey.fromHex('0x' + pk)

expect(publicKey.toPublicKey().toBase64()).toEqual(
expect(privateKey.toPublicKey().toBase64()).toEqual(
'A13cTVZCuTg+Lwh7LuiLcgf2KG68nzEOnfFAbszCwxgT',
)
})

it('returns true when verifying signature for a particular EIP712', () => {
const expectedSignature =
'e75db7f206927afd916b1423ed04fca37d2ac19662b220edc7d14f164b3af8f4727bb0f5b1f1372fd25675aebed92a5467cc55d2f38774a794a14bc59212c7d41c'
const eip712 = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'string' },
],
Tx: [
{ name: 'context', type: 'string' },
{ name: 'msgs', type: 'string' },
],
},
primaryType: 'Tx',
domain: {
name: 'Injective Web3',
version: '1.0.0',
chainId: '0xaa36a7',
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
salt: '0',
},
message: {
context:
'{"account_number":17,"chain_id":"injective-888","fee":{"amount":[{"denom":"inj","amount":"71101500000000"}],"gas":142203,"payer":"inj17gkuet8f6pssxd8nycm3qr9d9y699rupv6397z"},"memo":"","sequence":21979,"timeout_height":30038262}',
msgs: '[{"@type":"/injective.exchange.v1beta1.MsgCreateSpotMarketOrder","sender":"inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r","order":{"market_id":"0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe","order_info":{"subaccount_id":"0xbdaedec95d563fb05240d6e01821008454c24c36000000000000000000000000","fee_recipient":"inj1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8dkncm8","price":"0.000000000024039000","quantity":"41000000000000000.000000000000000000","cid":""},"order_type":"BUY","trigger_price":"0.000000000000000000"}}]',
},
}
const privateKey = PrivateKey.fromHex(pk)
const signature = privateKey.signTypedData(eip712)

expect(Buffer.from(signature).toString('hex')).toEqual(expectedSignature)
})

it('returns true when verifying signature for a public key and eip712', () => {
const signature =
'0xe75db7f206927afd916b1423ed04fca37d2ac19662b220edc7d14f164b3af8f4727bb0f5b1f1372fd25675aebed92a5467cc55d2f38774a794a14bc59212c7d41c'
Expand Down Expand Up @@ -69,17 +114,20 @@ describe('PrivateKey', () => {
})

it('returns true when verifying arbitrary message', async () => {
const pk = PrivateKey.fromHex(privateKey)
const privateKey = PrivateKey.fromHex(pk)

const message = 'testing ADR-36'
const { signDocBuff } = generateArbitrarySignDoc(message, pk.toBech32())
const signature = await pk.sign(signDocBuff)
const { signDocBuff } = generateArbitrarySignDoc(
message,
privateKey.toBech32(),
)
const signature = await privateKey.sign(signDocBuff)

expect(
PrivateKey.verifyArbitrarySignature({
signature: Buffer.from(signature).toString('hex'),
signDoc: signDocBuff,
publicKey: pk.toPublicKey().toHex(),
publicKey: privateKey.toPublicKey().toHex(),
}),
).toBe(true)
})
Expand Down
Loading

0 comments on commit cebea14

Please sign in to comment.