@bsv/wallet-toolbox 1.1.33 → 1.1.35

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.
Files changed (120) hide show
  1. package/docs/client.md +215 -213
  2. package/docs/setup.md +2 -2
  3. package/docs/storage.md +140 -34
  4. package/docs/wallet.md +215 -213
  5. package/out/src/Setup.d.ts.map +1 -1
  6. package/out/src/Setup.js +2 -2
  7. package/out/src/Setup.js.map +1 -1
  8. package/out/src/sdk/WERR_errors.d.ts +1 -1
  9. package/out/src/sdk/WERR_errors.d.ts.map +1 -1
  10. package/out/src/sdk/WERR_errors.js +2 -2
  11. package/out/src/sdk/WERR_errors.js.map +1 -1
  12. package/out/src/sdk/WalletStorage.interfaces.d.ts +107 -0
  13. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  14. package/out/src/sdk/index.d.ts +0 -2
  15. package/out/src/sdk/index.d.ts.map +1 -1
  16. package/out/src/sdk/index.js +0 -2
  17. package/out/src/sdk/index.js.map +1 -1
  18. package/out/src/services/__tests/verifyBeef.test.d.ts +2 -0
  19. package/out/src/services/__tests/verifyBeef.test.d.ts.map +1 -0
  20. package/out/src/services/__tests/verifyBeef.test.js +16 -0
  21. package/out/src/services/__tests/verifyBeef.test.js.map +1 -0
  22. package/out/src/services/providers/__tests/WhatsOnChain.test.js +11 -0
  23. package/out/src/services/providers/__tests/WhatsOnChain.test.js.map +1 -1
  24. package/out/src/storage/StorageReader.d.ts +1 -1
  25. package/out/src/storage/StorageReader.d.ts.map +1 -1
  26. package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
  27. package/out/src/storage/StorageReaderWriter.js +2 -1
  28. package/out/src/storage/StorageReaderWriter.js.map +1 -1
  29. package/out/src/storage/StorageSyncReader.d.ts +2 -18
  30. package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
  31. package/out/src/storage/StorageSyncReader.js +1 -105
  32. package/out/src/storage/StorageSyncReader.js.map +1 -1
  33. package/out/src/storage/WalletStorageManager.d.ts +86 -10
  34. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  35. package/out/src/storage/WalletStorageManager.js +235 -78
  36. package/out/src/storage/WalletStorageManager.js.map +1 -1
  37. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +1 -1
  38. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  39. package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
  40. package/out/src/storage/schema/KnexMigrations.js +19 -0
  41. package/out/src/storage/schema/KnexMigrations.js.map +1 -1
  42. package/out/src/storage/schema/entities/User.d.ts +2 -2
  43. package/out/src/storage/schema/entities/User.d.ts.map +1 -1
  44. package/out/src/storage/schema/entities/User.js +1 -1
  45. package/out/src/storage/schema/entities/User.js.map +1 -1
  46. package/out/src/storage/schema/entities/__tests/SyncStateTests.test.js +2 -1
  47. package/out/src/storage/schema/entities/__tests/SyncStateTests.test.js.map +1 -1
  48. package/out/src/storage/schema/entities/__tests/usersTests.test.js +12 -6
  49. package/out/src/storage/schema/entities/__tests/usersTests.test.js.map +1 -1
  50. package/out/src/storage/schema/tables/User.d.ts +1 -1
  51. package/out/src/storage/schema/tables/User.d.ts.map +1 -1
  52. package/out/src/storage/sync/StorageMySQLDojoReader.d.ts +1 -1
  53. package/out/src/storage/sync/StorageMySQLDojoReader.d.ts.map +1 -1
  54. package/out/src/storage/sync/StorageMySQLDojoReader.js +4 -5
  55. package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
  56. package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js +25 -13
  57. package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +1 -1
  58. package/out/test/Wallet/sync/setActive.test.d.ts +2 -0
  59. package/out/test/Wallet/sync/setActive.test.d.ts.map +1 -0
  60. package/out/test/Wallet/sync/setActive.test.js +60 -0
  61. package/out/test/Wallet/sync/setActive.test.js.map +1 -0
  62. package/out/test/examples/{backup.test.d.ts → backup.man.test.d.ts} +1 -1
  63. package/out/test/examples/backup.man.test.d.ts.map +1 -0
  64. package/out/test/examples/{backup.test.js → backup.man.test.js} +1 -1
  65. package/out/test/examples/backup.man.test.js.map +1 -0
  66. package/out/test/storage/StorageMySQLDojoReader.man.test.js.map +1 -1
  67. package/out/test/storage/count.test.js +1 -0
  68. package/out/test/storage/count.test.js.map +1 -1
  69. package/out/test/storage/find.test.js +1 -0
  70. package/out/test/storage/find.test.js.map +1 -1
  71. package/out/test/storage/update.test.js +3 -1
  72. package/out/test/storage/update.test.js.map +1 -1
  73. package/out/test/storage/update2.test.js +5 -2
  74. package/out/test/storage/update2.test.js.map +1 -1
  75. package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
  76. package/out/test/utils/TestUtilsWalletStorage.js +5 -4
  77. package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
  78. package/out/test/wallet/sync/Wallet.sync.test.js +1 -3
  79. package/out/test/wallet/sync/Wallet.sync.test.js.map +1 -1
  80. package/out/tsconfig.all.tsbuildinfo +1 -1
  81. package/package.json +1 -1
  82. package/src/Setup.ts +3 -2
  83. package/src/sdk/WERR_errors.ts +3 -2
  84. package/src/sdk/WalletStorage.interfaces.ts +117 -0
  85. package/src/sdk/index.ts +0 -2
  86. package/src/services/__tests/verifyBeef.test.ts +18 -0
  87. package/src/services/providers/__tests/WhatsOnChain.test.ts +16 -1
  88. package/src/storage/StorageReader.ts +1 -1
  89. package/src/storage/StorageReaderWriter.ts +2 -1
  90. package/src/storage/StorageSyncReader.ts +2 -109
  91. package/src/storage/WalletStorageManager.ts +307 -86
  92. package/src/storage/methods/attemptToPostReqsToNetwork.ts +1 -1
  93. package/src/storage/schema/KnexMigrations.ts +23 -1
  94. package/src/storage/schema/entities/User.ts +2 -2
  95. package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +2 -1
  96. package/src/storage/schema/entities/__tests/usersTests.test.ts +12 -6
  97. package/src/storage/schema/tables/User.ts +1 -1
  98. package/src/storage/sync/StorageMySQLDojoReader.ts +8 -6
  99. package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +30 -13
  100. package/test/Wallet/sync/setActive.test.ts +67 -0
  101. package/test/storage/StorageMySQLDojoReader.man.test.ts +1 -1
  102. package/test/storage/count.test.ts +1 -0
  103. package/test/storage/find.test.ts +1 -0
  104. package/test/storage/update.test.ts +3 -1
  105. package/test/storage/update2.test.ts +5 -2
  106. package/test/utils/TestUtilsWalletStorage.ts +5 -4
  107. package/test/wallet/sync/Wallet.sync.test.ts +1 -3
  108. package/out/src/sdk/StorageSyncReader.d.ts +0 -121
  109. package/out/src/sdk/StorageSyncReader.d.ts.map +0 -1
  110. package/out/src/sdk/StorageSyncReader.js +0 -3
  111. package/out/src/sdk/StorageSyncReader.js.map +0 -1
  112. package/out/src/sdk/StorageSyncReaderWriter.d.ts +0 -89
  113. package/out/src/sdk/StorageSyncReaderWriter.d.ts.map +0 -1
  114. package/out/src/sdk/StorageSyncReaderWriter.js +0 -3
  115. package/out/src/sdk/StorageSyncReaderWriter.js.map +0 -1
  116. package/out/test/examples/backup.test.d.ts.map +0 -1
  117. package/out/test/examples/backup.test.js.map +0 -1
  118. package/src/sdk/StorageSyncReader.ts +0 -173
  119. package/src/sdk/StorageSyncReaderWriter.ts +0 -277
  120. /package/test/examples/{backup.test.ts → backup.man.test.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/wallet-toolbox",
3
- "version": "1.1.33",
3
+ "version": "1.1.35",
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",
package/src/Setup.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  } from '@bsv/sdk'
14
14
  import {
15
15
  Monitor,
16
+ randomBytesHex,
16
17
  sdk,
17
18
  Services,
18
19
  StorageClient,
@@ -157,7 +158,7 @@ DEV_KEYS = '{
157
158
  args.active,
158
159
  args.backups
159
160
  )
