@did-plc/lib 0.0.3 → 0.0.4
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 +1 -20
- package/dist/data.d.ts +1 -0
- package/dist/index.js +55 -46
- package/dist/index.js.map +2 -2
- package/dist/operations.d.ts +2 -19
- package/package.json +1 -1
- package/src/client.ts +1 -1
- package/src/data.ts +16 -3
- package/src/operations.ts +48 -56
- package/tsconfig.build.tsbuildinfo +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -20,26 +20,7 @@ export declare class Client {
|
|
|
20
20
|
rotationKeys: string[];
|
|
21
21
|
signer: Keypair;
|
|
22
22
|
}): Promise<string>;
|
|
23
|
-
ensureLastOp
|
|
24
|
-
type: "create";
|
|
25
|
-
signingKey: string;
|
|
26
|
-
recoveryKey: string;
|
|
27
|
-
handle: string;
|
|
28
|
-
service: string;
|
|
29
|
-
prev: null;
|
|
30
|
-
sig: string;
|
|
31
|
-
} | {
|
|
32
|
-
type: "plc_operation";
|
|
33
|
-
prev: string | null;
|
|
34
|
-
sig: string;
|
|
35
|
-
rotationKeys: string[];
|
|
36
|
-
verificationMethods: Record<string, string>;
|
|
37
|
-
alsoKnownAs: string[];
|
|
38
|
-
services: Record<string, {
|
|
39
|
-
type: string;
|
|
40
|
-
endpoint: string;
|
|
41
|
-
}>;
|
|
42
|
-
}>;
|
|
23
|
+
private ensureLastOp;
|
|
43
24
|
updateData(did: string, signer: Keypair, fn: (lastOp: t.UnsignedOperation) => Omit<t.UnsignedOperation, 'prev'>): Promise<void>;
|
|
44
25
|
updateAtprotoKey(did: string, signer: Keypair, atprotoKey: string): Promise<void>;
|
|
45
26
|
updateHandle(did: string, signer: Keypair, handle: string): Promise<void>;
|
package/dist/data.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const assureValidNextOp: (did: string, ops: t.IndexedOperation[],
|
|
|
5
5
|
prev: CID | null;
|
|
6
6
|
}>;
|
|
7
7
|
export declare const validateOperationLog: (did: string, ops: t.CompatibleOpOrTombstone[]) => Promise<t.DocumentData | null>;
|
|
8
|
+
export declare const opToData: (did: string, op: t.CompatibleOpOrTombstone) => t.DocumentData | null;
|
|
8
9
|
export declare const getLastOpWithCid: (ops: t.CompatibleOpOrTombstone[]) => Promise<{
|
|
9
10
|
op: t.CompatibleOpOrTombstone;
|
|
10
11
|
cid: CID;
|
package/dist/index.js
CHANGED
|
@@ -24337,7 +24337,6 @@ __export(src_exports2, {
|
|
|
24337
24337
|
assureValidOp: () => assureValidOp,
|
|
24338
24338
|
assureValidSig: () => assureValidSig,
|
|
24339
24339
|
atprotoOp: () => atprotoOp,
|
|
24340
|
-
createAtprotoUpdateOp: () => createAtprotoUpdateOp,
|
|
24341
24340
|
createOp: () => createOp,
|
|
24342
24341
|
createUpdateOp: () => createUpdateOp,
|
|
24343
24342
|
def: () => def,
|
|
@@ -24354,6 +24353,7 @@ __export(src_exports2, {
|
|
|
24354
24353
|
getLastOpWithCid: () => getLastOpWithCid,
|
|
24355
24354
|
indexedOperation: () => indexedOperation,
|
|
24356
24355
|
normalizeOp: () => normalizeOp,
|
|
24356
|
+
opToData: () => opToData,
|
|
24357
24357
|
signOperation: () => signOperation,
|
|
24358
24358
|
tombstoneOp: () => tombstoneOp,
|
|
24359
24359
|
updateAtprotoKeyOp: () => updateAtprotoKeyOp,
|
|
@@ -32677,57 +32677,59 @@ var createUpdateOp = async (lastOp, signer, fn) => {
|
|
|
32677
32677
|
signer
|
|
32678
32678
|
);
|
|
32679
32679
|
};
|
|
32680
|
-
var
|
|
32681
|
-
return createUpdateOp(lastOp, signer, (normalized) => {
|
|
32682
|
-
|
|
32683
|
-
|
|
32684
|
-
|
|
32685
|
-
|
|
32686
|
-
atproto: opts.signingKey
|
|
32687
|
-
};
|
|
32680
|
+
var updateAtprotoKeyOp = async (lastOp, signer, atprotoKey) => {
|
|
32681
|
+
return createUpdateOp(lastOp, signer, (normalized) => ({
|
|
32682
|
+
...normalized,
|
|
32683
|
+
verificationMethods: {
|
|
32684
|
+
...normalized.verificationMethods,
|
|
32685
|
+
atproto: atprotoKey
|
|
32688
32686
|
}
|
|
32689
|
-
|
|
32690
|
-
|
|
32691
|
-
|
|
32692
|
-
|
|
32693
|
-
|
|
32694
|
-
|
|
32695
|
-
|
|
32696
|
-
|
|
32697
|
-
|
|
32698
|
-
|
|
32699
|
-
|
|
32700
|
-
|
|
32701
|
-
|
|
32702
|
-
|
|
32687
|
+
}));
|
|
32688
|
+
};
|
|
32689
|
+
var updateHandleOp = async (lastOp, signer, handle) => {
|
|
32690
|
+
const formatted = ensureAtprotoPrefix(handle);
|
|
32691
|
+
return createUpdateOp(lastOp, signer, (normalized) => {
|
|
32692
|
+
const handleI = normalized.alsoKnownAs.findIndex(
|
|
32693
|
+
(h) => h.startsWith("at://")
|
|
32694
|
+
);
|
|
32695
|
+
let aka;
|
|
32696
|
+
if (handleI < 0) {
|
|
32697
|
+
aka = [formatted, ...normalized.alsoKnownAs];
|
|
32698
|
+
} else {
|
|
32699
|
+
aka = [
|
|
32700
|
+
...normalized.alsoKnownAs.slice(0, handleI),
|
|
32701
|
+
formatted,
|
|
32702
|
+
...normalized.alsoKnownAs.slice(handleI + 1)
|
|
32703
|
+
];
|
|
32703
32704
|
}
|
|
32704
|
-
|
|
32705
|
-
|
|
32706
|
-
|
|
32705
|
+
return {
|
|
32706
|
+
...normalized,
|
|
32707
|
+
alsoKnownAs: aka
|
|
32708
|
+
};
|
|
32709
|
+
});
|
|
32710
|
+
};
|
|
32711
|
+
var updatePdsOp = async (lastOp, signer, endpoint) => {
|
|
32712
|
+
const formatted = ensureHttpPrefix(endpoint);
|
|
32713
|
+
return createUpdateOp(lastOp, signer, (normalized) => {
|
|
32714
|
+
return {
|
|
32715
|
+
...normalized,
|
|
32716
|
+
services: {
|
|
32707
32717
|
...normalized.services,
|
|
32708
32718
|
atproto_pds: {
|
|
32709
32719
|
type: "AtprotoPersonalDataServer",
|
|
32710
32720
|
endpoint: formatted
|
|
32711
32721
|
}
|
|
32712
|
-
}
|
|
32713
|
-
}
|
|
32714
|
-
if (opts.rotationKeys) {
|
|
32715
|
-
updated.rotationKeys = opts.rotationKeys;
|
|
32716
|
-
}
|
|
32717
|
-
return updated;
|
|
32722
|
+
}
|
|
32723
|
+
};
|
|
32718
32724
|
});
|
|
32719
32725
|
};
|
|
32720
|
-
var updateAtprotoKeyOp = async (lastOp, signer, signingKey) => {
|
|
32721
|
-
return createAtprotoUpdateOp(lastOp, signer, { signingKey });
|
|
32722
|
-
};
|
|
32723
|
-
var updateHandleOp = async (lastOp, signer, handle) => {
|
|
32724
|
-
return createAtprotoUpdateOp(lastOp, signer, { handle });
|
|
32725
|
-
};
|
|
32726
|
-
var updatePdsOp = async (lastOp, signer, pds) => {
|
|
32727
|
-
return createAtprotoUpdateOp(lastOp, signer, { pds });
|
|
32728
|
-
};
|
|
32729
32726
|
var updateRotationKeysOp = async (lastOp, signer, rotationKeys) => {
|
|
32730
|
-
return
|
|
32727
|
+
return createUpdateOp(lastOp, signer, (normalized) => {
|
|
32728
|
+
return {
|
|
32729
|
+
...normalized,
|
|
32730
|
+
rotationKeys
|
|
32731
|
+
};
|
|
32732
|
+
});
|
|
32731
32733
|
};
|
|
32732
32734
|
var tombstoneOp = async (prev, key) => {
|
|
32733
32735
|
return addSignature(
|
|
@@ -33036,19 +33038,26 @@ var validateOperationLog = async (did, ops) => {
|
|
|
33036
33038
|
throw new MisorderedOperationError();
|
|
33037
33039
|
}
|
|
33038
33040
|
await assureValidSig(doc.rotationKeys, op);
|
|
33039
|
-
|
|
33041
|
+
const data = opToData(did, op);
|
|
33042
|
+
if (data === null) {
|
|
33040
33043
|
if (i === rest.length - 1) {
|
|
33041
33044
|
return null;
|
|
33042
33045
|
} else {
|
|
33043
33046
|
throw new MisorderedOperationError();
|
|
33044
33047
|
}
|
|
33045
33048
|
}
|
|
33046
|
-
|
|
33047
|
-
doc = { did, verificationMethods, rotationKeys, alsoKnownAs, services };
|
|
33049
|
+
doc = data;
|
|
33048
33050
|
prev = await (0, import_common13.cidForCbor)(op);
|
|
33049
33051
|
}
|
|
33050
33052
|
return doc;
|
|
33051
33053
|
};
|
|
33054
|
+
var opToData = (did, op) => {
|
|
33055
|
+
if (import_common13.check.is(op, def.tombstone)) {
|
|
33056
|
+
return null;
|
|
33057
|
+
}
|
|
33058
|
+
const { verificationMethods, rotationKeys, alsoKnownAs, services } = normalizeOp(op);
|
|
33059
|
+
return { did, verificationMethods, rotationKeys, alsoKnownAs, services };
|
|
33060
|
+
};
|
|
33052
33061
|
var getLastOpWithCid = async (ops) => {
|
|
33053
33062
|
const op = ops.at(-1);
|
|
33054
33063
|
if (!op) {
|
|
@@ -33132,7 +33141,6 @@ var formatKeyAndContext = (key) => {
|
|
|
33132
33141
|
assureValidOp,
|
|
33133
33142
|
assureValidSig,
|
|
33134
33143
|
atprotoOp,
|
|
33135
|
-
createAtprotoUpdateOp,
|
|
33136
33144
|
createOp,
|
|
33137
33145
|
createUpdateOp,
|
|
33138
33146
|
def,
|
|
@@ -33149,6 +33157,7 @@ var formatKeyAndContext = (key) => {
|
|
|
33149
33157
|
getLastOpWithCid,
|
|
33150
33158
|
indexedOperation,
|
|
33151
33159
|
normalizeOp,
|
|
33160
|
+
opToData,
|
|
33152
33161
|
signOperation,
|
|
33153
33162
|
tombstoneOp,
|
|
33154
33163
|
updateAtprotoKeyOp,
|