onekey-monero-runtime 0.1.0-alpha.2 → 0.1.0-alpha.4

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.
@@ -22,7 +22,7 @@ export function balance(account_id: bigint, chain_tip?: bigint | null): string;
22
22
  * are marked, the transaction goes in flight, and `broadcast: accepted | unknown` is
23
23
  * returned. Only an explicit node rejection errors and releases the inputs.
24
24
  */
25
- export function broadcastTransaction(account_id: bigint, raw_hex: string, reservation_id: string, chain_tip: bigint, outgoing_atomic?: string | null, change_atomic?: string | null): Promise<string>;
25
+ export function broadcastTransaction(account_id: bigint, raw_hex: string, chain_tip: bigint, outgoing_atomic?: string | null, change_atomic?: string | null, signable_hex?: string | null, review_json?: string | null): Promise<string>;
26
26
 
27
27
  /**
28
28
  * Fetch the chain tip. Does not require an open wallet DB: account creation needs
@@ -89,18 +89,13 @@ export function init(): Promise<void>;
89
89
 
90
90
  export function listAccounts(): string;
91
91
 
92
- /**
93
- * Called before signing; every selected input must still belong to this review.
94
- */
95
- export function markReservationSigned(reservation_id: string, expected_inputs: number): string;
96
-
97
92
  /**
98
93
  * Open (or create) a wallet DB.
99
94
  */
100
95
  export function openWallet(db_name: string, network: string): string;
101
96
 
102
97
  /**
103
- * Select inputs, build and reserve. Needs no spend private key; does not broadcast.
98
+ * Select inputs and build. Needs no spend private key; does not broadcast.
104
99
  *
105
100
  * `recipientsJson` is `[{ "address": "...", "amountAtomic": "1000000000000" }]`.
106
101
  *
@@ -108,25 +103,20 @@ export function openWallet(db_name: string, network: string): string;
108
103
  * spendable total minus fee; the passed amount is ignored. Merely omitting change
109
104
  * would fold the remainder into the fee.
110
105
  *
111
- * Returns `{ reservationId, signableHex, feeAtomic, amountAtomic, changeAtomic,
112
- * inputsAtomic, inputCount }`. `feeAtomic` and `amountAtomic` are what the
106
+ * Returns `{ signableHex, feeAtomic, amountAtomic, changeAtomic, inputsAtomic,
107
+ * inputCount }`. `feeAtomic` and `amountAtomic` are what the
113
108
  * transaction will use: the confirmation page shows them and signing keeps them.
114
109
  *
115
- * Failure leaves no reservation. On success the host must call `signTransaction` +
116
- * `broadcastTransaction`, or `releaseReservation`; otherwise the inputs stay locked.
110
+ * Inputs are not reserved: a second prepare before broadcast may select the same
111
+ * ones, and broadcast then refuses the later transaction as `inputAlreadySpent`.
117
112
  */
118
- export function prepareTransaction(account_id: bigint, recipients_json: string, max_send: boolean, reservation_id: string, chain_tip: bigint, priority: string): Promise<string>;
113
+ export function prepareTransaction(account_id: bigint, recipients_json: string, max_send: boolean, chain_tip: bigint, priority: string): Promise<string>;
119
114
 
120
115
  /**
121
116
  * Register a subaddress and return its address. Funds to unregistered subaddresses go undetected.
122
117
  */
123
118
  export function registerSubaddress(account_id: bigint, major: number, minor: number, label?: string | null): string;
124
119
 
125
- /**
126
- * Release a reservation (user cancelled or construction failed).
127
- */
128
- export function releaseReservation(reservation_id: string): string;
129
-
130
120
  /**
131
121
  * Delete an identity and all its data. Irreversible.
132
122
  */
@@ -203,6 +193,8 @@ export function updateChainTip(account_id: bigint, tip: bigint): string;
203
193
  */
204
194
  export function validateAddress(network: string, address: string): boolean;
205
195
 
196
+ export function verifySignedTransaction(signable_hex: string, review_json: string, raw_hex: string): string;
197
+
206
198
  /**
207
199
  * Validate actual payment effects before the host presents its confirmation.
208
200
  */