160
- if (storage.stores.length > 0) await storage.makeAvailable()
161
+ if (storage.canMakeAvailable()) await storage.makeAvailable()
161
162
  const serviceOptions = Services.createDefaultOptions(chain)
162
163
  serviceOptions.taalApiKey = args.env.taalApiKey
163
164
  const services = new Services(serviceOptions)
@@ -411,7 +412,7 @@ DEV_KEYS = '{
411
412
  commissionPubKeyHex: undefined,
412
413
  feeModel: { model: 'sat/kb', value: 1 }
413
414
  })
414
- await storage.migrate(args.databaseName, wo.identityKey)
415
+ await storage.migrate(args.databaseName, randomBytesHex(33))
415
416
  await storage.makeAvailable()
416
417
  await wo.wallet.destroy()
417
418
  return storage
@@ -113,13 +113,14 @@ export class WERR_UNAUTHORIZED extends WalletError {
113
113
  }
114
114
 
115
115
  /**
116
- * WalletStorageManager is not accessing user's active storage.
116
+ * WalletStorageManager is not accessing user's active storage or there are conflicting active stores configured.
117
117
  */
118
118
  export class WERR_NOT_ACTIVE extends WalletError {
119
119
  constructor(message?: string) {
120
120
  super(
121
121
  'WERR_NOT_ACTIVE',
122
- message ?? `WalletStorageManager is not accessing user's active storage.`
122
+ message ??
123
+ `WalletStorageManager is not accessing user's active storage or there are conflicting active stores configured.`
123
124
  )
124
125
  }
125
126
  }
