@enbox/api 0.0.1

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.
Files changed (92) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +585 -0
  3. package/dist/browser.js +2226 -0
  4. package/dist/browser.js.map +7 -0
  5. package/dist/browser.mjs +2226 -0
  6. package/dist/browser.mjs.map +7 -0
  7. package/dist/cjs/did-api.js +126 -0
  8. package/dist/cjs/did-api.js.map +1 -0
  9. package/dist/cjs/dwn-api.js +804 -0
  10. package/dist/cjs/dwn-api.js.map +1 -0
  11. package/dist/cjs/grant-revocation.js +183 -0
  12. package/dist/cjs/grant-revocation.js.map +1 -0
  13. package/dist/cjs/index.js +63 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/permission-grant.js +365 -0
  17. package/dist/cjs/permission-grant.js.map +1 -0
  18. package/dist/cjs/permission-request.js +272 -0
  19. package/dist/cjs/permission-request.js.map +1 -0
  20. package/dist/cjs/protocol.js +110 -0
  21. package/dist/cjs/protocol.js.map +1 -0
  22. package/dist/cjs/record.js +1127 -0
  23. package/dist/cjs/record.js.map +1 -0
  24. package/dist/cjs/subscription-util.js +86 -0
  25. package/dist/cjs/subscription-util.js.map +1 -0
  26. package/dist/cjs/utils.js +127 -0
  27. package/dist/cjs/utils.js.map +1 -0
  28. package/dist/cjs/vc-api.js +64 -0
  29. package/dist/cjs/vc-api.js.map +1 -0
  30. package/dist/cjs/web5.js +471 -0
  31. package/dist/cjs/web5.js.map +1 -0
  32. package/dist/esm/did-api.js +69 -0
  33. package/dist/esm/did-api.js.map +1 -0
  34. package/dist/esm/dwn-api.js +573 -0
  35. package/dist/esm/dwn-api.js.map +1 -0
  36. package/dist/esm/grant-revocation.js +109 -0
  37. package/dist/esm/grant-revocation.js.map +1 -0
  38. package/dist/esm/index.js +34 -0
  39. package/dist/esm/index.js.map +1 -0
  40. package/dist/esm/permission-grant.js +233 -0
  41. package/dist/esm/permission-grant.js.map +1 -0
  42. package/dist/esm/permission-request.js +166 -0
  43. package/dist/esm/permission-request.js.map +1 -0
  44. package/dist/esm/protocol.js +67 -0
  45. package/dist/esm/protocol.js.map +1 -0
  46. package/dist/esm/record.js +814 -0
  47. package/dist/esm/record.js.map +1 -0
  48. package/dist/esm/subscription-util.js +35 -0
  49. package/dist/esm/subscription-util.js.map +1 -0
  50. package/dist/esm/utils.js +120 -0
  51. package/dist/esm/utils.js.map +1 -0
  52. package/dist/esm/vc-api.js +30 -0
  53. package/dist/esm/vc-api.js.map +1 -0
  54. package/dist/esm/web5.js +281 -0
  55. package/dist/esm/web5.js.map +1 -0
  56. package/dist/types/did-api.d.ts +66 -0
  57. package/dist/types/did-api.d.ts.map +1 -0
  58. package/dist/types/dwn-api.d.ts +336 -0
  59. package/dist/types/dwn-api.d.ts.map +1 -0
  60. package/dist/types/grant-revocation.d.ts +66 -0
  61. package/dist/types/grant-revocation.d.ts.map +1 -0
  62. package/dist/types/index.d.ts +34 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/permission-grant.d.ts +157 -0
  65. package/dist/types/permission-grant.d.ts.map +1 -0
  66. package/dist/types/permission-request.d.ts +108 -0
  67. package/dist/types/permission-request.d.ts.map +1 -0
  68. package/dist/types/protocol.d.ts +59 -0
  69. package/dist/types/protocol.d.ts.map +1 -0
  70. package/dist/types/record.d.ts +441 -0
  71. package/dist/types/record.d.ts.map +1 -0
  72. package/dist/types/subscription-util.d.ts +19 -0
  73. package/dist/types/subscription-util.d.ts.map +1 -0
  74. package/dist/types/utils.d.ts +85 -0
  75. package/dist/types/utils.d.ts.map +1 -0
  76. package/dist/types/vc-api.d.ts +24 -0
  77. package/dist/types/vc-api.d.ts.map +1 -0
  78. package/dist/types/web5.d.ts +219 -0
  79. package/dist/types/web5.d.ts.map +1 -0
  80. package/package.json +111 -0
  81. package/src/did-api.ts +90 -0
  82. package/src/dwn-api.ts +952 -0
  83. package/src/grant-revocation.ts +124 -0
  84. package/src/index.ts +35 -0
  85. package/src/permission-grant.ts +327 -0
  86. package/src/permission-request.ts +214 -0
  87. package/src/protocol.ts +87 -0
  88. package/src/record.ts +1125 -0
  89. package/src/subscription-util.ts +42 -0
  90. package/src/utils.ts +128 -0
  91. package/src/vc-api.ts +30 -0
  92. package/src/web5.ts +516 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * NOTE: Added reference types here to avoid a `pnpm` bug during build.
