-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-coin-baby): add babylon support
TICKET: COIN-2828
- Loading branch information
Showing
190 changed files
with
2,068 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
modules/abstract-utxo/src/offlineVault/OfflineVaultHalfSigned.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
modules/abstract-utxo/src/offlineVault/OfflineVaultUnsigned.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './transaction'; |
43 changes: 43 additions & 0 deletions
43
modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * as descriptor from './descriptor'; | ||
export * from './OfflineVaultHalfSigned'; |
Oops, something went wrong.