one 2.6.20 → 2.6.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/android/src/main/java/dev/onejs/onenative/OneNativeCameraManager.kt +24 -0
- package/android/src/main/java/dev/onejs/onenative/OneNativeCameraView.kt +197 -2
- package/cpp/HybridOneCrypto.cpp +327 -1
- package/cpp/HybridOneCrypto.hpp +8 -0
- package/dist/cjs/index.cjs +25 -22
- package/dist/cjs/index.native.cjs +25 -22
- package/dist/cjs/index.native.js +25 -22
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/one.cjs +1 -0
- package/dist/cjs/one.native.cjs +1 -0
- package/dist/cjs/one.native.js +1 -0
- package/dist/cjs/one.native.js.map +1 -1
- package/dist/cjs/platform/camera/index.cjs +3 -2
- package/dist/cjs/platform/camera/index.native.cjs +89 -3
- package/dist/cjs/platform/camera/index.native.js +89 -3
- package/dist/cjs/platform/camera/index.native.js.map +1 -1
- package/dist/cjs/platform/crypto/aes.cjs +259 -0
- package/dist/cjs/platform/crypto/aes.native.cjs +343 -0
- package/dist/cjs/platform/crypto/aes.native.js +345 -0
- package/dist/cjs/platform/crypto/aes.native.js.map +1 -0
- package/dist/cjs/platform/crypto/bytes.cjs +132 -0
- package/dist/cjs/platform/crypto/bytes.native.cjs +175 -0
- package/dist/cjs/platform/crypto/bytes.native.js +177 -0
- package/dist/cjs/platform/crypto/bytes.native.js.map +1 -0
- package/dist/cjs/platform/crypto/digest-api.cjs +65 -0
- package/dist/cjs/platform/crypto/digest-api.native.cjs +69 -0
- package/dist/cjs/platform/crypto/digest-api.native.js +71 -0
- package/dist/cjs/platform/crypto/digest-api.native.js.map +1 -0
- package/dist/cjs/platform/crypto/digest.cjs +26 -15
- package/dist/cjs/platform/crypto/digest.native.cjs +26 -15
- package/dist/cjs/platform/crypto/digest.native.js +26 -15
- package/dist/cjs/platform/crypto/digest.native.js.map +1 -1
- package/dist/cjs/platform/crypto/index.cjs +19 -1
- package/dist/cjs/platform/crypto/index.native.cjs +39 -1
- package/dist/cjs/platform/crypto/index.native.js +39 -1
- package/dist/cjs/platform/crypto/index.native.js.map +1 -1
- package/dist/cjs/platform/crypto/types.cjs +16 -0
- package/dist/cjs/platform/crypto/types.native.cjs +18 -0
- package/dist/cjs/platform/crypto/types.native.js +20 -0
- package/dist/cjs/platform/crypto/types.native.js.map +1 -0
- package/dist/cjs/platform/crypto/web.cjs +73 -0
- package/dist/cjs/platform/extras.cjs +4 -0
- package/dist/cjs/platform/extras.native.cjs +4 -0
- package/dist/cjs/platform/extras.native.js +4 -0
- package/dist/cjs/platform/extras.native.js.map +1 -1
- package/dist/cjs/platform/specs/OneNativeCameraNativeComponent.cjs +37 -21
- package/dist/cjs/platform/specs/OneNativeCameraNativeComponent.native.cjs +37 -21
- package/dist/cjs/platform/specs/OneNativeCameraNativeComponent.native.js +37 -21
- package/dist/cjs/platform/specs/OneNativeCameraNativeComponent.native.js.map +3 -3
- package/dist/cjs/router/router.cjs +4 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.native.js +2 -2
- package/dist/esm/one.mjs +2 -1
- package/dist/esm/one.mjs.map +1 -1
- package/dist/esm/one.native.js +2 -1
- package/dist/esm/one.native.js.map +1 -1
- package/dist/esm/platform/camera/index.mjs +4 -2
- package/dist/esm/platform/camera/index.mjs.map +1 -1
- package/dist/esm/platform/camera/index.native.js +90 -4
- package/dist/esm/platform/camera/index.native.js.map +1 -1
- package/dist/esm/platform/crypto/aes.mjs +236 -0
- package/dist/esm/platform/crypto/aes.mjs.map +1 -0
- package/dist/esm/platform/crypto/aes.native.js +318 -0
- package/dist/esm/platform/crypto/aes.native.js.map +1 -0
- package/dist/esm/platform/crypto/bytes.mjs +104 -0
- package/dist/esm/platform/crypto/bytes.mjs.map +1 -0
- package/dist/esm/platform/crypto/bytes.native.js +145 -0
- package/dist/esm/platform/crypto/bytes.native.js.map +1 -0
- package/dist/esm/platform/crypto/digest-api.mjs +42 -0
- package/dist/esm/platform/crypto/digest-api.mjs.map +1 -0
- package/dist/esm/platform/crypto/digest-api.native.js +44 -0
- package/dist/esm/platform/crypto/digest-api.native.js.map +1 -0
- package/dist/esm/platform/crypto/digest.mjs +23 -15
- package/dist/esm/platform/crypto/digest.mjs.map +1 -1
- package/dist/esm/platform/crypto/digest.native.js +23 -15
- package/dist/esm/platform/crypto/digest.native.js.map +1 -1
- package/dist/esm/platform/crypto/index.mjs +14 -1
- package/dist/esm/platform/crypto/index.mjs.map +1 -1
- package/dist/esm/platform/crypto/index.native.js +34 -1
- package/dist/esm/platform/crypto/index.native.js.map +1 -1
- package/dist/esm/platform/crypto/types.mjs +0 -0
- package/dist/esm/platform/crypto/types.native.js +0 -0
- package/dist/esm/platform/crypto/web.mjs +50 -0
- package/dist/esm/platform/crypto/web.mjs.map +1 -0
- package/dist/esm/platform/extras.mjs +2 -1
- package/dist/esm/platform/extras.native.js +2 -1
- package/dist/esm/platform/specs/OneNativeCameraNativeComponent.mjs +25 -9
- package/dist/esm/platform/specs/OneNativeCameraNativeComponent.mjs.map +3 -3
- package/dist/esm/platform/specs/OneNativeCameraNativeComponent.native.js +25 -9
- package/dist/esm/platform/specs/OneNativeCameraNativeComponent.native.js.map +3 -3
- package/dist/esm/router/router.mjs +5 -2
- package/dist/esm/router/router.mjs.map +1 -1
- package/ios/OneNativeCameraComponentView.mm +28 -0
- package/ios/OneNativeCameraView.swift +163 -0
- package/nitrogen/generated/shared/c++/HybridOneCryptoSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridOneCryptoSpec.hpp +4 -1
- package/package.json +12 -12
- package/src/index.ts +4 -0
- package/src/one.ts +3 -0
- package/src/platform/camera/index.native.tsx +116 -12
- package/src/platform/camera/index.tsx +15 -4
- package/src/platform/camera/types.ts +22 -0
- package/src/platform/crypto/aes.ts +345 -0
- package/src/platform/crypto/bytes.ts +120 -0
- package/src/platform/crypto/digest-api.ts +50 -0
- package/src/platform/crypto/digest.ts +24 -15
- package/src/platform/crypto/index.native.ts +68 -0
- package/src/platform/crypto/index.ts +31 -0
- package/src/platform/crypto/types.ts +64 -0
- package/src/platform/crypto/web.ts +69 -0
- package/src/platform/extras.ts +15 -0
- package/src/platform/index.native.ts +4 -0
- package/src/platform/index.ts +4 -0
- package/src/platform/specs/OneCrypto.nitro.ts +19 -0
- package/src/platform/specs/OneNativeCameraNativeComponent.ts +35 -2
- package/src/router/router.ts +7 -4
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/one.d.ts +2 -1
- package/types/one.d.ts.map +1 -1
- package/types/platform/camera/index.d.ts +3 -3
- package/types/platform/camera/index.d.ts.map +1 -1
- package/types/platform/camera/index.native.d.ts +3 -3
- package/types/platform/camera/index.native.d.ts.map +1 -1
- package/types/platform/camera/types.d.ts +18 -0
- package/types/platform/camera/types.d.ts.map +1 -1
- package/types/platform/crypto/aes.d.ts +211 -0
- package/types/platform/crypto/aes.d.ts.map +1 -0
- package/types/platform/crypto/bytes.d.ts +8 -0
- package/types/platform/crypto/bytes.d.ts.map +1 -0
- package/types/platform/crypto/digest-api.d.ts +9 -0
- package/types/platform/crypto/digest-api.d.ts.map +1 -0
- package/types/platform/crypto/digest.d.ts +5 -0
- package/types/platform/crypto/digest.d.ts.map +1 -1
- package/types/platform/crypto/index.d.ts +127 -0
- package/types/platform/crypto/index.d.ts.map +1 -1
- package/types/platform/crypto/index.native.d.ts +127 -0
- package/types/platform/crypto/index.native.d.ts.map +1 -1
- package/types/platform/crypto/types.d.ts +43 -0
- package/types/platform/crypto/types.d.ts.map +1 -0
- package/types/platform/crypto/web.d.ts +5 -0
- package/types/platform/crypto/web.d.ts.map +1 -0
- package/types/platform/extras.d.ts +2 -0
- package/types/platform/extras.d.ts.map +1 -1
- package/types/platform/index.d.ts +1 -1
- package/types/platform/index.d.ts.map +1 -1
- package/types/platform/index.native.d.ts +1 -1
- package/types/platform/index.native.d.ts.map +1 -1
- package/types/platform/specs/OneCrypto.nitro.d.ts +2 -0
- package/types/platform/specs/OneCrypto.nitro.d.ts.map +1 -1
- package/types/platform/specs/OneNativeCameraNativeComponent.d.ts +18 -2
- package/types/platform/specs/OneNativeCameraNativeComponent.d.ts.map +1 -1
- package/types/router/router.d.ts.map +1 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var aes_exports = {};
|
|
22
|
+
__export(aes_exports, {
|
|
23
|
+
assertTagLength: () => assertTagLength,
|
|
24
|
+
createAesApi: () => createAesApi,
|
|
25
|
+
toBytes: () => toBytes
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(aes_exports);
|
|
28
|
+
var import_bytes = require("./bytes.cjs");
|
|
29
|
+
const KEY_SIZES = [
|
|
30
|
+
128,
|
|
31
|
+
192,
|
|
32
|
+
256
|
|
33
|
+
];
|
|
34
|
+
const TAG_LENGTHS = [
|
|
35
|
+
16,
|
|
36
|
+
15,
|
|
37
|
+
14,
|
|
38
|
+
13,
|
|
39
|
+
12,
|
|
40
|
+
8,
|
|
41
|
+
4
|
|
42
|
+
];
|
|
43
|
+
const DEFAULT_IV_LENGTH = 12;
|
|
44
|
+
const DEFAULT_TAG_LENGTH = 16;
|
|
45
|
+
function assertTagLength(tagLength, verb) {
|
|
46
|
+
if (!TAG_LENGTHS.includes(tagLength)) {
|
|
47
|
+
throw new Error(`${verb}: tagLength must be one of: ${TAG_LENGTHS.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function toBytes(input, verb) {
|
|
51
|
+
if (typeof input === "string") return (0, import_bytes.base64ToBytes)(input, verb);
|
|
52
|
+
if (input instanceof ArrayBuffer) return new Uint8Array(input.slice(0));
|
|
53
|
+
if (ArrayBuffer.isView(input) && input.buffer instanceof ArrayBuffer) {
|
|
54
|
+
return (0, import_bytes.exactBytes)(new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
|
|
55
|
+
}
|
|
56
|
+
throw new TypeError(`${verb}: expected a base64 string, Uint8Array, or ArrayBuffer`);
|
|
57
|
+
}
|
|
58
|
+
const sealedParts = /* @__PURE__ */ new WeakMap();
|
|
59
|
+
const keyBytes = /* @__PURE__ */ new WeakMap();
|
|
60
|
+
function encodeParts(bytes, encoding) {
|
|
61
|
+
return encoding === "base64" ? (0, import_bytes.bytesToBase64)(bytes) : (0, import_bytes.exactBytes)(bytes);
|
|
62
|
+
}
|
|
63
|
+
function createAesApi(engine) {
|
|
64
|
+
class AESEncryptionKey {
|
|
65
|
+
size;
|
|
66
|
+
constructor(bytes) {
|
|
67
|
+
if (!KEY_SIZES.includes(bytes.length * 8)) {
|
|
68
|
+
throw new Error(`Crypto.AESEncryptionKey: key must be 128, 192, or 256 bits, got ${bytes.length * 8}`);
|
|
69
|
+
}
|
|
70
|
+
this.size = bytes.length * 8;
|
|
71
|
+
keyBytes.set(this, (0, import_bytes.exactBytes)(bytes));
|
|
72
|
+
}
|
|
73
|
+
static async generate(size = 256) {
|
|
74
|
+
if (!KEY_SIZES.includes(size)) {
|
|
75
|
+
throw new Error(`Crypto.AESEncryptionKey.generate: size must be one of: ${KEY_SIZES.join(", ")}`);
|
|
76
|
+
}
|
|
77
|
+
const bytes = new Uint8Array(size / 8);
|
|
78
|
+
engine.random(bytes);
|
|
79
|
+
return new AESEncryptionKey(bytes);
|
|
80
|
+
}
|
|
81
|
+
static async import(input, encoding) {
|
|
82
|
+
const verb = "Crypto.AESEncryptionKey.import";
|
|
83
|
+
let bytes;
|
|
84
|
+
if (typeof input === "string") {
|
|
85
|
+
if (encoding === "hex") bytes = (0, import_bytes.hexToBytes)(input, verb);
|
|
86
|
+
else if (encoding === "base64") bytes = (0, import_bytes.base64ToBytes)(input, verb);
|
|
87
|
+
else throw new Error(`${verb}: encoding must be 'hex' or 'base64'`);
|
|
88
|
+
} else if (input instanceof Uint8Array) {
|
|
89
|
+
bytes = (0, import_bytes.exactBytes)(input);
|
|
90
|
+
} else {
|
|
91
|
+
throw new TypeError(`${verb}: expected bytes or an encoded string`);
|
|
92
|
+
}
|
|
93
|
+
if (!KEY_SIZES.includes(bytes.length * 8)) {
|
|
94
|
+
throw new Error(`${verb}: key must be 128, 192, or 256 bits, got ${bytes.length * 8}`);
|
|
95
|
+
}
|
|
96
|
+
return new AESEncryptionKey(bytes);
|
|
97
|
+
}
|
|
98
|
+
async bytes() {
|
|
99
|
+
return (0, import_bytes.exactBytes)(keyBytes.get(this));
|
|
100
|
+
}
|
|
101
|
+
async encoded(encoding) {
|
|
102
|
+
const bytes = keyBytes.get(this);
|
|
103
|
+
if (encoding === "hex") return (0, import_bytes.bytesToHex)(bytes);
|
|
104
|
+
if (encoding === "base64") return (0, import_bytes.bytesToBase64)(bytes);
|
|
105
|
+
throw new Error(`Crypto.AESEncryptionKey.encoded: encoding must be 'hex' or 'base64'`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
class AESSealedData {
|
|
109
|
+
constructor(parts) {
|
|
110
|
+
if (parts.iv.length === 0) throw new Error("Crypto.AESSealedData: iv must not be empty");
|
|
111
|
+
assertTagLength(parts.tag.length, "Crypto.AESSealedData");
|
|
112
|
+
sealedParts.set(this, parts);
|
|
113
|
+
}
|
|
114
|
+
static fromCombined(combined, config = {}) {
|
|
115
|
+
const verb = "Crypto.AESSealedData.fromCombined";
|
|
116
|
+
const ivLength = config.ivLength ?? DEFAULT_IV_LENGTH;
|
|
117
|
+
const tagLength = config.tagLength ?? DEFAULT_TAG_LENGTH;
|
|
118
|
+
assertTagLength(tagLength, verb);
|
|
119
|
+
if (!Number.isInteger(ivLength) || ivLength <= 0) {
|
|
120
|
+
throw new Error(`${verb}: ivLength must be a positive integer`);
|
|
121
|
+
}
|
|
122
|
+
const bytes = toBytes(combined, verb);
|
|
123
|
+
if (bytes.length < ivLength + tagLength) {
|
|
124
|
+
throw new Error(`${verb}: combined data is shorter than its iv and tag`);
|
|
125
|
+
}
|
|
126
|
+
return new AESSealedData({
|
|
127
|
+
iv: (0, import_bytes.exactBytes)(bytes.subarray(0, ivLength)),
|
|
128
|
+
ciphertext: (0, import_bytes.exactBytes)(bytes.subarray(ivLength, bytes.length - tagLength)),
|
|
129
|
+
tag: (0, import_bytes.exactBytes)(bytes.subarray(bytes.length - tagLength))
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
static fromParts(ivInput, ciphertextInput, tagOrLength) {
|
|
133
|
+
const verb = "Crypto.AESSealedData.fromParts";
|
|
134
|
+
const iv = toBytes(ivInput, verb);
|
|
135
|
+
const ciphertext = toBytes(ciphertextInput, verb);
|
|
136
|
+
if (tagOrLength === void 0 || typeof tagOrLength === "number") {
|
|
137
|
+
const tagLength = tagOrLength ?? DEFAULT_TAG_LENGTH;
|
|
138
|
+
assertTagLength(tagLength, verb);
|
|
139
|
+
if (ciphertext.length < tagLength) {
|
|
140
|
+
throw new Error(`${verb}: ciphertext is shorter than its tag`);
|
|
141
|
+
}
|
|
142
|
+
return new AESSealedData({
|
|
143
|
+
iv,
|
|
144
|
+
ciphertext: (0, import_bytes.exactBytes)(ciphertext.subarray(0, ciphertext.length - tagLength)),
|
|
145
|
+
tag: (0, import_bytes.exactBytes)(ciphertext.subarray(ciphertext.length - tagLength))
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const tag = toBytes(tagOrLength, verb);
|
|
149
|
+
assertTagLength(tag.length, verb);
|
|
150
|
+
return new AESSealedData({
|
|
151
|
+
iv,
|
|
152
|
+
ciphertext,
|
|
153
|
+
tag
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
static fromSeal(iv, ciphertextWithTag, tagLength) {
|
|
157
|
+
return new AESSealedData({
|
|
158
|
+
iv,
|
|
159
|
+
ciphertext: (0, import_bytes.exactBytes)(ciphertextWithTag.subarray(0, ciphertextWithTag.length - tagLength)),
|
|
160
|
+
tag: (0, import_bytes.exactBytes)(ciphertextWithTag.subarray(ciphertextWithTag.length - tagLength))
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
get ivSize() {
|
|
164
|
+
return sealedParts.get(this).iv.length;
|
|
165
|
+
}
|
|
166
|
+
get tagSize() {
|
|
167
|
+
return sealedParts.get(this).tag.length;
|
|
168
|
+
}
|
|
169
|
+
get combinedSize() {
|
|
170
|
+
const parts = sealedParts.get(this);
|
|
171
|
+
return parts.iv.length + parts.ciphertext.length + parts.tag.length;
|
|
172
|
+
}
|
|
173
|
+
async iv(encoding) {
|
|
174
|
+
return encodeParts(sealedParts.get(this).iv, encoding);
|
|
175
|
+
}
|
|
176
|
+
async tag(encoding) {
|
|
177
|
+
return encodeParts(sealedParts.get(this).tag, encoding);
|
|
178
|
+
}
|
|
179
|
+
async ciphertext(options) {
|
|
180
|
+
const parts = sealedParts.get(this);
|
|
181
|
+
const bytes = options?.includeTag ? (0, import_bytes.concatBytes)([parts.ciphertext, parts.tag]) : parts.ciphertext;
|
|
182
|
+
return encodeParts(bytes, options?.encoding);
|
|
183
|
+
}
|
|
184
|
+
async combined(encoding) {
|
|
185
|
+
const parts = sealedParts.get(this);
|
|
186
|
+
return encodeParts((0, import_bytes.concatBytes)([
|
|
187
|
+
parts.iv,
|
|
188
|
+
parts.ciphertext,
|
|
189
|
+
parts.tag
|
|
190
|
+
]), encoding);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function keyMaterial(key, verb) {
|
|
194
|
+
const own = keyBytes.get(key);
|
|
195
|
+
if (own) return (0, import_bytes.exactBytes)(own);
|
|
196
|
+
if (key && typeof key.bytes === "function") return (0, import_bytes.exactBytes)(await key.bytes());
|
|
197
|
+
throw new TypeError(`${verb}: expected an AESEncryptionKey`);
|
|
198
|
+
}
|
|
199
|
+
async function partsOf(sealed, verb) {
|
|
200
|
+
const own = sealedParts.get(sealed);
|
|
201
|
+
if (own) {
|
|
202
|
+
return {
|
|
203
|
+
iv: (0, import_bytes.exactBytes)(own.iv),
|
|
204
|
+
ciphertext: (0, import_bytes.exactBytes)(own.ciphertext),
|
|
205
|
+
tag: (0, import_bytes.exactBytes)(own.tag)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (sealed && typeof sealed.iv === "function" && typeof sealed.combined === "function") {
|
|
209
|
+
const iv = (0, import_bytes.exactBytes)(await sealed.iv());
|
|
210
|
+
const tag = (0, import_bytes.exactBytes)(await sealed.tag());
|
|
211
|
+
const ciphertext = (0, import_bytes.exactBytes)(await sealed.ciphertext({
|
|
212
|
+
encoding: "bytes",
|
|
213
|
+
includeTag: false
|
|
214
|
+
}));
|
|
215
|
+
return {
|
|
216
|
+
iv,
|
|
217
|
+
ciphertext,
|
|
218
|
+
tag
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
throw new TypeError(`${verb}: expected an AESSealedData`);
|
|
222
|
+
}
|
|
223
|
+
async function aesEncrypt(plaintext, key, options = {}) {
|
|
224
|
+
const verb = "Crypto.aesEncrypt";
|
|
225
|
+
const tagLength = options.tagLength ?? DEFAULT_TAG_LENGTH;
|
|
226
|
+
assertTagLength(tagLength, verb);
|
|
227
|
+
let iv;
|
|
228
|
+
const nonce = options.nonce;
|
|
229
|
+
if (nonce && "bytes" in nonce && nonce.bytes !== void 0) {
|
|
230
|
+
iv = toBytes(nonce.bytes, verb);
|
|
231
|
+
if (iv.length === 0) throw new Error(`${verb}: nonce bytes must not be empty`);
|
|
232
|
+
} else {
|
|
233
|
+
const length = nonce && "length" in nonce && nonce.length !== void 0 ? nonce.length : DEFAULT_IV_LENGTH;
|
|
234
|
+
if (!Number.isInteger(length) || length <= 0) {
|
|
235
|
+
throw new Error(`${verb}: nonce length must be a positive integer`);
|
|
236
|
+
}
|
|
237
|
+
iv = new Uint8Array(length);
|
|
238
|
+
engine.random(iv);
|
|
239
|
+
}
|
|
240
|
+
const additionalData = options.additionalData === void 0 ? void 0 : toBytes(options.additionalData, verb);
|
|
241
|
+
const plainBytes = toBytes(plaintext, verb);
|
|
242
|
+
const sealed = await engine.seal(await keyMaterial(key, verb), iv, plainBytes, additionalData, tagLength);
|
|
243
|
+
const actualTag = sealed.length - plainBytes.length;
|
|
244
|
+
return AESSealedData.fromSeal(iv, sealed, actualTag > 0 ? actualTag : tagLength);
|
|
245
|
+
}
|
|
246
|
+
async function aesDecrypt(sealedData, key, options = {}) {
|
|
247
|
+
const verb = "Crypto.aesDecrypt";
|
|
248
|
+
const parts = await partsOf(sealedData, verb);
|
|
249
|
+
const additionalData = options.additionalData === void 0 ? void 0 : toBytes(options.additionalData, verb);
|
|
250
|
+
const plaintext = await engine.open(await keyMaterial(key, verb), parts.iv, (0, import_bytes.concatBytes)([parts.ciphertext, parts.tag]), additionalData, parts.tag.length);
|
|
251
|
+
return options.output === "base64" ? (0, import_bytes.bytesToBase64)(plaintext) : plaintext;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
AESEncryptionKey,
|
|
255
|
+
AESSealedData,
|
|
256
|
+
aesEncrypt,
|
|
257
|
+
aesDecrypt
|
|
258
|
+
};
|
|
259
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var aes_exports = {};
|
|
24
|
+
__export(aes_exports, {
|
|
25
|
+
assertTagLength: () => assertTagLength,
|
|
26
|
+
createAesApi: () => createAesApi,
|
|
27
|
+
toBytes: () => toBytes
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(aes_exports);
|
|
30
|
+
var import_bytes = require("./bytes.native.js");
|
|
31
|
+
function _class_call_check(instance, Constructor) {
|
|
32
|
+
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
function _defineProperties(target, props) {
|
|
35
|
+
for (var i = 0; i < props.length; i++) {
|
|
36
|
+
var descriptor = props[i];
|
|
37
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
38
|
+
descriptor.configurable = true;
|
|
39
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
40
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
44
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
45
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
46
|
+
return Constructor;
|
|
47
|
+
}
|
|
48
|
+
function _define_property(obj, key, value) {
|
|
49
|
+
if (key in obj) {
|
|
50
|
+
Object.defineProperty(obj, key, {
|
|
51
|
+
value,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true
|
|
55
|
+
});
|
|
56
|
+
} else obj[key] = value;
|
|
57
|
+
return obj;
|
|
58
|
+
}
|
|
59
|
+
var KEY_SIZES = [
|
|
60
|
+
128,
|
|
61
|
+
192,
|
|
62
|
+
256
|
|
63
|
+
];
|
|
64
|
+
var TAG_LENGTHS = [
|
|
65
|
+
16,
|
|
66
|
+
15,
|
|
67
|
+
14,
|
|
68
|
+
13,
|
|
69
|
+
12,
|
|
70
|
+
8,
|
|
71
|
+
4
|
|
72
|
+
];
|
|
73
|
+
var DEFAULT_IV_LENGTH = 12;
|
|
74
|
+
var DEFAULT_TAG_LENGTH = 16;
|
|
75
|
+
function assertTagLength(tagLength, verb) {
|
|
76
|
+
if (!TAG_LENGTHS.includes(tagLength)) {
|
|
77
|
+
throw new Error(`${verb}: tagLength must be one of: ${TAG_LENGTHS.join(", ")}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function toBytes(input, verb) {
|
|
81
|
+
if (typeof input === "string") return (0, import_bytes.base64ToBytes)(input, verb);
|
|
82
|
+
if (input instanceof ArrayBuffer) return new Uint8Array(input.slice(0));
|
|
83
|
+
if (ArrayBuffer.isView(input) && input.buffer instanceof ArrayBuffer) {
|
|
84
|
+
return (0, import_bytes.exactBytes)(new Uint8Array(input.buffer, input.byteOffset, input.byteLength));
|
|
85
|
+
}
|
|
86
|
+
throw new TypeError(`${verb}: expected a base64 string, Uint8Array, or ArrayBuffer`);
|
|
87
|
+
}
|
|
88
|
+
var sealedParts = /* @__PURE__ */ new WeakMap();
|
|
89
|
+
var keyBytes = /* @__PURE__ */ new WeakMap();
|
|
90
|
+
function encodeParts(bytes, encoding) {
|
|
91
|
+
return encoding === "base64" ? (0, import_bytes.bytesToBase64)(bytes) : (0, import_bytes.exactBytes)(bytes);
|
|
92
|
+
}
|
|
93
|
+
function createAesApi(engine) {
|
|
94
|
+
var AESEncryptionKey = /* @__PURE__ */ (function() {
|
|
95
|
+
"use strict";
|
|
96
|
+
function AESEncryptionKey2(bytes) {
|
|
97
|
+
_class_call_check(this, AESEncryptionKey2);
|
|
98
|
+
_define_property(this, "size", void 0);
|
|
99
|
+
if (!KEY_SIZES.includes(bytes.length * 8)) {
|
|
100
|
+
throw new Error(`Crypto.AESEncryptionKey: key must be 128, 192, or 256 bits, got ${bytes.length * 8}`);
|
|
101
|
+
}
|
|
102
|
+
this.size = bytes.length * 8;
|
|
103
|
+
keyBytes.set(this, (0, import_bytes.exactBytes)(bytes));
|
|
104
|
+
}
|
|
105
|
+
_create_class(AESEncryptionKey2, [{
|
|
106
|
+
key: "bytes",
|
|
107
|
+
value: async function bytes() {
|
|
108
|
+
return (0, import_bytes.exactBytes)(keyBytes.get(this));
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "encoded",
|
|
112
|
+
value: async function encoded(encoding) {
|
|
113
|
+
var bytes = keyBytes.get(this);
|
|
114
|
+
if (encoding === "hex") return (0, import_bytes.bytesToHex)(bytes);
|
|
115
|
+
if (encoding === "base64") return (0, import_bytes.bytesToBase64)(bytes);
|
|
116
|
+
throw new Error(`Crypto.AESEncryptionKey.encoded: encoding must be 'hex' or 'base64'`);
|
|
117
|
+
}
|
|
118
|
+
}], [{
|
|
119
|
+
key: "generate",
|
|
120
|
+
value: async function generate() {
|
|
121
|
+
var size = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 256;
|
|
122
|
+
if (!KEY_SIZES.includes(size)) {
|
|
123
|
+
throw new Error(`Crypto.AESEncryptionKey.generate: size must be one of: ${KEY_SIZES.join(", ")}`);
|
|
124
|
+
}
|
|
125
|
+
var bytes = new Uint8Array(size / 8);
|
|
126
|
+
engine.random(bytes);
|
|
127
|
+
return new AESEncryptionKey2(bytes);
|
|
128
|
+
}
|
|
129
|
+
}, {
|
|
130
|
+
key: "import",
|
|
131
|
+
value: async function _import(input, encoding) {
|
|
132
|
+
var verb = "Crypto.AESEncryptionKey.import";
|
|
133
|
+
var bytes;
|
|
134
|
+
if (typeof input === "string") {
|
|
135
|
+
if (encoding === "hex") bytes = (0, import_bytes.hexToBytes)(input, verb);
|
|
136
|
+
else if (encoding === "base64") bytes = (0, import_bytes.base64ToBytes)(input, verb);
|
|
137
|
+
else throw new Error(`${verb}: encoding must be 'hex' or 'base64'`);
|
|
138
|
+
} else if (input instanceof Uint8Array) {
|
|
139
|
+
bytes = (0, import_bytes.exactBytes)(input);
|
|
140
|
+
} else {
|
|
141
|
+
throw new TypeError(`${verb}: expected bytes or an encoded string`);
|
|
142
|
+
}
|
|
143
|
+
if (!KEY_SIZES.includes(bytes.length * 8)) {
|
|
144
|
+
throw new Error(`${verb}: key must be 128, 192, or 256 bits, got ${bytes.length * 8}`);
|
|
145
|
+
}
|
|
146
|
+
return new AESEncryptionKey2(bytes);
|
|
147
|
+
}
|
|
148
|
+
}]);
|
|
149
|
+
return AESEncryptionKey2;
|
|
150
|
+
})();
|
|
151
|
+
var AESSealedData = /* @__PURE__ */ (function() {
|
|
152
|
+
"use strict";
|
|
153
|
+
function AESSealedData2(parts) {
|
|
154
|
+
_class_call_check(this, AESSealedData2);
|
|
155
|
+
if (parts.iv.length === 0) throw new Error("Crypto.AESSealedData: iv must not be empty");
|
|
156
|
+
assertTagLength(parts.tag.length, "Crypto.AESSealedData");
|
|
157
|
+
sealedParts.set(this, parts);
|
|
158
|
+
}
|
|
159
|
+
_create_class(AESSealedData2, [
|
|
160
|
+
{
|
|
161
|
+
key: "ivSize",
|
|
162
|
+
get: function get() {
|
|
163
|
+
return sealedParts.get(this).iv.length;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
key: "tagSize",
|
|
168
|
+
get: function get() {
|
|
169
|
+
return sealedParts.get(this).tag.length;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
key: "combinedSize",
|
|
174
|
+
get: function get() {
|
|
175
|
+
var parts = sealedParts.get(this);
|
|
176
|
+
return parts.iv.length + parts.ciphertext.length + parts.tag.length;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
key: "iv",
|
|
181
|
+
value: async function iv(encoding) {
|
|
182
|
+
return encodeParts(sealedParts.get(this).iv, encoding);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
key: "tag",
|
|
187
|
+
value: async function tag(encoding) {
|
|
188
|
+
return encodeParts(sealedParts.get(this).tag, encoding);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: "ciphertext",
|
|
193
|
+
value: async function ciphertext(options) {
|
|
194
|
+
var parts = sealedParts.get(this);
|
|
195
|
+
var bytes = (options === null || options === void 0 ? void 0 : options.includeTag) ? (0, import_bytes.concatBytes)([parts.ciphertext, parts.tag]) : parts.ciphertext;
|
|
196
|
+
return encodeParts(bytes, options === null || options === void 0 ? void 0 : options.encoding);
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
key: "combined",
|
|
201
|
+
value: async function combined(encoding) {
|
|
202
|
+
var parts = sealedParts.get(this);
|
|
203
|
+
return encodeParts((0, import_bytes.concatBytes)([
|
|
204
|
+
parts.iv,
|
|
205
|
+
parts.ciphertext,
|
|
206
|
+
parts.tag
|
|
207
|
+
]), encoding);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
], [
|
|
211
|
+
{
|
|
212
|
+
key: "fromCombined",
|
|
213
|
+
value: function fromCombined(combined) {
|
|
214
|
+
var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
215
|
+
var _config_ivLength, _config_tagLength;
|
|
216
|
+
var verb = "Crypto.AESSealedData.fromCombined";
|
|
217
|
+
var ivLength = (_config_ivLength = config.ivLength) !== null && _config_ivLength !== void 0 ? _config_ivLength : DEFAULT_IV_LENGTH;
|
|
218
|
+
var tagLength = (_config_tagLength = config.tagLength) !== null && _config_tagLength !== void 0 ? _config_tagLength : DEFAULT_TAG_LENGTH;
|
|
219
|
+
assertTagLength(tagLength, verb);
|
|
220
|
+
if (!Number.isInteger(ivLength) || ivLength <= 0) {
|
|
221
|
+
throw new Error(`${verb}: ivLength must be a positive integer`);
|
|
222
|
+
}
|
|
223
|
+
var bytes = toBytes(combined, verb);
|
|
224
|
+
if (bytes.length < ivLength + tagLength) {
|
|
225
|
+
throw new Error(`${verb}: combined data is shorter than its iv and tag`);
|
|
226
|
+
}
|
|
227
|
+
return new AESSealedData2({
|
|
228
|
+
iv: (0, import_bytes.exactBytes)(bytes.subarray(0, ivLength)),
|
|
229
|
+
ciphertext: (0, import_bytes.exactBytes)(bytes.subarray(ivLength, bytes.length - tagLength)),
|
|
230
|
+
tag: (0, import_bytes.exactBytes)(bytes.subarray(bytes.length - tagLength))
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
key: "fromParts",
|
|
236
|
+
value: function fromParts(ivInput, ciphertextInput, tagOrLength) {
|
|
237
|
+
var verb = "Crypto.AESSealedData.fromParts";
|
|
238
|
+
var iv = toBytes(ivInput, verb);
|
|
239
|
+
var ciphertext = toBytes(ciphertextInput, verb);
|
|
240
|
+
if (tagOrLength === void 0 || typeof tagOrLength === "number") {
|
|
241
|
+
var tagLength = tagOrLength !== null && tagOrLength !== void 0 ? tagOrLength : DEFAULT_TAG_LENGTH;
|
|
242
|
+
assertTagLength(tagLength, verb);
|
|
243
|
+
if (ciphertext.length < tagLength) {
|
|
244
|
+
throw new Error(`${verb}: ciphertext is shorter than its tag`);
|
|
245
|
+
}
|
|
246
|
+
return new AESSealedData2({
|
|
247
|
+
iv,
|
|
248
|
+
ciphertext: (0, import_bytes.exactBytes)(ciphertext.subarray(0, ciphertext.length - tagLength)),
|
|
249
|
+
tag: (0, import_bytes.exactBytes)(ciphertext.subarray(ciphertext.length - tagLength))
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
var tag = toBytes(tagOrLength, verb);
|
|
253
|
+
assertTagLength(tag.length, verb);
|
|
254
|
+
return new AESSealedData2({
|
|
255
|
+
iv,
|
|
256
|
+
ciphertext,
|
|
257
|
+
tag
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
key: "fromSeal",
|
|
263
|
+
value: (function fromSeal(iv, ciphertextWithTag, tagLength) {
|
|
264
|
+
return new AESSealedData2({
|
|
265
|
+
iv,
|
|
266
|
+
ciphertext: (0, import_bytes.exactBytes)(ciphertextWithTag.subarray(0, ciphertextWithTag.length - tagLength)),
|
|
267
|
+
tag: (0, import_bytes.exactBytes)(ciphertextWithTag.subarray(ciphertextWithTag.length - tagLength))
|
|
268
|
+
});
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
]);
|
|
272
|
+
return AESSealedData2;
|
|
273
|
+
})();
|
|
274
|
+
async function keyMaterial(key, verb) {
|
|
275
|
+
var own = keyBytes.get(key);
|
|
276
|
+
if (own) return (0, import_bytes.exactBytes)(own);
|
|
277
|
+
if (key && typeof key.bytes === "function") return (0, import_bytes.exactBytes)(await key.bytes());
|
|
278
|
+
throw new TypeError(`${verb}: expected an AESEncryptionKey`);
|
|
279
|
+
}
|
|
280
|
+
async function partsOf(sealed, verb) {
|
|
281
|
+
var own = sealedParts.get(sealed);
|
|
282
|
+
if (own) {
|
|
283
|
+
return {
|
|
284
|
+
iv: (0, import_bytes.exactBytes)(own.iv),
|
|
285
|
+
ciphertext: (0, import_bytes.exactBytes)(own.ciphertext),
|
|
286
|
+
tag: (0, import_bytes.exactBytes)(own.tag)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (sealed && typeof sealed.iv === "function" && typeof sealed.combined === "function") {
|
|
290
|
+
var iv = (0, import_bytes.exactBytes)(await sealed.iv());
|
|
291
|
+
var tag = (0, import_bytes.exactBytes)(await sealed.tag());
|
|
292
|
+
var ciphertext = (0, import_bytes.exactBytes)(await sealed.ciphertext({
|
|
293
|
+
encoding: "bytes",
|
|
294
|
+
includeTag: false
|
|
295
|
+
}));
|
|
296
|
+
return {
|
|
297
|
+
iv,
|
|
298
|
+
ciphertext,
|
|
299
|
+
tag
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
throw new TypeError(`${verb}: expected an AESSealedData`);
|
|
303
|
+
}
|
|
304
|
+
async function aesEncrypt(plaintext, key) {
|
|
305
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
306
|
+
var _options_tagLength;
|
|
307
|
+
var verb = "Crypto.aesEncrypt";
|
|
308
|
+
var tagLength = (_options_tagLength = options.tagLength) !== null && _options_tagLength !== void 0 ? _options_tagLength : DEFAULT_TAG_LENGTH;
|
|
309
|
+
assertTagLength(tagLength, verb);
|
|
310
|
+
var iv;
|
|
311
|
+
var nonce = options.nonce;
|
|
312
|
+
if (nonce && "bytes" in nonce && nonce.bytes !== void 0) {
|
|
313
|
+
iv = toBytes(nonce.bytes, verb);
|
|
314
|
+
if (iv.length === 0) throw new Error(`${verb}: nonce bytes must not be empty`);
|
|
315
|
+
} else {
|
|
316
|
+
var length = nonce && "length" in nonce && nonce.length !== void 0 ? nonce.length : DEFAULT_IV_LENGTH;
|
|
317
|
+
if (!Number.isInteger(length) || length <= 0) {
|
|
318
|
+
throw new Error(`${verb}: nonce length must be a positive integer`);
|
|
319
|
+
}
|
|
320
|
+
iv = new Uint8Array(length);
|
|
321
|
+
engine.random(iv);
|
|
322
|
+
}
|
|
323
|
+
var additionalData = options.additionalData === void 0 ? void 0 : toBytes(options.additionalData, verb);
|
|
324
|
+
var plainBytes = toBytes(plaintext, verb);
|
|
325
|
+
var sealed = await engine.seal(await keyMaterial(key, verb), iv, plainBytes, additionalData, tagLength);
|
|
326
|
+
var actualTag = sealed.length - plainBytes.length;
|
|
327
|
+
return AESSealedData.fromSeal(iv, sealed, actualTag > 0 ? actualTag : tagLength);
|
|
328
|
+
}
|
|
329
|
+
async function aesDecrypt(sealedData, key) {
|
|
330
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
331
|
+
var verb = "Crypto.aesDecrypt";
|
|
332
|
+
var parts = await partsOf(sealedData, verb);
|
|
333
|
+
var additionalData = options.additionalData === void 0 ? void 0 : toBytes(options.additionalData, verb);
|
|
334
|
+
var plaintext = await engine.open(await keyMaterial(key, verb), parts.iv, (0, import_bytes.concatBytes)([parts.ciphertext, parts.tag]), additionalData, parts.tag.length);
|
|
335
|
+
return options.output === "base64" ? (0, import_bytes.bytesToBase64)(plaintext) : plaintext;
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
AESEncryptionKey,
|
|
339
|
+
AESSealedData,
|
|
340
|
+
aesEncrypt,
|
|
341
|
+
aesDecrypt
|
|
342
|
+
};
|
|
343
|
+
}
|