@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.
Files changed (92) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +585 -0
  3. package/dist/browser.js +2226 -0
  4. package/dist/browser.js.map +7 -0
  5. package/dist/browser.mjs +2226 -0
  6. package/dist/browser.mjs.map +7 -0
  7. package/dist/cjs/did-api.js +126 -0
  8. package/dist/cjs/did-api.js.map +1 -0
  9. package/dist/cjs/dwn-api.js +804 -0
  10. package/dist/cjs/dwn-api.js.map +1 -0
  11. package/dist/cjs/grant-revocation.js +183 -0
  12. package/dist/cjs/grant-revocation.js.map +1 -0
  13. package/dist/cjs/index.js +63 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/permission-grant.js +365 -0
  17. package/dist/cjs/permission-grant.js.map +1 -0
  18. package/dist/cjs/permission-request.js +272 -0
  19. package/dist/cjs/permission-request.js.map +1 -0
  20. package/dist/cjs/protocol.js +110 -0
  21. package/dist/cjs/protocol.js.map +1 -0
  22. package/dist/cjs/record.js +1127 -0
  23. package/dist/cjs/record.js.map +1 -0
  24. package/dist/cjs/subscription-util.js +86 -0
  25. package/dist/cjs/subscription-util.js.map +1 -0
  26. package/dist/cjs/utils.js +127 -0
  27. package/dist/cjs/utils.js.map +1 -0
  28. package/dist/cjs/vc-api.js +64 -0
  29. package/dist/cjs/vc-api.js.map +1 -0
  30. package/dist/cjs/web5.js +471 -0
  31. package/dist/cjs/web5.js.map +1 -0
  32. package/dist/esm/did-api.js +69 -0
  33. package/dist/esm/did-api.js.map +1 -0
  34. package/dist/esm/dwn-api.js +573 -0
  35. package/dist/esm/dwn-api.js.map +1 -0
  36. package/dist/esm/grant-revocation.js +109 -0
  37. package/dist/esm/grant-revocation.js.map +1 -0
  38. package/dist/esm/index.js +34 -0
  39. package/dist/esm/index.js.map +1 -0
  40. package/dist/esm/permission-grant.js +233 -0
  41. package/dist/esm/permission-grant.js.map +1 -0
  42. package/dist/esm/permission-request.js +166 -0
  43. package/dist/esm/permission-request.js.map +1 -0
  44. package/dist/esm/protocol.js +67 -0
  45. package/dist/esm/protocol.js.map +1 -0
  46. package/dist/esm/record.js +814 -0
  47. package/dist/esm/record.js.map +1 -0
  48. package/dist/esm/subscription-util.js +35 -0
  49. package/dist/esm/subscription-util.js.map +1 -0
  50. package/dist/esm/utils.js +120 -0
  51. package/dist/esm/utils.js.map +1 -0
  52. package/dist/esm/vc-api.js +30 -0
  53. package/dist/esm/vc-api.js.map +1 -0
  54. package/dist/esm/web5.js +281 -0
  55. package/dist/esm/web5.js.map +1 -0
  56. package/dist/types/did-api.d.ts +66 -0
  57. package/dist/types/did-api.d.ts.map +1 -0
  58. package/dist/types/dwn-api.d.ts +336 -0
  59. package/dist/types/dwn-api.d.ts.map +1 -0
  60. package/dist/types/grant-revocation.d.ts +66 -0
  61. package/dist/types/grant-revocation.d.ts.map +1 -0
  62. package/dist/types/index.d.ts +34 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/permission-grant.d.ts +157 -0
  65. package/dist/types/permission-grant.d.ts.map +1 -0
  66. package/dist/types/permission-request.d.ts +108 -0
  67. package/dist/types/permission-request.d.ts.map +1 -0
  68. package/dist/types/protocol.d.ts +59 -0
  69. package/dist/types/protocol.d.ts.map +1 -0
  70. package/dist/types/record.d.ts +441 -0
  71. package/dist/types/record.d.ts.map +1 -0
  72. package/dist/types/subscription-util.d.ts +19 -0
  73. package/dist/types/subscription-util.d.ts.map +1 -0
  74. package/dist/types/utils.d.ts +85 -0
  75. package/dist/types/utils.d.ts.map +1 -0
  76. package/dist/types/vc-api.d.ts +24 -0
  77. package/dist/types/vc-api.d.ts.map +1 -0
  78. package/dist/types/web5.d.ts +219 -0
  79. package/dist/types/web5.d.ts.map +1 -0
  80. package/package.json +111 -0
  81. package/src/did-api.ts +90 -0
  82. package/src/dwn-api.ts +952 -0
  83. package/src/grant-revocation.ts +124 -0
  84. package/src/index.ts +35 -0
  85. package/src/permission-grant.ts +327 -0
  86. package/src/permission-request.ts +214 -0
  87. package/src/protocol.ts +87 -0
  88. package/src/record.ts +1125 -0
  89. package/src/subscription-util.ts +42 -0
  90. package/src/utils.ts +128 -0
  91. package/src/vc-api.ts +30 -0
  92. package/src/web5.ts +516 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-grant.js","sourceRoot":"","sources":["../../src/permission-grant.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,wCAAwC;AACxC,sCAIsB;AACtB,6DAAkE;AAqElE;;;;;;;GAOG;AACH;IAUE,yBAAoB,EAKnB;YALqB,GAAG,SAAA,EAAE,YAAY,kBAAA,EAAE,OAAO,aAAA,EAAE,KAAK,WAAA;QAMrD,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QAExB,2CAA2C;QAC3C,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAElC,+CAA+C;QAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,iCAAiC;QACjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,4FAA4F;IAC/E,qBAAK,GAAlB,UAAmB,OAA+B;;;;;4BAElC,qBAAM,0BAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAA;;wBAAvD,KAAK,GAAG,SAA+C;wBACvD,GAAG,GAAG,IAAI,2BAAmB,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;wBAC9D,sBAAO,IAAI,eAAe,uBAAM,OAAO,KAAE,KAAK,OAAA,EAAE,GAAG,KAAA,IAAG,EAAC;;;;KACxD;IAGD,sBAAY,kCAAK;QADjB,2DAA2D;aAC3D;YACE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;QACjC,CAAC;;;OAAA;I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CAAyB,CAAC,KAAK,CAAC;gCACrC,YAAY,EAAG,IAAI,CAAC,aAAa;gCACjC,KAAK,EAAU,IAAI,CAAC,KAAK;gCACzB,OAAO,EAAQ,UAAU,CAAC,OAAO;6BAClC,CAAC,EAAC;;;;KACJ;IAED;;;;;;;;OAQG;IACH,mCAAS,GAAT,UAAU,MAAuB;QAAvB,uBAAA,EAAA,cAAuB;QAC/B,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC;YACtC,MAAM,EAAU,IAAI,CAAC,aAAa;YAClC,MAAM,EAAU,IAAI,CAAC,OAAO;YAC5B,aAAa,EAAG,IAAI,CAAC,EAAE;YACvB,MAAM,QAAA;SACP,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,gCAAM,GAAN;QACE,OAAO;YACL,EAAE,EAAY,IAAI,CAAC,EAAE;YACrB,OAAO,EAAO,IAAI,CAAC,OAAO;YAC1B,OAAO,EAAO,IAAI,CAAC,OAAO;YAC1B,WAAW,EAAG,IAAI,CAAC,WAAW;YAC9B,WAAW,EAAG,IAAI,CAAC,WAAW;YAC9B,SAAS,EAAK,IAAI,CAAC,SAAS;YAC5B,WAAW,EAAG,IAAI,CAAC,WAAW;YAC9B,SAAS,EAAK,IAAI,CAAC,SAAS;YAC5B,KAAK,EAAS,IAAI,CAAC,KAAK;YACxB,UAAU,EAAI,IAAI,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC;IACH,sBAAC;AAAD,CAAC,AA1OD,IA0OC;AA1OY,0CAAe"}
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ exports.PermissionRequest = void 0;
62
+ var agent_1 = require("@enbox/agent");
63
+ var agent_2 = require("@enbox/agent");
64
+ var common_1 = require("@enbox/common");
65
+ var permission_grant_js_1 = require("./permission-grant.js");
66
+ /**
67
+ * The `PermissionRequest` class encapsulates a permissions protocol `request` record, providing a more
68
+ * developer-friendly interface for working with Decentralized Web Node (DWN) records.
69
+ *
70
+ * Methods are provided to grant the request and manage the request's lifecycle, including writing to remote DWNs.
71
+ *
72
+ * @beta
73
+ */
74
+ var PermissionRequest = /** @class */ (function () {
75
+ function PermissionRequest(_a) {
76
+ var api = _a.api, connectedDid = _a.connectedDid, message = _a.message, request = _a.request;
77
+ this._permissions = api;
78
+ this._connectedDid = connectedDid;
79
+ // Store the parsed request object.
80
+ this._request = request;
81
+ // Store the message that represents the grant.
82
+ this._message = message;
83
+ }
84
+ /** parses the request given an agent, connectedDid and data encoded records write message */
85
+ PermissionRequest.parse = function (_a) {
86
+ var connectedDid = _a.connectedDid, agent = _a.agent, message = _a.message;
87
+ return __awaiter(this, void 0, void 0, function () {
88
+ var request, api;
89
+ return __generator(this, function (_b) {
90
+ switch (_b.label) {
91
+ case 0: return [4 /*yield*/, agent_1.DwnPermissionRequest.parse(message)];
92
+ case 1:
93
+ request = _b.sent();
94
+ api = new agent_1.AgentPermissionsApi({ agent: agent });
95
+ return [2 /*return*/, new PermissionRequest({ api: api, connectedDid: connectedDid, message: message, request: request })];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ Object.defineProperty(PermissionRequest.prototype, "agent", {
101
+ /** The agent to use for this instantiation of the request */
102
+ get: function () {
103
+ return this._permissions.agent;
104
+ },
105
+ enumerable: false,
106
+ configurable: true
107
+ });
108
+ Object.defineProperty(PermissionRequest.prototype, "id", {
109
+ /** The request's ID, which is also the underlying record's ID */
110
+ get: function () {
111
+ return this._request.id;
112
+ },
113
+ enumerable: false,
114
+ configurable: true
115
+ });
116
+ Object.defineProperty(PermissionRequest.prototype, "requester", {
117
+ /** The DID that is requesting a permission */
118
+ get: function () {
119
+ return this._request.requester;
120
+ },
121
+ enumerable: false,
122
+ configurable: true
123
+ });
124
+ Object.defineProperty(PermissionRequest.prototype, "description", {
125
+ /** (optional) Description of the permission request */
126
+ get: function () {
127
+ return this._request.description;
128
+ },
129
+ enumerable: false,
130
+ configurable: true
131
+ });
132
+ Object.defineProperty(PermissionRequest.prototype, "delegated", {
133
+ /** Whether or not the permission request can be used to impersonate the grantor */
134
+ get: function () {
135
+ return this._request.delegated;
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ Object.defineProperty(PermissionRequest.prototype, "scope", {
141
+ /** The permission scope under which the requested grant would be valid */
142
+ get: function () {
143
+ return this._request.scope;
144
+ },
145
+ enumerable: false,
146
+ configurable: true
147
+ });
148
+ Object.defineProperty(PermissionRequest.prototype, "conditions", {
149
+ /** The conditions under which the requested grant would be valid */
150
+ get: function () {
151
+ return this._request.conditions;
152
+ },
153
+ enumerable: false,
154
+ configurable: true
155
+ });
156
+ Object.defineProperty(PermissionRequest.prototype, "rawMessage", {
157
+ /** The `RecordsWrite` DWN message with encoded data that was used to instantiate this request */
158
+ get: function () {
159
+ return this._message;
160
+ },
161
+ enumerable: false,
162
+ configurable: true
163
+ });
164
+ /**
165
+ * Send the current permission request to a remote DWN by specifying their DID
166
+ * If no DID is specified, the target is assumed to be the owner (connectedDID).
167
+ *
168
+ * @param target - the optional DID to send the permission request to, if none is set it is sent to the connectedDid
169
+ * @returns the status of the send permission request
170
+ *
171
+ * @beta
172
+ */
173
+ PermissionRequest.prototype.send = function (target) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var _a, encodedData, rawMessage, dataStream, sendRequestOptions, reply;
176
+ return __generator(this, function (_b) {
177
+ switch (_b.label) {
178
+ case 0:
179
+ target !== null && target !== void 0 ? target : (target = this._connectedDid);
180
+ _a = this._message, encodedData = _a.encodedData, rawMessage = __rest(_a, ["encodedData"]);
181
+ dataStream = new Blob([common_1.Convert.base64Url(encodedData).toUint8Array()]);
182
+ sendRequestOptions = {
183
+ messageType: agent_2.DwnInterface.RecordsWrite,
184
+ author: this._connectedDid,
185
+ target: target,
186
+ dataStream: dataStream,
187
+ rawMessage: rawMessage,
188
+ };
189
+ return [4 /*yield*/, this.agent.sendDwnRequest(sendRequestOptions)];
190
+ case 1:
191
+ reply = (_b.sent()).reply;
192
+ return [2 /*return*/, reply];
193
+ }
194
+ });
195
+ });
196
+ };
197
+ /**
198
+ * Stores the current permission request to the owner's DWN.
199
+ *
200
+ * @param importGrant - if true, the permission request will signed by the owner before storing it to the owner's DWN. Defaults to false.
201
+ * @returns the status of the store request
202
+ *
203
+ * @beta
204
+ */
205
+ PermissionRequest.prototype.store = function () {
206
+ return __awaiter(this, void 0, void 0, function () {
207
+ var _a, encodedData, rawMessage, dataStream, _b, reply, message;
208
+ return __generator(this, function (_c) {
209
+ switch (_c.label) {
210
+ case 0:
211
+ _a = this.rawMessage, encodedData = _a.encodedData, rawMessage = __rest(_a, ["encodedData"]);
212
+ dataStream = new Blob([common_1.Convert.base64Url(encodedData).toUint8Array()]);
213
+ return [4 /*yield*/, this.agent.processDwnRequest({
214
+ author: this._connectedDid,
215
+ target: this._connectedDid,
216
+ messageType: agent_2.DwnInterface.RecordsWrite,
217
+ rawMessage: rawMessage,
218
+ dataStream: dataStream,
219
+ })];
220
+ case 1:
221
+ _b = _c.sent(), reply = _b.reply, message = _b.message;
222
+ this._message = __assign(__assign({}, message), { encodedData: encodedData });
223
+ return [2 /*return*/, { status: reply.status }];
224
+ }
225
+ });
226
+ });
227
+ };
228
+ /**
229
+ * Grants the permission request to the requester.
230
+ *
231
+ * @param dateExpires - the date when the permission grant will expire.
232
+ * @param store - if true, the permission grant will be stored in the owner's DWN. Defaults to true.
233
+ * @returns {PermissionGrant} the granted permission.
234
+ *
235
+ * @beta
236
+ */
237
+ PermissionRequest.prototype.grant = function (dateExpires, store) {
238
+ if (store === void 0) { store = true; }
239
+ return __awaiter(this, void 0, void 0, function () {
240
+ var message;
241
+ return __generator(this, function (_a) {
242
+ switch (_a.label) {
243
+ case 0: return [4 /*yield*/, this._permissions.createGrant({
244
+ requestId: this.id,
245
+ grantedTo: this.requester,
246
+ scope: this.scope,
247
+ delegated: this.delegated,
248
+ author: this._connectedDid,
249
+ store: store,
250
+ dateExpires: dateExpires,
251
+ })];
252
+ case 1:
253
+ message = (_a.sent()).message;
254
+ return [2 /*return*/, permission_grant_js_1.PermissionGrant.parse({
255
+ connectedDid: this._connectedDid,
256
+ agent: this.agent,
257
+ message: message
258
+ })];
259
+ }
260
+ });
261
+ });
262
+ };
263
+ /**
264
+ * @returns the JSON representation of the permission request
265
+ */
266
+ PermissionRequest.prototype.toJSON = function () {
267
+ return this._request;
268
+ };
269
+ return PermissionRequest;
270
+ }());
271
+ exports.PermissionRequest = PermissionRequest;
272
+ //# sourceMappingURL=permission-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-request.js","sourceRoot":"","sources":["../../src/permission-request.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAuM;AACvM,sCAA4C;AAC5C,wCAAwC;AACxC,6DAAwD;AAu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}
@@ -0,0 +1,110 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ var __generator = (this && this.__generator) || function (thisArg, body) {
17
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
18
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
19
+ function verb(n) { return function (v) { return step([n, v]); }; }
20
+ function step(op) {
21
+ if (f) throw new TypeError("Generator is already executing.");
22
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
23
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
24
+ if (y = 0, t) op = [op[0] & 2, t.value];
25
+ switch (op[0]) {
26
+ case 0: case 1: t = op; break;
27
+ case 4: _.label++; return { value: op[1], done: false };
28
+ case 5: _.label++; y = op[1]; op = [0]; continue;
29
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
30
+ default:
31
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
32
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
33
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
34
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
35
+ if (t[2]) _.ops.pop();
36
+ _.trys.pop(); continue;
37
+ }
38
+ op = body.call(thisArg, _);
39
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
40
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
41
+ }
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.Protocol = void 0;
45
+ var agent_1 = require("@enbox/agent");
46
+ /**
47
+ * Encapsulates a DWN Protocol with its associated metadata and configuration.
48
+ *
49
+ * This class primarly exists to provide developers with a convenient way to configure/install
50
+ * protocols on remote DWNs.
51
+ */
52
+ var Protocol = /** @class */ (function () {
53
+ /**
54
+ * Constructs a new instance of the Protocol class.
55
+ *
56
+ * @param agent - The Web5Agent instance used for network interactions.
57
+ * @param protocolsConfigureMessage - The configuration message containing the protocol details.
58
+ * @param metadata - Metadata associated with the protocol, including the author and optional message CID.
59
+ */
60
+ function Protocol(agent, protocolsConfigureMessage, metadata) {
61
+ this._agent = agent;
62
+ this._metadata = metadata;
63
+ this._protocolsConfigureMessage = protocolsConfigureMessage;
64
+ }
65
+ Object.defineProperty(Protocol.prototype, "definition", {
66
+ /**
67
+ * Retrieves the protocol definition from the protocol's configuration message.
68
+ * @returns The protocol definition.
69
+ */
70
+ get: function () {
71
+ return this._protocolsConfigureMessage.descriptor.definition;
72
+ },
73
+ enumerable: false,
74
+ configurable: true
75
+ });
76
+ /**
77
+ * Serializes the protocol's configuration message to JSON.
78
+ * @returns The serialized JSON object of the protocol's configuration message.
79
+ */
80
+ Protocol.prototype.toJSON = function () {
81
+ return this._protocolsConfigureMessage;
82
+ };
83
+ /**
84
+ * Sends the protocol configuration to a remote DWN identified by the target DID.
85
+ *
86
+ * @param target - The DID of the target DWN to which the protocol configuration will be installed.
87
+ * @returns A promise that resolves to an object containing the status of the send operation.
88
+ */
89
+ Protocol.prototype.send = function (target) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var reply;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0: return [4 /*yield*/, this._agent.sendDwnRequest({
95
+ author: this._metadata.author,
96
+ messageCid: this._metadata.messageCid,
97
+ messageType: agent_1.DwnInterface.ProtocolsConfigure,
98
+ target: target,
99
+ })];
100
+ case 1:
101
+ reply = (_a.sent()).reply;
102
+ return [2 /*return*/, { status: reply.status }];
103
+ }
104
+ });
105
+ });
106
+ };
107
+ return Protocol;
108
+ }());
109
+ exports.Protocol = Protocol;
110
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;AACH,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI3C,sCAA4C;AAiB5C;;;;;GAKG;AACH;IAUE;;;;;;OAMG;IACH,kBAAY,KAAgB,EAAE,yBAAsE,EAAE,QAA0B;QAC9H,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,0BAA0B,GAAG,yBAAyB,CAAC;IAC9D,CAAC;IAMD,sBAAI,gCAAU;QAJd;;;WAGG;aACH;YACE,OAAO,IAAI,CAAC,0BAA0B,CAAC,UAAU,CAAC,UAAU,CAAC;QAC/D,CAAC;;;OAAA;IAED;;;OAGG;IACH,yBAAM,GAAN;QACE,OAAO,IAAI,CAAC,0BAA0B,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACG,uBAAI,GAAV,UAAW,MAAc;;;;;4BACL,qBAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;4BACjD,MAAM,EAAQ,IAAI,CAAC,SAAS,CAAC,MAAM;4BACnC,UAAU,EAAI,IAAI,CAAC,SAAS,CAAC,UAAU;4BACvC,WAAW,EAAG,oBAAY,CAAC,kBAAkB;4BAC7C,MAAM,EAAQ,MAAM;yBACrB,CAAC,EAAA;;wBALM,KAAK,GAAK,CAAA,SAKhB,CAAA,MALW;wBAOb,sBAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAC;;;;KACjC;IACH,eAAC;AAAD,CAAC,AAvDD,IAuDC;AAvDY,4BAAQ"}