@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,573 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
16
|
+
var t = {};
|
|
17
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
18
|
+
t[p] = s[p];
|
|
19
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
20
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
21
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
22
|
+
t[p[i]] = s[p[i]];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
import { AgentPermissionsApi, } from '@enbox/agent';
|
|
27
|
+
import { isEmptyObject } from '@enbox/common';
|
|
28
|
+
import { DwnInterface, getRecordAuthor } from '@enbox/agent';
|
|
29
|
+
import { Record } from './record.js';
|
|
30
|
+
import { dataToBlob } from './utils.js';
|
|
31
|
+
import { Protocol } from './protocol.js';
|
|
32
|
+
import { PermissionGrant } from './permission-grant.js';
|
|
33
|
+
import { PermissionRequest } from './permission-request.js';
|
|
34
|
+
import { SubscriptionUtil } from './subscription-util.js';
|
|
35
|
+
/**
|
|
36
|
+
* Interface to interact with DWN Records and Protocols
|
|
37
|
+
*/
|
|
38
|
+
export class DwnApi {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.agent = options.agent;
|
|
41
|
+
this.connectedDid = options.connectedDid;
|
|
42
|
+
this.delegateDid = options.delegateDid;
|
|
43
|
+
this.permissionsApi = new AgentPermissionsApi({ agent: this.agent });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* API to interact with Grants
|
|
47
|
+
*
|
|
48
|
+
* NOTE: This is an EXPERIMENTAL API that will change behavior.
|
|
49
|
+
*
|
|
50
|
+
* Currently only supports issuing requests, grants, revokes and queries on behalf without permissions or impersonation.
|
|
51
|
+
* If the agent is connected to a delegateDid, the delegateDid will be used to sign/author the underlying records.
|
|
52
|
+
* If the agent is not connected to a delegateDid, the connectedDid will be used to sign/author the underlying records.
|
|
53
|
+
*
|
|
54
|
+
* @beta
|
|
55
|
+
*/
|
|
56
|
+
get permissions() {
|
|
57
|
+
return {
|
|
58
|
+
/**
|
|
59
|
+
* Request permission for a specific scope.
|
|
60
|
+
*/
|
|
61
|
+
request: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
const { message } = yield this.permissionsApi.createRequest(Object.assign(Object.assign({}, request), { author: (_a = this.delegateDid) !== null && _a !== void 0 ? _a : this.connectedDid }));
|
|
64
|
+
const requestParams = {
|
|
65
|
+
connectedDid: (_b = this.delegateDid) !== null && _b !== void 0 ? _b : this.connectedDid,
|
|
66
|
+
agent: this.agent,
|
|
67
|
+
message,
|
|
68
|
+
};
|
|
69
|
+
return yield PermissionRequest.parse(requestParams);
|
|
70
|
+
}),
|
|
71
|
+
/**
|
|
72
|
+
* Grant permission for a specific scope to a grantee DID.
|
|
73
|
+
*/
|
|
74
|
+
grant: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
var _c, _d;
|
|
76
|
+
const { message } = yield this.permissionsApi.createGrant(Object.assign(Object.assign({}, request), { author: (_c = this.delegateDid) !== null && _c !== void 0 ? _c : this.connectedDid }));
|
|
77
|
+
const grantParams = {
|
|
78
|
+
connectedDid: (_d = this.delegateDid) !== null && _d !== void 0 ? _d : this.connectedDid,
|
|
79
|
+
agent: this.agent,
|
|
80
|
+
message,
|
|
81
|
+
};
|
|
82
|
+
return yield PermissionGrant.parse(grantParams);
|
|
83
|
+
}),
|
|
84
|
+
/**
|
|
85
|
+
* Query permission requests. You can filter by protocol and specify if you want to query a remote DWN.
|
|
86
|
+
*/
|
|
87
|
+
queryRequests: (request = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
var _e, _f, _g;
|
|
89
|
+
const { from } = request, params = __rest(request, ["from"]);
|
|
90
|
+
const fetchResponse = yield this.permissionsApi.fetchRequests(Object.assign(Object.assign({}, params), { author: (_e = this.delegateDid) !== null && _e !== void 0 ? _e : this.connectedDid, target: (_f = from !== null && from !== void 0 ? from : this.delegateDid) !== null && _f !== void 0 ? _f : this.connectedDid, remote: from !== undefined }));
|
|
91
|
+
const requests = [];
|
|
92
|
+
for (const permission of fetchResponse) {
|
|
93
|
+
const requestParams = {
|
|
94
|
+
connectedDid: (_g = this.delegateDid) !== null && _g !== void 0 ? _g : this.connectedDid,
|
|
95
|
+
agent: this.agent,
|
|
96
|
+
message: permission.message,
|
|
97
|
+
};
|
|
98
|
+
requests.push(yield PermissionRequest.parse(requestParams));
|
|
99
|
+
}
|
|
100
|
+
return requests;
|
|
101
|
+
}),
|
|
102
|
+
/**
|
|
103
|
+
* Query permission grants. You can filter by grantee, grantor, protocol and specify if you want to query a remote DWN.
|
|
104
|
+
*/
|
|
105
|
+
queryGrants: (request = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
var _h, _j, _k;
|
|
107
|
+
const { checkRevoked, from } = request, params = __rest(request, ["checkRevoked", "from"]);
|
|
108
|
+
const remote = from !== undefined;
|
|
109
|
+
const author = (_h = this.delegateDid) !== null && _h !== void 0 ? _h : this.connectedDid;
|
|
110
|
+
const target = (_j = from !== null && from !== void 0 ? from : this.delegateDid) !== null && _j !== void 0 ? _j : this.connectedDid;
|
|
111
|
+
const fetchResponse = yield this.permissionsApi.fetchGrants(Object.assign(Object.assign({}, params), { author,
|
|
112
|
+
target,
|
|
113
|
+
remote }));
|
|
114
|
+
const grants = [];
|
|
115
|
+
for (const permission of fetchResponse) {
|
|
116
|
+
const grantParams = {
|
|
117
|
+
connectedDid: (_k = this.delegateDid) !== null && _k !== void 0 ? _k : this.connectedDid,
|
|
118
|
+
agent: this.agent,
|
|
119
|
+
message: permission.message,
|
|
120
|
+
};
|
|
121
|
+
if (checkRevoked) {
|
|
122
|
+
const grantRecordId = permission.grant.id;
|
|
123
|
+
if (yield this.permissionsApi.isGrantRevoked({ author, target, grantRecordId, remote })) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
grants.push(yield PermissionGrant.parse(grantParams));
|
|
128
|
+
}
|
|
129
|
+
return grants;
|
|
130
|
+
})
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* API to interact with DWN protocols (e.g., `dwn.protocols.configure()`).
|
|
135
|
+
*/
|
|
136
|
+
get protocols() {
|
|
137
|
+
return {
|
|
138
|
+
/**
|
|
139
|
+
* Configure method, used to setup a new protocol (or update) with the passed definitions
|
|
140
|
+
*/
|
|
141
|
+
configure: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const agentRequest = {
|
|
143
|
+
author: this.connectedDid,
|
|
144
|
+
messageParams: request.message,
|
|
145
|
+
messageType: DwnInterface.ProtocolsConfigure,
|
|
146
|
+
target: this.connectedDid
|
|
147
|
+
};
|
|
148
|
+
if (this.delegateDid) {
|
|
149
|
+
const { message: delegatedGrant } = yield this.permissionsApi.getPermissionForRequest({
|
|
150
|
+
connectedDid: this.connectedDid,
|
|
151
|
+
delegateDid: this.delegateDid,
|
|
152
|
+
protocol: request.message.definition.protocol,
|
|
153
|
+
delegate: true,
|
|
154
|
+
cached: true,
|
|
155
|
+
messageType: agentRequest.messageType
|
|
156
|
+
});
|
|
157
|
+
agentRequest.messageParams = Object.assign(Object.assign({}, agentRequest.messageParams), { delegatedGrant });
|
|
158
|
+
agentRequest.granteeDid = this.delegateDid;
|
|
159
|
+
}
|
|
160
|
+
const agentResponse = yield this.agent.processDwnRequest(agentRequest);
|
|
161
|
+
const { message, messageCid, reply: { status } } = agentResponse;
|
|
162
|
+
const response = { status };
|
|
163
|
+
if (status.code < 300) {
|
|
164
|
+
const metadata = { author: this.connectedDid, messageCid };
|
|
165
|
+
response.protocol = new Protocol(this.agent, message, metadata);
|
|
166
|
+
}
|
|
167
|
+
return response;
|
|
168
|
+
}),
|
|
169
|
+
/**
|
|
170
|
+
* Query the available protocols
|
|
171
|
+
*/
|
|
172
|
+
query: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const agentRequest = {
|
|
174
|
+
author: this.connectedDid,
|
|
175
|
+
messageParams: request.message,
|
|
176
|
+
messageType: DwnInterface.ProtocolsQuery,
|
|
177
|
+
target: request.from || this.connectedDid
|
|
178
|
+
};
|
|
179
|
+
if (this.delegateDid) {
|
|
180
|
+
// We attempt to get a grant within a try catch, if there is no grant we will still sign the query with the delegate DID's key
|
|
181
|
+
// If the protocol is public, the query should be successful. This allows the app to query for public protocols without having a grant.
|
|
182
|
+
try {
|
|
183
|
+
const { grant: { id: permissionGrantId } } = yield this.permissionsApi.getPermissionForRequest({
|
|
184
|
+
connectedDid: this.connectedDid,
|
|
185
|
+
delegateDid: this.delegateDid,
|
|
186
|
+
protocol: request.message.filter.protocol,
|
|
187
|
+
cached: true,
|
|
188
|
+
messageType: agentRequest.messageType
|
|
189
|
+
});
|
|
190
|
+
agentRequest.messageParams = Object.assign(Object.assign({}, agentRequest.messageParams), { permissionGrantId });
|
|
191
|
+
agentRequest.granteeDid = this.delegateDid;
|
|
192
|
+
}
|
|
193
|
+
catch (_error) {
|
|
194
|
+
// if a grant is not found, we should author the request as the delegated DID to get public protocols
|
|
195
|
+
agentRequest.author = this.delegateDid;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
let agentResponse;
|
|
199
|
+
if (request.from) {
|
|
200
|
+
agentResponse = yield this.agent.sendDwnRequest(agentRequest);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
agentResponse = yield this.agent.processDwnRequest(agentRequest);
|
|
204
|
+
}
|
|
205
|
+
const reply = agentResponse.reply;
|
|
206
|
+
const { entries = [], status } = reply;
|
|
207
|
+
const protocols = entries.map((entry) => {
|
|
208
|
+
const metadata = { author: this.connectedDid };
|
|
209
|
+
return new Protocol(this.agent, entry, metadata);
|
|
210
|
+
});
|
|
211
|
+
return { protocols, status };
|
|
212
|
+
})
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* API to interact with DWN records (e.g., `dwn.records.create()`).
|
|
217
|
+
*/
|
|
218
|
+
get records() {
|
|
219
|
+
return {
|
|
220
|
+
/**
|
|
221
|
+
* Alias for the `write` method
|
|
222
|
+
*/
|
|
223
|
+
create: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
return this.records.write(request);
|
|
225
|
+
}),
|
|
226
|
+
/**
|
|
227
|
+
* Write a record based on an existing one (useful for updating an existing record)
|
|
228
|
+
*/
|
|
229
|
+
createFrom: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
var _a;
|
|
231
|
+
const _b = request.record.toJSON(), { author: inheritedAuthor } = _b, inheritedProperties = __rest(_b, ["author"]);
|
|
232
|
+
// If `data` is being updated then `dataCid` and `dataSize` must not be present.
|
|
233
|
+
if (request.data !== undefined) {
|
|
234
|
+
delete inheritedProperties.dataCid;
|
|
235
|
+
delete inheritedProperties.dataSize;
|
|
236
|
+
}
|
|
237
|
+
// If `published` is set to false, ensure that `datePublished` is undefined. Otherwise, DWN SDK's schema validation
|
|
238
|
+
// will throw an error if `published` is false but `datePublished` is set.
|
|
239
|
+
if (((_a = request.message) === null || _a === void 0 ? void 0 : _a.published) === false && inheritedProperties.datePublished !== undefined) {
|
|
240
|
+
delete inheritedProperties.datePublished;
|
|
241
|
+
delete inheritedProperties.published;
|
|
242
|
+
}
|
|
243
|
+
// If the request changes the `author` or message `descriptor` then the deterministic `recordId` will change.
|
|
244
|
+
// As a result, we will discard the `recordId` if either of these changes occur.
|
|
245
|
+
if (!isEmptyObject(request.message) || (request.author && request.author !== inheritedAuthor)) {
|
|
246
|
+
delete inheritedProperties.recordId;
|
|
247
|
+
}
|
|
248
|
+
return this.records.write({
|
|
249
|
+
data: request.data,
|
|
250
|
+
message: Object.assign(Object.assign({}, inheritedProperties), request.message),
|
|
251
|
+
});
|
|
252
|
+
}),
|
|
253
|
+
/**
|
|
254
|
+
* Delete a record
|
|
255
|
+
*/
|
|
256
|
+
delete: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const agentRequest = {
|
|
258
|
+
/**
|
|
259
|
+
* The `author` is the DID that will sign the message and must be the DID the Web5 app is
|
|
260
|
+
* connected with and is authorized to access the signing private key of.
|
|
261
|
+
*/
|
|
262
|
+
author: this.connectedDid,
|
|
263
|
+
messageParams: request.message,
|
|
264
|
+
messageType: DwnInterface.RecordsDelete,
|
|
265
|
+
/**
|
|
266
|
+
* The `target` is the DID of the DWN tenant under which the delete will be executed.
|
|
267
|
+
* If `from` is provided, the delete operation will be executed on a remote DWN.
|
|
268
|
+
* Otherwise, the record will be deleted on the local DWN.
|
|
269
|
+
*/
|
|
270
|
+
target: request.from || this.connectedDid
|
|
271
|
+
};
|
|
272
|
+
if (this.delegateDid) {
|
|
273
|
+
const { message: delegatedGrant } = yield this.permissionsApi.getPermissionForRequest({
|
|
274
|
+
connectedDid: this.connectedDid,
|
|
275
|
+
delegateDid: this.delegateDid,
|
|
276
|
+
protocol: request.protocol,
|
|
277
|
+
delegate: true,
|
|
278
|
+
cached: true,
|
|
279
|
+
messageType: agentRequest.messageType
|
|
280
|
+
});
|
|
281
|
+
agentRequest.messageParams = Object.assign(Object.assign({}, agentRequest.messageParams), { delegatedGrant });
|
|
282
|
+
agentRequest.granteeDid = this.delegateDid;
|
|
283
|
+
}
|
|
284
|
+
let agentResponse;
|
|
285
|
+
if (request.from) {
|
|
286
|
+
agentResponse = yield this.agent.sendDwnRequest(agentRequest);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
agentResponse = yield this.agent.processDwnRequest(agentRequest);
|
|
290
|
+
}
|
|
291
|
+
const { reply: { status } } = agentResponse;
|
|
292
|
+
return { status };
|
|
293
|
+
}),
|
|
294
|
+
/**
|
|
295
|
+
* Query a single or multiple records based on the given filter
|
|
296
|
+
*/
|
|
297
|
+
query: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
const agentRequest = {
|
|
299
|
+
/**
|
|
300
|
+
* The `author` is the DID that will sign the message and must be the DID the Web5 app is
|
|
301
|
+
* connected with and is authorized to access the signing private key of.
|
|
302
|
+
*/
|
|
303
|
+
author: this.connectedDid,
|
|
304
|
+
messageParams: request.message,
|
|
305
|
+
messageType: DwnInterface.RecordsQuery,
|
|
306
|
+
/**
|
|
307
|
+
* The `target` is the DID of the DWN tenant under which the query will be executed.
|
|
308
|
+
* If `from` is provided, the query operation will be executed on a remote DWN.
|
|
309
|
+
* Otherwise, the local DWN will be queried.
|
|
310
|
+
*/
|
|
311
|
+
target: request.from || this.connectedDid
|
|
312
|
+
};
|
|
313
|
+
if (this.delegateDid) {
|
|
314
|
+
// if we don't find a delegated grant, we will attempt to query signing as the delegated DID
|
|
315
|
+
// This is to allow the API caller to query public records without needing to impersonate the delegate.
|
|
316
|
+
//
|
|
317
|
+
// NOTE: When a read-only DwnApi is implemented, callers should use that instead when they don't have an explicit permission.
|
|
318
|
+
// This should fail if a permission is not found.
|
|
319
|
+
// TODO: https://github.com/TBD54566975/web5-js/issues/898
|
|
320
|
+
try {
|
|
321
|
+
const { message: delegatedGrant } = yield this.permissionsApi.getPermissionForRequest({
|
|
322
|
+
connectedDid: this.connectedDid,
|
|
323
|
+
delegateDid: this.delegateDid,
|
|
324
|
+
protocol: request.protocol,
|
|
325
|
+
delegate: true,
|
|
326
|
+
cached: true,
|
|
327
|
+
messageType: agentRequest.messageType
|
|
328
|
+
});
|
|
329
|
+
agentRequest.messageParams = Object.assign(Object.assign({}, agentRequest.messageParams), { delegatedGrant });
|
|
330
|
+
agentRequest.granteeDid = this.delegateDid;
|
|
331
|
+
}
|
|
332
|
+
catch (_error) {
|
|
333
|
+
// if a grant is not found, we should author the request as the delegated DID to get public records
|
|
334
|
+
agentRequest.author = this.delegateDid;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
let agentResponse;
|
|
338
|
+
if (request.from) {
|
|
339
|
+
agentResponse = yield this.agent.sendDwnRequest(agentRequest);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
agentResponse = yield this.agent.processDwnRequest(agentRequest);
|
|
343
|
+
}
|
|
344
|
+
const reply = agentResponse.reply;
|
|
345
|
+
const { entries = [], status, cursor } = reply;
|
|
346
|
+
const records = entries.map((entry) => {
|
|
347
|
+
const recordOptions = Object.assign({
|
|
348
|
+
/**
|
|
349
|
+
* Extract the `author` DID from the record entry since records may be signed by the
|
|
350
|
+
* tenant owner or any other entity.
|
|
351
|
+
*/
|
|
352
|
+
author: getRecordAuthor(entry),
|
|
353
|
+
/**
|
|
354
|
+
* Set the `connectedDid` to currently connected DID so that subsequent calls to
|
|
355
|
+
* {@link Record} instance methods, such as `record.update()` are executed on the
|
|
356
|
+
* local DWN even if the record was returned by a query of a remote DWN.
|
|
357
|
+
*/
|
|
358
|
+
connectedDid: this.connectedDid,
|
|
359
|
+
/**
|
|
360
|
+
* If the record was returned by a query of a remote DWN, set the `remoteOrigin` to
|
|
361
|
+
* the DID of the DWN that returned the record. The `remoteOrigin` property will be used
|
|
362
|
+
* to determine which DWN to send subsequent read requests to in the event the data
|
|
363
|
+
* payload exceeds the threshold for being returned with queries.
|
|
364
|
+
*/
|
|
365
|
+
remoteOrigin: request.from, delegateDid: this.delegateDid, protocolRole: agentRequest.messageParams.protocolRole }, entry);
|
|
366
|
+
const record = new Record(this.agent, recordOptions, this.permissionsApi);
|
|
367
|
+
return record;
|
|
368
|
+
});
|
|
369
|
+
return { records, status, cursor };
|
|
370
|
+
}),
|
|
371
|
+
/**
|
|
372
|
+
* Read a single record based on the given filter
|
|
373
|
+
*/
|
|
374
|
+
read: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
375
|
+
const agentRequest = {
|
|
376
|
+
/**
|
|
377
|
+
* The `author` is the DID that will sign the message and must be the DID the Web5 app is
|
|
378
|
+
* connected with and is authorized to access the signing private key of.
|
|
379
|
+
*/
|
|
380
|
+
author: this.connectedDid,
|
|
381
|
+
messageParams: request.message,
|
|
382
|
+
messageType: DwnInterface.RecordsRead,
|
|
383
|
+
/**
|
|
384
|
+
* The `target` is the DID of the DWN tenant under which the read will be executed.
|
|
385
|
+
* If `from` is provided, the read operation will be executed on a remote DWN.
|
|
386
|
+
* Otherwise, the read will occur on the local DWN.
|
|
387
|
+
*/
|
|
388
|
+
target: request.from || this.connectedDid
|
|
389
|
+
};
|
|
390
|
+
if (this.delegateDid) {
|
|
391
|
+
// if we don't find a delegated grant, we will attempt to read signing as the delegated DID
|
|
392
|
+
// This is to allow the API caller to read public records without needing to impersonate the delegate.
|
|
393
|
+
//
|
|
394
|
+
// NOTE: When a read-only DwnApi is implemented, callers should use that instead when they don't have an explicit permission.
|
|
395
|
+
// This should fail if a permission is not found.
|
|
396
|
+
// TODO: https://github.com/TBD54566975/web5-js/issues/898
|
|
397
|
+
try {
|
|
398
|
+
const { message: delegatedGrant } = yield this.permissionsApi.getPermissionForRequest({
|
|
399
|
+
connectedDid: this.connectedDid,
|
|
400
|
+
delegateDid: this.delegateDid,
|
|
401
|
+
protocol: request.protocol,
|
|
402
|
+
delegate: true,
|
|
403
|
+
cached: true,
|
|
404
|
+
messageType: agentRequest.messageType
|
|
405
|
+
});
|
|
406
|
+
agentRequest.messageParams = Object.assign(Object.assign({}, agentRequest.messageParams), { delegatedGrant });
|
|
407
|
+
agentRequest.granteeDid = this.delegateDid;
|
|
408
|
+
}
|
|
409
|
+
catch (_error) {
|
|
410
|
+
// if a grant is not found, we should author the request as the delegated DID to get public records
|
|
411
|
+
agentRequest.author = this.delegateDid;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
let agentResponse;
|
|
415
|
+
if (request.from) {
|
|
416
|
+
agentResponse = yield this.agent.sendDwnRequest(agentRequest);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
agentResponse = yield this.agent.processDwnRequest(agentRequest);
|
|
420
|
+
}
|
|
421
|
+
const { reply: { entry, status } } = agentResponse;
|
|
422
|
+
let record;
|
|
423
|
+
if (200 <= status.code && status.code <= 299) {
|
|
424
|
+
const recordOptions = Object.assign({
|
|
425
|
+
/**
|
|
426
|
+
* Extract the `author` DID from the record since records may be signed by the
|
|
427
|
+
* tenant owner or any other entity.
|
|
428
|
+
*/
|
|
429
|
+
author: getRecordAuthor(entry.recordsWrite),
|
|
430
|
+
/**
|
|
431
|
+
* Set the `connectedDid` to currently connected DID so that subsequent calls to
|
|
432
|
+
* {@link Record} instance methods, such as `record.update()` are executed on the
|
|
433
|
+
* local DWN even if the record was read from a remote DWN.
|
|
434
|
+
*/
|
|
435
|
+
connectedDid: this.connectedDid,
|
|
436
|
+
/**
|
|
437
|
+
* If the record was returned by reading from a remote DWN, set the `remoteOrigin` to
|
|
438
|
+
* the DID of the DWN that returned the record. The `remoteOrigin` property will be used
|
|
439
|
+
* to determine which DWN to send subsequent read requests to in the event the data
|
|
440
|
+
* payload must be read again (e.g., if the data stream is consumed).
|
|
441
|
+
*/
|
|
442
|
+
remoteOrigin: request.from, delegateDid: this.delegateDid, data: entry.data, initialWrite: entry.initialWrite }, entry.recordsWrite);
|
|
443
|
+
record = new Record(this.agent, recordOptions, this.permissionsApi);
|
|
444
|
+
}
|
|
445
|
+
return { record, status };
|
|
446
|
+
}),
|
|
447
|
+
/**
|
|
448
|
+
* Subscribes to records based on the given filter and emits events to the `subscriptionHandler`.
|
|
449
|
+
*
|
|
450
|
+
* @param request must include the `message` with the subscription filter and the `subscriptionHandler` to process the events.
|
|
451
|
+
* @returns the subscription status and the subscription object used to close the subscription.
|
|
452
|
+
*/
|
|
453
|
+
subscribe: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
const agentRequest = {
|
|
455
|
+
/**
|
|
456
|
+
* The `author` is the DID that will sign the message and must be the DID the Web5 app is
|
|
457
|
+
* connected with and is authorized to access the signing private key of.
|
|
458
|
+
*/
|
|
459
|
+
author: this.connectedDid,
|
|
460
|
+
messageParams: request.message,
|
|
461
|
+
messageType: DwnInterface.RecordsSubscribe,
|
|
462
|
+
/**
|
|
463
|
+
* The `target` is the DID of the DWN tenant under which the subscribe operation will be executed.
|
|
464
|
+
* If `from` is provided, the subscribe operation will be executed on a remote DWN.
|
|
465
|
+
* Otherwise, the local DWN will execute the subscribe operation.
|
|
466
|
+
*/
|
|
467
|
+
target: request.from || this.connectedDid,
|
|
468
|
+
/**
|
|
469
|
+
* The handler to process the subscription events.
|
|
470
|
+
*/
|
|
471
|
+
subscriptionHandler: SubscriptionUtil.recordSubscriptionHandler({
|
|
472
|
+
agent: this.agent,
|
|
473
|
+
connectedDid: this.connectedDid,
|
|
474
|
+
delegateDid: this.delegateDid,
|
|
475
|
+
permissionsApi: this.permissionsApi,
|
|
476
|
+
protocolRole: request.message.protocolRole,
|
|
477
|
+
request
|
|
478
|
+
})
|
|
479
|
+
};
|
|
480
|
+
if (this.delegateDid) {
|
|
481
|
+
// if we don't find a delegated grant, we will attempt to subscribe signing as the delegated DID
|
|
482
|
+
// This is to allow the API caller to subscribe to public records without needing to impersonate the delegate.
|
|
483
|
+
//
|
|
484
|
+
// NOTE: When a read-only DwnApi is implemented, callers should use that instead when they don't have an explicit permission.
|
|
485
|
+
// This should fail if a permission is not found.
|
|
486
|
+
// TODO: https://github.com/TBD54566975/web5-js/issues/898
|
|
487
|
+
try {
|
|
488
|
+
const { message: delegatedGrant } = yield this.permissionsApi.getPermissionForRequest({
|
|
489
|
+
connectedDid: this.connectedDid,
|
|
490
|
+
delegateDid: this.delegateDid,
|
|
491
|
+
protocol: request.protocol,
|
|
492
|
+
delegate: true,
|
|
493
|
+
cached: true,
|
|
494
|
+
messageType: agentRequest.messageType
|
|
495
|
+
});
|
|
496
|
+
agentRequest.messageParams = Object.assign(Object.assign({}, agentRequest.messageParams), { delegatedGrant });
|
|
497
|
+
agentRequest.granteeDid = this.delegateDid;
|
|
498
|
+
}
|
|
499
|
+
catch (_error) {
|
|
500
|
+
// if a grant is not found, we should author the request as the delegated DID to get public records
|
|
501
|
+
agentRequest.author = this.delegateDid;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
;
|
|
505
|
+
let agentResponse;
|
|
506
|
+
if (request.from) {
|
|
507
|
+
agentResponse = yield this.agent.sendDwnRequest(agentRequest);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
agentResponse = yield this.agent.processDwnRequest(agentRequest);
|
|
511
|
+
}
|
|
512
|
+
const reply = agentResponse.reply;
|
|
513
|
+
const { status, subscription } = reply;
|
|
514
|
+
return { status, subscription };
|
|
515
|
+
}),
|
|
516
|
+
/**
|
|
517
|
+
* Writes a record to the DWN
|
|
518
|
+
*
|
|
519
|
+
* As a convenience, the Record instance returned will cache a copy of the data. This is done
|
|
520
|
+
* to maintain consistency with other DWN methods, like RecordsQuery, that include relatively
|
|
521
|
+
* small data payloads when returning RecordsWrite message properties. Regardless of data
|
|
522
|
+
* size, methods such as `record.data.stream()` will return the data when called even if it
|
|
523
|
+
* requires fetching from the DWN datastore.
|
|
524
|
+
*/
|
|
525
|
+
write: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
526
|
+
var _c;
|
|
527
|
+
const { dataBlob, dataFormat } = dataToBlob(request.data, (_c = request.message) === null || _c === void 0 ? void 0 : _c.dataFormat);
|
|
528
|
+
const dwnRequestParams = {
|
|
529
|
+
store: request.store,
|
|
530
|
+
messageType: DwnInterface.RecordsWrite,
|
|
531
|
+
messageParams: Object.assign(Object.assign({}, request.message), { dataFormat }),
|
|
532
|
+
author: this.connectedDid,
|
|
533
|
+
target: this.connectedDid,
|
|
534
|
+
dataStream: dataBlob
|
|
535
|
+
};
|
|
536
|
+
// if impersonation is enabled, fetch the delegated grant to use with the write operation
|
|
537
|
+
if (this.delegateDid) {
|
|
538
|
+
const { message: delegatedGrant } = yield this.permissionsApi.getPermissionForRequest({
|
|
539
|
+
connectedDid: this.connectedDid,
|
|
540
|
+
delegateDid: this.delegateDid,
|
|
541
|
+
protocol: request.message.protocol,
|
|
542
|
+
delegate: true,
|
|
543
|
+
cached: true,
|
|
544
|
+
messageType: dwnRequestParams.messageType
|
|
545
|
+
});
|
|
546
|
+
dwnRequestParams.messageParams = Object.assign(Object.assign({}, dwnRequestParams.messageParams), { delegatedGrant });
|
|
547
|
+
dwnRequestParams.granteeDid = this.delegateDid;
|
|
548
|
+
}
|
|
549
|
+
;
|
|
550
|
+
const agentResponse = yield this.agent.processDwnRequest(dwnRequestParams);
|
|
551
|
+
const { message: responseMessage, reply: { status } } = agentResponse;
|
|
552
|
+
let record;
|
|
553
|
+
if (200 <= status.code && status.code <= 299) {
|
|
554
|
+
const recordOptions = Object.assign({
|
|
555
|
+
/**
|
|
556
|
+
* Assume the author is the connected DID since the record was just written to the
|
|
557
|
+
* local DWN.
|
|
558
|
+
*/
|
|
559
|
+
author: this.connectedDid,
|
|
560
|
+
/**
|
|
561
|
+
* Set the `connectedDid` to currently connected DID so that subsequent calls to
|
|
562
|
+
* {@link Record} instance methods, such as `record.update()` are executed on the
|
|
563
|
+
* local DWN.
|
|
564
|
+
*/
|
|
565
|
+
connectedDid: this.connectedDid, encodedData: dataBlob, delegateDid: this.delegateDid }, responseMessage);
|
|
566
|
+
record = new Record(this.agent, recordOptions, this.permissionsApi);
|
|
567
|
+
}
|
|
568
|
+
return { record, status };
|
|
569
|
+
}),
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
//# sourceMappingURL=dwn-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-api.js","sourceRoot":"","sources":["../../src/dwn-api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,2CAA2C;;;;;;;;;;;;;;;;;;;;;AAS3C,OAAO,EASL,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA6P1D;;GAEG;AACH,MAAM,OAAO,MAAM;IAgBjB,YAAY,OAAyE;QACnF,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;;;;;OAUG;IACH,IAAI,WAAW;QACb,OAAO;YACL;;eA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