@bsv/sdk 2.1.4 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +7 -7
- package/dist/cjs/src/compat/Utxo.js +1 -1
- package/dist/cjs/src/compat/Utxo.js.map +1 -1
- package/dist/cjs/src/kvstore/GlobalKVStore.js +18 -3
- package/dist/cjs/src/kvstore/GlobalKVStore.js.map +1 -1
- package/dist/cjs/src/kvstore/types.js.map +1 -1
- package/dist/cjs/src/primitives/Hash.js +4 -2
- package/dist/cjs/src/primitives/Hash.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +8 -1
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/transaction/BdkVerifierInterface.js +3 -0
- package/dist/cjs/src/transaction/BdkVerifierInterface.js.map +1 -0
- package/dist/cjs/src/transaction/Transaction.js +35 -16
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/src/transaction/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/compat/Utxo.js +1 -1
- package/dist/esm/src/compat/Utxo.js.map +1 -1
- package/dist/esm/src/kvstore/GlobalKVStore.js +18 -3
- package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
- package/dist/esm/src/kvstore/types.js.map +1 -1
- package/dist/esm/src/primitives/Hash.js +4 -2
- package/dist/esm/src/primitives/Hash.js.map +1 -1
- package/dist/esm/src/script/Spend.js +8 -1
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/transaction/BdkVerifierInterface.js +2 -0
- package/dist/esm/src/transaction/BdkVerifierInterface.js.map +1 -0
- package/dist/esm/src/transaction/Transaction.js +35 -16
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/src/transaction/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
- package/dist/types/src/kvstore/types.d.ts +27 -0
- package/dist/types/src/kvstore/types.d.ts.map +1 -1
- package/dist/types/src/primitives/Hash.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/transaction/BdkVerifierInterface.d.ts +22 -0
- package/dist/types/src/transaction/BdkVerifierInterface.d.ts.map +1 -0
- package/dist/types/src/transaction/Transaction.d.ts +2 -1
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/src/transaction/index.d.ts +1 -0
- package/dist/types/src/transaction/index.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +3 -3
- package/package.json +7 -7
- package/src/compat/Utxo.ts +1 -1
- package/src/compat/__tests/Mnemonic.additional.test.ts +1 -1
- package/src/compat/__tests/Mnemonic.test.ts +1 -1
- package/src/kvstore/GlobalKVStore.ts +18 -3
- package/src/kvstore/__tests/GlobalKVStore.test.ts +36 -0
- package/src/kvstore/types.ts +28 -0
- package/src/overlay-tools/__tests/Historian.test.ts +1 -1
- package/src/overlay-tools/__tests/HostReputationTracker.additional.test.ts +1 -1
- package/src/primitives/Hash.ts +4 -2
- package/src/primitives/__tests/BigNumber.constructor.test.ts +1 -1
- package/src/primitives/__tests/DRBG.test.ts +4 -12
- package/src/primitives/__tests/Point.additional.test.ts +2 -2
- package/src/primitives/__tests/Point.test.ts +1 -1
- package/src/primitives/__tests/SymmetricKeyCompatibility.test.ts +4 -4
- package/src/registry/__tests/RegistryClient.additional.test.ts +4 -4
- package/src/registry/__tests/RegistryClient.test.ts +2 -2
- package/src/script/Spend.ts +8 -1
- package/src/script/__tests/Spend.codeseparator.test.ts +88 -0
- package/src/storage/__tests/StorageUploader.test.ts +7 -7
- package/src/transaction/BdkVerifierInterface.ts +22 -0
- package/src/transaction/Transaction.ts +40 -17
- package/src/transaction/__tests/Transaction.test.ts +3 -3
- package/src/transaction/__tests/Transaction.verifier.test.ts +72 -0
- package/src/transaction/index.ts +1 -0
|
@@ -703,7 +703,7 @@ describe('Transaction', () => {
|
|
|
703
703
|
sequence: 0xffffffff
|
|
704
704
|
}
|
|
705
705
|
],
|
|
706
|
-
Array(21)
|
|
706
|
+
new Array(21)
|
|
707
707
|
.fill(null)
|
|
708
708
|
.map(() => ({
|
|
709
709
|
lockingScript: p2pkh.lock(publicKeyHash),
|
|
@@ -1508,7 +1508,7 @@ describe('Transaction', () => {
|
|
|
1508
1508
|
|
|
1509
1509
|
tx.addInput({
|
|
1510
1510
|
sourceTXID: txid,
|
|
1511
|
-
sourceOutputIndex: parseInt(voutStr),
|
|
1511
|
+
sourceOutputIndex: Number.parseInt(voutStr),
|
|
1512
1512
|
unlockingScript
|
|
1513
1513
|
})
|
|
1514
1514
|
}
|
|
@@ -1553,7 +1553,7 @@ describe('Transaction', () => {
|
|
|
1553
1553
|
for (const [index, spend] of Object.entries(args.spends)) {
|
|
1554
1554
|
tx.addInput({
|
|
1555
1555
|
sourceTXID: '00'.repeat(32),
|
|
1556
|
-
sourceOutputIndex: parseInt(index),
|
|
1556
|
+
sourceOutputIndex: Number.parseInt(index),
|
|
1557
1557
|
unlockingScript: Script.fromHex((spend as any).unlockingScript)
|
|
1558
1558
|
})
|
|
1559
1559
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import Transaction from '../Transaction'
|
|
2
|
+
import Script from '../../script/Script'
|
|
3
|
+
import P2PKH from '../../script/templates/P2PKH'
|
|
4
|
+
import PrivateKey from '../../primitives/PrivateKey'
|
|
5
|
+
import MerklePath from '../MerklePath'
|
|
6
|
+
import type BdkVerifierInterface from '../BdkVerifierInterface'
|
|
7
|
+
|
|
8
|
+
// Build a tx whose single P2PKH input is genuinely valid under the pure-JS interpreter.
|
|
9
|
+
async function buildValidTx (): Promise<Transaction> {
|
|
10
|
+
const key = PrivateKey.fromRandom()
|
|
11
|
+
const source = new Transaction()
|
|
12
|
+
source.addInput({
|
|
13
|
+
sourceTXID: '00'.repeat(32),
|
|
14
|
+
sourceOutputIndex: 0,
|
|
15
|
+
unlockingScript: Script.fromASM('OP_TRUE')
|
|
16
|
+
})
|
|
17
|
+
source.addOutput({ satoshis: 2, lockingScript: new P2PKH().lock(key.toAddress()) })
|
|
18
|
+
await source.sign()
|
|
19
|
+
source.merklePath = new MerklePath(1000, [
|
|
20
|
+
[{ offset: 0, hash: source.id('hex'), txid: true }, { offset: 1, duplicate: true }]
|
|
21
|
+
])
|
|
22
|
+
|
|
23
|
+
const tx = new Transaction()
|
|
24
|
+
tx.addInput({
|
|
25
|
+
sourceTransaction: source,
|
|
26
|
+
sourceOutputIndex: 0,
|
|
27
|
+
unlockingScriptTemplate: new P2PKH().unlock(key)
|
|
28
|
+
})
|
|
29
|
+
tx.addOutput({ satoshis: 1, lockingScript: new P2PKH().lock(key.toAddress()) })
|
|
30
|
+
await tx.sign()
|
|
31
|
+
return tx
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('Transaction.verify with a pluggable verifier', () => {
|
|
35
|
+
it('routes to the verifier and returns its false result, bypassing Spend', async () => {
|
|
36
|
+
const tx = await buildValidTx()
|
|
37
|
+
let called = 0
|
|
38
|
+
const verifier: BdkVerifierInterface = {
|
|
39
|
+
verifyScripts: async () => { called++; return false }
|
|
40
|
+
}
|
|
41
|
+
// Pure-JS would return true; verifier says false -> proves bypass + routing.
|
|
42
|
+
const result = await tx.verify('scripts only', undefined, undefined, verifier)
|
|
43
|
+
expect(called).toBe(1)
|
|
44
|
+
expect(result).toBe(false)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('returns true when the verifier approves', async () => {
|
|
48
|
+
const tx = await buildValidTx()
|
|
49
|
+
const verifier: BdkVerifierInterface = { verifyScripts: async () => true }
|
|
50
|
+
const result = await tx.verify('scripts only', undefined, undefined, verifier)
|
|
51
|
+
expect(result).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('propagates a verifier throw (strict, no fallback)', async () => {
|
|
55
|
+
const tx = await buildValidTx()
|
|
56
|
+
const verifier: BdkVerifierInterface = {
|
|
57
|
+
verifyScripts: async () => { throw new Error('wasm unavailable') }
|
|
58
|
+
}
|
|
59
|
+
await expect(tx.verify('scripts only', undefined, undefined, verifier))
|
|
60
|
+
.rejects.toThrow('wasm unavailable')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('passes the post-Chronicle fallback blockHeight (943816) to the verifier', async () => {
|
|
64
|
+
const tx = await buildValidTx() // unmined tx -> no merkle proof -> fallback height
|
|
65
|
+
let seenHeight = -1
|
|
66
|
+
const verifier: BdkVerifierInterface = {
|
|
67
|
+
verifyScripts: async ({ blockHeight }) => { seenHeight = blockHeight; return true }
|
|
68
|
+
}
|
|
69
|
+
await tx.verify('scripts only', undefined, undefined, verifier)
|
|
70
|
+
expect(seenHeight).toBe(943816)
|
|
71
|
+
})
|
|
72
|
+
})
|
package/src/transaction/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as Transaction } from './Transaction.js'
|
|
2
|
+
export type { default as BdkVerifierInterface } from './BdkVerifierInterface.js'
|
|
2
3
|
export { default as MerklePath } from './MerklePath.js'
|
|
3
4
|
export type { default as TransactionInput } from './TransactionInput.js'
|
|
4
5
|
export type { default as TransactionOutput } from './TransactionOutput.js'
|