Skip to content

Commit

Permalink
Merge pull request #3631 from BitGo/BG-78116-sdk-celestia-addition
Browse files Browse the repository at this point in the history
feat(sdk-coin-tia): celestia sdk along with testcases
  • Loading branch information
DinshawKothari authored Jun 13, 2023
2 parents 5276d3e + eb1431a commit e2c7872
Show file tree
Hide file tree
Showing 44 changed files with 1,991 additions and 17 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-osmo /var/modules/sdk-coin-osmo/
RUN cd /var/modules/sdk-coin-osmo && yarn link
COPY --from=builder /tmp/bitgo/modules/abstract-cosmos /var/modules/abstract-cosmos/
RUN cd /var/modules/abstract-cosmos && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-tia /var/modules/sdk-coin-tia/
RUN cd /var/modules/sdk-coin-tia && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xlm /var/modules/sdk-coin-xlm/
RUN cd /var/modules/sdk-coin-xlm && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xrp /var/modules/sdk-coin-xrp/
Expand Down Expand Up @@ -195,15 +197,16 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-ltc && \
yarn link @bitgo/sdk-coin-osmo && \
yarn link @bitgo/abstract-cosmos && \
yarn link @bitgo/sdk-coin-tia && \
yarn link @bitgo/sdk-coin-xlm && \
yarn link @bitgo/sdk-coin-xrp && \
yarn link @bitgo/sdk-coin-zec
#LINK_END

#LABEL_START
LABEL created="Mon, 05 Jun 2023 16:57:03 GMT"
LABEL created="Tue, 06 Jun 2023 10:54:43 GMT"
LABEL version=9.27.0
LABEL git_hash=9efc360c50ab1809e58cb5b0024850f14d62943a
LABEL git_hash=82d33792e150f3ad67bda641c6c12f5e4d7322e0
#LABEL_END

