keri 0.0.0-dev.0ddd65e → 0.0.0-dev.7be936b

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 (73) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/dist/cli/main.d.ts +1 -1
  4. package/dist/cli/main.js +159 -56
  5. package/dist/cli/main.js.map +1 -0
  6. package/dist/client.d.ts +21 -0
  7. package/dist/client.js +72 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/controller.d.ts +64 -0
  10. package/dist/controller.js +472 -0
  11. package/dist/controller.js.map +1 -0
  12. package/dist/db/storage-sqlite.d.ts +12 -0
  13. package/dist/db/storage-sqlite.js +53 -0
  14. package/dist/db/storage-sqlite.js.map +1 -0
  15. package/dist/db/storage.d.ts +18 -0
  16. package/dist/db/storage.js +29 -0
  17. package/dist/db/storage.js.map +1 -0
  18. package/dist/events/event-store.d.ts +126 -0
  19. package/dist/events/event-store.js +242 -0
  20. package/dist/events/event-store.js.map +1 -0
  21. package/dist/events/events.d.ts +248 -0
  22. package/dist/events/events.js +184 -0
  23. package/dist/events/events.js.map +1 -0
  24. package/dist/keystore/encrypt.d.ts +10 -2
  25. package/dist/keystore/encrypt.js +26 -25
  26. package/dist/keystore/encrypt.js.map +1 -0
  27. package/dist/keystore/keystore.d.ts +16 -2
  28. package/dist/keystore/keystore.js +70 -1
  29. package/dist/keystore/keystore.js.map +1 -0
  30. package/dist/main.d.ts +6 -2
  31. package/dist/main.js +7 -2
  32. package/dist/main.js.map +1 -0
  33. package/package.json +27 -24
  34. package/dist/data-type.d.ts +0 -9
  35. package/dist/data-type.js +0 -1
  36. package/dist/db/event-store.d.ts +0 -20
  37. package/dist/db/event-store.js +0 -1
  38. package/dist/db/sqlite-db.d.ts +0 -13
  39. package/dist/db/sqlite-db.js +0 -123
  40. package/dist/events/common.d.ts +0 -6
  41. package/dist/events/common.js +0 -1
  42. package/dist/events/incept.d.ts +0 -26
  43. package/dist/events/incept.js +0 -28
  44. package/dist/events/interact.d.ts +0 -17
  45. package/dist/events/interact.js +0 -21
  46. package/dist/events/main.d.ts +0 -4
  47. package/dist/events/main.js +0 -4
  48. package/dist/events/reply.d.ts +0 -15
  49. package/dist/events/reply.js +0 -20
  50. package/dist/keri/habitat.d.ts +0 -20
  51. package/dist/keri/habitat.js +0 -130
  52. package/dist/keri/keri.d.ts +0 -26
  53. package/dist/keri/keri.js +0 -43
  54. package/dist/keystore/keystore-fs.d.ts +0 -13
  55. package/dist/keystore/keystore-fs.js +0 -50
  56. package/dist/keystore/keystore-web.d.ts +0 -12
  57. package/dist/keystore/keystore-web.js +0 -48
  58. package/dist/main-common.d.ts +0 -9
  59. package/dist/main-common.js +0 -8
  60. package/dist/main-web.d.ts +0 -2
  61. package/dist/main-web.js +0 -2
  62. package/dist/parser/base64.d.ts +0 -6
  63. package/dist/parser/base64.js +0 -74
  64. package/dist/parser/buffered-reader.d.ts +0 -5
  65. package/dist/parser/buffered-reader.js +0 -47
  66. package/dist/parser/cesr-encoding.d.ts +0 -34
  67. package/dist/parser/cesr-encoding.js +0 -158
  68. package/dist/parser/codes.d.ts +0 -143
  69. package/dist/parser/codes.js +0 -266
  70. package/dist/parser/parser.d.ts +0 -16
  71. package/dist/parser/parser.js +0 -161
  72. package/dist/parser/version.d.ts +0 -11
  73. package/dist/parser/version.js +0 -56
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # KERI for JS
2
+
3
+ Work in progress KERI library for javascript.
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env -S node --no-warnings
2
2
  export {};
package/dist/cli/main.js CHANGED
@@ -1,72 +1,175 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env -S node --no-warnings
2
2
  import { program } from "commander";
