@synonymdev/pubky 0.1.9 → 0.1.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.
- package/README.md +121 -1
- package/browser.js +146 -58
- package/index.cjs +145 -57
- package/package.json +1 -1
- package/pubky.d.ts +38 -5
- package/pubky_bg.wasm +0 -0
package/index.cjs
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
let imports = {};
|
|
2
2
|
imports['__wbindgen_placeholder__'] = module.exports;
|
|
3
3
|
let wasm;
|
|
4
|
-
const {
|
|
4
|
+
const { TextDecoder, TextEncoder } = require(`util`);
|
|
5
|
+
|
|
6
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
7
|
+
|
|
8
|
+
cachedTextDecoder.decode();
|
|
9
|
+
|
|
10
|
+
let cachedUint8Memory0 = null;
|
|
11
|
+
|
|
12
|
+
function getUint8Memory0() {
|
|
13
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
14
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
15
|
+
}
|
|
16
|
+
return cachedUint8Memory0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getStringFromWasm0(ptr, len) {
|
|
20
|
+
ptr = ptr >>> 0;
|
|
21
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
22
|
+
}
|
|
5
23
|
|
|
6
24
|
const heap = new Array(128).fill(undefined);
|
|
7
25
|
|
|
8
26
|
heap.push(undefined, null, true, false);
|
|
9
27
|
|
|
10
|
-
function getObject(idx) { return heap[idx]; }
|
|
11
|
-
|
|
12
28
|
let heap_next = heap.length;
|
|
13
29
|
|
|
30
|
+
function addHeapObject(obj) {
|
|
31
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
32
|
+
const idx = heap_next;
|
|
33
|
+
heap_next = heap[idx];
|
|
34
|
+
|
|
35
|
+
heap[idx] = obj;
|
|
36
|
+
return idx;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getObject(idx) { return heap[idx]; }
|
|
40
|
+
|
|
14
41
|
function dropObject(idx) {
|
|
15
42
|
if (idx < 132) return;
|
|
16
43
|
heap[idx] = heap_next;
|
|
@@ -25,15 +52,6 @@ function takeObject(idx) {
|
|
|
25
52
|
|
|
26
53
|
let WASM_VECTOR_LEN = 0;
|
|
27
54
|
|
|
28
|
-
let cachedUint8Memory0 = null;
|
|
29
|
-
|
|
30
|
-
function getUint8Memory0() {
|
|
31
|
-
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
32
|
-
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
33
|
-
}
|
|
34
|
-
return cachedUint8Memory0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
55
|
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
38
56
|
|
|
39
57
|
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
@@ -101,24 +119,6 @@ function getInt32Memory0() {
|
|
|
101
119
|
return cachedInt32Memory0;
|
|
102
120
|
}
|
|
103
121
|
|
|
104
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
105
|
-
|
|
106
|
-
cachedTextDecoder.decode();
|
|
107
|
-
|
|
108
|
-
function getStringFromWasm0(ptr, len) {
|
|
109
|
-
ptr = ptr >>> 0;
|
|
110
|
-
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function addHeapObject(obj) {
|
|
114
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
115
|
-
const idx = heap_next;
|
|
116
|
-
heap_next = heap[idx];
|
|
117
|
-
|
|
118
|
-
heap[idx] = obj;
|
|
119
|
-
return idx;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
122
|
function debugString(val) {
|
|
123
123
|
// primitive types
|
|
124
124
|
const type = typeof val;
|
|
@@ -218,6 +218,20 @@ function __wbg_adapter_26(arg0, arg1, arg2) {
|
|
|
218
218
|
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha5424c6cb7b1ff0d(arg0, arg1, addHeapObject(arg2));
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
function _assertClass(instance, klass) {
|
|
222
|
+
if (!(instance instanceof klass)) {
|
|
223
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
224
|
+
}
|
|
225
|
+
return instance.ptr;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
229
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
230
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
231
|
+
WASM_VECTOR_LEN = arg.length;
|
|
232
|
+
return ptr;
|
|
233
|
+
}
|
|
234
|
+
|
|
221
235
|
let cachedUint32Memory0 = null;
|
|
222
236
|
|
|
223
237
|
function getUint32Memory0() {
|
|
@@ -248,20 +262,6 @@ function getArrayJsValueFromWasm0(ptr, len) {
|
|
|
248
262
|
return result;
|
|
249
263
|
}
|
|
250
264
|
|
|
251
|
-
function _assertClass(instance, klass) {
|
|
252
|
-
if (!(instance instanceof klass)) {
|
|
253
|
-
throw new Error(`expected instance of ${klass.name}`);
|
|
254
|
-
}
|
|
255
|
-
return instance.ptr;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
259
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
260
|
-
getUint8Memory0().set(arg, ptr / 1);
|
|
261
|
-
WASM_VECTOR_LEN = arg.length;
|
|
262
|
-
return ptr;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
265
|
function handleError(f, args) {
|
|
266
266
|
try {
|
|
267
267
|
return f.apply(this, args);
|
|
@@ -269,7 +269,7 @@ function handleError(f, args) {
|
|
|
269
269
|
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function __wbg_adapter_122(arg0, arg1, arg2, arg3) {
|
|
273
273
|
wasm.wasm_bindgen__convert__closures__invoke2_mut__hcef77123246c6bdb(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -312,11 +312,19 @@ class Keypair {
|
|
|
312
312
|
* @param {Uint8Array} secret_key
|
|
313
313
|
* @returns {Keypair}
|
|
314
314
|
*/
|
|
315
|
-
static
|
|
316
|
-
const ret = wasm.
|
|
315
|
+
static fromSecretKey(secret_key) {
|
|
316
|
+
const ret = wasm.keypair_fromSecretKey(addHeapObject(secret_key));
|
|
317
317
|
return Keypair.__wrap(ret);
|
|
318
318
|
}
|
|
319
319
|
/**
|
|
320
|
+
* Returns the secret key of this keypair.
|
|
321
|
+
* @returns {Uint8Array}
|
|
322
|
+
*/
|
|
323
|
+
secretKey() {
|
|
324
|
+
const ret = wasm.keypair_secretKey(this.__wbg_ptr);
|
|
325
|
+
return takeObject(ret);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
320
328
|
* Returns the [PublicKey] of this keypair.
|
|
321
329
|
* @returns {PublicKey}
|
|
322
330
|
*/
|
|
@@ -370,10 +378,61 @@ class PubkyClient {
|
|
|
370
378
|
return PubkyClient.__wrap(ret);
|
|
371
379
|
}
|
|
372
380
|
/**
|
|
381
|
+
* Create a recovery file of the `keypair`, containing the secret key encrypted
|
|
382
|
+
* using the `passphrase`.
|
|
383
|
+
* @param {Keypair} keypair
|
|
384
|
+
* @param {string} passphrase
|
|
385
|
+
* @returns {Uint8Array}
|
|
386
|
+
*/
|
|
387
|
+
static createRecoveryFile(keypair, passphrase) {
|
|
388
|
+
try {
|
|
389
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
390
|
+
_assertClass(keypair, Keypair);
|
|
391
|
+
const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
392
|
+
const len0 = WASM_VECTOR_LEN;
|
|
393
|
+
wasm.pubkyclient_createRecoveryFile(retptr, keypair.__wbg_ptr, ptr0, len0);
|
|
394
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
395
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
396
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
397
|
+
if (r2) {
|
|
398
|
+
throw takeObject(r1);
|
|
399
|
+
}
|
|
400
|
+
return takeObject(r0);
|
|
401
|
+
} finally {
|
|
402
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Create a recovery file of the `keypair`, containing the secret key encrypted
|
|
407
|
+
* using the `passphrase`.
|
|
408
|
+
* @param {Uint8Array} recovery_file
|
|
409
|
+
* @param {string} passphrase
|
|
410
|
+
* @returns {Keypair}
|
|
411
|
+
*/
|
|
412
|
+
static decryptRecoveryFile(recovery_file, passphrase) {
|
|
413
|
+
try {
|
|
414
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
415
|
+
const ptr0 = passArray8ToWasm0(recovery_file, wasm.__wbindgen_malloc);
|
|
416
|
+
const len0 = WASM_VECTOR_LEN;
|
|
417
|
+
const ptr1 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
418
|
+
const len1 = WASM_VECTOR_LEN;
|
|
419
|
+
wasm.pubkyclient_decryptRecoveryFile(retptr, ptr0, len0, ptr1, len1);
|
|
420
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
421
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
422
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
423
|
+
if (r2) {
|
|
424
|
+
throw takeObject(r1);
|
|
425
|
+
}
|
|
426
|
+
return Keypair.__wrap(r0);
|
|
427
|
+
} finally {
|
|
428
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
373
432
|
* Set Pkarr relays used for publishing and resolving Pkarr packets.
|
|
374
433
|
*
|
|
375
434
|
* By default, [PubkyClient] will use `["https://relay.pkarr.org"]`
|
|
376
|
-
* @param {
|
|
435
|
+
* @param {(string)[]} relays
|
|
377
436
|
* @returns {PubkyClient}
|
|
378
437
|
*/
|
|
379
438
|
setPkarrRelays(relays) {
|
|
@@ -384,7 +443,7 @@ class PubkyClient {
|
|
|
384
443
|
return PubkyClient.__wrap(ret);
|
|
385
444
|
}
|
|
386
445
|
/**
|
|
387
|
-
* @returns {
|
|
446
|
+
* @returns {(string)[]}
|
|
388
447
|
*/
|
|
389
448
|
getPkarrRelays() {
|
|
390
449
|
try {
|
|
@@ -483,6 +542,25 @@ class PubkyClient {
|
|
|
483
542
|
const ret = wasm.pubkyclient_delete(this.__wbg_ptr, ptr0, len0);
|
|
484
543
|
return takeObject(ret);
|
|
485
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* Returns a list of Pubky URLs of the files within the `url` path,
|
|
547
|
+
* respecting the `cursor`, `reverse` and `limit` options.
|
|
548
|
+
*
|
|
549
|
+
* `cursor` is usually the last url from previous responses.
|
|
550
|
+
* @param {string} url
|
|
551
|
+
* @param {string | undefined} [cursor]
|
|
552
|
+
* @param {boolean | undefined} [reverse]
|
|
553
|
+
* @param {number | undefined} [limit]
|
|
554
|
+
* @returns {Promise<Array<any>>}
|
|
555
|
+
*/
|
|
556
|
+
list(url, cursor, reverse, limit) {
|
|
557
|
+
const ptr0 = passStringToWasm0(url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
558
|
+
const len0 = WASM_VECTOR_LEN;
|
|
559
|
+
var ptr1 = isLikeNone(cursor) ? 0 : passStringToWasm0(cursor, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
560
|
+
var len1 = WASM_VECTOR_LEN;
|
|
561
|
+
const ret = wasm.pubkyclient_list(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(reverse) ? 0xFFFFFF : reverse ? 1 : 0, isLikeNone(limit) ? 0xFFFFFF : limit);
|
|
562
|
+
return takeObject(ret);
|
|
563
|
+
}
|
|
486
564
|
}
|
|
487
565
|
module.exports.PubkyClient = PubkyClient;
|
|
488
566
|
|
|
@@ -592,6 +670,11 @@ class Session {
|
|
|
592
670
|
}
|
|
593
671
|
module.exports.Session = Session;
|
|
594
672
|
|
|
673
|
+
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
674
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
675
|
+
return addHeapObject(ret);
|
|
676
|
+
};
|
|
677
|
+
|
|
595
678
|
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
596
679
|
takeObject(arg0);
|
|
597
680
|
};
|
|
@@ -610,11 +693,6 @@ module.exports.__wbg_session_new = function(arg0) {
|
|
|
610
693
|
return addHeapObject(ret);
|
|
611
694
|
};
|
|
612
695
|
|
|
613
|
-
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
614
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
615
|
-
return addHeapObject(ret);
|
|
616
|
-
};
|
|
617
|
-
|
|
618
696
|
module.exports.__wbg_fetch_1e4e8ed1f64c7e28 = function(arg0) {
|
|
619
697
|
const ret = fetch(getObject(arg0));
|
|
620
698
|
return addHeapObject(ret);
|
|
@@ -765,6 +843,11 @@ module.exports.__wbg_getRandomValues_3aa56aa6edec874c = function() { return hand
|
|
|
765
843
|
getObject(arg0).getRandomValues(getObject(arg1));
|
|
766
844
|
}, arguments) };
|
|
767
845
|
|
|
846
|
+
module.exports.__wbg_new_16b304a2cfa7ff4a = function() {
|
|
847
|
+
const ret = new Array();
|
|
848
|
+
return addHeapObject(ret);
|
|
849
|
+
};
|
|
850
|
+
|
|
768
851
|
module.exports.__wbg_newnoargs_e258087cd0daa0ea = function(arg0, arg1) {
|
|
769
852
|
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
770
853
|
return addHeapObject(ret);
|
|
@@ -815,6 +898,11 @@ module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
|
815
898
|
return ret;
|
|
816
899
|
};
|
|
817
900
|
|
|
901
|
+
module.exports.__wbg_push_a5b05aedc7234f9f = function(arg0, arg1) {
|
|
902
|
+
const ret = getObject(arg0).push(getObject(arg1));
|
|
903
|
+
return ret;
|
|
904
|
+
};
|
|
905
|
+
|
|
818
906
|
module.exports.__wbg_new_28c511d9baebfa89 = function(arg0, arg1) {
|
|
819
907
|
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
820
908
|
return addHeapObject(ret);
|
|
@@ -852,7 +940,7 @@ module.exports.__wbg_new_81740750da40724f = function(arg0, arg1) {
|
|
|
852
940
|
const a = state0.a;
|
|
853
941
|
state0.a = 0;
|
|
854
942
|
try {
|
|
855
|
-
return
|
|
943
|
+
return __wbg_adapter_122(a, state0.b, arg0, arg1);
|
|
856
944
|
} finally {
|
|
857
945
|
state0.a = a;
|
|
858
946
|
}
|
|
@@ -950,8 +1038,8 @@ module.exports.__wbindgen_memory = function() {
|
|
|
950
1038
|
return addHeapObject(ret);
|
|
951
1039
|
};
|
|
952
1040
|
|
|
953
|
-
module.exports.
|
|
954
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1041
|
+
module.exports.__wbindgen_closure_wrapper1792 = function(arg0, arg1, arg2) {
|
|
1042
|
+
const ret = makeMutClosure(arg0, arg1, 295, __wbg_adapter_26);
|
|
955
1043
|
return addHeapObject(ret);
|
|
956
1044
|
};
|
|
957
1045
|
|
package/package.json
CHANGED
package/pubky.d.ts
CHANGED
|
@@ -14,7 +14,12 @@ export class Keypair {
|
|
|
14
14
|
* @param {Uint8Array} secret_key
|
|
15
15
|
* @returns {Keypair}
|
|
16
16
|
*/
|
|
17
|
-
static
|
|
17
|
+
static fromSecretKey(secret_key: Uint8Array): Keypair;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the secret key of this keypair.
|
|
20
|
+
* @returns {Uint8Array}
|
|
21
|
+
*/
|
|
22
|
+
secretKey(): Uint8Array;
|
|
18
23
|
/**
|
|
19
24
|
* Returns the [PublicKey] of this keypair.
|
|
20
25
|
* @returns {PublicKey}
|
|
@@ -35,17 +40,33 @@ export class PubkyClient {
|
|
|
35
40
|
*/
|
|
36
41
|
static testnet(): PubkyClient;
|
|
37
42
|
/**
|
|
43
|
+
* Create a recovery file of the `keypair`, containing the secret key encrypted
|
|
44
|
+
* using the `passphrase`.
|
|
45
|
+
* @param {Keypair} keypair
|
|
46
|
+
* @param {string} passphrase
|
|
47
|
+
* @returns {Uint8Array}
|
|
48
|
+
*/
|
|
49
|
+
static createRecoveryFile(keypair: Keypair, passphrase: string): Uint8Array;
|
|
50
|
+
/**
|
|
51
|
+
* Create a recovery file of the `keypair`, containing the secret key encrypted
|
|
52
|
+
* using the `passphrase`.
|
|
53
|
+
* @param {Uint8Array} recovery_file
|
|
54
|
+
* @param {string} passphrase
|
|
55
|
+
* @returns {Keypair}
|
|
56
|
+
*/
|
|
57
|
+
static decryptRecoveryFile(recovery_file: Uint8Array, passphrase: string): Keypair;
|
|
58
|
+
/**
|
|
38
59
|
* Set Pkarr relays used for publishing and resolving Pkarr packets.
|
|
39
60
|
*
|
|
40
61
|
* By default, [PubkyClient] will use `["https://relay.pkarr.org"]`
|
|
41
|
-
* @param {
|
|
62
|
+
* @param {(string)[]} relays
|
|
42
63
|
* @returns {PubkyClient}
|
|
43
64
|
*/
|
|
44
|
-
setPkarrRelays(relays:
|
|
65
|
+
setPkarrRelays(relays: (string)[]): PubkyClient;
|
|
45
66
|
/**
|
|
46
|
-
* @returns {
|
|
67
|
+
* @returns {(string)[]}
|
|
47
68
|
*/
|
|
48
|
-
getPkarrRelays():
|
|
69
|
+
getPkarrRelays(): (string)[];
|
|
49
70
|
/**
|
|
50
71
|
* Signup to a homeserver and update Pkarr accordingly.
|
|
51
72
|
*
|
|
@@ -96,6 +117,18 @@ export class PubkyClient {
|
|
|
96
117
|
* @returns {Promise<void>}
|
|
97
118
|
*/
|
|
98
119
|
delete(url: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns a list of Pubky URLs of the files within the `url` path,
|
|
122
|
+
* respecting the `cursor`, `reverse` and `limit` options.
|
|
123
|
+
*
|
|
124
|
+
* `cursor` is usually the last url from previous responses.
|
|
125
|
+
* @param {string} url
|
|
126
|
+
* @param {string | undefined} [cursor]
|
|
127
|
+
* @param {boolean | undefined} [reverse]
|
|
128
|
+
* @param {number | undefined} [limit]
|
|
129
|
+
* @returns {Promise<Array<any>>}
|
|
130
|
+
*/
|
|
131
|
+
list(url: string, cursor?: string, reverse?: boolean, limit?: number): Promise<Array<any>>;
|
|
99
132
|
}
|
|
100
133
|
/**
|
|
101
134
|
*/
|
package/pubky_bg.wasm
CHANGED
|
Binary file
|