@spirobel/monero-wallet-api 0.3.9 → 0.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.
@@ -5,7 +5,7 @@ export type ScanSetting = {
5
5
  halted?: boolean;
6
6
  wallet_route?: string;
7
7
  wallet_name?: string;
8
- wallet_index?: number;
8
+ wallet_slot?: number;
9
9
  };
10
10
  export type WriteScanSettingParams = {
11
11
  primary_address: string;
@@ -16,7 +16,7 @@ export type WriteScanSettingParams = {
16
16
  node_url?: string;
17
17
  wallet_route?: string;
18
18
  wallet_name?: string;
19
- wallet_index?: number;
19
+ wallet_slot?: number;
20
20
  };
21
21
  export type ScanSettingOpened = {
22
22
  primary_address: string;
@@ -28,7 +28,7 @@ export type ScanSettingOpened = {
28
28
  secret_spend_key?: string;
29
29
  wallet_route?: string;
30
30
  wallet_name?: string;
31
- wallet_index?: number;
31
+ wallet_slot?: number;
32
32
  };
33
33
  export type ScanSettings = {
34
34
  wallets: ScanSetting[];
@@ -101,7 +101,7 @@ export declare function walletSettingsPlusKeys(wallet_settings: ScanSettingOpene
101
101
  halted?: boolean;
102
102
  wallet_route?: string;
103
103
  wallet_name?: string;
104
- wallet_index?: number;
104
+ wallet_slot?: number;
105
105
  }>;
106
106
  export declare function writeWalletToScanSettings(params: WriteScanSettingParams): Promise<number>;
107
107
  export declare function openScanSettingsFile(scan_settings_path?: string): Promise<ScanSettings | undefined>;
@@ -192,7 +192,7 @@ export async function writeWalletToScanSettings(params) {
192
192
  halted: params.halted,
193
193
  wallet_route: params.wallet_route,
194
194
  wallet_name: params.wallet_name,
195
- wallet_index: params.wallet_index,
195
+ wallet_slot: params.wallet_slot,
196
196
  },
197
197
  ],
198
198
  node_url: params.node_url,
@@ -213,7 +213,7 @@ export async function writeWalletToScanSettings(params) {
213
213
  halted: params.halted,
214
214
  wallet_route: params.wallet_route,
215
215
  wallet_name: params.wallet_name,
216
- wallet_index: params.wallet_index,
216
+ wallet_slot: params.wallet_slot,
217
217
  });
218
218
  }
219
219
  else {
@@ -225,7 +225,7 @@ export async function writeWalletToScanSettings(params) {
225
225
  wallet.halted = params.halted || wallet.halted;
226
226
  wallet.wallet_route = params.wallet_route || wallet.wallet_route;
227
227
  wallet.wallet_name = params.wallet_name || wallet.wallet_name;
228
- wallet.wallet_index = params.wallet_index || wallet.wallet_index;
228
+ wallet.wallet_slot = params.wallet_slot || wallet.wallet_slot;
229
229
  }
230
230
  }
231
231
  return await atomicWrite(params.scan_settings_path, JSON.stringify(scanSettings, null, 2));
