@didcid/keymaster 0.3.9 → 0.4.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 CHANGED
@@ -234,11 +234,11 @@ keymaster list-ids
234
234
  | `create-asset` | Create empty asset |
235
235
  | `create-asset-json <file>` | Create from JSON file |
236
236
  | `create-asset-image <file>` | Create from image |
237
- | `create-asset-document <file>` | Create from document |
237
+ | `create-asset-file <file>` | Create from file |
238
238
  | `get-asset <id>` | Get asset by ID |
239
239
  | `update-asset-json <id> <file>` | Update with JSON |
240
240
  | `update-asset-image <id> <file>` | Update with image |
241
- | `update-asset-document <id> <file>` | Update with document |
241
+ | `update-asset-file <id> <file>` | Update with file |
242
242
  | `transfer-asset <id> <controller>` | Transfer ownership |
243
243
  | `clone-asset <id>` | Clone an asset |
244
244
  | `set-property <id> <key> [value]` | Set asset property |
@@ -13,7 +13,6 @@ var db_typeGuards = require('./db/typeGuards.cjs');
13
13
  require('image-size');
14
14
  require('file-type');
15
15
  require('crypto');
16
- require('./encryption.cjs');
17
16
  require('buffer');
18
17
  require('axios');
19
18
 
@@ -679,9 +679,9 @@ class KeymasterClient {
679
679
  throwError(error);
680
680
  }
681
681
  }
