@bsv/sdk 1.3.34 → 1.3.36
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/auth/clients/AuthFetch.js +33 -7
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +30 -17
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/transaction/Beef.js +2 -0
- package/dist/cjs/src/transaction/Beef.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js +33 -7
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +30 -17
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/transaction/Beef.js +2 -0
- package/dist/esm/src/transaction/Beef.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts +9 -8
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
- package/dist/types/src/transaction/Beef.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/package.json +1 -1
- package/src/auth/__tests/Peer.test.ts +12 -17
- package/src/auth/clients/AuthFetch.ts +53 -17
- package/src/auth/transports/SimplifiedFetchTransport.ts +30 -18
- package/src/auth/utils/__tests/cryptononce.test.ts +0 -2
- package/src/transaction/Beef.ts +2 -0
- package/src/transaction/__tests/Beef.test.ts +22 -3
- package/src/transaction/__tests/Transaction.benchmarks.test.ts +1 -16
package/package.json
CHANGED
|
@@ -211,15 +211,13 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
211
211
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
212
212
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
213
213
|
(async () => {
|
|
214
|
-
console.log('Bob received message:', Utils.toUTF8(payload))
|
|
215
214
|
await bob.toPeer(Utils.toArray('Hello Alice!'), senderPublicKey)
|
|
216
215
|
resolve()
|
|
217
|
-
})().catch(e =>
|
|
216
|
+
})().catch(e => { })
|
|
218
217
|
})
|
|
219
218
|
})
|
|
220
219
|
const aliceReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
221
220
|
alice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
222
|
-
console.log('Alice received message:', Utils.toUTF8(payload))
|
|
223
221
|
resolve()
|
|
224
222
|
})
|
|
225
223
|
})
|
|
@@ -260,29 +258,26 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
260
258
|
const bobReceivedGeneralMessage = new Promise<void>((resolve) => {
|
|
261
259
|
bob.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
262
260
|
(async () => {
|
|
263
|
-
console.log('Bob 1 received message:', Utils.toUTF8(payload))
|
|
264
261
|
await bob.toPeer(Utils.toArray('Hello Alice!'), senderPublicKey)
|
|
265
262
|
resolve()
|
|
266
263
|
bobMessageHandler(senderPublicKey, payload)
|
|
267
|
-
})().catch(e =>
|
|
264
|
+
})().catch(e => { })
|
|
268
265
|
})
|
|
269
266
|
})
|
|
270
267
|
let aliceReceivedGeneralMessageOnFirstDevice = new Promise<void>((resolve) => {
|
|
271
268
|
aliceFirstDevice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
272
269
|
(async () => {
|
|
273
|
-
console.log('Alice 1 received message:', Utils.toUTF8(payload))
|
|
274
270
|
resolve()
|
|
275
271
|
alice1MessageHandler(senderPublicKey, payload)
|
|
276
|
-
})().catch(e =>
|
|
272
|
+
})().catch(e => { })
|
|
277
273
|
})
|
|
278
274
|
})
|
|
279
275
|
const aliceReceivedGeneralMessageOnOtherDevice = new Promise<void>((resolve) => {
|
|
280
276
|
aliceOtherDevice.listenForGeneralMessages((senderPublicKey, payload) => {
|
|
281
277
|
(async () => {
|
|
282
|
-
console.log('Alice 2 received message:', Utils.toUTF8(payload))
|
|
283
278
|
resolve()
|
|
284
279
|
alice2MessageHandler(senderPublicKey, payload)
|
|
285
|
-
})().catch(e =>
|
|
280
|
+
})().catch(e => { })
|
|
286
281
|
})
|
|
287
282
|
})
|
|
288
283
|
|
|
@@ -333,10 +328,10 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
333
328
|
// Use a for...of loop instead of forEach with an async callback.
|
|
334
329
|
for (const cert of certificatesReceivedByBob) {
|
|
335
330
|
// Decrypt to ensure it has the correct fields.
|
|
336
|
-
const decryptedFields = await cert.decryptFields(walletB)
|
|
331
|
+
// const decryptedFields = await cert.decryptFields(walletB)
|
|
337
332
|
if (cert.certifier !== 'bob') {
|
|
338
|
-
console.log('Bob accepted the message:', Utils.toUTF8(payload))
|
|
339
|
-
console.log('Decrypted fields:', decryptedFields)
|
|
333
|
+
// console.log('Bob accepted the message:', Utils.toUTF8(payload))
|
|
334
|
+
// console.log('Decrypted fields:', decryptedFields)
|
|
340
335
|
}
|
|
341
336
|
}
|
|
342
337
|
}
|
|
@@ -640,7 +635,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
640
635
|
resolve()
|
|
641
636
|
}
|
|
642
637
|
}
|
|
643
|
-
})().catch(e =>
|
|
638
|
+
})().catch(e => { })
|
|
644
639
|
}
|
|
645
640
|
)
|
|
646
641
|
})
|
|
@@ -658,7 +653,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
658
653
|
resolve()
|
|
659
654
|
}
|
|
660
655
|
}
|
|
661
|
-
})().catch(e =>
|
|
656
|
+
})().catch(e => { })
|
|
662
657
|
}
|
|
663
658
|
)
|
|
664
659
|
})
|
|
@@ -672,7 +667,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
672
667
|
senderPublicKey
|
|
673
668
|
)
|
|
674
669
|
resolve()
|
|
675
|
-
})().catch(e =>
|
|
670
|
+
})().catch(e => { })
|
|
676
671
|
})
|
|
677
672
|
})
|
|
678
673
|
|
|
@@ -766,7 +761,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
766
761
|
resolve()
|
|
767
762
|
}
|
|
768
763
|
}
|
|
769
|
-
})().catch(e =>
|
|
764
|
+
})().catch(e => { })
|
|
770
765
|
})
|
|
771
766
|
})
|
|
772
767
|
|
|
@@ -783,7 +778,7 @@ describe('Peer class mutual authentication and certificate exchange', () => {
|
|
|
783
778
|
resolve()
|
|
784
779
|
}
|
|
785
780
|
}
|
|
786
|
-
})().catch(e =>
|
|
781
|
+
})().catch(e => { })
|
|
787
782
|
})
|
|
788
783
|
})
|
|
789
784
|
|
|
@@ -6,14 +6,21 @@ import { SessionManager } from '../SessionManager.js'
|
|
|
6
6
|
import { RequestedCertificateSet } from '../types.js'
|
|
7
7
|
import { VerifiableCertificate } from '../certificates/VerifiableCertificate.js'
|
|
8
8
|
import { Writer } from '../../primitives/utils.js'
|
|
9
|
+
import { getVerifiableCertificates } from '../utils/index.js'
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
method?: string
|
|
12
|
-
headers?: Record<string, string
|
|
13
|
-
body?: any
|
|
11
|
+
interface SimplifiedFetchRequestOptions {
|
|
12
|
+
method?: string
|
|
13
|
+
headers?: Record<string, string>
|
|
14
|
+
body?: any
|
|
14
15
|
retryCounter?: number
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
interface AuthPeer {
|
|
19
|
+
peer: Peer
|
|
20
|
+
identityKey?: string
|
|
21
|
+
supportsMutualAuth?: boolean
|
|
22
|
+
pendingCertificateRequests: Array<true>
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
const PAYMENT_VERSION = '1.0'
|
|
19
26
|
|
|
@@ -26,11 +33,11 @@ const PAYMENT_VERSION = '1.0'
|
|
|
26
33
|
* and sending BSV payment transactions when necessary.
|
|
27
34
|
*/
|
|
28
35
|
export class AuthFetch {
|
|
29
|
-
private sessionManager: SessionManager
|
|
30
|
-
private wallet: WalletInterface
|
|
36
|
+
private readonly sessionManager: SessionManager
|
|
37
|
+
private readonly wallet: WalletInterface
|
|
31
38
|
private callbacks: Record<string, { resolve: Function, reject: Function }> = {}
|
|
32
|
-
private certificatesReceived: VerifiableCertificate[] = []
|
|
33
|
-
private requestedCertificates?: RequestedCertificateSet
|
|
39
|
+
private readonly certificatesReceived: VerifiableCertificate[] = []
|
|
40
|
+
private readonly requestedCertificates?: RequestedCertificateSet
|
|
34
41
|
peers: Record<string, AuthPeer> = {}
|
|
35
42
|
|
|
36
43
|
/**
|
|
@@ -58,7 +65,7 @@ export class AuthFetch {
|
|
|
58
65
|
* @throws Will throw an error if unsupported headers are used or other validation fails.
|
|
59
66
|
*/
|
|
60
67
|
async fetch(url: string, config: SimplifiedFetchRequestOptions = {}): Promise<Response> {
|
|
61
|
-
if (config.retryCounter) {
|
|
68
|
+
if (typeof config.retryCounter === 'number') {
|
|
62
69
|
if (config.retryCounter <= 0) {
|
|
63
70
|
throw new Error('Request failed after maximum number of retries.')
|
|
64
71
|
}
|
|
@@ -79,13 +86,28 @@ export class AuthFetch {
|
|
|
79
86
|
// Create a peer for the request
|
|
80
87
|
const newTransport = new SimplifiedFetchTransport(baseURL)
|
|
81
88
|
peerToUse = {
|
|
82
|
-
peer: new Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager)
|
|
89
|
+
peer: new Peer(this.wallet, newTransport, this.requestedCertificates, this.sessionManager),
|
|
90
|
+
pendingCertificateRequests: []
|
|
83
91
|
}
|
|
84
92
|
this.peers[baseURL] = peerToUse
|
|
85
|
-
|
|
93
|
+
this.peers[baseURL].peer.listenForCertificatesReceived((senderPublicKey: string, certs: VerifiableCertificate[]) => {
|
|
86
94
|
this.certificatesReceived.push(...certs)
|
|
87
|
-
// peerToUse.peer.stopListeningForCertificatesReceived()
|
|
88
95
|
})
|
|
96
|
+
this.peers[baseURL].peer.listenForCertificatesRequested((async (verifier: string, requestedCertificates: RequestedCertificateSet) => {
|
|
97
|
+
try {
|
|
98
|
+
this.peers[baseURL].pendingCertificateRequests.push(true)
|
|
99
|
+
const certificatesToInclude = await getVerifiableCertificates(
|
|
100
|
+
this.wallet,
|
|
101
|
+
requestedCertificates,
|
|
102
|
+
verifier
|
|
103
|
+
)
|
|
104
|
+
await this.peers[baseURL].peer.sendCertificateResponse(verifier, certificatesToInclude)
|
|
105
|
+
} finally {
|
|
106
|
+
// Give the backend 500 ms to process the certificates we just sent, before releasing the queue entry
|
|
107
|
+
await new Promise(resolve => setTimeout(resolve, 500))
|
|
108
|
+
this.peers[baseURL].pendingCertificateRequests.shift()
|
|
109
|
+
}
|
|
110
|
+
}) as Function)
|
|
89
111
|
} else {
|
|
90
112
|
// Check if there's a session associated with this baseURL
|
|
91
113
|
if (this.peers[baseURL].supportsMutualAuth === false) {
|
|
@@ -174,6 +196,20 @@ export class AuthFetch {
|
|
|
174
196
|
delete this.callbacks[requestNonceAsBase64]
|
|
175
197
|
})
|
|
176
198
|
|
|
199
|
+
// Before sending general messages to the peer, ensure that no certificate requests are pending.
|
|
200
|
+
// This way, the user would need to choose to either allow or reject the certificate request first.
|
|
201
|
+
// If the server has a resource that requires certificates to be sent before access would be granted,
|
|
202
|
+
// this makes sure the user has a chance to send the certificates before the resource is requested.
|
|
203
|
+
if (peerToUse.pendingCertificateRequests.length > 0) {
|
|
204
|
+
await new Promise(resolve => {
|
|
205
|
+
setInterval(() => {
|
|
206
|
+
if (peerToUse.pendingCertificateRequests.length === 0) {
|
|
207
|
+
resolve()
|
|
208
|
+
}
|
|
209
|
+
}, 100) // Check every 100 ms for the user to finish responding
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
|
|
177
213
|
// Send the request, now that all listeners are set up
|
|
178
214
|
await peerToUse.peer.toPeer(writer.toArray(), peerToUse.identityKey).catch(async error => {
|
|
179
215
|
if (error.message.includes('Session not found for nonce')) {
|
|
@@ -217,7 +253,7 @@ export class AuthFetch {
|
|
|
217
253
|
const baseURL = parsedUrl.origin
|
|
218
254
|
|
|
219
255
|
let peerToUse: { peer: Peer; identityKey?: string }
|
|
220
|
-
if (this.peers[baseURL]) {
|
|
256
|
+
if (typeof this.peers[baseURL] !== 'undefined') {
|
|
221
257
|
peerToUse = { peer: this.peers[baseURL].peer }
|
|
222
258
|
} else {
|
|
223
259
|
const newTransport = new SimplifiedFetchTransport(baseURL)
|
|
@@ -233,7 +269,7 @@ export class AuthFetch {
|
|
|
233
269
|
}
|
|
234
270
|
|
|
235
271
|
// Return a promise that resolves when certificates are received
|
|
236
|
-
return new Promise<VerifiableCertificate[]>(async (resolve, reject) => {
|
|
272
|
+
return await new Promise<VerifiableCertificate[]>((async (resolve, reject) => {
|
|
237
273
|
// Set up the listener before making the request
|
|
238
274
|
const callbackId = peerToUse.peer.listenForCertificatesReceived((_senderPublicKey: string, certs: VerifiableCertificate[]) => {
|
|
239
275
|
peerToUse.peer.stopListeningForCertificatesReceived(callbackId)
|
|
@@ -248,7 +284,7 @@ export class AuthFetch {
|
|
|
248
284
|
peerToUse.peer.stopListeningForCertificatesReceived(callbackId)
|
|
249
285
|
reject(err)
|
|
250
286
|
}
|
|
251
|
-
})
|
|
287
|
+
}) as Function)
|
|
252
288
|
}
|
|
253
289
|
|
|
254
290
|
/**
|
|
@@ -513,4 +549,4 @@ export class AuthFetch {
|
|
|
513
549
|
// 9. Fallback
|
|
514
550
|
throw new Error('Unsupported body type in this SimplifiedFetch implementation.')
|
|
515
551
|
}
|
|
516
|
-
}
|
|
552
|
+
}
|
|
@@ -42,25 +42,38 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
42
42
|
if (!this.onDataCallback) {
|
|
43
43
|
throw new Error('Listen before you start speaking. God gave you two ears and one mouth for a reason.')
|
|
44
44
|
}
|
|
45
|
-
|
|
46
45
|
if (message.messageType !== 'general') {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
return new Promise(async (resolve, reject) => {
|
|
47
|
+
try {
|
|
48
|
+
const responsePromise = this.fetchClient(`${this.baseUrl}/.well-known/auth`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: {
|
|
51
|
+
'Content-Type': 'application/json'
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify(message)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if (message.messageType !== "initialRequest") {
|
|
57
|
+
resolve()
|
|
58
|
+
}
|
|
59
|
+
const response = await responsePromise
|
|
60
|
+
|
|
61
|
+
// Handle the response if data is received and callback is set
|
|
62
|
+
if (response.ok && this.onDataCallback) {
|
|
63
|
+
const responseMessage = await response.json()
|
|
64
|
+
this.onDataCallback(responseMessage as AuthMessage)
|
|
65
|
+
} else {
|
|
66
|
+
// Server may be a non authenticated server
|
|
67
|
+
throw new Error('HTTP server failed to authenticate')
|
|
68
|
+
}
|
|
69
|
+
if (message.messageType === "initialRequest") {
|
|
70
|
+
resolve()
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e)
|
|
74
|
+
return
|
|
59
75
|
}
|
|
60
|
-
}
|
|
61
|
-
// Server may be a non authenticated server
|
|
62
|
-
throw new Error('HTTP server failed to authenticate')
|
|
63
|
-
}
|
|
76
|
+
})
|
|
64
77
|
} else {
|
|
65
78
|
// Parse message payload
|
|
66
79
|
const httpRequest = this.deserializeRequestPayload(message.payload)
|
|
@@ -105,7 +118,6 @@ export class SimplifiedFetchTransport implements Transport {
|
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
|
|
108
|
-
|
|
109
121
|
// Send the actual fetch request to the server
|
|
110
122
|
const response = await this.fetchClient(url, {
|
|
111
123
|
method: httpRequestWithAuthHeaders.method,
|
package/src/transaction/Beef.ts
CHANGED
|
@@ -485,6 +485,8 @@ export class Beef {
|
|
|
485
485
|
* @returns A binary array representing the BEEF
|
|
486
486
|
*/
|
|
487
487
|
toBinary (): number[] {
|
|
488
|
+
// Always serialize in dependency sorted order.
|
|
489
|
+
this.sortTxs()
|
|
488
490
|
const writer = new Writer()
|
|
489
491
|
this.toWriter(writer)
|
|
490
492
|
return writer.toArray()
|
|
@@ -56,9 +56,7 @@ describe('Beef tests', () => {
|
|
|
56
56
|
beef.txs[0]._txid = undefined
|
|
57
57
|
|
|
58
58
|
expect(() => beef.txs[0].txid).toThrow('Internal')
|
|
59
|
-
expect(() => beef.toBinary()).toThrow(
|
|
60
|
-
'a valid serialized Transaction is expected'
|
|
61
|
-
)
|
|
59
|
+
expect(() => beef.toBinary()).toThrow('Internal')
|
|
62
60
|
|
|
63
61
|
beef.txs[0] = btx // Restore the original transaction
|
|
64
62
|
|
|
@@ -432,6 +430,25 @@ describe('Beef tests', () => {
|
|
|
432
430
|
expect(valid).toBe(false)
|
|
433
431
|
})
|
|
434
432
|
|
|
433
|
+
test('12_bumpIndexEncoding', async () => {
|
|
434
|
+
const b = Beef.fromString(bumpIndexEncoding)
|
|
435
|
+
// These are in the incorrect order!
|
|
436
|
+
expect(b.txs[1].txid).toBe('147050ccef091ca3d7a36661ca0928aa93a3a9a6dfe565977c2f56179d7a6159')
|
|
437
|
+
expect(b.txs[0].txid).toBe('0e579e9741f522e15536874090d20da7572a7e1ddd4bf42740f40e17c3605604')
|
|
438
|
+
const valid = b.isValid()
|
|
439
|
+
expect(valid).toBe(true)
|
|
440
|
+
expect(b.version).toBe(BEEF_V1)
|
|
441
|
+
const bytes = b.toBinary()
|
|
442
|
+
{
|
|
443
|
+
const b = Beef.fromBinary(bytes)
|
|
444
|
+
// These are now in the correct order!
|
|
445
|
+
expect(b.txs[0].txid).toBe('147050ccef091ca3d7a36661ca0928aa93a3a9a6dfe565977c2f56179d7a6159')
|
|
446
|
+
expect(b.txs[1].txid).toBe('0e579e9741f522e15536874090d20da7572a7e1ddd4bf42740f40e17c3605604')
|
|
447
|
+
const valid = b.isValid()
|
|
448
|
+
expect(valid).toBe(true)
|
|
449
|
+
expect(b.version).toBe(BEEF_V1)
|
|
450
|
+
}
|
|
451
|
+
})
|
|
435
452
|
})
|
|
436
453
|
|
|
437
454
|
const b58Beef10 =
|
|
@@ -479,3 +496,5 @@ const log2 = `BEEF with 1 BUMPS and 2 Transactions, isValid true
|
|
|
479
496
|
`
|
|
480
497
|
|
|
481
498
|
const wrongBumpTxid = '0100beef01fe4e6d0c001002fd909002088a382ec07a8cf47c6158b68e5822852362102d8571482d1257e0b7527e1882fd91900065cb01218f2506bb51155d243e4d6b32d69d1b5f2221c52e26963cfd8cf7283201fd4948008d7a44ae384797b0ae84db0c857e8c1083425d64d09ef8bc5e2e9d270677260501fd25240060f38aa33631c8d70adbac1213e7a5b418c90414e919e3a12ced63dd152fd85a01fd1312005ff132ee64a7a0c79150a29f66ef861e552d3a05b47d6303f5d8a2b2a09bc61501fd080900cc0baf21cf06b9439dfe05dce9bdb14ddc2ca2d560b1138296ef5769851a84b301fd85040063ccb26232a6e1d3becdb47a0f19a67a562b754e8894155b3ae7bba10335ce5101fd430200e153fc455a0f2c8372885c11af70af904dcf44740b9ebf3b3e5b2234cce550bc01fd20010077d5ea69d1dcc379dde65d6adcebde1838190118a8fae928c037275e78bd87910191000263e4f31684a25169857f2788aeef603504931f92585f02c4c9e023b2aa43d1014900de72292e0b3e5eeacfa2b657bf4d46c885559b081ee78632a99b318c1148d85c01250068a5f831ca99b9e7f3720920d6ea977fd2ab52b83d1a6567dafa4c8cafd941ed0113006a0b91d83f9056b702d6a8056af6365c7da626fc3818b815dd4b0de22d05450f0108009876ce56b68545a75859e93d200bdde7880d46f39384818b259ed847a9664ddf010500990bc5e95cacbc927b5786ec39a183f983fe160d52829cf47521c7eb369771c30103004fe794e50305f590b6010a51d050bf47dfeaabfdb949c5ee0673f577a59537d70100004dad44a358aea4d8bc1917912539901f5ae44e07a4748e1a9d3018814b0759d00201000000027b0a1b12c7c9e48015e78d3a08a4d62e439387df7e0d7a810ebd4af37661daaa000000006a47304402207d972759afba7c0ffa6cfbbf39a31c2aeede1dae28d8841db56c6dd1197d56a20220076a390948c235ba8e72b8e43a7b4d4119f1a81a77032aa6e7b7a51be5e13845412103f78ec31cf94ca8d75fb1333ad9fc884e2d489422034a1efc9d66a3b72eddca0fffffffff7f36874f858fb43ffcf4f9e3047825619bad0e92d4b9ad4ba5111d1101cbddfe010000006a473044022043f048043d56eb6f75024808b78f18808b7ab45609e4c4c319e3a27f8246fc3002204b67766b62f58bf6f30ea608eaba76b8524ed49f67a90f80ac08a9b96a6922cd41210254a583c1c51a06e10fab79ddf922915da5f5c1791ef87739f40cb68638397248ffffffff03e8030000000000001976a914b08f70bc5010fb026de018f19e7792385a146b4a88acf3010000000000001976a9147d48635f889372c3da12d75ce246c59f4ab907ed88acf7000000000000001976a914b8fbd58685b6920d8f9a8f1b274d8696708b51b088ac00000000010001000000018ae36502fdc82837319362c488fb9cb978e064daf600bbfc48389663fc5c160c000000006a47304402204a04841f6f626d30e21200e1c404ea80e319b643fe86f08e709413a89a493a4b022038a2e3e25a813d8d540c1a572fa8ec5fa2d2434bcea78d17902dcccddcc1c9484121028fd1afeee81361e801800afb264e35cdce3037ec6f7dc4f1d1eaba7ad519c948ffffffff01c8000000000000001976a9148ce2d21f9a75e98600be76b25b91c4fef6b40bcd88ac0000000000'
|
|
499
|
+
|
|
500
|
+
const bumpIndexEncoding = '0100beef01fe6e621900010200008cdbd6fe227cfafa6be4500cae6140c84b2ead61318063e92bdb6974f869cf33010259617a9d17562f7c9765e5dfa6a9a393aa2809ca6166a3d7a31c09efcc50701402010000000159617a9d17562f7c9765e5dfa6a9a393aa2809ca6166a3d7a31c09efcc507014130000006b4830450221009399820c643e5f2699b07ffa3289b22c6124e1317fd1ec41fb2431047dcf552f02201b7ee3ee3422fe1c33d8869a34a28fadddb9b790b3c5b332b7fafaaa8d4b413c4121029b15053bc379e2378cd6a84fb40b761b4e400faa4efd09280443731d4b3f8a8cffffffff0201000000000000001976a91423f2562a8092ed24eddc77c74387b44c561692a188ac03000000000000001976a9144ed83e2b3aae481f7fa48321024eb3d8e1f7417888ac00000000000100000001ee353cb1f4cb2b19bf7d2328f3c0a5fa2bd1aa94d0795934dd1d63756583b0ac000000006b4830450221009e779c3f04bb056da180b50ad3972b6fd552c52bd6337f572f08ca656625a4530220648e1fc5872d9bc3846f78edd79b4dc406dfecbab359e46b53c7d478747141684121022280e60c665907fb88a97f5e74dd4e1db0eba60a4dad18158ea8eb9495e242daffffffff2005000000000000001976a914e073bf1bf7b6160f7f68403a374717fdc4cce86d88ac4a000000000000001976a9145bbe83249067ec745d8e270c121c651f56ec2cf188ac42030000000000001976a914983a29113517769da9eace0ec25b760ad09c5f5988ac05000000000000001976a91402c75f3ec99db76e6cd2658a7c83c8bf21a0d14b88ac05000000000000001976a914de454fbce4e1be341d11cd5545664771f72d184088ac25000000000000001976a914b5c2a6831b5cdbc8985517f5d912064449ad118088ac3d010000000000001976a914e4566d91c063f99f7418f12d670b5da320160c8188ac05000000000000001976a914616dc74c3945895eafdac8da9174f95b4d91d75b88ac03010000000000001976a91476ae1c3f2c01a9a5f2aa7696cc9b89ea55b0d01688ac0d000000000000001976a9146d805d21013cc20351e5cd55ecaa7dcee59f2fde88ac05000000000000001976a914613408f68bdde1ff3f77a96abd4956a472766acf88ac21000000000000001976a914d7f0bcfa5b5cad93574a960627db60af8dac277c88ac05000000000000001976a9147e088fe21413442569fa59b6a5bf7e8fe6db71e388ac05000000000000001976a914e5ff336cbffc4ffef544ff4d131de68bf9b0aa1488ac05000000000000001976a9142145b563cd2766ba08d33ca0ecb5a6679268dfb788ac05000000000000001976a914da990487dff4910c8891cebcd00a569011f4f05188ac05000000000000001976a914100daf8fa5add521fb87b46ff51657728626c5fe88ac07000000000000001976a914de900668ddecd73f498c8560b8770231bef9616b88ac05000000000000001976a914dd08ccc14ebdcc534bb2320e7d3dba624a7ecd5388ac05000000000000001976a9141c5b5915e67a840fdcefd0db0ca1a1dfaaf4f3cf88ac06000000000000001976a91441815c6352756937fe6b2b17586dd6b39560321188ac05000000000000001976a91471dca8f8631f145ad5721f8387a764ae0ef2599888ac1d000000000000001976a9147e2621372c66ca3c6e6fca8cdb7eac42405d37fe88ac05000000000000001976a914d745ec07218bde8d179d49e4a6feca7f744f57e388ac05000000000000001976a91499456246822c4270ae73d6c7d8e1af690d1d31dd88ac05000000000000001976a914176dc7f479059d28593021e63bcb66bae6c2cc5388ac05000000000000001976a914a48809ce3c763a0a34c24ab2646fdf10cffdbc6588ac05000000000000001976a914e314da9f12f6bd888da53faa616890a2dce9eeb488ac05000000000000001976a91418f9185bb0ca144d934bd4845b3968d545e7ec8188ac17010000000000001976a9149db831932668077f8eebf597976ec61fc6ab90d588ac09000000000000001976a91479b349601390a6216994d44ca618db71e6e811ef88ac06000000000000001976a91451d25ac626a4b7c281b4200a3dcf34caae43f0df88ac000000000100'
|
|
@@ -9,7 +9,7 @@ import MerklePath from '../MerklePath'
|
|
|
9
9
|
jest.setTimeout(60000) // Increase timeout for benchmarking tests if necessary
|
|
10
10
|
|
|
11
11
|
// Helper function to measure execution time
|
|
12
|
-
async function measureTime
|
|
12
|
+
async function measureTime(fn: () => Promise<void>): Promise<number> {
|
|
13
13
|
const start = process.hrtime()
|
|
14
14
|
await fn()
|
|
15
15
|
const diff = process.hrtime(start)
|
|
@@ -113,11 +113,6 @@ describe('Transaction Verification Benchmark', () => {
|
|
|
113
113
|
const verified = await tx.verify('scripts only')
|
|
114
114
|
expect(verified).toBe(true)
|
|
115
115
|
})
|
|
116
|
-
console.log(
|
|
117
|
-
`Verification time for wide transaction with ${inputCount} inputs: ${timeTaken.toFixed(
|
|
118
|
-
2
|
|
119
|
-
)} ms`
|
|
120
|
-
)
|
|
121
116
|
})
|
|
122
117
|
|
|
123
118
|
it('verifies a large transaction with many inputs and outputs', async () => {
|
|
@@ -172,11 +167,6 @@ describe('Transaction Verification Benchmark', () => {
|
|
|
172
167
|
const verified = await tx.verify('scripts only')
|
|
173
168
|
expect(verified).toBe(true)
|
|
174
169
|
})
|
|
175
|
-
console.log(
|
|
176
|
-
`Verification time for large transaction with ${inputCount} inputs and ${outputCount} outputs: ${timeTaken.toFixed(
|
|
177
|
-
2
|
|
178
|
-
)} ms`
|
|
179
|
-
)
|
|
180
170
|
})
|
|
181
171
|
|
|
182
172
|
it('verifies a transaction with nested inputs (complex graph)', async () => {
|
|
@@ -243,10 +233,5 @@ describe('Transaction Verification Benchmark', () => {
|
|
|
243
233
|
const verified = await finalTx.verify('scripts only')
|
|
244
234
|
expect(verified).toBe(true)
|
|
245
235
|
})
|
|
246
|
-
console.log(
|
|
247
|
-
`Verification time for nested inputs with depth ${depth} and fan-out ${fanOut}: ${timeTaken.toFixed(
|
|
248
|
-
2
|
|
249
|
-
)} ms`
|
|
250
|
-
)
|
|
251
236
|
})
|
|
252
237
|
})
|