@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.
- package/LICENSE +201 -0
- package/README.md +54 -0
- package/dist/baseEncoding.d.ts +7 -0
- package/dist/baseEncoding.js +33 -0
- package/dist/cbor.d.ts +42 -0
- package/dist/cbor.js +189 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +11 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +63 -0
- package/dist/jcs.d.ts +2 -0
- package/dist/jcs.js +71 -0
- package/dist/multiformat.d.ts +40 -0
- package/dist/multiformat.js +169 -0
- package/dist/pem.d.ts +21 -0
- package/dist/pem.js +88 -0
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.d.ts +492 -0
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.js +256 -0
- package/dist/proto.d.ts +2 -0
- package/dist/proto.js +4 -0
- package/dist/readOutput.d.ts +21 -0
- package/dist/readOutput.js +109 -0
- package/dist/wasm/LICENSE +17 -0
- package/dist/wasm/reallyme_codec_wasm.d.ts +302 -0
- package/dist/wasm/reallyme_codec_wasm.js +984 -0
- package/dist/wasm/reallyme_codec_wasm_bg.wasm +0 -0
- package/dist/wasmProvider.d.ts +67 -0
- package/dist/wasmProvider.js +178 -0
- package/package.json +47 -0
|
Binary file
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
type BytesToStringFn = (bytes: Uint8Array) => unknown;
|
|
2
|
+
type StringToBytesFn = (text: string) => unknown;
|
|
3
|
+
type StringToStringFn = (text: string) => unknown;
|
|
4
|
+
type StringToObjectFn = (text: string) => unknown;
|
|
5
|
+
type BytesToObjectFn = (bytes: Uint8Array) => unknown;
|
|
6
|
+
type BytesToBytesFn = (bytes: Uint8Array) => unknown;
|
|
7
|
+
type StringBytesToStringFn = (text: string, bytes: Uint8Array) => unknown;
|
|
8
|
+
type StringToBooleanFn = (text: string) => unknown;
|
|
9
|
+
type StringStringToBooleanFn = (left: string, right: string) => unknown;
|
|
10
|
+
type ValidateKeyBindingFn = (bindingType: string, algorithm: string | undefined, multikey: string) => unknown;
|
|
11
|
+
type PemDecodeFn = (input: string, optionsJson: string) => unknown;
|
|
12
|
+
type PemEncodeFn = (label: string, der: Uint8Array, optionsJson: string) => unknown;
|
|
13
|
+
type Function0 = () => unknown;
|
|
14
|
+
type StringToObjectOutputFn = (text: string) => unknown;
|
|
15
|
+
type BytesToObjectOutputFn = (bytes: Uint8Array) => unknown;
|
|
16
|
+
type StringBytesToObjectOutputFn = (text: string, bytes: Uint8Array) => unknown;
|
|
17
|
+
type PemDecodeObjectOutputFn = (input: string, optionsJson: string) => unknown;
|
|
18
|
+
export declare const REALLYME_CODEC_WASM_EXPORTS: readonly ["base64Decode", "base64Encode", "base64urlDecode", "base64urlEncode", "bytesToLowerHex", "lowerHexToBytes", "base58btcDecode", "base58btcEncode", "multibaseBase58btcEncode", "multibaseBase64urlEncode", "multibaseDecode", "multicodecLookupPrefix", "multicodecLookupPrefixProto", "multicodecLookupPrefixProtoResult", "multicodecPrefixForName", "multicodecPrefixForNameProto", "multicodecPrefixForNameProtoResult", "multicodecStripPrefix", "multicodecTable", "multicodecTableProto", "multicodecTableProtoResult", "multikeyEncode", "multikeyParse", "multikeyParseProto", "multikeyParseProtoResult", "bindingTypeMatchesCodec", "validateKeyBinding", "requireSupportedMulticodec", "dagCborCodecCode", "dagCborComputeCid", "dagCborDecode", "dagCborEncode", "dagCborMultihash", "dagCborSha256ContentHash", "dagCborVerifyCid", "dagCborVerifyCidProto", "dagCborVerifyCidProtoResult", "isValidCidString", "tryParseCid", "canonicalizeJson", "pemDecode", "pemDecodeProto", "pemDecodeProtoResult", "pemEncode"];
|
|
19
|
+
export type ReallyMeCodecWasmProvider = Readonly<{
|
|
20
|
+
base64Decode: StringToBytesFn;
|
|
21
|
+
base64Encode: BytesToStringFn;
|
|
22
|
+
base64urlDecode: StringToBytesFn;
|
|
23
|
+
base64urlEncode: BytesToStringFn;
|
|
24
|
+
bytesToLowerHex: BytesToStringFn;
|
|
25
|
+
lowerHexToBytes: StringToBytesFn;
|
|
26
|
+
base58btcDecode: StringToBytesFn;
|
|
27
|
+
base58btcEncode: BytesToStringFn;
|
|
28
|
+
multibaseBase58btcEncode: BytesToStringFn;
|
|
29
|
+
multibaseBase64urlEncode: BytesToStringFn;
|
|
30
|
+
multibaseDecode: StringToBytesFn;
|
|
31
|
+
multicodecLookupPrefix: BytesToObjectFn;
|
|
32
|
+
multicodecLookupPrefixProto: BytesToBytesFn;
|
|
33
|
+
multicodecLookupPrefixProtoResult: BytesToObjectOutputFn;
|
|
34
|
+
multicodecPrefixForName: StringToObjectFn;
|
|
35
|
+
multicodecPrefixForNameProto: StringToBytesFn;
|
|
36
|
+
multicodecPrefixForNameProtoResult: StringToObjectOutputFn;
|
|
37
|
+
multicodecStripPrefix: BytesToBytesFn;
|
|
38
|
+
multicodecTable: Function0;
|
|
39
|
+
multicodecTableProto: Function0;
|
|
40
|
+
multicodecTableProtoResult: Function0;
|
|
41
|
+
multikeyEncode: StringBytesToStringFn;
|
|
42
|
+
multikeyParse: StringToObjectFn;
|
|
43
|
+
multikeyParseProto: StringToBytesFn;
|
|
44
|
+
multikeyParseProtoResult: StringToObjectOutputFn;
|
|
45
|
+
bindingTypeMatchesCodec: StringStringToBooleanFn;
|
|
46
|
+
validateKeyBinding: ValidateKeyBindingFn;
|
|
47
|
+
requireSupportedMulticodec: StringToStringFn;
|
|
48
|
+
dagCborCodecCode: Function0;
|
|
49
|
+
dagCborComputeCid: BytesToStringFn;
|
|
50
|
+
dagCborDecode: BytesToStringFn;
|
|
51
|
+
dagCborEncode: StringToBytesFn;
|
|
52
|
+
dagCborMultihash: BytesToBytesFn;
|
|
53
|
+
dagCborSha256ContentHash: BytesToBytesFn;
|
|
54
|
+
dagCborVerifyCid: StringBytesToStringFn;
|
|
55
|
+
dagCborVerifyCidProto: StringBytesToStringFn;
|
|
56
|
+
dagCborVerifyCidProtoResult: StringBytesToObjectOutputFn;
|
|
57
|
+
isValidCidString: StringToBooleanFn;
|
|
58
|
+
tryParseCid: StringToObjectFn;
|
|
59
|
+
canonicalizeJson: StringToStringFn;
|
|
60
|
+
pemDecode: PemDecodeFn;
|
|
61
|
+
pemDecodeProto: PemDecodeFn;
|
|
62
|
+
pemDecodeProtoResult: PemDecodeObjectOutputFn;
|
|
63
|
+
pemEncode: PemEncodeFn;
|
|
64
|
+
}>;
|
|
65
|
+
export declare const installReallyMeCodecWasmProvider: (module: unknown) => void;
|
|
66
|
+
export declare const requireReallyMeCodecWasmProvider: () => ReallyMeCodecWasmProvider;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { ReallyMeCodecError } from "./errors.js";
|
|
5
|
+
export const REALLYME_CODEC_WASM_EXPORTS = [
|
|
6
|
+
"base64Decode",
|
|
7
|
+
"base64Encode",
|
|
8
|
+
"base64urlDecode",
|
|
9
|
+
"base64urlEncode",
|
|
10
|
+
"bytesToLowerHex",
|
|
11
|
+
"lowerHexToBytes",
|
|
12
|
+
"base58btcDecode",
|
|
13
|
+
"base58btcEncode",
|
|
14
|
+
"multibaseBase58btcEncode",
|
|
15
|
+
"multibaseBase64urlEncode",
|
|
16
|
+
"multibaseDecode",
|
|
17
|
+
"multicodecLookupPrefix",
|
|
18
|
+
"multicodecLookupPrefixProto",
|
|
19
|
+
"multicodecLookupPrefixProtoResult",
|
|
20
|
+
"multicodecPrefixForName",
|
|
21
|
+
"multicodecPrefixForNameProto",
|
|
22
|
+
"multicodecPrefixForNameProtoResult",
|
|
23
|
+
"multicodecStripPrefix",
|
|
24
|
+
"multicodecTable",
|
|
25
|
+
"multicodecTableProto",
|
|
26
|
+
"multicodecTableProtoResult",
|
|
27
|
+
"multikeyEncode",
|
|
28
|
+
"multikeyParse",
|
|
29
|
+
"multikeyParseProto",
|
|
30
|
+
"multikeyParseProtoResult",
|
|
31
|
+
"bindingTypeMatchesCodec",
|
|
32
|
+
"validateKeyBinding",
|
|
33
|
+
"requireSupportedMulticodec",
|
|
34
|
+
"dagCborCodecCode",
|
|
35
|
+
"dagCborComputeCid",
|
|
36
|
+
"dagCborDecode",
|
|
37
|
+
"dagCborEncode",
|
|
38
|
+
"dagCborMultihash",
|
|
39
|
+
"dagCborSha256ContentHash",
|
|
40
|
+
"dagCborVerifyCid",
|
|
41
|
+
"dagCborVerifyCidProto",
|
|
42
|
+
"dagCborVerifyCidProtoResult",
|
|
43
|
+
"isValidCidString",
|
|
44
|
+
"tryParseCid",
|
|
45
|
+
"canonicalizeJson",
|
|
46
|
+
"pemDecode",
|
|
47
|
+
"pemDecodeProto",
|
|
48
|
+
"pemDecodeProtoResult",
|
|
49
|
+
"pemEncode",
|
|
50
|
+
];
|
|
51
|
+
let installedProvider;
|
|
52
|
+
const wasmErrorCode = (error) => {
|
|
53
|
+
switch (error) {
|
|
54
|
+
case "invalid-input":
|
|
55
|
+
return "invalid-input";
|
|
56
|
+
case "non-canonical":
|
|
57
|
+
return "non-canonical";
|
|
58
|
+
case "unsupported-codec":
|
|
59
|
+
return "unsupported-codec";
|
|
60
|
+
case "provider-failure":
|
|
61
|
+
default:
|
|
62
|
+
return "provider-failure";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const requireObject = (module) => {
|
|
66
|
+
if (typeof module !== "object" || module === null) {
|
|
67
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
68
|
+
}
|
|
69
|
+
return module;
|
|
70
|
+
};
|
|
71
|
+
const requireFunction = (module, name) => {
|
|
72
|
+
const candidate = Reflect.get(module, name);
|
|
73
|
+
if (typeof candidate !== "function") {
|
|
74
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
75
|
+
}
|
|
76
|
+
return (...args) => {
|
|
77
|
+
try {
|
|
78
|
+
return candidate(...args);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new ReallyMeCodecError(wasmErrorCode(error));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
const function0 = (module, name) => {
|
|
86
|
+
const callable = requireFunction(module, name);
|
|
87
|
+
return () => callable();
|
|
88
|
+
};
|
|
89
|
+
const stringFunction1 = (module, name) => {
|
|
90
|
+
const callable = requireFunction(module, name);
|
|
91
|
+
return (text) => callable(text);
|
|
92
|
+
};
|
|
93
|
+
const bytesFunction1 = (module, name) => {
|
|
94
|
+
const callable = requireFunction(module, name);
|
|
95
|
+
return (bytes) => callable(bytes);
|
|
96
|
+
};
|
|
97
|
+
const stringBytesFunction2 = (module, name) => {
|
|
98
|
+
const callable = requireFunction(module, name);
|
|
99
|
+
return (text, bytes) => callable(text, bytes);
|
|
100
|
+
};
|
|
101
|
+
const stringStringBooleanFunction = (module, name) => {
|
|
102
|
+
const callable = requireFunction(module, name);
|
|
103
|
+
return (left, right) => callable(left, right);
|
|
104
|
+
};
|
|
105
|
+
const stringBooleanFunction = (module, name) => {
|
|
106
|
+
const callable = requireFunction(module, name);
|
|
107
|
+
return (text) => callable(text);
|
|
108
|
+
};
|
|
109
|
+
const validateKeyBindingFunction = (module, name) => {
|
|
110
|
+
const callable = requireFunction(module, name);
|
|
111
|
+
return (bindingType, algorithm, multikey) => callable(bindingType, algorithm, multikey);
|
|
112
|
+
};
|
|
113
|
+
const pemDecodeFunction = (module, name) => {
|
|
114
|
+
const callable = requireFunction(module, name);
|
|
115
|
+
return (input, optionsJson) => callable(input, optionsJson);
|
|
116
|
+
};
|
|
117
|
+
const pemEncodeFunction = (module, name) => {
|
|
118
|
+
const callable = requireFunction(module, name);
|
|
119
|
+
return (label, der, optionsJson) => callable(label, der, optionsJson);
|
|
120
|
+
};
|
|
121
|
+
export const installReallyMeCodecWasmProvider = (module) => {
|
|
122
|
+
if (installedProvider !== undefined) {
|
|
123
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
124
|
+
}
|
|
125
|
+
const providerModule = requireObject(module);
|
|
126
|
+
installedProvider = {
|
|
127
|
+
base64Decode: stringFunction1(providerModule, "base64Decode"),
|
|
128
|
+
base64Encode: bytesFunction1(providerModule, "base64Encode"),
|
|
129
|
+
base64urlDecode: stringFunction1(providerModule, "base64urlDecode"),
|
|
130
|
+
base64urlEncode: bytesFunction1(providerModule, "base64urlEncode"),
|
|
131
|
+
bytesToLowerHex: bytesFunction1(providerModule, "bytesToLowerHex"),
|
|
132
|
+
lowerHexToBytes: stringFunction1(providerModule, "lowerHexToBytes"),
|
|
133
|
+
base58btcDecode: stringFunction1(providerModule, "base58btcDecode"),
|
|
134
|
+
base58btcEncode: bytesFunction1(providerModule, "base58btcEncode"),
|
|
135
|
+
multibaseBase58btcEncode: bytesFunction1(providerModule, "multibaseBase58btcEncode"),
|
|
136
|
+
multibaseBase64urlEncode: bytesFunction1(providerModule, "multibaseBase64urlEncode"),
|
|
137
|
+
multibaseDecode: stringFunction1(providerModule, "multibaseDecode"),
|
|
138
|
+
multicodecLookupPrefix: bytesFunction1(providerModule, "multicodecLookupPrefix"),
|
|
139
|
+
multicodecLookupPrefixProto: bytesFunction1(providerModule, "multicodecLookupPrefixProto"),
|
|
140
|
+
multicodecLookupPrefixProtoResult: bytesFunction1(providerModule, "multicodecLookupPrefixProtoResult"),
|
|
141
|
+
multicodecPrefixForName: stringFunction1(providerModule, "multicodecPrefixForName"),
|
|
142
|
+
multicodecPrefixForNameProto: stringFunction1(providerModule, "multicodecPrefixForNameProto"),
|
|
143
|
+
multicodecPrefixForNameProtoResult: stringFunction1(providerModule, "multicodecPrefixForNameProtoResult"),
|
|
144
|
+
multicodecStripPrefix: bytesFunction1(providerModule, "multicodecStripPrefix"),
|
|
145
|
+
multicodecTable: function0(providerModule, "multicodecTable"),
|
|
146
|
+
multicodecTableProto: function0(providerModule, "multicodecTableProto"),
|
|
147
|
+
multicodecTableProtoResult: function0(providerModule, "multicodecTableProtoResult"),
|
|
148
|
+
multikeyEncode: stringBytesFunction2(providerModule, "multikeyEncode"),
|
|
149
|
+
multikeyParse: stringFunction1(providerModule, "multikeyParse"),
|
|
150
|
+
multikeyParseProto: stringFunction1(providerModule, "multikeyParseProto"),
|
|
151
|
+
multikeyParseProtoResult: stringFunction1(providerModule, "multikeyParseProtoResult"),
|
|
152
|
+
bindingTypeMatchesCodec: stringStringBooleanFunction(providerModule, "bindingTypeMatchesCodec"),
|
|
153
|
+
validateKeyBinding: validateKeyBindingFunction(providerModule, "validateKeyBinding"),
|
|
154
|
+
requireSupportedMulticodec: stringFunction1(providerModule, "requireSupportedMulticodec"),
|
|
155
|
+
dagCborCodecCode: function0(providerModule, "dagCborCodecCode"),
|
|
156
|
+
dagCborComputeCid: bytesFunction1(providerModule, "dagCborComputeCid"),
|
|
157
|
+
dagCborDecode: bytesFunction1(providerModule, "dagCborDecode"),
|
|
158
|
+
dagCborEncode: stringFunction1(providerModule, "dagCborEncode"),
|
|
159
|
+
dagCborMultihash: bytesFunction1(providerModule, "dagCborMultihash"),
|
|
160
|
+
dagCborSha256ContentHash: bytesFunction1(providerModule, "dagCborSha256ContentHash"),
|
|
161
|
+
dagCborVerifyCid: stringBytesFunction2(providerModule, "dagCborVerifyCid"),
|
|
162
|
+
dagCborVerifyCidProto: stringBytesFunction2(providerModule, "dagCborVerifyCidProto"),
|
|
163
|
+
dagCborVerifyCidProtoResult: stringBytesFunction2(providerModule, "dagCborVerifyCidProtoResult"),
|
|
164
|
+
isValidCidString: stringBooleanFunction(providerModule, "isValidCidString"),
|
|
165
|
+
tryParseCid: stringFunction1(providerModule, "tryParseCid"),
|
|
166
|
+
canonicalizeJson: stringFunction1(providerModule, "canonicalizeJson"),
|
|
167
|
+
pemDecode: pemDecodeFunction(providerModule, "pemDecode"),
|
|
168
|
+
pemDecodeProto: pemDecodeFunction(providerModule, "pemDecodeProto"),
|
|
169
|
+
pemDecodeProtoResult: pemDecodeFunction(providerModule, "pemDecodeProtoResult"),
|
|
170
|
+
pemEncode: pemEncodeFunction(providerModule, "pemEncode"),
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
export const requireReallyMeCodecWasmProvider = () => {
|
|
174
|
+
if (installedProvider === undefined) {
|
|
175
|
+
throw new ReallyMeCodecError("provider-failure");
|
|
176
|
+
}
|
|
177
|
+
return installedProvider;
|
|
178
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reallyme/codec",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "TypeScript facade for the ReallyMe codec WASM package.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./proto": {
|
|
16
|
+
"types": "./dist/proto.d.ts",
|
|
17
|
+
"default": "./dist/proto.js"
|
|
18
|
+
},
|
|
19
|
+
"./wasm/reallyme_codec_wasm.js": {
|
|
20
|
+
"types": "./dist/wasm/reallyme_codec_wasm.d.ts",
|
|
21
|
+
"default": "./dist/wasm/reallyme_codec_wasm.js"
|
|
22
|
+
},
|
|
23
|
+
"./wasm/reallyme_codec_wasm_bg.wasm": {
|
|
24
|
+
"default": "./dist/wasm/reallyme_codec_wasm_bg.wasm"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "node scripts/clean-dist.mjs && npm run build:wasm && tsc",
|
|
34
|
+
"build:wasm": "node scripts/build-wasm.mjs",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"test": "npm run build && node --test \"test/*.test.mjs\""
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@bufbuild/protobuf": "2.12.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "5.8.3"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20.19.0"
|
|
46
|
+
}
|
|
47
|
+
}
|