USER node
Expand Down
1 change: 0 additions & 1 deletion modules/abstract-cosmos/src/cosmosCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export class CosmosCoin extends BaseCoin {
/** @inheritDoc **/
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
let totalAmount = new BigNumber(0);
// const coinConfig = coins.get(this.getChain());
const { txPrebuild, txParams } = params;
const rawTx = txPrebuild.txHex;
if (!rawTx) {
Expand Down
4 changes: 2 additions & 2 deletions modules/abstract-cosmos/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ export class CosmosUtils implements BaseUtils {

/**
* Returns whether or not the string is a valid protocol public key
* @param {string} publicKey - the public key to be validated
* @param {string | undefined} publicKey - the public key to be validated
*/
validatePublicKey(publicKey: string | undefined) {
if (publicKey !== undefined) {
try {
new KeyPair({ pub: publicKey });
} catch {
throw new InvalidTransactionError(`Key validation failed`);
throw new InvalidTransactionError(`Invalid Public Key`);
}
}
}
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 @@ -46,6 +46,7 @@
"@bitgo/sdk-coin-sol": "^2.5.1",
"@bitgo/sdk-coin-stx": "^2.0.7",
"@bitgo/sdk-coin-sui": "^3.0.7",
"@bitgo/sdk-coin-tia": "^1.0.0",
"@bitgo/sdk-coin-trx": "^1.8.0",
"@bitgo/sdk-coin-xtz": "^1.4.23",
"@bitgo/sdk-core": "^8.7.0",
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 @@ -71,6 +71,9 @@ export { Osmo };
import { AvaxpLib as AvaxP } from '@bitgo/sdk-coin-avaxp';
export { AvaxP };

import * as Tia from '@bitgo/sdk-coin-tia';
export { Tia };

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

Expand Down Expand Up @@ -126,6 +129,8 @@ const coinBuilderMap = {
tpolygon: Polygon.TransactionBuilder,
sui: Sui.TransactionBuilderFactory,
tsui: Sui.TransactionBuilderFactory,
tia: Tia.TransactionBuilderFactory,
ttia: Tia.TransactionBuilderFactory,
atom: Atom.TransactionBuilderFactory,
tatom: Atom.TransactionBuilderFactory,
osmo: Osmo.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 @@ -61,6 +61,9 @@
{
"path": "../sdk-coin-stx"
},
{
"path": "../sdk-coin-tia"
},
{
"path": "../sdk-coin-trx"
},
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@bitgo/sdk-coin-sol": "^2.5.1",
"@bitgo/sdk-coin-stx": "^2.0.7",
"@bitgo/sdk-coin-sui": "^3.0.7",
"@bitgo/sdk-coin-tia": "^1.0.0",
"@bitgo/sdk-coin-trx": "^1.8.0",
"@bitgo/sdk-coin-xlm": "^2.0.9",
"@bitgo/sdk-coin-xrp": "^1.5.2",
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 @@ -47,6 +47,7 @@ import {
Stx,
Sui,
Susd,
Tia,
Talgo,
TavaxC,
Tada,
Expand Down Expand Up @@ -74,6 +75,7 @@ import {
Tpolygon,
Trbtc,
Trx,
Ttia,
Tsol,
Tstx,
Tsui,
Expand Down Expand Up @@ -132,6 +134,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('stx', Stx.createInstance);
globalCoinFactory.register('sui', Sui.createInstance);
globalCoinFactory.register('susd', Susd.createInstance);
globalCoinFactory.register('tia', Tia.createInstance);
globalCoinFactory.register('talgo', Talgo.createInstance);
globalCoinFactory.register('tada', Tada.createInstance);
globalCoinFactory.register('tatom', Tatom.createInstance);
Expand Down Expand Up @@ -165,6 +168,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('tstx', Tstx.createInstance);
globalCoinFactory.register('tsui', Tsui.createInstance);
globalCoinFactory.register('tsusd', Tsusd.createInstance);
globalCoinFactory.register('ttia', Ttia.createInstance);
globalCoinFactory.register('ttrx', Ttrx.createInstance);
globalCoinFactory.register('txlm', Txlm.createInstance);
globalCoinFactory.register('txrp', Txrp.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 @@ -58,6 +58,8 @@ import { Stx, Tstx } from '@bitgo/sdk-coin-stx';
export { Stx, Tstx };
import { Sui, Tsui } from '@bitgo/sdk-coin-sui';
export { Sui, Tsui };
import { Tia, Ttia } from '@bitgo/sdk-coin-tia';
export { Tia, Ttia };
import { Trx, Ttrx } from '@bitgo/sdk-coin-trx';
export { Trx, Ttrx };
import { StellarToken, Txlm, Xlm } from '@bitgo/sdk-coin-xlm';
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
{
"path": "../sdk-coin-sui"
},
{
"path": "../sdk-coin-tia"
},
{
"path": "../sdk-coin-trx"
},
Expand Down
4 changes: 1 addition & 3 deletions modules/sdk-coin-osmo/test/integration/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import 'should';

import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';

import { Osmo, Tosmo } from '../../src/index';

describe('OSMO', function () {
let bitgo: TestBitGoAPI;
// let basecoin;
before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' });
bitgo.safeRegister('osmo', Osmo.createInstance);
bitgo.safeRegister('tosmo', Tosmo.createInstance);
bitgo.initializeTestVars();
// basecoin = bitgo.coin('tosmo');
});
});
6 changes: 3 additions & 3 deletions modules/sdk-coin-osmo/test/unit/osmo.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { BitGoAPI } from '@bitgo/sdk-api';
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import BigNumber from 'bignumber.js';
import should = require('should');
import sinon from 'sinon';
import { Osmo, Tosmo } from '../../src';
import utils from '../../src/lib/utils';
import {
address,
TEST_DELEGATE_TX,
TEST_SEND_TX,
TEST_TX_WITH_MEMO,
TEST_UNDELEGATE_TX,
TEST_WITHDRAW_REWARDS_TX,
TEST_TX_WITH_MEMO,
address,
} from '../resources/osmo';
import should = require('should');

describe('OSMO', function () {
let bitgo: TestBitGoAPI;
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-tia/.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-tia/.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-tia/.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-tia/.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-tia/.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-tia/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printWidth: 120
singleQuote: true
trailingComma: 'es5'
30 changes: 30 additions & 0 deletions modules/sdk-coin-tia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-tia

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-tia`.

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

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 { Tia } from '@bitgo/sdk-coin-tia';

const sdk = new BitGoAPI();

sdk.register('tia', Tia.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.
56 changes: 56 additions & 0 deletions modules/sdk-coin-tia/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@bitgo/sdk-coin-tia",
"version": "1.0.0",
"description": "BitGo SDK coin library for Celestia",
"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-tia"
},
"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-tia/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib';
export * from './tia';
export * from './ttia';
export * from './register';
3 changes: 3 additions & 0 deletions modules/sdk-coin-tia/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const validDenoms = ['ntia', 'utia', 'mtia', 'tia'];
export const accountAddressRegex = /^(celestia)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
export const validatorAddressRegex = /^(celestiavaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']+)$/;
10 changes: 10 additions & 0 deletions modules/sdk-coin-tia/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-tia/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';

/**
* Celestia 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,
},
'celestia'
);
}
}
Loading

0 comments on commit e2c7872

Please sign in to comment.