@tari-project/ootle-wasm 0.2.0 → 0.3.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/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2019, The Tari Developer Community
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/ootle_wasm.d.ts CHANGED
@@ -12,6 +12,69 @@ export class KeypairResult {
12
12
  secret_key: Uint8Array;
13
13
  }
14
14
 
15
+ /**
16
+ * A pair of Ootle public keys derived from an OotleSecretKey.
17
+ */
18
+ export class OotlePublicKey {
19
+ private constructor();
20
+ free(): void;
21
+ [Symbol.dispose](): void;
22
+ /**
23
+ * The owner (spending) public key bytes.
24
+ */
25
+ owner_key: Uint8Array;
26
+ /**
27
+ * The view-only public key bytes.
28
+ */
29
+ view_key: Uint8Array;
30
+ }
31
+
32
+ /**
33
+ * A pair of Ootle secret keys (owner + view).
34
+ */
35
+ export class OotleSecretKey {
36
+ private constructor();
37
+ free(): void;
38
+ [Symbol.dispose](): void;
39
+ /**
40
+ * The owner (spending) secret key bytes.
41
+ */
42
+ owner_key: Uint8Array;
43
+ /**
44
+ * The view-only secret key bytes.
45
+ */
46
+ view_key: Uint8Array;
47
+ }
48
+
49
+ /**
50
+ * Parsed components of an Ootle address.
51
+ */
52
+ export class ParsedOotleAddress {
53
+ private constructor();
54
+ free(): void;
55
+ [Symbol.dispose](): void;
56
+ /**
57
+ * Optional pay reference / memo bytes.
58
+ */
59
+ get memo(): Uint8Array | undefined;
60
+ /**
61
+ * Optional pay reference / memo bytes.
62
+ */
63
+ set memo(value: Uint8Array | null | undefined);
64
+ /**
65
+ * The network byte.
66
+ */
67
+ network: number;
68
+ /**
69
+ * The owner (spending) public key bytes.
70
+ */
71
+ owner_key: Uint8Array;
72
+ /**
73
+ * The view-only public key bytes.
74
+ */
75
+ view_key: Uint8Array;
76
+ }
77
+
15
78
  /**
16
79
  * Result of a Schnorr signature operation (raw bytes).
17
80
  */
@@ -34,6 +97,20 @@ export function borEncodeTransaction(transaction_json: string): string;
34
97
  */
35
98
  export function generateKeypair(): KeypairResult;
36
99
 
100
+ /**
101
+ * Generate an Ootle address (bech32m string) from public keys.
102
+ *
103
+ * `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, etc.).
104
+ * `memo` is an optional pay reference (max 64 bytes).
105
+ */
106
+ export function generateOotleAddress(owner_public_key: Uint8Array, view_public_key: Uint8Array, network: number, memo?: Uint8Array | null): string;
107
+
108
+ /**
109
+ * Generate a new random pair of Ootle secret keys (owner + view).
110
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array }.
111
+ */
112
+ export function generateOotleSecretKey(): OotleSecretKey;
113
+
37
114
  /**
38
115
  * Hash an UnsignedTransactionV1 (JSON string) for signing.
39
116
  * Returns the 64-byte signing message that must be Schnorr-signed.
@@ -47,6 +124,18 @@ export function hashUnsignedTransaction(unsigned_tx_json: string, seal_signer_pu
47
124
  */
48
125
  export function on_start(): void;
49
126
 
127
+ /**
128
+ * Derive the Ootle public keys from a pair of secret keys.
129
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array }.
130
+ */
131
+ export function ootlePublicKeyFromSecretKey(owner_key: Uint8Array, view_key: Uint8Array): OotlePublicKey;
132
+
133
+ /**
134
+ * Parse a bech32m Ootle address string into its components.
135
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array, network: number, memo: Uint8Array | undefined }.
136
+ */
137
+ export function parseOotleAddress(address: string): ParsedOotleAddress;
138
+
50
139
  /**
51
140
  * Derive the public key from a secret key (both raw bytes).
52
141
  */
