@bsv/sdk 1.6.18 → 1.6.20
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/README.md +11 -11
- package/dist/cjs/package.json +5 -9
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +39 -39
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/primitives/ECDSA.js +69 -167
- package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
- package/dist/cjs/src/primitives/Hash.js +660 -436
- package/dist/cjs/src/primitives/Hash.js.map +1 -1
- package/dist/cjs/src/primitives/Point.js +285 -293
- package/dist/cjs/src/primitives/Point.js.map +1 -1
- package/dist/cjs/src/script/ScriptEvaluationError.js +27 -0
- package/dist/cjs/src/script/ScriptEvaluationError.js.map +1 -0
- package/dist/cjs/src/script/Spend.js +13 -7
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/script/index.js +3 -1
- package/dist/cjs/src/script/index.js.map +1 -1
- package/dist/cjs/src/transaction/Beef.js +4 -4
- package/dist/cjs/src/transaction/Transaction.js +3 -3
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +39 -39
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/primitives/ECDSA.js +69 -167
- package/dist/esm/src/primitives/ECDSA.js.map +1 -1
- package/dist/esm/src/primitives/Hash.js +672 -444
- package/dist/esm/src/primitives/Hash.js.map +1 -1
- package/dist/esm/src/primitives/Point.js +268 -293
- package/dist/esm/src/primitives/Point.js.map +1 -1
- package/dist/esm/src/script/ScriptEvaluationError.js +33 -0
- package/dist/esm/src/script/ScriptEvaluationError.js.map +1 -0
- package/dist/esm/src/script/Spend.js +14 -8
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/script/index.js +1 -0
- package/dist/esm/src/script/index.js.map +1 -1
- package/dist/esm/src/transaction/Beef.js +4 -4
- package/dist/esm/src/transaction/Transaction.js +3 -3
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
- package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
- package/dist/types/src/primitives/Hash.d.ts +12 -19
- package/dist/types/src/primitives/Hash.d.ts.map +1 -1
- package/dist/types/src/primitives/Point.d.ts +37 -5
- package/dist/types/src/primitives/Point.d.ts.map +1 -1
- package/dist/types/src/script/ScriptEvaluationError.d.ts +24 -0
- package/dist/types/src/script/ScriptEvaluationError.d.ts.map +1 -0
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/script/index.d.ts +1 -0
- package/dist/types/src/script/index.d.ts.map +1 -1
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +20 -1
- package/dist/umd/bundle.js.map +1 -0
- package/package.json +5 -9
- package/src/auth/transports/SimplifiedFetchTransport.ts +64 -67
- package/src/primitives/ECDSA.ts +80 -222
- package/src/primitives/Hash.ts +752 -589
- package/src/primitives/Point.ts +277 -336
- package/src/script/ScriptEvaluationError.ts +44 -0
- package/src/script/Spend.ts +14 -12
- package/src/script/index.ts +1 -0
- package/src/transaction/Beef.ts +4 -4
- package/src/transaction/Transaction.ts +11 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { toHex } from '../primitives/utils.js'
|
|
2
|
+
export default class ScriptEvaluationError extends Error {
|
|
3
|
+
txid: string
|
|
4
|
+
outputIndex: number
|
|
5
|
+
context: 'UnlockingScript' | 'LockingScript'
|
|
6
|
+
programCounter: number
|
|
7
|
+
stackState: number[][]
|
|
8
|
+
altStackState: number[][]
|
|
9
|
+
ifStackState: boolean[]
|
|
10
|
+
stackMem: number
|
|
11
|
+
altStackMem: number
|
|
12
|
+
|
|
13
|
+
constructor (params: {
|
|
14
|
+
message: string
|
|
15
|
+
txid: string
|
|
16
|
+
outputIndex: number
|
|
17
|
+
context: 'UnlockingScript' | 'LockingScript'
|
|
18
|
+
programCounter: number
|
|
19
|
+
stackState: number[][]
|
|
20
|
+
altStackState: number[][]
|
|
21
|
+
ifStackState: boolean[]
|
|
22
|
+
stackMem: number
|
|
23
|
+
altStackMem: number
|
|
24
|
+
}) {
|
|
25
|
+
const stackHex = params.stackState.map(s => s != null && typeof s.length !== 'undefined' ? toHex(s) : (s === null || s === undefined ? 'null/undef' : 'INVALID_STACK_ITEM')).join(', ')
|
|
26
|
+
const altStackHex = params.altStackState.map(s => s != null && typeof s.length !== 'undefined' ? toHex(s) : (s === null || s === undefined ? 'null/undef' : 'INVALID_STACK_ITEM')).join(', ')
|
|
27
|
+
const pcInfo = `Context: ${params.context}, PC: ${params.programCounter}`
|
|
28
|
+
const stackInfo = `Stack: [${stackHex}] (len: ${params.stackState.length}, mem: ${params.stackMem})`
|
|
29
|
+
const altStackInfo = `AltStack: [${altStackHex}] (len: ${params.altStackState.length}, mem: ${params.altStackMem})`
|
|
30
|
+
const ifStackInfo = `IfStack: [${params.ifStackState.join(', ')}]`
|
|
31
|
+
const fullMessage = `Script evaluation error: ${params.message}\nTXID: ${params.txid}, OutputIdx: ${params.outputIndex}\n${pcInfo}\n${stackInfo}\n${altStackInfo}\n${ifStackInfo}`
|
|
32
|
+
super(fullMessage)
|
|
33
|
+
this.name = this.constructor.name
|
|
34
|
+
this.txid = params.txid
|
|
35
|
+
this.outputIndex = params.outputIndex
|
|
36
|
+
this.context = params.context
|
|
37
|
+
this.programCounter = params.programCounter
|
|
38
|
+
this.stackState = params.stackState.map(s => s.slice())
|
|
39
|
+
this.altStackState = params.altStackState.map(s => s.slice())
|
|
40
|
+
this.ifStackState = params.ifStackState.slice()
|
|
41
|
+
this.stackMem = params.stackMem
|
|
42
|
+
this.altStackMem = params.altStackMem
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/script/Spend.ts
CHANGED
|
@@ -4,7 +4,8 @@ import Script from './Script.js'
|
|
|
4
4
|
import BigNumber from '../primitives/BigNumber.js'
|
|
5
5
|
import OP from './OP.js'
|
|
6
6
|
import ScriptChunk from './ScriptChunk.js'
|
|
7
|
-
import {
|
|
7
|
+
import { minimallyEncode } from '../primitives/utils.js'
|
|
8
|
+
import ScriptEvaluationError from './ScriptEvaluationError.js'
|
|
8
9
|
import * as Hash from '../primitives/Hash.js'
|
|
9
10
|
import TransactionSignature from '../primitives/TransactionSignature.js'
|
|
10
11
|
import PublicKey from '../primitives/PublicKey.js'
|
|
@@ -1054,16 +1055,17 @@ export default class Spend {
|
|
|
1054
1055
|
}
|
|
1055
1056
|
|
|
1056
1057
|
private scriptEvaluationError (str: string): void {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1058
|
+
throw new ScriptEvaluationError({
|
|
1059
|
+
message: str,
|
|
1060
|
+
txid: this.sourceTXID,
|
|
1061
|
+
outputIndex: this.sourceOutputIndex,
|
|
1062
|
+
context: this.context,
|
|
1063
|
+
programCounter: this.programCounter,
|
|
1064
|
+
stackState: this.stack,
|
|
1065
|
+
altStackState: this.altStack,
|
|
1066
|
+
ifStackState: this.ifStack,
|
|
1067
|
+
stackMem: this.stackMem,
|
|
1068
|
+
altStackMem: this.altStackMem
|
|
1069
|
+
})
|
|
1068
1070
|
}
|
|
1069
1071
|
}
|
package/src/script/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { default as LockingScript } from './LockingScript.js'
|
|
|
4
4
|
export { default as UnlockingScript } from './UnlockingScript.js'
|
|
5
5
|
export { default as Spend } from './Spend.js'
|
|
6
6
|
export type { default as ScriptTemplateUnlock } from './ScriptTemplateUnlock.js'
|
|
7
|
+
export { default as ScriptEvaluationError } from './ScriptEvaluationError.js'
|
|
7
8
|
export type { default as ScriptTemplate } from './ScriptTemplate.js'
|
|
8
9
|
export * from './templates/index.js'
|
|
9
10
|
export type { default as ScriptChunk } from './ScriptChunk.js'
|
package/src/transaction/Beef.ts
CHANGED
|
@@ -21,18 +21,18 @@ export enum TX_DATA_FORMAT {
|
|
|
21
21
|
|
|
22
22
|
/*
|
|
23
23
|
* BEEF standard: BRC-62: Background Evaluation Extended Format (BEEF) Transactions
|
|
24
|
-
* https://github.com/
|
|
24
|
+
* https://github.com/bsv-blockchain/BRCs/blob/master/transactions/0062.md
|
|
25
25
|
*
|
|
26
26
|
* BUMP standard: BRC-74: BSV Unified Merkle Path (BUMP) Format
|
|
27
|
-
* https://github.com/
|
|
27
|
+
* https://github.com/bsv-blockchain/BRCs/blob/master/transactions/0074.md
|
|
28
28
|
*
|
|
29
29
|
* BRC-95: Atomic BEEF Transactions
|
|
30
|
-
* https://github.com/
|
|
30
|
+
* https://github.com/bsv-blockchain/BRCs/blob/master/transactions/0095.md
|
|
31
31
|
*
|
|
32
32
|
* The Atomic BEEF format is supported by the binary deserialization static method `fromBinary`.
|
|
33
33
|
*
|
|
34
34
|
* BRC-96: BEEF V2, Txid Only Extension
|
|
35
|
-
* https://github.com/
|
|
35
|
+
* https://github.com/bsv-blockchain/BRCs/blob/master/transactions/0096.md
|
|
36
36
|
*
|
|
37
37
|
* A valid serialized BEEF is the cornerstone of Simplified Payment Validation (SPV)
|
|
38
38
|
* where they are exchanged between two non-trusting parties to establish the
|
|
@@ -119,7 +119,11 @@ export default class Transaction {
|
|
|
119
119
|
static fromAtomicBEEF (beef: number[]): Transaction {
|
|
120
120
|
const { tx, txid, beef: b } = Transaction.fromAnyBeef(beef)
|
|
121
121
|
if (txid !== b.atomicTxid) {
|
|
122
|
-
if (b.atomicTxid
|
|
122
|
+
if (b.atomicTxid != null) {
|
|
123
|
+
throw new Error(`Transaction with TXID ${b.atomicTxid} not found in BEEF data.`)
|
|
124
|
+
} else {
|
|
125
|
+
throw new Error('beef must conform to BRC-95 and must contain the subject txid.')
|
|
126
|
+
}
|
|
123
127
|
}
|
|
124
128
|
return tx
|
|
125
129
|
}
|
|
@@ -129,10 +133,14 @@ export default class Transaction {
|
|
|
129
133
|
if (b.txs.length < 1) {
|
|
130
134
|
throw new Error('beef must include at least one transaction.')
|
|
131
135
|
}
|
|
132
|
-
const target = txid
|
|
136
|
+
const target = txid ?? b.atomicTxid ?? b.txs.slice(-1)[0].txid
|
|
133
137
|
const tx = b.findAtomicTransaction(target)
|
|
134
138
|
if (tx == null) {
|
|
135
|
-
if (txid
|
|
139
|
+
if (txid != null) {
|
|
140
|
+
throw new Error(`Transaction with TXID ${target} not found in BEEF data.`)
|
|
141
|
+
} else {
|
|
142
|
+
throw new Error('beef does not contain transaction for atomic txid.')
|
|
143
|
+
}
|
|
136
144
|
}
|
|
137
145
|
return { tx, beef: b, txid: target }
|
|
138
146
|
}
|