keri 0.0.0-dev.0ddd65e → 0.0.0-dev.1dab5a8
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/LICENSE +201 -0
- package/README.md +3 -0
- package/dist/cesr/__main__.d.ts +9 -0
- package/dist/cesr/__main__.js +10 -0
- package/dist/cesr/__main__.js.map +1 -0
- package/dist/cesr/array-utils.d.ts +3 -0
- package/dist/cesr/array-utils.js +29 -0
- package/dist/cesr/array-utils.js.map +1 -0
- package/dist/cesr/attachments-reader.d.ts +10 -0
- package/dist/cesr/attachments-reader.js +281 -0
- package/dist/cesr/attachments-reader.js.map +1 -0
- package/dist/cesr/attachments.d.ts +66 -0
- package/dist/cesr/attachments.js +108 -0
- package/dist/cesr/attachments.js.map +1 -0
- package/dist/cesr/codes.d.ts +1208 -0
- package/dist/cesr/codes.js +309 -0
- package/dist/cesr/codes.js.map +1 -0
- package/dist/cesr/counter.d.ts +114 -0
- package/dist/cesr/counter.js +78 -0
- package/dist/cesr/counter.js.map +1 -0
- package/dist/cesr/frame.d.ts +31 -0
- package/dist/cesr/frame.js +99 -0
- package/dist/cesr/frame.js.map +1 -0
- package/dist/cesr/genus.d.ts +18 -0
- package/dist/cesr/genus.js +57 -0
- package/dist/cesr/genus.js.map +1 -0
- package/dist/cesr/groups/generic-map.d.ts +11 -0
- package/dist/cesr/groups/generic-map.js +51 -0
- package/dist/cesr/groups/generic-map.js.map +1 -0
- package/dist/cesr/indexer.d.ts +68 -0
- package/dist/cesr/indexer.js +171 -0
- package/dist/cesr/indexer.js.map +1 -0
- package/dist/cesr/matter.d.ts +160 -0
- package/dist/cesr/matter.js +301 -0
- package/dist/cesr/matter.js.map +1 -0
- package/dist/cesr/message.d.ts +17 -0
- package/dist/cesr/message.js +81 -0
- package/dist/cesr/message.js.map +1 -0
- package/dist/cesr/parse.d.ts +37 -0
- package/dist/cesr/parse.js +138 -0
- package/dist/cesr/parse.js.map +1 -0
- package/dist/cesr/shifting.d.ts +7 -0
- package/dist/cesr/shifting.js +10 -0
- package/dist/cesr/shifting.js.map +1 -0
- package/dist/cesr/version-string.d.ts +35 -0
- package/dist/cesr/version-string.js +146 -0
- package/dist/cesr/version-string.js.map +1 -0
- package/dist/cli/cli.d.ts +5 -0
- package/dist/cli/cli.js +73 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/input.d.ts +1 -0
- package/dist/cli/input.js +22 -0
- package/dist/cli/input.js.map +1 -0
- package/dist/cli/node-cli.js +19 -0
- package/dist/cli/node-cli.js.map +1 -0
- package/dist/controller/controller.d.ts +97 -0
- package/dist/controller/controller.js +601 -0
- package/dist/controller/controller.js.map +1 -0
- package/dist/controller/encrypt.d.ts +45 -0
- package/dist/controller/encrypt.js +120 -0
- package/dist/controller/encrypt.js.map +1 -0
- package/dist/core/credential-event.d.ts +54 -0
- package/dist/core/credential-event.js +28 -0
- package/dist/core/credential-event.js.map +1 -0
- package/dist/core/credential.d.ts +79 -0
- package/dist/core/credential.js +25 -0
- package/dist/core/credential.js.map +1 -0
- package/dist/core/digest.d.ts +1 -0
- package/dist/core/digest.js +7 -0
- package/dist/core/digest.js.map +1 -0
- package/dist/core/endpoint-discovery.d.ts +20 -0
- package/dist/core/endpoint-discovery.js +60 -0
- package/dist/core/endpoint-discovery.js.map +1 -0
- package/dist/core/events.d.ts +12 -0
- package/dist/core/events.js +25 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/kawa.d.ts +17 -0
- package/dist/core/kawa.js +48 -0
- package/dist/core/kawa.js.map +1 -0
- package/dist/core/key-event-log.d.ts +19 -0
- package/dist/core/key-event-log.js +155 -0
- package/dist/core/key-event-log.js.map +1 -0
- package/dist/core/key-event.d.ts +94 -0
- package/dist/core/key-event.js +88 -0
- package/dist/core/key-event.js.map +1 -0
- package/dist/core/keys.d.ts +10 -0
- package/dist/core/keys.js +17 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/mailbox-client.d.ts +23 -0
- package/dist/core/mailbox-client.js +75 -0
- package/dist/core/mailbox-client.js.map +1 -0
- package/dist/core/main.d.ts +53 -0
- package/dist/core/main.js +45 -0
- package/dist/core/main.js.map +1 -0
- package/dist/core/receipt-event.d.ts +15 -0
- package/dist/core/receipt-event.js +13 -0
- package/dist/core/receipt-event.js.map +1 -0
- package/dist/core/registry-event.d.ts +26 -0
- package/dist/core/registry-event.js +18 -0
- package/dist/core/registry-event.js.map +1 -0
- package/dist/core/routed-event.d.ts +67 -0
- package/dist/core/routed-event.js +53 -0
- package/dist/core/routed-event.js.map +1 -0
- package/dist/core/said.d.ts +4 -0
- package/dist/core/said.js +29 -0
- package/dist/core/said.js.map +1 -0
- package/dist/core/sign.d.ts +5 -0
- package/dist/core/sign.js +10 -0
- package/dist/core/sign.js.map +1 -0
- package/dist/core/threshold.d.ts +6 -0
- package/dist/core/threshold.js +58 -0
- package/dist/core/threshold.js.map +1 -0
- package/dist/core/verify.d.ts +23 -0
- package/dist/core/verify.js +62 -0
- package/dist/core/verify.js.map +1 -0
- package/dist/core/witness-client.d.ts +8 -0
- package/dist/core/witness-client.js +39 -0
- package/dist/core/witness-client.js.map +1 -0
- package/dist/encoding/base64.d.ts +4 -0
- package/dist/encoding/base64.js +82 -0
- package/dist/encoding/base64.js.map +1 -0
- package/dist/encoding/main.d.ts +2 -0
- package/dist/encoding/main.js +3 -0
- package/dist/encoding/main.js.map +1 -0
- package/dist/encoding/utf8.d.ts +2 -0
- package/dist/encoding/utf8.js +9 -0
- package/dist/encoding/utf8.js.map +1 -0
- package/dist/logging/main.d.ts +15 -0
- package/dist/logging/main.js +25 -0
- package/dist/logging/main.js.map +1 -0
- package/dist/mailbox/mailbox-router.d.ts +6 -0
- package/dist/mailbox/mailbox-router.js +88 -0
- package/dist/mailbox/mailbox-router.js.map +1 -0
- package/dist/mailbox/mailbox.d.ts +27 -0
- package/dist/mailbox/mailbox.js +101 -0
- package/dist/mailbox/mailbox.js.map +1 -0
- package/dist/mailbox/main.d.ts +3 -0
- package/dist/mailbox/main.js +3 -0
- package/dist/mailbox/main.js.map +1 -0
- package/dist/main.d.ts +3 -2
- package/dist/main.js +3 -2
- package/dist/main.js.map +1 -0
- package/dist/nodejs-utils/main.d.ts +2 -0
- package/dist/nodejs-utils/main.js +2 -0
- package/dist/nodejs-utils/main.js.map +1 -0
- package/dist/nodejs-utils/serve.d.ts +6 -0
- package/dist/nodejs-utils/serve.js +68 -0
- package/dist/nodejs-utils/serve.js.map +1 -0
- package/dist/storage/credential-storage.d.ts +8 -0
- package/dist/storage/credential-storage.js +2 -0
- package/dist/storage/credential-storage.js.map +1 -0
- package/dist/storage/key-event-storage.d.ts +10 -0
- package/dist/storage/key-event-storage.js +2 -0
- package/dist/storage/key-event-storage.js.map +1 -0
- package/dist/storage/mailbox-server-storage.d.ts +9 -0
- package/dist/storage/mailbox-server-storage.js +2 -0
- package/dist/storage/mailbox-server-storage.js.map +1 -0
- package/dist/storage/mailbox-storage.d.ts +4 -0
- package/dist/storage/mailbox-storage.js +2 -0
- package/dist/storage/mailbox-storage.js.map +1 -0
- package/dist/storage/main.d.ts +5 -0
- package/dist/storage/main.js +2 -0
- package/dist/storage/main.js.map +1 -0
- package/dist/storage/private-key-storage.d.ts +5 -0
- package/dist/storage/private-key-storage.js +2 -0
- package/dist/storage/private-key-storage.js.map +1 -0
- package/dist/storage/sqlite/node-sqlite.d.ts +12 -0
- package/dist/storage/sqlite/node-sqlite.js +25 -0
- package/dist/storage/sqlite/node-sqlite.js.map +1 -0
- package/dist/storage/sqlite/schema.d.ts +2 -0
- package/dist/storage/sqlite/schema.js +67 -0
- package/dist/storage/sqlite/schema.js.map +1 -0
- package/dist/storage/sqlite/sqlite-database.d.ts +13 -0
- package/dist/storage/sqlite/sqlite-database.js +2 -0
- package/dist/storage/sqlite/sqlite-database.js.map +1 -0
- package/dist/storage/sqlite/storage-sqlite.d.ts +32 -0
- package/dist/storage/sqlite/storage-sqlite.js +237 -0
- package/dist/storage/sqlite/storage-sqlite.js.map +1 -0
- package/dist/witness/main.d.ts +3 -0
- package/dist/witness/main.js +3 -0
- package/dist/witness/main.js.map +1 -0
- package/dist/witness/witness-router.d.ts +6 -0
- package/dist/witness/witness-router.js +120 -0
- package/dist/witness/witness-router.js.map +1 -0
- package/dist/witness/witness.d.ts +26 -0
- package/dist/witness/witness.js +156 -0
- package/dist/witness/witness.js.map +1 -0
- package/package.json +84 -26
- package/dist/cli/main.js +0 -72
- package/dist/data-type.d.ts +0 -9
- package/dist/data-type.js +0 -1
- package/dist/db/event-store.d.ts +0 -20
- package/dist/db/event-store.js +0 -1
- package/dist/db/sqlite-db.d.ts +0 -13
- package/dist/db/sqlite-db.js +0 -123
- package/dist/events/common.d.ts +0 -6
- package/dist/events/common.js +0 -1
- package/dist/events/incept.d.ts +0 -26
- package/dist/events/incept.js +0 -28
- package/dist/events/interact.d.ts +0 -17
- package/dist/events/interact.js +0 -21
- package/dist/events/main.d.ts +0 -4
- package/dist/events/main.js +0 -4
- package/dist/events/reply.d.ts +0 -15
- package/dist/events/reply.js +0 -20
- package/dist/keri/habitat.d.ts +0 -20
- package/dist/keri/habitat.js +0 -130
- package/dist/keri/keri.d.ts +0 -26
- package/dist/keri/keri.js +0 -43
- package/dist/keystore/encrypt.d.ts +0 -2
- package/dist/keystore/encrypt.js +0 -38
- package/dist/keystore/keystore-fs.d.ts +0 -13
- package/dist/keystore/keystore-fs.js +0 -50
- package/dist/keystore/keystore-web.d.ts +0 -12
- package/dist/keystore/keystore-web.js +0 -48
- package/dist/keystore/keystore.d.ts +0 -15
- package/dist/keystore/keystore.js +0 -1
- package/dist/main-common.d.ts +0 -9
- package/dist/main-common.js +0 -8
- package/dist/main-web.d.ts +0 -2
- package/dist/main-web.js +0 -2
- package/dist/parser/base64.d.ts +0 -6
- package/dist/parser/base64.js +0 -74
- package/dist/parser/buffered-reader.d.ts +0 -5
- package/dist/parser/buffered-reader.js +0 -47
- package/dist/parser/cesr-encoding.d.ts +0 -34
- package/dist/parser/cesr-encoding.js +0 -158
- package/dist/parser/codes.d.ts +0 -143
- package/dist/parser/codes.js +0 -266
- package/dist/parser/parser.d.ts +0 -16
- package/dist/parser/parser.js +0 -161
- package/dist/parser/version.d.ts +0 -11
- package/dist/parser/version.js +0 -56
- /package/dist/cli/{main.d.ts → node-cli.d.ts} +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Attachments, encodeText, parse } from "#keri/cesr";
|
|
2
|
+
import { KeriLogger } from "#keri/logging";
|
|
3
|
+
const RETRY_MS = 5000;
|
|
4
|
+
function createOobiResponse(events) {
|
|
5
|
+
const body = events
|
|
6
|
+
.flatMap(({ message }) => {
|
|
7
|
+
const atc = new Attachments({
|
|
8
|
+
ControllerIdxSigs: message.attachments.ControllerIdxSigs,
|
|
9
|
+
NonTransReceiptCouples: message.attachments.NonTransReceiptCouples,
|
|
10
|
+
});
|
|
11
|
+
return [new TextDecoder().decode(message.raw), encodeText(atc.frames())];
|
|
12
|
+
})
|
|
13
|
+
.join("");
|
|
14
|
+
return new Response(body, {
|
|
15
|
+
status: 200,
|
|
16
|
+
headers: { "Content-Type": "application/json+cesr" },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function encodeReply(reply) {
|
|
20
|
+
const atc = new Attachments({
|
|
21
|
+
ControllerIdxSigs: reply.message.attachments.ControllerIdxSigs,
|
|
22
|
+
WitnessIdxSigs: reply.message.attachments.WitnessIdxSigs,
|
|
23
|
+
NonTransReceiptCouples: reply.message.attachments.NonTransReceiptCouples,
|
|
24
|
+
TransIdxSigGroups: reply.message.attachments.TransIdxSigGroups,
|
|
25
|
+
PathedMaterialCouples: reply.message.attachments.PathedMaterialCouples,
|
|
26
|
+
});
|
|
27
|
+
const cesr = new TextDecoder().decode(reply.message.raw) + encodeText(atc.frames());
|
|
28
|
+
return `id: ${reply.id}\nevent: ${reply.topic}\nretry: ${RETRY_MS}\ndata: ${cesr}\n\n`;
|
|
29
|
+
}
|
|
30
|
+
function createResponse(replies) {
|
|
31
|
+
if (replies.length === 0) {
|
|
32
|
+
return new Response(null, { status: 204 });
|
|
33
|
+
}
|
|
34
|
+
const body = replies.map(encodeReply).join("");
|
|
35
|
+
return new Response(body, {
|
|
36
|
+
status: 200,
|
|
37
|
+
headers: { "Content-Type": "text/event-stream" },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function createRouter(mailbox, options = {}) {
|
|
41
|
+
const log = new KeriLogger(options.logger);
|
|
42
|
+
async function handleMessageRequest(request) {
|
|
43
|
+
const atc = request.headers.get("CESR-ATTACHMENT");
|
|
44
|
+
if (!atc) {
|
|
45
|
+
log.warn("rejecting POST /: missing CESR-ATTACHMENT");
|
|
46
|
+
return Response.json({ error: "Bad Request" }, { status: 400 });
|
|
47
|
+
}
|
|
48
|
+
const bodyText = await request.text();
|
|
49
|
+
const replies = [];
|
|
50
|
+
let count = 0;
|
|
51
|
+
for await (const event of parse(bodyText + atc)) {
|
|
52
|
+
count++;
|
|
53
|
+
for await (const reply of mailbox.handleMessage(event)) {
|
|
54
|
+
replies.push(reply);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
log.debug("POST /: handled messages", { count, replies: replies.length });
|
|
58
|
+
return createResponse(replies);
|
|
59
|
+
}
|
|
60
|
+
return async function handler(request) {
|
|
61
|
+
const { method } = request;
|
|
62
|
+
const pathname = new URL(request.url).pathname;
|
|
63
|
+
if (pathname === "/") {
|
|
64
|
+
switch (method) {
|
|
65
|
+
case "GET":
|
|
66
|
+
return Response.json({ status: "OK" });
|
|
67
|
+
case "POST":
|
|
68
|
+
return handleMessageRequest(request);
|
|
69
|
+
default:
|
|
70
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (pathname.startsWith("/oobi")) {
|
|
74
|
+
switch (method) {
|
|
75
|
+
case "GET": {
|
|
76
|
+
log.debug("GET /oobi: serving self", { count: mailbox.events.length });
|
|
77
|
+
const response = createOobiResponse(mailbox.events);
|
|
78
|
+
response.headers.set("Keri-Aid", mailbox.aid);
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
default:
|
|
82
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return new Response("Not Found", { status: 404 });
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=mailbox-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox-router.js","sourceRoot":"","sources":["../../src/mailbox/mailbox-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AAGxD,MAAM,QAAQ,GAAG,IAAI,CAAC;AAMtB,SAAS,kBAAkB,CAAC,MAA+B;IACzD,MAAM,IAAI,GAAG,MAAM;SAChB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACvB,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC;YAC1B,iBAAiB,EAAE,OAAO,CAAC,WAAW,CAAC,iBAAiB;YACxD,sBAAsB,EAAE,OAAO,CAAC,WAAW,CAAC,sBAAsB;SACnE,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;IAEZ,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,uBAAuB,EAAE;KACrD,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,KAAmB;IACtC,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC;QAC1B,iBAAi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gBACvC;oBACE,OAAO,IAAI,QAAQ,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACjC,QAAQ,MAAM,EAAE,CAAC;gBACf,KAAK,KAAK,CAAC,CAAC,CAAC;oBACX,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;oBACvE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpD,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;oBAC9C,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD;oBACE,OAAO,IAAI,QAAQ,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,OAAO,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Message } from "#keri/cesr";
|
|
2
|
+
import { KeyEventLog } from "#keri/core";
|
|
3
|
+
import { type Logger } from "#keri/logging";
|
|
4
|
+
import type { MailboxServerStorage } from "#keri/storage";
|
|
5
|
+
export interface MailboxOptions {
|
|
6
|
+
storage: MailboxServerStorage;
|
|
7
|
+
privateKey?: Uint8Array;
|
|
8
|
+
url?: string;
|
|
9
|
+
logger?: Logger;
|
|
10
|
+
}
|
|
11
|
+
export interface MailboxEvent {
|
|
12
|
+
readonly message: Message;
|
|
13
|
+
readonly timestamp: Date;
|
|
14
|
+
}
|
|
15
|
+
export interface MailboxReply {
|
|
16
|
+
readonly id: number;
|
|
17
|
+
readonly topic: string;
|
|
18
|
+
readonly message: Message;
|
|
19
|
+
}
|
|
20
|
+
export declare class Mailbox {
|
|
21
|
+
#private;
|
|
22
|
+
readonly events: readonly MailboxEvent[];
|
|
23
|
+
static createKEL(privateKey: Uint8Array): KeyEventLog;
|
|
24
|
+
get aid(): string;
|
|
25
|
+
constructor(options: MailboxOptions);
|
|
26
|
+
handleMessage(message: Message): AsyncGenerator<MailboxReply>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
2
|
+
import { encodeText, Indexer, Matter, Message } from "#keri/cesr";
|
|
3
|
+
import { KeyEventLog, keri } from "#keri/core";
|
|
4
|
+
import { KeriLogger } from "#keri/logging";
|
|
5
|
+
export class Mailbox {
|
|
6
|
+
#storage;
|
|
7
|
+
#privateKey;
|
|
8
|
+
#kel;
|
|
9
|
+
#log;
|
|
10
|
+
events;
|
|
11
|
+
static createKEL(privateKey) {
|
|
12
|
+
const publicKey = encodeText(new Matter({ code: Matter.Code.Ed25519N, raw: ed25519.getPublicKey(privateKey) }));
|
|
13
|
+
const icp = keri.incept({ signingKeys: [publicKey], nextKeys: [] });
|
|
14
|
+
icp.attachments = {
|
|
15
|
+
ControllerIdxSigs: [encodeText(Indexer.crypto.ed25519_sig(ed25519.sign(icp.raw, privateKey), 0))],
|
|
16
|
+
};
|
|
17
|
+
return KeyEventLog.from([icp]);
|
|
18
|
+
}
|
|
19
|
+
get aid() {
|
|
20
|
+
return this.#kel.state.identifier;
|
|
21
|
+
}
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.#storage = options.storage;
|
|
24
|
+
this.#privateKey = options.privateKey ?? ed25519.utils.randomSecretKey();
|
|
25
|
+
this.#kel = Mailbox.createKEL(this.#privateKey);
|
|
26
|
+
this.#log = new KeriLogger(options.logger);
|
|
27
|
+
const events = [{ message: this.#kel.events[0], timestamp: new Date() }];
|
|
28
|
+
if (options.url) {
|
|
29
|
+
const url = new URL(options.url);
|
|
30
|
+
const scheme = url.protocol.replace(":", "");
|
|
31
|
+
const location = keri.reply({
|
|
32
|
+
r: "/loc/scheme",
|
|
33
|
+
a: { eid: this.aid, scheme, url: options.url },
|
|
34
|
+
});
|
|
35
|
+
const endrole = keri.reply({
|
|
36
|
+
r: "/end/role/add",
|
|
37
|
+
a: { cid: this.aid, role: "mailbox", eid: this.aid },
|
|
38
|
+
});
|
|
39
|
+
location.attachments = {
|
|
40
|
+
NonTransReceiptCouples: [{ prefix: this.aid, sig: this.#sign(location) }],
|
|
41
|
+
};
|
|
42
|
+
endrole.attachments = {
|
|
43
|
+
NonTransReceiptCouples: [{ prefix: this.aid, sig: this.#sign(endrole) }],
|
|
44
|
+
};
|
|
45
|
+
events.push({ message: location, timestamp: new Date() });
|
|
46
|
+
events.push({ message: endrole, timestamp: new Date() });
|
|
47
|
+
}
|
|
48
|
+
this.events = events;
|
|
49
|
+
}
|
|
50
|
+
async *handleMessage(message) {
|
|
51
|
+
const { t, r } = message.body;
|
|
52
|
+
if (t === "exn" && r === "/fwd") {
|
|
53
|
+
this.#log.debug("handling exn /fwd");
|
|
54
|
+
this.#handleForward(message);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (t === "qry" && r === "mbx") {
|
|
58
|
+
this.#log.debug("handling qry mbx");
|
|
59
|
+
yield* this.#handleQuery(message);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.#log.debug("ignoring message", { t, r });
|
|
63
|
+
}
|
|
64
|
+
#handleForward(message) {
|
|
65
|
+
const { q, e } = message.body;
|
|
66
|
+
const pre = q.pre;
|
|
67
|
+
const topic = q.topic;
|
|
68
|
+
if (!pre || !topic) {
|
|
69
|
+
this.#log.warn("ignoring forward: missing q.pre or q.topic");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const evtBody = e?.evt;
|
|
73
|
+
if (!evtBody) {
|
|
74
|
+
this.#log.warn("ignoring forward: missing e.evt", { pre, topic });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const evtCouple = message.attachments.PathedMaterialCouples.find((c) => c.path === "-e-evt");
|
|
78
|
+
const innerMessage = new Message(evtBody, evtCouple?.attachments);
|
|
79
|
+
this.#log.debug("saving mailbox entry", { pre, topic });
|
|
80
|
+
this.#storage.saveMailboxEntry(pre, topic, innerMessage);
|
|
81
|
+
}
|
|
82
|
+
*#handleQuery(message) {
|
|
83
|
+
const { i, topics } = message.body.q;
|
|
84
|
+
if (!i || !topics) {
|
|
85
|
+
this.#log.warn("ignoring query: missing q.i or q.topics");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.#log.debug("querying mailbox", { aid: i, topics });
|
|
89
|
+
for (const [topicPath, offset] of Object.entries(topics)) {
|
|
90
|
+
const storageTopic = topicPath.replace(/^\//, "");
|
|
91
|
+
for (const entry of this.#storage.getMailboxEntries(i, storageTopic, offset)) {
|
|
92
|
+
yield { id: entry.id, topic: topicPath, message: entry.message };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
#sign(message) {
|
|
97
|
+
const rawSignature = ed25519.sign(message.raw, this.#privateKey);
|
|
98
|
+
return encodeText(new Matter({ code: Matter.Code.Ed25519_Sig, raw: rawSignature }));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=mailbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox.js","sourceRoot":"","sources":["../../src/mailbox/mailbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAoB,MAAM,YAAY,CAAC;AAEpF,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AAqBx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EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YACnE,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAgB;QACpB,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACjE,OAAO,UAAU,CAAC,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;IACtF,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/mailbox/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAsB,MAAM,qBAAqB,CAAC"}
|
package/dist/main.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./main
|
|
1
|
+
export * from "./controller/controller.ts";
|
|
2
|
+
export * from "./core/main.ts";
|
|
3
|
+
export type { Logger } from "./logging/main.ts";
|
package/dist/main.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./main
|
|
1
|
+
export * from "./controller/controller.js";
|
|
2
|
+
export * from "./core/main.js";
|
|
3
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/nodejs-utils/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RequestListener } from "node:http";
|
|
2
|
+
import { type Logger } from "#keri/logging";
|
|
3
|
+
export interface ListenerOptions {
|
|
4
|
+
logger?: Logger;
|
|
5
|
+
}
|
|
6
|
+
export declare function createListener(handler: (request: Request) => Promise<Response>, options?: ListenerOptions): RequestListener;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { KeriLogger } from "#keri/logging";
|
|
3
|
+
function toWebRequest(req) {
|
|
4
|
+
const host = req.headers.host ?? "0.0.0.0";
|
|
5
|
+
const protocol = req.headers["x-forwarded-proto"] ?? "http";
|
|
6
|
+
const url = new URL(req.url ?? "/", `${protocol}://${host}`);
|
|
7
|
+
const headers = new Headers();
|
|
8
|
+
for (const [key, headerValue] of Object.entries(req.headers)) {
|
|
9
|
+
if (headerValue !== undefined) {
|
|
10
|
+
if (Array.isArray(headerValue)) {
|
|
11
|
+
for (const value of headerValue) {
|
|
12
|
+
headers.append(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
headers.set(key, headerValue);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let body = null;
|
|
21
|
+
if (!["GET", "HEAD"].includes(req.method ?? "")) {
|
|
22
|
+
body = Readable.toWeb(req);
|
|
23
|
+
}
|
|
24
|
+
return new Request(url, {
|
|
25
|
+
method: req.method,
|
|
26
|
+
headers,
|
|
27
|
+
body,
|
|
28
|
+
duplex: "half",
|
|
29
|
+
// Cast required because DOM types omit `duplex`, but Node.js undici fetch requires it when body is a stream
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function createListener(handler, options = {}) {
|
|
33
|
+
const log = new KeriLogger(options.logger);
|
|
34
|
+
return async (req, res) => {
|
|
35
|
+
const start = Date.now();
|
|
36
|
+
const method = req.method ?? "GET";
|
|
37
|
+
const url = req.url ?? "/";
|
|
38
|
+
res.on("finish", () => {
|
|
39
|
+
const durationMs = Date.now() - start;
|
|
40
|
+
log.info(`${method} ${url} ${res.statusCode} ${durationMs}ms`, {
|
|
41
|
+
method,
|
|
42
|
+
url,
|
|
43
|
+
status: res.statusCode,
|
|
44
|
+
durationMs,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
try {
|
|
48
|
+
const response = await handler(toWebRequest(req));
|
|
49
|
+
res.writeHead(response.status, Object.fromEntries(response.headers.entries()));
|
|
50
|
+
if (response.body) {
|
|
51
|
+
const reader = response.body.getReader();
|
|
52
|
+
while (true) {
|
|
53
|
+
const { done, value } = await reader.read();
|
|
54
|
+
if (done)
|
|
55
|
+
break;
|
|
56
|
+
res.write(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
res.end();
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
log.error("handler threw", { method, url, error: err instanceof Error ? err.message : String(err) });
|
|
63
|
+
res.statusCode = 500;
|
|
64
|
+
res.end("Internal Server Error");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/nodejs-utils/serve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAe,MAAM,eAAe,CAAC;AAMxD,SAAS,YAAY,CAAC,GAAoB;IACxC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;IAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,MAAM,CAAC;IAC5D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,GAAG,QAAQ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EAAE,CAAC,CAAC;YACrG,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CredentialBody, IssueEvent, Message, RegistryInceptEventBody, RevokeEvent } from "#keri/core";
|
|
2
|
+
export interface CredentialStorage {
|
|
3
|
+
getCredentialEvents(id: string): Generator<Message<IssueEvent | RevokeEvent>>;
|
|
4
|
+
getRegistry(id: string): Message<RegistryInceptEventBody> | null;
|
|
5
|
+
getRegistriesByOwner(owner: string): Generator<Message<RegistryInceptEventBody>>;
|
|
6
|
+
getCredential(id: string): CredentialBody | null;
|
|
7
|
+
getCredentialsByRegistry(registryId: string): CredentialBody[];
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-storage.js","sourceRoot":"","sources":["../../src/storage/credential-storage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { KeyEvent, Message, ReplyEventBody } from "#keri/core";
|
|
2
|
+
export interface KeyEventStorage {
|
|
3
|
+
saveMessage(message: Message): void;
|
|
4
|
+
getKeyEvents(prefix: string): Generator<KeyEvent>;
|
|
5
|
+
getReplies(filter?: {
|
|
6
|
+
route?: string;
|
|
7
|
+
eid?: string;
|
|
8
|
+
cid?: string;
|
|
9
|
+
}): Generator<Message<ReplyEventBody>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-event-storage.js","sourceRoot":"","sources":["../../src/storage/key-event-storage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Message } from "#keri/cesr";
|
|
2
|
+
export interface MailboxEntry {
|
|
3
|
+
id: number;
|
|
4
|
+
message: Message;
|
|
5
|
+
}
|
|
6
|
+
export interface MailboxServerStorage {
|
|
7
|
+
saveMailboxEntry(pre: string, topic: string, message: Message): void;
|
|
8
|
+
getMailboxEntries(pre: string, topic: string, offset: number): Generator<MailboxEntry>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox-server-storage.js","sourceRoot":"","sources":["../../src/storage/mailbox-server-storage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox-storage.js","sourceRoot":"","sources":["../../src/storage/mailbox-storage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { CredentialStorage } from "./credential-storage.ts";
|
|
2
|
+
export type { KeyEventStorage } from "./key-event-storage.ts";
|
|
3
|
+
export type { MailboxEntry, MailboxServerStorage } from "./mailbox-server-storage.ts";
|
|
4
|
+
export type { MailboxStorage } from "./mailbox-storage.ts";
|
|
5
|
+
export type { PrivateKeyStorage } from "./private-key-storage.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/storage/main.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-key-storage.js","sourceRoot":"","sources":["../../src/storage/private-key-storage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import type { Database, Params, Row } from "./sqlite-database.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Adapter that wraps the built-in `node:sqlite` `DatabaseSync` class so it satisfies the `Database` interface.
|
|
5
|
+
*/
|
|
6
|
+
export declare class NodeSqliteDatabase implements Database {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(db: DatabaseSync);
|
|
9
|
+
execute(sql: string, params?: Params): void;
|
|
10
|
+
queryOne(sql: string, params?: Params): Row | undefined;
|
|
11
|
+
iterate(sql: string, params?: Params): Iterable<Row>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter that wraps the built-in `node:sqlite` `DatabaseSync` class so it satisfies the `Database` interface.
|
|
3
|
+
*/
|
|
4
|
+
export class NodeSqliteDatabase {
|
|
5
|
+
#db;
|
|
6
|
+
constructor(db) {
|
|
7
|
+
this.#db = db;
|
|
8
|
+
}
|
|
9
|
+
execute(sql, params) {
|
|
10
|
+
if (params !== undefined) {
|
|
11
|
+
this.#db.prepare(sql).run(params);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.#db.exec(sql);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
queryOne(sql, params) {
|
|
18
|
+
const result = this.#db.prepare(sql).get(params ?? {});
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
iterate(sql, params) {
|
|
22
|
+
return this.#db.prepare(sql).iterate(params ?? {});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=node-sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-sqlite.js","sourceRoot":"","sources":["../../../src/storage/sqlite/node-sqlite.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC7B,GAAG,CAAe;IAElB,YAAY,EAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,MAAe;QAClC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,GAAW,EAAE,MAAe;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QACvD,OAAO,MAAyB,CAAC;IACnC,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,MAAe;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAkB,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const migrations = [
|
|
2
|
+
// Migration 1: initial schema
|
|
3
|
+
[
|
|
4
|
+
[
|
|
5
|
+
"CREATE TABLE IF NOT EXISTS event (",
|
|
6
|
+
" event_id TEXT PRIMARY KEY,",
|
|
7
|
+
" protocol TEXT NOT NULL,",
|
|
8
|
+
" type TEXT NOT NULL,",
|
|
9
|
+
" sn INTEGER,",
|
|
10
|
+
" event_json JSON NOT NULL,",
|
|
11
|
+
" attachments TEXT",
|
|
12
|
+
")",
|
|
13
|
+
].join("\n"),
|
|
14
|
+
[
|
|
15
|
+
"CREATE TABLE IF NOT EXISTS key_info (",
|
|
16
|
+
" public_key TEXT PRIMARY KEY,",
|
|
17
|
+
" public_key_digest TEXT NOT NULL,",
|
|
18
|
+
" encrypted_private_key TEXT NOT NULL",
|
|
19
|
+
")",
|
|
20
|
+
].join("\n"),
|
|
21
|
+
],
|
|
22
|
+
// Migration 2: mailbox cursor
|
|
23
|
+
[
|
|
24
|
+
[
|
|
25
|
+
"CREATE TABLE IF NOT EXISTS mailbox_cursor (",
|
|
26
|
+
" prefix TEXT NOT NULL,",
|
|
27
|
+
" topic TEXT NOT NULL,",
|
|
28
|
+
" offset INTEGER NOT NULL DEFAULT 0,",
|
|
29
|
+
" PRIMARY KEY (prefix, topic)",
|
|
30
|
+
")",
|
|
31
|
+
].join("\n"),
|
|
32
|
+
],
|
|
33
|
+
// Migration 3: mailbox entry (server-side message store)
|
|
34
|
+
[
|
|
35
|
+
[
|
|
36
|
+
"CREATE TABLE IF NOT EXISTS mailbox_entry (",
|
|
37
|
+
" id INTEGER PRIMARY KEY AUTOINCREMENT,",
|
|
38
|
+
" pre TEXT NOT NULL,",
|
|
39
|
+
" topic TEXT NOT NULL,",
|
|
40
|
+
" event_json JSON NOT NULL,",
|
|
41
|
+
" attachments TEXT",
|
|
42
|
+
")",
|
|
43
|
+
].join("\n"),
|
|
44
|
+
],
|
|
45
|
+
];
|
|
46
|
+
export function migrate(db) {
|
|
47
|
+
db.execute(`CREATE TABLE IF NOT EXISTS schema_version (version INTEGER NOT NULL)`);
|
|
48
|
+
db.execute(`INSERT INTO schema_version (version) SELECT 0 WHERE NOT EXISTS (SELECT 1 FROM schema_version)`);
|
|
49
|
+
const row = Array.from(db.iterate("SELECT version FROM schema_version"))[0];
|
|
50
|
+
let current = typeof row?.version === "number" ? row.version : 0;
|
|
51
|
+
for (let i = current; i < migrations.length; i++) {
|
|
52
|
+
db.execute("BEGIN");
|
|
53
|
+
try {
|
|
54
|
+
for (const statement of migrations[i]) {
|
|
55
|
+
db.execute(statement);
|
|
56
|
+
}
|
|
57
|
+
db.execute(`UPDATE schema_version SET version = ${i + 1}`);
|
|
58
|
+
db.execute("COMMIT");
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
db.execute("ROLLBACK");
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
current = i + 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/storage/sqlite/schema.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAe;IAC7B,8BAA8B;IAC9B;QACE;YACE,oCAAoC;YACpC,iCAAiC;YACjC,8BAA8B;YAC9B,8BAA8B;YAC9B,wBAAwB;YACxB,8BAA8B;YAC9B,oBAAoB;YACpB,GAAG;SACJ,CAAC,IAAI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CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACvB,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SQLValue = string | number | null | Uint8Array;
|
|
2
|
+
export type Params = Record<string, SQLValue>;
|
|
3
|
+
export type Row = Record<string, SQLValue>;
|
|
4
|
+
export interface Database {
|
|
5
|
+
/**
|
|
6
|
+
* Execute a statement that produces no rows (DDL, DML, transaction control).
|
|
7
|
+
*/
|
|
8
|
+
execute(sql: string, params?: Params): void;
|
|
9
|
+
/**
|
|
10
|
+
* Iterate over matching rows one at a time without loading all into memory.
|
|
11
|
+
*/
|
|
12
|
+
iterate(sql: string, params?: Params): Iterable<Row>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-database.js","sourceRoot":"","sources":["../../../src/storage/sqlite/sqlite-database.ts"],"names":[],"mappings":""}
|