package/ootle_wasm.js CHANGED
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./ootle_wasm_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- KeypairResult, SchnorrSignatureResult, borEncodeTransaction, generateKeypair, hashUnsignedTransaction, on_start, publicKeyFromSecretKey, schnorrSign
8
+ KeypairResult, OotlePublicKey, OotleSecretKey, ParsedOotleAddress, SchnorrSignatureResult, borEncodeTransaction, generateKeypair, generateOotleAddress, generateOotleSecretKey, hashUnsignedTransaction, on_start, ootlePublicKeyFromSecretKey, parseOotleAddress, publicKeyFromSecretKey, schnorrSign
9
9
  } from "./ootle_wasm_bg.js";
package/ootle_wasm_bg.js CHANGED
@@ -56,6 +56,229 @@ export class KeypairResult {
56
56
  }
57
57
  if (Symbol.dispose) KeypairResult.prototype[Symbol.dispose] = KeypairResult.prototype.free;
58
58
 
59
+ /**
60
+ * A pair of Ootle public keys derived from an OotleSecretKey.
61
+ */
62
+ export class OotlePublicKey {
63
+ static __wrap(ptr) {
64
+ ptr = ptr >>> 0;
65
+ const obj = Object.create(OotlePublicKey.prototype);
66
+ obj.__wbg_ptr = ptr;
67
+ OotlePublicKeyFinalization.register(obj, obj.__wbg_ptr, obj);
68
+ return obj;
69
+ }
70
+ __destroy_into_raw() {
71
+ const ptr = this.__wbg_ptr;
72
+ this.__wbg_ptr = 0;
73
+ OotlePublicKeyFinalization.unregister(this);
74
+ return ptr;
75
+ }
76
+ free() {
77
+ const ptr = this.__destroy_into_raw();
78
+ wasm.__wbg_ootlepublickey_free(ptr, 0);
79
+ }
80
+ /**
81
+ * The owner (spending) public key bytes.
82
+ * @returns {Uint8Array}
83
+ */
84
+ get owner_key() {
85
+ const ret = wasm.__wbg_get_ootlepublickey_owner_key(this.__wbg_ptr);
86
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
87
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
88
+ return v1;
89
+ }
90
+ /**
91
+ * The view-only public key bytes.
92
+ * @returns {Uint8Array}
93
+ */
94
+ get view_key() {
95
+ const ret = wasm.__wbg_get_ootlepublickey_view_key(this.__wbg_ptr);
96
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
97
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
98
+ return v1;
99
+ }
100
+ /**
101
+ * The owner (spending) public key bytes.
102
+ * @param {Uint8Array} arg0
103
+ */
104
+ set owner_key(arg0) {
105
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
106
+ const len0 = WASM_VECTOR_LEN;
107
+ wasm.__wbg_set_keypairresult_secret_key(this.__wbg_ptr, ptr0, len0);
108
+ }
109
+ /**
110
+ * The view-only public key bytes.
111
+ * @param {Uint8Array} arg0
112
+ */
113
+ set view_key(arg0) {
114
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
115
+ const len0 = WASM_VECTOR_LEN;
116
+ wasm.__wbg_set_keypairresult_public_key(this.__wbg_ptr, ptr0, len0);
117
+ }
118
+ }
119
+ if (Symbol.dispose) OotlePublicKey.prototype[Symbol.dispose] = OotlePublicKey.prototype.free;
120
+
121
+ /**
122
+ * A pair of Ootle secret keys (owner + view).
123
+ */
124
+ export class OotleSecretKey {
125
+ static __wrap(ptr) {
126
+ ptr = ptr >>> 0;
127
+ const obj = Object.create(OotleSecretKey.prototype);
128
+ obj.__wbg_ptr = ptr;
129
+ OotleSecretKeyFinalization.register(obj, obj.__wbg_ptr, obj);
130
+ return obj;
131
+ }
132
+ __destroy_into_raw() {
133
+ const ptr = this.__wbg_ptr;
134
+ this.__wbg_ptr = 0;
135
+ OotleSecretKeyFinalization.unregister(this);
136
+ return ptr;
137
+ }
138
+ free() {
139
+ const ptr = this.__destroy_into_raw();
140
+ wasm.__wbg_ootlesecretkey_free(ptr, 0);
141
+ }
142
+ /**
143
+ * The owner (spending) secret key bytes.
144
+ * @returns {Uint8Array}
145
+ */
146
+ get owner_key() {
147
+ const ret = wasm.__wbg_get_ootlesecretkey_owner_key(this.__wbg_ptr);
148
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
149
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
150
+ return v1;
151
+ }
152
+ /**
153
+ * The view-only secret key bytes.
154
+ * @returns {Uint8Array}
155
+ */
156
+ get view_key() {
157
+ const ret = wasm.__wbg_get_ootlesecretkey_view_key(this.__wbg_ptr);
158
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
159
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
160
+ return v1;
161
+ }
162
+ /**
163
+ * The owner (spending) secret key bytes.
164
+ * @param {Uint8Array} arg0
165
+ */
166
+ set owner_key(arg0) {
167
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
168
+ const len0 = WASM_VECTOR_LEN;
169
+ wasm.__wbg_set_keypairresult_secret_key(this.__wbg_ptr, ptr0, len0);
170
+ }
171
+ /**
172
+ * The view-only secret key bytes.
173
+ * @param {Uint8Array} arg0
174
+ */
175
+ set view_key(arg0) {
176
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
177
+ const len0 = WASM_VECTOR_LEN;
178
+ wasm.__wbg_set_keypairresult_public_key(this.__wbg_ptr, ptr0, len0);
179
+ }
180
+ }
181
+ if (Symbol.dispose) OotleSecretKey.prototype[Symbol.dispose] = OotleSecretKey.prototype.free;
182
+
183
+ /**
184
+ * Parsed components of an Ootle address.
185
+ */
186
+ export class ParsedOotleAddress {
187
+ static __wrap(ptr) {
188
+ ptr = ptr >>> 0;
189
+ const obj = Object.create(ParsedOotleAddress.prototype);
190
+ obj.__wbg_ptr = ptr;
191
+ ParsedOotleAddressFinalization.register(obj, obj.__wbg_ptr, obj);
192
+ return obj;
193
+ }
194
+ __destroy_into_raw() {
195
+ const ptr = this.__wbg_ptr;
196
+ this.__wbg_ptr = 0;
197
+ ParsedOotleAddressFinalization.unregister(this);
198
+ return ptr;
199
+ }
200
+ free() {
201
+ const ptr = this.__destroy_into_raw();
202
+ wasm.__wbg_parsedootleaddress_free(ptr, 0);
203
+ }
204
+ /**
205
+ * Optional pay reference / memo bytes.
206
+ * @returns {Uint8Array | undefined}
207
+ */
208
+ get memo() {
209
+ const ret = wasm.__wbg_get_parsedootleaddress_memo(this.__wbg_ptr);
210
+ let v1;
211
+ if (ret[0] !== 0) {
212
+ v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
213
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
214
+ }
215
+ return v1;
216
+ }
217
+ /**
218
+ * The network byte.
219
+ * @returns {number}
220
+ */
221
+ get network() {
222
+ const ret = wasm.__wbg_get_parsedootleaddress_network(this.__wbg_ptr);
223
+ return ret;
224
+ }
225
+ /**
226
+ * The owner (spending) public key bytes.
227
+ * @returns {Uint8Array}
228
+ */
229
+ get owner_key() {
230
+ const ret = wasm.__wbg_get_parsedootleaddress_owner_key(this.__wbg_ptr);
231
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
232
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
233
+ return v1;
234
+ }
235
+ /**
236
+ * The view-only public key bytes.
237
+ * @returns {Uint8Array}
238
+ */
239
+ get view_key() {
240
+ const ret = wasm.__wbg_get_parsedootleaddress_view_key(this.__wbg_ptr);
241
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
242
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
243
+ return v1;
244
+ }
245
+ /**
246
+ * Optional pay reference / memo bytes.
247
+ * @param {Uint8Array | null} [arg0]
248
+ */
249
+ set memo(arg0) {
250
+ var ptr0 = isLikeNone(arg0) ? 0 : passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
251
+ var len0 = WASM_VECTOR_LEN;
252
+ wasm.__wbg_set_parsedootleaddress_memo(this.__wbg_ptr, ptr0, len0);
253
+ }
254
+ /**
255
+ * The network byte.
256
+ * @param {number} arg0
257
+ */
258
+ set network(arg0) {
259
+ wasm.__wbg_set_parsedootleaddress_network(this.__wbg_ptr, arg0);
260
+ }
261
+ /**
262
+ * The owner (spending) public key bytes.
263
+ * @param {Uint8Array} arg0
264
+ */
265
+ set owner_key(arg0) {
266
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ wasm.__wbg_set_keypairresult_secret_key(this.__wbg_ptr, ptr0, len0);
269
+ }
270
+ /**
271
+ * The view-only public key bytes.
272
+ * @param {Uint8Array} arg0
273
+ */
274
+ set view_key(arg0) {
275
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
276
+ const len0 = WASM_VECTOR_LEN;
277
+ wasm.__wbg_set_keypairresult_public_key(this.__wbg_ptr, ptr0, len0);
278
+ }
279
+ }
280
+ if (Symbol.dispose) ParsedOotleAddress.prototype[Symbol.dispose] = ParsedOotleAddress.prototype.free;
281
+
59
282
  /**
60
283
  * Result of a Schnorr signature operation (raw bytes).
61
284
  */
