@did-plc/lib 0.0.2 → 0.0.3

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 CHANGED
@@ -22,23 +22,23 @@ export declare class Client {
22
22
  }): Promise<string>;
23
23
  ensureLastOp(did: any): Promise<{
24
24
  type: "create";
25
- service: string;
26
25
  signingKey: string;
27
26
  recoveryKey: string;
28
27
  handle: string;
28
+ service: string;
29
29
  prev: null;
30
30
  sig: string;
31
31
  } | {
32
32
  type: "plc_operation";
33
- alsoKnownAs: string[];
33
+ prev: string | null;
34
+ sig: string;
34
35
  rotationKeys: string[];
35
36
  verificationMethods: Record<string, string>;
37
+ alsoKnownAs: string[];
36
38
  services: Record<string, {
37
39
  type: string;
38
40
  endpoint: string;
39
41
  }>;
40
- prev: string | null;
41
- sig: string;
42
42
  }>;
43
43
  updateData(did: string, signer: Keypair, fn: (lastOp: t.UnsignedOperation) => Omit<t.UnsignedOperation, 'prev'>): Promise<void>;
44
44
  updateAtprotoKey(did: string, signer: Keypair, atprotoKey: string): Promise<void>;
package/dist/index.js CHANGED
@@ -24337,6 +24337,7 @@ __export(src_exports2, {
24337
24337
  assureValidOp: () => assureValidOp,
24338
24338
  assureValidSig: () => assureValidSig,
24339
24339
  atprotoOp: () => atprotoOp,
24340
+ createAtprotoUpdateOp: () => createAtprotoUpdateOp,
24340
24341
  createOp: () => createOp,
24341
24342
  createUpdateOp: () => createUpdateOp,
24342
24343
  def: () => def,
@@ -32676,59 +32677,57 @@ var createUpdateOp = async (lastOp, signer, fn) => {
32676
32677
  signer
32677
32678
  );
32678
32679
  };
32679
- var updateAtprotoKeyOp = async (lastOp, signer, atprotoKey) => {
32680
- return createUpdateOp(lastOp, signer, (normalized) => ({
32681
- ...normalized,
32682
- verificationMethods: {
32683
- ...normalized.verificationMethods,
32684
- atproto: atprotoKey
32685
- }
32686
- }));
32687
- };
32688
- var updateHandleOp = async (lastOp, signer, handle) => {
32689
- const formatted = ensureAtprotoPrefix(handle);
32680
+ var createAtprotoUpdateOp = async (lastOp, signer, opts) => {
32690
32681
  return createUpdateOp(lastOp, signer, (normalized) => {
32691
- const handleI = normalized.alsoKnownAs.findIndex(
32692
- (h) => h.startsWith("at://")
32693
- );
32694
- let aka;
32695
- if (handleI < 0) {
32696
- aka = [formatted, ...normalized.alsoKnownAs];
32697
- } else {
32698
- aka = [
32699
- ...normalized.alsoKnownAs.slice(0, handleI),
32700
- formatted,
32701
- ...normalized.alsoKnownAs.slice(handleI + 1)
32702
- ];
32682
+ const updated = { ...normalized };
32683
+ if (opts.signingKey) {
32684
+ updated.verificationMethods = {
32685
+ ...normalized.verificationMethods,
32686
+ atproto: opts.signingKey
32687
+ };
32703
32688
  }
32704
- return {
32705
- ...normalized,
32706
- alsoKnownAs: aka
32707
- };
32708
- });
32709
- };
32710
- var updatePdsOp = async (lastOp, signer, endpoint) => {
32711
- const formatted = ensureHttpPrefix(endpoint);
32712
- return createUpdateOp(lastOp, signer, (normalized) => {
32713
- return {
32714
- ...normalized,
32715
- services: {
32689
+ if (opts.handle) {
32690
+ const formatted = ensureAtprotoPrefix(opts.handle);
32691
+ const handleI = normalized.alsoKnownAs.findIndex(
32692
+ (h) => h.startsWith("at://")
32693
+ );
32694
+ if (handleI < 0) {
32695
+ updated.alsoKnownAs = [formatted, ...normalized.alsoKnownAs];
32696
+ } else {
32697
+ updated.alsoKnownAs = [
32698
+ ...normalized.alsoKnownAs.slice(0, handleI),
32699
+ formatted,
32700
+ ...normalized.alsoKnownAs.slice(handleI + 1)
32701
+ ];
32702
+ }
32703
+ }
32704
+ if (opts.pds) {
32705
+ const formatted = ensureHttpPrefix(opts.pds);
32706
+ updated.services = {
32716
32707
  ...normalized.services,
32717
32708
  atproto_pds: {
32718
32709
  type: "AtprotoPersonalDataServer",
32719
32710
  endpoint: formatted
32720
32711
  }
32721
- }
32722
- };
32712
+ };
32713
+ }
32714
+ if (opts.rotationKeys) {
32715
+ updated.rotationKeys = opts.rotationKeys;
32716
+ }
32717
+ return updated;
32723
32718
  });
32724
32719
  };
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
+ };
32725
32729
  var updateRotationKeysOp = async (lastOp, signer, rotationKeys) => {
32726
- return createUpdateOp(lastOp, signer, (normalized) => {
32727
- return {
32728
- ...normalized,
32729
- rotationKeys
32730
- };
32731
- });
32730
+ return createAtprotoUpdateOp(lastOp, signer, { rotationKeys });
32732
32731
  };
32733
32732
  var tombstoneOp = async (prev, key) => {
32734
32733
  return addSignature(
@@ -33133,6 +33132,7 @@ var formatKeyAndContext = (key) => {
33133
33132
  assureValidOp,
33134
33133
  assureValidSig,
33135
33134
  atprotoOp,
33135
+ createAtprotoUpdateOp,
33136
33136
  createOp,
33137
33137
  createUpdateOp,
33138
33138
  def,