Skip to content
Merged
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
3,698 changes: 1,118 additions & 2,580 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
"name": "@bitcoin-computer/components",
"version": "0.24.1-beta.0",
"description": "",
"homepage": "http://bitcoincomputer.io/",
"bugs": {
"url": "https://github.com/bitcoin-computer/monorepo/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/bitcoin-computer/monorepo/tree/main/packages/components"
},
"license": "MIT",
"author": {
"name": "Clemens Ley",
Expand All @@ -13,14 +21,6 @@
"Laura Tardivo",
"Vivek Singh"
],
"homepage": "http://bitcoincomputer.io/",
"bugs": {
"url": "https://github.com/bitcoin-computer/monorepo/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/bitcoin-computer/monorepo/tree/main/packages/components"
},
"main": "built/index.js",
"types": "built/index.d.ts",
"scripts": {
Expand Down
13 changes: 0 additions & 13 deletions packages/docs/Node/Blockchain/height.md

This file was deleted.

13 changes: 0 additions & 13 deletions packages/docs/Node/Blockchain/mine.md

This file was deleted.

20 changes: 10 additions & 10 deletions packages/lib/dist/bc-lib.browser.min.mjs

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions packages/lib/dist/bc-lib.commonjs.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lib/dist/bc-lib.main.es.mjs

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions packages/lib/dist/bc-lib.module.es.mjs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/nakamotojs/bitcoind-rpc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Type definitions for bitcoind-rpc

// <reference types="node" />

declare module 'bitcoind-rpc'
16 changes: 9 additions & 7 deletions packages/nakamotojs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@
"format:ci": "npm run prettier -- --check && npm run prettierjs -- --check",
"formatjs": "npm run prettierjs -- --write",
"gitdiff:ci": "npm run build && git diff --exit-code",
"integration": "npm run build && npm run nobuild:integration",
"lint": "eslint ts_src/** src/**/*.js",
"lint:tests": "eslint test/**/*.spec.ts",
"mocha:ts": "mocha --recursive --require test/ts-node-register",
"mocha:ts": "mocha --recursive -r ts-node/register",
"nobuild:coverage": "npm run build:tests && nyc --check-coverage --branches 80 --functions 80 --lines 80 mocha && npm run clean:jstests",
"nobuild:coverage:html": "nyc report --reporter=html",
"nobuild:coverage:report": "nyc report --reporter=lcov",
"nobuild:integration": "npm run mocha:ts -- --timeout 50000 'test/integration/*.ts'",
"nobuild:integration": "BITCOIN_RPC_HOST=127.0.0.1 npm run mocha:ts -- --timeout 50000 'test/integration/*.js'",
"nobuild:unit": "npm run mocha:ts -- 'test/*.ts'",
"prettier": "prettier \"ts_src/**/*.ts\" \"test/**/*.ts\" --ignore-path ./.prettierignore --write",
"prettierjs": "prettier \"src/**/*.js\" --ignore-path ./.prettierignore",
"test": "npm run build && npm run format:ci && npm run lint && npm run nobuild:coverage",
"test:unit:show": "npm run test 2>&1 | tee nakamotojs-test.log && open nakamotojs-test.log",
"test:integration": "npm run build && npm run format:ci && npm run lint && npm run nobuild:integration",
"test:integration:show": "npm run test:integration | tee nakamotojs-integration-test.log; if [ ${PIPESTATUS[0]} -ne 0 ]; then open nakamotojs-integration-test.log; fi",
"test:show": "npm run test:unit:show && npm run test:integration:show",
"test:unit:show": "npm run test 2>&1 | tee nakamotojs-test.log; if [ ${PIPESTATUS[0]} -ne 0 ]; then open nakamotojs-test.log; fi",
"unit": "npm run build && npm run nobuild:unit"
},
"dependencies": {
Expand All @@ -60,29 +62,29 @@
"varuint-bitcoin": "^1.1.2"
},
"devDependencies": {
"@bitcoin-computer/nakamotojs-client": "0.2.2",
"@bitcoin-computer/secp256k1": "^0.24.1-beta.0",
"@types/bs58": "^4.0.0",
"@types/bs58check": "^2.1.0",
"@types/mocha": "^5.2.7",
"@types/node": "^16.11.7",
"@types/proxyquire": "^1.3.28",
"@types/randombytes": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"bip32": "^4.0.0",
"bip39": "^3.1.0",
"bip65": "^1.0.1",
"bip68": "^1.0.3",
"bitcoind-rpc": "^0.9.1",
"bs58": "^4.0.0",
"dotenv": "^16.4.5",
"ecpair": "^2.0.1",
"elliptic": "^6.6.1",
"hoodwink": "^2.0.0",
"minimaldata": "^1.0.2",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^3.2.5",
"proxyquire": "^2.0.1",
"randombytes": "^2.1.0",
"ts-node": "^8.3.0",
"typescript": "^5.5.3"
},
Expand Down
21 changes: 21 additions & 0 deletions packages/nakamotojs/src/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface _Transaction {
txId: string;
txHex: string;
vsize: number;
version: number;
locktime: number;
ins: _Input[];
outs: _Output[];
}
export interface _Input {
txId: string;
vout: number;
script: string;
sequence: string;
}
export interface _Output {
value: number;
script: string;
address?: string;
}
export declare const rpcJSON2CB: (tx: any) => _Transaction;
38 changes: 38 additions & 0 deletions packages/nakamotojs/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export const rpcJSON2CB = tx => {
return {
txId: tx.txid,
txHex: tx.hex,
vsize: tx.vsize,
version: tx.version,
locktime: tx.locktime,
ins: tx.vin.map(x => {
if (x.coinbase) {
return {
coinbase: x.coinbase,
sequence: x.sequence,
};
}
return {
txId: x.txid,
vout: x.vout,
script: x.scriptSig.hex,
sequence: x.sequence,
};
}),
outs: tx.vout.map(x => {
let address;
if (x.scriptPubKey.addresses) {
[address] = x.scriptPubKey.addresses;
} else if (x.scriptPubKey.address) {
address = x.scriptPubKey.address;
} else {
address = undefined;
}
return {
address,
script: x.scriptPubKey.hex,
value: Math.round(x.value * 1e8), // satoshis
};
}),
};
};
30 changes: 13 additions & 17 deletions packages/nakamotojs/test/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import * as ecc from '@bitcoin-computer/secp256k1';
import * as baddress from '../src/address.js';
import * as bscript from '../src/script.js';
import { NETWORKS } from '../src/networks.js';
import * as fixturesModule from './fixtures/address.json' assert { type: 'json' };

