@didcid/keymaster 0.4.2 → 0.4.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.
@@ -697,6 +697,24 @@ export default class Keymaster {
697
697
  const file = await this.generateFileAsset(filename, buffer);
698
698
  return this.mergeData(id, { file });
699
699
  }
700
+ async generateFileAssetFromStream(filename, stream, contentType, bytes) {
701
+ const cid = await this.gatekeeper.addDataStream(stream);
702
+ return { cid, filename, type: contentType, bytes };
703
+ }
704
+ async createFileStream(stream, options = {}) {
705
+ const filename = options.filename || 'file';
706
+ const contentType = options.contentType || 'application/octet-stream';
707
+ const bytes = options.bytes || 0;
708
+ const file = await this.generateFileAssetFromStream(filename, stream, contentType, bytes);
709
+ return this.createAsset({ file }, options);
710
+ }
711
+ async updateFileStream(id, stream, options = {}) {
712
+ const filename = options.filename || 'file';
713
+ const contentType = options.contentType || 'application/octet-stream';
714
+ const bytes = options.bytes || 0;
715
+ const file = await this.generateFileAssetFromStream(filename, stream, contentType, bytes);
716
+ return this.mergeData(id, { file });
717
+ }
700
718
  async getFile(id) {
701
719
  const asset = await this.resolveAsset(id);
702
720
  const file = asset.file;
@@ -901,6 +919,23 @@ export default class Keymaster {
901
919
  }
902
920
  return ok;
903
921
  }
922
+ async changeRegistry(id, registry) {
923
+ if (!registry) {
924
+ throw new InvalidParameterError('registry');
925
+ }
926
+ const did = await this.lookupDID(id);
927
+ const current = await this.resolveDID(did);
928
+ const currentRegistry = current.didDocumentRegistration?.registry;
929
+ if (registry === currentRegistry) {
930
+ return true;
931
+ }
932
+ return this.updateDID(did, {
933
+ didDocumentRegistration: {
934
+ ...current.didDocumentRegistration,
935
+ registry,
936
+ },
937
+ });
938
+ }
904
939
  async addToOwned(did, owner) {
905
940
  await this.mutateWallet(async (wallet) => {
906
941
  const id = await this.fetchIdInfo(owner, wallet);
@@ -1518,16 +1553,29 @@ export default class Keymaster {
1518
1553
  return true;
1519
1554
  }
1520
1555
  async zapLightning(id, amount, memo, name) {
1521
- const did = await this.lookupDID(id);
1522
- if (!did) {
1523
- throw new InvalidParameterError('did');
1556
+ const isLud16 = id.includes('@') && !id.startsWith('did:');
1557
+ let recipient;
1558
+ if (isLud16) {
1559
+ recipient = id;
1560
+ }
1561
+ else {
1562
+ const did = await this.lookupDID(id);
1563
+ if (!did) {
1564
+ throw new InvalidParameterError('did');
1565
+ }
1566
+ recipient = did;
1524
1567
  }
1525
1568
  if (!amount || amount <= 0) {
1526
1569
  throw new InvalidParameterError('amount');
1527
1570
  }
1528
1571
  const drawbridge = this.requireDrawbridge();
1529
1572
  const config = await this.getLightningConfig(name);
1530
- return drawbridge.zapLightning(config.adminKey, did, amount, memo);
1573
+ return drawbridge.zapLightning(config.adminKey, recipient, amount, memo);
1574
+ }
1575
+ async getLightningPayments(name) {
1576
+ const drawbridge = this.requireDrawbridge();
1577
+ const config = await this.getLightningConfig(name);
1578
+ return drawbridge.getLightningPayments(config.adminKey);
1531
1579
  }
1532
1580
  async testAgent(id) {
1533
1581
  const doc = await this.resolveDID(id);