@@ -21,7 +21,7 @@ export declare class ScanCacheOpened {
21
21
  readonly view_pair: ViewPair;
22
22
  readonly wallet_route: string | undefined;
23
23
  readonly wallet_name: string | undefined;
24
- readonly wallet_index: number | undefined;
24
+ readonly wallet_slot: number | undefined;
25
25
  readonly no_worker: boolean;
26
26
  readonly masterCacheChanged: CacheChangedCallback | null;
27
27
  private _start_height;
@@ -10,7 +10,7 @@ export class ScanCacheOpened {
10
10
  view_pair;
11
11
  wallet_route;
12
12
  wallet_name;
13
- wallet_index;
13
+ wallet_slot;
14
14
  no_worker;
15
15
  masterCacheChanged;
16
16
  _start_height;
@@ -29,7 +29,7 @@ export class ScanCacheOpened {
29
29
  // read secret_view_key and secret_spend_key from env
30
30
  const walletSettingsWithKeys = await walletSettingsPlusKeys(walletSettings);
31
31
  // create viewpair + ScanCacheOpened instance
32
- const scanCacheOpen = new ScanCacheOpened(await ViewPair.create(params.primary_address, walletSettingsWithKeys.secret_view_key, walletSettings.subaddress_index, walletSettings.node_url), walletSettings.wallet_route, walletSettings.wallet_name, walletSettings.wallet_index, params.no_worker || false, params.masterCacheChanged || null, walletSettings.start_height, params.scan_settings_path, params.pathPrefix, params.workerError);
32
+ const scanCacheOpen = new ScanCacheOpened(await ViewPair.create(params.primary_address, walletSettingsWithKeys.secret_view_key, walletSettings.subaddress_index, walletSettings.node_url), walletSettings.wallet_route, walletSettings.wallet_name, walletSettings.wallet_slot, params.no_worker || false, params.masterCacheChanged || null, walletSettings.start_height, params.scan_settings_path, params.pathPrefix, params.workerError);
33
33
  if (theCatchToBeOpened)
34
34
  scanCacheOpen._cache = theCatchToBeOpened;
35
35
  if (!walletSettings.halted) {
@@ -522,11 +522,11 @@ export class ScanCacheOpened {
522
522
  primary_address: "",
523
523
  };
524
524
  worker = undefined;
525
- constructor(view_pair, wallet_route, wallet_name, wallet_index, no_worker, masterCacheChanged, _start_height, scan_settings_path, pathPrefix, workerError) {
525
+ constructor(view_pair, wallet_route, wallet_name, wallet_slot, no_worker, masterCacheChanged, _start_height, scan_settings_path, pathPrefix, workerError) {
526
526
  this.view_pair = view_pair;
527
527
  this.wallet_route = wallet_route;
528
528
  this.wallet_name = wallet_name;
529
- this.wallet_index = wallet_index;
529
+ this.wallet_slot = wallet_slot;
530
530
  this.no_worker = no_worker;
531
531
  this.masterCacheChanged = masterCacheChanged;
532
532
  this._start_height = _start_height;
@@ -47,3 +47,20 @@ export declare const ADDRESS_VALID_RESPONSE: {
47
47
  export declare const ADDRESS_INVALID_RESPONSE: {
48
48
  readonly valid_address: false;
49
49
  };
50
+ export type ShareViewkeyPayload = {
51
+ viewkey: string;
52
+ primary_address: string;
53
+ tool_invo: ParsedMoneroToolInvocation;
54
+ };
55
+ export type ShareViewkeyResult = {
56
+ ok: boolean;
57
+ successUrl: string | null;
58
+ };
59
+ export declare function shareViewKey002(payload: ShareViewkeyPayload): Promise<ShareViewkeyResult>;
60
+ export type ShareViewkey002Pruned = {
61
+ viewkey: string;
62
+ primary_address: string;
63
+ wallet_slot: string;
64
+ };
65
+ export declare function potentialSuccessRedirect002(payload: ShareViewkeyPayload): Promise<void>;
66
+ export declare function handle002ShareRequest(req: Request, parsed_cb: (parsed_body: ShareViewkey002Pruned) => Promise<void>, successUrl?: string): Promise<ShareViewkeyResult>;
@@ -168,3 +168,81 @@ export const ADDRESS_VALID_RESPONSE = {
168
168
  export const ADDRESS_INVALID_RESPONSE = {
169
169
  valid_address: false,
170
170
  };
171
+ export async function shareViewKey002(payload) {
172
+ const invo = payload.tool_invo;
173
+ if (invo.tool.tool_id !== "002")
174
+ return {
175
+ ok: false,
176
+ successUrl: null,
177
+ };
178
+ if (invo.valid !== "valid")
179
+ return {
180
+ ok: false,
181
+ successUrl: null,
182
+ };
183
+ const link = invo[invo.found_in];
184
+ const invo_link = new URL(link);
185
+ const shareVKUrl = `${invo_link.origin}/monerochan002/`;
186
+ const result = await fetch(shareVKUrl, {
187
+ method: "POST",
188
+ headers: { "Content-Type": "application/json" },
189
+ body: JSON.stringify({
190
+ viewkey: payload.viewkey,
191
+ primary_address: payload.primary_address,
192
+ wallet_slot: invo.tool.payload.wallet_slot,
193
+ }),
194
+ });
195
+ if (result.ok) {
196
+ const data = (await result.json());
197
+ if (data && typeof data === "object" && "ok" in data && data.ok === true) {
198
+ return {
199
+ ok: true,
200
+ successUrl: data.successUrl ?? null,
201
+ };
202
+ }
203
+ else {
204
+ return {
205
+ ok: false,
206
+ successUrl: null,
207
+ };
208
+ }
209
+ }
210
+ else {
211
+ return {
212
+ ok: false,
213
+ successUrl: null,
214
+ };
215
+ }
216
+ }
217
+ // client wallet side
218
+ export async function potentialSuccessRedirect002(payload) {
219
+ const shareVKresult = await shareViewKey002(payload);
220
+ if (shareVKresult.ok && shareVKresult.successUrl) {
221
+ window.location.href = shareVKresult.successUrl;
222
+ window.location.reload();
223
+ }
224
+ }
225
+ // backend response
226
+ export async function handle002ShareRequest(req, parsed_cb, successUrl) {
227
+ try {
228
+ const json_body = await req.json();
229
+ const { viewkey, primary_address, wallet_slot } = json_body;
230
+ if (Number.isNaN(parseInt(wallet_slot))) {
231
+ return { ok: false, successUrl: null };
232
+ }
233
+ if (typeof viewkey !== "string" ||
234
+ viewkey.trim().length === 0 ||
235
+ typeof primary_address !== "string" ||
236
+ primary_address.trim().length === 0) {
237
+ return { ok: false, successUrl: null };
238
+ }
239
+ await parsed_cb({ viewkey, primary_address, wallet_slot });
240
+ return {
241
+ ok: true,
242
+ successUrl: successUrl ?? null,
243
+ };
244
+ }
245
+ catch {
246
+ return { ok: false, successUrl: null };
247
+ }
248
+ }
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "clean": "rm -rf ./dist"
41
41
  },
42
42
  "files": ["dist"],
43
- "version": "0.3.9",
43
+ "version": "0.3.11",
44
44
  "devDependencies": {
45
45
  "@types/bun": "latest"
46
46
  },