3
+ * https://github.com/TBD54566975/web5-js/pull/507
4
+ */
5
+ /// <reference types="@enbox/dwn-sdk-js" />
6
+
7
+ import type { DwnMessage, DwnResponseStatus, Web5Agent } from '@enbox/agent';
8
+
9
+ import { DwnInterface } from '@enbox/agent';
10
+
11
+ /**
12
+ * Represents metadata associated with a protocol, including the author and an optional message CID.
13
+ */
14
+ export type ProtocolMetadata = {
15
+ /** The author of the protocol. */
16
+ author: string;
17
+
18
+ /**
19
+ * The Content Identifier (CID) of a ProtocolsConfigure message.
20
+ *
21
+ * This is an optional field, and is used by {@link Protocol.send}.
22
+ */
23
+ messageCid?: string;
24
+ };
25
+
26
+ /**
27
+ * Encapsulates a DWN Protocol with its associated metadata and configuration.
28
+ *
29
+ * This class primarly exists to provide developers with a convenient way to configure/install
30
+ * protocols on remote DWNs.
31
+ */
32
+ export class Protocol {
33
+ /** The {@link Web5Agent} instance that handles DWNs requests. */
34
+ private _agent: Web5Agent;
35
+
36
+ /** The ProtocolsConfigureMessage containing the detailed configuration for the protocol. */
37
+ private _metadata: ProtocolMetadata;
38
+
39
+ /** Metadata associated with the protocol, including the author and optional message CID. */
40
+ private _protocolsConfigureMessage: DwnMessage[DwnInterface.ProtocolsConfigure];
41
+
42
+ /**
43
+ * Constructs a new instance of the Protocol class.
44
+ *
45
+ * @param agent - The Web5Agent instance used for network interactions.
46
+ * @param protocolsConfigureMessage - The configuration message containing the protocol details.
47
+ * @param metadata - Metadata associated with the protocol, including the author and optional message CID.
48
+ */
49
+ constructor(agent: Web5Agent, protocolsConfigureMessage: DwnMessage[DwnInterface.ProtocolsConfigure], metadata: ProtocolMetadata) {
50
+ this._agent = agent;
51
+ this._metadata = metadata;
52
+ this._protocolsConfigureMessage = protocolsConfigureMessage;
53
+ }
54
+
55
+ /**
56
+ * Retrieves the protocol definition from the protocol's configuration message.
57
+ * @returns The protocol definition.
58
+ */
59
+ get definition() {
60
+ return this._protocolsConfigureMessage.descriptor.definition;
61
+ }
62
+
63
+ /**
64
+ * Serializes the protocol's configuration message to JSON.
65
+ * @returns The serialized JSON object of the protocol's configuration message.
66
+ */
67
+ toJSON() {
68
+ return this._protocolsConfigureMessage;
69
+ }
70
+
71
+ /**
72
+ * Sends the protocol configuration to a remote DWN identified by the target DID.
73
+ *
74
+ * @param target - The DID of the target DWN to which the protocol configuration will be installed.
75
+ * @returns A promise that resolves to an object containing the status of the send operation.
76
+ */
77
+ async send(target: string): Promise<DwnResponseStatus> {
78
+ const { reply } = await this._agent.sendDwnRequest({
79
+ author : this._metadata.author,
80
+ messageCid : this._metadata.messageCid,
81
+ messageType : DwnInterface.ProtocolsConfigure,
82
+ target : target,
83
+ });
84
+
85
+ return { status: reply.status };
86
+ }
87
+ }