Skip to content

Commit c05e7e1

Browse files
feat(sdk-coin-lnbtc): add new sdk coin lnbtc module
sdk coin lnbtc module Ticket: BTC-1258
1 parent fde27b2 commit c05e7e1

28 files changed

+403
-14
lines changed

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ COPY --from=builder /tmp/bitgo/modules/utxo-lib /var/modules/utxo-lib/
4747
COPY --from=builder /tmp/bitgo/modules/blake2b /var/modules/blake2b/
4848
COPY --from=builder /tmp/bitgo/modules/blake2b-wasm /var/modules/blake2b-wasm/
4949
COPY --from=builder /tmp/bitgo/modules/bitgo /var/modules/bitgo/
50-
COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
5150
COPY --from=builder /tmp/bitgo/modules/abstract-lightning /var/modules/abstract-lightning/
51+
COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
5252
COPY --from=builder /tmp/bitgo/modules/blockapis /var/modules/blockapis/
5353
COPY --from=builder /tmp/bitgo/modules/sdk-api /var/modules/sdk-api/
5454
COPY --from=builder /tmp/bitgo/modules/unspents /var/modules/unspents/
@@ -101,6 +101,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-doge /var/modules/sdk-coin-doge/
101101
COPY --from=builder /tmp/bitgo/modules/sdk-coin-eos /var/modules/sdk-coin-eos/
102102
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ethlike /var/modules/sdk-coin-ethlike/
103103
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ethw /var/modules/sdk-coin-ethw/
104+
COPY --from=builder /tmp/bitgo/modules/sdk-coin-lnbtc /var/modules/sdk-coin-lnbtc/
104105
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ltc /var/modules/sdk-coin-ltc/
105106
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xlm /var/modules/sdk-coin-xlm/
106107
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xrp /var/modules/sdk-coin-xrp/
@@ -115,8 +116,8 @@ cd /var/modules/utxo-lib && yarn link && \
115116
cd /var/modules/blake2b && yarn link && \
116117
cd /var/modules/blake2b-wasm && yarn link && \
117118
cd /var/modules/bitgo && yarn link && \
118-
cd /var/modules/abstract-utxo && yarn link && \
119119
cd /var/modules/abstract-lightning && yarn link && \
120+
cd /var/modules/abstract-utxo && yarn link && \
120121
cd /var/modules/blockapis && yarn link && \
121122
cd /var/modules/sdk-api && yarn link && \
122123
cd /var/modules/unspents && yarn link && \
@@ -169,6 +170,7 @@ cd /var/modules/sdk-coin-doge && yarn link && \
169170
cd /var/modules/sdk-coin-eos && yarn link && \
170171
cd /var/modules/sdk-coin-ethlike && yarn link && \
171172
cd /var/modules/sdk-coin-ethw && yarn link && \
173+
cd /var/modules/sdk-coin-lnbtc && yarn link && \
172174
cd /var/modules/sdk-coin-ltc && yarn link && \
173175
cd /var/modules/sdk-coin-xlm && yarn link && \
174176
cd /var/modules/sdk-coin-xrp && yarn link && \
@@ -186,8 +188,8 @@ RUN cd /var/bitgo-express && \
186188
yarn link @bitgo/blake2b && \
187189
yarn link @bitgo/blake2b-wasm && \
188190
yarn link bitgo && \
189-
yarn link @bitgo/abstract-utxo && \
190191
yarn link @bitgo/abstract-lightning && \
192+
yarn link @bitgo/abstract-utxo && \
191193
yarn link @bitgo/blockapis && \
192194
yarn link @bitgo/sdk-api && \
193195
yarn link @bitgo/unspents && \
@@ -240,16 +242,17 @@ RUN cd /var/bitgo-express && \
240242
yarn link @bitgo/sdk-coin-eos && \
241243
yarn link @bitgo/sdk-coin-ethlike && \
242244
yarn link @bitgo/sdk-coin-ethw && \
245+
yarn link @bitgo/sdk-coin-lnbtc && \
243246
yarn link @bitgo/sdk-coin-ltc && \
244247
yarn link @bitgo/sdk-coin-xlm && \
245248
yarn link @bitgo/sdk-coin-xrp && \
246249
yarn link @bitgo/sdk-coin-zec
247250
#LINK_END
248251

