Skip to content

Commit

Permalink
update export
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfnjust committed Dec 17, 2024
1 parent 36f6581 commit eb1cb51
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 51 deletions.
8 changes: 4 additions & 4 deletions test/address.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import * as ecc from 'tiny-secp256k1';
import { address as baddress } from 'bitcoinjs-lib';
import { script as bscript } from 'bitcoinjs-lib';
import { address as baddress } from '@scrypt-inc/bitcoinjs-lib';
import { script as bscript } from '@scrypt-inc/bitcoinjs-lib';
import fixtures from './fixtures/address.json';
import * as tools from 'uint8array-tools';
import { networks } from 'bitcoinjs-lib';
import { networks } from '@scrypt-inc/bitcoinjs-lib';

import { initEccLib } from 'bitcoinjs-lib';
import { initEccLib } from '@scrypt-inc/bitcoinjs-lib';

const NETWORKS: Record<string, networks.Network> = {
...networks,
Expand Down
2 changes: 1 addition & 1 deletion test/bitcoin.core.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import base58 from 'bs58';
import { describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import base58EncodeDecode from './fixtures/core/base58_encode_decode.json';
import base58KeysInvalid from './fixtures/core/base58_keys_invalid.json';
import base58KeysValid from './fixtures/core/base58_keys_valid.json';
Expand Down
2 changes: 1 addition & 1 deletion test/block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { beforeEach, describe, it } from 'mocha';
import { Block } from 'bitcoinjs-lib';
import { Block } from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';

import fixtures from './fixtures/block.json';
Expand Down
2 changes: 1 addition & 1 deletion test/bufferutils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import { BufferReader, BufferWriter } from 'bitcoinjs-lib/src/bufferutils';
import { BufferReader, BufferWriter } from '@scrypt-inc/bitcoinjs-lib';

import * as varuint from 'varuint-bitcoin';

Expand Down
14 changes: 8 additions & 6 deletions test/crypto.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import { crypto as bcrypto } from 'bitcoinjs-lib';
import type { TaggedHashPrefix } from 'bitcoinjs-lib';
import { crypto as bcrypto } from '@scrypt-inc/bitcoinjs-lib';
import type { TaggedHashPrefix } from '@scrypt-inc/bitcoinjs-lib';
import fixtures from './fixtures/crypto.json';
import * as tools from 'uint8array-tools';
import { TAGS, TAGGED_HASH_PREFIXES } from 'bitcoinjs-lib/src/crypto';
import { sha256 } from '@noble/hashes/sha256';

describe('crypto', () => {
Expand All @@ -29,22 +28,25 @@ describe('crypto', () => {
const bytes = Buffer.from(f.hex, 'hex');
const expected = f.result;
it(`returns ${f.result} for taggedHash "${f.tag}" of ${f.hex}`, () => {
const actual = bcrypto.taggedHash(f.tag as TaggedHashPrefix, bytes);
const actual = bcrypto.taggedHash(
f.tag as bcrypto.TaggedHashPrefix,
bytes,
);
assert.strictEqual(tools.toHex(actual), expected);
});
});
});

describe('TAGGED_HASH_PREFIXES', () => {
const taggedHashPrefixes = Object.fromEntries(
TAGS.map((tag: TaggedHashPrefix) => {
bcrypto.TAGS.map((tag: TaggedHashPrefix) => {
const tagHash = sha256(Buffer.from(tag));
return [tag, tools.concat([tagHash, tagHash])];
}),
);
it('stored the result of operation', () => {
assert.strictEqual(
JSON.stringify(TAGGED_HASH_PREFIXES),
JSON.stringify(bcrypto.TAGGED_HASH_PREFIXES),
JSON.stringify(taggedHashPrefixes),
);
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/addresses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as assert from 'assert';
import ECPairFactory from 'ecpair';
import * as ecc from 'tiny-secp256k1';
import { describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import { regtestUtils } from './_regtest.js';
import { randomBytes } from 'crypto';

Expand Down
2 changes: 1 addition & 1 deletion test/integration/bip32.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BIP32Factory from 'bip32';
import * as ecc from 'tiny-secp256k1';
import * as bip39 from 'bip39';
import { describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';

const bip32 = BIP32Factory(ecc);

Expand Down
2 changes: 1 addition & 1 deletion test/integration/blocks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';

describe('bitcoinjs-lib (blocks)', () => {
it('can extract a height from a CoinBase transaction', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/cltv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as assert from 'assert';
import ECPairFactory from 'ecpair';
import * as ecc from 'tiny-secp256k1';
import { before, describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import { regtestUtils } from './_regtest.js';
import { reverseBuffer } from 'bitcoinjs-lib/src/bufferutils';
import { reverseBuffer } from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';

const ECPair = ECPairFactory(ecc);
Expand Down
4 changes: 2 additions & 2 deletions test/integration/csv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { PsbtInput } from 'bip174';
import ECPairFactory from 'ecpair';
import * as ecc from 'tiny-secp256k1';
import { before, describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import { regtestUtils } from './_regtest.js';
import { reverseBuffer } from 'bitcoinjs-lib/src/bufferutils';
import { reverseBuffer } from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';

const ECPair = ECPairFactory(ecc);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/payments.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ECPairFactory from 'ecpair';
import * as ecc from 'tiny-secp256k1';
import { describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import { regtestUtils } from './_regtest.js';
import { randomBytes } from 'crypto';

Expand Down
13 changes: 5 additions & 8 deletions test/integration/taproot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import * as ecc from 'tiny-secp256k1';
import { describe, it } from 'mocha';
import { PsbtInput, TapLeaf, TapLeafScript } from 'bip174';
import { regtestUtils } from './_regtest.js';
import * as bitcoin from 'bitcoinjs-lib';
import { Taptree } from 'bitcoinjs-lib/src/types';
import {
LEAF_VERSION_TAPSCRIPT,
tapleafHash,
} from 'bitcoinjs-lib/src/payments/bip341';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import { Taptree } from '@scrypt-inc/bitcoinjs-lib';
import { LEAF_VERSION_TAPSCRIPT, tapleafHash } from '@scrypt-inc/bitcoinjs-lib';
import {
toXOnly,
tapTreeToList,
tapTreeFromList,
} from 'bitcoinjs-lib/src/psbt/bip371';
import { witnessStackToScriptWitness } from 'bitcoinjs-lib/src/psbt/psbtutils';
} from '@scrypt-inc/bitcoinjs-lib';
import { witnessStackToScriptWitness } from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';
import { sha256 } from '@noble/hashes/sha256';
import { randomBytes } from 'crypto';
Expand Down
2 changes: 1 addition & 1 deletion test/integration/transactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BIP32Factory from 'bip32';
import * as ecc from 'tiny-secp256k1';
import ECPairFactory from 'ecpair';
import { describe, it } from 'mocha';
import * as bitcoin from 'bitcoinjs-lib';
import * as bitcoin from '@scrypt-inc/bitcoinjs-lib';
import { regtestUtils } from './_regtest.js';
import * as tools from 'uint8array-tools';
import { randomBytes } from 'crypto';
Expand Down
4 changes: 2 additions & 2 deletions test/interpreter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
isNullInput,
readOutput,
TxOutput,
} from 'bitcoinjs-lib';
} from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';
import script_tests from './fixtures/scripts/script_tests.json';
import script_asset_tests from './fixtures/scripts/script_assets_test.json';
import tx_valid from './fixtures/scripts/tx_valid.json';
import tx_invalid from './fixtures/scripts/tx_invalid.json';
import { initEccLib } from 'bitcoinjs-lib';
import { initEccLib } from '@scrypt-inc/bitcoinjs-lib';
import * as ecc from 'tiny-secp256k1';
import sinon from 'sinon';

Expand Down
6 changes: 3 additions & 3 deletions test/payments.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as assert from 'assert';
import * as ecc from 'tiny-secp256k1';
import { describe, it, before, beforeEach } from 'mocha';
import { PaymentCreator } from 'bitcoinjs-lib';
import { PaymentCreator } from '@scrypt-inc/bitcoinjs-lib';
import * as u from './payments.utils.js';
import { initEccLib } from 'bitcoinjs-lib';
import { payments } from 'bitcoinjs-lib';
import { initEccLib } from '@scrypt-inc/bitcoinjs-lib';
import { payments } from '@scrypt-inc/bitcoinjs-lib';
const {
embed: p2data,
p2ms,
Expand Down
5 changes: 2 additions & 3 deletions test/payments.utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as t from 'assert';
import * as BNETWORKS from 'bitcoinjs-lib/src/networks';
import * as bscript from 'bitcoinjs-lib/src/script';
import { networks as BNETWORKS } from '@scrypt-inc/bitcoinjs-lib';
import { script as bscript } from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';
import { isTaptree } from 'bitcoinjs-lib/src/types';

function tryHex(x: Uint8Array | Uint8Array[]): string | string[] {
if (x instanceof Uint8Array) return tools.toHex(x);
Expand Down
13 changes: 6 additions & 7 deletions test/psbt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import ECPairFactory from 'ecpair';
import { describe, it } from 'mocha';

import { convertScriptTree } from './payments.utils.js';
import { LEAF_VERSION_TAPSCRIPT } from 'bitcoinjs-lib/src/payments/bip341';
import { tapTreeToList, tapTreeFromList } from 'bitcoinjs-lib/src/psbt/bip371';
import type { Taptree } from 'bitcoinjs-lib/src/types';
import { initEccLib } from 'bitcoinjs-lib';
import { tapTreeToList, tapTreeFromList } from '@scrypt-inc/bitcoinjs-lib';
import type { Taptree } from '@scrypt-inc/bitcoinjs-lib';
import { initEccLib } from '@scrypt-inc/bitcoinjs-lib';
import * as tools from 'uint8array-tools';

const rng = (size: number) => crypto.randomBytes(size);
Expand Down Expand Up @@ -1138,7 +1137,7 @@ describe(`Psbt`, () => {
.forEach(scriptTree => {
const originalTree = convertScriptTree(
scriptTree,
LEAF_VERSION_TAPSCRIPT,
payments.LEAF_VERSION_TAPSCRIPT,
);
const list = tapTreeToList(originalTree);
const treeFromList = tapTreeFromList(list);
Expand All @@ -1150,7 +1149,7 @@ describe(`Psbt`, () => {
it('Throws if too many leaves on a given level', () => {
const list = Array.from({ length: 5 }).map(() => ({
depth: 2,
leafVersion: LEAF_VERSION_TAPSCRIPT,
leafVersion: payments.LEAF_VERSION_TAPSCRIPT,
script: Buffer.from([]),
}));
assert.throws(() => {
Expand All @@ -1175,7 +1174,7 @@ describe(`Psbt`, () => {
const list = [
{
depth: 129,
leafVersion: LEAF_VERSION_TAPSCRIPT,
leafVersion: payments.LEAF_VERSION_TAPSCRIPT,
script: Buffer.from([]),
},
];
Expand Down
2 changes: 1 addition & 1 deletion test/script.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import { script as bscript } from 'bitcoinjs-lib';
import { script as bscript } from '@scrypt-inc/bitcoinjs-lib';
import fixtures from './fixtures/script.json';
import minimalData from 'minimaldata';

Expand Down
2 changes: 1 addition & 1 deletion test/script_number.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import * as scriptNumber from 'bitcoinjs-lib/src/script_number';
import { scriptNumber } from '@scrypt-inc/bitcoinjs-lib';
import fixtures from './fixtures/script_number.json';
import * as tools from 'uint8array-tools';

Expand Down
2 changes: 1 addition & 1 deletion test/script_signature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import { script } from 'bitcoinjs-lib';
import { script } from '@scrypt-inc/bitcoinjs-lib';
const bscriptSig = script.signature;
import fixtures from './fixtures/signature.json';
import * as tools from 'uint8array-tools';
Expand Down
2 changes: 1 addition & 1 deletion test/transaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { beforeEach, describe, it } from 'mocha';
import { Transaction, script as bscript } from 'bitcoinjs-lib';
import { Transaction, script as bscript } from '@scrypt-inc/bitcoinjs-lib';
import fixtures from './fixtures/transaction.json';
import * as tools from 'uint8array-tools';

Expand Down
2 changes: 1 addition & 1 deletion test/types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { describe, it } from 'mocha';
import * as types from 'bitcoinjs-lib/src/types';
import { types } from '@scrypt-inc/bitcoinjs-lib';
import * as v from 'valibot';

describe('types', () => {
Expand Down
7 changes: 6 additions & 1 deletion ts_src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import * as crypto from './crypto.js';
import * as networks from './networks.js';
import * as payments from './payments/index.js';
import * as script from './script.js';
import * as scriptNumber from './script_number.js';
import * as types from './types.js';

export { address, crypto, networks, payments, script };
export { address, crypto, networks, payments, script, scriptNumber, types };

export { Tapleaf, Taptree, TAPLEAF_VERSION_MASK } from './types.js';
export { Block } from './block.js';
/** @hidden */
export { TaggedHashPrefix } from './crypto.js';
Expand All @@ -22,6 +25,8 @@ export {
PaymentOpts,
Stack,
StackElement,
LEAF_VERSION_TAPSCRIPT,
tapleafHash,
} from './payments/index.js';
export {
Input as TxInput,
Expand Down
1 change: 1 addition & 0 deletions ts_src/payments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ export type StackFunction = () => Stack;

export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, p2tr };

export * from './bip341.js';
// TODO
// witness commitment

0 comments on commit eb1cb51

Please sign in to comment.