@bsv/sdk 1.0.4 → 1.0.5
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/src/primitives/BigNumber.js +1 -1
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/SymmetricKey.js +1 -1
- package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +3 -2
- 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 +1 -1
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/SymmetricKey.js +1 -1
- package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/esm/src/script/Spend.js +3 -2
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/SymmetricKey.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_BUILDING_CUSTOM_TX_BROADCASTER.md +89 -0
- package/docs/examples/EXAMPLE_COMPLEX_TX.md +164 -0
- package/docs/examples/EXAMPLE_ECIES.md +37 -0
- package/docs/examples/EXAMPLE_ENCRYPT_DECRYPT_MESSAGE.md +52 -0
- package/docs/examples/EXAMPLE_FEE_MODELING.md +199 -0
- package/docs/examples/EXAMPLE_HD_WALLETS.md +71 -0
- package/docs/examples/EXAMPLE_MESSAGE_SIGNING.md +63 -0
- package/docs/examples/EXAMPLE_PULSE_HEADERS.md +140 -0
- package/docs/examples/EXAMPLE_SCRIPT_TEMPLATES.md +170 -0
- package/docs/examples/EXAMPLE_SIMPLE_TX.md +64 -0
- package/docs/examples/EXAMPLE_TYPE_42.md +108 -0
- package/docs/examples/EXAMPLE_VERIFYING_BEEF.md +55 -0
- package/docs/examples/EXAMPLE_VERIFYING_SPENDS.md +69 -0
- package/docs/examples/GETTING_STARTED_NODE_CJS.md +73 -0
- package/docs/examples/GETTING_STARTED_REACT.md +121 -0
- package/docs/examples/README.md +19 -0
- package/docs/low-level/README.md +6 -0
- package/docs/low-level/TX_SIG.md +129 -0
- package/docs/low-level/TYPE_42.md +0 -0
- package/docs/primitives.md +585 -562
- package/docs/script.md +4 -4
- package/package.json +1 -1
- package/src/primitives/BigNumber.ts +2 -1
- package/src/primitives/Hash.ts +118 -64
- package/src/primitives/PrivateKey.ts +28 -1
- package/src/primitives/PublicKey.ts +24 -2
- package/src/primitives/SymmetricKey.ts +17 -3
- package/src/primitives/__tests/HMAC.test.ts +2 -2
- package/src/primitives/__tests/Hash.test.ts +2 -2
- package/src/primitives/index.ts +1 -0
- package/src/primitives/utils.ts +3 -3
- package/src/script/__tests/Script.test.ts +34 -0
- package/src/script/__tests/Spend.test.ts +7 -7
- package/src/script/templates/P2PKH.ts +13 -4
- package/src/transaction/__tests/Transaction.test.ts +1 -1
|
@@ -19,7 +19,7 @@ describe('Spend', () => {
|
|
|
19
19
|
const hash = publicKey.toHash()
|
|
20
20
|
const p2pkh = new P2PKH()
|
|
21
21
|
const lockingScript = p2pkh.lock(hash)
|
|
22
|
-
const satoshis =
|
|
22
|
+
const satoshis = 1
|
|
23
23
|
const unlockingTemplate = p2pkh.unlock(privateKey)
|
|
24
24
|
const sourceTx = new Transaction(1, [], [{
|
|
25
25
|
lockingScript,
|
|
@@ -54,7 +54,7 @@ describe('Spend', () => {
|
|
|
54
54
|
const hash = publicKey.toHash()
|
|
55
55
|
const p2pkh = new P2PKH()
|
|
56
56
|
const lockingScript = p2pkh.lock(hash)
|
|
57
|
-
const satoshis =
|
|
57
|
+
const satoshis = 1
|
|
58
58
|
const unlockingTemplate = p2pkh.unlock(wrongPrivateKey)
|
|
59
59
|
const sourceTx = new Transaction(1, [], [{
|
|
60
60
|
lockingScript,
|
|
@@ -88,7 +88,7 @@ describe('Spend', () => {
|
|
|
88
88
|
r = r[0] > 127 ? [0, ...r] : r
|
|
89
89
|
const puz = new RPuzzle()
|
|
90
90
|
const lockingScript = puz.lock(r)
|
|
91
|
-
const satoshis =
|
|
91
|
+
const satoshis = 1
|
|
92
92
|
const unlockingTemplate = puz.unlock(k)
|
|
93
93
|
const sourceTx = new Transaction(1, [], [{
|
|
94
94
|
lockingScript,
|
|
@@ -124,7 +124,7 @@ describe('Spend', () => {
|
|
|
124
124
|
r = hash256(r)
|
|
125
125
|
const puz = new RPuzzle('HASH256')
|
|
126
126
|
const lockingScript = puz.lock(r)
|
|
127
|
-
const satoshis =
|
|
127
|
+
const satoshis = 1
|
|
128
128
|
const unlockingTemplate = puz.unlock(k)
|
|
129
129
|
const sourceTx = new Transaction(1, [], [{
|
|
130
130
|
lockingScript,
|
|
@@ -161,7 +161,7 @@ describe('Spend', () => {
|
|
|
161
161
|
r = hash256(r)
|
|
162
162
|
const puz = new RPuzzle('HASH256')
|
|
163
163
|
const lockingScript = puz.lock(r)
|
|
164
|
-
const satoshis =
|
|
164
|
+
const satoshis = 1
|
|
165
165
|
const unlockingTemplate = puz.unlock(wrongK)
|
|
166
166
|
const sourceTx = new Transaction(1, [], [{
|
|
167
167
|
lockingScript,
|
|
@@ -196,7 +196,7 @@ describe('Spend', () => {
|
|
|
196
196
|
r = hash160(r)
|
|
197
197
|
const puz = new RPuzzle('HASH256')
|
|
198
198
|
const lockingScript = puz.lock(r)
|
|
199
|
-
const satoshis =
|
|
199
|
+
const satoshis = 1
|
|
200
200
|
const unlockingTemplate = puz.unlock(k)
|
|
201
201
|
const sourceTx = new Transaction(1, [], [{
|
|
202
202
|
lockingScript,
|
|
@@ -232,7 +232,7 @@ describe('Spend', () => {
|
|
|
232
232
|
const spend = new Spend({
|
|
233
233
|
sourceTXID: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
234
234
|
sourceOutputIndex: 0,
|
|
235
|
-
sourceSatoshis:
|
|
235
|
+
sourceSatoshis: 1,
|
|
236
236
|
lockingScript: new LockingScript(scriptFromVector(a[1]).chunks),
|
|
237
237
|
transactionVersion: 1,
|
|
238
238
|
otherInputs: [],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import OP from '../OP.js'
|
|
2
2
|
import ScriptTemplate from '../ScriptTemplate.js'
|
|
3
|
+
import { fromBase58Check } from '../../primitives/utils.js'
|
|
3
4
|
import LockingScript from '../LockingScript.js'
|
|
4
5
|
import UnlockingScript from '../UnlockingScript.js'
|
|
5
6
|
import Transaction from '../../transaction/Transaction.js'
|
|
@@ -14,16 +15,24 @@ import { sha256 } from '../../primitives/Hash.js'
|
|
|
14
15
|
*/
|
|
15
16
|
export default class P2PKH implements ScriptTemplate {
|
|
16
17
|
/**
|
|
17
|
-
* Creates a P2PKH locking script for a given public key hash
|
|
18
|
+
* Creates a P2PKH locking script for a given public key hash or address string
|
|
18
19
|
*
|
|
19
|
-
* @param {number[]} pubkeyhash - An array representing the public key hash.
|
|
20
|
+
* @param {number[] | string} pubkeyhash or address - An array or address representing the public key hash.
|
|
20
21
|
* @returns {LockingScript} - A P2PKH locking script.
|
|
21
22
|
*/
|
|
22
|
-
lock(pubkeyhash: number[]): LockingScript {
|
|
23
|
+
lock(pubkeyhash: string | number[]): LockingScript {
|
|
24
|
+
let data: number[]
|
|
25
|
+
if (typeof pubkeyhash === 'string') {
|
|
26
|
+
const hash = fromBase58Check(pubkeyhash)
|
|
27
|
+
if (hash.prefix[0] !== 0x00 && hash.prefix[0] !== 0x6f) throw new Error('only P2PKH is supported')
|
|
28
|
+
data = hash.data as number[]
|
|
29
|
+
} else {
|
|
30
|
+
data = pubkeyhash
|
|
31
|
+
}
|
|
23
32
|
return new LockingScript([
|
|
24
33
|
{ op: OP.OP_DUP },
|
|
25
34
|
{ op: OP.OP_HASH160 },
|
|
26
|
-
{ op: pubkeyhash.length, data
|
|
35
|
+
{ op: pubkeyhash.length, data },
|
|
27
36
|
{ op: OP.OP_EQUALVERIFY },
|
|
28
37
|
{ op: OP.OP_CHECKSIG }
|
|
29
38
|
])
|
|
@@ -317,7 +317,7 @@ describe('Transaction', () => {
|
|
|
317
317
|
|
|
318
318
|
describe('Verification', () => {
|
|
319
319
|
it('Verifies the transaction from the BEEF spec', async () => {
|
|
320
|
-
const tx = Transaction.
|
|
320
|
+
const tx = Transaction.fromHexBEEF(BRC62Hex)
|
|
321
321
|
const alwaysYesChainTracker = {
|
|
322
322
|
isValidRootForHeight: async () => true
|
|
323
323
|
}
|