@reallyme/crypto 0.3.17 → 0.4.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/dist/proto/generated/reallyme/crypto/v1/crypto_pb.d.ts +4346 -1113
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +1057 -98
- package/dist/proto/generated/reallyme/crypto/v1/native_formats_pb.d.ts +101 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_formats_pb.js +106 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_options_pb.d.ts +112 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_options_pb.js +77 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_primitives_pb.d.ts +87 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_primitives_pb.js +93 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_protocols_pb.d.ts +30 -0
- package/dist/proto/generated/reallyme/crypto/v1/native_protocols_pb.js +34 -0
- package/dist/proto/generated/reallyme/crypto/v1/policy_pb.d.ts +964 -0
- package/dist/proto/generated/reallyme/crypto/v1/policy_pb.js +925 -0
- package/dist/protoErrors.js +53 -180
- package/dist/wasm/reallyme_crypto_wasm.js +4 -0
- package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
- package/package.json +2 -2
package/dist/protoErrors.js
CHANGED
|
@@ -4,67 +4,50 @@
|
|
|
4
4
|
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
5
5
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
6
6
|
import { CryptoBackendErrorSchema, CryptoErrorReason, CryptoErrorSchema, CryptoPrimitiveErrorSchema, CryptoProviderErrorSchema, } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
7
|
+
// The public SDK categories predate the wire contract. This exhaustive projection
|
|
8
|
+
// keeps them stable while the wire adapter retains the original reason code.
|
|
9
|
+
const facadeErrorCodes = {
|
|
10
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER]: "invalid-input",
|
|
11
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_LENGTH]: "invalid-input",
|
|
12
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_KEY]: "invalid-input",
|
|
13
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_PUBLIC_KEY]: "invalid-input",
|
|
14
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_PRIVATE_KEY]: "invalid-input",
|
|
15
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_NONCE]: "invalid-input",
|
|
16
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_SALT]: "invalid-input",
|
|
17
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_PASSWORD]: "invalid-input",
|
|
18
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_ENCODING]: "invalid-input",
|
|
19
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE]: "invalid-signature",
|
|
20
|
+
[CryptoErrorReason.PRIMITIVE_VERIFICATION_FAILED]: "invalid-signature",
|
|
21
|
+
[CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED]: "authentication-failed",
|
|
22
|
+
[CryptoErrorReason.PRIMITIVE_MALFORMED_CIPHERTEXT]: "invalid-input",
|
|
23
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_TAG]: "invalid-input",
|
|
24
|
+
[CryptoErrorReason.PRIMITIVE_INVALID_SHARED_SECRET]: "invalid-input",
|
|
25
|
+
[CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF]: "invalid-input",
|
|
26
|
+
[CryptoErrorReason.PRIMITIVE_MALFORMED_JSON]: "invalid-input",
|
|
27
|
+
[CryptoErrorReason.PRIMITIVE_RESOURCE_LIMIT_EXCEEDED]: "invalid-input",
|
|
28
|
+
[CryptoErrorReason.PRIMITIVE_MISSING_OPERATION]: "invalid-input",
|
|
29
|
+
[CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM]: "unsupported-algorithm",
|
|
30
|
+
[CryptoErrorReason.PROVIDER_UNSUPPORTED_BACKEND]: "unsupported-algorithm",
|
|
31
|
+
[CryptoErrorReason.PROVIDER_UNAVAILABLE]: "provider-failure",
|
|
32
|
+
[CryptoErrorReason.PROVIDER_RANDOMNESS_UNAVAILABLE]: "provider-failure",
|
|
33
|
+
[CryptoErrorReason.PROVIDER_KEY_EXISTS]: "provider-failure",
|
|
34
|
+
[CryptoErrorReason.PROVIDER_KEY_NOT_FOUND]: "provider-failure",
|
|
35
|
+
[CryptoErrorReason.PROVIDER_ACCESS_DENIED]: "provider-failure",
|
|
36
|
+
[CryptoErrorReason.PROVIDER_USER_AUTHENTICATION_REQUIRED]: "provider-failure",
|
|
37
|
+
[CryptoErrorReason.PROVIDER_USER_CANCELED]: "provider-failure",
|
|
38
|
+
[CryptoErrorReason.PROVIDER_HARDWARE_UNAVAILABLE]: "provider-failure",
|
|
39
|
+
[CryptoErrorReason.PROVIDER_HARDWARE_REJECTED_KEY]: "provider-failure",
|
|
40
|
+
[CryptoErrorReason.BACKEND_INVALID_STATE]: "provider-failure",
|
|
41
|
+
[CryptoErrorReason.BACKEND_INTERNAL]: "provider-failure",
|
|
42
|
+
};
|
|
43
|
+
const isKnownErrorReason = (reason) => typeof reason === "number" && Number.isInteger(reason) && Object.hasOwn(facadeErrorCodes, reason);
|
|
44
|
+
const facadeErrorReasons = {
|
|
45
|
+
"invalid-input": { branch: "primitive", reason: CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER },
|
|
46
|
+
"invalid-signature": { branch: "primitive", reason: CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE },
|
|
47
|
+
"authentication-failed": { branch: "primitive", reason: CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED },
|
|
48
|
+
"provider-failure": { branch: "backend", reason: CryptoErrorReason.BACKEND_INTERNAL },
|
|
49
|
+
"unsupported-algorithm": { branch: "provider", reason: CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM },
|
|
49
50
|
};
|
|
50
|
-
const invalidInputReasons = new Set([
|
|
51
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER,
|
|
52
|
-
CryptoErrorReason.PRIMITIVE_INVALID_LENGTH,
|
|
53
|
-
CryptoErrorReason.PRIMITIVE_INVALID_KEY,
|
|
54
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PUBLIC_KEY,
|
|
55
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PRIVATE_KEY,
|
|
56
|
-
CryptoErrorReason.PRIMITIVE_INVALID_NONCE,
|
|
57
|
-
CryptoErrorReason.PRIMITIVE_INVALID_SALT,
|
|
58
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PASSWORD,
|
|
59
|
-
CryptoErrorReason.PRIMITIVE_INVALID_ENCODING,
|
|
60
|
-
CryptoErrorReason.PRIMITIVE_INVALID_SHARED_SECRET,
|
|
61
|
-
CryptoErrorReason.PRIMITIVE_MALFORMED_CIPHERTEXT,
|
|
62
|
-
CryptoErrorReason.PRIMITIVE_INVALID_TAG,
|
|
63
|
-
CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF,
|
|
64
|
-
CryptoErrorReason.PRIMITIVE_MALFORMED_JSON,
|
|
65
|
-
CryptoErrorReason.PRIMITIVE_RESOURCE_LIMIT_EXCEEDED,
|
|
66
|
-
CryptoErrorReason.PRIMITIVE_MISSING_OPERATION,
|
|
67
|
-
]);
|
|
68
51
|
export const cryptoWireErrorToProto = (error) => {
|
|
69
52
|
switch (error.branch) {
|
|
70
53
|
case "primitive":
|
|
@@ -125,11 +108,11 @@ export const cryptoWireErrorTryNew = (branch, reason) => {
|
|
|
125
108
|
if (reason === CryptoErrorReason.UNSPECIFIED) {
|
|
126
109
|
return { ok: false, error: "unspecified-reason" };
|
|
127
110
|
}
|
|
128
|
-
if (
|
|
129
|
-
return {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
if (!Number.isInteger(reason) || !cryptoErrorReasonCodeMatchesBranch(branch, reason)) {
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
error: isKnownErrorReason(reason) ? "branch-reason-mismatch" : "reason-code-out-of-range",
|
|
115
|
+
};
|
|
133
116
|
}
|
|
134
117
|
return { ok: true, value: { branch, reason, reasonCode: reason } };
|
|
135
118
|
};
|
|
@@ -148,123 +131,13 @@ const cryptoErrorReasonCodeMatchesBranch = (branch, reasonCode) => {
|
|
|
148
131
|
return reasonCode >= 300 && reasonCode <= 399;
|
|
149
132
|
}
|
|
150
133
|
};
|
|
151
|
-
const
|
|
152
|
-
switch (branch) {
|
|
153
|
-
case "primitive":
|
|
154
|
-
return primitiveCryptoErrorReasons.has(reason);
|
|
155
|
-
case "provider":
|
|
156
|
-
return providerCryptoErrorReasons.has(reason);
|
|
157
|
-
case "backend":
|
|
158
|
-
return backendCryptoErrorReasons.has(reason);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const primitiveCryptoErrorReasons = new Set([
|
|
162
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER,
|
|
163
|
-
CryptoErrorReason.PRIMITIVE_INVALID_LENGTH,
|
|
164
|
-
CryptoErrorReason.PRIMITIVE_INVALID_KEY,
|
|
165
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PUBLIC_KEY,
|
|
166
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PRIVATE_KEY,
|
|
167
|
-
CryptoErrorReason.PRIMITIVE_INVALID_NONCE,
|
|
168
|
-
CryptoErrorReason.PRIMITIVE_INVALID_SALT,
|
|
169
|
-
CryptoErrorReason.PRIMITIVE_INVALID_PASSWORD,
|
|
170
|
-
CryptoErrorReason.PRIMITIVE_INVALID_ENCODING,
|
|
171
|
-
CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE,
|
|
172
|
-
CryptoErrorReason.PRIMITIVE_VERIFICATION_FAILED,
|
|
173
|
-
CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED,
|
|
174
|
-
CryptoErrorReason.PRIMITIVE_MALFORMED_CIPHERTEXT,
|
|
175
|
-
CryptoErrorReason.PRIMITIVE_INVALID_TAG,
|
|
176
|
-
CryptoErrorReason.PRIMITIVE_INVALID_SHARED_SECRET,
|
|
177
|
-
CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF,
|
|
178
|
-
CryptoErrorReason.PRIMITIVE_MALFORMED_JSON,
|
|
179
|
-
CryptoErrorReason.PRIMITIVE_RESOURCE_LIMIT_EXCEEDED,
|
|
180
|
-
CryptoErrorReason.PRIMITIVE_MISSING_OPERATION,
|
|
181
|
-
]);
|
|
182
|
-
const providerCryptoErrorReasons = new Set([
|
|
183
|
-
CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM,
|
|
184
|
-
CryptoErrorReason.PROVIDER_UNSUPPORTED_BACKEND,
|
|
185
|
-
CryptoErrorReason.PROVIDER_UNAVAILABLE,
|
|
186
|
-
CryptoErrorReason.PROVIDER_RANDOMNESS_UNAVAILABLE,
|
|
187
|
-
CryptoErrorReason.PROVIDER_KEY_EXISTS,
|
|
188
|
-
CryptoErrorReason.PROVIDER_KEY_NOT_FOUND,
|
|
189
|
-
CryptoErrorReason.PROVIDER_ACCESS_DENIED,
|
|
190
|
-
CryptoErrorReason.PROVIDER_USER_AUTHENTICATION_REQUIRED,
|
|
191
|
-
CryptoErrorReason.PROVIDER_USER_CANCELED,
|
|
192
|
-
CryptoErrorReason.PROVIDER_HARDWARE_UNAVAILABLE,
|
|
193
|
-
CryptoErrorReason.PROVIDER_HARDWARE_REJECTED_KEY,
|
|
194
|
-
]);
|
|
195
|
-
const backendCryptoErrorReasons = new Set([
|
|
196
|
-
CryptoErrorReason.BACKEND_INVALID_STATE,
|
|
197
|
-
CryptoErrorReason.BACKEND_INTERNAL,
|
|
198
|
-
]);
|
|
199
|
-
const knownCryptoErrorReasons = new Set([
|
|
200
|
-
...primitiveCryptoErrorReasons,
|
|
201
|
-
...providerCryptoErrorReasons,
|
|
202
|
-
...backendCryptoErrorReasons,
|
|
203
|
-
]);
|
|
204
|
-
export const cryptoWireErrorToFacadeError = (error) => {
|
|
205
|
-
if (!knownCryptoErrorReasons.has(error.reason)) {
|
|
206
|
-
return new ReallyMeCryptoError("provider-failure");
|
|
207
|
-
}
|
|
208
|
-
const facadeError = cryptoErrorReasonToFacadeError(error.reason);
|
|
209
|
-
if (facadeError.code !== "invalid-input" || invalidInputReasons.has(error.reason)) {
|
|
210
|
-
return facadeError;
|
|
211
|
-
}
|
|
212
|
-
switch (error.branch) {
|
|
213
|
-
case "primitive":
|
|
214
|
-
return facadeError;
|
|
215
|
-
case "provider":
|
|
216
|
-
case "backend":
|
|
217
|
-
return new ReallyMeCryptoError("provider-failure");
|
|
218
|
-
}
|
|
219
|
-
};
|
|
134
|
+
export const cryptoWireErrorToFacadeError = (error) => new ReallyMeCryptoError(isKnownErrorReason(error.reason) ? facadeErrorCodes[error.reason] : "provider-failure");
|
|
220
135
|
export const cryptoErrorToProto = (error) => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
error: {
|
|
225
|
-
case: "primitive",
|
|
226
|
-
value: create(CryptoPrimitiveErrorSchema, {
|
|
227
|
-
reason: CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER,
|
|
228
|
-
}),
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
case "invalid-signature":
|
|
232
|
-
return create(CryptoErrorSchema, {
|
|
233
|
-
error: {
|
|
234
|
-
case: "primitive",
|
|
235
|
-
value: create(CryptoPrimitiveErrorSchema, {
|
|
236
|
-
reason: CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE,
|
|
237
|
-
}),
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
case "authentication-failed":
|
|
241
|
-
return create(CryptoErrorSchema, {
|
|
242
|
-
error: {
|
|
243
|
-
case: "primitive",
|
|
244
|
-
value: create(CryptoPrimitiveErrorSchema, {
|
|
245
|
-
reason: CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED,
|
|
246
|
-
}),
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
case "provider-failure":
|
|
250
|
-
return create(CryptoErrorSchema, {
|
|
251
|
-
error: {
|
|
252
|
-
case: "backend",
|
|
253
|
-
value: create(CryptoBackendErrorSchema, {
|
|
254
|
-
reason: CryptoErrorReason.BACKEND_INTERNAL,
|
|
255
|
-
}),
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
case "unsupported-algorithm":
|
|
259
|
-
return create(CryptoErrorSchema, {
|
|
260
|
-
error: {
|
|
261
|
-
case: "provider",
|
|
262
|
-
value: create(CryptoProviderErrorSchema, {
|
|
263
|
-
reason: CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM,
|
|
264
|
-
}),
|
|
265
|
-
},
|
|
266
|
-
});
|
|
136
|
+
const code = error.code;
|
|
137
|
+
if (typeof code !== "string" || !Object.hasOwn(facadeErrorReasons, code)) {
|
|
138
|
+
return cryptoWireErrorToProto(facadeErrorReasons["invalid-input"]);
|
|
267
139
|
}
|
|
140
|
+
return cryptoWireErrorToProto(facadeErrorReasons[code]);
|
|
268
141
|
};
|
|
269
142
|
export const cryptoErrorToProtoBytes = (error) => toBinary(CryptoErrorSchema, cryptoErrorToProto(error));
|
|
270
143
|
export const cryptoErrorFromProto = (value) => {
|
|
@@ -817,6 +817,10 @@ function __wbg_get_imports() {
|
|
|
817
817
|
__wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
|
|
818
818
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
819
819
|
},
|
|
820
|
+
__wbg_fill_6ab2ffab47cad7ab: function(arg0, arg1, arg2, arg3) {
|
|
821
|
+
const ret = arg0.fill(arg1, arg2 >>> 0, arg3 >>> 0);
|
|
822
|
+
return ret;
|
|
823
|
+
},
|
|
820
824
|
__wbg_getRandomValues_8b6f1f663e6f188d: function() { return handleError(function (arg0, arg1) {
|
|
821
825
|
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
822
826
|
}, arguments); },
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reallyme/crypto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "ReallyMe crypto SDK for TypeScript/JavaScript with an explicit, pinned provider set.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@bufbuild/protobuf": "2.17.0",
|
|
57
57
|
"@noble/curves": "2.4.0",
|
|
58
58
|
"@noble/hashes": "2.4.0",
|
|
59
|
-
"@reallyme/codec": "0.
|
|
59
|
+
"@reallyme/codec": "0.4.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"typescript": "7.0.2"
|