@reallyme/codec 0.1.9

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.
@@ -0,0 +1,984 @@
1
+ /* @ts-self-types="./reallyme_codec_wasm.d.ts" */
2
+
3
+ /**
4
+ * Decode bytes using the base58btc alphabet without a multibase prefix.
5
+ * @param {string} encoded
6
+ * @returns {Uint8Array}
7
+ */
8
+ export function base58btcDecode(encoded) {
9
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ret = wasm.base58btcDecode(ptr0, len0);
12
+ if (ret[2]) {
13
+ throw takeFromExternrefTable0(ret[1]);
14
+ }
15
+ return takeFromExternrefTable0(ret[0]);
16
+ }
17
+
18
+ /**
19
+ * Encode bytes using the base58btc alphabet without a multibase prefix.
20
+ * @param {Uint8Array} bytes
21
+ * @returns {string}
22
+ */
23
+ export function base58btcEncode(bytes) {
24
+ let deferred2_0;
25
+ let deferred2_1;
26
+ try {
27
+ const ret = wasm.base58btcEncode(bytes);
28
+ var ptr1 = ret[0];
29
+ var len1 = ret[1];
30
+ if (ret[3]) {
31
+ ptr1 = 0; len1 = 0;
32
+ throw takeFromExternrefTable0(ret[2]);
33
+ }
34
+ deferred2_0 = ptr1;
35
+ deferred2_1 = len1;
36
+ return getStringFromWasm0(ptr1, len1);
37
+ } finally {
38
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Decode canonical padded RFC 4648 base64.
44
+ * @param {string} encoded
45
+ * @returns {Uint8Array}
46
+ */
47
+ export function base64Decode(encoded) {
48
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
49
+ const len0 = WASM_VECTOR_LEN;
50
+ const ret = wasm.base64Decode(ptr0, len0);
51
+ if (ret[2]) {
52
+ throw takeFromExternrefTable0(ret[1]);
53
+ }
54
+ return takeFromExternrefTable0(ret[0]);
55
+ }
56
+
57
+ /**
58
+ * Encode bytes using canonical padded RFC 4648 base64.
59
+ * @param {Uint8Array} bytes
60
+ * @returns {string}
61
+ */
62
+ export function base64Encode(bytes) {
63
+ let deferred1_0;
64
+ let deferred1_1;
65
+ try {
66
+ const ret = wasm.base64Encode(bytes);
67
+ deferred1_0 = ret[0];
68
+ deferred1_1 = ret[1];
69
+ return getStringFromWasm0(ret[0], ret[1]);
70
+ } finally {
71
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Decode strict unpadded RFC 4648 URL-safe base64.
77
+ * @param {string} encoded
78
+ * @returns {Uint8Array}
79
+ */
80
+ export function base64urlDecode(encoded) {
81
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
82
+ const len0 = WASM_VECTOR_LEN;
83
+ const ret = wasm.base64urlDecode(ptr0, len0);
84
+ if (ret[2]) {
85
+ throw takeFromExternrefTable0(ret[1]);
86
+ }
87
+ return takeFromExternrefTable0(ret[0]);
88
+ }
89
+
90
+ /**
91
+ * Encode bytes using unpadded RFC 4648 URL-safe base64.
92
+ * @param {Uint8Array} bytes
93
+ * @returns {string}
94
+ */
95
+ export function base64urlEncode(bytes) {
96
+ let deferred1_0;
97
+ let deferred1_1;
98
+ try {
99
+ const ret = wasm.base64urlEncode(bytes);
100
+ deferred1_0 = ret[0];
101
+ deferred1_1 = ret[1];
102
+ return getStringFromWasm0(ret[0], ret[1]);
103
+ } finally {
104
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Return whether a multikey binding type is compatible with a codec name.
110
+ * @param {string} binding_type
111
+ * @param {string} codec_name
112
+ * @returns {boolean}
113
+ */
114
+ export function bindingTypeMatchesCodec(binding_type, codec_name) {
115
+ const ptr0 = passStringToWasm0(binding_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
116
+ const len0 = WASM_VECTOR_LEN;
117
+ const ptr1 = passStringToWasm0(codec_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
118
+ const len1 = WASM_VECTOR_LEN;
119
+ const ret = wasm.bindingTypeMatchesCodec(ptr0, len0, ptr1, len1);
120
+ return ret !== 0;
121
+ }
122
+
123
+ /**
124
+ * Encode bytes as canonical lowercase hexadecimal.
125
+ * @param {Uint8Array} bytes
126
+ * @returns {string}
127
+ */
128
+ export function bytesToLowerHex(bytes) {
129
+ let deferred1_0;
130
+ let deferred1_1;
131
+ try {
132
+ const ret = wasm.bytesToLowerHex(bytes);
133
+ deferred1_0 = ret[0];
134
+ deferred1_1 = ret[1];
135
+ return getStringFromWasm0(ret[0], ret[1]);
136
+ } finally {
137
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Canonicalize a JSON value using RFC 8785 JCS.
143
+ * @param {string} value_json
144
+ * @returns {string}
145
+ */
146
+ export function canonicalizeJson(value_json) {
147
+ let deferred3_0;
148
+ let deferred3_1;
149
+ try {
150
+ const ptr0 = passStringToWasm0(value_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
151
+ const len0 = WASM_VECTOR_LEN;
152
+ const ret = wasm.canonicalizeJson(ptr0, len0);
153
+ var ptr2 = ret[0];
154
+ var len2 = ret[1];
155
+ if (ret[3]) {
156
+ ptr2 = 0; len2 = 0;
157
+ throw takeFromExternrefTable0(ret[2]);
158
+ }
159
+ deferred3_0 = ptr2;
160
+ deferred3_1 = len2;
161
+ return getStringFromWasm0(ptr2, len2);
162
+ } finally {
163
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Return the DAG-CBOR multicodec code.
169
+ * @returns {number}
170
+ */
171
+ export function dagCborCodecCode() {
172
+ const ret = wasm.dagCborCodecCode();
173
+ return ret >>> 0;
174
+ }
175
+
176
+ /**
177
+ * Compute a CIDv1 dag-cbor/sha2-256 string for already-canonical DAG-CBOR bytes.
178
+ * @param {Uint8Array} bytes
179
+ * @returns {string}
180
+ */
181
+ export function dagCborComputeCid(bytes) {
182
+ let deferred2_0;
183
+ let deferred2_1;
184
+ try {
185
+ const ret = wasm.dagCborComputeCid(bytes);
186
+ var ptr1 = ret[0];
187
+ var len1 = ret[1];
188
+ if (ret[3]) {
189
+ ptr1 = 0; len1 = 0;
190
+ throw takeFromExternrefTable0(ret[2]);
191
+ }
192
+ deferred2_0 = ptr1;
193
+ deferred2_1 = len1;
194
+ return getStringFromWasm0(ptr1, len1);
195
+ } finally {
196
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Decode canonical DAG-CBOR bytes into the tagged JSON representation.
202
+ * @param {Uint8Array} bytes
203
+ * @returns {string}
204
+ */
205
+ export function dagCborDecode(bytes) {
206
+ let deferred2_0;
207
+ let deferred2_1;
208
+ try {
209
+ const ret = wasm.dagCborDecode(bytes);
210
+ var ptr1 = ret[0];
211
+ var len1 = ret[1];
212
+ if (ret[3]) {
213
+ ptr1 = 0; len1 = 0;
214
+ throw takeFromExternrefTable0(ret[2]);
215
+ }
216
+ deferred2_0 = ptr1;
217
+ deferred2_1 = len1;
218
+ return getStringFromWasm0(ptr1, len1);
219
+ } finally {
220
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Encode a tagged JSON representation as canonical DAG-CBOR bytes.
226
+ * @param {string} value_json
227
+ * @returns {Uint8Array}
228
+ */
229
+ export function dagCborEncode(value_json) {
230
+ const ptr0 = passStringToWasm0(value_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len0 = WASM_VECTOR_LEN;
232
+ const ret = wasm.dagCborEncode(ptr0, len0);
233
+ if (ret[2]) {
234
+ throw takeFromExternrefTable0(ret[1]);
235
+ }
236
+ return takeFromExternrefTable0(ret[0]);
237
+ }
238
+
239
+ /**
240
+ * Return the sha2-256 multihash envelope for canonical DAG-CBOR bytes.
241
+ * @param {Uint8Array} bytes
242
+ * @returns {Uint8Array}
243
+ */
244
+ export function dagCborMultihash(bytes) {
245
+ const ret = wasm.dagCborMultihash(bytes);
246
+ if (ret[2]) {
247
+ throw takeFromExternrefTable0(ret[1]);
248
+ }
249
+ return takeFromExternrefTable0(ret[0]);
250
+ }
251
+
252
+ /**
253
+ * Return the raw sha2-256 content hash for canonical DAG-CBOR bytes.
254
+ * @param {Uint8Array} bytes
255
+ * @returns {Uint8Array}
256
+ */
257
+ export function dagCborSha256ContentHash(bytes) {
258
+ const ret = wasm.dagCborSha256ContentHash(bytes);
259
+ if (ret[2]) {
260
+ throw takeFromExternrefTable0(ret[1]);
261
+ }
262
+ return takeFromExternrefTable0(ret[0]);
263
+ }
264
+
265
+ /**
266
+ * Recompute and compare a CIDv1 dag-cbor/sha2-256 string.
267
+ * @param {string} cid
268
+ * @param {Uint8Array} bytes
269
+ * @returns {any}
270
+ */
271
+ export function dagCborVerifyCid(cid, bytes) {
272
+ const ptr0 = passStringToWasm0(cid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
273
+ const len0 = WASM_VECTOR_LEN;
274
+ const ret = wasm.dagCborVerifyCid(ptr0, len0, bytes);
275
+ if (ret[2]) {
276
+ throw takeFromExternrefTable0(ret[1]);
277
+ }
278
+ return takeFromExternrefTable0(ret[0]);
279
+ }
280
+
281
+ /**
282
+ * Recompute and compare a CID as a `CodecDagCborVerifyCidResult` protobuf message.
283
+ * @param {string} cid
284
+ * @param {Uint8Array} bytes
285
+ * @returns {Uint8Array}
286
+ */
287
+ export function dagCborVerifyCidProto(cid, bytes) {
288
+ const ptr0 = passStringToWasm0(cid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
289
+ const len0 = WASM_VECTOR_LEN;
290
+ const ret = wasm.dagCborVerifyCidProto(ptr0, len0, bytes);
291
+ if (ret[2]) {
292
+ throw takeFromExternrefTable0(ret[1]);
293
+ }
294
+ return takeFromExternrefTable0(ret[0]);
295
+ }
296
+
297
+ /**
298
+ * Recompute and compare a CID protobuf message with an explicit result status.
299
+ * @param {string} cid
300
+ * @param {Uint8Array} bytes
301
+ * @returns {any}
302
+ */
303
+ export function dagCborVerifyCidProtoResult(cid, bytes) {
304
+ const ptr0 = passStringToWasm0(cid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
305
+ const len0 = WASM_VECTOR_LEN;
306
+ const ret = wasm.dagCborVerifyCidProtoResult(ptr0, len0, bytes);
307
+ if (ret[2]) {
308
+ throw takeFromExternrefTable0(ret[1]);
309
+ }
310
+ return takeFromExternrefTable0(ret[0]);
311
+ }
312
+
313
+ /**
314
+ * Return whether a string parses as a CID.
315
+ * @param {string} cid
316
+ * @returns {boolean}
317
+ */
318
+ export function isValidCidString(cid) {
319
+ const ptr0 = passStringToWasm0(cid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
320
+ const len0 = WASM_VECTOR_LEN;
321
+ const ret = wasm.isValidCidString(ptr0, len0);
322
+ return ret !== 0;
323
+ }
324
+
325
+ /**
326
+ * Decode canonical lowercase hexadecimal.
327
+ * @param {string} encoded
328
+ * @returns {Uint8Array}
329
+ */
330
+ export function lowerHexToBytes(encoded) {
331
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
332
+ const len0 = WASM_VECTOR_LEN;
333
+ const ret = wasm.lowerHexToBytes(ptr0, len0);
334
+ if (ret[2]) {
335
+ throw takeFromExternrefTable0(ret[1]);
336
+ }
337
+ return takeFromExternrefTable0(ret[0]);
338
+ }
339
+
340
+ /**
341
+ * Encode bytes with the multibase base58btc prefix.
342
+ * @param {Uint8Array} bytes
343
+ * @returns {string}
344
+ */
345
+ export function multibaseBase58btcEncode(bytes) {
346
+ let deferred2_0;
347
+ let deferred2_1;
348
+ try {
349
+ const ret = wasm.multibaseBase58btcEncode(bytes);
350
+ var ptr1 = ret[0];
351
+ var len1 = ret[1];
352
+ if (ret[3]) {
353
+ ptr1 = 0; len1 = 0;
354
+ throw takeFromExternrefTable0(ret[2]);
355
+ }
356
+ deferred2_0 = ptr1;
357
+ deferred2_1 = len1;
358
+ return getStringFromWasm0(ptr1, len1);
359
+ } finally {
360
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Encode bytes with the multibase base64url prefix.
366
+ * @param {Uint8Array} bytes
367
+ * @returns {string}
368
+ */
369
+ export function multibaseBase64urlEncode(bytes) {
370
+ let deferred1_0;
371
+ let deferred1_1;
372
+ try {
373
+ const ret = wasm.multibaseBase64urlEncode(bytes);
374
+ deferred1_0 = ret[0];
375
+ deferred1_1 = ret[1];
376
+ return getStringFromWasm0(ret[0], ret[1]);
377
+ } finally {
378
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Decode a supported multibase string.
384
+ * @param {string} encoded
385
+ * @returns {Uint8Array}
386
+ */
387
+ export function multibaseDecode(encoded) {
388
+ const ptr0 = passStringToWasm0(encoded, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
389
+ const len0 = WASM_VECTOR_LEN;
390
+ const ret = wasm.multibaseDecode(ptr0, len0);
391
+ if (ret[2]) {
392
+ throw takeFromExternrefTable0(ret[1]);
393
+ }
394
+ return takeFromExternrefTable0(ret[0]);
395
+ }
396
+
397
+ /**
398
+ * Resolve a byte slice that starts with a known multicodec prefix.
399
+ * @param {Uint8Array} bytes
400
+ * @returns {any}
401
+ */
402
+ export function multicodecLookupPrefix(bytes) {
403
+ const ret = wasm.multicodecLookupPrefix(bytes);
404
+ if (ret[2]) {
405
+ throw takeFromExternrefTable0(ret[1]);
406
+ }
407
+ return takeFromExternrefTable0(ret[0]);
408
+ }
409
+
410
+ /**
411
+ * Resolve a prefix as a `CodecMulticodecLookupResult` protobuf message.
412
+ * @param {Uint8Array} bytes
413
+ * @returns {Uint8Array}
414
+ */
415
+ export function multicodecLookupPrefixProto(bytes) {
416
+ const ret = wasm.multicodecLookupPrefixProto(bytes);
417
+ if (ret[2]) {
418
+ throw takeFromExternrefTable0(ret[1]);
419
+ }
420
+ return takeFromExternrefTable0(ret[0]);
421
+ }
422
+
423
+ /**
424
+ * Resolve a prefix protobuf message with an explicit result status.
425
+ * @param {Uint8Array} bytes
426
+ * @returns {any}
427
+ */
428
+ export function multicodecLookupPrefixProtoResult(bytes) {
429
+ const ret = wasm.multicodecLookupPrefixProtoResult(bytes);
430
+ if (ret[2]) {
431
+ throw takeFromExternrefTable0(ret[1]);
432
+ }
433
+ return takeFromExternrefTable0(ret[0]);
434
+ }
435
+
436
+ /**
437
+ * Return multicodec metadata for a canonical codec name.
438
+ * @param {string} codec_name
439
+ * @returns {any}
440
+ */
441
+ export function multicodecPrefixForName(codec_name) {
442
+ const ptr0 = passStringToWasm0(codec_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
443
+ const len0 = WASM_VECTOR_LEN;
444
+ const ret = wasm.multicodecPrefixForName(ptr0, len0);
445
+ if (ret[2]) {
446
+ throw takeFromExternrefTable0(ret[1]);
447
+ }
448
+ return takeFromExternrefTable0(ret[0]);
449
+ }
450
+
451
+ /**
452
+ * Return multicodec metadata as a `CodecMulticodecSpec` protobuf message.
453
+ * @param {string} codec_name
454
+ * @returns {Uint8Array}
455
+ */
456
+ export function multicodecPrefixForNameProto(codec_name) {
457
+ const ptr0 = passStringToWasm0(codec_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
458
+ const len0 = WASM_VECTOR_LEN;
459
+ const ret = wasm.multicodecPrefixForNameProto(ptr0, len0);
460
+ if (ret[2]) {
461
+ throw takeFromExternrefTable0(ret[1]);
462
+ }
463
+ return takeFromExternrefTable0(ret[0]);
464
+ }
465
+
466
+ /**
467
+ * Return multicodec metadata protobuf bytes with an explicit result status.
468
+ * @param {string} codec_name
469
+ * @returns {any}
470
+ */
471
+ export function multicodecPrefixForNameProtoResult(codec_name) {
472
+ const ptr0 = passStringToWasm0(codec_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
473
+ const len0 = WASM_VECTOR_LEN;
474
+ const ret = wasm.multicodecPrefixForNameProtoResult(ptr0, len0);
475
+ if (ret[2]) {
476
+ throw takeFromExternrefTable0(ret[1]);
477
+ }
478
+ return takeFromExternrefTable0(ret[0]);
479
+ }
480
+
481
+ /**
482
+ * Strip a known multicodec prefix, or return the original bytes when none is found.
483
+ * @param {Uint8Array} bytes
484
+ * @returns {Uint8Array}
485
+ */
486
+ export function multicodecStripPrefix(bytes) {
487
+ const ret = wasm.multicodecStripPrefix(bytes);
488
+ return ret;
489
+ }
490
+
491
+ /**
492
+ * Return the supported multicodec table.
493
+ * @returns {any}
494
+ */
495
+ export function multicodecTable() {
496
+ const ret = wasm.multicodecTable();
497
+ if (ret[2]) {
498
+ throw takeFromExternrefTable0(ret[1]);
499
+ }
500
+ return takeFromExternrefTable0(ret[0]);
501
+ }
502
+
503
+ /**
504
+ * Return the supported multicodec table as protobuf bytes.
505
+ * @returns {Uint8Array}
506
+ */
507
+ export function multicodecTableProto() {
508
+ const ret = wasm.multicodecTableProto();
509
+ if (ret[2]) {
510
+ throw takeFromExternrefTable0(ret[1]);
511
+ }
512
+ return takeFromExternrefTable0(ret[0]);
513
+ }
514
+
515
+ /**
516
+ * Return the supported multicodec table protobuf bytes with an explicit result status.
517
+ * @returns {any}
518
+ */
519
+ export function multicodecTableProtoResult() {
520
+ const ret = wasm.multicodecTableProtoResult();
521
+ if (ret[2]) {
522
+ throw takeFromExternrefTable0(ret[1]);
523
+ }
524
+ return takeFromExternrefTable0(ret[0]);
525
+ }
526
+
527
+ /**
528
+ * Encode a public key as a multibase base58btc multikey.
529
+ * @param {string} codec_name
530
+ * @param {Uint8Array} public_key
531
+ * @returns {string}
532
+ */
533
+ export function multikeyEncode(codec_name, public_key) {
534
+ let deferred3_0;
535
+ let deferred3_1;
536
+ try {
537
+ const ptr0 = passStringToWasm0(codec_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
538
+ const len0 = WASM_VECTOR_LEN;
539
+ const ret = wasm.multikeyEncode(ptr0, len0, public_key);
540
+ var ptr2 = ret[0];
541
+ var len2 = ret[1];
542
+ if (ret[3]) {
543
+ ptr2 = 0; len2 = 0;
544
+ throw takeFromExternrefTable0(ret[2]);
545
+ }
546
+ deferred3_0 = ptr2;
547
+ deferred3_1 = len2;
548
+ return getStringFromWasm0(ptr2, len2);
549
+ } finally {
550
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
551
+ }
552
+ }
553
+
554
+ /**
555
+ * Parse and validate a multikey string.
556
+ * @param {string} multikey
557
+ * @returns {any}
558
+ */
559
+ export function multikeyParse(multikey) {
560
+ const ptr0 = passStringToWasm0(multikey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
561
+ const len0 = WASM_VECTOR_LEN;
562
+ const ret = wasm.multikeyParse(ptr0, len0);
563
+ if (ret[2]) {
564
+ throw takeFromExternrefTable0(ret[1]);
565
+ }
566
+ return takeFromExternrefTable0(ret[0]);
567
+ }
568
+
569
+ /**
570
+ * Parse and validate a multikey as a `CodecMultikeyParseResult` protobuf message.
571
+ * @param {string} multikey
572
+ * @returns {Uint8Array}
573
+ */
574
+ export function multikeyParseProto(multikey) {
575
+ const ptr0 = passStringToWasm0(multikey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
576
+ const len0 = WASM_VECTOR_LEN;
577
+ const ret = wasm.multikeyParseProto(ptr0, len0);
578
+ if (ret[2]) {
579
+ throw takeFromExternrefTable0(ret[1]);
580
+ }
581
+ return takeFromExternrefTable0(ret[0]);
582
+ }
583
+
584
+ /**
585
+ * Parse and validate a multikey protobuf message with an explicit result status.
586
+ * @param {string} multikey
587
+ * @returns {any}
588
+ */
589
+ export function multikeyParseProtoResult(multikey) {
590
+ const ptr0 = passStringToWasm0(multikey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
591
+ const len0 = WASM_VECTOR_LEN;
592
+ const ret = wasm.multikeyParseProtoResult(ptr0, len0);
593
+ if (ret[2]) {
594
+ throw takeFromExternrefTable0(ret[1]);
595
+ }
596
+ return takeFromExternrefTable0(ret[0]);
597
+ }
598
+
599
+ /**
600
+ * Decode PEM text armor with caller-supplied size and label policy.
601
+ * @param {string} input
602
+ * @param {string} options_json
603
+ * @returns {any}
604
+ */
605
+ export function pemDecode(input, options_json) {
606
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
607
+ const len0 = WASM_VECTOR_LEN;
608
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
609
+ const len1 = WASM_VECTOR_LEN;
610
+ const ret = wasm.pemDecode(ptr0, len0, ptr1, len1);
611
+ if (ret[2]) {
612
+ throw takeFromExternrefTable0(ret[1]);
613
+ }
614
+ return takeFromExternrefTable0(ret[0]);
615
+ }
616
+
617
+ /**
618
+ * Decode PEM text armor as a `CodecPemDecodeResult` protobuf message.
619
+ * @param {string} input
620
+ * @param {string} options_json
621
+ * @returns {Uint8Array}
622
+ */
623
+ export function pemDecodeProto(input, options_json) {
624
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
625
+ const len0 = WASM_VECTOR_LEN;
626
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
627
+ const len1 = WASM_VECTOR_LEN;
628
+ const ret = wasm.pemDecodeProto(ptr0, len0, ptr1, len1);
629
+ if (ret[2]) {
630
+ throw takeFromExternrefTable0(ret[1]);
631
+ }
632
+ return takeFromExternrefTable0(ret[0]);
633
+ }
634
+
635
+ /**
636
+ * Decode PEM text armor protobuf bytes with an explicit result status.
637
+ * @param {string} input
638
+ * @param {string} options_json
639
+ * @returns {any}
640
+ */
641
+ export function pemDecodeProtoResult(input, options_json) {
642
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
643
+ const len0 = WASM_VECTOR_LEN;
644
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
645
+ const len1 = WASM_VECTOR_LEN;
646
+ const ret = wasm.pemDecodeProtoResult(ptr0, len0, ptr1, len1);
647
+ if (ret[2]) {
648
+ throw takeFromExternrefTable0(ret[1]);
649
+ }
650
+ return takeFromExternrefTable0(ret[0]);
651
+ }
652
+
653
+ /**
654
+ * Encode DER bytes as PEM text armor.
655
+ * @param {string} label
656
+ * @param {Uint8Array} der
657
+ * @param {string} options_json
658
+ * @returns {string}
659
+ */
660
+ export function pemEncode(label, der, options_json) {
661
+ let deferred4_0;
662
+ let deferred4_1;
663
+ try {
664
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
665
+ const len0 = WASM_VECTOR_LEN;
666
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
667
+ const len1 = WASM_VECTOR_LEN;
668
+ const ret = wasm.pemEncode(ptr0, len0, der, ptr1, len1);
669
+ var ptr3 = ret[0];
670
+ var len3 = ret[1];
671
+ if (ret[3]) {
672
+ ptr3 = 0; len3 = 0;
673
+ throw takeFromExternrefTable0(ret[2]);
674
+ }
675
+ deferred4_0 = ptr3;
676
+ deferred4_1 = len3;
677
+ return getStringFromWasm0(ptr3, len3);
678
+ } finally {
679
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
680
+ }
681
+ }
682
+
683
+ /**
684
+ * Fail closed when a codec name is not in the supported table.
685
+ * @param {string} codec_name
686
+ */
687
+ export function requireSupportedMulticodec(codec_name) {
688
+ const ptr0 = passStringToWasm0(codec_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
689
+ const len0 = WASM_VECTOR_LEN;
690
+ const ret = wasm.requireSupportedMulticodec(ptr0, len0);
691
+ if (ret[1]) {
692
+ throw takeFromExternrefTable0(ret[0]);
693
+ }
694
+ }
695
+
696
+ /**
697
+ * Return the canonical CID string, or `undefined` when parsing fails.
698
+ * @param {string} cid
699
+ * @returns {any}
700
+ */
701
+ export function tryParseCid(cid) {
702
+ const ptr0 = passStringToWasm0(cid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
703
+ const len0 = WASM_VECTOR_LEN;
704
+ const ret = wasm.tryParseCid(ptr0, len0);
705
+ return ret;
706
+ }
707
+
708
+ /**
709
+ * Validate a binding type and optional algorithm against a parsed multikey.
710
+ * @param {string} binding_type
711
+ * @param {string | null | undefined} algorithm
712
+ * @param {string} multikey
713
+ */
714
+ export function validateKeyBinding(binding_type, algorithm, multikey) {
715
+ const ptr0 = passStringToWasm0(binding_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
716
+ const len0 = WASM_VECTOR_LEN;
717
+ var ptr1 = isLikeNone(algorithm) ? 0 : passStringToWasm0(algorithm, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
718
+ var len1 = WASM_VECTOR_LEN;
719
+ const ptr2 = passStringToWasm0(multikey, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
720
+ const len2 = WASM_VECTOR_LEN;
721
+ const ret = wasm.validateKeyBinding(ptr0, len0, ptr1, len1, ptr2, len2);
722
+ if (ret[1]) {
723
+ throw takeFromExternrefTable0(ret[0]);
724
+ }
725
+ }
726
+ function __wbg_get_imports() {
727
+ const import0 = {
728
+ __proto__: null,
729
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
730
+ throw new Error(getStringFromWasm0(arg0, arg1));
731
+ },
732
+ __wbg_length_1f0964f4a5e2c6d8: function(arg0) {
733
+ const ret = arg0.length;
734
+ return ret;
735
+ },
736
+ __wbg_new_32b398fb48b6d94a: function() {
737
+ const ret = new Array();
738
+ return ret;
739
+ },
740
+ __wbg_new_da52cf8fe3429cb2: function() {
741
+ const ret = new Object();
742
+ return ret;
743
+ },
744
+ __wbg_new_from_slice_77cdfb7977362f3c: function(arg0, arg1) {
745
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
746
+ return ret;
747
+ },
748
+ __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
749
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
750
+ },
751
+ __wbg_push_d2ae3af0c1217ae6: function(arg0, arg1) {
752
+ const ret = arg0.push(arg1);
753
+ return ret;
754
+ },
755
+ __wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
756
+ const ret = Reflect.set(arg0, arg1, arg2);
757
+ return ret;
758
+ }, arguments); },
759
+ __wbindgen_cast_0000000000000001: function(arg0) {
760
+ // Cast intrinsic for `F64 -> Externref`.
761
+ const ret = arg0;
762
+ return ret;
763
+ },
764
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
765
+ // Cast intrinsic for `Ref(String) -> Externref`.
766
+ const ret = getStringFromWasm0(arg0, arg1);
767
+ return ret;
768
+ },
769
+ __wbindgen_init_externref_table: function() {
770
+ const table = wasm.__wbindgen_externrefs;
771
+ const offset = table.grow(4);
772
+ table.set(0, undefined);
773
+ table.set(offset + 0, undefined);
774
+ table.set(offset + 1, null);
775
+ table.set(offset + 2, true);
776
+ table.set(offset + 3, false);
777
+ },
778
+ };
779
+ return {
780
+ __proto__: null,
781
+ "./reallyme_codec_wasm_bg.js": import0,
782
+ };
783
+ }
784
+
785
+ function addToExternrefTable0(obj) {
786
+ const idx = wasm.__externref_table_alloc();
787
+ wasm.__wbindgen_externrefs.set(idx, obj);
788
+ return idx;
789
+ }
790
+
791
+ function getArrayU8FromWasm0(ptr, len) {
792
+ ptr = ptr >>> 0;
793
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
794
+ }
795
+
796
+ function getStringFromWasm0(ptr, len) {
797
+ return decodeText(ptr >>> 0, len);
798
+ }
799
+
800
+ let cachedUint8ArrayMemory0 = null;
801
+ function getUint8ArrayMemory0() {
802
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
803
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
804
+ }
805
+ return cachedUint8ArrayMemory0;
806
+ }
807
+
808
+ function handleError(f, args) {
809
+ try {
810
+ return f.apply(this, args);
811
+ } catch (e) {
812
+ const idx = addToExternrefTable0(e);
813
+ wasm.__wbindgen_exn_store(idx);
814
+ }
815
+ }
816
+
817
+ function isLikeNone(x) {
818
+ return x === undefined || x === null;
819
+ }
820
+
821
+ function passStringToWasm0(arg, malloc, realloc) {
822
+ if (realloc === undefined) {
823
+ const buf = cachedTextEncoder.encode(arg);
824
+ const ptr = malloc(buf.length, 1) >>> 0;
825
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
826
+ WASM_VECTOR_LEN = buf.length;
827
+ return ptr;
828
+ }
829
+
830
+ let len = arg.length;
831
+ let ptr = malloc(len, 1) >>> 0;
832
+
833
+ const mem = getUint8ArrayMemory0();
834
+
835
+ let offset = 0;
836
+
837
+ for (; offset < len; offset++) {
838
+ const code = arg.charCodeAt(offset);
839
+ if (code > 0x7F) break;
840
+ mem[ptr + offset] = code;
841
+ }
842
+ if (offset !== len) {
843
+ if (offset !== 0) {
844
+ arg = arg.slice(offset);
845
+ }
846
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
847
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
848
+ const ret = cachedTextEncoder.encodeInto(arg, view);
849
+
850
+ offset += ret.written;
851
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
852
+ }
853
+
854
+ WASM_VECTOR_LEN = offset;
855
+ return ptr;
856
+ }
857
+
858
+ function takeFromExternrefTable0(idx) {
859
+ const value = wasm.__wbindgen_externrefs.get(idx);
860
+ wasm.__externref_table_dealloc(idx);
861
+ return value;
862
+ }
863
+
864
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
865
+ cachedTextDecoder.decode();
866
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
867
+ let numBytesDecoded = 0;
868
+ function decodeText(ptr, len) {
869
+ numBytesDecoded += len;
870
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
871
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
872
+ cachedTextDecoder.decode();
873
+ numBytesDecoded = len;
874
+ }
875
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
876
+ }
877
+
878
+ const cachedTextEncoder = new TextEncoder();
879
+
880
+ if (!('encodeInto' in cachedTextEncoder)) {
881
+ cachedTextEncoder.encodeInto = function (arg, view) {
882
+ const buf = cachedTextEncoder.encode(arg);
883
+ view.set(buf);
884
+ return {
885
+ read: arg.length,
886
+ written: buf.length
887
+ };
888
+ };
889
+ }
890
+
891
+ let WASM_VECTOR_LEN = 0;
892
+
893
+ let wasmModule, wasmInstance, wasm;
894
+ function __wbg_finalize_init(instance, module) {
895
+ wasmInstance = instance;
896
+ wasm = instance.exports;
897
+ wasmModule = module;
898
+ cachedUint8ArrayMemory0 = null;
899
+ wasm.__wbindgen_start();
900
+ return wasm;
901
+ }
902
+
903
+ async function __wbg_load(module, imports) {
904
+ if (typeof Response === 'function' && module instanceof Response) {
905
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
906
+ try {
907
+ return await WebAssembly.instantiateStreaming(module, imports);
908
+ } catch (e) {
909
+ const validResponse = module.ok && expectedResponseType(module.type);
910
+
911
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
912
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
913
+
914
+ } else { throw e; }
915
+ }
916
+ }
917
+
918
+ const bytes = await module.arrayBuffer();
919
+ return await WebAssembly.instantiate(bytes, imports);
920
+ } else {
921
+ const instance = await WebAssembly.instantiate(module, imports);
922
+
923
+ if (instance instanceof WebAssembly.Instance) {
924
+ return { instance, module };
925
+ } else {
926
+ return instance;
927
+ }
928
+ }
929
+
930
+ function expectedResponseType(type) {
931
+ switch (type) {
932
+ case 'basic': case 'cors': case 'default': return true;
933
+ }
934
+ return false;
935
+ }
936
+ }
937
+
938
+ function initSync(module) {
939
+ if (wasm !== undefined) return wasm;
940
+
941
+
942
+ if (module !== undefined) {
943
+ if (Object.getPrototypeOf(module) === Object.prototype) {
944
+ ({module} = module)
945
+ } else {
946
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
947
+ }
948
+ }
949
+
950
+ const imports = __wbg_get_imports();
951
+ if (!(module instanceof WebAssembly.Module)) {
952
+ module = new WebAssembly.Module(module);
953
+ }
954
+ const instance = new WebAssembly.Instance(module, imports);
955
+ return __wbg_finalize_init(instance, module);
956
+ }
957
+
958
+ async function __wbg_init(module_or_path) {
959
+ if (wasm !== undefined) return wasm;
960
+
961
+
962
+ if (module_or_path !== undefined) {
963
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
964
+ ({module_or_path} = module_or_path)
965
+ } else {
966
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
967
+ }
968
+ }
969
+
970
+ if (module_or_path === undefined) {
971
+ module_or_path = new URL('reallyme_codec_wasm_bg.wasm', import.meta.url);
972
+ }
973
+ const imports = __wbg_get_imports();
974
+
975
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
976
+ module_or_path = fetch(module_or_path);
977
+ }
978
+
979
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
980
+
981
+ return __wbg_finalize_init(instance, module);
982
+ }
983
+
984
+ export { initSync, __wbg_init as default };