@credo-ts/askar 0.4.1-alpha.157
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 +58 -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 +139 -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 +110 -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 +7 -0
- package/build/utils/askarKeyTypes.js +45 -0
- package/build/utils/askarKeyTypes.js.map +1 -0
- package/build/utils/askarWalletConfig.d.ts +14 -0
- package/build/utils/askarWalletConfig.js +75 -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 +89 -0
- package/build/wallet/AskarBaseWallet.js +385 -0
- package/build/wallet/AskarBaseWallet.js.map +1 -0
- package/build/wallet/AskarProfileWallet.d.ts +24 -0
- package/build/wallet/AskarProfileWallet.js +150 -0
- package/build/wallet/AskarProfileWallet.js.map +1 -0
- package/build/wallet/AskarWallet.d.ts +58 -0
- package/build/wallet/AskarWallet.js +342 -0
- package/build/wallet/AskarWallet.js.map +1 -0
- package/build/wallet/AskarWalletStorageConfig.d.ts +31 -0
- package/build/wallet/AskarWalletStorageConfig.js +12 -0
- package/build/wallet/AskarWalletStorageConfig.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/didcommV1.d.ts +8 -0
- package/build/wallet/didcommV1.js +156 -0
- package/build/wallet/didcommV1.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,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AskarBaseWallet = void 0;
|
|
7
|
+
const core_1 = require("@credo-ts/core");
|
|
8
|
+
const aries_askar_shared_1 = require("@hyperledger/aries-askar-shared");
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const didcommV1_1 = require("./didcommV1");
|
|
12
|
+
const isError = (error) => error instanceof Error;
|
|
13
|
+
class AskarBaseWallet {
|
|
14
|
+
constructor(logger, signingKeyProviderRegistry) {
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.signingKeyProviderRegistry = signingKeyProviderRegistry;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Run callback with the session provided, the session will
|
|
20
|
+
* be closed once the callback resolves or rejects if it is not closed yet.
|
|
21
|
+
*
|
|
22
|
+
* TODO: update to new `using` syntax so we don't have to use a callback
|
|
23
|
+
*/
|
|
24
|
+
async withSession(callback) {
|
|
25
|
+
let session = undefined;
|
|
26
|
+
try {
|
|
27
|
+
session = await this.store.session(this.profile).open();
|
|
28
|
+
const result = await callback(session);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (session === null || session === void 0 ? void 0 : session.handle) {
|
|
33
|
+
await session.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Run callback with a transaction. If the callback resolves the transaction
|
|
39
|
+
* will be committed if the transaction is not closed yet. If the callback rejects
|
|
40
|
+
* the transaction will be rolled back if the transaction is not closed yet.
|
|
41
|
+
*
|
|
42
|
+
* TODO: update to new `using` syntax so we don't have to use a callback
|
|
43
|
+
*/
|
|
44
|
+
async withTransaction(callback) {
|
|
45
|
+
let session = undefined;
|
|
46
|
+
try {
|
|
47
|
+
session = await this.store.transaction(this.profile).open();
|
|
48
|
+
const result = await callback(session);
|
|
49
|
+
if (session.handle) {
|
|
50
|
+
await session.commit();
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (session === null || session === void 0 ? void 0 : session.handle) {
|
|
56
|
+
await (session === null || session === void 0 ? void 0 : session.rollback());
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
get supportedKeyTypes() {
|
|
62
|
+
const signingKeyProviderSupportedKeyTypes = this.signingKeyProviderRegistry.supportedKeyTypes;
|
|
63
|
+
return Array.from(new Set([...utils_1.keyTypesSupportedByAskar, ...signingKeyProviderSupportedKeyTypes]));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a key with an optional seed and keyType.
|
|
67
|
+
* The keypair is also automatically stored in the wallet afterwards
|
|
68
|
+
*/
|
|
69
|
+
async createKey({ seed, privateKey, keyType }) {
|
|
70
|
+
try {
|
|
71
|
+
if (seed && privateKey) {
|
|
72
|
+
throw new core_1.WalletError('Only one of seed and privateKey can be set');
|
|
73
|
+
}
|
|
74
|
+
if (seed && !(0, core_1.isValidSeed)(seed, keyType)) {
|
|
75
|
+
throw new core_1.WalletError('Invalid seed provided');
|
|
76
|
+
}
|
|
77
|
+
if (privateKey && !(0, core_1.isValidPrivateKey)(privateKey, keyType)) {
|
|
78
|
+
throw new core_1.WalletError('Invalid private key provided');
|
|
79
|
+
}
|
|
80
|
+
if ((0, utils_1.isKeyTypeSupportedByAskarForPurpose)(keyType, utils_1.AskarKeyTypePurpose.KeyManagement)) {
|
|
81
|
+
const algorithm = (0, aries_askar_shared_1.keyAlgFromString)(keyType);
|
|
82
|
+
// Create key
|
|
83
|
+
let key;
|
|
84
|
+
try {
|
|
85
|
+
const _key = privateKey
|
|
86
|
+
? aries_askar_shared_1.Key.fromSecretBytes({ secretKey: privateKey, algorithm })
|
|
87
|
+
: seed
|
|
88
|
+
? aries_askar_shared_1.Key.fromSeed({ seed, algorithm })
|
|
89
|
+
: aries_askar_shared_1.Key.generate(algorithm);
|
|
90
|
+
// FIXME: we need to create a separate const '_key' so TS definitely knows _key is defined in the session callback.
|
|
91
|
+
// This will be fixed once we use the new 'using' syntax
|
|
92
|
+
key = _key;
|
|
93
|
+
const keyPublicBytes = key.publicBytes;
|
|
94
|
+
// Store key
|
|
95
|
+
await this.withSession((session) => session.insertKey({ key: _key, name: core_1.TypedArrayEncoder.toBase58(keyPublicBytes) }));
|
|
96
|
+
key.handle.free();
|
|
97
|
+
return core_1.Key.fromPublicKey(keyPublicBytes, keyType);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
key === null || key === void 0 ? void 0 : key.handle.free();
|
|
101
|
+
// Handle case where key already exists
|
|
102
|
+
if ((0, utils_1.isAskarError)(error, utils_1.AskarErrorCode.Duplicate)) {
|
|
103
|
+
throw new core_1.WalletKeyExistsError('Key already exists');
|
|
104
|
+
}
|
|
105
|
+
// Otherwise re-throw error
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Check if there is a signing key provider for the specified key type.
|
|
111
|
+
if (this.signingKeyProviderRegistry.hasProviderForKeyType(keyType)) {
|
|
112
|
+
const signingKeyProvider = this.signingKeyProviderRegistry.getProviderForKeyType(keyType);
|
|
113
|
+
const keyPair = await signingKeyProvider.createKeyPair({ seed, privateKey });
|
|
114
|
+
await this.storeKeyPair(keyPair);
|
|
115
|
+
return core_1.Key.fromPublicKeyBase58(keyPair.publicKeyBase58, keyType);
|
|
116
|
+
}
|
|
117
|
+
throw new core_1.WalletError(`Unsupported key type: '${keyType}'`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
// If already instance of `WalletError`, re-throw
|
|
122
|
+
if (error instanceof core_1.WalletError)
|
|
123
|
+
throw error;
|
|
124
|
+
if (!isError(error)) {
|
|
125
|
+
throw new core_1.CredoError('Attempted to throw error, but it was not of type Error', { cause: error });
|
|
126
|
+
}
|
|
127
|
+
throw new core_1.WalletError(`Error creating key with key type '${keyType}': ${error.message}`, { cause: error });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* sign a Buffer with an instance of a Key class
|
|
132
|
+
*
|
|
133
|
+
* @param data Buffer The data that needs to be signed
|
|
134
|
+
* @param key Key The key that is used to sign the data
|
|
135
|
+
*
|
|
136
|
+
* @returns A signature for the data
|
|
137
|
+
*/
|
|
138
|
+
async sign({ data, key }) {
|
|
139
|
+
var _a;
|
|
140
|
+
let askarKey;
|
|
141
|
+
let keyPair;
|
|
142
|
+
try {
|
|
143
|
+
if ((0, utils_1.isKeyTypeSupportedByAskarForPurpose)(key.keyType, utils_1.AskarKeyTypePurpose.KeyManagement)) {
|
|
144
|
+
askarKey = await this.withSession(async (session) => { var _a; return (_a = (await session.fetchKey({ name: key.publicKeyBase58 }))) === null || _a === void 0 ? void 0 : _a.key; });
|
|
145
|
+
}
|
|
146
|
+
// FIXME: remove the custom KeyPair record now that we deprecate Indy SDK.
|
|
147
|
+
// We can do this in a migration script
|
|
148
|
+
// Fallback to fetching key from the non-askar storage, this is to handle the case
|
|
149
|
+
// where a key wasn't supported at first by the wallet, but now is
|
|
150
|
+
if (!askarKey) {
|
|
151
|
+
// TODO: we should probably make retrieveKeyPair + insertKey + deleteKeyPair a transaction
|
|
152
|
+
keyPair = await this.retrieveKeyPair(key.publicKeyBase58);
|
|
153
|
+
// If we have the key stored in a custom record, but it is now supported by Askar,
|
|
154
|
+
// we 'import' the key into askar storage and remove the custom key record
|
|
155
|
+
if (keyPair && (0, utils_1.isKeyTypeSupportedByAskarForPurpose)(keyPair.keyType, utils_1.AskarKeyTypePurpose.KeyManagement)) {
|
|
156
|
+
const _askarKey = aries_askar_shared_1.Key.fromSecretBytes({
|
|
157
|
+
secretKey: core_1.TypedArrayEncoder.fromBase58(keyPair.privateKeyBase58),
|
|
158
|
+
algorithm: (0, aries_askar_shared_1.keyAlgFromString)(keyPair.keyType),
|
|
159
|
+
});
|
|
160
|
+
askarKey = _askarKey;
|
|
161
|
+
await this.withSession((session) => session.insertKey({
|
|
162
|
+
name: key.publicKeyBase58,
|
|
163
|
+
key: _askarKey,
|
|
164
|
+
}));
|
|
165
|
+
// Now we can remove it from the custom record as we have imported it into Askar
|
|
166
|
+
await this.deleteKeyPair(key.publicKeyBase58);
|
|
167
|
+
keyPair = undefined;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!askarKey && !keyPair) {
|
|
171
|
+
throw new core_1.WalletError('Key entry not found');
|
|
172
|
+
}
|
|
173
|
+
// Not all keys are supported for signing
|
|
174
|
+
if ((0, utils_1.isKeyTypeSupportedByAskarForPurpose)(key.keyType, utils_1.AskarKeyTypePurpose.Signing)) {
|
|
175
|
+
if (!core_1.TypedArrayEncoder.isTypedArray(data)) {
|
|
176
|
+
throw new core_1.WalletError(`Currently not supporting signing of multiple messages`);
|
|
177
|
+
}
|
|
178
|
+
askarKey =
|
|
179
|
+
askarKey !== null && askarKey !== void 0 ? askarKey : (keyPair
|
|
180
|
+
? aries_askar_shared_1.Key.fromSecretBytes({
|
|
181
|
+
secretKey: core_1.TypedArrayEncoder.fromBase58(keyPair.privateKeyBase58),
|
|
182
|
+
algorithm: (0, aries_askar_shared_1.keyAlgFromString)(keyPair.keyType),
|
|
183
|
+
})
|
|
184
|
+
: undefined);
|
|
185
|
+
if (!askarKey) {
|
|
186
|
+
throw new core_1.WalletError('Key entry not found');
|
|
187
|
+
}
|
|
188
|
+
const signed = askarKey.signMessage({ message: data });
|
|
189
|
+
return core_1.Buffer.from(signed);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// Check if there is a signing key provider for the specified key type.
|
|
193
|
+
if (this.signingKeyProviderRegistry.hasProviderForKeyType(key.keyType)) {
|
|
194
|
+
const signingKeyProvider = this.signingKeyProviderRegistry.getProviderForKeyType(key.keyType);
|
|
195
|
+
// It could be that askar supports storing the key, but can't sign with it
|
|
196
|
+
// (in case of bls)
|
|
197
|
+
const privateKeyBase58 = (_a = keyPair === null || keyPair === void 0 ? void 0 : keyPair.privateKeyBase58) !== null && _a !== void 0 ? _a : ((askarKey === null || askarKey === void 0 ? void 0 : askarKey.secretBytes) ? core_1.TypedArrayEncoder.toBase58(askarKey.secretBytes) : undefined);
|
|
198
|
+
if (!privateKeyBase58) {
|
|
199
|
+
throw new core_1.WalletError('Key entry not found');
|
|
200
|
+
}
|
|
201
|
+
const signed = await signingKeyProvider.sign({
|
|
202
|
+
data,
|
|
203
|
+
privateKeyBase58: privateKeyBase58,
|
|
204
|
+
publicKeyBase58: key.publicKeyBase58,
|
|
205
|
+
});
|
|
206
|
+
return signed;
|
|
207
|
+
}
|
|
208
|
+
throw new core_1.WalletError(`Unsupported keyType: ${key.keyType}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
if (!isError(error)) {
|
|
213
|
+
throw new core_1.CredoError('Attempted to throw error, but it was not of type Error', { cause: error });
|
|
214
|
+
}
|
|
215
|
+
throw new core_1.WalletError(`Error signing data with verkey ${key.publicKeyBase58}. ${error.message}`, { cause: error });
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
askarKey === null || askarKey === void 0 ? void 0 : askarKey.handle.free();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Verify the signature with the data and the used key
|
|
223
|
+
*
|
|
224
|
+
* @param data Buffer The data that has to be confirmed to be signed
|
|
225
|
+
* @param key Key The key that was used in the signing process
|
|
226
|
+
* @param signature Buffer The signature that was created by the signing process
|
|
227
|
+
*
|
|
228
|
+
* @returns A boolean whether the signature was created with the supplied data and key
|
|
229
|
+
*
|
|
230
|
+
* @throws {WalletError} When it could not do the verification
|
|
231
|
+
* @throws {WalletError} When an unsupported keytype is used
|
|
232
|
+
*/
|
|
233
|
+
async verify({ data, key, signature }) {
|
|
234
|
+
let askarKey;
|
|
235
|
+
try {
|
|
236
|
+
if ((0, utils_1.isKeyTypeSupportedByAskarForPurpose)(key.keyType, utils_1.AskarKeyTypePurpose.Signing)) {
|
|
237
|
+
if (!core_1.TypedArrayEncoder.isTypedArray(data)) {
|
|
238
|
+
throw new core_1.WalletError(`Currently not supporting verification of multiple messages`);
|
|
239
|
+
}
|
|
240
|
+
askarKey = aries_askar_shared_1.Key.fromPublicBytes({
|
|
241
|
+
algorithm: (0, aries_askar_shared_1.keyAlgFromString)(key.keyType),
|
|
242
|
+
publicKey: key.publicKey,
|
|
243
|
+
});
|
|
244
|
+
const verified = askarKey.verifySignature({ message: data, signature });
|
|
245
|
+
askarKey.handle.free();
|
|
246
|
+
return verified;
|
|
247
|
+
}
|
|
248
|
+
else if (this.signingKeyProviderRegistry.hasProviderForKeyType(key.keyType)) {
|
|
249
|
+
// Check if there is a signing key provider for the specified key type.
|
|
250
|
+
const signingKeyProvider = this.signingKeyProviderRegistry.getProviderForKeyType(key.keyType);
|
|
251
|
+
const signed = await signingKeyProvider.verify({
|
|
252
|
+
data,
|
|
253
|
+
signature,
|
|
254
|
+
publicKeyBase58: key.publicKeyBase58,
|
|
255
|
+
});
|
|
256
|
+
return signed;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
throw new core_1.WalletError(`Unsupported keyType: ${key.keyType}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
askarKey === null || askarKey === void 0 ? void 0 : askarKey.handle.free();
|
|
264
|
+
if (!isError(error)) {
|
|
265
|
+
throw new core_1.CredoError('Attempted to throw error, but it was not of type Error', { cause: error });
|
|
266
|
+
}
|
|
267
|
+
throw new core_1.WalletError(`Error verifying signature of data signed with verkey ${key.publicKeyBase58}`, {
|
|
268
|
+
cause: error,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Pack a message using DIDComm V1 algorithm
|
|
274
|
+
*
|
|
275
|
+
* @param payload message to send
|
|
276
|
+
* @param recipientKeys array containing recipient keys in base58
|
|
277
|
+
* @param senderVerkey sender key in base58
|
|
278
|
+
* @returns JWE Envelope to send
|
|
279
|
+
*/
|
|
280
|
+
async pack(payload, recipientKeys, senderVerkey // in base58
|
|
281
|
+
) {
|
|
282
|
+
const senderKey = senderVerkey
|
|
283
|
+
? await this.withSession((session) => session.fetchKey({ name: senderVerkey }))
|
|
284
|
+
: undefined;
|
|
285
|
+
try {
|
|
286
|
+
if (senderVerkey && !senderKey) {
|
|
287
|
+
throw new core_1.WalletError(`Sender key not found`);
|
|
288
|
+
}
|
|
289
|
+
const envelope = (0, didcommV1_1.didcommV1Pack)(payload, recipientKeys, senderKey === null || senderKey === void 0 ? void 0 : senderKey.key);
|
|
290
|
+
return envelope;
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
senderKey === null || senderKey === void 0 ? void 0 : senderKey.key.handle.free();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Unpacks a JWE Envelope coded using DIDComm V1 algorithm
|
|
298
|
+
*
|
|
299
|
+
* @param messagePackage JWE Envelope
|
|
300
|
+
* @returns UnpackedMessageContext with plain text message, sender key and recipient key
|
|
301
|
+
*/
|
|
302
|
+
async unpack(messagePackage) {
|
|
303
|
+
const protectedJson = core_1.JsonEncoder.fromBase64(messagePackage.protected);
|
|
304
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
305
|
+
const recipientKids = protectedJson.recipients.map((r) => r.header.kid);
|
|
306
|
+
// TODO: how long should sessions last? Just for the duration of the unpack? Or should each item in the recipientKids get a separate session?
|
|
307
|
+
const returnValue = await this.withSession(async (session) => {
|
|
308
|
+
for (const recipientKid of recipientKids) {
|
|
309
|
+
const recipientKeyEntry = await session.fetchKey({ name: recipientKid });
|
|
310
|
+
try {
|
|
311
|
+
if (recipientKeyEntry) {
|
|
312
|
+
return (0, didcommV1_1.didcommV1Unpack)(messagePackage, recipientKeyEntry.key);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
recipientKeyEntry === null || recipientKeyEntry === void 0 ? void 0 : recipientKeyEntry.key.handle.free();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
if (!returnValue) {
|
|
321
|
+
throw new core_1.WalletError('No corresponding recipient key found');
|
|
322
|
+
}
|
|
323
|
+
return returnValue;
|
|
324
|
+
}
|
|
325
|
+
async generateNonce() {
|
|
326
|
+
try {
|
|
327
|
+
// generate an 80-bit nonce suitable for AnonCreds proofs
|
|
328
|
+
const nonce = aries_askar_shared_1.CryptoBox.randomNonce().slice(0, 10);
|
|
329
|
+
return new bn_js_1.default(nonce).toString();
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
if (!isError(error)) {
|
|
333
|
+
throw new core_1.CredoError('Attempted to throw error, but it was not of type Error', { cause: error });
|
|
334
|
+
}
|
|
335
|
+
throw new core_1.WalletError('Error generating nonce', { cause: error });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async generateWalletKey() {
|
|
339
|
+
try {
|
|
340
|
+
return aries_askar_shared_1.Store.generateRawKey();
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
throw new core_1.WalletError('Error generating wallet key', { cause: error });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async retrieveKeyPair(publicKeyBase58) {
|
|
347
|
+
try {
|
|
348
|
+
const entryObject = await this.withSession((session) => session.fetch({ category: 'KeyPairRecord', name: `key-${publicKeyBase58}` }));
|
|
349
|
+
if (!entryObject)
|
|
350
|
+
return null;
|
|
351
|
+
return core_1.JsonEncoder.fromString(entryObject === null || entryObject === void 0 ? void 0 : entryObject.value);
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
throw new core_1.WalletError('Error retrieving KeyPair record', { cause: error });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async deleteKeyPair(publicKeyBase58) {
|
|
358
|
+
try {
|
|
359
|
+
await this.withSession((session) => session.remove({ category: 'KeyPairRecord', name: `key-${publicKeyBase58}` }));
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
throw new core_1.WalletError('Error removing KeyPair record', { cause: error });
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async storeKeyPair(keyPair) {
|
|
366
|
+
try {
|
|
367
|
+
await this.withSession((session) => session.insert({
|
|
368
|
+
category: 'KeyPairRecord',
|
|
369
|
+
name: `key-${keyPair.publicKeyBase58}`,
|
|
370
|
+
value: JSON.stringify(keyPair),
|
|
371
|
+
tags: {
|
|
372
|
+
keyType: keyPair.keyType,
|
|
373
|
+
},
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
if ((0, utils_1.isAskarError)(error, utils_1.AskarErrorCode.Duplicate)) {
|
|
378
|
+
throw new core_1.WalletKeyExistsError('Key already exists');
|
|
379
|
+
}
|
|
380
|
+
throw new core_1.WalletError('Error saving KeyPair record', { cause: error });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
exports.AskarBaseWallet = AskarBaseWallet;
|
|
385
|
+
//# sourceMappingURL=AskarBaseWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskarBaseWallet.js","sourceRoot":"","sources":["../../src/wallet/AskarBaseWallet.ts"],"names":[],"mappings":";;;;;;AAgBA,yCAUuB;AACvB,wEAAqG;AACrG,kDAA6B;AAE7B,oCAMiB;AAEjB,2CAA4D;AAE5D,MAAM,OAAO,GAAG,CAAC,KAAc,EAAkB,EAAE,CAAC,KAAK,YAAY,KAAK,CAAA;AAE1E,MAAsB,eAAe;IAInC,YAAmB,MAAc,EAAE,0BAAmD;QACpF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,0BAA0B,GAAG,0BAA0B,CAAA;IAC9D,CAAC;IAoBD;;;;;OAKG;IACI,KAAK,CAAC,WAAW,CAAS,QAAsC;QACrE,IAAI,OAAO,GAAwB,SAAS,CAAA;QAC5C,IAAI;YACF,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAA;YAEvD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAA;YAEtC,OAAO,MAAM,CAAA;SACd;gBAAS;YACR,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAE;gBACnB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAA;aACtB;SACF;IACH,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,eAAe,CAAS,QAA0C;QAC7E,IAAI,OAAO,GAAwB,SAAS,CAAA;QAC5C,IAAI;YACF,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAA;YAE3D,MAAM,M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M,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,eAAe,EAAE,EAAE,CAAC,CAAC,CAAA;SACnH;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,kBAAW,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;SACzE;IACH,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,OAAgB;QACzC,IAAI;YACF,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,EAAE,CACjC,OAAO,CAAC,MAAM,CAAC;gBACb,QAAQ,EAAE,eAAe;gBACzB,IAAI,EAAE,OAAO,OAAO,CAAC,eAAe,EAAE;gBACtC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBAC9B,IAAI,EAAE;oBACJ,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB;aACF,CAAC,CACH,CAAA;SACF;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,IAAA,oBAAY,EAAC,KAAK,EAAE,sBAAc,CAAC,SAAS,CAAC,EAAE;gBACjD,MAAM,IAAI,2BAAoB,CAAC,oBAAoB,CAAC,CAAA;aACrD;YACD,MAAM,IAAI,kBAAW,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;SACvE;IACH,CAAC;CACF;AAxbD,0CAwbC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WalletConfig } from '@credo-ts/core';
|
|
2
|
+
import { Logger, SigningProviderRegistry } from '@credo-ts/core';
|
|
3
|
+
import { Store } from '@hyperledger/aries-askar-shared';
|
|
4
|
+
import { AskarBaseWallet } from './AskarBaseWallet';
|
|
5
|
+
export declare class AskarProfileWallet extends AskarBaseWallet {
|
|
6
|
+
private walletConfig?;
|
|
7
|
+
readonly store: Store;
|
|
8
|
+
isInitialized: boolean;
|
|
9
|
+
constructor(store: Store, logger: Logger, signingKeyProviderRegistry: SigningProviderRegistry);
|
|
10
|
+
get isProvisioned(): boolean;
|
|
11
|
+
get profile(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Dispose method is called when an agent context is disposed.
|
|
14
|
+
*/
|
|
15
|
+
dispose(): Promise<void>;
|
|
16
|
+
create(walletConfig: WalletConfig): Promise<void>;
|
|
17
|
+
open(walletConfig: WalletConfig): Promise<void>;
|
|
18
|
+
createAndOpen(walletConfig: WalletConfig): Promise<void>;
|
|
19
|
+
delete(): Promise<void>;
|
|
20
|
+
export(): Promise<void>;
|
|
21
|
+
import(): Promise<void>;
|
|
22
|
+
rotateKey(): Promise<void>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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.AskarProfileWallet = void 0;
|
|
16
|
+
const core_1 = require("@credo-ts/core");
|
|
17
|
+
const aries_askar_shared_1 = require("@hyperledger/aries-askar-shared");
|
|
18
|
+
const tsyringe_1 = require("tsyringe");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
20
|
+
const AskarBaseWallet_1 = require("./AskarBaseWallet");
|
|
21
|
+
let AskarProfileWallet = class AskarProfileWallet extends AskarBaseWallet_1.AskarBaseWallet {
|
|
22
|
+
constructor(store, logger, signingKeyProviderRegistry) {
|
|
23
|
+
super(logger, signingKeyProviderRegistry);
|
|
24
|
+
this.isInitialized = false;
|
|
25
|
+
this.store = store;
|
|
26
|
+
}
|
|
27
|
+
get isProvisioned() {
|
|
28
|
+
return this.walletConfig !== undefined;
|
|
29
|
+
}
|
|
30
|
+
get profile() {
|
|
31
|
+
if (!this.walletConfig) {
|
|
32
|
+
throw new core_1.WalletError('No profile configured.');
|
|
33
|
+
}
|
|
34
|
+
return this.walletConfig.id;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Dispose method is called when an agent context is disposed.
|
|
38
|
+
*/
|
|
39
|
+
async dispose() {
|
|
40
|
+
if (this.isInitialized) {
|
|
41
|
+
await this.close();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async create(walletConfig) {
|
|
45
|
+
this.logger.debug(`Creating wallet for profile '${walletConfig.id}'`);
|
|
46
|
+
try {
|
|
47
|
+
await this.store.createProfile(walletConfig.id);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if ((0, utils_1.isAskarError)(error, utils_1.AskarErrorCode.Duplicate)) {
|
|
51
|
+
const errorMessage = `Wallet for profile '${walletConfig.id}' already exists`;
|
|
52
|
+
this.logger.debug(errorMessage);
|
|
53
|
+
throw new core_1.WalletDuplicateError(errorMessage, {
|
|
54
|
+
walletType: 'AskarProfileWallet',
|
|
55
|
+
cause: error,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const errorMessage = `Error creating wallet for profile '${walletConfig.id}'`;
|
|
59
|
+
this.logger.error(errorMessage, {
|
|
60
|
+
error,
|
|
61
|
+
errorMessage: error.message,
|
|
62
|
+
});
|
|
63
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
this.logger.debug(`Successfully created wallet for profile '${walletConfig.id}'`);
|
|
66
|
+
}
|
|
67
|
+
async open(walletConfig) {
|
|
68
|
+
this.logger.debug(`Opening wallet for profile '${walletConfig.id}'`);
|
|
69
|
+
try {
|
|
70
|
+
this.walletConfig = walletConfig;
|
|
71
|
+
// TODO: what is faster? listProfiles or open and close session?
|
|
72
|
+
// I think open/close is more scalable (what if profiles is 10.000.000?)
|
|
73
|
+
// We just want to check if the profile exists. Because the wallet initialization logic
|
|
74
|
+
// first tries to open, and if it doesn't exist it will create it. So we must check here
|
|
75
|
+
// if the profile exists
|
|
76
|
+
await this.withSession(() => {
|
|
77
|
+
/* no-op */
|
|
78
|
+
});
|
|
79
|
+
this.isInitialized = true;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// Profile does not exist
|
|
83
|
+
if ((0, utils_1.isAskarError)(error, utils_1.AskarErrorCode.NotFound)) {
|
|
84
|
+
const errorMessage = `Wallet for profile '${walletConfig.id}' not found`;
|
|
85
|
+
this.logger.debug(errorMessage);
|
|
86
|
+
throw new core_1.WalletNotFoundError(errorMessage, {
|
|
87
|
+
walletType: 'AskarProfileWallet',
|
|
88
|
+
cause: error,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const errorMessage = `Error opening wallet for profile '${walletConfig.id}'`;
|
|
92
|
+
this.logger.error(errorMessage, {
|
|
93
|
+
error,
|
|
94
|
+
errorMessage: error.message,
|
|
95
|
+
});
|
|
96
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
97
|
+
}
|
|
98
|
+
this.logger.debug(`Successfully opened wallet for profile '${walletConfig.id}'`);
|
|
99
|
+
}
|
|
100
|
+
async createAndOpen(walletConfig) {
|
|
101
|
+
await this.create(walletConfig);
|
|
102
|
+
await this.open(walletConfig);
|
|
103
|
+
}
|
|
104
|
+
async delete() {
|
|
105
|
+
if (!this.walletConfig) {
|
|
106
|
+
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');
|
|
107
|
+
}
|
|
108
|
+
this.logger.info(`Deleting profile '${this.profile}'`);
|
|
109
|
+
if (this.isInitialized) {
|
|
110
|
+
await this.close();
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
await this.store.removeProfile(this.profile);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const errorMessage = `Error deleting wallet for profile '${this.profile}': ${error.message}`;
|
|
117
|
+
this.logger.error(errorMessage, {
|
|
118
|
+
error,
|
|
119
|
+
errorMessage: error.message,
|
|
120
|
+
});
|
|
121
|
+
throw new core_1.WalletError(errorMessage, { cause: error });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async export() {
|
|
125
|
+
// This PR should help with this: https://github.com/hyperledger/aries-askar/pull/159
|
|
126
|
+
throw new core_1.WalletExportUnsupportedError('Exporting a profile is not supported.');
|
|
127
|
+
}
|
|
128
|
+
async import() {
|
|
129
|
+
// This PR should help with this: https://github.com/hyperledger/aries-askar/pull/159
|
|
130
|
+
throw new core_1.WalletError('Importing a profile is not supported.');
|
|
131
|
+
}
|
|
132
|
+
async rotateKey() {
|
|
133
|
+
throw new core_1.WalletError('Rotating a key is not supported for a profile. You can rotate the key on the main askar wallet.');
|
|
134
|
+
}
|
|
135
|
+
async close() {
|
|
136
|
+
var _a;
|
|
137
|
+
this.logger.debug(`Closing wallet for profile ${(_a = this.walletConfig) === null || _a === void 0 ? void 0 : _a.id}`);
|
|
138
|
+
if (!this.isInitialized) {
|
|
139
|
+
throw new core_1.WalletError('Wallet is in invalid state, you are trying to close wallet that is not initialized.');
|
|
140
|
+
}
|
|
141
|
+
this.isInitialized = false;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
AskarProfileWallet = __decorate([
|
|
145
|
+
(0, tsyringe_1.injectable)(),
|
|
146
|
+
__param(1, (0, tsyringe_1.inject)(core_1.InjectionSymbols.Logger)),
|
|
147
|
+
__metadata("design:paramtypes", [aries_askar_shared_1.Store, Object, core_1.SigningProviderRegistry])
|
|
148
|
+
], AskarProfileWallet);
|
|
149
|
+
exports.AskarProfileWallet = AskarProfileWallet;
|
|
150
|
+
//# sourceMappingURL=AskarProfileWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskarProfileWallet.js","sourceRoot":"","sources":["../../src/wallet/AskarProfileWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAQuB;AACvB,wEAAuD;AACvD,uCAA6C;AAE7C,oCAAuD;AAEvD,uDAAmD;AAG5C,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,iCAAe;IAKrD,YACE,KAAY,EACqB,MAAc,EAC/C,0BAAmD;QAEnD,KAAK,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAA;QAPpC,kBAAa,GAAG,KAAK,CAAA;QAS1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,YAAY,KAAK,SAAS,CAAA;IACxC,CAAC;IAED,IAAW,OAAO;QAChB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,MAAM,IAAI,kBAAW,CAAC,wBAAwB,CAAC,CAAA;SAChD;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,CAAA;IAC7B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;SACnB;IACH,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,YAA0B;QAC5C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,YAAY,CAAC,EAAE,GAAG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core';
|
|
2
|
+
import { Logger, SigningProviderRegistry, FileSystem } from '@credo-ts/core';
|
|
3
|
+
import { Store } from '@hyperledger/aries-askar-shared';
|
|
4
|
+
import { AskarBaseWallet } from './AskarBaseWallet';
|
|
5
|
+
/**
|
|
6
|
+
* @todo: rename after 0.5.0, as we now have multiple types of AskarWallet
|
|
7
|
+
*/
|
|
8
|
+
export declare class AskarWallet extends AskarBaseWallet {
|
|
9
|
+
private fileSystem;
|
|
10
|
+
private walletConfig?;
|
|
11
|
+
private _store?;
|
|
12
|
+
constructor(logger: Logger, fileSystem: FileSystem, signingKeyProviderRegistry: SigningProviderRegistry);
|
|
13
|
+
get isProvisioned(): boolean;
|
|
14
|
+
get isInitialized(): boolean;
|
|
15
|
+
get store(): Store;
|
|
16
|
+
get profile(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Dispose method is called when an agent context is disposed.
|
|
19
|
+
*/
|
|
20
|
+
dispose(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* @throws {WalletDuplicateError} if the wallet already exists
|
|
23
|
+
* @throws {WalletError} if another error occurs
|
|
24
|
+
*/
|
|
25
|
+
create(walletConfig: WalletConfig): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* @throws {WalletDuplicateError} if the wallet already exists
|
|
28
|
+
* @throws {WalletError} if another error occurs
|
|
29
|
+
*/
|
|
30
|
+
createAndOpen(walletConfig: WalletConfig): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
33
|
+
* @throws {WalletError} if another error occurs
|
|
34
|
+
*/
|
|
35
|
+
open(walletConfig: WalletConfig): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
38
|
+
* @throws {WalletError} if another error occurs
|
|
39
|
+
*/
|
|
40
|
+
rotateKey(walletConfig: WalletConfigRekey): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
43
|
+
* @throws {WalletError} if another error occurs
|
|
44
|
+
*/
|
|
45
|
+
private _open;
|
|
46
|
+
/**
|
|
47
|
+
* @throws {WalletNotFoundError} if the wallet does not exist
|
|
48
|
+
* @throws {WalletError} if another error occurs
|
|
49
|
+
*/
|
|
50
|
+
delete(): Promise<void>;
|
|
51
|
+
export(exportConfig: WalletExportImportConfig): Promise<void>;
|
|
52
|
+
import(walletConfig: WalletConfig, importConfig: WalletExportImportConfig): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* @throws {WalletError} if the wallet is already closed or another error occurs
|
|
55
|
+
*/
|
|
56
|
+
close(): Promise<void>;
|
|
57
|
+
private getAskarWalletConfig;
|
|
58
|
+
}
|