-
Notifications
You must be signed in to change notification settings - Fork 27
feat: pulls out btc package #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
netbonus
wants to merge
5
commits into
dev
Choose a base branch
from
feat/btc-sdk-additions
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
74e425d
feat(btc): add BTC namespace with xpub, slip132, network, tx, wallet …
netbonus e309972
refactor(btc): extract BTC utilities to @gridplus/btc package
netbonus 0054990
fix(ci): handle missing simulator directory in cleanup steps
netbonus 92fa97e
fix(ci): build @gridplus/btc before SDK in monorepo scripts
netbonus 31ade0d
fix(btc): add missing @types/node devDependency
netbonus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| import js from '@eslint/js'; | ||
| import tsPlugin from '@typescript-eslint/eslint-plugin'; | ||
| import tsParser from '@typescript-eslint/parser'; | ||
| import prettierConfig from 'eslint-config-prettier'; | ||
| import prettierPlugin from 'eslint-plugin-prettier'; | ||
|
|
||
| const restrictedNodeImports = [ | ||
| { name: 'crypto', message: 'Use node:crypto instead.' }, | ||
| { name: 'fs', message: 'Use node:fs instead.' }, | ||
| { name: 'os', message: 'Use node:os instead.' }, | ||
| { name: 'path', message: 'Use node:path instead.' }, | ||
| { name: 'stream', message: 'Use node:stream instead.' }, | ||
| { name: 'url', message: 'Use node:url instead.' }, | ||
| { name: 'util', message: 'Use node:util instead.' }, | ||
| ]; | ||
|
|
||
| export default [ | ||
| js.configs.recommended, | ||
| { | ||
| files: ['src/**/*.ts', 'src/**/*.tsx'], | ||
| plugins: { | ||
| '@typescript-eslint': tsPlugin, | ||
| prettier: prettierPlugin, | ||
| }, | ||
| languageOptions: { | ||
| parser: tsParser, | ||
| parserOptions: { | ||
| ecmaVersion: 'latest', | ||
| sourceType: 'module', | ||
| }, | ||
| globals: { | ||
| Buffer: 'readonly', | ||
| URL: 'readonly', | ||
| URLSearchParams: 'readonly', | ||
| fetch: 'readonly', | ||
| Response: 'readonly', | ||
| Request: 'readonly', | ||
| RequestInit: 'readonly', | ||
| AbortController: 'readonly', | ||
| setTimeout: 'readonly', | ||
| clearTimeout: 'readonly', | ||
| // Test globals | ||
| vi: 'readonly', | ||
| describe: 'readonly', | ||
| it: 'readonly', | ||
| test: 'readonly', | ||
| expect: 'readonly', | ||
| beforeAll: 'readonly', | ||
| afterAll: 'readonly', | ||
| beforeEach: 'readonly', | ||
| afterEach: 'readonly', | ||
| // Node.js globals | ||
| process: 'readonly', | ||
| // Browser globals | ||
| console: 'readonly', | ||
| }, | ||
| }, | ||
| rules: { | ||
| ...tsPlugin.configs.recommended.rules, | ||
| ...prettierPlugin.configs.recommended.rules, | ||
| 'prettier/prettier': 'error', | ||
| eqeqeq: ['error'], | ||
| 'no-var': ['warn'], | ||
| 'no-duplicate-imports': ['error'], | ||
| 'prefer-const': ['error'], | ||
| 'prefer-spread': ['error'], | ||
| 'no-console': ['off'], | ||
| 'no-redeclare': 'off', | ||
| '@typescript-eslint/no-redeclare': 'error', | ||
| '@typescript-eslint/no-explicit-any': 'off', | ||
| '@typescript-eslint/no-unused-vars': [ | ||
| 'warn', | ||
| { argsIgnorePattern: '^_' }, | ||
| ], | ||
| quotes: [ | ||
| 'warn', | ||
| 'single', | ||
| { avoidEscape: true, allowTemplateLiterals: true }, | ||
| ], | ||
| 'no-restricted-imports': ['error', { paths: restrictedNodeImports }], | ||
| 'no-restricted-syntax': [ | ||
| 'error', | ||
| { | ||
| selector: "CallExpression[callee.name='require']", | ||
| message: 'Use ESM imports instead of require.', | ||
| }, | ||
| { | ||
| selector: | ||
| "AssignmentExpression[left.object.name='module'][left.property.name='exports']", | ||
| message: 'Use ESM exports instead of module.exports.', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| prettierConfig, | ||
| { | ||
| ignores: [ | ||
| 'dist/**', | ||
| 'node_modules/**', | ||
| 'coverage/**', | ||
| '*.js', | ||
| '*.cjs', | ||
| '*.mjs', | ||
| 'build/**', | ||
| ], | ||
| }, | ||
| ]; |
This file contains hidden or 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,51 @@ | ||
| { | ||
| "name": "@gridplus/btc", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "@gridplus/btc" looks clean and concise in the code, but I’m not sure it clearly signals what the package contains (wallet, utils, etc.). I was considering something like "@gridplus/btc-utils" instead, though I’m not 100% sold 🤔 |
||
| "version": "0.1.0", | ||
| "type": "module", | ||
| "description": "BTC utilities for GridPlus SDK - SLIP-132, network inference, transaction building, wallet utilities", | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "test": "vitest run ./src/__test__/unit", | ||
| "lint": "eslint src --config eslint.config.mjs", | ||
| "lint:fix": "eslint src --config eslint.config.mjs --fix" | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.mjs", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.cjs" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "types": "./dist/index.d.ts", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/GridPlus/gridplus-sdk.git", | ||
| "directory": "packages/btc" | ||
| }, | ||
| "dependencies": { | ||
| "bs58check": "^4.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "^9.36.0", | ||
| "@types/node": "^24.10.4", | ||
| "@typescript-eslint/eslint-plugin": "^8.44.1", | ||
| "@typescript-eslint/parser": "^8.44.1", | ||
| "eslint": "^9.36.0", | ||
| "eslint-config-prettier": "^10.1.8", | ||
| "eslint-plugin-prettier": "^5.5.4", | ||
| "prettier": "^3.6.2", | ||
| "tsup": "^8.5.0", | ||
| "typescript": "^5.9.2", | ||
| "vitest": "3.2.4" | ||
| }, | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=20" | ||
| } | ||
| } | ||
This file contains hidden or 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,51 @@ | ||
| import bs58check from 'bs58check'; | ||
| import { SLIP132_VERSION_BYTES } from '../../constants'; | ||
| import { | ||
| inferFromXpub, | ||
| getCoinType, | ||
| getNetworkFromCoinType, | ||
| isTestnet, | ||
| } from '../../network'; | ||
|
|
||
| const TEST_XPUB = | ||
| 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'; | ||
| const toVersion = (xpub: string, version: number) => { | ||
| const decoded = bs58check.decode(xpub); | ||
| const converted = new Uint8Array(decoded.length); | ||
| const view = new DataView(converted.buffer); | ||
| view.setUint32(0, version, false); | ||
| converted.set(decoded.subarray(4), 4); | ||
| return bs58check.encode(converted); | ||
| }; | ||
|
|
||
| const TEST_TPUB = toVersion(TEST_XPUB, SLIP132_VERSION_BYTES.tpub.public); | ||
|
|
||
| describe('btc/network', () => { | ||
| it('infers mainnet from xpub', () => { | ||
| expect(inferFromXpub(TEST_XPUB)).toBe('mainnet'); | ||
| }); | ||
|
|
||
| it('infers testnet from tpub', () => { | ||
| expect(inferFromXpub(TEST_TPUB)).toBe('testnet'); | ||
| }); | ||
|
|
||
| it('returns coin type for mainnet', () => { | ||
| expect(getCoinType('mainnet')).toBe(0); | ||
| }); | ||
|
|
||
| it('returns coin type for testnet/regtest', () => { | ||
| expect(getCoinType('testnet')).toBe(1); | ||
| expect(getCoinType('regtest')).toBe(1); | ||
| }); | ||
|
|
||
| it('returns network from coin type', () => { | ||
| expect(getNetworkFromCoinType(0)).toBe('mainnet'); | ||
| expect(getNetworkFromCoinType(1)).toBe('testnet'); | ||
| }); | ||
|
|
||
| it('identifies testnet-like networks', () => { | ||
| expect(isTestnet('mainnet')).toBe(false); | ||
| expect(isTestnet('testnet')).toBe(true); | ||
| expect(isTestnet('regtest')).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@netbonus should we use Turbo for the dependency orchestration? and we'll need to add @gridplus/btc as a depedency here for a true monorepo experience.