249252
#LABEL_START
250-
LABEL created="Thu, 20 Jun 2024 08:36:08 GMT"
253+
LABEL created="Fri, 21 Jun 2024 09:29:22 GMT"
251254
LABEL version=10.0.1
252-
LABEL git_hash=43ca8bc9facbe84d6dbf8cd6dc25da59a35aaf03
255+
LABEL git_hash=fde27b27726a42da00e57f4afaece82460737eec
253256
#LABEL_END
254257

255258
USER node

modules/abstract-lightning/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
]
3838
},
3939
"dependencies": {
40-
"@bitgo/sdk-core": "^27.1.0"
40+
"@bitgo/sdk-core": "^27.1.0",
41+
"@bitgo/utxo-lib": "^9.38.0"
4142
}
4243
}

modules/abstract-lightning/src/abstractLightningCoin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import {
99
VerifyAddressOptions,
1010
VerifyTransactionOptions,
1111
} from '@bitgo/sdk-core';
12+
import * as utxolib from '@bitgo/utxo-lib';
1213

1314
export abstract class AbstractLightningCoin extends BaseCoin {
14-
protected constructor(bitgo: BitGoBase) {
15+
private readonly _network: utxolib.Network;
16+
protected constructor(bitgo: BitGoBase, network: utxolib.Network) {
1517
super(bitgo);
18+
this._network = network;
1619
}
1720

1821
getBaseFactor(): number {

modules/bitgo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"gen-docs": "typedoc"
4545
},
4646
"dependencies": {
47-
"@bitgo/abstract-utxo": "^8.7.0",
4847
"@bitgo/abstract-lightning": "^1.0.0",
48+
"@bitgo/abstract-utxo": "^8.7.0",
4949
"@bitgo/account-lib": "^23.0.19",
5050
"@bitgo/blockapis": "^1.9.5",
5151
"@bitgo/sdk-api": "^1.49.0",
@@ -79,6 +79,7 @@
7979
"@bitgo/sdk-coin-hbar": "^2.0.19",
8080
"@bitgo/sdk-coin-injective": "^2.0.19",
8181
"@bitgo/sdk-coin-islm": "^2.0.19",
82+
"@bitgo/sdk-coin-lnbtc": "^1.0.0",
8283
"@bitgo/sdk-coin-ltc": "^3.0.19",
8384
"@bitgo/sdk-coin-near": "^2.0.19",
8485
"@bitgo/sdk-coin-opeth": "^18.1.4",

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ import {
125125
Zeta,
126126
Zketh,
127127
ZkethToken,
128+
Lnbtc,
129+
Tlnbtc,
128130
} from './coins';
129131

130132
function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
@@ -162,6 +164,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
162164
globalCoinFactory.register('hash', Hash.createInstance);
163165
globalCoinFactory.register('hbar', Hbar.createInstance);
164166
globalCoinFactory.register('hteth', Hteth.createInstance);
167+
globalCoinFactory.register('lnbtc', Lnbtc.createInstance);
165168
globalCoinFactory.register('ltc', Ltc.createInstance);
166169
globalCoinFactory.register('injective', Injective.createInstance);
167170
globalCoinFactory.register('islm', Islm.createInstance);
@@ -208,6 +211,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
208211
globalCoinFactory.register('thbar', Thbar.createInstance);
209212
globalCoinFactory.register('tinjective', Tinjective.createInstance);
210213
globalCoinFactory.register('tislm', Tislm.createInstance);
214+
globalCoinFactory.register('tlnbtc', Tlnbtc.createInstance);
211215
globalCoinFactory.register('tltc', Tltc.createInstance);
212216
globalCoinFactory.register('tnear', TNear.createInstance);
213217
globalCoinFactory.register('topeth', Topeth.createInstance);

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Hash, Thash } from '@bitgo/sdk-coin-hash';
3030
import { Hbar, Thbar } from '@bitgo/sdk-coin-hbar';
3131
import { Injective, Tinjective } from '@bitgo/sdk-coin-injective';
3232
import { Islm, Tislm } from '@bitgo/sdk-coin-islm';
33+
import { Lnbtc, Tlnbtc } from '@bitgo/sdk-coin-lnbtc';
3334
import { Ltc, Tltc } from '@bitgo/sdk-coin-ltc';
3435
import { Opeth, Topeth, OpethToken } from '@bitgo/sdk-coin-opeth';
3536
import { Osmo, Tosmo } from '@bitgo/sdk-coin-osmo';
@@ -78,6 +79,7 @@ export { EthLikeCoin, TethLikeCoin };
7879
export { Etc, Tetc };
7980
export { Hash, Thash };
8081
export { Hbar, Thbar };
82+
export { Lnbtc, Tlnbtc };
8183
export { Ltc, Tltc };
8284
export { Opeth, Topeth, OpethToken };
8385
export { Osmo, Tosmo };

modules/bitgo/tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
"path": "../abstract-eth"
3131
},
3232
{
33-
"path": "../abstract-utxo"
33+
"path": "../abstract-lightning"
3434
},
3535
{
36-
"path": "../abstract-lightning"
36+
"path": "../abstract-utxo"
3737
},
3838
{
3939
"path": "../sdk-api"
@@ -128,6 +128,9 @@
128128
{
129129
"path": "../sdk-coin-islm"
130130
},
131+
{
132+
"path": "../sdk-coin-lnbtc"
133+
},
131134
{
132135
"path": "../sdk-coin-ltc"
133136
},

modules/sdk-coin-lnbtc/.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.idea
3+
public
4+
dist
5+

modules/sdk-coin-lnbtc/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.idea/
3+
dist/

modules/sdk-coin-lnbtc/.mocharc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require: 'ts-node/register'
2+
timeout: '60000'
3+
reporter: 'min'
4+
reporter-option:
5+
- 'cdn=true'
6+
- 'json=false'
7+
exit: true
8+
spec: ['test/unit/**/*.ts']

modules/sdk-coin-lnbtc/.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!dist/
2+
dist/test/
3+
dist/tsconfig.tsbuildinfo
4+
.idea/
5+
.prettierrc.yml
6+
tsconfig.json
7+
src/
8+
test/
9+
scripts/
10+
.nyc_output
11+
CODEOWNERS
12+
node_modules/
13+
.prettierignore
14+
.mocharc.js
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.nyc_output/
2+
dist/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
printWidth: 120
2+
singleQuote: true
3+
trailingComma: 'es5'

modules/sdk-coin-lnbtc/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BitGo sdk-coin-lnbtc
2+
3+
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.
4+
5+
## Installation
6+
7+
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.
8+
9+
In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-lnbtc`.
10+
11+
```shell
12+
npm i @bitgo/sdk-api @bitgo/sdk-coin-lnbtc
13+
```
14+
15+
Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`.
16+
17+
```javascript
18+
import { BitGoAPI } from '@bitgo/sdk-api';
19+
import { Lnbtc } from '@bitgo/sdk-coin-lnbtc';
20+
21+
const sdk = new BitGoAPI();
22+
23+
sdk.register('lnbtc', Lnbtc.createInstance);
24+
```
25+
26+
## Development
27+
28+
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.
29+
30+
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.

modules/sdk-coin-lnbtc/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "@bitgo/sdk-coin-lnbtc",
3+
"version": "1.0.0",
4+
"description": "BitGo SDK coin library for LightningBitcoin",
5+
"main": "./dist/src/index.js",
6+
"types": "./dist/src/index.d.ts",
7+
"scripts": {
8+
"build": "yarn tsc --build --incremental --verbose .",
9+
"fmt": "prettier --write .",
10+
"check-fmt": "prettier --check .",
11+
"clean": "rm -r ./dist",
12+
"lint": "eslint --quiet .",
13+
"prepare": "npm run build",
14+
"test": "npm run coverage",
15+
"coverage": "nyc -- npm run unit-test",
16+
"unit-test": "mocha"
17+
},
18+
"author": "BitGo SDK Team <[email protected]>",
19+
"license": "MIT",
20+
"engines": {
21+
"node": ">=18 <21"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/BitGo/BitGoJS.git",
26+
"directory": "modules/sdk-coin-lnbtc"
27+
},
28+
"lint-staged": {
29+
"*.{js,ts}": [
30+
"yarn prettier --write",
31+
"yarn eslint --fix"
32+
]
33+
},
34+
"publishConfig": {
35+
"access": "public"
36+
},
37+
"nyc": {
38+
"extension": [
39+
".ts"
40+
]
41+
},
42+
"dependencies": {
43+
"@bitgo/abstract-lightning": "^1.0.0",
44+
"@bitgo/sdk-core": "^27.1.0",
45+
"@bitgo/utxo-lib": "^9.38.0"
46+
},
47+
"devDependencies": {
48+
"@bitgo/sdk-api": "^1.49.0",
49+
"@bitgo/sdk-test": "^8.0.24"
50+
}
51+
}

modules/sdk-coin-lnbtc/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lnbtc';
2+
export * from './tlnbtc';

modules/sdk-coin-lnbtc/src/lnbtc.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { AbstractLightningCoin } from '@bitgo/abstract-lightning';
2+
import { BitGoBase, BaseCoin } from '@bitgo/sdk-core';
3+
import * as utxolib from '@bitgo/utxo-lib';
4+
5+
export class Lnbtc extends AbstractLightningCoin {
6+
constructor(bitgo: BitGoBase, network?: utxolib.Network) {
7+
super(bitgo, network || utxolib.networks.bitcoin);
8+
}
9+
10+
static createInstance(bitgo: BitGoBase): BaseCoin {
11+
return new Lnbtc(bitgo);
12+
}
13+
14+
getChain(): string {
15+
return 'lnbtc';
16+
}
17+
18+
getFamily(): string {
19+
return 'lnbtc';
20+
}
21+
22+
getFullName(): string {
23+
return 'LightningBitcoin';
24+
}
25+
}

modules/sdk-coin-lnbtc/src/tlnbtc.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @prettier
3+
*/
4+
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
5+
import { Lnbtc } from './lnbtc';
6+
import * as utxolib from '@bitgo/utxo-lib';
7+
8+
export class Tlnbtc extends Lnbtc {
9+
constructor(bitgo: BitGoBase) {
10+
super(bitgo, utxolib.networks.testnet);
11+
}
12+
13+
static createInstance(bitgo: BitGoBase): BaseCoin {
14+
return new Tlnbtc(bitgo);
15+
}
16+
17+
getChain(): string {
18+
return 'tlnbtc';
19+
}
20+
21+
getFullName(): string {
22+
return 'Testnet LightningBitcoin';
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'should';
2+
3+
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
4+
import { BitGoAPI } from '@bitgo/sdk-api';
5+
6+
import { Tlnbtc } from '../../src/index';
7+
8+
describe('LightningBitcoin', function () {
9+
let bitgo: TestBitGoAPI;
10+
let basecoin: Tlnbtc;
11+
12+
before(function () {
13+
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
14+
bitgo.safeRegister('tlnbtc', Tlnbtc.createInstance);
15+
bitgo.initializeTestVars();
16+
basecoin = bitgo.coin('tlnbtc') as Tlnbtc;
17+
});
18+
19+
it('should instantiate the coin', function () {
20+
basecoin.should.be.an.instanceof(Tlnbtc);
21+
});
22+
23+
it('should return full name', function () {
24+
basecoin.getFullName().should.equal('Testnet LightningBitcoin');
25+
});
26+
});

0 commit comments

Comments
 (0)