@bsv/wallet-toolbox-client 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.
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"WalletSettingsManager.d.ts","sourceRoot":"","sources":["../../../src/WalletSettingsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEnE,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,aAAa,EAAE,aAAa,CAAA;IAC5B,KAAK,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: '
|
|
16
|
-
description: '
|
|
17
|
-
iconUrl: 'https://
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"WalletSettingsManager.js","sourceRoot":"","sources":["../../../src/WalletSettingsManager.ts"],"names":[],"mappings":";;;AAAA,kCAAmE;AA0BnE,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAEzC,uCAAuC;AAC1B,QAAA,gBAAgB,GAAG;IAC9B,aAAa,EAAE;QACb,UAAU,EAAE,CAAC;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CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAW,CAAC,CAAA;IAC3G,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAG,CAAC,QAAwB;QAChC,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;CACF;AApCD,sDAoCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/wallet-toolbox-client",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.33",
|
|
4
4
|
"description": "Client only Wallet Storage",
|
|
5
5
|
"main": "./out/src/index.client.js",
|
|
6
6
|
"types": "./out/src/index.client.d.ts",
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/bitcoin-sv/wallet-toolbox#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@bsv/sdk": "^1.4.
|
|
23
|
+
"@bsv/sdk": "^1.4.17"
|
|
24
24
|
}
|
|
25
25
|
}
|