Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
Gteth,
Hash,
Hbar,
Hemi,
Hteth,
Icp,
Initia,
Expand Down Expand Up @@ -179,6 +180,7 @@ import {
TfiatUsd,
Thash,
Thbar,
Themi,
Tia,
Ticp,
Tinitia,
Expand Down Expand Up @@ -285,6 +287,7 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
coinFactory.register('gteth', Gteth.createInstance);
coinFactory.register('hash', Hash.createInstance);
coinFactory.register('hbar', Hbar.createInstance);
coinFactory.register('hemi', Hemi.createInstance);
coinFactory.register('hteth', Hteth.createInstance);
coinFactory.register('lnbtc', Lnbtc.createInstance);
coinFactory.register('ltc', Ltc.createInstance);
Expand Down Expand Up @@ -357,6 +360,7 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
coinFactory.register('tmon', Tmon.createInstance);
coinFactory.register('thash', Thash.createInstance);
coinFactory.register('thbar', Thbar.createInstance);
coinFactory.register('themi', Themi.createInstance);
coinFactory.register('ticp', Ticp.createInstance);
coinFactory.register('tinitia', Tinitia.createInstance);
coinFactory.register('tinjective', Tinjective.createInstance);
Expand Down Expand Up @@ -715,6 +719,8 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine
return Hash.createInstance;
case 'hbar':
return Hbar.createInstance;
case 'hemi':
return Hemi.createInstance;
case 'hteth':
return Hteth.createInstance;
case 'lnbtc':
Expand Down Expand Up @@ -859,6 +865,8 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine
return Thash.createInstance;
case 'thbar':
return Thbar.createInstance;
case 'themi':
return Themi.createInstance;
case 'ticp':
return Ticp.createInstance;
case 'tinitia':
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 @@ -38,6 +38,7 @@ import { Ethw } from '@bitgo/sdk-coin-ethw';
import { EthLikeCoin, TethLikeCoin } from '@bitgo/sdk-coin-ethlike';
import { Hash, Thash, HashToken } from '@bitgo/sdk-coin-hash';
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
import { Hemi, Themi } from '@bitgo/sdk-coin-hemi';
import { Icp, Ticp } from '@bitgo/sdk-coin-icp';
import { Initia, Tinitia } from '@bitgo/sdk-coin-initia';
import { Injective, Tinjective } from '@bitgo/sdk-coin-injective';
Expand Down Expand Up @@ -115,6 +116,7 @@ export { Flr, Tflr, FlrToken };
export { Flrp };
export { Hash, Thash, HashToken };
export { Hbar, Thbar };
export { Hemi, Themi };
export { Icp, Ticp };
export { Initia, Tinitia };
export { Iota };
Expand Down
2 changes: 2 additions & 0 deletions modules/sdk-coin-hemi/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions modules/sdk-coin-hemi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist
/node_modules
/.nyc_output
8 changes: 8 additions & 0 deletions modules/sdk-coin-hemi/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require: 'tsx'
timeout: '120000'
reporter: 'min'
reporter-option:
- 'cdn=true'
- 'json=false'
exit: true
spec: ['test/unit/**/*.ts']
10 changes: 10 additions & 0 deletions modules/sdk-coin-hemi/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/*.ts
!**/*.d.ts
src
test
tsconfig.json
tslint.json
.gitignore
.eslintignore
.mocharc.yml
.prettierignore
2 changes: 2 additions & 0 deletions modules/sdk-coin-hemi/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions modules/sdk-coin-hemi/.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-hemi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-hemi

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

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

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

const sdk = new BitGoAPI();

sdk.register('hemi', Hemi.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.
Binary file not shown.
56 changes: 56 additions & 0 deletions modules/sdk-coin-hemi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@bitgo/sdk-coin-hemi",
"version": "1.0.0",
"description": "BitGo SDK coin library for Hemi Network",
"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 '**/*.{ts,js,json}'",
"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 <sdkteam@bitgo.com>",
"license": "MIT",
"engines": {
"node": ">=20 <25"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-hemi"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/sdk-core": "^36.30.0",
"@bitgo/statics": "^58.24.0",
"bignumber.js": "^9.1.1",
"@bitgo/sdk-lib-mpc": "^10.9.0",
"@bitgo/abstract-eth": "^24.20.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.73.4",
"@bitgo/sdk-test": "^9.1.25"
},
"files": [
"dist"
]
}
65 changes: 65 additions & 0 deletions modules/sdk-coin-hemi/src/hemi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @prettier
*/
import { BaseCoin, BitGoBase, MPCAlgorithm, MultisigType, multisigTypes } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins, ethGasConfigs } from '@bitgo/statics';
import { AbstractEthLikeNewCoins, TransactionBuilder as EthLikeTransactionBuilder } from '@bitgo/abstract-eth';

import { TransactionBuilder } from './lib';

export class Hemi extends AbstractEthLikeNewCoins {
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo, staticsCoin);
}

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

protected getTransactionBuilder(): EthLikeTransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}

/** @inheritDoc */
supportsTss(): boolean {
return true;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}

/** @inheritDoc */
supportsMessageSigning(): boolean {
return true;
}

