Add comprehensive installation and setup documentation

- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
This commit is contained in:
Dorian
2026-01-27 17:18:21 +00:00
parent a81f655133
commit 0d073fa89e
22658 changed files with 4494151 additions and 6 deletions
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+1
View File
@@ -0,0 +1 @@
# Web5 User Agent
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+18
View File
@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./user-agent.js"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
+1
View File
@@ -0,0 +1 @@
{"type": "commonjs"}
+235
View File
@@ -0,0 +1,235 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Web5UserAgent = void 0;
var common_1 = require("@web5/common");
var dids_1 = require("@web5/dids");
var agent_1 = require("@web5/agent");
var Web5UserAgent = /** @class */ (function () {
function Web5UserAgent(params) {
this._agentDid = params.agentDid;
this.crypto = params.cryptoApi;
this.did = params.didApi;
this.dwn = params.dwnApi;
this.identity = params.identityApi;
this.keyManager = params.keyManager;
this.rpc = params.rpcClient;
this.sync = params.syncApi;
this.vault = params.agentVault;
// Set this agent to be the default agent.
this.did.agent = this;
this.dwn.agent = this;
this.identity.agent = this;
this.keyManager.agent = this;
this.sync.agent = this;
}
Object.defineProperty(Web5UserAgent.prototype, "agentDid", {
get: function () {
if (this._agentDid === undefined) {
throw new Error('Web5UserAgent: The "agentDid" property is not set. Ensure the agent is properly ' +
'initialized and a DID is assigned.');
}
return this._agentDid;
},
set: function (did) {
this._agentDid = did;
},
enumerable: false,
configurable: true
});
/**
* If any of the required agent components are not provided, instantiate default implementations.
*/
Web5UserAgent.create = function (_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.dataPath, dataPath = _c === void 0 ? 'DATA/AGENT' : _c, agentDid = _b.agentDid, agentVault = _b.agentVault, cryptoApi = _b.cryptoApi, didApi = _b.didApi, dwnApi = _b.dwnApi, identityApi = _b.identityApi, keyManager = _b.keyManager, rpcClient = _b.rpcClient, syncApi = _b.syncApi;
return __awaiter(this, void 0, void 0, function () {
var _d, _e;
var _f;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
agentVault !== null && agentVault !== void 0 ? agentVault : (agentVault = new agent_1.HdIdentityVault({
keyDerivationWorkFactor: 210000,
store: new common_1.LevelStore({ location: "".concat(dataPath, "/VAULT_STORE") })
}));
cryptoApi !== null && cryptoApi !== void 0 ? cryptoApi : (cryptoApi = new agent_1.AgentCryptoApi());
didApi !== null && didApi !== void 0 ? didApi : (didApi = new agent_1.AgentDidApi({
didMethods: [dids_1.DidDht, dids_1.DidJwk],
resolverCache: new dids_1.DidResolverCacheLevel({ location: "".concat(dataPath, "/DID_RESOLVERCACHE") }),
store: new agent_1.DwnDidStore()
}));
if (!(dwnApi !== null && dwnApi !== void 0)) return [3 /*break*/, 1];
_d = dwnApi;
return [3 /*break*/, 3];
case 1:
_e = agent_1.AgentDwnApi.bind;
_f = {};
return [4 /*yield*/, agent_1.AgentDwnApi.createDwn({ dataPath: dataPath, didResolver: didApi })];
case 2:
_d = (dwnApi = new (_e.apply(agent_1.AgentDwnApi, [void 0, (_f.dwn = _g.sent(),
_f)]))());
_g.label = 3;
case 3:
_d;
identityApi !== null && identityApi !== void 0 ? identityApi : (identityApi = new agent_1.AgentIdentityApi({ store: new agent_1.DwnIdentityStore() }));
keyManager !== null && keyManager !== void 0 ? keyManager : (keyManager = new agent_1.LocalKeyManager({ keyStore: new agent_1.DwnKeyStore() }));
rpcClient !== null && rpcClient !== void 0 ? rpcClient : (rpcClient = new agent_1.Web5RpcClient());
syncApi !== null && syncApi !== void 0 ? syncApi : (syncApi = new agent_1.AgentSyncApi({ syncEngine: new agent_1.SyncEngineLevel({ dataPath: dataPath }) }));
// Instantiate the Agent using the provided or default components.
return [2 /*return*/, new Web5UserAgent({
agentDid: agentDid,
agentVault: agentVault,
cryptoApi: cryptoApi,
didApi: didApi,
dwnApi: dwnApi,
keyManager: keyManager,
identityApi: identityApi,
rpcClient: rpcClient,
syncApi: syncApi
})];
}
});
});
};
Web5UserAgent.prototype.firstLaunch = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.vault.isInitialized()];
case 1:
// Check whether data vault is already initialize
return [2 /*return*/, (_a.sent()) === false];
}
});
});
};
/**
* Initializes the User Agent with a password, and optionally a recovery phrase.
*
* This method is typically called once, the first time the Agent is launched, and is responsible
* for setting up the agent's operational environment, cryptographic key material, and readiness
* for processing Web5 requests.
*
* The password is used to secure the Agent vault, and the recovery phrase is used to derive the
* cryptographic keys for the vault. If a recovery phrase is not provided, a new recovery phrase
* will be generated and returned. The password should be chosen and entered by the end-user.
*/
Web5UserAgent.prototype.initialize = function (_a) {
var password = _a.password, recoveryPhrase = _a.recoveryPhrase;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this.vault.initialize({ password: password, recoveryPhrase: recoveryPhrase })];
case 1:
// Initialize the Agent vault.
recoveryPhrase = _b.sent();
return [2 /*return*/, recoveryPhrase];
}
});
});
};
Web5UserAgent.prototype.processDidRequest = function (request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.did.processRequest(request)];
});
});
};
Web5UserAgent.prototype.processDwnRequest = function (request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.dwn.processRequest(request)];
});
});
};
Web5UserAgent.prototype.processVcRequest = function (_request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error('Not implemented');
});
});
};
Web5UserAgent.prototype.sendDidRequest = function (_request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error('Not implemented');
});
});
};
Web5UserAgent.prototype.sendDwnRequest = function (request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.dwn.sendRequest(request)];
});
});
};
Web5UserAgent.prototype.sendVcRequest = function (_request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
throw new Error('Not implemented');
});
});
};
Web5UserAgent.prototype.start = function (_a) {
var password = _a.password;
return __awaiter(this, void 0, void 0, function () {
var _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!this.vault.isLocked()) return [3 /*break*/, 2];
return [4 /*yield*/, this.vault.unlock({ password: password })];
case 1:
_c.sent();
_c.label = 2;
case 2:
// Set the Agent's DID.
_b = this;
return [4 /*yield*/, this.vault.getDid()];
case 3:
// Set the Agent's DID.
_b.agentDid = _c.sent();
return [2 /*return*/];
}
});
});
};
return Web5UserAgent;
}());
exports.Web5UserAgent = Web5UserAgent;
//# sourceMappingURL=user-agent.js.map
@@ -0,0 +1 @@
{"version":3,"file":"user-agent.js","sourceRoot":"","sources":["../../src/user-agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,uCAA0C;AAC1C,mCAA8E;AAC9E,qCAcqB;AAsDrB;IAYE,uBAAY,MAAgC;QAC1C,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;QAE/B,0CAA0C;QAC1C,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG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Aa"}
+2
View File
@@ -0,0 +1,2 @@
export * from './user-agent.js';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
+142
View File
@@ -0,0 +1,142 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { LevelStore } from '@web5/common';
import { DidDht, DidJwk, DidResolverCacheLevel } from '@web5/dids';
import { AgentDidApi, AgentDwnApi, DwnDidStore, DwnKeyStore, AgentSyncApi, Web5RpcClient, AgentCryptoApi, HdIdentityVault, LocalKeyManager, SyncEngineLevel, AgentIdentityApi, DwnIdentityStore, } from '@web5/agent';
export class Web5UserAgent {
constructor(params) {
this._agentDid = params.agentDid;
this.crypto = params.cryptoApi;
this.did = params.didApi;
this.dwn = params.dwnApi;
this.identity = params.identityApi;
this.keyManager = params.keyManager;
this.rpc = params.rpcClient;
this.sync = params.syncApi;
this.vault = params.agentVault;
// Set this agent to be the default agent.
this.did.agent = this;
this.dwn.agent = this;
this.identity.agent = this;
this.keyManager.agent = this;
this.sync.agent = this;
}
get agentDid() {
if (this._agentDid === undefined) {
throw new Error('Web5UserAgent: The "agentDid" property is not set. Ensure the agent is properly ' +
'initialized and a DID is assigned.');
}
return this._agentDid;
}
set agentDid(did) {
this._agentDid = did;
}
/**
* If any of the required agent components are not provided, instantiate default implementations.
*/
static create({ dataPath = 'DATA/AGENT', agentDid, agentVault, cryptoApi, didApi, dwnApi, identityApi, keyManager, rpcClient, syncApi } = {}) {
return __awaiter(this, void 0, void 0, function* () {
agentVault !== null && agentVault !== void 0 ? agentVault : (agentVault = new HdIdentityVault({
keyDerivationWorkFactor: 210000,
store: new LevelStore({ location: `${dataPath}/VAULT_STORE` })
}));
cryptoApi !== null && cryptoApi !== void 0 ? cryptoApi : (cryptoApi = new AgentCryptoApi());
didApi !== null && didApi !== void 0 ? didApi : (didApi = new AgentDidApi({
didMethods: [DidDht, DidJwk],
resolverCache: new DidResolverCacheLevel({ location: `${dataPath}/DID_RESOLVERCACHE` }),
store: new DwnDidStore()
}));
dwnApi !== null && dwnApi !== void 0 ? dwnApi : (dwnApi = new AgentDwnApi({
dwn: yield AgentDwnApi.createDwn({ dataPath, didResolver: didApi })
}));
identityApi !== null && identityApi !== void 0 ? identityApi : (identityApi = new AgentIdentityApi({ store: new DwnIdentityStore() }));
keyManager !== null && keyManager !== void 0 ? keyManager : (keyManager = new LocalKeyManager({ keyStore: new DwnKeyStore() }));
rpcClient !== null && rpcClient !== void 0 ? rpcClient : (rpcClient = new Web5RpcClient());
syncApi !== null && syncApi !== void 0 ? syncApi : (syncApi = new AgentSyncApi({ syncEngine: new SyncEngineLevel({ dataPath }) }));
// Instantiate the Agent using the provided or default components.
return new Web5UserAgent({
agentDid,
agentVault,
cryptoApi,
didApi,
dwnApi,
keyManager,
identityApi,
rpcClient,
syncApi
});
});
}
firstLaunch() {
return __awaiter(this, void 0, void 0, function* () {
// Check whether data vault is already initialize
return (yield this.vault.isInitialized()) === false;
});
}
/**
* Initializes the User Agent with a password, and optionally a recovery phrase.
*
* This method is typically called once, the first time the Agent is launched, and is responsible
* for setting up the agent's operational environment, cryptographic key material, and readiness
* for processing Web5 requests.
*
* The password is used to secure the Agent vault, and the recovery phrase is used to derive the
* cryptographic keys for the vault. If a recovery phrase is not provided, a new recovery phrase
* will be generated and returned. The password should be chosen and entered by the end-user.
*/
initialize({ password, recoveryPhrase }) {
return __awaiter(this, void 0, void 0, function* () {
// Initialize the Agent vault.
recoveryPhrase = yield this.vault.initialize({ password, recoveryPhrase });
return recoveryPhrase;
});
}
processDidRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.did.processRequest(request);
});
}
processDwnRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.dwn.processRequest(request);
});
}
processVcRequest(_request) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented');
});
}
sendDidRequest(_request) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented');
});
}
sendDwnRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.dwn.sendRequest(request);
});
}
sendVcRequest(_request) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented');
});
}
start({ password }) {
return __awaiter(this, void 0, void 0, function* () {
// If the Agent vault is locked, unlock it.
if (this.vault.isLocked()) {
yield this.vault.unlock({ password });
}
// Set the Agent's DID.
this.agentDid = yield this.vault.getDid();
});
}
}
//# sourceMappingURL=user-agent.js.map
@@ -0,0 +1 @@
{"version":3,"file":"user-agent.js","sourceRoot":"","sources":["../../src/user-agent.ts"],"names":[],"mappings":";;;;;;;;;AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAa,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EAEd,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAsDrB,MAAM,OAAO,aAAa;IAYxB,YAAY,MAAgC;QAC1C,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,MAAM,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,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAC5C,CAAC;KAAA;CACF"}
+2
View File
@@ -0,0 +1,2 @@
export * from './user-agent.js';
//# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,90 @@
import type { Web5Rpc, DidRequest, VcResponse, DidResponse, DwnResponse, DidInterface, DwnInterface, SendVcRequest, SendDwnRequest, ProcessVcRequest, ProcessDwnRequest, Web5PlatformAgent } from '@web5/agent';
import { BearerDid } from '@web5/dids';
import { AgentDidApi, AgentDwnApi, AgentSyncApi, AgentCryptoApi, AgentKeyManager, HdIdentityVault, LocalKeyManager, AgentIdentityApi } from '@web5/agent';
/**
* Initialization parameters for {@link Web5UserAgent}, including an optional recovery phrase that
* can be used to derive keys to encrypt the vault and generate a DID.
*/
export type AgentInitializeParams = {
/**
* The password used to secure the Agent vault.
*
* The password selected should be strong and securely managed to prevent unauthorized access.
*/
password: string;
/**
* An optional recovery phrase used to deterministically generate the cryptographic keys for the
* Agent vault.
*
* Supplying this phrase enables the vault's contents to be restored or replicated across devices.
* If omitted, a new phrase is generated, which should be securely recorded for future recovery needs.
*/
recoveryPhrase?: string;
};
export type AgentStartParams = {
/**
* The password used to unlock the previously initialized Agent vault.
*/
password: string;
};
export type AgentParams<TKeyManager extends AgentKeyManager = LocalKeyManager> = {
/** Optional. The Decentralized Identifier (DID) representing this Web5 User Agent. */
agentDid?: BearerDid;
/** Encrypted vault used for managing the Agent's DID and associated keys. */
agentVault: HdIdentityVault;
/** Provides cryptographic capabilties like signing, encryption, hashing and key derivation. */
cryptoApi: AgentCryptoApi;
/** Specifies the local path to be used by the Agent's persistent data stores. */
dataPath?: string;
/** Facilitates DID operations including create, update, and resolve. */
didApi: AgentDidApi<TKeyManager>;
/** Facilitates DWN operations including processing and sending requests. */
dwnApi: AgentDwnApi;
/** Facilitates decentralized Identity operations including create, import, and export. */
identityApi: AgentIdentityApi<TKeyManager>;
/** Responsible for securely managing the cryptographic keys of the agent. */
keyManager: TKeyManager;
/** Remote procedure call (RPC) client used to communicate with other Web5 services. */
rpcClient: Web5Rpc;
/** Facilitates data synchronization of DWN records between nodes. */
syncApi: AgentSyncApi;
};
export declare class Web5UserAgent<TKeyManager extends AgentKeyManager = LocalKeyManager> implements Web5PlatformAgent<TKeyManager> {
crypto: AgentCryptoApi;
did: AgentDidApi<TKeyManager>;
dwn: AgentDwnApi;
identity: AgentIdentityApi<TKeyManager>;
keyManager: TKeyManager;
rpc: Web5Rpc;
sync: AgentSyncApi;
vault: HdIdentityVault;
private _agentDid?;
constructor(params: AgentParams<TKeyManager>);
get agentDid(): BearerDid;
set agentDid(did: BearerDid);
/**
* If any of the required agent components are not provided, instantiate default implementations.
*/
static create({ dataPath, agentDid, agentVault, cryptoApi, didApi, dwnApi, identityApi, keyManager, rpcClient, syncApi }?: Partial<AgentParams>): Promise<Web5UserAgent>;
firstLaunch(): Promise<boolean>;
/**
* Initializes the User Agent with a password, and optionally a recovery phrase.
*
* This method is typically called once, the first time the Agent is launched, and is responsible
* for setting up the agent's operational environment, cryptographic key material, and readiness
* for processing Web5 requests.
*
* The password is used to secure the Agent vault, and the recovery phrase is used to derive the
* cryptographic keys for the vault. If a recovery phrase is not provided, a new recovery phrase
* will be generated and returned. The password should be chosen and entered by the end-user.
*/
initialize({ password, recoveryPhrase }: AgentInitializeParams): Promise<string>;
processDidRequest<T extends DidInterface>(request: DidRequest<T>): Promise<DidResponse<T>>;
processDwnRequest<T extends DwnInterface>(request: ProcessDwnRequest<T>): Promise<DwnResponse<T>>;
processVcRequest(_request: ProcessVcRequest): Promise<VcResponse>;
sendDidRequest<T extends DidInterface>(_request: DidRequest<T>): Promise<DidResponse<T>>;
sendDwnRequest<T extends DwnInterface>(request: SendDwnRequest<T>): Promise<DwnResponse<T>>;
sendVcRequest(_request: SendVcRequest): Promise<VcResponse>;
start({ password }: AgentInitializeParams): Promise<void>;
}
//# sourceMappingURL=user-agent.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"user-agent.d.ts","sourceRoot":"","sources":["../../src/user-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,SAAS,EAAyC,MAAM,YAAY,CAAC;AAC9E,OAAO,EACL,WAAW,EACX,WAAW,EAGX,YAAY,EAEZ,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EAEf,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;QAII;IACH,QAAQ,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAA;AAEF,MAAM,MAAM,WAAW,CAAC,WAAW,SAAS,eAAe,GAAG,eAAe,IAAI;IAC/E,sFAAsF;IACtF,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,6EAA6E;IAC7E,UAAU,EAAE,eAAe,CAAC;IAC5B,+FAA+F;IAC/F,SAAS,EAAE,cAAc,CAAC;IAC1B,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IACjC,4EAA4E;IAC5E,MAAM,EAAE,WAAW,CAAC;IACpB,0FAA0F;IAC1F,WAAW,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC3C,6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Y,EACnD,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIb,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjE,cAAc,CAAC,CAAC,SAAS,YAAY,EAChD,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIb,cAAc,CAAC,CAAC,SAAS,YAAY,EAChD,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIb,aAAa,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC;IAI3D,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CASvE"}
+102
View File
@@ -0,0 +1,102 @@
{
"name": "@web5/user-agent",
"version": "0.3.8",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/user-agent#readme",
"bugs": "https://github.com/TBD54566975/web5-js/issues",
"repository": {
"type": "git",
"url": "git+https://github.com/TBD54566975/web5-js.git",
"directory": "packages/user-agent"
},
"license": "Apache-2.0",
"contributors": [
{
"name": "Daniel Buchner",
"url": "https://github.com/csuwildcat"
},
{
"name": "Frank Hinek",
"url": "https://github.com/frankhinek"
},
{
"name": "Moe Jangda",
"url": "https://github.com/mistermoe"
}
],
"files": [
"dist",
"src"
],
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"react-native": "./dist/esm/index.js",
"keywords": [
"decentralized",
"decentralized-applications",
"decentralized-identity",
"decentralized-web",
"vcs",
"verifiable credentials",
"web5"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"@web5/agent": "0.3.8",
"@web5/common": "1.0.0",
"@web5/crypto": "1.0.0",
"@web5/dids": "1.1.0"
},
"devDependencies": {
"@playwright/test": "1.40.1",
"@types/chai": "4.3.6",
"@types/chai-as-promised": "7.1.5",
"@types/dns-packet": "5.6.4",
"@types/eslint": "8.56.10",
"@types/mocha": "10.0.1",
"@types/node": "20.11.19",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@typescript-eslint/parser": "7.9.0",
"@web/test-runner": "0.18.0",
"@web/test-runner-playwright": "0.11.0",
"c8": "9.1.0",
"chai": "4.3.10",
"chai-as-promised": "7.1.1",
"esbuild": "0.19.8",
"eslint": "9.3.0",
"eslint-plugin-mocha": "10.4.3",
"mocha": "10.2.0",
"mocha-junit-reporter": "2.2.1",
"node-stdlib-browser": "1.2.0",
"playwright": "1.40.1",
"rimraf": "4.4.0",
"typescript": "5.1.6"
},
"scripts": {
"clean": "rimraf dist tests/compiled",
"build:esm": "rimraf dist/esm dist/types && pnpm tsc -p tsconfig.json",
"build:cjs": "rimraf dist/cjs && pnpm tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
"build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js",
"build:tests:node": "rimraf tests/compiled && pnpm tsc -p tests/tsconfig.json",
"build:tests:browser": "rimraf tests/compiled && node build/esbuild-tests.cjs",
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:browser",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix",
"test:node": "pnpm build:tests:node && pnpm c8 mocha",
"test:browser": "pnpm build:tests:browser && web-test-runner"
}
}
+1
View File
@@ -0,0 +1 @@
export * from './user-agent.js';
+243
View File
@@ -0,0 +1,243 @@
import type {
Web5Rpc,
DidRequest,
VcResponse,
DidResponse,
DwnResponse,
DidInterface,
DwnInterface,
SendVcRequest,
SendDwnRequest,
ProcessVcRequest,
ProcessDwnRequest,
Web5PlatformAgent,
} from '@web5/agent';
import { LevelStore } from '@web5/common';
import { BearerDid, DidDht, DidJwk, DidResolverCacheLevel } from '@web5/dids';
import {
AgentDidApi,
AgentDwnApi,
DwnDidStore,
DwnKeyStore,
AgentSyncApi,
Web5RpcClient,
AgentCryptoApi,
AgentKeyManager,
HdIdentityVault,
LocalKeyManager,
SyncEngineLevel,
AgentIdentityApi,
DwnIdentityStore,
} from '@web5/agent';
/**
* Initialization parameters for {@link Web5UserAgent}, including an optional recovery phrase that
* can be used to derive keys to encrypt the vault and generate a DID.
*/
export type AgentInitializeParams = {
/**
* The password used to secure the Agent vault.
*
* The password selected should be strong and securely managed to prevent unauthorized access.
*/
password: string;
/**
* An optional recovery phrase used to deterministically generate the cryptographic keys for the
* Agent vault.
*
* Supplying this phrase enables the vault's contents to be restored or replicated across devices.
* If omitted, a new phrase is generated, which should be securely recorded for future recovery needs.
*/
recoveryPhrase?: string;
};
export type AgentStartParams = {
/**
* The password used to unlock the previously initialized Agent vault.
*/
password: string;
}
export type AgentParams<TKeyManager extends AgentKeyManager = LocalKeyManager> = {
/** Optional. The Decentralized Identifier (DID) representing this Web5 User Agent. */
agentDid?: BearerDid;
/** Encrypted vault used for managing the Agent's DID and associated keys. */
agentVault: HdIdentityVault;
/** Provides cryptographic capabilties like signing, encryption, hashing and key derivation. */
cryptoApi: AgentCryptoApi;
/** Specifies the local path to be used by the Agent's persistent data stores. */
dataPath?: string;
/** Facilitates DID operations including create, update, and resolve. */
didApi: AgentDidApi<TKeyManager>;
/** Facilitates DWN operations including processing and sending requests. */
dwnApi: AgentDwnApi;
/** Facilitates decentralized Identity operations including create, import, and export. */
identityApi: AgentIdentityApi<TKeyManager>;
/** Responsible for securely managing the cryptographic keys of the agent. */
keyManager: TKeyManager;
/** Remote procedure call (RPC) client used to communicate with other Web5 services. */
rpcClient: Web5Rpc;
/** Facilitates data synchronization of DWN records between nodes. */
syncApi: AgentSyncApi;
}
export class Web5UserAgent<TKeyManager extends AgentKeyManager = LocalKeyManager> implements Web5PlatformAgent<TKeyManager> {
public crypto: AgentCryptoApi;
public did: AgentDidApi<TKeyManager>;
public dwn: AgentDwnApi;
public identity: AgentIdentityApi<TKeyManager>;
public keyManager: TKeyManager;
public rpc: Web5Rpc;
public sync: AgentSyncApi;
public vault: HdIdentityVault;
private _agentDid?: BearerDid;
constructor(params: AgentParams<TKeyManager>) {
this._agentDid = params.agentDid;
this.crypto = params.cryptoApi;
this.did = params.didApi;
this.dwn = params.dwnApi;
this.identity = params.identityApi;
this.keyManager = params.keyManager;
this.rpc = params.rpcClient;
this.sync = params.syncApi;
this.vault = params.agentVault;
// Set this agent to be the default agent.
this.did.agent = this;
this.dwn.agent = this;
this.identity.agent = this;
this.keyManager.agent = this;
this.sync.agent = this;
}
get agentDid(): BearerDid {
if (this._agentDid === undefined) {
throw new Error(
'Web5UserAgent: The "agentDid" property is not set. Ensure the agent is properly ' +
'initialized and a DID is assigned.'
);
}
return this._agentDid;
}
set agentDid(did: BearerDid) {
this._agentDid = did;
}
/**
* If any of the required agent components are not provided, instantiate default implementations.
*/
public static async create({
dataPath = 'DATA/AGENT',
agentDid, agentVault, cryptoApi, didApi, dwnApi, identityApi, keyManager, rpcClient, syncApi
}: Partial<AgentParams> = {}
): Promise<Web5UserAgent> {
agentVault ??= new HdIdentityVault({
keyDerivationWorkFactor : 210_000,
store : new LevelStore<string, string>({ location: `${dataPath}/VAULT_STORE` })
});
cryptoApi ??= new AgentCryptoApi();
didApi ??= new AgentDidApi({
didMethods : [DidDht, DidJwk],
resolverCache : new DidResolverCacheLevel({ location: `${dataPath}/DID_RESOLVERCACHE` }),
store : new DwnDidStore()
});
dwnApi ??= new AgentDwnApi({
dwn: await AgentDwnApi.createDwn({ dataPath, didResolver: didApi })
});
identityApi ??= new AgentIdentityApi({ store: new DwnIdentityStore() });
keyManager ??= new LocalKeyManager({ keyStore: new DwnKeyStore() });
rpcClient ??= new Web5RpcClient();
syncApi ??= new AgentSyncApi({ syncEngine: new SyncEngineLevel({ dataPath }) });
// Instantiate the Agent using the provided or default components.
return new Web5UserAgent({
agentDid,
agentVault,
cryptoApi,
didApi,
dwnApi,
keyManager,
identityApi,
rpcClient,
syncApi
});
}
public async firstLaunch(): Promise<boolean> {
// Check whether data vault is already initialize
return await this.vault.isInitialized() === false;
}
/**
* Initializes the User Agent with a password, and optionally a recovery phrase.
*
* This method is typically called once, the first time the Agent is launched, and is responsible
* for setting up the agent's operational environment, cryptographic key material, and readiness
* for processing Web5 requests.
*
* The password is used to secure the Agent vault, and the recovery phrase is used to derive the
* cryptographic keys for the vault. If a recovery phrase is not provided, a new recovery phrase
* will be generated and returned. The password should be chosen and entered by the end-user.
*/
public async initialize({ password, recoveryPhrase }: AgentInitializeParams): Promise<string> {
// Initialize the Agent vault.
recoveryPhrase = await this.vault.initialize({ password, recoveryPhrase });
return recoveryPhrase;
}
async processDidRequest<T extends DidInterface>(
request: DidRequest<T>
): Promise<DidResponse<T>> {
return this.did.processRequest(request);
}
public async processDwnRequest<T extends DwnInterface>(
request: ProcessDwnRequest<T>
): Promise<DwnResponse<T>> {
return this.dwn.processRequest(request);
}
public async processVcRequest(_request: ProcessVcRequest): Promise<VcResponse> {
throw new Error('Not implemented');
}
public async sendDidRequest<T extends DidInterface>(
_request: DidRequest<T>
): Promise<DidResponse<T>> {
throw new Error('Not implemented');
}
public async sendDwnRequest<T extends DwnInterface>(
request: SendDwnRequest<T>
): Promise<DwnResponse<T>> {
return this.dwn.sendRequest(request);
}
public async sendVcRequest(_request: SendVcRequest): Promise<VcResponse> {
throw new Error('Not implemented');
}
public async start({ password }: AgentInitializeParams): Promise<void> {
// If the Agent vault is locked, unlock it.
if (this.vault.isLocked()) {
await this.vault.unlock({ password });
}
// Set the Agent's DID.
this.agentDid = await this.vault.getDid();
}
}