@credo-ts/askar 0.5.0-alpha.101
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/README.md +31 -0
- package/build/AskarModule.d.ts +9 -0
- package/build/AskarModule.js +62 -0
- package/build/AskarModule.js.map +1 -0
- package/build/AskarModuleConfig.d.ts +68 -0
- package/build/AskarModuleConfig.js +33 -0
- package/build/AskarModuleConfig.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +16 -0
- package/build/index.js.map +1 -0
- package/build/storage/AskarStorageService.d.ts +17 -0
- package/build/storage/AskarStorageService.js +145 -0
- package/build/storage/AskarStorageService.js.map +1 -0
- package/build/storage/index.d.ts +1 -0
- package/build/storage/index.js +18 -0
- package/build/storage/index.js.map +1 -0
- package/build/storage/utils.d.ts +15 -0
- package/build/storage/utils.js +109 -0
- package/build/storage/utils.js.map +1 -0
- package/build/utils/askarError.d.ts +14 -0
- package/build/utils/askarError.js +20 -0
- package/build/utils/askarError.js.map +1 -0
- package/build/utils/askarKeyTypes.d.ts +3 -0
- package/build/utils/askarKeyTypes.js +17 -0
- package/build/utils/askarKeyTypes.js.map +1 -0
- package/build/utils/askarWalletConfig.d.ts +14 -0
- package/build/utils/askarWalletConfig.js +73 -0
- package/build/utils/askarWalletConfig.js.map +1 -0
- package/build/utils/assertAskarWallet.d.ts +3 -0
- package/build/utils/assertAskarWallet.js +15 -0
- package/build/utils/assertAskarWallet.js.map +1 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.js +20 -0
- package/build/utils/index.js.map +1 -0
- package/build/wallet/AskarBaseWallet.d.ts +73 -0
- package/build/wallet/AskarBaseWallet.js +429 -0
- package/build/wallet/AskarBaseWallet.js.map +1 -0
- package/build/wallet/AskarProfileWallet.d.ts +24 -0
- package/build/wallet/AskarProfileWallet.js +166 -0
- package/build/wallet/AskarProfileWallet.js.map +1 -0
- package/build/wallet/AskarWallet.d.ts +64 -0
- package/build/wallet/AskarWallet.js +338 -0
- package/build/wallet/AskarWallet.js.map +1 -0
- package/build/wallet/AskarWalletPostgresStorageConfig.d.ts +19 -0
- package/build/wallet/AskarWalletPostgresStorageConfig.js +3 -0
- package/build/wallet/AskarWalletPostgresStorageConfig.js.map +1 -0
- package/build/wallet/JweEnvelope.d.ts +32 -0
- package/build/wallet/JweEnvelope.js +55 -0
- package/build/wallet/JweEnvelope.js.map +1 -0
- package/build/wallet/index.d.ts +3 -0
- package/build/wallet/index.js +23 -0
- package/build/wallet/index.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { WalletConfig, WalletConfigRekey, WalletExportImportConfig } from '@credo-ts/core';
|
|
2
|
+
import { Logger, SigningProviderRegistry, FileSystem } from '@credo-ts/core';
|
|
3
|
+
import { Store } from '@hyperledger/aries-askar-shared';
|
|
4
|
+
import { AskarBaseWallet } from './AskarBaseWallet';
|
|
5
|
+
import { AskarProfileWallet } from './AskarProfileWallet';
|
|
6
|
+
/**
|
|
7
|
+
* @todo: rename after 0.5.0, as we now have multiple types of AskarWallet
|
|
8
|
+
*/
|
|
9
|
+
export declare class AskarWallet extends AskarBaseWallet {
|
|
10
|
+
private fileSystem;
|
|
11
|
+
private walletConfig?;
|
|
12
|
+
private _store?;
|
|
13
|
+
constructor(logger: Logger, fileSystem: FileSystem, signingKeyProviderRegistry: SigningProviderRegistry);
|
|
14
|
+
get isProvisioned(): boolean;
|
|
15
|
+
get isInitialized(): boolean;
|
|
16
|
+
get store(): Store;
|
|
17
|
+
get profile(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Dispose method is called when an agent context is disposed.
|
|
20
|
+
*/
|
|
21
|
+
dispose(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* @throws {WalletDuplicateError} if the wallet already exists
|
|
24
|
+
* @throws {WalletError} if another error occurs
|
|
25
|
+
*/
|
|
26
|
+
create(walletConfig: WalletConfig): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* TODO: we can add this method, and add custom logic in the tenants module
|
|
29
|
+
* or we can try to register the store on the agent context
|
|
30
|
+
*/
|
|
31
|
+
getProfileWallet(): Promise<AskarProfileWallet>;
|
|
32
|
+
/**
|
|
33
|
+
* @throws {WalletDuplicateError} if the wallet already exists
|
|
34
|
+
* @throws {WalletError} if another error occurs
|
|
35
|
+
*/
|
|
36
|
+
createAndOpen(walletConfig: WalletConfig): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
39
|
+
* @throws {WalletError} if another error occurs
|
|
40
|
+
*/
|
|
41
|
+
open(walletConfig: WalletConfig): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
44
|
+
* @throws {WalletError} if another error occurs
|
|
45
|
+
*/
|
|
46
|
+
rotateKey(walletConfig: WalletConfigRekey): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
49
|
+
* @throws {WalletError} if another error occurs
|
|
50
|
+
*/
|
|
51
|
+
private _open;
|
|
52
|
+
/**
|
|
53
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
54
|
+
* @throws {WalletError} if another error occurs
|
|
55
|
+
*/
|
|
56
|
+
delete(): Promise<void>;
|
|
57
|
+
export(exportConfig: WalletExportImportConfig): Promise<void>;
|
|
58
|
+
import(walletConfig: WalletConfig, importConfig: WalletExportImportConfig): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* @throws {WalletError} if the wallet is already closed or another error occurs
|
|
61
|
+
*/
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
private getAskarWalletConfig;
|
|
64
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AskarWallet = void 0;
|
|
16
|
+
const core_1 = require("@credo-ts/core");
|
|
17
|
+
// eslint-disable-next-line import/order
|
|
18
|
+
const aries_askar_shared_1 = require("@hyperledger/aries-askar-shared");
|
|
19
|
+
const tsyringe_1 = require("tsyringe");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
const AskarBaseWallet_1 = require("./AskarBaseWallet");
|
|
22
|
+
const AskarProfileWallet_1 = require("./AskarProfileWallet");
|
|
23
|
+
/**
|
|
24
|
+
* @todo: rename after 0.5.0, as we now have multiple types of AskarWallet
|
|
25
|
+
*/
|
|
26
|
+
let AskarWallet = class AskarWallet extends AskarBaseWallet_1.AskarBaseWallet {
|
|
27
|
+
constructor(logger, fileSystem, signingKeyProviderRegistry) {
|
|
28
|
+
super(logger, signingKeyProviderRegistry);
|
|
29
|
+
this.fileSystem = fileSystem;
|
|
30
|
+
}
|
|
31
|
+
get isProvisioned() {
|
|
32
|
+
return this.walletConfig !== undefined;
|
|
33
|
+
}
|
|
34
|
+
get isInitialized() {
|
|
35
|
+
return this._store !== undefined;
|
|
36
|
+
}
|
|
37
|
+
get store() {
|
|
38
|
+
if (!this._store) {
|
|
39
|
+
throw new core_1.AriesFrameworkError('Wallet has not been initialized yet. Make sure to await agent.initialize() before using the agent.');
|
|
40
|
+
}
|
|
41
|
+
return this._store;
|
|
42
|
+
}
|
|
43
|
+
get profile() {
|
|
44
|
+
if (!this.walletConfig) {
|
|
45
|
+
throw new core_1.WalletError('No profile configured.');
|
|
46
|
+
}
|
|
47
|
+
return this.walletConfig.id;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Dispose method is called when an agent context is disposed.
|
|
51
|
+
*/
|
|
52
|
+
async dispose() {
|
|
53
|
+
if (this.isInitialized) {
|
|
54
|
+
await this.close();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @throws {WalletDuplicateError} if the wallet already exists
|
|
59
|
+
* @throws {WalletError} if another error occurs
|
|
60
|
+
*/
|
|
61
|
+
async create(walletConfig) {
|
|
62
|
+
await this.createAndOpen(walletConfig);
|
|
63
|
+
await this.close();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* TODO: we can add this method, and add custom logic in the tenants module
|
|
67
|
+
* or we can try to register the store on the agent context
|
|
68
|
+
*/
|
|
69
|
+
async getProfileWallet() {
|
|
70
|
+
return new AskarProfileWallet_1.AskarProfileWallet(this.store, this.logger, this.signingKeyProviderRegistry);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @throws {WalletDuplicateError} if the wallet already exists
|
|
74
|
+
* @throws {WalletError} if another error occurs
|
|
75
|
+
*/
|
|
76
|
+
async createAndOpen(walletConfig) {
|
|
77
|
+
this.logger.debug(`Creating wallet '${walletConfig.id}`);
|
|
78
|
+
const askarWalletConfig = await this.getAskarWalletConfig(walletConfig);
|
|
79
|
+
// Check if database exists
|
|
80
|
+
const { path: filePath } = (0, utils_1.uriFromWalletConfig)(walletConfig, this.fileSystem.dataPath);
|
|
81
|
+
if (filePath && (await this.fileSystem.exists(filePath))) {
|
|
82
|
+
throw new core_1.WalletDuplicateError(`Wallet '${walletConfig.id}' already exists.`, {
|
|
83
|
+
walletType: 'AskarWallet',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
// Make sure path exists before creating the wallet
|
|
88
|
+
if (filePath) {
|
|
89
|
+
await this.fileSystem.createDirectory(filePath);
|
|
90
|
+
}
|
|
91
|
+
this._store = await aries_askar_shared_1.Store.provision({
|
|
92
|
+
recreate: false,
|
|
93
|
+
uri: askarWalletConfig.uri,
|
|
94
|
+
profile: askarWalletConfig.profile,
|
|
95
|
+
keyMethod: askarWalletConfig.keyMethod,
|
|
96
|
+
passKey: askarWalletConfig.passKey,
|
|
97
|
+
});
|
|
98
|
+
this.walletConfig = walletConfig;
|
|
99
|
+
this._session = await this._store.openSession();
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
// FIXME: Askar should throw a Duplicate error code, but is currently returning Encryption
|
|
103
|
+
// And if we provide the very same wallet key, it will open it without any error
|
|
104
|
+
if ((0, utils_1.isAskarError)(error) &&
|
|
105
|
+
(error.code === utils_1.AskarErrorCode.Encryption || error.code === utils_1.AskarErrorCode.Duplicate)) {
|
|
106
|
+
const errorMessage = `Wallet '${walletConfig.id}' already exists`;
|
|
107
|
+
this.logger.debug(errorMessage);
|
|
108
|
+
throw new core_1.WalletDuplicateError(errorMessage, {
|
|
109
|
+
walletType: 'AskarWallet',
|
|
110
|
+
cause: error,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const errorMessage = `Error creating wallet '${walletConfig.id}'`;
|
|
114
|
+
this.logger.error(errorMessage, {
|
|
115
|
+
error,
|
|
116
|
+
errorMessage: error.message,
|
|
117
|
+
});
|
|
118
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
119
|
+
}
|
|
120
|
+
this.logger.debug(`Successfully created wallet '${walletConfig.id}'`);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
124
|
+
* @throws {WalletError} if another error occurs
|
|
125
|
+
*/
|
|
126
|
+
async open(walletConfig) {
|
|
127
|
+
await this._open(walletConfig);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
131
|
+
* @throws {WalletError} if another error occurs
|
|
132
|
+
*/
|
|
133
|
+
async rotateKey(walletConfig) {
|
|
134
|
+
if (!walletConfig.rekey) {
|
|
135
|
+
throw new core_1.WalletError('Wallet rekey undefined!. Please specify the new wallet key');
|
|
136
|
+
}
|
|
137
|
+
await this._open({
|
|
138
|
+
id: walletConfig.id,
|
|
139
|
+
key: walletConfig.key,
|
|
140
|
+
keyDerivationMethod: walletConfig.keyDerivationMethod,
|
|
141
|
+
}, walletConfig.rekey, walletConfig.rekeyDerivationMethod);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
145
|
+
* @throws {WalletError} if another error occurs
|
|
146
|
+
*/
|
|
147
|
+
async _open(walletConfig, rekey, rekeyDerivation) {
|
|
148
|
+
var _a;
|
|
149
|
+
if (this._store) {
|
|
150
|
+
throw new core_1.WalletError('Wallet instance already opened. Close the currently opened wallet before re-opening the wallet');
|
|
151
|
+
}
|
|
152
|
+
const askarWalletConfig = await this.getAskarWalletConfig(walletConfig);
|
|
153
|
+
try {
|
|
154
|
+
this._store = await aries_askar_shared_1.Store.open({
|
|
155
|
+
uri: askarWalletConfig.uri,
|
|
156
|
+
keyMethod: askarWalletConfig.keyMethod,
|
|
157
|
+
passKey: askarWalletConfig.passKey,
|
|
158
|
+
});
|
|
159
|
+
if (rekey) {
|
|
160
|
+
await this._store.rekey({
|
|
161
|
+
passKey: rekey,
|
|
162
|
+
keyMethod: (0, utils_1.keyDerivationMethodToStoreKeyMethod)(rekeyDerivation !== null && rekeyDerivation !== void 0 ? rekeyDerivation : core_1.KeyDerivationMethod.Argon2IMod),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
this._session = await this._store.openSession();
|
|
166
|
+
this.walletConfig = walletConfig;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if ((0, utils_1.isAskarError)(error) &&
|
|
170
|
+
(error.code === utils_1.AskarErrorCode.NotFound ||
|
|
171
|
+
(error.code === utils_1.AskarErrorCode.Backend && ((_a = walletConfig.storage) === null || _a === void 0 ? void 0 : _a.inMemory)))) {
|
|
172
|
+
const errorMessage = `Wallet '${walletConfig.id}' not found`;
|
|
173
|
+
this.logger.debug(errorMessage);
|
|
174
|
+
throw new core_1.WalletNotFoundError(errorMessage, {
|
|
175
|
+
walletType: 'AskarWallet',
|
|
176
|
+
cause: error,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if ((0, utils_1.isAskarError)(error) && error.code === utils_1.AskarErrorCode.Encryption) {
|
|
180
|
+
const errorMessage = `Incorrect key for wallet '${walletConfig.id}'`;
|
|
181
|
+
this.logger.debug(errorMessage);
|
|
182
|
+
throw new core_1.WalletInvalidKeyError(errorMessage, {
|
|
183
|
+
walletType: 'AskarWallet',
|
|
184
|
+
cause: error,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
throw new core_1.WalletError(`Error opening wallet ${walletConfig.id}: ${error.message}`, { cause: error });
|
|
188
|
+
}
|
|
189
|
+
this.logger.debug(`Wallet '${walletConfig.id}' opened with handle '${this._store.handle.handle}'`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
193
|
+
* @throws {WalletError} if another error occurs
|
|
194
|
+
*/
|
|
195
|
+
async delete() {
|
|
196
|
+
if (!this.walletConfig) {
|
|
197
|
+
throw new core_1.WalletError('Can not delete wallet that does not have wallet config set. Make sure to call create wallet before deleting the wallet');
|
|
198
|
+
}
|
|
199
|
+
this.logger.info(`Deleting wallet '${this.walletConfig.id}'`);
|
|
200
|
+
if (this._store) {
|
|
201
|
+
await this.close();
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const { uri } = (0, utils_1.uriFromWalletConfig)(this.walletConfig, this.fileSystem.dataPath);
|
|
205
|
+
await aries_askar_shared_1.Store.remove(uri);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
const errorMessage = `Error deleting wallet '${this.walletConfig.id}': ${error.message}`;
|
|
209
|
+
this.logger.error(errorMessage, {
|
|
210
|
+
error,
|
|
211
|
+
errorMessage: error.message,
|
|
212
|
+
});
|
|
213
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async export(exportConfig) {
|
|
217
|
+
if (!this.walletConfig) {
|
|
218
|
+
throw new core_1.WalletError('Can not export wallet that does not have wallet config set. Make sure to open it before exporting');
|
|
219
|
+
}
|
|
220
|
+
const { path: destinationPath, key: exportKey } = exportConfig;
|
|
221
|
+
const { path: sourcePath } = (0, utils_1.uriFromWalletConfig)(this.walletConfig, this.fileSystem.dataPath);
|
|
222
|
+
if (!sourcePath) {
|
|
223
|
+
throw new core_1.WalletError('Export is only supported for SQLite backend');
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
// Export path already exists
|
|
227
|
+
if (await this.fileSystem.exists(destinationPath)) {
|
|
228
|
+
throw new core_1.WalletExportPathExistsError(`Unable to create export, wallet export at path '${exportConfig.path}' already exists`);
|
|
229
|
+
}
|
|
230
|
+
const exportedWalletConfig = await this.getAskarWalletConfig(Object.assign(Object.assign({}, this.walletConfig), { key: exportKey, storage: { type: 'sqlite', path: destinationPath } }));
|
|
231
|
+
// Make sure destination path exists
|
|
232
|
+
await this.fileSystem.createDirectory(destinationPath);
|
|
233
|
+
await this.store.copyTo({
|
|
234
|
+
recreate: false,
|
|
235
|
+
uri: exportedWalletConfig.uri,
|
|
236
|
+
keyMethod: exportedWalletConfig.keyMethod,
|
|
237
|
+
passKey: exportedWalletConfig.passKey,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
const errorMessage = `Error exporting wallet '${this.walletConfig.id}': ${error.message}`;
|
|
242
|
+
this.logger.error(errorMessage, {
|
|
243
|
+
error,
|
|
244
|
+
errorMessage: error.message,
|
|
245
|
+
});
|
|
246
|
+
if (error instanceof core_1.WalletExportPathExistsError)
|
|
247
|
+
throw error;
|
|
248
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async import(walletConfig, importConfig) {
|
|
252
|
+
const { path: sourcePath, key: importKey } = importConfig;
|
|
253
|
+
const { path: destinationPath } = (0, utils_1.uriFromWalletConfig)(walletConfig, this.fileSystem.dataPath);
|
|
254
|
+
if (!destinationPath) {
|
|
255
|
+
throw new core_1.WalletError('Import is only supported for SQLite backend');
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const importWalletConfig = await this.getAskarWalletConfig(walletConfig);
|
|
259
|
+
// Import path already exists
|
|
260
|
+
if (await this.fileSystem.exists(destinationPath)) {
|
|
261
|
+
throw new core_1.WalletExportPathExistsError(`Unable to import wallet. Path '${destinationPath}' already exists`);
|
|
262
|
+
}
|
|
263
|
+
// Make sure destination path exists
|
|
264
|
+
await this.fileSystem.createDirectory(destinationPath);
|
|
265
|
+
// Open imported wallet and copy to destination
|
|
266
|
+
const sourceWalletStore = await aries_askar_shared_1.Store.open({
|
|
267
|
+
uri: `sqlite://${sourcePath}`,
|
|
268
|
+
keyMethod: importWalletConfig.keyMethod,
|
|
269
|
+
passKey: importKey,
|
|
270
|
+
});
|
|
271
|
+
await sourceWalletStore.copyTo({
|
|
272
|
+
recreate: false,
|
|
273
|
+
uri: importWalletConfig.uri,
|
|
274
|
+
keyMethod: importWalletConfig.keyMethod,
|
|
275
|
+
passKey: importWalletConfig.passKey,
|
|
276
|
+
});
|
|
277
|
+
await sourceWalletStore.close();
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
const errorMessage = `Error importing wallet '${walletConfig.id}': ${error.message}`;
|
|
281
|
+
this.logger.error(errorMessage, {
|
|
282
|
+
error,
|
|
283
|
+
errorMessage: error.message,
|
|
284
|
+
});
|
|
285
|
+
if (error instanceof core_1.WalletImportPathExistsError)
|
|
286
|
+
throw error;
|
|
287
|
+
// Cleanup any wallet file we could have created
|
|
288
|
+
if (await this.fileSystem.exists(destinationPath)) {
|
|
289
|
+
await this.fileSystem.delete(destinationPath);
|
|
290
|
+
}
|
|
291
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @throws {WalletError} if the wallet is already closed or another error occurs
|
|
296
|
+
*/
|
|
297
|
+
async close() {
|
|
298
|
+
var _a;
|
|
299
|
+
this.logger.debug(`Closing wallet ${(_a = this.walletConfig) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
300
|
+
if (!this._store) {
|
|
301
|
+
throw new core_1.WalletError('Wallet is in invalid state, you are trying to close wallet that has no handle.');
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
await this.session.close();
|
|
305
|
+
await this.store.close();
|
|
306
|
+
this._session = undefined;
|
|
307
|
+
this._store = undefined;
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
const errorMessage = `Error closing wallet': ${error.message}`;
|
|
311
|
+
this.logger.error(errorMessage, {
|
|
312
|
+
error,
|
|
313
|
+
errorMessage: error.message,
|
|
314
|
+
});
|
|
315
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
async getAskarWalletConfig(walletConfig) {
|
|
319
|
+
var _a;
|
|
320
|
+
const { uri, path } = (0, utils_1.uriFromWalletConfig)(walletConfig, this.fileSystem.dataPath);
|
|
321
|
+
return {
|
|
322
|
+
uri,
|
|
323
|
+
path,
|
|
324
|
+
profile: walletConfig.id,
|
|
325
|
+
// FIXME: Default derivation method should be set somewhere in either agent config or some constants
|
|
326
|
+
keyMethod: (0, utils_1.keyDerivationMethodToStoreKeyMethod)((_a = walletConfig.keyDerivationMethod) !== null && _a !== void 0 ? _a : core_1.KeyDerivationMethod.Argon2IMod),
|
|
327
|
+
passKey: walletConfig.key,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
AskarWallet = __decorate([
|
|
332
|
+
(0, tsyringe_1.injectable)(),
|
|
333
|
+
__param(0, (0, tsyringe_1.inject)(core_1.InjectionSymbols.Logger)),
|
|
334
|
+
__param(1, (0, tsyringe_1.inject)(core_1.InjectionSymbols.FileSystem)),
|
|
335
|
+
__metadata("design:paramtypes", [Object, Object, core_1.SigningProviderRegistry])
|
|
336
|
+
], AskarWallet);
|
|
337
|
+
exports.AskarWallet = AskarWallet;
|
|
338
|
+
//# sourceMappingURL=AskarWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskarWallet.js","sourceRoot":"","sources":["../../src/wallet/AskarWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAauB;AACvB,wCAAwC;AACxC,wEAAuD;AAEvD,uCAA6C;AAE7C,oCAAiH;AAEjH,uDAAmD;AACnD,6DAAyD;AAEzD;;GAEG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,iCAAe;IAM9C,YACmC,MAAc,EACV,UAAsB,EAC3D,0BAAmD;QAEnD,KAAK,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAA;QACzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,YAAY,KAAK,SAAS,CAAA;IACxC,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAA;IAClC,CAAC;IAED,IAAW,KAAK;QACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,MAAM,IAAI,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,CAAC,CAAA;SACtD;IACH,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,YAA0B;;QAC3D,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAA,2BAAmB,EAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QAEjF,OAAO;YACL,GAAG;YACH,IAAI;YACJ,OAAO,EAAE,YAAY,CAAC,EAAE;YACxB,oGAAoG;YACpG,SAAS,EAAE,IAAA,2CAAmC,EAC5C,MAAA,YAAY,CAAC,mBAAmB,mCAAI,0BAAmB,CAAC,UAAU,CACnE;YACD,OAAO,EAAE,YAAY,CAAC,GAAG;SAC1B,CAAA;IACH,CAAC;CACF,CAAA;AA9XY,WAAW;IADvB,IAAA,qBAAU,GAAE;IAQR,WAAA,IAAA,iBAAM,EAAC,uBAAgB,CAAC,MAAM,CAAC,CAAA;IAC/B,WAAA,IAAA,iBAAM,EAAC,uBAAgB,CAAC,UAAU,CAAC,CAAA;qDACR,8BAAuB;GAT1C,WAAW,CA8XvB;AA9XY,kCAAW"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WalletStorageConfig } from '@credo-ts/core';
|
|
2
|
+
export interface AskarWalletPostgresConfig {
|
|
3
|
+
host: string;
|
|
4
|
+
connectTimeout?: number;
|
|
5
|
+
idleTimeout?: number;
|
|
6
|
+
maxConnections?: number;
|
|
7
|
+
minConnections?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface AskarWalletPostgresCredentials {
|
|
10
|
+
account: string;
|
|
11
|
+
password: string;
|
|
12
|
+
adminAccount?: string;
|
|
13
|
+
adminPassword?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AskarWalletPostgresStorageConfig extends WalletStorageConfig {
|
|
16
|
+
type: 'postgres';
|
|
17
|
+
config: AskarWalletPostgresConfig;
|
|
18
|
+
credentials: AskarWalletPostgresCredentials;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskarWalletPostgresStorageConfig.js","sourceRoot":"","sources":["../../src/wallet/AskarWalletPostgresStorageConfig.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class JweRecipient {
|
|
2
|
+
encryptedKey: string;
|
|
3
|
+
header?: Record<string, string>;
|
|
4
|
+
constructor(options: {
|
|
5
|
+
encryptedKey: Uint8Array;
|
|
6
|
+
header?: Record<string, string>;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export interface JweEnvelopeOptions {
|
|
10
|
+
protected: string;
|
|
11
|
+
unprotected?: string;
|
|
12
|
+
recipients?: JweRecipient[];
|
|
13
|
+
ciphertext: string;
|
|
14
|
+
iv: string;
|
|
15
|
+
tag: string;
|
|
16
|
+
aad?: string;
|
|
17
|
+
header?: string[];
|
|
18
|
+
encryptedKey?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class JweEnvelope {
|
|
21
|
+
protected: string;
|
|
22
|
+
unprotected?: string;
|
|
23
|
+
recipients?: JweRecipient[];
|
|
24
|
+
ciphertext: string;
|
|
25
|
+
iv: string;
|
|
26
|
+
tag: string;
|
|
27
|
+
aad?: string;
|
|
28
|
+
header?: string[];
|
|
29
|
+
encryptedKey?: string;
|
|
30
|
+
constructor(options: JweEnvelopeOptions);
|
|
31
|
+
toJson(): Record<string, any>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JweEnvelope = exports.JweRecipient = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const class_transformer_1 = require("class-transformer");
|
|
15
|
+
class JweRecipient {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
if (options) {
|
|
18
|
+
this.encryptedKey = core_1.TypedArrayEncoder.toBase64URL(options.encryptedKey);
|
|
19
|
+
this.header = options.header;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, class_transformer_1.Expose)({ name: 'encrypted_key' }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], JweRecipient.prototype, "encryptedKey", void 0);
|
|
27
|
+
exports.JweRecipient = JweRecipient;
|
|
28
|
+
class JweEnvelope {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
if (options) {
|
|
31
|
+
this.protected = options.protected;
|
|
32
|
+
this.unprotected = options.unprotected;
|
|
33
|
+
this.recipients = options.recipients;
|
|
34
|
+
this.ciphertext = options.ciphertext;
|
|
35
|
+
this.iv = options.iv;
|
|
36
|
+
this.tag = options.tag;
|
|
37
|
+
this.aad = options.aad;
|
|
38
|
+
this.header = options.header;
|
|
39
|
+
this.encryptedKey = options.encryptedKey;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
toJson() {
|
|
43
|
+
return core_1.JsonTransformer.toJSON(this);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, class_transformer_1.Type)(() => JweRecipient),
|
|
48
|
+
__metadata("design:type", Array)
|
|
49
|
+
], JweEnvelope.prototype, "recipients", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, class_transformer_1.Expose)({ name: 'encrypted_key' }),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], JweEnvelope.prototype, "encryptedKey", void 0);
|
|
54
|
+
exports.JweEnvelope = JweEnvelope;
|
|
55
|
+
//# sourceMappingURL=JweEnvelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JweEnvelope.js","sourceRoot":"","sources":["../../src/wallet/JweEnvelope.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmE;AACnE,yDAAgD;AAEhD,MAAa,YAAY;IAKvB,YAAmB,OAAsE;QACvF,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,YAAY,GAAG,wBAAiB,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;YAEvE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;SAC7B;IACH,CAAC;CACF;AAXC;IAAC,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;;kDACN;AAF9B,oCAYC;AAcD,MAAa,WAAW;IAetB,YAAmB,OAA2B;QAC5C,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;YAClC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;YACtC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;YACpC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;YACpC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAA;YACpB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;YACtB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;YACtB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;YAC5B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACzC;IACH,CAAC;IAEM,MAAM;QACX,OAAO,sBAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;CACF;AA5BC;IAAC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,YAAY,CAAC;;+CACS;AAOlC;IAAC,IAAA,0BAAM,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;;iDACN;AAb9B,kCAgCC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AskarProfileWallet = exports.AskarWallet = void 0;
|
|
18
|
+
var AskarWallet_1 = require("./AskarWallet");
|
|
19
|
+
Object.defineProperty(exports, "AskarWallet", { enumerable: true, get: function () { return AskarWallet_1.AskarWallet; } });
|
|
20
|
+
var AskarProfileWallet_1 = require("./AskarProfileWallet");
|
|
21
|
+
Object.defineProperty(exports, "AskarProfileWallet", { enumerable: true, get: function () { return AskarProfileWallet_1.AskarProfileWallet; } });
|
|
22
|
+
__exportStar(require("./AskarWalletPostgresStorageConfig"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wallet/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,2DAAyD;AAAhD,wHAAA,kBAAkB,OAAA;AAC3B,qEAAkD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@credo-ts/askar",
|
|
3
|
+
"main": "build/index",
|
|
4
|
+
"types": "build/index",
|
|
5
|
+
"version": "0.5.0-alpha.101+6f088673",
|
|
6
|
+
"files": [
|
|
7
|
+
"build"
|
|
8
|
+
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/openwallet-foundation/credo-ts/tree/main/packages/askar",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/openwallet-foundation/credo-ts",
|
|
17
|
+
"directory": "packages/askar"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "yarn run clean && yarn run compile",
|
|
21
|
+
"clean": "rimraf ./build",
|
|
22
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
23
|
+
"prepublishOnly": "yarn run build",
|
|
24
|
+
"test": "jest"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@credo-ts/core": "0.5.0-alpha.101+6f088673",
|
|
28
|
+
"bn.js": "^5.2.1",
|
|
29
|
+
"class-transformer": "0.5.1",
|
|
30
|
+
"class-validator": "0.14.0",
|
|
31
|
+
"rxjs": "^7.2.0",
|
|
32
|
+
"tsyringe": "^4.8.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@hyperledger/aries-askar-nodejs": "^0.2.0-dev.5",
|
|
36
|
+
"@hyperledger/aries-askar-shared": "^0.2.0-dev.5",
|
|
37
|
+
"@types/bn.js": "^5.1.0",
|
|
38
|
+
"@types/ref-array-di": "^1.2.6",
|
|
39
|
+
"@types/ref-struct-di": "^1.1.10",
|
|
40
|
+
"reflect-metadata": "^0.1.13",
|
|
41
|
+
"rimraf": "^4.4.0",
|
|
42
|
+
"typescript": "~4.9.5"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@hyperledger/aries-askar-shared": "^0.2.0-dev.5"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "6f088673214fc26c4c8f7c8c185354dd0a8c02c2"
|
|
48
|
+
}
|