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
2 changes: 1 addition & 1 deletion modules/abstract-utxo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@bitgo/utxo-descriptors": "^1.3.4",
"@bitgo/utxo-lib": "^11.24.1",
"@bitgo/utxo-ord": "^1.32.4",
"@bitgo/wasm-utxo": "^4.21.1",
"@bitgo/wasm-utxo": "^4.27.0",
"@types/lodash": "^4.14.121",
"@types/superagent": "4.1.15",
"bignumber.js": "^9.0.2",
Expand Down
1 change: 1 addition & 0 deletions modules/abstract-utxo/src/impl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * as btg from './btg';
export * as ltc from './ltc';
export * as dash from './dash';
export * as doge from './doge';
export * as pearl from './pearl';
export * as zec from './zec';
2 changes: 2 additions & 0 deletions modules/abstract-utxo/src/impl/pearl/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './pearl';
export * from './tpearl';
21 changes: 21 additions & 0 deletions modules/abstract-utxo/src/impl/pearl/pearl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BitGoBase } from '@bitgo/sdk-core';

import { AbstractUtxoCoin } from '../../abstractUtxoCoin';
import { UtxoCoinName } from '../../names';

/**
* Pearl (Duplex) is a taproot-only UTXO chain, a btcd fork using BIP-340 Schnorr
* signatures and BIP-341 script-path spending with a NUMS internal key.
*
* Unlike the other utxo coins, Pearl has no `@bitgo/utxo-lib` network registration -
* it is served entirely through `@bitgo/wasm-utxo`. No script type override is needed
* here: `supportsAddressType` delegates to `fixedScriptWallet.supportsScriptType`,
* which already reports only p2tr and p2trMusig2 for this coin.
*/
export class Pearl extends AbstractUtxoCoin {
readonly name: UtxoCoinName = 'pearl';

static createInstance(bitgo: BitGoBase): Pearl {
return new Pearl(bitgo);
}
}
13 changes: 13 additions & 0 deletions modules/abstract-utxo/src/impl/pearl/tpearl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BitGoBase } from '@bitgo/sdk-core';

import { UtxoCoinName } from '../../names';

import { Pearl } from './pearl';

export class Tpearl extends Pearl {
readonly name: UtxoCoinName = 'tpearl';

static createInstance(bitgo: BitGoBase): Tpearl {
return new Tpearl(bitgo);
}
}
1 change: 1 addition & 0 deletions modules/abstract-utxo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export * from './impl/btg';
export * from './impl/ltc';
export * from './impl/dash';
export * from './impl/doge';
export * from './impl/pearl';
export * from './impl/zec';
5 changes: 4 additions & 1 deletion modules/abstract-utxo/src/names.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const utxoCoinsMainnet = ['btc', 'bch', 'bcha', 'bsv', 'btg', 'dash', 'doge', 'ltc', 'zec'] as const;
export const utxoCoinsMainnet = ['btc', 'bch', 'bcha', 'bsv', 'btg', 'dash', 'doge', 'ltc', 'pearl', 'zec'] as const;
export const utxoCoinsTestnet = [
'tbtc',
'tbtc4',
Expand All @@ -11,6 +11,7 @@ export const utxoCoinsTestnet = [
'tdash',
'tdoge',
'tltc',
'tpearl',
'tzec',
] as const;

Expand Down Expand Up @@ -62,6 +63,8 @@ function getBaseNameFromMainnet(coinName: UtxoCoinNameMainnet): string {
return 'Dogecoin';
case 'ltc':
return 'Litecoin';
case 'pearl':
return 'Pearl';
case 'zec':
return 'ZCash';
}
Expand Down
85 changes: 85 additions & 0 deletions modules/abstract-utxo/test/unit/impl/pearl/unit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import assert from 'node:assert/strict';

import { BitGoAPI } from '@bitgo/sdk-api';
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import * as utxolib from '@bitgo/utxo-lib';

import { AbstractUtxoCoin } from '../../../../../src/abstractUtxoCoin';
import { Pearl, Tpearl } from '../../../../../src/impl/pearl';

describe('Pearl', function () {
let bitgo: TestBitGoAPI;

/** `bitgo.coin()` is typed as BaseCoin; these are registered as AbstractUtxoCoin */
function getCoin(coinName: 'pearl' | 'tpearl'): AbstractUtxoCoin {
return bitgo.coin(coinName) as unknown as AbstractUtxoCoin;
}

before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, {
env: 'mock',
});
bitgo.initializeTestVars();
bitgo.safeRegister('pearl', Pearl.createInstance);
bitgo.safeRegister('tpearl', Tpearl.createInstance);
});

it('should instantiate the coin', function () {
assert.ok(bitgo.coin('pearl') instanceof Pearl);
assert.ok(bitgo.coin('tpearl') instanceof Tpearl);
});

it('should return the chain', function () {
assert.strictEqual(bitgo.coin('pearl').getChain(), 'pearl');
assert.strictEqual(bitgo.coin('tpearl').getChain(), 'tpearl');
});

it('should return full name', function () {
assert.strictEqual(bitgo.coin('pearl').getFullName(), 'Pearl');
assert.strictEqual(bitgo.coin('tpearl').getFullName(), 'Testnet Pearl');
});

