@kumiai/mls-rpc 0.13.1 → 0.13.3
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/lib/mls.d.ts +3 -0
- package/lib/mls.js +12 -5
- package/lib/recovery.d.ts +3 -1
- package/lib/recovery.js +8 -4
- package/package.json +5 -5
package/lib/mls.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { OwnIdentity } from '@kokuin/token';
|
|
2
2
|
import { type GroupHandle } from '@kumiai/mls';
|
|
3
3
|
import type { GroupMLS } from '@kumiai/rpc';
|
|
4
|
+
import { type Now, type Runtime } from '@sozai/runtime';
|
|
4
5
|
import { type HandleAccess } from './access.js';
|
|
5
6
|
import { type RecoveryBinding } from './recovery.js';
|
|
6
7
|
export declare const groupHandleAccess: WeakMap<GroupMLS, HandleAccess>;
|
|
@@ -36,6 +37,7 @@ export type LedgerEntrySlot = {
|
|
|
36
37
|
};
|
|
37
38
|
export declare function createLedgerEntrySlot(): LedgerEntrySlot;
|
|
38
39
|
export type GroupMLSParams = {
|
|
40
|
+
runtime?: Runtime;
|
|
39
41
|
access: HandleAccess;
|
|
40
42
|
/** This member's signing identity: recovery requests and attestations are signed with it. */
|
|
41
43
|
identity: OwnIdentity;
|
|
@@ -62,6 +64,7 @@ export type RecoveryPending = {
|
|
|
62
64
|
};
|
|
63
65
|
export declare function createRecoveryPending(options?: {
|
|
64
66
|
ttlMS?: number;
|
|
67
|
+
monotonicNow?: Now;
|
|
65
68
|
}): RecoveryPending;
|
|
66
69
|
export declare function deriveRecoverySecret(handle: GroupHandle): Promise<Uint8Array>;
|
|
67
70
|
/**
|
package/lib/mls.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { confirmationKey, createRecoveryRequest, encodeGroupAnchor, ledgerEntryDigest, MissingLedgerEntriesError, openRecoveryGroupInfo, openRecoveryVerdict, openSealedLedger, readCommitEntryIDs, readMessageEpoch, recoverySignerEligible, sealGroupInfo, sealLedger, sealRecoveryVerdict, verifyRecoveryRequest } from '@kumiai/mls';
|
|
2
|
+
import { createRuntime } from '@sozai/runtime';
|
|
2
3
|
import { guardedReplace } from './access.js';
|
|
3
4
|
import { applyCommit } from './apply-commit.js';
|
|
4
5
|
import { createRecoveryBindingState, createVerdictJudge } from './recovery.js';
|
|
@@ -37,6 +38,7 @@ export function createLedgerEntrySlot() {
|
|
|
37
38
|
* timeout without saying so — so this bounds it off the mint time.
|
|
38
39
|
*/ const REQUEST_TTL_MS = 120_000;
|
|
39
40
|
export function createRecoveryPending(options) {
|
|
41
|
+
const monotonicNow = options?.monotonicNow ?? createRuntime().monotonicNow;
|
|
40
42
|
const ttlMS = options?.ttlMS ?? REQUEST_TTL_MS;
|
|
41
43
|
const requests = new Map();
|
|
42
44
|
const remove = (requestID, request)=>{
|
|
@@ -45,7 +47,7 @@ export function createRecoveryPending(options) {
|
|
|
45
47
|
requests.delete(requestID);
|
|
46
48
|
};
|
|
47
49
|
const sweep = ()=>{
|
|
48
|
-
const now =
|
|
50
|
+
const now = monotonicNow();
|
|
49
51
|
for (const [id, request] of requests){
|
|
50
52
|
if (request.expiresAt <= now) remove(id, request);
|
|
51
53
|
}
|
|
@@ -68,7 +70,7 @@ export function createRecoveryPending(options) {
|
|
|
68
70
|
nodeTimer.unref?.();
|
|
69
71
|
requests.set(requestID, {
|
|
70
72
|
ephemeralPrivateKey,
|
|
71
|
-
expiresAt:
|
|
73
|
+
expiresAt: monotonicNow() + retentionMs,
|
|
72
74
|
timer
|
|
73
75
|
});
|
|
74
76
|
},
|
|
@@ -109,8 +111,11 @@ export async function deriveRecoverySecret(handle) {
|
|
|
109
111
|
* host must not put anything on it that confidentiality depends on.
|
|
110
112
|
*/ export function createGroupMLS(params) {
|
|
111
113
|
const { access, identity, entrySlot } = params;
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
+
const runtime = createRuntime(params.runtime);
|
|
115
|
+
const pending = createRecoveryPending({
|
|
116
|
+
monotonicNow: runtime.monotonicNow
|
|
117
|
+
});
|
|
118
|
+
const recovery = createRecoveryBindingState(identity, params.recoveryBinding, runtime.now);
|
|
114
119
|
const port = {
|
|
115
120
|
async verifyRecoveryRequest (request) {
|
|
116
121
|
try {
|
|
@@ -315,9 +320,11 @@ export async function deriveRecoverySecret(handle) {
|
|
|
315
320
|
if (rejoined.group.anchor.controller != null && !await recoverySignerEligible({
|
|
316
321
|
group: rejoined.group,
|
|
317
322
|
registry: rejoined.knownRegistry,
|
|
318
|
-
signer: reply.signer
|
|
323
|
+
signer: reply.signer,
|
|
324
|
+
now: runtime.now
|
|
319
325
|
})) return null;
|
|
320
326
|
const judge = createVerdictJudge({
|
|
327
|
+
now: runtime.now,
|
|
321
328
|
group: rejoined.group,
|
|
322
329
|
sourceTree: rejoined.sourceTree,
|
|
323
330
|
known: rejoined.knownRegistry,
|
package/lib/recovery.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type OwnIdentity } from '@kokuin/token';
|
|
2
2
|
import { type ClientState, type ControllerBinding, type DeviceRegistry, type GroupHandle } from '@kumiai/mls';
|
|
3
3
|
import type { OpenedRecoveryVerdict, PendingRecovery, PendingRecoveryConfirmationKeyParams } from '@kumiai/rpc';
|
|
4
|
+
import type { Now } from '@sozai/runtime';
|
|
4
5
|
export type RecoveryBindingRequest = {
|
|
5
6
|
groupID: string;
|
|
6
7
|
controllerID: string;
|
|
@@ -13,6 +14,7 @@ export type RecoveryReply = {
|
|
|
13
14
|
signer: string;
|
|
14
15
|
};
|
|
15
16
|
export type VerdictJudgeParams = {
|
|
17
|
+
now: Now;
|
|
16
18
|
group: GroupHandle;
|
|
17
19
|
sourceTree: ClientState['ratchetTree'];
|
|
18
20
|
known: DeviceRegistry;
|
|
@@ -27,7 +29,7 @@ export type RecoveryCandidate = PendingRecovery & {
|
|
|
27
29
|
replyLedger: Array<string>;
|
|
28
30
|
signer: string;
|
|
29
31
|
};
|
|
30
|
-
export declare function createRecoveryBindingState(identity: OwnIdentity, host
|
|
32
|
+
export declare function createRecoveryBindingState(identity: OwnIdentity, host: RecoveryBinding | undefined, now: Now): {
|
|
31
33
|
prepare(group: GroupHandle): Promise<"ready" | "renewal-required">;
|
|
32
34
|
join(group: GroupHandle, reply: RecoveryReply): Promise<{
|
|
33
35
|
markBindingUnusable: () => void;
|
package/lib/recovery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizeDID } from '@kokuin/token';
|
|
2
2
|
import { assertRecoveryBinding, assertRetainsKnownEffects, confirmationKey, confirmationTag, joinGroupExternal, LeafBindingError, LeafLapsedError, parseMLSCredentialIdentity, RevokeProofError, recoverySignerEligible } from '@kumiai/mls';
|
|
3
|
-
export function createRecoveryBindingState(identity, host) {
|
|
3
|
+
export function createRecoveryBindingState(identity, host, now) {
|
|
4
4
|
let binding;
|
|
5
5
|
let asked = false;
|
|
6
6
|
let prepared = false;
|
|
@@ -26,6 +26,7 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
26
26
|
if (unusable.has(bindingID(candidate))) return false;
|
|
27
27
|
try {
|
|
28
28
|
await assertRecoveryBinding({
|
|
29
|
+
now,
|
|
29
30
|
group,
|
|
30
31
|
identity,
|
|
31
32
|
controller: candidate
|
|
@@ -82,6 +83,7 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
82
83
|
const build = (controller)=>{
|
|
83
84
|
signerEligible = group.anchor.controller == null;
|
|
84
85
|
return joinGroupExternal({
|
|
86
|
+
now,
|
|
85
87
|
identity,
|
|
86
88
|
groupInfo: reply.groupInfo,
|
|
87
89
|
credential: group.credential,
|
|
@@ -98,7 +100,8 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
98
100
|
if (!await recoverySignerEligible({
|
|
99
101
|
group: pending,
|
|
100
102
|
registry: source.registry,
|
|
101
|
-
signer: reply.signer
|
|
103
|
+
signer: reply.signer,
|
|
104
|
+
now
|
|
102
105
|
})) throw new Error('Ineligible recovery attestation signer');
|
|
103
106
|
signerEligible = true;
|
|
104
107
|
candidateSource = source;
|
|
@@ -145,7 +148,7 @@ export function createRecoveryBindingState(identity, host) {
|
|
|
145
148
|
};
|
|
146
149
|
}
|
|
147
150
|
export function createVerdictJudge(params) {
|
|
148
|
-
const { group, sourceTree, known, requestID } = params;
|
|
151
|
+
const { group, sourceTree, known, requestID, now } = params;
|
|
149
152
|
let tuple;
|
|
150
153
|
return {
|
|
151
154
|
async confirmationKey ({ position, commitDigest }) {
|
|
@@ -172,7 +175,8 @@ export function createVerdictJudge(params) {
|
|
|
172
175
|
if (group.anchor.controller != null) return await recoverySignerEligible({
|
|
173
176
|
group,
|
|
174
177
|
registry: known,
|
|
175
|
-
signer
|
|
178
|
+
signer,
|
|
179
|
+
now
|
|
176
180
|
}) ? 'authoritative' : 'advisory';
|
|
177
181
|
if (verdict.verdict === 'confirmed') return 'authoritative';
|
|
178
182
|
for (const node of sourceTree){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls-rpc",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"description": "The @kumiai/rpc consumer ports (GroupCrypto, GroupMLS) implemented over @kumiai/mls",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@kokuin/token": "^0.7.1",
|
|
29
|
-
"@kumiai/mls": "^0.13.
|
|
30
|
-
"@kumiai/rpc": "^0.13.
|
|
29
|
+
"@kumiai/mls": "^0.13.4",
|
|
30
|
+
"@kumiai/rpc": "^0.13.2",
|
|
31
31
|
"@noble/ciphers": "^2.4.0",
|
|
32
|
-
"@sozai/runtime": "^0.1.
|
|
32
|
+
"@sozai/runtime": "^0.1.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@kumiai/rpc-conformance": "^0.13.0",
|
|
36
36
|
"ts-mls": "2.0.0-rc.13",
|
|
37
|
-
"vitest": "^5.1.
|
|
37
|
+
"vitest": "^5.1.2"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|