@reallyme/codec 0.2.3 → 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/NOTICE +0 -2
- package/README.md +16 -8
- package/dist/baseEncoding.js +5 -8
- package/dist/boundary.js +1 -1
- package/dist/cbor.d.ts +5 -1
- package/dist/cbor.js +52 -19
- package/dist/deterministicCborBoundary.d.ts +1 -1
- package/dist/deterministicCborBoundary.js +4 -4
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +6 -4
- package/dist/jcs.js +1 -1
- package/dist/multiformat.js +16 -16
- package/dist/operationContract.d.ts +2 -3
- package/dist/operationContract.js +57 -19
- package/dist/pem.js +4 -1
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.d.ts +48 -3
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.js +46 -2
- package/dist/proto.js +1 -1
- package/dist/readOutput.d.ts +4 -0
- package/dist/readOutput.js +20 -1
- package/dist/wasm/reallyme_codec_wasm.d.ts +12 -12
- package/dist/wasm/reallyme_codec_wasm.js +85 -151
- package/dist/wasm/reallyme_codec_wasm_bg.wasm +0 -0
- package/dist/wasmProvider.js +53 -4
- package/package.json +3 -3
|
@@ -19,22 +19,11 @@ export function base58btcDecode(encoded) {
|
|
|
19
19
|
* @returns {string}
|
|
20
20
|
*/
|
|
21
21
|
export function base58btcEncode(bytes) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const ret = wasm.base58btcEncode(bytes);
|
|
26
|
-
var ptr1 = ret[0];
|
|
27
|
-
var len1 = ret[1];
|
|
28
|
-
if (ret[3]) {
|
|
29
|
-
ptr1 = 0; len1 = 0;
|
|
30
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
31
|
-
}
|
|
32
|
-
deferred2_0 = ptr1;
|
|
33
|
-
deferred2_1 = len1;
|
|
34
|
-
return getStringFromWasm0(ptr1, len1);
|
|
35
|
-
} finally {
|
|
36
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
22
|
+
const ret = wasm.base58btcEncode(bytes);
|
|
23
|
+
if (ret[2]) {
|
|
24
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
37
25
|
}
|
|
26
|
+
return takeFromExternrefTable0(ret[0]);
|
|
38
27
|
}
|
|
39
28
|
|
|
40
29
|
/**
|
|
@@ -56,22 +45,11 @@ export function base64Decode(encoded) {
|
|
|
56
45
|
* @returns {string}
|
|
57
46
|
*/
|
|
58
47
|
export function base64Encode(bytes) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const ret = wasm.base64Encode(bytes);
|
|
63
|
-
var ptr1 = ret[0];
|
|
64
|
-
var len1 = ret[1];
|
|
65
|
-
if (ret[3]) {
|
|
66
|
-
ptr1 = 0; len1 = 0;
|
|
67
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
68
|
-
}
|
|
69
|
-
deferred2_0 = ptr1;
|
|
70
|
-
deferred2_1 = len1;
|
|
71
|
-
return getStringFromWasm0(ptr1, len1);
|
|
72
|
-
} finally {
|
|
73
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
48
|
+
const ret = wasm.base64Encode(bytes);
|
|
49
|
+
if (ret[2]) {
|
|
50
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
74
51
|
}
|
|
52
|
+
return takeFromExternrefTable0(ret[0]);
|
|
75
53
|
}
|
|
76
54
|
|
|
77
55
|
/**
|
|
@@ -93,22 +71,11 @@ export function base64urlDecode(encoded) {
|
|
|
93
71
|
* @returns {string}
|
|
94
72
|
*/
|
|
95
73
|
export function base64urlEncode(bytes) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const ret = wasm.base64urlEncode(bytes);
|
|
100
|
-
var ptr1 = ret[0];
|
|
101
|
-
var len1 = ret[1];
|
|
102
|
-
if (ret[3]) {
|
|
103
|
-
ptr1 = 0; len1 = 0;
|
|
104
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
105
|
-
}
|
|
106
|
-
deferred2_0 = ptr1;
|
|
107
|
-
deferred2_1 = len1;
|
|
108
|
-
return getStringFromWasm0(ptr1, len1);
|
|
109
|
-
} finally {
|
|
110
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
74
|
+
const ret = wasm.base64urlEncode(bytes);
|
|
75
|
+
if (ret[2]) {
|
|
76
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
111
77
|
}
|
|
78
|
+
return takeFromExternrefTable0(ret[0]);
|
|
112
79
|
}
|
|
113
80
|
|
|
114
81
|
/**
|
|
@@ -131,22 +98,11 @@ export function bindingTypeMatchesCodec(binding_type, codec_name) {
|
|
|
131
98
|
* @returns {string}
|
|
132
99
|
*/
|
|
133
100
|
export function bytesToLowerHex(bytes) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const ret = wasm.bytesToLowerHex(bytes);
|
|
138
|
-
var ptr1 = ret[0];
|
|
139
|
-
var len1 = ret[1];
|
|
140
|
-
if (ret[3]) {
|
|
141
|
-
ptr1 = 0; len1 = 0;
|
|
142
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
143
|
-
}
|
|
144
|
-
deferred2_0 = ptr1;
|
|
145
|
-
deferred2_1 = len1;
|
|
146
|
-
return getStringFromWasm0(ptr1, len1);
|
|
147
|
-
} finally {
|
|
148
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
101
|
+
const ret = wasm.bytesToLowerHex(bytes);
|
|
102
|
+
if (ret[2]) {
|
|
103
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
149
104
|
}
|
|
105
|
+
return takeFromExternrefTable0(ret[0]);
|
|
150
106
|
}
|
|
151
107
|
|
|
152
108
|
/**
|
|
@@ -155,22 +111,11 @@ export function bytesToLowerHex(bytes) {
|
|
|
155
111
|
* @returns {string}
|
|
156
112
|
*/
|
|
157
113
|
export function canonicalizeJson(value_json) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const ret = wasm.canonicalizeJson(value_json);
|
|
162
|
-
var ptr1 = ret[0];
|
|
163
|
-
var len1 = ret[1];
|
|
164
|
-
if (ret[3]) {
|
|
165
|
-
ptr1 = 0; len1 = 0;
|
|
166
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
167
|
-
}
|
|
168
|
-
deferred2_0 = ptr1;
|
|
169
|
-
deferred2_1 = len1;
|
|
170
|
-
return getStringFromWasm0(ptr1, len1);
|
|
171
|
-
} finally {
|
|
172
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
114
|
+
const ret = wasm.canonicalizeJson(value_json);
|
|
115
|
+
if (ret[2]) {
|
|
116
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
173
117
|
}
|
|
118
|
+
return takeFromExternrefTable0(ret[0]);
|
|
174
119
|
}
|
|
175
120
|
|
|
176
121
|
/**
|
|
@@ -188,22 +133,11 @@ export function dagCborCodecCode() {
|
|
|
188
133
|
* @returns {string}
|
|
189
134
|
*/
|
|
190
135
|
export function dagCborComputeCid(bytes) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const ret = wasm.dagCborComputeCid(bytes);
|
|
195
|
-
var ptr1 = ret[0];
|
|
196
|
-
var len1 = ret[1];
|
|
197
|
-
if (ret[3]) {
|
|
198
|
-
ptr1 = 0; len1 = 0;
|
|
199
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
200
|
-
}
|
|
201
|
-
deferred2_0 = ptr1;
|
|
202
|
-
deferred2_1 = len1;
|
|
203
|
-
return getStringFromWasm0(ptr1, len1);
|
|
204
|
-
} finally {
|
|
205
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
136
|
+
const ret = wasm.dagCborComputeCid(bytes);
|
|
137
|
+
if (ret[2]) {
|
|
138
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
206
139
|
}
|
|
140
|
+
return takeFromExternrefTable0(ret[0]);
|
|
207
141
|
}
|
|
208
142
|
|
|
209
143
|
/**
|
|
@@ -264,22 +198,11 @@ export function lowerHexToBytes(encoded) {
|
|
|
264
198
|
* @returns {string}
|
|
265
199
|
*/
|
|
266
200
|
export function multibaseBase58btcEncode(bytes) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const ret = wasm.multibaseBase58btcEncode(bytes);
|
|
271
|
-
var ptr1 = ret[0];
|
|
272
|
-
var len1 = ret[1];
|
|
273
|
-
if (ret[3]) {
|
|
274
|
-
ptr1 = 0; len1 = 0;
|
|
275
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
276
|
-
}
|
|
277
|
-
deferred2_0 = ptr1;
|
|
278
|
-
deferred2_1 = len1;
|
|
279
|
-
return getStringFromWasm0(ptr1, len1);
|
|
280
|
-
} finally {
|
|
281
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
201
|
+
const ret = wasm.multibaseBase58btcEncode(bytes);
|
|
202
|
+
if (ret[2]) {
|
|
203
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
282
204
|
}
|
|
205
|
+
return takeFromExternrefTable0(ret[0]);
|
|
283
206
|
}
|
|
284
207
|
|
|
285
208
|
/**
|
|
@@ -288,22 +211,11 @@ export function multibaseBase58btcEncode(bytes) {
|
|
|
288
211
|
* @returns {string}
|
|
289
212
|
*/
|
|
290
213
|
export function multibaseBase64urlEncode(bytes) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const ret = wasm.multibaseBase64urlEncode(bytes);
|
|
295
|
-
var ptr1 = ret[0];
|
|
296
|
-
var len1 = ret[1];
|
|
297
|
-
if (ret[3]) {
|
|
298
|
-
ptr1 = 0; len1 = 0;
|
|
299
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
300
|
-
}
|
|
301
|
-
deferred2_0 = ptr1;
|
|
302
|
-
deferred2_1 = len1;
|
|
303
|
-
return getStringFromWasm0(ptr1, len1);
|
|
304
|
-
} finally {
|
|
305
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
214
|
+
const ret = wasm.multibaseBase64urlEncode(bytes);
|
|
215
|
+
if (ret[2]) {
|
|
216
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
306
217
|
}
|
|
218
|
+
return takeFromExternrefTable0(ret[0]);
|
|
307
219
|
}
|
|
308
220
|
|
|
309
221
|
/**
|
|
@@ -320,7 +232,7 @@ export function multibaseDecode(encoded) {
|
|
|
320
232
|
}
|
|
321
233
|
|
|
322
234
|
/**
|
|
323
|
-
* Strip a known multicodec prefix, or return
|
|
235
|
+
* Strip a known multicodec prefix, or return a typed error for an unknown prefix.
|
|
324
236
|
* @param {Uint8Array} bytes
|
|
325
237
|
* @returns {Uint8Array}
|
|
326
238
|
*/
|
|
@@ -339,22 +251,11 @@ export function multicodecStripPrefix(bytes) {
|
|
|
339
251
|
* @returns {string}
|
|
340
252
|
*/
|
|
341
253
|
export function multikeyEncode(codec_name, public_key) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const ret = wasm.multikeyEncode(codec_name, public_key);
|
|
346
|
-
var ptr1 = ret[0];
|
|
347
|
-
var len1 = ret[1];
|
|
348
|
-
if (ret[3]) {
|
|
349
|
-
ptr1 = 0; len1 = 0;
|
|
350
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
351
|
-
}
|
|
352
|
-
deferred2_0 = ptr1;
|
|
353
|
-
deferred2_1 = len1;
|
|
354
|
-
return getStringFromWasm0(ptr1, len1);
|
|
355
|
-
} finally {
|
|
356
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
254
|
+
const ret = wasm.multikeyEncode(codec_name, public_key);
|
|
255
|
+
if (ret[2]) {
|
|
256
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
357
257
|
}
|
|
258
|
+
return takeFromExternrefTable0(ret[0]);
|
|
358
259
|
}
|
|
359
260
|
|
|
360
261
|
/**
|
|
@@ -422,7 +323,11 @@ export function validateKeyBinding(binding_type, algorithm, multikey) {
|
|
|
422
323
|
function __wbg_get_imports() {
|
|
423
324
|
const import0 = {
|
|
424
325
|
__proto__: null,
|
|
425
|
-
|
|
326
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
327
|
+
const ret = typeof(arg0) === 'function';
|
|
328
|
+
return ret;
|
|
329
|
+
},
|
|
330
|
+
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
|
|
426
331
|
const obj = arg1;
|
|
427
332
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
428
333
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -430,44 +335,64 @@ function __wbg_get_imports() {
|
|
|
430
335
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
431
336
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
432
337
|
},
|
|
433
|
-
|
|
338
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
434
339
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
435
340
|
},
|
|
436
|
-
|
|
341
|
+
__wbg_call_1875a20c43a36133: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
342
|
+
const ret = arg0.call(arg1, arg2, arg3);
|
|
343
|
+
return ret;
|
|
344
|
+
}, arguments); },
|
|
345
|
+
__wbg_charCodeAt_bbfbcedfafe34880: function(arg0, arg1) {
|
|
437
346
|
const ret = arg0.charCodeAt(arg1 >>> 0);
|
|
438
347
|
return ret;
|
|
439
348
|
},
|
|
440
|
-
|
|
349
|
+
__wbg_fill_775586ed37049ccf: function(arg0, arg1, arg2, arg3) {
|
|
441
350
|
const ret = arg0.fill(arg1, arg2 >>> 0, arg3 >>> 0);
|
|
442
351
|
return ret;
|
|
443
352
|
},
|
|
444
|
-
|
|
353
|
+
__wbg_getPrototypeOf_228a4abae6ef0509: function(arg0) {
|
|
354
|
+
const ret = Object.getPrototypeOf(arg0);
|
|
355
|
+
return ret;
|
|
356
|
+
},
|
|
357
|
+
__wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
|
|
358
|
+
const ret = Reflect.get(arg0, arg1);
|
|
359
|
+
return ret;
|
|
360
|
+
}, arguments); },
|
|
361
|
+
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
|
|
362
|
+
let result;
|
|
363
|
+
try {
|
|
364
|
+
result = arg0 instanceof Uint8Array;
|
|
365
|
+
} catch (_) {
|
|
366
|
+
result = false;
|
|
367
|
+
}
|
|
368
|
+
const ret = result;
|
|
369
|
+
return ret;
|
|
370
|
+
},
|
|
371
|
+
__wbg_length_78dac82682e59660: function(arg0) {
|
|
445
372
|
const ret = arg0.length;
|
|
446
373
|
return ret;
|
|
447
374
|
},
|
|
448
|
-
|
|
375
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
449
376
|
const ret = arg0.length;
|
|
450
377
|
return ret;
|
|
451
378
|
},
|
|
452
|
-
|
|
379
|
+
__wbg_new_from_slice_9a868026ffa4208a: function(arg0, arg1) {
|
|
453
380
|
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
454
381
|
return ret;
|
|
455
382
|
},
|
|
456
|
-
|
|
383
|
+
__wbg_new_with_length_3da0ad195f6f63ba: function(arg0) {
|
|
457
384
|
const ret = new Uint8Array(arg0 >>> 0);
|
|
458
385
|
return ret;
|
|
459
386
|
},
|
|
460
|
-
|
|
387
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
461
388
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
462
389
|
},
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
__wbg_subarray_a4cc58201c7359fd: function(arg0, arg1, arg2) {
|
|
467
|
-
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
390
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
391
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
392
|
+
const ret = arg0;
|
|
468
393
|
return ret;
|
|
469
394
|
},
|
|
470
|
-
|
|
395
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
471
396
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
472
397
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
473
398
|
return ret;
|
|
@@ -519,6 +444,15 @@ function getUint8ArrayMemory0() {
|
|
|
519
444
|
return cachedUint8ArrayMemory0;
|
|
520
445
|
}
|
|
521
446
|
|
|
447
|
+
function handleError(f, args) {
|
|
448
|
+
try {
|
|
449
|
+
return f.apply(this, args);
|
|
450
|
+
} catch (e) {
|
|
451
|
+
const idx = addToExternrefTable0(e);
|
|
452
|
+
wasm.__wbindgen_exn_store(idx);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
522
456
|
function isLikeNone(x) {
|
|
523
457
|
return x === undefined || x === null;
|
|
524
458
|
}
|
|
Binary file
|
package/dist/wasmProvider.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText:
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 ReallyMe LLC
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCodecError } from "./errors.js";
|
|
5
|
+
import * as bundledWasm from "../dist/wasm/reallyme_codec_wasm.js";
|
|
5
6
|
export const REALLYME_CODEC_WASM_EXPORTS = [
|
|
6
7
|
"base64Decode",
|
|
7
8
|
"base64Encode",
|
|
@@ -30,6 +31,8 @@ export const REALLYME_CODEC_WASM_EXPORTS = [
|
|
|
30
31
|
"processOperationJson",
|
|
31
32
|
];
|
|
32
33
|
let installedProvider;
|
|
34
|
+
let providerPoisoned = false;
|
|
35
|
+
const DAG_CBOR_CODEC_CODE = 0x71;
|
|
33
36
|
const wasmErrorCode = (error) => {
|
|
34
37
|
switch (error) {
|
|
35
38
|
case "invalid-input":
|
|
@@ -38,10 +41,21 @@ const wasmErrorCode = (error) => {
|
|
|
38
41
|
return "non-canonical";
|
|
39
42
|
case "unsupported-codec":
|
|
40
43
|
return "unsupported-codec";
|
|
44
|
+
case "unsupported-ipld-value":
|
|
45
|
+
return "unsupported-ipld-value";
|
|
41
46
|
case "provider-failure":
|
|
42
|
-
default:
|
|
43
47
|
return "provider-failure";
|
|
48
|
+
default:
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const isWasmRuntimeError = (error) => {
|
|
53
|
+
const wasm = Reflect.get(globalThis, "WebAssembly");
|
|
54
|
+
if (typeof wasm !== "object" || wasm === null) {
|
|
55
|
+
return false;
|
|
44
56
|
}
|
|
57
|
+
const runtimeError = Reflect.get(wasm, "RuntimeError");
|
|
58
|
+
return typeof runtimeError === "function" && error instanceof runtimeError;
|
|
45
59
|
};
|
|
46
60
|
const requireObject = (module) => {
|
|
47
61
|
if (typeof module !== "object" || module === null) {
|
|
@@ -68,11 +82,23 @@ const requireFunction = (module, name) => {
|
|
|
68
82
|
throw new ReallyMeCodecError("provider-failure");
|
|
69
83
|
}
|
|
70
84
|
return (...args) => {
|
|
85
|
+
if (providerPoisoned) {
|
|
86
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
87
|
+
}
|
|
71
88
|
try {
|
|
72
89
|
return candidate(...args);
|
|
73
90
|
}
|
|
74
91
|
catch (error) {
|
|
75
|
-
|
|
92
|
+
const code = wasmErrorCode(error);
|
|
93
|
+
if (code === undefined) {
|
|
94
|
+
// A WASM trap may leave the instance partially unwound. Host-side
|
|
95
|
+
// errors do not prove that the instance is unusable.
|
|
96
|
+
if (isWasmRuntimeError(error)) {
|
|
97
|
+
providerPoisoned = true;
|
|
98
|
+
}
|
|
99
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
100
|
+
}
|
|
101
|
+
throw new ReallyMeCodecError(code);
|
|
76
102
|
}
|
|
77
103
|
};
|
|
78
104
|
};
|
|
@@ -108,7 +134,30 @@ export const installReallyMeCodecWasmProvider = (module) => {
|
|
|
108
134
|
if (installedProvider !== undefined) {
|
|
109
135
|
throw new ReallyMeCodecError("provider-failure");
|
|
110
136
|
}
|
|
137
|
+
// The generated ES module namespace is immutable. Identity pins the public
|
|
138
|
+
// installer to the Rust build shipped in this package instead of accepting
|
|
139
|
+
// a structurally compatible object supplied by another script.
|
|
140
|
+
if (module !== bundledWasm) {
|
|
141
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
142
|
+
}
|
|
111
143
|
const providerModule = requireObject(module);
|
|
144
|
+
// This zero-argument export accesses the initialized WASM module but does
|
|
145
|
+
// not handle caller data. Reject pre-init installation before making the
|
|
146
|
+
// install-once provider visible; a later initialized attempt can succeed.
|
|
147
|
+
const probe = Object.getOwnPropertyDescriptor(providerModule, "dagCborCodecCode")?.value;
|
|
148
|
+
if (typeof probe !== "function") {
|
|
149
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
150
|
+
}
|
|
151
|
+
let codecCode;
|
|
152
|
+
try {
|
|
153
|
+
codecCode = probe();
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
157
|
+
}
|
|
158
|
+
if (codecCode !== DAG_CBOR_CODEC_CODE) {
|
|
159
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
160
|
+
}
|
|
112
161
|
installedProvider = {
|
|
113
162
|
base64Decode: stringFunction1(providerModule, "base64Decode"),
|
|
114
163
|
base64Encode: bytesFunction1(providerModule, "base64Encode"),
|
|
@@ -138,7 +187,7 @@ export const installReallyMeCodecWasmProvider = (module) => {
|
|
|
138
187
|
};
|
|
139
188
|
};
|
|
140
189
|
export const requireReallyMeCodecWasmProvider = () => {
|
|
141
|
-
if (installedProvider === undefined) {
|
|
190
|
+
if (installedProvider === undefined || providerPoisoned) {
|
|
142
191
|
throw new ReallyMeCodecError("provider-failure");
|
|
143
192
|
}
|
|
144
193
|
return installedProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reallyme/codec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TypeScript facade for the ReallyMe codec WASM package.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"test": "npm run build && node --test \"test/*.test.mjs\""
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@bufbuild/protobuf": "2.
|
|
42
|
+
"@bufbuild/protobuf": "2.16.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"fast-check": "4.
|
|
45
|
+
"fast-check": "4.10.2",
|
|
46
46
|
"typescript": "7.0.2"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|