it('should have tpearl as the testnet variant of pearl', function () {
assert.ok(bitgo.coin('tpearl') instanceof Pearl);
});

/**
* Pearl is taproot-only. This is not enforced by an override here - it comes from
* `supportsAddressType` delegating to wasm-utxo, which reports only the taproot
* script types for this coin. Pinned so a regression in either layer is caught.
*/
it('should support only the taproot script types', function () {
for (const coinName of ['pearl', 'tpearl'] as const) {
const coin = getCoin(coinName);
assert.strictEqual(coin.supportsAddressType('p2tr'), true);
assert.strictEqual(coin.supportsAddressType('p2trMusig2'), true);
assert.strictEqual(coin.supportsAddressType('p2sh'), false);
assert.strictEqual(coin.supportsAddressType('p2shP2wsh'), false);
assert.strictEqual(coin.supportsAddressType('p2wsh'), false);
}
});

it('should support only the taproot address chains', function () {
for (const coinName of ['pearl', 'tpearl'] as const) {
const coin = getCoin(coinName);
// 30/31 = p2tr, 40/41 = p2trMusig2
for (const chain of [30, 31, 40, 41]) {
assert.strictEqual(coin.supportsAddressChain(chain), true, `chain ${chain} should be supported`);
}
// 0/1 = p2sh, 10/11 = p2shP2wsh, 20/21 = p2wsh
for (const chain of [0, 1, 10, 11, 20, 21]) {
assert.strictEqual(coin.supportsAddressChain(chain), false, `chain ${chain} should not be supported`);
}
}
});

/**
* Pearl is served through @bitgo/wasm-utxo and is deliberately absent from
* @bitgo/utxo-lib. No other checked-in coin has this profile, so it cannot be
* inferred from an existing coin - assert it explicitly.
*/
it('should have no utxo-lib network registration', function () {
assert.ok(!('pearl' in utxolib.networks));
assert.ok(!('tpearl' in utxolib.networks));
});
});
5 changes: 5 additions & 0 deletions modules/sdk-coin-pearl/.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-pearl/.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-pearl/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require: 'tsx'
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-pearl/.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-pearl/.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-pearl/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printWidth: 120
singleQuote: true
trailingComma: 'es5'
32 changes: 32 additions & 0 deletions modules/sdk-coin-pearl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# BitGo sdk-coin-pearl

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.

Pearl (Duplex) is a taproot-only UTXO chain — a btcd fork using BIP-340 Schnorr signatures and BIP-341 script-path spending. It is served through `@bitgo/wasm-utxo` and, unlike the other UTXO coins, has no `@bitgo/utxo-lib` network registration.

## 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-pearl`.

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

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

const sdk = new BitGoAPI();

sdk.register('pearl', Pearl.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.

The `Pearl` and `Tpearl` classes live in `@bitgo/abstract-utxo` and are re-exported here; this package is a registration shim only.
64 changes: 64 additions & 0 deletions modules/sdk-coin-pearl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@bitgo/sdk-coin-pearl",
"version": "1.0.0",
"description": "BitGo SDK coin library for Pearl",
"main": "./dist/cjs/src/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/esm/index.js",
"types": "./dist/cjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/src/index.d.ts",
"default": "./dist/cjs/src/index.js"
}
}
},
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "yarn tsc --build --incremental --verbose .",
"build:esm": "yarn tsc --project tsconfig.esm.json",
"fmt": "prettier --write .",
"check-fmt": "prettier --check '**/*.{ts,js,json}'",
"clean": "rm -rf ./dist",
"lint": "eslint --quiet .",
"prepare": "npm run build",
"unit-test": "echo 'test in abstract-utxo'"
},
"author": "BitGo SDK Team <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=20"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-pearl"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/abstract-utxo": "^12.0.5",
"@bitgo/sdk-core": "^38.4.0"
},
"files": [
"dist/cjs",
"dist/esm"
]
}
10 changes: 10 additions & 0 deletions modules/sdk-coin-pearl/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { Pearl, Tpearl } from '@bitgo/abstract-utxo';

export { Pearl } from '@bitgo/abstract-utxo';
export { Tpearl } from '@bitgo/abstract-utxo';

export const register = (sdk: BitGoBase): void => {
sdk.register('pearl', Pearl.createInstance);
sdk.register('tpearl', Tpearl.createInstance);
};
17 changes: 17 additions & 0 deletions modules/sdk-coin-pearl/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist/esm",
"rootDir": "./src",
"module": "ES2020",
"target": "ES2020",
"moduleResolution": "bundler",
"lib": ["ES2020", "DOM"],
"declaration": true,
"declarationMap": true,
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "test", "dist"],
"references": []
}
23 changes: 23 additions & 0 deletions modules/sdk-coin-pearl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/cjs",
"rootDir": "./",
"strictPropertyInitialization": false,
"esModuleInterop": true,
"typeRoots": ["../../types", "./node_modules/@types", "../../node_modules/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules"],
"references": [
{
"path": "../abstract-utxo"
},
{
"path": "../sdk-api"
},
{
"path": "../sdk-core"
}
]
}
Loading
Loading