Skip to content

Commit

Permalink
feat(sdk-coin-inj): inj sdk init along with testcases
Browse files Browse the repository at this point in the history
Ticket: BG-79064
  • Loading branch information
DinshawKothari committed Jun 21, 2023
1 parent e278cc8 commit d5fe470
Show file tree
Hide file tree
Showing 39 changed files with 1,990 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-eos /var/modules/sdk-coin-eos/
RUN cd /var/modules/sdk-coin-eos && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ethw /var/modules/sdk-coin-ethw/
RUN cd /var/modules/sdk-coin-ethw && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-inj /var/modules/sdk-coin-inj/
RUN cd /var/modules/sdk-coin-inj && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ltc /var/modules/sdk-coin-ltc/
RUN cd /var/modules/sdk-coin-ltc && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-sei /var/modules/sdk-coin-sei/
Expand Down Expand Up @@ -205,6 +207,7 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-doge && \
yarn link @bitgo/sdk-coin-eos && \
yarn link @bitgo/sdk-coin-ethw && \
yarn link @bitgo/sdk-coin-inj && \
yarn link @bitgo/sdk-coin-ltc && \
yarn link @bitgo/sdk-coin-sei && \
yarn link @bitgo/sdk-coin-xlm && \
Expand All @@ -213,9 +216,9 @@ RUN cd /var/bitgo-express && \
#LINK_END

#LABEL_START
LABEL created="Mon, 19 Jun 2023 12:36:24 GMT"
LABEL created="Tue, 20 Jun 2023 07:48:10 GMT"
LABEL version=9.27.0
LABEL git_hash=f244290e9dbdc327d7c958a8855dcef0fbc36ba4
LABEL git_hash=3ef27ebba622f79041e487c0ceb57a88d94911d2
#LABEL_END

USER node
Expand Down
1 change: 1 addition & 0 deletions modules/account-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@bitgo/sdk-coin-eth2": "^1.2.23",
"@bitgo/sdk-coin-hash": "^1.0.0",
"@bitgo/sdk-coin-hbar": "^1.3.23",
"@bitgo/sdk-coin-inj": "^1.0.0",
"@bitgo/sdk-coin-near": "^1.4.1",
"@bitgo/sdk-coin-osmo": "^1.1.0",
"@bitgo/sdk-coin-polygon": "^1.5.7",
Expand Down
5 changes: 5 additions & 0 deletions modules/account-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export { Hash };
import * as Sei from '@bitgo/sdk-coin-sei';
export { Sei };

import * as Inj from '@bitgo/sdk-coin-inj';
export { Inj };

import * as Sol from '@bitgo/sdk-coin-sol';
export { Sol };

Expand Down Expand Up @@ -150,6 +153,8 @@ const coinBuilderMap = {
thash: Hash.TransactionBuilderFactory,
sei: Sei.TransactionBuilderFactory,
tsei: Sei.TransactionBuilderFactory,
injective: Inj.TransactionBuilderFactory,
tinjective: Inj.TransactionBuilderFactory,
};