@@ -111,6 +111,11 @@ export interface WalletStorageSync extends WalletStorageWriter {
111
111
  storageName: string
112
112
  ): Promise<{ syncState: TableSyncState; isNew: boolean }>
113
113
 
114
+ /**
115
+ * Updagte the `activeStorage` property of the authenticated user by their `userId`.
116
+ * @param auth
117
+ * @param newActiveStorageIdentityKey
118
+ */
114
119
  setActive(
115
120
  auth: sdk.AuthId,
116
121
  newActiveStorageIdentityKey: string
@@ -123,6 +128,14 @@ export interface WalletStorageSync extends WalletStorageWriter {
123
128
  ): Promise<sdk.ProcessSyncChunkResult>
124
129
  }
125
130
 
131
+ /**
132
+ * This is the minimal interface required for a WalletStorageProvider to export data to another provider.
133
+ */
134
+ export interface WalletStorageSyncReader {
135
+ makeAvailable(): Promise<TableSettings>
136
+ getSyncChunk(args: RequestSyncChunkArgs): Promise<SyncChunk>
137
+ }
138
+
126
139
  export interface WalletStorageWriter extends WalletStorageReader {
127
140
  makeAvailable(): Promise<TableSettings>
128
141
  migrate(storageName: string, storageIdentityKey: string): Promise<string>
@@ -437,3 +450,107 @@ export interface UpdateProvenTxReqWithNewProvenTxResult {
437
450
  provenTxId: number
438
451
  log?: string
439
452
  }
453
+
454
+ /**
455
+ * success: Last sync of this user from this storage was successful.
456
+ *
457
+ * error: Last sync protocol operation for this user to this storage threw and error.
458
+ *
459
+ * identified: Configured sync storage has been identified but not sync'ed.
460
+ *
461
+ * unknown: Sync protocol state is unknown.
462
+ */
463
+ export type SyncStatus =
464
+ | 'success'
465
+ | 'error'
466
+ | 'identified'
467
+ | 'updated'
468
+ | 'unknown'
469
+
470
+ export type SyncProtocolVersion = '0.1.0'
471
+
472
+ export interface RequestSyncChunkArgs {
473
+ /**
474
+ * The storageIdentityKey of the storage supplying the update SyncChunk data.
475
+ */
476
+ fromStorageIdentityKey: string
477
+ /**
478
+ * The storageIdentityKey of the storage consuming the update SyncChunk data.
479
+ */
480
+ toStorageIdentityKey: string
481
+
482
+ /**
483
+ * The identity of whose data is being requested
484
+ */
485
+ identityKey: string
486
+ /**
487
+ * The max updated_at time received from the storage service receiving the request.
488
+ * Will be undefiend if this is the first request or if no data was previously sync'ed.
489
+ *
490
+ * `since` must include items if 'updated_at' is greater or equal. Thus, when not undefined, a sync request should always return at least one item already seen.
491
+ */
492
+ since?: Date
493
+ /**
494
+ * A rough limit on how large the response should be.
495
+ * The item that exceeds the limit is included and ends adding more items.
496
+ */
497
+ maxRoughSize: number
498
+ /**
499
+ * The maximum number of items (records) to be returned.
500
+ */
501
+ maxItems: number
502
+ /**
503
+ * For each entity in dependency order, the offset at which to start returning items
504
+ * from `since`.
505
+ *
506
+ * The entity order is:
507
+ * 0 ProvenTxs
508
+ * 1 ProvenTxReqs
509
+ * 2 OutputBaskets
510
+ * 3 TxLabels
511
+ * 4 OutputTags
512
+ * 5 Transactions
513
+ * 6 TxLabelMaps
514
+ * 7 Commissions
515
+ * 8 Outputs
516
+ * 9 OutputTagMaps
517
+ * 10 Certificates
518
+ * 11 CertificateFields
519
+ */
520
+ offsets: { name: string; offset: number }[]
521
+ }
522
+
523
+ /**
524
+ * Result received from remote `WalletStorage` in response to a `RequestSyncChunkArgs` request.
525
+ *
526
+ * Each property is undefined if there was no attempt to update it. Typically this is caused by size and count limits on this result.
527
+ *
528
+ * If all properties are empty arrays the sync process has received all available new and updated items.
529
+ */
530
+ export interface SyncChunk {
531
+ fromStorageIdentityKey: string
532
+ toStorageIdentityKey: string
533
+ userIdentityKey: string
534
+
535
+ user?: TableUser
536
+ provenTxs?: TableProvenTx[]
537
+ provenTxReqs?: TableProvenTxReq[]
538
+ outputBaskets?: TableOutputBasket[]
539
+ txLabels?: TableTxLabel[]
540
+ outputTags?: TableOutputTag[]
541
+ transactions?: TableTransaction[]
542
+ txLabelMaps?: TableTxLabelMap[]
543
+ commissions?: TableCommission[]
544
+ outputs?: TableOutput[]
545
+ outputTagMaps?: TableOutputTagMap[]
546
+ certificates?: TableCertificate[]
547
+ certificateFields?: TableCertificateField[]
548
+ }
549
+
550
+ export interface ProcessSyncChunkResult {
551
+ done: boolean
552
+ maxUpdated_at: Date | undefined
553
+ updates: number
554
+ inserts: number
555
+ error?: sdk.WalletError
556
+ }
package/src/sdk/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export * from './WalletError'
2
2
  export * from './WalletSigner.interfaces'
3
3
  export * from './WalletStorage.interfaces'
4
- export * from './StorageSyncReader'
5
- export * from './StorageSyncReaderWriter'
6
4
  export * from './WERR_errors'
7
5
  export * from './validationHelpers'
8
6
  export * from './CertOps'
@@ -0,0 +1,18 @@
1
+ import { Beef } from '@bsv/sdk'
2
+ import { Services } from '../Services'
3
+
4
+ describe('verifyBeef tests', () => {
5
+ jest.setTimeout(99999999)
6
+
7
+ test('0_', async () => {
8
+ const bhex =
9
+ '0200beef01fe7c830d000a02a0021d4ca6c031db7f6334c08ddfda43cbde3800c7fa27892f8e80a5218ca8493918a10081788ac8d8267d409b6258a6a6f5d28317ee65b5b25892def4f6cbf44f92571d01510027c2382032711033d0a1e2724b9eefcf257e27bce28e37b7472877860570ee6e0129008e15879954392f322efdd32376077a3323db02501926a697f5db6b68862f67ce01150061dcb195186d564d754a056d9ad90d65ece5bfa5ddccebd24b64d25df3780b15010b00bcd8f2c9c62b4fbbefad9640f9f6dccf21246fa08a6e1cab2c052666dee4182001040018ad6a5739749e27c191a5ef7442d861e5b8d204d36c91e08bf8015811851dbe010300f47047d1c4582eb02349eabcdafc7f4573e93ed687718275475d6f528783d16201000039a5fa5dbbbcd4a1754c250a7879ae1ad2eeb189d87d3614c2a2d9519a7a47af0101001670fc6a8d40adbd3f8a84ae35f0a702695f19f19a8feddcfd1de6249cc164e901010092a689a4cda27aea3552a98a7441ffbaed8566ae31e0a1a67e67647e2f3b8fda05025a8b77e1c82cfcfda197fec3f805a6b7000737a583e45833df6721975fe8bad102448f38860c45d33c87041c0fda51befb1c90853d3141a0df3ac737ccb9b5e61b01000100000001f7ddf439a165bf63a7d6c144b4bd8882ff45dc35a3ca3e75517fa56482fed6bd000000006b4830450221008106bc7164333415bc485ae1d12acd72bbc536f1f03b25aa42d92971565b329902202d484d09935be7fa49bbd5806148dbfdb90cc86516537351acf20655c03fa656412102b53b5339d6241c4271a07e7b09035966defe37c1a3edd60b8a427d5a5b488cb5ffffffff021d00000000000000c421029664d9baa433b4ded47ce151d348fda7ed30df597b93bf5f321ec2fe742b0faaac2131546f446f44744b7265457a6248594b466a6d6f42756475466d53585855475a4734aba7171082ff009628f6d1abea57bc1ffcdb6c2b45a5e17219eaf6bc6b6e093b5243036565505084548f9715a440b6c03e73427d4730450221008e4964dc5e8f3cc6f41da7508cba05babb2ce211fa47fe91ae9c06903d95fde902206cb21d6c188f302fccedbbcd80459561dbabcabe3da16853371fede9f5d027d06d75c8030000000000001976a914f8a84c2bef6eed4eb3270c8605a8063202ed25cb88ac000000000001000000015a8b77e1c82cfcfda197fec3f805a6b7000737a583e45833df6721975fe8bad1010000006b483045022100fb62de36ac2930029b1397931c3f30bf6df5166f2e82bed6b2ef1d23491f8e450220730105461dc12236439ee568709ee72c345bb6748efe8656a0e96e4cc5eaecfb412102c6b33e96f3b635ebd71bcedd9bcb90b4c098b9b38730f58984e23615e0864833ffffffff042800000000000000c521029664d9baa433b4ded47ce151d348fda7ed30df597b93bf5f321ec2fe742b0faaac2131546f446f44744b7265457a6248594b466a6d6f42756475466d53585855475a47361c08d47822cb0806cd17af298948641db6bd36440da9a988af0f6600cba6dabfcfe5c7fe086b7a08e8feef3a9d21d8b0126c2f4a260b46304402204f418ece238fb0587f887c1e0ea6beb4ebcefa6749d1b523195bd65dc9971374022009d0b21c669a72a8a01808d394c55de730a3a4d287b3bb209697b2e79a9787ce6d7516050000000000001976a914803a2e1d2ca2373c21129a7075f1a42587f16c8188acec030000000000001976a91441cb6381a584c464df4b6dd75b91fb0ab6c4b7a688acd0040000000000001976a914e08fbd92ba37c1d84bba8439c55793ea60c0dd6b88ac00000000000100000001448f38860c45d33c87041c0fda51befb1c90853d3141a0df3ac737ccb9b5e61b020000006a4730440220411ab1f23f747899bf71185fbb4ab03defc6e215fb1ee3d24060b14256d2dc40022035669cd13b5c5fd399a402862b4e6bc001d0cbf56660bac37b1563eeaf49a700412103b20f91159733fd69817cc4d4f9ed0cf4340f63b482e0a0a7f233885c61d1b044ffffffff020a00000000000000c421029664d9baa433b4ded47ce151d348fda7ed30df597b93bf5f321ec2fe742b0faaac2131546f446f44744b7265457a6248594b466a6d6f42756475466d53585855475a47343c32fe905bb02e70c0a9779048c921b1e26a2684c498ab44759ac25bcdfafa95309c59d1c3ac12f056ad8d10dabe777d1d57dd934730450221009a64cdc81a0ada12d329463db24260a15ad56bdc3523613c0fae2fb64762d20e022021b942e859749fc23585fdb0395585d6ea52dcf0a310cc989a38ff0483c8717e6d75b7150000000000001976a91468cce1214ccbd14d9dfd813d8490daadaa96b39288ac00000000'
10
+ const beef = Beef.fromString(bhex)
11
+ const chaintracker = await new Services('main').getChainTracker()
12
+
13
+ console.log(beef.toLogString())
14
+
15
+ const ok = await beef.verify(chaintracker, true)
16
+ expect(ok)
17
+ })
18
+ })
@@ -2,7 +2,7 @@ import { WhatsOnChainBroadcaster, WhatsOnChainConfig } from '@bsv/sdk'
2
2
  import { _tu } from '../../../../test/utils/TestUtilsWalletStorage'
3
3
  import { WhatsOnChain } from '../WhatsOnChain'
4
4
  import { Services } from '../../Services'
5
- import { sdk, wait } from '../../../index.client'
5
+ import { sdk, StorageClient, wait } from '../../../index.client'
6
6
  import { Setup, StorageKnex } from '../../../index.all'
7
7
  describe('whatsonchain tests', () => {
8
8
  jest.setTimeout(99999999)
@@ -224,4 +224,19 @@ describe('whatsonchain tests', () => {
224
224
 
225
225
  await c.wallet.destroy()
226
226
  })
227
+
228
+ test.skip('8c backup to cloud', async () => {
229
+ if (Setup.noEnv('main')) return
230
+ if (!Setup.getEnv('main').filePath) return
231
+
232
+ const c = await _tu.createWalletSetupEnv('main')
233
+ const client = new StorageClient(
234
+ c.wallet,
235
+ 'https://storage.babbage.systems'
236
+ )
237
+ await c.storage.addWalletStorageProvider(client)
238
+ await c.storage.updateBackups()
239
+
240
+ await c.wallet.destroy()
241
+ })
227
242
  })
@@ -35,7 +35,7 @@ import { getSyncChunk } from './methods/getSyncChunk'
35
35
  * The ability to construct a properly configured instance of this class implies authentication.
36
36
  * As such there are no user specific authenticated access checks implied in the implementation of any of these methods.
37
37
  */
38
- export abstract class StorageReader implements sdk.StorageSyncReader {
38
+ export abstract class StorageReader implements sdk.WalletStorageSyncReader {
39
39
  chain: sdk.Chain
40
40
  _settings?: TableSettings
41
41
  whenLastAccess?: Date
@@ -310,7 +310,8 @@ export abstract class StorageReaderWriter extends StorageReader {
310
310
  created_at: now,
311
311
  updated_at: now,
312
312
  userId: 0,
313
- identityKey
313
+ identityKey,
314
+ activeStorage: this.getSettings().storageIdentityKey
314
315
  }
315
316
  user.userId = await this.insertUser(user, trx)
316
317
  isNew = true
@@ -25,15 +25,12 @@ import { StorageReader } from './StorageReader'
25
25
  * Constructed from an `auth` object that must minimally include the authenticated user's identityKey,
26
26
  * and the `StorageBaseReader` to be protected.
27
27
  */
28
- export class StorageSyncReader implements sdk.StorageSyncReader {
28
+ export class StorageSyncReader implements sdk.WalletStorageSyncReader {
29
29
  constructor(
30
30
  public auth: sdk.AuthId,
31
31
  public storage: StorageReader
32
32
  ) {}
33
33
 
34
- isAvailable(): boolean {
35
- return this.storage.isAvailable()
36
- }
37
34
  async makeAvailable(): Promise<TableSettings> {
38
35
  await this.storage.makeAvailable()
39
36
  if (this.auth.userId === undefined) {
@@ -43,119 +40,15 @@ export class StorageSyncReader implements sdk.StorageSyncReader {
43
40
  if (!user) throw new sdk.WERR_UNAUTHORIZED()
44
41
  this.auth.userId = user.userId
45
42
  }
46
- return this.getSettings()
43
+ return this.storage.getSettings()
47
44
  }
48
45
  destroy(): Promise<void> {
49
46
  return this.storage.destroy()
50
47
  }
51
- getSettings(): TableSettings {
52
- return this.storage.getSettings()
53
- }
54
48
  async getSyncChunk(args: sdk.RequestSyncChunkArgs): Promise<sdk.SyncChunk> {
55
49
  if (!this.auth.userId) await this.makeAvailable()
56
50
  if (args.identityKey !== this.auth.identityKey)
57
51
  throw new sdk.WERR_UNAUTHORIZED()
58
52
  return await this.storage.getSyncChunk(args)
59
53
  }
60
- async findUserByIdentityKey(key: string): Promise<TableUser | undefined> {
61
- if (!this.auth.userId) await this.makeAvailable()
62
- if (key !== this.auth.identityKey) throw new sdk.WERR_UNAUTHORIZED()
63
- return await this.storage.findUserByIdentityKey(key)
64
- }
65
- async findSyncStates(
66
- args: sdk.FindSyncStatesArgs
67
- ): Promise<TableSyncState[]> {
68
- if (!this.auth.userId) await this.makeAvailable()
69
- if (args.partial.userId !== this.auth.userId)
70
- throw new sdk.WERR_UNAUTHORIZED()
71
- return await this.storage.findSyncStates(args)
72
- }
73
- async findCertificateFields(
74
- args: sdk.FindCertificateFieldsArgs
75
- ): Promise<TableCertificateField[]> {
76
- if (!this.auth.userId) await this.makeAvailable()
77
- if (args.partial.userId !== this.auth.userId)
78
- throw new sdk.WERR_UNAUTHORIZED()
79
- return await this.storage.findCertificateFields(args)
80
- }
81
- async findCertificates(
82
- args: sdk.FindCertificatesArgs
83
- ): Promise<TableCertificateX[]> {
84
- if (!this.auth.userId) await this.makeAvailable()
85
- if (args.partial.userId !== this.auth.userId)
86
- throw new sdk.WERR_UNAUTHORIZED()
87
- return await this.storage.findCertificates(args)
88
- }
89
- async findCommissions(
90
- args: sdk.FindCommissionsArgs
91
- ): Promise<TableCommission[]> {
92
- if (!this.auth.userId) await this.makeAvailable()
93
- if (args.partial.userId !== this.auth.userId)
94
- throw new sdk.WERR_UNAUTHORIZED()
95
- return await this.storage.findCommissions(args)
96
- }
97
- async findOutputBaskets(
98
- args: sdk.FindOutputBasketsArgs
99
- ): Promise<TableOutputBasket[]> {
100
- if (!this.auth.userId) await this.makeAvailable()
101
- if (args.partial.userId !== this.auth.userId)
102
- throw new sdk.WERR_UNAUTHORIZED()
103
- return await this.storage.findOutputBaskets(args)
104
- }
105
- async findOutputs(args: sdk.FindOutputsArgs): Promise<TableOutput[]> {
106
- if (!this.auth.userId) await this.makeAvailable()
107
- if (args.partial.userId !== this.auth.userId)
108
- throw new sdk.WERR_UNAUTHORIZED()
109
- return await this.storage.findOutputs(args)
110
- }
111
- async findOutputTags(
112
- args: sdk.FindOutputTagsArgs
113
- ): Promise<TableOutputTag[]> {
114
- if (!this.auth.userId) await this.makeAvailable()
115
- if (args.partial.userId !== this.auth.userId)
116
- throw new sdk.WERR_UNAUTHORIZED()
117
- return await this.storage.findOutputTags(args)
118
- }
119
- async findTransactions(
120
- args: sdk.FindTransactionsArgs
121
- ): Promise<TableTransaction[]> {
122
- if (!this.auth.userId) await this.makeAvailable()
123
- if (args.partial.userId !== this.auth.userId)
124
- throw new sdk.WERR_UNAUTHORIZED()
125
- return await this.storage.findTransactions(args)
126
- }
127
- async findTxLabels(args: sdk.FindTxLabelsArgs): Promise<TableTxLabel[]> {
128
- if (!this.auth.userId) await this.makeAvailable()
129
- if (args.partial.userId !== this.auth.userId)
130
- throw new sdk.WERR_UNAUTHORIZED()
131
- return await this.storage.findTxLabels(args)
132
- }
133
- async getProvenTxsForUser(
134
- args: sdk.FindForUserSincePagedArgs
135
- ): Promise<TableProvenTx[]> {
136
- if (!this.auth.userId) await this.makeAvailable()
137
- if (args.userId !== this.auth.userId) throw new sdk.WERR_UNAUTHORIZED()
138
- return await this.storage.getProvenTxsForUser(args)
139
- }
140
- async getProvenTxReqsForUser(
141
- args: sdk.FindForUserSincePagedArgs
142
- ): Promise<TableProvenTxReq[]> {
143
- if (!this.auth.userId) await this.makeAvailable()
144
- if (args.userId !== this.auth.userId) throw new sdk.WERR_UNAUTHORIZED()
145
- return await this.storage.getProvenTxReqsForUser(args)
146
- }
147
- async getTxLabelMapsForUser(
148
- args: sdk.FindForUserSincePagedArgs
149
- ): Promise<TableTxLabelMap[]> {
150
- if (!this.auth.userId) await this.makeAvailable()
151
- if (args.userId !== this.auth.userId) throw new sdk.WERR_UNAUTHORIZED()
152
- return await this.storage.getTxLabelMapsForUser(args)
153
- }
154
- async getOutputTagMapsForUser(
155
- args: sdk.FindForUserSincePagedArgs
156
- ): Promise<TableOutputTagMap[]> {
157
- if (!this.auth.userId) await this.makeAvailable()
158
- if (args.userId !== this.auth.userId) throw new sdk.WERR_UNAUTHORIZED()
159
- return await this.storage.getOutputTagMapsForUser(args)
160
- }
161
54
  }