@calimero-network/mero-js 23.0.0 → 23.1.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/dist/admin-api/admin-types.d.ts +3 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +100 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +100 -1
- package/dist/index.mjs.map +2 -2
- package/dist/warrant/governance-op.d.ts +36 -0
- package/dist/warrant/governance-op.js +115 -0
- package/dist/warrant/index.d.ts +1 -1
- package/dist/warrant/index.js +1 -1
- package/package.json +1 -1
|
@@ -155,3 +155,39 @@ export interface NamespaceCreatedInput {
|
|
|
155
155
|
* inline. The warrant's scope must be {@link foundedNamespaceId}`(founder, salt)`.
|
|
156
156
|
*/
|
|
157
157
|
export declare function namespaceCreatedOp(input: NamespaceCreatedInput): GovernanceOp;
|
|
158
|
+
/** Set `member`'s capabilities in the group (`GroupOp::MemberCapabilitySet`). Bit 9 is refused. */
|
|
159
|
+
export declare function memberCapabilitySetOp(member: string, capabilities: number): GovernanceOp;
|
|
160
|
+
/** Detach a context from the group (`GroupOp::ContextDetached`). */
|
|
161
|
+
export declare function contextDetachedOp(contextId: string): GovernanceOp;
|
|
162
|
+
/** Make a subgroup open (members of the parent may join it themselves) or restricted. */
|
|
163
|
+
export declare function subgroupVisibilitySetOp(mode: 'open' | 'restricted'): GovernanceOp;
|
|
164
|
+
/** Name the group, with optional key/value data (`GroupOp::GroupMetadataSet`). */
|
|
165
|
+
export declare function groupMetadataSetOp(input?: {
|
|
166
|
+
name?: string;
|
|
167
|
+
data?: Record<string, string>;
|
|
168
|
+
}): GovernanceOp;
|
|
169
|
+
/** Name a member in the group (`GroupOp::MemberMetadataSet`). */
|
|
170
|
+
export declare function memberMetadataSetOp(member: string, input?: {
|
|
171
|
+
name?: string;
|
|
172
|
+
data?: Record<string, string>;
|
|
173
|
+
}): GovernanceOp;
|
|
174
|
+
/** Name a context in the group (`GroupOp::ContextMetadataSet`). */
|
|
175
|
+
export declare function contextMetadataSetOp(contextId: string, input?: {
|
|
176
|
+
name?: string;
|
|
177
|
+
data?: Record<string, string>;
|
|
178
|
+
}): GovernanceOp;
|
|
179
|
+
/** Grant `member` a per-context capability (`GroupOp::ContextCapabilityGranted`). */
|
|
180
|
+
export declare function contextCapabilityGrantedOp(contextId: string, member: string, capability: number): GovernanceOp;
|
|
181
|
+
/** Revoke a per-context capability from `member` (`GroupOp::ContextCapabilityRevoked`). */
|
|
182
|
+
export declare function contextCapabilityRevokedOp(contextId: string, member: string, capability: number): GovernanceOp;
|
|
183
|
+
/**
|
|
184
|
+
* Join an open subgroup yourself (`RootOp::MemberJoinedOpen`), a root op posted
|
|
185
|
+
* to the namespace. `member` must be the author; `credential` is the author's
|
|
186
|
+
* own `AccountProof<DeviceCert>`, hex, carried as-is. The author's
|
|
187
|
+
* `CAN_JOIN_OPEN_SUBGROUPS` and the open inheritance path are checked as usual.
|
|
188
|
+
*/
|
|
189
|
+
export declare function memberJoinedOpenOp(input: {
|
|
190
|
+
member: string;
|
|
191
|
+
groupId: string;
|
|
192
|
+
credential: string;
|
|
193
|
+
}): GovernanceOp;
|
|
@@ -36,13 +36,22 @@ const GROUP_OP = {
|
|
|
36
36
|
MemberRemoved: 2,
|
|
37
37
|
MemberLeft: 3,
|
|
38
38
|
MemberRoleSet: 4,
|
|
39
|
+
MemberCapabilitySet: 5,
|
|
39
40
|
DefaultCapabilitiesSet: 6,
|
|
41
|
+
ContextDetached: 9,
|
|
42
|
+
SubgroupVisibilitySet: 10,
|
|
43
|
+
GroupMetadataSet: 11,
|
|
44
|
+
MemberMetadataSet: 12,
|
|
45
|
+
ContextMetadataSet: 13,
|
|
46
|
+
ContextCapabilityGranted: 16,
|
|
47
|
+
ContextCapabilityRevoked: 17,
|
|
40
48
|
};
|
|
41
49
|
/** `RootOp` discriminants, by position in core's enum. */
|
|
42
50
|
const ROOT_OP = {
|
|
43
51
|
GroupCreated: 0,
|
|
44
52
|
GroupReparented: 1,
|
|
45
53
|
GroupDeleted: 2,
|
|
54
|
+
MemberJoinedOpen: 7,
|
|
46
55
|
NamespaceCreatedV2: 9,
|
|
47
56
|
};
|
|
48
57
|
/** core's `NAMESPACE_ID_DOMAIN`, which a founded namespace id is hashed under. */
|
|
@@ -212,3 +221,109 @@ export function namespaceCreatedOp(input) {
|
|
|
212
221
|
bytes: concat(tag(ROOT_OP.NamespaceCreatedV2), fromHex(input.founder, 'founder', 32), credential, fromHex(input.salt, 'salt', 32)),
|
|
213
222
|
};
|
|
214
223
|
}
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
// The rest of the delegable set. Layouts are pinned against core's
|
|
226
|
+
// `delegable_governance_op_vectors_for_non_rust_encoders_are_stable`
|
|
227
|
+
// (crates/governance-types/src/tests.rs, core#4272).
|
|
228
|
+
/** A borsh `String`: a u32 byte length, then the UTF-8 bytes. */
|
|
229
|
+
function str(value) {
|
|
230
|
+
const bytes = new TextEncoder().encode(value);
|
|
231
|
+
return concat(u32le(bytes.length), bytes);
|
|
232
|
+
}
|
|
233
|
+
/** A borsh `Option<String>`: 0, or 1 then the string. */
|
|
234
|
+
function optionalStr(value) {
|
|
235
|
+
return value === undefined ? tag(0) : concat(tag(1), str(value));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* A borsh `BTreeMap<String, String>`: a u32 count, then each entry in the
|
|
239
|
+
* map's own order, which is by key BYTES (not JS string order).
|
|
240
|
+
*/
|
|
241
|
+
function stringMap(data = {}) {
|
|
242
|
+
const enc = new TextEncoder();
|
|
243
|
+
const entries = Object.entries(data)
|
|
244
|
+
.map(([k, v]) => [enc.encode(k), v, k])
|
|
245
|
+
.sort(([a], [b]) => {
|
|
246
|
+
for (let i = 0; i < Math.min(a.length, b.length); i++)
|
|
247
|
+
if (a[i] !== b[i])
|
|
248
|
+
return a[i] - b[i];
|
|
249
|
+
return a.length - b.length;
|
|
250
|
+
});
|
|
251
|
+
return concat(u32le(entries.length), ...entries.flatMap(([, v, k]) => [str(k), str(v)]));
|
|
252
|
+
}
|
|
253
|
+
/** Validate a u32 capability mask a relay may carry: never bit 9. */
|
|
254
|
+
function relayableMask(capabilities, what) {
|
|
255
|
+
if (!Number.isInteger(capabilities) || capabilities < 0 || capabilities > 4294967295) {
|
|
256
|
+
throw new Error(`${what} must be a u32 bit mask, got ${String(capabilities)}`);
|
|
257
|
+
}
|
|
258
|
+
if (hasCap(capabilities, CAPABILITIES.CAN_AUTHOR_ON_BEHALF)) {
|
|
259
|
+
throw new Error(`${what} may not include CAN_AUTHOR_ON_BEHALF (512): a relay never carries a change to it`);
|
|
260
|
+
}
|
|
261
|
+
return capabilities;
|
|
262
|
+
}
|
|
263
|
+
/** Set `member`'s capabilities in the group (`GroupOp::MemberCapabilitySet`). Bit 9 is refused. */
|
|
264
|
+
export function memberCapabilitySetOp(member, capabilities) {
|
|
265
|
+
return {
|
|
266
|
+
kind: 'group',
|
|
267
|
+
bytes: concat(tag(GROUP_OP.MemberCapabilitySet), fromHex(member, 'member', 32), u32le(relayableMask(capabilities, 'capabilities'))),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/** Detach a context from the group (`GroupOp::ContextDetached`). */
|
|
271
|
+
export function contextDetachedOp(contextId) {
|
|
272
|
+
return { kind: 'group', bytes: concat(tag(GROUP_OP.ContextDetached), fromHex(contextId, 'contextId', 32)) };
|
|
273
|
+
}
|
|
274
|
+
/** Make a subgroup open (members of the parent may join it themselves) or restricted. */
|
|
275
|
+
export function subgroupVisibilitySetOp(mode) {
|
|
276
|
+
if (mode !== 'open' && mode !== 'restricted')
|
|
277
|
+
throw new Error(`mode must be open or restricted, got ${String(mode)}`);
|
|
278
|
+
return { kind: 'group', bytes: concat(tag(GROUP_OP.SubgroupVisibilitySet), tag(mode === 'open' ? 0 : 1)) };
|
|
279
|
+
}
|
|
280
|
+
/** Name the group, with optional key/value data (`GroupOp::GroupMetadataSet`). */
|
|
281
|
+
export function groupMetadataSetOp(input = {}) {
|
|
282
|
+
return { kind: 'group', bytes: concat(tag(GROUP_OP.GroupMetadataSet), optionalStr(input.name), stringMap(input.data)) };
|
|
283
|
+
}
|
|
284
|
+
/** Name a member in the group (`GroupOp::MemberMetadataSet`). */
|
|
285
|
+
export function memberMetadataSetOp(member, input = {}) {
|
|
286
|
+
return {
|
|
287
|
+
kind: 'group',
|
|
288
|
+
bytes: concat(tag(GROUP_OP.MemberMetadataSet), fromHex(member, 'member', 32), optionalStr(input.name), stringMap(input.data)),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/** Name a context in the group (`GroupOp::ContextMetadataSet`). */
|
|
292
|
+
export function contextMetadataSetOp(contextId, input = {}) {
|
|
293
|
+
return {
|
|
294
|
+
kind: 'group',
|
|
295
|
+
bytes: concat(tag(GROUP_OP.ContextMetadataSet), fromHex(contextId, 'contextId', 32), optionalStr(input.name), stringMap(input.data)),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function contextCapability(capability) {
|
|
299
|
+
if (!Number.isInteger(capability) || capability < 1 || capability > 0xff) {
|
|
300
|
+
throw new Error(`capability must be a non-zero u8, got ${String(capability)}`);
|
|
301
|
+
}
|
|
302
|
+
return tag(capability);
|
|
303
|
+
}
|
|
304
|
+
/** Grant `member` a per-context capability (`GroupOp::ContextCapabilityGranted`). */
|
|
305
|
+
export function contextCapabilityGrantedOp(contextId, member, capability) {
|
|
306
|
+
return {
|
|
307
|
+
kind: 'group',
|
|
308
|
+
bytes: concat(tag(GROUP_OP.ContextCapabilityGranted), fromHex(contextId, 'contextId', 32), fromHex(member, 'member', 32), contextCapability(capability)),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/** Revoke a per-context capability from `member` (`GroupOp::ContextCapabilityRevoked`). */
|
|
312
|
+
export function contextCapabilityRevokedOp(contextId, member, capability) {
|
|
313
|
+
return {
|
|
314
|
+
kind: 'group',
|
|
315
|
+
bytes: concat(tag(GROUP_OP.ContextCapabilityRevoked), fromHex(contextId, 'contextId', 32), fromHex(member, 'member', 32), contextCapability(capability)),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Join an open subgroup yourself (`RootOp::MemberJoinedOpen`), a root op posted
|
|
320
|
+
* to the namespace. `member` must be the author; `credential` is the author's
|
|
321
|
+
* own `AccountProof<DeviceCert>`, hex, carried as-is. The author's
|
|
322
|
+
* `CAN_JOIN_OPEN_SUBGROUPS` and the open inheritance path are checked as usual.
|
|
323
|
+
*/
|
|
324
|
+
export function memberJoinedOpenOp(input) {
|
|
325
|
+
return {
|
|
326
|
+
kind: 'root',
|
|
327
|
+
bytes: concat(tag(ROOT_OP.MemberJoinedOpen), fromHex(input.member, 'member', 32), fromHex(input.groupId, 'groupId', 32), fromHexUnsized(input.credential, 'credential')),
|
|
328
|
+
};
|
|
329
|
+
}
|
package/dist/warrant/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { signCreationWarrant, parseCreationWarrant, creationInitHash, } from './
|
|
|
4
4
|
export type { CreationWarrantInput, CreationWarrantFields, SignedCreationWarrant, } from './creation-warrant.js';
|
|
5
5
|
export { signGovernanceWarrant, parseGovernanceWarrant, governanceOpHash, } from './governance-warrant.js';
|
|
6
6
|
export type { GovernanceWarrantInput, GovernanceWarrantFields, } from './governance-warrant.js';
|
|
7
|
-
export { memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from './governance-op.js';
|
|
7
|
+
export { memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, memberCapabilitySetOp, contextDetachedOp, subgroupVisibilitySetOp, groupMetadataSetOp, memberMetadataSetOp, contextMetadataSetOp, contextCapabilityGrantedOp, contextCapabilityRevokedOp, memberJoinedOpenOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from './governance-op.js';
|
|
8
8
|
export type { GovernanceOp, GovernanceOpKind, GovernanceMemberRole, GroupCreatedInput, SubgroupCreation, NamespaceCreatedInput, } from './governance-op.js';
|
package/dist/warrant/index.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
export { signWarrant, intentHash } from './warrant.js';
|
|
3
3
|
export { signCreationWarrant, parseCreationWarrant, creationInitHash, } from './creation-warrant.js';
|
|
4
4
|
export { signGovernanceWarrant, parseGovernanceWarrant, governanceOpHash, } from './governance-warrant.js';
|
|
5
|
-
export { memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from './governance-op.js';
|
|
5
|
+
export { memberAddedOp, memberRemovedOp, memberLeftOp, memberRoleSetOp, groupCreatedOp, createdSubgroupId, subgroupCreation, groupReparentedOp, groupDeletedOp, memberCapabilitySetOp, contextDetachedOp, subgroupVisibilitySetOp, groupMetadataSetOp, memberMetadataSetOp, contextMetadataSetOp, contextCapabilityGrantedOp, contextCapabilityRevokedOp, memberJoinedOpenOp, namespaceCreatedOp, defaultCapabilitiesSetOp, foundedNamespaceId, } from './governance-op.js';
|