/** @inheritDoc */
supportsSigningTypedData(): boolean {
return true;
}

/**
* Check whether gas limit passed in by user are within our max and min bounds
* If they are not set, set them to the defaults
* @param {number} userGasLimit user defined gas limit
* @returns {number} the gas limit to use for this transaction
*/
setGasLimit(userGasLimit?: number): number {
if (!userGasLimit) {
return ethGasConfigs.defaultGasLimit;
}
const gasLimitMax = ethGasConfigs.maximumGasLimit;
const gasLimitMin = ethGasConfigs.newEthLikeCoinsMinGasLimit;
if (userGasLimit < gasLimitMin || userGasLimit > gasLimitMax) {
throw new Error(`Gas limit must be between ${gasLimitMin} and ${gasLimitMax}`);
}
return userGasLimit;
}

/** @inheritDoc */
getDefaultMultisigType(): MultisigType {
return multisigTypes.tss;
}
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-hemi/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { Hemi } from './hemi';
export { Themi } from './themi';
export { register } from './register';
export * from './lib';
4 changes: 4 additions & 0 deletions modules/sdk-coin-hemi/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { TransactionBuilder } from './transactionBuilder';
export { TransferBuilder } from './transferBuilder';
export { getCommon } from './utils';
export * from './walletUtil';
28 changes: 28 additions & 0 deletions modules/sdk-coin-hemi/src/lib/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import EthereumCommon from '@ethereumjs/common';
import { coins, EthereumNetwork } from '@bitgo/statics';

export const testnetCommon = EthereumCommon.custom(
{
name: 'hemi sepolia',
networkId: (coins.get('themi').network as EthereumNetwork).chainId,
chainId: (coins.get('themi').network as EthereumNetwork).chainId,
},
{
baseChain: 'sepolia',
hardfork: 'london',
eips: [1559],
}
);

export const mainnetCommon = EthereumCommon.custom(
{
name: 'hemi',
networkId: (coins.get('hemi').network as EthereumNetwork).chainId,
chainId: (coins.get('hemi').network as EthereumNetwork).chainId,
},
{
baseChain: 'mainnet',
hardfork: 'london',
eips: [1559],
}
);
33 changes: 33 additions & 0 deletions modules/sdk-coin-hemi/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core';
import { KeyPair, Transaction, TransactionBuilder as EthLikeTransactionBuilder } from '@bitgo/abstract-eth';

import { getCommon } from './utils';
import { TransferBuilder } from './transferBuilder';
import { walletSimpleByteCode } from './walletUtil';

export class TransactionBuilder extends EthLikeTransactionBuilder {
protected _transfer!: TransferBuilder;

constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
this._common = getCommon(this._coinConfig.network.type);
this.transaction = new Transaction(this._coinConfig, this._common);
this._walletSimpleByteCode = walletSimpleByteCode;
}

/** @inheritdoc */
transfer(data?: string): TransferBuilder {
if (this._type !== TransactionType.Send) {
throw new BuildTransactionError('Transfers can only be set for send transactions');
}
if (!this._transfer) {
this._transfer = new TransferBuilder(data);
}
return this._transfer;
}

publicKey(key: string): void {
this._sourceKeyPair = new KeyPair({ pub: key });
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-hemi/src/lib/transferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TransferBuilder } from '@bitgo/abstract-eth';
21 changes: 21 additions & 0 deletions modules/sdk-coin-hemi/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NetworkType } from '@bitgo/statics';
import EthereumCommon from '@ethereumjs/common';
import { InvalidTransactionError } from '@bitgo/sdk-core';
import { testnetCommon, mainnetCommon } from './resources';

const commons: Map<NetworkType, EthereumCommon> = new Map<NetworkType, EthereumCommon>([
[NetworkType.MAINNET, mainnetCommon],
[NetworkType.TESTNET, testnetCommon],
]);

/**
* @param {NetworkType} network either mainnet or testnet
* @returns {EthereumCommon} Ethereum common configuration object
*/
export function getCommon(network: NetworkType): EthereumCommon {
const common = commons.get(network);
if (!common) {
throw new InvalidTransactionError('Missing network common configuration');
}
return common;
}
612 changes: 612 additions & 0 deletions modules/sdk-coin-hemi/src/lib/walletUtil.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions modules/sdk-coin-hemi/src/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { Hemi } from './hemi';
import { Themi } from './themi';

export const register = (sdk: BitGoBase): void => {
sdk.register('hemi', Hemi.createInstance);
sdk.register('themi', Themi.createInstance);
};
17 changes: 17 additions & 0 deletions modules/sdk-coin-hemi/src/themi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Testnet Hemi
*/
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';

import { Hemi } from './hemi';

export class Themi extends Hemi {
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo, staticsCoin);
}

static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
return new Themi(bitgo, staticsCoin);
}
}
11 changes: 11 additions & 0 deletions modules/sdk-coin-hemi/test/integration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Integration tests for Hemi Network
*
* These tests require a running Hemi Network node or testnet connection
* and are typically run separately from unit tests.
*
* TODO: Add integration tests
*/

// Placeholder to ensure test file loads correctly
export {};
Loading
Loading