@kumiai/mls 0.1.0 → 0.3.0
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/README.md +21 -9
- package/lib/anchor.d.ts +87 -0
- package/lib/anchor.js +124 -0
- package/lib/credential.d.ts +3 -12
- package/lib/credential.js +0 -13
- package/lib/envelope-fold.d.ts +35 -0
- package/lib/envelope-fold.js +86 -0
- package/lib/envelope.d.ts +53 -0
- package/lib/envelope.js +87 -0
- package/lib/fold.d.ts +68 -0
- package/lib/fold.js +53 -0
- package/lib/group-commit.d.ts +100 -0
- package/lib/group-commit.js +252 -0
- package/lib/group-context.d.ts +11 -0
- package/lib/group-context.js +33 -0
- package/lib/group-create.d.ts +19 -0
- package/lib/group-create.js +85 -0
- package/lib/group-credential.d.ts +6 -0
- package/lib/group-credential.js +39 -0
- package/lib/group-handle.d.ts +177 -0
- package/lib/group-handle.js +613 -0
- package/lib/group-info.d.ts +57 -0
- package/lib/group-info.js +85 -0
- package/lib/group-membership.d.ts +25 -0
- package/lib/group-membership.js +36 -0
- package/lib/group-welcome.d.ts +67 -0
- package/lib/group-welcome.js +178 -0
- package/lib/group.d.ts +7 -233
- package/lib/group.js +7 -653
- package/lib/head.d.ts +79 -0
- package/lib/head.js +150 -0
- package/lib/index.d.ts +11 -3
- package/lib/index.js +11 -3
- package/lib/ledger.d.ts +49 -0
- package/lib/ledger.js +67 -0
- package/lib/mutex.d.ts +14 -0
- package/lib/mutex.js +20 -0
- package/lib/policy.d.ts +71 -0
- package/lib/policy.js +191 -0
- package/lib/recovery.d.ts +227 -0
- package/lib/recovery.js +456 -0
- package/lib/roster.d.ts +45 -0
- package/lib/roster.js +72 -0
- package/lib/types.d.ts +31 -11
- package/package.json +2 -3
- package/lib/capability.d.ts +0 -47
- package/lib/capability.js +0 -79
package/lib/capability.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type CapabilityPayload, type CapabilityToken, type DelegationChainOptions } from '@kokuin/capability';
|
|
2
|
-
import { type SigningIdentity } from '@kokuin/token';
|
|
3
|
-
export type GroupPermission = 'admin' | 'member' | 'read';
|
|
4
|
-
export type GroupCapabilityPayload = CapabilityPayload & {
|
|
5
|
-
act: Array<GroupPermission>;
|
|
6
|
-
res: Array<string>;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Creates a root admin capability for a group.
|
|
10
|
-
* The signer becomes the group creator and root admin (iss === sub).
|
|
11
|
-
*/
|
|
12
|
-
export declare function createGroupCapability(identity: SigningIdentity, groupID: string): Promise<CapabilityToken>;
|
|
13
|
-
export type DelegateGroupMembershipParams = {
|
|
14
|
-
identity: SigningIdentity;
|
|
15
|
-
groupID: string;
|
|
16
|
-
recipientDID: string;
|
|
17
|
-
permission: GroupPermission;
|
|
18
|
-
expiration?: number;
|
|
19
|
-
parentCapability?: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Creates a delegated membership capability for a group.
|
|
23
|
-
* The signer must be an admin with a valid capability chain.
|
|
24
|
-
*/
|
|
25
|
-
export declare function delegateGroupMembership(params: DelegateGroupMembershipParams): Promise<CapabilityToken>;
|
|
26
|
-
export type ValidateGroupCapabilityParams = {
|
|
27
|
-
tokenData: string;
|
|
28
|
-
groupID: string;
|
|
29
|
-
delegationChain?: Array<string>;
|
|
30
|
-
options?: DelegationChainOptions;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Validates that a capability token grants the specified permission for a group.
|
|
34
|
-
*
|
|
35
|
-
* Resource matching accepts three forms:
|
|
36
|
-
* - `group/<groupID>/*` — full access to a single group (what
|
|
37
|
-
* {@link createGroupCapability} and {@link delegateGroupMembership} issue)
|
|
38
|
-
* - `group/<groupID>/<suffix>` — scoped access within a single group
|
|
39
|
-
* - `*` — **global wildcard**: grants access to EVERY group, and to every
|
|
40
|
-
* other resource type in the stack that honours `*`. This is intentionally
|
|
41
|
-
* supported so root identities holding a stack-wide capability can operate
|
|
42
|
-
* on any group, but its blast radius is total: a leaked, stolen or
|
|
43
|
-
* over-delegated `res: ['*']` token compromises all groups at once. Never
|
|
44
|
-
* issue `*` to regular members or services — delegate `group/<groupID>/*`
|
|
45
|
-
* (or narrower) instead, with an `exp` and a verifiable delegation chain.
|
|
46
|
-
*/
|
|
47
|
-
export declare function validateGroupCapability(params: ValidateGroupCapabilityParams): Promise<CapabilityToken>;
|
package/lib/capability.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { assertCapabilityToken, checkDelegationChain, createCapability } from '@kokuin/capability';
|
|
2
|
-
import { normalizeDID, verifyToken } from '@kokuin/token';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a root admin capability for a group.
|
|
5
|
-
* The signer becomes the group creator and root admin (iss === sub).
|
|
6
|
-
*/ export async function createGroupCapability(identity, groupID) {
|
|
7
|
-
return await createCapability(identity, {
|
|
8
|
-
sub: identity.id,
|
|
9
|
-
aud: identity.id,
|
|
10
|
-
act: '*',
|
|
11
|
-
res: [
|
|
12
|
-
`group/${groupID}/*`
|
|
13
|
-
]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Creates a delegated membership capability for a group.
|
|
18
|
-
* The signer must be an admin with a valid capability chain.
|
|
19
|
-
*/ export async function delegateGroupMembership(params) {
|
|
20
|
-
const { identity, groupID, recipientDID, permission, expiration, parentCapability } = params;
|
|
21
|
-
// In Enkaku's capability model, `sub` is the resource owner (stays the same
|
|
22
|
-
// through the chain) and `aud` is who can exercise the capability (the recipient).
|
|
23
|
-
const payload = {
|
|
24
|
-
sub: identity.id,
|
|
25
|
-
aud: recipientDID,
|
|
26
|
-
act: [
|
|
27
|
-
permission
|
|
28
|
-
],
|
|
29
|
-
res: [
|
|
30
|
-
`group/${groupID}/*`
|
|
31
|
-
]
|
|
32
|
-
};
|
|
33
|
-
if (expiration != null) {
|
|
34
|
-
payload.exp = expiration;
|
|
35
|
-
}
|
|
36
|
-
return await createCapability(identity, payload, undefined, parentCapability != null ? {
|
|
37
|
-
parentCapability
|
|
38
|
-
} : undefined);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Validates that a capability token grants the specified permission for a group.
|
|
42
|
-
*
|
|
43
|
-
* Resource matching accepts three forms:
|
|
44
|
-
* - `group/<groupID>/*` — full access to a single group (what
|
|
45
|
-
* {@link createGroupCapability} and {@link delegateGroupMembership} issue)
|
|
46
|
-
* - `group/<groupID>/<suffix>` — scoped access within a single group
|
|
47
|
-
* - `*` — **global wildcard**: grants access to EVERY group, and to every
|
|
48
|
-
* other resource type in the stack that honours `*`. This is intentionally
|
|
49
|
-
* supported so root identities holding a stack-wide capability can operate
|
|
50
|
-
* on any group, but its blast radius is total: a leaked, stolen or
|
|
51
|
-
* over-delegated `res: ['*']` token compromises all groups at once. Never
|
|
52
|
-
* issue `*` to regular members or services — delegate `group/<groupID>/*`
|
|
53
|
-
* (or narrower) instead, with an `exp` and a verifiable delegation chain.
|
|
54
|
-
*/ export async function validateGroupCapability(params) {
|
|
55
|
-
const { tokenData, groupID, delegationChain, options } = params;
|
|
56
|
-
const token = await verifyToken(tokenData, {
|
|
57
|
-
cache: options?.cache,
|
|
58
|
-
resolver: options?.resolver
|
|
59
|
-
});
|
|
60
|
-
assertCapabilityToken(token);
|
|
61
|
-
// Verify the resource matches the group. `res === '*'` is the global
|
|
62
|
-
// wildcard intentionally kept for root identities — see the JSDoc above
|
|
63
|
-
// for its blast radius before touching this condition.
|
|
64
|
-
const expectedResource = `group/${groupID}/`;
|
|
65
|
-
const resources = Array.isArray(token.payload.res) ? token.payload.res : [
|
|
66
|
-
token.payload.res
|
|
67
|
-
];
|
|
68
|
-
const matchesGroup = resources.some((res)=>res === `group/${groupID}/*` || res.startsWith(expectedResource) || res === '*');
|
|
69
|
-
if (!matchesGroup) {
|
|
70
|
-
throw new Error(`Invalid capability: does not grant access to group ${groupID}`);
|
|
71
|
-
}
|
|
72
|
-
// Verify delegation chain if provided
|
|
73
|
-
if (delegationChain != null && delegationChain.length > 0) {
|
|
74
|
-
await checkDelegationChain(token.payload, delegationChain, options);
|
|
75
|
-
} else if (normalizeDID(token.payload.iss) !== normalizeDID(token.payload.sub)) {
|
|
76
|
-
throw new Error('Invalid capability: delegation chain required for delegated capabilities');
|
|
77
|
-
}
|
|
78
|
-
return token;
|
|
79
|
-
}
|