@bsv/sdk 1.9.0 → 1.9.1
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/kvstore/LocalKVStore.js +7 -7
- package/dist/cjs/src/kvstore/LocalKVStore.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/kvstore/LocalKVStore.js +7 -7
- package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/dist/umd/bundle.js.map +1 -1
- package/package.json +1 -1
- package/src/kvstore/LocalKVStore.ts +7 -7
- package/src/kvstore/__tests/LocalKVStore.test.ts +17 -17
package/package.json
CHANGED
|
@@ -115,7 +115,7 @@ export default class LocalKVStore {
|
|
|
115
115
|
tagQueryMode: 'all',
|
|
116
116
|
include: 'entire transactions',
|
|
117
117
|
limit
|
|
118
|
-
})
|
|
118
|
+
}, this.originator)
|
|
119
119
|
return results
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -175,7 +175,7 @@ export default class LocalKVStore {
|
|
|
175
175
|
const { plaintext } = await this.wallet.decrypt({
|
|
176
176
|
...this.getProtocol(key),
|
|
177
177
|
ciphertext: field
|
|
178
|
-
})
|
|
178
|
+
}, this.originator)
|
|
179
179
|
r.value = Utils.toUTF8(plaintext)
|
|
180
180
|
}
|
|
181
181
|
return r
|
|
@@ -241,7 +241,7 @@ export default class LocalKVStore {
|
|
|
241
241
|
const { ciphertext } = await this.wallet.encrypt({
|
|
242
242
|
...protocol,
|
|
243
243
|
plaintext: valueAsArray
|
|
244
|
-
})
|
|
244
|
+
}, this.originator)
|
|
245
245
|
valueAsArray = ciphertext
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -272,7 +272,7 @@ export default class LocalKVStore {
|
|
|
272
272
|
acceptDelayedBroadcast: this.acceptDelayedBroadcast,
|
|
273
273
|
randomizeOutputs: false
|
|
274
274
|
}
|
|
275
|
-
})
|
|
275
|
+
}, this.originator)
|
|
276
276
|
|
|
277
277
|
if (outputs.length > 0 && typeof signableTransaction !== 'object') {
|
|
278
278
|
throw new Error('Wallet did not return a signable transaction when expected.')
|
|
@@ -285,7 +285,7 @@ export default class LocalKVStore {
|
|
|
285
285
|
const { txid } = await this.wallet.signAction({
|
|
286
286
|
reference: signableTransaction.reference,
|
|
287
287
|
spends
|
|
288
|
-
})
|
|
288
|
+
}, this.originator)
|
|
289
289
|
outpoint = `${txid as string}.0`
|
|
290
290
|
}
|
|
291
291
|
} catch (error) {
|
|
@@ -326,7 +326,7 @@ export default class LocalKVStore {
|
|
|
326
326
|
options: {
|
|
327
327
|
acceptDelayedBroadcast: this.acceptDelayedBroadcast
|
|
328
328
|
}
|
|
329
|
-
})
|
|
329
|
+
}, this.originator)
|
|
330
330
|
if (typeof signableTransaction !== 'object') {
|
|
331
331
|
throw new Error('Wallet did not return a signable transaction when expected.')
|
|
332
332
|
}
|
|
@@ -334,7 +334,7 @@ export default class LocalKVStore {
|
|
|
334
334
|
const { txid } = await this.wallet.signAction({
|
|
335
335
|
reference: signableTransaction.reference,
|
|
336
336
|
spends
|
|
337
|
-
})
|
|
337
|
+
}, this.originator)
|
|
338
338
|
if (txid === undefined) { throw new Error('signAction must return a valid txid') }
|
|
339
339
|
txids.push(txid)
|
|
340
340
|
} catch (error) {
|
|
@@ -104,7 +104,7 @@ describe('localKVStore', () => {
|
|
|
104
104
|
// const testUnlockingScriptHex = 'mockUnlockingScriptHex'; // Defined above
|
|
105
105
|
|
|
106
106
|
beforeEach(() => {
|
|
107
|
-
|
|
107
|
+
// Reset mocks before each test (clears calls and resets implementations)
|
|
108
108
|
jest.clearAllMocks()
|
|
109
109
|
|
|
110
110
|
// Create a fresh mock wallet for each test
|
|
@@ -122,7 +122,7 @@ describe('localKVStore', () => {
|
|
|
122
122
|
// --- Constructor Tests ---
|
|
123
123
|
describe('constructor', () => {
|
|
124
124
|
it('should create an instance with default wallet and encrypt=true', () => {
|
|
125
|
-
|
|
125
|
+
// We need to mock the default WalletClient if the SUT uses it
|
|
126
126
|
const MockedWalletClient = require('../../../mod.js').WalletClient
|
|
127
127
|
const store = new LocalKVStore(undefined, 'default-context')
|
|
128
128
|
expect(store).toBeInstanceOf(LocalKVStore)
|
|
@@ -200,7 +200,7 @@ describe('localKVStore', () => {
|
|
|
200
200
|
let pushDropInstance: PushDrop // To access the instance methods
|
|
201
201
|
|
|
202
202
|
beforeEach(() => {
|
|
203
|
-
|
|
203
|
+
// Get the mock instance that will be created by `new PushDrop()`
|
|
204
204
|
pushDropInstance = new (PushDrop as any)()
|
|
205
205
|
})
|
|
206
206
|
|
|
@@ -223,7 +223,7 @@ describe('localKVStore', () => {
|
|
|
223
223
|
plaintext: valueArray, // Should be Array<number>
|
|
224
224
|
protocolID: [2, testContext],
|
|
225
225
|
keyID: testKey
|
|
226
|
-
})
|
|
226
|
+
}, undefined)
|
|
227
227
|
// Check the mock instance's lock method
|
|
228
228
|
expect(mockPDInstance.lock).toHaveBeenCalledWith(
|
|
229
229
|
// The lock function expects Array<number[] | Uint8Array>
|
|
@@ -250,7 +250,7 @@ describe('localKVStore', () => {
|
|
|
250
250
|
acceptDelayedBroadcast: false,
|
|
251
251
|
randomizeOutputs: false
|
|
252
252
|
}
|
|
253
|
-
})
|
|
253
|
+
}, undefined)
|
|
254
254
|
expect(mockWallet.signAction).not.toHaveBeenCalled()
|
|
255
255
|
expect(mockWallet.relinquishOutput).not.toHaveBeenCalled()
|
|
256
256
|
})
|
|
@@ -293,7 +293,7 @@ describe('localKVStore', () => {
|
|
|
293
293
|
acceptDelayedBroadcast: false,
|
|
294
294
|
randomizeOutputs: false
|
|
295
295
|
}
|
|
296
|
-
})
|
|
296
|
+
}, undefined)
|
|
297
297
|
expect(mockWallet.signAction).not.toHaveBeenCalled()
|
|
298
298
|
expect(mockWallet.relinquishOutput).not.toHaveBeenCalled()
|
|
299
299
|
})
|
|
@@ -301,7 +301,7 @@ describe('localKVStore', () => {
|
|
|
301
301
|
it('should update an existing output (spend and create)', async () => {
|
|
302
302
|
const existingOutpoint = 'oldTxId.0'
|
|
303
303
|
const existingOutput = { outpoint: existingOutpoint, txid: 'oldTxId', vout: 0, lockingScript: 'oldScriptHex' } // Added script
|
|
304
|
-
const mockBEEF = [1,2,3,4,5,6]
|
|
304
|
+
const mockBEEF = [1, 2, 3, 4, 5, 6]
|
|
305
305
|
const signableRef = 'signableTxRef123'
|
|
306
306
|
const signableTx = []
|
|
307
307
|
const updatedTxId = 'updatedTxId'
|
|
@@ -366,7 +366,7 @@ describe('localKVStore', () => {
|
|
|
366
366
|
outputs: expect.arrayContaining([ // Check outputs array
|
|
367
367
|
expect.objectContaining({ lockingScript: testLockingScriptHex }) // Check the new output script
|
|
368
368
|
])
|
|
369
|
-
}))
|
|
369
|
+
}), undefined)
|
|
370
370
|
|
|
371
371
|
// Verify signing steps
|
|
372
372
|
expect(MockedTransaction.fromAtomicBEEF).toHaveBeenCalledWith(signableTx)
|
|
@@ -383,7 +383,7 @@ describe('localKVStore', () => {
|
|
|
383
383
|
spends: {
|
|
384
384
|
0: { unlockingScript: testUnlockingScriptHex } // Check unlocking script from mock sign result
|
|
385
385
|
}
|
|
386
|
-
})
|
|
386
|
+
}, undefined)
|
|
387
387
|
expect(mockWallet.relinquishOutput).not.toHaveBeenCalled()
|
|
388
388
|
})
|
|
389
389
|
|
|
@@ -395,7 +395,7 @@ describe('localKVStore', () => {
|
|
|
395
395
|
const existingOutpoint2 = 'oldTxId2.1'
|
|
396
396
|
const existingOutput1 = { outpoint: existingOutpoint1, txid: 'oldTxId1', vout: 0, lockingScript: 's1' }
|
|
397
397
|
const existingOutput2 = { outpoint: existingOutpoint2, txid: 'oldTxId2', vout: 1, lockingScript: 's2' }
|
|
398
|
-
const mockBEEF = [1,2,3,4,5,6]
|
|
398
|
+
const mockBEEF = [1, 2, 3, 4, 5, 6]
|
|
399
399
|
const signableRef = 'signableTxRefMulti'
|
|
400
400
|
const signableTx = []
|
|
401
401
|
const updatedTxId = 'updatedTxIdMulti'
|
|
@@ -457,7 +457,7 @@ describe('localKVStore', () => {
|
|
|
457
457
|
outputs: expect.arrayContaining([
|
|
458
458
|
expect.objectContaining({ lockingScript: testLockingScriptHex })
|
|
459
459
|
])
|
|
460
|
-
}))
|
|
460
|
+
}), undefined)
|
|
461
461
|
|
|
462
462
|
// Verify signing loop
|
|
463
463
|
expect(MockedTransaction.fromAtomicBEEF).toHaveBeenCalledWith(signableTx)
|
|
@@ -478,14 +478,14 @@ describe('localKVStore', () => {
|
|
|
478
478
|
0: { unlockingScript: testUnlockingScriptHex }, // Same mock script for both
|
|
479
479
|
1: { unlockingScript: testUnlockingScriptHex }
|
|
480
480
|
}
|
|
481
|
-
})
|
|
481
|
+
}, undefined)
|
|
482
482
|
expect(mockWallet.relinquishOutput).not.toHaveBeenCalled()
|
|
483
483
|
})
|
|
484
484
|
|
|
485
485
|
it('should preserve original error message when createAction fails', async () => {
|
|
486
486
|
const originalErrorMessage = 'Network connection timeout while creating transaction'
|
|
487
487
|
const originalError = new Error(originalErrorMessage)
|
|
488
|
-
|
|
488
|
+
|
|
489
489
|
// Mock the lookupValue to return a value that differs from what we're setting
|
|
490
490
|
// to ensure set() will attempt to create a transaction
|
|
491
491
|
const mockedLor: ListOutputsResult = {
|
|
@@ -533,7 +533,7 @@ describe('localKVStore', () => {
|
|
|
533
533
|
let pushDropInstance: PushDrop // To access the instance methods
|
|
534
534
|
|
|
535
535
|
beforeEach(() => {
|
|
536
|
-
|
|
536
|
+
// Get the mock instance that will be created by `new PushDrop()`
|
|
537
537
|
pushDropInstance = new (PushDrop as any)()
|
|
538
538
|
})
|
|
539
539
|
|
|
@@ -598,7 +598,7 @@ describe('localKVStore', () => {
|
|
|
598
598
|
options: {
|
|
599
599
|
acceptDelayedBroadcast: false
|
|
600
600
|
}
|
|
601
|
-
})
|
|
601
|
+
}, undefined)
|
|
602
602
|
// Check that outputs key is absent
|
|
603
603
|
expect(mockWallet.createAction.mock.calls[0][0]).not.toHaveProperty('outputs')
|
|
604
604
|
|
|
@@ -619,7 +619,7 @@ describe('localKVStore', () => {
|
|
|
619
619
|
0: { unlockingScript: testUnlockingScriptHex },
|
|
620
620
|
1: { unlockingScript: testUnlockingScriptHex }
|
|
621
621
|
}
|
|
622
|
-
})
|
|
622
|
+
}, undefined)
|
|
623
623
|
expect(mockWallet.relinquishOutput).not.toHaveBeenCalled()
|
|
624
624
|
})
|
|
625
625
|
|
|
@@ -659,7 +659,7 @@ describe('localKVStore', () => {
|
|
|
659
659
|
it('should preserve original error message when wallet operations fail during removal', async () => {
|
|
660
660
|
const originalErrorMessage = 'Insufficient funds to cover transaction fees'
|
|
661
661
|
const originalError = new Error(originalErrorMessage)
|
|
662
|
-
|
|
662
|
+
|
|
663
663
|
const existingOutpoint = 'failTxId.0'
|
|
664
664
|
const existingOutput = { outpoint: existingOutpoint, txid: 'failTxId', vout: 0, lockingScript: 's1' }
|
|
665
665
|
const mockBEEF = Buffer.from('mockBEEFFail')
|