3
- import { parse } from "../parser/parser.js";
4
- import { FileSystemKeyStore } from "../keystore/keystore-fs.js";
5
- import { SqliteEventStore } from "../db/sqlite-db.js";
6
- import { Habitat } from "../keri/habitat.js";
7
- const db = new SqliteEventStore({ filename: ".keri/db.sqlite" });
8
- db.init();
9
- program.command("parse").action(async () => {
10
- const stream = process.stdin;
11
- for await (const event of parse(ReadableStream.from(stream))) {
12
- console.log(event);
3
+ import { Controller } from "../controller.js";
4
+ import { SqliteStorage } from "../db/storage-sqlite.js";
5
+ import { KeyStore } from "../keystore/keystore.js";
6
+ import { keri } from "../events/events.js";
7
+ import { PassphraseEncrypter } from "../keystore/encrypt.js";
8
+ const storage = new SqliteStorage({ filename: ".keri/db.sqlite" });
9
+ storage.init();
10
+ function getStringArray(options, key) {
11
+ if (typeof options !== "object" || options === null || !(key in options)) {
12
+ return [];
13
13
  }
14
- });
15
- program
16
- .command("keygen")
17
- .requiredOption("--passcode <passcode>")
18
- .action(async ({ passcode }) => {
19
- const keystore = new FileSystemKeyStore({ dir: ".keri/keys", passphrase: passcode });
20
- await keystore.incept();
21
- });
22
- program.command("resolve <oobi>").action(async (oobi) => {
23
- const response = await fetch(oobi);
24
- if (!response.ok) {
25
- throw new Error(`Failed to fetch oobi: ${response.status} ${response.statusText}`);
14
+ const value = options[key];
15
+ const result = [];
16
+ if (typeof value === "string") {
17
+ result.push(value);
18
+ }
19
+ else if (Array.isArray(value)) {
20
+ result.push(...value);
26
21
  }
27
- if (!response.body) {
28
- throw new Error(`No body in response`);
22
+ return result;
23
+ }
24
+ function getOptionalString(options, key) {
25
+ if (typeof options !== "object" || options === null) {
26
+ throw new Error(`Options is not an object`);
29
27
  }
30
- for await (const event of parse(response.body)) {
31
- db.saveEvent(event.payload);
28
+ const value = options[key];
29
+ if (value !== undefined && typeof value !== "string") {
30
+ throw new Error(`Expected "${key}" to be a string, got "${typeof value}"`);
32
31
  }
32
+ return value;
33
+ }
34
+ function getString(options, key) {
35
+ const value = getOptionalString(options, key);
36
+ if (!value) {
37
+ throw new Error(`Expected "${key}" to be a string, got "${value}"`);
38
+ }
39
+ return value;
40
+ }
41
+ program.command("resolve <oobi>").action(async (oobi) => {
42
+ const controller = new Controller({
43
+ storage,
44
+ keystore: new KeyStore({ storage, encrypter: new PassphraseEncrypter("") }),
45
+ });
46
+ await controller.resolve(oobi);
33
47
  });
34
48
  program
35
49
  .command("incept")
36
50
  .requiredOption("--passcode <passcode>")
37
- .option("--wit <wit>")
38
- .action(async ({ passcode, wit }) => {
39
- if (typeof passcode !== "string") {
40
- throw new Error(`Invalid passcode`);
41
- }
42
- const keystore = new FileSystemKeyStore({ dir: ".keri/keys", passphrase: passcode });
43
- const hab = new Habitat({ db, keystore });
44
- const wits = [];
45
- if (typeof wit === "string") {
46
- wits.push(wit);
47
- }
48
- const result = await hab.create({ wits });
49
- console.dir(result);
51
+ .option("--wit <wit...>")
52
+ .action(async (options) => {
53
+ const passcode = getString(options, "passcode");
54
+ const wits = getStringArray(options, "wit");
55
+ const encrypter = new PassphraseEncrypter(passcode);
56
+ const keystore = new KeyStore({ encrypter, storage });
57
+ const controller = new Controller({ storage, keystore });
58
+ const event = await controller.createIdentifier({ wits });
59
+ console.log(event.i);
50
60
  });
51
61
  program
52
- .command("interact")
62
+ .command("send")
63
+ .description("Sends a signed exchange message to the specified recipient")
64
+ .requiredOption("--sender <sender aid>")
65
+ .requiredOption("--route <route>")
66
+ .requiredOption("--topic <topic>")
67
+ .requiredOption("--receiver <receiver aid>")
53
68
  .requiredOption("--passcode <passcode>")
54
- .requiredOption("--aid <aid>")
55
- .action(async ({ passcode, aid }) => {
56
- if (typeof passcode !== "string") {
57
- throw new Error(`Invalid passcode`);
58
- }
59
- if (typeof aid !== "string") {
60
- throw new Error(`Invalid aid`);
61
- }
62
- const keystore = new FileSystemKeyStore({ dir: ".keri/keys", passphrase: passcode });
63
- const hab = new Habitat({ db, keystore });
64
- const payload = await hab.interact(aid);
65
- console.dir(payload);
69
+ .requiredOption("--data <data>")
70
+ .action(async (options) => {
71
+ const passcode = getString(options, "passcode");
72
+ const sender = getString(options, "sender");
73
+ const receiver = getString(options, "receiver");
74
+ const route = getString(options, "route");
75
+ const topic = getString(options, "topic");
76
+ const data = JSON.parse(getString(options, "data"));
77
+ const keystore = new KeyStore({
78
+ storage,
79
+ encrypter: new PassphraseEncrypter(passcode),
80
+ });
81
+ const controller = new Controller({ storage, keystore });
82
+ const client = await controller.getClient(receiver);
83
+ await controller.forward(client, {
84
+ sender: await controller.state(sender),
85
+ topic,
86
+ recipient: receiver,
87
+ event: keri.exchange({
88
+ i: sender,
89
+ r: route,
90
+ q: {},
91
+ a: { i: sender, ...data },
92
+ e: {},
93
+ }),
94
+ });
95
+ });
96
+ program
97
+ .command("create-registry")
98
+ .description("Creates a new credential registry")
99
+ .requiredOption("--owner <owner aid>")
100
+ .requiredOption("--passcode <passcode>")
101
+ .action(async (options) => {
102
+ const passcode = getString(options, "passcode");
103
+ const owner = getString(options, "owner");
104
+ const keystore = new KeyStore({
105
+ storage,
106
+ encrypter: new PassphraseEncrypter(passcode),
107
+ });
108
+ const controller = new Controller({ storage, keystore });
109
+ const registry = await controller.createRegistry({ owner });
110
+ console.log(registry.i);
111
+ });
112
+ program
113
+ .command("create-credential")
114
+ .description("Creates a new credential")
115
+ .requiredOption("--registry <registry said>")
116
+ .requiredOption("--receiver <receiver aid>")
117
+ .requiredOption("--schema <schema said>")
118
+ .requiredOption("--data <data>")
119
+ .requiredOption("--rules <rules>")
120
+ .option("--salt <salt>")
121
+ .option("--edges <edges>")
122
+ .requiredOption("--passcode <passcode>")
123
+ .action(async (options) => {
124
+ const passcode = getString(options, "passcode");
125
+ const registryId = getString(options, "registry");
126
+ const receiver = getString(options, "receiver");
127
+ const schemaId = getString(options, "schema");
128
+ const salt = getOptionalString(options, "salt");
129
+ const data = JSON.parse(getString(options, "data"));
130
+ const rules = JSON.parse(getString(options, "rules"));
131
+ const edges = JSON.parse(getOptionalString(options, "edges") ?? "null");
132
+ const keystore = new KeyStore({
133
+ storage,
134
+ encrypter: new PassphraseEncrypter(passcode),
135
+ });
136
+ const controller = new Controller({ storage, keystore });
137
+ const acdc = await controller.createCredential({
138
+ holder: receiver,
139
+ registryId: registryId,
140
+ schemaId: schemaId,
141
+ data: data,
142
+ salt: salt,
143
+ rules: rules,
144
+ edges: edges || undefined,
145
+ });
146
+ console.log(acdc.d);
66
147
  });
67
- program.command("export").action(async () => {
68
- for (const event of await db.list()) {
69
- console.log(event);
148
+ program
149
+ .command("ipex-grant")
150
+ .requiredOption("--said <aid>")
151
+ .requiredOption("--passcode <passcode>")
152
+ .action(async (options) => {
153
+ const passcode = getString(options, "passcode");
154
+ const said = getString(options, "said");
155
+ const keystore = new KeyStore({
156
+ storage,
157
+ encrypter: new PassphraseEncrypter(passcode),
158
+ });
159
+ const controller = new Controller({
160
+ storage,
161
+ keystore,
162
+ });
163
+ const acdc = (await controller.store.get(said))?.event;
164
+ if (!acdc) {
165
+ throw new Error(`No ACDC found for said ${said}`);
166
+ }
167
+ if (acdc.a.i) {
168
+ await controller.sendCredentialArficats(acdc, acdc.a.i);
70
169
  }
170
+ await controller.grant({
171
+ credential: acdc,
172
+ });
71
173
  });
72
174
  program.parse(process.argv);
175
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAwB,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC,C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,CAAC;KAC9B,cAAc,CAAC,uBAAuB,CAAC;KACvC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAExC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;QAC5B,OAAO;QACP,SAAS,EAAE,IAAI,mBAAmB,CAAC,QAAQ,CAAC;KAC7C,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;QAChC,OAAO;QACP,QAAQ;KACT,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,KAAmC,CAAC;IACrF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACb,MAAM,UAAU,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,UAAU,CAAC,KAAK,CAAC;QACrB,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type KeyEvent, type ReceiptEvent } from "./events/events.ts";
2
+ import { type KeyEventMessage, type LocationRecord } from "./events/event-store.ts";
3
+ export interface Message {
4
+ event: KeyEvent;
5
+ attachment: string;
6
+ }
7
+ export interface SendArgs {
8
+ messages: Message[];
9
+ }
10
+ export interface ClientOptions {
11
+ role: string;
12
+ endpoint: LocationRecord;
13
+ }
14
+ export declare class Client {
15
+ #private;
16
+ role: string;
17
+ constructor(options: ClientOptions);
18
+ getReceipt(message: Message): Promise<KeyEventMessage<ReceiptEvent>>;
19
+ sendMessage(message: Message): Promise<void>;
20
+ }
21
+ export declare function parseKeyEvents(input: ReadableStream<Uint8Array>): AsyncIterableIterator<KeyEventMessage>;
package/dist/client.js ADDED
@@ -0,0 +1,72 @@
1
+ import { CountCode_10, parseMessages } from "cesr/__unstable__";
2
+ export class Client {
3
+ #location;
4
+ role;
5
+ constructor(options) {
6
+ this.#location = options.endpoint;
7
+ this.role = options.role;
8
+ }
9
+ async getReceipt(message) {
10
+ const url = new URL("/receipts", this.#location.url);
11
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
12
+ throw new Error(`Invalid protocol: ${url}`);
13
+ }
14
+ const response = await fetch(url, {
15
+ method: "POST",
16
+ body: JSON.stringify(message.event),
17
+ headers: {
18
+ "Content-Type": "application/cesr+json",
19
+ "CESR-ATTACHMENT": message.attachment,
20
+ },
21
+ });
22
+ if (!response.ok) {
23
+ throw new Error(`Failed to send event: ${response.status} ${response.statusText}`);
24
+ }
25
+ if (!response.body) {
26
+ throw new Error(`Failed to send event: ${response.status} ${response.statusText}`);
27
+ }
28
+ for await (const event of parseKeyEvents(response.body)) {
29
+ if (event.event.t === "rct" && event.event.d === message.event.d) {
30
+ return event;
31
+ }
32
+ }
33
+ throw new Error(`Failed to get receipt for event: ${response.status} ${response.statusText}`);
34
+ }
35
+ async sendMessage(message) {
36
+ const url = new URL("/", this.#location.url);
37
+ const response = await fetch(url, {
38
+ method: "POST",
39
+ body: JSON.stringify(message.event),
40
+ headers: {
41
+ "Content-Type": "application/cesr+json",
42
+ "CESR-ATTACHMENT": message.attachment,
43
+ "CESR-DESTINATION": this.#location.eid,
44
+ },
45
+ });
46
+ if (!response.ok) {
47
+ throw new Error(`Failed to send event: ${response.status} ${response.statusText}`);
48
+ }
49
+ }
50
+ }
51
+ export async function* parseKeyEvents(input) {
52
+ for await (const message of parseMessages(input)) {
53
+ const signatures = message.attachments[CountCode_10.ControllerIdxSigs]?.map((value) => value);
54
+ const receipts = decouple(message.attachments[CountCode_10.NonTransReceiptCouples] ?? []).map(([aid, sig]) => ({ backer: aid, signature: sig }));
55
+ yield {
56
+ event: message.payload,
57
+ receipts,
58
+ signatures,
59
+ timestamp: new Date(),
60
+ };
61
+ }
62
+ }
63
+ function decouple(arr) {
64
+ const result = [];
65
+ for (let i = 0; i < arr.length; i++) {
66
+ if (i % 2 === 0) {
67
+ result.push([arr[i], arr[i + 1]]);
68
+ }
69
+ }
70
+ return result;
71
+ }
72
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAkBhE,MAAM,OAAO,MAAM;IACjB,SAAS,CAAiB;IAC1B,IAAI,CAAS;IAEb,YAAY,OAAsB;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAgB;QAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC;YACnC,OAAO,EAAE;gBACP,cAAc,EAAE,uBAAuB;g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AAChB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { ControllerEventStore, type KeyValueStorage, type KeyEventMessage, type KeyEventSeal, type KeyState, type LocationRecord } from "./events/event-store.ts";
2
+ import type { Key, KeyStore } from "./keystore/keystore.ts";
3
+ import { type KeyEvent, type InteractEvent, type CredentialEvent, type RegistryInceptEvent } from "./events/events.ts";
4
+ import { Client } from "./client.ts";
5
+ export interface ControllerDeps {
6
+ keystore: KeyStore;
7
+ storage: KeyValueStorage;
8
+ }
9
+ export interface IpexGrantArgs {
10
+ credential: CredentialEvent;
11
+ recipient?: string;
12
+ timestamp?: string;
13
+ }
14
+ export interface ForwardArgs {
15
+ event: KeyEvent;
16
+ sender: KeyState;
17
+ topic: string;
18
+ recipient: string;
19
+ attachment?: string;
20
+ timestamp?: string;
21
+ }
22
+ export declare function serializeEventSeal(seal: KeyEventSeal): string;
23
+ export interface InceptArgs {
24
+ keys?: Key[];
25
+ wits?: string[];
26
+ toad?: number;
27
+ }
28
+ export interface InteractArgs {
29
+ aid: string;
30
+ data: Record<string, unknown>;
31
+ }
32
+ export interface CreateRegistryArgs {
33
+ owner: string;
34
+ nonce?: string;
35
+ }
36
+ export interface CreateCredentialArgs {
37
+ schemaId: string;
38
+ registryId: string;
39
+ holder: string;
40
+ salt?: string;
41
+ data?: Record<string, unknown>;
42
+ rules?: Record<string, unknown>;
43
+ edges?: Record<string, unknown>;
44
+ timestamp?: Date;
45
+ }
46
+ export declare class Controller {
47
+ #private;
48
+ get store(): ControllerEventStore;
49
+ constructor(deps: ControllerDeps);
50
+ createIdentifier(args?: InceptArgs): Promise<KeyState>;
51
+ interact(args: InteractArgs): Promise<InteractEvent>;
52
+ createRegistry(args: CreateRegistryArgs): Promise<RegistryInceptEvent>;
53
+ createCredential(args: CreateCredentialArgs): Promise<CredentialEvent>;
54
+ resolve(oobi: string): Promise<void>;
55
+ getClient(cid: string): Promise<Client>;
56
+ getLocation(aid: string): Promise<LocationRecord>;
57
+ submit(event: KeyEvent, signatures: string[]): Promise<void>;
58
+ state(said: string): Promise<KeyState>;
59
+ list(id: string): Promise<KeyEventMessage[]>;
60
+ sendCredentialArficats(credential: CredentialEvent, recipient: string): Promise<void>;
61
+ grant(args: IpexGrantArgs): Promise<void>;
62
+ forward(client: Client, args: ForwardArgs): Promise<void>;
63
+ sign(event: Record<string, unknown>, keys: string[]): Promise<string[]>;
64
+ }