@bsv/wallet-toolbox 1.3.9 → 1.3.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/wallet-toolbox",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "BRC100 conforming wallet, wallet storage and wallet signer components",
5
5
  "main": "./out/src/index.js",
6
6
  "types": "./out/src/index.d.ts",
@@ -104,6 +104,7 @@ export interface WalletStorageInfo {
104
104
  storageIdentityKey: string
105
105
  storageName: string
106
106
  storageClass: string
107
+ endpointURL?: string
107
108
  }
108
109
 
109
110
  /**
@@ -2195,7 +2195,7 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
2195
2195
  const val = entity[key]
2196
2196
  if (val === null) {
2197
2197
  entity[key] = undefined
2198
- } else if (Buffer.isBuffer(val) || val instanceof Uint8Array) {
2198
+ } else if (val instanceof Uint8Array) {
2199
2199
  entity[key] = Array.from(val)
2200
2200
  }
2201
2201
  }
@@ -2223,7 +2223,7 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
2223
2223
  booleanFields?: string[]
2224
2224
  ): Partial<T> {
2225
2225
  if (!this.dbtype) throw new sdk.WERR_INTERNAL('must call verifyReadyForDatabaseAccess first')
2226
- const v: any = update
2226
+ const v: any = { ...update }
2227
2227
  if (v.created_at) v.created_at = this.validateEntityDate(v.created_at)
2228
2228
  if (v.updated_at) v.updated_at = this.validateEntityDate(v.updated_at)
2229
2229
  if (!v.created_at) delete v.created_at
@@ -2241,10 +2241,10 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
2241
2241
  }
2242
2242
  for (const key of Object.keys(v)) {
2243
2243
  const val = v[key]
2244
- if (Array.isArray(val) && (val.length === 0 || typeof val[0] === 'number')) {
2245
- v[key] = Buffer.from(val)
2246
- } else if (val === undefined) {
2247
- v[key] = null
2244
+ if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
2245
+ v[key] = Uint8Array.from(val)
2246
+ } else if (val === null) {
2247
+ v[key] = undefined
2248
2248
  }
2249
2249
  }
2250
2250
  this.isDirty = true
@@ -2279,10 +2279,10 @@ export class StorageIdb extends StorageProvider implements sdk.WalletStorageProv
2279
2279
  }
2280
2280
  for (const key of Object.keys(v)) {
2281
2281
  const val = v[key]
2282
- if (Array.isArray(val) && (val.length === 0 || typeof val[0] === 'number')) {
2283
- v[key] = Buffer.from(val)
2284
- } else if (val === undefined) {
2285
- v[key] = null
2282
+ if (Array.isArray(val) && (val.length === 0 || Number.isInteger(val[0]))) {
2283
+ v[key] = Uint8Array.from(val)
2284
+ } else if (val === null) {
2285
+ v[key] = undefined
2286
2286
  }
2287
2287
  }
2288
2288
  this.isDirty = true
@@ -22,6 +22,7 @@ import {
22
22
  } from '../storage/schema/tables'
23
23
  import { wait } from '../utility/utilityHelpers'
24
24
  import { StorageProvider } from './StorageProvider'
25
+ import { StorageClient } from './remoting/StorageClient'
25
26
 
26
27
  class ManagedStorage {
27
28
  isAvailable: boolean
@@ -704,6 +705,11 @@ export class WalletStorageManager implements sdk.WalletStorage {
704
705
  return log
705
706
  }
706
707
 
708
+ getStoreEndpointURL(store: ManagedStorage): string | undefined {
709
+ if (store.storage.constructor.name === 'StorageClient') return (store.storage as StorageClient).endpointUrl
710
+ return undefined
711
+ }
712
+
707
713
  getStores(): sdk.WalletStorageInfo[] {
708
714
  const stores: sdk.WalletStorageInfo[] = []
709
715
  if (this._active) {
@@ -715,7 +721,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
715
721
  userId: this._active.user!.userId,
716
722
  storageIdentityKey: this._active.settings!.storageIdentityKey,
717
723
  storageName: this._active.settings!.storageName,
718
- storageClass: this._active.storage.constructor.name
724
+ storageClass: this._active.storage.constructor.name,
725
+ endpointURL: this.getStoreEndpointURL(this._active)
719
726
  })
720
727
  }
721
728
  for (const store of this._conflictingActives || []) {
@@ -727,7 +734,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
727
734
  userId: store.user!.userId,
728
735
  storageIdentityKey: store.settings!.storageIdentityKey,
729
736
  storageName: store.settings!.storageName,
730
- storageClass: store.storage.constructor.name
737
+ storageClass: store.storage.constructor.name,
738
+ endpointURL: this.getStoreEndpointURL(store)
731
739
  })
732
740
  }
733
741
  for (const store of this._backups || []) {
@@ -739,7 +747,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
739
747
  userId: store.user!.userId,
740
748
  storageIdentityKey: store.settings!.storageIdentityKey,
741
749
  storageName: store.settings!.storageName,
742
- storageClass: store.storage.constructor.name
750
+ storageClass: store.storage.constructor.name,
751
+ endpointURL: this.getStoreEndpointURL(store)
743
752
  })
744
753
  }
745
754
  return stores
@@ -38,7 +38,7 @@ import {
38
38
  * For details of the API implemented, follow the "See also" link for the `WalletStorageProvider` interface.
39
39
  */
