Skip to content

Commit

Permalink
feat(sdk-coin-lnbtc): add new sdk coin lnbtc module
Browse files Browse the repository at this point in the history
sdk coin lnbtc module

Ticket: BTC-1258
  • Loading branch information
saravanan7mani committed Jun 21, 2024
1 parent fde27b2 commit c05e7e1
Show file tree
Hide file tree
Showing 28 changed files with 403 additions and 14 deletions.
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ COPY --from=builder /tmp/bitgo/modules/utxo-lib /var/modules/utxo-lib/
COPY --from=builder /tmp/bitgo/modules/blake2b /var/modules/blake2b/
COPY --from=builder /tmp/bitgo/modules/blake2b-wasm /var/modules/blake2b-wasm/
COPY --from=builder /tmp/bitgo/modules/bitgo /var/modules/bitgo/
COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
COPY --from=builder /tmp/bitgo/modules/abstract-lightning /var/modules/abstract-lightning/
COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
COPY --from=builder /tmp/bitgo/modules/blockapis /var/modules/blockapis/
COPY --from=builder /tmp/bitgo/modules/sdk-api /var/modules/sdk-api/
COPY --from=builder /tmp/bitgo/modules/unspents /var/modules/unspents/
Expand Down Expand Up @@ -101,6 +101,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-doge /var/modules/sdk-coin-doge/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-eos /var/modules/sdk-coin-eos/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ethlike /var/modules/sdk-coin-ethlike/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ethw /var/modules/sdk-coin-ethw/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-lnbtc /var/modules/sdk-coin-lnbtc/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ltc /var/modules/sdk-coin-ltc/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xlm /var/modules/sdk-coin-xlm/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xrp /var/modules/sdk-coin-xrp/
Expand All @@ -115,8 +116,8 @@ cd /var/modules/utxo-lib && yarn link && \
cd /var/modules/blake2b && yarn link && \
cd /var/modules/blake2b-wasm && yarn link && \
cd /var/modules/bitgo && yarn link && \
cd /var/modules/abstract-utxo && yarn link && \
cd /var/modules/abstract-lightning && yarn link && \
cd /var/modules/abstract-utxo && yarn link && \
cd /var/modules/blockapis && yarn link && \
cd /var/modules/sdk-api && yarn link && \
cd /var/modules/unspents && yarn link && \
Expand Down Expand Up @@ -169,6 +170,7 @@ cd /var/modules/sdk-coin-doge && yarn link && \
cd /var/modules/sdk-coin-eos && yarn link && \
cd /var/modules/sdk-coin-ethlike && yarn link && \
cd /var/modules/sdk-coin-ethw && yarn link && \
cd /var/modules/sdk-coin-lnbtc && yarn link && \
cd /var/modules/sdk-coin-ltc && yarn link && \
cd /var/modules/sdk-coin-xlm && yarn link && \
cd /var/modules/sdk-coin-xrp && yarn link && \
Expand All @@ -186,8 +188,8 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/blake2b && \
yarn link @bitgo/blake2b-wasm && \
yarn link bitgo && \
yarn link @bitgo/abstract-utxo && \
yarn link @bitgo/abstract-lightning && \
yarn link @bitgo/abstract-utxo && \
yarn link @bitgo/blockapis && \
yarn link @bitgo/sdk-api && \
yarn link @bitgo/unspents && \
Expand Down Expand Up @@ -240,16 +242,17 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-eos && \
yarn link @bitgo/sdk-coin-ethlike && \
yarn link @bitgo/sdk-coin-ethw && \
yarn link @bitgo/sdk-coin-lnbtc && \
yarn link @bitgo/sdk-coin-ltc && \
yarn link @bitgo/sdk-coin-xlm && \
yarn link @bitgo/sdk-coin-xrp && \
yarn link @bitgo/sdk-coin-zec
#LINK_END