const fixtures: typeof import('./fixtures/address.json') =
// @ts-ignore
fixturesModule.default || fixturesModule;
import address from './fixtures/address.js';

import { initEccLib } from '../src/index.js';

describe('address', () => {
describe('fromBase58Check', () => {
fixtures.standard.forEach(f => {
address.standard.forEach(f => {
if (!f.base58check) return;

it('decodes ' + f.base58check, () => {
Expand All @@ -27,7 +23,7 @@ describe('address', () => {
});
});

fixtures.invalid.fromBase58Check.forEach(f => {
address.invalid.fromBase58Check.forEach(f => {
it('throws on ' + f.exception, () => {
assert.throws(
() => {
Expand All @@ -40,7 +36,7 @@ describe('address', () => {
});

describe('fromBech32', () => {
fixtures.standard.forEach(f => {
address.standard.forEach(f => {
if (!f.bech32) return;

it('decodes ' + f.bech32, () => {
Expand All @@ -52,7 +48,7 @@ describe('address', () => {
});
});

fixtures.invalid.bech32.forEach(f => {
address.invalid.bech32.forEach(f => {
it('decode fails for ' + f.address + '(' + f.exception + ')', () => {
assert.throws(() => {
baddress.fromBech32(f.address);
Expand All @@ -63,7 +59,7 @@ describe('address', () => {

describe('fromOutputScript', () => {
initEccLib(ecc);
fixtures.standard.forEach(f => {
address.standard.forEach(f => {
it('encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
const script = bscript.fromASM(f.script);
const address = baddress.fromOutputScript(script, NETWORKS[f.network]);
Expand All @@ -72,7 +68,7 @@ describe('address', () => {
});
});

fixtures.invalid.fromOutputScript.forEach(f => {
address.invalid.fromOutputScript.forEach(f => {
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, () => {
const script = bscript.fromASM(f.script);

Expand All @@ -84,7 +80,7 @@ describe('address', () => {
});

describe('toBase58Check', () => {
fixtures.standard.forEach(f => {
address.standard.forEach(f => {
if (!f.base58check) return;

it('encodes ' + f.hash + ' (' + f.network + ')', () => {
Expand All @@ -99,7 +95,7 @@ describe('address', () => {
});

describe('toBech32', () => {
fixtures.bech32.forEach(f => {
address.bech32.forEach(f => {
if (!f.address) return;
const data = Buffer.from(f.data, 'hex');

Expand All @@ -112,7 +108,7 @@ describe('address', () => {
});

// TODO: These fixtures (according to TypeScript) have none of the data used below
fixtures.invalid.bech32.forEach((f: any) => {
address.invalid.bech32.forEach((f: any) => {
if (!f.prefix || f.version === undefined || f.data === undefined) return;

it('encode fails (' + f.exception, () => {
Expand All @@ -124,7 +120,7 @@ describe('address', () => {
});

describe('toOutputScript', () => {
fixtures.standard.forEach(f => {
address.standard.forEach(f => {
it('decodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
const script = baddress.toOutputScript(
(f.base58check || f.bech32)!,
Expand All @@ -135,7 +131,7 @@ describe('address', () => {
});
});

fixtures.invalid.toOutputScript.forEach(f => {
address.invalid.toOutputScript.forEach(f => {
it('throws when ' + (f.exception || f.paymentException), () => {
const exception = f.paymentException || `${f.address} ${f.exception}`;
assert.throws(() => {
Expand All @@ -146,7 +142,7 @@ describe('address', () => {
});

describe('fromPublicKey', () => {
fixtures.valid.forEach(f => {
address.valid.forEach(f => {
f.types.forEach(t => {
if (!t.address) return;
it(
Expand Down
47 changes: 9 additions & 38 deletions packages/nakamotojs/test/bitcoin.core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,14 @@ import assert from 'assert';
import base58 from 'bs58';
import { describe, it } from 'mocha';
import * as bitcoin from '../src/index.js';
import * as base58EncodeDecodeModule from './fixtures/core/base58_encode_decode.json' assert { type: 'json' };
import * as base58KeysInvalidModule from './fixtures/core/base58_keys_invalid.json' assert { type: 'json' };
import * as base58KeysValidModule from './fixtures/core/base58_keys_valid.json' assert { type: 'json' };
import * as blocksValidModule from './fixtures/core/blocks.json' assert { type: 'json' };
import * as sigCanonicalModule from './fixtures/core/sig_canonical.json' assert { type: 'json' };
import * as sigNoncanonicalModule from './fixtures/core/sig_noncanonical.json' assert { type: 'json' };
import * as sigHashModule from './fixtures/core/sighash.json' assert { type: 'json' };
import * as txValidModule from './fixtures/core/tx_valid.json' assert { type: 'json' };

const base58EncodeDecode: typeof import('./fixtures/core/base58_encode_decode.json') =
// @ts-ignore
base58EncodeDecodeModule.default || base58EncodeDecodeModule;

const base58KeysInvalid: typeof import('./fixtures/core/base58_keys_invalid.json') =
// @ts-ignore
base58KeysInvalidModule.default || base58KeysInvalidModule;
const base58KeysValid: typeof import('./fixtures/core/base58_keys_valid.json') =
// @ts-ignore
base58KeysValidModule.default || base58KeysValidModule;

const blocksValid: typeof import('./fixtures/core/blocks.json') =
// @ts-ignore
blocksValidModule.default || blocksValidModule;
const sigCanonical: typeof import('./fixtures/core/sig_canonical.json') =
// @ts-ignore
sigCanonicalModule.default || sigCanonicalModule;

const sigNoncanonical: typeof import('./fixtures/core/sig_noncanonical.json') =
// @ts-ignore
sigNoncanonicalModule.default || sigNoncanonicalModule;

const sigHash: typeof import('./fixtures/core/sighash.json') =
// @ts-ignore
sigHashModule.default || sigHashModule;
const txValid: typeof import('./fixtures/core/tx_valid.json') =
// @ts-ignore
txValidModule.default || txValidModule;
import base58EncodeDecode from './fixtures/core/base58_encode_decode.js';
import base58KeysInvalid from './fixtures/core/base58_keys_invalid.js';
import base58KeysValid from './fixtures/core/base58_keys_valid.js';
import blocks from './fixtures/core/blocks.js';
import sigCanonical from './fixtures/core/sig_canonical.js';
import sigNoncanonical from './fixtures/core/sig_noncanonical.js';
import sigHash from './fixtures/core/sighash.js';
import txValid from './fixtures/core/tx_valid.js';

describe('Bitcoin-core', () => {
// base58EncodeDecode
Expand Down Expand Up @@ -121,7 +92,7 @@ describe('Bitcoin-core', () => {
});

describe('Block.fromHex', () => {
blocksValid.forEach(f => {
blocks.forEach(f => {
it('can parse ' + f.id, () => {
const block = bitcoin.Block.fromHex(f.hex);

Expand Down
6 changes: 1 addition & 5 deletions packages/nakamotojs/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import assert from 'assert';
import { beforeEach, describe, it } from 'mocha';
import { Block } from '../src/index.js';

import * as fixturesModule from './fixtures/block.json' assert { type: 'json' };

const fixtures: typeof import('./fixtures/block.json') =
// @ts-ignore
fixturesModule.default || fixturesModule;
import fixtures from './fixtures/block.js';

describe('Block', () => {
describe('version', () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/nakamotojs/test/bufferutils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { describe, it } from 'mocha';
import * as bufferutils from '../src/bufferutils.js';
import { BufferReader, BufferWriter } from '../src/bufferutils.js';

import * as fixturesModule from './fixtures/bufferutils.json' assert { type: 'json' };
const fixtures: typeof import('./fixtures/bufferutils.json') =
// @ts-ignore
fixturesModule.default || fixturesModule;
import fixtures from './fixtures/bufferutils.js';

import * as varuint from 'varuint-bitcoin';

Expand Down
Loading