@atcute/did-plc 0.3.3 → 1.0.0
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/README.md +2 -1
- package/dist/client.js +5 -5
- package/dist/client.js.map +1 -1
- package/dist/typedefs.d.ts +19 -19
- package/dist/typedefs.d.ts.map +1 -1
- package/dist/typedefs.js +54 -48
- package/dist/typedefs.js.map +1 -1
- package/lib/client.ts +5 -5
- package/lib/typedefs.ts +73 -59
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -54,13 +54,14 @@ const did = await deriveDidFromGenesisOp(signedGenesisOp);
|
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
56
|
import { defs, processIndexedEntryLog } from '@atcute/did-plc';
|
|
57
|
+
import * as v from 'valibot';
|
|
57
58
|
|
|
58
59
|
const did = 'did:plc:ragtjsm2j2vknwkz3zp4oxrd';
|
|
59
60
|
|
|
60
61
|
const response = await fetch(`https://plc.directory/${did}/log/audit`);
|
|
61
62
|
const json = await response.json();
|
|
62
63
|
|
|
63
|
-
const logs = defs.indexedEntryLog
|
|
64
|
+
const logs = v.parse(defs.indexedEntryLog, json);
|
|
64
65
|
const { canonical, nullified } = await processIndexedEntryLog(did, logs);
|
|
65
66
|
```
|
|
66
67
|
|
package/dist/client.js
CHANGED
|
@@ -44,11 +44,11 @@ const assertResponseOk = async (response) => {
|
|
|
44
44
|
}
|
|
45
45
|
throw await PlcClientError.fromResponse(response);
|
|
46
46
|
};
|
|
47
|
-
const handleDocument = pipe(assertResponseOk, parseResponseAsJson(/^application\/(did\+ld\+)?json$/, MAX_RESPONSE_SIZE), validateJsonWith(identityDefs.didDocument
|
|
48
|
-
const handlePlcState = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.plcState
|
|
49
|
-
const handleOperationLog = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.operationLog
|
|
50
|
-
const handleIndexedEntryLog = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.indexedEntryLog
|
|
51
|
-
const handleLastOperation = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.compatibleOperationOrTombstone
|
|
47
|
+
const handleDocument = pipe(assertResponseOk, parseResponseAsJson(/^application\/(did\+ld\+)?json$/, MAX_RESPONSE_SIZE), validateJsonWith(identityDefs.didDocument));
|
|
48
|
+
const handlePlcState = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.plcState));
|
|
49
|
+
const handleOperationLog = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.operationLog));
|
|
50
|
+
const handleIndexedEntryLog = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.indexedEntryLog));
|
|
51
|
+
const handleLastOperation = pipe(assertResponseOk, parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE), validateJsonWith(defs.compatibleOperationOrTombstone));
|
|
52
52
|
/**
|
|
53
53
|
* client for interacting with plc.directory
|
|
54
54
|
*/
|
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,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,cAA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@@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
import * as t from './types.ts';
|
|
3
|
-
export declare const didPlcString: v.
|
|
4
|
-
export declare const permissiveDidKeyString: v.
|
|
5
|
-
export declare const didKeyString: v.
|
|
6
|
-
export declare const unsignedLegacyCreateOperation: v.
|
|
7
|
-
export declare const legacyCreateOperation: v.
|
|
8
|
-
export declare const service: v.
|
|
9
|
-
export declare const unsignedOperation: v.
|
|
10
|
-
export declare const operation: v.
|
|
11
|
-
export declare const unsignedTombstone: v.
|
|
12
|
-
export declare const tombstone: v.
|
|
13
|
-
export declare const compatibleOperation: v.
|
|
14
|
-
export declare const compatibleOperationOrTombstone: v.
|
|
15
|
-
export declare const operationOrTombstone: v.
|
|
16
|
-
export declare const operationLog: v.
|
|
17
|
-
export declare const indexedEntry: v.
|
|
18
|
-
export declare const indexedEntryLog: v.
|
|
19
|
-
export declare const plcState: v.
|
|
20
|
-
export declare const sequencedEntry: v.
|
|
3
|
+
export declare const didPlcString: v.CustomSchema<`did:plc:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
4
|
+
export declare const permissiveDidKeyString: v.CustomSchema<`did:key:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
5
|
+
export declare const didKeyString: v.CustomSchema<`did:key:${string}`, v.ErrorMessage<v.CustomIssue> | undefined>;
|
|
6
|
+
export declare const unsignedLegacyCreateOperation: v.GenericSchema<unknown, t.UnsignedLegacyCreateOperation>;
|
|
7
|
+
export declare const legacyCreateOperation: v.GenericSchema<unknown, t.LegacyCreateOperation>;
|
|
8
|
+
export declare const service: v.GenericSchema<unknown, t.Service>;
|
|
9
|
+
export declare const unsignedOperation: v.GenericSchema<unknown, t.UnsignedOperation>;
|
|
10
|
+
export declare const operation: v.GenericSchema<unknown, t.Operation>;
|
|
11
|
+
export declare const unsignedTombstone: v.GenericSchema<unknown, t.UnsignedTombstone>;
|
|
12
|
+
export declare const tombstone: v.GenericSchema<unknown, t.Tombstone>;
|
|
13
|
+
export declare const compatibleOperation: v.GenericSchema<unknown, t.CompatibleOperation>;
|
|
14
|
+
export declare const compatibleOperationOrTombstone: v.GenericSchema<unknown, t.CompatibleOperationOrTombstone>;
|
|
15
|
+
export declare const operationOrTombstone: v.GenericSchema<unknown, t.OperationOrTombstone>;
|
|
16
|
+
export declare const operationLog: v.GenericSchema<unknown, t.OperationLog>;
|
|
17
|
+
export declare const indexedEntry: v.GenericSchema<unknown, t.IndexedEntry>;
|
|
18
|
+
export declare const indexedEntryLog: v.GenericSchema<unknown, t.IndexedEntryLog>;
|
|
19
|
+
export declare const plcState: v.GenericSchema<unknown, t.PlcState>;
|
|
20
|
+
export declare const sequencedEntry: v.GenericSchema<unknown, t.SequencedEntry>;
|
|
21
21
|
//# sourceMappingURL=typedefs.d.ts.map
|
package/dist/typedefs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../lib/typedefs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAGhC,eAAO,MAAM,YAAY,gFAA0D,CAAC;AAEpF,eAAO,MAAM,sBAAsB,gFAA0D,CAAC;AAE9F,eAAO,MAAM,YAAY,gFAUJ,CAAC;AAyBtB,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,6BAA6B,CAChD,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,qBAAqB,CAGlF,CAAC;AAIH,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,aAAa,CAAC,OAA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AC"}
|
package/dist/typedefs.js
CHANGED
|
@@ -1,105 +1,111 @@
|
|
|
1
1
|
import * as CID from '@atcute/cid';
|
|
2
2
|
import { parseDidKey } from '@atcute/crypto';
|
|
3
3
|
import { isKeyDid, isPlcDid } from '@atcute/identity';
|
|
4
|
-
import * as v from '
|
|
4
|
+
import * as v from 'valibot';
|
|
5
5
|
import * as t from './types.js';
|
|
6
6
|
// #region Strings
|
|
7
|
-
export const didPlcString = v.
|
|
8
|
-
export const permissiveDidKeyString = v.
|
|
9
|
-
export const didKeyString = v.
|
|
7
|
+
export const didPlcString = v.custom(isPlcDid, `must be a did:plc`);
|
|
8
|
+
export const permissiveDidKeyString = v.custom(isKeyDid, `must be a did:key`);
|
|
9
|
+
export const didKeyString = v.custom((input) => {
|
|
10
|
+
if (!isKeyDid(input)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
10
13
|
try {
|
|
11
14
|
parseDidKey(input);
|
|
15
|
+
return true;
|
|
12
16
|
}
|
|
13
|
-
catch
|
|
14
|
-
|
|
15
|
-
return v.err(`did:key can't be parsed`);
|
|
16
|
-
}
|
|
17
|
-
return v.err(`invalid did:key`);
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const cidString = v.string().chain((input) => {
|
|
20
|
+
}, `invalid did:key`);
|
|
21
|
+
const cidString = v.pipe(v.string(), v.check((input) => {
|
|
22
22
|
try {
|
|
23
23
|
CID.fromString(input);
|
|
24
|
+
return true;
|
|
24
25
|
}
|
|
25
26
|
catch {
|
|
26
|
-
return
|
|
27
|
+
return false;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
});
|
|
29
|
+
}, `invalid cid`));
|
|
30
30
|
// #endregion
|
|
31
31
|
// #region create
|
|
32
|
-
const
|
|
32
|
+
const unsignedLegacyCreateOperationEntries = {
|
|
33
33
|
type: v.literal('create'),
|
|
34
34
|
prev: v.null(),
|
|
35
35
|
signingKey: didKeyString,
|
|
36
36
|
recoveryKey: didKeyString,
|
|
37
37
|
handle: v.string(),
|
|
38
38
|
service: v.string(),
|
|
39
|
-
}
|
|
40
|
-
export const unsignedLegacyCreateOperation =
|
|
41
|
-
export const legacyCreateOperation =
|
|
39
|
+
};
|
|
40
|
+
export const unsignedLegacyCreateOperation = v.looseObject(unsignedLegacyCreateOperationEntries);
|
|
41
|
+
export const legacyCreateOperation = v.looseObject({
|
|
42
|
+
...unsignedLegacyCreateOperationEntries,
|
|
42
43
|
sig: v.string(),
|
|
43
44
|
});
|
|
44
45
|
// #endregion
|
|
45
46
|
// #region plc_operation
|
|
46
|
-
export const service = v.
|
|
47
|
+
export const service = v.looseObject({
|
|
47
48
|
type: v.string(),
|
|
48
49
|
endpoint: v.string(),
|
|
49
50
|
});
|
|
50
|
-
const
|
|
51
|
+
const unsignedOperationEntries = {
|
|
51
52
|
type: v.literal('plc_operation'),
|
|
52
|
-
prev: v.
|
|
53
|
+
prev: v.nullable(v.string()),
|
|
53
54
|
rotationKeys: v.array(didKeyString),
|
|
54
|
-
verificationMethods: v.record(permissiveDidKeyString),
|
|
55
|
+
verificationMethods: v.record(v.string(), permissiveDidKeyString),
|
|
55
56
|
alsoKnownAs: v.array(v.string()),
|
|
56
|
-
services: v.record(service),
|
|
57
|
-
}
|
|
58
|
-
export const unsignedOperation =
|
|
59
|
-
export const operation =
|
|
57
|
+
services: v.record(v.string(), service),
|
|
58
|
+
};
|
|
59
|
+
export const unsignedOperation = v.looseObject(unsignedOperationEntries);
|
|
60
|
+
export const operation = v.looseObject({
|
|
61
|
+
...unsignedOperationEntries,
|
|
60
62
|
sig: v.string(),
|
|
61
63
|
});
|
|
62
64
|
// #endregion
|
|
63
65
|
// #region plc_tombstone
|
|
64
|
-
const
|
|
66
|
+
const unsignedTombstoneEntries = {
|
|
65
67
|
type: v.literal('plc_tombstone'),
|
|
66
68
|
prev: v.string(),
|
|
67
|
-
}
|
|
68
|
-
export const unsignedTombstone =
|
|
69
|
-
export const tombstone =
|
|
69
|
+
};
|
|
70
|
+
export const unsignedTombstone = v.looseObject(unsignedTombstoneEntries);
|
|
71
|
+
export const tombstone = v.looseObject({
|
|
72
|
+
...unsignedTombstoneEntries,
|
|
70
73
|
sig: v.string(),
|
|
71
74
|
});
|
|
72
75
|
// #endregion
|
|
73
76
|
// #region Entry
|
|
74
|
-
export const compatibleOperation = v.union(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
export const compatibleOperation = v.union([
|
|
78
|
+
operation,
|
|
79
|
+
legacyCreateOperation,
|
|
80
|
+
]);
|
|
81
|
+
export const compatibleOperationOrTombstone = v.union([operation, legacyCreateOperation, tombstone]);
|
|
82
|
+
export const operationOrTombstone = v.union([
|
|
83
|
+
operation,
|
|
84
|
+
tombstone,
|
|
85
|
+
]);
|
|
86
|
+
export const operationLog = v.tupleWithRest([compatibleOperation], operationOrTombstone);
|
|
80
87
|
// #endregion
|
|
81
88
|
// #region Indexed entry
|
|
82
|
-
const
|
|
89
|
+
const indexedEntryEntries = {
|
|
83
90
|
did: didPlcString,
|
|
84
91
|
operation: compatibleOperationOrTombstone,
|
|
85
92
|
cid: cidString,
|
|
86
93
|
nullified: v.boolean(),
|
|
87
|
-
createdAt: v.string().
|
|
88
|
-
}
|
|
89
|
-
export const indexedEntry =
|
|
90
|
-
export const indexedEntryLog = v
|
|
91
|
-
.tuple([_indexedEntry.extend({ operation: compatibleOperation })])
|
|
92
|
-
.concat(v.array(_indexedEntry.extend({ operation: operationOrTombstone })));
|
|
94
|
+
createdAt: v.pipe(v.string(), v.check((input) => !Number.isNaN(new Date(input).getTime()), `invalid timestamp`)),
|
|
95
|
+
};
|
|
96
|
+
export const indexedEntry = v.looseObject(indexedEntryEntries);
|
|
97
|
+
export const indexedEntryLog = v.tupleWithRest([v.looseObject({ ...indexedEntryEntries, operation: compatibleOperation })], v.looseObject({ ...indexedEntryEntries, operation: operationOrTombstone }));
|
|
93
98
|
// #endregion
|
|
94
99
|
// #region Client response schemas
|
|
95
|
-
export const plcState = v.
|
|
100
|
+
export const plcState = v.looseObject({
|
|
96
101
|
did: didPlcString,
|
|
97
102
|
rotationKeys: v.array(didKeyString),
|
|
98
|
-
verificationMethods: v.record(permissiveDidKeyString),
|
|
103
|
+
verificationMethods: v.record(v.string(), permissiveDidKeyString),
|
|
99
104
|
alsoKnownAs: v.array(v.string()),
|
|
100
|
-
services: v.record(service),
|
|
105
|
+
services: v.record(v.string(), service),
|
|
101
106
|
});
|
|
102
|
-
export const sequencedEntry =
|
|
107
|
+
export const sequencedEntry = v.looseObject({
|
|
108
|
+
...indexedEntryEntries,
|
|
103
109
|
type: v.literal('sequenced_op'),
|
|
104
110
|
seq: v.number(),
|
|
105
111
|
});
|
package/dist/typedefs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,SAAS,CAAC;AAE7B,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAEhC,kBAAkB;AAClB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAiB,QAAQ,EAAE,mBAAmB,CAAC,CAAC;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E,CAAC,CAAC,WAAW,CAAC,EAAE,GAAG,mBAAmB,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAC1E,CAAC;AACF,aAAa;AAEb,kCAAkC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAAyC,CAAC,CAAC,WAAW,CAAC;IAC3E,GAAG,EAAE,YAAY;IACjB,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;IACnC,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,sBAAsB,CAAC;IACjE,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC;CACvC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAA+C,CAAC,CAAC,WAAW,CAAC;IACvF,GAAG,mBAAmB;IACtB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;IAC/B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AACH,aAAa"}
|
package/lib/client.ts
CHANGED
|
@@ -62,31 +62,31 @@ const assertResponseOk = async (response: Response): Promise<Response> => {
|
|
|
62
62
|
const handleDocument = pipe(
|
|
63
63
|
assertResponseOk,
|
|
64
64
|
parseResponseAsJson(/^application\/(did\+ld\+)?json$/, MAX_RESPONSE_SIZE),
|
|
65
|
-
validateJsonWith(identityDefs.didDocument
|
|
65
|
+
validateJsonWith(identityDefs.didDocument),
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
const handlePlcState = pipe(
|
|
69
69
|
assertResponseOk,
|
|
70
70
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
71
|
-
validateJsonWith(defs.plcState
|
|
71
|
+
validateJsonWith(defs.plcState),
|
|
72
72
|
);
|
|
73
73
|
|
|
74
74
|
const handleOperationLog = pipe(
|
|
75
75
|
assertResponseOk,
|
|
76
76
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
77
|
-
validateJsonWith(defs.operationLog
|
|
77
|
+
validateJsonWith(defs.operationLog),
|
|
78
78
|
);
|
|
79
79
|
|
|
80
80
|
const handleIndexedEntryLog = pipe(
|
|
81
81
|
assertResponseOk,
|
|
82
82
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
83
|
-
validateJsonWith(defs.indexedEntryLog
|
|
83
|
+
validateJsonWith(defs.indexedEntryLog),
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
const handleLastOperation = pipe(
|
|
87
87
|
assertResponseOk,
|
|
88
88
|
parseResponseAsJson(/^application\/json$/, MAX_RESPONSE_SIZE),
|
|
89
|
-
validateJsonWith(defs.compatibleOperationOrTombstone
|
|
89
|
+
validateJsonWith(defs.compatibleOperationOrTombstone),
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
export interface PlcClientOptions {
|
package/lib/typedefs.ts
CHANGED
|
@@ -2,135 +2,149 @@ import * as CID from '@atcute/cid';
|
|
|
2
2
|
import { parseDidKey } from '@atcute/crypto';
|
|
3
3
|
import { isKeyDid, isPlcDid } from '@atcute/identity';
|
|
4
4
|
|
|
5
|
-
import * as v from '
|
|
5
|
+
import * as v from 'valibot';
|
|
6
6
|
|
|
7
7
|
import * as t from './types.ts';
|
|
8
8
|
|
|
9
9
|
// #region Strings
|
|
10
|
-
export const didPlcString = v.
|
|
10
|
+
export const didPlcString = v.custom<t.DidPlcString>(isPlcDid, `must be a did:plc`);
|
|
11
11
|
|
|
12
|
-
export const permissiveDidKeyString = v.
|
|
12
|
+
export const permissiveDidKeyString = v.custom<t.DidKeyString>(isKeyDid, `must be a did:key`);
|
|
13
13
|
|
|
14
|
-
export const didKeyString = v.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} catch (err) {
|
|
18
|
-
if (err instanceof SyntaxError) {
|
|
19
|
-
return v.err(`did:key can't be parsed`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return v.err(`invalid did:key`);
|
|
14
|
+
export const didKeyString = v.custom<t.DidKeyString>((input) => {
|
|
15
|
+
if (!isKeyDid(input)) {
|
|
16
|
+
return false;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
return v.ok(input as t.DidKeyString);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const cidString = v.string().chain((input) => {
|
|
29
18
|
try {
|
|
30
|
-
|
|
19
|
+
parseDidKey(input);
|
|
20
|
+
return true;
|
|
31
21
|
} catch {
|
|
32
|
-
return
|
|
22
|
+
return false;
|
|
33
23
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
}, `invalid did:key`);
|
|
25
|
+
|
|
26
|
+
const cidString = v.pipe(
|
|
27
|
+
v.string(),
|
|
28
|
+
v.check((input) => {
|
|
29
|
+
try {
|
|
30
|
+
CID.fromString(input);
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}, `invalid cid`),
|
|
36
|
+
);
|
|
37
37
|
// #endregion
|
|
38
38
|
|
|
39
39
|
// #region create
|
|
40
|
-
const
|
|
40
|
+
const unsignedLegacyCreateOperationEntries = {
|
|
41
41
|
type: v.literal('create'),
|
|
42
42
|
prev: v.null(),
|
|
43
43
|
signingKey: didKeyString,
|
|
44
44
|
recoveryKey: didKeyString,
|
|
45
45
|
handle: v.string(),
|
|
46
46
|
service: v.string(),
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
export const unsignedLegacyCreateOperation: v.
|
|
50
|
-
|
|
49
|
+
export const unsignedLegacyCreateOperation: v.GenericSchema<unknown, t.UnsignedLegacyCreateOperation> =
|
|
50
|
+
v.looseObject(unsignedLegacyCreateOperationEntries);
|
|
51
51
|
|
|
52
|
-
export const legacyCreateOperation: v.
|
|
52
|
+
export const legacyCreateOperation: v.GenericSchema<unknown, t.LegacyCreateOperation> = v.looseObject({
|
|
53
|
+
...unsignedLegacyCreateOperationEntries,
|
|
53
54
|
sig: v.string(),
|
|
54
55
|
});
|
|
55
56
|
// #endregion
|
|
56
57
|
|
|
57
58
|
// #region plc_operation
|
|
58
|
-
export const service: v.
|
|
59
|
+
export const service: v.GenericSchema<unknown, t.Service> = v.looseObject({
|
|
59
60
|
type: v.string(),
|
|
60
61
|
endpoint: v.string(),
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
const
|
|
64
|
+
const unsignedOperationEntries = {
|
|
64
65
|
type: v.literal('plc_operation'),
|
|
65
|
-
prev: v.
|
|
66
|
+
prev: v.nullable(v.string()),
|
|
66
67
|
rotationKeys: v.array(didKeyString),
|
|
67
|
-
verificationMethods: v.record(permissiveDidKeyString),
|
|
68
|
+
verificationMethods: v.record(v.string(), permissiveDidKeyString),
|
|
68
69
|
alsoKnownAs: v.array(v.string()),
|
|
69
|
-
services: v.record(service),
|
|
70
|
-
}
|
|
70
|
+
services: v.record(v.string(), service),
|
|
71
|
+
};
|
|
71
72
|
|
|
72
|
-
export const unsignedOperation: v.
|
|
73
|
+
export const unsignedOperation: v.GenericSchema<unknown, t.UnsignedOperation> =
|
|
74
|
+
v.looseObject(unsignedOperationEntries);
|
|
73
75
|
|
|
74
|
-
export const operation: v.
|
|
76
|
+
export const operation: v.GenericSchema<unknown, t.Operation> = v.looseObject({
|
|
77
|
+
...unsignedOperationEntries,
|
|
75
78
|
sig: v.string(),
|
|
76
79
|
});
|
|
77
80
|
// #endregion
|
|
78
81
|
|
|
79
82
|
// #region plc_tombstone
|
|
80
|
-
const
|
|
83
|
+
const unsignedTombstoneEntries = {
|
|
81
84
|
type: v.literal('plc_tombstone'),
|
|
82
85
|
prev: v.string(),
|
|
83
|
-
}
|
|
86
|
+
};
|
|
84
87
|
|
|
85
|
-
export const unsignedTombstone: v.
|
|
88
|
+
export const unsignedTombstone: v.GenericSchema<unknown, t.UnsignedTombstone> =
|
|
89
|
+
v.looseObject(unsignedTombstoneEntries);
|
|
86
90
|
|
|
87
|
-
export const tombstone: v.
|
|
91
|
+
export const tombstone: v.GenericSchema<unknown, t.Tombstone> = v.looseObject({
|
|
92
|
+
...unsignedTombstoneEntries,
|
|
88
93
|
sig: v.string(),
|
|
89
94
|
});
|
|
90
95
|
// #endregion
|
|
91
96
|
|
|
92
97
|
// #region Entry
|
|
93
|
-
export const compatibleOperation: v.
|
|
94
|
-
|
|
95
|
-
export const compatibleOperationOrTombstone: v.Type<t.CompatibleOperationOrTombstone> = v.union(
|
|
98
|
+
export const compatibleOperation: v.GenericSchema<unknown, t.CompatibleOperation> = v.union([
|
|
96
99
|
operation,
|
|
97
100
|
legacyCreateOperation,
|
|
98
|
-
|
|
99
|
-
);
|
|
101
|
+
]);
|
|
100
102
|
|
|
101
|
-
export const
|
|
103
|
+
export const compatibleOperationOrTombstone: v.GenericSchema<unknown, t.CompatibleOperationOrTombstone> =
|
|
104
|
+
v.union([operation, legacyCreateOperation, tombstone]);
|
|
102
105
|
|
|
103
|
-
export const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
export const operationOrTombstone: v.GenericSchema<unknown, t.OperationOrTombstone> = v.union([
|
|
107
|
+
operation,
|
|
108
|
+
tombstone,
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
export const operationLog: v.GenericSchema<unknown, t.OperationLog> = v.tupleWithRest(
|
|
112
|
+
[compatibleOperation],
|
|
113
|
+
operationOrTombstone,
|
|
114
|
+
);
|
|
106
115
|
// #endregion
|
|
107
116
|
|
|
108
117
|
// #region Indexed entry
|
|
109
|
-
const
|
|
118
|
+
const indexedEntryEntries = {
|
|
110
119
|
did: didPlcString,
|
|
111
120
|
operation: compatibleOperationOrTombstone,
|
|
112
121
|
cid: cidString,
|
|
113
122
|
nullified: v.boolean(),
|
|
114
|
-
createdAt: v.
|
|
115
|
-
|
|
123
|
+
createdAt: v.pipe(
|
|
124
|
+
v.string(),
|
|
125
|
+
v.check((input) => !Number.isNaN(new Date(input).getTime()), `invalid timestamp`),
|
|
126
|
+
),
|
|
127
|
+
};
|
|
116
128
|
|
|
117
|
-
export const indexedEntry: v.
|
|
129
|
+
export const indexedEntry: v.GenericSchema<unknown, t.IndexedEntry> = v.looseObject(indexedEntryEntries);
|
|
118
130
|
|
|
119
|
-
export const indexedEntryLog: v.
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
export const indexedEntryLog: v.GenericSchema<unknown, t.IndexedEntryLog> = v.tupleWithRest(
|
|
132
|
+
[v.looseObject({ ...indexedEntryEntries, operation: compatibleOperation })],
|
|
133
|
+
v.looseObject({ ...indexedEntryEntries, operation: operationOrTombstone }),
|
|
134
|
+
);
|
|
122
135
|
// #endregion
|
|
123
136
|
|
|
124
137
|
// #region Client response schemas
|
|
125
|
-
export const plcState: v.
|
|
138
|
+
export const plcState: v.GenericSchema<unknown, t.PlcState> = v.looseObject({
|
|
126
139
|
did: didPlcString,
|
|
127
140
|
rotationKeys: v.array(didKeyString),
|
|
128
|
-
verificationMethods: v.record(permissiveDidKeyString),
|
|
141
|
+
verificationMethods: v.record(v.string(), permissiveDidKeyString),
|
|
129
142
|
alsoKnownAs: v.array(v.string()),
|
|
130
|
-
services: v.record(service),
|
|
143
|
+
services: v.record(v.string(), service),
|
|
131
144
|
});
|
|
132
145
|
|
|
133
|
-
export const sequencedEntry: v.
|
|
146
|
+
export const sequencedEntry: v.GenericSchema<unknown, t.SequencedEntry> = v.looseObject({
|
|
147
|
+
...indexedEntryEntries,
|
|
134
148
|
type: v.literal('sequenced_op'),
|
|
135
149
|
seq: v.number(),
|
|
136
150
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atcute/did-plc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "validations, type definitions and schemas for did:plc operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atproto",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"
|
|
31
|
+
"valibot": "^1.4.0",
|
|
32
32
|
"@atcute/cbor": "^2.3.3",
|
|
33
33
|
"@atcute/crypto": "^2.4.1",
|
|
34
34
|
"@atcute/cid": "^2.4.1",
|
|
35
|
-
"@atcute/identity": "^
|
|
36
|
-
"@atcute/lexicons": "^1.3.1",
|
|
35
|
+
"@atcute/identity": "^2.0.0",
|
|
37
36
|
"@atcute/uint8array": "^1.1.1",
|
|
38
|
-
"@atcute/
|
|
39
|
-
"@atcute/multibase": "^1.2.0"
|
|
37
|
+
"@atcute/lexicons": "^2.0.0",
|
|
38
|
+
"@atcute/multibase": "^1.2.0",
|
|
39
|
+
"@atcute/util-fetch": "^2.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@vitest/coverage-v8": "^4.1.5",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@atcute/cbor": "^2.0.0",
|
|
48
48
|
"@atcute/cid": "^2.0.0",
|
|
49
|
-
"@atcute/identity": "^
|
|
50
|
-
"@atcute/lexicons": "^
|
|
49
|
+
"@atcute/identity": "^2.0.0",
|
|
50
|
+
"@atcute/lexicons": "^2.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsgo",
|