@bsv/sdk 1.6.26 → 1.7.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/identity/IdentityClient.js +22 -6
- package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
- package/dist/cjs/src/storage/StorageDownloader.js +24 -10
- package/dist/cjs/src/storage/StorageDownloader.js.map +1 -1
- package/dist/cjs/src/storage/StorageUploader.js +5 -4
- package/dist/cjs/src/storage/StorageUploader.js.map +1 -1
- package/dist/cjs/src/storage/StorageUtils.js +11 -3
- package/dist/cjs/src/storage/StorageUtils.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/identity/IdentityClient.js +22 -6
- package/dist/esm/src/identity/IdentityClient.js.map +1 -1
- package/dist/esm/src/storage/StorageDownloader.js +24 -10
- package/dist/esm/src/storage/StorageDownloader.js.map +1 -1
- package/dist/esm/src/storage/StorageUploader.js +5 -4
- package/dist/esm/src/storage/StorageUploader.js.map +1 -1
- package/dist/esm/src/storage/StorageUtils.js +11 -3
- package/dist/esm/src/storage/StorageUtils.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/identity/IdentityClient.d.ts +4 -2
- package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
- package/dist/types/src/storage/StorageDownloader.d.ts +1 -1
- package/dist/types/src/storage/StorageDownloader.d.ts.map +1 -1
- package/dist/types/src/storage/StorageUploader.d.ts +1 -1
- package/dist/types/src/storage/StorageUploader.d.ts.map +1 -1
- package/dist/types/src/storage/StorageUtils.d.ts +3 -2
- package/dist/types/src/storage/StorageUtils.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +2 -2
- package/dist/umd/bundle.js.map +1 -1
- package/docs/reference/identity.md +8 -4
- package/docs/reference/storage.md +12 -5
- package/docs/tutorials/uhrp-storage.md +6 -6
- package/package.json +1 -1
- package/src/identity/IdentityClient.ts +32 -6
- package/src/identity/__tests/IdentityClient.test.ts +172 -45
- package/src/storage/StorageDownloader.ts +28 -12
- package/src/storage/StorageUploader.ts +6 -5
- package/src/storage/StorageUtils.ts +12 -4
- package/src/storage/__tests/StorageDownloader.test.ts +34 -2
- package/src/storage/__tests/StorageUploader.test.ts +20 -0
|
@@ -3,8 +3,9 @@ import { StorageUtils } from '../index.js'
|
|
|
3
3
|
import { LookupResolver } from '../../overlay-tools/index.js'
|
|
4
4
|
import Transaction from '../../transaction/Transaction.js'
|
|
5
5
|
import PushDrop from '../../script/templates/PushDrop.js'
|
|
6
|
-
import {
|
|
6
|
+
import { PublicKey } from '../../primitives/index.js'
|
|
7
7
|
import { Utils } from '../../primitives/index.js'
|
|
8
|
+
import { ReadableStream } from 'stream/web'
|
|
8
9
|
|
|
9
10
|
beforeEach(() => {
|
|
10
11
|
jest.restoreAllMocks()
|
|
@@ -125,7 +126,7 @@ describe('StorageDownloader', () => {
|
|
|
125
126
|
const result = await downloader.download('validUrl')
|
|
126
127
|
expect(fetchSpy).toHaveBeenCalledTimes(2)
|
|
127
128
|
expect(result).toEqual({
|
|
128
|
-
data: new
|
|
129
|
+
data: new Uint8Array(32).fill(0),
|
|
129
130
|
mimeType: 'application/test'
|
|
130
131
|
})
|
|
131
132
|
})
|
|
@@ -200,5 +201,36 @@ describe('StorageDownloader', () => {
|
|
|
200
201
|
.resolves
|
|
201
202
|
.toEqual(["", ""])
|
|
202
203
|
})
|
|
204
|
+
|
|
205
|
+
it.skip('downloads and verifies large streamed content', async () => {
|
|
206
|
+
const size = 5 * 1024 * 1024
|
|
207
|
+
const data = new Uint8Array(size)
|
|
208
|
+
for (let i = 0; i < size; i++) data[i] = i % 256
|
|
209
|
+
const uhrpUrl = StorageUtils.getURLForFile(data)
|
|
210
|
+
|
|
211
|
+
jest.spyOn(downloader, 'resolve').mockResolvedValue(['http://large-file'])
|
|
212
|
+
|
|
213
|
+
const chunkSize = 64 * 1024
|
|
214
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
215
|
+
start (controller) {
|
|
216
|
+
for (let offset = 0; offset < data.length; offset += chunkSize) {
|
|
217
|
+
controller.enqueue(data.subarray(offset, offset + chunkSize))
|
|
218
|
+
}
|
|
219
|
+
controller.close()
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
jest.spyOn(global, 'fetch').mockResolvedValue(
|
|
224
|
+
new Response(stream as any, {
|
|
225
|
+
status: 200,
|
|
226
|
+
headers: { 'Content-Type': 'application/octet-stream' }
|
|
227
|
+
})
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
const result = await downloader.download(uhrpUrl)
|
|
231
|
+
expect(result.mimeType).toBe('application/octet-stream')
|
|
232
|
+
expect(result.data.length).toBe(size)
|
|
233
|
+
expect(result.data).toEqual(data)
|
|
234
|
+
})
|
|
203
235
|
})
|
|
204
236
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StorageUploader } from '../StorageUploader.js'
|
|
2
2
|
import * as StorageUtils from '../StorageUtils.js'
|
|
3
3
|
import WalletClient from '../../wallet/WalletClient.js'
|
|
4
|
+
import { createHash } from 'crypto'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A helper for converting a string to a number[] of UTF-8 bytes
|
|
@@ -66,6 +67,25 @@ describe('StorageUploader Tests', () => {
|
|
|
66
67
|
expect(firstFour).toHaveLength(8)
|
|
67
68
|
})
|
|
68
69
|
|
|
70
|
+
it('should handle large file uploads efficiently', async () => {
|
|
71
|
+
const size = 5 * 1024 * 1024
|
|
72
|
+
const data = new Uint8Array(size)
|
|
73
|
+
for (let i = 0; i < size; i++) data[i] = i % 256
|
|
74
|
+
|
|
75
|
+
jest.spyOn(uploader as any, 'getUploadInfo').mockResolvedValue({
|
|
76
|
+
uploadURL: 'https://example-upload.com/put'
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const result = await uploader.publishFile({
|
|
80
|
+
file: { data, type: 'application/octet-stream' },
|
|
81
|
+
retentionPeriod: 7
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const expectedHash = createHash('sha256').update(data).digest()
|
|
85
|
+
const urlHash = StorageUtils.getHashFromURL(result.uhrpURL)
|
|
86
|
+
expect(Buffer.from(urlHash)).toEqual(expectedHash)
|
|
87
|
+
})
|
|
88
|
+
|
|
69
89
|
it('should throw if the upload fails with HTTP 500', async () => {
|
|
70
90
|
// Force the direct upload (global fetch) to fail
|
|
71
91
|
globalFetchSpy.mockResolvedValueOnce(new Response(null, { status: 500 }))
|