keri 0.0.0-dev.0ddd65e → 0.0.0-dev.2223857
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/dist/controller/controller.d.ts +109 -0
- package/dist/controller/controller.js +545 -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 +58 -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 +79 -0
- package/dist/core/kawa.js.map +1 -0
- package/dist/core/key-event-log.d.ts +13 -0
- package/dist/core/key-event-log.js +154 -0
- package/dist/core/key-event-log.js.map +1 -0
- package/dist/core/key-event.d.ts +96 -0
- package/dist/core/key-event.js +89 -0
- package/dist/core/key-event.js.map +1 -0
- package/dist/core/keys.d.ts +9 -0
- package/dist/core/keys.js +17 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/mailbox-client.d.ts +17 -0
- package/dist/core/mailbox-client.js +57 -0
- package/dist/core/mailbox-client.js.map +1 -0
- package/dist/core/main.d.ts +47 -0
- package/dist/core/main.js +44 -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 +28 -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 +73 -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 +26 -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 +14 -0
- package/dist/core/verify.js +43 -0
- package/dist/core/verify.js.map +1 -0
- package/dist/main.d.ts +2 -2
- package/dist/main.js +3 -2
- package/dist/main.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 +49 -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 +26 -0
- package/dist/storage/sqlite/storage-sqlite.js +213 -0
- package/dist/storage/sqlite/storage-sqlite.js.map +1 -0
- package/package.json +38 -26
- package/dist/cli/main.d.ts +0 -2
- 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/events/main.d.ts
DELETED
package/dist/events/main.js
DELETED
package/dist/events/reply.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { DataObject } from "../data-type.ts";
|
|
2
|
-
export interface ReplyArgs {
|
|
3
|
-
dt?: string;
|
|
4
|
-
r: string;
|
|
5
|
-
a: DataObject;
|
|
6
|
-
}
|
|
7
|
-
export interface ReplyEvent {
|
|
8
|
-
v: string;
|
|
9
|
-
t: "rpy";
|
|
10
|
-
d: string;
|
|
11
|
-
dt: string;
|
|
12
|
-
r: string;
|
|
13
|
-
a: DataObject;
|
|
14
|
-
}
|
|
15
|
-
export declare function reply(data: ReplyArgs): ReplyEvent;
|
package/dist/events/reply.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { blake3 } from "@noble/hashes/blake3";
|
|
2
|
-
import cesr from "../parser/cesr-encoding.js";
|
|
3
|
-
import { MatterCode } from "../parser/codes.js";
|
|
4
|
-
import { versify } from "../parser/version.js";
|
|
5
|
-
export function reply(data) {
|
|
6
|
-
const event = versify({
|
|
7
|
-
t: "rpy",
|
|
8
|
-
d: "#".repeat(44),
|
|
9
|
-
dt: data.dt ?? new Date().toISOString(),
|
|
10
|
-
r: data.r,
|
|
11
|
-
a: data.a,
|
|
12
|
-
});
|
|
13
|
-
const encoder = new TextEncoder();
|
|
14
|
-
const digest = cesr.encode(MatterCode.Blake3_256, blake3
|
|
15
|
-
.create({ dkLen: 32 })
|
|
16
|
-
.update(encoder.encode(JSON.stringify(event)))
|
|
17
|
-
.digest());
|
|
18
|
-
event["d"] = digest;
|
|
19
|
-
return event;
|
|
20
|
-
}
|
package/dist/keri/habitat.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { EventStore, KeyEventMessage } from "../db/event-store.ts";
|
|
2
|
-
import type { KeyStore } from "../keystore/keystore.ts";
|
|
3
|
-
import type { InteractEvent, InceptEvent } from "../events/main.ts";
|
|
4
|
-
export interface HabitatDeps {
|
|
5
|
-
keystore: KeyStore;
|
|
6
|
-
db: EventStore;
|
|
7
|
-
}
|
|
8
|
-
export interface InceptIdentifierArgs {
|
|
9
|
-
wits: string[];
|
|
10
|
-
toad?: number;
|
|
11
|
-
}
|
|
12
|
-
export declare class Habitat {
|
|
13
|
-
#private;
|
|
14
|
-
constructor(deps: HabitatDeps);
|
|
15
|
-
create(args: InceptIdentifierArgs): Promise<InceptEvent>;
|
|
16
|
-
interact(aid: string): Promise<InteractEvent>;
|
|
17
|
-
resolve(oobi: string): Promise<void>;
|
|
18
|
-
submit(eventId: string): Promise<void>;
|
|
19
|
-
list(id: string): Promise<KeyEventMessage[]>;
|
|
20
|
-
}
|
package/dist/keri/habitat.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Habitat_db, _Habitat_keystore;
|
|
13
|
-
import { cesr, CounterCode } from "../main-common.js";
|
|
14
|
-
import { parse } from "../parser/parser.js";
|
|
15
|
-
import { resolveKeyState, submit } from "./keri.js";
|
|
16
|
-
import { interact, incept } from "../events/main.js";
|
|
17
|
-
export class Habitat {
|
|
18
|
-
constructor(deps) {
|
|
19
|
-
_Habitat_db.set(this, void 0);
|
|
20
|
-
_Habitat_keystore.set(this, void 0);
|
|
21
|
-
__classPrivateFieldSet(this, _Habitat_db, deps.db, "f");
|
|
22
|
-
__classPrivateFieldSet(this, _Habitat_keystore, deps.keystore, "f");
|
|
23
|
-
}
|
|
24
|
-
async create(args) {
|
|
25
|
-
const keys = [await __classPrivateFieldGet(this, _Habitat_keystore, "f").incept(), await __classPrivateFieldGet(this, _Habitat_keystore, "f").incept()];
|
|
26
|
-
const toad = args.toad ?? (args.wits.length === 0 ? 0 : args.wits.length === 1 ? 1 : args.wits.length - 1);
|
|
27
|
-
const payload = incept({
|
|
28
|
-
kt: "1",
|
|
29
|
-
k: keys.map((key) => key.current),
|
|
30
|
-
nt: "1",
|
|
31
|
-
n: keys.map((key) => key.next),
|
|
32
|
-
bt: toad.toString(),
|
|
33
|
-
b: args.wits,
|
|
34
|
-
});
|
|
35
|
-
await __classPrivateFieldGet(this, _Habitat_db, "f").saveEvent(payload);
|
|
36
|
-
const raw = new TextEncoder().encode(JSON.stringify(payload));
|
|
37
|
-
await Promise.all(keys.map(async (key, index) => {
|
|
38
|
-
const sig = await __classPrivateFieldGet(this, _Habitat_keystore, "f").sign(key.current, raw);
|
|
39
|
-
await __classPrivateFieldGet(this, _Habitat_db, "f").saveAttachment(payload.d, {
|
|
40
|
-
code: CounterCode.ControllerIdxSigs,
|
|
41
|
-
value: cesr.index(sig, index),
|
|
42
|
-
});
|
|
43
|
-
}));
|
|
44
|
-
await this.submit(payload.d);
|
|
45
|
-
return payload;
|
|
46
|
-
}
|
|
47
|
-
async interact(aid) {
|
|
48
|
-
const events = await __classPrivateFieldGet(this, _Habitat_db, "f").list({ i: aid });
|
|
49
|
-
if (events.length === 0) {
|
|
50
|
-
throw new Error(`Could not find aid ${aid}`);
|
|
51
|
-
}
|
|
52
|
-
const state = resolveKeyState(events.map((e) => e.event));
|
|
53
|
-
const payload = interact({
|
|
54
|
-
i: aid,
|
|
55
|
-
s: (parseInt(state.s, 16) + 1).toString(),
|
|
56
|
-
a: [],
|
|
57
|
-
p: state.event,
|
|
58
|
-
});
|
|
59
|
-
await __classPrivateFieldGet(this, _Habitat_db, "f").saveEvent(payload);
|
|
60
|
-
const raw = new TextEncoder().encode(JSON.stringify(payload));
|
|
61
|
-
await Promise.all(state.keys.map(async (key, index) => {
|
|
62
|
-
const sig = await __classPrivateFieldGet(this, _Habitat_keystore, "f").sign(key, raw);
|
|
63
|
-
await __classPrivateFieldGet(this, _Habitat_db, "f").saveAttachment(payload.d, {
|
|
64
|
-
code: CounterCode.ControllerIdxSigs,
|
|
65
|
-
value: cesr.index(sig, index),
|
|
66
|
-
});
|
|
67
|
-
}));
|
|
68
|
-
await this.submit(payload.d);
|
|
69
|
-
return payload;
|
|
70
|
-
}
|
|
71
|
-
async resolve(oobi) {
|
|
72
|
-
const response = await fetch(oobi);
|
|
73
|
-
if (!response.ok) {
|
|
74
|
-
throw new Error(`Failed to fetch oobi: ${response.status} ${response.statusText}`);
|
|
75
|
-
}
|
|
76
|
-
if (!response.body) {
|
|
77
|
-
throw new Error(`No body in response`);
|
|
78
|
-
}
|
|
79
|
-
for await (const event of parse(response.body)) {
|
|
80
|
-
__classPrivateFieldGet(this, _Habitat_db, "f").saveEvent(event.payload);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async submit(eventId) {
|
|
84
|
-
const [event] = await __classPrivateFieldGet(this, _Habitat_db, "f").list({ d: eventId });
|
|
85
|
-
if (!event || !("i" in event.event && typeof event.event.i === "string")) {
|
|
86
|
-
throw new Error("No such event");
|
|
87
|
-
}
|
|
88
|
-
const [inception] = await __classPrivateFieldGet(this, _Habitat_db, "f").list({ i: event.event.i, t: "icp" });
|
|
89
|
-
if (!inception) {
|
|
90
|
-
throw new Error("No inception event found");
|
|
91
|
-
}
|
|
92
|
-
const state = resolveKeyState([inception.event]);
|
|
93
|
-
const locations = await __classPrivateFieldGet(this, _Habitat_db, "f").list({ t: "rpy", r: "/loc/scheme" });
|
|
94
|
-
const witnessEndpoints = await Promise.all(state.wits.map((wit) => {
|
|
95
|
-
const result = locations.map((loc) => loc.event).find((rpy) => rpy.a.eid === wit);
|
|
96
|
-
if (!result) {
|
|
97
|
-
throw new Error(`No location found for wit ${wit}`);
|
|
98
|
-
}
|
|
99
|
-
return result.a.url;
|
|
100
|
-
}));
|
|
101
|
-
for (const wit of witnessEndpoints) {
|
|
102
|
-
const response = await submit({
|
|
103
|
-
event: event.event,
|
|
104
|
-
signatures: {
|
|
105
|
-
controllers: event.attachments
|
|
106
|
-
.filter((attachment) => attachment.code === CounterCode.ControllerIdxSigs)
|
|
107
|
-
.map((attachment) => attachment.value),
|
|
108
|
-
witnesses: [],
|
|
109
|
-
},
|
|
110
|
-
}, wit);
|
|
111
|
-
for await (const receipt of parse(response)) {
|
|
112
|
-
await __classPrivateFieldGet(this, _Habitat_db, "f").saveEvent(receipt.payload);
|
|
113
|
-
let code = null;
|
|
114
|
-
for (const attachment of receipt.attachments) {
|
|
115
|
-
if (attachment.startsWith("-")) {
|
|
116
|
-
code = attachment;
|
|
117
|
-
}
|
|
118
|
-
else if (code) {
|
|
119
|
-
await __classPrivateFieldGet(this, _Habitat_db, "f").saveAttachment(receipt.payload.d, { code: code, value: attachment });
|
|
120
|
-
code = null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async list(id) {
|
|
127
|
-
return __classPrivateFieldGet(this, _Habitat_db, "f").list({ i: id });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
_Habitat_db = new WeakMap(), _Habitat_keystore = new WeakMap();
|
package/dist/keri/keri.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { KeyEvent } from "../events/main.ts";
|
|
2
|
-
export interface WitnessSignature {
|
|
3
|
-
aid: string;
|
|
4
|
-
signature: string;
|
|
5
|
-
}
|
|
6
|
-
export interface KeyEventSignatures {
|
|
7
|
-
controllers: string[];
|
|
8
|
-
witnesses?: WitnessSignature[];
|
|
9
|
-
}
|
|
10
|
-
export interface KeyEventMessage {
|
|
11
|
-
event: KeyEvent;
|
|
12
|
-
signatures: KeyEventSignatures;
|
|
13
|
-
}
|
|
14
|
-
export declare function resolveKeyState(events: KeyEvent[]): {
|
|
15
|
-
s: string;
|
|
16
|
-
prefix: string;
|
|
17
|
-
event: string;
|
|
18
|
-
wits: string[];
|
|
19
|
-
keys: string[];
|
|
20
|
-
sith: import("../main-common.ts").Threshold;
|
|
21
|
-
};
|
|
22
|
-
export declare function serializeAttachment(message: KeyEventMessage): string;
|
|
23
|
-
export interface Receipt {
|
|
24
|
-
event: KeyEvent;
|
|
25
|
-
}
|
|
26
|
-
export declare function submit(message: KeyEventMessage, witnessEndpoint: string): Promise<ReadableStream<Uint8Array>>;
|
package/dist/keri/keri.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { CounterCode, encodeBase64Int } from "../main-common.js";
|
|
2
|
-
export function resolveKeyState(events) {
|
|
3
|
-
const inception = events[0];
|
|
4
|
-
if (inception.t !== "icp") {
|
|
5
|
-
throw new Error("First event was not inception");
|
|
6
|
-
}
|
|
7
|
-
return {
|
|
8
|
-
s: "0",
|
|
9
|
-
prefix: inception.d,
|
|
10
|
-
event: inception.d,
|
|
11
|
-
wits: inception.b,
|
|
12
|
-
keys: inception.k,
|
|
13
|
-
sith: inception.kt,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export function serializeAttachment(message) {
|
|
17
|
-
const sigs = message.signatures.controllers;
|
|
18
|
-
const controllerSigs = `${CounterCode.ControllerIdxSigs}${encodeBase64Int(message.signatures.controllers.length, 2)}${sigs.join("")}`;
|
|
19
|
-
const attachmentSize = new TextEncoder().encode(controllerSigs).length / 4;
|
|
20
|
-
const attachment = `${CounterCode.AttachmentGroup}${encodeBase64Int(attachmentSize, 2)}${controllerSigs}`;
|
|
21
|
-
return attachment;
|
|
22
|
-
}
|
|
23
|
-
export async function submit(message, witnessEndpoint) {
|
|
24
|
-
const url = new URL("/receipts", witnessEndpoint);
|
|
25
|
-
const response = await fetch(url, {
|
|
26
|
-
method: "POST",
|
|
27
|
-
body: JSON.stringify(message.event),
|
|
28
|
-
headers: {
|
|
29
|
-
"Content-Type": "application/cesr+json",
|
|
30
|
-
"CESR-ATTACHMENT": serializeAttachment(message),
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
throw new Error(`Failed to send event to wit ${witnessEndpoint}: ${response.status} ${response.statusText}`);
|
|
35
|
-
}
|
|
36
|
-
if (response.status !== 200) {
|
|
37
|
-
throw new Error(`Failed to send event to wit ${witnessEndpoint}: ${response.status} ${response.statusText}`);
|
|
38
|
-
}
|
|
39
|
-
if (!response.body) {
|
|
40
|
-
throw new Error(`Failed to send event to wit ${witnessEndpoint}: ${response.status} ${response.statusText}`);
|
|
41
|
-
}
|
|
42
|
-
return response.body;
|
|
43
|
-
}
|
package/dist/keystore/encrypt.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export async function encrypt(passphrase, data) {
|
|
2
|
-
const encoder = new TextEncoder();
|
|
3
|
-
const encryptionKey = await crypto.subtle.importKey("raw", encoder.encode(passphrase), "PBKDF2", false, [
|
|
4
|
-
"deriveBits",
|
|
5
|
-
"deriveKey",
|
|
6
|
-
]);
|
|
7
|
-
const salt = crypto.getRandomValues(new Uint8Array(16));
|
|
8
|
-
const iv = crypto.getRandomValues(new Uint8Array(16));
|
|
9
|
-
const key = await crypto.subtle.deriveKey({
|
|
10
|
-
name: "PBKDF2",
|
|
11
|
-
salt,
|
|
12
|
-
iterations: 100000,
|
|
13
|
-
hash: "SHA-256",
|
|
14
|
-
}, encryptionKey, { name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
|
|
15
|
-
const encrypted = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, data);
|
|
16
|
-
const result = new Uint8Array(salt.byteLength + iv.byteLength + encrypted.byteLength);
|
|
17
|
-
result.set(salt, 0);
|
|
18
|
-
result.set(iv, salt.byteLength);
|
|
19
|
-
result.set(new Uint8Array(encrypted), salt.byteLength + iv.byteLength);
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
export async function decrypt(passphrase, ciphertext) {
|
|
23
|
-
const encoder = new TextEncoder();
|
|
24
|
-
const keyMaterial = await crypto.subtle.importKey("raw", encoder.encode(passphrase), "PBKDF2", false, [
|
|
25
|
-
"deriveBits",
|
|
26
|
-
"deriveKey",
|
|
27
|
-
]);
|
|
28
|
-
const salt = ciphertext.slice(0, 16);
|
|
29
|
-
const iv = ciphertext.slice(16, 32);
|
|
30
|
-
const encrypted = ciphertext.slice(32);
|
|
31
|
-
const key = await crypto.subtle.deriveKey({
|
|
32
|
-
name: "PBKDF2",
|
|
33
|
-
salt,
|
|
34
|
-
iterations: 100000,
|
|
35
|
-
hash: "SHA-256",
|
|
36
|
-
}, keyMaterial, { name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
|
|
37
|
-
return new Uint8Array(await crypto.subtle.decrypt({ name: "AES-GCM", iv }, key, encrypted));
|
|
38
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { KeyStore, Key } from "./keystore.ts";
|
|
2
|
-
export interface FileSystemKeyStoreOptions {
|
|
3
|
-
dir: string;
|
|
4
|
-
passphrase: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class FileSystemKeyStore implements KeyStore {
|
|
7
|
-
options: FileSystemKeyStoreOptions;
|
|
8
|
-
constructor(options: FileSystemKeyStoreOptions);
|
|
9
|
-
private load;
|
|
10
|
-
incept(): Promise<Key>;
|
|
11
|
-
rotate(currentKey: string): Promise<Key>;
|
|
12
|
-
sign(publicKey: string, message: Uint8Array): Promise<string>;
|
|
13
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ed25519 } from "@noble/curves/ed25519";
|
|
2
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import cesr from "../parser/cesr-encoding.js";
|
|
4
|
-
import { MatterCode } from "../parser/codes.js";
|
|
5
|
-
import { decodeBase64, encodeBase64 } from "../parser/base64.js";
|
|
6
|
-
import { decrypt, encrypt } from "./encrypt.js";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { blake3 } from "@noble/hashes/blake3";
|
|
9
|
-
export class FileSystemKeyStore {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
async load(publicKey) {
|
|
14
|
-
const value = await readFile(join(this.options.dir, publicKey), "utf-8");
|
|
15
|
-
const [key0, key1] = value.split("\n");
|
|
16
|
-
return [
|
|
17
|
-
await decrypt(this.options.passphrase, decodeBase64(key0)),
|
|
18
|
-
await decrypt(this.options.passphrase, decodeBase64(key1)),
|
|
19
|
-
];
|
|
20
|
-
}
|
|
21
|
-
async incept() {
|
|
22
|
-
const key0 = ed25519.utils.randomPrivateKey();
|
|
23
|
-
const key1 = ed25519.utils.randomPrivateKey();
|
|
24
|
-
await mkdir(this.options.dir, { recursive: true });
|
|
25
|
-
const current = cesr.encode(MatterCode.Ed25519, ed25519.getPublicKey(key0));
|
|
26
|
-
const next = cesr.encode(MatterCode.Blake3_256, blake3.create({ dkLen: 32 }).update(current).digest());
|
|
27
|
-
await writeFile(join(this.options.dir, current), [
|
|
28
|
-
encodeBase64(await encrypt(this.options.passphrase, key0)),
|
|
29
|
-
encodeBase64(await encrypt(this.options.passphrase, key1)),
|
|
30
|
-
"\n",
|
|
31
|
-
].join("\n"));
|
|
32
|
-
return { current, next };
|
|
33
|
-
}
|
|
34
|
-
async rotate(currentKey) {
|
|
35
|
-
const [, key0] = await this.load(currentKey);
|
|
36
|
-
const key1 = ed25519.utils.randomPrivateKey();
|
|
37
|
-
const current = cesr.encode(MatterCode.Ed25519, ed25519.getPublicKey(key0));
|
|
38
|
-
const next = cesr.encode(MatterCode.Blake3_256, blake3.create({ dkLen: 32 }).update(current).digest());
|
|
39
|
-
await writeFile(join(this.options.dir, current), [
|
|
40
|
-
encodeBase64(await encrypt(this.options.passphrase, key0)),
|
|
41
|
-
encodeBase64(await encrypt(this.options.passphrase, key1)),
|
|
42
|
-
"\n",
|
|
43
|
-
].join("\n"));
|
|
44
|
-
return { current, next };
|
|
45
|
-
}
|
|
46
|
-
async sign(publicKey, message) {
|
|
47
|
-
const [key] = await this.load(publicKey);
|
|
48
|
-
return cesr.sign(message, key, "ed25519");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Key, KeyStore } from "./keystore.ts";
|
|
2
|
-
export interface WebKeyStoreOptions {
|
|
3
|
-
passphrase: string;
|
|
4
|
-
}
|
|
5
|
-
export declare class WebKeyStore implements KeyStore {
|
|
6
|
-
private readonly options;
|
|
7
|
-
constructor(options: WebKeyStoreOptions);
|
|
8
|
-
private load;
|
|
9
|
-
incept(): Promise<Key>;
|
|
10
|
-
rotate(currentKey: string): Promise<Key>;
|
|
11
|
-
sign(publicKey: string, message: Uint8Array): Promise<string>;
|
|
12
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ed25519 } from "@noble/curves/ed25519";
|
|
2
|
-
import cesr from "../parser/cesr-encoding.js";
|
|
3
|
-
import { MatterCode } from "../parser/codes.js";
|
|
4
|
-
import { decodeBase64, encodeBase64 } from "../parser/base64.js";
|
|
5
|
-
import { decrypt, encrypt } from "./encrypt.js";
|
|
6
|
-
import { blake3 } from "@noble/hashes/blake3";
|
|
7
|
-
export class WebKeyStore {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.options = options;
|
|
10
|
-
}
|
|
11
|
-
async load(publicKey) {
|
|
12
|
-
const value = localStorage.getItem(publicKey);
|
|
13
|
-
if (!value) {
|
|
14
|
-
throw new Error("No such key");
|
|
15
|
-
}
|
|
16
|
-
const [key0, key1] = value.split("\n");
|
|
17
|
-
return [
|
|
18
|
-
await decrypt(this.options.passphrase, decodeBase64(key0)),
|
|
19
|
-
await decrypt(this.options.passphrase, decodeBase64(key1)),
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
async incept() {
|
|
23
|
-
const key0 = ed25519.utils.randomPrivateKey();
|
|
24
|
-
const key1 = ed25519.utils.randomPrivateKey();
|
|
25
|
-
const current = cesr.encode(MatterCode.Ed25519, ed25519.getPublicKey(key0));
|
|
26
|
-
const next = cesr.encode(MatterCode.Blake3_256, blake3.create({ dkLen: 32 }).update(current).digest());
|
|
27
|
-
localStorage.setItem(current, [
|
|
28
|
-
encodeBase64(await encrypt(this.options.passphrase, key0)),
|
|
29
|
-
encodeBase64(await encrypt(this.options.passphrase, key1)),
|
|
30
|
-
].join("\n"));
|
|
31
|
-
return { current, next };
|
|
32
|
-
}
|
|
33
|
-
async rotate(currentKey) {
|
|
34
|
-
const [, key0] = await this.load(currentKey);
|
|
35
|
-
const key1 = ed25519.utils.randomPrivateKey();
|
|
36
|
-
const current = cesr.encode(MatterCode.Ed25519, ed25519.getPublicKey(key0));
|
|
37
|
-
const next = cesr.encode(MatterCode.Blake3_256, blake3.create({ dkLen: 32 }).update(current).digest());
|
|
38
|
-
localStorage.setItem(current, [
|
|
39
|
-
encodeBase64(await encrypt(this.options.passphrase, key0)),
|
|
40
|
-
encodeBase64(await encrypt(this.options.passphrase, key1)),
|
|
41
|
-
].join("\n"));
|
|
42
|
-
return { current, next };
|
|
43
|
-
}
|
|
44
|
-
async sign(publicKey, message) {
|
|
45
|
-
const [key] = await this.load(publicKey);
|
|
46
|
-
return cesr.sign(message, key, "ed25519");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface Key {
|
|
2
|
-
/**
|
|
3
|
-
* The public key of the tranferable key.
|
|
4
|
-
*/
|
|
5
|
-
current: string;
|
|
6
|
-
/**
|
|
7
|
-
* Digest of the next public key of the key pair.
|
|
8
|
-
*/
|
|
9
|
-
next: string;
|
|
10
|
-
}
|
|
11
|
-
export interface KeyStore {
|
|
12
|
-
incept(): Promise<Key>;
|
|
13
|
-
rotate(currentKey: string): Promise<Key>;
|
|
14
|
-
sign(publicKey: string, message: Uint8Array): Promise<string>;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/main-common.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import cesr from "./parser/cesr-encoding.ts";
|
|
2
|
-
import * as keri from "./events/main.ts";
|
|
3
|
-
export type * from "./events/main.ts";
|
|
4
|
-
export * from "./keystore/keystore.ts";
|
|
5
|
-
export * from "./parser/codes.ts";
|
|
6
|
-
export * from "./parser/base64.ts";
|
|
7
|
-
export * from "./parser/parser.ts";
|
|
8
|
-
export * from "./keri/habitat.ts";
|
|
9
|
-
export { keri, cesr };
|
package/dist/main-common.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import cesr from "./parser/cesr-encoding.js";
|
|
2
|
-
import * as keri from "./events/main.js";
|
|
3
|
-
export * from "./keystore/keystore.js";
|
|
4
|
-
export * from "./parser/codes.js";
|
|
5
|
-
export * from "./parser/base64.js";
|
|
6
|
-
export * from "./parser/parser.js";
|
|
7
|
-
export * from "./keri/habitat.js";
|
|
8
|
-
export { keri, cesr };
|
package/dist/main-web.d.ts
DELETED
package/dist/main-web.js
DELETED
package/dist/parser/base64.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare function encodeBase64(uint8: Uint8Array): string;
|
|
2
|
-
export declare function decodeBase64(b64: string): Uint8Array;
|
|
3
|
-
export declare function decodeBase64Int(value: string): number;
|
|
4
|
-
export declare function encodeBase64Int(value: number, length?: number): string;
|
|
5
|
-
export declare function encodeBase64Url(buffer: Uint8Array): string;
|
|
6
|
-
export declare function decodeBase64Url(input: string): Uint8Array;
|
package/dist/parser/base64.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
2
|
-
const B64_URL_MAP = ALPHABET.split("");
|
|
3
|
-
const B64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
4
|
-
export function encodeBase64(uint8) {
|
|
5
|
-
// CREDIT: https://github.com/denoland/std/blob/main/encoding/base64.ts
|
|
6
|
-
// CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
7
|
-
let result = "";
|
|
8
|
-
let i;
|
|
9
|
-
const l = uint8.length;
|
|
10
|
-
for (i = 2; i < l; i += 3) {
|
|
11
|
-
result += B64_ALPHABET[uint8[i - 2] >> 2];
|
|
12
|
-
result += B64_ALPHABET[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
13
|
-
result += B64_ALPHABET[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
14
|
-
result += B64_ALPHABET[uint8[i] & 0x3f];
|
|
15
|
-
}
|
|
16
|
-
if (i === l + 1) {
|
|
17
|
-
// 1 octet yet to write
|
|
18
|
-
result += B64_ALPHABET[uint8[i - 2] >> 2];
|
|
19
|
-
result += B64_ALPHABET[(uint8[i - 2] & 0x03) << 4];
|
|
20
|
-
result += "==";
|
|
21
|
-
}
|
|
22
|
-
if (i === l) {
|
|
23
|
-
// 2 octets yet to write
|
|
24
|
-
result += B64_ALPHABET[uint8[i - 2] >> 2];
|
|
25
|
-
result += B64_ALPHABET[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
26
|
-
result += B64_ALPHABET[(uint8[i - 1] & 0x0f) << 2];
|
|
27
|
-
result += "=";
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
export function decodeBase64(b64) {
|
|
32
|
-
// CREDIT: https://github.com/denoland/std/blob/main/encoding/base64.ts
|
|
33
|
-
const binString = atob(b64);
|
|
34
|
-
const size = binString.length;
|
|
35
|
-
const bytes = new Uint8Array(size);
|
|
36
|
-
for (let i = 0; i < size; i++) {
|
|
37
|
-
bytes[i] = binString.charCodeAt(i);
|
|
38
|
-
}
|
|
39
|
-
return bytes;
|
|
40
|
-
}
|
|
41
|
-
export function decodeBase64Int(value) {
|
|
42
|
-
return value
|
|
43
|
-
.split("")
|
|
44
|
-
.reverse()
|
|
45
|
-
.reduce((result, character, index) => {
|
|
46
|
-
const value = ALPHABET.indexOf(character);
|
|
47
|
-
const factor = 64 ** index;
|
|
48
|
-
return result + value * factor;
|
|
49
|
-
}, 0);
|
|
50
|
-
}
|
|
51
|
-
export function encodeBase64Int(value, length = 1) {
|
|
52
|
-
let current = value;
|
|
53
|
-
let result = "";
|
|
54
|
-
while (length != 0) {
|
|
55
|
-
result = B64_URL_MAP[current % 64] + result;
|
|
56
|
-
current = Math.floor(current / 64);
|
|
57
|
-
if (current == 0) {
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return result.padStart(length, "A");
|
|
62
|
-
}
|
|
63
|
-
export function encodeBase64Url(buffer) {
|
|
64
|
-
return encodeBase64(buffer).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+/, "");
|
|
65
|
-
}
|
|
66
|
-
export function decodeBase64Url(input) {
|
|
67
|
-
if (!(typeof input === "string")) {
|
|
68
|
-
throw new TypeError("`input` must be a string.");
|
|
69
|
-
}
|
|
70
|
-
const n = input.length % 4;
|
|
71
|
-
const padded = input + "=".repeat(n > 0 ? 4 - n : n);
|
|
72
|
-
const base64String = padded.replace(/-/g, "+").replace(/_/g, "/");
|
|
73
|
-
return decodeBase64(base64String);
|
|
74
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _BufferedReader_stream, _BufferedReader_buffer;
|
|
13
|
-
function concat(a, b) {
|
|
14
|
-
if (a.length === 0) {
|
|
15
|
-
return b;
|
|
16
|
-
}
|
|
17
|
-
if (b.length === 0) {
|
|
18
|
-
return a;
|
|
19
|
-
}
|
|
20
|
-
const merged = new Uint8Array(a.length + b.length);
|
|
21
|
-
merged.set(a);
|
|
22
|
-
merged.set(b, a.length);
|
|
23
|
-
return merged;
|
|
24
|
-
}
|
|
25
|
-
export class BufferedReader {
|
|
26
|
-
constructor(stream) {
|
|
27
|
-
_BufferedReader_stream.set(this, void 0);
|
|
28
|
-
_BufferedReader_buffer.set(this, void 0);
|
|
29
|
-
__classPrivateFieldSet(this, _BufferedReader_stream, stream, "f");
|
|
30
|
-
}
|
|
31
|
-
async readBytes(size) {
|
|
32
|
-
if (typeof size !== "number") {
|
|
33
|
-
throw new Error(`Size must be a number, got '${size}'`);
|
|
34
|
-
}
|
|
35
|
-
while (!__classPrivateFieldGet(this, _BufferedReader_buffer, "f") || __classPrivateFieldGet(this, _BufferedReader_buffer, "f").length < size) {
|
|
36
|
-
const result = await __classPrivateFieldGet(this, _BufferedReader_stream, "f").next();
|
|
37
|
-
if (result.done) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
__classPrivateFieldSet(this, _BufferedReader_buffer, concat(__classPrivateFieldGet(this, _BufferedReader_buffer, "f") ?? new Uint8Array(0), result.value), "f");
|
|
41
|
-
}
|
|
42
|
-
const chunk = __classPrivateFieldGet(this, _BufferedReader_buffer, "f").slice(0, size);
|
|
43
|
-
__classPrivateFieldSet(this, _BufferedReader_buffer, __classPrivateFieldGet(this, _BufferedReader_buffer, "f").slice(size), "f");
|
|
44
|
-
return chunk;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
_BufferedReader_stream = new WeakMap(), _BufferedReader_buffer = new WeakMap();
|