/**
Expand Down
3 changes: 3 additions & 0 deletions modules/account-lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
{
"path": "../sdk-coin-hbar"
},
{
"path": "../sdk-coin-inj"
},
{
"path": "../sdk-coin-near"
},
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@bitgo/sdk-coin-ethw": "^1.3.23",
"@bitgo/sdk-coin-hash": "^1.0.0",
"@bitgo/sdk-coin-hbar": "^1.3.23",
"@bitgo/sdk-coin-inj": "^1.0.0",
"@bitgo/sdk-coin-ltc": "^2.0.18",
"@bitgo/sdk-coin-near": "^1.4.1",
"@bitgo/sdk-coin-osmo": "^1.1.0",
Expand Down
4 changes: 4 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
Gteth,
Hash,
Hbar,
Inj,
Ltc,
Ofc,
OfcToken,
Expand Down Expand Up @@ -81,6 +82,7 @@ import {
Thash,
Thbar,
Tia,
Tinj,
Tltc,
Tosmo,
Tpolygon,
Expand Down Expand Up @@ -133,6 +135,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('hash', Hash.createInstance);
globalCoinFactory.register('hbar', Hbar.createInstance);
globalCoinFactory.register('ltc', Ltc.createInstance);
globalCoinFactory.register('injective', Inj.createInstance);
globalCoinFactory.register('near', Near.createInstance);
globalCoinFactory.register('ofc', Ofc.createInstance);
globalCoinFactory.register('osmo', Osmo.createInstance);
Expand Down Expand Up @@ -169,6 +172,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('tfiatusd', TfiatUsd.createInstance);
globalCoinFactory.register('thash', Thash.createInstance);
globalCoinFactory.register('thbar', Thbar.createInstance);
globalCoinFactory.register('tinjective', Tinj.createInstance);
globalCoinFactory.register('tltc', Tltc.createInstance);
globalCoinFactory.register('tnear', TNear.createInstance);
globalCoinFactory.register('tosmo', Tosmo.createInstance);
Expand Down
2 changes: 2 additions & 0 deletions modules/bitgo/src/v2/coins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import { Hash, Thash } from '@bitgo/sdk-coin-hash';
export { Hash, Thash };
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
export { Hbar, Thbar };
import { Inj, Tinj } from '@bitgo/sdk-coin-inj';
export { Inj, Tinj };
import { Ltc, Tltc } from '@bitgo/sdk-coin-ltc';
export { Ltc, Tltc };
import { Osmo, Tosmo } from '@bitgo/sdk-coin-osmo';
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
{
"path": "../sdk-coin-hbar"
},
{
"path": "../sdk-coin-inj"
},
{
"path": "../sdk-coin-ltc"
},
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-inj/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.idea
public
dist

3 changes: 3 additions & 0 deletions modules/sdk-coin-inj/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.idea/
dist/
8 changes: 8 additions & 0 deletions modules/sdk-coin-inj/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require: 'ts-node/register'
timeout: '60000'
reporter: 'min'
reporter-option:
- 'cdn=true'
- 'json=false'
exit: true
spec: ['test/unit/**/*.ts']
14 changes: 14 additions & 0 deletions modules/sdk-coin-inj/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
!dist/
dist/test/
dist/tsconfig.tsbuildinfo
.idea/
.prettierrc.yml
tsconfig.json
src/
test/
scripts/
.nyc_output
CODEOWNERS
node_modules/
.prettierignore
.mocharc.js
2 changes: 2 additions & 0 deletions modules/sdk-coin-inj/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output/
dist/
3 changes: 3 additions & 0 deletions modules/sdk-coin-inj/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printWidth: 120
singleQuote: true
trailingComma: 'es5'
33 changes: 33 additions & 0 deletions modules/sdk-coin-inj/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# BitGo sdk-coin-inj

SDK coins provide a modular approach to a monolithic architecture. This and all BitGoJS SDK coins allow developers to use only the coins needed for a given project.

## Installation

All coins are loaded traditionally through the `bitgo` package. If you are using coins individually, you will be accessing the coin via the `@bitgo/sdk-api` package.

In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-inj`.

```shell
npm i @bitgo/sdk-api @bitgo/sdk-coin-inj
```

Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`.

```javascript
import { BitGoAPI } from '@bitgo/sdk-api';
import { Inj } from '@bitgo/sdk-coin-inj';

const sdk = new BitGoAPI();

sdk.register('inj', Inj.createInstance);
```

## Development

Most of the coin implementations are derived from `@bitgo/sdk-core`, `@bitgo/statics`, and coin specific packages. These implementations are used to interact with the BitGo API and BitGo platform services.

You will notice that the basic version of common class extensions have been provided to you and must be resolved before the package build will succeed. Upon initiation of a given SDK coin, you will need to verify that your coin has been included in the root `tsconfig.packages.json` and that the linting, formatting, and testing succeeds when run both within the coin and from the root of BitGoJS.

