bitmask-core 0.1.2 → 0.2.0

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/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Core functionality for the BitMask wallet - <https://bitmask.app>
4
4
 
5
+ [![Build Status](https://img.shields.io/github/workflow/status/diba-io/bitmask-core/Rust?style=flat-square)](https://github.com/diba-io/bitmask-core/actions/workflows/Rust.yml)
6
+ [![Crates.io](https://img.shields.io/crates/v/bitmask-core?style=flat-square)](https://docs.rs/bitmask-core/latest/bitmask-core/)
7
+ [![npm: bitmask-core](https://img.shields.io/npm/v/bitmask-core?style=flat-square)](https://www.npmjs.com/package/bitmask-core)
8
+ [![License: MIT+APACHE](https://img.shields.io/crates/l/bitmask-core?style=flat-square)](https://mit-license.org)
9
+ ![Lines of code](https://img.shields.io/tokei/lines/github/diba-io/bitmask-core?style=flat-square)
10
+ [![Telegram: rust_in_bitcoin](https://img.shields.io/badge/telegram-rust_in_bitcoin-blue?style=flat-square)](https://t.me/rust_in_bitcoin)
11
+
5
12
  ## Uses
6
13
 
7
14
  - [bdk](https://github.com/bitcoindevkit/bdk) - Bitcoin Dev Kit
@@ -19,4 +26,4 @@ If there are issues compiling, be sure to check you're compiling with the latest
19
26
  ## Test
20
27
 
21
28
  1. Lint against wasm32: `cargo clippy --target wasm32-unknown-unknown`
22
- 2. Run tests in browser: `wasm-pack test --headless --chrome`
29
+ 2. Run tests in browser: `TEST_WALLET_SEED="replace with a 12 word mnemonic for a wallet containing testnet sats" wasm-pack test --headless --chrome`
package/bitmask_core.d.ts CHANGED
@@ -2,9 +2,10 @@
2
2
  /* eslint-disable */
3
3
  /**
4
4
  * @param {string} password
5
+ * @param {string} encrypted_descriptors
5
6
  * @returns {Promise<any>}
6
7
  */
7
- export function get_vault(password: string): Promise<any>;
8
+ export function get_vault(password: string, encrypted_descriptors: string): Promise<any>;
8
9
  /**
9
10
  * @param {string} encryption_password
10
11
  * @param {string} seed_password
@@ -37,9 +38,16 @@ export function import_list_assets(): Promise<any>;
37
38
  */
38
39
  export function import_asset(descriptor: string, change_descriptor: string, asset?: string, genesis?: string): Promise<any>;
39
40
  /**
41
+ * @param {string} unspent
42
+ * @param {string} blinded_unspents
40
43
  * @returns {Promise<any>}
41
44
  */
42
- export function set_blinded_utxos(): Promise<any>;
45
+ export function set_blinded_utxos(unspent: string, blinded_unspents: string): Promise<any>;
46
+ /**
47
+ * @param {string} utxo_string
48
+ * @returns {Promise<any>}
49
+ */
50
+ export function set_blinded_utxo(utxo_string: string): Promise<any>;
43
51
  /**
44
52
  * @param {string} descriptor
45
53
  * @param {string} change_descriptor
@@ -75,10 +83,10 @@ export function validate_transaction(consignment: string): Promise<any>;
75
83
  * @param {string} consignment
76
84
  * @param {string} txid
77
85
  * @param {number} vout
78
- * @param {BigInt} blinding
86
+ * @param {string} blinding
79
87
  * @returns {Promise<any>}
80
88
  */
81
- export function accept_transaction(consignment: string, txid: string, vout: number, blinding: BigInt): Promise<any>;
89
+ export function accept_transaction(consignment: string, txid: string, vout: number, blinding: string): Promise<any>;
82
90
  /**
83
91
  * @param {string} network_str
84
92
  */
@@ -88,19 +96,20 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
88
96
 
89
97
  export interface InitOutput {
90
98
  readonly memory: WebAssembly.Memory;
91
- readonly get_vault: (a: number, b: number) => number;
99
+ readonly get_vault: (a: number, b: number, c: number, d: number) => number;
92
100
  readonly get_mnemonic_seed: (a: number, b: number, c: number, d: number) => number;
93
101
  readonly save_mnemonic_seed: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
94
102
  readonly get_wallet_data: (a: number, b: number, c: number, d: number) => number;
95
103
  readonly import_list_assets: () => number;
96
104
  readonly import_asset: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
105
+ readonly set_blinded_utxos: (a: number, b: number, c: number, d: number) => number;
106
+ readonly set_blinded_utxo: (a: number, b: number) => number;
97
107
  readonly send_sats: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
98
108
  readonly send_tokens: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number;
99
109
  readonly send_tokens_full: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number;
100
110
  readonly validate_transaction: (a: number, b: number) => number;
101
111
  readonly accept_transaction: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
102
112
  readonly switch_network: (a: number, b: number) => void;
103
- readonly set_blinded_utxos: () => number;
104
113
  readonly rustsecp256k1_v0_4_1_context_create: (a: number) => number;
105
114
  readonly rustsecp256k1_v0_4_1_context_destroy: (a: number) => void;
106
115
  readonly rustsecp256k1_v0_4_1_default_illegal_callback_fn: (a: number, b: number) => void;
package/bitmask_core.js CHANGED
@@ -1,6 +1,26 @@
1
1
 
2
2
  let wasm;
3
3
 
4
+ const heap = new Array(32).fill(undefined);
5
+
6
+ heap.push(undefined, null, true, false);
7
+
8
+ function getObject(idx) { return heap[idx]; }
9
+
10
+ let heap_next = heap.length;
11
+
12
+ function dropObject(idx) {
13
+ if (idx < 36) return;
14
+ heap[idx] = heap_next;
15
+ heap_next = idx;
16
+ }
17
+
18
+ function takeObject(idx) {
19
+ const ret = getObject(idx);
20
+ dropObject(idx);
21
+ return ret;
22
+ }
23
+
4
24
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
5
25
 
6
26
  cachedTextDecoder.decode();
@@ -17,12 +37,6 @@ function getStringFromWasm0(ptr, len) {
17
37
  return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
18
38
  }
19
39
 
20
- const heap = new Array(32).fill(undefined);
21
-
22
- heap.push(undefined, null, true, false);
23
-
24
- let heap_next = heap.length;
25
-
26
40
  function addHeapObject(obj) {
27
41
  if (heap_next === heap.length) heap.push(heap.length + 1);
28
42
  const idx = heap_next;
@@ -32,20 +46,6 @@ function addHeapObject(obj) {
32
46
  return idx;
33
47
  }
34
48
 
35
- function getObject(idx) { return heap[idx]; }
36
-
37
- function dropObject(idx) {
38
- if (idx < 36) return;
39
- heap[idx] = heap_next;
40
- heap_next = idx;
41
- }
42
-
43
- function takeObject(idx) {
44
- const ret = getObject(idx);
45
- dropObject(idx);
46
- return ret;
47
- }
48
-
49
49
  let WASM_VECTOR_LEN = 0;
50
50
 
51
51
  let cachedTextEncoder = new TextEncoder('utf-8');
@@ -208,12 +208,15 @@ function __wbg_adapter_28(arg0, arg1, arg2) {
208
208
 
209
209
  /**
210
210
  * @param {string} password
211
+ * @param {string} encrypted_descriptors
211
212
  * @returns {Promise<any>}
212
213
  */
213
- export function get_vault(password) {
214
+ export function get_vault(password, encrypted_descriptors) {
214
215
  var ptr0 = passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
215
216
  var len0 = WASM_VECTOR_LEN;
216
- var ret = wasm.get_vault(ptr0, len0);
217
+ var ptr1 = passStringToWasm0(encrypted_descriptors, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ var len1 = WASM_VECTOR_LEN;
219
+ var ret = wasm.get_vault(ptr0, len0, ptr1, len1);
217
220
  return takeObject(ret);
218
221
  }
219
222
 
@@ -291,10 +294,27 @@ export function import_asset(descriptor, change_descriptor, asset, genesis) {
291
294
  }
292
295
 
293
296
  /**
297
+ * @param {string} unspent
298
+ * @param {string} blinded_unspents
294
299
  * @returns {Promise<any>}
295
300
  */
296
- export function set_blinded_utxos() {
297
- var ret = wasm.set_blinded_utxos();
301
+ export function set_blinded_utxos(unspent, blinded_unspents) {
302
+ var ptr0 = passStringToWasm0(unspent, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
303
+ var len0 = WASM_VECTOR_LEN;
304
+ var ptr1 = passStringToWasm0(blinded_unspents, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
305
+ var len1 = WASM_VECTOR_LEN;
306
+ var ret = wasm.set_blinded_utxos(ptr0, len0, ptr1, len1);
307
+ return takeObject(ret);
308
+ }
309
+
310
+ /**
311
+ * @param {string} utxo_string
312
+ * @returns {Promise<any>}
313
+ */
314
+ export function set_blinded_utxo(utxo_string) {
315
+ var ptr0 = passStringToWasm0(utxo_string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
316
+ var len0 = WASM_VECTOR_LEN;
317
+ var ret = wasm.set_blinded_utxo(ptr0, len0);
298
318
  return takeObject(ret);
299
319
  }
300
320
 
@@ -385,7 +405,7 @@ export function validate_transaction(consignment) {
385
405
  * @param {string} consignment
386
406
  * @param {string} txid
387
407
  * @param {number} vout
388
- * @param {BigInt} blinding
408
+ * @param {string} blinding
389
409
  * @returns {Promise<any>}
390
410
  */
391
411
  export function accept_transaction(consignment, txid, vout, blinding) {
@@ -393,10 +413,9 @@ export function accept_transaction(consignment, txid, vout, blinding) {
393
413
  var len0 = WASM_VECTOR_LEN;
394
414
  var ptr1 = passStringToWasm0(txid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
395
415
  var len1 = WASM_VECTOR_LEN;
396
- uint64CvtShim[0] = blinding;
397
- const low2 = u32CvtShim[0];
398
- const high2 = u32CvtShim[1];
399
- var ret = wasm.accept_transaction(ptr0, len0, ptr1, len1, vout, low2, high2);
416
+ var ptr2 = passStringToWasm0(blinding, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
417
+ var len2 = WASM_VECTOR_LEN;
418
+ var ret = wasm.accept_transaction(ptr0, len0, ptr1, len1, vout, ptr2, len2);
400
419
  return takeObject(ret);
401
420
  }
402
421
 
@@ -438,7 +457,7 @@ function getArrayJsValueFromWasm0(ptr, len) {
438
457
  }
439
458
  return result;
440
459
  }
441
- function __wbg_adapter_150(arg0, arg1, arg2, arg3) {
460
+ function __wbg_adapter_145(arg0, arg1, arg2, arg3) {
442
461
  wasm.wasm_bindgen__convert__closures__invoke2_mut__h989d4d5a38951b01(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
443
462
  }
444
463
 
@@ -479,20 +498,12 @@ async function init(input) {
479
498
  }
480
499
  const imports = {};
481
500
  imports.wbg = {};
482
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
483
- var ret = getStringFromWasm0(arg0, arg1);
484
- return addHeapObject(ret);
485
- };
486
501
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
487
502
  takeObject(arg0);
488
503
  };
489
- imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) {
490
- const obj = getObject(arg1);
491
- var ret = JSON.stringify(obj === undefined ? null : obj);
492
- var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
493
- var len0 = WASM_VECTOR_LEN;
494
- getInt32Memory0()[arg0 / 4 + 1] = len0;
495
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
504
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
505
+ var ret = getStringFromWasm0(arg0, arg1);
506
+ return addHeapObject(ret);
496
507
  };
497
508
  imports.wbg.__wbindgen_cb_drop = function(arg0) {
498
509
  const obj = takeObject(arg0).original;
@@ -503,6 +514,14 @@ async function init(input) {
503
514
  var ret = false;
504
515
  return ret;
505
516
  };
517
+ imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) {
518
+ const obj = getObject(arg1);
519
+ var ret = JSON.stringify(obj === undefined ? null : obj);
520
+ var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
521
+ var len0 = WASM_VECTOR_LEN;
522
+ getInt32Memory0()[arg0 / 4 + 1] = len0;
523
+ getInt32Memory0()[arg0 / 4 + 0] = ptr0;
524
+ };
506
525
  imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
507
526
  const obj = getObject(arg1);
508
527
  var ret = typeof(obj) === 'string' ? obj : undefined;
@@ -511,6 +530,10 @@ async function init(input) {
511
530
  getInt32Memory0()[arg0 / 4 + 1] = len0;
512
531
  getInt32Memory0()[arg0 / 4 + 0] = ptr0;
513
532
  };
533
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
534
+ var ret = getObject(arg0);
535
+ return addHeapObject(ret);
536
+ };
514
537
  imports.wbg.__wbg_randomFillSync_378e02b85af41ab6 = function() { return handleError(function (arg0, arg1, arg2) {
515
538
  getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
516
539
  }, arguments) };
@@ -554,10 +577,6 @@ async function init(input) {
554
577
  var ret = getObject(arg0).msCrypto;
555
578
  return addHeapObject(ret);
556
579
  };
557
- imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
558
- var ret = getObject(arg0);
559
- return addHeapObject(ret);
560
- };
561
580
  imports.wbg.__wbg_log_06b7ffc63a0f8bee = function(arg0, arg1) {
562
581
  var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
563
582
  wasm.__wbindgen_free(arg0, arg1 * 4);
@@ -571,10 +590,6 @@ async function init(input) {
571
590
  var ret = getObject(arg0) instanceof Window;
572
591
  return ret;
573
592
  };
574
- imports.wbg.__wbg_localStorage_2b7091e6919605e2 = function() { return handleError(function (arg0) {
575
- var ret = getObject(arg0).localStorage;
576
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
577
- }, arguments) };
578
593
  imports.wbg.__wbg_fetch_427498e0ccea81f4 = function(arg0, arg1) {
579
594
  var ret = getObject(arg0).fetch(getObject(arg1));
580
595
  return addHeapObject(ret);
@@ -583,6 +598,16 @@ async function init(input) {
583
598
  var ret = getObject(arg0).fetch(getObject(arg1));
584
599
  return addHeapObject(ret);
585
600
  };
601
+ imports.wbg.__wbg_new_226d109446575877 = function() { return handleError(function () {
602
+ var ret = new Headers();
603
+ return addHeapObject(ret);
604
+ }, arguments) };
605
+ imports.wbg.__wbg_append_4d85f35672cbffa7 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
606
+ getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
607
+ }, arguments) };
608
+ imports.wbg.__wbg_set_f9448486a94c9aef = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
609
+ getObject(arg0).set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
610
+ }, arguments) };
586
611
  imports.wbg.__wbg_instanceof_Response_ea36d565358a42f7 = function(arg0) {
587
612
  var ret = getObject(arg0) instanceof Response;
588
613
  return ret;
@@ -622,26 +647,6 @@ async function init(input) {
622
647
  var ret = getObject(arg0).text();
623
648
  return addHeapObject(ret);
624
649
  }, arguments) };
625
- imports.wbg.__wbg_getItem_f92ef607397e96b1 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
626
- var ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3));
627
- var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
628
- var len0 = WASM_VECTOR_LEN;
629
- getInt32Memory0()[arg0 / 4 + 1] = len0;
630
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
631
- }, arguments) };
632
- imports.wbg.__wbg_setItem_279b13e5ad0b82cb = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
633
- getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
634
- }, arguments) };
635
- imports.wbg.__wbg_new_226d109446575877 = function() { return handleError(function () {
636
- var ret = new Headers();
637
- return addHeapObject(ret);
638
- }, arguments) };
639
- imports.wbg.__wbg_append_4d85f35672cbffa7 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
640
- getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
641
- }, arguments) };
642
- imports.wbg.__wbg_set_f9448486a94c9aef = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
643
- getObject(arg0).set(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
644
- }, arguments) };
645
650
  imports.wbg.__wbg_newwithstrandinit_c07f0662ece15bc6 = function() { return handleError(function (arg0, arg1, arg2) {
646
651
  var ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));
647
652
  return addHeapObject(ret);
@@ -759,7 +764,7 @@ async function init(input) {
759
764
  const a = state0.a;
760
765
  state0.a = 0;
761
766
  try {
762
- return __wbg_adapter_150(a, state0.b, arg0, arg1);
767
+ return __wbg_adapter_145(a, state0.b, arg0, arg1);
763
768
  } finally {
764
769
  state0.a = a;
765
770
  }
@@ -851,8 +856,8 @@ async function init(input) {
851
856
  var ret = wasm.memory;
852
857
  return addHeapObject(ret);
853
858
  };
854
- imports.wbg.__wbindgen_closure_wrapper2541 = function(arg0, arg1, arg2) {
855
- var ret = makeMutClosure(arg0, arg1, 796, __wbg_adapter_28);
859
+ imports.wbg.__wbindgen_closure_wrapper2535 = function(arg0, arg1, arg2) {
860
+ var ret = makeMutClosure(arg0, arg1, 793, __wbg_adapter_28);
856
861
  return addHeapObject(ret);
857
862
  };
858
863
 
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Hunter Trujillo <cryptoquick@pm.me>"
6
6
  ],
7
7
  "description": "Core functionality for the BitMask wallet",
8
- "version": "0.1.2",
8
+ "version": "0.2.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",