@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
|
@@ -0,0 +1,109 @@
|
|
|
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 { AgentPermissionsApi, getRecordAuthor } from '@enbox/agent';
|
|
22
|
+
import { DwnInterface } from '@enbox/agent';
|
|
23
|
+
import { Convert } from '@enbox/common';
|
|
24
|
+
/**
|
|
25
|
+
* The `PermissionGrantRevocation` class encapsulates a permissions protocol `grant/revocation` record, providing a more
|
|
26
|
+
* developer-friendly interface for working with Decentralized Web Node (DWN) records.
|
|
27
|
+
*
|
|
28
|
+
* Methods are provided to manage the grant revocation's lifecycle, including writing to remote DWNs.
|
|
29
|
+
*
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export class PermissionGrantRevocation {
|
|
33
|
+
constructor(permissions, options) {
|
|
34
|
+
this._permissions = permissions;
|
|
35
|
+
this._connectedDid = options.connectedDid;
|
|
36
|
+
// Store the message that represents the grant.
|
|
37
|
+
this._message = options.message;
|
|
38
|
+
}
|
|
39
|
+
/** The author of the underlying revocation message */
|
|
40
|
+
get author() {
|
|
41
|
+
return getRecordAuthor(this._message);
|
|
42
|
+
}
|
|
43
|
+
/** parses the grant revocation given am agent, connectedDid and data encoded records write message */
|
|
44
|
+
static parse({ connectedDid, agent, message }) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const permissions = new AgentPermissionsApi({ agent });
|
|
47
|
+
return new PermissionGrantRevocation(permissions, { connectedDid, message });
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** The agent to use for this instantiation of the grant revocation */
|
|
51
|
+
get agent() {
|
|
52
|
+
return this._permissions.agent;
|
|
53
|
+
}
|
|
54
|
+
/** The raw `RecordsWrite` DWN message with encoded data that was used to instantiate this grant revocation */
|
|
55
|
+
get rawMessage() {
|
|
56
|
+
return this._message;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Send the current grant revocation to a remote DWN by specifying their DID
|
|
60
|
+
* If no DID is specified, the target is assumed to be the owner (connectedDID).
|
|
61
|
+
*
|
|
62
|
+
* @param target - the optional DID to send the grant revocation to, if none is set it is sent to the connectedDid
|
|
63
|
+
* @returns the status of the send grant revocation request
|
|
64
|
+
*
|
|
65
|
+
* @beta
|
|
66
|
+
*/
|
|
67
|
+
send(target) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
target !== null && target !== void 0 ? target : (target = this._connectedDid);
|
|
70
|
+
const _a = this._message, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
71
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
72
|
+
const sendRequestOptions = {
|
|
73
|
+
messageType: DwnInterface.RecordsWrite,
|
|
74
|
+
author: this._connectedDid,
|
|
75
|
+
target: target,
|
|
76
|
+
dataStream,
|
|
77
|
+
rawMessage,
|
|
78
|
+
};
|
|
79
|
+
// Send the current/latest state to the target.
|
|
80
|
+
const { reply } = yield this.agent.sendDwnRequest(sendRequestOptions);
|
|
81
|
+
return reply;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Stores the current grant revocation to the owner's DWN.
|
|
86
|
+
*
|
|
87
|
+
* @param importGrant - if true, the grant revocation will signed by the owner before storing it to the owner's DWN. Defaults to false.
|
|
88
|
+
* @returns the status of the store request
|
|
89
|
+
*
|
|
90
|
+
* @beta
|
|
91
|
+
*/
|
|
92
|
+
store(importRevocation) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const _a = this.rawMessage, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
95
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
96
|
+
const { reply, message } = yield this.agent.processDwnRequest({
|
|
97
|
+
author: this._connectedDid,
|
|
98
|
+
target: this._connectedDid,
|
|
99
|
+
messageType: DwnInterface.RecordsWrite,
|
|
100
|
+
signAsOwner: importRevocation,
|
|
101
|
+
rawMessage,
|
|
102
|
+
dataStream,
|
|
103
|
+
});
|
|
104
|
+
this._message = Object.assign(Object.assign({}, message), { encodedData: encodedData });
|
|
105
|
+
return { status: reply.status };
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=grant-revocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-revocation.js","sourceRoot":"","sources":["../../src/grant-revocation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAwD,eAAe,EAA6B,MAAM,cAAc,CAAC;AACrJ,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,e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MAAM,EAAQ,IAAI,CAAC,aAAa;gBAChC,MAAM,EAAQ,MAAM;gBACpB,UAAU;gBACV,UAAU;aACX,CAAC;YAEF,+CAA+C;YAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IAED;;;;;;;OAOG;IACG,KAAK,CAAC,gBAA0B;;YACpC,MAAM,KAAiC,IAAI,CAAC,UAAU,EAAhD,EAAE,WAAW,OAAmC,EAA9B,UAAU,cAA5B,eAA8B,CAAkB,CAAC;YACvD,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,CAAE,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,CAAE,CAAC,CAAC;YAE/E,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC;gBAC5D,MAAM,EAAQ,IAAI,CAAC,aAAa;gBAChC,MAAM,EAAQ,IAAI,CAAC,aAAa;gBAChC,WAAW,EAAG,YAAY,CAAC,YAAY;gBACvC,WAAW,EAAG,gBAAgB;gBAC9B,UAAU;gBACV,UAAU;aACX,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,mCAAQ,OAAO,KAAE,WAAW,EAAE,WAAW,GAAE,CAAC;YACzD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAClC,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Making developing with Web5 components at least 5 times easier to work with.
|
|
3
|
+
*
|
|
4
|
+
* Web5 consists of the following components:
|
|
5
|
+
* - Decentralized Identifiers
|
|
6
|
+
* - Verifiable Credentials
|
|
7
|
+
* - DWeb Node personal datastores
|
|
8
|
+
*
|
|
9
|
+
* The SDK sets out to gather the most oft used functionality from all three of
|
|
10
|
+
* these pillar technologies to provide a simple library that is as close to
|
|
11
|
+
* effortless as possible.
|
|
12
|
+
*
|
|
13
|
+
* The SDK is currently still under active development, but having entered the
|
|
14
|
+
* Tech Preview phase there is now a drive to avoid unnecessary changes unless
|
|
15
|
+
* backwards compatibility is provided. Additional functionality will be added
|
|
16
|
+
* in the lead up to 1.0 final, and modifications will be made to address
|
|
17
|
+
* issues and community feedback.
|
|
18
|
+
*
|
|
19
|
+
* [Link to GitHub Repo](https://github.com/TBD54566975/web5-js)
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
export * from './did-api.js';
|
|
24
|
+
export * from './dwn-api.js';
|
|
25
|
+
export * from './grant-revocation.js';
|
|
26
|
+
export * from './permission-grant.js';
|
|
27
|
+
export * from './permission-request.js';
|
|
28
|
+
export * from './protocol.js';
|
|
29
|
+
export * from './record.js';
|
|
30
|
+
export * from './vc-api.js';
|
|
31
|
+
export * from './web5.js';
|
|
32
|
+
import * as utils from './utils.js';
|
|
33
|
+
export { utils };
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAE1B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,233 @@
|
|
|
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 { Convert } from '@enbox/common';
|
|
22
|
+
import { AgentPermissionsApi, DwnInterface, DwnPermissionGrant, } from '@enbox/agent';
|
|
23
|
+
import { PermissionGrantRevocation } from './grant-revocation.js';
|
|
24
|
+
/**
|
|
25
|
+
* The `PermissionGrant` class encapsulates a permissions protocol `grant` record, providing a more
|
|
26
|
+
* developer-friendly interface for working with Decentralized Web Node (DWN) records.
|
|
27
|
+
*
|
|
28
|
+
* Methods are provided to revoke, check if isRevoked, and manage the grant's lifecycle, including writing to remote DWNs.
|
|
29
|
+
*
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export class PermissionGrant {
|
|
33
|
+
constructor({ api, connectedDid, message, grant }) {
|
|
34
|
+
this._permissions = api;
|
|
35
|
+
// Store the connected DID for convenience.
|
|
36
|
+
this._connectedDid = connectedDid;
|
|
37
|
+
// Store the message that represents the grant.
|
|
38
|
+
this._message = message;
|
|
39
|
+
// Store the parsed grant object.
|
|
40
|
+
this._grant = grant;
|
|
41
|
+
}
|
|
42
|
+
/** parses the grant given an agent, connectedDid and data encoded records write message */
|
|
43
|
+
static parse(options) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
//TODO: this does not have to be async https://github.com/TBD54566975/web5-js/pull/831/files
|
|
46
|
+
const grant = yield DwnPermissionGrant.parse(options.message);
|
|
47
|
+
const api = new AgentPermissionsApi({ agent: options.agent });
|
|
48
|
+
return new PermissionGrant(Object.assign(Object.assign({}, options), { grant, api }));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** The agent to use for this instantiation of the grant */
|
|
52
|
+
get agent() {
|
|
53
|
+
return this._permissions.agent;
|
|
54
|
+
}
|
|
55
|
+
/** The grant's ID, which is also the underlying record's ID */
|
|
56
|
+
get id() {
|
|
57
|
+
return this._grant.id;
|
|
58
|
+
}
|
|
59
|
+
/** The DID which granted the permission */
|
|
60
|
+
get grantor() {
|
|
61
|
+
return this._grant.grantor;
|
|
62
|
+
}
|
|
63
|
+
/** The DID which the permission was granted to */
|
|
64
|
+
get grantee() {
|
|
65
|
+
return this._grant.grantee;
|
|
66
|
+
}
|
|
67
|
+
/** The date the permission was granted */
|
|
68
|
+
get dateGranted() {
|
|
69
|
+
return this._grant.dateGranted;
|
|
70
|
+
}
|
|
71
|
+
/** (optional) Description of the permission grant */
|
|
72
|
+
get description() {
|
|
73
|
+
return this._grant.description;
|
|
74
|
+
}
|
|
75
|
+
/** (optional) The Id of the PermissionRequest if one was used */
|
|
76
|
+
get requestId() {
|
|
77
|
+
return this._grant.requestId;
|
|
78
|
+
}
|
|
79
|
+
/** The date on which the permission expires */
|
|
80
|
+
get dateExpires() {
|
|
81
|
+
return this._grant.dateExpires;
|
|
82
|
+
}
|
|
83
|
+
/** Whether or not the permission grant can be used to impersonate the grantor */
|
|
84
|
+
get delegated() {
|
|
85
|
+
return this._grant.delegated;
|
|
86
|
+
}
|
|
87
|
+
/** The permission scope under which the grant is valid */
|
|
88
|
+
get scope() {
|
|
89
|
+
return this._grant.scope;
|
|
90
|
+
}
|
|
91
|
+
/** The conditions under which the grant is valid */
|
|
92
|
+
get conditions() {
|
|
93
|
+
return this._grant.conditions;
|
|
94
|
+
}
|
|
95
|
+
/** The raw `RecordsWrite` DWN message with encoded data that was used to instantiate this grant */
|
|
96
|
+
get rawMessage() {
|
|
97
|
+
return this._message;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Send the current grant to a remote DWN by specifying their DID
|
|
101
|
+
* If no DID is specified, the target is assumed to be the owner (connectedDID).
|
|
102
|
+
*
|
|
103
|
+
* @param target - the optional DID to send the grant to, if none is set it is sent to the connectedDid
|
|
104
|
+
* @returns the status of the send grant request
|
|
105
|
+
*
|
|
106
|
+
* @beta
|
|
107
|
+
*/
|
|
108
|
+
send(target) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
target !== null && target !== void 0 ? target : (target = this._connectedDid);
|
|
111
|
+
const _a = this._message, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
112
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
113
|
+
const sendRequestOptions = {
|
|
114
|
+
messageType: DwnInterface.RecordsWrite,
|
|
115
|
+
author: this._connectedDid,
|
|
116
|
+
target: target,
|
|
117
|
+
dataStream,
|
|
118
|
+
rawMessage,
|
|
119
|
+
};
|
|
120
|
+
// Send the current/latest state to the target.
|
|
121
|
+
const { reply } = yield this.agent.sendDwnRequest(sendRequestOptions);
|
|
122
|
+
return reply;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Stores the current grant to the owner's DWN.
|
|
127
|
+
*
|
|
128
|
+
* @param importGrant - if true, the grant will signed by the owner before storing it to the owner's DWN. Defaults to false.
|
|
129
|
+
* @returns the status of the store request
|
|
130
|
+
*
|
|
131
|
+
* @beta
|
|
132
|
+
*/
|
|
133
|
+
store(importGrant = false) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const _a = this.rawMessage, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
136
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
137
|
+
const { reply, message } = yield this.agent.processDwnRequest({
|
|
138
|
+
store: true,
|
|
139
|
+
author: this._connectedDid,
|
|
140
|
+
target: this._connectedDid,
|
|
141
|
+
messageType: DwnInterface.RecordsWrite,
|
|
142
|
+
signAsOwner: importGrant,
|
|
143
|
+
rawMessage,
|
|
144
|
+
dataStream,
|
|
145
|
+
});
|
|
146
|
+
this._message = Object.assign(Object.assign({}, message), { encodedData: encodedData });
|
|
147
|
+
return { status: reply.status };
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Signs the current grant as the owner and optionally stores it to the owner's DWN.
|
|
152
|
+
* This is useful when importing a grant that was signed by someone else into your own DWN.
|
|
153
|
+
*
|
|
154
|
+
* @param store - if true, the grant will be stored to the owner's DWN after signing. Defaults to true.
|
|
155
|
+
* @returns the status of the import request
|
|
156
|
+
*
|
|
157
|
+
* @beta
|
|
158
|
+
*/
|
|
159
|
+
import(store = false) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const _a = this.rawMessage, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
162
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
163
|
+
const { reply, message } = yield this.agent.processDwnRequest({
|
|
164
|
+
store,
|
|
165
|
+
author: this._connectedDid,
|
|
166
|
+
target: this._connectedDid,
|
|
167
|
+
messageType: DwnInterface.RecordsWrite,
|
|
168
|
+
signAsOwner: true,
|
|
169
|
+
rawMessage,
|
|
170
|
+
dataStream,
|
|
171
|
+
});
|
|
172
|
+
this._message = Object.assign(Object.assign({}, message), { encodedData: encodedData });
|
|
173
|
+
return { status: reply.status };
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Revokes the grant and optionally stores the revocation to the owner's DWN.
|
|
178
|
+
*
|
|
179
|
+
* @param store - if true, the revocation will be stored to the owner's DWN. Defaults to true.
|
|
180
|
+
* @returns {PermissionGrantRevocation} the grant revocation object
|
|
181
|
+
*
|
|
182
|
+
* @beta
|
|
183
|
+
*/
|
|
184
|
+
revoke(store = true) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
const revocation = yield this._permissions.createRevocation({
|
|
187
|
+
store,
|
|
188
|
+
author: this._connectedDid,
|
|
189
|
+
grant: this._grant,
|
|
190
|
+
});
|
|
191
|
+
return PermissionGrantRevocation.parse({
|
|
192
|
+
connectedDid: this._connectedDid,
|
|
193
|
+
agent: this.agent,
|
|
194
|
+
message: revocation.message,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Checks if the grant has been revoked.
|
|
200
|
+
*
|
|
201
|
+
* @param remote - if true, the check will be made against the remote DWN. Defaults to false.
|
|
202
|
+
* @returns true if the grant has been revoked, false otherwise.
|
|
203
|
+
* @throws if there is an error checking the revocation status.
|
|
204
|
+
*
|
|
205
|
+
* @beta
|
|
206
|
+
*/
|
|
207
|
+
isRevoked(remote = false) {
|
|
208
|
+
return this._permissions.isGrantRevoked({
|
|
209
|
+
author: this._connectedDid,
|
|
210
|
+
target: this.grantor,
|
|
211
|
+
grantRecordId: this.id,
|
|
212
|
+
remote
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* @returns the JSON representation of the grant
|
|
217
|
+
*/
|
|
218
|
+
toJSON() {
|
|
219
|
+
return {
|
|
220
|
+
id: this.id,
|
|
221
|
+
grantor: this.grantor,
|
|
222
|
+
grantee: this.grantee,
|
|
223
|
+
dateGranted: this.dateGranted,
|
|
224
|
+
description: this.description,
|
|
225
|
+
requestId: this.requestId,
|
|
226
|
+
dateExpires: this.dateExpires,
|
|
227
|
+
delegated: this.delegated,
|
|
228
|
+
scope: this.scope,
|
|
229
|
+
conditions: this.conditions
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=permission-grant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-grant.js","sourceRoot":"","sources":["../../src/permission-grant.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AASA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAqElE;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IAU1B,YAAoB,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAKtD;QACC,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;IAC5F,MAAM,CAAO,KAAK,CAAC,OAA+B;;YAChD,4FAA4F;YAC5F,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC9D,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC9D,OAAO,IAAI,eAAe,iCAAM,OAAO,KAAE,KAAK,EAAE,GAAG,IAAG,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C/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;SACP,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,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;CACF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
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 { AgentPermissionsApi, DwnPermissionRequest } from '@enbox/agent';
|
|
22
|
+
import { DwnInterface } from '@enbox/agent';
|
|
23
|
+
import { Convert } from '@enbox/common';
|
|
24
|
+
import { PermissionGrant } from './permission-grant.js';
|
|
25
|
+
/**
|
|
26
|
+
* The `PermissionRequest` class encapsulates a permissions protocol `request` record, providing a more
|
|
27
|
+
* developer-friendly interface for working with Decentralized Web Node (DWN) records.
|
|
28
|
+
*
|
|
29
|
+
* Methods are provided to grant the request and manage the request's lifecycle, including writing to remote DWNs.
|
|
30
|
+
*
|
|
31
|
+
* @beta
|
|
32
|
+
*/
|
|
33
|
+
export class PermissionRequest {
|
|
34
|
+
constructor({ api, connectedDid, message, request }) {
|
|
35
|
+
this._permissions = api;
|
|
36
|
+
this._connectedDid = connectedDid;
|
|
37
|
+
// Store the parsed request object.
|
|
38
|
+
this._request = request;
|
|
39
|
+
// Store the message that represents the grant.
|
|
40
|
+
this._message = message;
|
|
41
|
+
}
|
|
42
|
+
/** parses the request given an agent, connectedDid and data encoded records write message */
|
|
43
|
+
static parse({ connectedDid, agent, message }) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
//TODO: this does not have to be async https://github.com/TBD54566975/web5-js/pull/831/files
|
|
46
|
+
const request = yield DwnPermissionRequest.parse(message);
|
|
47
|
+
const api = new AgentPermissionsApi({ agent });
|
|
48
|
+
return new PermissionRequest({ api, connectedDid, message, request });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** The agent to use for this instantiation of the request */
|
|
52
|
+
get agent() {
|
|
53
|
+
return this._permissions.agent;
|
|
54
|
+
}
|
|
55
|
+
/** The request's ID, which is also the underlying record's ID */
|
|
56
|
+
get id() {
|
|
57
|
+
return this._request.id;
|
|
58
|
+
}
|
|
59
|
+
/** The DID that is requesting a permission */
|
|
60
|
+
get requester() {
|
|
61
|
+
return this._request.requester;
|
|
62
|
+
}
|
|
63
|
+
/** (optional) Description of the permission request */
|
|
64
|
+
get description() {
|
|
65
|
+
return this._request.description;
|
|
66
|
+
}
|
|
67
|
+
/** Whether or not the permission request can be used to impersonate the grantor */
|
|
68
|
+
get delegated() {
|
|
69
|
+
return this._request.delegated;
|
|
70
|
+
}
|
|
71
|
+
/** The permission scope under which the requested grant would be valid */
|
|
72
|
+
get scope() {
|
|
73
|
+
return this._request.scope;
|
|
74
|
+
}
|
|
75
|
+
/** The conditions under which the requested grant would be valid */
|
|
76
|
+
get conditions() {
|
|
77
|
+
return this._request.conditions;
|
|
78
|
+
}
|
|
79
|
+
/** The `RecordsWrite` DWN message with encoded data that was used to instantiate this request */
|
|
80
|
+
get rawMessage() {
|
|
81
|
+
return this._message;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Send the current permission request to a remote DWN by specifying their DID
|
|
85
|
+
* If no DID is specified, the target is assumed to be the owner (connectedDID).
|
|
86
|
+
*
|
|
87
|
+
* @param target - the optional DID to send the permission request to, if none is set it is sent to the connectedDid
|
|
88
|
+
* @returns the status of the send permission request
|
|
89
|
+
*
|
|
90
|
+
* @beta
|
|
91
|
+
*/
|
|
92
|
+
send(target) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
target !== null && target !== void 0 ? target : (target = this._connectedDid);
|
|
95
|
+
const _a = this._message, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
96
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
97
|
+
const sendRequestOptions = {
|
|
98
|
+
messageType: DwnInterface.RecordsWrite,
|
|
99
|
+
author: this._connectedDid,
|
|
100
|
+
target: target,
|
|
101
|
+
dataStream,
|
|
102
|
+
rawMessage,
|
|
103
|
+
};
|
|
104
|
+
// Send the current/latest state to the target.
|
|
105
|
+
const { reply } = yield this.agent.sendDwnRequest(sendRequestOptions);
|
|
106
|
+
return reply;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Stores the current permission request to the owner's DWN.
|
|
111
|
+
*
|
|
112
|
+
* @param importGrant - if true, the permission request will signed by the owner before storing it to the owner's DWN. Defaults to false.
|
|
113
|
+
* @returns the status of the store request
|
|
114
|
+
*
|
|
115
|
+
* @beta
|
|
116
|
+
*/
|
|
117
|
+
store() {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const _a = this.rawMessage, { encodedData } = _a, rawMessage = __rest(_a, ["encodedData"]);
|
|
120
|
+
const dataStream = new Blob([Convert.base64Url(encodedData).toUint8Array()]);
|
|
121
|
+
const { reply, message } = yield this.agent.processDwnRequest({
|
|
122
|
+
author: this._connectedDid,
|
|
123
|
+
target: this._connectedDid,
|
|
124
|
+
messageType: DwnInterface.RecordsWrite,
|
|
125
|
+
rawMessage,
|
|
126
|
+
dataStream,
|
|
127
|
+
});
|
|
128
|
+
this._message = Object.assign(Object.assign({}, message), { encodedData: encodedData });
|
|
129
|
+
return { status: reply.status };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Grants the permission request to the requester.
|
|
134
|
+
*
|
|
135
|
+
* @param dateExpires - the date when the permission grant will expire.
|
|
136
|
+
* @param store - if true, the permission grant will be stored in the owner's DWN. Defaults to true.
|
|
137
|
+
* @returns {PermissionGrant} the granted permission.
|
|
138
|
+
*
|
|
139
|
+
* @beta
|
|
140
|
+
*/
|
|
141
|
+
grant(dateExpires, store = true) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const { message } = yield this._permissions.createGrant({
|
|
144
|
+
requestId: this.id,
|
|
145
|
+
grantedTo: this.requester,
|
|
146
|
+
scope: this.scope,
|
|
147
|
+
delegated: this.delegated,
|
|
148
|
+
author: this._connectedDid,
|
|
149
|
+
store,
|
|
150
|
+
dateExpires,
|
|
151
|
+
});
|
|
152
|
+
return PermissionGrant.parse({
|
|
153
|
+
connectedDid: this._connectedDid,
|
|
154
|
+
agent: this.agent,
|
|
155
|
+
message
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @returns the JSON representation of the permission request
|
|
161
|
+
*/
|
|
162
|
+
toJSON() {
|
|
163
|
+
return this._request;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=permission-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-request.js","sourceRoot":"","sources":["../../src/permission-request.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAA8D,oBAAoB,EAAoE,MAAM,cAAc,CAAC;AACvM,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAuCxD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAU5B,YAAoB,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAKxD;QACC,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAElC,mCAAmC;QACnC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,+CAA+C;QAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,8FAA8F;IAC9F,MAAM,CAAO,KAAK,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAIhD;;YACC,4FAA4F;YAC5F,MAAM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,SAAS,EAAG,IAAI,CAAC,EAAE;gBACnB,SAAS,EAAG,IAAI,CAAC,SAAS;gBAC1B,KAAK,EAAO,IAAI,CAAC,KAAK;gBACtB,SAAS,EAAG,IAAI,CAAC,SAAS;gBAC1B,MAAM,EAAM,IAAI,CAAC,aAAa;gBAC9B,KAAK;gBACL,WAAW;aACZ,CAAC,CAAC;YAEH,OAAO,eAAe,CAAC,KAAK,CAAC;gBAC3B,YAAY,EAAG,IAAI,CAAC,aAAa;gBACjC,KAAK,EAAU,IAAI,CAAC,KAAK;gBACzB,OAAO;aACR,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOTE: Added reference types here to avoid a `pnpm` bug during build.
|
|
3
|
+
* https://github.com/TBD54566975/web5-js/pull/507
|
|
4
|
+
*/
|
|
5
|
+
/// <reference types="@enbox/dwn-sdk-js" />
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
import { DwnInterface } from '@enbox/agent';
|
|
16
|
+
/**
|
|
17
|
+
* Encapsulates a DWN Protocol with its associated metadata and configuration.
|
|
18
|
+
*
|
|
19
|
+
* This class primarly exists to provide developers with a convenient way to configure/install
|
|
20
|
+
* protocols on remote DWNs.
|
|
21
|
+
*/
|
|
22
|
+
export class Protocol {
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new instance of the Protocol class.
|
|
25
|
+
*
|
|
26
|
+
* @param agent - The Web5Agent instance used for network interactions.
|
|
27
|
+
* @param protocolsConfigureMessage - The configuration message containing the protocol details.
|
|
28
|
+
* @param metadata - Metadata associated with the protocol, including the author and optional message CID.
|
|
29
|
+
*/
|
|
30
|
+
constructor(agent, protocolsConfigureMessage, metadata) {
|
|
31
|
+
this._agent = agent;
|
|
32
|
+
this._metadata = metadata;
|
|
33
|
+
this._protocolsConfigureMessage = protocolsConfigureMessage;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the protocol definition from the protocol's configuration message.
|
|
37
|
+
* @returns The protocol definition.
|
|
38
|
+
*/
|
|
39
|
+
get definition() {
|
|
40
|
+
return this._protocolsConfigureMessage.descriptor.definition;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serializes the protocol's configuration message to JSON.
|
|
44
|
+
* @returns The serialized JSON object of the protocol's configuration message.
|
|
45
|
+
*/
|
|
46
|
+
toJSON() {
|
|
47
|
+
return this._protocolsConfigureMessage;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sends the protocol configuration to a remote DWN identified by the target DID.
|
|
51
|
+
*
|
|
52
|
+
* @param target - The DID of the target DWN to which the protocol configuration will be installed.
|
|
53
|
+
* @returns A promise that resolves to an object containing the status of the send operation.
|
|
54
|
+
*/
|
|
55
|
+
send(target) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const { reply } = yield this._agent.sendDwnRequest({
|
|
58
|
+
author: this._metadata.author,
|
|
59
|
+
messageCid: this._metadata.messageCid,
|
|
60
|
+
messageType: DwnInterface.ProtocolsConfigure,
|
|
61
|
+
target: target,
|
|
62
|
+
});
|
|
63
|
+
return { status: reply.status };
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# 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,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAiB5C;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IAUnB;;;;;;OAMG;IACH,YAAY,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;IAED;;;OAGG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,0BAA0B,CAAC,UAAU,CAAC,UAAU,CAAC;IAC/D,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,0BAA0B,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACG,IAAI,CAAC,MAAc;;YACvB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;gBACjD,MAAM,EAAQ,IAAI,CAAC,SAAS,CAAC,MAAM;gBACnC,UAAU,EAAI,IAAI,CAAC,SAAS,CAAC,UAAU;gBACvC,WAAW,EAAG,YAAY,CAAC,kBAAkB;gBAC7C,MAAM,EAAQ,MAAM;aACrB,CAAC,CAAC;YAEH,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAClC,CAAC;KAAA;CACF"}
|