Skip to content

Commit

Permalink
feat(sdk-coin-baby): add babylon support
Browse files Browse the repository at this point in the history
TICKET: COIN-2828
  • Loading branch information
MohammedRyaan786 committed Jan 21, 2025
2 parents 932541b + 1d05929 commit 3683915
Show file tree
Hide file tree
Showing 190 changed files with 2,068 additions and 520 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
/modules/sdk-coin-eos/ @BitGo/ethalt-team
/modules/sdk-coin-ethlike/ @BitGo/ethalt-team
/modules/sdk-coin-hbar/ @BitGo/ethalt-team
/modules/sdk-coin-icp/ @BitGo/ethalt-team
/modules/sdk-coin-near/ @BitGo/ethalt-team
/modules/sdk-coin-oas/ @BitGo/ethalt-team
/modules/sdk-coin-opeth/ @BitGo/ethalt-team
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-etc /var/modules/sdk-coin-etc/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-eth2 /var/modules/sdk-coin-eth2/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hash /var/modules/sdk-coin-hash/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hbar /var/modules/sdk-coin-hbar/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-icp /var/modules/sdk-coin-icp/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-injective /var/modules/sdk-coin-injective/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-islm /var/modules/sdk-coin-islm/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-near /var/modules/sdk-coin-near/
Expand Down Expand Up @@ -155,6 +156,7 @@ cd /var/modules/sdk-coin-etc && yarn link && \
cd /var/modules/sdk-coin-eth2 && yarn link && \
cd /var/modules/sdk-coin-hash && yarn link && \
cd /var/modules/sdk-coin-hbar && yarn link && \
cd /var/modules/sdk-coin-icp && yarn link && \
cd /var/modules/sdk-coin-injective && yarn link && \
cd /var/modules/sdk-coin-islm && yarn link && \
cd /var/modules/sdk-coin-near && yarn link && \
Expand Down Expand Up @@ -236,6 +238,7 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-eth2 && \
yarn link @bitgo/sdk-coin-hash && \
yarn link @bitgo/sdk-coin-hbar && \
yarn link @bitgo/sdk-coin-icp && \
yarn link @bitgo/sdk-coin-injective && \
yarn link @bitgo/sdk-coin-islm && \
yarn link @bitgo/sdk-coin-near && \
Expand Down Expand Up @@ -277,9 +280,9 @@ RUN cd /var/bitgo-express && \
#LINK_END

#LABEL_START
LABEL created="Wed, 15 Jan 2025 12:14:19 GMT"
LABEL version=10.6.8
LABEL git_hash=cf0b3b3479e1744566865e5ab544c85d3fcdf159
LABEL created="Mon, 20 Jan 2025 14:11:17 GMT"
LABEL version=10.6.9
LABEL git_hash=0ac3f4f1997fb2b28081f10e813f6790b2dc0b90
#LABEL_END

USER node
Expand Down
4 changes: 4 additions & 0 deletions modules/abstract-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [11.2.16](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-20)

**Note:** Version bump only for package @bitgo/abstract-cosmos

## [11.2.15](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-15)

**Note:** Version bump only for package @bitgo/abstract-cosmos
Expand Down
6 changes: 3 additions & 3 deletions modules/abstract-cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitgo/abstract-cosmos",
"version": "11.2.15",
"version": "11.2.16",
"description": "BitGo SDK coin library for COSMOS base implementation",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -38,8 +38,8 @@
]
},
"dependencies": {
"@bitgo/sdk-core": "^28.19.1",
"@bitgo/statics": "^50.19.0",
"@bitgo/sdk-core": "^28.20.0",
"@bitgo/statics": "^50.20.0",
"@bitgo/utxo-lib": "^11.2.1",
"@cosmjs/amino": "^0.29.5",
"@cosmjs/crypto": "^0.30.1",
Expand Down
4 changes: 4 additions & 0 deletions modules/abstract-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [22.4.10](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-20)

**Note:** Version bump only for package @bitgo/abstract-eth

## [22.4.9](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-15)

**Note:** Version bump only for package @bitgo/abstract-eth
Expand Down
10 changes: 5 additions & 5 deletions modules/abstract-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitgo/abstract-eth",
"version": "22.4.9",
"version": "22.4.10",
"description": "BitGo SDK coin library for ETH base implementation",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -40,8 +40,8 @@
]
},
"dependencies": {
"@bitgo/sdk-core": "^28.19.1",
"@bitgo/statics": "^50.19.0",
"@bitgo/sdk-core": "^28.20.0",
"@bitgo/statics": "^50.20.0",
"@bitgo/utxo-lib": "^11.2.1",
"@ethereumjs/common": "^2.6.5",
"@ethereumjs/tx": "^3.3.0",
Expand All @@ -58,8 +58,8 @@
"superagent": "^9.0.1"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.58.1",
"@bitgo/sdk-test": "^8.0.64",
"@bitgo/sdk-api": "^1.58.2",
"@bitgo/sdk-test": "^8.0.65",
"@types/keccak": "^3.0.5"
}
}
4 changes: 4 additions & 0 deletions modules/abstract-lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.2.38](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-20)

