@reallyme/codec 0.1.20 → 0.1.22
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 +16 -2
- package/dist/boundary.d.ts +11 -0
- package/dist/boundary.js +250 -0
- package/dist/cbor.js +119 -29
- package/dist/index.d.ts +7 -4
- package/dist/index.js +4 -0
- package/dist/jcs.js +3 -60
- package/dist/multiformat.js +57 -14
- package/dist/pem.d.ts +4 -4
- package/dist/pem.js +183 -36
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.d.ts +335 -1
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.js +149 -14
- package/dist/proto.d.ts +2 -2
- package/dist/proto.js +1 -1
- package/dist/protoProcess.d.ts +16 -0
- package/dist/protoProcess.js +282 -0
- package/dist/readOutput.d.ts +1 -1
- package/dist/readOutput.js +84 -21
- package/dist/wasm/reallyme_codec_wasm.d.ts +35 -95
- package/dist/wasm/reallyme_codec_wasm.js +153 -290
- package/dist/wasm/reallyme_codec_wasm_bg.wasm +0 -0
- package/dist/wasmProvider.d.ts +4 -18
- package/dist/wasmProvider.js +18 -25
- package/package.json +1 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
5
|
+
import { MAX_CODEC_PROTO_JSON_BYTES, MAX_CODEC_PROTO_MESSAGE_BYTES, requireBoundaryAggregate, utf8ByteLength, } from "./boundary.js";
|
|
6
|
+
import { ReallyMeCodecError } from "./errors.js";
|
|
7
|
+
import { CodecBoundaryErrorSchema, CodecErrorReason, CodecErrorSchema, CodecOperationRequestSchema, CodecProtoResultEnvelopeSchema, CodecProtoResultStatus, } from "./proto/generated/reallyme/codec/v1/codec_pb.js";
|
|
8
|
+
import { ensureBytesInput, readIndependentBoundedBytesOutput, } from "./readOutput.js";
|
|
9
|
+
import { requireReallyMeCodecWasmProvider } from "./wasmProvider.js";
|
|
10
|
+
const MAX_CODEC_PROTO_RESULT_ENVELOPE_BYTES = 1_048_592;
|
|
11
|
+
const PROTO_REQUEST_OVERHEAD_BUDGET = 64;
|
|
12
|
+
const requireProtoBytes = (value) => {
|
|
13
|
+
if (!(value instanceof Uint8Array)) {
|
|
14
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
15
|
+
}
|
|
16
|
+
return value.length;
|
|
17
|
+
};
|
|
18
|
+
const requireProtoString = (value) => {
|
|
19
|
+
if (typeof value !== "string") {
|
|
20
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
const protoUtf8Length = (value) => {
|
|
25
|
+
const text = requireProtoString(value);
|
|
26
|
+
try {
|
|
27
|
+
return utf8ByteLength(text);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof ReallyMeCodecError) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const validateGeneratedProtoRequest = (request) => {
|
|
37
|
+
const lengths = [PROTO_REQUEST_OVERHEAD_BUDGET];
|
|
38
|
+
switch (request.operation.case) {
|
|
39
|
+
case undefined:
|
|
40
|
+
case "multicodecTable":
|
|
41
|
+
break;
|
|
42
|
+
case "multicodecPrefixForName":
|
|
43
|
+
{
|
|
44
|
+
const length = protoUtf8Length(request.operation.value.name);
|
|
45
|
+
if (length === undefined) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
lengths.push(length);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case "multicodecLookupPrefix":
|
|
52
|
+
lengths.push(requireProtoBytes(request.operation.value.value));
|
|
53
|
+
break;
|
|
54
|
+
case "multikeyParse":
|
|
55
|
+
{
|
|
56
|
+
const length = protoUtf8Length(request.operation.value.multikey);
|
|
57
|
+
if (length === undefined) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
lengths.push(length);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case "dagCborVerifyCid":
|
|
64
|
+
{
|
|
65
|
+
const length = protoUtf8Length(request.operation.value.cid);
|
|
66
|
+
if (length === undefined) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
lengths.push(length);
|
|
70
|
+
}
|
|
71
|
+
lengths.push(requireProtoBytes(request.operation.value.payload));
|
|
72
|
+
break;
|
|
73
|
+
case "pemDecode": {
|
|
74
|
+
lengths.push(requireProtoBytes(request.operation.value.pem));
|
|
75
|
+
const options = request.operation.value.options;
|
|
76
|
+
if (options !== undefined) {
|
|
77
|
+
if (!Array.isArray(options.allowedLabels)) {
|
|
78
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
79
|
+
}
|
|
80
|
+
if (options.allowedLabels.length > MAX_CODEC_PROTO_MESSAGE_BYTES / 5) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
lengths.push(options.allowedLabels.length * 5);
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
requireBoundaryAggregate(lengths, MAX_CODEC_PROTO_MESSAGE_BYTES);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error instanceof ReallyMeCodecError) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const boundaryResourceLimitResult = () => {
|
|
102
|
+
try {
|
|
103
|
+
return {
|
|
104
|
+
status: "codec-error",
|
|
105
|
+
bytes: toBinary(CodecErrorSchema, create(CodecErrorSchema, {
|
|
106
|
+
error: {
|
|
107
|
+
case: "boundary",
|
|
108
|
+
value: create(CodecBoundaryErrorSchema, {
|
|
109
|
+
reason: CodecErrorReason.BOUNDARY_RESOURCE_LIMIT_EXCEEDED,
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
112
|
+
})),
|
|
113
|
+
isCodecError: true,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch (_error) {
|
|
117
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const boundaryResourceLimitEnvelope = () => {
|
|
121
|
+
const result = boundaryResourceLimitResult();
|
|
122
|
+
try {
|
|
123
|
+
return toBinary(CodecProtoResultEnvelopeSchema, create(CodecProtoResultEnvelopeSchema, {
|
|
124
|
+
status: CodecProtoResultStatus.CODEC_ERROR,
|
|
125
|
+
payload: result.bytes,
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
catch (_error) {
|
|
129
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
result.bytes.fill(0);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const decodeResultEnvelope = (envelopeBytes) => {
|
|
136
|
+
try {
|
|
137
|
+
const envelope = fromBinary(CodecProtoResultEnvelopeSchema, envelopeBytes);
|
|
138
|
+
try {
|
|
139
|
+
switch (envelope.status) {
|
|
140
|
+
case CodecProtoResultStatus.RESULT:
|
|
141
|
+
return {
|
|
142
|
+
status: "result",
|
|
143
|
+
bytes: envelope.payload.slice(),
|
|
144
|
+
isCodecError: false,
|
|
145
|
+
};
|
|
146
|
+
case CodecProtoResultStatus.CODEC_ERROR:
|
|
147
|
+
return {
|
|
148
|
+
status: "codec-error",
|
|
149
|
+
bytes: envelope.payload.slice(),
|
|
150
|
+
isCodecError: true,
|
|
151
|
+
};
|
|
152
|
+
case CodecProtoResultStatus.UNSPECIFIED:
|
|
153
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
envelope.payload.fill(0);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof ReallyMeCodecError) {
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Execute one binary generated-protobuf request.
|
|
169
|
+
*
|
|
170
|
+
* The returned bytes are always a `CodecProtoResultEnvelope`; malformed or
|
|
171
|
+
* unsupported requests are represented inside that envelope.
|
|
172
|
+
*/
|
|
173
|
+
export const processProto = (requestBytes) => {
|
|
174
|
+
ensureBytesInput(requestBytes);
|
|
175
|
+
if (requestBytes.length > MAX_CODEC_PROTO_MESSAGE_BYTES) {
|
|
176
|
+
return boundaryResourceLimitEnvelope();
|
|
177
|
+
}
|
|
178
|
+
return readIndependentBoundedBytesOutput(requireReallyMeCodecWasmProvider().processProto(requestBytes), requestBytes, MAX_CODEC_PROTO_RESULT_ENVELOPE_BYTES);
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Execute one generated ProtoJSON request and return the same binary envelope
|
|
182
|
+
* used by `processProto`.
|
|
183
|
+
*/
|
|
184
|
+
export const processProtoJson = (requestJson) => {
|
|
185
|
+
ensureBytesInput(requestJson);
|
|
186
|
+
if (requestJson.length > MAX_CODEC_PROTO_JSON_BYTES) {
|
|
187
|
+
return boundaryResourceLimitEnvelope();
|
|
188
|
+
}
|
|
189
|
+
return readIndependentBoundedBytesOutput(requireReallyMeCodecWasmProvider().processProtoJson(requestJson), requestJson, MAX_CODEC_PROTO_RESULT_ENVELOPE_BYTES);
|
|
190
|
+
};
|
|
191
|
+
export const processGeneratedProtoRequest = (request) => {
|
|
192
|
+
let withinBoundary;
|
|
193
|
+
try {
|
|
194
|
+
withinBoundary = validateGeneratedProtoRequest(request);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error instanceof ReallyMeCodecError) {
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
201
|
+
}
|
|
202
|
+
if (!withinBoundary) {
|
|
203
|
+
return boundaryResourceLimitResult();
|
|
204
|
+
}
|
|
205
|
+
let requestBytes;
|
|
206
|
+
try {
|
|
207
|
+
requestBytes = toBinary(CodecOperationRequestSchema, request);
|
|
208
|
+
}
|
|
209
|
+
catch (_error) {
|
|
210
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
if (requestBytes.length > MAX_CODEC_PROTO_MESSAGE_BYTES) {
|
|
214
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
215
|
+
}
|
|
216
|
+
const envelopeBytes = processProto(requestBytes);
|
|
217
|
+
try {
|
|
218
|
+
return decodeResultEnvelope(envelopeBytes);
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
envelopeBytes.fill(0);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
requestBytes.fill(0);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const errorCodeForCodecError = (bytes) => {
|
|
229
|
+
let error;
|
|
230
|
+
try {
|
|
231
|
+
error = fromBinary(CodecErrorSchema, bytes);
|
|
232
|
+
}
|
|
233
|
+
catch (_error) {
|
|
234
|
+
return "provider-failure";
|
|
235
|
+
}
|
|
236
|
+
const reason = error.error.value?.reason;
|
|
237
|
+
const reasonIsKnown = reason !== undefined &&
|
|
238
|
+
Object.values(CodecErrorReason).some((candidate) => candidate === reason);
|
|
239
|
+
if (!reasonIsKnown) {
|
|
240
|
+
return "provider-failure";
|
|
241
|
+
}
|
|
242
|
+
switch (error.error.case) {
|
|
243
|
+
case "baseEncoding":
|
|
244
|
+
return reason >= 100 && reason <= 199
|
|
245
|
+
? "invalid-input"
|
|
246
|
+
: "provider-failure";
|
|
247
|
+
case "pem":
|
|
248
|
+
return reason >= 200 && reason <= 299
|
|
249
|
+
? "invalid-input"
|
|
250
|
+
: "provider-failure";
|
|
251
|
+
case "multiformat":
|
|
252
|
+
return reason >= 300 && reason <= 399
|
|
253
|
+
? "invalid-input"
|
|
254
|
+
: "provider-failure";
|
|
255
|
+
case "canonicalization":
|
|
256
|
+
if (reason === CodecErrorReason.CANONICAL_INTERNAL) {
|
|
257
|
+
return "provider-failure";
|
|
258
|
+
}
|
|
259
|
+
return reason >= 400 && reason <= 499
|
|
260
|
+
? "invalid-input"
|
|
261
|
+
: "provider-failure";
|
|
262
|
+
case "backend":
|
|
263
|
+
return "provider-failure";
|
|
264
|
+
case "boundary":
|
|
265
|
+
// This is the only boundary error the generated facade creates from
|
|
266
|
+
// caller input. Malformed/missing generated requests indicate provider
|
|
267
|
+
// corruption or skew, not bad input supplied to the high-level API.
|
|
268
|
+
return reason === CodecErrorReason.BOUNDARY_RESOURCE_LIMIT_EXCEEDED
|
|
269
|
+
? "invalid-input"
|
|
270
|
+
: "provider-failure";
|
|
271
|
+
case undefined:
|
|
272
|
+
return "provider-failure";
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
export const protoPayloadOrThrow = (result) => {
|
|
276
|
+
if (result.isCodecError) {
|
|
277
|
+
const code = errorCodeForCodecError(result.bytes);
|
|
278
|
+
result.bytes.fill(0);
|
|
279
|
+
throw new ReallyMeCodecError(code);
|
|
280
|
+
}
|
|
281
|
+
return result.bytes;
|
|
282
|
+
};
|
package/dist/readOutput.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const ensureStringInput: (value: string) => void;
|
|
|
3
3
|
export declare const ensureStringValue: (value: string) => void;
|
|
4
4
|
export declare const readBooleanOutput: (value: unknown) => boolean;
|
|
5
5
|
export declare const readBytesOutput: (value: unknown) => Uint8Array;
|
|
6
|
+
export declare const readIndependentBoundedBytesOutput: (value: unknown, input: Uint8Array, maximumLength: number) => Uint8Array;
|
|
6
7
|
export declare const readNumberOutput: (value: unknown) => number;
|
|
7
8
|
export declare const readObjectOutput: (value: unknown) => object;
|
|
8
9
|
export declare const readStringOutput: (value: unknown) => string;
|
|
@@ -16,6 +17,5 @@ export type ReallyMeCodecProtoResult = Readonly<{
|
|
|
16
17
|
bytes: Uint8Array;
|
|
17
18
|
isCodecError: boolean;
|
|
18
19
|
}>;
|
|
19
|
-
export declare const readProtoResultOutput: (value: unknown) => ReallyMeCodecProtoResult;
|
|
20
20
|
export declare const readOptionalLengthProperty: (object: object, name: string) => number | undefined;
|
|
21
21
|
export declare const asciiBytesToString: (bytes: Uint8Array) => string;
|
package/dist/readOutput.js
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { MAX_CODEC_FFI_INPUT_BYTES, MAX_CODEC_FFI_OUTPUT_BYTES, requireBoundaryUtf8String, } from "./boundary.js";
|
|
4
5
|
import { ReallyMeCodecError } from "./errors.js";
|
|
6
|
+
const readProviderProperty = (object, name, allowMissing = false) => {
|
|
7
|
+
try {
|
|
8
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
|
9
|
+
if (descriptor === undefined) {
|
|
10
|
+
if (allowMissing) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
14
|
+
}
|
|
15
|
+
if (!("value" in descriptor)) {
|
|
16
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
17
|
+
}
|
|
18
|
+
return descriptor.value;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error instanceof ReallyMeCodecError) {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const requireBoundedProviderString = (value, allowEmpty) => {
|
|
28
|
+
try {
|
|
29
|
+
requireBoundaryUtf8String(value, allowEmpty, MAX_CODEC_FFI_OUTPUT_BYTES);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
catch (_error) {
|
|
33
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
5
36
|
export const ensureBytesInput = (value) => {
|
|
6
37
|
if (!(value instanceof Uint8Array)) {
|
|
7
38
|
throw new ReallyMeCodecError("invalid-input");
|
|
@@ -27,6 +58,25 @@ export const readBytesOutput = (value) => {
|
|
|
27
58
|
if (!(value instanceof Uint8Array)) {
|
|
28
59
|
throw new ReallyMeCodecError("provider-failure");
|
|
29
60
|
}
|
|
61
|
+
if (value.length > MAX_CODEC_FFI_OUTPUT_BYTES) {
|
|
62
|
+
value.fill(0);
|
|
63
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
};
|
|
67
|
+
export const readIndependentBoundedBytesOutput = (value, input, maximumLength) => {
|
|
68
|
+
if (!(value instanceof Uint8Array)) {
|
|
69
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
70
|
+
}
|
|
71
|
+
// Even non-overlapping views into one ArrayBuffer share transfer and detach
|
|
72
|
+
// semantics, so they do not provide independent result ownership.
|
|
73
|
+
if (value.buffer === input.buffer) {
|
|
74
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
75
|
+
}
|
|
76
|
+
if (value.length === 0 || value.length > maximumLength) {
|
|
77
|
+
value.fill(0);
|
|
78
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
79
|
+
}
|
|
30
80
|
return value;
|
|
31
81
|
};
|
|
32
82
|
export const readNumberOutput = (value) => {
|
|
@@ -39,56 +89,60 @@ export const readObjectOutput = (value) => {
|
|
|
39
89
|
if (typeof value !== "object" || value === null) {
|
|
40
90
|
throw new ReallyMeCodecError("provider-failure");
|
|
41
91
|
}
|
|
42
|
-
|
|
92
|
+
try {
|
|
93
|
+
const prototype = Object.getPrototypeOf(value);
|
|
94
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
95
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error instanceof ReallyMeCodecError) {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
104
|
+
}
|
|
43
105
|
};
|
|
44
106
|
export const readStringOutput = (value) => {
|
|
45
107
|
if (typeof value !== "string") {
|
|
46
108
|
throw new ReallyMeCodecError("provider-failure");
|
|
47
109
|
}
|
|
48
|
-
return value;
|
|
110
|
+
return requireBoundedProviderString(value, true);
|
|
49
111
|
};
|
|
50
112
|
export const readStringProperty = (object, name) => {
|
|
51
|
-
const value =
|
|
113
|
+
const value = readProviderProperty(object, name);
|
|
52
114
|
if (typeof value !== "string" || value.length === 0) {
|
|
53
115
|
throw new ReallyMeCodecError("provider-failure");
|
|
54
116
|
}
|
|
55
|
-
return value;
|
|
117
|
+
return requireBoundedProviderString(value, false);
|
|
56
118
|
};
|
|
57
119
|
export const readStringValueProperty = (object, name) => {
|
|
58
|
-
const value =
|
|
120
|
+
const value = readProviderProperty(object, name);
|
|
59
121
|
if (typeof value !== "string") {
|
|
60
122
|
throw new ReallyMeCodecError("provider-failure");
|
|
61
123
|
}
|
|
62
|
-
return value;
|
|
124
|
+
return requireBoundedProviderString(value, true);
|
|
63
125
|
};
|
|
64
126
|
export const readBooleanProperty = (object, name) => {
|
|
65
|
-
const value =
|
|
127
|
+
const value = readProviderProperty(object, name);
|
|
66
128
|
if (typeof value !== "boolean") {
|
|
67
129
|
throw new ReallyMeCodecError("provider-failure");
|
|
68
130
|
}
|
|
69
131
|
return value;
|
|
70
132
|
};
|
|
71
133
|
export const readBytesProperty = (object, name) => {
|
|
72
|
-
const value =
|
|
134
|
+
const value = readProviderProperty(object, name);
|
|
73
135
|
if (!(value instanceof Uint8Array)) {
|
|
74
136
|
throw new ReallyMeCodecError("provider-failure");
|
|
75
137
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export const readProtoResultOutput = (value) => {
|
|
79
|
-
const object = readObjectOutput(value);
|
|
80
|
-
const status = readStringProperty(object, "status");
|
|
81
|
-
if (status !== "result" && status !== "codec-error") {
|
|
138
|
+
if (value.length > MAX_CODEC_FFI_OUTPUT_BYTES) {
|
|
139
|
+
value.fill(0);
|
|
82
140
|
throw new ReallyMeCodecError("provider-failure");
|
|
83
141
|
}
|
|
84
|
-
return
|
|
85
|
-
status,
|
|
86
|
-
bytes: readBytesProperty(object, "bytes"),
|
|
87
|
-
isCodecError: status === "codec-error",
|
|
88
|
-
};
|
|
142
|
+
return value;
|
|
89
143
|
};
|
|
90
144
|
export const readOptionalLengthProperty = (object, name) => {
|
|
91
|
-
const value =
|
|
145
|
+
const value = readProviderProperty(object, name, true);
|
|
92
146
|
if (value === undefined) {
|
|
93
147
|
return undefined;
|
|
94
148
|
}
|
|
@@ -98,8 +152,17 @@ export const readOptionalLengthProperty = (object, name) => {
|
|
|
98
152
|
return value;
|
|
99
153
|
};
|
|
100
154
|
export const asciiBytesToString = (bytes) => {
|
|
155
|
+
if (bytes.length > MAX_CODEC_FFI_INPUT_BYTES) {
|
|
156
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
157
|
+
}
|
|
101
158
|
let value = "";
|
|
102
|
-
|
|
159
|
+
// Indexed access avoids executing an attacker-supplied iterator installed
|
|
160
|
+
// on an otherwise valid Uint8Array instance.
|
|
161
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
162
|
+
const byte = bytes[index];
|
|
163
|
+
if (byte === undefined) {
|
|
164
|
+
throw new ReallyMeCodecError("invalid-input");
|
|
165
|
+
}
|
|
103
166
|
if (byte > 0x7f) {
|
|
104
167
|
throw new ReallyMeCodecError("invalid-input");
|
|
105
168
|
}
|
|
@@ -81,16 +81,6 @@ export function dagCborSha256ContentHash(bytes: Uint8Array): Uint8Array;
|
|
|
81
81
|
*/
|
|
82
82
|
export function dagCborVerifyCid(cid: string, bytes: Uint8Array): any;
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* Recompute and compare a CID as a `CodecDagCborVerifyCidResult` protobuf message.
|
|
86
|
-
*/
|
|
87
|
-
export function dagCborVerifyCidProto(cid: string, bytes: Uint8Array): Uint8Array;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Recompute and compare a CID protobuf message with an explicit result status.
|
|
91
|
-
*/
|
|
92
|
-
export function dagCborVerifyCidProtoResult(cid: string, bytes: Uint8Array): any;
|
|
93
|
-
|
|
94
84
|
/**
|
|
95
85
|
* Return whether a string parses as a CID.
|
|
96
86
|
*/
|
|
@@ -121,31 +111,11 @@ export function multibaseDecode(encoded: string): Uint8Array;
|
|
|
121
111
|
*/
|
|
122
112
|
export function multicodecLookupPrefix(bytes: Uint8Array): any;
|
|
123
113
|
|
|
124
|
-
/**
|
|
125
|
-
* Resolve a prefix as a `CodecMulticodecLookupResult` protobuf message.
|
|
126
|
-
*/
|
|
127
|
-
export function multicodecLookupPrefixProto(bytes: Uint8Array): Uint8Array;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Resolve a prefix protobuf message with an explicit result status.
|
|
131
|
-
*/
|
|
132
|
-
export function multicodecLookupPrefixProtoResult(bytes: Uint8Array): any;
|
|
133
|
-
|
|
134
114
|
/**
|
|
135
115
|
* Return multicodec metadata for a canonical codec name.
|
|
136
116
|
*/
|
|
137
117
|
export function multicodecPrefixForName(codec_name: string): any;
|
|
138
118
|
|
|
139
|
-
/**
|
|
140
|
-
* Return multicodec metadata as a `CodecMulticodecSpec` protobuf message.
|
|
141
|
-
*/
|
|
142
|
-
export function multicodecPrefixForNameProto(codec_name: string): Uint8Array;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Return multicodec metadata protobuf bytes with an explicit result status.
|
|
146
|
-
*/
|
|
147
|
-
export function multicodecPrefixForNameProtoResult(codec_name: string): any;
|
|
148
|
-
|
|
149
119
|
/**
|
|
150
120
|
* Strip a known multicodec prefix, or return the original bytes when none is found.
|
|
151
121
|
*/
|
|
@@ -156,16 +126,6 @@ export function multicodecStripPrefix(bytes: Uint8Array): Uint8Array;
|
|
|
156
126
|
*/
|
|
157
127
|
export function multicodecTable(): any;
|
|
158
128
|
|
|
159
|
-
/**
|
|
160
|
-
* Return the supported multicodec table as protobuf bytes.
|
|
161
|
-
*/
|
|
162
|
-
export function multicodecTableProto(): Uint8Array;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Return the supported multicodec table protobuf bytes with an explicit result status.
|
|
166
|
-
*/
|
|
167
|
-
export function multicodecTableProtoResult(): any;
|
|
168
|
-
|
|
169
129
|
/**
|
|
170
130
|
* Encode a public key as a multibase base58btc multikey.
|
|
171
131
|
*/
|
|
@@ -177,34 +137,24 @@ export function multikeyEncode(codec_name: string, public_key: Uint8Array): stri
|
|
|
177
137
|
export function multikeyParse(multikey: string): any;
|
|
178
138
|
|
|
179
139
|
/**
|
|
180
|
-
*
|
|
140
|
+
* Decode PEM armor bytes with caller-supplied size and label policy.
|
|
181
141
|
*/
|
|
182
|
-
export function
|
|
142
|
+
export function pemDecode(input: Uint8Array, options_json: string): any;
|
|
183
143
|
|
|
184
144
|
/**
|
|
185
|
-
*
|
|
145
|
+
* Encode DER bytes as wipeable PEM armor bytes.
|
|
186
146
|
*/
|
|
187
|
-
export function
|
|
147
|
+
export function pemEncode(label: string, der: Uint8Array, options_json: string): Uint8Array;
|
|
188
148
|
|
|
189
149
|
/**
|
|
190
|
-
*
|
|
150
|
+
* Execute one generated binary protobuf request and return a binary result envelope.
|
|
191
151
|
*/
|
|
192
|
-
export function
|
|
152
|
+
export function processProto(request: Uint8Array): Uint8Array;
|
|
193
153
|
|
|
194
154
|
/**
|
|
195
|
-
*
|
|
155
|
+
* Execute one generated ProtoJSON request and return a binary result envelope.
|
|
196
156
|
*/
|
|
197
|
-
export function
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Decode PEM text armor protobuf bytes with an explicit result status.
|
|
201
|
-
*/
|
|
202
|
-
export function pemDecodeProtoResult(input: string, options_json: string): any;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Encode DER bytes as PEM text armor.
|
|
206
|
-
*/
|
|
207
|
-
export function pemEncode(label: string, der: Uint8Array, options_json: string): string;
|
|
157
|
+
export function processProtoJson(request_json: Uint8Array): Uint8Array;
|
|
208
158
|
|
|
209
159
|
/**
|
|
210
160
|
* Fail closed when a codec name is not in the supported table.
|
|
@@ -225,55 +175,45 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
225
175
|
|
|
226
176
|
export interface InitOutput {
|
|
227
177
|
readonly memory: WebAssembly.Memory;
|
|
228
|
-
readonly base58btcDecode: (a:
|
|
178
|
+
readonly base58btcDecode: (a: any) => [number, number, number];
|
|
229
179
|
readonly base58btcEncode: (a: any) => [number, number, number, number];
|
|
230
|
-
readonly base64Decode: (a:
|
|
231
|
-
readonly base64Encode: (a: any) => [number, number];
|
|
232
|
-
readonly base64urlDecode: (a:
|
|
233
|
-
readonly base64urlEncode: (a: any) => [number, number];
|
|
234
|
-
readonly bindingTypeMatchesCodec: (a:
|
|
235
|
-
readonly bytesToLowerHex: (a: any) => [number, number];
|
|
236
|
-
readonly canonicalizeJson: (a:
|
|
180
|
+
readonly base64Decode: (a: any) => [number, number, number];
|
|
181
|
+
readonly base64Encode: (a: any) => [number, number, number, number];
|
|
182
|
+
readonly base64urlDecode: (a: any) => [number, number, number];
|
|
183
|
+
readonly base64urlEncode: (a: any) => [number, number, number, number];
|
|
184
|
+
readonly bindingTypeMatchesCodec: (a: any, b: any) => [number, number, number];
|
|
185
|
+
readonly bytesToLowerHex: (a: any) => [number, number, number, number];
|
|
186
|
+
readonly canonicalizeJson: (a: any) => [number, number, number, number];
|
|
237
187
|
readonly dagCborCodecCode: () => number;
|
|
238
188
|
readonly dagCborComputeCid: (a: any) => [number, number, number, number];
|
|
239
189
|
readonly dagCborDecode: (a: any) => [number, number, number, number];
|
|
240
|
-
readonly dagCborEncode: (a:
|
|
190
|
+
readonly dagCborEncode: (a: any) => [number, number, number];
|
|
241
191
|
readonly dagCborMultihash: (a: any) => [number, number, number];
|
|
242
192
|
readonly dagCborSha256ContentHash: (a: any) => [number, number, number];
|
|
243
|
-
readonly dagCborVerifyCid: (a:
|
|
244
|
-
readonly
|
|
245
|
-
readonly
|
|
246
|
-
readonly isValidCidString: (a: number, b: number) => number;
|
|
247
|
-
readonly lowerHexToBytes: (a: number, b: number) => [number, number, number];
|
|
193
|
+
readonly dagCborVerifyCid: (a: any, b: any) => [number, number, number];
|
|
194
|
+
readonly isValidCidString: (a: any) => [number, number, number];
|
|
195
|
+
readonly lowerHexToBytes: (a: any) => [number, number, number];
|
|
248
196
|
readonly multibaseBase58btcEncode: (a: any) => [number, number, number, number];
|
|
249
|
-
readonly multibaseBase64urlEncode: (a: any) => [number, number];
|
|
250
|
-
readonly multibaseDecode: (a:
|
|
197
|
+
readonly multibaseBase64urlEncode: (a: any) => [number, number, number, number];
|
|
198
|
+
readonly multibaseDecode: (a: any) => [number, number, number];
|
|
251
199
|
readonly multicodecLookupPrefix: (a: any) => [number, number, number];
|
|
252
|
-
readonly
|
|
253
|
-
readonly
|
|
254
|
-
readonly multicodecPrefixForName: (a: number, b: number) => [number, number, number];
|
|
255
|
-
readonly multicodecPrefixForNameProto: (a: number, b: number) => [number, number, number];
|
|
256
|
-
readonly multicodecPrefixForNameProtoResult: (a: number, b: number) => [number, number, number];
|
|
257
|
-
readonly multicodecStripPrefix: (a: any) => any;
|
|
200
|
+
readonly multicodecPrefixForName: (a: any) => [number, number, number];
|
|
201
|
+
readonly multicodecStripPrefix: (a: any) => [number, number, number];
|
|
258
202
|
readonly multicodecTable: () => [number, number, number];
|
|
259
|
-
readonly
|
|
260
|
-
readonly
|
|
261
|
-
readonly
|
|
262
|
-
readonly
|
|
263
|
-
readonly
|
|
264
|
-
readonly
|
|
265
|
-
readonly
|
|
266
|
-
readonly
|
|
267
|
-
readonly
|
|
268
|
-
readonly
|
|
269
|
-
readonly
|
|
270
|
-
readonly tryParseCid: (a: number, b: number) => any;
|
|
271
|
-
readonly validateKeyBinding: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
203
|
+
readonly multikeyEncode: (a: any, b: any) => [number, number, number, number];
|
|
204
|
+
readonly multikeyParse: (a: any) => [number, number, number];
|
|
205
|
+
readonly pemDecode: (a: any, b: any) => [number, number, number];
|
|
206
|
+
readonly pemEncode: (a: any, b: any, c: any) => [number, number, number];
|
|
207
|
+
readonly processProto: (a: any) => [number, number, number];
|
|
208
|
+
readonly processProtoJson: (a: any) => [number, number, number];
|
|
209
|
+
readonly requireSupportedMulticodec: (a: any) => [number, number];
|
|
210
|
+
readonly tryParseCid: (a: any) => [number, number, number];
|
|
211
|
+
readonly validateKeyBinding: (a: any, b: number, c: any) => [number, number];
|
|
212
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
213
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
272
214
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
273
215
|
readonly __externref_table_alloc: () => number;
|
|
274
216
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
275
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
276
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
277
217
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
278
218
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
279
219
|
readonly __wbindgen_start: () => void;
|