@ajna-inc/vaults 0.1.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/LICENSE +202 -0
- package/build/VaultsApi.js +263 -0
- package/build/VaultsEvents.js +19 -0
- package/build/VaultsModule.js +71 -0
- package/build/crypto/wasm/VaultCrypto.js +70 -0
- package/build/errors/BadSuiteError.js +34 -0
- package/build/errors/DecryptAeadError.js +34 -0
- package/build/errors/DecryptKemError.js +34 -0
- package/build/errors/PolicyError.js +34 -0
- package/build/errors/VaultError.js +77 -0
- package/build/errors/index.js +16 -0
- package/build/index.js +119 -0
- package/build/messages/CreateVaultMessage.js +126 -0
- package/build/messages/DeleteVaultMessage.js +114 -0
- package/build/messages/DenyAccessMessage.js +114 -0
- package/build/messages/DenyShareMessage.js +120 -0
- package/build/messages/GrantAccessMessage.js +126 -0
- package/build/messages/ProvideShareMessage.js +126 -0
- package/build/messages/RequestAccessMessage.js +120 -0
- package/build/messages/RequestShareMessage.js +120 -0
- package/build/messages/RetrieveVaultMessage.js +108 -0
- package/build/messages/StoreVaultMessage.js +114 -0
- package/build/messages/UpdateVaultMessage.js +120 -0
- package/build/messages/VaultCreatedAckMessage.js +108 -0
- package/build/messages/VaultDataMessage.js +121 -0
- package/build/messages/VaultProblemReportMessage.js +124 -0
- package/build/messages/VaultStoredAckMessage.js +115 -0
- package/build/messages/index.js +36 -0
- package/build/models/ThresholdSession.js +24 -0
- package/build/models/VaultDocument.js +28 -0
- package/build/models/VaultHeader.js +31 -0
- package/build/models/VaultPolicy.js +29 -0
- package/build/models/index.js +20 -0
- package/build/repository/ThresholdSessionRecord.js +117 -0
- package/build/repository/ThresholdSessionRepository.js +216 -0
- package/build/repository/VaultRecord.js +128 -0
- package/build/repository/VaultRepository.js +200 -0
- package/build/repository/index.js +13 -0
- package/build/services/VaultEncryptionService.js +613 -0
- package/build/services/VaultService.js +398 -0
- package/build/services/index.js +8 -0
- package/package.json +45 -0
- package/wasm/README.md +166 -0
- package/wasm/package.json +16 -0
- package/wasm/vault_crypto.d.ts +526 -0
- package/wasm/vault_crypto.js +2137 -0
- package/wasm/vault_crypto_bg.wasm +0 -0
- package/wasm/vault_crypto_bg.wasm.d.ts +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020-present Hyperledger Contributors.
|
|
190
|
+
Copyright 2021 Queen’s Printer for Ontario. Mostafa Youssef (https://github.com/MosCD3), Amit Padmani (https://github.com/nbAmit), Prasad Katkar (https://github.com/NB-PrasadKatkar), Mike Richardson (https://github.com/NB-MikeRichardson)
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
73
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
74
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
75
|
+
};
|
|
76
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
|
+
exports.VaultsApi = void 0;
|
|
78
|
+
var core_1 = require("@credo-ts/core");
|
|
79
|
+
/**
|
|
80
|
+
* Vaults API
|
|
81
|
+
*
|
|
82
|
+
* Public API for vault operations.
|
|
83
|
+
* Provides a clean interface for creating, opening, and managing encrypted vaults.
|
|
84
|
+
*
|
|
85
|
+
* All encryption and decryption happens client-side.
|
|
86
|
+
*/
|
|
87
|
+
var VaultsApi = function () {
|
|
88
|
+
var _classDecorators = [(0, core_1.injectable)()];
|
|
89
|
+
var _classDescriptor;
|
|
90
|
+
var _classExtraInitializers = [];
|
|
91
|
+
var _classThis;
|
|
92
|
+
var VaultsApi = _classThis = /** @class */ (function () {
|
|
93
|
+
function VaultsApi_1(agentContext, vaultService) {
|
|
94
|
+
this.vaultService = vaultService;
|
|
95
|
+
this.agentContext = agentContext;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a new encrypted vault
|
|
99
|
+
*
|
|
100
|
+
* @param data - Raw data to encrypt (e.g., PDF bytes)
|
|
101
|
+
* @param options - Creation options including passphrase
|
|
102
|
+
* @returns Created vault identifiers
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const pdfBytes = await fs.readFile('contract.pdf')
|
|
107
|
+
* const { vaultId } = await agent.modules.vaults.create(pdfBytes, {
|
|
108
|
+
* passphrase: 'my-secure-passphrase',
|
|
109
|
+
* metadata: { description: 'Employment Contract' }
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
VaultsApi_1.prototype.create = function (data, options) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
return [2 /*return*/, this.vaultService.createVault(this.agentContext, data, options)];
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Open (decrypt) a vault
|
|
122
|
+
*
|
|
123
|
+
* @param vaultId - Vault identifier
|
|
124
|
+
* @param options - Open options including passphrase
|
|
125
|
+
* @returns Decrypted data
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const decrypted = await agent.modules.vaults.open(vaultId, {
|
|
130
|
+
* passphrase: 'my-secure-passphrase'
|
|
131
|
+
* })
|
|
132
|
+
* await fs.writeFile('contract-decrypted.pdf', decrypted)
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
VaultsApi_1.prototype.open = function (vaultId, options) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
return [2 /*return*/, this.vaultService.openVault(this.agentContext, vaultId, options)];
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Update vault with new data
|
|
144
|
+
*
|
|
145
|
+
* @param vaultId - Vault identifier
|
|
146
|
+
* @param data - New data to encrypt
|
|
147
|
+
* @param options - Update options including passphrase
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const newPdfBytes = await fs.readFile('contract-v2.pdf')
|
|
152
|
+
* await agent.modules.vaults.update(vaultId, newPdfBytes, {
|
|
153
|
+
* passphrase: 'my-secure-passphrase'
|
|
154
|
+
* })
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
VaultsApi_1.prototype.update = function (vaultId, data, options) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
+
return __generator(this, function (_a) {
|
|
160
|
+
return [2 /*return*/, this.vaultService.updateVault(this.agentContext, vaultId, data, options)];
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Delete a vault
|
|
166
|
+
*
|
|
167
|
+
* @param vaultId - Vault identifier
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* await agent.modules.vaults.delete(vaultId)
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
VaultsApi_1.prototype.delete = function (vaultId) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
return [2 /*return*/, this.vaultService.deleteVault(this.agentContext, vaultId)];
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* List all vaults
|
|
183
|
+
*
|
|
184
|
+
* @returns Array of vault records
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const vaults = await agent.modules.vaults.list()
|
|
189
|
+
* console.log(`Total vaults: ${vaults.length}`)
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
VaultsApi_1.prototype.list = function () {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
return [2 /*return*/, this.vaultService.listVaults(this.agentContext)];
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Get vault info (metadata without decrypting)
|
|
201
|
+
*
|
|
202
|
+
* @param vaultId - Vault identifier
|
|
203
|
+
* @returns Vault information
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const info = await agent.modules.vaults.getInfo(vaultId)
|
|
208
|
+
* console.log(`Vault: ${info.vaultId}, Epoch: ${info.header.epoch}`)
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
VaultsApi_1.prototype.getInfo = function (vaultId) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
return [2 /*return*/, this.vaultService.getVaultInfo(this.agentContext, vaultId)];
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Check if a vault exists
|
|
220
|
+
*
|
|
221
|
+
* @param vaultId - Vault identifier
|
|
222
|
+
* @returns True if vault exists
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* if (await agent.modules.vaults.exists(vaultId)) {
|
|
227
|
+
* console.log('Vault found!')
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
VaultsApi_1.prototype.exists = function (vaultId) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
return __generator(this, function (_a) {
|
|
234
|
+
return [2 /*return*/, this.vaultService.vaultExists(this.agentContext, vaultId)];
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Get the raw vault record (for advanced operations)
|
|
240
|
+
*
|
|
241
|
+
* @param vaultId - Vault identifier
|
|
242
|
+
* @returns Vault record or null
|
|
243
|
+
*/
|
|
244
|
+
VaultsApi_1.prototype.getRecord = function (vaultId) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
+
return __generator(this, function (_a) {
|
|
247
|
+
return [2 /*return*/, this.vaultService.getVaultRecord(this.agentContext, vaultId)];
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
return VaultsApi_1;
|
|
252
|
+
}());
|
|
253
|
+
__setFunctionName(_classThis, "VaultsApi");
|
|
254
|
+
(function () {
|
|
255
|
+
var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
256
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
257
|
+
VaultsApi = _classThis = _classDescriptor.value;
|
|
258
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
259
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
260
|
+
})();
|
|
261
|
+
return VaultsApi = _classThis;
|
|
262
|
+
}();
|
|
263
|
+
exports.VaultsApi = VaultsApi;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultEventTypes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Vault event types
|
|
6
|
+
*/
|
|
7
|
+
var VaultEventTypes;
|
|
8
|
+
(function (VaultEventTypes) {
|
|
9
|
+
VaultEventTypes["VaultCreated"] = "VaultCreated";
|
|
10
|
+
VaultEventTypes["VaultOpened"] = "VaultOpened";
|
|
11
|
+
VaultEventTypes["VaultUpdated"] = "VaultUpdated";
|
|
12
|
+
VaultEventTypes["VaultDeleted"] = "VaultDeleted";
|
|
13
|
+
VaultEventTypes["VaultShared"] = "VaultShared";
|
|
14
|
+
VaultEventTypes["AccessRequested"] = "AccessRequested";
|
|
15
|
+
VaultEventTypes["AccessGranted"] = "AccessGranted";
|
|
16
|
+
VaultEventTypes["AccessDenied"] = "AccessDenied";
|
|
17
|
+
VaultEventTypes["ThresholdMet"] = "ThresholdMet";
|
|
18
|
+
VaultEventTypes["ShareProvided"] = "ShareProvided";
|
|
19
|
+
})(VaultEventTypes || (exports.VaultEventTypes = VaultEventTypes = {}));
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultsModule = void 0;
|
|
4
|
+
var VaultsApi_1 = require("./VaultsApi");
|
|
5
|
+
var VaultService_1 = require("./services/VaultService");
|
|
6
|
+
var VaultEncryptionService_1 = require("./services/VaultEncryptionService");
|
|
7
|
+
var VaultRepository_1 = require("./repository/VaultRepository");
|
|
8
|
+
var ThresholdSessionRepository_1 = require("./repository/ThresholdSessionRepository");
|
|
9
|
+
/**
|
|
10
|
+
* Vaults Module
|
|
11
|
+
*
|
|
12
|
+
* Credo-TS module for post-quantum encrypted vaults with local storage support.
|
|
13
|
+
*
|
|
14
|
+
* Features:
|
|
15
|
+
* - Client-side encryption (all crypto happens in the agent)
|
|
16
|
+
* - Passphrase-based encryption (S3 suite with Argon2id)
|
|
17
|
+
* - Post-quantum encryption (P1 suite with ML-KEM-768)
|
|
18
|
+
* - Multiple access policies: passphrase, any-of, all-of, threshold
|
|
19
|
+
* - Local storage via agent wallet
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { Agent } from '@credo-ts/core'
|
|
24
|
+
* import { VaultsModule } from '@credo-ts/vaults'
|
|
25
|
+
*
|
|
26
|
+
* const agent = new Agent({
|
|
27
|
+
* config: { label: 'My Agent' },
|
|
28
|
+
* modules: {
|
|
29
|
+
* vaults: new VaultsModule()
|
|
30
|
+
* }
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* await agent.initialize()
|
|
34
|
+
*
|
|
35
|
+
* // Store encrypted PDF
|
|
36
|
+
* const { vaultId } = await agent.modules.vaults.create(pdfBytes, {
|
|
37
|
+
* passphrase: 'my-secure-passphrase'
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // Retrieve and decrypt
|
|
41
|
+
* const decrypted = await agent.modules.vaults.open(vaultId, {
|
|
42
|
+
* passphrase: 'my-secure-passphrase'
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
var VaultsModule = /** @class */ (function () {
|
|
47
|
+
function VaultsModule() {
|
|
48
|
+
this.api = VaultsApi_1.VaultsApi;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Register module dependencies
|
|
52
|
+
*/
|
|
53
|
+
VaultsModule.prototype.register = function (dependencyManager, featureRegistry) {
|
|
54
|
+
// Register repositories
|
|
55
|
+
dependencyManager.registerSingleton(VaultRepository_1.VaultRepository);
|
|
56
|
+
dependencyManager.registerSingleton(ThresholdSessionRepository_1.ThresholdSessionRepository);
|
|
57
|
+
// Register services
|
|
58
|
+
dependencyManager.registerSingleton(VaultEncryptionService_1.VaultEncryptionService);
|
|
59
|
+
dependencyManager.registerSingleton(VaultService_1.VaultService);
|
|
60
|
+
// Note: Message handlers for P2P sharing will be added in Phase 5
|
|
61
|
+
// For now, we focus on local storage operations
|
|
62
|
+
// Register protocol feature
|
|
63
|
+
featureRegistry.register({
|
|
64
|
+
type: 'protocol',
|
|
65
|
+
id: 'https://didcomm.org/vaults/1.0',
|
|
66
|
+
roles: ['owner', 'participant', 'storage'],
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return VaultsModule;
|
|
70
|
+
}());
|
|
71
|
+
exports.VaultsModule = VaultsModule;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WASM Cryptographic Primitives Wrapper
|
|
4
|
+
*
|
|
5
|
+
* Wraps vault-crypto WASM module for use in Credo-TS
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
18
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.buildContext = exports.canonicalAad = exports.generateUuid = exports.fromHex = exports.toHex = exports.fromBase64Url = exports.toBase64Url = exports.constantTimeEq = exports.computeSummary = exports.blake2s256 = exports.sha256 = exports.verifyKeyCommitment = exports.keyCommitment = exports.generateNonceXchacha = exports.generateNonceAesGcm = exports.generateCek = exports.randomBytes = exports.shamirUnwrapAndReconstruct = exports.shamirSplitAndWrap = exports.shamirReconstruct = exports.shamirSplit = exports.deriveSymmetricKid = exports.deriveKid = exports.deriveCek = exports.hkdfJoin = exports.hkdfExpand = exports.kemUnwrapCek = exports.kemWrapCek = exports.kemDecapsulate = exports.kemEncapsulate = exports.kemGenerateKeypair = exports.xchachaDecrypt = exports.xchachaEncrypt = exports.aesGcmDecrypt = exports.aesGcmEncrypt = exports.initVaultCrypto = void 0;
|
|
45
|
+
// Import WASM module
|
|
46
|
+
// Note: In Node.js, this auto-initializes
|
|
47
|
+
var wasm = require("../../../wasm/vault_crypto.js");
|
|
48
|
+
/**
|
|
49
|
+
* Initialize WASM module
|
|
50
|
+
* Call once at agent startup
|
|
51
|
+
*/
|
|
52
|
+
function initVaultCrypto() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
return __generator(this, function (_a) {
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.initVaultCrypto = initVaultCrypto;
|
|
60
|
+
// Re-export all WASM functions with documentation
|
|
61
|
+
// ========== AEAD Encryption ==========
|
|
62
|
+
exports.aesGcmEncrypt = wasm.aesGcmEncrypt, exports.aesGcmDecrypt = wasm.aesGcmDecrypt, exports.xchachaEncrypt = wasm.xchachaEncrypt, exports.xchachaDecrypt = wasm.xchachaDecrypt;
|
|
63
|
+
// ========== Key Encapsulation (KEM) ==========
|
|
64
|
+
exports.kemGenerateKeypair = wasm.kemGenerateKeypair, exports.kemEncapsulate = wasm.kemEncapsulate, exports.kemDecapsulate = wasm.kemDecapsulate, exports.kemWrapCek = wasm.kemWrapCek, exports.kemUnwrapCek = wasm.kemUnwrapCek;
|
|
65
|
+
// ========== Key Derivation (KDF) ==========
|
|
66
|
+
exports.hkdfExpand = wasm.hkdfExpand, exports.hkdfJoin = wasm.hkdfJoin, exports.deriveCek = wasm.deriveCek, exports.deriveKid = wasm.deriveKid, exports.deriveSymmetricKid = wasm.deriveSymmetricKid;
|
|
67
|
+
// ========== Shamir Secret Sharing ==========
|
|
68
|
+
exports.shamirSplit = wasm.shamirSplit, exports.shamirReconstruct = wasm.shamirReconstruct, exports.shamirSplitAndWrap = wasm.shamirSplitAndWrap, exports.shamirUnwrapAndReconstruct = wasm.shamirUnwrapAndReconstruct;
|
|
69
|
+
// ========== Utilities ==========
|
|
70
|
+
exports.randomBytes = wasm.randomBytes, exports.generateCek = wasm.generateCek, exports.generateNonceAesGcm = wasm.generateNonceAesGcm, exports.generateNonceXchacha = wasm.generateNonceXchacha, exports.keyCommitment = wasm.keyCommitment, exports.verifyKeyCommitment = wasm.verifyKeyCommitment, exports.sha256 = wasm.sha256, exports.blake2s256 = wasm.blake2s256, exports.computeSummary = wasm.computeSummary, exports.constantTimeEq = wasm.constantTimeEq, exports.toBase64Url = wasm.toBase64Url, exports.fromBase64Url = wasm.fromBase64Url, exports.toHex = wasm.toHex, exports.fromHex = wasm.fromHex, exports.generateUuid = wasm.generateUuid, exports.canonicalAad = wasm.canonicalAad, exports.buildContext = wasm.buildContext;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.BadSuiteError = void 0;
|
|
19
|
+
var VaultError_1 = require("./VaultError");
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when an unknown or unsupported ciphersuite is encountered
|
|
22
|
+
* Spec §11: ERR_BAD_SUITE
|
|
23
|
+
*/
|
|
24
|
+
var BadSuiteError = /** @class */ (function (_super) {
|
|
25
|
+
__extends(BadSuiteError, _super);
|
|
26
|
+
function BadSuiteError(message) {
|
|
27
|
+
var _this = _super.call(this, VaultError_1.VaultErrorCode.BAD_SUITE, message) || this;
|
|
28
|
+
_this.name = 'BadSuiteError';
|
|
29
|
+
Object.setPrototypeOf(_this, BadSuiteError.prototype);
|
|
30
|
+
return _this;
|
|
31
|
+
}
|
|
32
|
+
return BadSuiteError;
|
|
33
|
+
}(VaultError_1.VaultError));
|
|
34
|
+
exports.BadSuiteError = BadSuiteError;
|