@bsv/sdk 1.0.7 → 1.0.9
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 +1 -1
- package/dist/cjs/src/primitives/BigNumber.js +8 -5
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/index.js +3 -1
- package/dist/cjs/src/primitives/index.js.map +1 -1
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/BigNumber.js +8 -5
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/index.js +1 -0
- package/dist/esm/src/primitives/index.js.map +1 -1
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/index.d.ts +1 -0
- package/dist/types/src/primitives/index.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/examples/{EXAMPLE_PULSE_HEADERS.md → EXAMPLE_VERIFYING_ROOTS.md} +68 -66
- package/docs/low-level/USING_ECDSA.md +19 -0
- package/package.json +1 -1
- package/src/primitives/BigNumber.ts +8 -5
- package/src/primitives/index.ts +1 -0
- package/src/script/Spend.ts +0 -1
- package/src/script/__tests/Script.test.ts +11 -12
- package/src/script/__tests/Spend.test.ts +2 -4
- package/src/script/__tests/SpendComplex.test.ts +46 -0
- package/src/script/__tests/script.invalid.vectors.ts +2270 -828
- package/src/script/__tests/script.valid.vectors.ts +3115 -1021
- package/src/script/__tests/spend.valid.vectors.ts +1368 -1366
- package/dist/cjs/src/index.js +0 -5
- package/dist/cjs/src/index.js.map +0 -1
- package/dist/esm/src/index.js +0 -2
- package/dist/esm/src/index.js.map +0 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +0 -1
- package/src/script/__tests/scriptFromVector.ts +0 -42
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import BigNumber from '../../../dist/cjs/src/primitives/BigNumber'
|
|
2
1
|
import PrivateKey from '../../../dist/cjs/src/primitives/PrivateKey'
|
|
3
2
|
import { hash160, hash256 } from '../../../dist/cjs/src/primitives/Hash'
|
|
4
3
|
import Curve from '../../../dist/cjs/src/primitives/Curve'
|
|
@@ -6,7 +5,6 @@ import Spend from '../../../dist/cjs/src/script/Spend'
|
|
|
6
5
|
import P2PKH from '../../../dist/cjs/src/script/templates/P2PKH'
|
|
7
6
|
import RPuzzle from '../../../dist/cjs/src/script/templates/RPuzzle'
|
|
8
7
|
import Transaction from '../../../dist/cjs/src/transaction/Transaction'
|
|
9
|
-
import scriptFromVector from './scriptFromVector'
|
|
10
8
|
import LockingScript from '../../../dist/cjs/src/script/LockingScript'
|
|
11
9
|
import UnlockingScript from '../../../dist/cjs/src/script/UnlockingScript'
|
|
12
10
|
|
|
@@ -233,12 +231,12 @@ describe('Spend', () => {
|
|
|
233
231
|
sourceTXID: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
234
232
|
sourceOutputIndex: 0,
|
|
235
233
|
sourceSatoshis: 1,
|
|
236
|
-
lockingScript:
|
|
234
|
+
lockingScript: LockingScript.fromHex(a[1]),
|
|
237
235
|
transactionVersion: 1,
|
|
238
236
|
otherInputs: [],
|
|
239
237
|
outputs: [],
|
|
240
238
|
inputIndex: 0,
|
|
241
|
-
unlockingScript:
|
|
239
|
+
unlockingScript: UnlockingScript.fromHex(a[0]),
|
|
242
240
|
inputSequence: 0xffffffff,
|
|
243
241
|
lockTime: 0
|
|
244
242
|
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Script from "../../../dist/cjs/src/script/Script"
|
|
2
|
+
import Spend from "../../../dist/cjs/src/script/Spend"
|
|
3
|
+
import Transaction from "../../../dist/cjs/src/transaction/Transaction"
|
|
4
|
+
|
|
5
|
+
describe('SpendComplex', () => {
|
|
6
|
+
it('complex unlock script validation', () => {
|
|
7
|
+
const rawTx = '010000000130f9f05e6ff77b647f72a86c249204aa476d205a320e918d0ae589c1d17943f200000000fd8c0447304402205773ed93e743866c3b1987780d0e0fe79b83229e88ecc41caeb7028194ccbaa902201441eee38be05d8e041ca0ae4880c91e85f43e1a5209547cfb88dcf45dfdaa2dc2210253108f70a2a86ab671f7f8cbff55478d8fee1dd115ee34ada7778aa5407fe0f64d1f04010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030f9f05e6ff77b647f72a86c249204aa476d205a320e918d0ae589c1d17943f200000000fd80032097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000000014fb941ff552d7f5b07fe7cdb799f3a769a3818bba03ba6818615179567a75557a557a557a557a557a0079557a75547a547a547a547a757561577901c261517959795979210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce08105b795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169577961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a7561527a75517a57796100796100798277517951790128947f755179012c947f77517a75517a756161007901007e81517a7561517a7561517a75007905ffffffff009f6951795379a2695879a95479876959795979ac77777777777777777777e903000000000000feffffff0000000000000000000000000000000000000000000000000000000000000000ba681800c2000000feffffff02c8000000000000001976a91454193bbfcf6541e49d0a9e5b1aa40205eae76d6d88ac8e020000000000001976a91492e4a083b28a331b12d42d77d8b21126eaa9ccff88acba681800'
|
|
8
|
+
const lockingScript = '2097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c0000000014fb941ff552d7f5b07fe7cdb799f3a769a3818bba03ba6818615179567a75557a557a557a557a557a0079557a75547a547a547a547a757561577901c261517959795979210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce08105b795679615679aa0079610079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a75615779567956795679567961537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff00517951796151795179970079009f63007952799367007968517a75517a75517a7561527a75517a517951795296a0630079527994527a75517a6853798277527982775379012080517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01205279947f7754537993527993013051797e527e54797e58797e527e53797e52797e57797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75517a756169577961007961007982775179517954947f75517958947f77517a75517a756161007901007e81517a7561517a7561527a75517a57796100796100798277517951790128947f755179012c947f77517a75517a756161007901007e81517a7561517a7561517a75007905ffffffff009f6951795379a2695879a95479876959795979ac77777777777777777777'
|
|
9
|
+
const i = rawTx.indexOf(lockingScript.slice(0, 100))
|
|
10
|
+
const j = rawTx.indexOf(lockingScript.slice(lockingScript.length - 100))
|
|
11
|
+
if (i >= 0 && j >= 0) {
|
|
12
|
+
const pushtx = rawTx.slice(i, j + 100)
|
|
13
|
+
expect(pushtx).toBe(lockingScript)
|
|
14
|
+
}
|
|
15
|
+
const ok = validateUnlockScript(rawTx, 0, lockingScript, 1001)
|
|
16
|
+
expect(ok).toBe(true)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
function verifyTruthy<T>(v: T | undefined): T { if (v == null) throw new Error('must have value'); return v }
|
|
21
|
+
|
|
22
|
+
export function validateUnlockScript(spendingRawTx: string, vin: number, lockingScript: string, amount: number): boolean {
|
|
23
|
+
const spendingTx = Transaction.fromHex(spendingRawTx)
|
|
24
|
+
const ls = Script.fromHex(lockingScript)
|
|
25
|
+
|
|
26
|
+
const us = spendingTx.inputs[0].unlockingScript?.toASM()
|
|
27
|
+
const lsh = ls.toHex()
|
|
28
|
+
const lsa = ls.toASM()
|
|
29
|
+
|
|
30
|
+
const spend = new Spend({
|
|
31
|
+
sourceTXID: verifyTruthy(spendingTx.inputs[vin].sourceTXID),
|
|
32
|
+
sourceOutputIndex: spendingTx.inputs[vin].sourceOutputIndex,
|
|
33
|
+
sourceSatoshis: amount,
|
|
34
|
+
lockingScript: ls,
|
|
35
|
+
transactionVersion: spendingTx.version,
|
|
36
|
+
otherInputs: spendingTx.inputs.filter((v, i) => i !== vin),
|
|
37
|
+
inputIndex: vin,
|
|
38
|
+
unlockingScript: verifyTruthy(spendingTx.inputs[vin].unlockingScript),
|
|
39
|
+
outputs: spendingTx.outputs,
|
|
40
|
+
inputSequence: spendingTx.inputs[vin].sequence,
|
|
41
|
+
lockTime: spendingTx.lockTime
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const valid = spend.validate()
|
|
45
|
+
return valid
|
|
46
|
+
}
|