@reallyme/codec 0.2.2 → 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 +30 -0
- package/NOTICE +1 -5
- package/README.md +31 -11
- package/dist/baseEncoding.js +6 -9
- package/dist/boundary.js +3 -3
- package/dist/cbor.d.ts +5 -1
- package/dist/cbor.js +53 -20
- package/dist/deterministicCborBoundary.d.ts +1 -1
- package/dist/deterministicCborBoundary.js +5 -5
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +2 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -5
- package/dist/jcs.js +2 -2
- package/dist/multiformat.js +17 -17
- package/dist/operationContract.d.ts +2 -3
- package/dist/operationContract.js +58 -20
- package/dist/pem.js +5 -2
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.d.ts +48 -3
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.js +47 -3
- package/dist/proto.js +2 -2
- package/dist/readOutput.d.ts +4 -0
- package/dist/readOutput.js +51 -5
- package/dist/wasm/LICENSE +226 -12
- 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 +54 -5
- package/package.json +4 -4
package/dist/wasmProvider.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText:
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 ReallyMe LLC
|
|
2
2
|
//
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
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,8 +1,8 @@
|
|
|
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
|
-
"license": "Apache-2.0",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./dist/index.js",
|
|
@@ -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": {
|