@@ -150,6 +373,52 @@ export function generateKeypair() {
150
373
  return KeypairResult.__wrap(ret);
151
374
  }
152
375
 
376
+ /**
377
+ * Generate an Ootle address (bech32m string) from public keys.
378
+ *
379
+ * `network` is the network byte (0x00 = MainNet, 0x10 = LocalNet, 0x26 = Esmeralda, etc.).
380
+ * `memo` is an optional pay reference (max 64 bytes).
381
+ * @param {Uint8Array} owner_public_key
382
+ * @param {Uint8Array} view_public_key
383
+ * @param {number} network
384
+ * @param {Uint8Array | null} [memo]
385
+ * @returns {string}
386
+ */
387
+ export function generateOotleAddress(owner_public_key, view_public_key, network, memo) {
388
+ let deferred5_0;
389
+ let deferred5_1;
390
+ try {
391
+ const ptr0 = passArray8ToWasm0(owner_public_key, wasm.__wbindgen_malloc);
392
+ const len0 = WASM_VECTOR_LEN;
393
+ const ptr1 = passArray8ToWasm0(view_public_key, wasm.__wbindgen_malloc);
394
+ const len1 = WASM_VECTOR_LEN;
395
+ var ptr2 = isLikeNone(memo) ? 0 : passArray8ToWasm0(memo, wasm.__wbindgen_malloc);
396
+ var len2 = WASM_VECTOR_LEN;
397
+ const ret = wasm.generateOotleAddress(ptr0, len0, ptr1, len1, network, ptr2, len2);
398
+ var ptr4 = ret[0];
399
+ var len4 = ret[1];
400
+ if (ret[3]) {
401
+ ptr4 = 0; len4 = 0;
402
+ throw takeFromExternrefTable0(ret[2]);
403
+ }
404
+ deferred5_0 = ptr4;
405
+ deferred5_1 = len4;
406
+ return getStringFromWasm0(ptr4, len4);
407
+ } finally {
408
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
409
+ }
410
+ }
411
+
412
+ /**
413
+ * Generate a new random pair of Ootle secret keys (owner + view).
414
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array }.
415
+ * @returns {OotleSecretKey}
416
+ */
417
+ export function generateOotleSecretKey() {
418
+ const ret = wasm.generateOotleSecretKey();
419
+ return OotleSecretKey.__wrap(ret);
420
+ }
421
+
153
422
  /**
154
423
  * Hash an UnsignedTransactionV1 (JSON string) for signing.
155
424
  * Returns the 64-byte signing message that must be Schnorr-signed.
@@ -180,6 +449,41 @@ export function on_start() {
180
449
  wasm.on_start();
181
450
  }
182
451
 
452
+ /**
453
+ * Derive the Ootle public keys from a pair of secret keys.
454
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array }.
455
+ * @param {Uint8Array} owner_key
456
+ * @param {Uint8Array} view_key
457
+ * @returns {OotlePublicKey}
458
+ */
459
+ export function ootlePublicKeyFromSecretKey(owner_key, view_key) {
460
+ const ptr0 = passArray8ToWasm0(owner_key, wasm.__wbindgen_malloc);
461
+ const len0 = WASM_VECTOR_LEN;
462
+ const ptr1 = passArray8ToWasm0(view_key, wasm.__wbindgen_malloc);
463
+ const len1 = WASM_VECTOR_LEN;
464
+ const ret = wasm.ootlePublicKeyFromSecretKey(ptr0, len0, ptr1, len1);
465
+ if (ret[2]) {
466
+ throw takeFromExternrefTable0(ret[1]);
467
+ }
468
+ return OotlePublicKey.__wrap(ret[0]);
469
+ }
470
+
471
+ /**
472
+ * Parse a bech32m Ootle address string into its components.
473
+ * Returns { owner_key: Uint8Array, view_key: Uint8Array, network: number, memo: Uint8Array | undefined }.
474
+ * @param {string} address
475
+ * @returns {ParsedOotleAddress}
476
+ */
477
+ export function parseOotleAddress(address) {
478
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
479
+ const len0 = WASM_VECTOR_LEN;
480
+ const ret = wasm.parseOotleAddress(ptr0, len0);
481
+ if (ret[2]) {
482
+ throw takeFromExternrefTable0(ret[1]);
483
+ }
484
+ return ParsedOotleAddress.__wrap(ret[0]);
485
+ }
486
+
183
487
  /**
184
488
  * Derive the public key from a secret key (both raw bytes).
185
489
  * @param {Uint8Array} secret_key
@@ -334,6 +638,15 @@ export function __wbindgen_init_externref_table() {
334
638
  const KeypairResultFinalization = (typeof FinalizationRegistry === 'undefined')
335
639
  ? { register: () => {}, unregister: () => {} }
336
640
  : new FinalizationRegistry(ptr => wasm.__wbg_keypairresult_free(ptr >>> 0, 1));
641
+ const OotlePublicKeyFinalization = (typeof FinalizationRegistry === 'undefined')
642
+ ? { register: () => {}, unregister: () => {} }
643
+ : new FinalizationRegistry(ptr => wasm.__wbg_ootlepublickey_free(ptr >>> 0, 1));
644
+ const OotleSecretKeyFinalization = (typeof FinalizationRegistry === 'undefined')
645
+ ? { register: () => {}, unregister: () => {} }
646
+ : new FinalizationRegistry(ptr => wasm.__wbg_ootlesecretkey_free(ptr >>> 0, 1));
647
+ const ParsedOotleAddressFinalization = (typeof FinalizationRegistry === 'undefined')
648
+ ? { register: () => {}, unregister: () => {} }
649
+ : new FinalizationRegistry(ptr => wasm.__wbg_parsedootleaddress_free(ptr >>> 0, 1));
337
650
  const SchnorrSignatureResultFinalization = (typeof FinalizationRegistry === 'undefined')
338
651
  ? { register: () => {}, unregister: () => {} }
339
652
  : new FinalizationRegistry(ptr => wasm.__wbg_schnorrsignatureresult_free(ptr >>> 0, 1));
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "The Tari Development Community"
6
6
  ],
7
7
  "description": "WASM bindings for Tari Ootle client-side crypto — thin wasm-bindgen shell over ootle-wasm-core",
8
- "version": "0.2.0",
8
+ "version": "0.3.0",
9
9
  "license": "BSD-3-Clause",
10
10
  "repository": {
11
11
  "type": "git",
@@ -27,4 +27,4 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  }
30
- }
30
+ }