From eb1cb51fee95a7a6feea4b5807bb103002e05978 Mon Sep 17 00:00:00 2001 From: hh Date: Tue, 17 Dec 2024 17:48:25 +0800 Subject: [PATCH] update export --- test/address.spec.ts | 8 ++++---- test/bitcoin.core.spec.ts | 2 +- test/block.spec.ts | 2 +- test/bufferutils.spec.ts | 2 +- test/crypto.spec.ts | 14 ++++++++------ test/integration/addresses.spec.ts | 2 +- test/integration/bip32.spec.ts | 2 +- test/integration/blocks.spec.ts | 2 +- test/integration/cltv.spec.ts | 4 ++-- test/integration/csv.spec.ts | 4 ++-- test/integration/payments.spec.ts | 2 +- test/integration/taproot.spec.ts | 13 +++++-------- test/integration/transactions.spec.ts | 2 +- test/interpreter.spec.ts | 4 ++-- test/payments.spec.ts | 6 +++--- test/payments.utils.ts | 5 ++--- test/psbt.spec.ts | 13 ++++++------- test/script.spec.ts | 2 +- test/script_number.spec.ts | 2 +- test/script_signature.spec.ts | 2 +- test/transaction.spec.ts | 2 +- test/types.spec.ts | 2 +- ts_src/index.ts | 7 ++++++- ts_src/payments/index.ts | 1 + 24 files changed, 54 insertions(+), 51 deletions(-) diff --git a/test/address.spec.ts b/test/address.spec.ts index 8ef401791..7ce7a3aee 100644 --- a/test/address.spec.ts +++ b/test/address.spec.ts @@ -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 = { ...networks, diff --git a/test/bitcoin.core.spec.ts b/test/bitcoin.core.spec.ts index 1c1b50787..98de94087 100644 --- a/test/bitcoin.core.spec.ts +++ b/test/bitcoin.core.spec.ts @@ -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'; diff --git a/test/block.spec.ts b/test/block.spec.ts index 7cd123193..621b71197 100644 --- a/test/block.spec.ts +++ b/test/block.spec.ts @@ -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'; diff --git a/test/bufferutils.spec.ts b/test/bufferutils.spec.ts index e3e17f1a1..3bf747733 100644 --- a/test/bufferutils.spec.ts +++ b/test/bufferutils.spec.ts @@ -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'; diff --git a/test/crypto.spec.ts b/test/crypto.spec.ts index de59bf55a..8162d1e13 100644 --- a/test/crypto.spec.ts +++ b/test/crypto.spec.ts @@ -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', () => { @@ -29,7 +28,10 @@ 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); }); }); @@ -37,14 +39,14 @@ describe('crypto', () => { 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), ); }); diff --git a/test/integration/addresses.spec.ts b/test/integration/addresses.spec.ts index 0b234c473..00858f3eb 100644 --- a/test/integration/addresses.spec.ts +++ b/test/integration/addresses.spec.ts @@ -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'; diff --git a/test/integration/bip32.spec.ts b/test/integration/bip32.spec.ts index ac1088b7e..354c4f011 100644 --- a/test/integration/bip32.spec.ts +++ b/test/integration/bip32.spec.ts @@ -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); diff --git a/test/integration/blocks.spec.ts b/test/integration/blocks.spec.ts index e1533f955..1b0c5762d 100644 --- a/test/integration/blocks.spec.ts +++ b/test/integration/blocks.spec.ts @@ -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', () => { diff --git a/test/integration/cltv.spec.ts b/test/integration/cltv.spec.ts index 0e532fc5b..b9ee5f9fe 100644 --- a/test/integration/cltv.spec.ts +++ b/test/integration/cltv.spec.ts @@ -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); diff --git a/test/integration/csv.spec.ts b/test/integration/csv.spec.ts index 6e8754e3a..68583f88d 100644 --- a/test/integration/csv.spec.ts +++ b/test/integration/csv.spec.ts @@ -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); diff --git a/test/integration/payments.spec.ts b/test/integration/payments.spec.ts index c0b2f4a24..1835a35a4 100644 --- a/test/integration/payments.spec.ts +++ b/test/integration/payments.spec.ts @@ -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'; diff --git a/test/integration/taproot.spec.ts b/test/integration/taproot.spec.ts index ec8e4071e..c6df6b1f0 100644 --- a/test/integration/taproot.spec.ts +++ b/test/integration/taproot.spec.ts @@ -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'; diff --git a/test/integration/transactions.spec.ts b/test/integration/transactions.spec.ts index 994af186b..4e457b1d9 100644 --- a/test/integration/transactions.spec.ts +++ b/test/integration/transactions.spec.ts @@ -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'; diff --git a/test/interpreter.spec.ts b/test/interpreter.spec.ts index 9a3c79adb..4ec10244f 100644 --- a/test/interpreter.spec.ts +++ b/test/interpreter.spec.ts @@ -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'; diff --git a/test/payments.spec.ts b/test/payments.spec.ts index d7128c0ab..d39b663fb 100644 --- a/test/payments.spec.ts +++ b/test/payments.spec.ts @@ -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, diff --git a/test/payments.utils.ts b/test/payments.utils.ts index a2bde3848..d235c1fd5 100644 --- a/test/payments.utils.ts +++ b/test/payments.utils.ts @@ -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); diff --git a/test/psbt.spec.ts b/test/psbt.spec.ts index 410c3ed7d..eb0178174 100644 --- a/test/psbt.spec.ts +++ b/test/psbt.spec.ts @@ -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); @@ -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); @@ -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(() => { @@ -1175,7 +1174,7 @@ describe(`Psbt`, () => { const list = [ { depth: 129, - leafVersion: LEAF_VERSION_TAPSCRIPT, + leafVersion: payments.LEAF_VERSION_TAPSCRIPT, script: Buffer.from([]), }, ]; diff --git a/test/script.spec.ts b/test/script.spec.ts index eba1a15c5..ec97b99a1 100644 --- a/test/script.spec.ts +++ b/test/script.spec.ts @@ -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'; diff --git a/test/script_number.spec.ts b/test/script_number.spec.ts index e0082f1fd..3e91071db 100644 --- a/test/script_number.spec.ts +++ b/test/script_number.spec.ts @@ -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'; diff --git a/test/script_signature.spec.ts b/test/script_signature.spec.ts index c798a053e..7acad31a8 100644 --- a/test/script_signature.spec.ts +++ b/test/script_signature.spec.ts @@ -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'; diff --git a/test/transaction.spec.ts b/test/transaction.spec.ts index e4c58cedf..e59b5825d 100644 --- a/test/transaction.spec.ts +++ b/test/transaction.spec.ts @@ -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'; diff --git a/test/types.spec.ts b/test/types.spec.ts index e258fa271..1c8d1736f 100644 --- a/test/types.spec.ts +++ b/test/types.spec.ts @@ -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', () => { diff --git a/ts_src/index.ts b/ts_src/index.ts index 68bb95890..0d7a297ab 100644 --- a/ts_src/index.ts +++ b/ts_src/index.ts @@ -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'; @@ -22,6 +25,8 @@ export { PaymentOpts, Stack, StackElement, + LEAF_VERSION_TAPSCRIPT, + tapleafHash, } from './payments/index.js'; export { Input as TxInput, diff --git a/ts_src/payments/index.ts b/ts_src/payments/index.ts index 2fe2bb54a..fced04f77 100644 --- a/ts_src/payments/index.ts +++ b/ts_src/payments/index.ts @@ -52,5 +52,6 @@ export type StackFunction = () => Stack; export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh, p2tr }; +export * from './bip341.js'; // TODO // witness commitment