-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utxo-coredao): initialize utxo-coredao
This is dependent on wasm-miniscript with OP_DROP, which is not merged in yet. I will add tests for this once we can import it. TICKET: BTC-1578
- Loading branch information
1 parent
aa6d874
commit 4cd57fc
Showing
12 changed files
with
6,062 additions
and
3,917 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.idea | ||
public | ||
dist | ||
|
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,8 @@ | ||
require: 'ts-node/register' | ||
timeout: '60000' | ||
reporter: 'min' | ||
reporter-option: | ||
- 'cdn=true' | ||
- 'json=false' | ||
exit: true | ||
spec: ['test/unit/**/*.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,14 @@ | ||
!dist/ | ||
dist/test/ | ||
dist/tsconfig.tsbuildinfo | ||
.idea/ | ||
.prettierrc.yml | ||
tsconfig.json | ||
src/ | ||
test/ | ||
scripts/ | ||
.nyc_output | ||
CODEOWNERS | ||
node_modules/ | ||
.prettierignore | ||
.mocharc.js |
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 @@ | ||
.nyc_output/ | ||
dist/ |
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,3 @@ | ||
printWidth: 120 | ||
singleQuote: true | ||
trailingComma: 'es5' |
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,19 @@ | ||
# BitGo utxo-CoreDao | ||
|
||
Provides the functionality to build and parse coredao transactions. | ||
|
||
## 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-<%= symbol %>`. | ||
|
||
```shell | ||
npm i @bitgo/sdk-api @bitgo/utxo-coredao> | ||
``` | ||
|
||
## 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. |
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,46 @@ | ||
{ | ||
"name": "@bitgo/utxo-coredao", | ||
"version": "1.0.0", | ||
"description": "BitGo SDK for building CoreDao transactions", | ||
"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/utxo-coredao" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts}": [ | ||
"yarn prettier --write", | ||
"yarn eslint --fix" | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
] | ||
}, | ||
"dependencies": { | ||
"@bitgo/utxo-lib": "^11.0.0", | ||
"assert": "^2.1.0" | ||
} | ||
} |
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,46 @@ | ||
import { BIP32Interface, bitgo } from '@bitgo/utxo-lib'; | ||
|
||
/** | ||
* Script type for a descriptor. This is either a p2sh (sh) or a p2wsh (wsh) script. | ||
*/ | ||
export type ScriptType = 'sh' | 'wsh'; | ||
|
||
/** | ||
* Create a multi-sig descriptor to produce a coredao staking address | ||
* @param scriptType segwit or legacy | ||
* @param locktime locktime for CLTV | ||
* @param m Total number of keys required to unlock | ||
* @param orderedKeys | ||
*/ | ||
export function createMultiSigDescriptor( | ||
scriptType: ScriptType, | ||
locktime: number, | ||
m: number, | ||
orderedKeys: BIP32Interface[] | ||
): string { | ||
if (m > orderedKeys.length || m < 1) { | ||
throw new Error( | ||
`m (${m}) must be less than or equal to the number of keys (${orderedKeys.length}) and greater than 0` | ||
); | ||
} | ||
if (locktime <= 0) { | ||
throw new Error(`locktime (${locktime}) must be greater than 0`); | ||
} | ||
|
||
const xpubs = orderedKeys.map((key) => key.toBase58() + '/*'); | ||
return `${scriptType}(and_v(r:after(${locktime}),multi(${m},${xpubs.join(',')}))`; | ||
} | ||
|
||
/** | ||
* Create a wallet descriptor to produce a coredao staking address for a standard BitGo wallet | ||
* @param scriptType | ||
* @param locktime | ||
* @param rootWalletKeys | ||
*/ | ||
export function createWalletDescriptor( | ||
scriptType: ScriptType, | ||
locktime: number, | ||
rootWalletKeys: bitgo.RootWalletKeys | ||
): string { | ||
return createMultiSigDescriptor(scriptType, locktime, 2, rootWalletKeys.triple); | ||
} |
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 './descriptor'; |
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,14 @@ | ||
import * as assert from 'assert'; | ||
import { createMultiSigDescriptor, createWalletDescriptor } from '../../src'; | ||
import { testutil, bitgo } from '@bitgo/utxo-lib'; | ||
|
||
// TODO BTC-1583: Add test fixtures for compiling descriptors | ||
describe('CoreDao descriptor', function () { | ||
const keys = testutil.getKeyTriple('wasm-possum'); | ||
it('should fail if given invalid parameters', function () { | ||
assert.throws(() => createMultiSigDescriptor('wsh', -1, 2, keys)); | ||
assert.throws(() => createWalletDescriptor('wsh', 0, new bitgo.RootWalletKeys(keys))); | ||
assert.throws(() => createMultiSigDescriptor('wsh', 0, 2, keys)); | ||
assert.throws(() => createMultiSigDescriptor('wsh', 3, 4, keys)); | ||
}); | ||
}); |
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,18 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": ".", | ||
"typeRoots": ["./node_modules/@types", "../../node_modules/@types"], | ||
"allowJs": false, | ||
"strict": true, | ||
"useUnknownInCatchVariables": false | ||
}, | ||
"include": ["src/**/*", "bin/**/*", "test/**/*"], | ||
"exclude": ["node_modules"], | ||
"references": [ | ||
{ | ||
"path": "../utxo-lib" | ||
} | ||
] | ||
} |
Oops, something went wrong.