@enbox/api 0.0.1
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 +201 -0
- package/README.md +585 -0
- package/dist/browser.js +2226 -0
- package/dist/browser.js.map +7 -0
- package/dist/browser.mjs +2226 -0
- package/dist/browser.mjs.map +7 -0
- package/dist/cjs/did-api.js +126 -0
- package/dist/cjs/did-api.js.map +1 -0
- package/dist/cjs/dwn-api.js +804 -0
- package/dist/cjs/dwn-api.js.map +1 -0
- package/dist/cjs/grant-revocation.js +183 -0
- package/dist/cjs/grant-revocation.js.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/permission-grant.js +365 -0
- package/dist/cjs/permission-grant.js.map +1 -0
- package/dist/cjs/permission-request.js +272 -0
- package/dist/cjs/permission-request.js.map +1 -0
- package/dist/cjs/protocol.js +110 -0
- package/dist/cjs/protocol.js.map +1 -0
- package/dist/cjs/record.js +1127 -0
- package/dist/cjs/record.js.map +1 -0
- package/dist/cjs/subscription-util.js +86 -0
- package/dist/cjs/subscription-util.js.map +1 -0
- package/dist/cjs/utils.js +127 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/cjs/vc-api.js +64 -0
- package/dist/cjs/vc-api.js.map +1 -0
- package/dist/cjs/web5.js +471 -0
- package/dist/cjs/web5.js.map +1 -0
- package/dist/esm/did-api.js +69 -0
- package/dist/esm/did-api.js.map +1 -0
- package/dist/esm/dwn-api.js +573 -0
- package/dist/esm/dwn-api.js.map +1 -0
- package/dist/esm/grant-revocation.js +109 -0
- package/dist/esm/grant-revocation.js.map +1 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/permission-grant.js +233 -0
- package/dist/esm/permission-grant.js.map +1 -0
- package/dist/esm/permission-request.js +166 -0
- package/dist/esm/permission-request.js.map +1 -0
- package/dist/esm/protocol.js +67 -0
- package/dist/esm/protocol.js.map +1 -0
- package/dist/esm/record.js +814 -0
- package/dist/esm/record.js.map +1 -0
- package/dist/esm/subscription-util.js +35 -0
- package/dist/esm/subscription-util.js.map +1 -0
- package/dist/esm/utils.js +120 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/vc-api.js +30 -0
- package/dist/esm/vc-api.js.map +1 -0
- package/dist/esm/web5.js +281 -0
- package/dist/esm/web5.js.map +1 -0
- package/dist/types/did-api.d.ts +66 -0
- package/dist/types/did-api.d.ts.map +1 -0
- package/dist/types/dwn-api.d.ts +336 -0
- package/dist/types/dwn-api.d.ts.map +1 -0
- package/dist/types/grant-revocation.d.ts +66 -0
- package/dist/types/grant-revocation.d.ts.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/permission-grant.d.ts +157 -0
- package/dist/types/permission-grant.d.ts.map +1 -0
- package/dist/types/permission-request.d.ts +108 -0
- package/dist/types/permission-request.d.ts.map +1 -0
- package/dist/types/protocol.d.ts +59 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/record.d.ts +441 -0
- package/dist/types/record.d.ts.map +1 -0
- package/dist/types/subscription-util.d.ts +19 -0
- package/dist/types/subscription-util.d.ts.map +1 -0
- package/dist/types/utils.d.ts +85 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/vc-api.d.ts +24 -0
- package/dist/types/vc-api.d.ts.map +1 -0
- package/dist/types/web5.d.ts +219 -0
- package/dist/types/web5.d.ts.map +1 -0
- package/package.json +111 -0
- package/src/did-api.ts +90 -0
- package/src/dwn-api.ts +952 -0
- package/src/grant-revocation.ts +124 -0
- package/src/index.ts +35 -0
- package/src/permission-grant.ts +327 -0
- package/src/permission-request.ts +214 -0
- package/src/protocol.ts +87 -0
- package/src/record.ts +1125 -0
- package/src/subscription-util.ts +42 -0
- package/src/utils.ts +128 -0
- package/src/vc-api.ts +30 -0
- package/src/web5.ts +516 -0
package/dist/cjs/web5.js
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: Added reference types here to avoid a `pnpm` bug during build.
|
|
4
|
+
* https://github.com/TBD54566975/web5-js/pull/507
|
|
5
|
+
*/
|
|
6
|
+
/// <reference types="@enbox/dwn-sdk-js" />
|
|
7
|
+
var __assign = (this && this.__assign) || function () {
|
|
8
|
+
__assign = Object.assign || function(t) {
|
|
9
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
10
|
+
s = arguments[i];
|
|
11
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
12
|
+
t[p] = s[p];
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
};
|
|
16
|
+
return __assign.apply(this, arguments);
|
|
17
|
+
};
|
|
18
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
+
function step(op) {
|
|
32
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
+
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;
|
|
35
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
+
switch (op[0]) {
|
|
37
|
+
case 0: case 1: t = op; break;
|
|
38
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
+
default:
|
|
42
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
+
if (t[2]) _.ops.pop();
|
|
47
|
+
_.trys.pop(); continue;
|
|
48
|
+
}
|
|
49
|
+
op = body.call(thisArg, _);
|
|
50
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
55
|
+
var t = {};
|
|
56
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
57
|
+
t[p] = s[p];
|
|
58
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
59
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
60
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
61
|
+
t[p[i]] = s[p[i]];
|
|
62
|
+
}
|
|
63
|
+
return t;
|
|
64
|
+
};
|
|
65
|
+
var __values = (this && this.__values) || function(o) {
|
|
66
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
67
|
+
if (m) return m.call(o);
|
|
68
|
+
if (o && typeof o.length === "number") return {
|
|
69
|
+
next: function () {
|
|
70
|
+
if (o && i >= o.length) o = void 0;
|
|
71
|
+
return { value: o && o[i++], done: !o };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
75
|
+
};
|
|
76
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
77
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
78
|
+
if (!m) return o;
|
|
79
|
+
var i = m.call(o), r, ar = [], e;
|
|
80
|
+
try {
|
|
81
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
82
|
+
}
|
|
83
|
+
catch (error) { e = { error: error }; }
|
|
84
|
+
finally {
|
|
85
|
+
try {
|
|
86
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
87
|
+
}
|
|
88
|
+
finally { if (e) throw e.error; }
|
|
89
|
+
}
|
|
90
|
+
return ar;
|
|
91
|
+
};
|
|
92
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
93
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
94
|
+
if (ar || !(i in from)) {
|
|
95
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
96
|
+
ar[i] = from[i];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
100
|
+
};
|
|
101
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
102
|
+
exports.Web5 = void 0;
|
|
103
|
+
var user_agent_1 = require("@enbox/user-agent");
|
|
104
|
+
var agent_1 = require("@enbox/agent");
|
|
105
|
+
var did_api_js_1 = require("./did-api.js");
|
|
106
|
+
var dwn_api_js_1 = require("./dwn-api.js");
|
|
107
|
+
var vc_api_js_1 = require("./vc-api.js");
|
|
108
|
+
var permission_grant_js_1 = require("./permission-grant.js");
|
|
109
|
+
/**
|
|
110
|
+
* The main Web5 API interface. It manages the creation of a DID if needed, the connection to the
|
|
111
|
+
* local DWN and all the web5 main foundational APIs such as VC, syncing, etc.
|
|
112
|
+
*/
|
|
113
|
+
var Web5 = /** @class */ (function () {
|
|
114
|
+
function Web5(_a) {
|
|
115
|
+
var agent = _a.agent, connectedDid = _a.connectedDid, delegateDid = _a.delegateDid;
|
|
116
|
+
this.agent = agent;
|
|
117
|
+
this.did = new did_api_js_1.DidApi({ agent: agent, connectedDid: connectedDid });
|
|
118
|
+
this.dwn = new dwn_api_js_1.DwnApi({ agent: agent, connectedDid: connectedDid, delegateDid: delegateDid });
|
|
119
|
+
this.vc = new vc_api_js_1.VcApi({ agent: agent, connectedDid: connectedDid });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Connects to a {@link Web5Agent}. Defaults to creating a local {@link Web5UserAgent} if one
|
|
123
|
+
* isn't provided.
|
|
124
|
+
*
|
|
125
|
+
* If `walletConnectOptions` are provided, a WalletConnect flow will be initiated to import a delegated DID from an external wallet.
|
|
126
|
+
* If there is a failure at any point during connecting and processing grants, all created DIDs and Identities as well as the provided grants
|
|
127
|
+
* will be cleaned up and an error thrown. This allows for subsequent Connect attempts to be made without any errors.
|
|
128
|
+
*
|
|
129
|
+
* @param options - Optional overrides that can be provided when calling {@link Web5.connect}.
|
|
130
|
+
* @returns A promise that resolves to a {@link Web5} instance and the connected DID.
|
|
131
|
+
*/
|
|
132
|
+
Web5.connect = function (_a) {
|
|
133
|
+
var _b, _c, _d;
|
|
134
|
+
var _e = _a === void 0 ? {} : _a, agent = _e.agent, agentVault = _e.agentVault, connectedDid = _e.connectedDid, password = _e.password, recoveryPhrase = _e.recoveryPhrase, sync = _e.sync, techPreview = _e.techPreview, didCreateOptions = _e.didCreateOptions, registration = _e.registration, walletConnectOptions = _e.walletConnectOptions;
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var delegateDid, registerSync, userAgent, serviceEndpointNodes, connectedIdentity, identity, connectedProtocols, permissionRequests, connectOptions, walletPermissionRequests, _f, delegatePortableDid, connectedDid_1, delegateGrants, error_1, identities, existingIdentityCount, serviceEndpointNodes_1, serviceEndpointNodes_1_1, dwnEndpoint, serverInfo, e_1_1, error_2, web5;
|
|
137
|
+
var e_1, _g;
|
|
138
|
+
return __generator(this, function (_h) {
|
|
139
|
+
switch (_h.label) {
|
|
140
|
+
case 0:
|
|
141
|
+
if (!(agent === undefined)) return [3 /*break*/, 36];
|
|
142
|
+
registerSync = false;
|
|
143
|
+
return [4 /*yield*/, user_agent_1.Web5UserAgent.create({ agentVault: agentVault })];
|
|
144
|
+
case 1:
|
|
145
|
+
userAgent = _h.sent();
|
|
146
|
+
agent = userAgent;
|
|
147
|
+
// Warn the developer and application user of the security risks of using a static password.
|
|
148
|
+
if (password === undefined) {
|
|
149
|
+
password = 'insecure-static-phrase';
|
|
150
|
+
console.warn('%cSECURITY WARNING:%c ' +
|
|
151
|
+
'You have not set a password, which defaults to a static, guessable value. ' +
|
|
152
|
+
'This significantly compromises the security of your data. ' +
|
|
153
|
+
'Please configure a secure, unique password.', 'font-weight: bold; color: red;', 'font-weight: normal; color: inherit;');
|
|
154
|
+
}
|
|
155
|
+
serviceEndpointNodes = (_c = (_b = techPreview === null || techPreview === void 0 ? void 0 : techPreview.dwnEndpoints) !== null && _b !== void 0 ? _b : didCreateOptions === null || didCreateOptions === void 0 ? void 0 : didCreateOptions.dwnEndpoints) !== null && _c !== void 0 ? _c : ['https://enbox-production.up.railway.app'];
|
|
156
|
+
return [4 /*yield*/, userAgent.firstLaunch()];
|
|
157
|
+
case 2:
|
|
158
|
+
if (!_h.sent()) return [3 /*break*/, 4];
|
|
159
|
+
return [4 /*yield*/, userAgent.initialize({ password: password, recoveryPhrase: recoveryPhrase, dwnEndpoints: serviceEndpointNodes })];
|
|
160
|
+
case 3:
|
|
161
|
+
recoveryPhrase = _h.sent();
|
|
162
|
+
_h.label = 4;
|
|
163
|
+
case 4: return [4 /*yield*/, userAgent.start({ password: password })];
|
|
164
|
+
case 5:
|
|
165
|
+
_h.sent();
|
|
166
|
+
return [4 /*yield*/, userAgent.identity.connectedIdentity()];
|
|
167
|
+
case 6:
|
|
168
|
+
connectedIdentity = _h.sent();
|
|
169
|
+
identity = void 0;
|
|
170
|
+
connectedProtocols = [];
|
|
171
|
+
if (!connectedIdentity) return [3 /*break*/, 7];
|
|
172
|
+
// if a connected identity is found, use it
|
|
173
|
+
// TODO: In the future, implement a way to re-connect an already connected identity and apply additional grants/protocols
|
|
174
|
+
identity = connectedIdentity;
|
|
175
|
+
return [3 /*break*/, 19];
|
|
176
|
+
case 7:
|
|
177
|
+
if (!walletConnectOptions) return [3 /*break*/, 15];
|
|
178
|
+
if (sync === 'off') {
|
|
179
|
+
// Currently we require sync to be enabled when using WalletConnect
|
|
180
|
+
// This is to ensure a connected app is not in a disjointed state from any other clients/app using the connectedDid
|
|
181
|
+
throw new Error('Sync must not be disabled when using WalletConnect');
|
|
182
|
+
}
|
|
183
|
+
// Since we are connecting a new identity, we will want to register sync for the connectedDid
|
|
184
|
+
registerSync = true;
|
|
185
|
+
_h.label = 8;
|
|
186
|
+
case 8:
|
|
187
|
+
_h.trys.push([8, 12, , 14]);
|
|
188
|
+
permissionRequests = walletConnectOptions.permissionRequests, connectOptions = __rest(walletConnectOptions, ["permissionRequests"]);
|
|
189
|
+
walletPermissionRequests = permissionRequests.map(function (_a) {
|
|
190
|
+
var protocolDefinition = _a.protocolDefinition, permissions = _a.permissions;
|
|
191
|
+
return agent_1.WalletConnect.createPermissionRequestForProtocol({
|
|
192
|
+
definition: protocolDefinition,
|
|
193
|
+
permissions: permissions !== null && permissions !== void 0 ? permissions : [
|
|
194
|
+
'read', 'write', 'delete', 'query', 'subscribe'
|
|
195
|
+
]
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
return [4 /*yield*/, agent_1.WalletConnect.initClient(__assign(__assign({}, connectOptions), { permissionRequests: walletPermissionRequests }))];
|
|
199
|
+
case 9:
|
|
200
|
+
_f = _h.sent(), delegatePortableDid = _f.delegatePortableDid, connectedDid_1 = _f.connectedDid, delegateGrants = _f.delegateGrants;
|
|
201
|
+
return [4 /*yield*/, userAgent.identity.import({ portableIdentity: {
|
|
202
|
+
portableDid: delegatePortableDid,
|
|
203
|
+
metadata: {
|
|
204
|
+
connectedDid: connectedDid_1,
|
|
205
|
+
name: 'Default',
|
|
206
|
+
uri: delegatePortableDid.uri,
|
|
207
|
+
tenant: agent.agentDid.uri,
|
|
208
|
+
}
|
|
209
|
+
} })];
|
|
210
|
+
case 10:
|
|
211
|
+
// Import the delegated DID as an Identity in the User Agent.
|
|
212
|
+
// Setting the connectedDID in the metadata applies a relationship between the signer identity and the one it is impersonating.
|
|
213
|
+
identity = _h.sent();
|
|
214
|
+
return [4 /*yield*/, this.processConnectedGrants({ agent: agent, delegateDid: delegatePortableDid.uri, grants: delegateGrants })];
|
|
215
|
+
case 11:
|
|
216
|
+
// Attempts to process the connected grants to be used by the delegateDID
|
|
217
|
+
// If the process fails, we want to clean up the identity
|
|
218
|
+
// the connected grants will return a de-duped array of protocol URIs that are used to register sync for those protocols
|
|
219
|
+
connectedProtocols = _h.sent();
|
|
220
|
+
return [3 /*break*/, 14];
|
|
221
|
+
case 12:
|
|
222
|
+
error_1 = _h.sent();
|
|
223
|
+
// clean up the DID and Identity if import fails and throw
|
|
224
|
+
// TODO: Implement the ability to purge all of our messages as a tenant
|
|
225
|
+
return [4 /*yield*/, this.cleanUpIdentity({ identity: identity, userAgent: userAgent })];
|
|
226
|
+
case 13:
|
|
227
|
+
// clean up the DID and Identity if import fails and throw
|
|
228
|
+
// TODO: Implement the ability to purge all of our messages as a tenant
|
|
229
|
+
_h.sent();
|
|
230
|
+
throw new Error("Failed to connect to wallet: ".concat(error_1.message));
|
|
231
|
+
case 14: return [3 /*break*/, 19];
|
|
232
|
+
case 15: return [4 /*yield*/, userAgent.identity.list()];
|
|
233
|
+
case 16:
|
|
234
|
+
identities = _h.sent();
|
|
235
|
+
existingIdentityCount = identities.length;
|
|
236
|
+
if (!(existingIdentityCount === 0)) return [3 /*break*/, 18];
|
|
237
|
+
// since we are creating a new identity, we will want to register sync for the created Did
|
|
238
|
+
registerSync = true;
|
|
239
|
+
return [4 /*yield*/, userAgent.identity.create({
|
|
240
|
+
didMethod: 'dht',
|
|
241
|
+
metadata: { name: 'Default' },
|
|
242
|
+
didOptions: {
|
|
243
|
+
services: [
|
|
244
|
+
{
|
|
245
|
+
id: 'dwn',
|
|
246
|
+
type: 'DecentralizedWebNode',
|
|
247
|
+
serviceEndpoint: serviceEndpointNodes,
|
|
248
|
+
enc: '#enc',
|
|
249
|
+
sig: '#sig',
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
verificationMethods: [
|
|
253
|
+
{
|
|
254
|
+
algorithm: 'Ed25519',
|
|
255
|
+
id: 'sig',
|
|
256
|
+
purposes: ['assertionMethod', 'authentication']
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
algorithm: 'secp256k1',
|
|
260
|
+
id: 'enc',
|
|
261
|
+
purposes: ['keyAgreement']
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
})];
|
|
266
|
+
case 17:
|
|
267
|
+
// Generate a new Identity for the end-user.
|
|
268
|
+
identity = _h.sent();
|
|
269
|
+
return [3 /*break*/, 19];
|
|
270
|
+
case 18:
|
|
271
|
+
// If multiple identities are found, use the first one.
|
|
272
|
+
// TODO: Implement selecting a connectedDid from multiple identities
|
|
273
|
+
identity = identities[0];
|
|
274
|
+
_h.label = 19;
|
|
275
|
+
case 19:
|
|
276
|
+
// If the stored identity has a connected DID, use it as the connected DID, otherwise use the identity's DID.
|
|
277
|
+
connectedDid = (_d = identity.metadata.connectedDid) !== null && _d !== void 0 ? _d : identity.did.uri;
|
|
278
|
+
// If the stored identity has a connected DID, use the identity DID as the delegated DID, otherwise it is undefined.
|
|
279
|
+
delegateDid = identity.metadata.connectedDid ? identity.did.uri : undefined;
|
|
280
|
+
if (!(registration !== undefined)) return [3 /*break*/, 32];
|
|
281
|
+
_h.label = 20;
|
|
282
|
+
case 20:
|
|
283
|
+
_h.trys.push([20, 31, , 32]);
|
|
284
|
+
_h.label = 21;
|
|
285
|
+
case 21:
|
|
286
|
+
_h.trys.push([21, 28, 29, 30]);
|
|
287
|
+
serviceEndpointNodes_1 = __values(serviceEndpointNodes), serviceEndpointNodes_1_1 = serviceEndpointNodes_1.next();
|
|
288
|
+
_h.label = 22;
|
|
289
|
+
case 22:
|
|
290
|
+
if (!!serviceEndpointNodes_1_1.done) return [3 /*break*/, 27];
|
|
291
|
+
dwnEndpoint = serviceEndpointNodes_1_1.value;
|
|
292
|
+
return [4 /*yield*/, userAgent.rpc.getServerInfo(dwnEndpoint)];
|
|
293
|
+
case 23:
|
|
294
|
+
serverInfo = _h.sent();
|
|
295
|
+
if (serverInfo.registrationRequirements.length === 0) {
|
|
296
|
+
// no registration required
|
|
297
|
+
return [3 /*break*/, 26];
|
|
298
|
+
}
|
|
299
|
+
// register the agent DID
|
|
300
|
+
return [4 /*yield*/, agent_1.DwnRegistrar.registerTenant(dwnEndpoint, agent.agentDid.uri)];
|
|
301
|
+
case 24:
|
|
302
|
+
// register the agent DID
|
|
303
|
+
_h.sent();
|
|
304
|
+
// register the connected Identity DID
|
|
305
|
+
return [4 /*yield*/, agent_1.DwnRegistrar.registerTenant(dwnEndpoint, connectedDid)];
|
|
306
|
+
case 25:
|
|
307
|
+
// register the connected Identity DID
|
|
308
|
+
_h.sent();
|
|
309
|
+
_h.label = 26;
|
|
310
|
+
case 26:
|
|
311
|
+
serviceEndpointNodes_1_1 = serviceEndpointNodes_1.next();
|
|
312
|
+
return [3 /*break*/, 22];
|
|
313
|
+
case 27: return [3 /*break*/, 30];
|
|
314
|
+
case 28:
|
|
315
|
+
e_1_1 = _h.sent();
|
|
316
|
+
e_1 = { error: e_1_1 };
|
|
317
|
+
return [3 /*break*/, 30];
|
|
318
|
+
case 29:
|
|
319
|
+
try {
|
|
320
|
+
if (serviceEndpointNodes_1_1 && !serviceEndpointNodes_1_1.done && (_g = serviceEndpointNodes_1.return)) _g.call(serviceEndpointNodes_1);
|
|
321
|
+
}
|
|
322
|
+
finally { if (e_1) throw e_1.error; }
|
|
323
|
+
return [7 /*endfinally*/];
|
|
324
|
+
case 30:
|
|
325
|
+
// If no failures occurred, call the onSuccess callback
|
|
326
|
+
registration.onSuccess();
|
|
327
|
+
return [3 /*break*/, 32];
|
|
328
|
+
case 31:
|
|
329
|
+
error_2 = _h.sent();
|
|
330
|
+
// for any failure, call the onFailure callback with the error
|
|
331
|
+
registration.onFailure(error_2);
|
|
332
|
+
return [3 /*break*/, 32];
|
|
333
|
+
case 32:
|
|
334
|
+
if (!(sync !== 'off')) return [3 /*break*/, 36];
|
|
335
|
+
if (!registerSync) return [3 /*break*/, 35];
|
|
336
|
+
return [4 /*yield*/, userAgent.sync.registerIdentity({
|
|
337
|
+
did: connectedDid,
|
|
338
|
+
options: {
|
|
339
|
+
delegateDid: delegateDid,
|
|
340
|
+
protocols: connectedProtocols
|
|
341
|
+
}
|
|
342
|
+
})];
|
|
343
|
+
case 33:
|
|
344
|
+
_h.sent();
|
|
345
|
+
if (!(walletConnectOptions !== undefined)) return [3 /*break*/, 35];
|
|
346
|
+
// If we are using WalletConnect, we should do a one-shot sync to pull down any messages that are associated with the connectedDid
|
|
347
|
+
return [4 /*yield*/, userAgent.sync.sync('pull')];
|
|
348
|
+
case 34:
|
|
349
|
+
// If we are using WalletConnect, we should do a one-shot sync to pull down any messages that are associated with the connectedDid
|
|
350
|
+
_h.sent();
|
|
351
|
+
_h.label = 35;
|
|
352
|
+
case 35:
|
|
353
|
+
// Enable sync using the specified interval or default.
|
|
354
|
+
sync !== null && sync !== void 0 ? sync : (sync = '2m');
|
|
355
|
+
userAgent.sync.startSync({ interval: sync })
|
|
356
|
+
.catch(function (error) {
|
|
357
|
+
console.error("Sync failed: ".concat(error));
|
|
358
|
+
});
|
|
359
|
+
_h.label = 36;
|
|
360
|
+
case 36:
|
|
361
|
+
web5 = new Web5({ agent: agent, connectedDid: connectedDid, delegateDid: delegateDid });
|
|
362
|
+
return [2 /*return*/, { web5: web5, did: connectedDid, delegateDid: delegateDid, recoveryPhrase: recoveryPhrase }];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Cleans up the DID, Keys and Identity. Primarily used by a failed WalletConnect import.
|
|
369
|
+
* Does not throw on error, but logs to console.
|
|
370
|
+
*/
|
|
371
|
+
Web5.cleanUpIdentity = function (_a) {
|
|
372
|
+
var identity = _a.identity, userAgent = _a.userAgent;
|
|
373
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
+
var error_3, error_4;
|
|
375
|
+
return __generator(this, function (_b) {
|
|
376
|
+
switch (_b.label) {
|
|
377
|
+
case 0:
|
|
378
|
+
_b.trys.push([0, 2, , 3]);
|
|
379
|
+
// Delete the DID and the Associated Keys
|
|
380
|
+
return [4 /*yield*/, userAgent.did.delete({
|
|
381
|
+
didUri: identity.did.uri,
|
|
382
|
+
tenant: identity.metadata.tenant,
|
|
383
|
+
deleteKey: true,
|
|
384
|
+
})];
|
|
385
|
+
case 1:
|
|
386
|
+
// Delete the DID and the Associated Keys
|
|
387
|
+
_b.sent();
|
|
388
|
+
return [3 /*break*/, 3];
|
|
389
|
+
case 2:
|
|
390
|
+
error_3 = _b.sent();
|
|
391
|
+
console.error("Failed to delete DID ".concat(identity.did.uri, ": ").concat(error_3.message));
|
|
392
|
+
return [3 /*break*/, 3];
|
|
393
|
+
case 3:
|
|
394
|
+
_b.trys.push([3, 5, , 6]);
|
|
395
|
+
// Delete the Identity
|
|
396
|
+
return [4 /*yield*/, userAgent.identity.delete({ didUri: identity.did.uri })];
|
|
397
|
+
case 4:
|
|
398
|
+
// Delete the Identity
|
|
399
|
+
_b.sent();
|
|
400
|
+
return [3 /*break*/, 6];
|
|
401
|
+
case 5:
|
|
402
|
+
error_4 = _b.sent();
|
|
403
|
+
console.error("Failed to delete Identity ".concat(identity.metadata.name, ": ").concat(error_4.message));
|
|
404
|
+
return [3 /*break*/, 6];
|
|
405
|
+
case 6: return [2 /*return*/];
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* A static method to process connected grants for a delegate DID.
|
|
412
|
+
*
|
|
413
|
+
* This will store the grants as the DWN owner to be used later when impersonating the connected DID.
|
|
414
|
+
*/
|
|
415
|
+
Web5.processConnectedGrants = function (_a) {
|
|
416
|
+
var grants = _a.grants, agent = _a.agent, delegateDid = _a.delegateDid;
|
|
417
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
418
|
+
var connectedProtocols, grants_1, grants_1_1, grantMessage, grant, status_1, protocol, e_2_1;
|
|
419
|
+
var e_2, _b;
|
|
420
|
+
return __generator(this, function (_c) {
|
|
421
|
+
switch (_c.label) {
|
|
422
|
+
case 0:
|
|
423
|
+
connectedProtocols = new Set();
|
|
424
|
+
_c.label = 1;
|
|
425
|
+
case 1:
|
|
426
|
+
_c.trys.push([1, 7, 8, 9]);
|
|
427
|
+
grants_1 = __values(grants), grants_1_1 = grants_1.next();
|
|
428
|
+
_c.label = 2;
|
|
429
|
+
case 2:
|
|
430
|
+
if (!!grants_1_1.done) return [3 /*break*/, 6];
|
|
431
|
+
grantMessage = grants_1_1.value;
|
|
432
|
+
return [4 /*yield*/, permission_grant_js_1.PermissionGrant.parse({ connectedDid: delegateDid, agent: agent, message: grantMessage })];
|
|
433
|
+
case 3:
|
|
434
|
+
grant = _c.sent();
|
|
435
|
+
return [4 /*yield*/, grant.store(true)];
|
|
436
|
+
case 4:
|
|
437
|
+
status_1 = (_c.sent()).status;
|
|
438
|
+
if (status_1.code !== 202) {
|
|
439
|
+
throw new Error("AgentDwnApi: Failed to process connected grant: ".concat(status_1.detail));
|
|
440
|
+
}
|
|
441
|
+
protocol = grant.scope.protocol;
|
|
442
|
+
if (protocol) {
|
|
443
|
+
connectedProtocols.add(protocol);
|
|
444
|
+
}
|
|
445
|
+
_c.label = 5;
|
|
446
|
+
case 5:
|
|
447
|
+
grants_1_1 = grants_1.next();
|
|
448
|
+
return [3 /*break*/, 2];
|
|
449
|
+
case 6: return [3 /*break*/, 9];
|
|
450
|
+
case 7:
|
|
451
|
+
e_2_1 = _c.sent();
|
|
452
|
+
e_2 = { error: e_2_1 };
|
|
453
|
+
return [3 /*break*/, 9];
|
|
454
|
+
case 8:
|
|
455
|
+
try {
|
|
456
|
+
if (grants_1_1 && !grants_1_1.done && (_b = grants_1.return)) _b.call(grants_1);
|
|
457
|
+
}
|
|
458
|
+
finally { if (e_2) throw e_2.error; }
|
|
459
|
+
return [7 /*endfinally*/];
|
|
460
|
+
case 9:
|
|
461
|
+
// currently we return a de-duped set of protocols represented by these grants, this is used to register protocols for sync
|
|
462
|
+
// we expect that any connected protocols will include MessagesQuery and MessagesRead grants that will allow it to sync
|
|
463
|
+
return [2 /*return*/, __spreadArray([], __read(connectedProtocols), false)];
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
return Web5;
|
|
469
|
+
}());
|
|
470
|
+
exports.Web5 = Web5;
|
|
471
|
+
//# sourceMappingURL=web5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web5.js","sourceRoot":"","sources":["../../src/web5.ts"],"names":[],"mappings":";AAAA;;;GAGG;AACH,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,oCAA6B,QAAQ,CAAC,QAAQ,CAAC,IAAI,eAAK,OAAK,CAAC,OAAO,CAAE,CAAC,CAAC;;;;;;KAE1F;IAED;;;;OAIG;IACU,2BAAsB,GAAnC,UAAoC,EAInC;YAJqC,MAAM,YAAA,EAAE,KAAK,WAAA,EAAE,WAAW,iBAAA;;;;;;;wBAKxD,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;;;;wBAClB,WAAA,SAAA,MAAM,CAAA;;;;wBAAtB,YAAY;wBAEP,qBAAM,qCAAe,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,OAAA,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EAAA;;wBAAhG,KAAK,GAAG,SAAwF;wBAEnF,qBAAM,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA;;wBAAlC,WAAW,CAAA,SAAuB,CAAA,OAA5B;wBACd,IAAI,QAAM,CAAC,IAAI,KAAK,GAAG,EAAE;4BACvB,MAAM,IAAI,KAAK,CAAC,0DAAmD,QAAM,CAAC,MAAM,CAAE,CAAC,CAAC;yBACrF;wBAEK,QAAQ,GAAI,KAAK,CAAC,KAAgE,CAAC,QAAQ,CAAC;wBAClG,IAAI,QAAQ,EAAE;4BACZ,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;yBAClC;;;;;;;;;;;;;;;;;oBAGH,2HAA2H;oBAC3H,uHAAuH;oBACvH,+CAAW,kBAAkB,WAAE;;;;KAChC;IACH,WAAC;AAAD,CAAC,AAzSD,IAySC;AAzSY,oBAAI"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { DidInterface } from '@enbox/agent';
|
|
22
|
+
/**
|
|
23
|
+
* The DID API is used to resolve DIDs.
|
|
24
|
+
*
|
|
25
|
+
* @beta
|
|
26
|
+
*/
|
|
27
|
+
export class DidApi {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.agent = options.agent;
|
|
30
|
+
this.connectedDid = options.connectedDid;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Initiates the creation of a Decentralized Identifier (DID) using the specified method, options,
|
|
34
|
+
* and storage preference.
|
|
35
|
+
*
|
|
36
|
+
* This method sends a request to the Web5 Agent to create a new DID based on the provided method,
|
|
37
|
+
* with method-specific options. It also specifies whether the newly created DID should be stored.
|
|
38
|
+
*
|
|
39
|
+
* @param request - The request parameters for creating a DID, including the method, options, and
|
|
40
|
+
* storage flag.
|
|
41
|
+
* @returns A promise that resolves to a `DidCreateResponse`, which includes the operation's
|
|
42
|
+
* status and, if successful, the newly created DID.
|
|
43
|
+
*/
|
|
44
|
+
create(request) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const _a = yield this.agent.processDidRequest({
|
|
47
|
+
messageType: DidInterface.Create,
|
|
48
|
+
messageParams: Object.assign({}, request)
|
|
49
|
+
}), { result } = _a, status = __rest(_a, ["result"]);
|
|
50
|
+
return Object.assign({ did: result }, status);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolves a DID to a DID Resolution Result.
|
|
55
|
+
*
|
|
56
|
+
* @param didUri - The DID or DID URL to resolve.
|
|
57
|
+
* @returns A promise that resolves to the DID Resolution Result.
|
|
58
|
+
*/
|
|
59
|
+
resolve(didUri, options) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const { result: didResolutionResult } = yield this.agent.processDidRequest({
|
|
62
|
+
messageParams: { didUri, options },
|
|
63
|
+
messageType: DidInterface.Resolve
|
|
64
|
+
});
|
|
65
|
+
return didResolutionResult;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=did-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-api.js","sourceRoot":"","sources":["../../src/did-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA8B5C;;;;GAIG;AACH,MAAM,OAAO,MAAM;IAUjB,YAAY,OAAmD;QAC7D,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;OAWG;IACU,MAAM,CAAC,OAAyB;;YAC3C,MAAM,KAAwB,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;gBAC/D,WAAW,EAAK,YAAY,CAAC,MAAM;gBACnC,aAAa,oBAAQ,OAAO,CAAE;aAC/B,CAAC,EAHI,EAAE,MAAM,OAGZ,EAHiB,MAAM,cAAnB,UAAqB,CAGzB,CAAC;YAEH,uBAAS,GAAG,EAAE,MAAM,IAAK,MAAM,EAAG;QACpC,CAAC;KAAA;IAED;;;;;OAKG;IACU,OAAO,CAClB,MAAkC,EAAE,OAAqC;;YAEzE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;gBACzE,aAAa,EAAG,EAAE,MAAM,EAAE,OAAO,EAAE;gBACnC,WAAW,EAAK,YAAY,CAAC,OAAO;aACrC,CAAC,CAAC;YAEH,OAAO,mBAAmB,CAAC;QAC7B,CAAC;KAAA;CACF"}
|