@@ -214,7 +206,7 @@ export interface InitOutput {
214
206
  readonly memory: WebAssembly.Memory;
215
207
  readonly addAccount: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint) => [number, number, number, number];
216
208
  readonly balance: (a: bigint, b: number, c: bigint) => [number, number, number, number];
217
- readonly broadcastTransaction: (a: bigint, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number) => any;
209
+ readonly broadcastTransaction: (a: bigint, b: number, c: number, d: bigint, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => any;
218
210
  readonly chainTip: () => any;
219
211
  readonly closeWallet: () => [number, number];
220
212
  readonly deleteWallet: (a: number, b: number) => any;
@@ -226,11 +218,9 @@ export interface InitOutput {
226
218
  readonly importKeyImages: (a: bigint, b: number, c: number) => [number, number, number, number];
227
219
  readonly init: () => any;
228
220
  readonly listAccounts: () => [number, number, number, number];
229
- readonly markReservationSigned: (a: number, b: number, c: number) => [number, number, number, number];
230
221
  readonly openWallet: (a: number, b: number, c: number, d: number) => [number, number, number, number];
231
- readonly prepareTransaction: (a: bigint, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number, i: number) => any;
222
+ readonly prepareTransaction: (a: bigint, b: number, c: number, d: number, e: bigint, f: number, g: number) => any;
232
223
  readonly registerSubaddress: (a: bigint, b: number, c: number, d: number, e: number) => [number, number, number, number];
233
- readonly releaseReservation: (a: number, b: number) => [number, number, number, number];
234
224
  readonly removeAccount: (a: number, b: number) => [number, number, number, number];
235
225
  readonly rewindTo: (a: bigint, b: bigint, c: bigint) => [number, number, number, number];
236
226
  readonly setNodeUrl: (a: number, b: number) => any;
@@ -243,6 +233,7 @@ export interface InitOutput {
243
233
  readonly transactionDetails: (a: bigint, b: number, c: number) => [number, number, number, number];
244
234
  readonly updateChainTip: (a: bigint, b: bigint) => [number, number, number, number];
245
235
  readonly validateAddress: (a: number, b: number, c: number, d: number) => [number, number, number];
236
+ readonly verifySignedTransaction: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
246
237
  readonly verifyTransaction: (a: number, b: number, c: number, d: number) => [number, number];
247
238
  readonly rust_sqlite_wasm_abort: () => void;
248
239
  readonly rust_sqlite_wasm_assert_fail: (a: number, b: number, c: number, d: number) => void;
@@ -70,22 +70,25 @@ export function balance(account_id, chain_tip) {
70
70
  * returned. Only an explicit node rejection errors and releases the inputs.
71
71
  * @param {bigint} account_id
72
72
  * @param {string} raw_hex
73
- * @param {string} reservation_id
74
73
  * @param {bigint} chain_tip
75
74
  * @param {string | null} [outgoing_atomic]
76
75
  * @param {string | null} [change_atomic]
76
+ * @param {string | null} [signable_hex]
77
+ * @param {string | null} [review_json]
77
78
  * @returns {Promise<string>}
78
79
  */
79
- export function broadcastTransaction(account_id, raw_hex, reservation_id, chain_tip, outgoing_atomic, change_atomic) {
80
+ export function broadcastTransaction(account_id, raw_hex, chain_tip, outgoing_atomic, change_atomic, signable_hex, review_json) {
80
81
  const ptr0 = passStringToWasm0(raw_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
81
82
  const len0 = WASM_VECTOR_LEN;
82
- const ptr1 = passStringToWasm0(reservation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
83
- const len1 = WASM_VECTOR_LEN;
84
- var ptr2 = isLikeNone(outgoing_atomic) ? 0 : passStringToWasm0(outgoing_atomic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
83
+ var ptr1 = isLikeNone(outgoing_atomic) ? 0 : passStringToWasm0(outgoing_atomic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
84
+ var len1 = WASM_VECTOR_LEN;
85
+ var ptr2 = isLikeNone(change_atomic) ? 0 : passStringToWasm0(change_atomic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
85
86
  var len2 = WASM_VECTOR_LEN;
86
- var ptr3 = isLikeNone(change_atomic) ? 0 : passStringToWasm0(change_atomic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
87
+ var ptr3 = isLikeNone(signable_hex) ? 0 : passStringToWasm0(signable_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
87
88
  var len3 = WASM_VECTOR_LEN;
88
- const ret = wasm.broadcastTransaction(account_id, ptr0, len0, ptr1, len1, chain_tip, ptr2, len2, ptr3, len3);
89
+ var ptr4 = isLikeNone(review_json) ? 0 : passStringToWasm0(review_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
90
+ var len4 = WASM_VECTOR_LEN;
91
+ const ret = wasm.broadcastTransaction(account_id, ptr0, len0, chain_tip, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
89
92
  return ret;
90
93
  }
91
94
 
@@ -322,33 +325,6 @@ export function listAccounts() {
322
325
  }
323
326
  }
324
327
 
325
- /**
326
- * Called before signing; every selected input must still belong to this review.
327
- * @param {string} reservation_id
328
- * @param {number} expected_inputs
329
- * @returns {string}
330
- */
331
- export function markReservationSigned(reservation_id, expected_inputs) {
332
- let deferred3_0;
333
- let deferred3_1;
334
- try {
335
- const ptr0 = passStringToWasm0(reservation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
336
- const len0 = WASM_VECTOR_LEN;
337
- const ret = wasm.markReservationSigned(ptr0, len0, expected_inputs);
338
- var ptr2 = ret[0];
339
- var len2 = ret[1];
340
- if (ret[3]) {
341
- ptr2 = 0; len2 = 0;
342
- throw takeFromExternrefTable0(ret[2]);
343
- }
344
- deferred3_0 = ptr2;
345
- deferred3_1 = len2;
346
- return getStringFromWasm0(ptr2, len2);
347
- } finally {
348
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
349
- }
350
- }
351
-
352
328
  /**
353
329
  * Open (or create) a wallet DB.
354
330
  * @param {string} db_name
@@ -379,7 +355,7 @@ export function openWallet(db_name, network) {
379
355
  }
380
356
 
381
357
  /**
382
- * Select inputs, build and reserve. Needs no spend private key; does not broadcast.
358
+ * Select inputs and build. Needs no spend private key; does not broadcast.
383
359
  *
384
360
  * `recipientsJson` is `[{ "address": "...", "amountAtomic": "1000000000000" }]`.
385
361
  *
@@ -387,28 +363,25 @@ export function openWallet(db_name, network) {
387
363
  * spendable total minus fee; the passed amount is ignored. Merely omitting change
388
364
  * would fold the remainder into the fee.
389
365
  *
390
- * Returns `{ reservationId, signableHex, feeAtomic, amountAtomic, changeAtomic,
391
- * inputsAtomic, inputCount }`. `feeAtomic` and `amountAtomic` are what the
366
+ * Returns `{ signableHex, feeAtomic, amountAtomic, changeAtomic, inputsAtomic,
367
+ * inputCount }`. `feeAtomic` and `amountAtomic` are what the
392
368
  * transaction will use: the confirmation page shows them and signing keeps them.
393
369
  *
394
- * Failure leaves no reservation. On success the host must call `signTransaction` +
395
- * `broadcastTransaction`, or `releaseReservation`; otherwise the inputs stay locked.
370
+ * Inputs are not reserved: a second prepare before broadcast may select the same
371
+ * ones, and broadcast then refuses the later transaction as `inputAlreadySpent`.
396
372
  * @param {bigint} account_id
397
373
  * @param {string} recipients_json
398
374
  * @param {boolean} max_send
399
- * @param {string} reservation_id
400
375
  * @param {bigint} chain_tip
401
376
  * @param {string} priority
402
377
  * @returns {Promise<string>}
403
378
  */
404
- export function prepareTransaction(account_id, recipients_json, max_send, reservation_id, chain_tip, priority) {
379
+ export function prepareTransaction(account_id, recipients_json, max_send, chain_tip, priority) {
405
380
  const ptr0 = passStringToWasm0(recipients_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
406
381
  const len0 = WASM_VECTOR_LEN;
407
- const ptr1 = passStringToWasm0(reservation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
382
+ const ptr1 = passStringToWasm0(priority, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
408
383
  const len1 = WASM_VECTOR_LEN;
409
- const ptr2 = passStringToWasm0(priority, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
410
- const len2 = WASM_VECTOR_LEN;
411
- const ret = wasm.prepareTransaction(account_id, ptr0, len0, max_send, ptr1, len1, chain_tip, ptr2, len2);
384
+ const ret = wasm.prepareTransaction(account_id, ptr0, len0, max_send, chain_tip, ptr1, len1);
412
385
  return ret;
413
386
  }
414
387
 
@@ -441,32 +414,6 @@ export function registerSubaddress(account_id, major, minor, label) {
441
414
  }
442
415
  }
443
416
 
444
- /**
445
- * Release a reservation (user cancelled or construction failed).
446
- * @param {string} reservation_id
447
- * @returns {string}
448
- */
449
- export function releaseReservation(reservation_id) {
450
- let deferred3_0;
451
- let deferred3_1;
452
- try {
453
- const ptr0 = passStringToWasm0(reservation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
454
- const len0 = WASM_VECTOR_LEN;
455
- const ret = wasm.releaseReservation(ptr0, len0);
456
- var ptr2 = ret[0];
457
- var len2 = ret[1];
458
- if (ret[3]) {
459
- ptr2 = 0; len2 = 0;
460
- throw takeFromExternrefTable0(ret[2]);
461
- }
462
- deferred3_0 = ptr2;
463
- deferred3_1 = len2;
464
- return getStringFromWasm0(ptr2, len2);
465
- } finally {
466
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
467
- }
468
- }
469
-
470
417
  /**
471
418
  * Delete an identity and all its data. Irreversible.
472
419
  * @param {string} uuid
@@ -729,6 +676,37 @@ export function validateAddress(network, address) {
729
676
  return ret[0] !== 0;
730
677
  }
731
678
 
679
+ /**
680
+ * @param {string} signable_hex
681
+ * @param {string} review_json
682
+ * @param {string} raw_hex
683
+ * @returns {string}
684
+ */
685
+ export function verifySignedTransaction(signable_hex, review_json, raw_hex) {
686
+ let deferred5_0;
687
+ let deferred5_1;
688
+ try {
689
+ const ptr0 = passStringToWasm0(signable_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
690
+ const len0 = WASM_VECTOR_LEN;
691
+ const ptr1 = passStringToWasm0(review_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
692
+ const len1 = WASM_VECTOR_LEN;
693
+ const ptr2 = passStringToWasm0(raw_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
694
+ const len2 = WASM_VECTOR_LEN;
695
+ const ret = wasm.verifySignedTransaction(ptr0, len0, ptr1, len1, ptr2, len2);
696
+ var ptr4 = ret[0];
697
+ var len4 = ret[1];
698
+ if (ret[3]) {
699
+ ptr4 = 0; len4 = 0;
700
+ throw takeFromExternrefTable0(ret[2]);
701
+ }
702
+ deferred5_0 = ptr4;
703
+ deferred5_1 = len4;
704
+ return getStringFromWasm0(ptr4, len4);
705
+ } finally {
706
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
707
+ }
708
+ }
709
+
732
710
  /**
733
711
  * Validate actual payment effects before the host presents its confirmation.
734
712
  * @param {string} signable_hex
@@ -1174,12 +1152,12 @@ function __wbg_get_imports() {
1174
1152
  return ret;
1175
1153
  }, arguments); },
1176
1154
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1177
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 941, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1155
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 938, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1178
1156
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h7657f6f35500acf9);
1179
1157
  return ret;
1180
1158
  },
1181
1159
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1182
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 296, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1160
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 293, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1183
1161
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h38334fab7c782151);
1184
1162
  return ret;
1185
1163
  },
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "onekey-monero-runtime",
3
3
  "type": "module",
4
4
  "description": "OneKey Monero Runtime: wallet state over monero-oxide, persisted in SQLite",
5
- "version": "0.1.0-alpha.2",
5
+ "version": "0.1.0-alpha.4",
6
6
  "license": "Apache-2.0",
7
7
  "files": [
8
8
  "onekey_monero_runtime.js",