@bsv/wallet-toolbox 1.2.26 → 1.2.28

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.2.26",
3
+ "version": "1.2.28",
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",
@@ -1,4 +1,4 @@
1
- import { WalletInterface, Utils, PushDrop, LockingScript, Transaction } from '@bsv/sdk'
1
+ import { WalletInterface, Utils, PushDrop, LockingScript, Transaction, WalletProtocol } from '@bsv/sdk'
2
2
  import { validateCreateActionArgs } from './sdk'
3
3
 
4
4
  ////// TODO: ADD SUPPORT FOR ADMIN COUNTERPARTIES BASED ON WALLET STORAGE
@@ -23,7 +23,7 @@ export interface PermissionRequest {
23
23
  type: 'protocol' | 'basket' | 'certificate' | 'spending'
24
24
  originator: string // The domain or FQDN of the requesting application
25
25
  privileged?: boolean // For "protocol" or "certificate" usage, indicating privileged key usage
26
- protocolID?: [0 | 1 | 2, string] // For type='protocol': BRC-43 style (securityLevel, protocolName)
26
+ protocolID?: WalletProtocol // For type='protocol': BRC-43 style (securityLevel, protocolName)
27
27
  counterparty?: string // For type='protocol': e.g. target public key or "self"/"anyone"
28
28
 
29
29
  basket?: string // For type='basket': the basket name being requested
@@ -509,7 +509,7 @@ export class WalletPermissionsManager implements WalletInterface {
509
509
  }: {
510
510
  originator: string
511
511
  privileged: boolean
512
- protocolID: [0 | 1 | 2, string]
512
+ protocolID: WalletProtocol
513
513
  counterparty: string
514
514
  reason?: string
515
515
  seekPermission?: boolean
@@ -985,7 +985,7 @@ export class WalletPermissionsManager implements WalletInterface {
985
985
  private async findProtocolToken(
986
986
  originator: string,
987
987
  privileged: boolean,
988
- protocolID: [0 | 1 | 2, string],
988
+ protocolID: WalletProtocol,
989
989
  counterparty: string,
990
990
  includeExpired: boolean
991
991
  ): Promise<PermissionToken | undefined> {
@@ -1489,7 +1489,7 @@ export class WalletPermissionsManager implements WalletInterface {
1489
1489
  public async hasProtocolPermission(params: {
1490
1490
  originator: string
1491
1491
  privileged: boolean
1492
- protocolID: [0 | 1 | 2, string]
1492
+ protocolID: WalletProtocol
1493
1493
  counterparty: string
1494
1494
  }): Promise<boolean> {
1495
1495
  try {
@@ -2369,7 +2369,7 @@ export class WalletPermissionsManager implements WalletInterface {
2369
2369
  *
2370
2370
  * If it violates these rules and the caller is not admin, we consider it "admin-only."
2371
2371
  */
2372
- private isAdminProtocol(proto: [0 | 1 | 2, string]): boolean {
2372
+ private isAdminProtocol(proto: WalletProtocol): boolean {
2373
2373
  const protocolName = proto[1]
2374
2374
  if (protocolName.startsWith('admin') || protocolName.startsWith('p ')) {
2375
2375
  return true
@@ -47,7 +47,7 @@ export const DEFAULT_SETTINGS = {
47
47
  name: 'Babbage Trust Services',
48
48
  description: 'Resolves identity information for Babbage-run APIs and Bitcoin infrastructure.',
49
49
  iconUrl: 'https://projectbabbage.com/favicon.ico',
50
- identityKey: '028703956178067ea7ca405111f1ca698290a0112a3d7cf3d843e195bf58a7cfa6',
50
+ identityKey: '03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8',
51
51
  trust: 4
52
52
  },
53
53
  {
@@ -62,7 +62,7 @@ export const DEFAULT_SETTINGS = {
62
62
  description: 'Certifies social media handles, phone numbers and emails',
63
63
  iconUrl: 'https://socialcert.net/favicon.ico',
64
64
  trust: 3,
65
- identityKey: '03285263f06139b66fb27f51cf8a92e9dd007c4c4b83876ad6c3e7028db450a4c2'
65
+ identityKey: '02cf6cdf466951d8dfc9e7c9367511d0007ed6fba35ed42d425cc412fd6cfd4a17'
66
66
  }
67
67
  ]
68
68
  },
@@ -107,10 +107,10 @@ export class WalletSettingsManager {
107
107
  */
108
108
  async get(): Promise<WalletSettings> {
109
109
  // List outputs in the 'wallet-settings' basket
110
+ // There should only be one settings token
110
111
  const results = await this.wallet.listOutputs({
111
112
  basket: SETTINGS_BASKET,
112
- include: 'locking scripts',
113
- limit: 1 // There should only be one settings token
113
+ include: 'locking scripts'
114
114
  })
115
115
 
116
116
  // Return defaults if no settings token is found
@@ -118,7 +118,9 @@ export class WalletSettingsManager {
118
118
  return this.config.defaultSettings
119
119
  }
120
120
 
121
- const { fields } = PushDrop.decode(LockingScript.fromHex(results.outputs[0].lockingScript!))
121
+ const { fields } = PushDrop.decode(
122
+ LockingScript.fromHex(results.outputs[results.outputs.length - 1].lockingScript!)
123
+ )
122
124
  // Parse and return settings token
123
125
  return JSON.parse(Utils.toUTF8(fields[0]))
124
126
  }
@@ -164,15 +166,12 @@ export class WalletSettingsManager {
164
166
  // 1. List the existing token UTXO(s) for the settings basket.
165
167
  const existingUtxos = await this.wallet.listOutputs({
166
168
  basket: SETTINGS_BASKET,
167
- include: 'entire transactions',
168
- limit: 1
169
+ include: 'entire transactions'
169
170
  })
170
171
 
171
172
  // This is the "create a new token" path — no signAction, just a new locking script.
172
173
  if (!existingUtxos.outputs.length) {
173
174
  if (!newLockingScript) {
174
- // The intention was to clear the token, but no tokn was found to clear.
175
- // Thus, we are done.
176
175
  return true
177
176
  }
178
177
  await this.wallet.createAction({
@@ -186,14 +185,15 @@ export class WalletSettingsManager {
186
185
  }
187
186
  ],
188
187
  options: {
189
- randomizeOutputs: false
188
+ randomizeOutputs: false,
189
+ acceptDelayedBroadcast: false
190
190
  }
191
191
  })
192
192
  return true
193
193
  }
194
194
 
195
195
  // 2. Prepare the token UTXO for consumption.
196
- const tokenOutput = existingUtxos.outputs[0]
196
+ const tokenOutput = existingUtxos.outputs[existingUtxos.outputs.length - 1]
197
197
  const inputToConsume: CreateActionInput = {
198
198
  outpoint: tokenOutput.outpoint,
199
199
  unlockingScriptLength: 73,
@@ -219,7 +219,8 @@ export class WalletSettingsManager {
219
219
  inputs: [inputToConsume], // input index 0
220
220
  outputs,
221
221
  options: {
222
- randomizeOutputs: false
222
+ randomizeOutputs: false,
223
+ acceptDelayedBroadcast: false
223
224
  }
224
225
  })
225
226
  const tx = Transaction.fromBEEF(signableTransaction!.tx)
@@ -210,14 +210,14 @@ export async function listOutputs(
210
210
  isDeleted: false
211
211
  })
212
212
  .whereNotNull('outputTagId')
213
- .whereIn('tag', vargs.tags)
213
+ .whereIn('tag', tags)
214
214
  .select('outputTagId')
215
215
  const r = await q
216
216
  tagIds = r.map(r => r.outputTagId!)
217
217
  }
218
218
 
219
219
  const isQueryModeAll = vargs.tagQueryMode === 'all'
220
- if (isQueryModeAll && tagIds.length < vargs.tags.length) return r
220
+ if (isQueryModeAll && tagIds.length < tags.length) return r
221
221
 
222
222
  const columns: string[] = [
223
223
  'outputId',
@@ -1,6 +1,6 @@
1
- import { EntitySyncState, sdk } from '../../../src'
2
- import { _tu } from '../../utils/TestUtilsWalletStorage'
3
- import { specOpInvalidChange, WERR_REVIEW_ACTIONS } from '../../../src/sdk'
1
+ import { EntitySyncState, sdk, Services, Setup, StorageKnex, TableOutput, TableUser } from '../../../src'
2
+ import { _tu, TuEnv } from '../../utils/TestUtilsWalletStorage'
3
+ import { specOpInvalidChange, ValidListOutputsArgs, WERR_REVIEW_ACTIONS } from '../../../src/sdk'
4
4
  import {
5
5
  burnOneSatTestOutput,
6
6
  createOneSatTestOutput,
@@ -11,6 +11,10 @@ import {
11
11
  } from './localWalletMethods'
12
12
  import { abort } from 'process'
13
13
 
14
+ import * as dotenv from 'dotenv'
15
+ import { WalletOutput } from '@bsv/sdk'
16
+ dotenv.config()
17
+
14
18
  const chain: sdk.Chain = 'main'
15
19
 
16
20
  const options: LocalWalletTestOptions = {
@@ -93,4 +97,74 @@ describe('localWallet2 tests', () => {
93
97
  }
94
98
  await setup.wallet.destroy()
95
99
  })
100
+
101
+ test('5 review and release all production invalid change utxos', async () => {
102
+ const { env, storage } = await createMainReviewSetup()
103
+ const users = await storage.findUsers({ partial: {} })
104
+ const withInvalid: Record<number, { user: TableUser; outputs: WalletOutput[]; total: number }> = {}
105
+ // [76, 48, 166, 94, 110, 111, 81]
106
+ const vargs: ValidListOutputsArgs = {
107
+ basket: specOpInvalidChange,
108
+ tags: [],
109
+ tagQueryMode: 'all',
110
+ includeLockingScripts: false,
111
+ includeTransactions: false,
112
+ includeCustomInstructions: false,
113
+ includeTags: false,
114
+ includeLabels: false,
115
+ limit: 0,
116
+ offset: 0,
117
+ seekPermission: false,
118
+ knownTxids: []
119
+ }
120
+ for (const user of users) {
121
+ const { userId } = user
122
+ const auth = { userId, identityKey: '' }
123
+ let r = await storage.listOutputs(auth, vargs)
124
+ if (r.totalOutputs > 0) {
125
+ const total: number = r.outputs.reduce((s, o) => (s += o.satoshis), 0)
126
+ console.log(`userId ${userId}: ${r.totalOutputs} unspendable utxos, total ${total}, ${user.identityKey}`)
127
+ withInvalid[userId] = { user, outputs: r.outputs, total }
128
+ }
129
+ }
130
+ if (Object.keys(withInvalid).length > 0) {
131
+ debugger
132
+ // Release invalids
133
+ for (const { user, outputs } of Object.values(withInvalid)) {
134
+ const { userId } = user
135
+ const auth = { userId, identityKey: '' }
136
+ await storage.listOutputs(auth, { ...vargs, tags: ['release'] })
137
+ }
138
+ // Verify
139
+ for (const { user, outputs } of Object.values(withInvalid)) {
140
+ const { userId } = user
141
+ const auth = { userId, identityKey: '' }
142
+ const r = await storage.listOutputs(auth, vargs)
143
+ expect(r.totalOutputs).toBe(0)
144
+ }
145
+ }
146
+ await storage.destroy()
147
+ })
96
148
  })
149
+
150
+ async function createMainReviewSetup(): Promise<{
151
+ env: TuEnv
152
+ storage: StorageKnex
153
+ services: Services
154
+ }> {
155
+ const env = _tu.getEnv('main')
156
+ const knex = Setup.createMySQLKnex(process.env.MAIN_CLOUD_MYSQL_CONNECTION!)
157
+ const storage = new StorageKnex({
158
+ chain: env.chain,
159
+ knex: knex,
160
+ commissionSatoshis: 0,
161
+ commissionPubKeyHex: undefined,
162
+ feeModel: { model: 'sat/kb', value: 1 }
163
+ })
164
+ const servicesOptions = Services.createDefaultOptions(env.chain)
165
+ if (env.whatsonchainApiKey) servicesOptions.whatsOnChainApiKey = env.whatsonchainApiKey
166
+ const services = new Services(servicesOptions)
167
+ storage.setServices(services)
168
+ await storage.makeAvailable()
169
+ return { env, storage, services }
170
+ }