@atcute/did-plc 0.3.0 → 0.3.2
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/dist/client.d.ts +19 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +63 -17
- package/dist/client.js.map +1 -1
- package/dist/data.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/typedefs.d.ts +1 -1
- package/dist/typedefs.d.ts.map +1 -1
- package/dist/typedefs.js +1 -1
- package/dist/typedefs.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/client.ts +74 -19
- package/lib/data.ts +4 -4
- package/lib/errors.ts +1 -1
- package/lib/index.ts +7 -7
- package/lib/typedefs.ts +3 -3
- package/lib/utils.ts +2 -2
- package/package.json +17 -16
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import type { DidDocument } from '@atcute/identity';
|
|
2
|
-
import * as t from './types.
|
|
2
|
+
import * as t from './types.ts';
|
|
3
|
+
export interface PlcErrorBody {
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* error thrown when the plc server returns a non-ok response
|
|
8
|
+
*/
|
|
9
|
+
export declare class PlcClientError extends Error {
|
|
10
|
+
status: number;
|
|
11
|
+
body: PlcErrorBody | null;
|
|
12
|
+
readonly name = "PlcClientError";
|
|
13
|
+
constructor(status: number, body: PlcErrorBody | null, message: string);
|
|
14
|
+
/**
|
|
15
|
+
* creates a PlcClientError from a failed fetch response
|
|
16
|
+
* @param response the failed response
|
|
17
|
+
* @returns the error with parsed body if available
|
|
18
|
+
*/
|
|
19
|
+
static fromResponse(response: Response): Promise<PlcClientError>;
|
|
20
|
+
}
|
|
3
21
|
export interface PlcClientOptions {
|
|
4
22
|
/** plc directory URL, defaults to https://plc.directory */
|
|
5
23
|
serviceUrl?: string;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAKpD,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAKpD,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAIhC,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAIhC,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,YAAY,GAAG,IAAI;IAJjC,SAAkB,IAAI,oBAAoB;IAE1C,YACQ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,YAAY,GAAG,IAAI,EAChC,OAAO,EAAE,MAAM,EAGf;IAED;;;;OAIG;IACH,OAAa,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CAkBrE;CACD;AAuCD,MAAM,WAAW,gBAAgB;IAChC,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,SAAS;;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAG5B,YAAY,EAAE,UAAoC,EAAE,KAAK,EAAE,OAAe,EAAE,GAAE,gBAAqB,EAGlG;IAED;;;;;OAKG;IACG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAUxF;IAED;;;;;OAKG;IACG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAUpF;IAED;;;;;OAKG;IACG,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAU/F;IAED;;;;;OAKG;IACG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAU9F;IAED;;;;;OAKG;IACG,gBAAgB,CACrB,GAAG,EAAE,CAAC,CAAC,YAAY,EACnB,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAU3C;IAED;;;;;OAKG;IACG,eAAe,CACpB,GAAG,EAAE,CAAC,CAAC,YAAY,EACnB,SAAS,EAAE,CAAC,CAAC,oBAAoB,EACjC,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAaf;IAED;;;;OAIG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAYxD;CACD"}
|
package/dist/client.js
CHANGED
|
@@ -1,13 +1,54 @@
|
|
|
1
1
|
import { defs as identityDefs } from '@atcute/identity';
|
|
2
|
-
import {
|
|
2
|
+
import { parseResponseAsJson, pipe, validateJsonWith } from '@atcute/util-fetch';
|
|
3
3
|
import * as defs from './typedefs.js';
|
|
4
4
|
import * as t from './types.js';
|
|
5
5
|
const MAX_RESPONSE_SIZE = 64 * 1024;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* error thrown when the plc server returns a non-ok response
|
|
8
|
+
*/
|
|
9
|
+
export class PlcClientError extends Error {
|
|
10
|
+
status;
|
|
11
|
+
body;
|
|
12
|
+
name = 'PlcClientError';
|
|
13
|
+
constructor(status, body, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.body = body;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* creates a PlcClientError from a failed fetch response
|
|
20
|
+
* @param response the failed response
|
|
21
|
+
* @returns the error with parsed body if available
|
|
22
|
+
*/
|
|
23
|
+
static async fromResponse(response) {
|
|
24
|
+
const status = response.status;
|
|
25
|
+
let body = null;
|
|
26
|
+
let message = `got http ${status}`;
|
|
27
|
+
try {
|
|
28
|
+
const text = await response.text();
|
|
29
|
+
const json = JSON.parse(text);
|
|
30
|
+
if (typeof json.message === 'string') {
|
|
31
|
+
body = { message: json.message };
|
|
32
|
+
message = json.message;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// failed to parse response body, use default message
|
|
37
|
+
}
|
|
38
|
+
return new PlcClientError(status, body, message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const assertResponseOk = async (response) => {
|
|
42
|
+
if (response.ok) {
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
throw await PlcClientError.fromResponse(response);
|
|
46
|
+
};
|
|
47
|
+
const handleDocument = pipe(assertResponseOk, parseResponseAsJson(/^application\/(did\+ld\+)?json$/, MAX_RESPONSE_SIZE), validateJsonWith(identityDefs.didDocument, { mode: 'passthrough' }));
|
|
48
|
+
const handlePlcState = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.plcState, { mode: 'passthrough' }));
|
|
49
|
+
const handleOperationLog = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.operationLog, { mode: 'passthrough' }));
|
|
50
|
+
const handleIndexedEntryLog = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.indexedEntryLog, { mode: 'passthrough' }));
|
|
51
|
+
const handleLastOperation = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.compatibleOperationOrTombstone, { mode: 'passthrough' }));
|
|
11
52
|
/**
|
|
12
53
|
* client for interacting with plc.directory
|
|
13
54
|
*/
|
|
@@ -26,7 +67,7 @@ export class PlcClient {
|
|
|
26
67
|
*/
|
|
27
68
|
async getDocument(did, options) {
|
|
28
69
|
const url = new URL(`/${encodeURIComponent(did)}`, this.serviceUrl);
|
|
29
|
-
const response = await this.#fetch(url, {
|
|
70
|
+
const response = await (0, this.#fetch)(url, {
|
|
30
71
|
signal: options?.signal,
|
|
31
72
|
headers: { accept: 'application/did+ld+json,application/json' },
|
|
32
73
|
});
|
|
@@ -41,7 +82,7 @@ export class PlcClient {
|
|
|
41
82
|
*/
|
|
42
83
|
async getState(did, options) {
|
|
43
84
|
const url = new URL(`/${encodeURIComponent(did)}/data`, this.serviceUrl);
|
|
44
|
-
const response = await this.#fetch(url, {
|
|
85
|
+
const response = await (0, this.#fetch)(url, {
|
|
45
86
|
signal: options?.signal,
|
|
46
87
|
headers: { accept: 'application/json' },
|
|
47
88
|
});
|
|
@@ -56,7 +97,7 @@ export class PlcClient {
|
|
|
56
97
|
*/
|
|
57
98
|
async getOperationLog(did, options) {
|
|
58
99
|
const url = new URL(`/${encodeURIComponent(did)}/log`, this.serviceUrl);
|
|
59
|
-
const response = await this.#fetch(url, {
|
|
100
|
+
const response = await (0, this.#fetch)(url, {
|
|
60
101
|
signal: options?.signal,
|
|
61
102
|
headers: { accept: 'application/json' },
|
|
62
103
|
});
|
|
@@ -71,7 +112,7 @@ export class PlcClient {
|
|
|
71
112
|
*/
|
|
72
113
|
async getAuditLog(did, options) {
|
|
73
114
|
const url = new URL(`/${encodeURIComponent(did)}/log/audit`, this.serviceUrl);
|
|
74
|
-
const response = await this.#fetch(url, {
|
|
115
|
+
const response = await (0, this.#fetch)(url, {
|
|
75
116
|
signal: options?.signal,
|
|
76
117
|
headers: { accept: 'application/json' },
|
|
77
118
|
});
|
|
@@ -86,7 +127,7 @@ export class PlcClient {
|
|
|
86
127
|
*/
|
|
87
128
|
async getLastOperation(did, options) {
|
|
88
129
|
const url = new URL(`/${encodeURIComponent(did)}/log/last`, this.serviceUrl);
|
|
89
|
-
const response = await this.#fetch(url, {
|
|
130
|
+
const response = await (0, this.#fetch)(url, {
|
|
90
131
|
signal: options?.signal,
|
|
91
132
|
headers: { accept: 'application/json' },
|
|
92
133
|
});
|
|
@@ -101,14 +142,14 @@ export class PlcClient {
|
|
|
101
142
|
*/
|
|
102
143
|
async submitOperation(did, operation, options) {
|
|
103
144
|
const url = new URL(`/${encodeURIComponent(did)}`, this.serviceUrl);
|
|
104
|
-
const response = await this.#fetch(url, {
|
|
145
|
+
const response = await (0, this.#fetch)(url, {
|
|
105
146
|
method: 'POST',
|
|
106
147
|
signal: options?.signal,
|
|
107
148
|
headers: { 'content-type': 'application/json' },
|
|
108
149
|
body: JSON.stringify(operation),
|
|
109
150
|
});
|
|
110
151
|
if (!response.ok) {
|
|
111
|
-
throw
|
|
152
|
+
throw await PlcClientError.fromResponse(response);
|
|
112
153
|
}
|
|
113
154
|
}
|
|
114
155
|
/**
|
|
@@ -118,10 +159,15 @@ export class PlcClient {
|
|
|
118
159
|
*/
|
|
119
160
|
async ping(options) {
|
|
120
161
|
const url = new URL('/_health', this.serviceUrl);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
162
|
+
try {
|
|
163
|
+
const response = await (0, this.#fetch)(url, {
|
|
164
|
+
signal: options?.signal,
|
|
165
|
+
});
|
|
166
|
+
return response.ok;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
125
171
|
}
|
|
126
172
|
}
|
|
127
173
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../lib/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../lib/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEjF,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAEhC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC;AAMpC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAIhC,MAAM;IACN,IAAI;IAJM,IAAI,GAAG,gBAAgB,CAAC;IAE1C,YACQ,MAAc,EACd,IAAyB,EAChC,OAAe,EACd;QACD,KAAK,CAAC,OAAO,CAAC,CAAC;sBAJR,MAAM;oBACN,IAAI;IAGI,CACf;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,QAAkB,EAA2B;QACtE,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC/B,IAAI,IAAI,GAAwB,IAAI,CAAC;QACrC,IAAI,OAAO,GAAG,YAAY,MAAM,EAAE,CAAC;QAEnC,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAE9B,IAAI,OAAO,IAAI,CAAC,OAAO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AAG,IAAI,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEjD,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE;gBAC5C,MAAM,EAAE,OAAO,EAAE,MAAM;aACvB,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,EAAE,CAAC;QACpB,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IAAA,CACD;CACD"}
|
package/dist/data.d.ts
CHANGED
package/dist/errors.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * as defs from './typedefs.
|
|
2
|
-
export * from './types.
|
|
3
|
-
export * from './client.
|
|
4
|
-
export * from './constants.
|
|
5
|
-
export * from './data.
|
|
6
|
-
export * from './errors.
|
|
7
|
-
export * from './utils.
|
|
1
|
+
export * as defs from './typedefs.ts';
|
|
2
|
+
export * from './types.ts';
|
|
3
|
+
export * from './client.ts';
|
|
4
|
+
export * from './constants.ts';
|
|
5
|
+
export * from './data.ts';
|
|
6
|
+
export * from './errors.ts';
|
|
7
|
+
export * from './utils.ts';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from '@badrap/valita';
|
|
2
|
-
import * as t from './types.
|
|
2
|
+
import * as t from './types.ts';
|
|
3
3
|
export declare const didPlcString: v.Type<`did:plc:${string}`>;
|
|
4
4
|
export declare const permissiveDidKeyString: v.Type<`did:key:${string}`>;
|
|
5
5
|
export declare const didKeyString: v.Type<`did:key:${string}`>;
|
package/dist/typedefs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version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Y,CAET,CAAC;AAYxC,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAiB,CAAC;AAElE,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAEsB,CAAC;AAI7E,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAMtC,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAGlD,CAAC"}
|
package/dist/typedefs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
1
|
import * as CID from '@atcute/cid';
|
|
3
2
|
import { parseDidKey } from '@atcute/crypto';
|
|
4
3
|
import { isKeyDid, isPlcDid } from '@atcute/identity';
|
|
4
|
+
import * as v from '@badrap/valita';
|
|
5
5
|
import * as t from './types.js';
|
|
6
6
|
// #region Strings
|
|
7
7
|
export const didPlcString = v.string().assert(isPlcDid, `must be a did:plc`);
|
package/dist/typedefs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAEhC,kBAAkB;AAClB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,MA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,CAAC,CAAC;KACjE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7E,aAAa;AAEb,kCAAkC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAAuB,CAAC,CAAC,MAAM,CAAC;IACpD,GAAG,EAAE,YAAY;IACjB,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;IACnC,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC;IACrD,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAA6B,aAAa,CAAC,MAAM,CAAC;IAC5E,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IAC/B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AACH,aAAa"}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -24,7 +24,7 @@ export const wrapAtprotoPrefix = (str) => {
|
|
|
24
24
|
export const deriveDidFromGenesisOp = async (op) => {
|
|
25
25
|
const opBytes = CBOR.encode(op);
|
|
26
26
|
const hash = await toSha256(opBytes);
|
|
27
|
-
return `did:plc:${toBase32(hash
|
|
27
|
+
return `did:plc:${toBase32(hash.subarray(0, 15))}`;
|
|
28
28
|
};
|
|
29
29
|
export const normalizeOp = (op) => {
|
|
30
30
|
if (op.type === 'create') {
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,mBAAmB,E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,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;AAAA,CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,EAAuB,EAAE,GAAe,EAAwB,EAAE,CAAC;IACtG,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;AAAA,CACxC,CAAC;AAEF,aAAa"}
|
package/lib/client.ts
CHANGED
|
@@ -1,38 +1,89 @@
|
|
|
1
1
|
import type { DidDocument } from '@atcute/identity';
|
|
2
2
|
import { defs as identityDefs } from '@atcute/identity';
|
|
3
|
-
import {
|
|
3
|
+
import { parseResponseAsJson, pipe, validateJsonWith } from '@atcute/util-fetch';
|
|
4
4
|
|
|
5
|
-
import * as defs from './typedefs.
|
|
6
|
-
import * as t from './types.
|
|
5
|
+
import * as defs from './typedefs.ts';
|
|
6
|
+
import * as t from './types.ts';
|
|
7
7
|
|
|
8
8
|
const MAX_RESPONSE_SIZE = 64 * 1024;
|
|
9
9
|
|
|
10
|
+
export interface PlcErrorBody {
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* error thrown when the plc server returns a non-ok response
|
|
16
|
+
*/
|
|
17
|
+
export class PlcClientError extends Error {
|
|
18
|
+
override readonly name = 'PlcClientError';
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
public status: number,
|
|
22
|
+
public body: PlcErrorBody | null,
|
|
23
|
+
message: string,
|
|
24
|
+
) {
|
|
25
|
+
super(message);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* creates a PlcClientError from a failed fetch response
|
|
30
|
+
* @param response the failed response
|
|
31
|
+
* @returns the error with parsed body if available
|
|
32
|
+
*/
|
|
33
|
+
static async fromResponse(response: Response): Promise<PlcClientError> {
|
|
34
|
+
const status = response.status;
|
|
35
|
+
let body: PlcErrorBody | null = null;
|
|
36
|
+
let message = `got http ${status}`;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const text = await response.text();
|
|
40
|
+
const json = JSON.parse(text);
|
|
41
|
+
|
|
42
|
+
if (typeof json.message === 'string') {
|
|
43
|
+
body = { message: json.message };
|
|
44
|
+
message = json.message;
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// failed to parse response body, use default message
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return new PlcClientError(status, body, message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const assertResponseOk = async (response: Response): Promise<Response> => {
|
|
55
|
+
if (response.ok) {
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
throw await PlcClientError.fromResponse(response);
|
|
59
|
+
};
|
|
60
|
+
|
|
10
61
|
const handleDocument = pipe(
|
|
11
|
-
|
|
62
|
+
assertResponseOk,
|
|
12
63
|
parseResponseAsJson(/^application\/(did\+ld\+)?json$/, MAX_RESPONSE_SIZE),
|
|
13
64
|
validateJsonWith(identityDefs.didDocument, { mode: 'passthrough' }),
|
|
14
65
|
);
|
|
15
66
|
|
|
16
67
|
const handlePlcState = pipe(
|
|
17
|
-
|
|
68
|
+
assertResponseOk,
|
|
18
69
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
19
70
|
validateJsonWith(defs.plcState, { mode: 'passthrough' }),
|
|
20
71
|
);
|
|
21
72
|
|
|
22
73
|
const handleOperationLog = pipe(
|
|
23
|
-
|
|
74
|
+
assertResponseOk,
|
|
24
75
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
25
76
|
validateJsonWith(defs.operationLog, { mode: 'passthrough' }),
|
|
26
77
|
);
|
|
27
78
|
|
|
28
79
|
const handleIndexedEntryLog = pipe(
|
|
29
|
-
|
|
80
|
+
assertResponseOk,
|
|
30
81
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
31
82
|
validateJsonWith(defs.indexedEntryLog, { mode: 'passthrough' }),
|
|
32
83
|
);
|
|
33
84
|
|
|
34
85
|
const handleLastOperation = pipe(
|
|
35
|
-
|
|
86
|
+
assertResponseOk,
|
|
36
87
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
37
88
|
validateJsonWith(defs.compatibleOperationOrTombstone, { mode: 'passthrough' }),
|
|
38
89
|
);
|
|
@@ -69,7 +120,7 @@ export class PlcClient {
|
|
|
69
120
|
async getDocument(did: t.DidPlcString, options?: PlcRequestOptions): Promise<DidDocument> {
|
|
70
121
|
const url = new URL(`/${encodeURIComponent(did)}`, this.serviceUrl);
|
|
71
122
|
|
|
72
|
-
const response = await this.#fetch(url, {
|
|
123
|
+
const response = await (0, this.#fetch)(url, {
|
|
73
124
|
signal: options?.signal,
|
|
74
125
|
headers: { accept: 'application/did+ld+json,application/json' },
|
|
75
126
|
});
|
|
@@ -87,7 +138,7 @@ export class PlcClient {
|
|
|
87
138
|
async getState(did: t.DidPlcString, options?: PlcRequestOptions): Promise<t.PlcState> {
|
|
88
139
|
const url = new URL(`/${encodeURIComponent(did)}/data`, this.serviceUrl);
|
|
89
140
|
|
|
90
|
-
const response = await this.#fetch(url, {
|
|
141
|
+
const response = await (0, this.#fetch)(url, {
|
|
91
142
|
signal: options?.signal,
|
|
92
143
|
headers: { accept: 'application/json' },
|
|
93
144
|
});
|
|
@@ -105,7 +156,7 @@ export class PlcClient {
|
|
|
105
156
|
async getOperationLog(did: t.DidPlcString, options?: PlcRequestOptions): Promise<t.OperationLog> {
|
|
106
157
|
const url = new URL(`/${encodeURIComponent(did)}/log`, this.serviceUrl);
|
|
107
158
|
|
|
108
|
-
const response = await this.#fetch(url, {
|
|
159
|
+
const response = await (0, this.#fetch)(url, {
|
|
109
160
|
signal: options?.signal,
|
|
110
161
|
headers: { accept: 'application/json' },
|
|
111
162
|
});
|
|
@@ -123,7 +174,7 @@ export class PlcClient {
|
|
|
123
174
|
async getAuditLog(did: t.DidPlcString, options?: PlcRequestOptions): Promise<t.IndexedEntryLog> {
|
|
124
175
|
const url = new URL(`/${encodeURIComponent(did)}/log/audit`, this.serviceUrl);
|
|
125
176
|
|
|
126
|
-
const response = await this.#fetch(url, {
|
|
177
|
+
const response = await (0, this.#fetch)(url, {
|
|
127
178
|
signal: options?.signal,
|
|
128
179
|
headers: { accept: 'application/json' },
|
|
129
180
|
});
|
|
@@ -144,7 +195,7 @@ export class PlcClient {
|
|
|
144
195
|
): Promise<t.CompatibleOperationOrTombstone> {
|
|
145
196
|
const url = new URL(`/${encodeURIComponent(did)}/log/last`, this.serviceUrl);
|
|
146
197
|
|
|
147
|
-
const response = await this.#fetch(url, {
|
|
198
|
+
const response = await (0, this.#fetch)(url, {
|
|
148
199
|
signal: options?.signal,
|
|
149
200
|
headers: { accept: 'application/json' },
|
|
150
201
|
});
|
|
@@ -166,7 +217,7 @@ export class PlcClient {
|
|
|
166
217
|
): Promise<void> {
|
|
167
218
|
const url = new URL(`/${encodeURIComponent(did)}`, this.serviceUrl);
|
|
168
219
|
|
|
169
|
-
const response = await this.#fetch(url, {
|
|
220
|
+
const response = await (0, this.#fetch)(url, {
|
|
170
221
|
method: 'POST',
|
|
171
222
|
signal: options?.signal,
|
|
172
223
|
headers: { 'content-type': 'application/json' },
|
|
@@ -174,7 +225,7 @@ export class PlcClient {
|
|
|
174
225
|
});
|
|
175
226
|
|
|
176
227
|
if (!response.ok) {
|
|
177
|
-
throw
|
|
228
|
+
throw await PlcClientError.fromResponse(response);
|
|
178
229
|
}
|
|
179
230
|
}
|
|
180
231
|
|
|
@@ -186,10 +237,14 @@ export class PlcClient {
|
|
|
186
237
|
async ping(options?: PlcRequestOptions): Promise<boolean> {
|
|
187
238
|
const url = new URL('/_health', this.serviceUrl);
|
|
188
239
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
240
|
+
try {
|
|
241
|
+
const response = await (0, this.#fetch)(url, {
|
|
242
|
+
signal: options?.signal,
|
|
243
|
+
});
|
|
192
244
|
|
|
193
|
-
|
|
245
|
+
return response.ok;
|
|
246
|
+
} catch {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
194
249
|
}
|
|
195
250
|
}
|
package/lib/data.ts
CHANGED
|
@@ -2,10 +2,10 @@ import * as CBOR from '@atcute/cbor';
|
|
|
2
2
|
import * as CID from '@atcute/cid';
|
|
3
3
|
import { isKeyDid } from '@atcute/identity';
|
|
4
4
|
|
|
5
|
-
import { DISPUTE_WINDOW } from './constants.
|
|
6
|
-
import * as err from './errors.
|
|
7
|
-
import * as t from './types.
|
|
8
|
-
import { deriveDidFromGenesisOp, isSignedOperationValid, normalizeOp } from './utils.
|
|
5
|
+
import { DISPUTE_WINDOW } from './constants.ts';
|
|
6
|
+
import * as err from './errors.ts';
|
|
7
|
+
import * as t from './types.ts';
|
|
8
|
+
import { deriveDidFromGenesisOp, isSignedOperationValid, normalizeOp } from './utils.ts';
|
|
9
9
|
|
|
10
10
|
// soft constraint limits for incoming operations
|
|
11
11
|
const MAX_OP_BYTES = 4000;
|
package/lib/errors.ts
CHANGED
package/lib/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * as defs from './typedefs.
|
|
2
|
-
export * from './types.
|
|
1
|
+
export * as defs from './typedefs.ts';
|
|
2
|
+
export * from './types.ts';
|
|
3
3
|
|
|
4
|
-
export * from './client.
|
|
5
|
-
export * from './constants.
|
|
6
|
-
export * from './data.
|
|
7
|
-
export * from './errors.
|
|
8
|
-
export * from './utils.
|
|
4
|
+
export * from './client.ts';
|
|
5
|
+
export * from './constants.ts';
|
|
6
|
+
export * from './data.ts';
|
|
7
|
+
export * from './errors.ts';
|
|
8
|
+
export * from './utils.ts';
|
package/lib/typedefs.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
|
-
|
|
3
1
|
import * as CID from '@atcute/cid';
|
|
4
2
|
import { parseDidKey } from '@atcute/crypto';
|
|
5
3
|
import { isKeyDid, isPlcDid } from '@atcute/identity';
|
|
6
4
|
|
|
7
|
-
import * as
|
|
5
|
+
import * as v from '@badrap/valita';
|
|
6
|
+
|
|
7
|
+
import * as t from './types.ts';
|
|
8
8
|
|
|
9
9
|
// #region Strings
|
|
10
10
|
export const didPlcString = v.string().assert(isPlcDid, `must be a did:plc`);
|
package/lib/utils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { verifySigWithDidKey } from '@atcute/crypto';
|
|
|
4
4
|
import { fromBase64Url, toBase32, toBase64Url } from '@atcute/multibase';
|
|
5
5
|
import { toSha256 } from '@atcute/uint8array';
|
|
6
6
|
|
|
7
|
-
import * as t from './types.
|
|
7
|
+
import * as t from './types.ts';
|
|
8
8
|
|
|
9
9
|
export const wrapHttpPrefix = (str: string): string => {
|
|
10
10
|
if (str.startsWith('http://') || str.startsWith('https://')) {
|
|
@@ -32,7 +32,7 @@ export const wrapAtprotoPrefix = (str: string): string => {
|
|
|
32
32
|
export const deriveDidFromGenesisOp = async (op: t.CompatibleOperation): Promise<t.DidPlcString> => {
|
|
33
33
|
const opBytes = CBOR.encode(op);
|
|
34
34
|
const hash = await toSha256(opBytes);
|
|
35
|
-
return `did:plc:${toBase32(hash
|
|
35
|
+
return `did:plc:${toBase32(hash.subarray(0, 15))}`;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export const normalizeOp = (op: t.CompatibleOperation): t.Operation => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@atcute/did-plc",
|
|
4
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
5
4
|
"description": "validations, type definitions and schemas for did:plc operations",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"atproto",
|
|
@@ -13,33 +12,35 @@
|
|
|
13
12
|
"url": "https://github.com/mary-ext/atcute",
|
|
14
13
|
"directory": "packages/identity/did-plc"
|
|
15
14
|
},
|
|
16
|
-
"publishConfig": {
|
|
17
|
-
"access": "public"
|
|
18
|
-
},
|
|
19
15
|
"files": [
|
|
20
16
|
"dist/",
|
|
21
17
|
"lib/",
|
|
22
18
|
"!lib/**/*.bench.ts",
|
|
23
19
|
"!lib/**/*.test.ts"
|
|
24
20
|
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
25
23
|
"exports": {
|
|
26
24
|
".": "./dist/index.js"
|
|
27
25
|
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
"@vitest/coverage-v8": "^4.0.16",
|
|
31
|
-
"vitest": "^4.0.16"
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
32
28
|
},
|
|
33
29
|
"dependencies": {
|
|
34
30
|
"@badrap/valita": "^0.4.6",
|
|
35
|
-
"@atcute/
|
|
36
|
-
"@atcute/cid": "^2.2.6",
|
|
37
|
-
"@atcute/crypto": "^2.3.0",
|
|
31
|
+
"@atcute/cid": "^2.4.1",
|
|
38
32
|
"@atcute/identity": "^1.1.3",
|
|
39
|
-
"@atcute/
|
|
40
|
-
"@atcute/
|
|
41
|
-
"@atcute/
|
|
42
|
-
"@atcute/
|
|
33
|
+
"@atcute/cbor": "^2.3.2",
|
|
34
|
+
"@atcute/lexicons": "^1.2.9",
|
|
35
|
+
"@atcute/multibase": "^1.1.8",
|
|
36
|
+
"@atcute/uint8array": "^1.1.1",
|
|
37
|
+
"@atcute/crypto": "^2.3.0",
|
|
38
|
+
"@atcute/util-fetch": "^1.0.5"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
42
|
+
"vitest": "^4.0.18",
|
|
43
|
+
"@atcute/internal-dev-env": "^1.0.2"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"build": "tsgo --project tsconfig.build.json",
|