@bsv/wallet-toolbox 1.2.32 → 1.2.33

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/docs/client.md CHANGED
@@ -5130,7 +5130,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
5130
5130
  | [MergeEntity](#class-mergeentity) | [TaskReviewStatus](#class-taskreviewstatus) | [WalletSigner](#class-walletsigner) |
5131
5131
  | [Monitor](#class-monitor) | [TaskSendWaiting](#class-tasksendwaiting) | [WalletStorageManager](#class-walletstoragemanager) |
5132
5132
  | [MonitorDaemon](#class-monitordaemon) | [TaskSyncWhenIdle](#class-tasksyncwhenidle) | [WhatsOnChain](#class-whatsonchain) |
5133
- | [OverlayUMPTokenInteractor](#class-overlayumptokeninteractor) | [TaskUnFail](#class-taskunfail) | |
5133
+ | [OverlayUMPTokenInteractor](#class-overlayumptokeninteractor) | [TaskUnFail](#class-taskunfail) | [localKVStore](#class-localkvstore) |
5134
5134
  | [PersonaIDInteractor](#class-personaidinteractor) | [TwilioPhoneInteractor](#class-twiliophoneinteractor) | |
5135
5135
 
5136
5136
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
@@ -10712,6 +10712,7 @@ Manages wallet settings
10712
10712
 
10713
10713
  ```ts
10714
10714
  export class WalletSettingsManager {
10715
+ kv: LocalKVStore;
10715
10716
  constructor(private wallet: WalletInterface, private config: WalletSettingsManagerConfig = {
10716
10717
  defaultSettings: DEFAULT_SETTINGS
10717
10718
  })
@@ -11146,6 +11147,117 @@ Argument Details
11146
11147
 
11147
11148
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
11148
11149
 
11150
+ ---
11151
+ ##### Class: localKVStore
11152
+
11153
+ Implements a key-value storage system backed by transaction outputs managed by a wallet.
11154
+ Each key-value pair is represented by a PushDrop token output in a specific context (basket).
11155
+ Allows setting, getting, and removing key-value pairs, with optional encryption.
11156
+
11157
+ ```ts
11158
+ export default class localKVStore {
11159
+ constructor(wallet?: WalletInterface, context?: string, encrypt?: boolean);
11160
+ get(key: string, defaultValue?: string | undefined): Promise<string | undefined>;
11161
+ set(key: string, value: string): Promise<OutpointString>;
11162
+ remove(key: string): Promise<OutpointString | void>;
11163
+ }
11164
+ ```
11165
+
11166
+ ###### Constructor
11167
+
11168
+ Creates an instance of the localKVStore.
11169
+
11170
+ ```ts
11171
+ constructor(wallet?: WalletInterface, context?: string, encrypt?: boolean)
11172
+ ```
11173
+
11174
+ Argument Details
11175
+
11176
+ + **wallet**
11177
+ + The wallet interface to use. Defaults to a new WalletClient instance.
11178
+ + **context**
11179
+ + The context (basket) for namespacing keys. Defaults to 'kvstore-default'.
11180
+ + **encrypt**
11181
+ + Whether to encrypt values. Defaults to true.
11182
+
11183
+ Throws
11184
+
11185
+ If the context is missing or empty.
11186
+
11187
+ ###### Method get
11188
+
11189
+ Retrieves the value associated with a given key.
11190
+
11191
+ ```ts
11192
+ get(key: string, defaultValue?: string | undefined): Promise<string | undefined>
11193
+ ```
11194
+
11195
+ Returns
11196
+
11197
+ A promise that resolves to the value as a string,
11198
+ the defaultValue if the key is not found, or undefined if no defaultValue is provided.
11199
+
11200
+ Argument Details
11201
+
11202
+ + **key**
11203
+ + The key to retrieve the value for.
11204
+ + **defaultValue**
11205
+ + The value to return if the key is not found.
11206
+
11207
+ Throws
11208
+
11209
+ If multiple outputs are found for the key (ambiguous state).
11210
+
11211
+ If the found output's locking script cannot be decoded or represents an invalid token format.
11212
+
11213
+ ###### Method remove
11214
+
11215
+ Removes the key-value pair associated with the given key.
11216
+ It finds the existing output(s) for the key and spends them without creating a new output.
11217
+ If multiple outputs exist, they are all spent in the same transaction.
11218
+ If the key does not exist, it does nothing.
11219
+ If signing the removal transaction fails, it relinquishes the original outputs instead of spending.
11220
+
11221
+ ```ts
11222
+ remove(key: string): Promise<OutpointString | void>
11223
+ ```
11224
+
11225
+ Returns
11226
+
11227
+ A promise that resolves to the txid of the removal transaction if successful.
11228
+
11229
+ Argument Details
11230
+
11231
+ + **key**
11232
+ + The key to remove.
11233
+
11234
+ ###### Method set
11235
+
11236
+ Sets or updates the value associated with a given key.
11237
+ If the key already exists (one or more outputs found), it spends the existing output(s)
11238
+ and creates a new one with the updated value. If multiple outputs exist for the key,
11239
+ they are collapsed into a single new output.
11240
+ If the key does not exist, it creates a new output.
11241
+ Handles encryption if enabled.
11242
+ If signing the update/collapse transaction fails, it relinquishes the original outputs and starts over with a new chain.
11243
+
11244
+ ```ts
11245
+ set(key: string, value: string): Promise<OutpointString>
11246
+ ```
11247
+
11248
+ Returns
11249
+
11250
+ A promise that resolves to the outpoint string (txid.vout) of the new or updated token output.
11251
+
11252
+ Argument Details
11253
+
11254
+ + **key**
11255
+ + The key to set or update.
11256
+ + **value**
11257
+ + The value to associate with the key.
11258
+
11259
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
11260
+
11149
11261
  ---
11150
11262
  #### Functions
11151
11263
 
@@ -13176,19 +13288,12 @@ DEFAULT_SETTINGS = {
13176
13288
  trustLevel: 2,
13177
13289
  trustedCertifiers: [
13178
13290
  {
13179
- name: "Babbage Trust Services",
13291
+ name: "Metanet Trust Services",
13180
13292
  description: "Resolves identity information for Babbage-run APIs and Bitcoin infrastructure.",
13181
- iconUrl: "https://projectbabbage.com/favicon.ico",
13293
+ iconUrl: "https://bsvblockchain.org/favicon.ico",
13182
13294
  identityKey: "03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8",
13183
13295
  trust: 4
13184
13296
  },
13185
- {
13186
- name: "IdentiCert",
13187
- description: "Certifies legal first and last name, and photos",
13188
- iconUrl: "https://identicert.me/favicon.ico",
13189
- trust: 5,
13190
- identityKey: "0295bf1c7842d14babf60daf2c733956c331f9dcb2c79e41f85fd1dda6a3fa4549"
13191
- },
13192
13297
  {
13193
13298
  name: "SocialCert",
13194
13299
  description: "Certifies social media handles, phone numbers and emails",
package/docs/wallet.md CHANGED
@@ -5129,7 +5129,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
5129
5129
  | [MergeEntity](#class-mergeentity) | [TaskReviewStatus](#class-taskreviewstatus) | [WalletSigner](#class-walletsigner) |
5130
5130
  | [Monitor](#class-monitor) | [TaskSendWaiting](#class-tasksendwaiting) | [WalletStorageManager](#class-walletstoragemanager) |
5131
5131
  | [MonitorDaemon](#class-monitordaemon) | [TaskSyncWhenIdle](#class-tasksyncwhenidle) | [WhatsOnChain](#class-whatsonchain) |
5132
- | [OverlayUMPTokenInteractor](#class-overlayumptokeninteractor) | [TaskUnFail](#class-taskunfail) | |
5132
+ | [OverlayUMPTokenInteractor](#class-overlayumptokeninteractor) | [TaskUnFail](#class-taskunfail) | [localKVStore](#class-localkvstore) |
5133
5133
  | [PersonaIDInteractor](#class-personaidinteractor) | [TwilioPhoneInteractor](#class-twiliophoneinteractor) | |
5134
5134
 
5135
5135
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
@@ -10711,6 +10711,7 @@ Manages wallet settings
10711
10711
 
10712
10712
  ```ts
10713
10713
  export class WalletSettingsManager {
10714
+ kv: LocalKVStore;
10714
10715
  constructor(private wallet: WalletInterface, private config: WalletSettingsManagerConfig = {
10715
10716
  defaultSettings: DEFAULT_SETTINGS
10716
10717
  })
@@ -11145,6 +11146,117 @@ Argument Details
11145
11146
 
11146
11147
  Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
11147
11148
 
11149
+ ---
11150
+ ##### Class: localKVStore
11151
+
11152
+ Implements a key-value storage system backed by transaction outputs managed by a wallet.
11153
+ Each key-value pair is represented by a PushDrop token output in a specific context (basket).
11154
+ Allows setting, getting, and removing key-value pairs, with optional encryption.
11155
+
11156
+ ```ts
11157
+ export default class localKVStore {
11158
+ constructor(wallet?: WalletInterface, context?: string, encrypt?: boolean);
11159
+ get(key: string, defaultValue?: string | undefined): Promise<string | undefined>;
11160
+ set(key: string, value: string): Promise<OutpointString>;
11161
+ remove(key: string): Promise<OutpointString | void>;
11162
+ }
11163
+ ```
11164
+
11165
+ ###### Constructor
11166
+
11167
+ Creates an instance of the localKVStore.
11168
+
11169
+ ```ts
11170
+ constructor(wallet?: WalletInterface, context?: string, encrypt?: boolean)
11171
+ ```
11172
+
11173
+ Argument Details
11174
+
11175
+ + **wallet**
11176
+ + The wallet interface to use. Defaults to a new WalletClient instance.
11177
+ + **context**
11178
+ + The context (basket) for namespacing keys. Defaults to 'kvstore-default'.
11179
+ + **encrypt**
11180
+ + Whether to encrypt values. Defaults to true.
11181
+
11182
+ Throws
11183
+
11184
+ If the context is missing or empty.
11185
+
11186
+ ###### Method get
11187
+
11188
+ Retrieves the value associated with a given key.
11189
+
11190
+ ```ts
11191
+ get(key: string, defaultValue?: string | undefined): Promise<string | undefined>
11192
+ ```
11193
+
11194
+ Returns
11195
+
11196
+ A promise that resolves to the value as a string,
11197
+ the defaultValue if the key is not found, or undefined if no defaultValue is provided.
11198
+
11199
+ Argument Details
11200
+
11201
+ + **key**
11202
+ + The key to retrieve the value for.
11203
+ + **defaultValue**
11204
+ + The value to return if the key is not found.
11205
+
11206
+ Throws
11207
+
11208
+ If multiple outputs are found for the key (ambiguous state).
11209
+
11210
+ If the found output's locking script cannot be decoded or represents an invalid token format.
11211
+
11212
+ ###### Method remove
11213
+
11214
+ Removes the key-value pair associated with the given key.
11215
+ It finds the existing output(s) for the key and spends them without creating a new output.
11216
+ If multiple outputs exist, they are all spent in the same transaction.
11217
+ If the key does not exist, it does nothing.
11218
+ If signing the removal transaction fails, it relinquishes the original outputs instead of spending.
11219
+
11220
+ ```ts
11221
+ remove(key: string): Promise<OutpointString | void>
11222
+ ```
11223
+
11224
+ Returns
11225
+
11226
+ A promise that resolves to the txid of the removal transaction if successful.
11227
+
11228
+ Argument Details
11229
+
11230
+ + **key**
11231
+ + The key to remove.
11232
+
11233
+ ###### Method set
11234
+
11235
+ Sets or updates the value associated with a given key.
11236
+ If the key already exists (one or more outputs found), it spends the existing output(s)
11237
+ and creates a new one with the updated value. If multiple outputs exist for the key,
11238
+ they are collapsed into a single new output.
11239
+ If the key does not exist, it creates a new output.
11240
+ Handles encryption if enabled.
11241
+ If signing the update/collapse transaction fails, it relinquishes the original outputs and starts over with a new chain.
11242
+
11243
+ ```ts
11244
+ set(key: string, value: string): Promise<OutpointString>
11245
+ ```
11246
+
11247
+ Returns
11248
+
11249
+ A promise that resolves to the outpoint string (txid.vout) of the new or updated token output.
11250
+
11251
+ Argument Details
11252
+
11253
+ + **key**
11254
+ + The key to set or update.
11255
+ + **value**
11256
+ + The value to associate with the key.
11257
+
11258
+ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
11259
+
11148
11260
  ---
11149
11261
  #### Functions
11150
11262
 
@@ -13175,19 +13287,12 @@ DEFAULT_SETTINGS = {
13175
13287
  trustLevel: 2,
13176
13288
  trustedCertifiers: [
13177
13289
  {
13178
- name: "Babbage Trust Services",
13290
+ name: "Metanet Trust Services",
13179
13291
  description: "Resolves identity information for Babbage-run APIs and Bitcoin infrastructure.",
13180
- iconUrl: "https://projectbabbage.com/favicon.ico",
13292
+ iconUrl: "https://bsvblockchain.org/favicon.ico",
13181
13293
  identityKey: "03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8",
13182
13294
  trust: 4
13183
13295
  },
13184
- {
13185
- name: "IdentiCert",
13186
- description: "Certifies legal first and last name, and photos",
13187
- iconUrl: "https://identicert.me/favicon.ico",
13188
- trust: 5,
13189
- identityKey: "0295bf1c7842d14babf60daf2c733956c331f9dcb2c79e41f85fd1dda6a3fa4549"
13190
- },
13191
13296
  {
13192
13297
  name: "SocialCert",
13193
13298
  description: "Certifies social media handles, phone numbers and emails",
@@ -1,4 +1,4 @@
1
- import { PubKeyHex, WalletInterface } from '@bsv/sdk';
1
+ import { LocalKVStore, PubKeyHex, WalletInterface } from '@bsv/sdk';
2
2
  export interface Certifier {
3
3
  name: string;
4
4
  description: string;
@@ -30,6 +30,7 @@ export declare const TESTNET_DEFAULT_SETTINGS: WalletSettings;
30
30
  export declare class WalletSettingsManager {
31
31
  private wallet;
32
32
  private config;
33
+ kv: LocalKVStore;
33
34
  constructor(wallet: WalletInterface, config?: WalletSettingsManagerConfig);
34
35
  /**
35
36
  * Returns a user's wallet settings
@@ -47,13 +48,5 @@ export declare class WalletSettingsManager {
47
48
  * Deletes the user's settings token.
48
49
  */
49
50
  delete(): Promise<void>;
50
- /**
51
- * Updates a settings token. Any previous token is consumed, and if a new locking script
52
- * is provided, it replaces what (if anything) was there before.
53
- *
54
- * @param newLockingScript - Optional locking script for replacing the settings token.
55
- * @returns {Promise<boolean>} - True if operation succeeded, throws an error otherwise.
56
- */
57
- private updateToken;
58
51
  }
59
52
  //# sourceMappingURL=WalletSettingsManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WalletSettingsManager.d.ts","sourceRoot":"","sources":["../../src/WalletSettingsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAIT,eAAe,EAEhB,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,SAAS,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AACD,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,SAAS,EAAE,CAAA;CAC/B;AACD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;CACb;AACD,MAAM,WAAW,cAAc;IAC7B,a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CAAC,EAAE,WAAW,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AACD,MAAM,WAAW,2BAA2B;IAC1C,eAAe,EAAE,cAAc,CAAA;CAChC;AAKD,eAAO,MAAM,gBAAgB,EAqBxB,cAAc,CAAA;AAUnB,eAAO,MAAM,wBAAwB,EAAE,cAUtC,CAAA;AAED;;GAEG;AACH,qBAAa,qBAAqB;IAI9B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IAJhB,EAAE,EAAE,YAAY,CAAA;gBAGN,MAAM,EAAE,eAAe,EACvB,MAAM,GAAE,2BAEf;IAKH;;;;OAIG;IACG,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC;IAIpC;;;;OAIG;IACG,GAAG,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
@@ -2,29 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WalletSettingsManager = exports.TESTNET_DEFAULT_SETTINGS = exports.DEFAULT_SETTINGS = void 0;
4
4
  const sdk_1 = require("@bsv/sdk");
5
- const PROTOCOL_ID = [2, 'wallet settings'];
6
- const KEY_ID = '1';
7
5
  const SETTINGS_BASKET = 'wallet settings';
8
- const TOKEN_AMOUNT = 1;
9
6
  // Defaults can be overridden as needed
10
7
  exports.DEFAULT_SETTINGS = {
11
8
  trustSettings: {
12
9
  trustLevel: 2,
13
10
  trustedCertifiers: [
14
11
  {
15
- name: 'Babbage Trust Services',
16
- description: 'Resolves identity information for Babbage-run APIs and Bitcoin infrastructure.',
17
- iconUrl: 'https://projectbabbage.com/favicon.ico',
12
+ name: 'Metanet Trust Services',
13
+ description: 'Registry for protocols, baskets, and certificates types',
14
+ iconUrl: 'https://bsvblockchain.org/favicon.ico',
18
15
  identityKey: '03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8',
19
16
  trust: 4
20
17
  },
21
- {
22
- name: 'IdentiCert',
23
- description: 'Certifies legal first and last name, and photos',
24
- iconUrl: 'https://identicert.me/favicon.ico',
25
- trust: 5,
26
- identityKey: '0295bf1c7842d14babf60daf2c733956c331f9dcb2c79e41f85fd1dda6a3fa4549'
27
- },
28
18
  {
29
19
  name: 'SocialCert',
30
20
  description: 'Certifies social media handles, phone numbers and emails',
@@ -63,6 +53,7 @@ class WalletSettingsManager {
63
53
  }) {
64
54
  this.wallet = wallet;
65
55
  this.config = config;
56
+ this.kv = new sdk_1.LocalKVStore(wallet, SETTINGS_BASKET, true);
66
57
  }
67
58
  /**
68
59
  * Returns a user's wallet settings
@@ -70,19 +61,7 @@ class WalletSettingsManager {
70
61
  * @returns - Wallet settings object
71
62
  */
72
63
  async get() {
73
- // List outputs in the 'wallet-settings' basket
74
- // There should only be one settings token
75
- const results = await this.wallet.listOutputs({
76
- basket: SETTINGS_BASKET,
77
- include: 'locking scripts'
78
- });
79
- // Return defaults if no settings token is found
80
- if (!results.outputs.length) {
81
- return this.config.defaultSettings;
82
- }
83
- const { fields } = sdk_1.PushDrop.decode(sdk_1.LockingScript.fromHex(results.outputs[results.outputs.length - 1].lockingScript));
84
- // Parse and return settings token
85
- return JSON.parse(sdk_1.Utils.toUTF8(fields[0]));
64
+ return JSON.parse((await this.kv.get('settings', JSON.stringify(this.config.defaultSettings))));
86
65
  }
87
66
  /**
88
67
  * Creates (or updates) the user's settings token.
@@ -90,98 +69,13 @@ class WalletSettingsManager {
90
69
  * @param settings - The wallet settings to be stored.
91
70
  */
92
71
  async set(settings) {
93
- const pushdrop = new sdk_1.PushDrop(this.wallet);
94
- // Build the new locking script with the updated settings JSON.
95
- const lockingScript = await pushdrop.lock([sdk_1.Utils.toArray(JSON.stringify(settings), 'utf8')], PROTOCOL_ID, KEY_ID, 'self');
96
- // Consume any existing token and create a new one with the new locking script.
97
- await this.updateToken(lockingScript);
72
+ await this.kv.set('settings', JSON.stringify(settings));
98
73
  }
99
74
  /**
100
75
  * Deletes the user's settings token.
101
76
  */
102
77
  async delete() {
103
- // Consume the token; if none exists, consumeToken simply returns.
104
- await this.updateToken();
105
- }
106
- /**
107
- * Updates a settings token. Any previous token is consumed, and if a new locking script
108
- * is provided, it replaces what (if anything) was there before.
109
- *
110
- * @param newLockingScript - Optional locking script for replacing the settings token.
111
- * @returns {Promise<boolean>} - True if operation succeeded, throws an error otherwise.
112
- */
113
- async updateToken(newLockingScript) {
114
- const pushdrop = new sdk_1.PushDrop(this.wallet);
115
- // 1. List the existing token UTXO(s) for the settings basket.
116
- const existingUtxos = await this.wallet.listOutputs({
117
- basket: SETTINGS_BASKET,
118
- include: 'entire transactions'
119
- });
120
- // This is the "create a new token" path — no signAction, just a new locking script.
121
- if (!existingUtxos.outputs.length) {
122
- if (!newLockingScript) {
123
- return true;
124
- }
125
- await this.wallet.createAction({
126
- description: 'Create a user settings token',
127
- outputs: [
128
- {
129
- satoshis: TOKEN_AMOUNT,
130
- lockingScript: newLockingScript.toHex(),
131
- outputDescription: 'Wallet settings token',
132
- basket: SETTINGS_BASKET
133
- }
134
- ],
135
- options: {
136
- randomizeOutputs: false,
137
- acceptDelayedBroadcast: false
138
- }
139
- });
140
- return true;
141
- }
142
- // 2. Prepare the token UTXO for consumption.
143
- const tokenOutput = existingUtxos.outputs[existingUtxos.outputs.length - 1];
144
- const inputToConsume = {
145
- outpoint: tokenOutput.outpoint,
146
- unlockingScriptLength: 73,
147
- inputDescription: 'Consume old wallet settings token'
148
- };
149
- // 3. Build the outputs array: if a new locking script is provided, add an output.
150
- const outputs = newLockingScript
151
- ? [
152
- {
153
- satoshis: TOKEN_AMOUNT,
154
- lockingScript: newLockingScript.toHex(),
155
- outputDescription: 'Wallet settings token',
156
- basket: SETTINGS_BASKET
157
- }
158
- ]
159
- : [];
160
- // 4. Create a signable transaction action using the inputs and (optionally) outputs.
161
- const { signableTransaction } = await this.wallet.createAction({
162
- description: `${newLockingScript ? 'Update' : 'Delete'} a user settings token`,
163
- inputBEEF: existingUtxos.BEEF,
164
- inputs: [inputToConsume], // input index 0
165
- outputs,
166
- options: {
167
- randomizeOutputs: false,
168
- acceptDelayedBroadcast: false
169
- }
170
- });
171
- const tx = sdk_1.Transaction.fromBEEF(signableTransaction.tx);
172
- // 5. Build and sign the unlocking script for the token being consumed.
173
- const unlocker = pushdrop.unlock(PROTOCOL_ID, KEY_ID, 'self');
174
- const unlockingScript = await unlocker.sign(tx, 0);
175
- // 6. Sign the transaction using our unlocking script.
176
- await this.wallet.signAction({
177
- reference: signableTransaction.reference,
178
- spends: {
179
- 0: {
180
- unlockingScript: unlockingScript.toHex()
181
- }
182
- }
183
- });
184
- return true;
78
+ await this.kv.remove('settings');
185
79
  }
186
80
  }
187
81
  exports.WalletSettingsManager = WalletSettingsManager;
@@ -1 +1 @@
1
- {"version":3,"file":"WalletSettingsManager.js","sourceRoot":"","sources":["../../src/WalletSettingsManager.ts"],"names":[],"mappings":";;;AAAA,kCASiB;AA0BjB,MAAM,WAAW,GAAmB,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAC1D,MAAM,MAAM,GAAG,GAAG,CAAA;AAClB,MAAM,eAAe,GAAG,iBAAiB,CAAA;AACzC,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB,uCAAuC;AAC1B,QAAA,gBAAgB,GAAG;IAC9B,aAAa,EAAE;QACb,UAAU,EAAE,CAAC;QACb,iBAAiB,EAAE;YACjB;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,WAAW,EAAE,gFAAgF;gBAC7F,OAAO,EAAE,wCAAwC;gBACjD,WAAW,EAAE,oEAAoE;gBACjF,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,YAAY;gBAClB,WAAW,EAAE,iDAAiD;gBAC9D,OAAO,EAAE,mCAAmC;gBAC5C,KAAK,EAAE,CAAC;gBACR,WAAW,EAAE,oEAAoE;aAClF;YACD;gBACE,IAAI,EAAE,YAAY;gBAClB,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