**Note:** Version bump only for package @bitgo/abstract-lightning

## [1.2.37](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-15)

**Note:** Version bump only for package @bitgo/abstract-lightning
Expand Down
4 changes: 2 additions & 2 deletions modules/abstract-lightning/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitgo/abstract-lightning",
"version": "1.2.37",
"version": "1.2.38",
"description": "BitGo SDK coin library for base Lightning Network coin implementation",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
]
},
"dependencies": {
"@bitgo/sdk-core": "^28.19.1",
"@bitgo/sdk-core": "^28.20.0",
"@bitgo/utxo-lib": "^11.2.1"
}
}
4 changes: 4 additions & 0 deletions modules/abstract-substrate/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.0.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-20)

**Note:** Version bump only for package @bitgo/abstract-substrate

## 1.0.1 (2025-01-15)

### Bug Fixes
Expand Down
6 changes: 3 additions & 3 deletions modules/abstract-substrate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitgo/abstract-substrate",
"version": "1.0.1",
"version": "1.0.2",
"description": "BitGo SDK coin library for Substrate base implementation",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,7 @@
]
},
"dependencies": {
"@bitgo/sdk-core": "^28.19.1",
"@bitgo/statics": "^50.19.0"
"@bitgo/sdk-core": "^28.20.0",
"@bitgo/statics": "^50.20.0"
}
}
10 changes: 10 additions & 0 deletions modules/abstract-utxo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [9.12.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-20)

### Bug Fixes