#LABEL_START
LABEL created="Thu, 20 Jun 2024 08:36:08 GMT"
LABEL created="Fri, 21 Jun 2024 09:29:22 GMT"
LABEL version=10.0.1
LABEL git_hash=43ca8bc9facbe84d6dbf8cd6dc25da59a35aaf03
LABEL git_hash=fde27b27726a42da00e57f4afaece82460737eec
#LABEL_END

USER node
Expand Down
3 changes: 2 additions & 1 deletion modules/abstract-lightning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
]
},
"dependencies": {
"@bitgo/sdk-core": "^27.1.0"
"@bitgo/sdk-core": "^27.1.0",
"@bitgo/utxo-lib": "^9.38.0"
}
}
5 changes: 4 additions & 1 deletion modules/abstract-lightning/src/abstractLightningCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import {
VerifyAddressOptions,
VerifyTransactionOptions,
} from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

export abstract class AbstractLightningCoin extends BaseCoin {
protected constructor(bitgo: BitGoBase) {
private readonly _network: utxolib.Network;
protected constructor(bitgo: BitGoBase, network: utxolib.Network) {
super(bitgo);
this._network = network;
}

getBaseFactor(): number {
Expand Down
3 changes: 2 additions & 1 deletion modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"gen-docs": "typedoc"
},
"dependencies": {
"@bitgo/abstract-utxo": "^8.7.0",
"@bitgo/abstract-lightning": "^1.0.0",
"@bitgo/abstract-utxo": "^8.7.0",
"@bitgo/account-lib": "^23.0.19",
"@bitgo/blockapis": "^1.9.5",
"@bitgo/sdk-api": "^1.49.0",
Expand Down Expand Up @@ -79,6 +79,7 @@
"@bitgo/sdk-coin-hbar": "^2.0.19",
"@bitgo/sdk-coin-injective": "^2.0.19",
"@bitgo/sdk-coin-islm": "^2.0.19",
"@bitgo/sdk-coin-lnbtc": "^1.0.0",
"@bitgo/sdk-coin-ltc": "^3.0.19",
"@bitgo/sdk-coin-near": "^2.0.19",
"@bitgo/sdk-coin-opeth": "^18.1.4",
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 @@ -125,6 +125,8 @@ import {
Zeta,
Zketh,
ZkethToken,
Lnbtc,
Tlnbtc,
} from './coins';

function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
Expand Down Expand Up @@ -162,6 +164,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('hash', Hash.createInstance);
globalCoinFactory.register('hbar', Hbar.createInstance);
globalCoinFactory.register('hteth', Hteth.createInstance);
globalCoinFactory.register('lnbtc', Lnbtc.createInstance);
globalCoinFactory.register('ltc', Ltc.createInstance);
globalCoinFactory.register('injective', Injective.createInstance);
globalCoinFactory.register('islm', Islm.createInstance);
Expand Down Expand Up @@ -208,6 +211,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('thbar', Thbar.createInstance);
globalCoinFactory.register('tinjective', Tinjective.createInstance);
globalCoinFactory.register('tislm', Tislm.createInstance);
globalCoinFactory.register('tlnbtc', Tlnbtc.createInstance);
globalCoinFactory.register('tltc', Tltc.createInstance);
globalCoinFactory.register('tnear', TNear.createInstance);
globalCoinFactory.register('topeth', Topeth.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 @@ -30,6 +30,7 @@ import { Hash, Thash } from '@bitgo/sdk-coin-hash';
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
import { Injective, Tinjective } from '@bitgo/sdk-coin-injective';
import { Islm, Tislm } from '@bitgo/sdk-coin-islm';
import { Lnbtc, Tlnbtc } from '@bitgo/sdk-coin-lnbtc';
import { Ltc, Tltc } from '@bitgo/sdk-coin-ltc';
import { Opeth, Topeth, OpethToken } from '@bitgo/sdk-coin-opeth';
import { Osmo, Tosmo } from '@bitgo/sdk-coin-osmo';
Expand Down Expand Up @@ -78,6 +79,7 @@ export { EthLikeCoin, TethLikeCoin };
export { Etc, Tetc };
export { Hash, Thash };
export { Hbar, Thbar };
export { Lnbtc, Tlnbtc };
export { Ltc, Tltc };
export { Opeth, Topeth, OpethToken };
export { Osmo, Tosmo };
Expand Down
7 changes: 5 additions & 2 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"path": "../abstract-eth"
},
{
"path": "../abstract-utxo"
"path": "../abstract-lightning"
},
{
"path": "../abstract-lightning"
"path": "../abstract-utxo"
},
{
"path": "../sdk-api"
Expand Down Expand Up @@ -128,6 +128,9 @@
{
"path": "../sdk-coin-islm"
},
{
"path": "../sdk-coin-lnbtc"
},
{
"path": "../sdk-coin-ltc"
},
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-lnbtc/.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-lnbtc/.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-lnbtc/.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-lnbtc/.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-lnbtc/.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-lnbtc/.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-lnbtc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-lnbtc

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

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

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

const sdk = new BitGoAPI();

sdk.register('lnbtc', Lnbtc.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.
51 changes: 51 additions & 0 deletions modules/sdk-coin-lnbtc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@bitgo/sdk-coin-lnbtc",
"version": "1.0.0",
"description": "BitGo SDK coin library for LightningBitcoin",
"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": ">=18 <21"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-lnbtc"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/abstract-lightning": "^1.0.0",
"@bitgo/sdk-core": "^27.1.0",
"@bitgo/utxo-lib": "^9.38.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.49.0",
"@bitgo/sdk-test": "^8.0.24"
}
}
2 changes: 2 additions & 0 deletions modules/sdk-coin-lnbtc/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lnbtc';
export * from './tlnbtc';
25 changes: 25 additions & 0 deletions modules/sdk-coin-lnbtc/src/lnbtc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AbstractLightningCoin } from '@bitgo/abstract-lightning';
import { BitGoBase, BaseCoin } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

export class Lnbtc extends AbstractLightningCoin {
constructor(bitgo: BitGoBase, network?: utxolib.Network) {
super(bitgo, network || utxolib.networks.bitcoin);
}

static createInstance(bitgo: BitGoBase): BaseCoin {
return new Lnbtc(bitgo);
}

getChain(): string {
return 'lnbtc';
}

getFamily(): string {
return 'lnbtc';
}

getFullName(): string {
return 'LightningBitcoin';
}
}
24 changes: 24 additions & 0 deletions modules/sdk-coin-lnbtc/src/tlnbtc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @prettier
*/
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
import { Lnbtc } from './lnbtc';
import * as utxolib from '@bitgo/utxo-lib';

export class Tlnbtc extends Lnbtc {
constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.testnet);
}

static createInstance(bitgo: BitGoBase): BaseCoin {
return new Tlnbtc(bitgo);
}

getChain(): string {
return 'tlnbtc';
}

getFullName(): string {
return 'Testnet LightningBitcoin';
}
}
26 changes: 26 additions & 0 deletions modules/sdk-coin-lnbtc/test/unit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'should';

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

import { Tlnbtc } from '../../src/index';

describe('LightningBitcoin', function () {
let bitgo: TestBitGoAPI;
let basecoin: Tlnbtc;

before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
bitgo.safeRegister('tlnbtc', Tlnbtc.createInstance);
bitgo.initializeTestVars();
basecoin = bitgo.coin('tlnbtc') as Tlnbtc;
});

it('should instantiate the coin', function () {
basecoin.should.be.an.instanceof(Tlnbtc);
});

it('should return full name', function () {
basecoin.getFullName().should.equal('Testnet LightningBitcoin');
});
});
Loading

0 comments on commit c05e7e1

Please sign in to comment.