Official Website link - https://docs.injective.network/
Developer Portal link - https://docs.injective.network/develop/guides/
56 changes: 56 additions & 0 deletions modules/sdk-coin-inj/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@bitgo/sdk-coin-inj",
"version": "1.0.0",
"description": "BitGo SDK coin library for Injective",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "yarn tsc --build --incremental --verbose .",
"fmt": "prettier --write .",
"check-fmt": "prettier --check .",
"clean": "rm -r ./dist",
"lint": "eslint --quiet .",
"prepare": "npm run build",
"test": "npm run coverage",
"coverage": "nyc -- npm run unit-test",
"unit-test": "mocha"
},
"author": "BitGo SDK Team <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=14 <17"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-inj"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/abstract-cosmos": "^1.1.0",
"@bitgo/sdk-core": "^8.7.0",
"@bitgo/statics": "^16.1.0",
"@cosmjs/amino": "^0.29.5",
"@cosmjs/encoding": "^0.29.5",
"@cosmjs/stargate": "^0.29.5",
"bignumber.js": "^9.1.1"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.10.5",
"@bitgo/sdk-test": "^1.2.23",
"@types/lodash": "^4.14.183"
}
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-inj/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './inj';
export * from './lib';
export * from './register';
export * from './tinj';
38 changes: 38 additions & 0 deletions modules/sdk-coin-inj/src/inj.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CosmosCoin } from '@bitgo/abstract-cosmos';
import { BaseCoin, BitGoBase, Environments } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';

import { TransactionBuilderFactory } from './lib';
import utils from './lib/utils';

export class Inj extends CosmosCoin {
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo, staticsCoin);

if (!staticsCoin) {
throw new Error('missing required constructor parameter staticsCoin');
}

this._staticsCoin = staticsCoin;
}

static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
return new Inj(bitgo, staticsCoin);
}

/** @inheritDoc **/
getBuilder(): TransactionBuilderFactory {
return new TransactionBuilderFactory(coins.get(this.getChain()));
}

/** @inheritDoc **/
isValidAddress(address: string): boolean {
return utils.isValidAddress(address) || utils.isValidValidatorAddress(address);
}

/** @inheritDoc **/
protected getPublicNodeUrl(): string {
return Environments[this.bitgo.getEnv()].injNodeUrl;
}
}
3 changes: 3 additions & 0 deletions modules/sdk-coin-inj/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const validDenoms = ['ninj', 'uinj', 'minj', 'inj'];
export const accountAddressRegex = /^(inj)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
export const validatorAddressRegex = /^(injvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
10 changes: 10 additions & 0 deletions modules/sdk-coin-inj/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Constants from './constants';
import * as Utils from './utils';

export {
CosmosTransaction as Transaction,
CosmosTransactionBuilder as TransactionBuilder,
} from '@bitgo/abstract-cosmos';
export { KeyPair } from './keyPair';
export { TransactionBuilderFactory } from './transactionBuilderFactory';
export { Constants, Utils };
25 changes: 25 additions & 0 deletions modules/sdk-coin-inj/src/lib/keyPair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { KeyPairOptions } from '@bitgo/sdk-core';
import { pubkeyToAddress } from '@cosmjs/amino';

import { CosmosKeyPair } from '@bitgo/abstract-cosmos';

/**
* Injective keys and address management.
*/
export class KeyPair extends CosmosKeyPair {
constructor(source?: KeyPairOptions) {
super(source);
}

/** @inheritdoc */
getAddress(): string {
const base64String = Buffer.from(this.getKeys().pub.slice(0, 66), 'hex').toString('base64');
return pubkeyToAddress(
{
type: 'tendermint/PubKeySecp256k1',
value: base64String,
},
'inj'
);
}
}
Loading

0 comments on commit d5fe470

Please sign in to comment.