@bsv/sdk 2.0.12 → 2.0.14
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 +2 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js +827 -0
- package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +1 -0
- package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +654 -0
- package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +1 -0
- package/dist/cjs/src/identity/IdentityClient.js +3 -3
- package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
- package/dist/cjs/src/identity/types/index.js +1 -1
- package/dist/cjs/src/identity/types/index.js.map +1 -1
- package/dist/cjs/src/storage/StorageUploader.js +315 -96
- package/dist/cjs/src/storage/StorageUploader.js.map +1 -1
- package/dist/cjs/src/storage/index.js +3 -1
- package/dist/cjs/src/storage/index.js.map +1 -1
- package/dist/cjs/src/transaction/MerklePath.js +132 -0
- package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
- package/dist/cjs/src/wallet/WERR_REVIEW_ACTIONS.js +2 -2
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js +825 -0
- package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +1 -0
- package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +619 -0
- package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +1 -0
- package/dist/esm/src/identity/IdentityClient.js +3 -3
- package/dist/esm/src/identity/IdentityClient.js.map +1 -1
- package/dist/esm/src/identity/types/index.js +1 -1
- package/dist/esm/src/identity/types/index.js.map +1 -1
- package/dist/esm/src/storage/StorageUploader.js +319 -95
- package/dist/esm/src/storage/StorageUploader.js.map +1 -1
- package/dist/esm/src/storage/index.js +1 -1
- package/dist/esm/src/storage/index.js.map +1 -1
- package/dist/esm/src/transaction/MerklePath.js +132 -0
- package/dist/esm/src/transaction/MerklePath.js.map +1 -1
- package/dist/esm/src/wallet/WERR_REVIEW_ACTIONS.js +2 -2
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts +21 -0
- package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts.map +1 -0
- package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts +2 -0
- package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts.map +1 -0
- package/dist/types/src/storage/StorageUploader.d.ts +94 -55
- package/dist/types/src/storage/StorageUploader.d.ts.map +1 -1
- package/dist/types/src/storage/index.d.ts +1 -1
- package/dist/types/src/storage/index.d.ts.map +1 -1
- package/dist/types/src/transaction/MerklePath.d.ts +27 -0
- package/dist/types/src/transaction/MerklePath.d.ts.map +1 -1
- package/dist/types/src/wallet/WERR_REVIEW_ACTIONS.d.ts +2 -2
- package/dist/types/src/wallet/Wallet.interfaces.d.ts +2 -2
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +4 -4
- package/dist/umd/bundle.js.map +1 -1
- package/docs/index.md +3 -1
- package/docs/reference/identity.md +1 -1
- package/docs/reference/storage.md +215 -86
- package/docs/reference/transaction.md +40 -0
- package/docs/reference/wallet.md +4 -4
- package/package.json +1 -1
- package/src/auth/clients/__tests__/AuthFetch.additional.test.ts +1131 -0
- package/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.ts +770 -0
- package/src/compat/__tests/Mnemonic.additional.test.ts +64 -0
- package/src/identity/IdentityClient.ts +3 -3
- package/src/identity/__tests/IdentityClient.additional.test.ts +767 -0
- package/src/identity/types/index.ts +1 -1
- package/src/kvstore/__tests/LocalKVStore.additional.test.ts +611 -0
- package/src/kvstore/__tests/kvStoreInterpreter.test.ts +327 -0
- package/src/overlay-tools/__tests/HostReputationTracker.additional.test.ts +561 -0
- package/src/overlay-tools/__tests/LookupResolver.additional.test.ts +612 -0
- package/src/overlay-tools/__tests/withDoubleSpendRetry.test.ts +278 -0
- package/src/primitives/__tests/BigNumber.additional.test.ts +79 -0
- package/src/primitives/__tests/Curve.additional.test.ts +208 -0
- package/src/primitives/__tests/ECDSA.additional.test.ts +122 -0
- package/src/primitives/__tests/Hash.additional.test.ts +59 -0
- package/src/primitives/__tests/JacobianPoint.test.ts +308 -0
- package/src/primitives/__tests/Point.additional.test.ts +503 -0
- package/src/primitives/__tests/PublicKey.additional.test.ts +383 -0
- package/src/primitives/__tests/Random.additional.test.ts +262 -0
- package/src/primitives/__tests/Signature.test.ts +333 -0
- package/src/primitives/__tests/TransactionSignature.additional.test.ts +241 -0
- package/src/registry/__tests/RegistryClient.additional.test.ts +750 -0
- package/src/remittance/__tests/BasicBRC29.additional.test.ts +657 -0
- package/src/remittance/__tests/RemittanceManager.additional.test.ts +1272 -0
- package/src/script/__tests/LockingUnlockingScript.test.ts +79 -0
- package/src/script/__tests/Script.additional.test.ts +100 -0
- package/src/script/__tests/ScriptEvaluationError.test.ts +98 -0
- package/src/script/__tests/Spend.additional.test.ts +837 -0
- package/src/script/templates/__tests/RPuzzle.test.ts +134 -0
- package/src/storage/StorageUploader.ts +427 -105
- package/src/storage/__tests/StorageUploader.test.ts +881 -64
- package/src/storage/index.ts +1 -1
- package/src/transaction/MerklePath.ts +155 -0
- package/src/transaction/__tests/BeefParty.additional.test.ts +22 -0
- package/src/transaction/__tests/Broadcaster.test.ts +159 -0
- package/src/transaction/__tests/MerklePath.bench.test.ts +105 -0
- package/src/transaction/__tests/MerklePath.test.ts +80 -0
- package/src/transaction/__tests/Transaction.additional.test.ts +225 -0
- package/src/transaction/broadcasters/__tests/ARC.additional.test.ts +585 -0
- package/src/transaction/broadcasters/__tests/Teranode.test.ts +349 -0
- package/src/transaction/chaintrackers/__tests/BlockHeadersService.test.ts +253 -0
- package/src/transaction/chaintrackers/__tests/DefaultChainTracker.test.ts +44 -0
- package/src/transaction/chaintrackers/__tests/WhatsOnChain.additional.test.ts +193 -0
- package/src/transaction/fee-models/__tests/SatoshisPerKilobyte.test.ts +262 -0
- package/src/transaction/http/__tests/BinaryFetchClient.test.ts +212 -0
- package/src/transaction/http/__tests/DefaultHttpClient.additional.test.ts +192 -0
- package/src/transaction/http/__tests/DefaultHttpClient.test.ts +71 -0
- package/src/wallet/WERR_REVIEW_ACTIONS.ts +2 -2
- package/src/wallet/Wallet.interfaces.ts +2 -2
- package/src/wallet/__tests/ProtoWallet.additional.test.ts +134 -0
- package/src/wallet/__tests/WERR.test.ts +212 -0
- package/src/wallet/__tests/WalletClient.additional.test.ts +699 -0
- package/src/wallet/__tests/WalletClient.substrate.test.ts +759 -0
- package/src/wallet/__tests/WalletError.test.ts +290 -0
- package/src/wallet/__tests/validationHelpers.test.ts +1218 -0
- package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +496 -0
- package/src/wallet/substrates/__tests/HTTPWalletWire.test.ts +273 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import RPuzzle from '../RPuzzle'
|
|
2
|
+
import Spend from '../../Spend'
|
|
3
|
+
import LockingScript from '../../LockingScript'
|
|
4
|
+
import Transaction from '../../../transaction/Transaction'
|
|
5
|
+
import PrivateKey from '../../../primitives/PrivateKey'
|
|
6
|
+
import BigNumber from '../../../primitives/BigNumber'
|
|
7
|
+
import Curve from '../../../primitives/Curve'
|
|
8
|
+
|
|
9
|
+
const ZERO_TXID = '0'.repeat(64)
|
|
10
|
+
|
|
11
|
+
function getRValue (k: BigNumber): number[] {
|
|
12
|
+
const c = new Curve()
|
|
13
|
+
let r = c.g.mul(k).x?.umod(c.n)?.toArray()
|
|
14
|
+
if (r == null) return []
|
|
15
|
+
if (r[0] > 127) r = [0, ...r]
|
|
16
|
+
return r
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function buildRPuzzleSpend (
|
|
20
|
+
puz: RPuzzle,
|
|
21
|
+
k: BigNumber,
|
|
22
|
+
privateKey: PrivateKey,
|
|
23
|
+
r: number[],
|
|
24
|
+
signOutputs: 'all' | 'none' | 'single' = 'all',
|
|
25
|
+
anyoneCanPay: boolean = false
|
|
26
|
+
): Promise<Spend> {
|
|
27
|
+
const lockingScript: LockingScript = puz.lock(r)
|
|
28
|
+
const sourceTx = new Transaction(1, [], [{ lockingScript, satoshis: 1 }], 0)
|
|
29
|
+
const spendTx = new Transaction(
|
|
30
|
+
1,
|
|
31
|
+
[{ sourceTransaction: sourceTx, sourceOutputIndex: 0, sequence: 0xffffffff }],
|
|
32
|
+
[{ lockingScript: LockingScript.fromASM('OP_1'), satoshis: 1 }],
|
|
33
|
+
0
|
|
34
|
+
)
|
|
35
|
+
const unlockingScript = await puz.unlock(k, privateKey, signOutputs, anyoneCanPay).sign(spendTx, 0)
|
|
36
|
+
return new Spend({
|
|
37
|
+
sourceTXID: sourceTx.id('hex'),
|
|
38
|
+
sourceOutputIndex: 0,
|
|
39
|
+
sourceSatoshis: 1,
|
|
40
|
+
lockingScript,
|
|
41
|
+
transactionVersion: 1,
|
|
42
|
+
otherInputs: [],
|
|
43
|
+
outputs: spendTx.outputs,
|
|
44
|
+
inputIndex: 0,
|
|
45
|
+
unlockingScript,
|
|
46
|
+
inputSequence: 0xffffffff,
|
|
47
|
+
lockTime: 0
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe('RPuzzle – additional coverage', () => {
|
|
52
|
+
const k = new BigNumber(12345678)
|
|
53
|
+
const privateKey = new PrivateKey(1)
|
|
54
|
+
const r = getRValue(k)
|
|
55
|
+
|
|
56
|
+
describe('signOutputs variations', () => {
|
|
57
|
+
it('signs with signOutputs=none', async () => {
|
|
58
|
+
const puz = new RPuzzle()
|
|
59
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, r, 'none')
|
|
60
|
+
expect(spend.validate()).toBe(true)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('signs with signOutputs=single', async () => {
|
|
64
|
+
const puz = new RPuzzle()
|
|
65
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, r, 'single')
|
|
66
|
+
expect(spend.validate()).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('signs with anyoneCanPay=true', async () => {
|
|
70
|
+
const puz = new RPuzzle()
|
|
71
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, r, 'all', true)
|
|
72
|
+
expect(spend.validate()).toBe(true)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('estimateLength', () => {
|
|
77
|
+
it('returns 108', async () => {
|
|
78
|
+
const puz = new RPuzzle()
|
|
79
|
+
const result = await puz.unlock(k, privateKey).estimateLength()
|
|
80
|
+
expect(result).toBe(108)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('missing source transaction', () => {
|
|
85
|
+
it('throws when input has no sourceTransaction', async () => {
|
|
86
|
+
const puz = new RPuzzle()
|
|
87
|
+
const lockingScript = puz.lock(r)
|
|
88
|
+
// Construct a tx where the input has no sourceTransaction
|
|
89
|
+
const spendTx = new Transaction(
|
|
90
|
+
1,
|
|
91
|
+
[{ sourceTXID: ZERO_TXID, sourceOutputIndex: 0, sequence: 0xffffffff }],
|
|
92
|
+
[],
|
|
93
|
+
0
|
|
94
|
+
)
|
|
95
|
+
await expect(
|
|
96
|
+
puz.unlock(k, privateKey).sign(spendTx, 0)
|
|
97
|
+
).rejects.toThrow('The source transaction is needed')
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
describe('hash type variants', () => {
|
|
102
|
+
it('SHA256 RPuzzle round-trips using hashed r value', async () => {
|
|
103
|
+
const { sha256 } = await import('../../../primitives/Hash')
|
|
104
|
+
const hashedR = sha256(r)
|
|
105
|
+
const puz = new RPuzzle('SHA256')
|
|
106
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, hashedR)
|
|
107
|
+
expect(spend.validate()).toBe(true)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('SHA1 RPuzzle round-trips using hashed r value', async () => {
|
|
111
|
+
const { sha1 } = await import('../../../primitives/Hash')
|
|
112
|
+
const hashedR = sha1(r)
|
|
113
|
+
const puz = new RPuzzle('SHA1')
|
|
114
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, hashedR)
|
|
115
|
+
expect(spend.validate()).toBe(true)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('RIPEMD160 RPuzzle round-trips using hashed r value', async () => {
|
|
119
|
+
const { ripemd160 } = await import('../../../primitives/Hash')
|
|
120
|
+
const hashedR = ripemd160(r)
|
|
121
|
+
const puz = new RPuzzle('RIPEMD160')
|
|
122
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, hashedR)
|
|
123
|
+
expect(spend.validate()).toBe(true)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('HASH160 RPuzzle round-trips using hashed r value', async () => {
|
|
127
|
+
const { hash160 } = await import('../../../primitives/Hash')
|
|
128
|
+
const hashedR = hash160(r)
|
|
129
|
+
const puz = new RPuzzle('HASH160')
|
|
130
|
+
const spend = await buildRPuzzleSpend(puz, k, privateKey, hashedR)
|
|
131
|
+
expect(spend.validate()).toBe(true)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
})
|