@reallyme/codec 0.1.22 → 0.2.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 +16 -0
- package/README.md +52 -15
- package/dist/boundary.d.ts +8 -2
- package/dist/boundary.js +31 -4
- package/dist/cbor.d.ts +67 -4
- package/dist/cbor.js +1170 -74
- package/dist/deterministicCborBoundary.d.ts +11 -0
- package/dist/deterministicCborBoundary.js +17 -0
- package/dist/index.d.ts +37 -23
- package/dist/index.js +14 -22
- package/dist/multiformat.d.ts +10 -12
- package/dist/multiformat.js +149 -128
- package/dist/operationContract.d.ts +31 -0
- package/dist/operationContract.js +754 -0
- package/dist/pem.d.ts +0 -3
- package/dist/pem.js +111 -34
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.d.ts +641 -38
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.js +187 -43
- package/dist/proto.d.ts +2 -2
- package/dist/proto.js +1 -1
- package/dist/readOutput.d.ts +7 -6
- package/dist/readOutput.js +62 -11
- package/dist/wasm/reallyme_codec_wasm.d.ts +7 -62
- package/dist/wasm/reallyme_codec_wasm.js +11 -168
- package/dist/wasm/reallyme_codec_wasm_bg.wasm +0 -0
- package/dist/wasmProvider.d.ts +5 -17
- package/dist/wasmProvider.js +4 -30
- package/package.json +4 -1
- package/dist/protoProcess.d.ts +0 -16
- package/dist/protoProcess.js +0 -282
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const MAX_DETERMINISTIC_CBOR_INPUT_LEN = 1048576;
|
|
2
|
+
export declare const MAX_DETERMINISTIC_CBOR_OUTPUT_LEN = 1048576;
|
|
3
|
+
export declare const MAX_DETERMINISTIC_CBOR_NESTING_DEPTH = 64;
|
|
4
|
+
export declare const MAX_DETERMINISTIC_CBOR_NODES = 65536;
|
|
5
|
+
export declare const MAX_DETERMINISTIC_CBOR_CONTAINER_ENTRIES = 16384;
|
|
6
|
+
export declare const MAX_DETERMINISTIC_CBOR_AGGREGATE_TEXT_BYTES = 1048576;
|
|
7
|
+
export declare const MAX_DETERMINISTIC_CBOR_AGGREGATE_BYTE_STRING_BYTES = 1048576;
|
|
8
|
+
export declare const MAX_DETERMINISTIC_CBOR_PROTO_RECURSION_DEPTH: number;
|
|
9
|
+
export declare const DETERMINISTIC_CBOR_U64_MAX: bigint;
|
|
10
|
+
export declare const DETERMINISTIC_CBOR_I64_MIN: bigint;
|
|
11
|
+
export declare const DETERMINISTIC_CBOR_NEGATIVE_MAX = -1n;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
export const MAX_DETERMINISTIC_CBOR_INPUT_LEN = 1_048_576;
|
|
5
|
+
export const MAX_DETERMINISTIC_CBOR_OUTPUT_LEN = 1_048_576;
|
|
6
|
+
export const MAX_DETERMINISTIC_CBOR_NESTING_DEPTH = 64;
|
|
7
|
+
export const MAX_DETERMINISTIC_CBOR_NODES = 65_536;
|
|
8
|
+
export const MAX_DETERMINISTIC_CBOR_CONTAINER_ENTRIES = 16_384;
|
|
9
|
+
export const MAX_DETERMINISTIC_CBOR_AGGREGATE_TEXT_BYTES = 1_048_576;
|
|
10
|
+
export const MAX_DETERMINISTIC_CBOR_AGGREGATE_BYTE_STRING_BYTES = 1_048_576;
|
|
11
|
+
// A nested map expands to Value -> Map -> MapEntry on the protobuf wire. The
|
|
12
|
+
// five additional layers cover the result/request and deepest scalar wrapper.
|
|
13
|
+
// Buf's default recursion limit of 100 cannot represent semantic depth 64.
|
|
14
|
+
export const MAX_DETERMINISTIC_CBOR_PROTO_RECURSION_DEPTH = MAX_DETERMINISTIC_CBOR_NESTING_DEPTH * 3 + 5;
|
|
15
|
+
export const DETERMINISTIC_CBOR_U64_MAX = (1n << 64n) - 1n;
|
|
16
|
+
export const DETERMINISTIC_CBOR_I64_MIN = -(1n << 63n);
|
|
17
|
+
export const DETERMINISTIC_CBOR_NEGATIVE_MAX = -1n;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
export { ReallyMeCodecError } from "./errors.js";
|
|
2
2
|
export type { ReallyMeCodecErrorCode } from "./errors.js";
|
|
3
3
|
export { base64Decode, base64Encode, base64urlDecode, base64urlDecodeBytes, base64urlEncode, bytesToLowerHex, lowerHexToBytes, } from "./baseEncoding.js";
|
|
4
|
-
export { base58btcDecode, base58btcEncode, bindingTypeMatchesCodec, multibaseBase58btcEncode, multibaseBase64urlEncode, multibaseDecode,
|
|
5
|
-
export type { ReallyMeKeyMaterialKind, ReallyMeMulticodecMetadata, ReallyMeMulticodecTag, ReallyMeParsedMultikey, } from "./multiformat.js";
|
|
6
|
-
export { dagCborCodecCode, dagCborComputeCid, dagCborDecode, dagCborEncode, dagCborMultihash, dagCborSha256ContentHash, dagCborVerifyCid,
|
|
7
|
-
export type { ReallyMeCborMapEntry, ReallyMeCborValue, ReallyMeDagCborCidVerification, } from "./cbor.js";
|
|
4
|
+
export { base58btcDecode, base58btcEncode, bindingTypeMatchesCodec, multibaseBase58btcEncode, multibaseBase64urlEncode, multibaseDecode, multicodecLookupPrefix, multicodecPrefixForName, multicodecStripPrefix, multicodecTable, multikeyEncode, multikeyParse, requireSupportedMulticodec, validateKeyBinding, } from "./multiformat.js";
|
|
5
|
+
export type { ReallyMeKeyMaterialKind, ReallyMeMulticodecLookupResult, ReallyMeMulticodecMetadata, ReallyMeMulticodecTable, ReallyMeMulticodecTag, ReallyMeParsedMultikey, } from "./multiformat.js";
|
|
6
|
+
export { dagCborCodecCode, dagCborComputeCid, dagCborDecode, dagCborEncode, dagCborMultihash, dagCborSha256ContentHash, dagCborVerifyCid, deterministicCborDecode, deterministicCborEncode, isValidCidString, ReallyMeDagCbor, ReallyMeDeterministicCbor, tryParseCid, } from "./cbor.js";
|
|
7
|
+
export type { ReallyMeDeterministicCborInteger, ReallyMeDeterministicCborMapEntry, ReallyMeDeterministicCborMapKey, ReallyMeDeterministicCborValue, ReallyMeCborMapEntry, ReallyMeCborValue, ReallyMeDagCborCidVerification, } from "./cbor.js";
|
|
8
8
|
export { canonicalizeJson, canonicalizeJsonText } from "./jcs.js";
|
|
9
|
-
export { decodePem,
|
|
10
|
-
export {
|
|
11
|
-
export type { ReallyMeCodecProtoResult, ReallyMeCodecProtoStatus } from "./readOutput.js";
|
|
9
|
+
export { decodePem, encodePem } from "./pem.js";
|
|
10
|
+
export { processOperation, processOperationJson } from "./operationContract.js";
|
|
12
11
|
export type { ReallyMePemDecodePolicy, ReallyMePemDocument, ReallyMePemEncodeOptions, ReallyMePemLabel, ReallyMePemLineEnding, } from "./pem.js";
|
|
13
12
|
export { REALLYME_CODEC_WASM_EXPORTS, installReallyMeCodecWasmProvider, requireReallyMeCodecWasmProvider, } from "./wasmProvider.js";
|
|
14
13
|
export type { ReallyMeCodecWasmProvider } from "./wasmProvider.js";
|
|
@@ -26,20 +25,12 @@ export declare const ReallyMeCodec: {
|
|
|
26
25
|
readonly multibaseBase58btcEncode: (bytes: Uint8Array) => string;
|
|
27
26
|
readonly multibaseBase64urlEncode: (bytes: Uint8Array) => string;
|
|
28
27
|
readonly multibaseDecode: (encoded: string) => Uint8Array;
|
|
29
|
-
readonly
|
|
30
|
-
readonly multicodecLookupPrefixProtoResult: (bytes: Uint8Array) => import("./readOutput.js").ReallyMeCodecProtoResult;
|
|
31
|
-
readonly multicodecLookupPrefix: (bytes: Uint8Array) => import("./multiformat.js").ReallyMeMulticodecMetadata;
|
|
32
|
-
readonly multicodecPrefixForNameProto: (codecName: string) => Uint8Array;
|
|
33
|
-
readonly multicodecPrefixForNameProtoResult: (codecName: string) => import("./readOutput.js").ReallyMeCodecProtoResult;
|
|
28
|
+
readonly multicodecLookupPrefix: (bytes: Uint8Array) => import("./multiformat.js").ReallyMeMulticodecLookupResult;
|
|
34
29
|
readonly multicodecPrefixForName: (codecName: string) => import("./multiformat.js").ReallyMeMulticodecMetadata;
|
|
35
30
|
readonly multicodecStripPrefix: (bytes: Uint8Array) => Uint8Array;
|
|
36
|
-
readonly multicodecTable: () =>
|
|
37
|
-
readonly multicodecTableProto: () => Uint8Array;
|
|
38
|
-
readonly multicodecTableProtoResult: () => import("./readOutput.js").ReallyMeCodecProtoResult;
|
|
31
|
+
readonly multicodecTable: () => import("./multiformat.js").ReallyMeMulticodecTable;
|
|
39
32
|
readonly multikeyEncode: (codecName: string, publicKey: Uint8Array) => string;
|
|
40
33
|
readonly multikeyParse: (multikey: string) => import("./multiformat.js").ReallyMeParsedMultikey;
|
|
41
|
-
readonly multikeyParseProto: (multikey: string) => Uint8Array;
|
|
42
|
-
readonly multikeyParseProtoResult: (multikey: string) => import("./readOutput.js").ReallyMeCodecProtoResult;
|
|
43
34
|
readonly requireSupportedMulticodec: (codecName: string) => void;
|
|
44
35
|
readonly validateKeyBinding: (bindingType: string, algorithm: string | undefined, multikey: string) => void;
|
|
45
36
|
readonly dagCborCodecCode: () => number;
|
|
@@ -49,16 +40,39 @@ export declare const ReallyMeCodec: {
|
|
|
49
40
|
readonly dagCborMultihash: (bytes: Uint8Array) => Uint8Array;
|
|
50
41
|
readonly dagCborSha256ContentHash: (bytes: Uint8Array) => Uint8Array;
|
|
51
42
|
readonly dagCborVerifyCid: (cid: string, bytes: Uint8Array) => import("./cbor.js").ReallyMeDagCborCidVerification;
|
|
52
|
-
readonly
|
|
53
|
-
readonly
|
|
43
|
+
readonly deterministicCborDecode: (bytes: Uint8Array) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
44
|
+
readonly deterministicCborEncode: (value: unknown) => Uint8Array;
|
|
54
45
|
readonly isValidCidString: (cid: string) => boolean;
|
|
46
|
+
readonly ReallyMeDagCbor: {
|
|
47
|
+
readonly null: () => import("./cbor.js").ReallyMeCborValue;
|
|
48
|
+
readonly bool: (value: boolean) => import("./cbor.js").ReallyMeCborValue;
|
|
49
|
+
readonly int: (value: number | bigint) => import("./cbor.js").ReallyMeCborValue;
|
|
50
|
+
readonly unsigned: (value: number | bigint) => import("./cbor.js").ReallyMeCborValue;
|
|
51
|
+
readonly negative: (value: number | bigint) => import("./cbor.js").ReallyMeCborValue;
|
|
52
|
+
readonly text: (value: string) => import("./cbor.js").ReallyMeCborValue;
|
|
53
|
+
readonly bytes: (value: Uint8Array) => import("./cbor.js").ReallyMeCborValue;
|
|
54
|
+
readonly array: (value: ReadonlyArray<import("./cbor.js").ReallyMeCborValue>) => import("./cbor.js").ReallyMeCborValue;
|
|
55
|
+
readonly mapText: (entries: ReadonlyArray<readonly [string, import("./cbor.js").ReallyMeCborValue]>) => import("./cbor.js").ReallyMeCborValue;
|
|
56
|
+
};
|
|
57
|
+
readonly ReallyMeDeterministicCbor: {
|
|
58
|
+
readonly null: () => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
59
|
+
readonly bool: (value: boolean) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
60
|
+
readonly unsigned: (value: bigint) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
61
|
+
readonly negative: (value: bigint) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
62
|
+
readonly text: (value: string) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
63
|
+
readonly bytes: (value: Uint8Array) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
64
|
+
readonly array: (value: ReadonlyArray<import("./cbor.js").ReallyMeDeterministicCborValue>) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
65
|
+
readonly mapInt: (entries: ReadonlyArray<readonly [bigint, import("./cbor.js").ReallyMeDeterministicCborValue]>) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
66
|
+
readonly mapText: (entries: ReadonlyArray<readonly [string, import("./cbor.js").ReallyMeDeterministicCborValue]>) => import("./cbor.js").ReallyMeDeterministicCborValue;
|
|
67
|
+
readonly intKey: (value: bigint) => import("./cbor.js").ReallyMeDeterministicCborMapKey;
|
|
68
|
+
readonly textKey: (value: string) => import("./cbor.js").ReallyMeDeterministicCborMapKey;
|
|
69
|
+
readonly entry: (key: import("./cbor.js").ReallyMeDeterministicCborMapKey, value: import("./cbor.js").ReallyMeDeterministicCborValue) => import("./cbor.js").ReallyMeDeterministicCborMapEntry;
|
|
70
|
+
};
|
|
55
71
|
readonly tryParseCid: (cid: string) => string | undefined;
|
|
56
72
|
readonly canonicalizeJson: (value: unknown) => string;
|
|
57
73
|
readonly canonicalizeJsonText: (json: string) => string;
|
|
58
74
|
readonly decodePem: (input: Uint8Array, policy?: import("./pem.js").ReallyMePemDecodePolicy) => import("./pem.js").ReallyMePemDocument;
|
|
59
|
-
readonly decodePemProto: (input: Uint8Array, policy?: import("./pem.js").ReallyMePemDecodePolicy) => Uint8Array;
|
|
60
|
-
readonly decodePemProtoResult: (input: Uint8Array, policy?: import("./pem.js").ReallyMePemDecodePolicy) => import("./readOutput.js").ReallyMeCodecProtoResult;
|
|
61
75
|
readonly encodePem: (label: import("./pem.js").ReallyMePemLabel, der: Uint8Array, options?: import("./pem.js").ReallyMePemEncodeOptions) => Uint8Array;
|
|
62
|
-
readonly
|
|
63
|
-
readonly
|
|
76
|
+
readonly processOperation: (requestBytes: Uint8Array) => Uint8Array;
|
|
77
|
+
readonly processOperationJson: (requestJson: Uint8Array) => Uint8Array;
|
|
64
78
|
};
|
package/dist/index.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
export { ReallyMeCodecError } from "./errors.js";
|
|
5
5
|
export { base64Decode, base64Encode, base64urlDecode, base64urlDecodeBytes, base64urlEncode, bytesToLowerHex, lowerHexToBytes, } from "./baseEncoding.js";
|
|
6
|
-
export { base58btcDecode, base58btcEncode, bindingTypeMatchesCodec, multibaseBase58btcEncode, multibaseBase64urlEncode, multibaseDecode,
|
|
7
|
-
export { dagCborCodecCode, dagCborComputeCid, dagCborDecode, dagCborEncode, dagCborMultihash, dagCborSha256ContentHash, dagCborVerifyCid,
|
|
6
|
+
export { base58btcDecode, base58btcEncode, bindingTypeMatchesCodec, multibaseBase58btcEncode, multibaseBase64urlEncode, multibaseDecode, multicodecLookupPrefix, multicodecPrefixForName, multicodecStripPrefix, multicodecTable, multikeyEncode, multikeyParse, requireSupportedMulticodec, validateKeyBinding, } from "./multiformat.js";
|
|
7
|
+
export { dagCborCodecCode, dagCborComputeCid, dagCborDecode, dagCborEncode, dagCborMultihash, dagCborSha256ContentHash, dagCborVerifyCid, deterministicCborDecode, deterministicCborEncode, isValidCidString, ReallyMeDagCbor, ReallyMeDeterministicCbor, tryParseCid, } from "./cbor.js";
|
|
8
8
|
export { canonicalizeJson, canonicalizeJsonText } from "./jcs.js";
|
|
9
|
-
export { decodePem,
|
|
10
|
-
export {
|
|
9
|
+
export { decodePem, encodePem } from "./pem.js";
|
|
10
|
+
export { processOperation, processOperationJson } from "./operationContract.js";
|
|
11
11
|
export { REALLYME_CODEC_WASM_EXPORTS, installReallyMeCodecWasmProvider, requireReallyMeCodecWasmProvider, } from "./wasmProvider.js";
|
|
12
12
|
import { base64Decode, base64Encode, base64urlDecode, base64urlDecodeBytes, base64urlEncode, bytesToLowerHex, lowerHexToBytes, } from "./baseEncoding.js";
|
|
13
|
-
import { dagCborCodecCode, dagCborComputeCid, dagCborDecode, dagCborEncode, dagCborMultihash, dagCborSha256ContentHash, dagCborVerifyCid,
|
|
13
|
+
import { dagCborCodecCode, dagCborComputeCid, dagCborDecode, dagCborEncode, dagCborMultihash, dagCborSha256ContentHash, dagCborVerifyCid, deterministicCborDecode, deterministicCborEncode, isValidCidString, ReallyMeDagCbor, ReallyMeDeterministicCbor, tryParseCid, } from "./cbor.js";
|
|
14
14
|
import { canonicalizeJson, canonicalizeJsonText } from "./jcs.js";
|
|
15
|
-
import { base58btcDecode, base58btcEncode, bindingTypeMatchesCodec, multibaseBase58btcEncode, multibaseBase64urlEncode, multibaseDecode,
|
|
16
|
-
import { decodePem,
|
|
17
|
-
import {
|
|
15
|
+
import { base58btcDecode, base58btcEncode, bindingTypeMatchesCodec, multibaseBase58btcEncode, multibaseBase64urlEncode, multibaseDecode, multicodecLookupPrefix, multicodecPrefixForName, multicodecStripPrefix, multicodecTable, multikeyEncode, multikeyParse, requireSupportedMulticodec, validateKeyBinding, } from "./multiformat.js";
|
|
16
|
+
import { decodePem, encodePem } from "./pem.js";
|
|
17
|
+
import { processOperation, processOperationJson } from "./operationContract.js";
|
|
18
18
|
export const ReallyMeCodec = {
|
|
19
19
|
base64Decode,
|
|
20
20
|
base64Encode,
|
|
@@ -29,20 +29,12 @@ export const ReallyMeCodec = {
|
|
|
29
29
|
multibaseBase58btcEncode,
|
|
30
30
|
multibaseBase64urlEncode,
|
|
31
31
|
multibaseDecode,
|
|
32
|
-
multicodecLookupPrefixProto,
|
|
33
|
-
multicodecLookupPrefixProtoResult,
|
|
34
32
|
multicodecLookupPrefix,
|
|
35
|
-
multicodecPrefixForNameProto,
|
|
36
|
-
multicodecPrefixForNameProtoResult,
|
|
37
33
|
multicodecPrefixForName,
|
|
38
34
|
multicodecStripPrefix,
|
|
39
35
|
multicodecTable,
|
|
40
|
-
multicodecTableProto,
|
|
41
|
-
multicodecTableProtoResult,
|
|
42
36
|
multikeyEncode,
|
|
43
37
|
multikeyParse,
|
|
44
|
-
multikeyParseProto,
|
|
45
|
-
multikeyParseProtoResult,
|
|
46
38
|
requireSupportedMulticodec,
|
|
47
39
|
validateKeyBinding,
|
|
48
40
|
dagCborCodecCode,
|
|
@@ -52,16 +44,16 @@ export const ReallyMeCodec = {
|
|
|
52
44
|
dagCborMultihash,
|
|
53
45
|
dagCborSha256ContentHash,
|
|
54
46
|
dagCborVerifyCid,
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
deterministicCborDecode,
|
|
48
|
+
deterministicCborEncode,
|
|
57
49
|
isValidCidString,
|
|
50
|
+
ReallyMeDagCbor,
|
|
51
|
+
ReallyMeDeterministicCbor,
|
|
58
52
|
tryParseCid,
|
|
59
53
|
canonicalizeJson,
|
|
60
54
|
canonicalizeJsonText,
|
|
61
55
|
decodePem,
|
|
62
|
-
decodePemProto,
|
|
63
|
-
decodePemProtoResult,
|
|
64
56
|
encodePem,
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
processOperation,
|
|
58
|
+
processOperationJson,
|
|
67
59
|
};
|
package/dist/multiformat.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ReallyMeCodecProtoResult } from "./readOutput.js";
|
|
2
1
|
export type ReallyMeMulticodecTag = "encryption" | "hash" | "key" | "multihash" | "multikey";
|
|
3
2
|
export type ReallyMeKeyMaterialKind = "not-key" | "public-key" | "private-key" | "symmetric-key";
|
|
4
3
|
export type ReallyMeMulticodecMetadata = Readonly<{
|
|
@@ -9,32 +8,31 @@ export type ReallyMeMulticodecMetadata = Readonly<{
|
|
|
9
8
|
prefix: Uint8Array;
|
|
10
9
|
expectedKeyLength?: number;
|
|
11
10
|
}>;
|
|
11
|
+
export type ReallyMeMulticodecLookupResult = Readonly<{
|
|
12
|
+
name: string;
|
|
13
|
+
prefixLength: number;
|
|
14
|
+
metadata: ReallyMeMulticodecMetadata;
|
|
15
|
+
}>;
|
|
16
|
+
export type ReallyMeMulticodecTable = Readonly<{
|
|
17
|
+
entries: ReadonlyArray<ReallyMeMulticodecMetadata>;
|
|
18
|
+
}>;
|
|
12
19
|
export type ReallyMeParsedMultikey = Readonly<{
|
|
13
20
|
codecName: string;
|
|
14
21
|
algorithmName: string;
|
|
15
22
|
publicKey: Uint8Array;
|
|
16
23
|
expectedPublicKeyLength?: number;
|
|
17
24
|
}>;
|
|
18
|
-
export declare const readMulticodecMetadata: (value: unknown) => ReallyMeMulticodecMetadata;
|
|
19
25
|
export declare const base58btcEncode: (bytes: Uint8Array) => string;
|
|
20
26
|
export declare const base58btcDecode: (encoded: string) => Uint8Array;
|
|
21
27
|
export declare const multibaseBase64urlEncode: (bytes: Uint8Array) => string;
|
|
22
28
|
export declare const multibaseBase58btcEncode: (bytes: Uint8Array) => string;
|
|
23
29
|
export declare const multibaseDecode: (encoded: string) => Uint8Array;
|
|
24
30
|
export declare const multicodecPrefixForName: (codecName: string) => ReallyMeMulticodecMetadata;
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const multicodecPrefixForNameProtoResult: (codecName: string) => ReallyMeCodecProtoResult;
|
|
27
|
-
export declare const multicodecLookupPrefix: (bytes: Uint8Array) => ReallyMeMulticodecMetadata;
|
|
28
|
-
export declare const multicodecLookupPrefixProto: (bytes: Uint8Array) => Uint8Array;
|
|
29
|
-
export declare const multicodecLookupPrefixProtoResult: (bytes: Uint8Array) => ReallyMeCodecProtoResult;
|
|
31
|
+
export declare const multicodecLookupPrefix: (bytes: Uint8Array) => ReallyMeMulticodecLookupResult;
|
|
30
32
|
export declare const multicodecStripPrefix: (bytes: Uint8Array) => Uint8Array;
|
|
31
|
-
export declare const multicodecTable: () =>
|
|
32
|
-
export declare const multicodecTableProto: () => Uint8Array;
|
|
33
|
-
export declare const multicodecTableProtoResult: () => ReallyMeCodecProtoResult;
|
|
33
|
+
export declare const multicodecTable: () => ReallyMeMulticodecTable;
|
|
34
34
|
export declare const multikeyEncode: (codecName: string, publicKey: Uint8Array) => string;
|
|
35
35
|
export declare const multikeyParse: (multikey: string) => ReallyMeParsedMultikey;
|
|
36
|
-
export declare const multikeyParseProto: (multikey: string) => Uint8Array;
|
|
37
|
-
export declare const multikeyParseProtoResult: (multikey: string) => ReallyMeCodecProtoResult;
|
|
38
36
|
export declare const bindingTypeMatchesCodec: (bindingType: string, codecName: string) => boolean;
|
|
39
37
|
export declare const validateKeyBinding: (bindingType: string, algorithm: string | undefined, multikey: string) => void;
|
|
40
38
|
export declare const requireSupportedMulticodec: (codecName: string) => void;
|
package/dist/multiformat.js
CHANGED
|
@@ -3,106 +3,66 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { create } from "@bufbuild/protobuf";
|
|
5
5
|
import { ReallyMeCodecError } from "./errors.js";
|
|
6
|
-
import { CodecMulticodecLookupPrefixRequestSchema, CodecMulticodecPrefixForNameRequestSchema, CodecMulticodecTableRequestSchema, CodecMultikeyParseRequestSchema, CodecOperationRequestSchema, } from "./proto/generated/reallyme/codec/v1/codec_pb.js";
|
|
7
|
-
import {
|
|
8
|
-
import { ensureBytesInput, ensureStringInput, ensureStringValue, readBooleanOutput, readBytesOutput,
|
|
6
|
+
import { CodecMulticodecLookupPrefixRequestSchema, CodecMulticodecPrefixForNameRequestSchema, CodecMulticodecTableRequestSchema, CodecMultikeyParseRequestSchema, CodecOperationRequestSchema, CodecKeyMaterialKind, CodecTag, } from "./proto/generated/reallyme/codec/v1/codec_pb.js";
|
|
7
|
+
import { clearGeneratedOperationResult, processGeneratedOperationRequest, } from "./operationContract.js";
|
|
8
|
+
import { ensureBytesInput, ensureStringInput, ensureStringValue, readBooleanOutput, readBytesOutput, readStringOutput, snapshotBoundedBytesInput, } from "./readOutput.js";
|
|
9
9
|
import { requireReallyMeCodecWasmProvider } from "./wasmProvider.js";
|
|
10
|
-
const validTags = new Set([
|
|
11
|
-
"encryption",
|
|
12
|
-
"hash",
|
|
13
|
-
"key",
|
|
14
|
-
"multihash",
|
|
15
|
-
"multikey",
|
|
16
|
-
]);
|
|
17
|
-
const validKeyMaterialKinds = new Set([
|
|
18
|
-
"not-key",
|
|
19
|
-
"public-key",
|
|
20
|
-
"private-key",
|
|
21
|
-
"symmetric-key",
|
|
22
|
-
]);
|
|
23
10
|
const MAX_MULTICODEC_TABLE_ENTRIES = 1_024;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
if (!validTags.has(tag)) {
|
|
11
|
+
const requireNoProviderUnknownFields = (message) => {
|
|
12
|
+
if (message.$unknown !== undefined && message.$unknown.length !== 0) {
|
|
27
13
|
throw new ReallyMeCodecError("provider-failure");
|
|
28
14
|
}
|
|
15
|
+
};
|
|
16
|
+
const sdkTag = (tag) => {
|
|
29
17
|
switch (tag) {
|
|
30
|
-
case
|
|
31
|
-
|
|
32
|
-
case
|
|
33
|
-
|
|
34
|
-
case
|
|
35
|
-
return
|
|
18
|
+
case CodecTag.ENCRYPTION:
|
|
19
|
+
return "encryption";
|
|
20
|
+
case CodecTag.HASH:
|
|
21
|
+
return "hash";
|
|
22
|
+
case CodecTag.KEY:
|
|
23
|
+
return "key";
|
|
24
|
+
case CodecTag.MULTIHASH:
|
|
25
|
+
return "multihash";
|
|
26
|
+
case CodecTag.MULTIKEY:
|
|
27
|
+
return "multikey";
|
|
28
|
+
case CodecTag.UNSPECIFIED:
|
|
36
29
|
default:
|
|
37
30
|
throw new ReallyMeCodecError("provider-failure");
|
|
38
31
|
}
|
|
39
32
|
};
|
|
40
|
-
const
|
|
41
|
-
const keyMaterial = readStringProperty(object, "keyMaterial");
|
|
42
|
-
if (!validKeyMaterialKinds.has(keyMaterial)) {
|
|
43
|
-
throw new ReallyMeCodecError("provider-failure");
|
|
44
|
-
}
|
|
33
|
+
const sdkKeyMaterial = (keyMaterial) => {
|
|
45
34
|
switch (keyMaterial) {
|
|
46
|
-
case
|
|
47
|
-
|
|
48
|
-
case
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
case CodecKeyMaterialKind.NOT_KEY:
|
|
36
|
+
return "not-key";
|
|
37
|
+
case CodecKeyMaterialKind.PUBLIC_KEY:
|
|
38
|
+
return "public-key";
|
|
39
|
+
case CodecKeyMaterialKind.PRIVATE_KEY:
|
|
40
|
+
return "private-key";
|
|
41
|
+
case CodecKeyMaterialKind.SYMMETRIC_KEY:
|
|
42
|
+
return "symmetric-key";
|
|
43
|
+
case CodecKeyMaterialKind.UNSPECIFIED:
|
|
51
44
|
default:
|
|
52
45
|
throw new ReallyMeCodecError("provider-failure");
|
|
53
46
|
}
|
|
54
47
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const expectedKeyLength = readOptionalLengthProperty(object, "expectedKeyLength");
|
|
48
|
+
const readMulticodecMetadata = (value) => {
|
|
49
|
+
validateMulticodecMetadata(value);
|
|
58
50
|
const metadata = {
|
|
59
|
-
name:
|
|
60
|
-
alg:
|
|
61
|
-
tag:
|
|
62
|
-
keyMaterial:
|
|
63
|
-
prefix:
|
|
51
|
+
name: value.name,
|
|
52
|
+
alg: value.algorithmName,
|
|
53
|
+
tag: sdkTag(value.tag),
|
|
54
|
+
keyMaterial: sdkKeyMaterial(value.keyMaterialKind),
|
|
55
|
+
prefix: value.prefix.slice(),
|
|
64
56
|
};
|
|
65
|
-
if (
|
|
57
|
+
if (value.variableLength || value.fixedLength === 0) {
|
|
66
58
|
return metadata;
|
|
67
59
|
}
|
|
68
|
-
return { ...metadata, expectedKeyLength };
|
|
69
|
-
};
|
|
70
|
-
const readParsedMultikey = (value) => {
|
|
71
|
-
const object = readObjectOutput(value);
|
|
72
|
-
const expectedPublicKeyLength = readOptionalLengthProperty(object, "expectedPublicKeyLength");
|
|
73
|
-
const parsed = {
|
|
74
|
-
codecName: readStringProperty(object, "codecName"),
|
|
75
|
-
algorithmName: readStringProperty(object, "algorithmName"),
|
|
76
|
-
publicKey: readBytesProperty(object, "publicKey"),
|
|
77
|
-
};
|
|
78
|
-
if (expectedPublicKeyLength === undefined) {
|
|
79
|
-
return parsed;
|
|
80
|
-
}
|
|
81
|
-
return { ...parsed, expectedPublicKeyLength };
|
|
60
|
+
return { ...metadata, expectedKeyLength: value.fixedLength };
|
|
82
61
|
};
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
value.length > MAX_MULTICODEC_TABLE_ENTRIES) {
|
|
88
|
-
throw new ReallyMeCodecError("provider-failure");
|
|
89
|
-
}
|
|
90
|
-
const table = [];
|
|
91
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
92
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
93
|
-
if (descriptor === undefined || !("value" in descriptor)) {
|
|
94
|
-
throw new ReallyMeCodecError("provider-failure");
|
|
95
|
-
}
|
|
96
|
-
table.push(readMulticodecMetadata(descriptor.value));
|
|
97
|
-
}
|
|
98
|
-
return table;
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (error instanceof ReallyMeCodecError) {
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
throw new ReallyMeCodecError("provider-failure");
|
|
105
|
-
}
|
|
62
|
+
const validateMulticodecMetadata = (value) => {
|
|
63
|
+
requireNoProviderUnknownFields(value);
|
|
64
|
+
sdkTag(value.tag);
|
|
65
|
+
sdkKeyMaterial(value.keyMaterialKind);
|
|
106
66
|
};
|
|
107
67
|
export const base58btcEncode = (bytes) => {
|
|
108
68
|
ensureBytesInput(bytes);
|
|
@@ -126,52 +86,99 @@ export const multibaseDecode = (encoded) => {
|
|
|
126
86
|
};
|
|
127
87
|
export const multicodecPrefixForName = (codecName) => {
|
|
128
88
|
ensureStringInput(codecName);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
name: codecName,
|
|
141
|
-
}),
|
|
142
|
-
},
|
|
143
|
-
}));
|
|
89
|
+
const result = processGeneratedOperationRequest(multicodecPrefixForNameRequest(codecName));
|
|
90
|
+
if (result.result.case !== "multicodecPrefixForName") {
|
|
91
|
+
clearGeneratedOperationResult(result);
|
|
92
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
return readMulticodecMetadata(result.result.value);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
result.result.value.prefix.fill(0);
|
|
99
|
+
}
|
|
144
100
|
};
|
|
101
|
+
const multicodecPrefixForNameRequest = (codecName) => create(CodecOperationRequestSchema, {
|
|
102
|
+
operation: {
|
|
103
|
+
case: "multicodecPrefixForName",
|
|
104
|
+
value: create(CodecMulticodecPrefixForNameRequestSchema, {
|
|
105
|
+
name: codecName,
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
});
|
|
145
109
|
export const multicodecLookupPrefix = (bytes) => {
|
|
146
110
|
ensureBytesInput(bytes);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
111
|
+
const bytesSnapshot = snapshotBoundedBytesInput(bytes);
|
|
112
|
+
try {
|
|
113
|
+
const operationResult = processGeneratedOperationRequest(multicodecLookupPrefixRequest(bytesSnapshot));
|
|
114
|
+
if (operationResult.result.case !== "multicodecLookupPrefix") {
|
|
115
|
+
clearGeneratedOperationResult(operationResult);
|
|
116
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
117
|
+
}
|
|
118
|
+
const result = operationResult.result.value;
|
|
119
|
+
try {
|
|
120
|
+
requireNoProviderUnknownFields(result);
|
|
121
|
+
if (result.metadata === undefined) {
|
|
122
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
name: result.name,
|
|
126
|
+
prefixLength: result.prefixLength,
|
|
127
|
+
metadata: readMulticodecMetadata(result.metadata),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
result.metadata?.prefix.fill(0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
bytesSnapshot.fill(0);
|
|
136
|
+
}
|
|
162
137
|
};
|
|
138
|
+
const multicodecLookupPrefixRequest = (bytes) => create(CodecOperationRequestSchema, {
|
|
139
|
+
operation: {
|
|
140
|
+
case: "multicodecLookupPrefix",
|
|
141
|
+
value: create(CodecMulticodecLookupPrefixRequestSchema, {
|
|
142
|
+
value: bytes,
|
|
143
|
+
}),
|
|
144
|
+
},
|
|
145
|
+
});
|
|
163
146
|
export const multicodecStripPrefix = (bytes) => {
|
|
164
147
|
ensureBytesInput(bytes);
|
|
165
148
|
return readBytesOutput(requireReallyMeCodecWasmProvider().multicodecStripPrefix(bytes));
|
|
166
149
|
};
|
|
167
|
-
export const multicodecTable = () =>
|
|
168
|
-
|
|
169
|
-
|
|
150
|
+
export const multicodecTable = () => {
|
|
151
|
+
const operationResult = processGeneratedOperationRequest(multicodecTableRequest());
|
|
152
|
+
if (operationResult.result.case !== "multicodecTable") {
|
|
153
|
+
clearGeneratedOperationResult(operationResult);
|
|
154
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
155
|
+
}
|
|
156
|
+
const result = operationResult.result.value;
|
|
157
|
+
try {
|
|
158
|
+
requireNoProviderUnknownFields(result);
|
|
159
|
+
if (result.entries.length > MAX_MULTICODEC_TABLE_ENTRIES) {
|
|
160
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
161
|
+
}
|
|
162
|
+
// Validate every entry before making caller-owned byte copies. If one
|
|
163
|
+
// entry is malformed, no earlier prefix copy can become unreachable
|
|
164
|
+
// without an explicit wipe while the generated response is rejected.
|
|
165
|
+
for (const entry of result.entries) {
|
|
166
|
+
validateMulticodecMetadata(entry);
|
|
167
|
+
}
|
|
168
|
+
return { entries: result.entries.map((entry) => readMulticodecMetadata(entry)) };
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
for (const entry of result.entries) {
|
|
172
|
+
entry.prefix.fill(0);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const multicodecTableRequest = () => create(CodecOperationRequestSchema, {
|
|
170
177
|
operation: {
|
|
171
178
|
case: "multicodecTable",
|
|
172
179
|
value: create(CodecMulticodecTableRequestSchema),
|
|
173
180
|
},
|
|
174
|
-
})
|
|
181
|
+
});
|
|
175
182
|
export const multikeyEncode = (codecName, publicKey) => {
|
|
176
183
|
ensureStringInput(codecName);
|
|
177
184
|
ensureBytesInput(publicKey);
|
|
@@ -179,20 +186,34 @@ export const multikeyEncode = (codecName, publicKey) => {
|
|
|
179
186
|
};
|
|
180
187
|
export const multikeyParse = (multikey) => {
|
|
181
188
|
ensureStringInput(multikey);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
const operationResult = processGeneratedOperationRequest(multikeyParseRequest(multikey));
|
|
190
|
+
if (operationResult.result.case !== "multikeyParse") {
|
|
191
|
+
clearGeneratedOperationResult(operationResult);
|
|
192
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
193
|
+
}
|
|
194
|
+
const result = operationResult.result.value;
|
|
195
|
+
try {
|
|
196
|
+
requireNoProviderUnknownFields(result);
|
|
197
|
+
const parsed = {
|
|
198
|
+
codecName: result.codecName,
|
|
199
|
+
algorithmName: result.algorithmName,
|
|
200
|
+
publicKey: result.publicKey.slice(),
|
|
201
|
+
};
|
|
202
|
+
if (result.variablePublicKeyLength || result.expectedPublicKeyLength === 0) {
|
|
203
|
+
return parsed;
|
|
204
|
+
}
|
|
205
|
+
return { ...parsed, expectedPublicKeyLength: result.expectedPublicKeyLength };
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
result.publicKey.fill(0);
|
|
209
|
+
}
|
|
195
210
|
};
|
|
211
|
+
const multikeyParseRequest = (multikey) => create(CodecOperationRequestSchema, {
|
|
212
|
+
operation: {
|
|
213
|
+
case: "multikeyParse",
|
|
214
|
+
value: create(CodecMultikeyParseRequestSchema, { multikey }),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
196
217
|
export const bindingTypeMatchesCodec = (bindingType, codecName) => {
|
|
197
218
|
ensureStringInput(bindingType);
|
|
198
219
|
ensureStringInput(codecName);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CodecOperationRequest, CodecOperationResult } from "./proto/generated/reallyme/codec/v1/codec_pb.js";
|
|
2
|
+
/**
|
|
3
|
+
* Execute one binary generated-protobuf request and return the fully
|
|
4
|
+
* discriminated binary `CodecOperationResponse`.
|
|
5
|
+
*
|
|
6
|
+
* Oversized requests are rejected before the provider call. Malformed and
|
|
7
|
+
* unsupported in-limit requests are represented by the response error oneof
|
|
8
|
+
* rather than a boundary-local exception.
|
|
9
|
+
*/
|
|
10
|
+
export declare const processOperation: (requestBytes: Uint8Array) => Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Execute one generated ProtoJSON request and return the same discriminated
|
|
13
|
+
* binary response used by `processOperation`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const processOperationJson: (requestJson: Uint8Array) => Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a generated request through the fully discriminated response lane.
|
|
18
|
+
*
|
|
19
|
+
* Structured convenience methods use this boundary so a provider cannot
|
|
20
|
+
* return a valid payload of the wrong operation-specific result type.
|
|
21
|
+
*/
|
|
22
|
+
export declare const processGeneratedOperationRequest: (request: CodecOperationRequest) => CodecOperationResult;
|
|
23
|
+
/**
|
|
24
|
+
* Clears mutable byte owners held by a generated operation result.
|
|
25
|
+
*
|
|
26
|
+
* Callers invoke this before rejecting an unexpected valid oneof variant and
|
|
27
|
+
* after copying a sensitive result into its public SDK owner. JavaScript
|
|
28
|
+
* strings remain subject to the managed-runtime memory model, but every
|
|
29
|
+
* mutable `Uint8Array` created by this adapter is released promptly.
|
|
30
|
+
*/
|
|
31
|
+
export declare const clearGeneratedOperationResult: (result: CodecOperationResult) => void;
|