40
40
  export class StorageClient implements sdk.WalletStorageProvider {
41
- private readonly endpointUrl: string
41
+ readonly endpointUrl: string
42
42
  private readonly authClient: AuthFetch
43
43
  private nextId = 1
44
44
 
@@ -507,7 +507,7 @@ export class StorageClient implements sdk.WalletStorageProvider {
507
507
  const val = entity[key]
508
508
  if (val === null) {
509
509
  entity[key] = undefined
510
- } else if (Buffer.isBuffer(val)) {
510
+ } else if (val instanceof Uint8Array) {
511
511
  entity[key] = Array.from(val)
512
512
  }
513
513
  }
@@ -30,5 +30,7 @@ describe('idbSpeed tests', () => {
30
30
  log += `${key},${value.count},${value.totalMsecs},${value.totalMsecs / value.count}\n`
31
31
  }
32
32
  logger(log)
33
+
34
+ await setup.wallet.destroy()
33
35
  })
34
36
  })
@@ -207,14 +207,13 @@ describe('update tests', () => {
207
207
  expect(actualValue).toBe(value)
208
208
  continue
209
209
  }
210
- if (typeof actualValue === 'object' && actualValue?.type === 'Buffer') {
211
- const actualArray = actualValue.data || actualValue
212
- const expectedArray =
213
- Buffer.isBuffer(value) || Array.isArray(value) ? Array.from(value as ArrayLike<number>) : value
210
+ if (typeof actualValue === 'object' && Array.isArray(actualValue)) {
211
+ const actualArray = actualValue
212
+ const expectedArray = value
214
213
  expect(actualArray).toStrictEqual(expectedArray)
215
214
  continue
216
215
  }
217
- expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value))
216
+ expect(JSON.stringify(actualValue)).toStrictEqual(JSON.stringify(value))
218
217
  }
219
218
  } catch (error: any) {
220
219
  console.error(
@@ -556,8 +555,8 @@ describe('update tests', () => {
556
555
  expect(normalizedActual).toBe(normalizedExpected)
557
556
  continue
558
557
  }
559
- if (Buffer.isBuffer(actualValue) || Array.isArray(actualValue)) {
560
- expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value))
558
+ if (Array.isArray(actualValue)) {
559
+ expect(actualValue).toStrictEqual(value)
561
560
  continue
562
561
  }
563
562
  expect(actualValue).toBe(value)
@@ -638,8 +637,8 @@ describe('update tests', () => {
638
637
  expect(normalizedActual).toBe(normalizedExpected)
639
638
  continue
640
639
  }
641
- if (Buffer.isBuffer(actualValue) || Array.isArray(actualValue)) {
642
- expect(JSON.stringify({ type: 'Buffer', data: actualValue })).toStrictEqual(JSON.stringify(value))
640
+ if (Array.isArray(actualValue)) {
641
+ expect(actualValue).toStrictEqual(value)
643
642
  continue
644
643
  }
645
644
  expect(actualValue).toBe(value)