- **abstract-utxo:** improve createHalfSigned ([bac55b4](https://github.com/BitGo/BitGoJS/commit/bac55b4aa5a9c6624479e55424568a2bda32cac9))

### Features

- **abstract-utxo:** add descriptor support for offline vault ([7082893](https://github.com/BitGo/BitGoJS/commit/7082893036763d6c5bbe37236ebac68acd1976f5))

## [9.11.1](https://github.com/BitGo/BitGoJS/compare/@bitgo/[email protected]...@bitgo/[email protected]) (2025-01-15)

**Note:** Version bump only for package @bitgo/abstract-utxo
Expand Down
6 changes: 3 additions & 3 deletions modules/abstract-utxo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitgo/abstract-utxo",
"version": "9.11.1",
"version": "9.12.0",
"description": "BitGo SDK coin library for UTXO base implementation",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -40,8 +40,8 @@
},
"dependencies": {
"@bitgo/blockapis": "^1.10.9",
"@bitgo/sdk-api": "^1.58.1",
"@bitgo/sdk-core": "^28.19.1",
"@bitgo/sdk-api": "^1.58.2",
"@bitgo/sdk-core": "^28.20.0",
"@bitgo/unspents": "^0.47.17",
"@bitgo/utxo-lib": "^11.2.1",
"@bitgo/wasm-miniscript": "^2.0.0-beta.2",
Expand Down
13 changes: 13 additions & 0 deletions modules/abstract-utxo/src/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export function getChainFromNetwork(n: utxolib.Network): string {
}
}

/**
* @param coinName - the name of the coin (e.g. 'btc', 'bch', 'ltc'). Also called 'chain' in some contexts.
* @returns the network for a coin. This is the mainnet network for the coin.
*/
export function getNetworkFromChain(coinName: string): utxolib.Network {
for (const network of utxolib.getNetworkList()) {
if (getChainFromNetwork(network) === coinName) {
return network;
}
}
throw new Error(`Unknown chain ${coinName}`);
}

export function getFullNameFromNetwork(n: utxolib.Network): string {
const name = getNetworkName(n);

Expand Down
36 changes: 36 additions & 0 deletions modules/abstract-utxo/src/offlineVault/OfflineVaultHalfSigned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as utxolib from '@bitgo/utxo-lib';
import { BIP32Interface } from '@bitgo/utxo-lib';
import { BaseCoin } from '@bitgo/sdk-core';

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

import { OfflineVaultUnsigned } from './OfflineVaultUnsigned';
import { DescriptorTransaction, getHalfSignedPsbt } from './descriptor';

export type OfflineVaultHalfSigned = {
halfSigned: { txHex: string };
};

function createHalfSignedFromPsbt(psbt: utxolib.Psbt): OfflineVaultHalfSigned {
return { halfSigned: { txHex: psbt.toHex() } };
}

export function createHalfSigned(
coin: string,
prv: string | BIP32Interface,
derivationId: string,
tx: unknown
): OfflineVaultHalfSigned {
const network = getNetworkFromChain(coin);
if (typeof prv === 'string') {
prv = utxolib.bip32.fromBase58(prv);
}
prv = BaseCoin.deriveKeyWithSeedBip32(prv, derivationId).key;
if (!OfflineVaultUnsigned.is(tx)) {
throw new Error('unsupported transaction type');
}
if (DescriptorTransaction.is(tx)) {
return createHalfSignedFromPsbt(getHalfSignedPsbt(tx, prv, network));
}
throw new Error('unsupported transaction type');
}
35 changes: 35 additions & 0 deletions modules/abstract-utxo/src/offlineVault/OfflineVaultUnsigned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as utxolib from '@bitgo/utxo-lib';
import { Triple } from '@bitgo/sdk-core';
import * as t from 'io-ts';

export const XPubWithDerivationPath = t.intersection(
[t.type({ xpub: t.string }), t.partial({ derivedFromParentWithSeed: t.string })],
'XPubWithDerivationPath'
);

export type XPubWithDerivationPath = t.TypeOf<typeof XPubWithDerivationPath>;

/**
* This is the transaction payload that is sent to the offline vault to sign.
*/
export const OfflineVaultUnsigned = t.type(
{
xpubsWithDerivationPath: t.type({
user: XPubWithDerivationPath,
backup: XPubWithDerivationPath,
bitgo: XPubWithDerivationPath,
}),
coinSpecific: t.type({ txHex: t.string }),
},
'BaseTransaction'
);

export type OfflineVaultUnsigned = t.TypeOf<typeof OfflineVaultUnsigned>;

type WithXpub = { xpub: string };
type NamedKeys = { user: WithXpub; backup: WithXpub; bitgo: WithXpub };
export function toKeyTriple(xpubs: NamedKeys): Triple<utxolib.BIP32Interface> {
return [xpubs.user.xpub, xpubs.backup.xpub, xpubs.bitgo.xpub].map((xpub) =>
utxolib.bip32.fromBase58(xpub)
) as Triple<utxolib.BIP32Interface>;
}
1 change: 1 addition & 0 deletions modules/abstract-utxo/src/offlineVault/descriptor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './transaction';
43 changes: 43 additions & 0 deletions modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as utxolib from '@bitgo/utxo-lib';
import * as t from 'io-ts';

import { NamedDescriptor } from '../../descriptor';
import { OfflineVaultUnsigned, toKeyTriple } from '../OfflineVaultUnsigned';
import {
getValidatorOneOfTemplates,
getValidatorSignedByUserKey,
getValidatorSome,
toDescriptorMapValidate,
} from '../../descriptor/validatePolicy';
import { DescriptorMap } from '../../core/descriptor';
import { signPsbt } from '../../transaction/descriptor';

export const DescriptorTransaction = t.intersection(
[OfflineVaultUnsigned, t.type({ descriptors: t.array(NamedDescriptor) })],
'DescriptorTransaction'
);

export type DescriptorTransaction = t.TypeOf<typeof DescriptorTransaction>;

export function getDescriptorsFromDescriptorTransaction(tx: DescriptorTransaction): DescriptorMap {
const { descriptors, xpubsWithDerivationPath } = tx;
const pubkeys = toKeyTriple(xpubsWithDerivationPath);
const policy = getValidatorSome([
// allow all 2-of-3-ish descriptors where the keys match the wallet keys
getValidatorOneOfTemplates(['Wsh2Of3', 'Wsh2Of3CltvDrop', 'ShWsh2Of3CltvDrop']),
// allow all descriptors signed by the user key
getValidatorSignedByUserKey(),
]);
return toDescriptorMapValidate(descriptors, pubkeys, policy);
}

export function getHalfSignedPsbt(
tx: DescriptorTransaction,
prv: utxolib.BIP32Interface,
network: utxolib.Network
): utxolib.Psbt {
const psbt = utxolib.bitgo.createPsbtDecode(tx.coinSpecific.txHex, network);
const descriptorMap = getDescriptorsFromDescriptorTransaction(tx);
signPsbt(psbt, descriptorMap, prv, { onUnknownInput: 'throw' });
return psbt;
}
2 changes: 2 additions & 0 deletions modules/abstract-utxo/src/offlineVault/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as descriptor from './descriptor';
export * from './OfflineVaultHalfSigned';
Loading

0 comments on commit 3683915

Please sign in to comment.