682
- async createPoll(poll, options) {
682
+ async createPoll(config, options) {
683
683
  try {
684
- const response = await axios.post(`${this.API}/polls`, { poll, options });
684
+ const response = await axios.post(`${this.API}/polls`, { poll: config, options });
685
685
  return response.data.did;
686
686
  }
687
687
  catch (error) {
@@ -697,6 +697,24 @@ class KeymasterClient {
697
697
  throwError(error);
698
698
  }
699
699
  }
700
+ async testPoll(id) {
701
+ try {
702
+ const response = await axios.get(`${this.API}/polls/${id}/test`);
703
+ return response.data.test;
704
+ }
705
+ catch (error) {
706
+ throwError(error);
707
+ }
708
+ }
709
+ async listPolls(owner) {
710
+ try {
711
+ const response = await axios.get(`${this.API}/polls`, { params: { owner } });
712
+ return response.data.polls;
713
+ }
714
+ catch (error) {
715
+ throwError(error);
716
+ }
717
+ }
700
718
  async viewPoll(pollId) {
701
719
  try {
702
720
  const response = await axios.get(`${this.API}/polls/${pollId}/view`);
@@ -715,6 +733,33 @@ class KeymasterClient {
715
733
  throwError(error);
716
734
  }
717
735
  }
736
+ async sendPoll(pollId) {
737
+ try {
738
+ const response = await axios.post(`${this.API}/polls/${pollId}/send`);
739
+ return response.data.did;
740
+ }
741
+ catch (error) {
742
+ throwError(error);
743
+ }
744
+ }
745
+ async sendBallot(ballotDid, pollId) {
746
+ try {
747
+ const response = await axios.post(`${this.API}/polls/ballot/send`, { ballot: ballotDid, poll: pollId });
748
+ return response.data.did;
749
+ }
750
+ catch (error) {
751
+ throwError(error);
752
+ }
753
+ }
754
+ async viewBallot(ballotDid) {
755
+ try {
756
+ const response = await axios.get(`${this.API}/polls/ballot/${ballotDid}`);
757
+ return response.data.ballot;
758
+ }
759
+ catch (error) {
760
+ throwError(error);
761
+ }
762
+ }
718
763
  async updatePoll(ballot) {
719
764
  try {
720
765
  const response = await axios.put(`${this.API}/polls/update`, { ballot });
@@ -742,13 +787,40 @@ class KeymasterClient {
742
787
  throwError(error);
743
788
  }
744
789
  }
790
+ async addPollVoter(pollId, memberId) {
791
+ try {
792
+ const response = await axios.post(`${this.API}/polls/${pollId}/voters`, { memberId });
793
+ return response.data.ok;
794
+ }
795
+ catch (error) {
796
+ throwError(error);
797
+ }
798
+ }
799
+ async removePollVoter(pollId, memberId) {
800
+ try {
801
+ const response = await axios.delete(`${this.API}/polls/${pollId}/voters/${memberId}`);
802
+ return response.data.ok;
803
+ }
804
+ catch (error) {
805
+ throwError(error);
806
+ }
807
+ }
808
+ async listPollVoters(pollId) {
809
+ try {
810
+ const response = await axios.get(`${this.API}/polls/${pollId}/voters`);
811
+ return response.data.voters;
812
+ }
813
+ catch (error) {
814
+ throwError(error);
815
+ }
816
+ }
745
817
  async createImage(data, options = {}) {
746
818
  try {
747
819
  const response = await axios.post(`${this.API}/images`, data, {
748
820
  headers: {
749
821
  // eslint-disable-next-line
750
822
  'Content-Type': 'application/octet-stream',
751
- 'X-Options': JSON.stringify(options), // Pass options as a custom header
823
+ 'X-Options': JSON.stringify(options),
752
824
  }
753
825
  });
754
826
  return response.data.did;
@@ -757,11 +829,12 @@ class KeymasterClient {
757
829
  throwError(error);
758
830
  }
759
831
  }
760
- async updateImage(id, data) {
832
+ async updateImage(id, data, options = {}) {
761
833
  try {
762
834
  const response = await axios.put(`${this.API}/images/${id}`, data, {
763
835
  headers: {
764
- 'Content-Type': 'application/octet-stream'
836
+ 'Content-Type': 'application/octet-stream',
837
+ 'X-Options': JSON.stringify(options),
765
838
  }
766
839
  });
767
840
  return response.data.ok;
@@ -773,7 +846,7 @@ class KeymasterClient {
773
846
  async getImage(id) {
774
847
  try {
775
848
  const response = await axios.get(`${this.API}/images/${id}`);
776
- return response.data.image;
849
+ return response.data;
777
850
  }
778
851
  catch (error) {
779
852
  throwError(error);
@@ -788,9 +861,9 @@ class KeymasterClient {
788
861
  throwError(error);
789
862
  }
790
863
  }
791
- async createDocument(data, options = {}) {
864
+ async createFile(data, options = {}) {
792
865
  try {
793
- const response = await axios.post(`${this.API}/documents`, data, {
866
+ const response = await axios.post(`${this.API}/files`, data, {
794
867
  headers: {
795
868
  'Content-Type': 'application/octet-stream',
796
869
  'X-Options': JSON.stringify(options), // Pass options as a custom header
@@ -802,9 +875,9 @@ class KeymasterClient {
802
875
  throwError(error);
803
876
  }
804
877
  }
805
- async updateDocument(id, data, options = {}) {
878
+ async updateFile(id, data, options = {}) {
806
879
  try {
807
- const response = await axios.put(`${this.API}/documents/${id}`, data, {
880
+ const response = await axios.put(`${this.API}/files/${id}`, data, {
808
881
  headers: {
809
882
  'Content-Type': 'application/octet-stream',
810
883
  'X-Options': JSON.stringify(options), // Pass options as a custom header
@@ -816,18 +889,18 @@ class KeymasterClient {
816
889
  throwError(error);
817
890
  }
818
891
  }
819
- async getDocument(id) {
892
+ async getFile(id) {
820
893
  try {
821
- const response = await axios.get(`${this.API}/documents/${id}`);
822
- return response.data.document;
894
+ const response = await axios.get(`${this.API}/files/${id}`);
895
+ return response.data.file;
823
896
  }
824
897
  catch (error) {
825
898
  throwError(error);
826
899
  }
827
900
  }
828
- async testDocument(id) {
901
+ async testFile(id) {
829
902
  try {
830
- const response = await axios.post(`${this.API}/documents/${id}/test`);
903
+ const response = await axios.post(`${this.API}/files/${id}/test`);
831
904
  return response.data.test;
832
905
  }
833
906
  catch (error) {